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 two of the GNU 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 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());
56 * This function is intended to be called from within the Pages class to pull
57 * a window from floating to in the stack widget.
60 void Pages::dockPage()
66 /* These two lines are for making sure if it is being changed from a window
67 * that it has the proper window flag and parent.
69 setWindowFlags(Qt::Widget);
71 /* calculate the index that the tab should be inserted into */
73 QTreeWidgetItemIterator it(mainWin->treeWidget);
75 Pages *somepage = mainWin->getFromHash(*it);
76 if (this == somepage) {
80 int pageindex = mainWin->tabWidget->indexOf(somepage);
81 if (pageindex != -1) { tabPos = pageindex; }
85 /* This was being done already */
86 m_parent->insertTab(tabPos, this, m_name);
90 mainWin->tabWidget->setCurrentWidget(this);
91 /* lets set the page selectors action for docking or undocking */
92 setContextMenuDockText();
98 * This function is intended to be called from within the Pages class to put
99 * a window from the stack widget to a floating window.
102 void Pages::undockPage()
108 /* Change from a stacked widget to a normal window */
109 m_parent->removeTab(m_parent->indexOf(this));
110 setWindowFlags(Qt::Window);
112 /* Clear docked flag */
114 /* The window has been undocked, lets change the context menu */
115 setContextMenuDockText();
119 * This function is intended to be called with the subclasses. When it is
120 * called the specific sublclass does not have to be known to Pages. When it
121 * is called this function will change the page from it's current state of being
122 * docked or undocked and change it to the other.
125 void Pages::togglePageDocking()
135 * This function is because I wanted for some reason to keep it protected but still
136 * give any subclasses the ability to find out if it is currently stacked or not.
138 bool Pages::isDocked()
144 * To keep m_closeable protected as well
146 bool Pages::isCloseable()
152 * When a window is closed, this slot is called. The idea is to put it back in the
153 * stack here, and it works. I wanted to get it to the top of the stack so that the
154 * user immediately sees where his window went. Also, if he undocks the window, then
155 * closes it with the tree item highlighted, it may be confusing that the highlighted
156 * treewidgetitem is not the stack item in the front.
159 void Pages::closeEvent(QCloseEvent* event)
161 /* A Widget was closed, lets toggle it back into the window, and set it in front. */
164 /* this fixes my woes of getting the widget to show up on top when closed */
167 /* Set the current tree widget item in the Page Selector window to the item
168 * which represents "this"
169 * Which will also bring "this" to the top of the stacked widget */
174 * The next three are virtual functions. The idea here is that each subclass will have the
175 * built in virtual function to override if the programmer wants to populate the window
176 * when it it is first clicked.
178 void Pages::PgSeltreeWidgetClicked()
183 * Virtual function which is called when this page is visible on the stack.
184 * This will be overridden by classes that want to populate if they are on the
187 void Pages::currentStackItem()
192 * Function to close the stacked page and remove the widget from the
193 * Page selector window
195 void Pages::closeStackPage()
197 /* First get the tree widget item and destroy it */
198 QTreeWidgetItem *item=mainWin->getFromHash(this);
199 /* remove the QTreeWidgetItem <-> page from the hash */
200 mainWin->hashRemove(item, this);
201 /* remove the item from the page selector by destroying it */
208 * Function to set members from the external mainwin and it's overload being
209 * passed a specific QTreeWidgetItem to be it's parent on the tree
211 void Pages::pgInitialize()
213 pgInitialize(QString(), NULL);
216 void Pages::pgInitialize(const QString &name)
218 pgInitialize(name, NULL);
221 void Pages::pgInitialize(const QString &tname, QTreeWidgetItem *parentTreeWidgetItem)
227 m_parent = mainWin->tabWidget;
228 m_console = mainWin->currentConsole();
230 if (!parentTreeWidgetItem) {
231 parentTreeWidgetItem = m_console->directorTreeItem();
234 QTreeWidgetItem *item = new QTreeWidgetItem(parentTreeWidgetItem);
236 treeWidgetName(name);
237 item->setText(0, name);
238 mainWin->hashInsert(item, this);
243 * Virtual Function to return a name
244 * All subclasses should override this function
246 void Pages::treeWidgetName(QString &name)
252 * Function to simplify executing a console command and bringing the
253 * console to the front of the stack
255 void Pages::consoleCommand(QString &command)
257 consoleCommand(command, true);
259 void Pages::consoleCommand(QString &command, bool setCurrent)
262 bool donotify = false;
263 if (m_console->availableDirComm(conn)) {
264 if (m_console->is_notify_enabled(conn)) {
266 m_console->notify(conn, false);
268 consoleCommand(command, conn, setCurrent);
269 if (donotify) { m_console->notify(conn, true); }
272 void Pages::consoleCommand(QString &command, int conn)
274 consoleCommand(command, conn, true);
276 void Pages::consoleCommand(QString &command, int conn, bool setCurrent)
278 /* Bring this director's console to the front of the stack */
279 if (setCurrent) { setConsoleCurrent(); }
280 QString displayhtml("<font color=\"blue\">");
281 displayhtml += command + "</font>\n";
282 m_console->display_html(displayhtml);
283 m_console->display_text("\n");
284 mainWin->waitEnter();
285 m_console->write_dir(conn, command.toUtf8().data(), false);
286 m_console->displayToPrompt(conn);
291 * Function for handling undocked windows becoming active.
292 * Change the currently selected item in the page selector window to the now
293 * active undocked window. This will also make the console for the undocked
294 * window m_currentConsole.
296 void Pages::changeEvent(QEvent *event)
298 if ((event->type() == QEvent::ActivationChange) && (isActiveWindow())) {
304 * Function to simplify getting the name of the class and the director into
305 * the caption or title of the window
307 void Pages::setTitle()
309 QString wdgname, director;
310 treeWidgetName(wdgname);
311 m_console->getDirResName(director);
312 QString title = tr("%1 of Director %2").arg(wdgname).arg(director);
313 setWindowTitle(title);
317 * Bring the current directors console window to the top of the stack.
319 void Pages::setConsoleCurrent()
321 mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(m_console));
325 * Bring this window to the top of the stack.
327 void Pages::setCurrent()
329 mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(this));
333 * Function to set the text of the toggle dock context menu when page and
334 * widget item are NOT known.
336 void Pages::setContextMenuDockText()
338 QTreeWidgetItem *item = mainWin->getFromHash(this);
341 docktext = tr("UnDock %1 Window").arg(item->text(0));
343 docktext = tr("ReDock %1 Window").arg(item->text(0));
346 mainWin->actionToggleDock->setText(docktext);
347 setTreeWidgetItemDockColor();
351 * Function to set the color of the tree widget item based on whether it is
354 void Pages::setTreeWidgetItemDockColor()
356 QTreeWidgetItem* item = mainWin->getFromHash(this);
358 if (item->text(0) != tr("Console")) {
360 /* Set the brush to blue if undocked */
361 QBrush blackBrush(Qt::black);
362 item->setForeground(0, blackBrush);
364 /* Set the brush back to black if docked */
365 QBrush blueBrush(Qt::blue);
366 item->setForeground(0, blueBrush);
372 /* Function to get a list of volumes */
373 void Pages::getVolumeList(QStringList &volumeList)
375 QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
376 if (mainWin->m_sqlDebug) {
377 Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
380 if (m_console->sql_cmd(query, results)) {
382 QStringList fieldlist;
383 /* Iterate through the lines of results. */
384 foreach (QString resultline, results) {
385 fieldlist = resultline.split("\t");
386 volumeList.append(fieldlist[0]);
387 } /* foreach resultline */
388 } /* if results from query */
391 /* Function to get a list of volumes */
392 void Pages::getStatusList(QStringList &statusLongList)
394 QString statusQuery("SELECT JobStatusLong FROM Status");
395 if (mainWin->m_sqlDebug) {
396 Pmsg1(000, "Query cmd : %s\n",statusQuery.toUtf8().data());
398 QStringList statusResults;
399 if (m_console->sql_cmd(statusQuery, statusResults)) {
401 QStringList fieldlist;
402 /* Iterate through the lines of results. */
403 foreach (QString resultline, statusResults) {
404 fieldlist = resultline.split("\t");
405 statusLongList.append(fieldlist[0]);
406 } /* foreach resultline */
407 } /* if results from statusquery */