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