From 7844ddd81518905c3ba2a2b3786add0b599b890e Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 28 Jan 2007 13:05:41 +0000 Subject: [PATCH] Implement Console class git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4064 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/Makefile | 61 ++++-- bacula/src/qt-console/bat.h | 8 +- bacula/src/qt-console/bat.pro | 4 +- bacula/src/qt-console/console.cpp | 192 ++++++++---------- bacula/src/qt-console/console.h | 31 ++- bacula/src/qt-console/main.cpp | 10 +- .../{mainwindow.cpp => mainwin.cpp} | 24 +-- .../qt-console/{mainwindow.h => mainwin.h} | 13 +- 8 files changed, 162 insertions(+), 181 deletions(-) rename bacula/src/qt-console/{mainwindow.cpp => mainwin.cpp} (84%) rename bacula/src/qt-console/{mainwindow.h => mainwin.h} (88%) diff --git a/bacula/src/qt-console/Makefile b/bacula/src/qt-console/Makefile index fe961c9a96..0023e8cae9 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 Jan 27 21:58:01 2007 +# Generated by qmake (2.01a) (Qt 4.2.1) on: Sun Jan 28 13:54:36 2007 # Project: bat.pro # Template: app # Command: /usr/bin/qmake -unix -o Makefile bat.pro @@ -48,13 +48,17 @@ OBJECTS_DIR = ./ SOURCES = main.cpp \ authenticate.cpp \ bat_conf.cpp \ - mainwindow.cpp moc_mainwindow.cpp \ + mainwin.cpp \ + console.cpp moc_mainwin.cpp \ + moc_console.cpp \ qrc_main.cpp OBJECTS = main.o \ authenticate.o \ bat_conf.o \ - mainwindow.o \ - moc_mainwindow.o \ + mainwin.o \ + console.o \ + moc_mainwin.o \ + moc_console.o \ qrc_main.o DIST = /usr/share/qt4/mkspecs/common/unix.conf \ /usr/share/qt4/mkspecs/common/g++.conf \ @@ -146,7 +150,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 mainwindow.h bat.h bat_conf.h .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.qrc .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.cpp authenticate.cpp bat_conf.cpp mainwindow.cpp .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.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 console.h .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.qrc .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.cpp authenticate.cpp bat_conf.cpp mainwin.cpp console.cpp .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.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: @@ -170,13 +174,17 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean mocables: compiler_moc_header_make_all compiler_moc_source_make_all -compiler_moc_header_make_all: moc_mainwindow.cpp +compiler_moc_header_make_all: moc_mainwin.cpp moc_console.cpp compiler_moc_header_clean: - -$(DEL_FILE) moc_mainwindow.cpp -moc_mainwindow.cpp: ui_main.h \ - mainwindow.h \ + -$(DEL_FILE) moc_mainwin.cpp moc_console.cpp +moc_mainwin.cpp: ui_main.h \ + mainwin.h \ /usr/bin/moc - /usr/bin/moc $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp + /usr/bin/moc $(DEFINES) $(INCPATH) mainwin.h -o moc_mainwin.cpp + +moc_console.cpp: console.h \ + /usr/bin/moc + /usr/bin/moc $(DEFINES) $(INCPATH) console.h -o moc_console.cpp compiler_rcc_make_all: qrc_main.cpp compiler_rcc_clean: @@ -208,28 +216,41 @@ compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_image_coll ####### Compile main.o: main.cpp bat.h \ - mainwindow.h \ + mainwin.h \ ui_main.h \ - bat_conf.h + bat_conf.h \ + console.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp authenticate.o: authenticate.cpp bat.h \ - mainwindow.h \ + mainwin.h \ ui_main.h \ - bat_conf.h + bat_conf.h \ + console.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o authenticate.o authenticate.cpp bat_conf.o: bat_conf.cpp bat_conf.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bat_conf.o bat_conf.cpp -mainwindow.o: mainwindow.cpp bat.h \ - mainwindow.h \ +mainwin.o: mainwin.cpp bat.h \ + mainwin.h \ ui_main.h \ - bat_conf.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp + bat_conf.h \ + console.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwin.o mainwin.cpp + +console.o: console.cpp bat.h \ + mainwin.h \ + ui_main.h \ + bat_conf.h \ + console.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o console.o console.cpp + +moc_mainwin.o: moc_mainwin.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwin.o moc_mainwin.cpp -moc_mainwindow.o: moc_mainwindow.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp +moc_console.o: moc_console.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_console.o moc_console.cpp qrc_main.o: qrc_main.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_main.o qrc_main.cpp diff --git a/bacula/src/qt-console/bat.h b/bacula/src/qt-console/bat.h index 906d931f9c..5168e0a035 100644 --- a/bacula/src/qt-console/bat.h +++ b/bacula/src/qt-console/bat.h @@ -1,16 +1,16 @@ #ifndef _BAT_H_ +#define _BAT_H_ -#include "mainwindow.h" +#include "mainwin.h" #include "config.h" #include "bacula.h" #include "bat_conf.h" #include "jcr.h" +#include "console.h" -extern MainWindow *mainWin; +extern MainWin *mainWin; extern QApplication *app; -extern BSOCK *UA_sock; - void set_textf(const char *fmt, ...); void set_text(const char *buf); diff --git a/bacula/src/qt-console/bat.pro b/bacula/src/qt-console/bat.pro index 4b582888cc..e7e092f31b 100644 --- a/bacula/src/qt-console/bat.pro +++ b/bacula/src/qt-console/bat.pro @@ -14,6 +14,6 @@ RESOURCES = main.qrc # Input FORMS += main.ui -HEADERS += mainwindow.h bat.h bat_conf.h +HEADERS += mainwin.h bat.h bat_conf.h console.h SOURCES += main.cpp authenticate.cpp bat_conf.cpp -SOURCES += mainwindow.cpp +SOURCES += mainwin.cpp console.cpp diff --git a/bacula/src/qt-console/console.cpp b/bacula/src/qt-console/console.cpp index 2f288439b2..46fff3c01e 100644 --- a/bacula/src/qt-console/console.cpp +++ b/bacula/src/qt-console/console.cpp @@ -27,7 +27,7 @@ */ /* - * Connect to a Bacula daemon + * Console Class * * Kern Sibbald, January MMVI * @@ -36,50 +36,42 @@ #include "bat.h" #include "console.h" +Console::Console() +{ + QTreeWidgetItem *item, *topItem; + QTreeWidget *treeWidget = mainWin->treeWidget; + + m_textEdit = mainWin->textEdit; /* our console screen */ + + /* Dummy setup of treeWidget */ + treeWidget->clear(); + treeWidget->setColumnCount(1); + treeWidget->setHeaderLabel("Selection"); + topItem = new QTreeWidgetItem(treeWidget); + topItem->setText(0, "Rufus"); + item = new QTreeWidgetItem(topItem); + item->setText(0, "Console"); + item->setText(1, "0"); + item = new QTreeWidgetItem(topItem); + item->setText(0, "Restore"); + item->setText(1, "1"); + treeWidget->expandItem(topItem); +} + /* * Connect to Director. If there are more than one, put up * a modal dialog so that the user chooses one. */ -bool Console::connect(QWidget *textEdit) +bool Console::connect() { JCR jcr; - m_textEdit = textEdit; + m_textEdit = mainWin->textEdit; /* our console screen */ -#ifdef xxx - if (ndir > 1) { - LockRes(); - foreach_res(dir, R_DIRECTOR) { - dirs = g_list_append(dirs, dir->hdr.name); - } - UnlockRes(); - dir_dialog = create_SelectDirectorDialog(); - combo = lookup_widget(dir_dialog, "combo1"); - dir_select = lookup_widget(dir_dialog, "dirselect"); - if (dirs) { - gtk_combo_set_popdown_strings(GTK_COMBO(combo), dirs); - } - gtk_widget_show(dir_dialog); - gtk_main(); - - if (reply == OK) { - gchar *ecmd = gtk_editable_get_chars((GtkEditable *)dir_select, 0, -1); - dir = (DIRRES *)GetResWithName(R_DIRECTOR, ecmd); - if (ecmd) { - g_free(ecmd); /* release director name string */ - } - } - if (dirs) { - g_free(dirs); - } - gtk_widget_destroy(dir_dialog); - dir_dialog = NULL; - } else { -#endif - /* Just take the first Director */ - LockRes(); - m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); - UnlockRes(); + /* Just take the first Director */ + LockRes(); + m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); + UnlockRes(); if (!m_dir) { return false; @@ -87,113 +79,93 @@ bool Console::connect(QWidget *textEdit) memset(&jcr, 0, sizeof(jcr)); - set_statusf(_(" Connecting to Director %s:%d"), m_dir->address,dir->DIRport); - set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address,dir->DIRport); + 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); + /* Give GUI a chance */ + app->processEvents(); LockRes(); /* If cons==NULL, default console will be used */ CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL); UnlockRes(); -#ifdef xxx - char buf[1024]; - /* Initialize Console TLS context */ - if (cons && (cons->tls_enable || cons->tls_require)) { - /* Generate passphrase prompt */ - bsnprintf(buf, sizeof(buf), _("Passphrase for Console \"%s\" TLS private key: "), cons->hdr.name); - - /* Initialize TLS context: - * Args: CA certfile, CA certdir, Certfile, Keyfile, - * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */ - cons->tls_ctx = new_tls_context(cons->tls_ca_certfile, - cons->tls_ca_certdir, cons->tls_certfile, - cons->tls_keyfile, tls_pem_callback, &buf, NULL, true); - - if (!cons->tls_ctx) { - bsnprintf(buf, sizeof(buf), _("Failed to initialize TLS context for Console \"%s\".\n"), - dir->hdr.name); - set_text(buf, strlen(buf)); - terminate_console(0); - return true; - } - - } - - /* Initialize Director TLS context */ - if (dir->tls_enable || dir->tls_require) { - /* Generate passphrase prompt */ - bsnprintf(buf, sizeof(buf), _("Passphrase for Director \"%s\" TLS private key: "), dir->hdr.name); - - /* Initialize TLS context: - * Args: CA certfile, CA certdir, Certfile, Keyfile, - * Keyfile PEM Callback, Keyfile CB Userdata, DHfile, Verify Peer */ - dir->tls_ctx = new_tls_context(dir->tls_ca_certfile, - dir->tls_ca_certdir, dir->tls_certfile, - dir->tls_keyfile, tls_pem_callback, &buf, NULL, true); - - if (!dir->tls_ctx) { - bsnprintf(buf, sizeof(buf), _("Failed to initialize TLS context for Director \"%s\".\n"), - dir->hdr.name); - set_text(buf, strlen(buf)); - terminate_console(0); - return true; - } - } -#endif - m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address, NULL, m_dir->DIRport, 0); - if (m__sock == NULL) { + if (m_sock == NULL) { return false; } jcr.dir_bsock = m_sock; + if (!authenticate_director(&jcr, m_dir, cons)) { set_text(m_sock->msg); return false; } + /* Give GUI a chance */ + app->processEvents(); + set_status(_(" Initializing ...")); bnet_fsend(m_sock, "autodisplay on"); /* Read and display all initial messages */ while (bnet_recv(m_sock) > 0) { - set_text(UA_sock->msg); + set_text(m_sock->msg); } /* Give GUI a chance */ app->processEvents(); -#ifdef xxx - /* Fill the run_dialog combo boxes */ - 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"); - - /* Fill the label dialog combo boxes */ - fill_combo(label_dialog, "label_combo_storage", storage_list); - fill_combo(label_dialog, "label_combo_pool", pool_list); - - - /* Fill the restore_dialog combo boxes */ - fill_combo(restore_dialog, "combo_restore_job", job_list); - fill_combo(restore_dialog, "combo_restore_client", client_list); - fill_combo(restore_dialog, "combo_restore_fileset", fileset_list); - fill_combo(restore_dialog, "combo_restore_pool", pool_list); - fill_combo(restore_dialog, "combo_restore_storage", storage_list); -#endif + /* Query Directory for .jobs, .clients, .filesets, .msgs, + * .pools, .storage, .types, .levels, ... + */ set_status(_(" Connected")); return true; } +void Console::set_textf(const char *fmt, ...) +{ + va_list arg_ptr; + char buf[1000]; + int len; + va_start(arg_ptr, fmt); + len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr); + va_end(arg_ptr); + m_textEdit->append(buf); +} + +void Console::set_text(const char *buf) +{ + m_textEdit->append(buf); +} + +void Console::set_statusf(const char *fmt, ...) +{ + va_list arg_ptr; + char buf[1000]; + int len; + va_start(arg_ptr, fmt); + len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr); + va_end(arg_ptr); + set_status(buf); +} + +void Console::set_status_ready() +{ + mainWin->statusBar()->showMessage("Ready"); +// ready = true; +} + +void Console::set_status(const char *buf) +{ + mainWin->statusBar()->showMessage(buf); +// ready = false; +} + + #ifdef xxx void write_director(const gchar *msg) { diff --git a/bacula/src/qt-console/console.h b/bacula/src/qt-console/console.h index bf836b6b96..b5b8ba79e3 100644 --- a/bacula/src/qt-console/console.h +++ b/bacula/src/qt-console/console.h @@ -2,36 +2,31 @@ #ifndef _CONSOLE_H_ #define _CONSOLE_H_ -#include "mainwindow.h" -#include "config.h" -#include "bacula.h" -#include "console_conf.h" -#include "jcr.h" +#include -extern MainWindow *mainWin; -extern QApplication *app; +class DIRRES; +class BSOCK; +class JCR; +class CONRES; -class Console(QWidget *textEdit) +class Console : public QWidget { + Q_OBJECT public: Console(); bool connect(); -// void setDirector() -// void write(); -// void read(); void set_text(const char *buf); void set_textf(const char *fmt, ...); + void set_statusf(const char *fmt, ...); + void set_status_ready(); + void set_status(const char *buf); + private: - QWidget *m_textEdit; + QTextEdit *m_textEdit; DIRRES *m_dir; BSOCK *m_sock; }; - - -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); +extern int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); #endif /* _CONSOLE_H_ */ diff --git a/bacula/src/qt-console/main.cpp b/bacula/src/qt-console/main.cpp index 2da43403c9..0c802c7378 100644 --- a/bacula/src/qt-console/main.cpp +++ b/bacula/src/qt-console/main.cpp @@ -51,7 +51,7 @@ static int check_resources(); /* Static variables */ static char *configfile = NULL; -MainWindow *mainWin; +MainWin *mainWin; QApplication *app; BSOCK *UA_sock = NULL; @@ -67,9 +67,6 @@ int main(int argc, char *argv[]) app = new QApplication(argc, argv); app->setQuitOnLastWindowClosed(true); - mainWin = new MainWindow; - - mainWin->show(); #ifdef ENABLE_NLS setlocale(LC_ALL, ""); @@ -142,6 +139,9 @@ int main(int argc, char *argv[]) Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), configfile); } + mainWin = new MainWin; + mainWin->show(); + return app->exec(); } @@ -167,6 +167,7 @@ PROG_COPYRIGHT exit(1); } +#ifdef xxx /* * Call-back for reading a passphrase for an encrypted PEM file * This function uses getpass(), which uses a static buffer and is NOT thread-safe. @@ -185,6 +186,7 @@ static int tls_pem_callback(char *buf, int size, const void *userdata) return 0; #endif } +#endif /* diff --git a/bacula/src/qt-console/mainwindow.cpp b/bacula/src/qt-console/mainwin.cpp similarity index 84% rename from bacula/src/qt-console/mainwindow.cpp rename to bacula/src/qt-console/mainwin.cpp index f12ccad826..4d50408b2f 100644 --- a/bacula/src/qt-console/mainwindow.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -35,9 +35,9 @@ #include "bat.h" -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) +MainWin::MainWin(QWidget *parent) : QMainWindow(parent) { - QTreeWidgetItem *item, *topItem; + mainWin = this; setupUi(this); /* Setup UI defined by main.ui (designer) */ stackedWidget->setCurrentIndex(0); /* Dummy message ***FIXME*** remove a bit later */ @@ -54,23 +54,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int))); + m_console = new Console(); - /* Dummy setup of treeWidget */ - treeWidget->clear(); - treeWidget->setColumnCount(1); - treeWidget->setHeaderLabel("Selection"); - topItem = new QTreeWidgetItem(treeWidget); - topItem->setText(0, "Rufus"); - item = new QTreeWidgetItem(topItem); - item->setText(0, "Console"); - item->setText(1, "0"); - item = new QTreeWidgetItem(topItem); - item->setText(0, "Restore"); - item->setText(1, "1"); - treeWidget->expandItem(topItem); } -void MainWindow::treeItemClicked(QTreeWidgetItem *item, int column) +void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) { (void)column; int index = item->text(1).toInt(); @@ -83,13 +71,13 @@ void MainWindow::treeItemClicked(QTreeWidgetItem *item, int column) /* * The user just finished typing a line in the command line edit box */ -void MainWindow::input_line() +void MainWin::input_line() { QString cmdStr = lineEdit->text(); /* Get the text */ lineEdit->clear(); /* clear the lineEdit box */ textEdit->append(cmdStr); /* append text on screen */ } -void MainWindow::about() +void MainWin::about() { QMessageBox::about(this, tr("About bat"), tr("

bat 0.1

" diff --git a/bacula/src/qt-console/mainwindow.h b/bacula/src/qt-console/mainwin.h similarity index 88% rename from bacula/src/qt-console/mainwindow.h rename to bacula/src/qt-console/mainwin.h index 41f1f47f08..6176d2058a 100644 --- a/bacula/src/qt-console/mainwindow.h +++ b/bacula/src/qt-console/mainwin.h @@ -32,18 +32,20 @@ * Written by Kern Sibbald, January MMVI */ -#ifndef _MAINWINDOW_H_ -#define _MAINWINDOW_H_ +#ifndef _MAINWIN_H_ +#define _MAINWIN_H_ #include #include "ui_main.h" -class MainWindow : public QMainWindow, public Ui::MainForm +class Console; + +class MainWin : public QMainWindow, public Ui::MainForm { Q_OBJECT public: - MainWindow(QWidget *parent = 0); + MainWin(QWidget *parent = 0); public slots: void input_line(); @@ -52,6 +54,7 @@ public slots: private: QString m_UserInput; + Console *m_console; }; -#endif /* _MAINWINDOW_H_ */ +#endif /* _MAINWIN_H_ */ -- 2.39.5