2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2009 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 three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
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 Affero 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 Kern Sibbald.
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.
31 * Dirk Bartley, March 2007
37 /* A global function */
38 bool isWin32Path(QString &fullPath)
40 if (fullPath.size()<2) {
44 bool toret = fullPath[1].toAscii() == ':' && fullPath[0].isLetter();
45 if (mainWin->m_miscDebug) {
47 Pmsg1(000, "returning from isWin32Path true %s\n", fullPath.toUtf8().data());
49 Pmsg1(000, "returning from isWin32Path false %s\n", fullPath.toUtf8().data());
54 /* Need to initialize variables here */
60 m_dockOnFirstUse = true;
64 void Pages::firstUseDock()
66 if (!m_onceDocked && m_dockOnFirstUse) {
73 * This function is intended to be called from within the Pages class to pull
74 * a window from floating to in the stack widget.
77 void Pages::dockPage()
83 /* These two lines are for making sure if it is being changed from a window
84 * that it has the proper window flag and parent.
86 setWindowFlags(Qt::Widget);
88 /* calculate the index that the tab should be inserted into */
90 QTreeWidgetItemIterator it(mainWin->treeWidget);
92 Pages *somepage = mainWin->getFromHash(*it);
93 if (this == somepage) {
97 int pageindex = mainWin->tabWidget->indexOf(somepage);
98 if (pageindex != -1) { tabPos = pageindex; }
102 /* This was being done already */
103 m_parent->insertTab(tabPos, this, m_name);
105 /* Set docked flag */
108 mainWin->tabWidget->setCurrentWidget(this);
109 /* lets set the page selectors action for docking or undocking */
110 setContextMenuDockText();
115 * This function is intended to be called from within the Pages class to put
116 * a window from the stack widget to a floating window.
119 void Pages::undockPage()
125 /* Change from a stacked widget to a normal window */
126 m_parent->removeTab(m_parent->indexOf(this));
127 setWindowFlags(Qt::Window);
129 /* Clear docked flag */
131 /* The window has been undocked, lets change the context menu */
132 setContextMenuDockText();
136 * This function is intended to be called with the subclasses. When it is
137 * called the specific sublclass does not have to be known to Pages. When it
138 * is called this function will change the page from it's current state of being
139 * docked or undocked and change it to the other.
142 void Pages::togglePageDocking()
152 * This function is because I wanted for some reason to keep it protected but still
153 * give any subclasses the ability to find out if it is currently stacked or not.
155 bool Pages::isDocked()
161 * This function is because after the tabbed widget was added I could not tell
162 * from is docked if it had been docked yet. To prevent status pages from requesting
163 * status from the director
165 bool Pages::isOnceDocked()
172 * To keep m_closeable protected as well
174 bool Pages::isCloseable()
180 * When a window is closed, this slot is called. The idea is to put it back in the
181 * stack here, and it works. I wanted to get it to the top of the stack so that the
182 * user immediately sees where his window went. Also, if he undocks the window, then
183 * closes it with the tree item highlighted, it may be confusing that the highlighted
184 * treewidgetitem is not the stack item in the front.
187 void Pages::closeEvent(QCloseEvent* event)
189 /* A Widget was closed, lets toggle it back into the window, and set it in front. */
192 /* this fixes my woes of getting the widget to show up on top when closed */
195 /* Set the current tree widget item in the Page Selector window to the item
196 * which represents "this"
197 * Which will also bring "this" to the top of the stacked widget */
202 * The next three are virtual functions. The idea here is that each subclass will have the
203 * built in virtual function to override if the programmer wants to populate the window
204 * when it it is first clicked.
206 void Pages::PgSeltreeWidgetClicked()
211 * Virtual function which is called when this page is visible on the stack.
212 * This will be overridden by classes that want to populate if they are on the
215 void Pages::currentStackItem()
220 * Function to close the stacked page and remove the widget from the
221 * Page selector window
223 void Pages::closeStackPage()
225 /* First get the tree widget item and destroy it */
226 QTreeWidgetItem *item=mainWin->getFromHash(this);
227 /* remove the QTreeWidgetItem <-> page from the hash */
228 mainWin->hashRemove(item, this);
229 /* remove the item from the page selector by destroying it */
236 * Function to set members from the external mainwin and it's overload being
237 * passed a specific QTreeWidgetItem to be it's parent on the tree
239 void Pages::pgInitialize()
241 pgInitialize(QString(), NULL);
244 void Pages::pgInitialize(const QString &name)
246 pgInitialize(name, NULL);
249 void Pages::pgInitialize(const QString &tname, QTreeWidgetItem *parentTreeWidgetItem)
252 m_onceDocked = false;
256 m_parent = mainWin->tabWidget;
257 m_console = mainWin->currentConsole();
259 if (!parentTreeWidgetItem) {
260 parentTreeWidgetItem = m_console->directorTreeItem();
263 QTreeWidgetItem *item = new QTreeWidgetItem(parentTreeWidgetItem);
265 treeWidgetName(name);
266 item->setText(0, name);
267 mainWin->hashInsert(item, this);
272 * Virtual Function to return a name
273 * All subclasses should override this function
275 void Pages::treeWidgetName(QString &name)
281 * Function to simplify executing a console command and bringing the
282 * console to the front of the stack
284 void Pages::consoleCommand(QString &command)
286 consoleCommand(command, true);
288 void Pages::consoleCommand(QString &command, bool setCurrent)
291 bool donotify = false;
292 if (m_console->getDirComm(conn)) {
293 if (m_console->is_notify_enabled(conn)) {
295 m_console->notify(conn, false);
297 consoleCommand(command, conn, setCurrent);
298 if (donotify) { m_console->notify(conn, true); }
301 void Pages::consoleCommand(QString &command, int conn)
303 consoleCommand(command, conn, true);
305 void Pages::consoleCommand(QString &command, int conn, bool setCurrent)
307 /* Bring this director's console to the front of the stack */
308 if (setCurrent) { setConsoleCurrent(); }
309 QString displayhtml("<font color=\"blue\">");
310 displayhtml += command + "</font>\n";
311 m_console->display_html(displayhtml);
312 m_console->display_text("\n");
313 mainWin->waitEnter();
314 m_console->write_dir(conn, command.toUtf8().data(), false);
315 m_console->displayToPrompt(conn);
320 * Function for handling undocked windows becoming active.
321 * Change the currently selected item in the page selector window to the now
322 * active undocked window. This will also make the console for the undocked
323 * window m_currentConsole.
325 void Pages::changeEvent(QEvent *event)
327 if ((event->type() == QEvent::ActivationChange) && (isActiveWindow())) {
333 * Function to simplify getting the name of the class and the director into
334 * the caption or title of the window
336 void Pages::setTitle()
338 QString wdgname, director;
339 treeWidgetName(wdgname);
340 m_console->getDirResName(director);
341 QString title = tr("%1 of Director %2").arg(wdgname).arg(director);
342 setWindowTitle(title);
346 * Bring the current directors console window to the top of the stack.
348 void Pages::setConsoleCurrent()
350 mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(m_console));
354 * Bring this window to the top of the stack.
356 void Pages::setCurrent()
358 mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(this));
362 * Function to set the text of the toggle dock context menu when page and
363 * widget item are NOT known.
365 void Pages::setContextMenuDockText()
367 QTreeWidgetItem *item = mainWin->getFromHash(this);
370 docktext = tr("UnDock %1 Window").arg(item->text(0));
372 docktext = tr("ReDock %1 Window").arg(item->text(0));
375 mainWin->actionToggleDock->setText(docktext);
376 setTreeWidgetItemDockColor();
380 * Function to set the color of the tree widget item based on whether it is
383 void Pages::setTreeWidgetItemDockColor()
385 QTreeWidgetItem* item = mainWin->getFromHash(this);
387 if (item->text(0) != tr("Console")) {
389 /* Set the brush to blue if undocked */
390 QBrush blackBrush(Qt::black);
391 item->setForeground(0, blackBrush);
393 /* Set the brush back to black if docked */
394 QBrush blueBrush(Qt::blue);
395 item->setForeground(0, blueBrush);
401 /* Function to get a list of volumes */
402 void Pages::getVolumeList(QStringList &volumeList)
404 QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
405 if (mainWin->m_sqlDebug) {
406 Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
409 if (m_console->sql_cmd(query, results)) {
411 QStringList fieldlist;
412 /* Iterate through the lines of results. */
413 foreach (QString resultline, results) {
414 fieldlist = resultline.split("\t");
415 volumeList.append(fieldlist[0]);
416 } /* foreach resultline */
417 } /* if results from query */
420 /* Function to get a list of volumes */
421 void Pages::getStatusList(QStringList &statusLongList)
423 QString statusQuery("SELECT JobStatusLong FROM Status");
424 if (mainWin->m_sqlDebug) {
425 Pmsg1(000, "Query cmd : %s\n",statusQuery.toUtf8().data());
427 QStringList statusResults;
428 if (m_console->sql_cmd(statusQuery, statusResults)) {
430 QStringList fieldlist;
431 /* Iterate through the lines of results. */
432 foreach (QString resultline, statusResults) {
433 fieldlist = resultline.split("\t");
434 statusLongList.append(fieldlist[0]);
435 } /* foreach resultline */
436 } /* if results from statusquery */