2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2007 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 two of the GNU General Public
10 License as published by the Free Software Foundation plus additions
11 that are 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 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 John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
32 * Main Window control for bat (qt-console)
34 * Kern Sibbald, January MMVII
39 #include "medialist/medialist.h"
41 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
45 setupUi(this); /* Setup UI defined by main.ui (designer) */
47 treeWidget->setColumnCount(1);
48 treeWidget->setHeaderLabel("Select Page");
62 m_medialist->populateTree();
65 void MainWin::createPages()
69 QTreeWidgetItem *item, *topItem;
70 m_console = new Console(stackedWidget);
71 stackedWidget->addWidget(m_console);
73 bRestore *brestore = new bRestore(stackedWidget);
74 stackedWidget->addWidget(brestore);
76 m_medialist = new MediaList(stackedWidget, m_console);
77 stackedWidget->addWidget(m_medialist);
79 /* Just take the first Director */
81 dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
82 m_console->setDirRes(dir);
85 topItem = createTopPage(dir->name(), false);
86 topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
88 item = createPage("Console", topItem, true);
89 m_console->setTreeItem(item);
90 QBrush redBrush(Qt::red);
91 item->setForeground(0, redBrush);
93 item = createPage("brestore", topItem, true);
94 item = createPage("MediaList", topItem, true);
96 treeWidget->expandItem(topItem);
98 stackedWidget->setCurrentIndex(0);
101 QTreeWidgetItem *MainWin::createTopPage(char *name, bool canDisplay)
103 QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
104 item->setText(0, name);
106 item->setData(0, Qt::UserRole, QVariant(m_pages++));
108 item->setData(0, Qt::UserRole, QVariant(-1));
113 QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent, bool canDisplay)
115 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
116 item->setText(0, name);
118 item->setData(0, Qt::UserRole, QVariant(m_pages++));
120 item->setData(0, Qt::UserRole, QVariant(-1));
127 * Handle up and down arrow keys for the command line
130 void MainWin::keyPressEvent(QKeyEvent *event)
132 if (m_cmd_history.size() == 0) {
136 switch (event->key()) {
138 if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
145 if (m_cmd_last == 0) {
149 if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
150 m_cmd_last = m_cmd_history.size() - 1;
159 lineEdit->setText(m_cmd_history[m_cmd_last]);
162 void MainWin::createConnections()
164 /* Connect signals to slots */
165 connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
166 connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
168 connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this,
169 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
170 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
171 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
172 connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
173 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
174 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
175 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
177 connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
178 connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
179 connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
180 connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
181 connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelDialogClicked()));
182 connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked()));
183 connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked()));
187 * Reimplementation of QWidget closeEvent virtual function
189 void MainWin::closeEvent(QCloseEvent *event)
192 m_console->writeSettings();
193 m_console->terminate();
197 void MainWin::writeSettings()
199 QSettings settings("bacula.org", "bat");
201 settings.beginGroup("MainWin");
202 settings.setValue("winSize", size());
203 settings.setValue("winPos", pos());
207 void MainWin::readSettings()
209 QSettings settings("bacula.org", "bat");
211 settings.beginGroup("MainWin");
212 resize(settings.value("winSize", QSize(1041, 801)).toSize());
213 move(settings.value("winPos", QPoint(200, 150)).toPoint());
217 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
219 int index = item->data(column, Qt::UserRole).toInt();
221 stackedWidget->setCurrentIndex(index);
227 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
229 int index = item->data(column, Qt::UserRole).toInt();
231 stackedWidget->setCurrentIndex(index);
235 void MainWin::labelDialogClicked()
237 new labelDialog(m_console);
240 void MainWin::runDialogClicked()
242 new runDialog(m_console);
245 void MainWin::restoreDialogClicked()
247 new prerestoreDialog(m_console);
253 * The user just finished typing a line in the command line edit box
255 void MainWin::input_line()
257 QString cmdStr = lineEdit->text(); /* Get the text */
258 lineEdit->clear(); /* clear the lineEdit box */
259 if (m_console->is_connected()) {
260 m_console->display_text(cmdStr + "\n");
261 m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
263 set_status("Director not connected. Click on connect button.");
265 m_cmd_history.append(cmdStr);
270 void MainWin::about()
272 QMessageBox::about(this, tr("About bat"),
273 tr("<br><h2>bat 0.2, by Kern Sibbald</h2>"
274 "<p>Copyright © " BYEAR " Free Software Foundation Europe e.V."
275 "<p>The <b>bat</b> is an administrative console"
276 " interface to the Director."));
279 void MainWin::set_statusf(const char *fmt, ...)
284 va_start(arg_ptr, fmt);
285 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
290 void MainWin::set_status_ready()
292 set_status(" Ready");
295 void MainWin::set_status(const char *buf)
297 statusBar()->showMessage(buf);