diff --git a/Modules/about-distro/src/Module.h b/Modules/about-distro/src/Module.h --- a/Modules/about-distro/src/Module.h +++ b/Modules/about-distro/src/Module.h @@ -27,6 +27,8 @@ class Module; } +class QLabel; + class Module : public KCModule { Q_OBJECT @@ -63,6 +65,13 @@ void loadSoftware(); void loadHardware(); + /** + * Copies the software and hardware information to clipboard. + */ + void copyToClipboard(); + + QList > labelsForClipboard; + /** * UI */ diff --git a/Modules/about-distro/src/Module.cpp b/Modules/about-distro/src/Module.cpp --- a/Modules/about-distro/src/Module.cpp +++ b/Modules/about-distro/src/Module.cpp @@ -21,6 +21,7 @@ #include "Module.h" #include "ui_Module.h" +#include #include #include @@ -102,6 +103,10 @@ // We have no help so remove the button from the buttons. setButtons(buttons() ^ KCModule::Help ^ KCModule::Default ^ KCModule::Apply); + // Setup Copy to Clipboard button + connect(ui->pushButtonCopyInfo, &QPushButton::clicked, this, &Module::copyToClipboard); + ui->pushButtonCopyInfo->setShortcut(QKeySequence::Copy); + // https://bugs.kde.org/show_bug.cgi?id=366158 // When a KCM loads fast enough do a blocking load via the constructor. // Otherwise there is a notciable rendering gap where dummy/no data is @@ -116,6 +121,7 @@ void Module::load() { + labelsForClipboard.clear(); loadSoftware(); loadHardware(); } @@ -153,6 +159,10 @@ const QString versionId = cg.readEntry("Version", os.versionId); ui->nameVersionLabel->setText(QStringLiteral("%1 %2").arg(distroName, versionId)); + const auto dummyDistroDescriptionLabel = new QLabel(i18nc("@title:row", "Distro:"), this); + dummyDistroDescriptionLabel->hide(); + labelsForClipboard << qMakePair(dummyDistroDescriptionLabel, ui->nameVersionLabel); + const QString variant = cg.readEntry("Variant", QString()); if (variant.isEmpty()) { ui->variantLabel->hide(); @@ -175,11 +185,16 @@ ui->plasmaLabel->hide(); } else { ui->plasmaLabel->setText(plasma); + labelsForClipboard << qMakePair(ui->plasma, ui->plasmaLabel); } - ui->qtLabel->setText(qVersion()); + const QString qversion = qVersion(); + ui->qtLabel->setText(qversion); + labelsForClipboard << qMakePair(ui->qt, ui->qtLabel); - ui->frameworksLabel->setText(KCoreAddons::versionString()); + const QString frameworksVersion = KCoreAddons::versionString(); + ui->frameworksLabel->setText(frameworksVersion); + labelsForClipboard << qMakePair(ui->frameworksLabelKey, ui->frameworksLabel); } void Module::loadHardware() @@ -190,11 +205,14 @@ ui->kernelLabel->hide(); } else { ui->kernelLabel->setText(utsName.release); + labelsForClipboard << qMakePair(ui->kernel, ui->kernelLabel); } const int bits = QT_POINTER_SIZE == 8 ? 64 : 32; + const QString bitsStr = QString::number(bits); ui->bitsLabel->setText(i18nc("@label %1 is the CPU bit width (e.g. 32 or 64)", - "%1-bit", QString::number(bits))); + "%1-bit", bitsStr)); + labelsForClipboard << qMakePair(ui->bitsKey, ui->bitsLabel); const QList list = Solid::Device::listFromType(Solid::DeviceInterface::Processor); ui->processor->setText(i18np("Processor:", "Processors:", list.count())); @@ -221,17 +239,39 @@ name = name.simplified(); names.append(QStringLiteral("%1 × %2").arg(count).arg(name)); } - ui->processorLabel->setText(names.join(QStringLiteral(", "))); + + const QString processorLabel = names.join(QStringLiteral(", ")); + ui->processorLabel->setText(processorLabel); if (ui->processorLabel->text().isEmpty()) { ui->processor->setHidden(true); ui->processorLabel->setHidden(true); + } else { + labelsForClipboard << qMakePair(ui->processor, ui->processorLabel); } const qlonglong totalRam = calculateTotalRam(); - ui->memoryLabel->setText(totalRam > 0 + const QString memoryLabel = totalRam > 0 ? i18nc("@label %1 is the formatted amount of system memory (e.g. 7,7 GiB)", "%1 of RAM", KFormat().formatByteSize(totalRam)) - : i18nc("Unknown amount of RAM", "Unknown")); + : i18nc("Unknown amount of RAM", "Unknown"); + ui->memoryLabel->setText(memoryLabel); + labelsForClipboard << qMakePair(ui->memory, ui->memoryLabel); +} + +void Module::copyToClipboard() +{ + QString text; + // note that this loop does not necessarily represent the same order as in the GUI + for (auto labelPair : qAsConst(labelsForClipboard)) { + const auto valueLabel = labelPair.second; + if (!valueLabel->isHidden()) { + const auto descriptionLabelText = labelPair.first->text(); + const auto valueLabelText = valueLabel->text(); + text += i18nc("%1 is a label already including a colon, %2 is the corresponding value", "%1 %2", descriptionLabelText, valueLabelText) + QStringLiteral("\n"); + } + } + + QGuiApplication::clipboard()->setText(text); } QString Module::plasmaVersion() const diff --git a/Modules/about-distro/src/Module.ui b/Modules/about-distro/src/Module.ui --- a/Modules/about-distro/src/Module.ui +++ b/Modules/about-distro/src/Module.ui @@ -10,147 +10,334 @@ 586 - - - + + + + + Qt::Vertical + + + QSizePolicy::Maximum + + + + 17 + 21 + + + + + + - + - Qt::Vertical + Qt::Horizontal - QSizePolicy::Preferred + QSizePolicy::Expanding - 20 - 40 + 0 + 0 - - - {NameVersionLabel} - - - - - - - {variantLabel} - - - - - - - {UrlLabel} - - - true - - + + + + + + + {LogoLabel} + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + + + + {NameVersionLabel} + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 40 + + + + + + + + {UrlLabel} + + + true + + + + + + + {variantLabel} + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 17 + 21 + + + + + + + + + 75 + true + + + + Software + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + KDE Plasma Version: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + {KDEVersion} + + + + + + + KDE Frameworks Version: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + {FrameworksVersion} + + + + + + + Qt Version: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + {QtVersion} + + + + + + + Kernel Version: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + {KernelName} + + + + + + + OS Type: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + {QtArchitecutre} + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 17 + 21 + + + + + + + + + 75 + true + + + + Hardware + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Processor: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + {PrcoessorName} + + + + + + + Memory: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + {MemoryAmount} + + + + - + - Qt::Vertical - - - QSizePolicy::Preferred + Qt::Horizontal - 20 - 40 + 0 + 0 - - - - KDE Plasma Version: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Horizontal - - - - 215 - 20 - - - - - - - - - - - {LogoLabel} - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 4 - 0 - - - - - - - - - - - {MemoryAmount} - - - - - - - {KDEVersion} - - - - - - - Memory: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + Qt::Vertical @@ -163,183 +350,36 @@ - - - - Processor: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 75 - true - - - - Software - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - {KernelName} - - - - - - - {QtVersion} - - - - - - - Qt::Horizontal - - - - 215 - 17 - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 24 - - - - - - - - Qt Version: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - {QtArchitecutre} - - - - - - - - 75 - true - - - - Hardware - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - OS Type: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 24 - - - - - - - - Kernel Version: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - QSizePolicy::Maximum - - - - 20 - 24 - - - - - - - - {PrcoessorName} - - - - - - - KDE Frameworks Version: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - {FrameworksVersion} - - + + + + + + Copy software and hardware information to clipboard + + + Copy to Clipboard + + + + .. + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + +