]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/status/dirstat.cpp
Prevent timer recursion in bat
[bacula/bacula] / bacula / src / qt-console / status / dirstat.cpp
index 540ee8b8aa03c148d8e71160136a4d5d87449de7..47c77fc8867afb320c0163b0f42b87c67480caae 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2008 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.
 
    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.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
 /*
- *   Version $Id: dirstat.cpp 5880 2007-11-09 01:20:40Z bartleyd2 $
  *
  *   Dirk Bartley, March 2007
  */
  
+#include "bat.h"
 #include <QAbstractEventDispatcher>
 #include <QTableWidgetItem>
-#include "bat.h"
 #include "dirstat.h"
 
+static bool working = false;         /* prevent timer recursion */
+
 /*
  * Constructor for the class
  */
@@ -43,19 +44,17 @@ DirStat::DirStat()
 {
    setupUi(this);
    m_name = tr("Director Status");
-   m_closeable = true;
    pgInitialize();
    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
-   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
+   thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
    m_cursor = new QTextCursor(textEdit->document());
 
-   readSettings();
-   dockPage();
    m_timer = new QTimer(this);
-   QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
-   m_timer->start(mainWin->m_refreshStatusDirInterval*1000);
+   readSettings();
+   m_timer->start(1000);
 
    createConnections();
+   setCurrent();
 }
 
 void DirStat::getFont()
@@ -86,8 +85,6 @@ DirStat::~DirStat()
  */
 void DirStat::populateAll()
 {
-   if (!m_console->preventInUseConnect())
-       return;
    populateHeader();
    populateTerminated();
    populateScheduled();
@@ -99,11 +96,18 @@ void DirStat::populateAll()
  */
 void DirStat::timerTriggered()
 {
-   bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
-   if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
-      if (m_console->is_ready())
+   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()) && isOnceDocked())) && (checkBox->checkState() == Qt::Checked)) {
          populateAll();
+      }
+      working = false;
    }
+   timerDisplay->display(value);
 }
 
 /*
@@ -112,6 +116,8 @@ void DirStat::timerTriggered()
 void DirStat::populateHeader()
 {
    QString command = QString(".status dir header");
+   if (mainWin->m_commandDebug)
+      Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
    QStringList results;
    textEdit->clear();
 
@@ -129,6 +135,8 @@ void DirStat::populateHeader()
 void DirStat::populateTerminated()
 {
    QString command = QString(".status dir terminated");
+   if (mainWin->m_commandDebug)
+      Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
    QStringList results;
    QBrush blackBrush(Qt::black);
 
@@ -161,12 +169,13 @@ void DirStat::populateTerminated()
             p_tableitem->setFlags(0);
             if (flaglist[column].contains("R"))
                p_tableitem->setTextAlignment(Qt::AlignRight);
-            if (flaglist[column].contains("C"))
+            if (flaglist[column].contains("C")) {
                if (field == "OK")
                   p_tableitem->setBackground(Qt::green);
                else
                   p_tableitem->setBackground(Qt::red);
-            terminatedTable->setItem(row, column, p_tableitem);
+            }
+            terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
             column += 1;
          }
          row += 1;
@@ -183,6 +192,8 @@ void DirStat::populateTerminated()
 void DirStat::populateScheduled()
 {
    QString command = QString(".status dir scheduled");
+   if (mainWin->m_commandDebug)
+      Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
    QStringList results;
    QBrush blackBrush(Qt::black);
 
@@ -195,6 +206,8 @@ void DirStat::populateScheduled()
 
    scheduledTable->setColumnCount(headerlist.size());
    scheduledTable->setHorizontalHeaderLabels(headerlist);
+   scheduledTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+   scheduledTable->setSelectionMode(QAbstractItemView::SingleSelection);
 
    if (m_console->dir_cmd(command, results)) {
       int row = 0;
@@ -210,7 +223,6 @@ void DirStat::populateScheduled()
             field = field.trimmed();  /* strip leading & trailing spaces */
             p_tableitem = new QTableWidgetItem(field, 1);
             p_tableitem->setForeground(blackBrush);
