From e6b90f9266d8497ea090db13e6dd879bdef43c4e Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 21 Feb 2007 10:53:36 +0000 Subject: [PATCH] Implement first cut of job defaults in run dialog git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4228 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/Makefile | 60 ++++++++++++----- bacula/src/qt-console/bat.h | 3 - bacula/src/qt-console/bat.pro | 4 +- .../src/qt-console/console/authenticate.cpp | 12 ++-- bacula/src/qt-console/console/console.cpp | 65 +++++++++++-------- bacula/src/qt-console/console/console.h | 23 +++++-- bacula/src/qt-console/mainwin.cpp | 6 +- bacula/src/qt-console/run/run.cpp | 12 +++- 8 files changed, 124 insertions(+), 61 deletions(-) diff --git a/bacula/src/qt-console/Makefile b/bacula/src/qt-console/Makefile index a36f765e48..6456ade6ac 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: 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 diff --git a/bacula/src/qt-console/bat.h b/bacula/src/qt-console/bat.h index e54064e040..1138677199 100644 --- a/bacula/src/qt-console/bat.h +++ b/bacula/src/qt-console/bat.h @@ -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_ */ diff --git a/bacula/src/qt-console/bat.pro b/bacula/src/qt-console/bat.pro index 7959015474..c61f9273e1 100644 --- a/bacula/src/qt-console/bat.pro +++ b/bacula/src/qt-console/bat.pro @@ -1,6 +1,6 @@ ###################################################################### -# Automatically generated by qmake (2.01a) Thu Jan 18 09:40:56 2007 -###################################################################### + +CONFIG += qt debug TEMPLATE = app TARGET = bat diff --git a/bacula/src/qt-console/console/authenticate.cpp b/bacula/src/qt-console/console/authenticate.cpp index d1ff85be97..dd5b3533a6 100644 --- a/bacula/src/qt-console/console/authenticate.cpp +++ b/bacula/src/qt-console/console/authenticate.cpp @@ -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, "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; } diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 73c2657834..9048774c5b 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -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); diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index c693c9ed6e..be9509cee4 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -42,8 +42,21 @@ #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; diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index a75ec9b117..6ddd36d201 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -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(); } diff --git a/bacula/src/qt-console/run/run.cpp b/bacula/src/qt-console/run/run.cpp index 7711c98c7c..e8ac824b3e 100644 --- a/bacula/src/qt-console/run/run.cpp +++ b/bacula/src/qt-console/run/run.cpp @@ -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; } -- 2.39.5