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 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 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.
31 * Dirk Bartley, March 2007
39 * This function is intended to be called from within the Pages class to pull
40 * a window from floating to in the stack widget.
43 void Pages::dockPage()
45 /* These two lines are for making sure if it is being changed from a window
46 * that it has the proper window flag and parent.
48 setWindowFlags(Qt::Widget);
50 /* This was being done already */
51 m_parent->addWidget(this);
55 mainWin->stackedWidget->setCurrentWidget(this);
56 /* lets set the page selectors action for docking or undocking */
57 setContextMenuDockText();
62 * This function is intended to be called from within the Pages class to put
63 * a window from the stack widget to a floating window.
66 void Pages::undockPage()
68 /* Change from a stacked widget to a normal window */
69 m_parent->removeWidget(this);
70 setWindowFlags(Qt::Window);
72 /* Clear docked flag */
74 /* The window has been undocked, lets change the context menu */
75 setContextMenuDockText();
79 * This function is intended to be called with the subclasses. When it is
80 * called the specific sublclass does not have to be known to Pages. When it
81 * is called this function will change the page from it's current state of being
82 * docked or undocked and change it to the other.
85 void Pages::togglePageDocking()
95 * This function is because I wanted for some reason to keep it protected but still
96 * give any subclasses the ability to find out if it is currently stacked or not.
98 bool Pages::isDocked()
104 * To keep m_closeable protected as well
106 bool Pages::isCloseable()
112 * When a window is closed, this slot is called. The idea is to put it back in the
113 * stack here, and it works. I wanted to get it to the top of the stack so that the
114 * user immediately sees where his window went. Also, if he undocks the window, then
115 * closes it with the tree item highlighted, it may be confusing that the highlighted
116 * treewidgetitem is not the stack item in the front.
119 void Pages::closeEvent(QCloseEvent* event)
121 /* A Widget was closed, lets toggle it back into the window, and set it in front. */
124 /* this fixes my woes of getting the widget to show up on top when closed */
127 /* Set the current tree widget item in the Page Selector window to the item
128 * which represents "this"
129 * Which will also bring "this" to the top of the stacked widget */
134 * The next three are virtual functions. The idea here is that each subclass will have the
135 * built in virtual function to override if the programmer wants to populate the window
136 * when it it is first clicked.
138 void Pages::PgSeltreeWidgetClicked()
143 * Virtual function which is called when this page is visible on the stack.
144 * This will be overridden by classes that want to populate if they are on the
147 void Pages::currentStackItem()
152 * Function to close the stacked page and remove the widget from the
153 * Page selector window
155 void Pages::closeStackPage()
157 /* First get the tree widget item and destroy it */
158 QTreeWidgetItem *item=mainWin->getFromHash(this);
159 /* remove the QTreeWidgetItem <-> page from the hash */
160 mainWin->hashRemove(item, this);
161 /* remove the item from the page selector by destroying it */
168 * Function to set members from the external mainwin and it's overload being
169 * passed a specific QTreeWidgetItem to be it's parent on the tree
171 void Pages::pgInitialize()
176 void Pages::pgInitialize(QTreeWidgetItem *parentTreeWidgetItem)
178 m_parent = mainWin->stackedWidget;
179 m_console = mainWin->currentConsole();
181 if (!parentTreeWidgetItem) {
182 parentTreeWidgetItem = m_console->directorTreeItem();
185 QTreeWidgetItem *item = new QTreeWidgetItem(parentTreeWidgetItem);
187 treeWidgetName(name);
188 item->setText(0, name);
189 mainWin->hashInsert(item, this);
194 * Virtual Function to return a name
195 * All subclasses should override this function
197 void Pages::treeWidgetName(QString &name)
203 * Function to simplify executing a console command and bringing the
204 * console to the front of the stack
206 void Pages::consoleCommand(QString &command)
208 /*if (!m_console->is_connectedGui())
210 if (!m_console->preventInUseConnect()) {
213 consoleInput(command);
217 * Function to simplify executing a console command, but does not
218 * check for the connection in use. We need this so that we can
219 * *always* enter command from the command line.
221 void Pages::consoleInput(QString &command)
223 /* Bring this director's console to the front of the stack */
225 QString displayhtml("<font color=\"blue\">");
226 displayhtml += command + "</font>\n";
227 m_console->display_html(displayhtml);
228 m_console->display_text("\n");
229 m_console->write_dir(command.toUtf8().data());
230 m_console->displayToPrompt();
234 * Function for handling undocked windows becoming active.
235 * Change the currently selected item in the page selector window to the now
236 * active undocked window. This will also make the console for the undocked
237 * window m_currentConsole.
239 void Pages::changeEvent(QEvent *event)
241 if ((event->type() == QEvent::ActivationChange) && (isActiveWindow())) {
247 * Function to simplify getting the name of the class and the director into
248 * the caption or title of the window
250 void Pages::setTitle()
252 QString title, director;
253 treeWidgetName(title);
254 m_console->getDirResName(director);
255 title += " of Director ";
257 setWindowTitle(title);
261 * Bring the current directors console window to the top of the stack.
263 void Pages::setConsoleCurrent()
265 mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(m_console));
269 * Bring this window to the top of the stack.
271 void Pages::setCurrent()
273 mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(this));
277 * Function to set the text of the toggle dock context menu when page and
278 * widget item are NOT known.
280 void Pages::setContextMenuDockText()
282 QTreeWidgetItem *item = mainWin->getFromHash(this);
283 QString docktext("");
285 docktext += "UnDock ";
287 docktext += "ReDock ";
289 docktext += item->text(0) += " Window";
291 mainWin->actionToggleDock->setText(docktext);
292 setTreeWidgetItemDockColor();
296 * Function to set the color of the tree widget item based on whether it is
299 void Pages::setTreeWidgetItemDockColor()
301 QTreeWidgetItem* item = mainWin->getFromHash(this);
303 if (item->text(0) != "Console") {
305 /* Set the brush to blue if undocked */
306 QBrush blackBrush(Qt::black);
307 item->setForeground(0, blackBrush);
309 /* Set the brush back to black if docked */
310 QBrush blueBrush(Qt::blue);
311 item->setForeground(0, blueBrush);