]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/console/console.cpp
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / qt-console / console / console.cpp
index 7a6790e00d3a83cf7d2a920a92f03dba8fefc78c..a183b919ecb016e340e929dc4f0950281402b397 100644 (file)
@@ -1,34 +1,25 @@
 /*
-   Bacula® - The Network Backup Solution
-
-   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 three of the GNU Affero 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 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.
-
-   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.
 */
 /*
  *  Console Class
  *
- *   Kern Sibbald, January MMVII
+ *   Written by Kern Sibbald, January MMVII
  *
  */ 
 
@@ -38,7 +29,7 @@
 #include "select.h"
 #include "run/run.h"
 
-Console::Console(QTabWidget *parent)
+Console::Console(QTabWidget *parent) : Pages()
 {
    QFont font;
    m_name = tr("Console");
@@ -78,7 +69,7 @@ void Console::startTimer()
 {
    m_timer = new QTimer(this);
    QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(poll_messages()));
-   m_timer->start(mainWin->m_checkMessagesInterval*1000);
+   m_timer->start(mainWin->m_checkMessagesInterval*30000);
 }
 
 void Console::stopTimer()
@@ -97,6 +88,11 @@ void Console::poll_messages()
 {
    int conn;
 
+   /* Do not poll if notifier off */
+   if (!mainWin->m_notify) {
+      return;
+   }
+
    /*
     * Note if we call getDirComm here, we continuously consume
     *  file descriptors.
@@ -107,7 +103,6 @@ void Console::poll_messages()
 
    DirComm *dircomm = m_dircommHash.value(conn);
    if (mainWin->m_checkMessages && dircomm->m_at_main_prompt && hasFocus() && !mainWin->getWaitState()){
-      messagesPending(true);
       dircomm->write(".messages");
       displayToPrompt(conn);
       messagesPending(false);
@@ -148,20 +143,20 @@ void Console::populateLists(bool /*forcenew*/)
 {
    int conn;
    if (!getDirComm(conn)) {
-      if (mainWin->m_connDebug) {
-         Pmsg0(000, "call newDirComm\n");
-      }
+      if (mainWin->m_connDebug) Pmsg0(000, "call newDirComm\n");
       if (!newDirComm(conn)) {
-         Emsg1(M_ABORT, 0, "Failed to connect to %s for populateLists.\n", m_dir->name());
+         Emsg1(M_INFO, 0, "Failed to connect to %s for populateLists.\n", m_dir->name());
          return;
       }
    }
    populateLists(conn);
+   notify(conn, true);
 }
 
 void Console::populateLists(int conn)
 {
    job_list.clear();
+   restore_list.clear();
    client_list.clear();
    fileset_list.clear();
    messages_list.clear();
@@ -172,6 +167,7 @@ void Console::populateLists(int conn)
    volstatus_list.clear();
    mediatype_list.clear();
    dir_cmd(conn, ".jobs", job_list);
+   dir_cmd(conn, ".jobs type=R", restore_list);
    dir_cmd(conn, ".clients", client_list);
    dir_cmd(conn, ".filesets", fileset_list);  
    dir_cmd(conn, ".msgs", messages_list);
@@ -233,12 +229,15 @@ bool Console::dir_cmd(int conn, const char *cmd, QStringList &results)
    mainWin->waitEnter();
    DirComm *dircomm = m_dircommHash.value(conn);
    int stat;
+   bool prev_notify = is_notify_enabled(conn);
 
    if (mainWin->m_connDebug) {
       QString dbgmsg = QString("dir_cmd conn %1 %2 %3\n").arg(conn).arg(m_dir->name()).arg(cmd);
       Pmsg1(000, "%s", dbgmsg.toUtf8().data());
    }
-   notify(conn, false);
+   if (prev_notify) {
+      notify(conn, false);
+   }
    dircomm->write(cmd);
    while ((stat = dircomm->read()) > 0 && dircomm->is_in_command()) {
       if (mainWin->m_displayAll) display_text(dircomm->msg());
@@ -246,10 +245,12 @@ bool Console::dir_cmd(int conn, const char *cmd, QStringList &results)
       results << dircomm->msg();
    }
    if (stat > 0 && mainWin->m_displayAll) display_text(dircomm->msg());
-   notify(conn, true);
+   if (prev_notify) {
+      notify(conn, true);         /* turn it back on */
+   }
    discardToPrompt(conn);
    mainWin->waitExit();
-   return true;              /* ***FIXME*** return any command error */
+   return true;                  /* ***FIXME*** return any command error */
 }
 
 /*
@@ -287,15 +288,16 @@ bool Console::sql_cmd(int &conn, const char *query, QStringList &results, bool d
    DirComm *dircomm = m_dircommHash.value(conn);
    int stat;
    POOL_MEM cmd(PM_MESSAGE);
+   bool prev_notify = is_notify_enabled(conn);
 
    if (!is_connectedGui()) {
       return false;
    }
 
-   if (mainWin->m_connDebug)
-      Pmsg2(000, "sql_cmd conn %i %s\n", conn, query);
-   if (donotify)
+   if (mainWin->m_connDebug) Pmsg2(000, "sql_cmd conn %i %s\n", conn, query);
+   if (donotify) {
       dircomm->notify(false);
+   }
    mainWin->waitEnter();
    
    pm_strcpy(cmd, ".sql query=\"");
@@ -314,15 +316,20 @@ bool Console::sql_cmd(int &conn, const char *query, QStringList &results, bool d
          QString dum = dircomm->msg();
          if ((dum.left(6) == "*None*")) doappend = false;
       }
-      if (doappend)
+      if (doappend) {
          results << dircomm->msg();
+      }
       first = false;
    }
-   if (donotify)
+   if (donotify && prev_notify) {
       dircomm->notify(true);
+   }
    discardToPrompt(conn);
    mainWin->waitExit();
-   return true;              /* ***FIXME*** return any command error */
+   if (donotify && prev_notify) {
+      dircomm->notify(true);
+   }
+   return !mainWin->isClosing();      /* return false if closing */
 }
 
 /* 
@@ -383,12 +390,13 @@ void Console::write_dir(int conn, const char *msg, bool dowait)
 bool Console::get_job_defaults(struct job_defaults &job_defs)
 {
    int conn;
+   getDirComm(conn);
    return get_job_defaults(conn, job_defs, true);
 }
 
 bool Console::get_job_defaults(int &conn, struct job_defaults &job_defs)
 {
-   return get_job_defaults(conn, job_defs, false);
+   return get_job_defaults(conn, job_defs, true);
 }
 
 /*  
@@ -400,16 +408,21 @@ bool Console::get_job_defaults(int &conn, struct job_defaults &job_defs, bool do
    QString scmd;
    int stat;
    char *def;
+   bool prev_notify = is_notify_enabled(conn);
+   bool rtn = false;
+   DirComm *dircomm = m_dircommHash.value(conn);
 
-   if (donotify)
-      conn = notifyOff();
+   if (donotify) {
+      dircomm->notify(false);
+   }
    beginNewCommand(conn);
-   DirComm *dircomm = m_dircommHash.value(conn);
    bool prevWaitState = mainWin->getWaitState();
-   if (!prevWaitState)
+   if (!prevWaitState) {
       mainWin->waitEnter();
-   if (mainWin->m_connDebug)
+   }
+   if (mainWin->m_connDebug) {
       Pmsg2(000, "job_defaults conn %i %s\n", conn, m_dir->name());
+   }
    scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name);
    dircomm->write(scmd);
    while ((stat = dircomm->read()) > 0) {
@@ -469,19 +482,16 @@ bool Console::get_job_defaults(int &conn, struct job_defaults &job_defs, bool do
          continue;
       }
    }
-
-   if (donotify)
-      notify(conn, true);
-   if (!prevWaitState)
-      mainWin->waitExit();
-   return true;
-
+   rtn = true;
+   /* Fall through wanted */
 bail_out:
