From: Kern Sibbald Date: Thu, 1 Feb 2007 16:28:39 +0000 (+0000) Subject: Implement save/restore settings + Font dialog X-Git-Tag: Release-7.0.0~6972 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=14c6da285fc82199f2ae681ac844ae74cd54c95d;p=bacula%2Fbacula Implement save/restore settings + Font dialog git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4085 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/.cvsignore b/bacula/src/qt-console/.cvsignore index ea9a48ab75..5ed38b93e4 100644 --- a/bacula/src/qt-console/.cvsignore +++ b/bacula/src/qt-console/.cvsignore @@ -1,4 +1,4 @@ -ui_main.h +ui_*.h *.o bat about-func diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 5af0c86096..6590d28355 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -49,11 +49,6 @@ Console::Console() m_cursor = new QTextCursor(m_textEdit->document()); mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png"))); - /* ***FIXME*** make this configurable */ - font.setFamily("Courier"); - font.setFixedPitch(true); - font.setPointSize(10); - m_textEdit->setFont(font); /* Just take the first Director */ LockRes(); @@ -77,6 +72,9 @@ Console::Console() item->setText(0, "Restore"); item->setText(1, "1"); treeWidget->expandItem(topItem); + + readSettings(); + } /* @@ -153,6 +151,47 @@ void Console::connect() return; } + +void Console::writeSettings() +{ + QFont font = get_font(); + + QSettings settings("bacula.org", "bat"); + settings.beginGroup("Console"); + settings.setValue("consoleFont", font.family()); + settings.setValue("consolePointSize", font.pointSize()); + settings.setValue("consoleFixedPitch", font.fixedPitch()); + settings.endGroup(); +} + +void Console::readSettings() +{ + QFont font = get_font(); + + QSettings settings("bacula.org", "bat"); + settings.beginGroup("Console"); + font.setFamily(settings.value("consoleFont", "Courier").value()); + font.setPointSize(settings.value("consolePointSize", 10).toInt()); + font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool()); + settings.endGroup(); + m_textEdit->setFont(font); +} + +void Console::set_font() +{ + bool ok; + QFont font = QFontDialog::getFont(&ok, QFont(m_textEdit->font()), this); + if (ok) { + m_textEdit->setFont(font); + } +} + +const QFont Console::get_font() +{ + return m_textEdit->font(); +} + + void Console::status_dir() { write_dir("status dir\n"); diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index 0d0304c44b..921b1f9245 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -22,11 +22,15 @@ public: void write_dir(const char *buf); bool authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); bool is_connected() { return m_sock != NULL; }; + const QFont get_font(); + void writeSettings(); + void readSettings(); public slots: void connect(void); void read_dir(int fd); void status_dir(void); + void set_font(void); private: QTextEdit *m_textEdit; diff --git a/bacula/src/qt-console/main.ui b/bacula/src/qt-console/main.ui index 7c4d50ac22..606e7ffcc0 100644 --- a/bacula/src/qt-console/main.ui +++ b/bacula/src/qt-console/main.ui @@ -6,8 +6,8 @@ 0 0 - 1038 - 802 + 1041 + 801 @@ -230,10 +230,22 @@ 0 0 - 1038 + 1041 33 + + + &Help + + + + + + Settings + + + &Edit @@ -250,14 +262,9 @@ - - - &Help - - - + @@ -440,6 +447,11 @@ Status of Director + + + &Select Font ... + + diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 79f1cfbb6d..db26d49de2 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -47,6 +47,13 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) lineEdit->setFocus(); + createConnections(); + + readSettings(); +} + +void MainWin::createConnections() +{ /* Connect signals to slots */ connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line())); connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about())); @@ -63,6 +70,38 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows())); connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect())); connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir())); + connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font())); +} + +/* + * Reimplementation of QWidget closeEvent virtual function + */ +void MainWin::closeEvent(QCloseEvent *event) +{ + /* ***FIXME*** close any open sockets */ + writeSettings(); + m_console->writeSettings(); + event->accept(); +} + +void MainWin::writeSettings() +{ + QSettings settings("bacula.org", "bat"); + + settings.beginGroup("MainWin"); + settings.setValue("winSize", size()); + settings.setValue("winPos", pos()); + settings.endGroup(); +} + +void MainWin::readSettings() +{ + QSettings settings("bacula.org", "bat"); + + settings.beginGroup("MainWin"); + resize(settings.value("winSize", QSize(1041, 801)).toSize()); + move(settings.value("winPos", QPoint(200, 150)).toPoint()); + settings.endGroup(); } void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index eed58b2185..247fa11c6f 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -49,6 +49,8 @@ public: void set_statusf(const char *fmt, ...); void set_status_ready(); void set_status(const char *buf); + void writeSettings(); + void readSettings(); public slots: void input_line(); @@ -56,6 +58,12 @@ public slots: void treeItemClicked(QTreeWidgetItem *item, int column); void treeItemDoubleClicked(QTreeWidgetItem *item, int column); +protected: + void closeEvent(QCloseEvent *event); + +private: + void createConnections(); + private: QString m_UserInput; Console *m_console;