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
41 QTreeWidgetItem *item, *topItem;
42 QTreeWidget *treeWidget = mainWin->treeWidget;
44 m_textEdit = mainWin->textEdit; /* our console screen */
46 /* Just take the first Director */
48 m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
51 /* Dummy setup of treeWidget */
53 treeWidget->setColumnCount(1);
54 treeWidget->setHeaderLabel("Selection");
55 topItem = new QTreeWidgetItem(treeWidget);
56 topItem->setText(0, m_dir->name());
57 item = new QTreeWidgetItem(topItem);
58 item->setText(0, "Console");
59 item->setText(1, "0");
60 item = new QTreeWidgetItem(topItem);
61 item->setText(0, "Restore");
62 item->setText(1, "1");
63 treeWidget->expandItem(topItem);
67 * Connect to Director. If there are more than one, put up
68 * a modal dialog so that the user chooses one.
70 bool Console::connect()
74 m_textEdit = mainWin->textEdit; /* our console screen */
81 memset(&jcr, 0, sizeof(jcr));
83 set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
84 set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
86 /* Give GUI a chance */
90 /* If cons==NULL, default console will be used */
91 CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
94 m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address,
95 NULL, m_dir->DIRport, 0);
100 jcr.dir_bsock = m_sock;
102 if (!authenticate_director(&jcr, m_dir, cons)) {
103 set_text(m_sock->msg);
107 /* Give GUI a chance */
108 app->processEvents();
110 set_status(_(" Initializing ..."));
112 bnet_fsend(m_sock, "autodisplay on");
114 /* Read and display all initial messages */
115 while (bnet_recv(m_sock) > 0) {
116 set_text(m_sock->msg);
119 /* Give GUI a chance */
120 app->processEvents();
122 /* Query Directory for .jobs, .clients, .filesets, .msgs,
123 * .pools, .storage, .types, .levels, ...
126 set_status(_(" Connected"));
130 void Console::set_textf(const char *fmt, ...)
135 va_start(arg_ptr, fmt);
136 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
138 m_textEdit->append(buf);
141 void Console::set_text(const char *buf)
143 m_textEdit->append(buf);
146 void Console::set_statusf(const char *fmt, ...)
151 va_start(arg_ptr, fmt);
152 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
157 void Console::set_status_ready()
159 mainWin->statusBar()->showMessage("Ready");
163 void Console::set_status(const char *buf)
165 mainWin->statusBar()->showMessage(buf);
171 void write_director(const gchar *msg)
175 set_status(_(" Processing command ..."));
176 UA_sock->msglen = strlen(msg);
177 pm_strcpy(&UA_sock->msg, msg);
180 if (strcmp(msg, ".quit") == 0 || strcmp(msg, ".exit") == 0) {
181 disconnect_from_director((gpointer)NULL);
187 void read_director(gpointer data, gint fd, GdkInputCondition condition)
191 if (!UA_sock || UA_sock->fd != fd) {
194 stat = bnet_recv(UA_sock);
200 set_text(UA_sock->msg, UA_sock->msglen);
203 if (is_bnet_stop(UA_sock)) { /* error or term request */
207 /* Must be a signal -- either do something or ignore it */
208 if (UA_sock->msglen == BNET_PROMPT) {
210 set_status(_(" At prompt waiting for input ..."));
212 if (UA_sock->msglen == BNET_EOD) {
220 void start_director_reader(gpointer data)
223 if (director_reader_running || !UA_sock) {
226 tag = gdk_input_add(UA_sock->fd, GDK_INPUT_READ, read_director, NULL);
227 director_reader_running = true;
230 void stop_director_reader(gpointer data)
232 if (!director_reader_running) {
235 gdk_input_remove(tag);
236 director_reader_running = false;