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")));
53 /* Just take the first Director */
55 m_dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
58 /* Dummy setup of treeWidget */
60 treeWidget->setColumnCount(1);
61 treeWidget->setHeaderLabel("Selection");
62 topItem = new QTreeWidgetItem(treeWidget);
63 topItem->setText(0, m_dir->name());
64 topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png")));
65 item = new QTreeWidgetItem(topItem);
67 item->setText(0, "Console");
68 item->setText(1, "0");
69 QBrush redBrush(Qt::red);
70 item->setForeground(0, redBrush);
71 item = new QTreeWidgetItem(topItem);
72 item->setText(0, "Restore");
73 item->setText(1, "1");
74 treeWidget->expandItem(topItem);
81 * Connect to Director. If there are more than one, put up
82 * a modal dialog so that the user chooses one.
84 void Console::connect()
88 m_textEdit = mainWin->textEdit; /* our console screen */
91 mainWin->set_status("No Director found.");
95 mainWin->set_status("Already connected.");
99 memset(&jcr, 0, sizeof(jcr));
101 mainWin->set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
102 set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
104 /* Give GUI a chance */
105 app->processEvents();
108 /* If cons==NULL, default console will be used */
109 CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
112 m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address,
113 NULL, m_dir->DIRport, 0);
114 if (m_sock == NULL) {
115 mainWin->set_status("Connection failed");
118 /* Update page selector to green to indicate that Console is connected */
119 mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/connected.png")));
120 QBrush greenBrush(Qt::green);
121 m_consoleItem->setForeground(0, greenBrush);
124 jcr.dir_bsock = m_sock;
126 if (!authenticate_director(&jcr, m_dir, cons)) {
127 set_text(m_sock->msg);
131 /* Give GUI a chance */
132 app->processEvents();
134 mainWin->set_status(_(" Initializing ..."));
136 bnet_fsend(m_sock, "autodisplay on");
138 /* Set up input notifier */
139 m_notifier = new QSocketNotifier(m_sock->fd, QSocketNotifier::Read, 0);
140 QObject::connect(m_notifier, SIGNAL(activated(int)), this, SLOT(read_dir(int)));
142 /* Give GUI a chance */
143 app->processEvents();
146 * Query Directory for .jobs, .clients, .filesets, .msgs,
147 * .pools, .storage, .types, .levels, ...
150 mainWin->set_status(_(" Connected"));
155 void Console::writeSettings()
157 QFont font = get_font();
159 QSettings settings("bacula.org", "bat");
160 settings.beginGroup("Console");
161 settings.setValue("consoleFont", font.family());
162 settings.setValue("consolePointSize", font.pointSize());
163 settings.setValue("consoleFixedPitch", font.fixedPitch());
167 void Console::readSettings()
169 QFont font = get_font();
171 QSettings settings("bacula.org", "bat");
172 settings.beginGroup("Console");
173 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
174 font.setPointSize(settings.value("consolePointSize", 10).toInt());
175 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
177 m_textEdit->setFont(font);
180 void Console::set_font()
183 QFont font = QFontDialog::getFont(&ok, QFont(m_textEdit->font()), this);
185 m_textEdit->setFont(font);
189 const QFont Console::get_font()
191 return m_textEdit->font();
195 void Console::status_dir()
197 write_dir("status dir\n");
200 void Console::set_textf(const char *fmt, ...)
205 va_start(arg_ptr, fmt);
206 len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
211 void Console::set_text(const QString buf)
213 m_cursor->movePosition(QTextCursor::End);
214 m_cursor->insertText(buf);
218 void Console::set_text(const char *buf)
220 m_cursor->movePosition(QTextCursor::End);
221 m_cursor->insertText(buf);
224 /* Position cursor to end of screen */
225 void Console::update_cursor()
227 QApplication::restoreOverrideCursor();
228 m_textEdit->moveCursor(QTextCursor::End);
229 m_textEdit->ensureCursorVisible();
233 /* Send a command to the Director */
234 void Console::write_dir(const char *msg)
238 mainWin->set_status(_(" Processing command ..."));
239 QApplication::setOverrideCursor(Qt::WaitCursor);
240 m_sock->msglen = strlen(msg);
241 pm_strcpy(&m_sock->msg, msg);
244 mainWin->set_status(" Director not connected. Click on connect button.");
245 mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
246 QBrush redBrush(Qt::red);
247 m_consoleItem->setForeground(0, redBrush);
251 /* Called by signal when the Director has output for us */
252 void Console::read_dir(int fd)
260 stat = bnet_recv(m_sock);
266 set_text(m_sock->msg);
269 if (is_bnet_stop(m_sock)) { /* error or term request */
272 mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png")));
273 QBrush redBrush(Qt::red);
274 m_consoleItem->setForeground(0, redBrush);
275 m_notifier->setEnabled(false);
278 mainWin->set_status(_(" Director disconnected."));
279 QApplication::restoreOverrideCursor();
282 /* Must be a signal -- either do something or ignore it */
283 if (m_sock->msglen == BNET_PROMPT) {
285 mainWin->set_status(_(" At prompt waiting for input ..."));
288 if (m_sock->msglen == BNET_EOD) {
289 mainWin->set_status_ready();
299 void start_director_reader(gpointer data)
302 if (director_reader_running || !UA_sock) {
305 tag = gdk_input_add(UA_sock->fd, GDK_INPUT_READ, read_director, NULL);
306 director_reader_running = true;
309 void stop_director_reader(gpointer data)
311 if (!director_reader_running) {
314 gdk_input_remove(tag);
315 director_reader_running = false;