]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/mainwin.cpp
Translation tweaks
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
index ac13a49b028396749b99aa2119fffe9bbdd2e445..20335059c6f0a3cc3d1506c530b795fa8694dac5 100644 (file)
@@ -1,14 +1,14 @@
 /*
    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.
    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 "bat.h"
-#include "pagehash.h"
+#include "joblist/joblist.h"
+#include "storage/storage.h"
+#include "fileset/fileset.h"
+#include "label/label.h"
+#include "run/run.h"
+#include "pages.h"
+#include "restore/restore.h"
+#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"
+#include "status/dirstat.h"
 
-MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
+/* 
+ * Daemon message callback
+ */
+void message_callback(int /* type */, char *msg)
 {
+   QMessageBox::warning(mainWin, "Bat", msg, QMessageBox::Ok);
+}
 
+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) */
+   register_message_callback(message_callback);
+   readPreferences();
    treeWidget->clear();
    treeWidget->setColumnCount(1);
    treeWidget->setHeaderLabel("Select Page");
@@ -58,82 +83,104 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
 
    readSettings();
 
-   m_console->connect();
+   foreach(Console *console, m_consoleHash) {
+      console->connect_dir();
+   }
+   m_currentConsole = (Console*)getFromHash(m_firstItem);
+   m_currentConsole->setCurrent();
+   if (m_miscDebug) {
+      QString directoryResourceName;
+      m_currentConsole->getDirResName(directoryResourceName);
+      Pmsg1(000, "Setting initial window to %s\n", directoryResourceName.toUtf8().data());
+   }
 }
 
 void MainWin::createPages()
 {
    DIRRES *dir;
    QTreeWidgetItem *item, *topItem;
+   m_firstItem = NULL;
 
-   /* Create console tree stacked widget item */
-   m_console = new Console(stackedWidget);
-
-   /* Console is special -> needs director*/
-   /* Just take the first Director */
    LockRes();
-   dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
-   m_console->setDirRes(dir);
+   foreach_res(dir, R_DIRECTOR) {
+
+      /* Create console tree stacked widget item */
+      m_currentConsole = new Console(stackedWidget);
+      m_currentConsole->setDirRes(dir);
+      m_currentConsole->readSettings();
+
+      /* The top tree item representing the director */
+      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);
+      topItem->setBackground(0, greyBrush);
+      m_currentConsole->setDirectorTreeItem(topItem);
+      m_consoleHash.insert(topItem, m_currentConsole);
+
+      /* Create Tree Widget Item */
+      item = new QTreeWidgetItem(topItem);
+      item->setText(0, "Console");
+      if (!m_firstItem){ m_firstItem = item; }
+      item->setIcon(0,QIcon(QString::fromUtf8(":images/utilities-terminal.png")));
+
+      /* insert the cosole and tree widget item into the hashes */
+      hashInsert(item, m_currentConsole);
+
+      /* 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 Clients();
+      new FileSet();
+      new Jobs();
+      createPageJobList("", "", "", "", NULL);
+      JobPlotPass pass;
+      pass.use = false;
+      if (m_openPlot)
+         new JobPlot(NULL, pass);
+      new MediaList();
+      new Storage();
+      if (m_openBrowser)
+         new restoreTree();
+      if (m_openDirStat)
+         new DirStat();
+
+      treeWidget->expandItem(topItem);
+      stackedWidget->setCurrentWidget(m_currentConsole);
+   }
    UnlockRes();
-
-   /* The top tree item representing the director */
-   topItem = createTopPage(dir->name());
-   topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
-
-   /* Create Tree Widget Item */
-   item = createPage("Console", topItem);
-   m_console->setTreeItem(item);
-
-   /* Append to pagelist */
-   m_treeindex.insert(item, m_console);
-
-   /* Set Color of treeWidgetItem for the console
-   * It will be set to gree in the console class if the connection is made.
-   */
-   QBrush redBrush(Qt::red);
-   item->setForeground(0, redBrush);
-
-   /*
-    * Now with the console created, on with the rest, these are easy   
-    * All should be
-    * 1. create tree widget item
-    * 2. create object passing pointer to tree widget item (modified constructors to pass QTreeWidget pointers)
-    * 3. append to stackhash
-    */
-
-   /* brestore */
-   item=createPage("brestore", topItem);
-   bRestore* brestore=new bRestore(stackedWidget);
-   m_treeindex.insert(item, brestore);
-
-
-   /* lastly for now, the medialist */
-   item=createPage("Media", topItem );
-   MediaList* medialist=new MediaList(stackedWidget, m_console);
-   m_treeindex.insert(item, medialist);
-
-   /* Iterate through and add to the stack */
-   foreach(Pages *page, m_treeindex.m_pagehash)
-      page->dockPage();
-
-   treeWidget->expandItem(topItem);
-   stackedWidget->setCurrentIndex(0);
 }
 
