]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Implement auto display of messages in bat.
authorKern Sibbald <kern@sibbald.com>
Wed, 16 May 2007 12:43:32 +0000 (12:43 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 16 May 2007 12:43:32 +0000 (12:43 +0000)
kes  Enhanced preferences to allow all Bacula output to be
     displayed in bat.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4798 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/ua_server.c
bacula/src/lib/bsock.h
bacula/src/qt-console/bat.h
bacula/src/qt-console/console/console.cpp
bacula/src/qt-console/console/console.h
bacula/src/qt-console/main.cpp
bacula/src/qt-console/mainwin.cpp
bacula/src/qt-console/pages.cpp
bacula/src/version.h
bacula/technotes-2.1

index bc9c54e9efba4c9c318a39176e5406e7b6e5d577..b4c956ea3b1028e348c8a8493271959518507e82 100644 (file)
@@ -136,7 +136,7 @@ static void *handle_UA_client_request(void *arg)
    }
 
    while (!ua->quit) {
-      if (ua->api) user->signal(BNET_PROMPT);
+      if (ua->api) user->signal(BNET_MAIN_PROMPT);
       stat = user->recv();
       if (stat >= 0) {
          pm_strcpy(ua->cmd, ua->UA_sock->msg);
index 1bd1b73013ffdc1b2ba431ec8cf158221b6663ae..1db9de0839c85aec5f5a350e4831963845926d28 100644 (file)
@@ -103,7 +103,7 @@ enum {
    BNET_POLL           = -5,          /* Poll request, I'm hanging on a read */
    BNET_HEARTBEAT      = -6,          /* Heartbeat Response requested */
    BNET_HB_RESPONSE    = -7,          /* Only response permited to HB */
-   BNET_PROMPT         = -8,          /* Prompt for UA */
+   BNET_PROMPT         = -8,          /* Prompt for subcommand */
    BNET_BTIME          = -9,          /* Send UTC btime */
    BNET_BREAK          = -10,         /* Stop current command -- ctl-c */
    BNET_START_SELECT   = -11,         /* Start of a selection list */
@@ -113,7 +113,7 @@ enum {
    BNET_CMD_OK         = -15,         /* Command succeeded */
    BNET_CMD_BEGIN      = -16,         /* Start command execution */
    BNET_MSGS_PENDING   = -17,         /* Messages pending */
-   BNET_SERVER_READY   = -18,         /* Server ready and waiting */
+   BNET_MAIN_PROMPT    = -18,         /* Server ready and waiting */
    BNET_SELECT_INPUT   = -19,         /* Return selection input */
    BNET_WARNING_MSG    = -20,         /* Warning message */
    BNET_ERROR_MSG      = -21,         /* Error message -- command failed */
index 173119f30f965132757b3560481f212ffd2598ad..c1d8f5d9bc3feb901a01ca70830358008a086f3f 100644 (file)
@@ -46,7 +46,8 @@ using namespace qstd;
 
 extern MainWin *mainWin;
 extern QApplication *app;
-extern bool commDebug;
+extern bool g_commDebug;
+extern bool g_displayAll;
 
 int bvsnprintf(char *str, int32_t size, const char *format, va_list ap);
 
index c228cc3908242e318c1fd1f58be9402b16a1e3f2..09ca2cb915e9850656480df775d174e3108f76b6 100644 (file)
@@ -52,14 +52,15 @@ Console::Console(QStackedWidget *parent)
    setupUi(this);
    m_sock = NULL;
    m_at_prompt = false;
+   m_at_main_prompt = false;
    m_textEdit = textEdit;   /* our console screen */
    m_cursor = new QTextCursor(m_textEdit->document());
    mainWin->actionConnect->setIcon(QIcon(":images/disconnected.png"));
 
    /* Check for messages every 5 seconds */
-// m_timer = new QTimer(this);
-// QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(poll_messages()));
-// m_timer->start(5000);
+   m_timer = new QTimer(this);
+   QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(poll_messages()));
+   m_timer->start(5000);
 }
 
 Console::~Console()
@@ -69,6 +70,10 @@ Console::~Console()
 void Console::poll_messages()
 {
    m_messages_pending = true;
+   if (m_at_main_prompt) {
+      write(".messages");
+      displayToPrompt();
+   }
 }
 
 /* Terminate any open socket */
@@ -78,7 +83,7 @@ void Console::terminate()
       m_sock->close();
       m_sock = NULL;
    }
-// m_timer->stop();
+   m_timer->stop();
 }
 
 /*
@@ -185,6 +190,7 @@ bool Console::dir_cmd(const char *cmd, QStringList &results)
    notify(false);
    write(cmd);
    while ((stat = read()) > 0) {
+      if (g_displayAll) display_text(msg());
       strip_trailing_junk(msg());
       results << msg();
    }
@@ -216,6 +222,7 @@ bool Console::sql_cmd(const char *query, QStringList &results)
    pm_strcat(cmd, "\"");
    write(cmd.c_str());
    while ((stat = read()) > 0) {
+      if (g_displayAll) display_text(msg());
       strip_trailing_junk(msg());
       results << msg();
    }
@@ -240,6 +247,7 @@ bool Console::get_job_defaults(struct job_defaults &job_defs)
    scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name);
    write(scmd);
    while ((stat = read()) > 0) {
+      if (g_displayAll) display_text(msg());
       def = strchr(msg(), '=');
       if (!def) {
          continue;
@@ -452,6 +460,7 @@ void Console::write_dir(const char *msg)
       QTreeWidgetItem *item = mainWin->getFromHash(this);
       item->setForeground(0, redBrush);
       m_at_prompt = false;
+      m_at_main_prompt = false;
    }
 }
 
@@ -464,7 +473,8 @@ int Console::write(const char *msg)
 {
    m_sock->msglen = pm_strcpy(m_sock->msg, msg);
    m_at_prompt = false;
-   if (commDebug) Pmsg1(000, "send: %s\n", msg);
+   m_at_main_prompt = false;
+   if (g_commDebug) Pmsg1(000, "send: %s\n", msg);
    return m_sock->send();
 }
 
@@ -475,12 +485,15 @@ void Console::beginNewCommand()
 {
    write(".\n");
    while (read() > 0) {
+      if (g_displayAll) display_text(msg());
    }
    write(".\n");
    while (read() > 0) {
+      if (g_displayAll) display_text(msg());
    }
    write(".\n");
    while (read() > 0) {
+      if (g_displayAll) display_text(msg());
    }
    display_text("\n");
 }
@@ -488,23 +501,25 @@ void Console::beginNewCommand()
 void Console::displayToPrompt()
 { 
    int stat;
-   if (commDebug) Pmsg0(000, "DisplaytoPrompt\n");
+   if (g_commDebug) Pmsg0(000, "DisplaytoPrompt\n");
    while (!m_at_prompt) {
       if ((stat=read()) > 0) {
          display_text(msg());
       }
    }
-   if (commDebug) Pmsg1(000, "endDisplaytoPrompt=%d\n", stat);
+   if (g_commDebug) Pmsg1(000, "endDisplaytoPrompt=%d\n", stat);
 }
 
 void Console::discardToPrompt()
 { 
    int stat;
-   if (commDebug) Pmsg0(000, "discardToPrompt\n");
+   if (g_commDebug) Pmsg0(000, "discardToPrompt\n");
    while (!m_at_prompt) {
-      stat = read();
+      if ((stat=read()) > 0) {
+         if (g_displayAll) display_text(msg());
+      }
    }
-   if (commDebug) Pmsg1(000, "endDisplayToPrompt=%d\n", stat);
+   if (g_commDebug) Pmsg1(000, "endDisplayToPrompt=%d\n", stat);
 }
 
 
@@ -531,45 +546,52 @@ int Console::read()
          if (m_at_prompt) {
             display_text("\n");
             m_at_prompt = false;
+            m_at_main_prompt = false;
          }
-         if (commDebug) Pmsg1(000, "got: %s", m_sock->msg);
+         if (g_commDebug) Pmsg1(000, "got: %s", m_sock->msg);
       }
       switch (m_sock->msglen) {
-      case BNET_SERVER_READY:
-         if (m_api_set && m_messages_pending) {
-            write_dir(".messages");
-            m_messages_pending = false;
-         }
-         m_at_prompt = true;
-         continue;
       case BNET_MSGS_PENDING:
-         if (commDebug) Pmsg0(000, "MSGS PENDING\n");
-         m_messages_pending = true;
+         if (g_commDebug) Pmsg0(000, "MSGS PENDING\n");
+         write_dir(".messages");
+         displayToPrompt();
+         m_messages_pending = false;
          continue;
       case BNET_CMD_OK:
-         if (commDebug) Pmsg0(000, "CMD OK\n");
+         if (g_commDebug) Pmsg0(000, "CMD OK\n");
          m_at_prompt = false;
+         m_at_main_prompt = false;
          continue;
       case BNET_CMD_BEGIN:
-         if (commDebug) Pmsg0(000, "CMD BEGIN\n");
+         if (g_commDebug) Pmsg0(000, "CMD BEGIN\n");
          m_at_prompt = false;
+         m_at_main_prompt = false;
          continue;
+      case BNET_MAIN_PROMPT:
+         if (g_commDebug) Pmsg0(000, "PROMPT\n");
+         m_at_prompt = true;
+         m_at_main_prompt = true;
+         mainWin->set_status(_("At prompt waiting for input ..."));
+         update_cursor();
+         QApplication::restoreOverrideCursor();
+         break;
       case BNET_PROMPT:
-         if (commDebug) Pmsg0(000, "PROMPT\n");
+         if (g_commDebug) Pmsg0(000, "PROMPT\n");
          m_at_prompt = true;
+         m_at_main_prompt = false;
          mainWin->set_status(_("At prompt waiting for input ..."));
          update_cursor();
          QApplication::restoreOverrideCursor();
          break;
       case BNET_CMD_FAILED:
-         if (commDebug) Pmsg0(000, "CMD FAIL\n");
+         if (g_commDebug) Pmsg0(000, "CMD FAIL\n");
          mainWin->set_status(_("Command failed. At prompt waiting for input ..."));
          update_cursor();
          QApplication::restoreOverrideCursor();
          break;
       /* We should not get this one */
       case BNET_EOD:
