]> git.sur5r.net Git - bacula/bacula/commitdiff
Implement save/restore settings + Font dialog
authorKern Sibbald <kern@sibbald.com>
Thu, 1 Feb 2007 16:28:39 +0000 (16:28 +0000)
committerKern Sibbald <kern@sibbald.com>
Thu, 1 Feb 2007 16:28:39 +0000 (16:28 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4085 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/qt-console/.cvsignore
bacula/src/qt-console/console/console.cpp
bacula/src/qt-console/console/console.h
bacula/src/qt-console/main.ui
bacula/src/qt-console/mainwin.cpp
bacula/src/qt-console/mainwin.h

index ea9a48ab7540c7478490af7ed8e6fcaccde6a61b..5ed38b93e465c959e42f63373b078538a9655d26 100644 (file)
@@ -1,4 +1,4 @@
-ui_main.h
+ui_*.h
 *.o
 bat
 about-func
index 5af0c86096c1b5d1666cdeaea1d9e6ef0dfa43bc..6590d283557a9d0d319b32b03e6e2651c5d4ddad 100644 (file)
@@ -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<QString>());
+   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");
index 0d0304c44bfbef555a8d5b155cd2ae0fb9937ae5..921b1f9245b931f50dda0e901a88f456a046864e 100644 (file)
@@ -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;
index 7c4d50ac2201ddea4beb75601cc3b0b512f7e033..606e7ffcc0b6689a80476bee74b26be220cc7478 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>1038</width>
-    <height>802</height>
+    <width>1041</width>
+    <height>801</height>
    </rect>
   </property>
   <property name="windowTitle" >
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>1038</width>
+     <width>1041</width>
      <height>33</height>
     </rect>
    </property>
+   <widget class="QMenu" name="menuHelp" >
+    <property name="title" >
+     <string>&amp;Help</string>
+    </property>
+    <addaction name="actionAbout_bat" />
+   </widget>
+   <widget class="QMenu" name="menuSettings" >
+    <property name="title" >
+     <string>Settings</string>
+    </property>
+    <addaction name="actionSelectFont" />
+   </widget>
    <widget class="QMenu" name="menuEdit" >
     <property name="title" >
      <string>&amp;Edit</string>
     <addaction name="actionSave" />
     <addaction name="actionQuit" />
    </widget>
-   <widget class="QMenu" name="menuHelp" >
-    <property name="title" >
-     <string>&amp;Help</string>
-    </property>
-    <addaction name="actionAbout_bat" />
-   </widget>
    <addaction name="menuFile" />
    <addaction name="menuEdit" />
+   <addaction name="menuSettings" />
    <addaction name="menuHelp" />
   </widget>
   <widget class="QStatusBar" name="statusbar" >
     <string>Status of Director</string>
    </property>
   </action>
+  <action name="actionSelectFont" >
+   <property name="text" >
+    <string>&amp;Select Font ...</string>
+   </property>
+  </action>
  </widget>
  <resources>
   <include location="main.qrc" />
index 79f1cfbb6db5cbab563053ba29a2fddb10d37333..db26d49de21a5f113bf3797117063d4b11a9802f 100644 (file)
@@ -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)
index eed58b21855592b064d7a3df7840e5a7f09f4729..247fa11c6f28da88fe61e13eac4b35509bf46da0 100644 (file)
@@ -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;