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
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
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.
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
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.
30 #include <QAbstractEventDispatcher>
31 #include <QTableWidgetItem>
32 #include <QMessageBox>
33 #include "mediainfo.h"
38 MediaInfo::MediaInfo(QTreeWidgetItem *parentWidget, QString &mediaName)
41 pgInitialize(tr("Media Info"), parentWidget);
42 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
43 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/cartridge-edit.png")));
44 m_mediaName = mediaName;
51 // Need to use the fmtwidgetitem helper instead
52 static QString convertBytesSI(qint64 qfld)
54 static const qint64 KB = Q_INT64_C(1000);
55 static const qint64 MB = (KB * KB);
56 static const qint64 GB = (MB * KB);
57 static const qint64 TB = (GB * KB);
58 static const qint64 PB = (TB * KB);
59 static const qint64 EB = (PB * KB);
61 /* note: division is integer, so to have some decimals we divide for a
62 smaller unit (e.g. GB for a TB number and so on) */
68 else if (qfld >= PB) {
72 else if (qfld >= TB) {
76 else if (qfld >= GB) {
80 else if (qfld >= MB) {
84 else if (qfld >= KB) {
85 suffix = 'k'; /* SI uses lowercase k */
88 /* plain bytes, no need to reformat */
89 return QString("%1 B").arg(qfld);
92 /* having divided for a smaller unit, now we can safely convert to double and
93 use the extra room for decimals */
94 return QString("%1 %2B").arg(qfld / 1000.0, 0, 'f', 2).arg(suffix);
98 * Populate the text in the window
100 void MediaInfo::populateForm()
105 "SELECT VolumeName, Pool.Name, MediaType, FirstWritten,"
106 "LastWritten, VolMounts, VolBytes, Media.Enabled,"
107 "Location.Location, VolStatus, RecyclePool.Name, Media.Recycle, "
108 "VolReadTime, VolWriteTime, Media.VolUseDuration, Media.MaxVolJobs, "
109 "Media.MaxVolFiles, Media.MaxVolBytes, Media.VolRetention,Slot,InChanger "
110 "FROM Media JOIN Pool USING (PoolId) LEFT JOIN Pool AS RecyclePool "
111 "ON (Media.RecyclePoolId = RecyclePool.PoolId) "
112 "LEFT JOIN Location USING (LocationId) "
113 "WHERE Media.VolumeName = '" + m_mediaName + "'";
116 if (m_console->sql_cmd(query, results)) {
118 QStringList fieldlist;
120 foreach (resultline, results) { // should have only one result
121 fieldlist = resultline.split("\t");
122 QStringListIterator fld(fieldlist);
123 label_VolumeName->setText(fld.next());
124 label_Pool->setText(fld.next());
125 label_MediaType->setText(fld.next());
126 label_FirstWritten->setText(fld.next());
127 label_LastWritten->setText(fld.next());
128 // label_VolFiles->setText(fld.next());
129 label_VolMounts->setText(fld.next());
130 label_VolBytes->setText(convertBytesSI(fld.next().toULongLong()));
131 label_Enabled->setPixmap(QPixmap(":/images/inflag" + fld.next() + ".png"));
132 label_Location->setText(fld.next());
133 label_VolStatus->setText(fld.next());
134 label_RecyclePool->setText(fld.next());
135 chkbox_Recycle->setCheckState(fld.next().toInt()?Qt::Checked:Qt::Unchecked);
136 label_VolReadTime->setText(fld.next());
137 label_VolWriteTime->setText(fld.next());
138 label_VolUseDuration->setText(fld.next());
139 label_MaxVolJobs->setText(fld.next());
140 label_MaxVolFiles->setText(fld.next());
141 label_MaxVolBytes->setText(fld.next());
142 label_VolRetention->setText(fld.next());
144 // label_VolFiles->setText(fld.next());
145 // label_VolErrors->setText(fld.next());
148 // label_Online->setPixmap(QPixmap(":/images/inflag" + stat + ".png"));
149 // jobstatus_to_ascii_gui(stat[0].toAscii(), buf, sizeof(buf));