2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
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
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.
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
23 Bacula® is a registered trademark of John Walker.
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.
32 * Helper functions for tree widget formatting
34 * Riccardo Ghetta, May 2008
38 #include <QTreeWidgetItem>
40 #include <QStringList>
42 #include "fmtwidgetitem.h"
44 ItemFormatter::ItemFormatter(QTreeWidgetItem &parent, int indent_level):
45 wdg(new QTreeWidgetItem(&parent)),
50 void ItemFormatter::setBoolFld(int index, const QString &fld, bool center)
52 if (fld.trimmed().toInt())
53 setTextFld(index, "Yes", center);
55 setTextFld(index, "No", center);
58 void ItemFormatter::setBoolFld(int index, int fld, bool center)
61 setTextFld(index, "Yes", center);
63 setTextFld(index, "No", center);
66 void ItemFormatter::setTextFld(int index, const QString &fld, bool center)
68 wdg->setData(index, Qt::UserRole, level);
70 wdg->setTextAlignment(index, Qt::AlignHCenter);
72 wdg->setText(index, fld.trimmed());
75 void ItemFormatter::setNumericFld(int index, const QString &fld)
77 wdg->setData(index, Qt::UserRole, level);
78 wdg->setTextAlignment(index, Qt::AlignRight);
79 wdg->setText(index, fld.trimmed());
82 void ItemFormatter::setBytesFld(int index, const QString &fld)
84 static const double KB = 1024.0;
85 static const double MB = KB * KB;
86 static const double GB = MB * KB;
87 static const double TB = GB * KB;
89 double dfld = fld.trimmed().toDouble();
92 msg = QString("%1TB").arg(dfld / TB, 0, 'f', 2);
94 msg = QString("%1GB").arg(dfld / GB, 0, 'f', 2);
96 msg = QString("%1MB").arg(dfld / MB, 0, 'f', 2);
98 msg = QString("%1KB").arg(dfld / KB, 0, 'f', 2);
100 msg = QString::number(dfld, 'f', 0);
102 wdg->setData(index, Qt::UserRole, level);
103 wdg->setTextAlignment(index, Qt::AlignRight);
104 wdg->setText(index, msg);
107 void ItemFormatter::setDurationFld(int index, const QString &fld)
109 static const double HOUR = 3600;
110 static const double DAY = HOUR * 24;
111 static const double WEEK = DAY * 7;
112 static const double MONTH = DAY * 30;
113 static const double YEAR = DAY * 365;
115 double dfld = fld.trimmed().toDouble();
117 if (fmod(dfld, YEAR) == 0)
118 msg = QString("%1y").arg(dfld / YEAR, 0, 'f', 0);
119 else if (fmod(dfld, MONTH) == 0)
120 msg = QString("%1m").arg(dfld / MONTH, 0, 'f', 0);
121 else if (fmod(dfld, WEEK) == 0)
122 msg = QString("%1w").arg(dfld / WEEK, 0, 'f', 0);
123 else if (fmod(dfld, DAY) == 0)
124 msg = QString("%1d").arg(dfld / DAY, 0, 'f', 0);
125 else if (fmod(dfld, HOUR) == 0)
126 msg = QString("%1h").arg(dfld / HOUR, 0, 'f', 0);
128 msg = QString("%1s").arg(dfld, 0, 'f', 0);
130 wdg->setData(index, Qt::UserRole, level);
131 wdg->setTextAlignment(index, Qt::AlignRight);
132 wdg->setText(index, msg);
135 void ItemFormatter::setVolStatusFld(int index, const QString &fld, bool center)
137 setTextFld(index, fld, center);
139 if (fld == "Append" ) {
140 wdg->setBackground(index, Qt::green);
141 } else if (fld == "Error") {
142 wdg->setBackground(index, Qt::red);
143 } else if (fld == "Used" || fld == "Full"){
144 wdg->setBackground(index, Qt::yellow);