]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/util/fmtwidgetitem.h
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / qt-console / util / fmtwidgetitem.h
index 2f6c35a73684e80c6a9ae354c6989c963a888ab0..859977ddf1e89f488b4c64970fa7cfc7fd9b5554 100644 (file)
@@ -1,61 +1,97 @@
 #ifndef _FMTWIDGETITEM_H_
 #define _FMTWIDGETITEM_H_
 /*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2007-2007 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 John Walker.
-   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-2016 Kern Sibbald
+
+   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.
 */
 /*
- *   Version $Id$
- *
  *   TreeView formatting helpers - Riccardo Ghetta, May 2008 
  */
 
+class QWidget;
 class QTreeWidgetItem;
+class QTableWidget;
+class QTableWidgetItem;
 class QString;
+class QBrush;
+
 
 /*
- * This class can be used instead of QTreeWidgetItem (it allocates one internally,
- * to format data fields.
- * All setXXXFld routines receive a column index and the unformatted string value.
+ * common conversion routines
+ *
+ */
+QString convertJobStatus(const QString &sts);
+
+/* bytes formatted as power-of-two with IEC suffixes (KiB, MiB, and so on) */
+QString convertBytesIEC(qint64 fld);
+
+/* bytes formatted as power-of-ten with SI suffixes (kB, MB, and so on) */
+QString convertBytesSI(qint64 fld);
+
+/*
+ * disable widget updating
+ */
+class Freeze
+{
+private:
+   QWidget *qw;
+
+ public:
+   Freeze(QWidget &q);
+   ~Freeze();
+};
+
+
+
+/*
+ * base class for formatters
+ *
  */
-class ItemFormatter
+class ItemFormatterBase
 {
 public:
+   enum BYTES_CONVERSION {
+      BYTES_CONVERSION_NONE,
+      BYTES_CONVERSION_IEC,
+      BYTES_CONVERSION_SI,
+   };
 
-   ItemFormatter(QTreeWidgetItem &parent, int indent_level);
+public:
+   virtual ~ItemFormatterBase(); 
 
    /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
    void setBoolFld(int index, const QString &fld, bool center = true);
    void setBoolFld(int index, int fld, bool center = true);
 
+   /* Print nice icon to represent percent */
+   void setPercent(int index, float number);
+
    /* Normal text field. Centers field if center true*/
    void setTextFld(int index, const QString &fld, bool center = false);
 
-   /* Right-aligned text field.*/
+   /* Normal date field. Centers field if center true*/
+   void setDateFld(int index, utime_t fld, bool center = false);
+
+   /* Right-aligned text field. */
+   void setRightFld(int index, const QString &fld);
+
+   /* Numeric field - sorted as numeric type */
    void setNumericFld(int index, const QString &fld);
+   void setNumericFld(int index, const QString &fld, const QVariant &sortVal);
 
    /* fld value interpreted as bytes and formatted with size suffixes */
    void setBytesFld(int index, const QString &fld);
@@ -65,91 +101,117 @@ public:
 
    /* fld value interpreted as volume status. Colored accordingly */
    void setVolStatusFld(int index, const QString &fld, bool center = true);
-
-   /* access internal widget */
-   QTreeWidgetItem *widget() { return wdg; }
-   const QTreeWidgetItem *widget() const { return wdg; }
+  
+   /* fld value interpreted as job status. Colored accordingly */
+   void setJobStatusFld(int index, const QString &status, bool center = true);
+  
+   /* fld value interpreted as job type. */
+   void setJobTypeFld(int index, const QString &fld, bool center = false);
+  
+   /* fld value interpreted as job level. */
+   void setJobLevelFld(int index, const QString &fld, bool center = false);
+
+   /* fld value interpreted as Online/Offline */
+   void setInChanger(int index, const QString &InChanger);
+  
+   /* fld value interpreted as file or folder */
+   void setFileType(int index, const QString &type);
+
+   static void setBytesConversion(BYTES_CONVERSION b) {
+      cnvFlag = b;
+   }
+   static BYTES_CONVERSION getBytesConversion() {
+      return cnvFlag;
+   }
+
+protected:
+   /* only derived classes can create one of these */
+   ItemFormatterBase();
+
+   virtual void setText(int index, const QString &fld) = 0;
+   virtual void setTextAlignment(int index, int align) = 0;
+   virtual void setBackground(int index, const QBrush &) = 0;
+   virtual void setPixmap(int index, const QPixmap &pix) = 0;
+   virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
+
+   /* sets the *optional* value used for sorting */
+   virtual void setSortValue(int index, const QVariant &value) = 0;
 
 private:
-   QTreeWidgetItem *wdg;
-   int level;
+   static BYTES_CONVERSION cnvFlag;
 };
 