-         if (commDebug) Pmsg0(000, "EOD\n");
+         if (g_commDebug) Pmsg0(000, "EOD\n");
          mainWin->set_status_ready();
          update_cursor();
          QApplication::restoreOverrideCursor();
@@ -624,7 +646,7 @@ void Console::read_dir(int fd)
    int stat;
    (void)fd;
 
-   if (commDebug) Pmsg0(000, "read_dir\n");
+   if (g_commDebug) Pmsg0(000, "read_dir\n");
    while ((stat = read()) >= 0) {
       display_text(msg());
    }
index 8e3b4218eb5b82059f196b5ee57b7f8d3f697a6d..b36c09561801f4a4dfdcaccb726c6d3f50412024 100644 (file)
@@ -125,6 +125,7 @@ private:
    DIRRES *m_dir;
    BSOCK *m_sock;   
    bool m_at_prompt;
+   bool m_at_main_prompt;
    QSocketNotifier *m_notifier;
    QTextCursor *m_cursor;
    QTreeWidgetItem *m_directorTreeItem;
index dcc24f95b8e2fbee6bd217ad6bc5a4a35411df63..43eeaf6a872df04a601ba5be2dec217d70148ed0 100644 (file)
 #include <QApplication>
 #include "bat.h"
 
-bool commDebug = false;
 MainWin *mainWin;
 QApplication *app;
 
