From: Kern Sibbald Date: Sun, 4 Feb 2007 16:29:53 +0000 (+0000) Subject: Implement command output lists X-Git-Tag: Release-7.0.0~6961 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d2d3d3a8aeb54da45a576b1490832332e1667cc8;p=bacula%2Fbacula Implement command output lists git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4097 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/Makefile b/bacula/src/qt-console/Makefile index 2855bb4935..ec897f84ef 100644 --- a/bacula/src/qt-console/Makefile +++ b/bacula/src/qt-console/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: bat -# Generated by qmake (2.01a) (Qt 4.2.1) on: Sat Feb 3 13:49:24 2007 +# Generated by qmake (2.01a) (Qt 4.2.1) on: Sun Feb 4 16:56:30 2007 # Project: bat.pro # Template: app # Command: /usr/bin/qmake -unix -o Makefile bat.pro @@ -48,6 +48,7 @@ OBJECTS_DIR = ./ SOURCES = main.cpp \ bat_conf.cpp \ mainwin.cpp \ + qstd.cpp \ console/authenticate.cpp \ console/console.cpp \ restore/brestore.cpp moc_mainwin.cpp \ @@ -57,6 +58,7 @@ SOURCES = main.cpp \ OBJECTS = main.o \ bat_conf.o \ mainwin.o \ + qstd.o \ authenticate.o \ console.o \ brestore.o \ @@ -154,7 +156,7 @@ qmake: FORCE dist: @$(CHK_DIR_EXISTS) .tmp/bat1.0.0 || $(MKDIR) .tmp/bat1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/bat1.0.0/ && $(COPY_FILE) --parents mainwin.h bat.h bat_conf.h console/console.h restore/restore.h .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.qrc .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.cpp bat_conf.cpp mainwin.cpp console/authenticate.cpp console/console.cpp restore/brestore.cpp .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.ui label.ui console/console.ui restore/brestore.ui .tmp/bat1.0.0/ && (cd `dirname .tmp/bat1.0.0` && $(TAR) bat1.0.0.tar bat1.0.0 && $(COMPRESS) bat1.0.0.tar) && $(MOVE) `dirname .tmp/bat1.0.0`/bat1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/bat1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/bat1.0.0/ && $(COPY_FILE) --parents mainwin.h bat.h bat_conf.h qstd.h console/console.h restore/restore.h .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.qrc .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.cpp bat_conf.cpp mainwin.cpp qstd.cpp console/authenticate.cpp console/console.cpp restore/brestore.cpp .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.ui label.ui console/console.ui restore/brestore.ui .tmp/bat1.0.0/ && (cd `dirname .tmp/bat1.0.0` && $(TAR) bat1.0.0.tar bat1.0.0 && $(COMPRESS) bat1.0.0.tar) && $(MOVE) `dirname .tmp/bat1.0.0`/bat1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/bat1.0.0 yaccclean: @@ -244,7 +246,8 @@ compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_image_coll main.o: main.cpp bat.h \ mainwin.h \ ui_main.h \ - bat_conf.h + bat_conf.h \ + qstd.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp bat_conf.o: bat_conf.cpp bat_conf.h @@ -253,19 +256,25 @@ bat_conf.o: bat_conf.cpp bat_conf.h mainwin.o: mainwin.cpp bat.h \ mainwin.h \ ui_main.h \ - bat_conf.h + bat_conf.h \ + qstd.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwin.o mainwin.cpp +qstd.o: qstd.cpp qstd.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qstd.o qstd.cpp + authenticate.o: console/authenticate.cpp bat.h \ mainwin.h \ ui_main.h \ - bat_conf.h + bat_conf.h \ + qstd.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o authenticate.o console/authenticate.cpp console.o: console/console.cpp bat.h \ mainwin.h \ ui_main.h \ bat_conf.h \ + qstd.h \ console/console.h \ ui_console.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o console.o console/console.cpp @@ -274,6 +283,7 @@ brestore.o: restore/brestore.cpp bat.h \ mainwin.h \ ui_main.h \ bat_conf.h \ + qstd.h \ restore/restore.h \ ui_brestore.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o brestore.o restore/brestore.cpp diff --git a/bacula/src/qt-console/bat.h b/bacula/src/qt-console/bat.h index 5168e0a035..06b4fdb578 100644 --- a/bacula/src/qt-console/bat.h +++ b/bacula/src/qt-console/bat.h @@ -8,6 +8,9 @@ #include "bat_conf.h" #include "jcr.h" #include "console.h" +#include "qstd.h" + +using namespace qstd; extern MainWin *mainWin; extern QApplication *app; diff --git a/bacula/src/qt-console/bat.pro b/bacula/src/qt-console/bat.pro index 19efb18cbf..db24cd27ee 100644 --- a/bacula/src/qt-console/bat.pro +++ b/bacula/src/qt-console/bat.pro @@ -20,8 +20,8 @@ FORMS += console/console.ui FORMS += restore/brestore.ui -HEADERS += mainwin.h bat.h bat_conf.h -SOURCES += main.cpp bat_conf.cpp mainwin.cpp +HEADERS += mainwin.h bat.h bat_conf.h qstd.h +SOURCES += main.cpp bat_conf.cpp mainwin.cpp qstd.cpp # Console HEADERS += console/console.h diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 48a491189c..2cee7bbe8f 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -94,11 +94,11 @@ void Console::connect() 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 @@ void Console::connect() 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 @@ void Console::update_cursor() 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 @@ void Console::write_dir(const char *msg) } } +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) { diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index 924c728a3d..652a89df8d 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -26,10 +26,24 @@ public: 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); diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index dfcf7027bd..04d666287e 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -40,8 +40,6 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) mainWin = this; setupUi(this); /* Setup UI defined by main.ui (designer) */ - statusBar()->showMessage("Director not connected. Click on connect button."); - m_console = new Console(stackedWidget); stackedWidget->setCurrentIndex(0); @@ -49,36 +47,13 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) createConnections(); - readSettings(); -} + this->show(); -#ifdef xxx - job_list = get_and_fill_combo(run_dialog, "combo_job", ".jobs"); - client_list = get_and_fill_combo(run_dialog, "combo_client", ".clients"); - fileset_list = get_and_fill_combo(run_dialog, "combo_fileset", ".filesets"); - messages_list = get_and_fill_combo(run_dialog, "combo_messages", ".msgs"); - pool_list = get_and_fill_combo(run_dialog, "combo_pool", ".pools"); - storage_list = get_and_fill_combo(run_dialog, "combo_storage", ".storage"); - type_list = get_and_fill_combo(run_dialog, "combo_type", ".types"); - level_list = get_and_fill_combo(run_dialog, "combo_level", ".levels"); - -static GList *get_list(char *cmd) -{ - GList *options; - char *msg; - - options = NULL; - write_director(cmd); - while (bnet_recv(UA_sock) > 0) { - strip_trailing_junk(UA_sock->msg); - msg = (char *)malloc(strlen(UA_sock->msg) + 1); - strcpy(msg, UA_sock->msg); - options = g_list_append(options, msg); - } - return options; + readSettings(); + m_console->connect(); } -#endif + void MainWin::createConnections() {