/*
- Bacula® - The Network Backup Solution
-
- Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
-
- The main author of Bacula is Kern Sibbald, with contributions from
- many others, a complete list can be found in the file AUTHORS.
- This program is Free Software; you can redistribute it and/or
- modify it under the terms of version two of the GNU General Public
- License as published by the Free Software Foundation and included
- in the file LICENSE.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Bacula® is a registered trademark of Kern Sibbald.
- The licensor of Bacula is the Free Software Foundation Europe
- (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
- Switzerland, email:ftf@fsfeurope.org.
+ Bacula(R) - The Network Backup Solution
+
+ Copyright (C) 2000-2015 Kern Sibbald
+ Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
+
+ The original author of Bacula is Kern Sibbald, with contributions
+ from many others, a complete list can be found in the file AUTHORS.
+
+ You may use this file and others of this release according to the
+ license defined in the LICENSE file, which includes the Affero General
+ Public License, v3.0 ("AGPLv3") and some additional permissions and
+ terms pursuant to its AGPLv3 Section 7.
+
+ This notice must be preserved when any source code is
+ conveyed and/or propagated.
+
+ Bacula(R) is a registered trademark of Kern Sibbald.
*/
#include "bat.h"
#include "run/run.h"
#include "util/fmtwidgetitem.h"
-MediaView::MediaView()
+MediaView::MediaView() : Pages()
{
setupUi(this);
m_name = tr("Media");
bool MediaView::getSelection(QStringList &list)
{
- QList<QTableWidgetItem*> items = m_tableMedia->selectedItems();
QTableWidgetItem *it;
+ QList<QTableWidgetItem*> items = m_tableMedia->selectedItems();
int row;
- int *tab;
+ int nrows; /* number of rows */
+ bool *tab;
int nb = items.count();
if (!nb) {
return false;
}
- tab = (int *) malloc (nb * sizeof(int));
- memset(tab, 0, sizeof(int)*nb);
+ nrows = m_tableMedia->rowCount();
+ tab = (bool *) malloc (nrows * sizeof(bool));
+ memset(tab, 0, sizeof(bool)*nrows);
for (int i = 0; i < nb; ++i) {
row = items[i]->row();
if (!tab[row]) {
- tab[row]=1;
+ tab[row] = true;
it = m_tableMedia->item(row, 0);
list.append(it->text());
}
/* We should now in advance how many rows we will have */
if (m_chkExpired->isChecked()) {
for (int i=list.size() -1; i >= 0; i--) {
- fieldlist = list.at(i).split("\t");
+ fieldlist = list.at(i).split("\t");
+ ASSERT(fieldlist.size() != 9);
LastWritten = fieldlist.at(7);
if (LastWritten == "") {
list.removeAt(i);
{
utime_t t;
time_t ttime;
- QString stat, LastWritten;
+ QString stat, resultline, query;
+ QString str_usage;
+ QHash<QString, float> hash_size;
+ QStringList fieldlist, results;
char buf[256];
+ float usage;
struct tm tm;
m_populated = true;
cmd = "";
}
- m_tableMedia->clearContents();
+ query =
+ "SELECT AVG(VolBytes) AS size, COUNT(1) as nb, "
+ "MediaType FROM Media "
+ "WHERE VolStatus IN ('Full', 'Used') "
+ "GROUP BY MediaType";
- QString query =
+ if (mainWin->m_sqlDebug) {
+ Pmsg1(000, "MediaView query cmd : %s\n",query.toUtf8().data());
+ }
+ if (m_console->sql_cmd(query, results)) {
+ foreach (resultline, results) {
+ fieldlist = resultline.split("\t");
+ if (fieldlist.size() != 3) {
+ Pmsg1(000, "Unexpected line %s", resultline.toUtf8().data());
+ continue;
+ }
+ if (fieldlist.at(1).toInt() >= 1) {
+ // MediaType
+ hash_size[fieldlist.at(2)]
+ = fieldlist.at(0).toFloat();
+ }
+ }
+ }
+
+ m_tableMedia->clearContents();
+ query =
"SELECT VolumeName, InChanger, "
- "Slot, VolBytes, VolStatus, Pool.Name, MediaType, "
+ "Slot, MediaType, VolStatus, VolBytes, Pool.Name, "
"LastWritten, Media.VolRetention "
"FROM Media JOIN Pool USING (PoolId) "
- "LEFT JOIN Location USING (LocationId) "
+ "LEFT JOIN Location ON (Media.LocationId=Location.LocationId) "
+ cmd +
" ORDER BY VolumeName LIMIT " + m_sbLimit->cleanText();
-// Pmsg1(000, "MediaView query cmd : %s\n",query.toUtf8().data());
+ m_tableMedia->sortByColumn(0, Qt::AscendingOrder);
m_tableMedia->setSortingEnabled(false); /* Don't sort during insert */
- QStringList results;
+ results.clear();
+ if (mainWin->m_sqlDebug) {
+ Pmsg1(000, "MediaView query cmd : %s\n",query.toUtf8().data());
+ }
if (m_console->sql_cmd(query, results)) {
- QString resultline;
- QStringList fieldlist;
int row=0;
filterExipired(results);
m_tableMedia->setRowCount(results.size());
-
foreach (resultline, results) { // should have only one result
+ int index = 0;
+ QString Slot, VolBytes, MediaType, LastWritten, VolStatus;
fieldlist = resultline.split("\t");
+ if (fieldlist.size() != 9) {
+ Pmsg1(000, "Unexpected line %s", resultline.toUtf8().data());
+ continue;
+ }
QStringListIterator fld(fieldlist);
- int index=0;
TableItemFormatter mediaitem(*m_tableMedia, row);
/* VolumeName */
mediaitem.setTextFld(index++, fld.next());
/* Online */
- mediaitem.setTextFld(index++, fld.next());
- fld.next(); // Slot
+ mediaitem.setInChanger(index++, fld.next());
+
+ Slot = fld.next(); // Slot
+ mediaitem.setNumericFld(index++, Slot);
+
+ MediaType = fld.next();
+ VolStatus = fld.next();
/* Volume bytes */
- mediaitem.setBytesFld(index++, fld.next());
+ VolBytes = fld.next();
+ mediaitem.setBytesFld(index++, VolBytes);
/* Usage */
- mediaitem.setTextFld(index++, "NYI");
-
+ usage = 0;
+ if (hash_size.contains(MediaType) &&
+ hash_size[MediaType] != 0) {
+ usage = VolBytes.toLongLong() * 100 / hash_size[MediaType];
+ }
+ mediaitem.setPercent(index++, usage);
+
/* Volstatus */
- mediaitem.setVolStatusFld(index++, fld.next());
+ mediaitem.setVolStatusFld(index++, VolStatus);
/* Pool */
mediaitem.setTextFld(index++, fld.next());
/* MediaType */
- mediaitem.setTextFld(index++, fld.next());
+ mediaitem.setTextFld(index++, MediaType);
LastWritten = fld.next();
buf[0] = 0;
populateForm();
populateTable();
}
- dockPage();
+ if (!isOnceDocked()) {
+ dockPage();
+ }
}
/*