-#endif /* _FMTWIDGETITEM_H_ */
-#ifndef _FMTWIDGETITEM_H_
-#define _FMTWIDGETITEM_H_
-/*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2007-2007 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 John Walker.
-   The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
-   Switzerland, email:ftf@fsfeurope.org.
-*/
-/*
- *   Version $Id$
- *
- *   TreeView formatting helpers - Riccardo Ghetta, May 2008 
- */
-
-class QTreeWidgetItem;
-class QString;
-
 /*
  * This class can be used instead of QTreeWidgetItem (it allocates one internally,
  * to format data fields.
  * All setXXXFld routines receive a column index and the unformatted string value.
  */
-class ItemFormatter
+class TreeItemFormatter : public ItemFormatterBase
 {
 public:
 
-   ItemFormatter(QTreeWidgetItem &parent, int indent_level);
+   TreeItemFormatter(QTreeWidgetItem &parent, int indent_level);
 
-   /* Prints Yes if fld is != 0, No otherwise. Centers field if center true*/
-   void setBoolFld(int index, const QString &fld, bool center = true);
+   /* access internal widget */
+   QTreeWidgetItem *widget() { return wdg; }
+   const QTreeWidgetItem *widget() const { return wdg; }
 
-   /* Normal text field. Centers field if center true*/
-   void setTextFld(int index, const QString &fld, bool center = false);
+protected:
+   virtual void setText(int index, const QString &fld);
+   virtual void setTextAlignment(int index, int align);
+   virtual void setBackground(int index, const QBrush &);
+   virtual void setSortValue(int index, const QVariant &value);
+   virtual void setPixmap(int index, const QPixmap &pix);
 
-   /* Right-aligned text field.*/
-   void setNumericFld(int index, const QString &fld);
+private:
+   QTreeWidgetItem *wdg;
+   int level;
+};
 
-   /* fld value interpreted as bytes and formatted with size suffixes */
-   void setBytesFld(int index, const QString &fld);
+/*
+ * This class can be used instead of QTableWidgetItem (it allocates one internally,
+ * to format data fields.
+ * All setXXXFld routines receive the column and the unformatted string value.
+ */
+class TableItemFormatter : public ItemFormatterBase
+{
+private:
 
-   /* fld value interpreted as seconds and formatted with y,m,w,h suffixes */
-   void setDurationFld(int index, const QString &fld);
+   /* specialized widget item - allows an optional data property for sorting */ 
+   class BatSortingTableItem : public QTableWidgetItem
+   {
+   private:
+      static const int SORTDATA_ROLE = Qt::UserRole + 100;
+   public:
+      BatSortingTableItem();
+      
+      /* uses the sort data if available, reverts to default behavior othervise */
+      virtual bool operator< ( const QTableWidgetItem & o ) const;
+
+      /* set the value used for sorting - MUST BE A NUMERIC TYPE */
+      void setSortData(const QVariant &d);
+   };
 
-   /* fld value interpreted as volume status. Colored accordingly */
-   void setVolStatusFld(int index, const QString &fld, bool center = true);
+public:
 
-   /* access internal widget */
-   QTreeWidgetItem *widget() { return wdg; }
-   const QTreeWidgetItem *widget() const { return wdg; }
+   TableItemFormatter(QTableWidget &parent, int row);
+
+   /* access internal widget at column col*/
+   QTableWidgetItem *widget(int col);
+   const QTableWidgetItem *widget(int col) const;
+
+protected:
+   virtual void setText(int index, const QString &fld);
+   virtual void setTextAlignment(int index, int align);
+   virtual void setBackground(int index, const QBrush &);
+   virtual void setSortValue(int index, const QVariant &value);
+   virtual void setPixmap(int index, const QPixmap &pix);
+   virtual void setPixmap(int index, const QPixmap &pix, const QString &tip);
 
 private:
-   QTreeWidgetItem *wdg;
-   int level;
+   QTableWidget *parent;
+   int row;
+   BatSortingTableItem  *last;
 };
 
 #endif /* _FMTWIDGETITEM_H_ */