diff --git a/src/core/provider.cpp b/src/core/provider.cpp index b904130a..8ce80f83 100644 --- a/src/core/provider.cpp +++ b/src/core/provider.cpp @@ -1,57 +1,71 @@ /* knewstuff3/provider.cpp Copyright (c) 2002 Cornelius Schumacher Copyright (c) 2003 - 2007 Josef Spillner Copyright (c) 2009 Jeremy Whiting Copyright (C) 2009 Frederik Gladhorn 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, see . */ #include "provider.h" #include "xmlloader.h" #include namespace KNSCore { QString Provider::SearchRequest::hashForRequest() const { return QString(QString::number((int)sortMode) + ',' + searchTerm + ',' + categories.join(QString('-')) + ',' + QString::number(page) + ',' + QString::number(pageSize)); } Provider::Provider() {} Provider::~Provider() {} QString Provider::name() const { return mName; } QUrl Provider::icon() const { return mIcon; } +QDebug operator<<(QDebug dbg, const Provider::SearchRequest & search) +{ + QDebugStateSaver saver(dbg); + dbg.nospace(); + dbg << "Provider::SearchRequest("; + dbg << "searchTerm: " << search.searchTerm << ','; + dbg << "categories: " << search.categories << ','; + dbg << "filter: " << search.filter << ','; + dbg << "page: " << search.page << ','; + dbg << "pageSize: " << search.pageSize; + dbg << ')'; + return dbg; +} + } diff --git a/src/core/provider.h b/src/core/provider.h index 7cc8d91d..9fc90962 100644 --- a/src/core/provider.h +++ b/src/core/provider.h @@ -1,188 +1,190 @@ /* knewstuff3/provider.h This file is part of KNewStuff2. Copyright (c) 2009 Jeremy Whiting Copyright (C) 2009 Frederik Gladhorn 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, see . */ #ifndef KNEWSTUFF3_PROVIDER_P_H #define KNEWSTUFF3_PROVIDER_P_H #include #include #include #include "entryinternal.h" #include "knewstuffcore_export.h" class KJob; namespace KNSCore { /** * @short KNewStuff Base Provider class. * * This class provides accessors for the provider object. * It should not be used directly by the application. * This class is the base class and will be instantiated for * static website providers. * * @author Jeremy Whiting * * @internal */ class KNEWSTUFFCORE_EXPORT Provider: public QObject { Q_OBJECT public: typedef QList List; enum SortMode { Newest, Alphabetical, Rating, Downloads, }; Q_ENUM(SortMode) enum Filter { None, Installed, Updates, ExactEntryId }; Q_ENUM(Filter) /** * used to keep track of a search */ struct SearchRequest { SortMode sortMode; Filter filter; QString searchTerm; QStringList categories; int page; int pageSize; SearchRequest(SortMode sortMode_ = Newest, Filter filter_ = None, const QString &searchTerm_ = QString(), const QStringList &categories_ = QStringList(), int page_ = -1, int pageSize_ = 20) : sortMode(sortMode_), filter(filter_), searchTerm(searchTerm_), categories(categories_), page(page_), pageSize(pageSize_) {} QString hashForRequest() const; }; /** * Describes a category: id/name/disaplayName */ struct CategoryMetadata { QString id; QString name; QString displayName; }; /** * Constructor. */ Provider(); /** * Destructor. */ virtual ~Provider(); /** * A unique Id for this provider (the url in most cases) */ virtual QString id() const = 0; /** * Set the provider data xml, to initialize the provider. * The Provider needs to have it's ID set in this function and cannot change it from there on. */ virtual bool setProviderXML(const QDomElement &xmldata) = 0; virtual bool isInitialized() const = 0; virtual void setCachedEntries(const KNSCore::EntryInternal::List &cachedEntries) = 0; /** * Retrieves the common name of the provider. * * @return provider name */ virtual QString name() const; /** * Retrieves the icon URL for this provider. * * @return icon URL */ virtual QUrl icon() const; // FIXME use QIcon::fromTheme or pixmap? /** * load the given search and return given page * @param sortMode string to select the order in which the results are presented * @param searchstring string to search with * @param page page number to load * * Note: the engine connects to loadingFinished() signal to get the result */ virtual void loadEntries(const KNSCore::Provider::SearchRequest &request) = 0; virtual void loadEntryDetails(const KNSCore::EntryInternal &) {} virtual void loadPayloadLink(const EntryInternal &entry, int linkId) = 0; virtual bool userCanVote() { return false; } virtual void vote(const EntryInternal &entry, uint rating) { Q_UNUSED(entry) Q_UNUSED(rating) } virtual bool userCanBecomeFan() { return false; } virtual void becomeFan(const EntryInternal &entry) { Q_UNUSED(entry) } Q_SIGNALS: void providerInitialized(KNSCore::Provider *); void loadingFinished(const KNSCore::Provider::SearchRequest &, const KNSCore::EntryInternal::List &) const; void loadingFailed(const KNSCore::Provider::SearchRequest &); void entryDetailsLoaded(const KNSCore::EntryInternal &); void payloadLinkLoaded(const KNSCore::EntryInternal &); void signalInformation(const QString &) const; void signalError(const QString &) const; void categoriesMetadataLoded(const QList &categories); protected: QString mName; QUrl mIcon; private: Q_DISABLE_COPY(Provider) }; + +KNEWSTUFFCORE_EXPORT QDebug operator<<(QDebug, const Provider::SearchRequest &); } #endif