diff --git a/DiskUsageApplet.cxx b/DiskUsageApplet.cxx index 238d1ee..fce0862 100644 --- a/DiskUsageApplet.cxx +++ b/DiskUsageApplet.cxx @@ -1,154 +1,184 @@ // SPDX-License-Identifier: GPL-3.0-or-later /* - Copyright 2017 Martin Koller, kollix@aon.at + Copyright 2017 - 2020 Martin Koller, kollix@aon.at This file is part of liquidshell. liquidshell is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. liquidshell 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 liquidshell. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include //-------------------------------------------------------------------------------- DiskUsageApplet::DiskUsageApplet(QWidget *parent, const QString &theId) : DesktopApplet(parent, theId) { setAutoFillBackground(true); connect(&timer, &QTimer::timeout, this, &DiskUsageApplet::fill); timer.setInterval(10000); timer.start(); new QGridLayout(this); fill(); } //-------------------------------------------------------------------------------- void DiskUsageApplet::fill() { QGridLayout *grid = static_cast(layout()); for (SizeInfo &info : partitionMap) info.used = false; QList partitions = Solid::Device::listFromType(Solid::DeviceInterface::StorageVolume); int row = grid->rowCount(); for (const Solid::Device &partition : partitions) { const Solid::StorageVolume *volume = partition.as(); if ( !volume || volume->isIgnored() || (volume->usage() != Solid::StorageVolume::FileSystem) ) continue; const Solid::StorageAccess *storage = partition.as(); if ( !storage || !storage->isAccessible() ) continue; QProgressBar *progress; QLabel *sizeLabel; KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(storage->filePath()); if ( !partitionMap.contains(info.mountPoint()) ) { progress = new QProgressBar(this); QLabel *label = new QLabel(info.mountPoint(), this); grid->addWidget(label, row, 0); grid->addWidget(progress, row, 1); grid->addWidget(sizeLabel = new QLabel(this), row, 2); row++; SizeInfo sizeInfo; sizeInfo.label = label; sizeInfo.progress = progress; sizeInfo.sizeLabel = sizeLabel; sizeInfo.used = true; partitionMap.insert(storage->filePath(), sizeInfo); // workaround Qt bug label->setPalette(palette()); sizeLabel->setPalette(palette()); } else { partitionMap[info.mountPoint()].used = true; SizeInfo sizeInfo = partitionMap[info.mountPoint()]; progress = sizeInfo.progress; sizeLabel = sizeInfo.sizeLabel; } progress->setValue(std::round(double(info.used()) / double(info.size()) * 100.0)); sizeLabel->setText(i18n("%1 free / %2", KIO::convertSize(info.available()), KIO::convertSize(info.size()))); } // remove entries which are no longer used QMutableMapIterator iter(partitionMap); while ( iter.hasNext() ) { iter.next(); if ( !iter.value().used ) { delete iter.value().label; delete iter.value().progress; delete iter.value().sizeLabel; iter.remove(); } } } //-------------------------------------------------------------------------------- void DiskUsageApplet::configure() { if ( dialog ) { dialog->raise(); dialog->activateWindow(); return; } dialog = new DiskUsageAppletConfigureDialog(this); dialog->setWindowTitle(i18n("Configure DiskUsage Applet")); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); connect(dialog.data(), &QDialog::accepted, this, &DiskUsageApplet::saveConfig); } //-------------------------------------------------------------------------------- + +void DiskUsageApplet::loadConfig() +{ + DesktopApplet::loadConfig(); + + KConfig config; + KConfigGroup group = config.group(id); + + QColor barTextCol = group.readEntry("barTextCol", palette().color(QPalette::HighlightedText)); + QColor barBackCol = group.readEntry("barBackCol", palette().color(QPalette::Highlight)); + + QPalette pal = palette(); + pal.setColor(QPalette::HighlightedText, barTextCol); + pal.setColor(QPalette::Highlight, barBackCol); + setPalette(pal); +} + +//-------------------------------------------------------------------------------- + +void DiskUsageApplet::saveConfig() +{ + DesktopApplet::saveConfig(); + + KConfig config; + KConfigGroup group = config.group(id); + group.writeEntry("barTextCol", palette().color(QPalette::HighlightedText)); + group.writeEntry("barBackCol", palette().color(QPalette::Highlight)); +} + +//-------------------------------------------------------------------------------- diff --git a/DiskUsageApplet.hxx b/DiskUsageApplet.hxx index fd77b3d..d45803d 100644 --- a/DiskUsageApplet.hxx +++ b/DiskUsageApplet.hxx @@ -1,60 +1,63 @@ // SPDX-License-Identifier: GPL-3.0-or-later /* - Copyright 2017 Martin Koller, kollix@aon.at + Copyright 2017 - 2020 Martin Koller, kollix@aon.at This file is part of liquidshell. liquidshell is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. liquidshell 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 liquidshell. If not, see . */ #ifndef _DiskUsageApplet_H_ #define _DiskUsageApplet_H_ #include #include #include #include #include class QProgressBar; class QLabel; class DiskUsageApplet : public DesktopApplet { Q_OBJECT public: DiskUsageApplet(QWidget *parent, const QString &theId); + void loadConfig() override; + public Q_SLOTS: void configure() override; + void saveConfig() override; private Q_SLOTS: void fill(); private: QTimer timer; struct SizeInfo { QLabel *label; QProgressBar *progress; QLabel *sizeLabel; bool used; }; QMap partitionMap; QPointer dialog; }; #endif diff --git a/DiskUsageAppletConfigureDialog.cxx b/DiskUsageAppletConfigureDialog.cxx index 7988196..2b9d291 100644 --- a/DiskUsageAppletConfigureDialog.cxx +++ b/DiskUsageAppletConfigureDialog.cxx @@ -1,46 +1,50 @@ // SPDX-License-Identifier: GPL-3.0-or-later /* - Copyright 2017 Martin Koller, kollix@aon.at + Copyright 2017 - 2020 Martin Koller, kollix@aon.at This file is part of liquidshell. liquidshell is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. liquidshell 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 liquidshell. If not, see . */ #include #include //-------------------------------------------------------------------------------- DiskUsageAppletConfigureDialog::DiskUsageAppletConfigureDialog(DiskUsageApplet *parent) : QDialog(parent), applet(parent) { ui.setupUi(this); ui.textColor->setColor(applet->palette().color(applet->foregroundRole())); ui.backgroundColor->setColor(applet->palette().color(applet->backgroundRole())); + ui.barTextColor->setColor(applet->palette().color(QPalette::HighlightedText)); + ui.barBackgroundColor->setColor(applet->palette().color(QPalette::Highlight)); } //-------------------------------------------------------------------------------- void DiskUsageAppletConfigureDialog::accept() { QPalette pal = applet->palette(); pal.setColor(applet->foregroundRole(), ui.textColor->color()); pal.setColor(applet->backgroundRole(), ui.backgroundColor->color()); + pal.setColor(QPalette::HighlightedText, ui.barTextColor->color()); + pal.setColor(QPalette::Highlight, ui.barBackgroundColor->color()); applet->setPalette(pal); QDialog::accept(); } //-------------------------------------------------------------------------------- diff --git a/DiskUsageAppletConfigureDialog.hxx b/DiskUsageAppletConfigureDialog.hxx index eea5af8..67baec9 100644 --- a/DiskUsageAppletConfigureDialog.hxx +++ b/DiskUsageAppletConfigureDialog.hxx @@ -1,43 +1,43 @@ // SPDX-License-Identifier: GPL-3.0-or-later /* - Copyright 2017 Martin Koller, kollix@aon.at + Copyright 2017 - 2020 Martin Koller, kollix@aon.at This file is part of liquidshell. liquidshell is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. liquidshell 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 liquidshell. If not, see . */ #ifndef _DiskUsageAppletConfigureDialog_H_ #define _DiskUsageAppletConfigureDialog_H_ #include #include class DiskUsageApplet; class DiskUsageAppletConfigureDialog : public QDialog { Q_OBJECT public: DiskUsageAppletConfigureDialog(DiskUsageApplet *parent); private Q_SLOTS: void accept() override; private: DiskUsageApplet *applet; Ui::DiskUsageAppletConfigureDialog ui; }; #endif diff --git a/DiskUsageAppletConfigureDialog.ui b/DiskUsageAppletConfigureDialog.ui index 06faa98..9303e9f 100644 --- a/DiskUsageAppletConfigureDialog.ui +++ b/DiskUsageAppletConfigureDialog.ui @@ -1,99 +1,127 @@ DiskUsageAppletConfigureDialog 0 0 - 462 - 101 + 477 + 177 Dialog - + + + + Text + + + + Qt::Horizontal QDialogButtonBox::Cancel|QDialogButtonBox::Ok true - - + + - Text + Bar Text + + + + + + + true Background - - + + + + true + + + + + + + Bar Background + + + + + true KColorButton QPushButton
kcolorbutton.h
buttonBox accepted() DiskUsageAppletConfigureDialog accept() 248 254 157 274 buttonBox rejected() DiskUsageAppletConfigureDialog reject() 316 260 286 274