]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/mainwin.cpp
Remove jobq.c constraint that read and write SD must be
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
index 566c702653c198767e5d24f442632ae8daf20ae6..a03e22102598e6afffd38d5ecc7db045ca44eedc 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2008 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.
@@ -20,7 +20,7 @@
    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.
@@ -36,6 +36,7 @@
  */ 
 
 #include "bat.h"
+#include "version.h"
 #include "joblist/joblist.h"
 #include "storage/storage.h"
 #include "fileset/fileset.h"
 #include "restore/restoretree.h"
 #include "help/help.h"
 #include "jobs/jobs.h"
+#ifdef HAVE_QWT
 #include "jobgraphs/jobplot.h"
+#endif
+#include "status/dirstat.h"
+#include "util/fmtwidgetitem.h"
 
 /* 
  * Daemon message callback
@@ -69,7 +74,7 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
    readPreferences();
    treeWidget->clear();
    treeWidget->setColumnCount(1);
-   treeWidget->setHeaderLabel("Select Page");
+   treeWidget->setHeaderLabel( tr("Select Page") );
    treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
 
    createPages();
@@ -78,6 +83,11 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
 
    createConnections();
 
+#ifndef HAVE_QWT
+   actionJobPlot->setEnabled(false);
+   actionJobPlot->setVisible(false);
+#endif
+
    this->show();
 
    readSettings();
@@ -90,7 +100,7 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
    if (m_miscDebug) {
       QString directoryResourceName;
       m_currentConsole->getDirResName(directoryResourceName);
-      Pmsg1(000, "Setting initial window to %s\n", directoryResourceName.toUtf8().data());
+      Pmsg1(100, "Setting initial window to %s\n", directoryResourceName.toUtf8().data());
    }
 }
 
@@ -120,9 +130,9 @@ void MainWin::createPages()
 
       /* Create Tree Widget Item */
       item = new QTreeWidgetItem(topItem);
-      item->setText(0, "Console");
+      item->setText(0, tr("Console"));
       if (!m_firstItem){ m_firstItem = item; }
-      item->setIcon(0,QIcon(QString::fromUtf8(":images/utilities-terminal.svg")));
+      item->setIcon(0,QIcon(QString::fromUtf8(":images/utilities-terminal.png")));
 
       /* insert the cosole and tree widget item into the hashes */
       hashInsert(item, m_currentConsole);
@@ -143,12 +153,18 @@ void MainWin::createPages()
       new FileSet();
       new Jobs();
       createPageJobList("", "", "", "", NULL);
-      new MediaList();
-      new Storage();
-      new restoreTree();
+#ifdef HAVE_QWT
       JobPlotPass pass;
       pass.use = false;
-      new JobPlot(NULL, pass);
+      if (m_openPlot)
+         new JobPlot(NULL, pass);
+#endif
+      new MediaList();
+      new Storage();
+      if (m_openBrowser)
+         new restoreTree();
+      if (m_openDirStat)
+         new DirStat();
 
       treeWidget->expandItem(topItem);
       stackedWidget->setCurrentWidget(m_currentConsole);
@@ -232,7 +248,10 @@ void MainWin::createConnections()
    connect(actionRun, SIGNAL(triggered()), this,  SLOT(runButtonClicked()));
    connect(actionEstimate, SIGNAL(triggered()), this,  SLOT(estimateButtonClicked()));
    connect(actionBrowse, SIGNAL(triggered()), this,  SLOT(browseButtonClicked()));
+   connect(actionStatusDirPage, SIGNAL(triggered()), this,  SLOT(statusPageButtonClicked()));
+#ifdef HAVE_QWT
    connect(actionJobPlot, SIGNAL(triggered()), this,  SLOT(jobPlotButtonClicked()));
+#endif
    connect(actionRestore, SIGNAL(triggered()), this,  SLOT(restoreButtonClicked()));
    connect(actionUndock, SIGNAL(triggered()), this,  SLOT(undockWindowButton()));
    connect(actionToggleDock, SIGNAL(triggered()), this,  SLOT(toggleDockContextWindow()));
@@ -248,13 +267,17 @@ void MainWin::closeEvent(QCloseEvent *event)
    m_isClosing = true;
    writeSettings();
    /* close all non console pages, this will call settings in destructors */
