2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
18 #include <QAbstractEventDispatcher>
19 #include <QTableWidgetItem>
20 #include <QMessageBox>
21 #include "mediaedit/mediaedit.h"
22 #include "relabel/relabel.h"
24 #include "mediainfo.h"
25 #include "util/fmtwidgetitem.h"
31 MediaInfo::MediaInfo(QTreeWidgetItem *parentWidget, QString &mediaName)
35 pgInitialize(tr("Media Info"), parentWidget);
36 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
37 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge-edit.png")));
38 m_mediaName = mediaName;
39 connect(pbPrune, SIGNAL(clicked()), this, SLOT(pruneVol()));
40 connect(pbPurge, SIGNAL(clicked()), this, SLOT(purgeVol()));
41 connect(pbDelete, SIGNAL(clicked()), this, SLOT(deleteVol()));
42 connect(pbEdit, SIGNAL(clicked()), this, SLOT(editVol()));
43 connect(tableJob, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(showInfoForJob(QTableWidgetItem *)));
51 * Subroutine to call class to show the log in the database from that job
53 void MediaInfo::showInfoForJob(QTableWidgetItem * item)
55 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
56 int row = item->row();
57 QString jobid = tableJob->item(row, 0)->text();
58 new Job(jobid, pageSelectorTreeWidgetItem);
59 // connect(j, SIGNAL(destroyed()), this, SLOT(populateTree()));
62 void MediaInfo::pruneVol()
64 new prunePage(m_mediaName, "");
65 // connect(prune, SIGNAL(destroyed()), this, SLOT(populateTree()));
68 // TODO: use same functions as in medialist.cpp
69 void MediaInfo::purgeVol()
71 if (QMessageBox::warning(this, "Bat",
72 tr("Are you sure you want to purge ?? !!!.\n"
73 "The Purge command will delete associated Catalog database records from Jobs and"
74 " Volumes without considering the retention period. Purge works only on the"
75 " Catalog database and does not affect data written to Volumes. This command can"
76 " be dangerous because you can delete catalog records associated with current"
77 " backups of files, and we recommend that you do not use it unless you know what"
79 "Press OK to proceed with the purge operation?"),
80 QMessageBox::Ok | QMessageBox::Cancel)
81 == QMessageBox::Cancel) { return; }
83 QString cmd("purge volume=");
88 void MediaInfo::deleteVol()
90 if (QMessageBox::warning(this, "Bat",
91 tr("Are you sure you want to delete?? !!!.\n"
92 "This delete command is used to delete a Volume record and all associated catalog"
93 " records that were created. This command operates only on the Catalog"
94 " database and has no effect on the actual data written to a Volume. This"
95 " command can be dangerous and we strongly recommend that you do not use"
96 " it unless you know what you are doing. All Jobs and all associated"
97 " records (File and JobMedia) will be deleted from the catalog."
98 "Press OK to proceed with delete operation.?"),
99 QMessageBox::Ok | QMessageBox::Cancel)
100 == QMessageBox::Cancel) { return; }
102 QString cmd("delete volume=");
107 void MediaInfo::editVol()
109 new MediaEdit(mainWin->getFromHash(this), m_mediaId);
110 // connect(edit, SIGNAL(destroyed()), this, SLOT(populateTree()));
114 * Populate the text in the window
116 void MediaInfo::populateForm()
121 QString stat, LastWritten;
125 "SELECT MediaId, VolumeName, Pool.Name, MediaType, FirstWritten,"
126 "LastWritten, VolMounts, VolBytes, Media.Enabled,"
127 "Location.Location, VolStatus, RecyclePool.Name, Media.Recycle, "
128 "VolReadTime/1000000, VolWriteTime/1000000, Media.VolUseDuration, "
129 "Media.MaxVolJobs, Media.MaxVolFiles, Media.MaxVolBytes, "
130 "Media.VolRetention,InChanger,Slot "
131 "FROM Media JOIN Pool USING (PoolId) LEFT JOIN Pool AS RecyclePool "
132 "ON (Media.RecyclePoolId=RecyclePool.PoolId) "
133 "LEFT JOIN Location ON (Media.LocationId=Location.LocationId) "
134 "WHERE Media.VolumeName='" + m_mediaName + "'";
136 if (mainWin->m_sqlDebug) {
137 Pmsg1(000, "MediaInfo query cmd : %s\n",query.toUtf8().data());
140 if (m_console->sql_cmd(query, results)) {
142 QStringList fieldlist;
144 foreach (resultline, results) { // should have only one result
145 fieldlist = resultline.split("\t");
146 QStringListIterator fld(fieldlist);
147 m_mediaId = fld.next();
149 label_VolumeName->setText(fld.next());
150 label_Pool->setText(fld.next());
151 label_MediaType->setText(fld.next());
152 label_FirstWritten->setText(fld.next());
153 LastWritten = fld.next();
154 label_LastWritten->setText(LastWritten);
155 // label_VolFiles->setText(fld.next());
156 label_VolMounts->setText(fld.next());
157 label_VolBytes->setText(convertBytesSI(fld.next().toULongLong()));
158 label_Enabled->setPixmap(QPixmap(":/images/inflag" + fld.next() + ".png"));
159 label_Location->setText(fld.next());
160 label_VolStatus->setText(fld.next());
161 label_RecyclePool->setText(fld.next());
162 chkbox_Recycle->setCheckState(fld.next().toInt()?Qt::Checked:Qt::Unchecked);
163 edit_utime(fld.next().toULongLong(), buf, sizeof(buf));
164 label_VolReadTime->setText(QString(buf));
166 edit_utime(fld.next().toULongLong(), buf, sizeof(buf));
167 label_VolWriteTime->setText(QString(buf));
169 edit_utime(fld.next().toULongLong(), buf, sizeof(buf));
170 label_VolUseDuration->setText(QString(buf));
172 label_MaxVolJobs->setText(fld.next());
173 label_MaxVolFiles->setText(fld.next());
174 label_MaxVolBytes->setText(fld.next());
177 edit_utime(stat.toULongLong(), buf, sizeof(buf));
178 label_VolRetention->setText(QString(buf));
180 if (LastWritten != "") {
181 t = str_to_utime(LastWritten.toAscii().data());
182 t = t + stat.toULongLong();
184 localtime_r(&ttime, &tm);
185 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
186 label_Expire->setText(QString(buf));
188 label_Online->setPixmap(QPixmap(":/images/inflag"+fld.next()+".png"));
189 // label_VolFiles->setText(fld.next());
190 // label_VolErrors->setText(fld.next());
194 // jobstatus_to_ascii_gui(stat[0].toAscii(), buf, sizeof(buf));
201 "SELECT DISTINCT JobId, Name, StartTime, Type, Level, JobFiles,"
202 "JobBytes,JobStatus "
203 "FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) "
204 "WHERE Media.VolumeName = '" + m_mediaName + "'";
206 if (mainWin->m_sqlDebug) {
207 Pmsg1(000, "MediaInfo query cmd : %s\n",query.toUtf8().data());
210 if (m_console->sql_cmd(query, results)) {
212 QStringList fieldlist;
214 tableJob->setRowCount(results.size());
215 foreach (resultline, results) {
216 fieldlist = resultline.split("\t");
217 QStringListIterator fld(fieldlist);
219 TableItemFormatter jobitem(*tableJob, row);
222 jobitem.setNumericFld(index++, fld.next());
225 jobitem.setTextFld(index++, fld.next());
228 jobitem.setTextFld(index++, fld.next(), true);
231 jobitem.setJobTypeFld(index++, fld.next());
234 jobitem.setJobLevelFld(index++, fld.next());
237 jobitem.setNumericFld(index++, fld.next());
240 jobitem.setBytesFld(index++, fld.next());
243 jobitem.setJobStatusFld(index++, fld.next());
248 tableJob->resizeColumnsToContents();
249 tableJob->resizeRowsToContents();
250 tableJob->verticalHeader()->hide();
253 tableJob->setEditTriggers(QAbstractItemView::NoEditTriggers);