1
/***************************************************************************
2
* Copyright © 2011 Jonathan Thomas <echidnaman@kubuntu.org> *
4
* This program is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU General Public License as *
6
* published by the Free Software Foundation; either version 2 of *
7
* the License or (at your option) version 3 or any later version *
8
* accepted by the membership of KDE e.V. (or its successor approved *
9
* by the membership of KDE e.V.), which shall act as a proxy *
10
* defined in Section 14 of version 3 of the license. *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
19
***************************************************************************/
21
#include "ReviewWidget.h"
23
#include <QtCore/QStringBuilder>
24
#include <QtGui/QHBoxLayout>
25
#include <QtGui/QLabel>
29
#include <Nepomuk/KRatingWidget>
31
#include <LibQApt/Package>
33
#include <ReviewsBackend/Review.h>
35
ReviewWidget::ReviewWidget(QWidget *parent)
38
QWidget *headerWidget = new QWidget(this);
39
QHBoxLayout *headerLayout = new QHBoxLayout(headerWidget);
40
headerLayout->setMargin(0);
41
headerWidget->setLayout(headerLayout);
43
m_ratingWidget = new KRatingWidget(headerWidget);
44
m_ratingWidget->setAttribute(Qt::WA_TransparentForMouseEvents);
45
m_ratingWidget->setPixmapSize(16);
46
m_summaryLabel = new QLabel(headerWidget);
47
QWidget *headerSpacer = new QWidget(headerWidget);
48
headerSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
49
m_nameDateLabel = new QLabel(headerWidget);
50
m_nameDateLabel->setEnabled(false);
52
headerLayout->addWidget(m_ratingWidget);
53
headerLayout->addWidget(m_summaryLabel);
54
headerLayout->addWidget(headerSpacer);
55
headerLayout->addWidget(m_nameDateLabel);
57
m_reviewLabel = new QLabel(this);
58
m_reviewLabel->setWordWrap(true);
60
m_versionLabel = new QLabel(this);
61
m_versionLabel->setEnabled(false);
62
m_versionLabel->hide();
64
QWidget *usefulnessWidget = new QWidget(this);
65
QHBoxLayout *usefulnessLayout = new QHBoxLayout(usefulnessWidget);
66
usefulnessLayout->setMargin(0);
67
usefulnessWidget->setLayout(usefulnessLayout);
69
m_usefulnessLabel = new QLabel(usefulnessWidget);
70
// TODO: Report usefulness/inappropriateness once submitting works
72
usefulnessLayout->addWidget(m_usefulnessLabel);
75
ReviewWidget::~ReviewWidget()
79
void ReviewWidget::setReview(Review *review)
81
if (!review->package())
84
m_ratingWidget->setRating(review->rating());
86
m_summaryLabel->setText(QLatin1Literal("<b>") % review->summary()
87
% QLatin1Literal("</b>"));
89
QString date = KGlobal::locale()->formatDate(review->creationDate().date(), KLocale::ShortDate);
90
m_nameDateLabel->setText(i18nc("@label Formatted: username, date",
92
review->reviewer(), date));
94
m_reviewLabel->setText(review->reviewText());
96
const QString reviewUpstream = QApt::Package::upstreamVersion(review->packageVersion());
97
const QString currentUpstream = review->package()->upstreamVersion();
99
int res = QApt::Package::compareVersion(reviewUpstream, currentUpstream);
102
m_versionLabel->setText(QLatin1Literal("<i>") %
103
i18nc("@label", "This review was written for an older version "
104
"(Version: %1)", review->packageVersion()) %
105
QLatin1Literal("</i>"));
106
m_versionLabel->show();
109
if (review->usefulnessTotal()) {
110
m_usefulnessLabel->setText(i18ncp("@label", "%1 out of %2 person found this review useful",
111
"%1 out of %2 people found this review useful",
112
review->usefulnessFavorable(), review->usefulnessTotal()));
116
#include "ReviewWidget.moc"