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());
50 mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
52 /* ***FIXME*** make this configurable */
53 font.setFamily("Courier");
54 font.setFixedPitch(true);
55 font.setPointSize(10);
56 m_textEdit->setFont(font);
58 /* Just take the first Director */
60 m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
63 /* Dummy setup of treeWidget */
65 treeWidget->setColumnCount(1);
66 treeWidget->setHeaderLabel("Selection");
67 topItem = new QTreeWidgetItem(treeWidget);
68 topItem->setText(0, m_dir->name());
69 topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
70 item = new QTreeWidgetItem(topItem);
72 item->setText(0, "Console");
73 item->setText(1, "0");
74 QBrush redBrush(Qt::red);
75 item->setForeground(0, redBrush);
76 item = new QTreeWidgetItem(topItem);
77 item->setText(0, "Restore");
78 item->setText(1, "1");
79 treeWidget->expandItem(topItem);
83 * Connect to Director. If there are more than one, put up
84 * a modal dialog so that the user chooses one.
86 void Console::connect()
90 m_textEdit = mainWin->textEdit; /* our console screen */
93 mainWin->set_status("No Director found.");
97 mainWin->set_status("Already connected.");
101 memset(&jcr, 0, sizeof(jcr));
103 mainWin->set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
104 set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
106 /* Give GUI a chance */
107 app->processEvents();
110 /* If cons==NULL, default console will be used */
111 CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
114 m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address,
115 NULL, m_dir->DIRport, 0);
116 if (m_sock == NULL) {
117 mainWin->set_status("Connection failed");
120 mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/connected.png")));
121 QBrush greenBrush(Qt::green);
122 m_consoleItem->setForeground(0, greenBrush);
126 jcr.dir_bsock = m_sock;
128 if (!authenticate_director(&jcr, m_dir, cons)) {
129 set_text(m_sock->msg);
133 /* Give GUI a chance */
134 app->processEvents();
136 mainWin->set_status(_(" Initializing ..."));
138 bnet_fsend(m_sock, "autodisplay on");
140 /* Set up input notifier */
141 m_notifier = new QSocketNotifier(m_sock->fd, QSocketNotifier::Read, 0);
142 QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int)));
144 /* Give GUI a chance */
145 app->processEvents();
148 * Query Directory for .jobs, .clients, .filesets, .msgs,
149 * .pools, .storage, .types, .levels, ...
152 mainWin->set_status(_(" Connected"));
156 QByteArray bytes = m_Bash->readAllStandardOutput();
157 QStringList lines = QString(bytes).split("\n");
158 foreach (QString line, lines) {
159 m_Logw->append(line);
163 void Console::set_textf(const char *fmt, ...)
168 va_start(arg_ptr, fmt);
169 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
174 void Console::set_text(const QString buf)
176 m_cursor->movePosition(QTextCursor::End);
177 m_cursor->insertText(buf);
178 m_textEdit->moveCursor(QTextCursor::End);
179 m_textEdit->ensureCursorVisible();
183 void Console::set_text(const char *buf)
185 m_cursor->movePosition(QTextCursor::End);
186 m_cursor->insertText(buf);
187 m_textEdit->moveCursor(QTextCursor::End);
188 m_textEdit->ensureCursorVisible();
192 void Console::write_dir(const char *msg)
196 mainWin->set_status(_(" Processing command ..."));
197 QApplication::setOverrideCursor(Qt::WaitCursor);
198 m_sock->msglen = strlen(msg);
199 pm_strcpy(&m_sock->msg, msg);
202 mainWin->set_status(" Director not connected. Click on connect button.");
203 mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
204 QBrush redBrush(Qt::red);
205 m_consoleItem->setForeground(0, redBrush);
209 void Console::read_dir(int fd)
217 stat = bnet_recv(m_sock);
223 set_text(m_sock->msg);
226 if (is_bnet_stop(m_sock)) { /* error or term request */
229 mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
230 QBrush redBrush(Qt::red);
231 m_consoleItem->setForeground(0, redBrush);
232 m_notifier->setEnabled(false);
235 mainWin->set_status(_(" Director disconnected."));
236 QApplication::restoreOverrideCursor();
239 /* Must be a signal -- either do something or ignore it */
240 if (m_sock->msglen == BNET_PROMPT) {
242 mainWin->set_status(_(" At prompt waiting for input ..."));
243 QApplication::restoreOverrideCursor();
245 if (m_sock->msglen == BNET_EOD) {
246 mainWin->set_status_ready();
247 QApplication::restoreOverrideCursor();
256 void start_director_reader(gpointer data)
259 if (director_reader_running || !UA_sock) {
262 tag = gdk_input_add(UA_sock->fd, GDK_INPUT_READ, read_director, NULL);
263 director_reader_running = true;
266 void stop_director_reader(gpointer data)
268 if (!director_reader_running) {
271 gdk_input_remove(tag);
272 director_reader_running = false;