]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/storage/content.cpp
try to insert data on table content
[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    populateContent();
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::populateContent()
62 {
63    m_populated = true;
64    m_firstpopulation = false;
65 //   Freeze frz(*tableContent); /* disable updating*/
66    tableContent->clear();
67
68    int row = 0;
69    QStringList results_all;
70    QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\"");
71
72    m_console->dir_cmd(cmd, results_all);
73    // skip non list messages
74    QStringList results = results_all.filter(QRegExp("[0-9]+\\|"));
75    Pmsg1(0, "count=%i\n", results.size());
76    tableContent->setRowCount(results.size());
77
78    foreach (QString resultline, results){
79       int col=0;
80       QStringList fieldlist = resultline.split("|");
81       QStringListIterator fld(fieldlist);
82
83       if (fieldlist.size() < 9)
84          continue; /* some fields missing, ignore row */
85
86       Pmsg1(0, "s=%s\n", resultline.toUtf8().data());
87
88       TableItemFormatter slotitem(*tableContent, row);
89
90       slotitem.setNumericFld(col++, fld.next()); // Slot
91       Pmsg1(0, "s=%s\n", fld.next().toUtf8().data()); // Real Slot
92
93 //      if (fld.next() != "") {                          // skip "Real Slot"
94          slotitem.setTextFld(col++, fld.next());         // Volume
95          slotitem.setNumericFld(col++, fld.next());      // Bytes
96          slotitem.setVolStatusFld(col++, fld.next());    // Status
97          slotitem.setTextFld(col++, fld.next());         // MediaType
98          slotitem.setTextFld(col++, fld.next());         // Pool
99          slotitem.setTextFld(col++, fld.next());         // LastWritten
100          slotitem.setTextFld(col++, fld.next());         // Expire
101 //      }
102       row++;
103    }
104
105    tableContent->resizeColumnsToContents();
106    tableContent->verticalHeader()->hide();
107
108    tableContent->sortByColumn(0, Qt::AscendingOrder);
109    tableContent->setSortingEnabled(true);
110
111    int rcnt = tableContent->rowCount();
112    int ccnt = tableContent->columnCount();
113    for(int r=0; r < rcnt; r++) {
114       for(int c=0; c < ccnt; c++) {
115          QTableWidgetItem* item = tableContent->item(r, c);
116          if (item) {
117             item->setFlags(Qt::ItemFlags(item->flags() & (~Qt::ItemIsEditable)));
118          }
119       }
120    }
121
122    tableContent->update();
123
124    tableDrive->verticalHeader()->hide();
125 }
126
127 /*
128  * Virtual function which is called when this page is visible on the stack
129  */
130 void Content::currentStackItem()
131 {
132    if(!m_populated) {
133       populateContent();
134    }
135 }
136
137 /*
138  *  Functions to respond to local context sensitive menu sending console
139  *  commands If I could figure out how to make these one function passing a
140  *  string, Yaaaaaa
141  */
142 void Content::consoleStatusStorage()
143 {
144    QString cmd("status storage=");
145    cmd += m_currentStorage;
146    consoleCommand(cmd);
147 }
148
149 /* Label Media populating current storage by default */
150 void Content::consoleLabelStorage()
151 {
152    new labelPage(m_currentStorage);
153 }
154
155 void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
156 {
157
158 }
159
160 /* Mount currently selected storage */
161 void Content::consoleMountStorage()
162 {
163    if (m_currentAutoChanger == 0){
164       /* no autochanger, just execute the command in the console */
165       QString cmd("mount storage=");
166       cmd += m_currentStorage;
167       consoleCommand(cmd);
168    } else {
169       setConsoleCurrent();
170       /* if this storage is an autochanger, lets ask for the slot */
171       new mountDialog(m_console, m_currentStorage);
172    }
173 }
174
175 /* Unmount Currently selected storage */
176 void Content::consoleUnMountStorage()
177 {
178    QString cmd("umount storage=");
179    cmd += m_currentStorage;
180    consoleCommand(cmd);
181 }
182
183 /* Update Slots */
184 void Content::consoleUpdateSlots()
185 {
186    QString cmd("update slots storage=");
187    cmd += m_currentStorage;
188    consoleCommand(cmd);
189 }
190
191 /* Update Slots Scan*/
192 void Content::consoleUpdateSlotsScan()
193 {
194    QString cmd("update slots scan storage=");
195    cmd += m_currentStorage;
196    consoleCommand(cmd);
197 }
198
199 /* Release a tape in the drive */
200 void Content::consoleRelease()
201 {
202    QString cmd("release storage=");
203    cmd += m_currentStorage;
204    consoleCommand(cmd);
205 }
206
207 /*
208  *  Open a status storage window
209  */
210 void Content::statusStorageWindow()
211 {
212    /* if one exists, then just set it current */
213    bool found = false;
214    foreach(Pages *page, mainWin->m_pagehash) {
215       if (mainWin->currentConsole() == page->console()) {
216          if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) {
217             found = true;
218             page->setCurrent();
219          }
220       }
221    }
222    if (!found) {
223       QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
224       new StorStat(m_currentStorage, parentItem);
225    }
226 }