]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/mainwin.cpp
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
index 67d1a07a1b003ad4fd6a615dbb8e57a0e5ab7063..27d477d9b1091ac709608a09136fd36de2a3e87e 100644 (file)
@@ -1,33 +1,23 @@
 /*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2007-2009 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
-   License as published by the Free Software Foundation and included
-   in the file LICENSE.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   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
-   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 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.
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2016 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
 
 /*
- *   Version $Id$
  *
  *  Main Window control for bat (qt-console)
  *
@@ -81,7 +71,7 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
    treeWidget->setColumnCount(1);
    treeWidget->setHeaderLabel( tr("Select Page") );
    treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
-   // tabWidget->setTabsClosable(true);  /* wait for QT 4.5 */
+   tabWidget->setTabsClosable(true);  /* wait for QT 4.5 */
    createPages();
 
    resetFocus(); /* lineEdit->setFocus() */
@@ -95,25 +85,37 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
 
    readSettings();
 
-   foreach(Console *console, m_consoleHash)
+   foreach(Console *console, m_consoleHash) {
       console->connect_dir();
+   }
+   /* 
+    * Note, the notifier is now a global flag, although each notifier
+    *  can be individually turned on and off at a socket level.  Once
+    *  the notifier is turned off, we don't accept anything from anyone
+    *  this prevents unwanted messages from getting into the input
+    *  dialogs such as restore that read from the director and "know"
+    *  what to expect.
+    */
+   m_notify = true;
    m_currentConsole = (Console*)getFromHash(m_firstItem);
-   QTimer::singleShot(750, this, SLOT(popLists()));
+   QTimer::singleShot(2000, this, SLOT(popLists()));
    if (m_miscDebug) {
       QString directoryResourceName;
       m_currentConsole->getDirResName(directoryResourceName);
       Pmsg1(100, "Setting initial window to %s\n", directoryResourceName.toUtf8().data());
    }
+   app->restoreOverrideCursor();
 }
 
 void MainWin::popLists()
 {
-   foreach(Console *console, m_consoleHash)
+   foreach(Console *console, m_consoleHash) {
       console->populateLists(true);
-   app->restoreOverrideCursor();
+   }
    m_doConnect = true;
    connectConsoleSignals();
    connectSignals();
+   app->restoreOverrideCursor();
    m_currentConsole->setCurrent();
 }
 
@@ -149,19 +151,19 @@ void MainWin::createPages()
 
       /* insert the cosole and tree widget item into the hashes */
       hashInsert(item, m_currentConsole);
+      m_currentConsole->dockPage();
 
       /* Set Color of treeWidgetItem for the console
       * It will be set to green in the console class if the connection is made.
       */
       QBrush redBrush(Qt::red);
       item->setForeground(0, redBrush);
-      m_currentConsole->dockPage();
 
       /*
        * Create instances in alphabetic order of the rest 
        *  of the classes that will by default exist under each Director.  
        */
-//      new bRestore();
+      new bRestore();
       new Clients();
       new FileSet();
       new Jobs();
@@ -175,11 +177,12 @@ void MainWin::createPages()
       new MediaList();
       new MediaView();
       new Storage();
-      if (m_openBrowser)
-         new restoreTree();
-      if (m_openDirStat)
+//    if (m_openBrowser) {
+//       new restoreTree();
+//    }
+      if (m_openDirStat) {
          new DirStat();
-
+      }
       treeWidget->expandItem(topItem);
       tabWidget->setCurrentWidget(m_currentConsole);
    }
@@ -253,6 +256,7 @@ void MainWin::connectSignals()
    connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
    connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
    connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
+   connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closePage(int)));
    connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
    connect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelButtonClicked()));
    connect(actionRun, SIGNAL(triggered()), this,  SLOT(runButtonClicked()));
@@ -265,7 +269,7 @@ void MainWin::connectSignals()
    connect(actionRestore, SIGNAL(triggered()), this,  SLOT(restoreButtonClicked()));
    connect(actionUndock, SIGNAL(triggered()), this,  SLOT(undockWindowButton()));
    connect(actionToggleDock, SIGNAL(triggered()), this,  SLOT(toggleDockContextWindow()));
-   connect(actionClosePage, SIGNAL(triggered()), this,  SLOT(closePage()));
+   connect(actionClosePage, SIGNAL(triggered()), this,  SLOT(closeCurrentPage()));
    connect(actionPreferences, SIGNAL(triggered()), this,  SLOT(setPreferences()));
    connect(actionRepopLists, SIGNAL(triggered()), this,  SLOT(repopLists()));
    connect(actionReloadRepop, SIGNAL(triggered()), this,  SLOT(reloadRepopLists()));
