2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
17 * Dirk Bartley, March 2007
23 /* A global function */
24 bool isWin32Path(QString &fullPath)
26 if (fullPath.size()<2) {
30 bool toret = fullPath[1].toAscii() == ':' && fullPath[0].isLetter();
31 if (mainWin->m_miscDebug) {
33 Pmsg1(000, "returning from isWin32Path true %s\n", fullPath.toUtf8().data());
35 Pmsg1(000, "returning from isWin32Path false %s\n", fullPath.toUtf8().data());
40 /* Need to initialize variables here */
41 Pages::Pages() : QWidget()
46 m_dockOnFirstUse = true;
52 void Pages::firstUseDock()
54 if (!m_onceDocked && m_dockOnFirstUse) {
61 * This function is intended to be called from within the Pages class to pull
62 * a window from floating to in the stack widget.
65 void Pages::dockPage()
71 /* These two lines are for making sure if it is being changed from a window
72 * that it has the proper window flag and parent.
74 setWindowFlags(Qt::Widget);
76 /* calculate the index that the tab should be inserted into */
78 QTreeWidgetItemIterator it(mainWin->treeWidget);
80 Pages *somepage = mainWin->getFromHash(*it);
81 if (this == somepage) {
85 int pageindex = mainWin->tabWidget->indexOf(somepage);
86 if (pageindex != -1) { tabPos = pageindex; }
90 /* This was being done already */
91 m_parent->insertTab(tabPos, this, m_name);
96 mainWin->tabWidget->setCurrentWidget(this);
97 /* lets set the page selectors action for docking or undocking */
98 setContextMenuDockText();
103 * This function is intended to be called from within the Pages class to put
104 * a window from the stack widget to a floating window.
107 void Pages::undockPage()
113 /* Change from a stacked widget to a normal window */
114 m_parent->removeTab(m_parent->indexOf(this));
115 setWindowFlags(Qt::Window);
117 /* Clear docked flag */
119 /* The window has been undocked, lets change the context menu */
120 setContextMenuDockText();
124 * This function is intended to be called with the subclasses. When it is
125 * called the specific sublclass does not have to be known to Pages. When it
126 * is called this function will change the page from it's current state of being
127 * docked or undocked and change it to the other.
130 void Pages::togglePageDocking()
140 * This function is because I wanted for some reason to keep it protected but still
141 * give any subclasses the ability to find out if it is currently stacked or not.
143 bool Pages::isDocked()
149 * This function is because after the tabbed widget was added I could not tell
150 * from is docked if it had been docked yet. To prevent status pages from requesting
151 * status from the director
153 bool Pages::isOnceDocked()
160 * To keep m_closeable protected as well
162 bool Pages::isCloseable()
167 void Pages::hidePage()
169 if (!m_parent || (m_parent->indexOf(this) <= 0)) {
172 /* Remove any tab that may exist */
173 m_parent->removeTab(m_parent->indexOf(this));
175 /* Clear docked flag */
177 /* The window has been undocked, lets change the context menu */
178 setContextMenuDockText();
182 * When a window is closed, this slot is called. The idea is to put it back in the
183 * stack here, and it works. I wanted to get it to the top of the stack so that the
184 * user immediately sees where his window went. Also, if he undocks the window, then
185 * closes it with the tree item highlighted, it may be confusing that the highlighted
186 * treewidgetitem is not the stack item in the front.
189 void Pages::closeEvent(QCloseEvent* event)
191 /* A Widget was closed, lets toggle it back into the window, and set it in front. */
194 /* this fixes my woes of getting the widget to show up on top when closed */
197 /* Set the current tree widget item in the Page Selector window to the item
198 * which represents "this"
199 * Which will also bring "this" to the top of the stacked widget */
204 * The next three are virtual functions. The idea here is that each subclass will have the
205 * built in virtual function to override if the programmer wants to populate the window
206 * when it it is first clicked.
208 void Pages::PgSeltreeWidgetClicked()
213 * Virtual function which is called when this page is visible on the stack.
214 * This will be overridden by classes that want to populate if they are on the
217 void Pages::currentStackItem()
222 * Function to close the stacked page and remove the widget from the
223 * Page selector window
225 void Pages::closeStackPage()
227 /* First get the tree widget item and destroy it */
228 QTreeWidgetItem *item=mainWin->getFromHash(this);
229 /* remove the QTreeWidgetItem <-> page from the hash */
231 mainWin->hashRemove(item, this);
232 /* remove the item from the page selector by destroying it */
240 * Function to set members from the external mainwin and it's overload being
241 * passed a specific QTreeWidgetItem to be it's parent on the tree
243 void Pages::pgInitialize()
245 pgInitialize(QString(), NULL);
248 void Pages::pgInitialize(const QString &name)
250 pgInitialize(name, NULL);
253 void Pages::pgInitialize(const QString &tname, QTreeWidgetItem *parentTreeWidgetItem)
256 m_onceDocked = false;
260 m_parent = mainWin->tabWidget;
261 m_console = mainWin->currentConsole();
263 if (!parentTreeWidgetItem) {
264 parentTreeWidgetItem = m_console->directorTreeItem();
267 QTreeWidgetItem *item = new QTreeWidgetItem(parentTreeWidgetItem);
269 treeWidgetName(name);
270 item->setText(0, name);
271 mainWin->hashInsert(item, this);
276 * Virtual Function to return a name
277 * All subclasses should override this function
279 void Pages::treeWidgetName(QString &name)
285 * Function to simplify executing a console command and bringing the
286 * console to the front of the stack
288 void Pages::consoleCommand(QString &command)
290 consoleCommand(command, true);
293 void Pages::consoleCommand(QString &command, bool setCurrent)
296 bool donotify = false;
297 if (m_console->getDirComm(conn)) {
298 if (m_console->is_notify_enabled(conn)) {
300 m_console->notify(conn, false);
302 consoleCommand(command, conn, setCurrent);
303 if (donotify) { m_console->notify(conn, true); }
307 void Pages::consoleCommand(QString &command, int conn)
309 consoleCommand(command, conn, true);
312 void Pages::consoleCommand(QString &command, int conn, bool setCurrent)
314 /* Bring this director's console to the front of the stack */
315 if (setCurrent) { setConsoleCurrent(); }
316 QString displayhtml("<font color=\"blue\">");
317 displayhtml += command + "</font>\n";
318 m_console->display_html(displayhtml);
319 m_console->display_text("\n");
320 mainWin->waitEnter();
321 m_console->write_dir(conn, command.toUtf8().data(), false);
322 m_console->displayToPrompt(conn);
327 * Function for handling undocked windows becoming active.
328 * Change the currently selected item in the page selector window to the now
329 * active undocked window. This will also make the console for the undocked
330 * window m_currentConsole.
332 void Pages::changeEvent(QEvent *event)
334 if ((event->type() == QEvent::ActivationChange) && (isActiveWindow())) {
340 * Function to simplify getting the name of the class and the director into
341 * the caption or title of the window
343 void Pages::setTitle()
345 QString wdgname, director;
346 treeWidgetName(wdgname);
347 m_console->getDirResName(director);
348 QString title = tr("%1 of Director %2").arg(wdgname).arg(director);
349 setWindowTitle(title);
353 * Bring the current directors console window to the top of the stack.
355 void Pages::setConsoleCurrent()
357 mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(m_console));
361 * Bring this window to the top of the stack.
363 void Pages::setCurrent()
365 mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(this));
369 * Function to set the text of the toggle dock context menu when page and
370 * widget item are NOT known.
372 void Pages::setContextMenuDockText()
374 QTreeWidgetItem *item = mainWin->getFromHash(this);
377 docktext = tr("UnDock %1 Window").arg(item->text(0));
379 docktext = tr("ReDock %1 Window").arg(item->text(0));
382 mainWin->actionToggleDock->setText(docktext);
383 setTreeWidgetItemDockColor();
387 * Function to set the color of the tree widget item based on whether it is
390 void Pages::setTreeWidgetItemDockColor()
392 QTreeWidgetItem* item = mainWin->getFromHash(this);
394 if (item->text(0) != tr("Console")) {
396 /* Set the brush to blue if undocked */
397 QBrush blackBrush(Qt::black);
398 item->setForeground(0, blackBrush);
400 /* Set the brush back to black if docked */
401 QBrush blueBrush(Qt::blue);
402 item->setForeground(0, blueBrush);
408 /* Function to get a list of volumes */
409 void Pages::getVolumeList(QStringList &volumeList)
411 QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
412 if (mainWin->m_sqlDebug) {
413 Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
416 if (m_console->sql_cmd(query, results)) {
418 QStringList fieldlist;
419 /* Iterate through the lines of results. */
420 foreach (QString resultline, results) {
421 fieldlist = resultline.split("\t");
422 volumeList.append(fieldlist[0]);
423 } /* foreach resultline */
424 } /* if results from query */
427 /* Function to get a list of volumes */
428 void Pages::getStatusList(QStringList &statusLongList)
430 QString statusQuery("SELECT JobStatusLong FROM Status");
431 if (mainWin->m_sqlDebug) {
432 Pmsg1(000, "Query cmd : %s\n",statusQuery.toUtf8().data());
434 QStringList statusResults;
435 if (m_console->sql_cmd(statusQuery, statusResults)) {
437 QStringList fieldlist;
438 /* Iterate through the lines of results. */
439 foreach (QString resultline, statusResults) {
440 fieldlist = resultline.split("\t");
441 statusLongList.append(fieldlist[0]);
442 } /* foreach resultline */
443 } /* if results from statusquery */