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