-   foreach(Pages *page, m_pagehash) {
-      if (page !=  page->console()) {
-         page->console()->setCurrent();
-         page->closeStackPage();
+   while (m_consoleHash.count() < m_pagehash.count()) {
+      foreach(Pages *page, m_pagehash) {
+         if (page !=  page->console()) {
+            QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(page);
+            if (pageSelectorTreeWidgetItem->childCount() == 0) {
+               page->console()->setCurrent();
+               page->closeStackPage();
+            }
+         }
       }
    }
-   /* close the console pages and terminate connection */
    foreach(Console *console, m_consoleHash){
       console->writeSettings();
       console->terminate();
@@ -424,6 +447,22 @@ void MainWin::browseButtonClicked()
    new restoreTree();
 }
 
+void MainWin::statusPageButtonClicked()
+{
+   /* if one exists, then just set it current */
+   bool found = false;
+   foreach(Pages *page, m_pagehash) {
+      if (m_currentConsole == page->console()) {
+         if (page->name() == tr("Director Status")) {
+            found = true;
+            page->setCurrent();
+         }
+      }
+   }
+   if (!found)
+      new DirStat();
+}
+
 void MainWin::restoreButtonClicked() 
 {
    new prerestorePage();
@@ -431,9 +470,11 @@ void MainWin::restoreButtonClicked()
 
 void MainWin::jobPlotButtonClicked()
 {
+#ifdef HAVE_QWT
    JobPlotPass pass;
    pass.use = false;
    new JobPlot(NULL, pass);
+#endif
 }
 
 /*
@@ -447,7 +488,7 @@ void MainWin::input_line()
       /* Use consoleInput to allow typing anything */
       m_currentConsole->consoleInput(cmdStr);
    } else {
-      set_status("Director not connected. Click on connect button.");
+      set_status(tr("Director not connected. Click on connect button."));
    }
    m_cmd_history.append(cmdStr);
    m_cmd_last = -1;
@@ -459,10 +500,10 @@ void MainWin::input_line()
 void MainWin::about()
 {
    QMessageBox::about(this, tr("About bat"),
-      tr("<br><h2>bat 1.0, by Dirk H Bartley and Kern Sibbald</h2>"
-         "<p>Copyright &copy; " BYEAR " Free Software Foundation Europe e.V."
+      tr("<br><h2>bat %1 (%2), by Dirk H Bartley and Kern Sibbald</h2>"
+         "<p>Copyright &copy; 2007-%3 Free Software Foundation Europe e.V."
          "<p>The <b>bat</b> is an administrative console"
-         " interface to the Director."));
+         " interface to the Director.").arg(VERSION).arg(BDATE).arg(BYEAR));
 }
 
 void MainWin::help()
@@ -483,7 +524,12 @@ void MainWin::set_statusf(const char *fmt, ...)
 
 void MainWin::set_status_ready()
 {
-   set_status(" Ready");
+   set_status(tr(" Ready"));
+}
+
+void MainWin::set_status(const QString &str)
+{
+   statusBar()->showMessage(str);
 }
 
 void MainWin::set_status(const char *buf)
@@ -614,6 +660,8 @@ void MainWin::setPreferences()
    prefs.daysSpinBox->setValue(m_daysLimitVal);
    prefs.checkMessages->setCheckState(m_checkMessages ? Qt::Checked : Qt::Unchecked);
    prefs.checkMessagesSpin->setValue(m_checkMessagesInterval);
+   prefs.refreshStatusDir->setCheckState(m_refreshStatusDir ? Qt::Checked : Qt::Unchecked);
+   prefs.refreshStatusDirSpin->setValue(m_refreshStatusDirInterval);
    prefs.executeLongCheckBox->setCheckState(m_longList ? Qt::Checked : Qt::Unchecked);
    prefs.rtPopDirCheckBox->setCheckState(m_rtPopDirDebug ? Qt::Checked : Qt::Unchecked);
    prefs.rtDirCurICCheckBox->setCheckState(m_rtDirCurICDebug ? Qt::Checked : Qt::Unchecked);
@@ -627,6 +675,23 @@ void MainWin::setPreferences()
    prefs.rtRestore1CheckBox->setCheckState(m_rtRestore1Debug ? Qt::Checked : Qt::Unchecked);
    prefs.rtRestore2CheckBox->setCheckState(m_rtRestore2Debug ? Qt::Checked : Qt::Unchecked);
    prefs.rtRestore3CheckBox->setCheckState(m_rtRestore3Debug ? Qt::Checked : Qt::Unchecked);
+   switch (ItemFormatterBase::getBytesConversion()) {
+   case ItemFormatterBase::BYTES_CONVERSION_NONE:
+      prefs.radioConvertOff->setChecked(Qt::Checked);
+      break;
+   case ItemFormatterBase::BYTES_CONVERSION_IEC:
+      prefs.radioConvertIEC->setChecked(Qt::Checked);
+      break;
+   default:
+      prefs.radioConvertStandard->setChecked(Qt::Checked);
+      break;
+   }
+   prefs.openPlotCheckBox->setCheckState(m_openPlot ? Qt::Checked : Qt::Unchecked);
+#ifndef HAVE_QWT
+   prefs.openPlotCheckBox->setVisible(false);
+#endif
+   prefs.openBrowserCheckBox->setCheckState(m_openBrowser ? Qt::Checked : Qt::Unchecked);
+   prefs.openDirStatCheckBox->setCheckState(m_openDirStat ? Qt::Checked : Qt::Unchecked);
    prefs.exec();
 }
 