@@ -280,6 +284,7 @@ void MainWin::disconnectSignals()
    disconnect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
    disconnect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
    disconnect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
+   disconnect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closePage(int)));
    disconnect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
    disconnect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelButtonClicked()));
    disconnect(actionRun, SIGNAL(triggered()), this,  SLOT(runButtonClicked()));
@@ -292,7 +297,7 @@ void MainWin::disconnectSignals()
    disconnect(actionRestore, SIGNAL(triggered()), this,  SLOT(restoreButtonClicked()));
    disconnect(actionUndock, SIGNAL(triggered()), this,  SLOT(undockWindowButton()));
    disconnect(actionToggleDock, SIGNAL(triggered()), this,  SLOT(toggleDockContextWindow()));
-   disconnect(actionClosePage, SIGNAL(triggered()), this,  SLOT(closePage()));
+   disconnect(actionClosePage, SIGNAL(triggered()), this,  SLOT(closeCurrentPage()));
    disconnect(actionPreferences, SIGNAL(triggered()), this,  SLOT(setPreferences()));
    disconnect(actionRepopLists, SIGNAL(triggered()), this,  SLOT(repopLists()));
    disconnect(actionReloadRepop, SIGNAL(triggered()), this,  SLOT(reloadRepopLists()));
@@ -303,14 +308,11 @@ void MainWin::disconnectSignals()
  */
 void MainWin::waitEnter()
 {
-   if (m_waitState){ 
-      if (mainWin->m_connDebug)
-         Pmsg0(000, "Should Never Get Here DANGER DANGER, for now I'll return\n");
+   if (m_waitState || m_isClosing) { 
       return;
    }
    m_waitState = true;
-   if (mainWin->m_connDebug)
-      Pmsg0(000, "Entering Wait State\n");
+   if (mainWin->m_connDebug) Pmsg0(000, "Entering Wait State\n");
    app->setOverrideCursor(QCursor(Qt::WaitCursor));
    disconnectSignals();
    disconnectConsoleSignals(m_currentConsole);
@@ -322,15 +324,19 @@ void MainWin::waitEnter()
  */
 void MainWin::waitExit()
 {
-   m_waitState = false;
+   if (!m_waitState || m_isClosing) {
+      return;
+   }
    if (mainWin->m_connDebug) Pmsg0(000, "Exiting Wait State\n");
-   app->restoreOverrideCursor();
-   if (m_waitTreeItem != treeWidget->currentItem())
+   if (m_waitTreeItem && (m_waitTreeItem != treeWidget->currentItem())) {
       treeWidget->setCurrentItem(m_waitTreeItem);
+   }
    if (m_doConnect) {
       connectSignals();
       connectConsoleSignals();
    }
+   app->restoreOverrideCursor();
+   m_waitState = false;
 }
 
 void MainWin::connectConsoleSignals()
@@ -427,15 +433,18 @@ void MainWin::readSettings()
 void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/)
 {
    /* Is this a page that has been inserted into the hash  */
-   if (getFromHash(item)) {
-      Pages* page = getFromHash(item);
-      int stackindex=tabWidget->indexOf(page);
+   Pages* page = getFromHash(item);
+   if (page) {
+      int stackindex = tabWidget->indexOf(page);
 
       if (stackindex >= 0) {
          tabWidget->setCurrentWidget(page);
       }
+      page->dockPage();
       /* run the virtual function in case this class overrides it */
       page->PgSeltreeWidgetClicked();
+   } else {
+      Dmsg0(000, "Page not in hash");
    }
 }
 
@@ -514,6 +523,7 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre
       }
       /* set the value for the currently active console */
       int stackindex = tabWidget->indexOf(nextPage);
+      nextPage->firstUseDock();
    
       /* Is this page currently on the stack or is it undocked */
       if (stackindex >= 0) {
@@ -554,7 +564,7 @@ void MainWin::estimateButtonClicked()
 
 void MainWin::browseButtonClicked() 
 {
-   new restoreTree();
+//   new restoreTree();
 }
 
 void MainWin::statusPageButtonClicked()
@@ -569,13 +579,15 @@ void MainWin::statusPageButtonClicked()
          }
       }
    }
-   if (!found)
+   if (!found) {
       new DirStat();
+   }
 }
 
 void MainWin::restoreButtonClicked() 
 {
    new prerestorePage();
+   if (mainWin->m_miscDebug) Pmsg0(000, "in restoreButtonClicked after prerestorePage\n");
 }
 
 void MainWin::jobPlotButtonClicked()
