2 Bacula® - The Network Backup Solution
4 Copyright (C) 2011-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 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 Bacula® is a registered trademark of Kern Sibbald.
21 # ifndef _STAT_DEFINED
22 # define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */
27 #include <QApplication>
28 #include <QButtonGroup>
29 #include <QDialogButtonBox>
30 #include <QHeaderView>
31 #include <QMainWindow>
32 #include <QPlainTextEdit>
35 #include <QVBoxLayout>
41 #include <QSystemTrayIcon>
44 #include <QMessageBox>
48 #include "ui/ui_run.h"
49 #include "tray-monitor.h"
51 class RunDlg: public QDialog, public Ui::runForm
58 void fill(QComboBox *cb, QStringList &lst) {
62 cb->setEnabled(false);
65 RunDlg(monitoritem *i) {
67 struct job_defaults jdefault;
71 qDebug() << "start getting elements";
72 get_list(item, ".jobs type=B", res.job_list);
74 if (res.job_list.length() == 0) {
76 msgBox.setText("This restricted console doesn't have access to Backup jobs");
77 msgBox.setIcon(QMessageBox::Warning);
83 get_list(item, ".pools", res.pool_list);
84 get_list(item, ".clients", res.client_list);
85 get_list(item, ".storage", res.storage_list);
86 res.levels << "Full" << "Incremental" << "Differential";
87 get_list(item, ".filesets", res.fileset_list);
88 get_list(item, ".messages", res.messages_list);
92 qDebug() << " -> done";
93 label_5->setVisible(false);
94 bootstrap->setVisible(false);
95 jobCombo->addItems(res.job_list);
96 fill(filesetCombo, res.fileset_list);
97 fill(levelCombo, res.levels);
98 fill(clientCombo, res.client_list);
99 fill(poolCombo, res.pool_list);
100 fill(storageCombo, res.storage_list);
101 dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss");
102 dateTimeEdit->setDateTime(dt.currentDateTime());
103 fill(messagesCombo, res.messages_list);
104 messagesCombo->setEnabled(false);
106 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
107 connect(cancelButton, SIGNAL(pressed()), this, SLOT(deleteLater()));
108 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
114 void okButtonPushed()
118 if (jobCombo->isEnabled()) {
119 cmd += " job=\"" + jobCombo->currentText() + "\"" ;
121 if (filesetCombo->isEnabled()) {
122 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
124 cmd += " level=\"" + levelCombo->currentText() + "\"";
125 if (clientCombo->isEnabled()) {
126 cmd += " client=\"" + clientCombo->currentText() + "\"" ;
128 if (poolCombo->isEnabled()) {
129 cmd += " pool=\"" + poolCombo->currentText() + "\"";
131 if (storageCombo->isEnabled()) {
132 cmd += " storage=\"" + storageCombo->currentText() + "\"";
134 cmd += " priority=\"" + QString().setNum(prioritySpin->value()) + "\"";
135 cmd += " when=\"" + dateTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss") + "\"";
137 " messages=\"" << messagesCombo->currentText() << "\"";
138 /* FIXME when there is an option to modify the messages resoruce associated
143 item->D_sock->fsend("%s", cmd.toUtf8().data());
145 while(item->D_sock->recv() >= 0) {output += item->D_sock->msg;}
147 msgBox.setText(output);
152 void job_name_change(int)
154 job_defaults job_defs;
155 job_defs.job_name = jobCombo->currentText();
157 if (item->get_job_defaults(job_defs)) {
158 typeLabel->setText("<H3>"+job_defs.type+"</H3>");
159 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
160 levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
161 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
162 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
163 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
164 messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
175 class TrayUI: public QMainWindow
180 QWidget *centralwidget;
181 QTabWidget *tabWidget;
182 QStatusBar *statusbar;
183 QHash<QString, QPlainTextEdit*> hash;
184 monitoritem* director;
186 QSystemTrayIcon *tray;
187 QSpinBox *spinRefresh;
190 QPlainTextEdit *getTextEdit(char *title)
192 return hash.value(QString(title));
195 void clearText(char *title)
197 QPlainTextEdit *w = getTextEdit(title);
204 void appendText(char *title, char *line)
206 QPlainTextEdit *w = getTextEdit(title);
210 w->appendPlainText(QString(line));
213 void addDirector(monitoritem *item)
218 void addTab(char *title)
220 QString t = QString(title);
221 QWidget *tab = new QWidget();
222 QVBoxLayout *vLayout = new QVBoxLayout(tab);
223 QPlainTextEdit *plainTextEdit = new QPlainTextEdit(tab);
224 plainTextEdit->setObjectName(t);
225 plainTextEdit->setReadOnly(true);
226 plainTextEdit->setFont(QFont("courier"));
227 vLayout->addWidget(plainTextEdit);
228 hash.insert(t, plainTextEdit);
229 tabWidget->addTab(tab, t);
235 timer = new QTimer(this);
236 connect(timer, SIGNAL(timeout()), this, SLOT(refresh_screen()));
238 timer->start(spinRefresh->value()*1000);
241 void setupUi(QMainWindow *TrayMonitor)
245 if (TrayMonitor->objectName().isEmpty())
246 TrayMonitor->setObjectName(QString::fromUtf8("TrayMonitor"));
247 TrayMonitor->setWindowIcon(QIcon(":/images/cartridge1.png"));
248 TrayMonitor->resize(789, 595);
249 centralwidget = new QWidget(TrayMonitor);
250 centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
251 QVBoxLayout *verticalLayout = new QVBoxLayout(centralwidget);
252 verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
253 tabWidget = new QTabWidget(centralwidget);
254 tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
255 tabWidget->setTabPosition(QTabWidget::North);
256 tabWidget->setTabShape(QTabWidget::Rounded);
257 tabWidget->setTabsClosable(false);
258 verticalLayout->addWidget(tabWidget);
260 QDialogButtonBox *buttonBox = new QDialogButtonBox(centralwidget);
261 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
262 buttonBox->setStandardButtons(QDialogButtonBox::Close);
263 connect(buttonBox, SIGNAL(rejected()), this, SLOT(cb_show()));
265 TrayMonitor->setCentralWidget(centralwidget);
266 statusbar = new QStatusBar(TrayMonitor);
267 statusbar->setObjectName(QString::fromUtf8("statusbar"));
268 TrayMonitor->setStatusBar(statusbar);
270 QHBoxLayout *hLayout = new QHBoxLayout();
271 QLabel *refreshlabel = new QLabel(centralwidget);
272 refreshlabel->setText("Refresh:");
273 hLayout->addWidget(refreshlabel);
274 spinRefresh = new QSpinBox(centralwidget);
275 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
276 sizePolicy.setHorizontalStretch(0);
277 sizePolicy.setVerticalStretch(0);
278 sizePolicy.setHeightForWidth(spinRefresh->sizePolicy().hasHeightForWidth());
279 spinRefresh->setSizePolicy(sizePolicy);
280 spinRefresh->setMinimum(1);
281 spinRefresh->setMaximum(600);
282 spinRefresh->setSingleStep(10);
283 spinRefresh->setValue(60);
284 hLayout->addWidget(spinRefresh);
285 hLayout->addWidget(buttonBox);
287 verticalLayout->addLayout(hLayout);
289 tray = new QSystemTrayIcon(TrayMonitor);
290 QMenu* stmenu = new QMenu(TrayMonitor);
292 QAction *actShow = new QAction(QApplication::translate("TrayMonitor",
294 0, QApplication::UnicodeUTF8),TrayMonitor);
295 QAction* actQuit = new QAction(QApplication::translate("TrayMonitor",
297 0, QApplication::UnicodeUTF8),TrayMonitor);
298 QAction* actAbout = new QAction(QApplication::translate("TrayMonitor",
300 0, QApplication::UnicodeUTF8),TrayMonitor);
301 QAction* actRun = new QAction(QApplication::translate("TrayMonitor",
303 0, QApplication::UnicodeUTF8),TrayMonitor);
304 stmenu->addAction(actShow);
305 stmenu->addAction(actRun);
306 stmenu->addAction(actAbout);
307 stmenu->addSeparator();
308 stmenu->addAction(actQuit);
310 connect(actRun, SIGNAL(triggered()), this, SLOT(cb_run()));
311 connect(actShow, SIGNAL(triggered()), this, SLOT(cb_show()));
312 connect(actQuit, SIGNAL(triggered()), this, SLOT(cb_quit()));
313 connect(actAbout, SIGNAL(triggered()), this, SLOT(cb_about()));
314 connect(spinRefresh, SIGNAL(valueChanged(int)), this, SLOT(cb_refresh(int)));
315 connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
316 this, SLOT(cb_trayIconActivated(QSystemTrayIcon::ActivationReason)));
318 tray->setContextMenu(stmenu);
319 QIcon icon(":/images/cartridge1.png");
321 tray->setToolTip(QString("Bacula Tray Monitor"));
324 retranslateUi(TrayMonitor);
325 QMetaObject::connectSlotsByName(TrayMonitor);
328 void retranslateUi(QMainWindow *TrayMonitor)
330 TrayMonitor->setWindowTitle(QApplication::translate("TrayMonitor", "Bacula Tray Monitor", 0, QApplication::UnicodeUTF8));
335 QApplication::quit();
338 void cb_refresh(int val) {
340 timer->setInterval(val*1000);
345 QMessageBox::about(this, "Bacula Tray Monitor", "Bacula Tray Monitor\n"
346 "For more information, see: www.baculasystems.com\n"
347 "Copyright (C) 1999-2010, Bacula Systems(R) SA\n"
348 "Licensed under GNU AGPLv3.");
353 RunDlg *runbox = new RunDlg(director);
358 void cb_trayIconActivated(QSystemTrayIcon::ActivationReason r) {
359 if (r == QSystemTrayIcon::Trigger) {
364 void refresh_screen() {
365 // qDebug() << "refresh_screen()";
368 // qDebug() << " -> OK";
383 #endif /* TRAYUI_H */