]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/mainwin.cpp
kes Change Bacula trademark owner from John Walker to Kern Sibbald
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28
29 /*
30  *   Version $Id$
31  *
32  *  Main Window control for bat (qt-console)
33  *
34  *   Kern Sibbald, January MMVII
35  *
36  */ 
37
38 #include "bat.h"
39 #include "version.h"
40 #include "joblist/joblist.h"
41 #include "storage/storage.h"
42 #include "fileset/fileset.h"
43 #include "label/label.h"
44 #include "run/run.h"
45 #include "pages.h"
46 #include "restore/restore.h"
47 #include "medialist/medialist.h"
48 #include "joblist/joblist.h"
49 #include "clients/clients.h"
50 #include "restore/restoretree.h"
51 #include "help/help.h"
52 #include "jobs/jobs.h"
53 #ifdef HAVE_QWT
54 #include "jobgraphs/jobplot.h"
55 #endif
56 #include "status/dirstat.h"
57 #include "util/fmtwidgetitem.h"
58
59 /* 
60  * Daemon message callback
61  */
62 void message_callback(int /* type */, char *msg)
63 {
64    QMessageBox::warning(mainWin, "Bat", msg, QMessageBox::Ok);
65 }
66
67 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
68 {
69    m_isClosing = false;
70    m_dtformat = "yyyy-MM-dd HH:mm:ss";
71    mainWin = this;
72    setupUi(this);                     /* Setup UI defined by main.ui (designer) */
73    register_message_callback(message_callback);
74    readPreferences();
75    treeWidget->clear();
76    treeWidget->setColumnCount(1);
77    treeWidget->setHeaderLabel( tr("Select Page") );
78    treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
79
80    createPages();
81
82    resetFocus();
83
84    createConnections();
85
86 #ifndef HAVE_QWT
87    actionJobPlot->setEnabled(false);
88    actionJobPlot->setVisible(false);
89 #endif
90
91    this->show();
92
93    readSettings();
94
95    foreach(Console *console, m_consoleHash) {
96       console->connect_dir();
97    }
98    m_currentConsole = (Console*)getFromHash(m_firstItem);
99    m_currentConsole->setCurrent();
100    if (m_miscDebug) {
101       QString directoryResourceName;
102       m_currentConsole->getDirResName(directoryResourceName);
103       Pmsg1(100, "Setting initial window to %s\n", directoryResourceName.toUtf8().data());
104    }
105 }
106
107 void MainWin::createPages()
108 {
109    DIRRES *dir;
110    QTreeWidgetItem *item, *topItem;
111    m_firstItem = NULL;
112
113    LockRes();
114    foreach_res(dir, R_DIRECTOR) {
115
116       /* Create console tree stacked widget item */
117       m_currentConsole = new Console(stackedWidget);
118       m_currentConsole->setDirRes(dir);
119       m_currentConsole->readSettings();
120
121       /* The top tree item representing the director */
122       topItem = new QTreeWidgetItem(treeWidget);
123       topItem->setText(0, dir->name());
124       topItem->setIcon(0, QIcon(":images/server.png"));
125       /* Set background to grey for ease of identification of inactive Director */
126       QBrush greyBrush(Qt::lightGray);
127       topItem->setBackground(0, greyBrush);
128       m_currentConsole->setDirectorTreeItem(topItem);
129       m_consoleHash.insert(topItem, m_currentConsole);
130
131       /* Create Tree Widget Item */
132       item = new QTreeWidgetItem(topItem);
133       item->setText(0, tr("Console"));
134       if (!m_firstItem){ m_firstItem = item; }
135       item->setIcon(0,QIcon(QString::fromUtf8(":images/utilities-terminal.png")));
136
137       /* insert the cosole and tree widget item into the hashes */
138       hashInsert(item, m_currentConsole);
139
140       /* Set Color of treeWidgetItem for the console
141       * It will be set to green in the console class if the connection is made.
142       */
143       QBrush redBrush(Qt::red);
144       item->setForeground(0, redBrush);
145       m_currentConsole->dockPage();
146
147       /*
148        * Create instances in alphabetic order of the rest 
149        *  of the classes that will by default exist under each Director.  
150        */
151 //      new bRestore();
152       new Clients();
153       new FileSet();
154       new Jobs();
155       createPageJobList("", "", "", "", NULL);
156 #ifdef HAVE_QWT
157       JobPlotPass pass;
158       pass.use = false;
159       if (m_openPlot)
160          new JobPlot(NULL, pass);
161 #endif
162       new MediaList();
163       new Storage();
164       if (m_openBrowser)
165          new restoreTree();
166       if (m_openDirStat)
167          new DirStat();
168
169       treeWidget->expandItem(topItem);
170       stackedWidget->setCurrentWidget(m_currentConsole);
171    }
172    UnlockRes();
173 }
174
175 /*
176  * create an instance of the the joblist class on the stack
177  */
178 void MainWin::createPageJobList(const QString &media, const QString &client,
179               const QString &job, const QString &fileset, QTreeWidgetItem *parentTreeWidgetItem)
180 {
181    QTreeWidgetItem *holdItem;
182
183    /* save current tree widget item in case query produces no results */
184    holdItem = treeWidget->currentItem();
185    JobList* joblist = new JobList(media, client, job, fileset, parentTreeWidgetItem);
186    /* If this is a query of jobs on a specific media */
187    if ((media != "") || (client != "") || (job != "") || (fileset != "")) {
188       joblist->setCurrent();
189       /* did query produce results, if not close window and set back to hold */
190       if (joblist->m_resultCount == 0) {
191          joblist->closeStackPage();
192          treeWidget->setCurrentItem(holdItem);
193       }
194    }
195 }
196
197 /*
198  * Handle up and down arrow keys for the command line
199  *  history.
200  */
201 void MainWin::keyPressEvent(QKeyEvent *event)
202 {
203    if (m_cmd_history.size() == 0) {
204       event->ignore();
205       return;
206    }
207    switch (event->key()) {
208    case Qt::Key_Down:
209       if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
210          event->ignore();
211          return;
212       }
213       m_cmd_last++;
214       break;
215    case Qt::Key_Up:
216       if (m_cmd_last == 0) {
217          event->ignore();
218          return;
219       }
220       if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
221          m_cmd_last = m_cmd_history.size() - 1;
222       } else {
223          m_cmd_last--;
224       }
225       break;
226    default:
227       event->ignore();
228       return;
229    }
230    lineEdit->setText(m_cmd_history[m_cmd_last]);
231 }
232
233 void MainWin::createConnections()
234 {
235    /* Connect signals to slots */
236    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
237    connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
238    connect(actionBat_Help, SIGNAL(triggered()), this, SLOT(help()));
239    connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, 
240            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
241    connect(treeWidget, SIGNAL(
242            currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
243            this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
244    connect(stackedWidget, SIGNAL(currentChanged(int)),
245            this, SLOT(stackItemChanged(int)));
246    connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
247    connect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelButtonClicked()));
248    connect(actionRun, SIGNAL(triggered()), this,  SLOT(runButtonClicked()));
249    connect(actionEstimate, SIGNAL(triggered()), this,  SLOT(estimateButtonClicked()));
250    connect(actionBrowse, SIGNAL(triggered()), this,  SLOT(browseButtonClicked()));
251    connect(actionStatusDirPage, SIGNAL(triggered()), this,  SLOT(statusPageButtonClicked()));
252 #ifdef HAVE_QWT
253    connect(actionJobPlot, SIGNAL(triggered()), this,  SLOT(jobPlotButtonClicked()));
254 #endif
255    connect(actionRestore, SIGNAL(triggered()), this,  SLOT(restoreButtonClicked()));
256    connect(actionUndock, SIGNAL(triggered()), this,  SLOT(undockWindowButton()));
257    connect(actionToggleDock, SIGNAL(triggered()), this,  SLOT(toggleDockContextWindow()));
258    connect(actionClosePage, SIGNAL(triggered()), this,  SLOT(closePage()));
259    connect(actionPreferences, SIGNAL(triggered()), this,  SLOT(setPreferences()));
260 }
261
262 /* 
263  * Reimplementation of QWidget closeEvent virtual function   
264  */
265 void MainWin::closeEvent(QCloseEvent *event)
266 {
267    m_isClosing = true;
268    writeSettings();
269 /*   foreach(Console *console, m_consoleHash){
270       console->writeSettings();
271       console->terminate();
272       console->closeStackPage();
273    } */
274    /* close all non console pages, this will call settings in destructors */
275    while (m_consoleHash.count() < m_pagehash.count()) {
276       foreach(Pages *page, m_pagehash) {
277          if (page !=  page->console()) {
278             QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(page);
279             if (pageSelectorTreeWidgetItem->childCount() == 0) {
280                page->console()->setCurrent();
281                page->closeStackPage();
282             }
283          }
284       }
285    }
286    foreach(Console *console, m_consoleHash){
287       console->writeSettings();
288       console->terminate();
289       console->closeStackPage();
290    }
291    event->accept();
292 }
293
294 void MainWin::writeSettings()
295 {
296    QSettings settings("bacula.org", "bat");
297
298    settings.beginGroup("MainWin");
299    settings.setValue("winSize", size());
300    settings.setValue("winPos", pos());
301    settings.setValue("state", saveState());
302    settings.endGroup();
303 }
304
305 void MainWin::readSettings()
306
307    QSettings settings("bacula.org", "bat");
308
309    settings.beginGroup("MainWin");
310    resize(settings.value("winSize", QSize(1041, 801)).toSize());
311    move(settings.value("winPos", QPoint(200, 150)).toPoint());
312    restoreState(settings.value("state").toByteArray());
313    settings.endGroup();
314 }
315
316 /*
317  * This subroutine is called with an item in the Page Selection window
318  *   is clicked 
319  */
320 void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/)
321 {
322    /* Is this a page that has been inserted into the hash  */
323    if (getFromHash(item)) {
324       Pages* page = getFromHash(item);
325       int stackindex=stackedWidget->indexOf(page);
326
327       if (stackindex >= 0) {
328          stackedWidget->setCurrentWidget(page);
329       }
330       /* run the virtual function in case this class overrides it */
331       page->PgSeltreeWidgetClicked();
332    }
333 }
334
335 /*
336  * Called with a change of the highlighed tree widget item in the page selector.
337  */
338 void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *previousitem)
339 {
340    if (m_isClosing) return; /* if closing the application, do nothing here */
341
342    Pages *previousPage, *nextPage;
343    Console *previousConsole = NULL;
344    Console *nextConsole;
345
346    /* remove all actions before adding actions appropriate for new page */
347    foreach(QAction* pageAction, treeWidget->actions()) {
348       treeWidget->removeAction(pageAction);
349    }
350
351    /* first determine the next item */
352
353    /* knowing the treeWidgetItem, get the page from the hash */
354    nextPage = getFromHash(currentitem);
355    nextConsole = m_consoleHash.value(currentitem);
356    /* Is this a page that has been inserted into the hash  */
357    if (nextPage) {
358       nextConsole = nextPage->console();
359       /* then is it a treeWidgetItem representing a director */
360    } else if (nextConsole) {
361       /* let the next page BE the console */
362       nextPage = nextConsole;
363    } else {
364       /* Should never get here */
365       nextPage = NULL;
366       nextConsole = NULL;
367    }
368           
369    /* The Previous item */
370
371    /* this condition prevents a segfault.  The first time there is no previousitem*/
372    if (previousitem) {
373       /* knowing the treeWidgetItem, get the page from the hash */
374       previousPage = getFromHash(previousitem);
375       previousConsole = m_consoleHash.value(previousitem);
376       if (previousPage) {
377          previousConsole = previousPage->console();
378       } else if (previousConsole) {
379          previousPage = previousConsole;
380       }
381       if ((previousPage) || (previousConsole)) {
382          if (nextConsole != previousConsole) {
383             /* remove connections to the current console */
384             disconnect(actionConnect, SIGNAL(triggered()), previousConsole, SLOT(connect_dir()));
385             disconnect(actionStatusDir, SIGNAL(triggered()), previousConsole, SLOT(status_dir()));
386             disconnect(actionMessages, SIGNAL(triggered()), previousConsole, SLOT(messages()));
387             disconnect(actionSelectFont, SIGNAL(triggered()), previousConsole, SLOT(set_font()));
388             QTreeWidgetItem *dirItem = previousConsole->directorTreeItem();
389             QBrush greyBrush(Qt::lightGray);
390             dirItem->setBackground(0, greyBrush);
391          }
392       }
393    }
394
395    /* process the current (next) item */
396    
397    if ((nextPage) || (nextConsole)) {
398       if (nextConsole != previousConsole) {
399          /* make connections to the current console */
400          m_currentConsole = nextConsole;
401          connect(actionConnect, SIGNAL(triggered()), m_currentConsole, SLOT(connect_dir()));
402          connect(actionSelectFont, SIGNAL(triggered()), m_currentConsole, SLOT(set_font()));
403          connect(actionStatusDir, SIGNAL(triggered()), m_currentConsole, SLOT(status_dir()));
404          connect(actionMessages, SIGNAL(triggered()), m_currentConsole, SLOT(messages()));
405          /* Set director's tree widget background to magenta for ease of identification */
406          QTreeWidgetItem *dirItem = m_currentConsole->directorTreeItem();
407          QBrush magentaBrush(Qt::magenta);
408          dirItem->setBackground(0, magentaBrush);
409       }
410       /* set the value for the currently active console */
411       int stackindex = stackedWidget->indexOf(nextPage);
412    
413       /* Is this page currently on the stack or is it undocked */
414       if (stackindex >= 0) {
415          /* put this page on the top of the stack */
416          stackedWidget->setCurrentIndex(stackindex);
417       } else {
418          /* it is undocked, raise it to the front */
419          nextPage->raise();
420       }
421       /* for the page selectors menu action to dock or undock, set the text */
422       nextPage->setContextMenuDockText();
423
424       treeWidget->addAction(actionToggleDock);
425       /* if this page is closeable, and it has no childern, then add that action */
426       if ((nextPage->isCloseable()) && (currentitem->child(0) == NULL))
427          treeWidget->addAction(actionClosePage);
428
429       /* Add the actions to the Page Selectors tree widget that are part of the
430        * current items list of desired actions regardless of whether on top of stack*/
431       treeWidget->addActions(nextPage->m_contextActions);
432    }
433 }
434
435 void MainWin::labelButtonClicked() 
436 {
437    new labelPage();
438 }
439
440 void MainWin::runButtonClicked() 
441 {
442    new runPage("");
443 }
444
445 void MainWin::estimateButtonClicked() 
446 {
447    new estimatePage();
448 }
449
450 void MainWin::browseButtonClicked() 
451 {
452    new restoreTree();
453 }
454
455 void MainWin::statusPageButtonClicked()
456 {
457    /* if one exists, then just set it current */
458    bool found = false;
459    foreach(Pages *page, m_pagehash) {
460       if (m_currentConsole == page->console()) {
461          if (page->name() == tr("Director Status")) {
462             found = true;
463             page->setCurrent();
464          }
465       }
466    }
467    if (!found)
468       new DirStat();
469 }
470
471 void MainWin::restoreButtonClicked() 
472 {
473    new prerestorePage();
474 }
475
476 void MainWin::jobPlotButtonClicked()
477 {
478 #ifdef HAVE_QWT
479    JobPlotPass pass;
480    pass.use = false;
481    new JobPlot(NULL, pass);
482 #endif
483 }
484
485 /*
486  * The user just finished typing a line in the command line edit box
487  */
488 void MainWin::input_line()
489 {
490    QString cmdStr = lineEdit->text();    /* Get the text */
491    lineEdit->clear();                    /* clear the lineEdit box */
492    if (m_currentConsole->is_connected()) {
493       /* Use consoleInput to allow typing anything */
494       m_currentConsole->consoleInput(cmdStr);
495    } else {
496       set_status(tr("Director not connected. Click on connect button."));
497    }
498    m_cmd_history.append(cmdStr);
499    m_cmd_last = -1;
500    if (treeWidget->currentItem() != getFromHash(m_currentConsole))
501       m_currentConsole->setCurrent();
502 }
503
504
505 void MainWin::about()
506 {
507    QMessageBox::about(this, tr("About bat"),
508       tr("<br><h2>bat %1 (%2), by Dirk H Bartley and Kern Sibbald</h2>"
509          "<p>Copyright &copy; 2007-%3 Free Software Foundation Europe e.V."
510          "<p>The <b>bat</b> is an administrative console"
511          " interface to the Director.").arg(VERSION).arg(BDATE).arg(BYEAR));
512 }
513
514 void MainWin::help()
515 {
516    Help::displayFile("index.html");
517 }
518
519 void MainWin::set_statusf(const char *fmt, ...)
520 {
521    va_list arg_ptr;
522    char buf[1000];
523    int len;
524    va_start(arg_ptr, fmt);
525    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
526    va_end(arg_ptr);
527    set_status(buf);
528 }
529
530 void MainWin::set_status_ready()
531 {
532    set_status(tr(" Ready"));
533 }
534
535 void MainWin::set_status(const QString &str)
536 {
537    statusBar()->showMessage(str);
538 }
539
540 void MainWin::set_status(const char *buf)
541 {
542    statusBar()->showMessage(buf);
543 }
544
545 /*
546  * Function to respond to the button bar button to undock
547  */
548 void MainWin::undockWindowButton()
549 {
550    Pages* page = (Pages*)stackedWidget->currentWidget();
551    page->togglePageDocking();
552 }
553
554 /*
555  * Function to respond to action on page selector context menu to toggle the 
556  * dock status of the window associated with the page selectors current
557  * tree widget item.
558  */
559 void MainWin::toggleDockContextWindow()
560 {
561    QTreeWidgetItem *currentitem = treeWidget->currentItem();
562    
563    /* Is this a page that has been inserted into the hash  */
564    if (getFromHash(currentitem)) {
565       Pages* page = getFromHash(currentitem);
566       page->togglePageDocking();
567    }
568 }
569
570 /*
571  * This function is called when the stack item is changed.  Call
572  * the virtual function here.  Avoids a window being undocked leaving
573  * a window at the top of the stack unpopulated.
574  */
575 void MainWin::stackItemChanged(int)
576 {
577    if (m_isClosing) return; /* if closing the application, do nothing here */
578    Pages* page = (Pages*)stackedWidget->currentWidget();
579    /* run the virtual function in case this class overrides it */
580    page->currentStackItem();
581 }
582
583 /*
584  * Function to simplify insertion of QTreeWidgetItem <-> Page association
585  * into a double direction hash.
586  */
587 void MainWin::hashInsert(QTreeWidgetItem *item, Pages *page)
588 {
589    m_pagehash.insert(item, page);
590    m_widgethash.insert(page, item);
591 }
592
593 /*
594  * Function to simplify removal of QTreeWidgetItem <-> Page association
595  * into a double direction hash.
596  */
597 void MainWin::hashRemove(QTreeWidgetItem *item, Pages *page)
598 {
599    /* I had all sorts of return status checking code here.  Do we have a log
600     * level capability in bat.  I would have left it in but it used printf's
601     * and it should really be some kind of log level facility ???
602     * ******FIXME********/
603    m_pagehash.remove(item);
604    m_widgethash.remove(page);
605 }
606
607 /*
608  * Function to retrieve a Page* when the item in the page selector's tree is
609  * known.
610  */
611 Pages* MainWin::getFromHash(QTreeWidgetItem *item)
612 {
613    return m_pagehash.value(item);
614 }
615
616 /*
617  * Function to retrieve the page selectors tree widget item when the page is
618  * known.
619  */
620 QTreeWidgetItem* MainWin::getFromHash(Pages *page)
621 {
622    return m_widgethash.value(page);
623 }
624
625 /*
626  * Function to respond to action on page selector context menu to close the
627  * current window.
628  */
629 void MainWin::closePage()
630 {
631    QTreeWidgetItem *currentitem = treeWidget->currentItem();
632    
633    /* Is this a page that has been inserted into the hash  */
634    if (getFromHash(currentitem)) {
635       Pages* page = getFromHash(currentitem);
636       if (page->isCloseable()) {
637          page->closeStackPage();
638       }
639    }
640 }
641
642 /* Quick function to return the current console */
643 Console *MainWin::currentConsole()
644 {
645    return m_currentConsole;
646 }
647 /* Quick function to return the tree item for the director */
648 QTreeWidgetItem *MainWin::currentTopItem()
649 {
650    return m_currentConsole->directorTreeItem();
651 }
652
653 /* Preferences menu item clicked */
654 void MainWin::setPreferences()
655 {
656    prefsDialog prefs;
657    prefs.commDebug->setCheckState(m_commDebug ? Qt::Checked : Qt::Unchecked);
658    prefs.displayAll->setCheckState(m_displayAll ? Qt::Checked : Qt::Unchecked);
659    prefs.sqlDebug->setCheckState(m_sqlDebug ? Qt::Checked : Qt::Unchecked);
660    prefs.commandDebug->setCheckState(m_commandDebug ? Qt::Checked : Qt::Unchecked);
661    prefs.miscDebug->setCheckState(m_miscDebug ? Qt::Checked : Qt::Unchecked);
662    prefs.recordLimit->setCheckState(m_recordLimitCheck ? Qt::Checked : Qt::Unchecked);
663    prefs.recordSpinBox->setValue(m_recordLimitVal);
664    prefs.daysLimit->setCheckState(m_daysLimitCheck ? Qt::Checked : Qt::Unchecked);
665    prefs.daysSpinBox->setValue(m_daysLimitVal);
666    prefs.checkMessages->setCheckState(m_checkMessages ? Qt::Checked : Qt::Unchecked);
667    prefs.checkMessagesSpin->setValue(m_checkMessagesInterval);
668    prefs.refreshStatusDir->setCheckState(m_refreshStatusDir ? Qt::Checked : Qt::Unchecked);
669    prefs.refreshStatusDirSpin->setValue(m_refreshStatusDirInterval);
670    prefs.executeLongCheckBox->setCheckState(m_longList ? Qt::Checked : Qt::Unchecked);
671    prefs.rtPopDirCheckBox->setCheckState(m_rtPopDirDebug ? Qt::Checked : Qt::Unchecked);
672    prefs.rtDirCurICCheckBox->setCheckState(m_rtDirCurICDebug ? Qt::Checked : Qt::Unchecked);
673    prefs.rtDirICCheckBox->setCheckState(m_rtDirICDebug ? Qt::Checked : Qt::Unchecked);
674    prefs.rtFileTabICCheckBox->setCheckState(m_rtFileTabICDebug ? Qt::Checked : Qt::Unchecked);
675    prefs.rtVerTabICCheckBox->setCheckState(m_rtVerTabICDebug ? Qt::Checked : Qt::Unchecked);
676    prefs.rtUpdateFTCheckBox->setCheckState(m_rtUpdateFTDebug ? Qt::Checked : Qt::Unchecked);
677    prefs.rtUpdateVTCheckBox->setCheckState(m_rtUpdateVTDebug ? Qt::Checked : Qt::Unchecked);
678    prefs.rtChecksCheckBox->setCheckState(m_rtChecksDebug ? Qt::Checked : Qt::Unchecked);
679    prefs.rtIconStateCheckBox->setCheckState(m_rtIconStateDebug ? Qt::Checked : Qt::Unchecked);
680    prefs.rtRestore1CheckBox->setCheckState(m_rtRestore1Debug ? Qt::Checked : Qt::Unchecked);
681    prefs.rtRestore2CheckBox->setCheckState(m_rtRestore2Debug ? Qt::Checked : Qt::Unchecked);
682    prefs.rtRestore3CheckBox->setCheckState(m_rtRestore3Debug ? Qt::Checked : Qt::Unchecked);
683    switch (ItemFormatterBase::getBytesConversion()) {
684    case ItemFormatterBase::BYTES_CONVERSION_NONE:
685       prefs.radioConvertOff->setChecked(Qt::Checked);
686       break;
687    case ItemFormatterBase::BYTES_CONVERSION_IEC:
688       prefs.radioConvertIEC->setChecked(Qt::Checked);
689       break;
690    default:
691       prefs.radioConvertStandard->setChecked(Qt::Checked);
692       break;
693    }
694    prefs.openPlotCheckBox->setCheckState(m_openPlot ? Qt::Checked : Qt::Unchecked);
695 #ifndef HAVE_QWT
696    prefs.openPlotCheckBox->setVisible(false);
697 #endif
698    prefs.openBrowserCheckBox->setCheckState(m_openBrowser ? Qt::Checked : Qt::Unchecked);
699    prefs.openDirStatCheckBox->setCheckState(m_openDirStat ? Qt::Checked : Qt::Unchecked);
700    prefs.exec();
701 }
702
703 /* Preferences dialog */
704 prefsDialog::prefsDialog()
705 {
706    setupUi(this);
707 }
708
709 void prefsDialog::accept()
710 {
711    this->hide();
712    mainWin->m_commDebug = this->commDebug->checkState() == Qt::Checked;
713    mainWin->m_displayAll = this->displayAll->checkState() == Qt::Checked;
714    mainWin->m_sqlDebug = this->sqlDebug->checkState() == Qt::Checked;
715    mainWin->m_commandDebug = this->commandDebug->checkState() == Qt::Checked;
716    mainWin->m_miscDebug = this->miscDebug->checkState() == Qt::Checked;
717    mainWin->m_recordLimitCheck = this->recordLimit->checkState() == Qt::Checked;
718    mainWin->m_recordLimitVal = this->recordSpinBox->value();
719    mainWin->m_daysLimitCheck = this->daysLimit->checkState() == Qt::Checked;
720    mainWin->m_daysLimitVal = this->daysSpinBox->value();
721    mainWin->m_checkMessages = this->checkMessages->checkState() == Qt::Checked;
722    mainWin->m_checkMessagesInterval = this->checkMessagesSpin->value();
723    mainWin->m_refreshStatusDir = this->refreshStatusDir->checkState() == Qt::Checked;
724    mainWin->m_refreshStatusDirInterval = this->refreshStatusDirSpin->value();
725    mainWin->m_longList = this->executeLongCheckBox->checkState() == Qt::Checked;
726
727    mainWin->m_rtPopDirDebug = this->rtPopDirCheckBox->checkState() == Qt::Checked;
728    mainWin->m_rtDirCurICDebug = this->rtDirCurICCheckBox->checkState() == Qt::Checked;
729    mainWin->m_rtDirICDebug = this->rtDirICCheckBox->checkState() == Qt::Checked;
730    mainWin->m_rtFileTabICDebug = this->rtFileTabICCheckBox->checkState() == Qt::Checked;
731    mainWin->m_rtVerTabICDebug = this->rtVerTabICCheckBox->checkState() == Qt::Checked;
732    mainWin->m_rtUpdateFTDebug = this->rtUpdateFTCheckBox->checkState() == Qt::Checked;
733    mainWin->m_rtUpdateVTDebug = this->rtUpdateVTCheckBox->checkState() == Qt::Checked;
734    mainWin->m_rtChecksDebug = this->rtChecksCheckBox->checkState() == Qt::Checked;
735    mainWin->m_rtIconStateDebug = this->rtIconStateCheckBox->checkState() == Qt::Checked;
736    mainWin->m_rtRestore1Debug = this->rtRestore1CheckBox->checkState() == Qt::Checked;
737    mainWin->m_rtRestore2Debug = this->rtRestore2CheckBox->checkState() == Qt::Checked;
738    mainWin->m_rtRestore3Debug = this->rtRestore3CheckBox->checkState() == Qt::Checked;
739    if (this->radioConvertOff->isChecked()) {
740       ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_NONE);
741    } else if (this->radioConvertIEC->isChecked()){
742       ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_IEC);
743    } else {
744       ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_SI);
745    }
746    mainWin->m_openPlot = this->openPlotCheckBox->checkState() == Qt::Checked;
747    mainWin->m_openBrowser = this->openBrowserCheckBox->checkState() == Qt::Checked;
748    mainWin->m_openDirStat = this->openDirStatCheckBox->checkState() == Qt::Checked;
749
750    QSettings settings("www.bacula.org", "bat");
751    settings.beginGroup("Debug");
752    settings.setValue("commDebug", mainWin->m_commDebug);
753    settings.setValue("displayAll", mainWin->m_displayAll);
754    settings.setValue("sqlDebug", mainWin->m_sqlDebug);
755    settings.setValue("commandDebug", mainWin->m_commandDebug);
756    settings.setValue("miscDebug", mainWin->m_miscDebug);
757    settings.endGroup();
758    settings.beginGroup("JobList");
759    settings.setValue("recordLimitCheck", mainWin->m_recordLimitCheck);
760    settings.setValue("recordLimitVal", mainWin->m_recordLimitVal);
761    settings.setValue("daysLimitCheck", mainWin->m_daysLimitCheck);
762    settings.setValue("daysLimitVal", mainWin->m_daysLimitVal);
763    settings.endGroup();
764    settings.beginGroup("Timers");
765    settings.setValue("checkMessages", mainWin->m_checkMessages);
766    settings.setValue("checkMessagesInterval", mainWin->m_checkMessagesInterval);
767    settings.setValue("refreshStatusDir", mainWin->m_refreshStatusDir);
768    settings.setValue("refreshStatusDirInterval", mainWin->m_refreshStatusDirInterval);
769    settings.endGroup();
770    settings.beginGroup("Misc");
771    settings.setValue("longList", mainWin->m_longList);
772    settings.setValue("byteConvert", ItemFormatterBase::getBytesConversion());
773    settings.setValue("openplot", mainWin->m_openPlot);
774    settings.setValue("openbrowser", mainWin->m_openBrowser);
775    settings.setValue("opendirstat", mainWin->m_openDirStat);
776    settings.endGroup();
777    settings.beginGroup("RestoreTree");
778    settings.setValue("rtPopDirDebug", mainWin->m_rtPopDirDebug);
779    settings.setValue("rtDirCurICDebug", mainWin->m_rtDirCurICDebug);
780    settings.setValue("rtDirCurICRetDebug", mainWin->m_rtDirICDebug);
781    settings.setValue("rtFileTabICDebug", mainWin->m_rtFileTabICDebug);
782    settings.setValue("rtVerTabICDebug", mainWin->m_rtVerTabICDebug);
783    settings.setValue("rtUpdateFTDebug", mainWin->m_rtUpdateFTDebug);
784    settings.setValue("rtUpdateVTDebug", mainWin->m_rtUpdateVTDebug);
785    settings.setValue("rtChecksDebug", mainWin->m_rtChecksDebug);
786    settings.setValue("rtIconStateDebug", mainWin->m_rtIconStateDebug);
787    settings.setValue("rtRestore1Debug", mainWin->m_rtRestore1Debug);
788    settings.setValue("rtRestore2Debug", mainWin->m_rtRestore2Debug);
789    settings.setValue("rtRestore3Debug", mainWin->m_rtRestore3Debug);
790    settings.endGroup();
791    foreach(Console *console, mainWin->m_consoleHash) {
792       console->startTimer();
793    }
794 }
795
796 void prefsDialog::reject()
797 {
798    this->hide();
799    mainWin->set_status(tr("Canceled"));
800 }
801
802 /* read preferences for the prefences dialog box */
803 void MainWin::readPreferences()
804 {
805    QSettings settings("www.bacula.org", "bat");
806    settings.beginGroup("Debug");
807    m_commDebug = settings.value("commDebug", false).toBool();
808    m_displayAll = settings.value("displayAll", false).toBool();
809    m_sqlDebug = settings.value("sqlDebug", false).toBool();
810    m_commandDebug = settings.value("commandDebug", false).toBool();
811    m_miscDebug = settings.value("miscDebug", false).toBool();
812    settings.endGroup();
813    settings.beginGroup("JobList");
814    m_recordLimitCheck = settings.value("recordLimitCheck", true).toBool();
815    m_recordLimitVal = settings.value("recordLimitVal", 150).toInt();
816    m_daysLimitCheck = settings.value("daysLimitCheck", false).toBool();
817    m_daysLimitVal = settings.value("daysLimitVal", 28).toInt();
818    settings.endGroup();
819    settings.beginGroup("Timers");
820    m_checkMessages = settings.value("checkMessages", false).toBool();
821    m_checkMessagesInterval = settings.value("checkMessagesInterval", 28).toInt();
822    m_refreshStatusDir = settings.value("refreshStatusDir", false).toBool();
823    m_refreshStatusDirInterval = settings.value("refreshStatusDirInterval", 28).toInt();
824    settings.endGroup();
825    settings.beginGroup("Misc");
826    m_longList = settings.value("longList", false).toBool();
827    ItemFormatterBase::setBytesConversion(
828          (ItemFormatterBase::BYTES_CONVERSION) settings.value("byteConvert", 
829          ItemFormatterBase::BYTES_CONVERSION_IEC).toInt());
830    m_openPlot = settings.value("openplot", false).toBool();
831    m_openBrowser = settings.value("openbrowser", false).toBool();
832    m_openDirStat = settings.value("opendirstat", false).toBool();
833    settings.endGroup();
834    settings.beginGroup("RestoreTree");
835    m_rtPopDirDebug = settings.value("rtPopDirDebug", false).toBool();
836    m_rtDirCurICDebug = settings.value("rtDirCurICDebug", false).toBool();
837    m_rtDirICDebug = settings.value("rtDirCurICRetDebug", false).toBool();
838    m_rtFileTabICDebug = settings.value("rtFileTabICDebug", false).toBool();
839    m_rtVerTabICDebug = settings.value("rtVerTabICDebug", false).toBool();
840    m_rtUpdateFTDebug = settings.value("rtUpdateFTDebug", false).toBool();
841    m_rtUpdateVTDebug = settings.value("rtUpdateVTDebug", false).toBool();
842    m_rtChecksDebug = settings.value("rtChecksDebug", false).toBool();
843    m_rtIconStateDebug = settings.value("rtIconStateDebug", false).toBool();
844    m_rtRestore1Debug = settings.value("rtRestore1Debug", false).toBool();
845    m_rtRestore2Debug = settings.value("rtRestore2Debug", false).toBool();
846    m_rtRestore3Debug = settings.value("rtRestore3Debug", false).toBool();
847    settings.endGroup();
848 }
849