@@ -596,7 +608,7 @@ void MainWin::input_line()
    QString cmdStr = lineEdit->text();    /* Get the text */
    lineEdit->clear();                    /* clear the lineEdit box */
    if (m_currentConsole->is_connected()) {
-      if (m_currentConsole->currentDirComm(conn)) {
+      if (m_currentConsole->findDirComm(conn)) {
          m_currentConsole->consoleCommand(cmdStr, conn);
       } else {
          /* Use consoleCommand to allow typing anything */
@@ -615,8 +627,8 @@ void MainWin::input_line()
 void MainWin::about()
 {
    QMessageBox::about(this, tr("About bat"),
-      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."
+      tr("<br><h2>Bacula Bat %1 (%2)</h2>"
+         "<p>Copyright &copy; 2007-%3 Kern Sibbald"
          "<p>The <b>bat</b> is an administrative console"
          " interface to the Director.").arg(VERSION).arg(BDATE).arg(BYEAR));
 }
@@ -630,9 +642,8 @@ void MainWin::set_statusf(const char *fmt, ...)
 {
    va_list arg_ptr;
    char buf[1000];
-   int len;
    va_start(arg_ptr, fmt);
-   len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
+   bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
    va_end(arg_ptr);
    set_status(buf);
 }
@@ -658,7 +669,9 @@ void MainWin::set_status(const char *buf)
 void MainWin::undockWindowButton()
 {
    Pages* page = (Pages*)tabWidget->currentWidget();
-   page->togglePageDocking();
+   if (page) {
+      page->togglePageDocking();
+   }
 }
 
 /*
@@ -673,7 +686,9 @@ void MainWin::toggleDockContextWindow()
    /* Is this a page that has been inserted into the hash  */
    if (getFromHash(currentitem)) {
       Pages* page = getFromHash(currentitem);
-      page->togglePageDocking();
+      if (page) {
+         page->togglePageDocking();
+      }
    }
 }
 
@@ -687,7 +702,9 @@ void MainWin::stackItemChanged(int)
    if (m_isClosing) return; /* if closing the application, do nothing here */
    Pages* page = (Pages*)tabWidget->currentWidget();
    /* run the virtual function in case this class overrides it */
-   page->currentStackItem();
+   if (page) {
+      page->currentStackItem();
+   }
    if (!m_waitState) {
       disconnect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
       disconnect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
@@ -739,19 +756,35 @@ QTreeWidgetItem* MainWin::getFromHash(Pages *page)
    return m_widgethash.value(page);
 }
 
+void MainWin::closeCurrentPage()
+{
+   closePage(-1);
+}
+
 /*
  * Function to respond to action on page selector context menu to close the
  * current window.
  */
-void MainWin::closePage()
+void MainWin::closePage(int item)
 {
-   QTreeWidgetItem *currentitem = treeWidget->currentItem();
+   QTreeWidgetItem *currentitem;
+   Pages *page = NULL;
+
+   if (item >= 0) {
+     page = (Pages *)tabWidget->widget(item);
+   } else {
+      currentitem = treeWidget->currentItem();
+      /* Is this a page that has been inserted into the hash  */
+      if (getFromHash(currentitem)) {
+         page = getFromHash(currentitem);
+      }
+   }   
    
-   /* Is this a page that has been inserted into the hash  */
-   if (getFromHash(currentitem)) {
-      Pages* page = getFromHash(currentitem);
+   if (page) {
       if (page->isCloseable()) {
          page->closeStackPage();
+      } else {
+         page->hidePage();
       }
    }
 }
@@ -818,7 +851,7 @@ void MainWin::setPreferences()
 }
 
 /* Preferences dialog */
-prefsDialog::prefsDialog()
+prefsDialog::prefsDialog() : QDialog()
 {
    setupUi(this);
 }
@@ -925,7 +958,7 @@ void MainWin::readPreferences()
    settings.endGroup();
    settings.beginGroup("JobList");
    m_recordLimitCheck = settings.value("recordLimitCheck", true).toBool();
-   m_recordLimitVal = settings.value("recordLimitVal", 150).toInt();
+   m_recordLimitVal = settings.value("recordLimitVal", 50).toInt();
    m_daysLimitCheck = settings.value("daysLimitCheck", false).toBool();
    m_daysLimitVal = settings.value("daysLimitVal", 28).toInt();
    settings.endGroup();