]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/mainwin.cpp
Fix bat browser to ignore copy jobs. Fix bug #1604
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
index 1d5975d7327fbb7695ba502094983d4211e47096..c3d803c046ef8d36463f93664660dc41921da463 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.
@@ -27,7 +27,6 @@
 */
 
 /*
- *   Version $Id$
  *
  *  Main Window control for bat (qt-console)
  *
@@ -50,6 +49,7 @@
 #include "restore/restoretree.h"
 #include "help/help.h"
 #include "jobs/jobs.h"
+#include "medialist/mediaview.h"
 #ifdef HAVE_QWT
 #include "jobgraphs/jobplot.h"
 #endif
@@ -70,6 +70,7 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
    m_isClosing = false;
    m_waitState = false;
    m_doConnect = false;
+   m_treeStackTrap = false;
    m_dtformat = "yyyy-MM-dd HH:mm:ss";
    mainWin = this;
    setupUi(this);                     /* Setup UI defined by main.ui (designer) */
@@ -79,7 +80,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 */
    createPages();
 
    resetFocus(); /* lineEdit->setFocus() */
@@ -93,25 +94,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();
 }
 
@@ -125,7 +138,7 @@ void MainWin::createPages()
    foreach_res(dir, R_DIRECTOR) {
 
       /* Create console tree stacked widget item */
-      m_currentConsole = new Console(stackedWidget);
+      m_currentConsole = new Console(tabWidget);
       m_currentConsole->setDirRes(dir);
       m_currentConsole->readSettings();
 
@@ -147,13 +160,13 @@ 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 
@@ -171,14 +184,16 @@ void MainWin::createPages()
          new JobPlot(NULL, pass);
 #endif
       new MediaList();
+      new MediaView();
       new Storage();
-      if (m_openBrowser)
+      if (m_openBrowser) {
          new restoreTree();
-      if (m_openDirStat)
+      }
+      if (m_openDirStat) {
          new DirStat();
-
+      }
       treeWidget->expandItem(topItem);
-      stackedWidget->setCurrentWidget(m_currentConsole);
+      tabWidget->setCurrentWidget(m_currentConsole);
    }
    UnlockRes();
 }
@@ -248,8 +263,8 @@ void MainWin::connectSignals()
    connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
    connect(actionBat_Help, SIGNAL(triggered()), this, SLOT(help()));
    connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
-   connect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
-   connect(stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
+   connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
+   connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
    connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
    connect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelButtonClicked()));
    connect(actionRun, SIGNAL(triggered()), this,  SLOT(runButtonClicked()));
@@ -276,7 +291,7 @@ void MainWin::disconnectSignals()
    disconnect(actionBat_Help, SIGNAL(triggered()), this, SLOT(help()));
    disconnect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
    disconnect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
-   disconnect(stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
+   disconnect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
    disconnect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
    disconnect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelButtonClicked()));
    disconnect(actionRun, SIGNAL(triggered()), this,  SLOT(runButtonClicked()));
@@ -300,14 +315,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);
@@ -319,30 +331,31 @@ void MainWin::waitEnter()
  */
 void MainWin::waitExit()
 {
-   m_waitState = false;
-   if (mainWin->m_connDebug)
-      Pmsg0(000, "Exiting Wait State\n");
-   app->restoreOverrideCursor();
-   if (m_waitTreeItem != treeWidget->currentItem())
+   if (!m_waitState || m_isClosing) {
+      return;
+   }
+   if (mainWin->m_connDebug) Pmsg0(000, "Exiting Wait State\n");
+   if (m_waitTreeItem && (m_waitTreeItem != treeWidget->currentItem())) {
       treeWidget->setCurrentItem(m_waitTreeItem);
+   }
    if (m_doConnect) {
       connectSignals();
       connectConsoleSignals();
    }
+   app->restoreOverrideCursor();
+   m_waitState = false;
 }
 
 void MainWin::connectConsoleSignals()
 {
    connect(actionConnect, SIGNAL(triggered()), m_currentConsole, SLOT(connect_dir()));
    connect(actionSelectFont, SIGNAL(triggered()), m_currentConsole, SLOT(set_font()));
-   connect(actionStatusDir, SIGNAL(triggered()), m_currentConsole, SLOT(status_dir()));
    connect(actionMessages, SIGNAL(triggered()), m_currentConsole, SLOT(messages()));
 }
 
 void MainWin::disconnectConsoleSignals(Console *console)
 {
    disconnect(actionConnect, SIGNAL(triggered()), console, SLOT(connect_dir()));
-   disconnect(actionStatusDir, SIGNAL(triggered()), console, SLOT(status_dir()));
    disconnect(actionMessages, SIGNAL(triggered()), console, SLOT(messages()));
    disconnect(actionSelectFont, SIGNAL(triggered()), console, SLOT(set_font()));
 }
