]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/storage/content.cpp
continue storage content panel
[bacula/bacula] / bacula / src / qt-console / storage / content.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2009 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 and included
11    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 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.
27 */
28  
29 #include "bat.h"
30 #include <QAbstractEventDispatcher>
31 #include <QMenu>
32 #include "content.h"
33 #include "label/label.h"
34 #include "mount/mount.h"
35 #include "util/fmtwidgetitem.h"
36 #include "status/storstat.h"
37
38 Content::Content(QString storage)
39 {
40    setupUi(this);
41    pgInitialize(tr("Storage Content"));
42    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
43    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png")));
44
45    m_populated = false;
46    m_firstpopulation = true;
47    m_checkcurwidget = true;
48    m_closeable = true;
49    m_currentStorage = storage;
50
51    populate();
52
53    dockPage();
54    setCurrent();
55 }
56
57 /*
58  * The main meat of the class!!  The function that querries the director and 
59  * creates the widgets with appropriate values.
60  */
61 void Content::populate()
62 {
63    m_populated = true;
64    m_firstpopulation = false;
65    Freeze frz(*tableContent); /* disable updating*/
66    int row = 0;
67    QStringList results;
68    QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\"");
69    m_console->dir_cmd(cmd, results);
70    foreach (QString resultline, results){
71       Pmsg1(0, "s=%s\n", resultline.toUtf8().data());
72       QStringList fieldlist = resultline.split("|");
73       QStringListIterator fld(fieldlist);
74       if (fieldlist.size() < 9)
75          continue; /* some fields missing, ignore row */
76       Pmsg1(0, "s=%s\n", resultline.toUtf8().data());
77       TableItemFormatter jobitem(*tableContent, row);
78       int col=0;
79       jobitem.setNumericFld(col++, fld.next()); 
80       fld.next();
81       jobitem.setTextFld(col++, fld.next());
82       jobitem.setNumericFld(col++, fld.next());
83       jobitem.setVolStatusFld(col++, fld.next());
84       jobitem.setTextFld(col++, fld.next());
85       jobitem.setTextFld(col++, fld.next());
86       jobitem.setTextFld(col++, fld.next());
87       jobitem.setTextFld(col++, fld.next());
88
89       row++;
90    }
91 }
92
93 /*
94  * Virtual function which is called when this page is visible on the stack
95  */
96 void Content::currentStackItem()
97 {
98    if(!m_populated) {
99       populate();
100    }
101 }
102
103 /*
104  *  Functions to respond to local context sensitive menu sending console
105  *  commands If I could figure out how to make these one function passing a
106  *  string, Yaaaaaa
107  */
108 void Content::consoleStatusStorage()
109 {
110    QString cmd("status storage=");
111    cmd += m_currentStorage;
112    consoleCommand(cmd);
113 }
114
115 /* Label Media populating current storage by default */
116 void Content::consoleLabelStorage()
117 {
118    new labelPage(m_currentStorage);
119 }
120
121 void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
122 {
123
124 }
125
126 /* Mount currently selected storage */
127 void Content::consoleMountStorage()
128 {
129    if (m_currentAutoChanger == 0){
130       /* no autochanger, just execute the command in the console */
131       QString cmd("mount storage=");
132       cmd += m_currentStorage;
133       consoleCommand(cmd);
134    } else {
135       setConsoleCurrent();
136       /* if this storage is an autochanger, lets ask for the slot */
137       new mountDialog(m_console, m_currentStorage);
138    }
139 }
140
141 /* Unmount Currently selected storage */
142 void Content::consoleUnMountStorage()
143 {
144    QString cmd("umount storage=");
145    cmd += m_currentStorage;
146    consoleCommand(cmd);
147 }
148
149 /* Update Slots */
150 void Content::consoleUpdateSlots()
151 {
152    QString cmd("update slots storage=");
153    cmd += m_currentStorage;
154    consoleCommand(cmd);
155 }
156
157 /* Update Slots Scan*/
158 void Content::consoleUpdateSlotsScan()
159 {
160    QString cmd("update slots scan storage=");
161    cmd += m_currentStorage;
162    consoleCommand(cmd);
163 }
164
165 /* Release a tape in the drive */
166 void Content::consoleRelease()
167 {
168    QString cmd("release storage=");
169    cmd += m_currentStorage;
170    consoleCommand(cmd);
171 }
172
173 /*
174  *  Open a status storage window
175  */
176 void Content::statusStorageWindow()
177 {
178    /* if one exists, then just set it current */
179    bool found = false;
180    foreach(Pages *page, mainWin->m_pagehash) {
181       if (mainWin->currentConsole() == page->console()) {
182          if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) {
183             found = true;
184             page->setCurrent();
185          }
186       }
187    }
188    if (!found) {
189       QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
190       new StorStat(m_currentStorage, parentItem);
191    }
192 }