]> git.sur5r.net Git - bacula/bacula/commitdiff
Implement first cut of job defaults in run dialog
authorKern Sibbald <kern@sibbald.com>
Wed, 21 Feb 2007 10:53:36 +0000 (10:53 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 21 Feb 2007 10:53:36 +0000 (10:53 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4228 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/authenticate.cpp
bacula/src/qt-console/console/console.cpp
bacula/src/qt-console/console/console.h
bacula/src/qt-console/mainwin.cpp
bacula/src/qt-console/run/run.cpp

index a36f765e4878d3fa78199206794dc8683718f53e..6456ade6ac478585ad6a2df1d63e311ddbd8ed87 100644 (file)
@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: bat
-# Generated by qmake (2.01a) (Qt 4.2.1) on: Sun Feb 11 21:47:13 2007
+# Generated by qmake (2.01a) (Qt 4.2.1) on: Wed Feb 21 10:11:16 2007
 # Project:  bat.pro
 # Template: app
 # Command: /usr/bin/qmake -unix -o Makefile bat.pro
@@ -12,9 +12,9 @@ CC            = gcc
 CXX           = g++
 LEX           = flex
 YACC          = yacc
-DEFINES       = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
-CFLAGS        = -pipe -O2 -Wall -W -D_REENTRANT  $(DEFINES)
-CXXFLAGS      = -pipe -O2 -Wall -W -D_REENTRANT  $(DEFINES)
+DEFINES       = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
+CFLAGS        = -pipe -g -D_REENTRANT -Wall -W  $(DEFINES)
+CXXFLAGS      = -pipe -g -D_REENTRANT -Wall -W  $(DEFINES)
 LEXFLAGS      = 
 YACCFLAGS     = -d
 INCPATH       = -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -Iconsole -Irestore -I.. -Imoc -I.
@@ -84,12 +84,12 @@ DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
                /usr/share/qt4/mkspecs/features/qt_config.prf \
                /usr/share/qt4/mkspecs/features/exclusive_builds.prf \
                /usr/share/qt4/mkspecs/features/default_pre.prf \
-               /usr/share/qt4/mkspecs/features/release.prf \
+               /usr/share/qt4/mkspecs/features/debug.prf \
                /usr/share/qt4/mkspecs/features/default_post.prf \
-               /usr/share/qt4/mkspecs/features/warn_on.prf \
                /usr/share/qt4/mkspecs/features/qt.prf \
                /usr/share/qt4/mkspecs/features/unix/thread.prf \
                /usr/share/qt4/mkspecs/features/moc.prf \
+               /usr/share/qt4/mkspecs/features/warn_on.prf \
                /usr/share/qt4/mkspecs/features/resources.prf \
                /usr/share/qt4/mkspecs/features/uic.prf \
                bat.pro
@@ -132,12 +132,12 @@ Makefile: bat.pro  /usr/share/qt4/mkspecs/default/qmake.conf /usr/share/qt4/mksp
                /usr/share/qt4/mkspecs/features/qt_config.prf \
                /usr/share/qt4/mkspecs/features/exclusive_builds.prf \
                /usr/share/qt4/mkspecs/features/default_pre.prf \
-               /usr/share/qt4/mkspecs/features/release.prf \
+               /usr/share/qt4/mkspecs/features/debug.prf \
                /usr/share/qt4/mkspecs/features/default_post.prf \
-               /usr/share/qt4/mkspecs/features/warn_on.prf \
                /usr/share/qt4/mkspecs/features/qt.prf \
                /usr/share/qt4/mkspecs/features/unix/thread.prf \
                /usr/share/qt4/mkspecs/features/moc.prf \
+               /usr/share/qt4/mkspecs/features/warn_on.prf \
                /usr/share/qt4/mkspecs/features/resources.prf \
                /usr/share/qt4/mkspecs/features/uic.prf \
                /usr/lib/libQtGui.prl \
@@ -151,12 +151,12 @@ Makefile: bat.pro  /usr/share/qt4/mkspecs/default/qmake.conf /usr/share/qt4/mksp
 /usr/share/qt4/mkspecs/features/qt_config.prf:
 /usr/share/qt4/mkspecs/features/exclusive_builds.prf:
 /usr/share/qt4/mkspecs/features/default_pre.prf:
-/usr/share/qt4/mkspecs/features/release.prf:
+/usr/share/qt4/mkspecs/features/debug.prf:
 /usr/share/qt4/mkspecs/features/default_post.prf:
-/usr/share/qt4/mkspecs/features/warn_on.prf:
 /usr/share/qt4/mkspecs/features/qt.prf:
 /usr/share/qt4/mkspecs/features/unix/thread.prf:
 /usr/share/qt4/mkspecs/features/moc.prf:
+/usr/share/qt4/mkspecs/features/warn_on.prf:
 /usr/share/qt4/mkspecs/features/resources.prf:
 /usr/share/qt4/mkspecs/features/uic.prf:
 /usr/lib/libQtGui.prl:
@@ -198,6 +198,10 @@ moc/moc_mainwin.cpp: ui_main.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
+               restore/restore.h \
+               ui_brestore.h \
+               ui_restore.h \
+               ui_prerestore.h \
                mainwin.h \
                /usr/bin/moc
        /usr/bin/moc $(DEFINES) $(INCPATH) mainwin.h -o moc/moc_mainwin.cpp
@@ -285,6 +289,10 @@ obj/main.o: main.cpp bat.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
+               restore/restore.h \
+               ui_brestore.h \
+               ui_restore.h \
+               ui_prerestore.h \
                bat_conf.h \
                qstd.h
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/main.o main.cpp
@@ -299,6 +307,10 @@ obj/mainwin.o: mainwin.cpp bat.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
+               restore/restore.h \
+               ui_brestore.h \
+               ui_restore.h \
+               ui_prerestore.h \
                bat_conf.h \
                qstd.h
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/mainwin.o mainwin.cpp
@@ -313,6 +325,10 @@ obj/authenticate.o: console/authenticate.cpp bat.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
+               restore/restore.h \
+               ui_brestore.h \
+               ui_restore.h \
+               ui_prerestore.h \
                bat_conf.h \
                qstd.h
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/authenticate.o console/authenticate.cpp
@@ -324,6 +340,10 @@ obj/console.o: console/console.cpp bat.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
+               restore/restore.h \
+               ui_brestore.h \
+               ui_restore.h \
+               ui_prerestore.h \
                bat_conf.h \
                qstd.h \
                console/console.h \
@@ -337,12 +357,12 @@ obj/restore.o: restore/restore.cpp bat.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
-               bat_conf.h \
-               qstd.h \
                restore/restore.h \
                ui_brestore.h \
                ui_restore.h \
-               ui_prerestore.h
+               ui_prerestore.h \
+               bat_conf.h \
+               qstd.h
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/restore.o restore/restore.cpp
 
 obj/brestore.o: restore/brestore.cpp bat.h \
@@ -352,12 +372,12 @@ obj/brestore.o: restore/brestore.cpp bat.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
-               bat_conf.h \
-               qstd.h \
                restore/restore.h \
                ui_brestore.h \
                ui_restore.h \
-               ui_prerestore.h
+               ui_prerestore.h \
+               bat_conf.h \
+               qstd.h
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/brestore.o restore/brestore.cpp
 
 obj/label.o: label/label.cpp bat.h \
@@ -367,6 +387,10 @@ obj/label.o: label/label.cpp bat.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
+               restore/restore.h \
+               ui_brestore.h \
+               ui_restore.h \
+               ui_prerestore.h \
                bat_conf.h \
                qstd.h
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/label.o label/label.cpp
@@ -378,6 +402,10 @@ obj/run.o: run/run.cpp bat.h \
                ui_label.h \
                run/run.h \
                ui_run.h \
+               restore/restore.h \
+               ui_brestore.h \
+               ui_restore.h \
+               ui_prerestore.h \
                bat_conf.h \
                qstd.h
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o obj/run.o run/run.cpp
index e54064e040974d91e664a2265f625927f0ddb57c..1138677199d98edae4ea5a6625ed90999a50117b 100644 (file)
@@ -47,9 +47,6 @@ using namespace qstd;
 extern MainWin *mainWin;
 extern QApplication *app;
 
-void set_textf(const char *fmt, ...);
-void set_text(const char *buf);
-
 int bvsnprintf(char *str, int32_t size, const char *format, va_list ap);
 
 #endif /* _BAT_H_ */
index 7959015474b18266a91d7e9e38a01142ff6c6664..c61f9273e1022476dd831a0bdecf91c59344f765 100644 (file)
@@ -1,6 +1,6 @@
 ######################################################################
-# Automatically generated by qmake (2.01a) Thu Jan 18 09:40:56 2007
-######################################################################
+
+CONFIG += qt debug
 
 TEMPLATE = app
 TARGET = bat
index d1ff85be970f744030327e8120434918c83d3530..dd5b3533a6af3dcb999f716b919835fa076ae1cf 100644 (file)
@@ -82,8 +82,8 @@ bool Console::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
        !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
       stop_bsock_timer(tid);
       printf(_("%s: Director authorization problem.\n"), my_name);
-      set_text(_("Director authorization problem.\n"));    
-      set_text(_(
+      display_text(_("Director authorization problem.\n"));    
+      display_text(_(
        "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"));
       return false;
    }
@@ -91,20 +91,20 @@ bool Console::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
    Dmsg1(6, ">dird: %s", dir->msg);
    if (bnet_recv(dir) <= 0) {
       stop_bsock_timer(tid);
-      set_textf(_("Bad response to Hello command: ERR=%s\n"),
+      display_textf(_("Bad response to Hello command: ERR=%s\n"),
          bnet_strerror(dir));
       printf(_("%s: Bad response to Hello command: ERR=%s\n"),
          my_name, bnet_strerror(dir));
-      set_text(_("The Director is probably not running.\n"));
+      display_text(_("The Director is probably not running.\n"));
       return false;
    }
   stop_bsock_timer(tid);
    Dmsg1(10, "<dird: %s", dir->msg);
    if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
-      set_text(_("Director rejected Hello command\n"));    
+      display_text(_("Director rejected Hello command\n"));    
       return false;
    } else {
-      set_text(dir->msg);
+      display_text(dir->msg);
    }
    return true;
 }
index 73c2657834c08a259694795836b9afb2e759ea66..9048774c5b360443d90110c34a8f66769da1f8c0 100644 (file)
@@ -84,6 +84,15 @@ Console::Console(QStackedWidget *parent)
 
 }
 
+/* Terminate any open socket */
+void Console::terminate()
+{
+   if (m_sock) {
+      m_sock->close();
+      m_sock = NULL;
+   }
+}
+
 /*
  * Connect to Director. If there are more than one, put up
  * a modal dialog so that the user chooses one.
@@ -106,7 +115,7 @@ void Console::connect()
    memset(&jcr, 0, sizeof(jcr));
 
    mainWin->set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
-   set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
+   display_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
 
    /* Give GUI a chance */
    app->processEvents();
@@ -131,7 +140,7 @@ void Console::connect()
    jcr.dir_bsock = m_sock;
 
    if (!authenticate_director(&jcr, m_dir, cons)) {
-      set_text(m_sock->msg);
+      display_text(m_sock->msg);
       return;
    }
 
@@ -189,7 +198,7 @@ bool Console::get_job_defaults(struct job_defaults &job_defs)
    char *def;
 
    setEnabled(false);
-   bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job_defs.job_name);
+   bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job_defs.job_name.toUtf8().data());
    write(cmd);
    while ((stat = read()) > 0) {
       def = strchr(msg(), '=');
@@ -201,45 +210,45 @@ bool Console::get_job_defaults(struct job_defaults &job_defs)
       strip_trailing_junk(def);
 
       if (strcmp(msg(), "job") == 0) {
-         if (strcmp(def, job_defs.job_name) != 0) {
+         if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0) {
             goto bail_out;
          }
          continue;
       }
       if (strcmp(msg(), "pool") == 0) {
-         bstrncpy(job_defs.pool_name, def, sizeof(job_defs.pool_name));
+         job_defs.pool_name = def;
          continue;
       }
       if (strcmp(msg(), "messages") == 0) {
-         bstrncpy(job_defs.messages_name, def, sizeof(job_defs.messages_name));
+         job_defs.messages_name = def;
          continue;
       }
       if (strcmp(msg(), "client") == 0) {
-         bstrncpy(job_defs.client_name, def, sizeof(job_defs.client_name));
+         job_defs.client_name = def;
          continue;
       }
       if (strcmp(msg(), "storage") == 0) {
-         bstrncpy(job_defs.store_name, def, sizeof(job_defs.store_name));
+         job_defs.store_name = def;
          continue;
       }
       if (strcmp(msg(), "where") == 0) {
-         bstrncpy(job_defs.where, def, sizeof(job_defs.where));
+         job_defs.where = def;
          continue;
       }
       if (strcmp(msg(), "level") == 0) {
-         bstrncpy(job_defs.level, def, sizeof(job_defs.level));
+         job_defs.level = def;
          continue;
       }
       if (strcmp(msg(), "type") == 0) {
-         bstrncpy(job_defs.type, def, sizeof(job_defs.type));
+         job_defs.type = def;
          continue;
       }
       if (strcmp(msg(), "fileset") == 0) {
-         bstrncpy(job_defs.fileset_name, def, sizeof(job_defs.fileset_name));
+         job_defs.fileset_name = def;
          continue;
       }
       if (strcmp(msg(), "catalog") == 0) {
-         bstrncpy(job_defs.catalog_name, def, sizeof(job_defs.catalog_name));
+         job_defs.catalog_name = def;
          continue;
       }
       if (strcmp(msg(), "enabled") == 0) {
@@ -249,10 +258,13 @@ bool Console::get_job_defaults(struct job_defaults &job_defs)
    }
    bsnprintf(cmd, sizeof(cmd), "job=%s pool=%s client=%s storage=%s where=%s\n"
       "level=%s type=%s fileset=%s catalog=%s enabled=%d\n",
-      job_defs.job_name, job_defs.pool_name, job_defs.client_name, 
-      job_defs.pool_name, job_defs.messages_name, job_defs.store_name,
-      job_defs.where, job_defs.level, job_defs.type, job_defs.fileset_name,
-      job_defs.catalog_name, job_defs.enabled);
+      job_defs.job_name.toUtf8().data(), job_defs.pool_name.toUtf8().data(), 
+      job_defs.client_name.toUtf8().data(), 
+      job_defs.pool_name.toUtf8().data(), job_defs.messages_name.toUtf8().data(), 
+      job_defs.store_name.toUtf8().data(),
+      job_defs.where.toUtf8().data(), job_defs.level.toUtf8().data(), 
+      job_defs.type.toUtf8().data(), job_defs.fileset_name.toUtf8().data(),
+      job_defs.catalog_name.toUtf8().data(), job_defs.enabled);
 
    setEnabled(true);
    return true;
