Ignore:
Timestamp:
04/18/13 07:56:14 (15 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.1-release, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2
Children:
aa082fc8
Parents:
92b4ba0
Message:

Get the mountTray saving/loading it's settings properly, and integrate those settings with the new Settings dlialog. You can now turn the disk space watcher off/on and set the refresh times/flags within the settings dialog.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/pc-mounttray/mountTray.cpp

    rd386893 r891636a  
    2121  getInitialUsername(); //try to detect the non-root user who is running the program with root permissions 
    2222  getDefaultFileManager(); //try to detect the default file-manager for opening the mount directory 
     23  loadSavedSettings(); 
    2324   
    2425  trayIcon = new QSystemTrayIcon(this); 
     
    3334    //Add the setting dialog option seperately 
    3435    sysMenu->addSeparator(); 
    35     sysMenu->addAction( QIcon(":icons/config.png"), tr("Settings"), this, SLOT(slotOpenSettings()) ); 
     36    sysMenu->addAction( QIcon(":icons/config.png"), tr("Change Settings"), this, SLOT(slotOpenSettings()) ); 
    3637    //Add the Close button seperately 
    3738    sysMenu->addSeparator(); 
     
    5758   
    5859  //Start up the filesystem watcher 
    59   qDebug() << "-Starting up the disk space alert system"; 
    6060  diskWatcher = new FSWatcher(); 
    6161  connect(diskWatcher,SIGNAL(FSWarning(QString,QString)),this,SLOT(slotDisplayWarning(QString,QString))); 
    62   diskWatcher->start(3600000); // check every 1 hour in milliseconds 
     62  if(useDiskWatcher){  
     63    qDebug() << "-Starting up the disk space alert system"; 
     64    diskWatcher->start(diskTimerMaxMS);  
     65  } 
    6366   
    6467  //Update the tray menu and icons 
     
    173176 
    174177void MountTray::newDevdMessage(){        
    175   devdTimer->start(1000); //wait 1.5 seconds before checking for device changes 
     178  devdTimer->start(1500); //wait 1.5 seconds before checking for device changes 
    176179  return; 
    177180} 
     
    251254    } 
    252255  } //end loop over cd/dvd devices 
     256   
     257  //Run the disk space check if appropriate 
     258  if(useDiskWatcher && useDiskTimerDevd && showPopup){ diskWatcher->checkFS(); } 
    253259} 
    254260 
     
    340346    deviceList[i]->updateItem(); 
    341347  } 
     348  //Run the disk check if appropriate 
     349  if(useDiskWatcher){ diskWatcher->checkFS(); } 
    342350} 
    343351 
     
    349357 
    350358void MountTray::slotOpenSettings(){ 
     359  //Stop the refresh timer on the watcher 
     360  diskWatcher->stop(); 
    351361  //Open up the settings window and apply changes as necessary 
    352   qDebug() << "Settings window not implemented yet"; 
     362  SettingsDialog *sdlg = new SettingsDialog(); 
     363  sdlg->useDiskWatcher = useDiskWatcher; 
     364  sdlg->useDiskAutoTimer = useDiskTimerDevd; 
     365  sdlg->diskRefreshMS = diskTimerMaxMS; 
     366  sdlg->showDialog(); 
     367  //Now parse the output and save if necessary 
     368  if(sdlg->SettingsChanged){ 
     369    useDiskWatcher = sdlg->useDiskWatcher; 
     370    useDiskTimerDevd = sdlg->useDiskAutoTimer; 
     371    diskTimerMaxMS = sdlg->diskRefreshMS; 
     372    qDebug() << "INFO: Saving updated settings to file"; 
     373    saveCurrentSettings(); //update the saved settings 
     374  } 
     375  //Now restart the disk watcher if enabled 
     376  if(useDiskWatcher){ diskWatcher->start(diskTimerMaxMS); } 
    353377} 
    354378 
     
    373397  trayIcon->showMessage(title, msg , QSystemTrayIcon::Warning,5000 ); 
    374398} 
     399 
     400void MountTray::loadSavedSettings(){ 
     401  //The saved settings file 
     402  QString filename = QDir::homePath()+"/.mounttray.settings"; 
     403  //Set the defaults 
     404  useDiskWatcher=TRUE; useDiskTimerDevd=TRUE; 
     405  diskTimerMaxMS=3600000; //1 hour refresh timer 
     406  //Now load the file 
     407  QFile file(filename); 
     408  if(file.exists()){ 
     409    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){  
     410      qDebug() << "-Could not open settings file: using defaults"; 
     411      return;  
     412    } 
     413    QTextStream in(&file); 
     414    while(!in.atEnd()){ 
     415      QString line = in.readLine(); 
     416      if(!line.startsWith("#")){ //skip comment lines 
     417        QString var = line.section(")",0,0,QString::SectionSkipEmpty).simplified(); 
     418        QString val = line.section(")",1,30,QString::SectionSkipEmpty).simplified(); 
     419        if(var=="UseDiskSpaceMonitoring"){  
     420          if(val.toLower() == "true"){ useDiskWatcher = TRUE;} 
     421          else{ useDiskWatcher = FALSE; } 
     422        }else if(var=="UseDiskSpaceDevdTiming"){ 
     423          if(val.toLower() == "true"){ useDiskTimerDevd = TRUE;} 
     424          else{ useDiskTimerDevd = FALSE; }      
     425        }else if(var=="DiskSpaceTimingMaxMilliseconds"){ 
     426          diskTimerMaxMS = val.toInt();  
     427        } 
     428      } 
     429    } 
     430    file.close(); 
     431  }else{ 
     432    qDebug() << "-Creating new settings file with defaults"; 
     433    saveCurrentSettings(); 
     434  } 
     435} 
     436 
     437void MountTray::saveCurrentSettings(){ 
     438  //The saved settings file 
     439  QString filename = QDir::homePath()+"/.mounttray.settings"; 
     440  //Now write the current values to the file 
     441  QFile file(filename); 
     442  if(!file.open(QIODevice::WriteOnly | QIODevice::Text)){ 
     443    qDebug() << "ERROR: Could not open file to save settings:"<<filename; 
     444    return; 
     445  } 
     446  QTextStream out(&file); 
     447  out << "#pc-mounttray saved settings file\n"; 
     448  out << "# DO NOT EDIT: Use the settings dialog in the application instead!!\n"; 
     449  //Save the settings 
     450  out << "UseDiskSpaceMonitoring)"; 
     451  if(useDiskWatcher){ out << "true\n";} 
     452  else{ out << "false\n"; } 
     453  out << "UseDiskSpaceDevdTiming)"; 
     454  if(useDiskTimerDevd){ out << "true\n";} 
     455  else{ out << "false\n"; } 
     456  out << "DiskSpaceTimingMaxMilliseconds)"+QString::number(diskTimerMaxMS)+"\n"; 
     457  //Now close the file 
     458  file.close(); 
     459} 
Note: See TracChangeset for help on using the changeset viewer.