diff --git a/plugins/extensions/resourcemanager/CMakeLists.txt b/plugins/extensions/resourcemanager/CMakeLists.txt index 8c06f6d510..c4526d49f3 100644 --- a/plugins/extensions/resourcemanager/CMakeLists.txt +++ b/plugins/extensions/resourcemanager/CMakeLists.txt @@ -1,24 +1,31 @@ find_package(KF5NewStuffCore) set_package_properties(KF5NewStuffCore PROPERTIES DESCRIPTION "The KNewStuff library implements collaborative data sharing for applications." URL "https://api.kde.org/frameworks/knewstuff/html/index.html" TYPE REQUIRED PURPOSE "Required to implement sharing functionality with share.krita.org and krita") set(kritaresourcemanager_SOURCES resourcemanager.cpp dlg_create_bundle.cpp dlg_bundle_manager.cpp dlg_content_downloader.cpp - content_downloader_backend.cpp ) ki18n_wrap_ui(kritaresourcemanager_SOURCES wdgdlgcreatebundle.ui wdgdlgbundlemanager.ui ) +install( FILES + data/kritapresets.knsrc + datakritabrushes.knsrc + data/kritapatterns.knsrc + data/kritagradients.knsrc + DESTINATION ${CONFIG_INSTALL_DIR} ) + + add_library(kritaresourcemanager MODULE ${kritaresourcemanager_SOURCES}) target_link_libraries(kritaresourcemanager kritawidgets kritaui kritalibpaintop KF5::NewStuffCore) install(TARGETS kritaresourcemanager DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) install(FILES resourcemanager.xmlgui DESTINATION ${DATA_INSTALL_DIR}/kritaplugins) diff --git a/plugins/extensions/resourcemanager/content_downloader_backend.cpp b/plugins/extensions/resourcemanager/content_downloader_backend.cpp new file mode 100644 index 0000000000..99bf94b55b --- /dev/null +++ b/plugins/extensions/resourcemanager/content_downloader_backend.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2016 Aniketh Girish anikethgireesh@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include "content_downloader_backend.h" +#include "dlg_content_downloader.h" diff --git a/plugins/extensions/resourcemanager/content_downloader_backend.h b/plugins/extensions/resourcemanager/content_downloader_backend.h new file mode 100644 index 0000000000..a2a00ab593 --- /dev/null +++ b/plugins/extensions/resourcemanager/content_downloader_backend.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016 Aniketh Girish anikethgireesh@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#ifndef CONTENT_DOWNLOADER_BACKEND_H +#define CONTENT_DOWNLOADER_BACKEND_H + +#include + +#include //backend of resources are coming from this + +//KNSCore Includes +#include + +class KoResource; +class KNSResourceDownloader; //KNS resource class needed to be added. + +namespace KNSCore +{ +class Engine; +} + +class KNSDownloaderBackend: KoResourceServer //KoResource here as the backend +{ + Q_OBJECT +public: + explicit KNSDownloaderBackend(QObject* parent, const QString& iconName, const QString &knsrc); + ~KNSDownloaderBackend() override; + + void removeResource(KoResourceServer* app) override; + void installResource(KoResourceServer* app) override; + + QString iconName() const { return m_iconName; } + + KNSCore::Engine* engine() const { return m_engine; } + + //Search needed to be implemented + + //loading the categories + +Q_SIGNALS: + void receivedResources(const QVector &resources); //act as the selected resource or the downloaded resource + +public Q_SLOTS: + void receivedEntries(const KNSCore::EntryInternal::List& entries); + +private: + KNSResource* resourceForEntry(const KNSCore::EntryInternal& entry); + + KNSCore::Engine* m_engine; + QString m_name; + QString m_iconName; + QHash m_resourceByName; + + QStringList m_categories; //Sorting between categories. + + +}; +#endif // CONTENT_DOWNLOADER_BACKEND_H diff --git a/plugins/extensions/resourcemanager/data/kritabrushes.knsrc b/plugins/extensions/resourcemanager/data/kritabrushes.knsrc new file mode 100644 index 0000000000..3c8635aac1 --- /dev/null +++ b/plugins/extensions/resourcemanager/data/kritabrushes.knsrc @@ -0,0 +1,9 @@ +[KNewStuff3] +ProvidersUrl=https://share.krita.org/ocs/providers.xml +Categories=Krita Brush +XdgTargetDir=krita/brushes +Uncompress=never + + + + diff --git a/plugins/extensions/resourcemanager/data/kritagradients.knsrc b/plugins/extensions/resourcemanager/data/kritagradients.knsrc new file mode 100644 index 0000000000..9a53f9b4ea --- /dev/null +++ b/plugins/extensions/resourcemanager/data/kritagradients.knsrc @@ -0,0 +1,6 @@ +[KNewStuff3] +ProvidersUrl=https://share.krita.org/ocs/providers.xml +Categories=Krita Gradient +XdgTargetDir=krita/gradients +Uncompress=never + diff --git a/plugins/extensions/resourcemanager/data/kritapatterns.knsrc b/plugins/extensions/resourcemanager/data/kritapatterns.knsrc new file mode 100644 index 0000000000..f8f0e59813 --- /dev/null +++ b/plugins/extensions/resourcemanager/data/kritapatterns.knsrc @@ -0,0 +1,7 @@ +[KNewStuff3] +ProvidersUrl=https://share.krita.org/ocs/providers.xml +Categories=Krita Pattern +XdgTargetDir=krita/patterns +Uncompress=never + + diff --git a/plugins/extensions/resourcemanager/data/kritapresets.knsrc b/plugins/extensions/resourcemanager/data/kritapresets.knsrc new file mode 100644 index 0000000000..f9b955c046 --- /dev/null +++ b/plugins/extensions/resourcemanager/data/kritapresets.knsrc @@ -0,0 +1,8 @@ +[KNewStuff3] +ProvidersUrl=https://share.krita.org/ocs/providers.xml +Categories=Krita Preset +XdgTargetDir=krita/paintoppresets +Uncompress=never + + + diff --git a/plugins/extensions/resourcemanager/dlg_content_downloader.cpp b/plugins/extensions/resourcemanager/dlg_content_downloader.cpp index e69de29bb2..d975896ad3 100644 --- a/plugins/extensions/resourcemanager/dlg_content_downloader.cpp +++ b/plugins/extensions/resourcemanager/dlg_content_downloader.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2016 Aniketh Girish anikethgireesh@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include + +#include "dlg_content_downloader.h" + +class KNSResourceDownloader::Private +{ +public: + Private() : {} + const QString knsrc; + KoResourceServer m_resourcesServer; +}; + +KNSResourceDownloader::KNSResourceDownloader(const KNSCore::EntryInternal& entry, const KNSCore::Author& author, QStringList categories, QObject* parent) + : KoResourceServer(parent) + , m_categories(std::move(categories)) + , m_author(author) + , m_entry(entry) + , d( new Private(this) ) +{ + const QString fileName = QFileInfo(d->knsrc).fileName(); + setName(fileName); + setObjectName(d->knsrc); + + m_categories = QStringList{ fileName }; +} + +KNSResourceDownloader::~KNSResourceDownloader() +{ + delete d; +} + +//Need to see which is need the name or the packageName. + +QString KNSResourceDownloader::name() +{ + return m_entry.name(); +} + +QString KNSResourceDownloader::packagename() +{ + return m_entry.uniqueId(); +} + +QString KNSResourceDownloader::author() +{ + return m_author.name(); +} + +QStringList KNSResourceDownloader::categories() +{ + return m_categories; +} + +int KNSResourceDownloader::downloadcount() +{ + const auto downloadInfo = m_entry.downloadLinkInformationList(); + return downloadInfo.isEmpty() ? 0 : downloadInfo.at(0).size; +} + +QString KNSResourceDownloader::source() +{ + return m_entry.providerId(); +} + +QString KNSResourceDownloader::license() +{ + return m_entry.license(); +} + +QString KNSResourceDownloader::details() +{ + QString ret = m_entry.summary(); + if (m_entry.shortSummary().isEmpty()) { //ret.isEmpty() ?? + const int newLine = ret.indexOf(QLatin1Char('\n')); + if (newLine < 0) + ret.clear(); + else + ret = ret.mid(newLine+1).trimmed(); + } + ret = ret.replace(QLatin1Char('\r'), QString()); + ret = ret.replace(QStringLiteral("[li]"), QStringLiteral("\n* ")); + ret = ret.replace(QRegularExpression(QStringLiteral("\\[/?[a-z]*\\]")), QString()); + return ret; +} + +void KNSResourceDownloader::downloadResources(KoResourceServer *app) +{ + KNS3::DownloadWidget dialog(d->knsrc, this); + dialog.exec(); + + foreach (const KNS3::Entry& e, dialog.changedEntries()) { + + foreach (const QString &file, e.installedFiles()) { + QFileInfo fi(file); + d->m_resourcesServer.importResourceFile(fi.absolutePath()+'/'+fi.fileName() , false); //need to rewrite according to MVC. + } + + foreach (const QString &file, e.uninstalledFiles()) { + QFileInfo fi(file); + d->m_resourcesServer.removeResourceFile(fi.absolutePath()+'/'+fi.fileName()); //need to rewrite according to MVC. + } + + } + + +} + +void KNSResourceDownloader::setKnsrcFile(const QString &knsrcFileArg) +{ + d->knsrc = knsrcFileArg; +} + + +KoResourceServer * KNSResourceDownloader::koresourceserver() const +{ + return qobject_cast(parent()); +} + +KNSCore::EntryInternal KNSResourceDownloader::entry() const +{ + return m_entry; +} diff --git a/plugins/extensions/resourcemanager/dlg_content_downloader.h b/plugins/extensions/resourcemanager/dlg_content_downloader.h index d8bf9baae2..2339fac708 100644 --- a/plugins/extensions/resourcemanager/dlg_content_downloader.h +++ b/plugins/extensions/resourcemanager/dlg_content_downloader.h @@ -1,4 +1,86 @@ +/* + * Copyright (c) 2016 Aniketh Girish anikethgireesh@gmail.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ #ifndef DLG_CONTENT_DOWNLOADER_H #define DLG_CONTENT_DOWNLOADER_H +#include + +#include //The backend for resource selection + +//KNS Includes + +#include +#include +#include + +class Private; +class KNSResourceDownloader: public KoResourceServer +{ +Q_OBJECT +public: + explicit KNSResourceDownloader(const KNSCore::EntryInternal & c, const KNSCore::Author & a, QStringList categories, const QString &knsrc, QObject* parent); + ~KNSResourceDownloader(); + + // KoResourceServer::state state() override; this is to verify the state of the content. need to implement, ie, enumaration stating that if the package is downloading, processing etc. + + QString name() override; + QString packagename() const override; // Have a doubt if name() and this isn't similar? KNSCore issue + +// QVariant icon() const override; + + QString author() override; + QStringList categories() override; //Need to implement. No idea yet. + int downloadcount() override; //no of downloads done + QString source() override; //orgin / providerID + QString license() override; + QString details() override; //Long description + +// QString iconName() const { return m_iconName; } + + void downloadResources(KoResourceServer* app) override; + +// void removeResources(KoResourceServer* res) override; + + void setKnsrcFile(const QString& knsrcFileArg) override; + +// QUrl thumbnailUrl() override; // If needed. +// QUrl screenshotUrl() override; // If needed. +// void fetchScreenshots() override; //if needed. + + KoResourceServer* koresourceserver() const; + + KNSCore::EntryInternal entry() const; + KNSCore::Engine* engine() const { return m_engine; } + +private: + const QStringList m_categories; +// QString m_iconName; + + KNSCore::EntryInternal m_entry; + KNSCore::Author m_author; + KNSCore::Engine* m_engine; + + class Private; + + Private * const d; + +}; + + #endif // DLG_CONTENT_DOWNLOADER_H diff --git a/plugins/extensions/resourcemanager/dlg_content_downloader_backend.cpp b/plugins/extensions/resourcemanager/dlg_content_downloader_backend.cpp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/plugins/extensions/resourcemanager/dlg_content_downloader_backend.h b/plugins/extensions/resourcemanager/dlg_content_downloader_backend.h deleted file mode 100644 index 634cab75c8..0000000000 --- a/plugins/extensions/resourcemanager/dlg_content_downloader_backend.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef DLG_CONTENT_DOWNLOADER_BACKEND_H -#define DLG_CONTENT_DOWNLOADER_BACKEND_H - -#endif // DLG_CONTENT_DOWNLOADER_BACKEND_H diff --git a/plugins/extensions/resourcemanager/wdgdlgcontentdownloader.ui b/plugins/extensions/resourcemanager/wdgdlgcontentdownloader.ui deleted file mode 100644 index e69de29bb2..0000000000