-/* 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)
+/*
+ * create an instance of the the joblist class on the stack
+ */
+void MainWin::createPageJobList(const QString &media, const QString &client,
+              const QString &job, const QString &fileset, QTreeWidgetItem *parentTreeWidgetItem)
 {
-   QTreeWidgetItem *item = new QTreeWidgetItem(parent);
-   item->setText(0, name);
-   return item;
+   QTreeWidgetItem *holdItem;
+
+   /* save current tree widget item in case query produces no results */
+   holdItem = treeWidget->currentItem();
+   JobList* joblist = new JobList(media, client, job, fileset, parentTreeWidgetItem);
+   /* If this is a query of jobs on a specific media */
+   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) {
+         joblist->closeStackPage();
+         treeWidget->setCurrentItem(holdItem);
+      }
+   }
 }
 
 /*
@@ -177,32 +224,26 @@ void MainWin::createConnections()
    /* Connect signals to slots */
    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
    connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
-
-#ifdef xxx
-     connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, 
-           SLOT(treeItemClicked(QTreeWidgetItem *, int)));
-   connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, 
-           SLOT(treeItemClicked(QTreeWidgetItem *, int)));  
-#endif
+   connect(actionBat_Help, SIGNAL(triggered()), this, SLOT(help()));
    connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, 
            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
-   connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, 
-           SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
    connect(treeWidget, SIGNAL(
            currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
            this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
    connect(stackedWidget, SIGNAL(currentChanged(int)),
            this, SLOT(stackItemChanged(int)));
-
    connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
-   connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
-   connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
-   connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
-   connect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelDialogClicked()));
-   connect(actionRun, SIGNAL(triggered()), this,  SLOT(runDialogClicked()));
-   connect(actionRestore, SIGNAL(triggered()), this,  SLOT(restoreDialogClicked()));
+   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(actionStatusDirPage, SIGNAL(triggered()), this,  SLOT(statusPageButtonClicked()));
+   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()));
+   connect(actionClosePage, SIGNAL(triggered()), this,  SLOT(closePage()));
+   connect(actionPreferences, SIGNAL(triggered()), this,  SLOT(setPreferences()));
 }
 
 /* 
@@ -210,14 +251,27 @@ void MainWin::createConnections()
  */
 void MainWin::closeEvent(QCloseEvent *event)
 {
+   m_isClosing = true;
    writeSettings();
-   m_console->writeSettings();
-   m_console->terminate();
-   event->accept();
-   foreach(Pages *page, m_treeindex.m_pagehash){
-      if( !page->isDocked() )
-         page->close();
+   /* close all non console pages, this will call settings in destructors */
+   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();
+      console->closeStackPage();
+   }
+   event->accept();
 }
 
 void MainWin::writeSettings()
@@ -227,6 +281,7 @@ void MainWin::writeSettings()
    settings.beginGroup("MainWin");
    settings.setValue("winSize", size());
    settings.setValue("winPos", pos());
+   settings.setValue("state", saveState());
    settings.endGroup();
 }
 
@@ -237,6 +292,7 @@ void MainWin::readSettings()
    settings.beginGroup("MainWin");
    resize(settings.value("winSize", QSize(1041, 801)).toSize());
    move(settings.value("winPos", QPoint(200, 150)).toPoint());
+   restoreState(settings.value("state").toByteArray());
    settings.endGroup();
 }
 
