]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/mainwin.cpp
7df2cb222bedd156b39dc22df8ad6f39ecd48a8b
[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    m_console->write_dir(cmdStr.toUtf8().data());         /* send to dir */
85 }
86 void MainWin::about()
87 {
88    QMessageBox::about(this, tr("About bat"),
89             tr("<br><h2>bat 0.1</h2>"
90             "<p>Copyright &copy; " BYEAR " Free Software Foundation Europe e.V."
91             "<p>The <b>bat</b> is an administrative console"
92                " interface to the Director."));
93 }
94
95 void set_textf(const char *fmt, ...)
96 {
97    va_list arg_ptr;
98    char buf[1000];
99    int len;
100    va_start(arg_ptr, fmt);
101    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
102    va_end(arg_ptr);
103    mainWin->textEdit->append(buf);
104 }
105
106 void set_text(const char *buf)
107 {
108    mainWin->textEdit->append(buf);
109 }
110
111 void set_statusf(const char *fmt, ...)
112 {
113    va_list arg_ptr;
114    char buf[1000];
115    int len;
116    va_start(arg_ptr, fmt);
117    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
118    va_end(arg_ptr);
119 // gtk_label_set_text(GTK_LABEL(status1), buf);
120 // set_scroll_bar_to_end();
121 // ready = false;
122 }
123
124 void set_status_ready()
125 {
126    mainWin->statusBar()->showMessage("Ready");
127 // ready = true;
128 // set_scroll_bar_to_end();
129 }
130
131 void set_status(const char *buf)
132 {
133    mainWin->statusBar()->showMessage(buf);
134 // ready = false;
135 }