]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/mainwin.cpp
767ae66cfc6f38049fb135f7f2abeeec2000ed75
[bacula/bacula] / bacula / src / qt-console / mainwin.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
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.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28
29 /*
30  *   Version $Id$
31  *
32  *  Main Window control for bat (qt-console)
33  *
34  *   Kern Sibbald, January MMVII
35  *
36  */ 
37
38 #include "bat.h"
39
40 MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
41 {
42    mainWin = this;
43    setupUi(this);                     /* Setup UI defined by main.ui (designer) */
44
45    m_console = new Console(stackedWidget);
46    stackedWidget->setCurrentIndex(0);
47
48    resetFocus();
49
50    createConnections();
51
52    this->show();
53
54    readSettings();
55
56    m_console->connect();
57 }
58
59 void MainWin::resetFocus()
60 {  
61    lineEdit->setFocus();
62 }   
63
64
65 void MainWin::createConnections()
66 {
67    /* Connect signals to slots */
68    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
69    connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
70
71    connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, 
72            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
73    connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, 
74            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
75    connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, 
76            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
77    connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, 
78            SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
79
80    connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
81    connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
82    connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
83    connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
84    connect(actionLabel, SIGNAL(triggered()), this,  SLOT(labelDialogClicked()));
85    connect(actionRun, SIGNAL(triggered()), this,  SLOT(runDialogClicked()));
86    connect(actionRestore, SIGNAL(triggered()), this,  SLOT(restoreDialogClicked()));
87 }
88
89 /* 
90  * Reimplementation of QWidget closeEvent virtual function   
91  */
92 void MainWin::closeEvent(QCloseEvent *event)
93 {
94    writeSettings();
95    m_console->writeSettings();
96    m_console->terminate();
97    event->accept();
98 }
99
100 void MainWin::writeSettings()
101 {
102    QSettings settings("bacula.org", "bat");
103
104    settings.beginGroup("MainWin");
105    settings.setValue("winSize", size());
106    settings.setValue("winPos", pos());
107    settings.endGroup();
108 }
109
110 void MainWin::readSettings()
111
112    QSettings settings("bacula.org", "bat");
113
114    settings.beginGroup("MainWin");
115    resize(settings.value("winSize", QSize(1041, 801)).toSize());
116    move(settings.value("winPos", QPoint(200, 150)).toPoint());
117    settings.endGroup();
118 }
119
120 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
121 {
122    (void)column;
123    int index = item->text(1).toInt();
124    if (index >= 0 && index < 4) {
125       stackedWidget->setCurrentIndex(index);
126    }
127 }
128
129 /*
130  */
131 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
132 {
133    (void)column;
134    int index = item->text(1).toInt();
135    /* ***FIXME**** make this automatic */
136    if (index >= 0 && index < 4) {
137       stackedWidget->setCurrentIndex(index);
138    }
139 }
140
141 void MainWin::labelDialogClicked() 
142 {
143    new labelDialog(m_console);
144 }
145
146 void MainWin::runDialogClicked() 
147 {
148    new runDialog(m_console);
149 }
150
151 void MainWin::restoreDialogClicked() 
152 {
153    new prerestoreDialog(m_console);
154 }
155
156
157
158 /*
159  * The user just finished typing a line in the command line edit box
160  */
161 void MainWin::input_line()
162 {
163    QString cmdStr = lineEdit->text();    /* Get the text */
164    lineEdit->clear();                    /* clear the lineEdit box */
165    if (m_console->is_connected()) {
166       m_console->display_text(cmdStr + "\n");
167       m_console->write_dir(cmdStr.toUtf8().data());         /* send to dir */
168    } else {
169       set_status("Director not connected. Click on connect button.");
170    }
171 }
172
173
174 void MainWin::about()
175 {
176    QMessageBox::about(this, tr("About bat"),
177             tr("<br><h2>bat 0.1</h2>"
178             "<p>Copyright &copy; " BYEAR " Free Software Foundation Europe e.V."
179             "<p>The <b>bat</b> is an administrative console"
180                " interface to the Director."));
181 }
182
183 void MainWin::set_statusf(const char *fmt, ...)
184 {
185    va_list arg_ptr;
186    char buf[1000];
187    int len;
188    va_start(arg_ptr, fmt);
189    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
190    va_end(arg_ptr);
191    set_status(buf);
192 // set_scroll_bar_to_end();
193 }
194
195 void MainWin::set_status_ready()
196 {
197    set_status(" Ready");
198 // set_scroll_bar_to_end();
199 }
200
201 void MainWin::set_status(const char *buf)
202 {
203    statusBar()->showMessage(buf);
204 // ready = false;
205 }