]> git.sur5r.net Git - bacula/bacula/commitdiff
Implement command output lists
authorKern Sibbald <kern@sibbald.com>
Sun, 4 Feb 2007 16:29:53 +0000 (16:29 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 4 Feb 2007 16:29:53 +0000 (16:29 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4097 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/qt-console/Makefile
bacula/src/qt-console/bat.h
bacula/src/qt-console/bat.pro
bacula/src/qt-console/console/console.cpp
bacula/src/qt-console/console/console.h
bacula/src/qt-console/mainwin.cpp

index 2855bb4935ccde3cb158217f60157081cbbf4d2d..ec897f84ef61f571bff8f064d2203a1fb6da26e4 100644 (file)
@@ -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
index 5168e0a0352e1d755300f0f94e20a7e0fa4e9b8c..06b4fdb57850653d6202ad4155ab042d27582de4 100644 (file)
@@ -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;
index 19efb18cbf65feb03c5a5c40ce3f07cfd5e39560..db24cd27ee96f70b3ebc6e08776d8f75675484e3 100644 (file)
@@ -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
index 48a491189c2e9cf17a7a2ae4e178f4786ef77f2a..2cee7bbe8fda13cf3954a9b41e1786d03ce0837b 100644 (file)
@@ -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)
 {
index 924c728a3d8e97e118884963e745a66f2420c18f..652a89df8d04a9759e5ea190ef7dd36d0f51b1ac 100644 (file)
@@ -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);
 
index dfcf7027bd373adb02ec9ee7fe35c2cd1755b0f8..04d666287e0f26cf26b3c1a98d5f02b9cd9deb15 100644 (file)
@@ -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()
 {