2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
22 * Main Window control for bat (qt-console)
24 * Kern Sibbald, January MMVII
30 #include "joblist/joblist.h"
31 #include "storage/storage.h"
32 #include "fileset/fileset.h"
33 #include "label/label.h"
36 #include "restore/restore.h"
37 #include "medialist/medialist.h"
38 #include "joblist/joblist.h"
39 #include "clients/clients.h"
40 #include "restore/restoretree.h"
41 #include "help/help.h"
42 #include "jobs/jobs.h"
43 #include "medialist/mediaview.h"
45 #include "jobgraphs/jobplot.h"
47 #include "status/dirstat.h"
48 #include "util/fmtwidgetitem.h"
51 * Daemon message callback
53 void message_callback(int /* type */, char *msg)
55 QMessageBox::warning(mainWin, "Bat", msg, QMessageBox::Ok);
58 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
60 app->setOverrideCursor(QCursor(Qt::WaitCursor));
64 m_treeStackTrap = false;
65 m_dtformat = "yyyy-MM-dd HH:mm:ss";
67 setupUi(this); /* Setup UI defined by main.ui (designer) */
68 register_message_callback(message_callback);
71 treeWidget->setColumnCount(1);
72 treeWidget->setHeaderLabel( tr("Select Page") );
73 treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
74 tabWidget->setTabsClosable(true); /* wait for QT 4.5 */
77 resetFocus(); /* lineEdit->setFocus() */
80 actionJobPlot->setEnabled(false);
81 actionJobPlot->setVisible(false);
88 foreach(Console *console, m_consoleHash) {
89 console->connect_dir();
92 * Note, the notifier is now a global flag, although each notifier
93 * can be individually turned on and off at a socket level. Once
94 * the notifier is turned off, we don't accept anything from anyone
95 * this prevents unwanted messages from getting into the input
96 * dialogs such as restore that read from the director and "know"
100 m_currentConsole = (Console*)getFromHash(m_firstItem);
101 QTimer::singleShot(2000, this, SLOT(popLists()));
103 QString directoryResourceName;
104 m_currentConsole->getDirResName(directoryResourceName);
105 Pmsg1(100, "Setting initial window to %s\n", directoryResourceName.toUtf8().data());
107 app->restoreOverrideCursor();
110 void MainWin::popLists()
112 foreach(Console *console, m_consoleHash) {
113 console->populateLists(true);
116 connectConsoleSignals();
118 app->restoreOverrideCursor();
119 m_currentConsole->setCurrent();
122 void MainWin::createPages()
125 QTreeWidgetItem *item, *topItem;
129 foreach_res(dir, R_DIRECTOR) {
131 /* Create console tree stacked widget item */
132 m_currentConsole = new Console(tabWidget);
133 m_currentConsole->setDirRes(dir);
134 m_currentConsole->readSettings();
136 /* The top tree item representing the director */
137 topItem = new QTreeWidgetItem(treeWidget);
138 topItem->setText(0, dir->name());
139 topItem->setIcon(0, QIcon(":images/server.png"));
140 /* Set background to grey for ease of identification of inactive Director */
141 QBrush greyBrush(Qt::lightGray);
142 topItem->setBackground(0, greyBrush);
143 m_currentConsole->setDirectorTreeItem(topItem);
144 m_consoleHash.insert(topItem, m_currentConsole);
146 /* Create Tree Widget Item */
147 item = new QTreeWidgetItem(topItem);
148 item->setText(0, tr("Console"));
149 if (!m_firstItem){ m_firstItem = item; }
150 item->setIcon(0,QIcon(QString::fromUtf8(":images/utilities-terminal.png")));
152 /* insert the cosole and tree widget item into the hashes */
153 hashInsert(item, m_currentConsole);
154 m_currentConsole->dockPage();
156 /* Set Color of treeWidgetItem for the console
157 * It will be set to green in the console class if the connection is made.
159 QBrush redBrush(Qt::red);
160 item->setForeground(0, redBrush);
163 * Create instances in alphabetic order of the rest
164 * of the classes that will by default exist under each Director.
170 createPageJobList("", "", "", "", NULL);
175 new JobPlot(NULL, pass);
180 // if (m_openBrowser) {
181 // new restoreTree();
186 treeWidget->expandItem(topItem);
187 tabWidget->setCurrentWidget(m_currentConsole);
193 * create an instance of the the joblist class on the stack
195 void MainWin::createPageJobList(const QString &media, const QString &client,
196 const QString &job, const QString &fileset, QTreeWidgetItem *parentTreeWidgetItem)
198 QTreeWidgetItem *holdItem;
200 /* save current tree widget item in case query produces no results */
201 holdItem = treeWidget->currentItem();
202 JobList* joblist = new JobList(media, client, job, fileset, parentTreeWidgetItem);
203 /* If this is a query of jobs on a specific media */
204 if ((media != "") || (client != "") || (job != "") || (fileset != "")) {
205 joblist->setCurrent();
206 /* did query produce results, if not close window and set back to hold */
207 if (joblist->m_resultCount == 0) {
208 joblist->closeStackPage();
209 treeWidget->setCurrentItem(holdItem);
215 * Handle up and down arrow keys for the command line
218 void MainWin::keyPressEvent(QKeyEvent *event)
220 if (m_cmd_history.size() == 0) {
224 switch (event->key()) {
226 if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
233 if (m_cmd_last == 0) {
237 if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
238 m_cmd_last = m_cmd_history.size() - 1;
247 lineEdit->setText(m_cmd_history[m_cmd_last]);
250 void MainWin::connectSignals()
252 /* Connect signals to slots */
253 connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
254 connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
255 connect(actionBat_Help, SIGNAL(triggered()), this, SLOT(help()));
256 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
257 connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
258 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
259 connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closePage(int)));
260 connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
261 connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelButtonClicked()));
262 connect(actionRun, SIGNAL(triggered()), this, SLOT(runButtonClicked()));
263 connect(actionEstimate, SIGNAL(triggered()), this, SLOT(estimateButtonClicked()));
264 connect(actionBrowse, SIGNAL(triggered()), this, SLOT(browseButtonClicked()));
265 connect(actionStatusDirPage, SIGNAL(triggered()), this, SLOT(statusPageButtonClicked()));
267 connect(actionJobPlot, SIGNAL(triggered()), this, SLOT(jobPlotButtonClicked()));
269 connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreButtonClicked()));
270 connect(actionUndock, SIGNAL(triggered()), this, SLOT(undockWindowButton()));
271 connect(actionToggleDock, SIGNAL(triggered()), this, SLOT(toggleDockContextWindow()));
272 connect(actionClosePage, SIGNAL(triggered()), this, SLOT(closeCurrentPage()));
273 connect(actionPreferences, SIGNAL(triggered()), this, SLOT(setPreferences()));
274 connect(actionRepopLists, SIGNAL(triggered()), this, SLOT(repopLists()));
275 connect(actionReloadRepop, SIGNAL(triggered()), this, SLOT(reloadRepopLists()));
278 void MainWin::disconnectSignals()
280 /* Connect signals to slots */
281 disconnect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
282 disconnect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
283 disconnect(actionBat_Help, SIGNAL(triggered()), this, SLOT(help()));
284 disconnect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
285 disconnect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
286 disconnect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int)));
287 disconnect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closePage(int)));
288 disconnect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
289 disconnect(actionLabel, SIGNAL(triggered()), this, SLOT(labelButtonClicked()));
290 disconnect(actionRun, SIGNAL(triggered()), this, SLOT(runButtonClicked()));
291 disconnect(actionEstimate, SIGNAL(triggered()), this, SLOT(estimateButtonClicked()));
292 disconnect(actionBrowse, SIGNAL(triggered()), this, SLOT(browseButtonClicked()));
293 disconnect(actionStatusDirPage, SIGNAL(triggered()), this, SLOT(statusPageButtonClicked()));
295 disconnect(actionJobPlot, SIGNAL(triggered()), this, SLOT(jobPlotButtonClicked()));
297 disconnect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreButtonClicked()));
298 disconnect(actionUndock, SIGNAL(triggered()), this, SLOT(undockWindowButton()));
299 disconnect(actionToggleDock, SIGNAL(triggered()), this, SLOT(toggleDockContextWindow()));
300 disconnect(actionClosePage, SIGNAL(triggered()), this, SLOT(closeCurrentPage()));
301 disconnect(actionPreferences, SIGNAL(triggered()), this, SLOT(setPreferences()));
302 disconnect(actionRepopLists, SIGNAL(triggered()), this, SLOT(repopLists()));
303 disconnect(actionReloadRepop, SIGNAL(triggered()), this, SLOT(reloadRepopLists()));
309 void MainWin::waitEnter()
311 if (m_waitState || m_isClosing) {
315 if (mainWin->m_connDebug) Pmsg0(000, "Entering Wait State\n");
316 app->setOverrideCursor(QCursor(Qt::WaitCursor));
318 disconnectConsoleSignals(m_currentConsole);
319 m_waitTreeItem = treeWidget->currentItem();
325 void MainWin::waitExit()
327 if (!m_waitState || m_isClosing) {
330 if (mainWin->m_connDebug) Pmsg0(000, "Exiting Wait State\n");
331 if (m_waitTreeItem && (m_waitTreeItem != treeWidget->currentItem())) {
332 treeWidget->setCurrentItem(m_waitTreeItem);
336 connectConsoleSignals();
338 app->restoreOverrideCursor();
342 void MainWin::connectConsoleSignals()
344 connect(actionConnect, SIGNAL(triggered()), m_currentConsole, SLOT(connect_dir()));
345 connect(actionSelectFont, SIGNAL(triggered()), m_currentConsole, SLOT(set_font()));
346 connect(actionMessages, SIGNAL(triggered()), m_currentConsole, SLOT(messages()));
349 void MainWin::disconnectConsoleSignals(Console *console)
351 disconnect(actionConnect, SIGNAL(triggered()), console, SLOT(connect_dir()));
352 disconnect(actionMessages, SIGNAL(triggered()), console, SLOT(messages()));
353 disconnect(actionSelectFont, SIGNAL(triggered()), console, SLOT(set_font()));
358 * Two functions to respond to menu items to repop lists and execute reload and repopulate
359 * the lists for jobs, clients, filesets .. ..
361 void MainWin::repopLists()
363 m_currentConsole->populateLists(false);
365 void MainWin::reloadRepopLists()
367 QString cmd = "reload";
368 m_currentConsole->consoleCommand(cmd);
369 m_currentConsole->populateLists(false);
373 * Reimplementation of QWidget closeEvent virtual function
375 void MainWin::closeEvent(QCloseEvent *event)
379 /* Remove all groups from settings for OpenOnExit so that we can start some of the status windows */
380 foreach(Console *console, m_consoleHash){
381 QSettings settings(console->m_dir->name(), "bat");
382 settings.beginGroup("OpenOnExit");
386 /* close all non console pages, this will call settings in destructors */
387 while (m_consoleHash.count() < m_pagehash.count()) {
388 foreach(Pages *page, m_pagehash) {
389 if (page != page->console()) {
390 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(page);
391 if (pageSelectorTreeWidgetItem->childCount() == 0) {
392 page->console()->setCurrent();
393 page->closeStackPage();
398 foreach(Console *console, m_consoleHash){
399 console->writeSettings();
400 console->terminate();
401 console->closeStackPage();
406 void MainWin::writeSettings()
408 QSettings settings("bacula.org", "bat");
410 settings.beginGroup("MainWin");
411 settings.setValue("winSize", size());
412 settings.setValue("winPos", pos());
413 settings.setValue("state", saveState());
418 void MainWin::readSettings()
420 QSettings settings("bacula.org", "bat");
422 settings.beginGroup("MainWin");
423 resize(settings.value("winSize", QSize(1041, 801)).toSize());
424 move(settings.value("winPos", QPoint(200, 150)).toPoint());
425 restoreState(settings.value("state").toByteArray());
430 * This subroutine is called with an item in the Page Selection window
433 void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/)
435 /* Is this a page that has been inserted into the hash */
436 Pages* page = getFromHash(item);
438 int stackindex = tabWidget->indexOf(page);
440 if (stackindex >= 0) {
441 tabWidget->setCurrentWidget(page);
444 /* run the virtual function in case this class overrides it */
445 page->PgSeltreeWidgetClicked();
447 Dmsg0(000, "Page not in hash");
452 * Called with a change of the highlighed tree widget item in the page selector.
454 void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *previousitem)
456 if (m_isClosing) return; /* if closing the application, do nothing here */
458 Pages *previousPage, *nextPage;
459 Console *previousConsole = NULL;
460 Console *nextConsole;
462 /* remove all actions before adding actions appropriate for new page */
463 foreach(QAction* pageAction, treeWidget->actions()) {
464 treeWidget->removeAction(pageAction);
467 /* first determine the next item */
469 /* knowing the treeWidgetItem, get the page from the hash */
470 nextPage = getFromHash(currentitem);
471 nextConsole = m_consoleHash.value(currentitem);
472 /* Is this a page that has been inserted into the hash */
474 nextConsole = nextPage->console();
475 /* then is it a treeWidgetItem representing a director */
476 } else if (nextConsole) {
477 /* let the next page BE the console */
478 nextPage = nextConsole;
480 /* Should never get here */
485 /* The Previous item */
487 /* this condition prevents a segfault. The first time there is no previousitem*/
489 if (m_treeStackTrap == false) { /* keep track of previous items for going Back */
490 m_treeWidgetStack.append(previousitem);
492 /* knowing the treeWidgetItem, get the page from the hash */
493 previousPage = getFromHash(previousitem);
494 previousConsole = m_consoleHash.value(previousitem);
496 previousConsole = previousPage->console();
497 } else if (previousConsole) {
498 previousPage = previousConsole;
500 if ((previousPage) || (previousConsole)) {
501 if (nextConsole != previousConsole) {
502 /* remove connections to the current console */
503 disconnectConsoleSignals(previousConsole);
504 QTreeWidgetItem *dirItem = previousConsole->directorTreeItem();
505 QBrush greyBrush(Qt::lightGray);
506 dirItem->setBackground(0, greyBrush);
511 /* process the current (next) item */
513 if ((nextPage) || (nextConsole)) {
514 if (nextConsole != previousConsole) {
515 /* make connections to the current console */
516 m_currentConsole = nextConsole;
517 connectConsoleSignals();
519 /* Set director's tree widget background to magenta for ease of identification */
520 QTreeWidgetItem *dirItem = m_currentConsole->directorTreeItem();
521 QBrush magentaBrush(Qt::magenta);
522 dirItem->setBackground(0, magentaBrush);
524 /* set the value for the currently active console */
525 int stackindex = tabWidget->indexOf(nextPage);
526 nextPage->firstUseDock();
528 /* Is this page currently on the stack or is it undocked */
529 if (stackindex >= 0) {
530 /* put this page on the top of the stack */
531 tabWidget->setCurrentIndex(stackindex);
533 /* it is undocked, raise it to the front */
536 /* for the page selectors menu action to dock or undock, set the text */
537 nextPage->setContextMenuDockText();
539 treeWidget->addAction(actionToggleDock);
540 /* if this page is closeable, and it has no childern, then add that action */
541 if ((nextPage->isCloseable()) && (currentitem->child(0) == NULL))
542 treeWidget->addAction(actionClosePage);
544 /* Add the actions to the Page Selectors tree widget that are part of the
545 * current items list of desired actions regardless of whether on top of stack*/
546 treeWidget->addActions(nextPage->m_contextActions);
550 void MainWin::labelButtonClicked()
555 void MainWin::runButtonClicked()
560 void MainWin::estimateButtonClicked()
565 void MainWin::browseButtonClicked()
567 // new restoreTree();
570 void MainWin::statusPageButtonClicked()
572 /* if one exists, then just set it current */
574 foreach(Pages *page, m_pagehash) {
575 if (m_currentConsole == page->console()) {
576 if (page->name() == tr("Director Status")) {
587 void MainWin::restoreButtonClicked()
589 new prerestorePage();
590 if (mainWin->m_miscDebug) Pmsg0(000, "in restoreButtonClicked after prerestorePage\n");
593 void MainWin::jobPlotButtonClicked()
598 new JobPlot(NULL, pass);
603 * The user just finished typing a line in the command line edit box
605 void MainWin::input_line()
608 QString cmdStr = lineEdit->text(); /* Get the text */
609 lineEdit->clear(); /* clear the lineEdit box */
610 if (m_currentConsole->is_connected()) {
611 if (m_currentConsole->findDirComm(conn)) {
612 m_currentConsole->consoleCommand(cmdStr, conn);
614 /* Use consoleCommand to allow typing anything */
615 m_currentConsole->consoleCommand(cmdStr);
618 set_status(tr("Director not connected. Click on connect button."));
620 m_cmd_history.append(cmdStr);
622 if (treeWidget->currentItem() != getFromHash(m_currentConsole))
623 m_currentConsole->setCurrent();
627 void MainWin::about()
629 QMessageBox::about(this, tr("About bat"),
630 tr("<br><h2>Bacula Bat %1 (%2)</h2>"
631 "<p>Copyright © 2007-%3 Kern Sibbald"
632 "<p>The <b>bat</b> is an administrative console"
633 " interface to the Director.").arg(VERSION).arg(BDATE).arg(BYEAR));
638 Help::displayFile("index.html");
641 void MainWin::set_statusf(const char *fmt, ...)
645 va_start(arg_ptr, fmt);
646 bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
651 void MainWin::set_status_ready()
653 set_status(tr(" Ready"));
656 void MainWin::set_status(const QString &str)
658 statusBar()->showMessage(str);
661 void MainWin::set_status(const char *buf)
663 statusBar()->showMessage(buf);
667 * Function to respond to the button bar button to undock
669 void MainWin::undockWindowButton()
671 Pages* page = (Pages*)tabWidget->currentWidget();
673 page->togglePageDocking();
678 * Function to respond to action on page selector context menu to toggle the
679 * dock status of the window associated with the page selectors current
682 void MainWin::toggleDockContextWindow()
684 QTreeWidgetItem *currentitem = treeWidget->currentItem();
686 /* Is this a page that has been inserted into the hash */
687 if (getFromHash(currentitem)) {
688 Pages* page = getFromHash(currentitem);
690 page->togglePageDocking();
696 * This function is called when the stack item is changed. Call
697 * the virtual function here. Avoids a window being undocked leaving
698 * a window at the top of the stack unpopulated.
700 void MainWin::stackItemChanged(int)
702 if (m_isClosing) return; /* if closing the application, do nothing here */
703 Pages* page = (Pages*)tabWidget->currentWidget();
704 /* run the virtual function in case this class overrides it */
706 page->currentStackItem();
709 disconnect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
710 disconnect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
711 treeWidget->setCurrentItem(getFromHash(page));
712 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int)));
713 connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
718 * Function to simplify insertion of QTreeWidgetItem <-> Page association
719 * into a double direction hash.
721 void MainWin::hashInsert(QTreeWidgetItem *item, Pages *page)
723 m_pagehash.insert(item, page);
724 m_widgethash.insert(page, item);
728 * Function to simplify removal of QTreeWidgetItem <-> Page association
729 * into a double direction hash.
731 void MainWin::hashRemove(QTreeWidgetItem *item, Pages *page)
733 /* I had all sorts of return status checking code here. Do we have a log
734 * level capability in bat. I would have left it in but it used printf's
735 * and it should really be some kind of log level facility ???
736 * ******FIXME********/
737 m_pagehash.remove(item);
738 m_widgethash.remove(page);
742 * Function to retrieve a Page* when the item in the page selector's tree is
745 Pages* MainWin::getFromHash(QTreeWidgetItem *item)
747 return m_pagehash.value(item);
751 * Function to retrieve the page selectors tree widget item when the page is
754 QTreeWidgetItem* MainWin::getFromHash(Pages *page)
756 return m_widgethash.value(page);
759 void MainWin::closeCurrentPage()
765 * Function to respond to action on page selector context menu to close the
768 void MainWin::closePage(int item)
770 QTreeWidgetItem *currentitem;
774 page = (Pages *)tabWidget->widget(item);
776 currentitem = treeWidget->currentItem();
777 /* Is this a page that has been inserted into the hash */
778 if (getFromHash(currentitem)) {
779 page = getFromHash(currentitem);
784 if (page->isCloseable()) {
785 page->closeStackPage();
792 /* Quick function to return the current console */
793 Console *MainWin::currentConsole()
795 return m_currentConsole;
798 /* Quick function to return the tree item for the director */
799 QTreeWidgetItem *MainWin::currentTopItem()
801 return m_currentConsole->directorTreeItem();
804 /* Preferences menu item clicked */
805 void MainWin::setPreferences()
808 prefs.commDebug->setCheckState(m_commDebug ? Qt::Checked : Qt::Unchecked);
809 prefs.connDebug->setCheckState(m_connDebug ? Qt::Checked : Qt::Unchecked);
810 prefs.displayAll->setCheckState(m_displayAll ? Qt::Checked : Qt::Unchecked);
811 prefs.sqlDebug->setCheckState(m_sqlDebug ? Qt::Checked : Qt::Unchecked);
812 prefs.commandDebug->setCheckState(m_commandDebug ? Qt::Checked : Qt::Unchecked);
813 prefs.miscDebug->setCheckState(m_miscDebug ? Qt::Checked : Qt::Unchecked);
814 prefs.recordLimit->setCheckState(m_recordLimitCheck ? Qt::Checked : Qt::Unchecked);
815 prefs.recordSpinBox->setValue(m_recordLimitVal);
816 prefs.daysLimit->setCheckState(m_daysLimitCheck ? Qt::Checked : Qt::Unchecked);
817 prefs.daysSpinBox->setValue(m_daysLimitVal);
818 prefs.checkMessages->setCheckState(m_checkMessages ? Qt::Checked : Qt::Unchecked);
819 prefs.checkMessagesSpin->setValue(m_checkMessagesInterval);
820 prefs.executeLongCheckBox->setCheckState(m_longList ? Qt::Checked : Qt::Unchecked);
821 prefs.rtPopDirCheckBox->setCheckState(m_rtPopDirDebug ? Qt::Checked : Qt::Unchecked);
822 prefs.rtDirCurICCheckBox->setCheckState(m_rtDirCurICDebug ? Qt::Checked : Qt::Unchecked);
823 prefs.rtDirICCheckBox->setCheckState(m_rtDirICDebug ? Qt::Checked : Qt::Unchecked);
824 prefs.rtFileTabICCheckBox->setCheckState(m_rtFileTabICDebug ? Qt::Checked : Qt::Unchecked);
825 prefs.rtVerTabICCheckBox->setCheckState(m_rtVerTabICDebug ? Qt::Checked : Qt::Unchecked);
826 prefs.rtUpdateFTCheckBox->setCheckState(m_rtUpdateFTDebug ? Qt::Checked : Qt::Unchecked);
827 prefs.rtUpdateVTCheckBox->setCheckState(m_rtUpdateVTDebug ? Qt::Checked : Qt::Unchecked);
828 prefs.rtChecksCheckBox->setCheckState(m_rtChecksDebug ? Qt::Checked : Qt::Unchecked);
829 prefs.rtIconStateCheckBox->setCheckState(m_rtIconStateDebug ? Qt::Checked : Qt::Unchecked);
830 prefs.rtRestore1CheckBox->setCheckState(m_rtRestore1Debug ? Qt::Checked : Qt::Unchecked);
831 prefs.rtRestore2CheckBox->setCheckState(m_rtRestore2Debug ? Qt::Checked : Qt::Unchecked);
832 prefs.rtRestore3CheckBox->setCheckState(m_rtRestore3Debug ? Qt::Checked : Qt::Unchecked);
833 switch (ItemFormatterBase::getBytesConversion()) {
834 case ItemFormatterBase::BYTES_CONVERSION_NONE:
835 prefs.radioConvertOff->setChecked(Qt::Checked);
837 case ItemFormatterBase::BYTES_CONVERSION_IEC:
838 prefs.radioConvertIEC->setChecked(Qt::Checked);
841 prefs.radioConvertStandard->setChecked(Qt::Checked);
844 prefs.openPlotCheckBox->setCheckState(m_openPlot ? Qt::Checked : Qt::Unchecked);
846 prefs.openPlotCheckBox->setVisible(false);
848 prefs.openBrowserCheckBox->setCheckState(m_openBrowser ? Qt::Checked : Qt::Unchecked);
849 prefs.openDirStatCheckBox->setCheckState(m_openDirStat ? Qt::Checked : Qt::Unchecked);
853 /* Preferences dialog */
854 prefsDialog::prefsDialog() : QDialog()
859 void prefsDialog::accept()
862 mainWin->m_commDebug = this->commDebug->checkState() == Qt::Checked;
863 mainWin->m_connDebug = this->connDebug->checkState() == Qt::Checked;
864 mainWin->m_displayAll = this->displayAll->checkState() == Qt::Checked;
865 mainWin->m_sqlDebug = this->sqlDebug->checkState() == Qt::Checked;
866 mainWin->m_commandDebug = this->commandDebug->checkState() == Qt::Checked;
867 mainWin->m_miscDebug = this->miscDebug->checkState() == Qt::Checked;
868 mainWin->m_recordLimitCheck = this->recordLimit->checkState() == Qt::Checked;
869 mainWin->m_recordLimitVal = this->recordSpinBox->value();
870 mainWin->m_daysLimitCheck = this->daysLimit->checkState() == Qt::Checked;
871 mainWin->m_daysLimitVal = this->daysSpinBox->value();
872 mainWin->m_checkMessages = this->checkMessages->checkState() == Qt::Checked;
873 mainWin->m_checkMessagesInterval = this->checkMessagesSpin->value();
874 mainWin->m_longList = this->executeLongCheckBox->checkState() == Qt::Checked;
876 mainWin->m_rtPopDirDebug = this->rtPopDirCheckBox->checkState() == Qt::Checked;
877 mainWin->m_rtDirCurICDebug = this->rtDirCurICCheckBox->checkState() == Qt::Checked;
878 mainWin->m_rtDirICDebug = this->rtDirICCheckBox->checkState() == Qt::Checked;
879 mainWin->m_rtFileTabICDebug = this->rtFileTabICCheckBox->checkState() == Qt::Checked;
880 mainWin->m_rtVerTabICDebug = this->rtVerTabICCheckBox->checkState() == Qt::Checked;
881 mainWin->m_rtUpdateFTDebug = this->rtUpdateFTCheckBox->checkState() == Qt::Checked;
882 mainWin->m_rtUpdateVTDebug = this->rtUpdateVTCheckBox->checkState() == Qt::Checked;
883 mainWin->m_rtChecksDebug = this->rtChecksCheckBox->checkState() == Qt::Checked;
884 mainWin->m_rtIconStateDebug = this->rtIconStateCheckBox->checkState() == Qt::Checked;
885 mainWin->m_rtRestore1Debug = this->rtRestore1CheckBox->checkState() == Qt::Checked;
886 mainWin->m_rtRestore2Debug = this->rtRestore2CheckBox->checkState() == Qt::Checked;
887 mainWin->m_rtRestore3Debug = this->rtRestore3CheckBox->checkState() == Qt::Checked;
888 if (this->radioConvertOff->isChecked()) {
889 ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_NONE);
890 } else if (this->radioConvertIEC->isChecked()){
891 ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_IEC);
893 ItemFormatterBase::setBytesConversion(ItemFormatterBase::BYTES_CONVERSION_SI);
895 mainWin->m_openPlot = this->openPlotCheckBox->checkState() == Qt::Checked;
896 mainWin->m_openBrowser = this->openBrowserCheckBox->checkState() == Qt::Checked;
897 mainWin->m_openDirStat = this->openDirStatCheckBox->checkState() == Qt::Checked;
899 QSettings settings("www.bacula.org", "bat");
900 settings.beginGroup("Debug");
901 settings.setValue("commDebug", mainWin->m_commDebug);
902 settings.setValue("connDebug", mainWin->m_connDebug);
903 settings.setValue("displayAll", mainWin->m_displayAll);
904 settings.setValue("sqlDebug", mainWin->m_sqlDebug);
905 settings.setValue("commandDebug", mainWin->m_commandDebug);
906 settings.setValue("miscDebug", mainWin->m_miscDebug);
908 settings.beginGroup("JobList");
909 settings.setValue("recordLimitCheck", mainWin->m_recordLimitCheck);
910 settings.setValue("recordLimitVal", mainWin->m_recordLimitVal);
911 settings.setValue("daysLimitCheck", mainWin->m_daysLimitCheck);
912 settings.setValue("daysLimitVal", mainWin->m_daysLimitVal);
914 settings.beginGroup("Timers");
915 settings.setValue("checkMessages", mainWin->m_checkMessages);
916 settings.setValue("checkMessagesInterval", mainWin->m_checkMessagesInterval);
918 settings.beginGroup("Misc");
919 settings.setValue("longList", mainWin->m_longList);
920 settings.setValue("byteConvert", ItemFormatterBase::getBytesConversion());
921 settings.setValue("openplot", mainWin->m_openPlot);
922 settings.setValue("openbrowser", mainWin->m_openBrowser);
923 settings.setValue("opendirstat", mainWin->m_openDirStat);
925 settings.beginGroup("RestoreTree");
926 settings.setValue("rtPopDirDebug", mainWin->m_rtPopDirDebug);
927 settings.setValue("rtDirCurICDebug", mainWin->m_rtDirCurICDebug);
928 settings.setValue("rtDirCurICRetDebug", mainWin->m_rtDirICDebug);
929 settings.setValue("rtFileTabICDebug", mainWin->m_rtFileTabICDebug);
930 settings.setValue("rtVerTabICDebug", mainWin->m_rtVerTabICDebug);
931 settings.setValue("rtUpdateFTDebug", mainWin->m_rtUpdateFTDebug);
932 settings.setValue("rtUpdateVTDebug", mainWin->m_rtUpdateVTDebug);
933 settings.setValue("rtChecksDebug", mainWin->m_rtChecksDebug);
934 settings.setValue("rtIconStateDebug", mainWin->m_rtIconStateDebug);
935 settings.setValue("rtRestore1Debug", mainWin->m_rtRestore1Debug);
936 settings.setValue("rtRestore2Debug", mainWin->m_rtRestore2Debug);
937 settings.setValue("rtRestore3Debug", mainWin->m_rtRestore3Debug);
941 void prefsDialog::reject()
944 mainWin->set_status(tr("Canceled"));
947 /* read preferences for the prefences dialog box */
948 void MainWin::readPreferences()
950 QSettings settings("www.bacula.org", "bat");
951 settings.beginGroup("Debug");
952 m_commDebug = settings.value("commDebug", false).toBool();
953 m_connDebug = settings.value("connDebug", false).toBool();
954 m_displayAll = settings.value("displayAll", false).toBool();
955 m_sqlDebug = settings.value("sqlDebug", false).toBool();
956 m_commandDebug = settings.value("commandDebug", false).toBool();
957 m_miscDebug = settings.value("miscDebug", false).toBool();
959 settings.beginGroup("JobList");
960 m_recordLimitCheck = settings.value("recordLimitCheck", true).toBool();
961 m_recordLimitVal = settings.value("recordLimitVal", 50).toInt();
962 m_daysLimitCheck = settings.value("daysLimitCheck", false).toBool();
963 m_daysLimitVal = settings.value("daysLimitVal", 28).toInt();
965 settings.beginGroup("Timers");
966 m_checkMessages = settings.value("checkMessages", false).toBool();
967 m_checkMessagesInterval = settings.value("checkMessagesInterval", 28).toInt();
969 settings.beginGroup("Misc");
970 m_longList = settings.value("longList", false).toBool();
971 ItemFormatterBase::setBytesConversion(
972 (ItemFormatterBase::BYTES_CONVERSION) settings.value("byteConvert",
973 ItemFormatterBase::BYTES_CONVERSION_IEC).toInt());
974 m_openPlot = settings.value("openplot", false).toBool();
975 m_openBrowser = settings.value("openbrowser", false).toBool();
976 m_openDirStat = settings.value("opendirstat", false).toBool();
978 settings.beginGroup("RestoreTree");
979 m_rtPopDirDebug = settings.value("rtPopDirDebug", false).toBool();
980 m_rtDirCurICDebug = settings.value("rtDirCurICDebug", false).toBool();
981 m_rtDirICDebug = settings.value("rtDirCurICRetDebug", false).toBool();
982 m_rtFileTabICDebug = settings.value("rtFileTabICDebug", false).toBool();
983 m_rtVerTabICDebug = settings.value("rtVerTabICDebug", false).toBool();
984 m_rtUpdateFTDebug = settings.value("rtUpdateFTDebug", false).toBool();
985 m_rtUpdateVTDebug = settings.value("rtUpdateVTDebug", false).toBool();
986 m_rtChecksDebug = settings.value("rtChecksDebug", false).toBool();
987 m_rtIconStateDebug = settings.value("rtIconStateDebug", false).toBool();
988 m_rtRestore1Debug = settings.value("rtRestore1Debug", false).toBool();
989 m_rtRestore2Debug = settings.value("rtRestore2Debug", false).toBool();
990 m_rtRestore3Debug = settings.value("rtRestore3Debug", false).toBool();
994 void MainWin::setMessageIcon()
996 if (m_currentConsole->is_messagesPending())
997 actionMessages->setIcon(QIcon(QString::fromUtf8(":/images/mail-message-pending.png")));
999 actionMessages->setIcon(QIcon(QString::fromUtf8(":/images/mail-message-new.png")));
1002 void MainWin::goToPreviousPage()
1004 m_treeStackTrap = true;
1007 /* If stack list is emtpty, then done */
1008 if (m_treeWidgetStack.isEmpty()) {
1011 QTreeWidgetItem* testItem = m_treeWidgetStack.takeLast();
1012 QTreeWidgetItemIterator it(treeWidget);
1013 /* lets avoid a segfault by setting an item current that no longer exists */
1015 if (*it == testItem) {
1016 if (testItem != treeWidget->currentItem()) {
1017 treeWidget->setCurrentItem(testItem);
1026 m_treeStackTrap = false;