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 @@ -116,8 +117,12 @@ void Module::load() { + labelsForClipboard.clear(); loadSoftware(); loadHardware(); + + connect(ui->pushButtonCopyInfo, &QPushButton::clicked, this, &Module::copyToClipboard); + ui->pushButtonCopyInfo->setShortcut(QKeySequence::Copy); } void Module::save() @@ -175,11 +180,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 +200,14 @@ ui->kernelLabel->hide(); } else { ui->kernelLabel->setText(utsName.release); + labelsForClipboard << qMakePair(ui->kernel, ui->frameworksLabelKey); } 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 +234,42 @@ 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; + if (!ui->nameVersionLabel->isHidden()) { + text += i18nc("one line in the information that goes to the clipboard", "%1 %2", i18nc("label in the Copy to Clipboard button", "Distro:"), ui->nameVersionLabel->text()) + QStringLiteral("\n"); + } + + typedef QPair QLabelPair; // because the "," cannot be used in the foreach macro + foreach (QLabelPair p, labelsForClipboard) { // note that does not necessarily represent the same order as in the GUI + auto labelLabel = p.first; + auto versionLabel = p.second; + if (!versionLabel->isHidden()) { + text += i18nc("one line in the information that goes to the clipboard", "%1 %2", labelLabel->text(), versionLabel->text()) + 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 @@ -150,19 +150,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -266,7 +253,7 @@ - + OS Type: @@ -341,6 +328,40 @@ + + + + + 0 + 0 + + + + Copy software and hardware information to clipboard + + + Copy to Clipboard + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + +