Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Bacula® is a registered trademark of John Walker.
+ 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.
*
*/
+#include "bat.h"
#include <QTreeWidgetItem>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <math.h>
#include "fmtwidgetitem.h"
+/***********************************************
+ *
+ * common helpers
+ *
+ ***********************************************/
+
+QString convertJobStatus(const QString &sts)
+{
+ QString code( sts.trimmed() );
+ if ( code.size() != 1) {
+ return QObject::tr("Invalid job status %1").arg(sts);
+ }
+
+ char buf[256];
+ jobstatus_to_ascii_gui( code[0].toAscii(), buf, sizeof(buf));
+ return QString(buf);
+}
+
+/*
+ * disable widget updating
+ */
+Freeze::Freeze(QWidget &q):
+qw(&q)
+{
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+ qw->setUpdatesEnabled(false);
+}
+
+Freeze::~Freeze()
+{
+ if (qw) {
+ qw->setUpdatesEnabled(true);
+ QApplication::restoreOverrideCursor();
+ qw->update();
+ }
+}
+
/***********************************************
*
* ItemFormatterBase static members
{
}
+void ItemFormatterBase::setTextFld(int index, const QString &fld, bool center)
+{
+ setText(index, fld.trimmed());
+ if (center) {
+ setTextAlignment(index, Qt::AlignCenter);
+ }
+}
+
+void ItemFormatterBase::setRightFld(int index, const QString &fld)
+{
+ setText(index, fld.trimmed());
+ setTextAlignment(index, Qt::AlignRight | Qt::AlignVCenter);
+}
+
void ItemFormatterBase::setBoolFld(int index, const QString &fld, bool center)
{
if (fld.trimmed().toInt())
- setTextFld(index, "Yes", center);
+ setTextFld(index, QObject::tr("Yes"), center);
else
- setTextFld(index, "No", center);
+ setTextFld(index, QObject::tr("No"), center);
}
void ItemFormatterBase::setBoolFld(int index, int fld, bool center)
{
if (fld)
- setTextFld(index, "Yes", center);
+ setTextFld(index, QObject::tr("Yes"), center);
else
- setTextFld(index, "No", center);
+ setTextFld(index, QObject::tr("No"), center);
}
void ItemFormatterBase::setNumericFld(int index, const QString &fld)
{
- setTextFld(index, fld);
- setTextAlignment(index, Qt::AlignRight | Qt::AlignVCenter);
+ setRightFld(index, fld.trimmed());
+ setSortValue(index, fld.toDouble() );
+}
+
+void ItemFormatterBase::setNumericFld(int index, const QString &fld, const QVariant &sortval)
+{
+ setRightFld(index, fld.trimmed());
+ setSortValue(index, sortval );
}
void ItemFormatterBase::setBytesFld(int index, const QString &fld)
msg = convertBytesSI(qfld);
break;
}
- setNumericFld(index, msg);
+
+ setNumericFld(index, msg, qfld);
}
void ItemFormatterBase::setDurationFld(int index, const QString &fld)
}
if (dfld)
msg += QString(" %1s").arg(dfld);
-
-/*
- double net = 0;
- QList<qlonglong> durations;
- durations.append(1);
- durations.append(60);
- durations.append(HOUR);
- durations.append(DAY);
- durations.append(MONTH);
- durations.append(YEAR);
- QStringList abbrlist = (QStringList() << "s" << "min" << "h" << "d" << "m" << "y");
- bool done = false;
- int count = 1;
- while (done == false) {
- if ((dfld < durations[count]) || (count >= abbrlist.count() - 1)) {
- done = true;
- net = (double)dfld / (double)(durations[count - 1]);
- if (net != 0) {
- msg = QString("%1%2")
- .arg(net, 0, 'f', 2, QLatin1Char(' '))
- .arg(abbrlist[count - 1]);
- } else {
- msg = "0s";
- }
- }
- count += 1;
- }
-*/ }
-
- setNumericFld(index, msg);
+ }
+
+ setNumericFld(index, msg, fld.trimmed().toLongLong());
}
void ItemFormatterBase::setVolStatusFld(int index, const QString &fld, bool center)
{
- setTextFld(index, fld, center);
+ QString mp(fld.trimmed());
+ setTextFld(index, volume_status_to_str(mp.toUtf8()), center);
- if (fld == "Append" ) {
+ if (mp == "Append" ) {
setBackground(index, Qt::green);
- } else if (fld == "Error") {
+ } else if (mp == "Error") {
setBackground(index, Qt::red);
- } else if (fld == "Used" || fld == "Full"){
+ } else if (mp == "Used" || mp == "Full"){
setBackground(index, Qt::yellow);
+ } else if (mp == "Read-only" || mp == "Disabled"){
+ setBackground(index, Qt::lightGray);
}
}
-void ItemFormatterBase::setJobStatusFld(int index, const QString &shortstatus,
- const QString &longstatus, bool center)
+void ItemFormatterBase::setJobStatusFld(int index, const QString &status, bool center)
{
/* C (created, not yet running) uses the default background */
static QString greenchars("TR");
static QString redchars("BEf");
static QString yellowchars("eDAFSMmsjdctp");
- setTextFld(index, longstatus, center);
+ setTextFld(index, convertJobStatus(status), center);
- QString st(shortstatus.trimmed());
+ QString st(status.trimmed());
if (greenchars.contains(st, Qt::CaseSensitive)) {
setBackground(index, Qt::green);
} else if (redchars.contains(st, Qt::CaseSensitive)) {
void ItemFormatterBase::setJobTypeFld(int index, const QString &fld, bool center)
{
- static QHash<QString, QString> jobt;
- if (jobt.isEmpty()) {
- jobt.insert("B", QObject::tr("Backup"));
- jobt.insert("R", QObject::tr("Restore"));
- jobt.insert("V", QObject::tr("Verify"));
- jobt.insert("A", QObject::tr("Admin"));
+ QByteArray jtype(fld.trimmed().toAscii());
+ if (jtype.size()) {
+ setTextFld(index, job_type_to_str(jtype[0]), center);
+ } else {
+ setTextFld(index, "", center);
}
-
- setTextFld(index, jobt.value(fld.trimmed(), fld.trimmed()), center);
}
void ItemFormatterBase::setJobLevelFld(int index, const QString &fld, bool center)
{
- static QHash<QString, QString> jobt;
- if (jobt.isEmpty()) {
- jobt.insert("F", QObject::tr("Full"));
- jobt.insert("D", QObject::tr("Differential"));
- jobt.insert("I", QObject::tr("Incremental"));
- jobt.insert("C", QObject::tr("Catalog"));
- jobt.insert("O", QObject::tr("VolToCatalog"));
+ QByteArray lvl(fld.trimmed().toAscii());
+ if (lvl.size()) {
+ setTextFld(index, job_level_to_str(lvl[0]), center);
+ } else {
+ setTextFld(index, "", center);
}
-
- setTextFld(index, jobt.value(fld.trimmed(), fld.trimmed()), center);
}
{
}
-void TreeItemFormatter::setTextFld(int index, const QString &fld, bool center)
+void TreeItemFormatter::setText(int index, const QString &fld)
{
wdg->setData(index, Qt::UserRole, level);
- if (center) {
- setTextAlignment(index, Qt::AlignCenter);
- }
- wdg->setText(index, fld.trimmed());
+ wdg->setText(index, fld);
}
void TreeItemFormatter::setTextAlignment(int index, int align)
wdg->setBackground(index, qb);
}
+/* at this time we don't sort trees, so this method does nothing */
+void TreeItemFormatter::setSortValue(int /* index */, const QVariant & /* value */)
+{
+}
+
+/***********************************************
+ *
+ * Specialized table widget used for sorting
+ *
+ ***********************************************/
+TableItemFormatter::BatSortingTableItem::BatSortingTableItem():
+QTableWidgetItem(1)
+{
+}
+
+void TableItemFormatter::BatSortingTableItem::setSortData(const QVariant &d)
+{
+ setData(SORTDATA_ROLE, d);
+}
+
+bool TableItemFormatter::BatSortingTableItem::operator< ( const QTableWidgetItem & o ) const
+{
+ QVariant my = data(SORTDATA_ROLE);
+ QVariant other = o.data(SORTDATA_ROLE);
+ if (!my.isValid() || !other.isValid() || my.type() != other.type())
+ return QTableWidgetItem::operator< (o); /* invalid combination, revert to default sorting */
+
+ /* 64bit integers must be handled separately, others can be converted to double */
+ if (QVariant::ULongLong == my.type()) {
+ return my.toULongLong() < other.toULongLong();
+ } else if (QVariant::LongLong == my.type()) {
+ return my.toLongLong() < other.toLongLong();
+ } else if (my.canConvert(QVariant::Double)) {
+ return my.toDouble() < other.toDouble();
+ } else {
+ return QTableWidgetItem::operator< (o); /* invalid combination, revert to default sorting */
+ }
+}
/***********************************************
*
{
}
-void TableItemFormatter::setTextFld(int col, const QString &fld, bool center)
+void TableItemFormatter::setText(int col, const QString &fld)
{
- last = new QTableWidgetItem(1);
-/* last->setForeground(blackBrush); */
+ last = new BatSortingTableItem;
parent->setItem(row, col, last);
- if (center) {
- setTextAlignment(col, Qt::AlignCenter);
- }
- last->setText(fld.trimmed());
+ last->setText(fld);
}
void TableItemFormatter::setTextAlignment(int /*index*/, int align)
last->setBackground(qb);
}
+void TableItemFormatter::setSortValue(int /* index */, const QVariant &value )
+{
+ last->setSortData(value);
+}
+
QTableWidgetItem *TableItemFormatter::widget(int col)
{
- return parent->item(row, col);
+ return parent->item(row, col);
}
const QTableWidgetItem *TableItemFormatter::widget(int col) const
{
- return parent->item(row, col);
+ return parent->item(row, col);
}
+