]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/mediainfo/mediainfo.cpp
bat fill mediainfo fields
[bacula/bacula] / bacula / src / qt-console / mediainfo / mediainfo.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 <QTableWidgetItem>
32 #include <QMessageBox>
33 #include "mediainfo.h"
34
35 /*
36  * A constructor 
37  */
38 MediaInfo::MediaInfo(QTreeWidgetItem *parentWidget, QString &mediaName)
39 {
40    setupUi(this);
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;
45    m_closeable = true;
46    dockPage();
47    setCurrent();
48    populateForm();
49 }
50
51 // Need to use the fmtwidgetitem helper instead
52 static QString convertBytesSI(qint64 qfld)
53 {
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);
60
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) */
63    char suffix;
64    if (qfld >= EB) {
65       qfld /= PB; 
66       suffix = 'E';
67    }
68    else if (qfld >= PB) {
69       qfld /= TB; 
70       suffix = 'P';
71    }
72    else if (qfld >= TB) {
73       qfld /= GB; 
74       suffix = 'T';
75    }
76    else if (qfld >= GB) {
77       qfld /= MB;
78       suffix = 'G';
79    }
80    else if (qfld >= MB) {
81       qfld /= KB;
82       suffix = 'M';
83    }
84    else if (qfld >= KB) {
85       suffix = 'k'; /* SI uses lowercase k */
86    }
87    else  {
88       /* plain bytes, no need to reformat */
89       return QString("%1 B").arg(qfld); 
90    }
91
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);
95 }
96
97 /*
98  * Populate the text in the window
99  */
100 void MediaInfo::populateForm()
101 {
102    QString stat;
103    char buf[256];
104    QString query = 
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 + "'";
114
115    QStringList results;
116    if (m_console->sql_cmd(query, results)) {
117       QString resultline;
118       QStringList fieldlist;
119
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());
143          
144 //         label_VolFiles->setText(fld.next());
145 //         label_VolErrors->setText(fld.next());
146
147 //         stat=fld.next();
148 //         label_Online->setPixmap(QPixmap(":/images/inflag" + stat + ".png"));
149 //         jobstatus_to_ascii_gui(stat[0].toAscii(), buf, sizeof(buf));
150 //         stat = buf;
151 //       
152       }
153    }
154 }