]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/pages.cpp
Update description of PAGES and changes to TODO. Also removed spacers
[bacula/bacula] / bacula / src / qt-console / pages.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
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.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28 /*
29  *   Version $Id: batstack.cpp 4230 2007-02-21 20:07:37Z kerns $
30  *
31  *   Dirk Bartley, March 2007
32  */
33
34 #include "pages.h"
35 #include "bat.h"
36
37 /*
38  * dockPage
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.
41  */
42
43 void Pages::dockPage()
44 {
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.
47     */
48    setWindowFlags(Qt::Widget);
49 //   setParent(m_parent);
50
51    /* This was being done already */
52    m_parent->addWidget(this);
53
54    /* Set docked flag */
55    m_docked = true;
56 }
57
58 /*
59  * undockPage
60  * This function is intended to be called from within the Pages class to put
61  * a window from the stack widget to a floating window.
62  */
63
64 void Pages::undockPage()
65 {
66    /* Change from a stacked widget to a normal window */
67    m_parent->removeWidget(this);
68    setWindowFlags(Qt::Window);
69    show();
70    /* Clear docked flag */
71    m_docked = false;
72 }
73
74 /*
75  * This function is intended to be called with the subclasses.  When it is 
76  * called the specific sublclass does not have to be known to Pages.  When it 
77  * is called this function will change the page from it's current state of being
78  * docked or undocked and change it to the other.
79  */
80
81 void Pages::togglePageDocking()
82 {
83    if (m_docked) {
84       undockPage();
85    } else {
86       dockPage();
87    }
88 }
89
90 /*
91  * This function is because I wanted for some reason to keep it protected but still 
92  * give any subclasses the ability to find out if it is currently stacked or not.
93  */
94 bool Pages::isDocked()
95 {
96    return m_docked;
97 }
98
99 /*
100  * To keep m_closeable protected as well
101  */
102 bool Pages::isCloseable()
103 {
104    return m_closeable;
105 }
106
107 /*
108  * When a window is closed, this slot is called.  The idea is to put it back in the
109  * stack here, and it works.  I wanted to get it to the top of the stack so that the
110  * user immediately sees where his window went.  Also, if he undocks the window, then
111  * closes it with the tree item highlighted, it may be confusing that the highlighted
112  * treewidgetitem is not the stack item in the front.
113  */
114
115 void Pages::closeEvent(QCloseEvent* event)
116 {
117    /* A Widget was closed, lets toggle it back into the window, and set it in front. */
118    dockPage();
119
120    /* is the tree widget item for "this" the current widget item */
121    if (mainWin->treeWidget->currentItem() == mainWin->getFromHash(this))
122       /* in case the current widget is the one which represents this, lets set the context
123        * menu to undock */
124       mainWin->setContextMenuDockText();
125    else
126       /* in case the current widget is not the one which represents this, lets set the
127       * color back to black */
128       mainWin->setTreeWidgetItemDockColor(this);
129
130    /* this fixes my woes of getting the widget to show up on top when closed */
131    event->ignore();
132
133    /* put this widget on the top of the stack widget */
134    m_parent->setCurrentWidget(this);
135
136    /* Set the current tree widget item in the Page Selector window to the item 
137     * which represents "this" */
138    setCurrent();
139 }
140
141 /*
142  * The next three are virtual functions.  The idea here is that each subclass will have the
143  * built in virtual function to override if the programmer wants to populate the window
144  * when it it is first clicked.
145  */
146 void Pages::PgSeltreeWidgetClicked()
147 {
148 }
149
150 /*
151  *  Virtual function which is called when this page is visible on the stack.
152  *  This will be overridden by classes that want to populate if they are on the
153  *  top.
154  */
155 void Pages::currentStackItem()
156 {
157 }
158
159 /*
160  * Function to close the stacked page and remove the widget from the
161  * Page selector window
162  */
163 void Pages::closeStackPage()
164 {
165    /* First get the tree widget item and destroy it */
166    QTreeWidgetItem *item=mainWin->getFromHash(this);
167    /* remove the QTreeWidgetItem <-> page from the hash */
168    mainWin->hashRemove(item, this);
169    /* remove the item from the page selector by destroying it */
170    delete item;
171    /* remove this */
172    delete this;
173 }
174
175 /*
176  * Function to set members from the external mainwin and it's overload being
177  * passed a specific QTreeWidgetItem to be it's parent on the tree
178  */
179 void Pages::pgInitialize()
180 {
181    pgInitialize(NULL);
182 }
183
184 void Pages::pgInitialize(QTreeWidgetItem *parentTreeWidgetItem)
185 {
186    m_parent = mainWin->stackedWidget;
187    m_console = mainWin->currentConsole();
188
189    if (!parentTreeWidgetItem) {
190       parentTreeWidgetItem = m_console->directorTreeItem();
191    }
192
193    QTreeWidgetItem *item = new QTreeWidgetItem(parentTreeWidgetItem);
194    QString name; 
195    treeWidgetName(name);
196    item->setText(0, name);
197    mainWin->hashInsert(item, this);
198    setTitle();
199 }
200
201 /*
202  * Virtual Function to return a name
203  * All subclasses should override this function
204  */
205 void Pages::treeWidgetName(QString &name)
206 {
207    name = m_name;
208 }
209
210 /*
211  * Function to simplify executing a console command and bringing the
212  * console to the front of the stack
213  */
214 void Pages::consoleCommand(QString &command)
215 {
216    if (!m_console->is_connectedGui())
217        return;
218    /* Bring this directors console to the front of the stack */
219    setConsoleCurrent();
220    m_console->display_text("Context sensitive command :\n\n");
221    m_console->display_text("****    ");
222    m_console->display_text(command + "    ****\n");
223    m_console->display_text("Director Response :\n\n");
224    m_console->write_dir(command.toUtf8().data());
225    m_console->displayToPrompt();
226 }
227
228 /*
229  * Function for handling undocked windows becoming active.
230  * Change the currently selected item in the page selector window to the now
231  * active undocked window.  This will also make the console for the undocked
232  * window m_currentConsole.
233  */
234 void Pages::changeEvent(QEvent *event)
235 {
236    if ((event->type() ==  QEvent::ActivationChange) && (isActiveWindow())) {
237       setCurrent();
238    }
239 }
240
241 /*
242  * Function to simplify getting the name of the class and the director into
243  * the caption or title of the window
244  */
245 void Pages::setTitle()
246 {
247    QString title, director;
248    treeWidgetName(title);
249    m_console->getDirResName(director);
250    title += " of Director ";
251    title += director;
252    setWindowTitle(title);
253 }
254
255 /*
256  * Bring the current directors console window to the top of the stack.
257  */
258 void Pages::setConsoleCurrent()
259 {
260    mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(m_console));
261 }
262
263 /*
264  * Bring this window to the top of the stack.
265  */
266 void Pages::setCurrent()
267 {
268    mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(this));
269 }