]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/mainwin.cpp
b995aea71c7beb5db00e0ba6f7621777183ed736
[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    stackedWidget->setCurrentIndex(0);
43
44    m_console = new Console();
45
46    /* Dummy message ***FIXME*** remove a bit later */
47    textEdit->setPlainText("Hello Baculites\nThis is the main console window.");
48    lineEdit->setFocus();
49
50
51    /* Connect signals to slots */
52    connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
53    connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
54
55    connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, 
56            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
57    connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, 
58            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
59    connect(treeWidget, SIGNAL(itemPressed(QTreeWidgetItem *, int)), this, 
60            SLOT(treeItemClicked(QTreeWidgetItem *, int)));
61    connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows()));
62    connect(actionConnect, SIGNAL(triggered()), m_console, SLOT(connect()));
63
64 }
65
66 void MainWin::treeItemClicked(QTreeWidgetItem *item, int column)
67 {
68    (void)column;
69    int index = item->text(1).toInt();
70    if (index >= 0 && index < 2) {
71       stackedWidget->setCurrentIndex(index);
72    }
73 }
74
75
76 /*
77  * The user just finished typing a line in the command line edit box
78  */
79 void MainWin::input_line()
80 {
81    QString cmdStr = lineEdit->text();    /* Get the text */
82    lineEdit->clear();                    /* clear the lineEdit box */
83    textEdit->append(cmdStr);             /* append text on screen */
84 }
85 void MainWin::about()
86 {
87    QMessageBox::about(this, tr("About bat"),
88             tr("<h2>bat 0.1</h2>"
89             "<p>Copyright &copy; " BYEAR " Free Software Foundation Europe e.V."
90             "<p>The <b>bat</b> is an administrative console"
91                " interface to the Director."));
92 }
93
94 void set_textf(const char *fmt, ...)
95 {
96    va_list arg_ptr;
97    char buf[1000];
98    int len;
99    va_start(arg_ptr, fmt);
100    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
101    va_end(arg_ptr);
102    mainWin->textEdit->append(buf);
103 }
104
105 void set_text(const char *buf)
106 {
107    mainWin->textEdit->append(buf);
108 }
109
110 void set_statusf(const char *fmt, ...)
111 {
112    va_list arg_ptr;
113    char buf[1000];
114    int len;
115    va_start(arg_ptr, fmt);
116    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
117    va_end(arg_ptr);
118 // gtk_label_set_text(GTK_LABEL(status1), buf);
119 // set_scroll_bar_to_end();
120 // ready = false;
121 }
122
123 void set_status_ready()
124 {
125    mainWin->statusBar()->showMessage("Ready");
126 // ready = true;
127 // set_scroll_bar_to_end();
128 }
129
130 void set_status(const char *buf)
131 {
132    mainWin->statusBar()->showMessage(buf);
133 // ready = false;
134 }