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