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 # ifndef _STAT_DEFINED
35 # define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */
40 #include <QApplication>
41 #include <QButtonGroup>
42 #include <QDialogButtonBox>
43 #include <QHeaderView>
44 #include <QMainWindow>
45 #include <QPlainTextEdit>
48 #include <QVBoxLayout>
54 #include <QSystemTrayIcon>
57 #include <QMessageBox>
61 #include "ui/ui_run.h"
62 #include "tray-monitor.h"
64 class RunDlg: public QDialog, public Ui::runForm
71 void fill(QComboBox *cb, QStringList &lst) {
75 cb->setEnabled(false);
78 RunDlg(monitoritem *i) {
80 struct job_defaults jdefault;
84 qDebug() << "start getting elements";
85 get_list(item, ".jobs type=B", res.job_list);
87 if (res.job_list.length() == 0) {
89 msgBox.setText("This restricted console doesn't have access to Backup jobs");
90 msgBox.setIcon(QMessageBox::Warning);
96 get_list(item, ".pools", res.pool_list);
97 get_list(item, ".clients", res.client_list);
98 get_list(item, ".storage", res.storage_list);
99 res.levels << "Full" << "Incremental" << "Differential";
100 get_list(item, ".filesets", res.fileset_list);
101 get_list(item, ".messages", res.messages_list);
105 qDebug() << " -> done";
106 label_5->setVisible(false);
107 bootstrap->setVisible(false);
108 jobCombo->addItems(res.job_list);
109 fill(filesetCombo, res.fileset_list);
110 fill(levelCombo, res.levels);
111 fill(clientCombo, res.client_list);
112 fill(poolCombo, res.pool_list);
113 fill(storageCombo, res.storage_list);
114 dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss");
115 dateTimeEdit->setDateTime(dt.currentDateTime());
116 fill(messagesCombo, res.messages_list);
117 messagesCombo->setEnabled(false);
119 connect(jobCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(job_name_change(int)));
120 connect(cancelButton, SIGNAL(pressed()), this, SLOT(deleteLater()));
121 connect(okButton, SIGNAL(pressed()), this, SLOT(okButtonPushed()));
127 void okButtonPushed()
131 if (jobCombo->isEnabled()) {
132 cmd += " job=\"" + jobCombo->currentText() + "\"" ;
134 if (filesetCombo->isEnabled()) {
135 cmd += " fileset=\"" + filesetCombo->currentText() + "\"";
137 cmd += " level=\"" + levelCombo->currentText() + "\"";
138 if (clientCombo->isEnabled()) {
139 cmd += " client=\"" + clientCombo->currentText() + "\"" ;
141 if (poolCombo->isEnabled()) {
142 cmd += " pool=\"" + poolCombo->currentText() + "\"";
144 if (storageCombo->isEnabled()) {
145 cmd += " storage=\"" + storageCombo->currentText() + "\"";
147 cmd += " priority=\"" + QString().setNum(prioritySpin->value()) + "\"";
148 cmd += " when=\"" + dateTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss") + "\"";
150 " messages=\"" << messagesCombo->currentText() << "\"";
151 /* FIXME when there is an option to modify the messages resoruce associated
156 item->D_sock->fsend("%s", cmd.toUtf8().data());
158 while(bnet_recv(item->D_sock) >= 0) {output += item->D_sock->msg;}
160 msgBox.setText(output);
165 void job_name_change(int)
167 job_defaults job_defs;
168 job_defs.job_name = jobCombo->currentText();
170 if (item->get_job_defaults(job_defs)) {
171 typeLabel->setText("<H3>"+job_defs.type+"</H3>");
172 filesetCombo->setCurrentIndex(filesetCombo->findText(job_defs.fileset_name, Qt::MatchExactly));
173 levelCombo->setCurrentIndex(levelCombo->findText(job_defs.level, Qt::MatchExactly));
174 clientCombo->setCurrentIndex(clientCombo->findText(job_defs.client_name, Qt::MatchExactly));
175 poolCombo->setCurrentIndex(poolCombo->findText(job_defs.pool_name, Qt::MatchExactly));
176 storageCombo->setCurrentIndex(storageCombo->findText(job_defs.store_name, Qt::MatchExactly));
177 messagesCombo->setCurrentIndex(messagesCombo->findText(job_defs.messages_name, Qt::MatchExactly));
188 class TrayUI: public QMainWindow
193 QWidget *centralwidget;
194 QTabWidget *tabWidget;
195 QStatusBar *statusbar;
196 QHash<QString, QPlainTextEdit*> hash;
197 monitoritem* director;
199 QSystemTrayIcon *tray;
200 QSpinBox *spinRefresh;
203 QPlainTextEdit *getTextEdit(char *title)
205 return hash.value(QString(title));
208 void clearText(char *title)
210 QPlainTextEdit *w = getTextEdit(title);
217 void appendText(char *title, char *line)
219 QPlainTextEdit *w = getTextEdit(title);
223 w->appendPlainText(QString(line));
226 void addDirector(monitoritem *item)
231 void addTab(char *title)
233 QString t = QString(title);
234 QWidget *tab = new QWidget();
235 QVBoxLayout *vLayout = new QVBoxLayout(tab);
236 QPlainTextEdit *plainTextEdit = new QPlainTextEdit(tab);
237 plainTextEdit->setObjectName(t);
238 plainTextEdit->setReadOnly(true);
239 plainTextEdit->setFont(QFont("courier"));
240 vLayout->addWidget(plainTextEdit);
241 hash.insert(t, plainTextEdit);
242 tabWidget->addTab(tab, t);
248 timer = new QTimer(this);
249 connect(timer, SIGNAL(timeout()), this, SLOT(refresh_screen()));
251 timer->start(spinRefresh->value()*1000);
254 void setupUi(QMainWindow *TrayMonitor)
258 if (TrayMonitor->objectName().isEmpty())
259 TrayMonitor->setObjectName(QString::fromUtf8("TrayMonitor"));
260 TrayMonitor->setWindowIcon(QIcon(":/images/cartridge1.png"));
261 TrayMonitor->resize(789, 595);
262 centralwidget = new QWidget(TrayMonitor);
263 centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
264 QVBoxLayout *verticalLayout = new QVBoxLayout(centralwidget);
265 verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
266 tabWidget = new QTabWidget(centralwidget);
267 tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
268 tabWidget->setTabPosition(QTabWidget::North);
269 tabWidget->setTabShape(QTabWidget::Rounded);
270 tabWidget->setTabsClosable(false);
271 verticalLayout->addWidget(tabWidget);
273 QDialogButtonBox *buttonBox = new QDialogButtonBox(centralwidget);
274 buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
275 buttonBox->setStandardButtons(QDialogButtonBox::Close);
276 connect(buttonBox, SIGNAL(rejected()), this, SLOT(cb_show()));
278 TrayMonitor->setCentralWidget(centralwidget);
279 statusbar = new QStatusBar(TrayMonitor);
280 statusbar->setObjectName(QString::fromUtf8("statusbar"));
281 TrayMonitor->setStatusBar(statusbar);
283 QHBoxLayout *hLayout = new QHBoxLayout();
284 QLabel *refreshlabel = new QLabel(centralwidget);
285 refreshlabel->setText("Refresh:");
286 hLayout->addWidget(refreshlabel);
287 spinRefresh = new QSpinBox(centralwidget);
288 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
289 sizePolicy.setHorizontalStretch(0);
290 sizePolicy.setVerticalStretch(0);
291 sizePolicy.setHeightForWidth(spinRefresh->sizePolicy().hasHeightForWidth());
292 spinRefresh->setSizePolicy(sizePolicy);
293 spinRefresh->setMinimum(1);
294 spinRefresh->setMaximum(600);
295 spinRefresh->setSingleStep(10);
296 spinRefresh->setValue(60);
297 hLayout->addWidget(spinRefresh);
298 hLayout->addWidget(buttonBox);
300 verticalLayout->addLayout(hLayout);
302 tray = new QSystemTrayIcon(TrayMonitor);
303 QMenu* stmenu = new QMenu(TrayMonitor);
305 QAction *actShow = new QAction(QApplication::translate("TrayMonitor",
307 0, QApplication::UnicodeUTF8),TrayMonitor);
308 QAction* actQuit = new QAction(QApplication::translate("TrayMonitor",
310 0, QApplication::UnicodeUTF8),TrayMonitor);
311 QAction* actAbout = new QAction(QApplication::translate("TrayMonitor",
313 0, QApplication::UnicodeUTF8),TrayMonitor);
314 QAction* actRun = new QAction(QApplication::translate("TrayMonitor",
316 0, QApplication::UnicodeUTF8),TrayMonitor);
317 stmenu->addAction(actShow);
318 stmenu->addAction(actRun);
319 stmenu->addAction(actAbout);
320 stmenu->addSeparator();
321 stmenu->addAction(actQuit);
323 connect(actRun, SIGNAL(triggered()), this, SLOT(cb_run()));
324 connect(actShow, SIGNAL(triggered()), this, SLOT(cb_show()));
325 connect(actQuit, SIGNAL(triggered()), this, SLOT(cb_quit()));
326 connect(actAbout, SIGNAL(triggered()), this, SLOT(cb_about()));
327 connect(spinRefresh, SIGNAL(valueChanged(int)), this, SLOT(cb_refresh(int)));
328 connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
329 this, SLOT(cb_trayIconActivated(QSystemTrayIcon::ActivationReason)));
331 tray->setContextMenu(stmenu);
332 QIcon icon(":/images/cartridge1.png");
334 tray->setToolTip(QString("Bacula Tray Monitor"));
337 retranslateUi(TrayMonitor);
338 QMetaObject::connectSlotsByName(TrayMonitor);
341 void retranslateUi(QMainWindow *TrayMonitor)
343 TrayMonitor->setWindowTitle(QApplication::translate("TrayMonitor", "Bacula Tray Monitor", 0, QApplication::UnicodeUTF8));
348 QApplication::quit();
351 void cb_refresh(int val) {
353 timer->setInterval(val*1000);
358 QMessageBox::about(this, "Bacula Tray Monitor", "Bacula Tray Monitor\n"
359 "For more information, see: www.baculasystems.com\n"
360 "Copyright (C) 1999-2010, Bacula Systems(R) SA\n"
361 "Licensed under GNU AGPLv3.");
366 RunDlg *runbox = new RunDlg(director);
371 void cb_trayIconActivated(QSystemTrayIcon::ActivationReason r) {
372 if (r == QSystemTrayIcon::Trigger) {
377 void refresh_screen() {
378 // qDebug() << "refresh_screen()";
381 // qDebug() << " -> OK";
396 #endif /* TRAYUI_H */