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() @@ -153,6 +158,9 @@ const QString versionId = cg.readEntry("Version", os.versionId); ui->nameVersionLabel->setText(QStringLiteral("%1 %2").arg(distroName, versionId)); + auto dummyDistroDescriptionLabel = new QLabel(i18nc("@title:row", "Distro:"), this); + labelsForClipboard << qMakePair(dummyDistroDescriptionLabel, ui->nameVersionLabel); + const QString variant = cg.readEntry("Variant", QString()); if (variant.isEmpty()) { ui->variantLabel->hide(); @@ -175,11 +183,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 +203,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 +237,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 p : qAsConst(labelsForClipboard)) { + auto descriptionLabelText = p.first->text(); + auto valueLabel = p.second; + auto valueLabelText = valueLabel->text(); + if (!valueLabel->isHidden()) { + 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,301 @@ 586 - - - - - + + + + + Qt::Vertical + + + QSizePolicy::Maximum + + + + 17 + 21 + + + + + + + + + + + + {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::Preferred + QSizePolicy::Fixed - 20 - 40 + 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} + + + + + - {NameVersionLabel} + Qt Version: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + - {variantLabel} + {QtVersion} - - + + - {UrlLabel} + Kernel Version: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - true + + + + + + {KernelName} - - + + + + OS Type: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + {QtArchitecutre} + + + + + Qt::Vertical - QSizePolicy::Preferred + QSizePolicy::Fixed - 20 - 40 + 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} + + + - - - - 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 +317,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 + + + + +