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");
64 void MainWin::createPages()
68 QTreeWidgetItem *item, *topItem;
69 m_console = new Console(stackedWidget);
70 stackedWidget->addWidget(m_console);
72 bRestore *brestore = new bRestore(stackedWidget);
73 stackedWidget->addWidget(brestore);
75 m_medialist = new MediaList(stackedWidget);
76 stackedWidget->addWidget(m_medialist);
78 /* Just take the first Director */
80 dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
81 m_console->setDirRes(dir);
84 topItem = createTopPage(dir->name(), false);
85 topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
87 item = createPage("Console", topItem, true);
88 m_console->setTreeItem(item);
89 QBrush redBrush(Qt::red);
90 item->setForeground(0, redBrush);
92 item = createPage("brestore", topItem, true);
93 item = createPage("MediaList", topItem, true);
95 treeWidget->expandItem(topItem);
97 stackedWidget->setCurrentIndex(0);
100 QTreeWidgetItem *MainWin::createTopPage(char *name, bool canDisplay)
102 QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
103 item->setText(0, name);
105 item->setData(0, Qt::UserRole, QVariant(m_pages++));
107 item->setData(0, Qt::UserRole, QVariant(-1));
112 QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent, bool canDisplay)
114 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
115 item->setText(0, name);
117 item->setData(0, Qt::UserRole, QVariant(m_pages++));
119 item->setData(0, Qt::UserRole, QVariant(-1));
126 * Handle up and down arrow keys for the command line
129 void MainWin::keyPressEvent(QKeyEvent *event)
131 if (m_cmd_history.size() == 0) {
135 switch (event->key()) {
137 if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
144 if (m_cmd_last == 0) {
148 if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
149 m_cmd_last = m_cmd_history.size() - 1;
158 lineEdit->setText(m_cmd_history[m_cmd_last]);
161 void MainWin::createConnections()
163 /* Connect signals to slots */
164 connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
165 connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
167 connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this,
168 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
169 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
170 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
171 connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
172 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
173 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
174 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
176 connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
177 connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
178 connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
179 connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
180 connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelDialogClicked()));
181 connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked()));
182 connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked()));
186 * Reimplementation of QWidget closeEvent virtual function
188 void MainWin::closeEvent(QCloseEvent *event)
191 m_console->writeSettings();
192 m_console->terminate();
196 void MainWin::writeSettings()
198 QSettings settings("bacula.org", "bat");
200 settings.beginGroup("MainWin");
201 settings.setValue("winSize", size());
202 settings.setValue("winPos", pos());
206 void MainWin::readSettings()
208 QSettings settings("bacula.org", "bat");
210 settings.beginGroup("MainWin");
211 resize(settings.value("winSize", QSize(1041, 801)).toSize());
212 move(settings.value("winPos", QPoint(200, 150)).toPoint());
216 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
218 int index = item->data(column, Qt::UserRole).toInt();
220 stackedWidget->setCurrentIndex(index);
226 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
228 int index = item->data(column, Qt::UserRole).toInt();
230 stackedWidget->setCurrentIndex(index);
232 m_medialist->DoDisplay(m_console);
237 void MainWin::labelDialogClicked()
239 new labelDialog(m_console);
242 void MainWin::runDialogClicked()
244 new runDialog(m_console);
247 void MainWin::restoreDialogClicked()
249 new prerestoreDialog(m_console);
255 * The user just finished typing a line in the command line edit box
257 void MainWin::input_line()
259 QString cmdStr = lineEdit->text(); /* Get the text */
260 lineEdit->clear(); /* clear the lineEdit box */
261 if (m_console->is_connected()) {
262 m_console->display_text(cmdStr + "\n");
263 m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
265 set_status("Director not connected. Click on connect button.");
267 m_cmd_history.append(cmdStr);
272 void MainWin::about()
274 QMessageBox::about(this, tr("About bat"),
275 tr("<br><h2>bat 0.2, by Kern Sibbald</h2>"
276 "<p>Copyright © " BYEAR " Free Software Foundation Europe e.V."
277 "<p>The <b>bat</b> is an administrative console"
278 " interface to the Director."));
281 void MainWin::set_statusf(const char *fmt, ...)
286 va_start(arg_ptr, fmt);
287 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
292 void MainWin::set_status_ready()
294 set_status(" Ready");
297 void MainWin::set_status(const char *buf)
299 statusBar()->showMessage(buf);