diff --git a/Modules/about-distro/src/CMakeLists.txt b/Modules/about-distro/src/CMakeLists.txt --- a/Modules/about-distro/src/CMakeLists.txt +++ b/Modules/about-distro/src/CMakeLists.txt @@ -15,7 +15,8 @@ KF5::ConfigWidgets KF5::CoreAddons KF5::I18n - KF5::Solid) + KF5::Solid + KF5::XmlGui) install(TARGETS kcm_about_distro DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES about-distro.desktop DESTINATION ${SERVICES_INSTALL_DIR}) 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 @@ -22,6 +22,7 @@ #define MODULE_H #include +#include namespace Ui { class Module; @@ -64,6 +65,15 @@ void loadHardware(); /** + * Copies the software and hardware information to clipboard. + * The label language is currently English only + * because the Plasma development language is English. + */ + void copyToClipboard(); + + QMap collectedData; + + /** * UI */ Ui::Module *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,14 +21,16 @@ #include "Module.h" #include "ui_Module.h" +#include +#include +#include + #include #include #include #include -#if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5,20,0) #include -#endif #include #include #include @@ -121,6 +123,19 @@ { loadSoftware(); loadHardware(); + + auto menu = new QMenu(this); + ui->pushButtonActionMenu->setMenu(menu); + + auto actionCopyToClipboard = new QAction(i18n("Copy to Clipboard"), this); + menu->addAction(actionCopyToClipboard); + connect(actionCopyToClipboard, &QAction::triggered, this, &Module::copyToClipboard); + + auto helpMenu = new KHelpMenu(); + menu->addAction(helpMenu->action(KHelpMenu::MenuId::menuAboutKDE)); + + // WIP TODO: remove: + //menu->addAction(KStandardAction::aboutKDE(this, SLOT(aboutKDE()), this)); // this does not show the About KDE dialog } void Module::save() @@ -139,7 +154,7 @@ KConfig::NoGlobals); KConfigGroup cg = KConfigGroup(config, "General"); - QString logoPath = cg.readEntry("LogoPath", QString()); + const QString logoPath = cg.readEntry("LogoPath", QString()); QPixmap logo; if (logoPath.isEmpty()) { logo = QIcon::fromTheme(QStringLiteral("start-here-kde")).pixmap(128, 128); @@ -152,42 +167,43 @@ // We allow overriding of the OS name for branding purposes. // For example OS Ubuntu may be rebranded as Kubuntu. Also Kubuntu Active // as a product brand is different from Kubuntu. - QString distroName = cg.readEntry("Name", os.name); - QString versionId = cg.readEntry("Version", os.versionId); + const QString distroName = cg.readEntry("Name", os.name); + const QString versionId = cg.readEntry("Version", os.versionId); + collectedData["4_Distro"] = distroName + " " + versionId; ui->nameVersionLabel->setText(QStringLiteral("%1 %2").arg(distroName, versionId)); - QString variant = cg.readEntry("Variant", QString()); + const QString variant = cg.readEntry("Variant", QString()); if (variant.isEmpty()) { ui->variantLabel->hide(); } else { ui->variantLabel->setText(variant); } - QString url = cg.readEntry("Website", os.homeUrl); + const QString url = cg.readEntry("Website", os.homeUrl); if (url.isEmpty()) { ui->urlLabel->hide(); } else { ui->urlLabel->setText(QStringLiteral("%1").arg(url)); } // Since Plasma version detection isn't based on a library query it can fail // in weird cases; instead of admiting defeat we simply hide everything :P - QString plasma = plasmaVersion(); + const QString plasma = plasmaVersion(); if (plasma.isEmpty()) { ui->plasma->hide(); ui->plasmaLabel->hide(); } else { + collectedData["1_Plasma Version"] = plasma; ui->plasmaLabel->setText(plasma); } - ui->qtLabel->setText(qVersion()); + const QString qversion = qVersion(); + collectedData["3_Qt Version"] = qversion; + ui->qtLabel->setText(qversion); -#if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5,20,0) - ui->frameworksLabel->setText(KCoreAddons::versionString()); -#else - ui->frameworksLabelKey->setVisible(false); - ui->frameworksLabel->setVisible(false); -#endif + const QString frameworksVersion = KCoreAddons::versionString(); + collectedData["2_KDE Frameworks Version"] = frameworksVersion; + ui->frameworksLabel->setText(frameworksVersion); } void Module::loadHardware() @@ -197,12 +213,15 @@ ui->kernel->hide(); ui->kernelLabel->hide(); } else { + collectedData["4_Kernel"] = utsName.release; ui->kernelLabel->setText(utsName.release); } const int bits = QT_POINTER_SIZE == 8 ? 64 : 32; + const QString bitsStr = QString::number(bits); + collectedData["5_OS Type"] = bitsStr + " bit"; ui->bitsLabel->setText(i18nc("@label %1 is the CPU bit width (e.g. 32 or 64)", - "%1-bit", QString::number(bits))); + "%1-bit", bitsStr)); const QList list = Solid::Device::listFromType(Solid::DeviceInterface::Processor); ui->processor->setText(i18np("Processor:", "Processors:", list.count())); @@ -228,17 +247,37 @@ name = name.simplified(); names.append(QStringLiteral("%1 × %2").arg(count).arg(name)); } - ui->processorLabel->setText(names.join(QStringLiteral(", "))); + + const QString processorLabel = names.join(QStringLiteral(", ")); + collectedData["6_Processors"] = processorLabel; + ui->processorLabel->setText(processorLabel); if (ui->processorLabel->text().isEmpty()) { ui->processor->setHidden(true); ui->processorLabel->setHidden(true); } 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"); + collectedData["7_Memory"] = memoryLabel; + ui->memoryLabel->setText(memoryLabel); +} + +void Module::copyToClipboard() +{ + auto clipboard = QGuiApplication::clipboard(); + QMapIterator i(collectedData); + QString text; + while (i.hasNext()) { + i.next(); + // "1_", "2_" etc. at the beginning of the key is for the ordering + // in the map and will not be part of the text for the clipboard + text += i.key().mid(2) + ": " + i.value(); + text += "\n"; + } + 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,7 +150,7 @@ - + Qt::Vertical @@ -242,6 +242,23 @@ + + + + + 0 + 0 + + + + Menu + + + + .. + + + @@ -341,6 +358,22 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 24 + + + +