diff --git a/kcmkwin/CMakeLists.txt b/kcmkwin/CMakeLists.txt --- a/kcmkwin/CMakeLists.txt +++ b/kcmkwin/CMakeLists.txt @@ -9,6 +9,7 @@ add_subdirectory( kwinscripts ) add_subdirectory( kwindesktop ) add_subdirectory( kwineffects ) +add_subdirectory( supportinformation ) if( KWIN_BUILD_TABBOX ) add_subdirectory( kwintabbox ) diff --git a/kcmkwin/supportinformation/CMakeLists.txt b/kcmkwin/supportinformation/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kcmkwin/supportinformation/CMakeLists.txt @@ -0,0 +1,20 @@ +add_definitions(-DTRANSLATION_DOMAIN=\"kcm-kwin-supportinformation\") + +set(kcm_SRCS + main.cpp +) + +ki18n_wrap_ui(kcm_SRCS main.ui ) + +qt5_add_dbus_interface( kcm_SRCS ${KWIN_SOURCE_DIR}/org.kde.KWin.xml kwin_interface ) + +add_library(kcm_kwinsupportinformation MODULE ${kcm_SRCS}) + +target_link_libraries(kcm_kwinsupportinformation + Qt5::DBus + KF5::KCMUtils + KF5::I18n +) + +install(TARGETS kcm_kwinsupportinformation DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES kwinsupportinformation.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/kcmkwin/supportinformation/Messages.sh b/kcmkwin/supportinformation/Messages.sh new file mode 100644 --- /dev/null +++ b/kcmkwin/supportinformation/Messages.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash +$EXTRACTRC `find . -name \*.ui` >> rc.cpp +$XGETTEXT *.cpp -o $podir/kcm_kwinsupportinformation.pot +rm -f rc.cpp diff --git a/kcmkwin/supportinformation/kwinsupportinformation.desktop b/kcmkwin/supportinformation/kwinsupportinformation.desktop new file mode 100644 --- /dev/null +++ b/kcmkwin/supportinformation/kwinsupportinformation.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Type=Service +Exec=kcmshell5 kwinsupportinformation +Icon=kwin + +X-KDE-ServiceTypes=KCModule +X-KDE-KInfoCenter-Category=graphical_information +X-KDE-Library=kcm_kwinsupportinformation +X-KDE-ParentApp=kinfocenter + +Name=KWin Support Information + +Comment=Support information for reporting issues in KWin + +X-KDE-Keywords=KWin,Support,Information,Bug,Bugs + +Categories=Qt;KDE;X-KDE-information; diff --git a/kcmkwin/supportinformation/main.h b/kcmkwin/supportinformation/main.h new file mode 100644 --- /dev/null +++ b/kcmkwin/supportinformation/main.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 Kai Uwe Broulik + * + * This program 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 any later version accepted by the membership of + * KDE e.V. (or its successor approved by the membership of KDE + * e.V.), which shall act as a proxy defined in Section 14 of + * version 3 of the license. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include + +#include +#include + +#include "ui_main.h" + +namespace Ui +{ +class KWinSupportInformationForm; +} + +namespace KWin +{ + +class KWinSupportInformation : public KCModule +{ + Q_OBJECT + +public: + explicit KWinSupportInformation(QWidget *parent, const QVariantList &args); + ~KWinSupportInformation() override; + +private: + void showMessage(KMessageWidget::MessageType type, const QString &text); + bool saveToFile(const QString &path); + + QScopedPointer m_ui; + +}; + +} // namespace KWin diff --git a/kcmkwin/supportinformation/main.cpp b/kcmkwin/supportinformation/main.cpp new file mode 100644 --- /dev/null +++ b/kcmkwin/supportinformation/main.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2019 Kai Uwe Broulik + * + * This program 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 any later version accepted by the membership of + * KDE e.V. (or its successor approved by the membership of KDE + * e.V.), which shall act as a proxy defined in Section 14 of + * version 3 of the license. + * + * This program 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 this program. If not, see . + */ + +#include "main.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "ui_main.h" + +#include "kwin_interface.h" + +K_PLUGIN_FACTORY(KWinSupportInformationFactory, registerPlugin();) + +using namespace KWin; + +KWinSupportInformation::KWinSupportInformation(QWidget *parent, const QVariantList &args) + : KCModule(KAboutData::pluginData(QStringLiteral("kcm_kwinsupportinformation")), parent, args) + , m_ui(new Ui::KWinSupportInformationForm) +{ + m_ui->setupUi(this); + m_ui->textBrowser->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); + m_ui->textBrowser->setEnabled(false); + m_ui->messageWidget->hide(); + + auto *kwinInterface = new org::kde::KWin(QStringLiteral("org.kde.KWin"), + QStringLiteral("/KWin"), + QDBusConnection::sessionBus(), + this); + + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(kwinInterface->supportInformation(), this); + connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, watcher]() { + QDBusPendingReply reply = *watcher; + if (reply.isError()) { + showMessage(KMessageWidget::Error, i18n("Failed to query support information from KWin: %1", reply.error().message())); + } else { + m_ui->textBrowser->setPlainText(reply.value()); + m_ui->textBrowser->setEnabled(true); + } + watcher->deleteLater(); + }); + + connect(m_ui->copyButton, &QPushButton::clicked, this, [this] { + QGuiApplication::clipboard()->setText(m_ui->textBrowser->toPlainText()); + m_ui->messageWidget->setMessageType(KMessageWidget::Positive); + m_ui->messageWidget->setText(i18n("Support information was copied to clipboard.")); + m_ui->messageWidget->animatedShow(); + }); + connect(m_ui->saveButton, &QPushButton::clicked, this, [this] { + QFileDialog *dialog = new QFileDialog(this); + dialog->setWindowTitle(i18n("Save Support Information")); + dialog->setAcceptMode(QFileDialog::AcceptSave); + dialog->setMimeTypeFilters({QStringLiteral("text/plain")}); + dialog->setSupportedSchemes({QStringLiteral("file")}); + dialog->setConfirmOverwrite(true); + if (!dialog->exec()) { + return; + } + + const QUrl url = dialog->selectedUrls().value(0); + if (!url.isValid()) { + return; + } + + if (!saveToFile(url.toLocalFile())) { + showMessage(KMessageWidget::Error, i18n("Failed to save support information to this file.")); + return; + } + }); +} + +KWinSupportInformation::~KWinSupportInformation() = default; + +void KWinSupportInformation::showMessage(KMessageWidget::MessageType type, const QString &text) +{ + m_ui->messageWidget->setMessageType(type); + m_ui->messageWidget->setText(text); + m_ui->messageWidget->animatedShow(); +} + +bool KWinSupportInformation::saveToFile(const QString &path) +{ + QSaveFile file(path); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + return false; + } + + file.write(m_ui->textBrowser->toPlainText().toUtf8()); + + if (!file.commit()) { + return false; + } + + return true; +} + +#include "main.moc" diff --git a/kcmkwin/supportinformation/main.ui b/kcmkwin/supportinformation/main.ui new file mode 100644 --- /dev/null +++ b/kcmkwin/supportinformation/main.ui @@ -0,0 +1,78 @@ + + + KWinSupportInformationForm + + + + 0 + 0 + 643 + 586 + + + + + + + true + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Copy software and hardware information to clipboard + + + Copy to Clipboard + + + + .. + + + + + + + Save to File + + + + .. + + + + + + + + + + KMessageWidget + QFrame +
kmessagewidget.h
+ 1 +
+
+ + +