-            p_tableitem->setFlags(0);
             scheduledTable->setItem(row, column, p_tableitem);
             column += 1;
          }
@@ -228,6 +240,8 @@ void DirStat::populateScheduled()
 void DirStat::populateRunning()
 {
    QString command = QString(".status dir running");
+   if (mainWin->m_commandDebug)
+      Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
    QStringList results;
    QBrush blackBrush(Qt::black);
 
@@ -237,6 +251,7 @@ void DirStat::populateRunning()
 
    runningTable->setColumnCount(headerlist.size());
    runningTable->setHorizontalHeaderLabels(headerlist);
+   runningTable->setSelectionBehavior(QAbstractItemView::SelectRows);
 
    if (m_console->dir_cmd(command, results)) {
       int row = 0;
@@ -252,7 +267,6 @@ void DirStat::populateRunning()
             field = field.trimmed();  /* strip leading & trailing spaces */
             p_tableitem = new QTableWidgetItem(field, 1);
             p_tableitem->setForeground(blackBrush);
-            p_tableitem->setFlags(0);
             runningTable->setItem(row, column, p_tableitem);
             column += 1;
          }
@@ -274,6 +288,9 @@ void DirStat::PgSeltreeWidgetClicked()
       populateAll();
       m_populated=true;
    }
+   if (!isOnceDocked()) {
+      dockPage();
+   }
 }
 
 /*
@@ -283,6 +300,7 @@ void DirStat::PgSeltreeWidgetClicked()
 void DirStat::currentStackItem()
 {
    populateAll();
+   timerDisplay->display(spinBox->value());
    if (!m_populated) {
       m_populated=true;
    }
@@ -294,12 +312,10 @@ void DirStat::currentStackItem()
  */
 void DirStat::createConnections()
 {
-   connect(actionRefresh, SIGNAL(triggered()), this,
-                   SLOT(populateAll()));
-   connect(actionCancelRunning, SIGNAL(triggered()), this,
-                   SLOT(consoleCancelJob()));
-   connect(actionDisableScheduledJob, SIGNAL(triggered()), this,
-                   SLOT(consoleDisableJob()));
+   connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
+   connect(actionCancelRunning, SIGNAL(triggered()), this, SLOT(consoleCancelJob()));
+   connect(actionDisableScheduledJob, SIGNAL(triggered()), this, SLOT(consoleDisableJob()));
+   connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
 
    scheduledTable->setContextMenuPolicy(Qt::ActionsContextMenu);
    scheduledTable->addAction(actionRefresh);
@@ -319,6 +335,8 @@ void DirStat::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();
 }
 
@@ -331,8 +349,12 @@ void DirStat::readSettings()
    m_splitText = "splitterSizes_0";
    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());
 }
 
 /*
@@ -340,12 +362,24 @@ void DirStat::readSettings()
  */
 void DirStat::consoleCancelJob()
 {
-   int currentrow = runningTable->currentRow();
-   QTableWidgetItem *item = runningTable->item(currentrow, 0);
-   if (item) {
-      QString text = item->text();
+   QList<int> rowList;
+   QList<QTableWidgetItem *> sitems = runningTable->selectedItems();
+   foreach (QTableWidgetItem *sitem, sitems) {
+      int row = sitem->row();
+      if (!rowList.contains(row)) {
+         rowList.append(row);
+      }
+   }
+
+   QStringList selectedJobsList;
+   foreach(int row, rowList) {
+      QTableWidgetItem * sitem = runningTable->item(row, 0);
+      selectedJobsList.append(sitem->text());
+   }
+   foreach( QString job, selectedJobsList )
+   {
       QString cmd("cancel jobid=");
-      cmd += text;
+      cmd += job;
       consoleCommand(cmd);
    }
 }
@@ -364,4 +398,3 @@ void DirStat::consoleDisableJob()
       consoleCommand(cmd);
    }
 }
-