@@ -429,10 +442,10 @@ 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=stackedWidget->indexOf(page);
+      int stackindex=tabWidget->indexOf(page);
 
       if (stackindex >= 0) {
-         stackedWidget->setCurrentWidget(page);
+         tabWidget->setCurrentWidget(page);
       }
       /* run the virtual function in case this class overrides it */
       page->PgSeltreeWidgetClicked();
@@ -477,6 +490,9 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre
 
    /* this condition prevents a segfault.  The first time there is no previousitem*/
    if (previousitem) {
+      if (m_treeStackTrap == false) { /* keep track of previous items for going Back */
+         m_treeWidgetStack.append(previousitem);
+      }
       /* knowing the treeWidgetItem, get the page from the hash */
       previousPage = getFromHash(previousitem);
       previousConsole = m_consoleHash.value(previousitem);
@@ -510,12 +526,13 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre
          dirItem->setBackground(0, magentaBrush);
       }
       /* set the value for the currently active console */
-      int stackindex = stackedWidget->indexOf(nextPage);
+      int stackindex = tabWidget->indexOf(nextPage);
+      nextPage->firstUseDock();
    
       /* Is this page currently on the stack or is it undocked */
       if (stackindex >= 0) {
          /* put this page on the top of the stack */
-         stackedWidget->setCurrentIndex(stackindex);
+         tabWidget->setCurrentIndex(stackindex);
       } else {
          /* it is undocked, raise it to the front */
          nextPage->raise();
@@ -566,13 +583,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()
@@ -589,11 +608,16 @@ void MainWin::jobPlotButtonClicked()
  */
 void MainWin::input_line()
 {
+   int conn;
    QString cmdStr = lineEdit->text();    /* Get the text */
    lineEdit->clear();                    /* clear the lineEdit box */
    if (m_currentConsole->is_connected()) {
-      /* Use consoleCommand to allow typing anything */
-      m_currentConsole->consoleCommand(cmdStr);
+      if (m_currentConsole->findDirComm(conn)) {
+         m_currentConsole->consoleCommand(cmdStr, conn);
+      } else {
+         /* Use consoleCommand to allow typing anything */
+         m_currentConsole->consoleCommand(cmdStr);
+      }
    } else {
       set_status(tr("Director not connected. Click on connect button."));
    }
@@ -649,7 +673,7 @@ void MainWin::set_status(const char *buf)
  */
 void MainWin::undockWindowButton()
 {
-   Pages* page = (Pages*)stackedWidget->currentWidget();
+   Pages* page = (Pages*)tabWidget->currentWidget();
    page->togglePageDocking();
 }
 
@@ -677,9 +701,16 @@ void MainWin::toggleDockContextWindow()
 void MainWin::stackItemChanged(int)
 {
    if (m_isClosing) return; /* if closing the application, do nothing here */
-   Pages* page = (Pages*)stackedWidget->currentWidget();
+   Pages* page = (Pages*)tabWidget->currentWidget();
    /* run the virtual function in case this class overrides it */
    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 *)));
+      treeWidget->setCurrentItem(getFromHash(page));
+      connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
+      connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
+   }
 }
 
 /*
@@ -910,7 +941,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();
@@ -950,3 +981,30 @@ void MainWin::setMessageIcon()
    else
       actionMessages->setIcon(QIcon(QString::fromUtf8(":/images/mail-message-new.png")));
 }
+
+void MainWin::goToPreviousPage()
+{
+   m_treeStackTrap = true;
+   bool done = false;
+   while (!done) {
+      /* If stack list is emtpty, then done */
+      if (m_treeWidgetStack.isEmpty()) {
+         done = true;
+      } else {
+         QTreeWidgetItem* testItem = m_treeWidgetStack.takeLast();
+         QTreeWidgetItemIterator it(treeWidget);
+         /* lets avoid a segfault by setting an item current that no longer exists */
+         while (*it) {
+            if (*it == testItem) {
+               if (testItem != treeWidget->currentItem()) {
+                  treeWidget->setCurrentItem(testItem);
+                  done = true;
+               }
+               break;
+            }
+            ++it;
+         }
+      }
+   }
+   m_treeStackTrap = false;
+}