@@ -650,6 +715,8 @@ void prefsDialog::accept()
    mainWin->m_daysLimitVal = this->daysSpinBox->value();
    mainWin->m_checkMessages = this->checkMessages->checkState() == Qt::Checked;
    mainWin->m_checkMessagesInterval = this->checkMessagesSpin->value();
+   mainWin->m_refreshStatusDir = this->refreshStatusDir->checkState() == Qt::Checked;
+   mainWin->m_refreshStatusDirInterval = this->refreshStatusDirSpin->value();
    mainWin->m_longList = this->executeLongCheckBox->checkState() == Qt::Checked;
 
    mainWin->m_rtPopDirDebug = this->rtPopDirCheckBox->checkState() == Qt::Checked;
@@ -664,6 +731,16 @@ void prefsDialog::accept()
    mainWin->m_rtRestore1Debug = this->rtRestore1CheckBox->checkState() == Qt::Checked;
    mainWin->m_rtRestore2Debug = this->rtRestore2CheckBox->checkState() == Qt::Checked;
    mainWin->m_rtRestore3Debug = this->rtRestore3CheckBox->checkState() == Qt::Checked;
+   if (this->radioConvertOff->isChecked()) {
+      ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_NONE);
+   } else if (this->radioConvertIEC->isChecked()){
+      ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_IEC);
+   } else {
+      ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_SI);
+   }
+   mainWin->m_openPlot = this->openPlotCheckBox->checkState() == Qt::Checked;
+   mainWin->m_openBrowser = this->openBrowserCheckBox->checkState() == Qt::Checked;
+   mainWin->m_openDirStat = this->openDirStatCheckBox->checkState() == Qt::Checked;
 
    QSettings settings("www.bacula.org", "bat");
    settings.beginGroup("Debug");
@@ -679,12 +756,18 @@ void prefsDialog::accept()
    settings.setValue("daysLimitCheck", mainWin->m_daysLimitCheck);
    settings.setValue("daysLimitVal", mainWin->m_daysLimitVal);
    settings.endGroup();
-   settings.beginGroup("Messages");
+   settings.beginGroup("Timers");
    settings.setValue("checkMessages", mainWin->m_checkMessages);
    settings.setValue("checkMessagesInterval", mainWin->m_checkMessagesInterval);
+   settings.setValue("refreshStatusDir", mainWin->m_refreshStatusDir);
+   settings.setValue("refreshStatusDirInterval", mainWin->m_refreshStatusDirInterval);
    settings.endGroup();
    settings.beginGroup("Misc");
    settings.setValue("longList", mainWin->m_longList);
+   settings.setValue("byteConvert", ItemFormatterBase::getBytesConversion());
+   settings.setValue("openplot", mainWin->m_openPlot);
+   settings.setValue("openbrowser", mainWin->m_openBrowser);
+   settings.setValue("opendirstat", mainWin->m_openDirStat);
    settings.endGroup();
    settings.beginGroup("RestoreTree");
    settings.setValue("rtPopDirDebug", mainWin->m_rtPopDirDebug);
@@ -708,7 +791,7 @@ void prefsDialog::accept()
 void prefsDialog::reject()
 {
    this->hide();
-   mainWin->set_status("Canceled");
+   mainWin->set_status(tr("Canceled"));
 }
 
 /* read preferences for the prefences dialog box */
@@ -728,12 +811,20 @@ void MainWin::readPreferences()
    m_daysLimitCheck = settings.value("daysLimitCheck", false).toBool();
    m_daysLimitVal = settings.value("daysLimitVal", 28).toInt();
    settings.endGroup();
-   settings.beginGroup("Messages");
+   settings.beginGroup("Timers");
    m_checkMessages = settings.value("checkMessages", false).toBool();
    m_checkMessagesInterval = settings.value("checkMessagesInterval", 28).toInt();
+   m_refreshStatusDir = settings.value("refreshStatusDir", false).toBool();
+   m_refreshStatusDirInterval = settings.value("refreshStatusDirInterval", 28).toInt();
    settings.endGroup();
    settings.beginGroup("Misc");
    m_longList = settings.value("longList", false).toBool();
+   ItemFormatterBase::setBytesConversion(
+         (ItemFormatterBase::BYTES_CONVERSION) settings.value("byteConvert", 
+         ItemFormatterBase::BYTES_CONVERSION_IEC).toInt());
+   m_openPlot = settings.value("openplot", false).toBool();
+   m_openBrowser = settings.value("openbrowser", false).toBool();
+   m_openDirStat = settings.value("opendirstat", false).toBool();
    settings.endGroup();
    settings.beginGroup("RestoreTree");
    m_rtPopDirDebug = settings.value("rtPopDirDebug", false).toBool();