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;
45 m_textEdit = mainWin->textEdit; /* our console screen */
47 /* Just take the first Director */
49 m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
52 /* Dummy setup of treeWidget */
54 treeWidget->setColumnCount(1);
55 treeWidget->setHeaderLabel("Selection");
56 topItem = new QTreeWidgetItem(treeWidget);
57 topItem->setText(0, m_dir->name());
58 item = new QTreeWidgetItem(topItem);
59 item->setText(0, "Console");
60 item->setText(1, "0");
61 item = new QTreeWidgetItem(topItem);
62 item->setText(0, "Restore");
63 item->setText(1, "1");
64 treeWidget->expandItem(topItem);
68 * Connect to Director. If there are more than one, put up
69 * a modal dialog so that the user chooses one.
71 void Console::connect()
75 m_textEdit = mainWin->textEdit; /* our console screen */
78 set_text("No Director to connect to.\n");
82 set_text("Already connected.\n");
86 memset(&jcr, 0, sizeof(jcr));
88 set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
89 set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
91 /* Give GUI a chance */
95 /* If cons==NULL, default console will be used */
96 CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
99 m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address,
100 NULL, m_dir->DIRport, 0);
101 if (m_sock == NULL) {
102 set_text("Connection failed\n");
106 jcr.dir_bsock = m_sock;
108 if (!authenticate_director(&jcr, m_dir, cons)) {
109 set_text(m_sock->msg);
113 /* Give GUI a chance */
114 app->processEvents();
116 set_status(_(" Initializing ..."));
118 bnet_fsend(m_sock, "autodisplay on");
120 /* Read and display all initial messages */
121 while (bnet_recv(m_sock) > 0) {
122 set_text(m_sock->msg);
125 /* Give GUI a chance */
126 app->processEvents();
128 /* Query Directory for .jobs, .clients, .filesets, .msgs,
129 * .pools, .storage, .types, .levels, ...
132 set_status(_(" Connected"));
133 set_text("Connected\n");
138 void Console::set_textf(const char *fmt, ...)
143 va_start(arg_ptr, fmt);
144 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
146 m_textEdit->append(buf);
149 void Console::set_text(const char *buf)
151 m_textEdit->append(buf);
154 void Console::set_statusf(const char *fmt, ...)
159 va_start(arg_ptr, fmt);
160 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
165 void Console::set_status_ready()
167 mainWin->statusBar()->showMessage("Ready");
171 void Console::set_status(const char *buf)
173 mainWin->statusBar()->showMessage(buf);
180 void write_director(const gchar *msg)
184 set_status(_(" Processing command ..."));
185 UA_sock->msglen = strlen(msg);
186 pm_strcpy(&UA_sock->msg, msg);
189 if (strcmp(msg, ".quit") == 0 || strcmp(msg, ".exit") == 0) {
190 disconnect_from_director((gpointer)NULL);
196 void read_director(gpointer data, gint fd, GdkInputCondition condition)
200 if (!UA_sock || UA_sock->fd != fd) {
203 stat = bnet_recv(UA_sock);
209 set_text(UA_sock->msg, UA_sock->msglen);
212 if (is_bnet_stop(UA_sock)) { /* error or term request */
216 /* Must be a signal -- either do something or ignore it */
217 if (UA_sock->msglen == BNET_PROMPT) {
219 set_status(_(" At prompt waiting for input ..."));
221 if (UA_sock->msglen == BNET_EOD) {
229 void start_director_reader(gpointer data)
232 if (director_reader_running || !UA_sock) {
235 tag = gdk_input_add(UA_sock->fd, GDK_INPUT_READ, read_director, NULL);
236 director_reader_running = true;
239 void stop_director_reader(gpointer data)
241 if (!director_reader_running) {
244 gdk_input_remove(tag);
245 director_reader_running = false;