]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/util/fmtwidgetitem.cpp
Fix reference to uninitialized stack variable
[bacula/bacula] / bacula / src / qt-console / util / fmtwidgetitem.cpp
index 7871e8a9c4b40b0a9b8c18e627380a61abd20ef8..3971fc5eb7861d6b67afb50edc6321d3807f470d 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2010 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
 
    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
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
    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
+   You should have received a copy of the GNU Affero 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.
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -27,7 +27,6 @@
 */
  
 /*
 */
  
 /*
- *   Version $Id$
  *
  *  Helper functions for tree widget formatting
  *
  *
  *  Helper functions for tree widget formatting
  *
@@ -192,6 +191,53 @@ ItemFormatterBase::~ItemFormatterBase()
 {
 }
 
 {
 }
 
+void ItemFormatterBase::setPercent(int index, float value)
+{
+   char buf[100];
+   bsnprintf(buf, sizeof(buf), "%.2f%%", value);
+   QString val = buf;
+   QString pix;
+   if (value < 8) {
+      pix = ":images/0p.png";
+   } else if (value < 24) {
+      pix = ":images/16p.png";
+   } else if (value < 40) {
+      pix = ":images/32p.png";
+   } else if (value < 56) {
+      pix = ":images/48p.png";
+   } else if (value < 72) {
+      pix = ":images/64p.png";
+   } else if (value < 88) {
+      pix = ":images/80p.png";
+   } else {
+      pix = ":images/96p.png";
+   }
+   setPixmap(index, QPixmap(pix), val);
+   //setSortValue(index, (int) value);
+   //setBackground(index, Qt::green);
+}
+
+/* By default, the setPixmap implementation with tooltip don't implement
+ * the tooltip stuff
+ */
+void ItemFormatterBase::setPixmap(int index, const QPixmap &pix, 
+                                  const QString & /* tip */)
+{
+   setPixmap(index, pix);
+}
+
+void ItemFormatterBase::setInChanger(int index, const QString &InChanger)
+{
+   setPixmap(index, QPixmap(":images/inflag"+InChanger+".png"));
+   //setSortValue(index, InChanger.toInt() );
+}
+
+void ItemFormatterBase::setFileType(int index, const QString &type)
+{
+   setPixmap(index, QPixmap(":images/"+type+".png"));
+   //setSortValue(index, InChanger.toInt() );
+}
+
 void ItemFormatterBase::setTextFld(int index, const QString &fld, bool center)
 {
    setText(index, fld.trimmed());
 void ItemFormatterBase::setTextFld(int index, const QString &fld, bool center)
 {
    setText(index, fld.trimmed());
@@ -200,6 +246,16 @@ void ItemFormatterBase::setTextFld(int index, const QString &fld, bool center)
    }
 }
 
    }
 }
 
+void ItemFormatterBase::setDateFld(int index, utime_t fld, bool center)
+{
+   char buf[200];
+   bstrutime(buf, sizeof(buf), fld);
+   setText(index, QString(buf).trimmed());
+   if (center) {
+      setTextAlignment(index, Qt::AlignCenter);
+   }
+}
+
 void ItemFormatterBase::setRightFld(int index, const QString &fld)
 {
    setText(index, fld.trimmed());
 void ItemFormatterBase::setRightFld(int index, const QString &fld)
 {
    setText(index, fld.trimmed());
@@ -248,6 +304,9 @@ void ItemFormatterBase::setBytesFld(int index, const QString &fld)
    case BYTES_CONVERSION_SI:
       msg = convertBytesSI(qfld);
       break;
    case BYTES_CONVERSION_SI:
       msg = convertBytesSI(qfld);
       break;
+   default:
+      msg = " ";
+      break;
    }
 
    setNumericFld(index, msg, qfld);
    }
 
    setNumericFld(index, msg, qfld);
@@ -268,11 +327,11 @@ void ItemFormatterBase::setDurationFld(int index, const QString &fld)
    char suffix = 's';
    if (dfld) {
       for (int pos = 0 ; sufs[pos] ; ++pos) {
    char suffix = 's';
    if (dfld) {
       for (int pos = 0 ; sufs[pos] ; ++pos) {
-         if (dfld % divs[pos] == 0) {
-            dfld /= divs[pos];
-            suffix = sufs[pos];
-            break;
-         }
+          if (dfld % divs[pos] == 0) {
+             dfld /= divs[pos];
+             suffix = sufs[pos];
+             break;
+          }
       }
    }
    QString msg;
       }
    }
    QString msg;
@@ -284,13 +343,13 @@ void ItemFormatterBase::setDurationFld(int index, const QString &fld)
       dfld = fld.trimmed().toLongLong();
       msg = "";
       for (int pos = 0 ; sufs[pos] ; ++pos) {
       dfld = fld.trimmed().toLongLong();
       msg = "";
       for (int pos = 0 ; sufs[pos] ; ++pos) {
-         if (dfld / divs[pos] != 0) {
-            msg += QString(" %1%2").arg(dfld / divs[pos]).arg(sufs[pos]);
-            dfld %= divs[pos];
-         }
+          if (dfld / divs[pos] != 0) {
+             msg += QString(" %1%2").arg(dfld / divs[pos]).arg(sufs[pos]);
+             dfld %= divs[pos];
+          }
       }
       if (dfld)
       }
       if (dfld)
-        msg += QString(" %1s").arg(dfld);
+         msg += QString(" %1s").arg(dfld);
    }
 
    setNumericFld(index, msg, fld.trimmed().toLongLong());
    }
 
    setNumericFld(index, msg, fld.trimmed().toLongLong());
@@ -386,6 +445,11 @@ void TreeItemFormatter::setSortValue(int /* index */, const QVariant & /* value
 {
 }
 
 {
 }
 
+void TreeItemFormatter::setPixmap(int index, const QPixmap &pix)
+{
+   wdg->setIcon(index, QIcon(pix));
+}
+
 /***********************************************
  *
  * Specialized table widget used for sorting
 /***********************************************
  *
  * Specialized table widget used for sorting
@@ -433,6 +497,32 @@ last(NULL)
 {
 }
 
 {
 }
 
+void TableItemFormatter::setPixmap(int index, const QPixmap &pix)
+{
+// Centered, but not sortable !
+   QLabel *lbl = new QLabel();
+   lbl->setAlignment(Qt::AlignCenter);
+   lbl->setPixmap(pix);
+   parent->setCellWidget(row, index, lbl);
+}
+
+void TableItemFormatter::setPixmap(int index, const QPixmap &pix, 
+                                   const QString &tips)
+{
+// Centered, but not sortable !
+   QLabel *lbl = new QLabel();
+   lbl->setAlignment(Qt::AlignCenter);
+   lbl->setPixmap(pix);
+   if (!tips.isEmpty()) {
+      lbl->setToolTip(tips);
+   }
+   parent->setCellWidget(row, index, lbl);
+
+//   last = new BatSortingTableItem;
+//   parent->setItem(row, index, last);
+//   last->setIcon(pix);
+}
+
 void TableItemFormatter::setText(int col, const QString &fld)
 {
    last = new BatSortingTableItem;
 void TableItemFormatter::setText(int col, const QString &fld)
 {
    last = new BatSortingTableItem;
@@ -464,4 +554,3 @@ const QTableWidgetItem *TableItemFormatter::widget(int col) const
 {
    return parent->item(row, col);
 }
 {
    return parent->item(row, col);
 }
-