From c876d3bbefe0dc00c27ca0c12d29da5874946962 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Wed, 15 Dec 2021 21:04:28 +0100 Subject: rbutil: Merge rbutil with utils folder. rbutil uses several components from the utils folder, and can be considered part of utils too. Having it in a separate folder is an arbitrary split that doesn't help anymore these days, so merge them. This also allows other utils to easily use libtools.make without the need to navigate to a different folder. Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21 --- utils/rbutilqt/gui/infowidget.cpp | 112 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 utils/rbutilqt/gui/infowidget.cpp (limited to 'utils/rbutilqt/gui/infowidget.cpp') diff --git a/utils/rbutilqt/gui/infowidget.cpp b/utils/rbutilqt/gui/infowidget.cpp new file mode 100644 index 0000000000..25b0503090 --- /dev/null +++ b/utils/rbutilqt/gui/infowidget.cpp @@ -0,0 +1,112 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2012 by Dominik Riebeling + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include +#include "infowidget.h" +#include "rbsettings.h" +#include "Logger.h" + +InfoWidget::InfoWidget(QWidget *parent) : QWidget(parent) +{ + ui.setupUi(this); + + ui.treeInfo->setAlternatingRowColors(true); + ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version")); + ui.treeInfo->expandAll(); + ui.treeInfo->setColumnCount(2); + ui.treeInfo->setLayoutDirection(Qt::LeftToRight); +} + + +void InfoWidget::updateInfo(void) +{ + LOG_INFO() << "updating server info"; + + QString mp = RbSettings::value(RbSettings::Mountpoint).toString(); + QSettings log(mp + "/.rockbox/rbutil.log", QSettings::IniFormat, this); + QStringList groups = log.childGroups(); + QList items; + QTreeWidgetItem *w, *w2; + QString min, max; + int olditems = 0; + + // remove old list entries (if any) + int l = ui.treeInfo->topLevelItemCount(); + while(l--) { + QTreeWidgetItem *m; + m = ui.treeInfo->takeTopLevelItem(l); + // delete childs (single level deep, no recursion here) + int n = m->childCount(); + while(n--) + delete m->child(n); + } + // get and populate new items + for(int a = 0; a < groups.size(); a++) { + log.beginGroup(groups.at(a)); + QStringList keys = log.allKeys(); + w = new QTreeWidgetItem; + w->setFlags(Qt::ItemIsEnabled); + w->setText(0, groups.at(a)); + items.append(w); + // get minimum and maximum version information so we can hilight old files + min = max = log.value(keys.at(0)).toString(); + for(int b = 0; b < keys.size(); b++) { + if(log.value(keys.at(b)).toString() > max) + max = log.value(keys.at(b)).toString(); + if(log.value(keys.at(b)).toString() < min) + min = log.value(keys.at(b)).toString(); + } + + for(int b = 0; b < keys.size(); b++) { + QString file; + file = mp + "/" + keys.at(b); + if(QFileInfo(file).isDir()) + continue; + w2 = new QTreeWidgetItem(w, QStringList() << "/" + + keys.at(b) << log.value(keys.at(b)).toString()); + if(log.value(keys.at(b)).toString() != max) { + w2->setForeground(0, QBrush(QColor(255, 0, 0))); + w2->setForeground(1, QBrush(QColor(255, 0, 0))); + olditems++; + } + items.append(w2); + } + log.endGroup(); + if(min != max) + w->setData(1, Qt::DisplayRole, QString("%1 / %2").arg(min, max)); + else + w->setData(1, Qt::DisplayRole, max); + } + ui.treeInfo->insertTopLevelItems(0, items); + ui.treeInfo->expandAll(); + ui.treeInfo->resizeColumnToContents(0); + ui.treeInfo->collapseAll(); +} + + +void InfoWidget::changeEvent(QEvent *e) +{ + if(e->type() == QEvent::LanguageChange) { + ui.retranslateUi(this); + ui.treeInfo->setHeaderLabels(QStringList() << tr("File") << tr("Version")); + } else { + QWidget::changeEvent(e); + } +} + -- cgit v1.2.3