File indexing completed on 2024-05-05 17:33:22

0001 /*
0002  *   SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 
0011 #include "Review.h"
0012 #include "ReviewsModel.h"
0013 class Rating;
0014 class AbstractResource;
0015 
0016 class DISCOVERCOMMON_EXPORT AbstractReviewsBackend : public QObject
0017 {
0018     Q_OBJECT
0019     Q_PROPERTY(bool isReviewable READ isReviewable CONSTANT)
0020     Q_PROPERTY(bool supportsNameChange READ supportsNameChange CONSTANT)
0021     Q_PROPERTY(bool hasCredentials READ hasCredentials)
0022     Q_PROPERTY(QString preferredUserName READ preferredUserName NOTIFY preferredUserNameChanged)
0023     Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
0024 public:
0025     explicit AbstractReviewsBackend(QObject *parent = nullptr);
0026 
0027     virtual bool hasCredentials() const = 0;
0028 
0029     Q_SCRIPTABLE virtual Rating *ratingForApplication(AbstractResource *app) const = 0;
0030     Q_INVOKABLE virtual QString errorMessage() const;
0031     Q_INVOKABLE virtual bool isResourceSupported(AbstractResource *res) const = 0;
0032     virtual bool isFetching() const = 0;
0033     virtual bool isReviewable() const;
0034     virtual bool supportsNameChange() const;
0035 
0036 public Q_SLOTS:
0037     virtual void login() = 0;
0038     virtual void registerAndLogin() = 0;
0039     virtual void logout() = 0;
0040     virtual void submitUsefulness(Review *r, bool useful) = 0;
0041     // About all the different "user_names": the user_name that is taken as input here
0042     // is the user_name the user typed in the review dialog, which defaults to what
0043     // the backend returns in userName() or the last username used
0044     // if the backend supports changing it (that is what the preferredUserName is).
0045     // If the backend returns true for "supportsNameChange()", then the review dialog won't let them change it,
0046     // therefore making the user_name here the same as "userName()".
0047     void submitReview(AbstractResource *app, const QString &summary, const QString &review_text, const QString &rating, const QString &userName);
0048     QString preferredUserName() const;
0049     virtual void deleteReview(Review *r) = 0;
0050     virtual void flagReview(Review *r, const QString &reason, const QString &text) = 0;
0051     virtual void fetchReviews(AbstractResource *app, int page = 1) = 0;
0052 
0053 Q_SIGNALS:
0054     void reviewsReady(AbstractResource *app, const QVector<ReviewPtr> &reviews, bool canFetchMore);
0055     void error(const QString &message);
0056     void fetchingChanged(bool fetching);
0057     void preferredUserNameChanged();
0058     void errorMessageChanged();
0059 
0060 protected:
0061     virtual void sendReview(AbstractResource *app, const QString &summary, const QString &review_text, const QString &rating, const QString &userName) = 0;
0062     virtual QString userName() const = 0;
0063 };