]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/medialist/mediaview.cpp
Add new MediaView
[bacula/bacula] / bacula / src / qt-console / medialist / mediaview.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 <math.h>
33 #include "mediaview.h"
34 #include "mediaedit/mediaedit.h"
35 #include "mediainfo/mediainfo.h"
36 #include "joblist/joblist.h"
37 #include "relabel/relabel.h"
38 #include "run/run.h"
39 #include "util/fmtwidgetitem.h"
40
41 MediaView::MediaView()
42 {
43    setupUi(this);
44    m_name = tr("Media");
45    pgInitialize();
46    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
47    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge.png")));
48
49    /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_medialist.h */
50    m_populated = false;
51    m_checkcurwidget = true;
52    m_closeable = false;
53 }
54
55 MediaView::~MediaView()
56 {
57 }
58
59 /*
60  * The main meat of the class!!  The function that querries the director and 
61  * creates the widgets with appropriate values.
62  */
63 void MediaView::populateTable()
64 {
65    m_populated = true;
66
67    Freeze frz(*m_tableMedia); /* disable updating*/
68
69 }
70
71 /*
72  * Called from the signal of the context sensitive menu!
73  */
74 void MediaView::editVolume()
75 {
76    MediaEdit* edit = new MediaEdit(mainWin->getFromHash(this), m_currentVolumeId);
77    connect(edit, SIGNAL(destroyed()), this, SLOT(populateTable()));
78 }
79
80 /*
81  * Called from the signal of the context sensitive menu!
82  */
83 void MediaView::showJobs()
84 {
85    QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
86    mainWin->createPageJobList(m_currentVolumeName, "", "", "", parentItem);
87 }
88
89 /*
90  * Called from the signal of the context sensitive menu!
91  */
92 void MediaView::viewVolume()
93 {
94    QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
95    MediaInfo* view = new MediaInfo(parentItem, m_currentVolumeName);
96    connect(view, SIGNAL(destroyed()), this, SLOT(populateTable()));
97
98 }
99
100 /*
101  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
102  * The tree has been populated.
103  */
104 void MediaView::PgSeltreeWidgetClicked()
105 {
106    if (!m_populated) {
107       populateTable();
108    }
109    dockPage();
110 }
111
112 /*
113  * Virtual function which is called when this page is visible on the stack
114  */
115 void MediaView::currentStackItem()
116 {
117    if(!m_populated) {
118       populateTable();
119    }
120 }
121
122 /*
123  * Called from the signal of the context sensitive menu to delete a volume!
124  */
125 void MediaView::deleteVolume()
126 {
127    if (QMessageBox::warning(this, "Bat",
128       tr("Are you sure you want to delete??  !!!.\n"
129 "This delete command is used to delete a Volume record and all associated catalog"
130 " records that were created. This command operates only on the Catalog"
131 " database and has no effect on the actual data written to a Volume. This"
132 " command can be dangerous and we strongly recommend that you do not use"
133 " it unless you know what you are doing.  All Jobs and all associated"
134 " records (File and JobMedia) will be deleted from the catalog."
135       "Press OK to proceed with delete operation.?"),
136       QMessageBox::Ok | QMessageBox::Cancel)
137       == QMessageBox::Cancel) { return; }
138
139    QString cmd("delete volume=");
140    cmd += m_currentVolumeName;
141    consoleCommand(cmd);
142 }
143
144 /*
145  * Called from the signal of the context sensitive menu to purge!
146  */
147 void MediaView::purgeVolume()
148 {
149    if (QMessageBox::warning(this, "Bat",
150       tr("Are you sure you want to purge ??  !!!.\n"
151 "The Purge command will delete associated Catalog database records from Jobs and"
152 " Volumes without considering the retention period. Purge  works only on the"
153 " Catalog database and does not affect data written to Volumes. This command can"
154 " be dangerous because you can delete catalog records associated with current"
155 " backups of files, and we recommend that you do not use it unless you know what"
156 " you are doing.\n"
157       "Press OK to proceed with the purge operation?"),
158       QMessageBox::Ok | QMessageBox::Cancel)
159       == QMessageBox::Cancel) { return; }
160
161    QString cmd("purge volume=");
162    cmd += m_currentVolumeName;
163    consoleCommand(cmd);
164    populateTable();
165 }
166
167 /*
168  * Called from the signal of the context sensitive menu to prune!
169  */
170 void MediaView::pruneVolume()
171 {
172    new prunePage(m_currentVolumeName, "");
173 }
174
175 // /*
176 //  * Called from the signal of the context sensitive menu to relabel!
177 //  */
178 // void MediaView::relabelVolume()
179 // {
180 //    setConsoleCurrent();
181 //    new relabelDialog(m_console, m_currentVolumeName);
182 // }
183 // 
184 // /*
185 //  * Called from the signal of the context sensitive menu to purge!
186 //  */
187 // void MediaView::allVolumesFromPool()
188 // {
189 //    QString cmd = "update volume AllFromPool=" + m_currentVolumeName;
190 //    consoleCommand(cmd);
191 //    populateTable();
192 // }
193 // 
194 // void MediaView::allVolumes()
195 // {
196 //    QString cmd = "update volume allfrompools";
197 //    consoleCommand(cmd);
198 //    populateTable();
199 // }
200 // 
201 //  /*
202 //   * Called from the signal of the context sensitive menu to purge!
203 //   */
204 //  void MediaView::volumeFromPool()
205 //  {
206 //     QTreeWidgetItem *currentItem = mp_treeWidget->currentItem();
207 //     QTreeWidgetItem *parent = currentItem->parent();
208 //     QString pool = parent->text(0);
209 //     QString cmd;
210 //     cmd = "update volume=" + m_currentVolumeName + " frompool=" + pool;
211 //     consoleCommand(cmd);
212 //     populateTable();
213 //  }
214 //