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 /* Dummy setup of treeWidget */
48 treeWidget->setColumnCount(1);
49 treeWidget->setHeaderLabel("Selection");
50 topItem = new QTreeWidgetItem(treeWidget);
51 topItem->setText(0, "Rufus");
52 item = new QTreeWidgetItem(topItem);
53 item->setText(0, "Console");
54 item->setText(1, "0");
55 item = new QTreeWidgetItem(topItem);
56 item->setText(0, "Restore");
57 item->setText(1, "1");
58 treeWidget->expandItem(topItem);
62 * Connect to Director. If there are more than one, put up
63 * a modal dialog so that the user chooses one.
65 bool Console::connect()
69 m_textEdit = mainWin->textEdit; /* our console screen */
71 /* Just take the first Director */
73 m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
80 memset(&jcr, 0, sizeof(jcr));
82 set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
83 set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
85 /* Give GUI a chance */
89 /* If cons==NULL, default console will be used */
90 CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
93 m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address,
94 NULL, m_dir->DIRport, 0);
99 jcr.dir_bsock = m_sock;
101 if (!authenticate_director(&jcr, m_dir, cons)) {
102 set_text(m_sock->msg);
106 /* Give GUI a chance */
107 app->processEvents();
109 set_status(_(" Initializing ..."));
111 bnet_fsend(m_sock, "autodisplay on");
113 /* Read and display all initial messages */
114 while (bnet_recv(m_sock) > 0) {
115 set_text(m_sock->msg);
118 /* Give GUI a chance */
119 app->processEvents();
121 /* Query Directory for .jobs, .clients, .filesets, .msgs,
122 * .pools, .storage, .types, .levels, ...
125 set_status(_(" Connected"));
129 void Console::set_textf(const char *fmt, ...)
134 va_start(arg_ptr, fmt);
135 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
137 m_textEdit->append(buf);
140 void Console::set_text(const char *buf)
142 m_textEdit->append(buf);
145 void Console::set_statusf(const char *fmt, ...)
150 va_start(arg_ptr, fmt);
151 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
156 void Console::set_status_ready()
158 mainWin->statusBar()->showMessage("Ready");
162 void Console::set_status(const char *buf)
164 mainWin->statusBar()->showMessage(buf);
170 void write_director(const gchar *msg)
174 set_status(_(" Processing command ..."));
175 UA_sock->msglen = strlen(msg);
176 pm_strcpy(&UA_sock->msg, msg);
179 if (strcmp(msg, ".quit") == 0 || strcmp(msg, ".exit") == 0) {
180 disconnect_from_director((gpointer)NULL);
186 void read_director(gpointer data, gint fd, GdkInputCondition condition)
190 if (!UA_sock || UA_sock->fd != fd) {
193 stat = bnet_recv(UA_sock);
199 set_text(UA_sock->msg, UA_sock->msglen);
202 if (is_bnet_stop(UA_sock)) { /* error or term request */
206 /* Must be a signal -- either do something or ignore it */
207 if (UA_sock->msglen == BNET_PROMPT) {
209 set_status(_(" At prompt waiting for input ..."));
211 if (UA_sock->msglen == BNET_EOD) {
219 void start_director_reader(gpointer data)
222 if (director_reader_running || !UA_sock) {
225 tag = gdk_input_add(UA_sock->fd, GDK_INPUT_READ, read_director, NULL);
226 director_reader_running = true;
229 void stop_director_reader(gpointer data)
231 if (!director_reader_running) {
234 gdk_input_remove(tag);
235 director_reader_running = false;