Changeset 891636a


Ignore:
Timestamp:
04/18/13 07:56:14 (16 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.

Location:
src-qt4/pc-mounttray
Files:
10 edited

Legend:

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

    r7639577 r891636a  
    6161  QHBoxLayout *hb = new QHBoxLayout(); 
    6262  hb->addStretch(); 
    63   QPushButton *closeButton = new QPushButton("Close"); 
     63  QPushButton *closeButton = new QPushButton(QIcon(":icons/application-exit.png"),tr("Close")); 
    6464  hb->addWidget(closeButton); 
    6565  hb->addStretch(); 
  • src-qt4/pc-mounttray/fsDialog.h

    rbe298e4 r891636a  
    1212#include <QBrush> 
    1313#include <QColor> 
     14#include <QIcon> 
    1415 
    1516#include "fsWatcher.h" 
  • src-qt4/pc-mounttray/fsWatcher.cpp

    rbb6089a r891636a  
    44  //setup the timer 
    55  timer = new QTimer(); 
     6  timer->setSingleShot(TRUE); 
    67  QObject::connect(timer, SIGNAL(timeout()), this, SLOT(checkFS())); 
    78} 
     
    1112 
    1213void FSWatcher::start(int ms){  
    13     timer->start(ms);  
     14    timer->stop(); 
     15    timer->setInterval(ms); //max time between system checks 
     16    timer->start();  
    1417    QTimer::singleShot(2000,this,SLOT(checkFS()) ); //make sure to perform a check when it starts up 
    1518} 
     
    100103} 
    101104 
    102 //====== Private Slot ======= 
     105//====== Public Slot ======= 
    103106void FSWatcher::checkFS(){ 
    104107  QStringList devList = getFSmountpoints(); 
     
    117120    emit FSWarning(title,message); 
    118121  } 
     122  timer->start(); //reset the timer again 
    119123} 
    120124 
     125//===== Calculate Percentages ===== 
    121126int FSWatcher::calculatePercentage(int used, int total){ 
    122127  double U = used; 
  • src-qt4/pc-mounttray/fsWatcher.h

    rbb6089a r891636a  
    1010#include <QCoreApplication> 
    1111#include <QDebug> 
     12 
    1213 
    1314class FSWatcher : public QObject 
     
    3132  static int calculatePercentage(int,int); 
    3233   
    33 private slots: 
     34public slots: 
    3435  void checkFS(); //function in a timer loop 
    3536 
  • 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} 
  • src-qt4/pc-mounttray/mountTray.h

    rd386893 r891636a  
    1111#include <QList> 
    1212#include <QTimer> 
     13#include <QDir> 
     14#include <QFile> 
     15#include <QTextStream> 
    1316 
    1417#include "menuItem.h" 
     
    1619#include "fsWatcher.h" 
    1720#include "fsDialog.h" 
     21#include "settingsDialog.h" 
    1822 
    1923extern bool DEBUG_MODE; 
     
    6266  FSWatcher *diskWatcher; 
    6367  FSDialog *diskDisplay; 
     68  //Saved Settings 
     69  bool useDiskWatcher, useDiskTimerDevd; 
     70  int diskTimerMaxMS; //milliseconds 
    6471 
    6572 
     
    7178  void getInitialUsername(); 
    7279  void getDefaultFileManager(); 
     80  void loadSavedSettings(); 
     81  void saveCurrentSettings(); 
    7382   
    7483}; 
  • src-qt4/pc-mounttray/pc-mounttray.pro

    rbb6089a r891636a  
    1111        devCheck.h \ 
    1212        fsWatcher.h \ 
    13         fsDialog.h 
     13        fsDialog.h \ 
     14        settingsDialog.h 
    1415 
    1516SOURCES += main.cpp \ 
     
    1819        devCheck.cpp \ 
    1920        fsWatcher.cpp \ 
    20         fsDialog.cpp 
     21        fsDialog.cpp \ 
     22        settingsDialog.cpp 
    2123 
    2224RESOURCES += pc-mounttray.qrc 
  • src-qt4/pc-mounttray/pc-mounttray.qrc

    rd386893 r891636a  
    1414    <file>icons/refresh.png</file> 
    1515    <file>icons/config.png</file> 
     16    <file>icons/checkmark.png</file> 
    1617  </qresource> 
    1718</RCC> 
  • src-qt4/pc-mounttray/settingsDialog.cpp

    r92b4ba0 r891636a  
    4545  groupDiskWatch->setChecked(useDiskWatcher); 
    4646  checkDiskAutoTimer->setChecked(useDiskAutoTimer); 
    47   spinDiskRefreshMin->setValue(diskRefreshMS/60000); 
     47  int minutes = diskRefreshMS/60000; 
     48  //qDebug() << "Refresh Time:"<< QString::number(diskRefreshMS)+" ms, "+QString::number(minutes)+" min"; 
     49  spinDiskRefreshMin->setValue(minutes); 
    4850    //Apply signals/slots AFTER setting the values 
    4951    connect(groupDiskWatch, SIGNAL(clicked(bool)),this,SLOT(slotUpdateUI(bool)) ); 
  • src-qt4/pc-mounttray/settingsDialog.h

    r92b4ba0 r891636a  
    1414#include <QLabel> 
    1515#include <QIcon> 
     16#include <QDebug> 
    1617 
    1718class SettingsDialog : public QDialog{ 
Note: See TracChangeset for help on using the changeset viewer.