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.
24 # ifndef _STAT_DEFINED
25 # define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */
29 //#include "winhdrs.h"
31 #include <QApplication>
32 #include <QButtonGroup>
33 #include <QDialogButtonBox>
34 #include <QHeaderView>
35 #include <QMainWindow>
36 #include <QPlainTextEdit>
39 #include <QVBoxLayout>
45 #include <QSystemTrayIcon>
48 #include <QMessageBox>
53 #include "tray-monitor.h"
55 class RunDlg: public QDialog, public Ui::runForm
62 void fill(QComboBox *cb, QStringList &lst) {
66 cb->setEnabled(false);
69 RunDlg(monitoritem *i) {
71 struct job_defaults jdefault;
75 qDebug() << "start getting elements";
76 get_list(item, ".jobs type=B", res.job_list);
78 if (res.job_list.length() == 0) {
80 msgBox.setText("This restricted console doesn't have access to Backup jobs");
81 msgBox.setIcon(QMessageBox::Warning);
87 get_list(item, ".pools", res.pool_list);
88 get_list(item, ".clients", res.client_list);
89 get_list(item, ".storage", res.storage_list);
90 res.levels << "Full" << "Incremental" << "Differential";
91 get_list(item, ".filesets", res.fileset_list);
92 get_list(item, ".messages", res.messages_list);
96 qDebug() << " -> done";
97 label_5->setVisible(false);
98 bootstrap->setVisible(false);
99 jobCombo->addItems(res.job_list);
100 fill(filesetCombo, res.fileset_list);
101 fill(levelCombo, res.levels);
102 fill(clientCombo, res.client_list);
103 fill(poolCombo, res.pool_list);
104 fill(storageCombo, res.storage_list);
105 dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss");
106 dateTimeEdit->setDateTime(dt.currentDateTime());
107 fill(messagesCombo, res.messages_list);
108 messagesCombo->setEnabled(false);
110 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
111 connect(cancelButton, SIGNAL(pressed()), this, SLOT(deleteLater()));
112 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
118 void okButtonPushed()
122 if (jobCombo->isEnabled()) {
123 cmd += " job=\"" + jobCombo->currentText() + "\"" ;
125 if (filesetCombo->isEnabled()) {
126 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
128 cmd += " level=\"" + levelCombo->currentText() + "\"";
129 if (clientCombo->isEnabled()) {
130 cmd += " client=\"" + clientCombo->currentText() + "\"" ;
132 if (poolCombo->isEnabled()) {
133 cmd += " pool=\"" + poolCombo->currentText() + "\"";
135 if (storageCombo->isEnabled()) {
136 cmd += " storage=\"" + storageCombo->currentText() + "\"";
138 cmd += " priority=\"" + QString().setNum(prioritySpin->value()) + "\"";
139 cmd += " when=\"" + dateTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss") + "\"";
141 " messages=\"" << messagesCombo->currentText() << "\"";
142 /* FIXME when there is an option to modify the messages resoruce associated
147 item->D_sock->fsend("%s", cmd.toUtf8().data());
149 while(item->D_sock->recv() >= 0) {output += item->D_sock->msg;}
151 msgBox.setText(output);
156 void job_name_change(int)
158 job_defaults job_defs;
159 job_defs.job_name = jobCombo->currentText();
161 if (item->get_job_defaults(job_defs)) {
162 typeLabel->setText("<H3>"+job_defs.type+"</H3>");
163 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
164 levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
165 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
166 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
167 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
168 messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
179 class TrayUI: public QMainWindow
184 QWidget *centralwidget;
185 QTabWidget *tabWidget;
186 QStatusBar *statusbar;
187 QHash<QString, QPlainTextEdit*> hash;
188 monitoritem* director;
190 QSystemTrayIcon *tray;
191 QSpinBox *spinRefresh;
194 QPlainTextEdit *getTextEdit(char *title)
196 return hash.value(QString(title));
199 void clearText(char *title)
201 QPlainTextEdit *w = getTextEdit(title);
208 void appendText(char *title, char *line)
210 QPlainTextEdit *w = getTextEdit(title);
214 w->appendPlainText(QString(line));
217 void addDirector(monitoritem *item)
222 void addTab(char *title)
224 QString t = QString(title);
225 QWidget *tab = new QWidget();
226 QVBoxLayout *vLayout = new QVBoxLayout(tab);
227 QPlainTextEdit *plainTextEdit = new QPlainTextEdit(tab);
228 plainTextEdit->setObjectName(t);
229 plainTextEdit->setReadOnly(true);
230 plainTextEdit->setFont(QFont("courier"));
231 vLayout->addWidget(plainTextEdit);
232 hash.insert(t, plainTextEdit);
233 tabWidget->addTab(tab, t);
239 timer = new QTimer(this);
240 connect(timer, SIGNAL(timeout()), this, SLOT(refresh_screen()));
242 timer->start(spinRefresh->value()*1000);
245 void setupUi(QMainWindow *TrayMonitor)
249 if (TrayMonitor->objectName().isEmpty())
250 TrayMonitor->setObjectName(QString::fromUtf8("TrayMonitor"));
251 TrayMonitor->setWindowIcon(QIcon(":/images/cartridge1.png"));
252 TrayMonitor->resize(789, 595);
253 centralwidget = new QWidget(TrayMonitor);
254 centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
255 QVBoxLayout *verticalLayout = new QVBoxLayout(centralwidget);
256 verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
257 tabWidget = new QTabWidget(centralwidget);
258 tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
259 tabWidget->setTabPosition(QTabWidget::North);
260 tabWidget->setTabShape(QTabWidget::Rounded);
261 tabWidget->setTabsClosable(false);
262 verticalLayout->addWidget(tabWidget);
264 QDialogButtonBox *buttonBox = new QDialogButtonBox(centralwidget);
265 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
266 buttonBox->setStandardButtons(QDialogButtonBox::Close);
267 connect(buttonBox, SIGNAL(rejected()), this, SLOT(cb_show()));
269 TrayMonitor->setCentralWidget(centralwidget);
270 statusbar = new QStatusBar(TrayMonitor);
271 statusbar->setObjectName(QString::fromUtf8("statusbar"));
272 TrayMonitor->setStatusBar(statusbar);
274 QHBoxLayout *hLayout = new QHBoxLayout();
275 QLabel *refreshlabel = new QLabel(centralwidget);
276 refreshlabel->setText("Refresh:");
277 hLayout->addWidget(refreshlabel);
278 spinRefresh = new QSpinBox(centralwidget);
279 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
280 sizePolicy.setHorizontalStretch(0);
281 sizePolicy.setVerticalStretch(0);
282 sizePolicy.setHeightForWidth(spinRefresh->sizePolicy().hasHeightForWidth());
283 spinRefresh->setSizePolicy(sizePolicy);
284 spinRefresh->setMinimum(1);
285 spinRefresh->setMaximum(600);
286 spinRefresh->setSingleStep(10);
287 spinRefresh->setValue(60);
288 hLayout->addWidget(spinRefresh);
289 hLayout->addWidget(buttonBox);
291 verticalLayout->addLayout(hLayout);
293 tray = new QSystemTrayIcon(TrayMonitor);
294 QMenu* stmenu = new QMenu(TrayMonitor);
296 QAction *actShow = new QAction(QApplication::translate("TrayMonitor",
298 0, QApplication::UnicodeUTF8),TrayMonitor);
299 QAction* actQuit = new QAction(QApplication::translate("TrayMonitor",
301 0, QApplication::UnicodeUTF8),TrayMonitor);
302 QAction* actAbout = new QAction(QApplication::translate("TrayMonitor",
304 0, QApplication::UnicodeUTF8),TrayMonitor);
305 QAction* actRun = new QAction(QApplication::translate("TrayMonitor",
307 0, QApplication::UnicodeUTF8),TrayMonitor);
308 stmenu->addAction(actShow);
309 stmenu->addAction(actRun);
310 stmenu->addAction(actAbout);
311 stmenu->addSeparator();
312 stmenu->addAction(actQuit);
314 connect(actRun, SIGNAL(triggered()), this, SLOT(cb_run()));
315 connect(actShow, SIGNAL(triggered()), this, SLOT(cb_show()));
316 connect(actQuit, SIGNAL(triggered()), this, SLOT(cb_quit()));
317 connect(actAbout, SIGNAL(triggered()), this, SLOT(cb_about()));
318 connect(spinRefresh, SIGNAL(valueChanged(int)), this, SLOT(cb_refresh(int)));
319 connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
320 this, SLOT(cb_trayIconActivated(QSystemTrayIcon::ActivationReason)));
322 tray->setContextMenu(stmenu);
323 QIcon icon(":/images/cartridge1.png");
325 tray->setToolTip(QString("Bacula Tray Monitor"));
328 retranslateUi(TrayMonitor);
329 QMetaObject::connectSlotsByName(TrayMonitor);
332 void retranslateUi(QMainWindow *TrayMonitor)
334 TrayMonitor->setWindowTitle(QApplication::translate("TrayMonitor", "Bacula Tray Monitor", 0, QApplication::UnicodeUTF8));
339 QApplication::quit();
342 void cb_refresh(int val) {
344 timer->setInterval(val*1000);
349 QMessageBox::about(this, "Bacula Tray Monitor", "Bacula Tray Monitor\n"
350 "For more information, see: www.baculasystems.com\n"
351 "Copyright (C) 1999-2015, Kern Sibbald.\n"
352 "License AGPLv3 see LICENSE.");
357 RunDlg *runbox = new RunDlg(director);
362 void cb_trayIconActivated(QSystemTrayIcon::ActivationReason r) {
363 if (r == QSystemTrayIcon::Trigger) {
368 void refresh_screen() {
369 // qDebug() << "refresh_screen()";
372 // qDebug() << " -> OK";
387 #endif /* TRAYUI_H */