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 m_console->AddTostack();
73 m_brestore = new bRestore(stackedWidget);
74 m_brestore->AddTostack();
76 m_medialist = new MediaList(stackedWidget, m_console);
77 m_medialist->AddTostack();
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("Storage Tree", topItem, true);
96 treeWidget->expandItem(topItem);
98 stackedWidget->setCurrentIndex(0);
101 /* Create a root Tree Widget */
102 QTreeWidgetItem *MainWin::createTopPage(char *name, bool canDisplay)
104 QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
105 item->setText(0, name);
107 item->setData(0, Qt::UserRole, QVariant(m_pages++));
109 item->setData(0, Qt::UserRole, QVariant(-1));
114 /* Create A Tree Widget Item Representing a Page */
115 QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent, bool canDisplay)
117 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
118 item->setText(0, name);
120 item->setData(0, Qt::UserRole, QVariant(m_pages++));
122 item->setData(0, Qt::UserRole, QVariant(-1));
129 * Handle up and down arrow keys for the command line
132 void MainWin::keyPressEvent(QKeyEvent *event)
134 if (m_cmd_history.size() == 0) {
138 switch (event->key()) {
140 if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
147 if (m_cmd_last == 0) {
151 if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
152 m_cmd_last = m_cmd_history.size() - 1;
161 lineEdit->setText(m_cmd_history[m_cmd_last]);
164 void MainWin::createConnections()
166 /* Connect signals to slots */
167 connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
168 connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
170 connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this,
171 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
172 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
173 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
174 connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
175 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
176 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
177 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
179 connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
180 connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
181 connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
182 connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
183 connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelDialogClicked()));
184 connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked()));
185 connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked()));
189 * Reimplementation of QWidget closeEvent virtual function
191 void MainWin::closeEvent(QCloseEvent *event)
194 m_console->writeSettings();
195 m_console->terminate();
199 void MainWin::writeSettings()
201 QSettings settings("bacula.org", "bat");
203 settings.beginGroup("MainWin");
204 settings.setValue("winSize", size());
205 settings.setValue("winPos", pos());
209 void MainWin::readSettings()
211 QSettings settings("bacula.org", "bat");
213 settings.beginGroup("MainWin");
214 resize(settings.value("winSize", QSize(1041, 801)).toSize());
215 move(settings.value("winPos", QPoint(200, 150)).toPoint());
219 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
221 /* There just has to be a more elegant way of doing this
222 * as more and more pages get added, this could get realllly long */
223 int treeindex = item->data(column, Qt::UserRole).toInt();
225 if( treeindex == 0 ) {
226 stackindex=stackedWidget->indexOf( m_console );
228 if( treeindex == 1 ) {
229 stackindex=stackedWidget->indexOf( m_brestore );
231 if( treeindex == 2 ) {
232 stackindex=stackedWidget->indexOf( m_medialist );
234 if( stackindex >= 0 ){
235 stackedWidget->setCurrentIndex(stackindex);
241 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
243 /* There just has to be a more elegant way of doing this
244 * as more and more pages get added, this could get realllly long */
245 int treeindex = item->data(column, Qt::UserRole).toInt();
246 if( treeindex == 0 ) {
247 m_console->Togglestack();
249 if( treeindex == 1 ) {
250 m_brestore->Togglestack();
252 if( treeindex == 2 ) {
253 m_medialist->Togglestack();
257 void MainWin::labelDialogClicked()
259 new labelDialog(m_console);
262 void MainWin::runDialogClicked()
264 new runDialog(m_console);
267 void MainWin::restoreDialogClicked()
269 new prerestoreDialog(m_console);
275 * The user just finished typing a line in the command line edit box
277 void MainWin::input_line()
279 QString cmdStr = lineEdit->text(); /* Get the text */
280 lineEdit->clear(); /* clear the lineEdit box */
281 if (m_console->is_connected()) {
282 m_console->display_text(cmdStr + "\n");
283 m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
285 set_status("Director not connected. Click on connect button.");
287 m_cmd_history.append(cmdStr);
292 void MainWin::about()
294 QMessageBox::about(this, tr("About bat"),
295 tr("<br><h2>bat 0.2, by Kern Sibbald</h2>"
296 "<p>Copyright © " BYEAR " Free Software Foundation Europe e.V."
297 "<p>The <b>bat</b> is an administrative console"
298 " interface to the Director."));
301 void MainWin::set_statusf(const char *fmt, ...)
306 va_start(arg_ptr, fmt);
307 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
312 void MainWin::set_status_ready()
314 set_status(" Ready");
317 void MainWin::set_status(const char *buf)
319 statusBar()->showMessage(buf);