2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2011-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
25 # ifndef _STAT_DEFINED
26 # define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */
32 #include <QApplication>
33 #include <QButtonGroup>
34 #include <QDialogButtonBox>
35 #include <QHeaderView>
36 #include <QMainWindow>
37 #include <QPlainTextEdit>
40 #include <QVBoxLayout>
46 #include <QSystemTrayIcon>
49 #include <QMessageBox>
54 #include "tray-monitor.h"
56 class RunDlg: public QDialog, public Ui::runForm
63 void fill(QComboBox *cb, QStringList &lst) {
67 cb->setEnabled(false);
70 RunDlg(monitoritem *i) {
72 struct job_defaults jdefault;
76 qDebug() << "start getting elements";
77 get_list(item, ".jobs type=B", res.job_list);
79 if (res.job_list.length() == 0) {
81 msgBox.setText("This restricted console doesn't have access to Backup jobs");
82 msgBox.setIcon(QMessageBox::Warning);
88 get_list(item, ".pools", res.pool_list);
89 get_list(item, ".clients", res.client_list);
90 get_list(item, ".storage", res.storage_list);
91 res.levels << "Full" << "Incremental" << "Differential";
92 get_list(item, ".filesets", res.fileset_list);
93 get_list(item, ".messages", res.messages_list);
97 qDebug() << " -> done";
98 label_5->setVisible(false);
99 bootstrap->setVisible(false);
100 jobCombo->addItems(res.job_list);
101 fill(filesetCombo, res.fileset_list);
102 fill(levelCombo, res.levels);
103 fill(clientCombo, res.client_list);
104 fill(poolCombo, res.pool_list);
105 fill(storageCombo, res.storage_list);
106 dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss");
107 dateTimeEdit->setDateTime(dt.currentDateTime());
108 fill(messagesCombo, res.messages_list);
109 messagesCombo->setEnabled(false);
111 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
112 connect(cancelButton, SIGNAL(pressed()), this, SLOT(deleteLater()));
113 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
119 void okButtonPushed()
123 if (jobCombo->isEnabled()) {
124 cmd += " job=\"" + jobCombo->currentText() + "\"" ;
126 if (filesetCombo->isEnabled()) {
127 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
129 cmd += " level=\"" + levelCombo->currentText() + "\"";
130 if (clientCombo->isEnabled()) {
131 cmd += " client=\"" + clientCombo->currentText() + "\"" ;
133 if (poolCombo->isEnabled()) {
134 cmd += " pool=\"" + poolCombo->currentText() + "\"";
136 if (storageCombo->isEnabled()) {
137 cmd += " storage=\"" + storageCombo->currentText() + "\"";
139 cmd += " priority=\"" + QString().setNum(prioritySpin->value()) + "\"";
140 cmd += " when=\"" + dateTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss") + "\"";
142 " messages=\"" << messagesCombo->currentText() << "\"";
143 /* FIXME when there is an option to modify the messages resoruce associated
148 item->D_sock->fsend("%s", cmd.toUtf8().data());
150 while(item->D_sock->recv() >= 0) {output += item->D_sock->msg;}
152 msgBox.setText(output);
157 void job_name_change(int)
159 job_defaults job_defs;
160 job_defs.job_name = jobCombo->currentText();
162 if (item->get_job_defaults(job_defs)) {
163 typeLabel->setText("<H3>"+job_defs.type+"</H3>");
164 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
165 levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
166 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
167 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
168 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
169 messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
180 class TrayUI: public QMainWindow
185 QWidget *centralwidget;
186 QTabWidget *tabWidget;
187 QStatusBar *statusbar;
188 QHash<QString, QPlainTextEdit*> hash;
189 monitoritem* director;
191 QSystemTrayIcon *tray;
192 QSpinBox *spinRefresh;
195 QPlainTextEdit *getTextEdit(char *title)
197 return hash.value(QString(title));
200 void clearText(char *title)
202 QPlainTextEdit *w = getTextEdit(title);
209 void appendText(char *title, char *line)
211 QPlainTextEdit *w = getTextEdit(title);
215 w->appendPlainText(QString(line));
218 void addDirector(monitoritem *item)
223 void addTab(char *title)
225 QString t = QString(title);
226 QWidget *tab = new QWidget();
227 QVBoxLayout *vLayout = new QVBoxLayout(tab);
228 QPlainTextEdit *plainTextEdit = new QPlainTextEdit(tab);
229 plainTextEdit->setObjectName(t);
230 plainTextEdit->setReadOnly(true);
231 plainTextEdit->setFont(QFont("courier"));
232 vLayout->addWidget(plainTextEdit);
233 hash.insert(t, plainTextEdit);
234 tabWidget->addTab(tab, t);
240 timer = new QTimer(this);
241 connect(timer, SIGNAL(timeout()), this, SLOT(refresh_screen()));
243 timer->start(spinRefresh->value()*1000);
246 void setupUi(QMainWindow *TrayMonitor)
250 if (TrayMonitor->objectName().isEmpty())
251 TrayMonitor->setObjectName(QString::fromUtf8("TrayMonitor"));
252 TrayMonitor->setWindowIcon(QIcon(":/images/cartridge1.png"));
253 TrayMonitor->resize(789, 595);
254 centralwidget = new QWidget(TrayMonitor);
255 centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
256 QVBoxLayout *verticalLayout = new QVBoxLayout(centralwidget);
257 verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
258 tabWidget = new QTabWidget(centralwidget);
259 tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
260 tabWidget->setTabPosition(QTabWidget::North);
261 tabWidget->setTabShape(QTabWidget::Rounded);
262 tabWidget->setTabsClosable(false);
263 verticalLayout->addWidget(tabWidget);
265 QDialogButtonBox *buttonBox = new QDialogButtonBox(centralwidget);
266 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
267 buttonBox->setStandardButtons(QDialogButtonBox::Close);
268 connect(buttonBox, SIGNAL(rejected()), this, SLOT(cb_show()));
270 TrayMonitor->setCentralWidget(centralwidget);
271 statusbar = new QStatusBar(TrayMonitor);
272 statusbar->setObjectName(QString::fromUtf8("statusbar"));
273 TrayMonitor->setStatusBar(statusbar);
275 QHBoxLayout *hLayout = new QHBoxLayout();
276 QLabel *refreshlabel = new QLabel(centralwidget);
277 refreshlabel->setText("Refresh:");
278 hLayout->addWidget(refreshlabel);
279 spinRefresh = new QSpinBox(centralwidget);
280 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
281 sizePolicy.setHorizontalStretch(0);
282 sizePolicy.setVerticalStretch(0);
283 sizePolicy.setHeightForWidth(spinRefresh->sizePolicy().hasHeightForWidth());
284 spinRefresh->setSizePolicy(sizePolicy);
285 spinRefresh->setMinimum(1);
286 spinRefresh->setMaximum(600);
287 spinRefresh->setSingleStep(10);
288 spinRefresh->setValue(60);
289 hLayout->addWidget(spinRefresh);
290 hLayout->addWidget(buttonBox);
292 verticalLayout->addLayout(hLayout);
294 tray = new QSystemTrayIcon(TrayMonitor);
295 QMenu* stmenu = new QMenu(TrayMonitor);
297 QAction *actShow = new QAction(QApplication::translate("TrayMonitor",
299 0, QApplication::UnicodeUTF8),TrayMonitor);
300 QAction* actQuit = new QAction(QApplication::translate("TrayMonitor",
302 0, QApplication::UnicodeUTF8),TrayMonitor);
303 QAction* actAbout = new QAction(QApplication::translate("TrayMonitor",
305 0, QApplication::UnicodeUTF8),TrayMonitor);
306 QAction* actRun = new QAction(QApplication::translate("TrayMonitor",
308 0, QApplication::UnicodeUTF8),TrayMonitor);
309 stmenu->addAction(actShow);
310 stmenu->addAction(actRun);
311 stmenu->addAction(actAbout);
312 stmenu->addSeparator();
313 stmenu->addAction(actQuit);
315 connect(actRun, SIGNAL(triggered()), this, SLOT(cb_run()));
316 connect(actShow, SIGNAL(triggered()), this, SLOT(cb_show()));
317 connect(actQuit, SIGNAL(triggered()), this, SLOT(cb_quit()));
318 connect(actAbout, SIGNAL(triggered()), this, SLOT(cb_about()));
319 connect(spinRefresh, SIGNAL(valueChanged(int)), this, SLOT(cb_refresh(int)));
320 connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
321 this, SLOT(cb_trayIconActivated(QSystemTrayIcon::ActivationReason)));
323 tray->setContextMenu(stmenu);
324 QIcon icon(":/images/cartridge1.png");
326 tray->setToolTip(QString("Bacula Tray Monitor"));
329 retranslateUi(TrayMonitor);
330 QMetaObject::connectSlotsByName(TrayMonitor);
333 void retranslateUi(QMainWindow *TrayMonitor)
335 TrayMonitor->setWindowTitle(QApplication::translate("TrayMonitor", "Bacula Tray Monitor", 0, QApplication::UnicodeUTF8));
340 QApplication::quit();
343 void cb_refresh(int val) {
345 timer->setInterval(val*1000);
350 QMessageBox::about(this, "Bacula Tray Monitor", "Bacula Tray Monitor\n"
351 "For more information, see: www.baculasystems.com\n"
352 "Copyright (C) 1999-2015, Kern Sibbald.\n"
353 "License AGPLv3 see LICENSE.");
358 RunDlg *runbox = new RunDlg(director);
363 void cb_trayIconActivated(QSystemTrayIcon::ActivationReason r) {
364 if (r == QSystemTrayIcon::Trigger) {
369 void refresh_screen() {
370 // qDebug() << "refresh_screen()";
373 // qDebug() << " -> OK";
388 #endif /* TRAYUI_H */