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()
67 QTreeWidgetItem *item, *topItem;
69 /* Create console tree stacked widget item */
70 m_console = new Console(stackedWidget);
71 /* Console is special -> needs director*/
72 /* Just take the first Director */
74 dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
75 m_console->setDirRes(dir);
77 /* The top tree item representing the director */
78 topItem = createTopPage(dir->name());
79 topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
80 /* Create Tree Widget Item */
81 item = createPage("Console", topItem);
82 m_console->setTreeItem(item);
83 /* Append to bstacklist */
84 m_bstacklist.append(m_console);
85 /* Set BatStack m_treeItem */
86 m_console->SetBSTreeWidgetItem(item);
87 QBrush redBrush(Qt::red);
88 item->setForeground(0, redBrush);
90 /* Now with the console created, on with the rest, these are easy */
92 * 1. create tree widget item
93 * 2. create object passing pointer to tree widget item (modified constructors to pass QTreeWidget pointers)
94 * 3. append to stacklist
95 * And it can even be done in one line.
99 m_bstacklist.append(new bRestore( stackedWidget, createPage("brestore", topItem) ));
101 /* lastly for now, the medialist */
102 m_bstacklist.append(new MediaList(stackedWidget, m_console, createPage("Storage Tree", topItem )));
104 /* Iterate through and add to the stack */
105 for ( QList<BatStack*>::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) {
106 (*bstackItem)->AddTostack();
109 treeWidget->expandItem(topItem);
110 stackedWidget->setCurrentIndex(0);
113 /* Create a root Tree Widget */
114 QTreeWidgetItem *MainWin::createTopPage(char *name )
116 QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
117 item->setText(0, name);
121 /* Create A Tree Widget Item which will be associated with a Page in the stacked widget */
122 QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent)
124 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
125 item->setText(0, name);
130 * Handle up and down arrow keys for the command line
133 void MainWin::keyPressEvent(QKeyEvent *event)
135 if (m_cmd_history.size() == 0) {
139 switch (event->key()) {
141 if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
148 if (m_cmd_last == 0) {
152 if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
153 m_cmd_last = m_cmd_history.size() - 1;
162 lineEdit->setText(m_cmd_history[m_cmd_last]);
165 void MainWin::createConnections()
167 /* Connect signals to slots */
168 connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
169 connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
171 /* connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this,
172 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
173 connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
174 SLOT(treeItemClicked(QTreeWidgetItem *, int))); Commented out because it was getting to clicked multiple times*/
175 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
176 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
177 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
178 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
180 connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
181 connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
182 connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
183 connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
184 connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelDialogClicked()));
185 connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked()));
186 connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked()));
190 * Reimplementation of QWidget closeEvent virtual function
192 void MainWin::closeEvent(QCloseEvent *event)
195 m_console->writeSettings();
196 m_console->terminate();
200 void MainWin::writeSettings()
202 QSettings settings("bacula.org", "bat");
204 settings.beginGroup("MainWin");
205 settings.setValue("winSize", size());
206 settings.setValue("winPos", pos());
210 void MainWin::readSettings()
212 QSettings settings("bacula.org", "bat");
214 settings.beginGroup("MainWin");
215 resize(settings.value("winSize", QSize(1041, 801)).toSize());
216 move(settings.value("winPos", QPoint(200, 150)).toPoint());
220 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
222 /* Iterate through and find the tree widget item clicked */
224 QList<BatStack*>::iterator bstackItem;
225 bstackItem = m_bstacklist.begin();
226 while ( bstackItem != m_bstacklist.end() ){
227 if ( item == (*bstackItem)->m_treeItem ) {
228 int stackindex=stackedWidget->indexOf( *bstackItem );
229 if( stackindex >= 0 ){
230 stackedWidget->setCurrentIndex(stackindex);
232 (*bstackItem)->PgSeltreeWidgetClicked();
240 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
242 /* Iterate through and find the tree widget item double clicked */
244 QList<BatStack*>::iterator bstackItem;
245 bstackItem = m_bstacklist.begin();
246 while ( bstackItem != m_bstacklist.end() ){
247 if ( item == (*bstackItem)->m_treeItem ) {
248 /* This could be a call a virtual function ?? or just popup a popup menu for an action */
249 if ( (*bstackItem)->isStacked() == true ){
250 m_bstackpophold=*bstackItem;
251 QMenu *popup = new QMenu( treeWidget );
252 connect(popup->addAction("Pull Window Out"), SIGNAL(triggered()), this, SLOT(pullWindowOut()));
253 popup->exec(QCursor::pos());
255 (*bstackItem)->Togglestack();
257 (*bstackItem)->PgSeltreeWidgetDoubleClicked();
263 void MainWin::labelDialogClicked()
265 new labelDialog(m_console);
268 void MainWin::runDialogClicked()
270 new runDialog(m_console);
273 void MainWin::restoreDialogClicked()
275 new prerestoreDialog(m_console);
281 * The user just finished typing a line in the command line edit box
283 void MainWin::input_line()
285 QString cmdStr = lineEdit->text(); /* Get the text */
286 lineEdit->clear(); /* clear the lineEdit box */
287 if (m_console->is_connected()) {
288 m_console->display_text(cmdStr + "\n");
289 m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
291 set_status("Director not connected. Click on connect button.");
293 m_cmd_history.append(cmdStr);
298 void MainWin::about()
300 QMessageBox::about(this, tr("About bat"),
301 tr("<br><h2>bat 0.2, by Kern Sibbald</h2>"
302 "<p>Copyright © " BYEAR " Free Software Foundation Europe e.V."
303 "<p>The <b>bat</b> is an administrative console"
304 " interface to the Director."));
307 void MainWin::set_statusf(const char *fmt, ...)
312 va_start(arg_ptr, fmt);
313 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
318 void MainWin::set_status_ready()
320 set_status(" Ready");
323 void MainWin::set_status(const char *buf)
325 statusBar()->showMessage(buf);
328 void MainWin::pullWindowOut()
330 m_bstackpophold->Togglestack();