]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/mainwin.cpp
Properly save RecyclePoolId
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
index 3f5ad3979ddec98381f84b2901647ebd25a73363..81deb3f3dc14f2ea9783ff0c905b7ff13c229519 100644 (file)
@@ -7,8 +7,8 @@
    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 plus additions
-   that are listed in the file LICENSE.
+   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
 #include "medialist/medialist.h"
 #include "joblist/joblist.h"
 #include "clients/clients.h"
+#include "restore/restoretree.h"
 #include "help/help.h"
+#include "jobs/jobs.h"
+#include "jobgraphs/jobplot.h"
 
 /* 
  * Daemon message callback
@@ -58,6 +61,7 @@ void message_callback(int /* type */, char *msg)
 
 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
 {
+   m_isClosing = false;
    m_dtformat = "yyyy-MM-dd HH:mm:ss";
    mainWin = this;
    setupUi(this);                     /* Setup UI defined by main.ui (designer) */
@@ -105,7 +109,8 @@ void MainWin::createPages()
       m_currentConsole->readSettings();
 
       /* The top tree item representing the director */
-      topItem = createTopPage(dir->name());
+      topItem = new QTreeWidgetItem(treeWidget);
+      topItem->setText(0, dir->name());
       topItem->setIcon(0, QIcon(":images/server.png"));
       /* Set background to grey for ease of identification of inactive Director */
       QBrush greyBrush(Qt::lightGray);
@@ -114,7 +119,8 @@ void MainWin::createPages()
       m_consoleHash.insert(topItem, m_currentConsole);
 
       /* Create Tree Widget Item */
-      item = createPage("Console", topItem);
+      item = new QTreeWidgetItem(topItem);
+      item->setText(0, "Console");
       if (!m_firstItem){ m_firstItem = item; }
       item->setIcon(0,QIcon(QString::fromUtf8(":images/utilities-terminal.svg")));
 
@@ -132,13 +138,17 @@ void MainWin::createPages()
        * Create instances in alphabetic order of the rest 
        *  of the classes that will by default exist under each Director.  
        */
-//    createPagebRestore();
-      createPageClients();
-      createPageFileSet();
-      QString emptymedia(""), emptyclient("");
-      createPageJobList(emptymedia, emptyclient, NULL);
-      createPageMediaList();
-      createPageStorage();
+//      new bRestore();
+      new Clients();
+      new FileSet();
+      new Jobs();
+      createPageJobList("", "", "", "", NULL);
+      new MediaList();
+      new Storage();
+      new restoreTree();
+      JobPlotPass pass;
+      pass.use = false;
+      new JobPlot(NULL, pass);
 
       treeWidget->expandItem(topItem);
       stackedWidget->setCurrentWidget(m_currentConsole);
@@ -146,38 +156,19 @@ void MainWin::createPages()
    UnlockRes();
 }
 
-/*
- * create an instance of the the brestore class on the stack
- */
-void MainWin::createPagebRestore()
-{
-   bRestore* brestore = new bRestore();
-   brestore->dockPage();
-}
-
-/*
- * create an instance of the the medialist class on the stack
- */
-void MainWin::createPageMediaList()
-{
-   MediaList* medialist = new MediaList();
-   medialist->dockPage();
-}
-
 /*
  * create an instance of the the joblist class on the stack
  */
-void MainWin::createPageJobList(QString &media, QString &client,
-              QTreeWidgetItem *parentTreeWidgetItem)
+void MainWin::createPageJobList(const QString &media, const QString &client,
+              const QString &job, const QString &fileset, QTreeWidgetItem *parentTreeWidgetItem)
 {
    QTreeWidgetItem *holdItem;
 
    /* save current tree widget item in case query produces no results */
    holdItem = treeWidget->currentItem();
-   JobList* joblist = new JobList(media, client, parentTreeWidgetItem);
-   joblist->dockPage();
+   JobList* joblist = new JobList(media, client, job, fileset, parentTreeWidgetItem);
    /* If this is a query of jobs on a specific media */
-   if ((media != "") || (client != "")) {
+   if ((media != "") || (client != "") || (job != "") || (fileset != "")) {
       joblist->setCurrent();
       /* did query produce results, if not close window and set back to hold */
       if (joblist->m_resultCount == 0) {
@@ -187,49 +178,6 @@ void MainWin::createPageJobList(QString &media, QString &client,
    }
 }
 
-/*
- * create an instance of the the Clients class on the stack
- */
-void MainWin::createPageClients()
-{
-   Clients* clients = new Clients();
-   clients->dockPage();
-}
-
-/*
- * create an instance of the the storage class on the stack
- */
-void MainWin::createPageStorage()
-{
-   Storage* storage = new Storage();
-   storage->dockPage();
-}
-
-/*
- * create an instance of the the fileset class on the stack
- */
-void MainWin::createPageFileSet()
-{
-   FileSet* fileset = new FileSet();
-   fileset->dockPage();
-}
-
-/* Create a root Tree Widget */
-QTreeWidgetItem *MainWin::createTopPage(char *name)
-{
-   QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
-   item->setText(0, name);
-   return item;
-}
-
-/* Create A Tree Widget Item which will be associated with a Page in the stacked widget */
-QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent)
-{
-   QTreeWidgetItem *item = new QTreeWidgetItem(parent);
-   item->setText(0, name);
-   return item;
-}
-
 /*
  * Handle up and down arrow keys for the command line
  *  history.
@@ -283,6 +231,8 @@ void MainWin::createConnections()
    connect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelButtonClicked()));
    connect(actionRun, SIGNAL(triggered()), this,  SLOT(runButtonClicked()));
    connect(actionEstimate, SIGNAL(triggered()), this,  SLOT(estimateButtonClicked()));
+   connect(actionBrowse, SIGNAL(triggered()), this,  SLOT(browseButtonClicked()));
+   connect(actionJobPlot, SIGNAL(triggered()), this,  SLOT(jobPlotButtonClicked()));
    connect(actionRestore, SIGNAL(triggered()), this,  SLOT(restoreButtonClicked()));
    connect(actionUndock, SIGNAL(triggered()), this,  SLOT(undockWindowButton()));
    connect(actionToggleDock, SIGNAL(triggered()), this,  SLOT(toggleDockContextWindow()));
@@ -295,16 +245,22 @@ void MainWin::createConnections()
  */
 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();
+      }
+   }
+   /* close the console pages and terminate connection */
    foreach(Console *console, m_consoleHash){
       console->writeSettings();
       console->terminate();
+      console->closeStackPage();
    }
    event->accept();
