示例#1
0
bool MountTray::addDevice(QString dev, QString label, QString type, QString filesys){
  if(!dev.startsWith(DEVICEDIR)){ dev.prepend(DEVICEDIR); }
  
  //Check if the device is already in the list
  int tot=0;
  for(int i=0; i<deviceList.length(); i++){
    if( deviceList[i]->device == dev ){ return false; } //already exists, do nothing
    if( deviceList[i]->getDeviceName().startsWith(label) ){ tot++; }
  }
  //See if the label is unique as well, otherwise add a number to the end to make it unique
  if(tot > 0 && !label.isEmpty()){ label.append("-"+QString::number(tot)); }
 
  qDebug() << "Valid Device Connection:" << dev << type << label << filesys;
  //Create the menu item (will automount if necessary)
  MenuItem *tmp = new MenuItem(this, DCheck, dev, label, type, filesys);
  //connect the signals/slots
  connect(tmp, SIGNAL(itemMounted(QString)), this, SLOT(openMediaDir(QString)) );
  connect(tmp, SIGNAL(newMessage(QString,QString)), this, SLOT(slotDisplayPopup(QString,QString)) );
  connect(tmp, SIGNAL(itemRemoved(QString)), this, SLOT(removeDevice(QString)) );
  connect(tmp, SIGNAL(itemWorking()), this, SLOT(slotCloseMenu()) );
  connect(tmp, SIGNAL(openAVDisk(QString)), this, SLOT(slotOpenAVDisk(QString)) );
  deviceList << tmp;
  //Update the menu
  updateMenu();
  return true;
}
示例#2
0
void MountTray::slotRescan(){
  //Display a notification
  qDebug() << "Re-scanning devices:";
  slotDisplayPopup(tr("Please Wait"),tr("Rescanning devices attached to the system"));
  //Rescan the device list for new devices
  UpdateDeviceMenu(false, true); //flag this as a refresh (don't show notifications)
  //Run the disk check if appropriate
  if(useDiskWatcher){ diskWatcher->checkFS(); }
  //Re-open the menu
  slotTrayActivated();
}
示例#3
0
void MountTray::slotDevChanges(bool showPopup){
  //This function actually checks the system device list for changes
  //  and updates the available devices appropriately
  
  if(DEBUG_MODE){ qDebug() << "Checking for Device Changes:"; }
  //Get the current list of devices
  QStringList nsd = DCheck->devChildren("");
  //Remove all the currently managed devices
  qDebug() << "Rescanning Device List";
  for(int i=0; i<deviceList.length(); i++){
    QString dev = deviceList[i]->device.section("/",-1);
    if(DEBUG_MODE){ qDebug() << " - Check device:" << dev; }
    int ni = nsd.indexOf(dev);
    if(ni == -1){
      //Device Removed
      if(DEBUG_MODE){ qDebug() << " - Device no longer connected:" << dev; }
      removeDevice(dev);
      i--;
    }else{
      //Probe the device for validity if not currently mounted
      if( !deviceList[i]->isMounted() ){
	QString ja, jb, jc, jd; //junk variables
        if( !DCheck->devInfo(dev,&ja,&jb,&jc,&jd) ){
	  if(DEBUG_MODE){ qDebug() << " - Device no longer valid:" << dev; }
	  //no longer valid device
	  removeDevice(dev);
	  i--;
	}
      }
      nsd.removeAt(ni);
    }
  }
  //Now Iterate through all available devices and probe them for validity
  // (This should catch devices that do not "announce" their presence by creating a new device node)
  for(int i=0; i<nsd.length(); i++){
    //Check if it is a good device
    QString dlabel, dtype, dfs, dsize; //additional output info
    bool good = DCheck->devInfo(nsd[i],&dtype,&dlabel,&dfs,&dsize);
    if(good){
      //Now create a new entry for this device
      bool added = addDevice(nsd[i],dlabel,dtype,dfs);  
      //Show a message bubble
      if(showPopup && added){ //make sure this is not shown for previously added devices
        QString title = tr("New Device");
        QString message = QString( tr("%1 can now be accessed")).arg(dlabel);
        slotDisplayPopup(title, message, nsd[i]);
      }
    }
  }
  
  //Run the disk space check if appropriate
  if(useDiskWatcher && useDiskTimerDevd && showPopup){ diskWatcher->checkFS(); }
}
示例#4
0
void MountTray::slotRescan(){
  //Display a notification
  qDebug() << "Re-scanning devices:";
  slotDisplayPopup(tr("Please Wait"),tr("Rescanning devices attached to the system"));
  //Rescan the device list for new devices
  scanInitialDevices();
  //Check that all the existing devices still exist
  for(int i=0; i<deviceList.length(); i++){
    deviceList[i]->updateItem();
  }
  //Run the disk check if appropriate
  if(useDiskWatcher){ diskWatcher->checkFS(); }
}
示例#5
0
void MountTray::UpdateDeviceMenu(bool fast, bool refresh){
  QStringList avail, mounted;
  QStringList tmp = pcbsd::Utils::runShellCommand("pc-sysconfig list-remdev list-mounteddev");
  if(tmp.length()<2 || tmp.join("").contains("Client Connection Error:") ){ return; } //invalid return
  if(!tmp[0].contains("[NO INFO]")){ avail = tmp[0].split(", "); }
  if(!tmp[1].contains("[NO INFO]")){ mounted = tmp[1].split(", "); }
  //qDebug() << "Update Devices:" << avail << mounted;
  //Update the current menu items as necessary
  bool newitems = false;
  for(int i=0; i<DEVLIST.length(); i++){
    QString dev = DEVLIST[i]->node();
    //qDebug() << "Check device:" << dev;
    if(avail.contains(dev)){ 
      if(fast){ DEVLIST[i]->QuickUpdate(mounted.contains(dev)); }
      else{ DEVLIST[i]->UpdateDevice(mounted.contains(dev)); }
      avail.removeAll(dev); //remove this device from the list for the moment
    }else{
      //Invalid device, remove it from the list
      disconnect(DEVLIST[i]);
      trayIconMenu->removeAction(DEVLIST[i]->action());
      DEVLIST.removeAt(i);
      i--;
    }
  }
  //Now create widgets for any new devices
  for(int i=0; i<avail.length(); i++){
    newitems = true;
    DeviceWidget *item = new DeviceWidget(this, avail[i]);
    item->setAutoPlay(useAutoPlay);
    connect(item, SIGNAL(CloseMenu()), this, SLOT(slotCloseMenu()) );
    connect(item, SIGNAL(RefreshDeviceList()), this, SLOT(UpdateDeviceMenu()) );
    connect(item, SIGNAL(ShowMessage(QString, QString)), this, SLOT(slotDisplayPopup(QString, QString)) );
    DEVLIST << item;
    trayIconMenu->insertAction(menuline, item->action()); //put them above the line
    item->UpdateDevice( mounted.contains(avail[i]) ); //need the full update to start
  }
  
  //Now update the list of available network shares
  netMenu->clear();
  QStringList info = pcbsd::Utils::runShellCommand("pc-sysconfig list-mountednetdrives").join("").split(", ");
  qDebug() << "Net Info:" << info;
  //Syntax for the list: [<name> (<IP>) on <directory>]
  for(int i=0; i<info.length(); i++){
    if(info[i].startsWith("[")){ continue; } //error code from pc-sysconfig
    QAction *act = new QAction(info[i].section("(",0,0).simplified(), netMenu);
      act->setWhatsThis( info[i].section(" on ",1,1).simplified() );
      act->setToolTip( info[i].section(")",0,0).section("(",1,1).simplified() );
    netMenu->addAction(act);
  }
  netMenu->setEnabled( !netMenu->isEmpty() );
  
  //Now show a popup message about any new devices
  if(!avail.isEmpty() && !MTINIT && newitems && !refresh){
    slotDisplayPopup(tr("Devices Available"), tr("New Devices are available for use"));
  }
  
  if(useDiskWatcher && useDiskTimerDevd && !MTINIT){ diskWatcher->checkFS(); }
  
   //Update the main icon based upon whether devices have been found
  if(DEVLIST.length()==0){
    trayIcon->setIcon( QIcon(":icons/CDdevices-inactive.png") );
  }else{
    if(mounted.length()==0){
      trayIcon->setIcon( QIcon(":icons/CDdevices.png") );
    }else{
      trayIcon->setIcon( QIcon(":icons/CDdevices.png") );
    }
  } 
}