summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2017-01-12 16:01:55 +0100
committerAleix Pol <[email protected]>2017-01-12 16:02:02 +0100
commit9c0dd3d491c499292f38cb2afa40833722641db6 (patch)
tree62c8df45e3b12050ffecf6fe3a32087810062b49
parent8d4434b657c8d19d24709b8492fed06d61cf0887 (diff)
Gain control over the applications shown on the main browsing page
For now in here: https://autoconfig.kde.org/discover/featured-5.9.json
-rw-r--r--CMakeLists.txt2
-rw-r--r--discover/CMakeLists.txt3
-rw-r--r--discover/DiscoverMainWindow.cpp3
-rw-r--r--discover/FeaturedModel.cpp135
-rw-r--r--discover/FeaturedModel.h46
-rw-r--r--discover/featured.json17
-rw-r--r--discover/qml/ApplicationDelegate.qml8
-rw-r--r--discover/qml/BrowsingPage.qml12
-rw-r--r--libdiscover/backends/PackageKitBackend/CMakeLists.txt1
9 files changed, 191 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6b63e7a..b7527f9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,7 +17,7 @@ include(ECMMarkAsTest)
include(ECMAddTests)
include(GenerateExportHeader)
-find_package(KF5 5.29 REQUIRED CoreAddons Config Crash DBusAddons I18n Archive Declarative XmlGui ItemModels)
+find_package(KF5 5.29 REQUIRED CoreAddons Config Crash DBusAddons I18n Archive Declarative XmlGui ItemModels KIO)
find_package(KF5Kirigami2)
find_package(packagekitqt5)
diff --git a/discover/CMakeLists.txt b/discover/CMakeLists.txt
index 6af0344..2e72068 100644
--- a/discover/CMakeLists.txt
+++ b/discover/CMakeLists.txt
@@ -7,6 +7,7 @@ set(plasma_discover_SRCS
main.cpp
DiscoverMainWindow.cpp
+ FeaturedModel.cpp
PaginateModel.cpp
SystemFonts.cpp
IconColors.cpp
@@ -26,6 +27,7 @@ target_link_libraries(plasma-discover LINK_PUBLIC
KF5::XmlGui
KF5::Declarative
KF5::ItemModels
+ KF5::KIOCore
Qt5::Quick
Discover::Common
)
@@ -33,6 +35,5 @@ target_link_libraries(plasma-discover LINK_PUBLIC
install(TARGETS plasma-discover ${INSTALL_TARGETS_DEFAULT_ARGS} )
install(PROGRAMS org.kde.discover.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} )
-install(FILES featured.json DESTINATION ${DATA_INSTALL_DIR}/plasmadiscover)
install(FILES plasmadiscoverui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/plasmadiscover)
install( FILES org.kde.discover.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR} )
diff --git a/discover/DiscoverMainWindow.cpp b/discover/DiscoverMainWindow.cpp
index 088ab7a..a60e429 100644
--- a/discover/DiscoverMainWindow.cpp
+++ b/discover/DiscoverMainWindow.cpp
@@ -22,6 +22,7 @@
#include "SystemFonts.h"
#include "IconColors.h"
#include "UnityLauncher.h"
+#include "FeaturedModel.h"
// Qt includes
#include <QAction>
@@ -95,7 +96,7 @@ DiscoverMainWindow::DiscoverMainWindow(CompactMode mode)
qmlRegisterType<PaginateModel>("org.kde.discover.app", 1, 0, "PaginateModel");
qmlRegisterType<IconColors>("org.kde.discover.app", 1, 0, "IconColors");
qmlRegisterType<KConcatenateRowsProxyModel>("org.kde.discover.app", 1, 0, "KConcatenateRowsProxyModel");
- qmlRegisterType<QSortFilterProxyModel>("org.kde.discover.app", 1, 0, "QSortFilterProxyModel");
+ qmlRegisterType<FeaturedModel>("org.kde.discover.app", 1, 0, "FeaturedModel");
qmlRegisterSingletonType<SystemFonts>("org.kde.discover.app", 1, 0, "SystemFonts", ([](QQmlEngine*, QJSEngine*) -> QObject* { return new SystemFonts; }));
qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/qml/DiscoverSystemPalette.qml")), "org.kde.discover.app", 1, 0, "DiscoverSystemPalette");
diff --git a/discover/FeaturedModel.cpp b/discover/FeaturedModel.cpp
new file mode 100644
index 0000000..9828701
--- /dev/null
+++ b/discover/FeaturedModel.cpp
@@ -0,0 +1,135 @@
+/***************************************************************************
+ * Copyright © 2016 Aleix Pol Gonzalez <[email protected]> *
+ * *
+ * 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/>. *
+ ***************************************************************************/
+
+#include "FeaturedModel.h"
+
+#include <QDebug>
+#include <QStandardPaths>
+#include <QFile>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QDir>
+#include <KIO/FileCopyJob>
+
+#include <resources/ResourcesModel.h>
+
+class StoredResultsStream : public AggregatedResultsStream
+{
+public:
+ StoredResultsStream(const QSet<ResultsStream*>& streams)
+ : AggregatedResultsStream(streams)
+ {
+ connect(this, &ResultsStream::resourcesFound, this, [this](const QVector<AbstractResource*>& resources) {
+ m_resources += resources;
+ });
+ }
+
+ QVector<AbstractResource*> resources() const {
+ return m_resources;
+ }
+
+private:
+ QVector<AbstractResource*> m_resources;
+};
+
+Q_GLOBAL_STATIC(QString, featuredCache)
+
+FeaturedModel::FeaturedModel()
+{
+ connect(ResourcesModel::global(), &ResourcesModel::backendsChanged, this, &FeaturedModel::refresh);
+ connect(ResourcesModel::global(), &ResourcesModel::resourceRemoved, this, &FeaturedModel::removeResource);
+
+ const QString dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
+ QDir().mkpath(dir);
+ *featuredCache = dir+QLatin1String("/featured-5.9.json");
+
+ const QUrl featuredUrl(QStringLiteral("https://autoconfig.kde.org/discover/featured-5.9.json"));
+ KIO::FileCopyJob *getJob = KIO::file_copy(featuredUrl, QUrl::fromLocalFile(*featuredCache), -1, KIO::Overwrite | KIO::HideProgressInfo);
+ connect(getJob, &KIO::FileCopyJob::result, this, &FeaturedModel::refresh);
+}
+
+void FeaturedModel::refresh()
+{
+ QSet<ResultsStream*> streams;
+
+ QFile f(*featuredCache);
+ if (!f.open(QIODevice::ReadOnly)) {
+ qWarning() << "couldn't open file" << *featuredCache;
+ return;
+ }
+ QJsonParseError error;
+ const auto array = QJsonDocument::fromJson(f.readAll(), &error).array();
+ if (error.error) {
+ qWarning() << "couldn't parse" << *featuredCache << ". error:" << error.errorString();
+ return;
+ }
+
+ foreach(const QJsonValue &uri, array) {
+ foreach(auto backend, ResourcesModel::global()->backends()) {
+ streams << backend->findResourceByPackageName(QUrl(uri.toString()));
+ }
+ }
+ auto stream = new StoredResultsStream(streams);
+ connect(stream, &AggregatedResultsStream::finished, stream, [this, stream] () {
+ setResources(stream->resources());
+ });
+}
+
+void FeaturedModel::setResources(const QVector<AbstractResource *>& resources)
+{
+ //TODO: sort like in the json files
+
+ beginResetModel();
+ m_resources = resources;
+ endResetModel();
+}
+
+void FeaturedModel::removeResource(AbstractResource* resource)
+{
+ int index = m_resources.indexOf(resource);
+ if (index<0)
+ return;
+
+ beginRemoveRows({}, index, 0);
+ m_resources.removeAt(index);
+ endRemoveRows();
+}
+
+QVariant FeaturedModel::data(const QModelIndex& index, int role) const
+{
+ if (!index.isValid() || role!=Qt::UserRole)
+ return {};
+
+ auto res = m_resources.value(index.row());
+ if (!res)
+ return {};
+
+ return QVariant::fromValue<QObject*>(res);
+}
+
+int FeaturedModel::rowCount(const QModelIndex& parent) const
+{
+ return parent.isValid() ? 0 : m_resources.count();
+}
+
+QHash<int, QByteArray> FeaturedModel::roleNames() const
+{
+ return {{Qt::UserRole, "application"}};
+}
diff --git a/discover/FeaturedModel.h b/discover/FeaturedModel.h
new file mode 100644
index 0000000..e8615a0
--- /dev/null
+++ b/discover/FeaturedModel.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * Copyright © 2016 Aleix Pol Gonzalez <[email protected]> *
+ * *
+ * 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/>. *
+ ***************************************************************************/
+
+#ifndef FEATUREDMODEL_H
+#define FEATUREDMODEL_H
+
+#include <QAbstractListModel>
+
+class AbstractResource;
+
+class FeaturedModel : public QAbstractListModel
+{
+ Q_OBJECT
+ public:
+ FeaturedModel();
+
+ void setResources(const QVector<AbstractResource*>& resources);
+ QVariant data(const QModelIndex & index, int role) const override;
+ int rowCount(const QModelIndex & parent) const override;
+ QHash<int, QByteArray> roleNames() const override;
+
+ private:
+ void refresh();
+ void removeResource(AbstractResource* resource);
+
+ QVector<AbstractResource*> m_resources;
+};
+
+#endif // FEATUREDMODEL_H
diff --git a/discover/featured.json b/discover/featured.json
deleted file mode 100644
index e2358a7..0000000
--- a/discover/featured.json
+++ /dev/null
@@ -1,17 +0,0 @@
-[
- {
- "icon": "kde",
- "image": "qrc:/qml/DefaultBanner.qml",
- "text": "KDE",
- "comment": "Awesomeness!",
- "url": "http://kde.org",
- "color": "blue"
- },
- {
- "icon": "kde",
- "image": "http://kde.org/images/teaser/jointhegame.gif",
- "text": "Support KDE",
- "comment": "Join the Game!",
- "url": "https://relate.kde.org/civicrm/contribute/transact?reset=1&id=5"
- }
-]
diff --git a/discover/qml/ApplicationDelegate.qml b/discover/qml/ApplicationDelegate.qml
index f8f5c7e..8a7550d 100644
--- a/discover/qml/ApplicationDelegate.qml
+++ b/discover/qml/ApplicationDelegate.qml
@@ -76,14 +76,14 @@ Kirigami.AbstractListItem
Heading {
Layout.fillWidth: true
elide: Text.ElideRight
- text: name
+ text: delegateArea.application.name
maximumLineCount: 1
}
Label {
Layout.fillWidth: true
elide: Text.ElideRight
horizontalAlignment: Text.AlignRight
- text: categoryDisplay
+ text: delegateArea.application.categoryDisplay
color: Kirigami.Theme.linkColor
visible: conts.width > implicitWidth
}
@@ -99,7 +99,7 @@ Kirigami.AbstractListItem
Layout.fillWidth: true
elide: Text.ElideRight
- text: comment
+ text: delegateArea.application.comment
maximumLineCount: 1
font: SystemFonts.titleFont
}
@@ -112,7 +112,7 @@ Kirigami.AbstractListItem
wrapMode: Text.WordWrap
elide: Text.ElideRight
textFormat: Text.StyledText
- text: longDescription
+ text: delegateArea.application.longDescription
}
}
InstallApplicationButton {
diff --git a/discover/qml/BrowsingPage.qml b/discover/qml/BrowsingPage.qml
index a387d10..2e3a8a2 100644
--- a/discover/qml/BrowsingPage.qml
+++ b/discover/qml/BrowsingPage.qml
@@ -42,8 +42,6 @@ DiscoverPage
}
ListView {
- id: apps
-
header: CategoryDisplay {
anchors {
left: parent.left
@@ -52,15 +50,7 @@ DiscoverPage
category: null
background: "qrc:/banners/coffee.jpg"
}
- model: PaginateModel {
- pageSize: 5
- sourceModel: ResourcesProxyModel {
- id: appsModel
- sortOrder: Qt.DescendingOrder
- sortRole: ResourcesProxyModel.RatingCountRole
-// onRowsInserted: sortModel()
- }
- }
+ model: FeaturedModel {}
spacing: Kirigami.Units.gridUnit
currentIndex: -1
delegate: ApplicationDelegate {
diff --git a/libdiscover/backends/PackageKitBackend/CMakeLists.txt b/libdiscover/backends/PackageKitBackend/CMakeLists.txt
index 12861a1..01f5363 100644
--- a/libdiscover/backends/PackageKitBackend/CMakeLists.txt
+++ b/libdiscover/backends/PackageKitBackend/CMakeLists.txt
@@ -1,4 +1,3 @@
-find_package(KF5KIO REQUIRED)
find_package(KF5Archive REQUIRED)
add_subdirectory(runservice)