@@ -264,13 +276,14 @@ bail_out:
 
 
 /*
- * Save user settings
+ * Save user settings associated with this console
  */
 void Console::writeSettings()
 {
    QFont font = get_font();
 
    QSettings settings("bacula.org", "bat");
+   /* ***FIXME*** make console name unique */
    settings.beginGroup("Console");
    settings.setValue("consoleFont", font.family());
    settings.setValue("consolePointSize", font.pointSize());
@@ -279,7 +292,7 @@ void Console::writeSettings()
 }
 
 /*
- * Read and restore user settings
+ * Read and restore user settings associated with this console
  */
 void Console::readSettings()
 { 
@@ -323,7 +336,7 @@ void Console::status_dir()
 /*
  * Put text into the console window
  */
-void Console::set_textf(const char *fmt, ...)
+void Console::display_textf(const char *fmt, ...)
 {
    va_list arg_ptr;
    char buf[1000];
@@ -331,17 +344,17 @@ void Console::set_textf(const char *fmt, ...)
    va_start(arg_ptr, fmt);
    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
    va_end(arg_ptr);
-   set_text(buf);
+   display_text(buf);
 }
 
-void Console::set_text(const QString buf)
+void Console::display_text(const QString buf)
 {
    m_cursor->movePosition(QTextCursor::End);
    m_cursor->insertText(buf);
 }
 
 
-void Console::set_text(const char *buf)
+void Console::display_text(const char *buf)
 {
    m_cursor->movePosition(QTextCursor::End);
    m_cursor->insertText(buf);
@@ -424,14 +437,14 @@ void Console::read_dir(int fd)
    stat = bnet_recv(m_sock);
    if (stat >= 0) {
       if (m_at_prompt) {
-         set_text("\n");
+         display_text("\n");
          m_at_prompt = false;
       }
-      set_text(m_sock->msg);
+      display_text(m_sock->msg);
       return;
    }
    if (is_bnet_stop(m_sock)) {         /* error or term request */
-      bnet_close(m_sock);
+      m_sock->close();
       m_sock = NULL;
       mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
       QBrush redBrush(Qt::red);
index c693c9ed6e7f70ae1da40179babad78ec9f69efc..be9509cee4f0a4ca2a935a496f26f1c31262b738 100644 (file)
 #define MAX_NAME_LENGTH 128
 #endif
 
+/*
+ * Structure for obtaining the defaults for a job
+ */
 struct job_defaults {
-   char job_name[MAX_NAME_LENGTH];
+   QString job_name;
+   QString pool_name;
+   QString messages_name;
+   QString client_name;
+   QString store_name;
+   QString where;
+   QString level;
+   QString type;
+   QString fileset_name;
+   QString catalog_name;
+#ifdef xxx
    char pool_name[MAX_NAME_LENGTH];
    char messages_name[MAX_NAME_LENGTH];
    char client_name[MAX_NAME_LENGTH];
@@ -53,6 +66,7 @@ struct job_defaults {
    char type[MAX_NAME_LENGTH];
    char fileset_name[MAX_NAME_LENGTH];
    char catalog_name[MAX_NAME_LENGTH];
+#endif
    bool enabled;
 };
 
@@ -67,9 +81,9 @@ class Console : public QWidget, public Ui::ConsoleForm
 
 public:
    Console(QStackedWidget *parent);
-   void set_text(const char *buf);
-   void set_text(const QString buf);
-   void set_textf(const char *fmt, ...);
+   void display_text(const char *buf);
+   void display_text(const QString buf);
+   void display_textf(const char *fmt, ...);
    void update_cursor(void);
    void write_dir(const char *buf);
    bool authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
@@ -81,6 +95,7 @@ public:
    void setEnabled(bool enable) { m_notifier->setEnabled(enable); };
    QStringList get_list(char *cmd);
    bool get_job_defaults(struct job_defaults &);
+   void terminate();
 
    QStringList job_list;
    QStringList client_list;
index a75ec9b1175fd5ebdfd7fcffdd6a8351079663cf..6ddd36d20108392630fad98cbabb675716317c22 100644 (file)
@@ -86,9 +86,9 @@ void MainWin::createConnections()
  */
 void MainWin::closeEvent(QCloseEvent *event)
 {
-   /* ***FIXME*** close any open sockets */
    writeSettings();
    m_console->writeSettings();
+   m_console->terminate();
    event->accept();
 }
 
@@ -158,7 +158,7 @@ void MainWin::input_line()
    QString cmdStr = lineEdit->text();    /* Get the text */
    lineEdit->clear();                    /* clear the lineEdit box */
    if (m_console->is_connected()) {
-      m_console->set_text(cmdStr + "\n");
+      m_console->display_text(cmdStr + "\n");
       m_console->write_dir(cmdStr.toUtf8().data());         /* send to dir */
    } else {
       set_status("Director not connected. Click on connect button.");
@@ -189,7 +189,7 @@ void MainWin::set_statusf(const char *fmt, ...)
 
 void MainWin::set_status_ready()
 {
-   set_status("Ready");
+   set_status(" Ready");
 // set_scroll_bar_to_end();
 }
 
index 7711c98c7c23fed00e6af7ddd7f84839f2d4c660..e8ac824b3eed1fa00d910fcb8c07e922c84fcb6f 100644 (file)
@@ -39,6 +39,8 @@
 runDialog::runDialog(Console *console)
 {
    QDateTime dt;
+   job_defaults job_defs;
+
    m_console = console;
    setupUi(this);
    jobCombo->addItems(console->job_list);
@@ -48,6 +50,14 @@ runDialog::runDialog(Console *console)
    poolCombo->addItems(console->pool_list);
    storageCombo->addItems(console->storage_list);
    dateTimeEdit->setDateTime(dt.currentDateTime());
+   job_defs.job_name = jobCombo->currentText();
+   if (console->get_job_defaults(job_defs)) {
+      filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
+      levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
+      clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
+      poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
+      storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
+   }
    this->show();
 }
 
@@ -71,7 +81,7 @@ void runDialog::accept()
              prioritySpin->value());
 
 // m_console->write(cmd);
-   m_console->set_text(cmd);
+   m_console->display_text(cmd);
    delete this;
 }