From: Kern S. <ke...@us...> - 2007-02-04 16:29:57
|
Update of /cvsroot/bacula/bacula/src/qt-console/console In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19516/console Modified Files: console.cpp console.h Log Message: Implement command output lists Index: console.h =================================================================== RCS file: /cvsroot/bacula/bacula/src/qt-console/console/console.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- console.h 3 Feb 2007 11:33:09 -0000 1.8 +++ console.h 4 Feb 2007 16:29:53 -0000 1.9 @@ -26,10 +26,24 @@ const QFont get_font(); void writeSettings(); void readSettings(); + char *msg(); + void setEnabled(bool enable) { m_notifier->setEnabled(enable); }; + QStringList get_list(char *cmd); + + QStringList job_list; + QStringList client_list; + QStringList fileset_list; + QStringList messages_list; + QStringList pool_list; + QStringList storage_list; + QStringList type_list; + QStringList level_list; public slots: void connect(void); void read_dir(int fd); + int read(void); + int write(const char *msg); void status_dir(void); void set_font(void); Index: console.cpp =================================================================== RCS file: /cvsroot/bacula/bacula/src/qt-console/console/console.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- console.cpp 4 Feb 2007 09:41:27 -0000 1.13 +++ console.cpp 4 Feb 2007 16:29:53 -0000 1.14 @@ -94,11 +94,11 @@ m_textEdit = textEdit; /* our console screen */ if (!m_dir) { - mainWin->set_status("No Director found."); + mainWin->set_status(" No Director found."); return; } if (m_sock) { - mainWin->set_status("Already connected."); + mainWin->set_status(" Already connected."); return; } @@ -139,25 +139,44 @@ mainWin->set_status(_(" Initializing ...")); - bnet_fsend(m_sock, "autodisplay on"); - /* 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(); - - /* *** FIXME *** - * Query Directory for .jobs, .clients, .filesets, .msgs, - * .pools, .storage, .types, .levels, ... - */ + job_list = get_list(".jobs"); + client_list = get_list(".clients"); + fileset_list = get_list(".filesets"); + messages_list = get_list(".messages"); + messages_list = get_list(".pools"); + messages_list = get_list(".storages"); + messages_list = get_list(".types"); + messages_list = get_list(".levels"); mainWin->set_status(_(" Connected")); return; } +/* + * Send a command to the director, and read all the resulting + * output into a list. + */ +QStringList Console::get_list(char *cmd) +{ + QStringList list; + int stat; + + setEnabled(false); + write(cmd); + while ((stat = read()) > 0) { + strip_trailing_junk(msg()); + list << msg(); + } + setEnabled(true); + return list; +} + + void Console::writeSettings() { QFont font = get_font(); @@ -235,6 +254,13 @@ m_textEdit->ensureCursorVisible(); } +char *Console::msg() +{ + if (m_sock) { + return m_sock->msg; + } + return NULL; +} /* Send a command to the Director */ void Console::write_dir(const char *msg) @@ -254,6 +280,34 @@ } } +int Console::write(const char *msg) +{ + m_sock->msglen = strlen(msg); + pm_strcpy(&m_sock->msg, msg); + return bnet_send(m_sock); +} + +/* + * Blocking read from director */ +int Console::read() +{ + int stat; + if (m_sock) { + for (;;) { + stat = bnet_wait_data_intr(m_sock, 1); + if (stat > 0) { + break; + } + app->processEvents(); + if (stat < 0) { + return BNET_ERROR; + } + } + return bnet_recv(m_sock); + } + return BNET_HARDEOF; +} + /* Called by signal when the Director has output for us */ void Console::read_dir(int fd) { |