@@ -246,13 +302,12 @@ void MainWin::readSettings()
  */
 void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/)
 {
-   /* Is this one of the first level pages */
-   if( m_treeindex.value(item) ){
-      Pages* page = m_treeindex.value(item);
+   /* Is this a page that has been inserted into the hash  */
+   if (getFromHash(item)) {
+      Pages* page = getFromHash(item);
       int stackindex=stackedWidget->indexOf(page);
 
-      if( stackindex >= 0 ){
-         stackedWidget->setCurrentIndex(0);
+      if (stackindex >= 0) {
          stackedWidget->setCurrentWidget(page);
       }
       /* run the virtual function in case this class overrides it */
@@ -260,68 +315,153 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/)
    }
 }
 
-/*
- * This subroutine is called with an item in the Page Selection window
- *   is double clicked
- */
-void MainWin::treeItemDoubleClicked(QTreeWidgetItem * /*item*/, int /*column*/)
-{
-}
-
 /*
  * Called with a change of the highlighed tree widget item in the page selector.
  */
 void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *previousitem)
 {
+   if (m_isClosing) return; /* if closing the application, do nothing here */
+
+   Pages *previousPage, *nextPage;
+   Console *previousConsole = NULL;
+   Console *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 */
+   nextPage = getFromHash(currentitem);
+   nextConsole = m_consoleHash.value(currentitem);
+   /* Is this a page that has been inserted into the hash  */
+   if (nextPage) {
+      nextConsole = nextPage->console();
+      /* then is it a treeWidgetItem representing a director */
+   } else if (nextConsole) {
+      /* let the next page BE the console */
+      nextPage = nextConsole;
+   } else {
+      /* Should never get here */
+      nextPage = NULL;
+      nextConsole = NULL;
+   }
+          
    /* The Previous item */
 
-   if ( previousitem ){
-      /* Is this one of the first level pages */
-      if( m_treeindex.value(previousitem) ){
-         Pages* page = m_treeindex.value(previousitem);
-         treeWidget->removeAction(actionToggleDock);
-         foreach( QAction* pageaction, page->m_contextActions ){
-            treeWidget->removeAction(pageaction);
-         } 
+   /* this condition prevents a segfault.  The first time there is no previousitem*/
+   if (previousitem) {
+      /* knowing the treeWidgetItem, get the page from the hash */
+      previousPage = getFromHash(previousitem);
+      previousConsole = m_consoleHash.value(previousitem);
+      if (previousPage) {
+         previousConsole = previousPage->console();
+      } else if (previousConsole) {
+         previousPage = previousConsole;
+      }
+      if ((previousPage) || (previousConsole)) {
+         if (nextConsole != previousConsole) {
+            /* remove connections to the current console */
+            disconnect(actionConnect, SIGNAL(triggered()), previousConsole, SLOT(connect_dir()));
+            disconnect(actionStatusDir, SIGNAL(triggered()), previousConsole, SLOT(status_dir()));
+            disconnect(actionMessages, SIGNAL(triggered()), previousConsole, SLOT(messages()));
+            disconnect(actionSelectFont, SIGNAL(triggered()), previousConsole, SLOT(set_font()));
+            QTreeWidgetItem *dirItem = previousConsole->directorTreeItem();
+            QBrush greyBrush(Qt::lightGray);
+            dirItem->setBackground(0, greyBrush);
+         }
       }
    }
 
-   /* Is this one of the first level pages */
-   if( m_treeindex.value(currentitem) ){
-      Pages* page = m_treeindex.value(currentitem);
-      int stackindex = stackedWidget->indexOf(page);
+   /* process the current (next) item */
    
-      /* Is this page currently on the stack */
-      if( stackindex >= 0 ){
+   if ((nextPage) || (nextConsole)) {
+      if (nextConsole != previousConsole) {
+         /* make connections to the current console */
+         m_currentConsole = nextConsole;
+         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()));
+         /* Set director's tree widget background to magenta for ease of identification */
+         QTreeWidgetItem *dirItem = m_currentConsole->directorTreeItem();
+         QBrush magentaBrush(Qt::magenta);
+         dirItem->setBackground(0, magentaBrush);
+      }
+      /* set the value for the currently active console */
+      int stackindex = stackedWidget->indexOf(nextPage);
+   
+      /* 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);
+      } else {
+         /* it is undocked, raise it to the front */
+         nextPage->raise();
       }
-      setContextMenuDockText(page, currentitem);
+      /* for the page selectors menu action to dock or undock, set the text */
+      nextPage->setContextMenuDockText();
 
       treeWidget->addAction(actionToggleDock);
+      /* 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*/
-      treeWidget->addActions(page->m_contextActions);
+      treeWidget->addActions(nextPage->m_contextActions);
    }
 }
 
-void MainWin::labelDialogClicked() 
+void MainWin::labelButtonClicked() 
+{
+   new labelPage();
+}
+
+void MainWin::runButtonClicked() 
 {
-   new labelDialog(m_console);
+   new runPage("");
 }
 
-void MainWin::runDialogClicked() 
+void MainWin::estimateButtonClicked() 
 {
-   new runDialog(m_console);
+   new estimatePage();
 }
 
-void MainWin::restoreDialogClicked() 
+void MainWin::browseButtonClicked() 
 {
-   new prerestoreDialog(m_console);
+   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() == "Director Status") {
+            found = true;
+            page->setCurrent();
+         }
+      }
+   }
+   if (!found)
+      new DirStat();
 }
 
