From: Kern Sibbald Date: Sun, 28 Jan 2007 21:38:09 +0000 (+0000) Subject: It now talks to Dir X-Git-Tag: Release-7.0.0~6986 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5b8188d281f9a1a4e9633ec2713e7905411156ca;p=bacula%2Fbacula It now talks to Dir git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4070 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 3127c9c8d1..d68ae1f880 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -33,6 +33,7 @@ * */ +#include #include "bat.h" #include "console.h" @@ -42,6 +43,7 @@ Console::Console() QTreeWidget *treeWidget = mainWin->treeWidget; m_sock = NULL; + m_at_prompt = false; m_textEdit = mainWin->textEdit; /* our console screen */ /* Just take the first Director */ @@ -117,15 +119,15 @@ void Console::connect() bnet_fsend(m_sock, "autodisplay on"); - /* Read and display all initial messages */ - while (bnet_recv(m_sock) > 0) { - set_text(m_sock->msg); - } + /* Set up input notifier */ + m_notifier = new QSocketNotifier(m_sock->fd, QSocketNotifier::Read, 0); + QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int))); /* Give GUI a chance */ app->processEvents(); - /* Query Directory for .jobs, .clients, .filesets, .msgs, + /* *** FIXME *** + * Query Directory for .jobs, .clients, .filesets, .msgs, * .pools, .storage, .types, .levels, ... */ @@ -134,6 +136,13 @@ void Console::connect() return; } +#ifdef xxx + QByteArray bytes = m_Bash->readAllStandardOutput(); + QStringList lines = QString(bytes).split("\n"); + foreach (QString line, lines) { + m_Logw->append(line); + } +#endif void Console::set_textf(const char *fmt, ...) { @@ -171,59 +180,60 @@ void Console::set_status_ready() void Console::set_status(const char *buf) { mainWin->statusBar()->showMessage(buf); - set_text(buf); +// set_text(buf); // ready = false; } -#ifdef xxx -void write_director(const gchar *msg) +void Console::write_dir(const char *msg) { - if (UA_sock) { - at_prompt = false; + if (m_sock) { + m_at_prompt = false; set_status(_(" Processing command ...")); - UA_sock->msglen = strlen(msg); - pm_strcpy(&UA_sock->msg, msg); - bnet_send(UA_sock); + m_sock->msglen = strlen(msg); + pm_strcpy(&m_sock->msg, msg); + bnet_send(m_sock); } if (strcmp(msg, ".quit") == 0 || strcmp(msg, ".exit") == 0) { - disconnect_from_director((gpointer)NULL); - gtk_main_quit(); + app->closeAllWindows(); } } -extern "C" -void read_director(gpointer data, gint fd, GdkInputCondition condition) +void Console::read_dir(int fd) { int stat; + (void)fd; - if (!UA_sock || UA_sock->fd != fd) { + if (!m_sock) { return; } - stat = bnet_recv(UA_sock); + stat = bnet_recv(m_sock); if (stat >= 0) { - if (at_prompt) { - set_text("\n", 1); - at_prompt = false; + if (m_at_prompt) { + set_text("\n"); + m_at_prompt = false; } - set_text(UA_sock->msg, UA_sock->msglen); + set_text(m_sock->msg); return; } - if (is_bnet_stop(UA_sock)) { /* error or term request */ - gtk_main_quit(); + if (is_bnet_stop(m_sock)) { /* error or term request */ + bnet_close(m_sock); + m_sock = NULL; return; } /* Must be a signal -- either do something or ignore it */ - if (UA_sock->msglen == BNET_PROMPT) { - at_prompt = true; + if (m_sock->msglen == BNET_PROMPT) { + m_at_prompt = true; set_status(_(" At prompt waiting for input ...")); } - if (UA_sock->msglen == BNET_EOD) { + if (m_sock->msglen == BNET_EOD) { set_status_ready(); } return; } +#ifdef xxx + static gint tag; void start_director_reader(gpointer data) diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index 138f7e5537..cd2340cbe3 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -12,6 +12,7 @@ class CONRES; class Console : public QWidget { Q_OBJECT + public: Console(); void set_text(const char *buf); @@ -19,14 +20,18 @@ public: void set_statusf(const char *fmt, ...); void set_status_ready(); void set_status(const char *buf); + void write_dir(const char *buf); public slots: void connect(); + void read_dir(int fd); private: QTextEdit *m_textEdit; DIRRES *m_dir; BSOCK *m_sock; + bool m_at_prompt; + QSocketNotifier *m_notifier; }; extern int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index b995aea71c..cee73289e4 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -81,6 +81,7 @@ void MainWin::input_line() QString cmdStr = lineEdit->text(); /* Get the text */ lineEdit->clear(); /* clear the lineEdit box */ textEdit->append(cmdStr); /* append text on screen */ + m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */ } void MainWin::about() {