Paste P195

Masterwork From Distant Lands
ActivePublic

Authored by davidedmundson on Apr 16 2018, 4:13 PM.
commit 7e4164c346dfd238488a539cc54d6928e7a81b3b
Author: David Edmundson <kde@davidedmundson.co.uk>
Date: Mon Apr 16 17:12:46 2018 +0100
GHNS button
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 765cf13..9bc4463 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,6 +28,8 @@ find_package(KF5WindowSystem ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5GlobalAccel ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5GuiAddons ${KF5_DEP_VERSION} REQUIRED)
find_package(KF5Package ${KF5_DEP_VERSION} REQUIRED)
+find_package(KF5NewStuff ${KF5_DEP_VERSION} REQUIRED)
+
#########################################################################
diff --git a/src/qmlcontrols/kquickcontrols/GHNSButton.qml b/src/qmlcontrols/kquickcontrols/GHNSButton.qml
new file mode 100644
index 0000000..ee5c45a
--- /dev/null
+++ b/src/qmlcontrols/kquickcontrols/GHNSButton.qml
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2018 David Edmundson <davidedmundson@kde.org>
+ *
+ * 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 2 of
+ * the License or (at your option) version 3 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 <http://www.gnu.org/licenses/>
+ */
+
+import QtQuick 2.6
+import QtQuick.Controls 2.0
+
+import org.kde.private.kquickcontrols 2.0 as KQuickControlsPrivate
+import org.kde.kconfig 1.0 // for KAuthorized
+
+Button
+{
+ id: button
+ property alias ksnrcFile: _helper.ksnrcFile
+ property alias dialogTitle: _helper.title
+ /**
+ * Emitted when a user finishes installing new items
+ */
+ signals: entriesChanged
+
+ text: _tr.i18n("Get New...")
+ icon.name: "get-hot-new-stuff" //DAVE - either needs up to date Qt or I use QQC1 here. QQC1.Button has a palette bug
+
+ enabled: KAuthorized.authorize("ghns")
+
+ KQuickControlsPrivate.TranslationContext {
+ id: _tr
+ domain: "kdeclarative5"
+ }
+
+ KQuickControlsPrivate.GHNSHelper {
+ id: _helper
+ onEntriesChanged: button.entriesChanged
+ }
+
+ onClicked: _helper.getNew(button)
+}
diff --git a/src/qmlcontrols/kquickcontrols/private/CMakeLists.txt b/src/qmlcontrols/kquickcontrols/private/CMakeLists.txt
index da355c1..ef9d010 100644
--- a/src/qmlcontrols/kquickcontrols/private/CMakeLists.txt
+++ b/src/qmlcontrols/kquickcontrols/private/CMakeLists.txt
@@ -4,6 +4,7 @@ set(kquickcontrolsprivate_SRCS
kquickcontrolsprivateplugin.cpp
keysequencehelper.cpp
translationcontext.cpp
+ ghnshelper.cpp
)
add_library(kquickcontrolsprivateplugin SHARED ${kquickcontrolsprivate_SRCS})
@@ -17,6 +18,7 @@ target_link_libraries(kquickcontrolsprivateplugin
KF5::WidgetsAddons
KF5::WindowSystem
KF5::GlobalAccel
+ KF5::NewStuff
)
install(TARGETS kquickcontrolsprivateplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/private/kquickcontrols)
diff --git a/src/qmlcontrols/kquickcontrols/private/ghnshelper.cpp b/src/qmlcontrols/kquickcontrols/private/ghnshelper.cpp
new file mode 100644
index 0000000..d54d53e
--- /dev/null
+++ b/src/qmlcontrols/kquickcontrols/private/ghnshelper.cpp
@@ -0,0 +1,45 @@
+#include "ghnshelper.h"
+
+#include <QQuickItem>
+#include <QQuickWindow>
+
+#include <KNewStuff3/KNS3/DownloadDialog>
+
+GHNSHelper::GHNSHelper(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+GHNSHelper::~GHNSHelper()
+{
+ if (m_newStuffDialog) {
+ m_newStuffDialog->close();
+ }
+}
+
+void GHNSHelper::getNewStuff(QQuickItem *ctx)
+{
+ if (m_ksnrc.isEmpty()) {
+ return;
+ }
+ if (!m_newStuffDialog) {
+ m_newStuffDialog = new KNS3::DownloadDialog(m_ksnrc);
+ if (!m_title.isEmpty()) {
+ m_newStuffDialog->setTitle(m_title);
+ }
+ connect(m_newStuffDialog.data(), &QDialog::accepted, this, [this]() {
+ if (m_newStuffDialog->changedEntries().size() > 0) {
+ emit entriesChanged();
+ }
+ });
+ }
+
+ if (ctx && ctx->window()) {
+ m_newStuffDialog->setWindowModality(Qt::WindowModal);
+ m_newStuffDialog->winId(); // so it creates the windowHandle();
+ m_newStuffDialog->windowHandle()->setTransientParent(ctx->window());
+ }
+
+ m_newStuffDialog->show();
+}
diff --git a/src/qmlcontrols/kquickcontrols/private/ghnshelper.h b/src/qmlcontrols/kquickcontrols/private/ghnshelper.h
new file mode 100644
index 0000000..4cf71e8
--- /dev/null
+++ b/src/qmlcontrols/kquickcontrols/private/ghnshelper.h
@@ -0,0 +1,68 @@
+/*
+ * <one line to give the library's name and an idea of what it does.>
+ * Copyright (C) 2014 David Edmundson <davidedmundson@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef KHNSHELPER_H
+#define KHNSHELPER_H
+
+#include <QObject>
+#include <QQuickItem>
+#include <QPointer>
+
+namespace KNS3 {
+ class DownloadDialog;
+}
+
+
+
+/**
+ * This class wraps GHNS Dialogs
+ * It is a private class to be used by GHNSButton
+ *
+ */
+class GHNSHelper : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString ksnrc MEMBER m_ksnrc NOTIFY ksnrcChanged)
+ Q_PROPERTY(QString ksnrc MEMBER m_title NOTIFY titleChanged)
+
+public:
+ explicit GHNSHelper(QObject* parent = nullptr);
+
+ virtual ~GHNSHelper();
+
+public Q_SLOTS:
+ void getNewStuff(QQuickItem *context);
+
+Q_SIGNALS:
+ void entriesChanged();
+ void ksnrcChanged();
+ void titleChanged();
+
+private:
+ QString m_ksnrc;
+ QString m_title;
+ QPointer<KNS3::DownloadDialog> m_newStuffDialog;
+ Q_DISABLE_COPY(GHNSHelper)
+};
+
+
+
+#endif
diff --git a/src/qmlcontrols/kquickcontrols/qmldir b/src/qmlcontrols/kquickcontrols/qmldir
index c977449..f8cb233 100644
--- a/src/qmlcontrols/kquickcontrols/qmldir
+++ b/src/qmlcontrols/kquickcontrols/qmldir
@@ -1,2 +1,3 @@
KeySequenceItem 2.0 KeySequenceItem.qml
-ColorButton 2.0 ColorButton.qml
\ No newline at end of file
+ColorButton 2.0 ColorButton.qml
+GHNSButton 2.0 GHNSButton.qml
davidedmundson edited the content of this paste. (Show Details)Apr 16 2018, 4:13 PM
davidedmundson changed the title of this paste from untitled to Masterwork From Distant Lands.
davidedmundson updated the paste's language from autodetect to autodetect.