2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
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.
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.
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
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.
32 * Kern Sibbald, January MMVI
36 #include <QAbstractEventDispatcher>
42 QTreeWidgetItem *item, *topItem;
43 QTreeWidget *treeWidget = mainWin->treeWidget;
47 m_textEdit = mainWin->textEdit; /* our console screen */
49 /* Just take the first Director */
51 m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
54 /* Dummy setup of treeWidget */
56 treeWidget->setColumnCount(1);
57 treeWidget->setHeaderLabel("Selection");
58 topItem = new QTreeWidgetItem(treeWidget);
59 topItem->setText(0, m_dir->name());
60 item = new QTreeWidgetItem(topItem);
61 item->setText(0, "Console");
62 item->setText(1, "0");
63 item = new QTreeWidgetItem(topItem);
64 item->setText(0, "Restore");
65 item->setText(1, "1");
66 treeWidget->expandItem(topItem);
70 * Connect to Director. If there are more than one, put up
71 * a modal dialog so that the user chooses one.
73 void Console::connect()
77 m_textEdit = mainWin->textEdit; /* our console screen */
80 set_text("No Director to connect to.\n");
84 set_text("Already connected.\n");
88 memset(&jcr, 0, sizeof(jcr));
90 set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
91 set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
93 /* Give GUI a chance */
97 /* If cons==NULL, default console will be used */
98 CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
101 m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address,
102 NULL, m_dir->DIRport, 0);
103 if (m_sock == NULL) {
104 set_text("Connection failed\n");
108 jcr.dir_bsock = m_sock;
110 if (!authenticate_director(&jcr, m_dir, cons)) {
111 set_text(m_sock->msg);
115 /* Give GUI a chance */
116 app->processEvents();
118 set_status(_(" Initializing ..."));
120 bnet_fsend(m_sock, "autodisplay on");
122 /* Set up input notifier */
123 m_notifier = new QSocketNotifier(m_sock->fd, QSocketNotifier::Read, 0);
124 QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int)));
126 /* Give GUI a chance */
127 app->processEvents();
130 * Query Directory for .jobs, .clients, .filesets, .msgs,
131 * .pools, .storage, .types, .levels, ...
134 set_status(_(" Connected"));
135 set_text("Connected\n");
140 QByteArray bytes = m_Bash->readAllStandardOutput();
141 QStringList lines = QString(bytes).split("\n");
142 foreach (QString line, lines) {
143 m_Logw->append(line);
147 void Console::set_textf(const char *fmt, ...)
152 va_start(arg_ptr, fmt);
153 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
155 m_textEdit->append(buf);
158 void Console::set_text(const char *buf)
160 m_textEdit->append(buf);
163 void Console::set_statusf(const char *fmt, ...)
168 va_start(arg_ptr, fmt);
169 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
174 void Console::set_status_ready()
176 mainWin->statusBar()->showMessage("Ready");
180 void Console::set_status(const char *buf)
182 mainWin->statusBar()->showMessage(buf);
188 void Console::write_dir(const char *msg)
192 set_status(_(" Processing command ..."));
193 m_sock->msglen = strlen(msg);
194 pm_strcpy(&m_sock->msg, msg);
197 if (strcmp(msg, ".quit") == 0 || strcmp(msg, ".exit") == 0) {
198 app->closeAllWindows();
202 void Console::read_dir(int fd)
210 stat = bnet_recv(m_sock);
216 set_text(m_sock->msg);
219 if (is_bnet_stop(m_sock)) { /* error or term request */
224 /* Must be a signal -- either do something or ignore it */
225 if (m_sock->msglen == BNET_PROMPT) {
227 set_status(_(" At prompt waiting for input ..."));
229 if (m_sock->msglen == BNET_EOD) {
239 void start_director_reader(gpointer data)
242 if (director_reader_running || !UA_sock) {
245 tag = gdk_input_add(UA_sock->fd, GDK_INPUT_READ, read_director, NULL);
246 director_reader_running = true;
249 void stop_director_reader(gpointer data)
251 if (!director_reader_running) {
254 gdk_input_remove(tag);
255 director_reader_running = false;