File indexing completed on 2024-11-10 09:42:32
0001 /* 0002 SPDX-FileCopyrightText: 2010 Frederik Gladhorn <gladhorn@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef KNEWSTUFF3_ATTICAHELPER_P_H 0008 #define KNEWSTUFF3_ATTICAHELPER_P_H 0009 0010 #include <QStringList> 0011 0012 #include <attica/provider.h> 0013 #include <attica/providermanager.h> 0014 0015 #include <attica/category.h> 0016 #include <attica/content.h> 0017 #include <attica/license.h> 0018 0019 #include "knewstuffcore_export.h" 0020 0021 class KJob; 0022 0023 namespace KNSCore 0024 { 0025 class HTTPJob; 0026 /** 0027 * @short Upload helper for Attica based providers 0028 * 0029 * Use this class to help you build upload functionality into applications 0030 * which do not fit the KNS3::UploadDialog use case, such as situations where 0031 * you have to fit the uploading into the middle of another workflow. 0032 * 0033 * As uploading is not entirely trivial, we suggest you look at the code in 0034 * uploaddialog.cpp to see an example of an actual implementation. 0035 * 0036 * @see KNS3::UploadDialog 0037 */ 0038 class KNEWSTUFFCORE_EXPORT AtticaHelper : public QObject 0039 { 0040 Q_OBJECT 0041 public: 0042 explicit AtticaHelper(QObject *parent = nullptr); 0043 void init(); 0044 0045 void setCurrentProvider(const QString &provider); 0046 void addProviderFile(const QUrl &file); 0047 0048 Attica::Provider provider(); 0049 0050 void checkLogin(const QString &name, const QString &password); 0051 bool loadCredentials(QString &name, QString &password); 0052 bool saveCredentials(const QString &name, const QString &password); 0053 void loadCategories(const QStringList &configuredCategories); 0054 void loadContentByCurrentUser(); 0055 void loadLicenses(); 0056 void loadDetailsLink(const QString &contentId); 0057 void loadContent(const QString &contentId); 0058 void loadCurrency(); 0059 void loadPreviews(const QString &contentId); 0060 0061 Q_SIGNALS: 0062 void loginChecked(bool); 0063 void providersLoaded(const QStringList &); 0064 void categoriesLoaded(Attica::Category::List); 0065 void contentByCurrentUserLoaded(const Attica::Content::List &); 0066 void licensesLoaded(const Attica::License::List &); 0067 void detailsLinkLoaded(const QUrl &); 0068 void contentLoaded(const Attica::Content &); 0069 void currencyLoaded(const QString &); 0070 void previewLoaded(int index, const QImage &image); 0071 0072 private Q_SLOTS: 0073 void checkLoginFinished(Attica::BaseJob *baseJob); 0074 void defaultProvidersLoaded(); 0075 void categoriesLoaded(Attica::BaseJob *baseJob); 0076 void contentByCurrentUserLoaded(Attica::BaseJob *baseJob); 0077 void licensesLoaded(Attica::BaseJob *baseJob); 0078 void detailsLinkLoaded(Attica::BaseJob *baseJob); 0079 void contentLoaded(Attica::BaseJob *baseJob); 0080 void currencyLoaded(Attica::BaseJob *baseJob); 0081 0082 void slotPreviewData(KJob *job, const QByteArray &buf); 0083 void slotPreviewDownload(KJob *job); 0084 0085 private: 0086 Attica::ProviderManager providerManager; 0087 Attica::Provider currentProvider; 0088 Attica::Category::List m_validCategories; 0089 0090 QString m_username; 0091 QStringList m_configuredCategories; 0092 Attica::Content::List m_userCreatedContent; 0093 0094 QByteArray m_previewBuffer[3]; 0095 HTTPJob *m_previewJob[3]; 0096 0097 Q_DISABLE_COPY(AtticaHelper) 0098 }; 0099 } 0100 0101 #endif