+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
@@ -330,24 +470,31 @@ void MainWin::input_line()
 {
    QString cmdStr = lineEdit->text();    /* Get the text */
    lineEdit->clear();                    /* clear the lineEdit box */
-   if (m_console->is_connected()) {
-      m_console->display_text(cmdStr + "\n");
-      m_console->write_dir(cmdStr.toUtf8().data());         /* send to dir */
+   if (m_currentConsole->is_connected()) {
+      /* 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;
+   if (treeWidget->currentItem() != getFromHash(m_currentConsole))
+      m_currentConsole->setCurrent();
 }
 
 
 void MainWin::about()
 {
    QMessageBox::about(this, tr("About bat"),
-            tr("<br><h2>bat 0.2, by Kern Sibbald</h2>"
-            "<p>Copyright &copy; " BYEAR " Free Software Foundation Europe e.V."
-            "<p>The <b>bat</b> is an administrative console"
-               " interface to the Director."));
+      tr("<br><h2>bat 1.0, by Dirk H Bartley and Kern Sibbald</h2>"
+         "<p>Copyright &copy; 2007-" BYEAR " Free Software Foundation Europe e.V."
+         "<p>The <b>bat</b> is an administrative console"
+         " interface to the Director."));
+}
+
+void MainWin::help()
+{
+   Help::displayFile("index.html");
 }
 
 void MainWin::set_statusf(const char *fmt, ...)
@@ -363,7 +510,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)
@@ -378,8 +530,6 @@ void MainWin::undockWindowButton()
 {
    Pages* page = (Pages*)stackedWidget->currentWidget();
    page->togglePageDocking();
-   /* The window has been undocked, lets change the context menu */
-   setContextMenuDockText();
 }
 
 /*
@@ -391,93 +541,341 @@ void MainWin::toggleDockContextWindow()
 {
    QTreeWidgetItem *currentitem = treeWidget->currentItem();
    
-   /* Is this one of the first level pages */
-   if( m_treeindex.value(currentitem) ){
-      Pages* page = m_treeindex.value(currentitem);
+   /* Is this a page that has been inserted into the hash  */
+   if (getFromHash(currentitem)) {
+      Pages* page = getFromHash(currentitem);
       page->togglePageDocking();
-      if ( page->isDocked() ){
-         stackedWidget->setCurrentWidget(page);
-      }
-      /* Toggle the menu item.  The window's dock status has been toggled */
-      setContextMenuDockText(page, currentitem);
    }
 }
 
 /*
- * Function to set the text of the toggle dock context menu when page and
- * widget item are NOT known.  This is an overoaded funciton.
- * It is called from MainWin::undockWindowButton, it is not intended to change
- * for the top pages tree widget, it is for the currently active tree widget
- * item.  Which is why the page is not passed.
+ * This function is called when the stack item is changed.  Call
+ * the virtual function here.  Avoids a window being undocked leaving
+ * a window at the top of the stack unpopulated.
  */
-void MainWin::setContextMenuDockText()
+void MainWin::stackItemChanged(int)
 {
-   QTreeWidgetItem *currentitem = treeWidget->currentItem();
-   
-   /* Is this one of the first level pages */
-   if( m_treeindex.value(currentitem) ){
-      Pages* page = m_treeindex.value(currentitem);
-      setContextMenuDockText(page, currentitem);
-   }
+   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();
 }
 
 /*
- * Function to set the text of the toggle dock context menu when page and
- * widget item are known.  This is the more commonly used.
+ * Function to simplify insertion of QTreeWidgetItem <-> Page association
+ * into a double direction hash.
  */
-void MainWin::setContextMenuDockText(Pages* page, QTreeWidgetItem* item)
+void MainWin::hashInsert(QTreeWidgetItem *item, Pages *page)
 {
-   QString docktext("");
-   if( page->isDocked() ){
-      docktext += "UnDock ";
-   } else {
-      docktext += "ReDock ";
-   }
-   docktext += item->text(0) += " Window";
-   
-   actionToggleDock->setText(docktext);
-   setTreeWidgetItemDockColor(page, item);
+   m_pagehash.insert(item, page);
+   m_widgethash.insert(page, item);
 }
 
 /*
- * Function to set the color of the tree widget item based on whether it is
- * docked or not.
+ * Function to simplify removal of QTreeWidgetItem <-> Page association
+ * into a double direction hash.
  */
-void MainWin::setTreeWidgetItemDockColor(Pages* page, QTreeWidgetItem* item)
+void MainWin::hashRemove(QTreeWidgetItem *item, Pages *page)
 {
-   if( item->text(0) != "Console" ){
-      if( page->isDocked() ){
-      /* Set the brush to blue if undocked */
-         QBrush blackBrush(Qt::black);
-         item->setForeground(0, blackBrush);
-      } else {
-      /* Set the brush back to black if docked */
-         QBrush blueBrush(Qt::blue);
-         item->setForeground(0, blueBrush);
-      }
-   }
+   /* I had all sorts of return status checking code here.  Do we have a log
+    * level capability in bat.  I would have left it in but it used printf's
+    * and it should really be some kind of log level facility ???
+    * ******FIXME********/
+   m_pagehash.remove(item);
+   m_widgethash.remove(page);
 }
 
 /*
- *  Overload of previous function, use treeindex to get item from page
- *  This is called when an undocked window is closed.
+ * Function to retrieve a Page* when the item in the page selector's tree is
+ * known.
  */
-void MainWin::setTreeWidgetItemDockColor(Pages* page)
+Pages* MainWin::getFromHash(QTreeWidgetItem *item)
 {
-   QTreeWidgetItem* item = m_treeindex.value(page);
-   if( item ){
-     setTreeWidgetItemDockColor(page, item);
-   }
+   return m_pagehash.value(item);
 }
 
 /*
- * This function is called when the stack item is changed.  Call
- * the virtual function here.  Avoids a window being undocked leaving
- * a window at the top of the stack unpopulated.
+ * Function to retrieve the page selectors tree widget item when the page is
+ * known.
  */
-void MainWin::stackItemChanged(int)
+QTreeWidgetItem* MainWin::getFromHash(Pages *page)
 {
-   Pages* page = (Pages*)stackedWidget->currentWidget();
-   /* run the virtual function in case this class overrides it */
-   page->currentStackItem();
+   return m_widgethash.value(page);
+}
+
+/*
+ * Function to respond to action on page selector context menu to close the
+ * current window.
+ */
+void MainWin::closePage()
+{
+   QTreeWidgetItem *currentitem = treeWidget->currentItem();
+   
+   /* Is this a page that has been inserted into the hash  */
+   if (getFromHash(currentitem)) {
+      Pages* page = getFromHash(currentitem);
+      if (page->isCloseable()) {
+         page->closeStackPage();
+      }
+   }
+}
+
+/* Quick function to return the current console */
+Console *MainWin::currentConsole()
+{
+   return m_currentConsole;
+}
+/* Quick function to return the tree item for the director */
+QTreeWidgetItem *MainWin::currentTopItem()
+{
+   return m_currentConsole->directorTreeItem();
+}
+
+/* Preferences menu item clicked */
+void MainWin::setPreferences()
+{
+   prefsDialog prefs;
+   prefs.commDebug->setCheckState(m_commDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.displayAll->setCheckState(m_displayAll ? Qt::Checked : Qt::Unchecked);
+   prefs.sqlDebug->setCheckState(m_sqlDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.commandDebug->setCheckState(m_commandDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.miscDebug->setCheckState(m_miscDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.recordLimit->setCheckState(m_recordLimitCheck ? Qt::Checked : Qt::Unchecked);
+   prefs.recordSpinBox->setValue(m_recordLimitVal);
+   prefs.daysLimit->setCheckState(m_daysLimitCheck ? Qt::Checked : Qt::Unchecked);
+   prefs.daysSpinBox->setValue(m_daysLimitVal);
+   prefs.checkMessages->setCheckState(m_checkMessages ? Qt::Checked : Qt::Unchecked);
+   prefs.checkMessagesSpin->setValue(m_checkMessagesInterval);
+   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);
+   prefs.rtDirICCheckBox->setCheckState(m_rtDirICDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.rtFileTabICCheckBox->setCheckState(m_rtFileTabICDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.rtVerTabICCheckBox->setCheckState(m_rtVerTabICDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.rtUpdateFTCheckBox->setCheckState(m_rtUpdateFTDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.rtUpdateVTCheckBox->setCheckState(m_rtUpdateVTDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.rtChecksCheckBox->setCheckState(m_rtChecksDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.rtIconStateCheckBox->setCheckState(m_rtIconStateDebug ? Qt::Checked : Qt::Unchecked);
+   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);
+   if (m_radioConvert == 0) {
+      prefs.radioConvertOff->setChecked(Qt::Checked);
+   } else if (m_radioConvert == 1){
+      prefs.radioConvertIEC->setChecked(Qt::Checked);
+   } else {
+      m_radioConvert = 2;
+      prefs.radioConvertStandard->setChecked(Qt::Checked);
+   }
+   prefs.openPlotCheckBox->setCheckState(m_openPlot ? Qt::Checked : Qt::Unchecked);
+   prefs.openBrowserCheckBox->setCheckState(m_openBrowser ? Qt::Checked : Qt::Unchecked);
+   prefs.openDirStatCheckBox->setCheckState(m_openDirStat ? Qt::Checked : Qt::Unchecked);
+   prefs.exec();
+}
+
+/* Preferences dialog */
+prefsDialog::prefsDialog()
+{
+   setupUi(this);
+}
+
+void prefsDialog::accept()
+{
+   this->hide();
+   mainWin->m_commDebug = this->commDebug->checkState() == Qt::Checked;
+   mainWin->m_displayAll = this->displayAll->checkState() == Qt::Checked;
+   mainWin->m_sqlDebug = this->sqlDebug->checkState() == Qt::Checked;
+   mainWin->m_commandDebug = this->commandDebug->checkState() == Qt::Checked;
+   mainWin->m_miscDebug = this->miscDebug->checkState() == Qt::Checked;
+   mainWin->m_recordLimitCheck = this->recordLimit->checkState() == Qt::Checked;
+   mainWin->m_recordLimitVal = this->recordSpinBox->value();
+   mainWin->m_daysLimitCheck = this->daysLimit->checkState() == Qt::Checked;
+   mainWin->m_daysLimitVal = this->daysSpinBox->value();
+   mainWin->m_checkMessages = this->checkMessages->checkState() == Qt::Checked;
+   mainWin->m_checkMessagesInterval = this->checkMessagesSpin->value();
+   mainWin->m_longList = this->executeLongCheckBox->checkState() == Qt::Checked;
+
+   mainWin->m_rtPopDirDebug = this->rtPopDirCheckBox->checkState() == Qt::Checked;
+   mainWin->m_rtDirCurICDebug = this->rtDirCurICCheckBox->checkState() == Qt::Checked;
+   mainWin->m_rtDirICDebug = this->rtDirICCheckBox->checkState() == Qt::Checked;
+   mainWin->m_rtFileTabICDebug = this->rtFileTabICCheckBox->checkState() == Qt::Checked;
+   mainWin->m_rtVerTabICDebug = this->rtVerTabICCheckBox->checkState() == Qt::Checked;
+   mainWin->m_rtUpdateFTDebug = this->rtUpdateFTCheckBox->checkState() == Qt::Checked;
+   mainWin->m_rtUpdateVTDebug = this->rtUpdateVTCheckBox->checkState() == Qt::Checked;
+   mainWin->m_rtChecksDebug = this->rtChecksCheckBox->checkState() == Qt::Checked;
+   mainWin->m_rtIconStateDebug = this->rtIconStateCheckBox->checkState() == Qt::Checked;
+   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()) {
+      mainWin->m_radioConvert = 0;
+   } else if (this->radioConvertIEC->isChecked()){
+      mainWin->m_radioConvert = 1;
+   } else {
+      mainWin->m_radioConvert = 2;
+   }
+   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");
+   settings.setValue("commDebug", mainWin->m_commDebug);
+   settings.setValue("displayAll", mainWin->m_displayAll);
+   settings.setValue("sqlDebug", mainWin->m_sqlDebug);
+   settings.setValue("commandDebug", mainWin->m_commandDebug);
+   settings.setValue("miscDebug", mainWin->m_miscDebug);
+   settings.endGroup();
+   settings.beginGroup("JobList");
+   settings.setValue("recordLimitCheck", mainWin->m_recordLimitCheck);
+   settings.setValue("recordLimitVal", mainWin->m_recordLimitVal);
+   settings.setValue("daysLimitCheck", mainWin->m_daysLimitCheck);
+   settings.setValue("daysLimitVal", mainWin->m_daysLimitVal);
+   settings.endGroup();
+   settings.beginGroup("Messages");
+   settings.setValue("checkMessages", mainWin->m_checkMessages);
+   settings.setValue("checkMessagesInterval", mainWin->m_checkMessagesInterval);
+   settings.endGroup();
+   settings.beginGroup("Misc");
+   settings.setValue("longList", mainWin->m_longList);
+   settings.setValue("byteConvert", mainWin->m_radioConvert);
+   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);
+   settings.setValue("rtDirCurICDebug", mainWin->m_rtDirCurICDebug);
+   settings.setValue("rtDirCurICRetDebug", mainWin->m_rtDirICDebug);
+   settings.setValue("rtFileTabICDebug", mainWin->m_rtFileTabICDebug);
+   settings.setValue("rtVerTabICDebug", mainWin->m_rtVerTabICDebug);
+   settings.setValue("rtUpdateFTDebug", mainWin->m_rtUpdateFTDebug);
+   settings.setValue("rtUpdateVTDebug", mainWin->m_rtUpdateVTDebug);
+   settings.setValue("rtChecksDebug", mainWin->m_rtChecksDebug);
+   settings.setValue("rtIconStateDebug", mainWin->m_rtIconStateDebug);
+   settings.setValue("rtRestore1Debug", mainWin->m_rtRestore1Debug);
+   settings.setValue("rtRestore2Debug", mainWin->m_rtRestore2Debug);
+   settings.setValue("rtRestore3Debug", mainWin->m_rtRestore3Debug);
+   settings.endGroup();
+   foreach(Console *console, mainWin->m_consoleHash) {
+      console->startTimer();
+   }
+}
+
+void prefsDialog::reject()
+{
+   this->hide();
+   mainWin->set_status(tr("Canceled"));
+}
+
+/* read preferences for the prefences dialog box */
+void MainWin::readPreferences()
+{
+   QSettings settings("www.bacula.org", "bat");
+   settings.beginGroup("Debug");
+   m_commDebug = settings.value("commDebug", false).toBool();
+   m_displayAll = settings.value("displayAll", false).toBool();
+   m_sqlDebug = settings.value("sqlDebug", false).toBool();
+   m_commandDebug = settings.value("commandDebug", false).toBool();
+   m_miscDebug = settings.value("miscDebug", false).toBool();
+   settings.endGroup();
+   settings.beginGroup("JobList");
+   m_recordLimitCheck = settings.value("recordLimitCheck", true).toBool();
+   m_recordLimitVal = settings.value("recordLimitVal", 150).toInt();
+   m_daysLimitCheck = settings.value("daysLimitCheck", false).toBool();
+   m_daysLimitVal = settings.value("daysLimitVal", 28).toInt();
+   settings.endGroup();
+   settings.beginGroup("Messages");
+   m_checkMessages = settings.value("checkMessages", false).toBool();
+   m_checkMessagesInterval = settings.value("checkMessagesInterval", 28).toInt();
+   settings.endGroup();
+   settings.beginGroup("Misc");
+   m_longList = settings.value("longList", false).toBool();
+   m_radioConvert = settings.value("byteConvert", false).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();
+   m_rtDirCurICDebug = settings.value("rtDirCurICDebug", false).toBool();
+   m_rtDirICDebug = settings.value("rtDirCurICRetDebug", false).toBool();
+   m_rtFileTabICDebug = settings.value("rtFileTabICDebug", false).toBool();
+   m_rtVerTabICDebug = settings.value("rtVerTabICDebug", false).toBool();
+   m_rtUpdateFTDebug = settings.value("rtUpdateFTDebug", false).toBool();
+   m_rtUpdateVTDebug = settings.value("rtUpdateVTDebug", false).toBool();
+   m_rtChecksDebug = settings.value("rtChecksDebug", false).toBool();
+   m_rtIconStateDebug = settings.value("rtIconStateDebug", false).toBool();
+   m_rtRestore1Debug = settings.value("rtRestore1Debug", false).toBool();
+   m_rtRestore2Debug = settings.value("rtRestore2Debug", false).toBool();
+   m_rtRestore3Debug = settings.value("rtRestore3Debug", false).toBool();
+   settings.endGroup();
+}
+
+void MainWin::hrConvert(QString &ret, qlonglong &inval)
+{
+   double net = 0;
+   qlonglong base;
+   QStringList suflist;
+
+   if (m_radioConvert == 0) {
+      ret =  QString("%1").arg(inval);
+      return;
+   } else if (m_radioConvert == 1){
+      base = 1000;
+      suflist = (QStringList() << "B" << "KiB" << "MiB" << "GiB" << "TiB" << "PiB" << "EiB" << "ZiB");
+   } else {
+      base = 1024;
+      suflist = (QStringList() << "B" << "KB" << "MB" << "GB" << "TB" << "PB" << "EB" << "ZB");
+   }
+   qlonglong running = base;
+   bool done = false;
+   int count = 1;
+   while (done == false) {
+      QString test1 =  QString("%1").arg(inval);
+      QString test2 =  QString("%1").arg(running);
+      if (float(inval) < (float)(running)) {
+         done = true;
+         ret = suflist[count - 1];
+         net = (float)inval / (float)(running/base);
+      }
+      count += 1;
+      if (count > suflist.count()) done = true;
+      running *= base;
+   }
+   char format = 'f';
+   if (net != 0)
+      ret =  QString("%1 %2")
+                  .arg(net, 0, format, 2, QLatin1Char(' '))
+                  .arg(ret);
+   else ret = "0 B";
+}
+
+void MainWin::hrConvertSeconds(QString &ret, qlonglong &inval)
+{
+   double net = 0;
+   QList<qlonglong> durations;
+   durations.append(1);
+   durations.append(60);
+   durations.append(3600);
+   durations.append(86400);
+   durations.append(2592000);
+   durations.append(31536000);
+   QStringList abbrlist = (QStringList() << "Sec" << "Min" << "Hrs" << "Days" << "Mnth" << "Yrs");
+   bool done = false;
+   int count = 1;
+   while (done == false) {
+      QString test1 =  QString("%1").arg(inval);
+      QString test2 =  QString("%1").arg(durations[count]);
+      if ((inval < durations[count]) || (count >= abbrlist.count() - 1)) { 
+         done = true;
+         net = (float)inval / (float)(durations[count - 1]);
+         if (net != 0)
+            ret =  QString("%1 %2")
+                  .arg(net, 0, 'f', 2, QLatin1Char(' '))
+                  .arg(abbrlist[count - 1]);
+         else ret = "0 S";
+      }
+      count += 1;
+   }
 }