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