]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/status/clientstat.cpp
Prevent timer recursion in bat
[bacula/bacula] / bacula / src / qt-console / status / clientstat.cpp
index 87d146c8611a437c1afec656bd1504c9197f8b94..b36b22bf58842d4bfcef71001b46a95b3596eb37 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -26,7 +26,6 @@
    Switzerland, email:ftf@fsfeurope.org.
 */
 /*
- *   Version $Id: clientstat.cpp 5880 2007-11-09 01:20:40Z bartleyd2 $
  *
  *   Dirk Bartley, March 2007
  */
@@ -36,6 +35,9 @@
 #include <QTableWidgetItem>
 #include "clientstat.h"
 
+/* This probably should be on a mutex */
+static bool working = false;   /* prevent timer recursion */
+
 /*
  * Constructor for the class
  */
@@ -43,7 +45,6 @@ ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
 {
    m_client = client;
    setupUi(this);
-   m_closeable = true;
    pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
@@ -52,10 +53,9 @@ ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
    readSettings();
    dockPage();
    m_timer = new QTimer(this);
-   QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
-   m_timer->start(mainWin->m_refreshStatusDirInterval*1000);
 
    createConnections();
+   m_timer->start(1000);
    setCurrent();
 }
 
@@ -87,9 +87,8 @@ ClientStat::~ClientStat()
  */
 void ClientStat::populateAll()
 {
-   populateHeader();
    populateTerminated();
-   populateRunning();
+   populateCurrentTab(tabWidget->currentIndex());
 }
 
 /*
@@ -97,10 +96,27 @@ void ClientStat::populateAll()
  */
 void ClientStat::timerTriggered()
 {
-   bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
-   if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
-      populateAll();
+   double value = timerDisplay->value();
+   value -= 1;
+   if (value <= 0 && !working) {
+      working = true;
+      value = spinBox->value();
+      bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
+      if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
+         populateAll();
+      }
+      working = false;
    }
+   timerDisplay->display(value);
+}
+
+
+void ClientStat::populateCurrentTab(int index)
+{
+   if (index == 0)
+      populateRunning();
+   if (index == 1)
+      populateHeader();
 }
 
 /*
@@ -166,8 +182,8 @@ void ClientStat::populateTerminated()
                if (field == "OK")
                   p_tableitem->setBackground(Qt::green);
                else
-                p_tableitem->setBackground(Qt::red);
-           }
+                 p_tableitem->setBackground(Qt::red);
+            }
             terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
             column += 1;
          }
@@ -199,7 +215,7 @@ void ClientStat::populateRunning()
 }
 
 /*
- * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
+ * When the treeWidgetItem in the page selector tree is single clicked, Make sure
  * The tree has been populated.
  */
 void ClientStat::PgSeltreeWidgetClicked()
@@ -217,6 +233,8 @@ void ClientStat::PgSeltreeWidgetClicked()
 void ClientStat::currentStackItem()
 {
    populateAll();
+   timerDisplay->display(spinBox->value());
+
    if (!m_populated) {
       m_populated=true;
    }
@@ -228,8 +246,11 @@ void ClientStat::currentStackItem()
  */
 void ClientStat::createConnections()
 {
-   connect(actionRefresh, SIGNAL(triggered()), this,
-                   SLOT(populateAll()));
+   connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
+   connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
+   connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
+   terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
+   terminatedTable->addAction(actionRefresh);
 }
 
 /*
@@ -240,6 +261,13 @@ void ClientStat::writeSettings()
    QSettings settings(m_console->m_dir->name(), "bat");
    settings.beginGroup(m_groupText);
    settings.setValue(m_splitText, splitter->saveState());
+   settings.setValue("refreshInterval", spinBox->value());
+   settings.setValue("refreshCheck", checkBox->checkState());
+   settings.endGroup();
+
+   settings.beginGroup("OpenOnExit");
+   QString toWrite = "ClientStatus_" + m_client;
+   settings.setValue(toWrite, 1);
    settings.endGroup();
 }
 
@@ -252,6 +280,10 @@ void ClientStat::readSettings()
    m_splitText = "splitterSizes_1";
    QSettings settings(m_console->m_dir->name(), "bat");
    settings.beginGroup(m_groupText);
-   splitter->restoreState(settings.value(m_splitText).toByteArray());
+   if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
+   spinBox->setValue(settings.value("refreshInterval", 28).toInt());
+   checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
    settings.endGroup();
+
+   timerDisplay->display(spinBox->value());
 }