2 Bacula® - The Network Backup Solution
4 Copyright (C) 2011-2011 Free Software Foundation Europe e.V.
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 three of the GNU Affero General Public
10 License as published by the Free Software Foundation, which is
11 listed in the file LICENSE.
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.
18 You should have received a copy of the GNU Affero 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
23 Bacula® is a registered trademark of Kern Sibbald.
25 The licensor of Bacula is the Free Software Foundation Europe
26 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
27 Switzerland, email:ftf@fsfeurope.org.
34 #include <QApplication>
35 #include <QButtonGroup>
36 #include <QDialogButtonBox>
37 #include <QHeaderView>
38 #include <QMainWindow>
39 #include <QPlainTextEdit>
42 #include <QVBoxLayout>
48 #include <QSystemTrayIcon>
51 #include <QMessageBox>
54 #include "ui/ui_run.h"
55 #include "tray-monitor.h"
58 class RunDlg: public QDialog, public Ui::runForm
65 void fill(QComboBox *cb, QStringList &lst) {
69 cb->setEnabled(false);
72 RunDlg(monitoritem *i) {
74 struct job_defaults jdefault;
78 qDebug() << "start getting elements";
79 get_list(item, ".jobs type=B", res.job_list);
81 if (res.job_list.length() == 0) {
83 msgBox.setText("This restricted console doesn't have access to Backup jobs");
84 msgBox.setIcon(QMessageBox::Warning);
90 get_list(item, ".pools", res.pool_list);
91 get_list(item, ".clients", res.client_list);
92 get_list(item, ".storage", res.storage_list);
93 res.levels << "Full" << "Incremental" << "Differential";
94 get_list(item, ".filesets", res.fileset_list);
95 get_list(item, ".messages", res.messages_list);
99 qDebug() << " -> done";
100 label_5->setVisible(false);
101 bootstrap->setVisible(false);
102 jobCombo->addItems(res.job_list);
103 fill(filesetCombo, res.fileset_list);
104 fill(levelCombo, res.levels);
105 fill(clientCombo, res.client_list);
106 fill(poolCombo, res.pool_list);
107 fill(storageCombo, res.storage_list);
108 dateTimeEdit->setDateTime(dt.currentDateTime());
109 fill(messagesCombo, res.messages_list);
110 messagesCombo->setEnabled(false);
112 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
113 connect(cancelButton, SIGNAL(pressed()), this, SLOT(deleteLater()));
114 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
120 void okButtonPushed()
124 if (jobCombo->isEnabled()) {
125 cmd += " job=\"" + jobCombo->currentText() + "\"" ;
127 if (filesetCombo->isEnabled()) {
128 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
130 cmd += " level=\"" + levelCombo->currentText() + "\"";
131 if (clientCombo->isEnabled()) {
132 cmd += " client=\"" + clientCombo->currentText() + "\"" ;
134 if (poolCombo->isEnabled()) {
135 cmd += " pool=\"" + poolCombo->currentText() + "\"";
137 if (storageCombo->isEnabled()) {
138 cmd += " storage=\"" + storageCombo->currentText() + "\"";
140 cmd += " priority=\"" + QString().setNum(prioritySpin->value()) + "\"";
141 cmd += " when=\"" + dateTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss") + "\"";
143 " messages=\"" << messagesCombo->currentText() << "\"";
144 /* FIXME when there is an option to modify the messages resoruce associated
149 item->D_sock->fsend("%s", cmd.toUtf8().data());
151 while(bnet_recv(item->D_sock) >= 0) {output += item->D_sock->msg;}
153 msgBox.setText(output);
158 void job_name_change(int)
160 job_defaults job_defs;
161 job_defs.job_name = jobCombo->currentText();
163 if (item->get_job_defaults(job_defs)) {
164 typeLabel->setText("<H3>"+job_defs.type+"</H3>");
165 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
166 levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
167 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
168 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
169 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
170 messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
181 class TrayUI: public QMainWindow
186 QWidget *centralwidget;
187 QTabWidget *tabWidget;
188 QStatusBar *statusbar;
189 QHash<QString, QPlainTextEdit*> hash;
190 monitoritem* director;
192 QSystemTrayIcon *tray;
193 QSpinBox *spinRefresh;
196 QPlainTextEdit *getTextEdit(char *title)
198 return hash.value(QString(title));
201 void clearText(char *title)
203 QPlainTextEdit *w = getTextEdit(title);
210 void appendText(char *title, char *line)
212 QPlainTextEdit *w = getTextEdit(title);
216 w->appendPlainText(QString(line));
219 void addDirector(monitoritem *item)
224 void addTab(char *title)
226 QString t = QString(title);
227 QWidget *tab = new QWidget();
228 QVBoxLayout *vLayout = new QVBoxLayout(tab);
229 QPlainTextEdit *plainTextEdit = new QPlainTextEdit(tab);
230 plainTextEdit->setObjectName(t);
231 plainTextEdit->setReadOnly(true);
232 plainTextEdit->setFont(QFont("courier"));
233 vLayout->addWidget(plainTextEdit);
234 hash.insert(t, plainTextEdit);
235 tabWidget->addTab(tab, t);
241 timer = new QTimer(this);
242 connect(timer, SIGNAL(timeout()), this, SLOT(refresh_screen()));
244 timer->start(spinRefresh->value()*1000);
247 void setupUi(QMainWindow *TrayMonitor)
251 if (TrayMonitor->objectName().isEmpty())
252 TrayMonitor->setObjectName(QString::fromUtf8("TrayMonitor"));
253 TrayMonitor->setWindowIcon(QIcon(":/images/cartridge1.png"));
254 TrayMonitor->resize(789, 595);
255 centralwidget = new QWidget(TrayMonitor);
256 centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
257 QVBoxLayout *verticalLayout = new QVBoxLayout(centralwidget);
258 verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
259 tabWidget = new QTabWidget(centralwidget);
260 tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
261 tabWidget->setTabPosition(QTabWidget::North);
262 tabWidget->setTabShape(QTabWidget::Rounded);
263 tabWidget->setTabsClosable(false);
264 verticalLayout->addWidget(tabWidget);
266 QDialogButtonBox *buttonBox = new QDialogButtonBox(centralwidget);
267 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
268 buttonBox->setStandardButtons(QDialogButtonBox::Close);
269 connect(buttonBox, SIGNAL(rejected()), this, SLOT(cb_show()));
271 TrayMonitor->setCentralWidget(centralwidget);
272 statusbar = new QStatusBar(TrayMonitor);
273 statusbar->setObjectName(QString::fromUtf8("statusbar"));
274 TrayMonitor->setStatusBar(statusbar);
276 QHBoxLayout *hLayout = new QHBoxLayout();
277 QLabel *refreshlabel = new QLabel(centralwidget);
278 refreshlabel->setText("Refresh:");
279 hLayout->addWidget(refreshlabel);
280 spinRefresh = new QSpinBox(centralwidget);
281 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
282 sizePolicy.setHorizontalStretch(0);
283 sizePolicy.setVerticalStretch(0);
284 sizePolicy.setHeightForWidth(spinRefresh->sizePolicy().hasHeightForWidth());
285 spinRefresh->setSizePolicy(sizePolicy);
286 spinRefresh->setMinimum(1);
287 spinRefresh->setMaximum(600);
288 spinRefresh->setSingleStep(10);
289 spinRefresh->setValue(60);
290 hLayout->addWidget(spinRefresh);
291 hLayout->addWidget(buttonBox);
293 verticalLayout->addLayout(hLayout);
295 tray = new QSystemTrayIcon(TrayMonitor);
296 QMenu* stmenu = new QMenu(TrayMonitor);
298 QAction *actShow = new QAction(QApplication::translate("TrayMonitor",
300 0, QApplication::UnicodeUTF8),TrayMonitor);
301 QAction* actQuit = new QAction(QApplication::translate("TrayMonitor",
303 0, QApplication::UnicodeUTF8),TrayMonitor);
304 QAction* actAbout = new QAction(QApplication::translate("TrayMonitor",
306 0, QApplication::UnicodeUTF8),TrayMonitor);
307 QAction* actRun = new QAction(QApplication::translate("TrayMonitor",
309 0, QApplication::UnicodeUTF8),TrayMonitor);
310 stmenu->addAction(actShow);
311 stmenu->addAction(actRun);
312 stmenu->addAction(actAbout);
313 stmenu->addSeparator();
314 stmenu->addAction(actQuit);
316 connect(actRun, SIGNAL(triggered()), this, SLOT(cb_run()));
317 connect(actShow, SIGNAL(triggered()), this, SLOT(cb_show()));
318 connect(actQuit, SIGNAL(triggered()), this, SLOT(cb_quit()));
319 connect(actAbout, SIGNAL(triggered()), this, SLOT(cb_about()));
320 connect(spinRefresh, SIGNAL(valueChanged(int)), this, SLOT(cb_refresh(int)));
321 connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
322 this, SLOT(cb_trayIconActivated(QSystemTrayIcon::ActivationReason)));
324 tray->setContextMenu(stmenu);
325 QIcon icon(":/images/cartridge1.png");
327 tray->setToolTip(QString("Bacula Tray Monitor"));
330 retranslateUi(TrayMonitor);
331 QMetaObject::connectSlotsByName(TrayMonitor);
334 void retranslateUi(QMainWindow *TrayMonitor)
336 TrayMonitor->setWindowTitle(QApplication::translate("TrayMonitor", "Bacula Tray Monitor", 0, QApplication::UnicodeUTF8));
341 QApplication::quit();
344 void cb_refresh(int val) {
346 timer->setInterval(val*1000);
351 QMessageBox::about(this, "Bacula Tray Monitor", "Bacula Tray Monitor\n"
352 "For more information, see: www.baculasystems.com\n"
353 "Copyright (C) 1999-2010, Bacula Systems(R) SA\n"
354 "Licensed under GNU AGPLv3.");
359 RunDlg *runbox = new RunDlg(director);
364 void cb_trayIconActivated(QSystemTrayIcon::ActivationReason r) {
365 if (r == QSystemTrayIcon::Trigger) {
370 void refresh_screen() {
371 // qDebug() << "refresh_screen()";
374 // qDebug() << " -> OK";
389 #endif /* TRAYUI_H */