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>
43 QTreeWidgetItem *item, *topItem;
44 QTreeWidget *treeWidget = mainWin->treeWidget;
48 m_textEdit = mainWin->textEdit; /* our console screen */
49 m_cursor = new QTextCursor(m_textEdit->document());
51 /* ***FIXME*** make this configurable */
52 font.setFamily("Courier");
53 font.setFixedPitch(true);
54 font.setPointSize(10);
55 m_textEdit->setFont(font);
57 /* Just take the first Director */
59 m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
62 /* Dummy setup of treeWidget */
64 treeWidget->setColumnCount(1);
65 treeWidget->setHeaderLabel("Selection");
66 topItem = new QTreeWidgetItem(treeWidget);
67 topItem->setText(0, m_dir->name());
68 item = new QTreeWidgetItem(topItem);
69 item->setText(0, "Console");
70 item->setText(1, "0");
71 item = new QTreeWidgetItem(topItem);
72 item->setText(0, "Restore");
73 item->setText(1, "1");
74 treeWidget->expandItem(topItem);
78 * Connect to Director. If there are more than one, put up
79 * a modal dialog so that the user chooses one.
81 void Console::connect()
85 m_textEdit = mainWin->textEdit; /* our console screen */
88 mainWin->set_status("No Director found.");
92 mainWin->set_status("Already connected.");
96 memset(&jcr, 0, sizeof(jcr));
98 mainWin->set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
99 set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
101 /* Give GUI a chance */
102 app->processEvents();
105 /* If cons==NULL, default console will be used */
106 CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
109 m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address,
110 NULL, m_dir->DIRport, 0);
111 if (m_sock == NULL) {
112 mainWin->set_status("Connection failed");
116 jcr.dir_bsock = m_sock;
118 if (!authenticate_director(&jcr, m_dir, cons)) {
119 set_text(m_sock->msg);
123 /* Give GUI a chance */
124 app->processEvents();
126 mainWin->set_status(_(" Initializing ..."));
128 bnet_fsend(m_sock, "autodisplay on");
130 /* Set up input notifier */
131 m_notifier = new QSocketNotifier(m_sock->fd, QSocketNotifier::Read, 0);
132 QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int)));
134 /* Give GUI a chance */
135 app->processEvents();
138 * Query Directory for .jobs, .clients, .filesets, .msgs,
139 * .pools, .storage, .types, .levels, ...
142 mainWin->set_status(_(" Connected"));
146 QByteArray bytes = m_Bash->readAllStandardOutput();
147 QStringList lines = QString(bytes).split("\n");
148 foreach (QString line, lines) {
149 m_Logw->append(line);
153 void Console::set_textf(const char *fmt, ...)
158 va_start(arg_ptr, fmt);
159 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
164 void Console::set_text(const QString buf)
166 m_cursor->movePosition(QTextCursor::End);
167 m_cursor->insertText(buf);
168 m_textEdit->moveCursor(QTextCursor::End);
169 m_textEdit->ensureCursorVisible();
173 void Console::set_text(const char *buf)
175 m_cursor->movePosition(QTextCursor::End);
176 m_cursor->insertText(buf);
177 m_textEdit->moveCursor(QTextCursor::End);
178 m_textEdit->ensureCursorVisible();
182 void Console::write_dir(const char *msg)
186 mainWin->set_status(_(" Processing command ..."));
187 QApplication::setOverrideCursor(Qt::WaitCursor);
188 m_sock->msglen = strlen(msg);
189 pm_strcpy(&m_sock->msg, msg);
192 mainWin->set_status(" Director not connected. Click on connect button.");
196 void Console::read_dir(int fd)
204 stat = bnet_recv(m_sock);
210 set_text(m_sock->msg);
213 if (is_bnet_stop(m_sock)) { /* error or term request */
216 m_notifier->setEnabled(false);
219 mainWin->set_status(_(" Director disconnected."));
220 QApplication::restoreOverrideCursor();
223 /* Must be a signal -- either do something or ignore it */
224 if (m_sock->msglen == BNET_PROMPT) {
226 mainWin->set_status(_(" At prompt waiting for input ..."));
227 QApplication::restoreOverrideCursor();
229 if (m_sock->msglen == BNET_EOD) {
230 mainWin->set_status_ready();
231 QApplication::restoreOverrideCursor();
240 void start_director_reader(gpointer data)
243 if (director_reader_running || !UA_sock) {
246 tag = gdk_input_add(UA_sock->fd, GDK_INPUT_READ, read_director, NULL);
247 director_reader_running = true;
250 void stop_director_reader(gpointer data)
252 if (!director_reader_running) {
255 gdk_input_remove(tag);
256 director_reader_running = false;