-   if (donotify)
+   if (donotify && prev_notify) {
       notify(conn, true);
-   if (!prevWaitState)
+   }
+   if (!prevWaitState) {
       mainWin->waitExit();
-   return false;
+   }
+   return rtn;
 }
 
 
@@ -563,30 +573,38 @@ void Console::display_textf(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);
    display_text(buf);
 }
 
 void Console::display_text(const QString buf)
 {
-   m_cursor->insertText(buf);
-   update_cursor();
+   if (mainWin->isClosing()) return;
+   if (buf.size() != 0) {
+      m_cursor->insertText(buf);
+      update_cursor();
+   }
 }
 
 
 void Console::display_text(const char *buf)
 {
-   m_cursor->insertText(buf);
-   update_cursor();
+   if (mainWin->isClosing()) return;
+   if (*buf != 0) {
+      m_cursor->insertText(buf);
+      update_cursor();
+   }
 }
 
 void Console::display_html(const QString buf)
 {
-   m_cursor->insertHtml(buf);
-   update_cursor();
+   if (mainWin->isClosing()) return;
+   if (buf.size() != 0) {
+      m_cursor->insertHtml(buf);
+      update_cursor();
+   }
 }
 
 /* Position cursor to end of screen */
@@ -600,17 +618,20 @@ void Console::beginNewCommand(int conn)
 {
    DirComm *dircomm = m_dircommHash.value(conn);
 
+   if (dircomm->m_at_main_prompt) {
+      return;
+   }
    for (int i=0; i < 3; i++) {
       dircomm->write(".");
       while (dircomm->read() > 0) {
-         Pmsg2(000, "begin new command loop %i %s\n", i, m_dir->name());
+         if (mainWin->m_commDebug) Pmsg2(000, "begin new command loop %i %s\n", i, m_dir->name());
          if (mainWin->m_displayAll) display_text(dircomm->msg());
       }
       if (dircomm->m_at_main_prompt) {
          break;
       }
    }
-   display_text("\n");
+   //display_text("\n");
 }
 
 void Console::displayToPrompt(int conn)