+/*
+ * ***FIXME*** move the following two into the MainWin class or
+ *   the Console class.
+ */
+bool g_commDebug = false;
+bool g_displayAll = false;
+
 
 /* Forward referenced functions */
 void terminate_console(int sig);                                
@@ -55,7 +61,6 @@ static char *configfile = NULL;
 
 int main(int argc, char *argv[])
 {
-
    int ch;
    bool no_signals = true;
    bool test_config = false;
index 4820df1d2a453f991b4a4b5fca1f7d9494ed5329..ec64b6042bf2cb632e570a0a99947441342bad81 100644 (file)
@@ -47,8 +47,6 @@
 #include "joblist/joblist.h"
 #include "clients/clients.h"
 
-extern bool commDebug;
-
 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
 {
 
@@ -610,7 +608,8 @@ QTreeWidgetItem *MainWin::currentTopItem()
 void MainWin::setPreferences()
 {
    prefsDialog prefs;
-   prefs.checkBox->setCheckState(commDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.commDebug->setCheckState(g_commDebug ? Qt::Checked : Qt::Unchecked);
+   prefs.displayAll->setCheckState(g_displayAll ? Qt::Checked : Qt::Unchecked);
    prefs.exec();
 }
 
@@ -623,7 +622,8 @@ prefsDialog::prefsDialog()
 void prefsDialog::accept()
 {
    this->hide();
-   commDebug = this->checkBox->checkState() == Qt::Checked;
+   g_commDebug = this->commDebug->checkState() == Qt::Checked;
+   g_displayAll = this->displayAll->checkState() == Qt::Checked;
 }
 
 void prefsDialog::reject()
index 59c7ca8e22c3b05d46f54fe7c1b070a0acd099ab..ebdd8b06fca33f5fb5a55de836748f3a246e97ee 100644 (file)
@@ -205,8 +205,9 @@ void Pages::treeWidgetName(QString &name)
  */
 void Pages::consoleCommand(QString &command)
 {
-   if (!m_console->is_connectedGui())
+   if (!m_console->is_connectedGui()) {
        return;
+   }
    /* Bring this directors console to the front of the stack */
    setConsoleCurrent();
    QString displayhtml("<font color=\"blue\">");
index c71cb4f86da4db0d7b180823f07c500cc719b163..7189096cd9ee7194dc4e859e11df8072e6434037 100644 (file)
@@ -4,8 +4,8 @@
 
 #undef  VERSION
 #define VERSION "2.1.8"
-#define BDATE   "14 May 2007"
-#define LSMDATE "14May07"
+#define BDATE   "16 May 2007"
+#define LSMDATE "16May07"
 
 #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n"
 #define BYEAR "2007"       /* year for copyright messages in progs */
index 10604835b35fafe66670220eca7ef1e55d29531e..19b8ee268030af9e361e157e7de594595d1ea409 100644 (file)
@@ -1,6 +1,10 @@
               Technical notes on version 2.1
 
 General:
+16May07
+kes  Implement auto display of messages in bat.
+kes  Enhanced preferences to allow all Bacula output to be
+     displayed in bat.
 15May07
 kes  Try to make bsmtp date routines more generic.
 kes  Fixed bug #856 autochanger documentation.