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->setDisplayFormat("yyyy-MM-dd hh:mm:ss");
109 dateTimeEdit->setDateTime(dt.currentDateTime());
110 fill(messagesCombo, res.messages_list);
111 messagesCombo->setEnabled(false);
113 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
114 connect(cancelButton, SIGNAL(pressed()), this, SLOT(deleteLater()));
115 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
121 void okButtonPushed()
125 if (jobCombo->isEnabled()) {
126 cmd += " job=\"" + jobCombo->currentText() + "\"" ;
128 if (filesetCombo->isEnabled()) {
129 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
131 cmd += " level=\"" + levelCombo->currentText() + "\"";
132 if (clientCombo->isEnabled()) {
133 cmd += " client=\"" + clientCombo->currentText() + "\"" ;
135 if (poolCombo->isEnabled()) {
136 cmd += " pool=\"" + poolCombo->currentText() + "\"";
138 if (storageCombo->isEnabled()) {
139 cmd += " storage=\"" + storageCombo->currentText() + "\"";
141 cmd += " priority=\"" + QString().setNum(prioritySpin->value()) + "\"";
142 cmd += " when=\"" + dateTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss") + "\"";
144 " messages=\"" << messagesCombo->currentText() << "\"";
145 /* FIXME when there is an option to modify the messages resoruce associated
150 item->D_sock->fsend("%s", cmd.toUtf8().data());
152 while(bnet_recv(item->D_sock) >= 0) {output += item->D_sock->msg;}
154 msgBox.setText(output);
159 void job_name_change(int)
161 job_defaults job_defs;
162 job_defs.job_name = jobCombo->currentText();
164 if (item->get_job_defaults(job_defs)) {
165 typeLabel->setText("<H3>"+job_defs.type+"</H3>");
166 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
167 levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
168 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
169 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
170 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
171 messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
182 class TrayUI: public QMainWindow
187 QWidget *centralwidget;
188 QTabWidget *tabWidget;
189 QStatusBar *statusbar;
190 QHash<QString, QPlainTextEdit*> hash;
191 monitoritem* director;
193 QSystemTrayIcon *tray;
194 QSpinBox *spinRefresh;
197 QPlainTextEdit *getTextEdit(char *title)
199 return hash.value(QString(title));
202 void clearText(char *title)
204 QPlainTextEdit *w = getTextEdit(title);
211 void appendText(char *title, char *line)
213 QPlainTextEdit *w = getTextEdit(title);
217 w->appendPlainText(QString(line));
220 void addDirector(monitoritem *item)
225 void addTab(char *title)
227 QString t = QString(title);
228 QWidget *tab = new QWidget();
229 QVBoxLayout *vLayout = new QVBoxLayout(tab);
230 QPlainTextEdit *plainTextEdit = new QPlainTextEdit(tab);
231 plainTextEdit->setObjectName(t);
232 plainTextEdit->setReadOnly(true);
233 plainTextEdit->setFont(QFont("courier"));
234 vLayout->addWidget(plainTextEdit);
235 hash.insert(t, plainTextEdit);
236 tabWidget->addTab(tab, t);
242 timer = new QTimer(this);
243 connect(timer, SIGNAL(timeout()), this, SLOT(refresh_screen()));
245 timer->start(spinRefresh->value()*1000);
248 void setupUi(QMainWindow *TrayMonitor)
252 if (TrayMonitor->objectName().isEmpty())
253 TrayMonitor->setObjectName(QString::fromUtf8("TrayMonitor"));
254 TrayMonitor->setWindowIcon(QIcon(":/images/cartridge1.png"));
255 TrayMonitor->resize(789, 595);
256 centralwidget = new QWidget(TrayMonitor);
257 centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
258 QVBoxLayout *verticalLayout = new QVBoxLayout(centralwidget);
259 verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
260 tabWidget = new QTabWidget(centralwidget);
261 tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
262 tabWidget->setTabPosition(QTabWidget::North);
263 tabWidget->setTabShape(QTabWidget::Rounded);
264 tabWidget->setTabsClosable(false);
265 verticalLayout->addWidget(tabWidget);
267 QDialogButtonBox *buttonBox = new QDialogButtonBox(centralwidget);
268 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
269 buttonBox->setStandardButtons(QDialogButtonBox::Close);
270 connect(buttonBox, SIGNAL(rejected()), this, SLOT(cb_show()));
272 TrayMonitor->setCentralWidget(centralwidget);
273 statusbar = new QStatusBar(TrayMonitor);
274 statusbar->setObjectName(QString::fromUtf8("statusbar"));
275 TrayMonitor->setStatusBar(statusbar);
277 QHBoxLayout *hLayout = new QHBoxLayout();
278 QLabel *refreshlabel = new QLabel(centralwidget);
279 refreshlabel->setText("Refresh:");
280 hLayout->addWidget(refreshlabel);
281 spinRefresh = new QSpinBox(centralwidget);
282 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
283 sizePolicy.setHorizontalStretch(0);
284 sizePolicy.setVerticalStretch(0);
285 sizePolicy.setHeightForWidth(spinRefresh->sizePolicy().hasHeightForWidth());
286 spinRefresh->setSizePolicy(sizePolicy);
287 spinRefresh->setMinimum(1);
288 spinRefresh->setMaximum(600);
289 spinRefresh->setSingleStep(10);
290 spinRefresh->setValue(60);
291 hLayout->addWidget(spinRefresh);
292 hLayout->addWidget(buttonBox);
294 verticalLayout->addLayout(hLayout);
296 tray = new QSystemTrayIcon(TrayMonitor);
297 QMenu* stmenu = new QMenu(TrayMonitor);
299 QAction *actShow = new QAction(QApplication::translate("TrayMonitor",
301 0, QApplication::UnicodeUTF8),TrayMonitor);
302 QAction* actQuit = new QAction(QApplication::translate("TrayMonitor",
304 0, QApplication::UnicodeUTF8),TrayMonitor);
305 QAction* actAbout = new QAction(QApplication::translate("TrayMonitor",
307 0, QApplication::UnicodeUTF8),TrayMonitor);
308 QAction* actRun = new QAction(QApplication::translate("TrayMonitor",
310 0, QApplication::UnicodeUTF8),TrayMonitor);
311 stmenu->addAction(actShow);
312 stmenu->addAction(actRun);
313 stmenu->addAction(actAbout);
314 stmenu->addSeparator();
315 stmenu->addAction(actQuit);
317 connect(actRun, SIGNAL(triggered()), this, SLOT(cb_run()));
318 connect(actShow, SIGNAL(triggered()), this, SLOT(cb_show()));
319 connect(actQuit, SIGNAL(triggered()), this, SLOT(cb_quit()));
320 connect(actAbout, SIGNAL(triggered()), this, SLOT(cb_about()));
321 connect(spinRefresh, SIGNAL(valueChanged(int)), this, SLOT(cb_refresh(int)));
322 connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
323 this, SLOT(cb_trayIconActivated(QSystemTrayIcon::ActivationReason)));
325 tray->setContextMenu(stmenu);
326 QIcon icon(":/images/cartridge1.png");
328 tray->setToolTip(QString("Bacula Tray Monitor"));
331 retranslateUi(TrayMonitor);
332 QMetaObject::connectSlotsByName(TrayMonitor);
335 void retranslateUi(QMainWindow *TrayMonitor)
337 TrayMonitor->setWindowTitle(QApplication::translate("TrayMonitor", "Bacula Tray Monitor", 0, QApplication::UnicodeUTF8));
342 QApplication::quit();
345 void cb_refresh(int val) {
347 timer->setInterval(val*1000);
352 QMessageBox::about(this, "Bacula Tray Monitor", "Bacula Tray Monitor\n"
353 "For more information, see: www.baculasystems.com\n"
354 "Copyright (C) 1999-2010, Bacula Systems(R) SA\n"
355 "Licensed under GNU AGPLv3.");
360 RunDlg *runbox = new RunDlg(director);
365 void cb_trayIconActivated(QSystemTrayIcon::ActivationReason r) {
366 if (r == QSystemTrayIcon::Trigger) {
371 void refresh_screen() {
372 // qDebug() << "refresh_screen()";
375 // qDebug() << " -> OK";
390 #endif /* TRAYUI_H */