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()
68 QTreeWidgetItem *item, *topItem;
70 /* Create console tree stacked widget item */
71 m_console = new Console(stackedWidget);
72 /* Console is special needs director*/
73 /* Just take the first Director */
75 dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
76 m_console->setDirRes(dir);
78 /* The top tree item representing the director */
79 topItem = createTopPage(dir->name());
80 topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
81 /* Create Tree Widget Item */
82 item = createPage("Console", topItem);
83 m_console->setTreeItem(item);
84 /* Append to bstacklist */
85 m_bstacklist.append(m_console);
86 /* Set BatStack m_treeItem */
87 m_console->SetBSTreeWidgetItem(item);
88 QBrush redBrush(Qt::red);
89 item->setForeground(0, redBrush);
91 /* Now with the console created, on with the rest, these are easy */
93 * 1. create tree widget item
94 * 2. create object passing pointer to tree widget item (modified constructors to pass QTreeWidget pointers)
95 * 3. append to stacklist */
98 item = createPage("brestore", topItem);
99 m_brestore = new bRestore(stackedWidget,item);
100 m_bstacklist.append(m_brestore);
102 /* lastly for now, the medialist */
103 item = createPage("Storage Tree", topItem );
104 m_medialist = new MediaList(stackedWidget, m_console, item);
105 m_bstacklist.append(m_medialist);
107 /* Iterate through and add to the stack */
108 for ( QList<BatStack*>::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) {
109 (*bstackItem)->AddTostack();
112 treeWidget->expandItem(topItem);
113 stackedWidget->setCurrentIndex(0);
116 /* Create a root Tree Widget */
117 QTreeWidgetItem *MainWin::createTopPage(char *name )
119 QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
120 item->setText(0, name);
124 /* Create A Tree Widget Item which will be associated with a Page in the stacked widget */
125 QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent)
127 QTreeWidgetItem *item = new QTreeWidgetItem(parent);
128 item->setText(0, name);
133 * Handle up and down arrow keys for the command line
136 void MainWin::keyPressEvent(QKeyEvent *event)
138 if (m_cmd_history.size() == 0) {
142 switch (event->key()) {
144 if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
151 if (m_cmd_last == 0) {
155 if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
156 m_cmd_last = m_cmd_history.size() - 1;
165 lineEdit->setText(m_cmd_history[m_cmd_last]);
168 void MainWin::createConnections()
170 /* Connect signals to slots */
171 connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
172 connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
174 /* connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this,
175 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
176 connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
177 SLOT(treeItemClicked(QTreeWidgetItem *, int))); Commented out because it was getting to clicked multiple times*/
178 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
179 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
180 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
181 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
183 connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
184 connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
185 connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
186 connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
187 connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelDialogClicked()));
188 connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked()));
189 connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked()));
193 * Reimplementation of QWidget closeEvent virtual function
195 void MainWin::closeEvent(QCloseEvent *event)
198 m_console->writeSettings();
199 m_console->terminate();
203 void MainWin::writeSettings()
205 QSettings settings("bacula.org", "bat");
207 settings.beginGroup("MainWin");
208 settings.setValue("winSize", size());
209 settings.setValue("winPos", pos());
213 void MainWin::readSettings()
215 QSettings settings("bacula.org", "bat");
217 settings.beginGroup("MainWin");
218 resize(settings.value("winSize", QSize(1041, 801)).toSize());
219 move(settings.value("winPos", QPoint(200, 150)).toPoint());
223 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
225 /* Iterate through and find the tree widget item clicked */
227 QList<BatStack*>::iterator bstackItem;
228 bstackItem = m_bstacklist.begin();
229 while ( bstackItem != m_bstacklist.end() ){
230 if ( item == (*bstackItem)->m_treeItem ) {
231 int stackindex=stackedWidget->indexOf( *bstackItem );
232 if( stackindex >= 0 ){
233 stackedWidget->setCurrentIndex(stackindex);
242 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
244 /* Iterate through and find the tree widget item double clicked */
246 QList<BatStack*>::iterator bstackItem;
247 bstackItem = m_bstacklist.begin();
248 while ( bstackItem != m_bstacklist.end() ){
249 if ( item == (*bstackItem)->m_treeItem ) {
250 /* This could be a call a virtual function ?? or just popup a popup menu for an action */
251 if ( (*bstackItem)->isStacked() == true ){
252 m_bstackpophold=*bstackItem;
253 QMenu *popup = new QMenu( treeWidget );
254 connect(popup->addAction("Pull Window Out"), SIGNAL(triggered()), this, SLOT(pullWindowOut()));
255 popup->exec(QCursor::pos());
257 (*bstackItem)->Togglestack();
264 void MainWin::labelDialogClicked()
266 new labelDialog(m_console);
269 void MainWin::runDialogClicked()
271 new runDialog(m_console);
274 void MainWin::restoreDialogClicked()
276 new prerestoreDialog(m_console);
282 * The user just finished typing a line in the command line edit box
284 void MainWin::input_line()
286 QString cmdStr = lineEdit->text(); /* Get the text */
287 lineEdit->clear(); /* clear the lineEdit box */
288 if (m_console->is_connected()) {
289 m_console->display_text(cmdStr + "\n");
290 m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
292 set_status("Director not connected. Click on connect button.");
294 m_cmd_history.append(cmdStr);
299 void MainWin::about()
301 QMessageBox::about(this, tr("About bat"),
302 tr("<br><h2>bat 0.2, by Kern Sibbald</h2>"
303 "<p>Copyright © " BYEAR " Free Software Foundation Europe e.V."
304 "<p>The <b>bat</b> is an administrative console"
305 " interface to the Director."));
308 void MainWin::set_statusf(const char *fmt, ...)
313 va_start(arg_ptr, fmt);
314 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
319 void MainWin::set_status_ready()
321 set_status(" Ready");
324 void MainWin::set_status(const char *buf)
326 statusBar()->showMessage(buf);
329 void MainWin::pullWindowOut()
331 m_bstackpophold->Togglestack();