]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/medialist/mediaview.cpp
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / qt-console / medialist / mediaview.cpp
index 3210ad505b828c054bd0434259ea8bede5fa958c..5650a264a973e48105ef45783edffc631b873015 100644 (file)
@@ -1,29 +1,21 @@
 /*
-   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"
@@ -38,7 +30,7 @@
 #include "run/run.h"
 #include "util/fmtwidgetitem.h"
 
-MediaView::MediaView()
+MediaView::MediaView() : Pages()
 {
    setupUi(this);
    m_name = tr("Media");
@@ -115,20 +107,22 @@ void MediaView::purgePushed()
 
 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());
       }
@@ -287,9 +281,16 @@ void MediaView::populateTable()
       "WHERE VolStatus IN ('Full', 'Used') "
       "GROUP BY MediaType";
 
+   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)] 
@@ -304,26 +305,29 @@ void MediaView::populateTable()
       "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 */
    results.clear();
+   if (mainWin->m_sqlDebug) {
+      Pmsg1(000, "MediaView query cmd : %s\n",query.toUtf8().data());
+   }
    if (m_console->sql_cmd(query, results)) {
       int row=0;
       filterExipired(results);
       m_tableMedia->setRowCount(results.size());
-
       foreach (resultline, results) { // should have only one result
-         QString VolBytes, MediaType, LastWritten, VolStatus;
+         int index = 0;
+         QString Slot, VolBytes, MediaType, LastWritten, VolStatus;
          fieldlist = resultline.split("\t");
-         if (fieldlist.size() != 10) {
+         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 */
@@ -331,7 +335,9 @@ void MediaView::populateTable()
          
          /* Online */
          mediaitem.setInChanger(index++, fld.next());
-         fld.next();            // Slot
+
+         Slot = fld.next();            // Slot
+         mediaitem.setNumericFld(index++, Slot);
 
          MediaType = fld.next();
          VolStatus = fld.next();
@@ -343,8 +349,7 @@ void MediaView::populateTable()
          /* Usage */
          usage = 0;
          if (hash_size.contains(MediaType) &&
-             hash_size[MediaType] != 0) 
-         {
+             hash_size[MediaType] != 0) {
             usage = VolBytes.toLongLong() * 100 / hash_size[MediaType];
          }
          mediaitem.setPercent(index++, usage);
@@ -396,7 +401,9 @@ void MediaView::PgSeltreeWidgetClicked()
       populateForm();
       populateTable();
    }
-   dockPage();
+   if (!isOnceDocked()) {
+      dockPage();
+   }
 }
 
 /*