]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/console/console.cpp
Fix bug #1486 -- bat doesn't show any errors on command-line
[bacula/bacula] / bacula / src / qt-console / console / console.cpp
index 496f99ae551ec13e7d33b616b45eeca18a75031a..8c383c8cb0990f42d11b9b9c1e03e14ffd4476dc 100644 (file)
@@ -1,7 +1,7 @@
 /*
    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.
@@ -26,8 +26,6 @@
    Switzerland, email:ftf@fsfeurope.org.
 */
 /*
- *   Version $Id$
- *
  *  Console Class
  *
  *   Kern Sibbald, January MMVII
 #include "select.h"
 #include "run/run.h"
 
-Console::Console(QStackedWidget *parent)
+Console::Console(QTabWidget *parent)
 {
    QFont font;
+   m_name = tr("Console");
    m_messages_pending = false;
    m_parent = parent;
    m_closeable = false;
    m_console = this;
+   m_warningPrevent = false;
    m_dircommCounter = 0;
+
+   /* 
+    * Create a connection to the Director and put it in a hash table
+    */
    m_dircommHash.insert(m_dircommCounter, new DirComm(this, m_dircommCounter));
 
    setupUi(this);
@@ -133,19 +137,12 @@ void Console::connect_dir()
  * A function created to separate out the population of the lists
  * from the Console::connect_dir function
  */
-void Console::populateLists(bool forcenew)
+void Console::populateLists(bool /*forcenew*/)
 {
    int conn;
-   if (forcenew) {
-      if (!newDirComm(conn)) {
-         Pmsg1(000, "newDirComm Seems to Failed to create a connection for populateLists %s\n", m_dir->name());
-         return;
-      }
-   } else {
-      if(!availableDirComm(conn)) {
-         Pmsg1(000, "availableDirComm Seems to Failed to find a connection for populateListsi %s\n", m_dir->name());
-         return;
-      }
+   if (!availableDirComm(conn) && !newDirComm(conn)) {
+      Emsg1(M_ABORT, 0, "Failed to connect to %s for populateLists.\n", m_dir->name());
+      return;
    }
    populateLists(conn);
 }
@@ -160,6 +157,8 @@ void Console::populateLists(int conn)
    storage_list.clear();
    type_list.clear();
    level_list.clear();
+   volstatus_list.clear();
+   mediatype_list.clear();
    dir_cmd(conn, ".jobs", job_list);
    dir_cmd(conn, ".clients", client_list);
    dir_cmd(conn, ".filesets", fileset_list);  
@@ -168,6 +167,9 @@ void Console::populateLists(int conn)
    dir_cmd(conn, ".storage", storage_list);
    dir_cmd(conn, ".types", type_list);
    dir_cmd(conn, ".levels", level_list);
+   dir_cmd(conn, ".volstatus", volstatus_list);
+   dir_cmd(conn, ".mediatypes", mediatype_list);
+   dir_cmd(conn, ".locations", location_list);
 
    if (mainWin->m_connDebug) {
       QString dbgmsg = QString("jobs=%1 clients=%2 filesets=%3 msgs=%4 pools=%5 storage=%6 types=%7 levels=%8 conn=%9 %10\n")
@@ -205,7 +207,7 @@ bool Console::dir_cmd(const char *cmd, QStringList &results)
       dir_cmd(conn, cmd, results);
       return true;
    } else {
-      Pmsg1(000, "dir_cmd Seems to Failed to find a connection %s\n", m_dir->name());
+      Pmsg1(000, "dir_cmd failed to connect to %s\n", m_dir->name());
       return false;
    }
 }
@@ -635,14 +637,31 @@ void Console::discardToPrompt(int conn)
    if (mainWin->m_commDebug) Pmsg2(000, "endDiscardToPrompt=%d %s\n", stat, m_dir->name());
 }
 
+QString Console::returnFromPrompt(int conn)
+{ 
+   DirComm *dircomm = m_dircommHash.value(conn);
+   QString text("");
+
+   int stat = 0;
+   text = "";
+   if (mainWin->m_commDebug) Pmsg1(000, "returnFromPrompt %s\n", m_dir->name());
+   while (!dircomm->m_at_prompt) {
+      if ((stat=dircomm->read()) > 0) {
+         text += dircomm->msg();
+      }
+   }
+   if (mainWin->m_commDebug) Pmsg2(000, "endreturnFromPrompt=%d %s\n", stat, m_dir->name());
+   return text;
+}
+
 /*
  * When the notifier is enabled, read_dir() will automatically be
  * called by the Qt event loop when ever there is any output 
- * from the Directory, and read_dir() will then display it on
+ * from the Director, and read_dir() will then display it on
  * the console.
  *
  * When we are in a bat dialog, we want to control *all* output
- * from the Directory, so we set notify to off.
+ * from the Director, so we set notify to off.
  *    m_console->notifiy(false);
  */
 
@@ -705,7 +724,7 @@ void Console::consoleReload()
  * This may be rendered not needed if the multiple connections feature gets working */
 bool Console::hasFocus()
 {
-   if (mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this))
+   if (mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this))
       return true;
    else
       return false;
@@ -810,6 +829,24 @@ bool Console::availableDirComm(int &conn)
       return false;
 }
 
+
+/*
+ * Need current connection.
+ */
+bool Console::currentDirComm(int &conn)
+{
+   QHash<int, DirComm*>::const_iterator iter = m_dircommHash.constBegin();
+   while (iter != m_dircommHash.constEnd()) {
+      DirComm *dircomm = iter.value();
+      if (dircomm->m_at_prompt && !dircomm->m_at_main_prompt && dircomm->is_notify_enabled()) {
+         conn = dircomm->m_conn;
+         return true;
+      }
+      ++iter;
+   }
+   return false;
+}
+
 /*
  *  Create a new connection
  */