~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to installer/ReviewsWidget/ReviewWidget.cpp

Tags: upstream-1.3.65
Import upstream version 1.3.65

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright © 2011 Jonathan Thomas <echidnaman@kubuntu.org>             *
 
3
 *                                                                         *
 
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.                    *
 
11
 *                                                                         *
 
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.                          *
 
16
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "ReviewWidget.h"
 
22
 
 
23
#include <QtCore/QStringBuilder>
 
24
#include <QtGui/QHBoxLayout>
 
25
#include <QtGui/QLabel>
 
26
 
 
27
#include <KGlobal>
 
28
#include <KLocale>
 
29
#include <Nepomuk/KRatingWidget>
 
30
 
 
31
#include <LibQApt/Package>
 
32
 
 
33
#include <ReviewsBackend/Review.h>
 
34
 
 
35
ReviewWidget::ReviewWidget(QWidget *parent)
 
36
        : KVBox(parent)
 
37
{
 
38
    QWidget *headerWidget = new QWidget(this);
 
39
    QHBoxLayout *headerLayout = new QHBoxLayout(headerWidget);
 
40
    headerLayout->setMargin(0);
 
41
    headerWidget->setLayout(headerLayout);
 
42
 
 
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);
 
51
 
 
52
    headerLayout->addWidget(m_ratingWidget);
 
53
    headerLayout->addWidget(m_summaryLabel);
 
54
    headerLayout->addWidget(headerSpacer);
 
55
    headerLayout->addWidget(m_nameDateLabel);
 
56
 
 
57
    m_reviewLabel = new QLabel(this);
 
58
    m_reviewLabel->setWordWrap(true);
 
59
 
 
60
    m_versionLabel = new QLabel(this);
 
61
    m_versionLabel->setEnabled(false);
 
62
    m_versionLabel->hide();
 
63
 
 
64
    QWidget *usefulnessWidget = new QWidget(this);
 
65
    QHBoxLayout *usefulnessLayout = new QHBoxLayout(usefulnessWidget);
 
66
    usefulnessLayout->setMargin(0);
 
67
    usefulnessWidget->setLayout(usefulnessLayout);
 
68
 
 
69
    m_usefulnessLabel = new QLabel(usefulnessWidget);
 
70
    // TODO: Report usefulness/inappropriateness once submitting works
 
71
 
 
72
    usefulnessLayout->addWidget(m_usefulnessLabel);
 
73
}
 
74
 
 
75
ReviewWidget::~ReviewWidget()
 
76
{
 
77
}
 
78
 
 
79
void ReviewWidget::setReview(Review *review)
 
80
{
 
81
    if (!review->package())
 
82
        return;
 
83
 
 
84
    m_ratingWidget->setRating(review->rating());
 
85
 
 
86
    m_summaryLabel->setText(QLatin1Literal("<b>") % review->summary()
 
87
                            % QLatin1Literal("</b>"));
 
88
 
 
89
    QString date = KGlobal::locale()->formatDate(review->creationDate().date(), KLocale::ShortDate);
 
90
    m_nameDateLabel->setText(i18nc("@label Formatted: username, date",
 
91
                                   "%1, %2",
 
92
                                   review->reviewer(), date));
 
93
 
 
94
    m_reviewLabel->setText(review->reviewText());
 
95
 
 
96
    const QString reviewUpstream = QApt::Package::upstreamVersion(review->packageVersion());
 
97
    const QString currentUpstream = review->package()->upstreamVersion();
 
98
 
 
99
    int res = QApt::Package::compareVersion(reviewUpstream, currentUpstream);
 
100
 
 
101
    if (res < 0) {
 
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();
 
107
    }
 
108
 
 
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()));
 
113
    }
 
114
}
 
115
 
 
116
#include "ReviewWidget.moc"