[PC-BSD Commits] r4926 - pcbsd/trunk/lifePreserver

svn at pcbsd.org svn at pcbsd.org
Mon Nov 9 10:44:16 PST 2009


Author: kris
Date: 2009-11-09 10:44:16 -0800 (Mon, 09 Nov 2009)
New Revision: 4926

Modified:
   pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
   pcbsd/trunk/lifePreserver/lifePreserverMain.h
   pcbsd/trunk/lifePreserver/preserver.cpp
   pcbsd/trunk/lifePreserver/preserver.h
Log:

Updated lifePreserver to read crontab scheduled frequency and display it on the GUI



Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-11-09 17:53:05 UTC (rev 4925)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-11-09 18:44:16 UTC (rev 4926)
@@ -54,6 +54,7 @@
    connect(pushNewPreserver, SIGNAL( clicked() ), this, SLOT(slotPushNewPreserverClicked() ) );
    connect(pushRemovePreserver, SIGNAL( clicked() ), this, SLOT(slotPushRemovePreserverClicked() ) );
    connect(pushEditPreserver, SIGNAL( clicked() ), this, SLOT(slotPushEditPreserverClicked() ) );
+   connect(pushPreserverStart, SIGNAL( clicked() ), this, SLOT(slotPushPreserverStartClicked() ) );
    treePreservers->resizeColumnToContents(0);
 }
 
@@ -64,10 +65,34 @@
    pushEditPreserver->setEnabled(true);
    pushRemovePreserver->setEnabled(true);
    pushPreserverStart->setEnabled(true);
+
+   PRESERVER myPreserver(host);
+   int pid = myPreserver.getPID();
+   if ( pid == -1 )
+     pushPreserverStart->setText(tr("Start"));
+   else
+     pushPreserverStart->setText(tr("Stop"));
   
 }
 
 // Slot to remove a preserver host
+void lifePreserver::slotPushPreserverStartClicked()
+{
+   if (treePreservers->currentColumn() == -1)
+   {
+      return;
+   }
+
+   QString host = treePreservers->currentItem()->text(0);
+   PRESERVER myPreserver(host);
+   int pid = myPreserver.getPID();
+   if ( pid == -1 )
+     myPreserver.startBackup();
+   else
+     myPreserver.stopBackup();
+}
+
+// Slot to remove a preserver host
 void lifePreserver::slotPushRemovePreserverClicked()
 {
    if (treePreservers->currentColumn() == -1)

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.h
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-11-09 17:53:05 UTC (rev 4925)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-11-09 18:44:16 UTC (rev 4926)
@@ -34,6 +34,7 @@
    void slotPushNewPreserverClicked();
    void slotPushRemovePreserverClicked();
    void slotPushEditPreserverClicked();
+   void slotPushPreserverStartClicked();
    void slotCurrentTreePreserverChanged(QTreeWidgetItem *curItem);
    void loadPreservers();
 

Modified: pcbsd/trunk/lifePreserver/preserver.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/preserver.cpp	2009-11-09 17:53:05 UTC (rev 4925)
+++ pcbsd/trunk/lifePreserver/preserver.cpp	2009-11-09 18:44:16 UTC (rev 4926)
@@ -101,6 +101,16 @@
 
 }
 
+// Function which starts the target backup
+void PRESERVER::startBackup()
+{
+}
+
+// Function which stops the target backup
+void PRESERVER::stopBackup()
+{
+}
+
 // Function which removes a cron entry for this backup
 void PRESERVER::removeCron()
 {
@@ -197,6 +207,61 @@
 QString PRESERVER::getFrequency()
 {
   QString schedule = "Unknown";
+  QString hour, day;
+  int tmpnum;
+  bool ok;
+  QFile cronFile( "/etc/crontab" );
+  if ( cronFile.open( QIODevice::ReadOnly ) )
+  {
+    QTextStream stream( &cronFile );
+    QString line;
+    while ( !stream.atEnd() ) {
+      line = stream.readLine(); // line of text excluding '\n'
+      // Check if we have a match for this backup
+      if ( line.indexOf(connectHost) != -1  ) {
+         // Now read the line and return details about the backup time
+         QString tmp = line.simplified();
+         hour = tmp.section(" ", 1,1);
+         day = tmp.section(" ", 4,4);
+         tmpnum = day.toInt(&ok);
+         if ( ! ok )
+         {
+           tmp = tr("Daily:") + " " + hour + ":00";
+           return tmp;
+         } else {
+           switch (tmpnum) {
+            case 0:
+              day = tr("Sunday");
+              break;
+            case 1:
+              day = tr("Monday");
+              break;
+            case 2:
+              day = tr("Tuesday");
+              break;
+            case 3:
+              day = tr("Wednesday");
+              break;
+            case 4:
+              day = tr("Thursday");
+              break;
+            case 5:
+              day = tr("Friday");
+              break;
+            case 6:
+              day = tr("Saturday");
+              break;
+            default: 
+              day = "Sunday";
+           } 
+           tmp = tr("Weekly:") + " " + day + "@" + hour + ":00";
+           return tmp;
+         }
+      }
+    }
+    cronFile.close();
+  }
+
   return schedule;
 }
 

Modified: pcbsd/trunk/lifePreserver/preserver.h
===================================================================
--- pcbsd/trunk/lifePreserver/preserver.h	2009-11-09 17:53:05 UTC (rev 4925)
+++ pcbsd/trunk/lifePreserver/preserver.h	2009-11-09 18:44:16 UTC (rev 4926)
@@ -53,6 +53,8 @@
     virtual void setCron(QString hour, QString day);
 
     virtual void remove();
+    virtual void startBackup();
+    virtual void stopBackup();
 
 private:
     void setConfValue(QString key, QVariant value);



More information about the Commits mailing list