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
40 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
43 setupUi(this); /* Setup UI defined by main.ui (designer) */
45 m_console = new Console(stackedWidget);
46 stackedWidget->setCurrentIndex(0);
59 void MainWin::resetFocus()
64 void MainWin::keyPressEvent(QKeyEvent *event)
66 if (m_cmd_history.size() == 0) {
70 switch (event->key()) {
72 if (m_cmd_last < 0 || m_cmd_last >= (m_cmd_history.size()-1)) {
79 if (m_cmd_last == 0) {
83 if (m_cmd_last < 0 || m_cmd_last > (m_cmd_history.size()-1)) {
84 m_cmd_last = m_cmd_history.size() - 1;
93 lineEdit->setText(m_cmd_history[m_cmd_last]);
96 void MainWin::createConnections()
98 /* Connect signals to slots */
99 connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
100 connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
102 connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this,
103 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
104 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
105 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
106 connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this,
107 SLOT(treeItemClicked(QTreeWidgetItem *, int)));
108 connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
109 SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
111 connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
112 connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
113 connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
114 connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
115 connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelDialogClicked()));
116 connect(actionRun, SIGNAL(triggered()), this, SLOT(runDialogClicked()));
117 connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreDialogClicked()));
121 * Reimplementation of QWidget closeEvent virtual function
123 void MainWin::closeEvent(QCloseEvent *event)
126 m_console->writeSettings();
127 m_console->terminate();
131 void MainWin::writeSettings()
133 QSettings settings("bacula.org", "bat");
135 settings.beginGroup("MainWin");
136 settings.setValue("winSize", size());
137 settings.setValue("winPos", pos());
141 void MainWin::readSettings()
143 QSettings settings("bacula.org", "bat");
145 settings.beginGroup("MainWin");
146 resize(settings.value("winSize", QSize(1041, 801)).toSize());
147 move(settings.value("winPos", QPoint(200, 150)).toPoint());
151 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
154 int index = item->text(1).toInt();
155 if (index >= 0 && index < 4) {
156 stackedWidget->setCurrentIndex(index);
162 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
165 int index = item->text(1).toInt();
166 /* ***FIXME**** make this automatic */
167 if (index >= 0 && index < 4) {
168 stackedWidget->setCurrentIndex(index);
172 void MainWin::labelDialogClicked()
174 new labelDialog(m_console);
177 void MainWin::runDialogClicked()
179 new runDialog(m_console);
182 void MainWin::restoreDialogClicked()
184 new prerestoreDialog(m_console);
190 * The user just finished typing a line in the command line edit box
192 void MainWin::input_line()
194 QString cmdStr = lineEdit->text(); /* Get the text */
195 lineEdit->clear(); /* clear the lineEdit box */
196 if (m_console->is_connected()) {
197 m_console->display_text(cmdStr + "\n");
198 m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
200 set_status("Director not connected. Click on connect button.");
202 m_cmd_history.append(cmdStr);
207 void MainWin::about()
209 QMessageBox::about(this, tr("About bat"),
210 tr("<br><h2>bat 0.1</h2>"
211 "<p>Copyright © " BYEAR " Free Software Foundation Europe e.V."
212 "<p>The <b>bat</b> is an administrative console"
213 " interface to the Director."));
216 void MainWin::set_statusf(const char *fmt, ...)
221 va_start(arg_ptr, fmt);
222 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
227 void MainWin::set_status_ready()
229 set_status(" Ready");
232 void MainWin::set_status(const char *buf)
234 statusBar()->showMessage(buf);