From: Kern Sibbald Date: Wed, 16 May 2007 12:43:32 +0000 (+0000) Subject: kes Implement auto display of messages in bat. X-Git-Tag: Release-7.0.0~6334 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3a122a380f457cee0a46e7488e1b76e0b48c33b6;p=bacula%2Fbacula kes Implement auto display of messages in bat. 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 --- diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index bc9c54e9ef..b4c956ea3b 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -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); diff --git a/bacula/src/lib/bsock.h b/bacula/src/lib/bsock.h index 1bd1b73013..1db9de0839 100644 --- a/bacula/src/lib/bsock.h +++ b/bacula/src/lib/bsock.h @@ -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 */ diff --git a/bacula/src/qt-console/bat.h b/bacula/src/qt-console/bat.h index 173119f30f..c1d8f5d9bc 100644 --- a/bacula/src/qt-console/bat.h +++ b/bacula/src/qt-console/bat.h @@ -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); diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index c228cc3908..09ca2cb915 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -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()); } diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index 8e3b4218eb..b36c095618 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -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; diff --git a/bacula/src/qt-console/main.cpp b/bacula/src/qt-console/main.cpp index dcc24f95b8..43eeaf6a87 100644 --- a/bacula/src/qt-console/main.cpp +++ b/bacula/src/qt-console/main.cpp @@ -38,10 +38,16 @@ #include #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; diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 4820df1d2a..ec64b6042b 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -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() diff --git a/bacula/src/qt-console/pages.cpp b/bacula/src/qt-console/pages.cpp index 59c7ca8e22..ebdd8b06fc 100644 --- a/bacula/src/qt-console/pages.cpp +++ b/bacula/src/qt-console/pages.cpp @@ -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(""); diff --git a/bacula/src/version.h b/bacula/src/version.h index c71cb4f86d..7189096cd9 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -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 */ diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 10604835b3..19b8ee2680 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -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.