2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many 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 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
21 #include <QAbstractEventDispatcher>
22 #include <QTableWidgetItem>
23 #include <QMessageBox>
24 #include "mediaedit/mediaedit.h"
25 #include "relabel/relabel.h"
27 #include "mediainfo.h"
28 #include "util/fmtwidgetitem.h"
34 MediaInfo::MediaInfo(QTreeWidgetItem *parentWidget, QString &mediaName)
38 pgInitialize(tr("Media Info"), parentWidget);
39 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
40 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge-edit.png")));
41 m_mediaName = mediaName;
42 connect(pbPrune, SIGNAL(clicked()), this, SLOT(pruneVol()));
43 connect(pbPurge, SIGNAL(clicked()), this, SLOT(purgeVol()));
44 connect(pbDelete, SIGNAL(clicked()), this, SLOT(deleteVol()));
45 connect(pbEdit, SIGNAL(clicked()), this, SLOT(editVol()));
46 connect(tableJob, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(showInfoForJob(QTableWidgetItem *)));
54 * Subroutine to call class to show the log in the database from that job
56 void MediaInfo::showInfoForJob(QTableWidgetItem * item)
58 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
59 int row = item->row();
60 QString jobid = tableJob->item(row, 0)->text();
61 new Job(jobid, pageSelectorTreeWidgetItem);
62 // connect(j, SIGNAL(destroyed()), this, SLOT(populateTree()));
65 void MediaInfo::pruneVol()
67 new prunePage(m_mediaName, "");
68 // connect(prune, SIGNAL(destroyed()), this, SLOT(populateTree()));
71 // TODO: use same functions as in medialist.cpp
72 void MediaInfo::purgeVol()
74 if (QMessageBox::warning(this, "Bat",
75 tr("Are you sure you want to purge ?? !!!.\n"
76 "The Purge command will delete associated Catalog database records from Jobs and"
77 " Volumes without considering the retention period. Purge works only on the"
78 " Catalog database and does not affect data written to Volumes. This command can"
79 " be dangerous because you can delete catalog records associated with current"
80 " backups of files, and we recommend that you do not use it unless you know what"
82 "Press OK to proceed with the purge operation?"),
83 QMessageBox::Ok | QMessageBox::Cancel)
84 == QMessageBox::Cancel) { return; }
86 QString cmd("purge volume=");
91 void MediaInfo::deleteVol()
93 if (QMessageBox::warning(this, "Bat",
94 tr("Are you sure you want to delete?? !!!.\n"
95 "This delete command is used to delete a Volume record and all associated catalog"
96 " records that were created. This command operates only on the Catalog"
97 " database and has no effect on the actual data written to a Volume. This"
98 " command can be dangerous and we strongly recommend that you do not use"
99 " it unless you know what you are doing. All Jobs and all associated"
100 " records (File and JobMedia) will be deleted from the catalog."
101 "Press OK to proceed with delete operation.?"),
102 QMessageBox::Ok | QMessageBox::Cancel)
103 == QMessageBox::Cancel) { return; }
105 QString cmd("delete volume=");
110 void MediaInfo::editVol()
112 new MediaEdit(mainWin->getFromHash(this), m_mediaId);
113 // connect(edit, SIGNAL(destroyed()), this, SLOT(populateTree()));
117 * Populate the text in the window
119 void MediaInfo::populateForm()
124 QString stat, LastWritten;
128 "SELECT MediaId, VolumeName, Pool.Name, MediaType, FirstWritten,"
129 "LastWritten, VolMounts, VolBytes, Media.Enabled,"
130 "Location.Location, VolStatus, RecyclePool.Name, Media.Recycle, "
131 "VolReadTime/1000000, VolWriteTime/1000000, Media.VolUseDuration, "
132 "Media.MaxVolJobs, Media.MaxVolFiles, Media.MaxVolBytes, "
133 "Media.VolRetention,InChanger,Slot "
134 "FROM Media JOIN Pool USING (PoolId) LEFT JOIN Pool AS RecyclePool "
135 "ON (Media.RecyclePoolId=RecyclePool.PoolId) "
136 "LEFT JOIN Location ON (Media.LocationId=Location.LocationId) "
137 "WHERE Media.VolumeName='" + m_mediaName + "'";
139 if (mainWin->m_sqlDebug) {
140 Pmsg1(000, "MediaInfo query cmd : %s\n",query.toUtf8().data());
143 if (m_console->sql_cmd(query, results)) {
145 QStringList fieldlist;
147 foreach (resultline, results) { // should have only one result
148 fieldlist = resultline.split("\t");
149 QStringListIterator fld(fieldlist);
150 m_mediaId = fld.next();
152 label_VolumeName->setText(fld.next());
153 label_Pool->setText(fld.next());
154 label_MediaType->setText(fld.next());
155 label_FirstWritten->setText(fld.next());
156 LastWritten = fld.next();
157 label_LastWritten->setText(LastWritten);
158 // label_VolFiles->setText(fld.next());
159 label_VolMounts->setText(fld.next());
160 label_VolBytes->setText(convertBytesSI(fld.next().toULongLong()));
161 label_Enabled->setPixmap(QPixmap(":/images/inflag" + fld.next() + ".png"));
162 label_Location->setText(fld.next());
163 label_VolStatus->setText(fld.next());
164 label_RecyclePool->setText(fld.next());
165 chkbox_Recycle->setCheckState(fld.next().toInt()?Qt::Checked:Qt::Unchecked);
166 edit_utime(fld.next().toULongLong(), buf, sizeof(buf));
167 label_VolReadTime->setText(QString(buf));
169 edit_utime(fld.next().toULongLong(), buf, sizeof(buf));
170 label_VolWriteTime->setText(QString(buf));
172 edit_utime(fld.next().toULongLong(), buf, sizeof(buf));
173 label_VolUseDuration->setText(QString(buf));
175 label_MaxVolJobs->setText(fld.next());
176 label_MaxVolFiles->setText(fld.next());
177 label_MaxVolBytes->setText(fld.next());
180 edit_utime(stat.toULongLong(), buf, sizeof(buf));
181 label_VolRetention->setText(QString(buf));
183 if (LastWritten != "") {
184 t = str_to_utime(LastWritten.toLatin1().data());
185 t = t + stat.toULongLong();
187 localtime_r(&ttime, &tm);
188 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
189 label_Expire->setText(QString(buf));
191 label_Online->setPixmap(QPixmap(":/images/inflag"+fld.next()+".png"));
192 // label_VolFiles->setText(fld.next());
193 // label_VolErrors->setText(fld.next());
197 // jobstatus_to_ascii_gui(stat[0].toLatin1(), buf, sizeof(buf));
204 "SELECT DISTINCT JobId, Name, StartTime, Type, Level, JobFiles,"
205 "JobBytes,JobStatus "
206 "FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) "
207 "WHERE Media.VolumeName = '" + m_mediaName + "'";
209 if (mainWin->m_sqlDebug) {
210 Pmsg1(000, "MediaInfo query cmd : %s\n",query.toUtf8().data());
213 if (m_console->sql_cmd(query, results)) {
215 QStringList fieldlist;
217 tableJob->setRowCount(results.size());
218 foreach (resultline, results) {
219 fieldlist = resultline.split("\t");
220 QStringListIterator fld(fieldlist);
222 TableItemFormatter jobitem(*tableJob, row);
225 jobitem.setNumericFld(index++, fld.next());
228 jobitem.setTextFld(index++, fld.next());
231 jobitem.setTextFld(index++, fld.next(), true);
234 jobitem.setJobTypeFld(index++, fld.next());
237 jobitem.setJobLevelFld(index++, fld.next());
240 jobitem.setNumericFld(index++, fld.next());
243 jobitem.setBytesFld(index++, fld.next());
246 jobitem.setJobStatusFld(index++, fld.next());
251 tableJob->resizeColumnsToContents();
252 tableJob->resizeRowsToContents();
253 tableJob->verticalHeader()->hide();
256 tableJob->setEditTriggers(QAbstractItemView::NoEditTriggers);