@@ -662,6 +683,8 @@ QString Console::returnFromPrompt(int conn)
 
    int stat = 0;
    text = "";
+   dircomm->read();
+   text += dircomm->msg();
    if (mainWin->m_commDebug) Pmsg1(000, "returnFromPrompt %s\n", m_dir->name());
    while (!dircomm->m_at_prompt) {
       if ((stat=dircomm->read()) > 0) {
@@ -697,14 +720,22 @@ int Console::notifyOff()
 bool Console::notify(int conn, bool enable)
 { 
    DirComm *dircomm = m_dircommHash.value(conn);
-   return dircomm->notify(enable);
+   if (dircomm) {
+      return dircomm->notify(enable);
+   } else {
+      return false;
+   }
 }
 
 /* knowing a connection, return notify state */
 bool Console::is_notify_enabled(int conn) const
 {
    DirComm *dircomm = m_dircommHash.value(conn);
-   return dircomm->is_notify_enabled();
+   if (dircomm) {
+      return dircomm->is_notify_enabled();
+   } else {
+      return false;
+   }
 }
 
 void Console::setDirectorTreeItem(QTreeWidgetItem *item)
@@ -836,9 +867,7 @@ bool Console::getDirComm(int &conn)
    if (findDirComm(conn)) {
       return true;
    }
-   if (mainWin->m_connDebug) {
-      Pmsg0(000, "call newDirComm\n");
-   }
+   if (mainWin->m_connDebug) Pmsg0(000, "call newDirComm\n");
    return newDirComm(conn);
 }
 
@@ -856,7 +885,6 @@ bool Console::getDirComm(int &conn)
  */
 bool Console::findDirComm(int &conn)
 {
-   int i = 1;
    QHash<int, DirComm*>::const_iterator iter = m_dircommHash.constBegin();
    while (iter != m_dircommHash.constEnd()) {
       DirComm *dircomm = iter.value();
@@ -866,8 +894,7 @@ bool Console::findDirComm(int &conn)
       }
       if (mainWin->m_connDebug) {
          Pmsg4(000, "currentDirComm=%d at_prompt=%d at_main=%d && notify=%d\n",                                      
-            i, dircomm->m_at_prompt, dircomm->m_at_main_prompt, dircomm->is_notify_enabled());
-         i++;
+            dircomm->m_conn, dircomm->m_at_prompt, dircomm->m_at_main_prompt, dircomm->is_notify_enabled());
       }
       ++iter;
    }