File indexing completed on 2024-11-17 04:55:37
0001 /* 0002 * SPDX-FileCopyrightText: 2013 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 #include "DummyReviewsBackend.h" 0008 #include "DummyBackend.h" 0009 #include "DummyResource.h" 0010 #include <QDebug> 0011 #include <QRandomGenerator> 0012 #include <QTimer> 0013 #include <ReviewsBackend/Rating.h> 0014 #include <ReviewsBackend/Review.h> 0015 #include <resources/AbstractResource.h> 0016 0017 DummyReviewsBackend::DummyReviewsBackend(DummyBackend *parent) 0018 : AbstractReviewsBackend(parent) 0019 { 0020 } 0021 0022 DummyReviewsBackend::~DummyReviewsBackend() noexcept 0023 { 0024 qDeleteAll(m_ratings); 0025 } 0026 0027 void DummyReviewsBackend::fetchReviews(AbstractResource *resource, int page) 0028 { 0029 if (page >= 5) { 0030 return; 0031 } 0032 0033 QVector<ReviewPtr> review; 0034 for (int i = 0; i < 33; i++) { 0035 review += ReviewPtr(new Review(resource->name(), 0036 resource->packageName(), 0037 QStringLiteral("en_US"), 0038 QStringLiteral("good morning"), 0039 QStringLiteral("the morning is very good"), 0040 QStringLiteral("dummy"), 0041 QDateTime(), 0042 true, 0043 page + i, 0044 i % 5, 0045 1, 0046 1, 0047 3, 0048 resource->packageName())); 0049 } 0050 Q_EMIT reviewsReady(resource, review, false); 0051 } 0052 0053 Rating *DummyReviewsBackend::ratingForApplication(AbstractResource *resource) const 0054 { 0055 return m_ratings[resource]; 0056 } 0057 0058 void DummyReviewsBackend::initialize() 0059 { 0060 int i = 11; 0061 const auto backend = qobject_cast<DummyBackend *>(parent()); 0062 const auto resources = backend->resources(); 0063 for (const auto resource : resources) { 0064 if (m_ratings.contains(resource)) { 0065 continue; 0066 } 0067 0068 int ratings[] = {0, 0, 0, 0, 0, QRandomGenerator::global()->bounded(0, 10)}; 0069 auto rating = new Rating(resource->packageName(), ++i, ratings); 0070 m_ratings.insert(resource, rating); 0071 Q_EMIT resource->ratingFetched(); 0072 } 0073 Q_EMIT ratingsReady(); 0074 } 0075 0076 void DummyReviewsBackend::submitUsefulness(Review *review, bool useful) 0077 { 0078 qDebug() << "usefulness..." << review->applicationName() << review->reviewer() << useful; 0079 review->setUsefulChoice(useful ? ReviewsModel::Yes : ReviewsModel::No); 0080 } 0081 0082 void DummyReviewsBackend::sendReview(AbstractResource *resource, 0083 const QString &summary, 0084 const QString &reviewText, 0085 const QString &rating, 0086 const QString &userName) 0087 { 0088 qDebug() << "dummy submit review" << resource->name() << summary << reviewText << rating << userName; 0089 } 0090 0091 bool DummyReviewsBackend::isResourceSupported(AbstractResource *resource) const 0092 { 0093 Q_UNUSED(resource) 0094 return true; 0095 }