Changeset 9352a7e


Ignore:
Timestamp:
01/14/15 12:42:58 (2 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.1.1
Children:
05dfeaa
Parents:
fdc30a1
Message:

Completely revamp the device-widgets for the mounttray. This now uses the new pc-sysconfig backend, and works much better/faster.

Location:
src-qt5/pc-mounttray
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src-qt5/pc-mounttray/DeviceWidget.cpp

    ree1b292 r9352a7e  
    55#include <QStringList> 
    66#include <QIcon> 
    7  
    8 DeviceWidget::DeviceWidget(QString devnode) : QWidget(), ui(new Ui::DeviceWidget){ 
     7#include <QInputDialog> 
     8#include <QMessageBox> 
     9#include <QTimer> 
     10#include <QFile> 
     11#include <QDir> 
     12#include <QDebug> 
     13#include <QPainter> 
     14#include <QPixmap> 
     15#include <QIcon> 
     16 
     17#include <pcbsd-utils.h> 
     18 
     19DeviceWidget::DeviceWidget(QWidget *parent, QString devnode) : QWidget(parent), ui(new Ui::DeviceWidget){ 
    920  ui->setupUi(this); //load the designer file 
    1021  isMounted = false; //default value 
     
    1223    WAct->setDefaultWidget(this); 
    1324  ui->label_dev->setWhatsThis(devnode); 
     25  connect(ui->tool_run, SIGNAL(clicked()), this, SLOT(runButtonClicked()) ); 
     26  connect(ui->tool_mount, SIGNAL(clicked()), this, SLOT(mountButtonClicked()) ); 
     27  connect(ui->check_auto, SIGNAL(clicked(bool)), this, SLOT(changeAutoMount(bool)) ); 
     28  connect(ui->tool_tray, SIGNAL(clicked()), this, SLOT(OpenTrayClicked()) ); 
     29         
    1430} 
    1531 
     
    3551} 
    3652 
     53QString DeviceWidget::mountpoint(){ 
     54  return ui->tool_run->whatsThis();      
     55} 
     56 
    3757QWidgetAction* DeviceWidget::action(){ 
    3858  return WAct; 
     
    4060 
    4161// == Widget UpdateRoutines 
    42 void DeviceWidget::updateDevice(bool ismounted){ 
     62void DeviceWidget::UpdateDevice(bool ismounted){ 
    4363  //This is the full device update routine - usually only needs to be run on init (except for CD devices) 
    4464  isMounted = ismounted; //save this for later 
     
    5676 
    5777// == PRIVATE FUNCTIONS == 
    58 void DeviceWidget::doUpdates(){ 
     78void DeviceWidget::doUpdate(){ 
    5979  bool firstrun = type().isEmpty(); 
     80  //qDebug() << "Update Item:" << firstrun << quickupdates << node(); 
    6081  if(firstrun || !quickupdates){ 
    6182    QStringList info = pcbsd::Utils::runShellCommand("pc-sysconfig \"devinfo "+node()+"\"").join("").split(", "); 
     83    if(info.length() < 3){ emit RefreshDeviceList(); return; } //invalid device - will probably get removed here in a moment 
    6284    //Info Output: <filesystem>, <label>, <type> 
     85    //qDebug() << " - info:" << info; 
    6386    //Save this into the internal variables 
    6487    ui->label_icon->setWhatsThis(info[2]); //type 
     
    7396    else if(type()=="CD-AUDIO"){ icon = icon.arg("musiccd"); } 
    7497    else if(type()=="CD-VIDEO"){ icon = icon.arg("cd-video"); } 
    75     else if(type().startsWith("CD"){ icon = icon.arg("cd-generic"); } 
     98    else if(type().startsWith("CD")){ icon = icon.arg("cd-generic"); } 
    7699    else if(type()=="ISO"){ icon = icon.arg("dvd"); } 
    77100    else{ icon = icon.arg("CDdevices"); } 
    78     if(filesystem=="NONE"){ 
     101    if(filesystem()=="NONE" && !type().startsWith("CD")){ 
    79102      //Add the question-mark overlay to the icon, signifying that it is an unknown filesystem 
    80103      QPixmap tmp(icon); 
     
    87110      ui->label_icon->setPixmap(QPixmap(icon)); 
    88111    } 
    89     if(type().startsWith("CD") && type()!="CD-DATA" ){  
     112    if(type()=="CD-AUDIO" || type()=="CD-VIDEO"){  
    90113      ui->tool_run->setIcon(QIcon(":icons/play.png"));  
     114      ui->tool_run->setText(tr("Play")); 
    91115    }else{  
    92116      ui->tool_run->setIcon(QIcon(":icons/folder.png") );  
     117      ui->tool_run->setText(tr("Browse")); 
    93118    } 
    94119    ui->tool_tray->setVisible(type().startsWith("CD")); //This is a CD tray 
    95     canmount = !filesystem().isEmpty() || !type().startsWith("CD"); //has a detected filesystem or is not a CD 
     120    canmount = filesystem()!="NONE" || !type().startsWith("CD"); //has a detected filesystem or is not a CD 
    96121    ui->tool_mount->setVisible(canmount); 
    97122    ui->check_auto->setVisible(canmount && !type().startsWith("CD")); 
     
    100125  //Update the status of the mount button (TO DO - special ISO handling) 
    101126  if(isMounted){ 
    102     ui->tool_mount->setText(tr("Mount")); 
    103     ui->tool_mount->setIcon(QIcon(":icons/mount.png"));  
     127    ui->tool_mount->setText(tr("Unmount")); 
     128    ui->tool_mount->setIcon(QIcon(":icons/eject.png"));  
    104129    QString devsize = pcbsd::Utils::runShellCommand("pc-sysconfig \"devsize "+node()+"\"").join(""); 
    105130    if(devsize.contains("??")){  
    106131      ui->progressBar->setRange(0,0); 
    107     else{ 
     132    }else{ 
    108133       ui->progressBar->setRange(0,100); 
    109134       ui->progressBar->setValue(devsize.section("(",1,1).section("%",0,0).toInt()); 
    110        ui->progressBar->setToolTip(devSize); 
     135       ui->progressBar->setToolTip(devsize); 
    111136    } 
    112137  }else{ 
    113     ui->tool_mount->setText(tr("Unmount")); 
    114     ui->tool_mount->setIcon(QIcon(":icons/eject.png")); 
     138    ui->tool_mount->setText(tr("Mount")); 
     139    ui->tool_mount->setIcon(QIcon(":icons/mount.png")); 
    115140  } 
    116141  ui->label_icon->setEnabled(isMounted || !canmount); 
    117   ui->tool_run->setVisible( !type().startsWith("CD") ); //if it is mounted, it can also be run 
     142  ui->tool_run->setVisible( (isMounted && !mountpoint().isEmpty()) || type()=="CD-AUDIO" || type()=="CD-VIDEO" ); //if it is mounted, it can also be run 
    118143  ui->progressBar->setVisible(isMounted && ui->progressBar->maximum()==100); 
    119144   
    120145   
    121146  if(firstrun){ 
    122     if(canmount && !type.startsWith("CD") ){ 
     147    if(canmount && !type().startsWith("CD") ){ 
    123148      //Load auto-mount database and act appropriately 
    124              
     149      QString AMFILE = QDir::homePath() + "/.pc-automounttray"; 
     150      if(QFile::exists(AMFILE)){ 
     151        QString cmd = "cat "+AMFILE; 
     152        QString search = label() +" "+ type()+" "+ filesystem(); 
     153        bool amount = !pcbsd::Utils::runShellCommandSearch(cmd, search).isEmpty(); 
     154        ui->check_auto->setChecked(amount); 
     155        if(amount){ 
     156          mountButtonClicked(); 
     157          if(isMounted){ 
     158            emit ShowMessage(tr("Device Mounted"), QString(tr("%1 has been automatically mounted on %2")).arg(label(), mountpoint()) ); 
     159            runButtonClicked(); //also open the directory 
     160          } 
     161        } 
     162      } 
    125163    }else if(canmount){ 
    126164      //This is some kind of optical disk that can also be mounted (Blueray/DVD, or data disk for instance) 
     
    134172} 
    135173 
    136 void DeviceWidget::changeAutoMount(); //auto-mount option changed 
    137 void DeviceWidget::mountButtonClicked(); //mount/unmount the device (based on current status) 
    138 void DeviceWidget::runButtonClicked(); //Run the device (audio/video CD, browse filesystem) 
     174void DeviceWidget::changeAutoMount(bool checked){ 
     175  //auto-mount option changed 
     176  QString  AMFILE= QDir::homePath() + "/.pc-automounttray"; 
     177  qDebug() << "Auto-mount toggled for:" << node() << checked; 
     178  QString entry = label()+":::"+type()+":::"+filesystem(); 
     179  if(checked){ 
     180    //Add this entry to the auto-mount file 
     181    QString cmd = "echo \""+entry+"\" >> "+AMFILE; 
     182    system( cmd.toUtf8() ); 
     183  }else{ 
     184    //Remove this entry from the automount file 
     185    QString tmpFile = AMFILE+".tmp"; 
     186    QString cmd = "cat "+AMFILE+" | grep -v "+entry+" > "+tmpFile+"; mv "+tmpFile+" "+AMFILE; 
     187    system( cmd.toUtf8() ); 
     188  } 
     189} 
     190 
     191void DeviceWidget::mountButtonClicked(){ 
     192  //mount/unmount the device (based on current status) 
     193  if(isMounted){ 
     194    QString res = pcbsd::Utils::runShellCommand("pc-sysconfig \"unmount "+node()+"\"").join(""); 
     195    if(res.simplified()!="[SUCCESS]"){ 
     196      //Can add additional types of error parsing later (TO-DO) 
     197      //See if the user wants to try and force the unmount 
     198      if(QMessageBox::Yes == QMessageBox::question(0, tr("Device Busy"), tr("The device appears to be busy. Do you want to forcibly unmount the device?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No)){ 
     199        res = pcbsd::Utils::runShellCommand("pc-sysconfig \"unmount "+node()+" force\"").join(""); 
     200      }else{ 
     201        return; //don't show the result message if the action was cancelled 
     202      }        
     203    } 
     204    //Now parse the output and emit the proper signals 
     205    if(res=="[SUCCESS]"){ 
     206      QuickUpdate(false); //quickly update the UI with the new mount status 
     207    }else{ 
     208      QMessageBox::warning(this, tr("Unmount Error"), tr("The device could not be unmounted. Please try again later") ); 
     209    } 
     210     
     211  }else{ 
     212    //Device unmounted, need to mount it 
     213    QString fs = filesystem(); 
     214    if(fs=="NONE"){ 
     215      //prompt for what filesystem to try and use  to mount the device 
     216      QStringList fslist = pcbsd::Utils::runShellCommand("pc-sysconfig supportedfilesystems").join("").split(", "); 
     217      bool ok = false; 
     218      fs = QInputDialog::getItem(0,tr("No Filesystem Detected"), tr("Select a filesystem to try:"), fslist, 0, false, &ok); 
     219      if(!ok){ return; } //cancelled 
     220    } 
     221    //Now try to mount the device 
     222    QString res = pcbsd::Utils::runShellCommand("pc-sysconfig \"mount "+node()+" "+fs+"\"").join(""); 
     223    if(res.startsWith("[SUCCESS]")){ 
     224      //Save the mountpoint for use later (return format: "[SUCCESS] <mountpoint>" 
     225      ui->tool_run->setWhatsThis( res.section("]",1,20).simplified() ); 
     226      QuickUpdate(true); 
     227    }else{ 
     228      qDebug() << node()+":" << res; 
     229      QString err = tr("The device could not be mounted. Please try again later."); 
     230      QMessageBox::warning(0,tr("Device Mounting Error"), err); 
     231    } 
     232     
     233  } //end of mount detection 
     234  emit RefreshDeviceList(); 
     235} 
     236 
     237void DeviceWidget::runButtonClicked(){ 
     238  //Run the device (audio/video CD, browse filesystem) 
     239  if(isMounted){  
     240    //Open the mountpoint directory 
     241    QProcess::startDetached("xdg-open \""+mountpoint()+"\""); 
     242  }else if(type()=="CD-AUDIO"){ 
     243    QProcess::startDetached("smplayer cdda://1"); 
     244  }else if(type()=="CD-VIDEO"){ 
     245    QProcess::startDetached("smplayer dvd://1"); 
     246  } 
     247  emit CloseMenu(); 
     248} 
     249 
    139250void DeviceWidget::OpenTrayClicked(){   
    140251  //Open the CD tray 
    141252  QProcess::startDetached("cdcontrol eject /dev/"+node()); 
    142   emit  
    143 } 
     253  emit CloseMenu(); 
     254  emit RefreshDeviceList(); 
     255} 
  • src-qt5/pc-mounttray/DeviceWidget.h

    ree1b292 r9352a7e  
    1414        Q_OBJECT 
    1515public: 
    16         DeviceWidget(QString devicenode); 
     16        DeviceWidget(QWidget *parent, QString devicenode); 
    1717        ~DeviceWidget(); 
    1818 
    1919        QString node(); //Get the device ID that is managed by this widget 
    2020        QString type(); //Get the device type  
     21        QString label(); 
     22        QString filesystem(); 
     23        QString mountpoint(); 
    2124        QWidgetAction* action(); //Simplification for adding a widget to a menu (QMenu->addAction(DeviceWidget->action()) 
    2225 
     
    3134private slots: 
    3235        void doUpdate(); 
    33         void changeAutoMount(); //auto-mount option changed 
     36        void changeAutoMount(bool checked); //auto-mount option changed 
    3437        void mountButtonClicked(); //mount/unmount the device (based on current status) 
    3538        void runButtonClicked(); //Run the device (audio/video CD, browse filesystem) 
     
    3740 
    3841signals: 
    39         void closeMenu(); 
     42        void CloseMenu(); 
    4043        void ShowMessage(QString title, QString contents); 
    41         void OpenDevice(QString nodedir, QString type); //device/directory to open, and the type of device it is 
    4244        void RefreshDeviceList(); //this is usually if the device was modified by the gui directly (such as opening the CD tray) 
    4345         
  • src-qt5/pc-mounttray/DeviceWidget.ui

    ree1b292 r9352a7e  
    88    <y>0</y> 
    99    <width>300</width> 
    10     <height>100</height> 
     10    <height>70</height> 
    1111   </rect> 
    1212  </property> 
     
    2020   <size> 
    2121    <width>300</width> 
    22     <height>100</height> 
     22    <height>70</height> 
    2323   </size> 
    2424  </property> 
    2525  <property name="maximumSize"> 
    2626   <size> 
    27     <width>300</width> 
    28     <height>100</height> 
     27    <width>301</width> 
     28    <height>70</height> 
    2929   </size> 
    3030  </property> 
     
    5050   <item> 
    5151    <layout class="QHBoxLayout" name="horizontalLayout_2"> 
     52     <property name="spacing"> 
     53      <number>0</number> 
     54     </property> 
    5255     <item> 
    5356      <layout class="QVBoxLayout" name="verticalLayout_3"> 
     
    8689        </widget> 
    8790       </item> 
    88        <item> 
    89         <widget class="QCheckBox" name="check_auto"> 
    90          <property name="toolTip"> 
    91           <string>Automatically use this device when it is attached to the system</string> 
    92          </property> 
    93          <property name="text"> 
    94           <string>Auto-Run</string> 
    95          </property> 
    96         </widget> 
    97        </item> 
    9891      </layout> 
    9992     </item> 
    10093     <item> 
    10194      <layout class="QVBoxLayout" name="verticalLayout"> 
     95       <property name="spacing"> 
     96        <number>2</number> 
     97       </property> 
    10298       <item> 
    103         <widget class="QLabel" name="label_dev"> 
    104          <property name="font"> 
    105           <font> 
    106            <pointsize>10</pointsize> 
    107            <weight>75</weight> 
    108            <bold>true</bold> 
    109           </font> 
    110          </property> 
    111          <property name="text"> 
    112           <string notr="true">Device Label</string> 
    113          </property> 
    114          <property name="scaledContents"> 
    115           <bool>true</bool> 
    116          </property> 
    117          <property name="alignment"> 
    118           <set>Qt::AlignCenter</set> 
    119          </property> 
    120         </widget> 
    121        </item> 
    122        <item> 
    123         <widget class="QProgressBar" name="progressBar"> 
    124          <property name="value"> 
    125           <number>24</number> 
    126          </property> 
    127          <property name="alignment"> 
    128           <set>Qt::AlignCenter</set> 
    129          </property> 
    130          <property name="textDirection"> 
    131           <enum>QProgressBar::TopToBottom</enum> 
    132          </property> 
    133         </widget> 
    134        </item> 
    135        <item> 
    136         <spacer name="verticalSpacer"> 
    137          <property name="orientation"> 
    138           <enum>Qt::Vertical</enum> 
    139          </property> 
    140          <property name="sizeHint" stdset="0"> 
    141           <size> 
    142            <width>20</width> 
    143            <height>0</height> 
    144           </size> 
    145          </property> 
    146         </spacer> 
     99        <layout class="QHBoxLayout" name="horizontalLayout_3"> 
     100         <item> 
     101          <widget class="QLabel" name="label_dev"> 
     102           <property name="sizePolicy"> 
     103            <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> 
     104             <horstretch>0</horstretch> 
     105             <verstretch>0</verstretch> 
     106            </sizepolicy> 
     107           </property> 
     108           <property name="font"> 
     109            <font> 
     110             <pointsize>10</pointsize> 
     111             <weight>75</weight> 
     112             <bold>true</bold> 
     113            </font> 
     114           </property> 
     115           <property name="styleSheet"> 
     116            <string notr="true">background: rgba(200,230,250,150); border-radius: 5px; border: none;</string> 
     117           </property> 
     118           <property name="text"> 
     119            <string notr="true">Device Label</string> 
     120           </property> 
     121           <property name="scaledContents"> 
     122            <bool>false</bool> 
     123           </property> 
     124           <property name="alignment"> 
     125            <set>Qt::AlignCenter</set> 
     126           </property> 
     127           <property name="wordWrap"> 
     128            <bool>true</bool> 
     129           </property> 
     130          </widget> 
     131         </item> 
     132         <item> 
     133          <widget class="QToolButton" name="tool_tray"> 
     134           <property name="toolTip"> 
     135            <string>Open the disk tray</string> 
     136           </property> 
     137           <property name="text"> 
     138            <string notr="true">Open Tray</string> 
     139           </property> 
     140           <property name="icon"> 
     141            <iconset resource="pc-mounttray.qrc"> 
     142             <normaloff>:/icons/drive-optical.png</normaloff>:/icons/drive-optical.png</iconset> 
     143           </property> 
     144           <property name="popupMode"> 
     145            <enum>QToolButton::InstantPopup</enum> 
     146           </property> 
     147           <property name="toolButtonStyle"> 
     148            <enum>Qt::ToolButtonIconOnly</enum> 
     149           </property> 
     150           <property name="arrowType"> 
     151            <enum>Qt::NoArrow</enum> 
     152           </property> 
     153          </widget> 
     154         </item> 
     155         <item> 
     156          <widget class="QCheckBox" name="check_auto"> 
     157           <property name="toolTip"> 
     158            <string>Automatically use this device when it is attached to the system</string> 
     159           </property> 
     160           <property name="text"> 
     161            <string>Auto-Run</string> 
     162           </property> 
     163          </widget> 
     164         </item> 
     165        </layout> 
    147166       </item> 
    148167       <item> 
    149168        <layout class="QHBoxLayout" name="horizontalLayout"> 
     169         <property name="rightMargin"> 
     170          <number>0</number> 
     171         </property> 
    150172         <item> 
    151173          <spacer name="horizontalSpacer"> 
     
    153175            <enum>Qt::Horizontal</enum> 
    154176           </property> 
     177           <property name="sizeType"> 
     178            <enum>QSizePolicy::Expanding</enum> 
     179           </property> 
    155180           <property name="sizeHint" stdset="0"> 
    156181            <size> 
    157              <width>40</width> 
     182             <width>0</width> 
    158183             <height>20</height> 
    159184            </size> 
    160185           </property> 
    161186          </spacer> 
     187         </item> 
     188         <item> 
     189          <widget class="QProgressBar" name="progressBar"> 
     190           <property name="value"> 
     191            <number>24</number> 
     192           </property> 
     193           <property name="alignment"> 
     194            <set>Qt::AlignCenter</set> 
     195           </property> 
     196           <property name="textDirection"> 
     197            <enum>QProgressBar::TopToBottom</enum> 
     198           </property> 
     199          </widget> 
    162200         </item> 
    163201         <item> 
     
    171209           </property> 
    172210           <property name="toolButtonStyle"> 
    173             <enum>Qt::ToolButtonTextUnderIcon</enum> 
     211            <enum>Qt::ToolButtonTextBesideIcon</enum> 
    174212           </property> 
    175213          </widget> 
     
    185223           </property> 
    186224           <property name="toolButtonStyle"> 
    187             <enum>Qt::ToolButtonTextUnderIcon</enum> 
     225            <enum>Qt::ToolButtonTextBesideIcon</enum> 
    188226           </property> 
    189227           <property name="autoRaise"> 
    190228            <bool>false</bool> 
    191            </property> 
    192           </widget> 
    193          </item> 
    194          <item> 
    195           <widget class="QToolButton" name="tool_tray"> 
    196            <property name="text"> 
    197             <string>Open Tray</string> 
    198            </property> 
    199            <property name="icon"> 
    200             <iconset resource="pc-mounttray.qrc"> 
    201              <normaloff>:/icons/drive-optical.png</normaloff>:/icons/drive-optical.png</iconset> 
    202            </property> 
    203            <property name="popupMode"> 
    204             <enum>QToolButton::InstantPopup</enum> 
    205            </property> 
    206            <property name="toolButtonStyle"> 
    207             <enum>Qt::ToolButtonTextUnderIcon</enum> 
    208            </property> 
    209            <property name="arrowType"> 
    210             <enum>Qt::NoArrow</enum> 
    211229           </property> 
    212230          </widget> 
  • src-qt5/pc-mounttray/mountTray.cpp

    r6482c61 r9352a7e  
    1212#include <pcbsd-utils.h> 
    1313 
     14#include "DeviceWidget.h" 
     15 
    1416MountTray::~MountTray(){ 
    1517} 
     
    2123  MTINIT=true; //set the flag that the mount tray is initializing; 
    2224  //getInitialUsername(); //try to detect the non-root user who is running the program with root permissions 
    23   getFileManager(); 
     25  //getFileManager(); 
    2426     
    2527  loadSavedSettings(); 
     
    2729  trayIcon = new QSystemTrayIcon(this); 
    2830  trayIconMenu = new QMenu(); 
     31    trayIcon->setContextMenu(trayIconMenu); 
     32         
    2933  //Generate the system menu options (these don't change) 
    3034  sysMenu = new QMenu( tr("More Options") ); 
    3135    sysMenu->setIcon( QIcon(":icons/config.png") ); 
    3236    //Add the additional options 
    33     sysMenu->addAction( QIcon(":icons/folder.png"), tr("Open Media Directory"), this, SLOT(slotOpenMediaDir()) ); 
     37    //sysMenu->addAction( QIcon(":icons/folder.png"), tr("Open Media Directory"), this, SLOT(slotOpenMediaDir()) ); 
    3438    sysMenu->addAction( QIcon(":icons/harddrive.png"), tr("View Disk Usage"),this,SLOT(slotOpenFSDialog()) ); 
    3539    sysMenu->addAction( QIcon(":icons/refresh.png"),tr("Rescan Devices"), this, SLOT(slotRescan()) ); 
     
    4246    sysMenu->addAction( QIcon(":icons/application-exit.png"), tr("Close Tray"), this, SLOT(closeTray()) ); 
    4347   
     48    menuline = trayIconMenu->addSeparator(); 
     49    trayIconMenu->addMenu(sysMenu); 
     50     
    4451  // Tie the left-click signal to open the context menu 
    4552  connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason)) ); 
     
    5158 
    5259  //Do an initial scan of the devices with dmesg 
    53   qDebug() << "-Performing initial device scan"; 
    54   scanInitialDevices(); 
     60  //qDebug() << "-Performing initial device scan"; 
     61  //scanInitialDevices(); 
     62 
    5563   
    5664  //Startup the devd watching process 
     
    5866  devdTimer = new QTimer(); 
    5967  devdTimer->setSingleShot(true); 
    60   connect(devdTimer,SIGNAL(timeout()),this,SLOT(slotDevChanges())); 
     68  connect(devdTimer,SIGNAL(timeout()),this,SLOT(UpdateDeviceMenu()) ); //slotDevChanges())); 
    6169  startupDevdProc(); 
    6270   
     
    7078   
    7179  //Update the tray menu and icons 
    72   updateMenu(); 
    73  
     80  //updateMenu(); 
     81  UpdateDeviceMenu(); 
     82   
    7483  qDebug() << "-Program now ready for use"; 
    7584  QTimer::singleShot(500, this, SLOT(slotDoneWithInit()) ); //give it 1/2 a second to settle 
    7685} 
    7786 
    78 void MountTray::updateMenu(){ 
     87/*void MountTray::updateMenu(){ 
    7988  //Clear the menu 
    8089  trayIconMenu->clear(); 
     
    165174  qDebug() << "Valid Device Removal:" <<  dev; 
    166175} 
    167  
     176*/ 
    168177void MountTray::slotTrayActivated(QSystemTrayIcon::ActivationReason reason) { 
    169    if(reason == QSystemTrayIcon::Trigger) { 
     178   //if(reason == QSystemTrayIcon::Trigger) { 
    170179     //Make sure all the items are updated 
    171      for(int i=0; i<deviceList.length(); i++){ 
     180     /*for(int i=0; i<deviceList.length(); i++){ 
    172181        deviceList[i]->updateItem(); 
    173      } 
     182     }*/ 
     183     UpdateDeviceMenu(true); //do the quick version 
     184     //qDebug() << "Show Menu"; 
    174185     trayIcon->contextMenu()->popup( QCursor::pos() ); 
    175    } 
     186   //} 
    176187} 
    177188 
     
    192203} 
    193204 
    194 void MountTray::slotDevChanges(bool showPopup){ 
     205/*void MountTray::slotDevChanges(bool showPopup){ 
    195206  //This function actually checks the system device list for changes 
    196207  //  and updates the available devices appropriately 
     
    244255  //Run the disk space check if appropriate 
    245256  if(useDiskWatcher && useDiskTimerDevd && showPopup){ diskWatcher->checkFS(); } 
    246 } 
     257}*/ 
    247258 
    248259void MountTray::closeTray(){ 
     
    251262  qDebug() << " -Shutting down DEVD watcher"; 
    252263  devdProc->disconnectFromServer(); 
    253   qDebug() << " -Unmounting managed devices and mount points"; 
     264  /*qDebug() << " -Unmounting managed devices and mount points"; 
    254265  for(int i=0; i<deviceList.length(); i++){ 
    255266    deviceList[i]->cleanup(); 
    256   } 
     267  }*/ 
    257268  //Close down the application 
    258269  exit(0); 
    259270} 
    260271 
    261 void MountTray::getFileManager(){ 
     272/*void MountTray::getFileManager(){ 
    262273  //Check for broken DE's that need a FM manually set 
    263274  FMCMD = "xdg-open"; //the default auto-detection application 
     
    291302  //cmd.prepend("("); cmd.append(") &"); 
    292303  QProcess::startDetached(cmd); 
    293 } 
     304}*/ 
    294305 
    295306void MountTray::slotRescan(){ 
     
    298309  slotDisplayPopup(tr("Please Wait"),tr("Rescanning devices attached to the system")); 
    299310  //Rescan the device list for new devices 
    300   scanInitialDevices(); 
     311  UpdateDeviceMenu(); 
     312  /*scanInitialDevices(); 
    301313  //Check that all the existing devices still exist 
    302314  for(int i=0; i<deviceList.length(); i++){ 
    303315    deviceList[i]->updateItem(); 
    304   } 
     316  }*/ 
    305317  //Run the disk check if appropriate 
    306318  if(useDiskWatcher){ diskWatcher->checkFS(); } 
     
    338350  QString file = QFileDialog::getOpenFileName( this, tr("Select ISO File"), QDir::homePath(), tr("ISO Files (*.iso)") ); 
    339351  if(file.isEmpty()){ return; } //cancelled 
    340   //check for available device node number /dev/md<number> 
     352   
     353  /*//check for available device node number /dev/md<number> 
    341354  int num = 1; 
    342355  while( QFile::exists("/dev/md"+QString::number(num)) ){ num++; } 
    343356  //add it to the device tree (will automatically get picked up by the device detection method) 
    344   QString cmd = "pc-su mdconfig -a -f "+file+" -u "+QString::number(num); 
     357  QString cmd = "pc-su mdconfig -a -f "+file+" -u "+QString::number(num);*/ 
     358  QString cmd = "pc-sysconfig \"load-iso "+file+"\""; 
    345359  QProcess::startDetached(cmd); 
    346360} 
     
    378392  }else if(!popupSave.isEmpty()){ 
    379393    //Check if it is a currently valid device 
    380     if(!popupSave.startsWith(DEVICEDIR)){ popupSave.prepend(DEVICEDIR); } 
     394    /*if(!popupSave.startsWith(DEVICEDIR)){ popupSave.prepend(DEVICEDIR); } 
    381395    for(int i=0; i<deviceList.length(); i++){ 
    382396      if( deviceList[i]->device == popupSave){ 
     
    391405        break; 
    392406      } 
    393     } 
     407    }*/ 
    394408  } 
    395409 
     
    461475} 
    462476 
    463 void MountTray::slotOpenAVDisk(QString type){ 
     477/*void MountTray::slotOpenAVDisk(QString type){ 
    464478  if(MTINIT){ return; } //don't open the launcher during program initialization 
    465479  //Get the list of all AudioVideo Applications on the sytem 
     
    510524  qDebug() << " -- Exec:" << cmd; 
    511525  QProcess::startDetached( cmd ); 
    512 } 
    513    
     526}*/ 
     527   
     528void MountTray::UpdateDeviceMenu(bool fast){ 
     529  QStringList avail, mounted; 
     530  QStringList tmp = pcbsd::Utils::runShellCommand("pc-sysconfig list-remdev list-mounteddev"); 
     531  if(tmp.length()<2 || tmp.join("").contains("Client Connection Error:") ){ return; } //invalid return 
     532  if(!tmp[0].contains("[NO INFO]")){ avail = tmp[0].split(", "); } 
     533  if(!tmp[1].contains("[NO INFO]")){ mounted = tmp[1].split(", "); } 
     534  //qDebug() << "Update Devices:" << avail << mounted; 
     535  //Update the current menu items as necessary 
     536  for(int i=0; i<DEVLIST.length(); i++){ 
     537    QString dev = DEVLIST[i]->node(); 
     538    if(avail.contains(dev)){  
     539      if(fast){ DEVLIST[i]->QuickUpdate(mounted.contains(dev)); } 
     540      else{ DEVLIST[i]->UpdateDevice(mounted.contains(dev)); } 
     541      avail.removeAll(dev); //remove this device from the list for the moment 
     542    }else{ 
     543      //Invalid device, remove it from the list 
     544      disconnect(DEVLIST[i]); 
     545      trayIconMenu->removeAction(DEVLIST[i]->action()); 
     546      DeviceWidget *tmp = DEVLIST.removeAt(i); 
     547      i--; 
     548    } 
     549  } 
     550  //Now create widgets for any new devices 
     551  for(int i=0; i<avail.length(); i++){ 
     552    DeviceWidget *item = new DeviceWidget(this, avail[i]); 
     553    connect(item, SIGNAL(CloseMenu()), this, SLOT(slotCloseMenu()) ); 
     554    connect(item, SIGNAL(RefreshDeviceList()), this, SLOT(UpdateDeviceMenu()) ); 
     555    connect(item, SIGNAL(ShowMessage(QString, QString)), this, SLOT(slotDisplayPopup(QString, QString)) ); 
     556    DEVLIST << item; 
     557    trayIconMenu->insertAction(menuline, item->action()); //put them above the line 
     558    item->UpdateDevice( mounted.contains(avail[i]) ); //need the full update to start 
     559  } 
     560  //Now show a popup message about any new devices 
     561  if(!avail.isEmpty() && !MTINIT){ 
     562    slotDisplayPopup(tr("Devices Available"), tr("New Devices are available for use")); 
     563  } 
     564   
     565  if(useDiskWatcher && useDiskTimerDevd && !MTINIT){ diskWatcher->checkFS(); } 
     566   
     567   //Update the main icon based upon whether devices have been found 
     568  if(DEVLIST.length()==0){ 
     569    trayIcon->setIcon( QIcon(":icons/CDdevices-inactive.png") ); 
     570  }else{ 
     571    if(mounted.length()==0){ 
     572      trayIcon->setIcon( QIcon(":icons/CDdevices.png") ); 
     573    }else{ 
     574      trayIcon->setIcon( QIcon(":icons/CDdevices.png") ); 
     575    } 
     576  }  
     577} 
  • src-qt5/pc-mounttray/mountTray.h

    r6482c61 r9352a7e  
    2020#include <pcbsd-xdgutils.h> 
    2121 
    22 #include "menuItem.h" 
     22//#include "menuItem.h" 
    2323#include "devCheck.h" 
    2424#include "fsWatcher.h" 
    2525#include "fsDialog.h" 
    2626#include "settingsDialog.h" 
    27  
     27#include "DeviceWidget.h" 
    2828 
    2929extern bool DEBUG_MODE; 
     
    5050  void slotDoneWithInit(); 
    5151  void newDevdMessage(); 
    52   void slotDevChanges(bool showPopup = true); 
     52  //void slotDevChanges(bool showPopup = true); 
    5353  void slotTrayActivated(QSystemTrayIcon::ActivationReason); 
    54   void slotOpenMediaDir(); 
    55   void openMediaDir(QString);  
     54  //void slotOpenMediaDir(); 
     55  //void openMediaDir(QString);  
    5656  void slotDisplayPopup(QString,QString, QString device = ""); 
    5757  void slotDisplayWarning(QString,QString); 
    5858  void slotPopupClicked(); 
    59   void removeDevice(QString); 
     59  //void removeDevice(QString); 
    6060  void slotRescan(); 
    6161  void slotOpenFSDialog(); 
     
    6363  void slotOpenISO(); 
    6464  void slotCloseMenu(); 
    65   void slotOpenAVDisk(QString dev); 
     65  //void slotOpenAVDisk(QString dev); 
     66 
     67  //New Functions 
     68  void UpdateDeviceMenu(bool fast = false); 
    6669   
    6770private: 
     71  QList<DeviceWidget*> DEVLIST;  
     72  QAction *menuline; 
     73 
    6874  DevCheck *DCheck; 
    6975  //QString USERNAME; 
     
    7379  QSystemTrayIcon* trayIcon; 
    7480  QMenu *trayIconMenu, *sysMenu; 
    75   QList<MenuItem*> deviceList; 
     81  //QList<MenuItem*> deviceList; 
    7682  //QStringList oldsysdev; 
    7783  FSWatcher *diskWatcher; 
     
    8490 
    8591  //CMD to use for opening the file manager 
    86   QString FMCMD; 
     92  //QString FMCMD; 
    8793 
    88   void updateMenu(); 
    89   void scanInitialDevices(); 
    90   int findDeviceInList(QString); 
    91   bool addDevice(QString,QString,QString,QString); 
     94  //void updateMenu(); 
     95  //void scanInitialDevices(); 
     96  //int findDeviceInList(QString); 
     97  //bool addDevice(QString,QString,QString,QString); 
    9298  void startupDevdProc(); 
    9399  //void getInitialUsername(); 
    94   void getFileManager(); 
     100  //void getFileManager(); 
    95101  void loadSavedSettings(); 
    96102  void saveCurrentSettings(); 
  • src-qt5/pc-mounttray/pc-mounttray.pro

    r673f7cf r9352a7e  
    88 
    99HEADERS += mountTray.h \ 
    10         menuItem.h \ 
    1110        devCheck.h \ 
    1211        fsWatcher.h \ 
    1312        fsDialog.h \ 
    14         settingsDialog.h 
     13        settingsDialog.h \ 
     14        DeviceWidget.h 
    1515 
    1616SOURCES += main.cpp \ 
    1717        mountTray.cpp \ 
    18         menuItem.cpp \ 
    1918        devCheck.cpp \ 
    2019        fsWatcher.cpp \ 
    2120        fsDialog.cpp \ 
    22         settingsDialog.cpp 
     21        settingsDialog.cpp \ 
     22        DeviceWidget.cpp 
     23 
     24FORMS += DeviceWidget.ui 
    2325 
    2426RESOURCES += pc-mounttray.qrc 
Note: See TracChangeset for help on using the changeset viewer.