From 26d43d52bd11714ac9ed421329471a8334b7f18e Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Sun, 3 Feb 2008 20:57:29 +0000 Subject: [PATCH] Modifications to get human readable information into fields in the medialist and joblist interfaces. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6364 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/joblist/joblist.cpp | 28 ++++++ bacula/src/qt-console/mainwin.cpp | 85 +++++++++++++++++++ bacula/src/qt-console/mainwin.h | 3 + bacula/src/qt-console/medialist/medialist.cpp | 27 ++++++ bacula/src/qt-console/prefs.ui | 58 ++++++++++++- 5 files changed, 198 insertions(+), 3 deletions(-) diff --git a/bacula/src/qt-console/joblist/joblist.cpp b/bacula/src/qt-console/joblist/joblist.cpp index 2157970ba6..0bb7930d7b 100644 --- a/bacula/src/qt-console/joblist/joblist.cpp +++ b/bacula/src/qt-console/joblist/joblist.cpp @@ -238,6 +238,7 @@ void JobList::populateTable() m_startIndex = headerlist.indexOf("Job Starttime"); m_filesIndex = headerlist.indexOf("Job Files"); m_bytesIndex = headerlist.indexOf("Job Bytes"); + int jobLevelIndex = headerlist.indexOf("Job Level"); /* Initialize the QTableWidget */ m_checkCurrentWidget = false; @@ -277,6 +278,33 @@ void JobList::populateTable() mp_tableWidget->setItem(row, column, p_tableitem); if (column == m_statusIndex) setStatusColor(p_tableitem, statusCode); + if (column == m_bytesIndex) { + QString text; + bool okay; + qlonglong bytes = field.toULongLong(&okay); + if (okay){ + QString test = QString("%1").arg(bytes); + mainWin->hrConvert(text, bytes); + p_tableitem->setText(text); + } else { Pmsg1(000, "conversion error %s\n", field.toUtf8().data()); } + } else if (column == m_purgedIndex) { + bool okay; + int isPurged = field.toInt(&okay); + if (okay){ + if (isPurged) { p_tableitem->setText("IS"); + } else { p_tableitem->setText("NOT"); } + } + } else if (column == m_typeIndex) { + if (field == "B") { p_tableitem->setText("Backup"); } + else if (field == "R") { p_tableitem->setText("Restore"); } + } else if (column == jobLevelIndex) { + if (field == "F") { p_tableitem->setText("Full"); } + else if (field == "D") { p_tableitem->setText("Diff"); } + else if (field == "I") { p_tableitem->setText("Incr"); } + } + if ((column == m_bytesIndex) || (column == m_filesIndex)){ + p_tableitem->setTextAlignment(Qt::AlignRight); + } column++; } } diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index e3c43ed662..7add181b43 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -632,6 +632,14 @@ void MainWin::setPreferences() prefs.rtRestore1CheckBox->setCheckState(m_rtRestore1Debug ? Qt::Checked : Qt::Unchecked); prefs.rtRestore2CheckBox->setCheckState(m_rtRestore2Debug ? Qt::Checked : Qt::Unchecked); prefs.rtRestore3CheckBox->setCheckState(m_rtRestore3Debug ? Qt::Checked : Qt::Unchecked); + if (m_radioConvert == 0) { + prefs.radioConvertOff->setChecked(Qt::Checked); + } else if (m_radioConvert == 1){ + prefs.radioConvertIEC->setChecked(Qt::Checked); + } else { + m_radioConvert = 2; + prefs.radioConvertStandard->setChecked(Qt::Checked); + } prefs.exec(); } @@ -669,6 +677,13 @@ void prefsDialog::accept() mainWin->m_rtRestore1Debug = this->rtRestore1CheckBox->checkState() == Qt::Checked; mainWin->m_rtRestore2Debug = this->rtRestore2CheckBox->checkState() == Qt::Checked; mainWin->m_rtRestore3Debug = this->rtRestore3CheckBox->checkState() == Qt::Checked; + if (this->radioConvertOff->isChecked()) { + mainWin->m_radioConvert = 0; + } else if (this->radioConvertIEC->isChecked()){ + mainWin->m_radioConvert = 1; + } else { + mainWin->m_radioConvert = 2; + } QSettings settings("www.bacula.org", "bat"); settings.beginGroup("Debug"); @@ -690,6 +705,7 @@ void prefsDialog::accept() settings.endGroup(); settings.beginGroup("Misc"); settings.setValue("longList", mainWin->m_longList); + settings.setValue("byteConvert", mainWin->m_radioConvert); settings.endGroup(); settings.beginGroup("RestoreTree"); settings.setValue("rtPopDirDebug", mainWin->m_rtPopDirDebug); @@ -739,6 +755,7 @@ void MainWin::readPreferences() settings.endGroup(); settings.beginGroup("Misc"); m_longList = settings.value("longList", false).toBool(); + m_radioConvert = settings.value("byteConvert", false).toInt(); settings.endGroup(); settings.beginGroup("RestoreTree"); m_rtPopDirDebug = settings.value("rtPopDirDebug", false).toBool(); @@ -755,3 +772,71 @@ void MainWin::readPreferences() m_rtRestore3Debug = settings.value("rtRestore3Debug", false).toBool(); settings.endGroup(); } + +void MainWin::hrConvert(QString &ret, qlonglong &inval) +{ + double net = 0; + qlonglong base; + QStringList suflist; + + if (m_radioConvert == 0) { + ret = QString("%1").arg(inval); + return; + } else if (m_radioConvert == 1){ + base = 1000; + suflist = (QStringList() << "B" << "KiB" << "MiB" << "GiB" << "TiB" << "PiB" << "EiB" << "ZiB"); + } else { + base = 1024; + suflist = (QStringList() << "B" << "KB" << "MB" << "GB" << "TB" << "PB" << "EB" << "ZB"); + } + qlonglong running = base; + bool done = false; + int count = 1; + while (done == false) { + QString test1 = QString("%1").arg(inval); + QString test2 = QString("%1").arg(running); + if (float(inval) < (float)(running)) { + done = true; + ret = suflist[count - 1]; + net = (float)inval / (float)(running/base); + } + count += 1; + if (count > suflist.count()) done = true; + running *= base; + } + char format = 'f'; + if (net != 0) + ret = QString("%1 %2") + .arg(net, 0, format, 2, QLatin1Char(' ')) + .arg(ret); + else ret = "0 B"; +} + +void MainWin::hrConvertSeconds(QString &ret, qlonglong &inval) +{ + double net = 0; + QList durations; + durations.append(1); + durations.append(60); + durations.append(3600); + durations.append(86400); + durations.append(2592000); + durations.append(31536000); + QStringList abbrlist = (QStringList() << "Sec" << "Min" << "Hrs" << "Days" << "Mnth" << "Yrs"); + bool done = false; + int count = 1; + while (done == false) { + QString test1 = QString("%1").arg(inval); + QString test2 = QString("%1").arg(durations[count]); + if ((inval < durations[count]) || (count >= abbrlist.count() - 1)) { + done = true; + net = (float)inval / (float)(durations[count - 1]); + if (net != 0) + ret = QString("%1 %2") + .arg(net, 0, 'f', 2, QLatin1Char(' ')) + .arg(abbrlist[count - 1]); + else ret = "0 S"; + } + count += 1; + } +} diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 1db143c3a1..84fc76b5f4 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -58,6 +58,8 @@ public: void hashInsert(QTreeWidgetItem *, Pages *); void hashRemove(Pages *); void hashRemove(QTreeWidgetItem *, Pages *); + void hrConvert(QString &, qlonglong &); + void hrConvertSeconds(QString &, qlonglong &); Console *currentConsole(); QTreeWidgetItem *currentTopItem(); Pages* getFromHash(QTreeWidgetItem *); @@ -96,6 +98,7 @@ public: bool m_rtRestore1Debug; bool m_rtRestore2Debug; bool m_rtRestore3Debug; + int m_radioConvert; public slots: void input_line(); diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index a9e792460c..8a871dcf55 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -85,6 +85,11 @@ void MediaList::populateTree() << "Max Jobs" << "Max Files" << "Max Bytes" << "Recycle" << "Enabled" << "RecyclePool" << "Last Written"); int statusIndex = headerlist.indexOf("Status"); + QStringList flaglist = (QStringList() + << "L" << "R" << "L" << "R" << "BR" << "R" + << "R" << "RS" << "L" << "R" << "RS" + << "R" << "R" << "BR" << "R" << "R" + << "L" << "L"); m_checkcurwidget = false; if (m_populated) @@ -153,7 +158,29 @@ void MediaList::populateTree() mediatreeitem->setText(index, field); if (index == statusIndex) { setStatusColor(mediatreeitem, field, index); + } + if (flaglist[index].contains("B")) { + QString text; + bool okay; + qlonglong bytes = field.toULongLong(&okay); + if (okay){ + QString test = QString("%1").arg(bytes); + mainWin->hrConvert(text, bytes); + mediatreeitem->setText(index, text); + } else { Pmsg1(000, "conversion error %s\n", field.toUtf8().data()); } } + if (flaglist[index].contains("S")) { + QString text; + bool okay; + qlonglong seconds = field.toULongLong(&okay); + if (okay){ + QString test = QString("%1").arg(seconds); + mainWin->hrConvertSeconds(text, seconds); + mediatreeitem->setText(index, text); + } else { Pmsg1(000, "conversion error %s\n", field.toUtf8().data()); } + } + if (flaglist[index].contains("R")) + mediatreeitem->setTextAlignment(index, Qt::AlignRight); } index++; } /* foreach field */ diff --git a/bacula/src/qt-console/prefs.ui b/bacula/src/qt-console/prefs.ui index 9454dd7f7c..cc4d8fb361 100644 --- a/bacula/src/qt-console/prefs.ui +++ b/bacula/src/qt-console/prefs.ui @@ -33,7 +33,7 @@ - 0 + 2 @@ -185,8 +185,8 @@ - 70 - 120 + 40 + 40 190 55 @@ -210,6 +210,58 @@ + + + + 40 + 160 + 261 + 131 + + + + Convert + + + + + 20 + 20 + 231 + 22 + + + + Convert Off + + + + + + 20 + 60 + 231 + 22 + + + + Convert Bytes with IEC 1000B = KB + + + + + + 20 + 100 + 231 + 22 + + + + Convert Bytes with 1024B = KB + + + -- 2.39.5