-   foreach(Pages *page, m_pagehash) {
-      if (!page->isDocked())
-         page->close();
-   }
 }
 
 void MainWin::writeSettings()
@@ -353,9 +309,16 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/)
  */
 void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *previousitem)
 {
+   if (m_isClosing) return; /* if closing the application, do nothing here */
+
    Pages *previousPage, *nextPage;
    Console *previousConsole, *nextConsole;
 
+   /* remove all actions before adding actions appropriate for new page */
+   foreach(QAction* pageAction, treeWidget->actions()) {
+      treeWidget->removeAction(pageAction);
+   }
+
    /* first determine the next item */
 
    /* knowing the treeWidgetItem, get the page from the hash */
@@ -397,15 +360,6 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre
             QBrush greyBrush(Qt::lightGray);
             dirItem->setBackground(0, greyBrush);
          }
-         /* make sure the close window and toggle dock options are removed */
-         treeWidget->removeAction(actionClosePage);
-         treeWidget->removeAction(actionToggleDock);
-         /* Is this a page that has been inserted into the hash  */
-         if (previousPage) {
-            foreach(QAction* pageaction, previousPage->m_contextActions) {
-               treeWidget->removeAction(pageaction);
-            }
-         } 
       }
    }
 
@@ -439,10 +393,9 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre
       nextPage->setContextMenuDockText();
 
       treeWidget->addAction(actionToggleDock);
-      /* if this page is closeable, then add that action */
-      if (nextPage->isCloseable()) {
+      /* if this page is closeable, and it has no childern, then add that action */
+      if ((nextPage->isCloseable()) && (currentitem->child(0) == NULL))
          treeWidget->addAction(actionClosePage);
-      }
 
       /* Add the actions to the Page Selectors tree widget that are part of the
        * current items list of desired actions regardless of whether on top of stack*/
@@ -457,7 +410,7 @@ void MainWin::labelButtonClicked()
 
 void MainWin::runButtonClicked() 
 {
-   new runPage();
+   new runPage("");
 }
 
 void MainWin::estimateButtonClicked() 
@@ -465,11 +418,23 @@ void MainWin::estimateButtonClicked()
    new estimatePage();
 }
 
+void MainWin::browseButtonClicked() 
+{
+   new restoreTree();
+}
+
 void MainWin::restoreButtonClicked() 
 {
    new prerestorePage();
 }
 
+void MainWin::jobPlotButtonClicked()
+{
+   JobPlotPass pass;
+   pass.use = false;
+   new JobPlot(NULL, pass);
+}
+
 /*
  * The user just finished typing a line in the command line edit box
  */
@@ -478,7 +443,8 @@ void MainWin::input_line()
    QString cmdStr = lineEdit->text();    /* Get the text */
    lineEdit->clear();                    /* clear the lineEdit box */
    if (m_currentConsole->is_connected()) {
-      m_currentConsole->consoleCommand(cmdStr);
+      /* Use consoleInput to allow typing anything */
+      m_currentConsole->consoleInput(cmdStr);
    } else {
       set_status("Director not connected. Click on connect button.");
    }
@@ -556,6 +522,7 @@ void MainWin::toggleDockContextWindow()
  */
 void MainWin::stackItemChanged(int)
 {
+   if (m_isClosing) return; /* if closing the application, do nothing here */
    Pages* page = (Pages*)stackedWidget->currentWidget();
    /* run the virtual function in case this class overrides it */
    page->currentStackItem();