]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/mainwin.cpp
kes Clarify some stored/acquire messages to indicate if the
[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    statusBar()->showMessage("Director not connected. Click on connect button.");
44
45    m_console = new Console(stackedWidget);
46    stackedWidget->setCurrentIndex(0);
47
48    lineEdit->setFocus();
49
50    createConnections();
51
52    readSettings();
53 }
54
55 #ifdef xxx
56    job_list      = get_and_fill_combo(run_dialog, "combo_job", ".jobs");
57    client_list   = get_and_fill_combo(run_dialog, "combo_client", ".clients");
58    fileset_list  = get_and_fill_combo(run_dialog, "combo_fileset", ".filesets");
59    messages_list = get_and_fill_combo(run_dialog, "combo_messages", ".msgs");
60    pool_list     = get_and_fill_combo(run_dialog, "combo_pool", ".pools");
61    storage_list  = get_and_fill_combo(run_dialog, "combo_storage", ".storage");
62    type_list     = get_and_fill_combo(run_dialog, "combo_type", ".types");
63    level_list    = get_and_fill_combo(run_dialog, "combo_level", ".levels");
64
65 static GList *get_list(char *cmd)
66 {
67    GList *options;
68    char *msg;
69
70    options = NULL;
71    write_director(cmd);
72    while (bnet_recv(UA_sock) > 0) {
73       strip_trailing_junk(UA_sock->msg);
74       msg = (char *)malloc(strlen(UA_sock->msg) + 1);
75       strcpy(msg, UA_sock->msg);
76       options = g_list_append(options, msg);
77    }
78    return options;
79
80 }
81 #endif
82
83 void MainWin::createConnections()
84 {
85    /* Connect signals to slots */
86    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
87    connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
88
89    connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, 
90            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
91    connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, 
92            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
93    connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, 
94            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
95    connect(treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, 
96            SLOT(treeItemDoubleClicked(QTreeWidgetItem *, int)));
97
98    connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
99    connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
100    connect(actionStatusDir, SIGNAL(triggered()), m_console, SLOT(status_dir()));
101    connect(actionSelectFont, SIGNAL(triggered()), m_console, SLOT(set_font()));
102 }
103
104 /* 
105  * Reimplementation of QWidget closeEvent virtual function   
106  */
107 void MainWin::closeEvent(QCloseEvent *event)
108 {
109    /* ***FIXME*** close any open sockets */
110    writeSettings();
111    m_console->writeSettings();
112    event->accept();
113 }
114
115 void MainWin::writeSettings()
116 {
117    QSettings settings("bacula.org", "bat");
118
119    settings.beginGroup("MainWin");
120    settings.setValue("winSize", size());
121    settings.setValue("winPos", pos());
122    settings.endGroup();
123 }
124
125 void MainWin::readSettings()
126
127    QSettings settings("bacula.org", "bat");
128
129    settings.beginGroup("MainWin");
130    resize(settings.value("winSize", QSize(1041, 801)).toSize());
131    move(settings.value("winPos", QPoint(200, 150)).toPoint());
132    settings.endGroup();
133 }
134
135 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
136 {
137    (void)column;
138    int index = item->text(1).toInt();
139    if (index >= 0 && index < 2) {
140       stackedWidget->setCurrentIndex(index);
141    }
142 }
143
144 /*
145  * ***FIXME***
146  * If item is a Console, then connect it
147  */
148 void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column)
149 {
150    (void)column;
151    int index = item->text(1).toInt();
152    /* ***FIXME**** make this automatic */
153    if (index >= 0 && index < 2) {
154       stackedWidget->setCurrentIndex(index);
155    }
156 }
157
158
159
160 /*
161  * The user just finished typing a line in the command line edit box
162  */
163 void MainWin::input_line()
164 {
165    QString cmdStr = lineEdit->text();    /* Get the text */
166    lineEdit->clear();                    /* clear the lineEdit box */
167    if (m_console->is_connected()) {
168       m_console->set_text(cmdStr + "\n");
169       m_console->write_dir(cmdStr.toUtf8().data());         /* send to dir */
170    } else {
171       set_status("Director not connected. Click on connect button.");
172    }
173 }
174
175
176 void MainWin::about()
177 {
178    QMessageBox::about(this, tr("About bat"),
179             tr("<br><h2>bat 0.1</h2>"
180             "<p>Copyright &copy; " BYEAR " Free Software Foundation Europe e.V."
181             "<p>The <b>bat</b> is an administrative console"
182                " interface to the Director."));
183 }
184
185 void MainWin::set_statusf(const char *fmt, ...)
186 {
187    va_list arg_ptr;
188    char buf[1000];
189    int len;
190    va_start(arg_ptr, fmt);
191    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
192    va_end(arg_ptr);
193    set_status(buf);
194 // set_scroll_bar_to_end();
195 }
196
197 void MainWin::set_status_ready()
198 {
199    set_status("Ready");
200 // set_scroll_bar_to_end();
201 }
202
203 void MainWin::set_status(const char *buf)
204 {
205    statusBar()->showMessage(buf);
206 // ready = false;
207 }