2
Copyright (C) 2009 Frederik Gladhorn <gladhorn@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public
15
License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
#include "entrydetailsdialog_p.h"
22
#include <klocalizedstring.h>
24
#include "core/engine_p.h"
25
#include "ui/imageloader_p.h"
26
#include <attica/provider.h>
30
EntryDetails::EntryDetails(Engine *engine, Ui::DownloadWidget *widget)
31
: QObject(widget->m_listView), m_engine(engine), ui(widget)
36
EntryDetails::~EntryDetails()
40
void EntryDetails::init()
42
connect(ui->preview1, SIGNAL(clicked()), this, SLOT(preview1Selected()));
43
connect(ui->preview2, SIGNAL(clicked()), this, SLOT(preview2Selected()));
44
connect(ui->preview3, SIGNAL(clicked()), this, SLOT(preview3Selected()));
46
ui->ratingWidget->setMaxRating(10);
47
ui->ratingWidget->setHalfStepsEnabled(true);
50
connect(ui->installButton, SIGNAL(clicked()), this, SLOT(install()));
51
connect(ui->uninstallButton, SIGNAL(clicked()), this, SLOT(uninstall()));
52
// updating is the same as installing
53
connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(install()));
54
connect(ui->becomeFanButton, SIGNAL(clicked()), this, SLOT(becomeFan()));
56
ui->installButton->setIcon(QIcon::fromTheme("dialog-ok"));
57
ui->updateButton->setIcon(QIcon::fromTheme("system-software-update"));
58
ui->uninstallButton->setIcon(QIcon::fromTheme("edit-delete"));
60
connect(m_engine, SIGNAL(signalEntryDetailsLoaded(KNS3::EntryInternal)),
61
this, SLOT(entryChanged(KNS3::EntryInternal)));
62
connect(m_engine, SIGNAL(signalEntryChanged(KNS3::EntryInternal)),
63
this, SLOT(entryStatusChanged(KNS3::EntryInternal)));
64
connect(m_engine, SIGNAL(signalEntryPreviewLoaded(KNS3::EntryInternal,KNS3::EntryInternal::PreviewType)),
65
this, SLOT(slotEntryPreviewLoaded(KNS3::EntryInternal,KNS3::EntryInternal::PreviewType)));
68
void EntryDetails::setEntry(const KNS3::EntryInternal &entry)
71
// immediately show something
72
entryChanged(m_entry);
73
// fetch more preview images
74
m_engine->loadDetails(m_entry);
77
void EntryDetails::entryChanged(const KNS3::EntryInternal &entry)
79
if (ui->detailsStack->currentIndex() == 0) {
85
//ui->ratingWidget->setEditable(m_engine->userCanVote(m_entry));
87
if (!m_engine->userCanBecomeFan(m_entry)) {
88
ui->becomeFanButton->setEnabled(false);
91
ui->m_titleWidget->setText(i18n("Details for %1", m_entry.name()));
92
if (!m_entry.author().homepage().isEmpty()) {
93
ui->authorLabel->setText("<a href=\"" + m_entry.author().homepage() + "\">" + m_entry.author().name() + "</a>");
94
} else if (!m_entry.author().email().isEmpty()) {
95
ui->authorLabel->setText("<a href=\"mailto:" + m_entry.author().email() + "\">" + m_entry.author().name() + "</a>");
97
ui->authorLabel->setText(m_entry.author().name());
100
QString summary = replaceBBCode(m_entry.summary()).replace("\n", "<br/>");
101
QString changelog = replaceBBCode(m_entry.changelog()).replace("\n", "<br/>");
103
QString description = "<html><body>" + summary;
104
if (!changelog.isEmpty()) {
105
description += "<br/><p><b>" + i18n("Changelog:") + "</b><br/>" + changelog + "</p>";
107
description += "</body></html>";
108
ui->descriptionLabel->setText(description);
110
QString homepageText("<a href=\"" + m_entry.homepage().url() + "\">" +
111
i18nc("A link to the description of this Get Hot New Stuff item", "Homepage") + "</a>");
113
if (!m_entry.donationLink().isEmpty()) {
114
homepageText += "<br><a href=\"" + m_entry.donationLink() + "\">" + i18nc("A link to make a donation for a Get Hot New Stuff item (opens a web browser)", "Make a donation") + "</a>";
116
if (!m_entry.knowledgebaseLink().isEmpty()) {
117
homepageText += "<br><a href=\"" + m_entry.knowledgebaseLink() + "\">"
118
+ i18ncp("A link to the knowledgebase (like a forum) (opens a web browser)", "Knowledgebase (no entries)", "Knowledgebase (%1 entries)", m_entry.numberKnowledgebaseEntries()) + "</a>";
120
ui->homepageLabel->setText(homepageText);
121
ui->homepageLabel->setToolTip(i18nc("Tooltip for a link in a dialog", "Opens in a browser window"));
123
if (m_entry.rating() > 0) {
124
ui->ratingWidget->setVisible(true);
125
disconnect(ui->ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingChanged(uint)));
126
// Most of the voting is 20 - 80, so rate 20 as 0 stars and 80 as 5 stars
127
int rating = qMax(0, qMin(10, (m_entry.rating() - 20) / 6));
128
ui->ratingWidget->setRating(rating);
129
connect(ui->ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingChanged(uint)));
131
ui->ratingWidget->setVisible(false);
134
bool hideSmallPreviews = m_entry.previewUrl(EntryInternal::PreviewSmall2).isEmpty()
135
&& m_entry.previewUrl(EntryInternal::PreviewSmall3).isEmpty();
137
ui->preview1->setVisible(!hideSmallPreviews);
138
ui->preview2->setVisible(!hideSmallPreviews);
139
ui->preview3->setVisible(!hideSmallPreviews);
141
// in static xml we often only get a small preview, use that in details
142
if (m_entry.previewUrl(EntryInternal::PreviewBig1).isEmpty() && !m_entry.previewUrl(EntryInternal::PreviewSmall1).isEmpty()) {
143
m_entry.setPreviewUrl(m_entry.previewUrl(EntryInternal::PreviewSmall1), EntryInternal::PreviewBig1);
144
m_entry.setPreviewImage(m_entry.previewImage(EntryInternal::PreviewSmall1), EntryInternal::PreviewBig1);
147
for (int type = EntryInternal::PreviewSmall1; type <= EntryInternal::PreviewBig3; ++type) {
148
if (m_entry.previewUrl(EntryInternal::PreviewSmall1).isEmpty()) {
149
ui->previewBig->setVisible(false);
152
if (!m_entry.previewUrl((EntryInternal::PreviewType)type).isEmpty()) {
153
// qDebug() << "type: " << type << m_entry.previewUrl((EntryInternal::PreviewType)type);
154
if (m_entry.previewImage((EntryInternal::PreviewType)type).isNull()) {
155
m_engine->loadPreview(m_entry, (EntryInternal::PreviewType)type);
157
slotEntryPreviewLoaded(m_entry, (EntryInternal::PreviewType)type);
165
void EntryDetails::entryStatusChanged(const KNS3::EntryInternal &entry)
171
void EntryDetails::updateButtons()
173
if (ui->detailsStack->currentIndex() == 0) {
176
// qDebug() << "update buttons: " << m_entry.status();
177
ui->installButton->setVisible(false);
178
ui->uninstallButton->setVisible(false);
179
ui->updateButton->setVisible(false);
181
switch (m_entry.status()) {
182
case Entry::Installed:
183
ui->uninstallButton->setVisible(true);
184
ui->uninstallButton->setEnabled(true);
186
case Entry::Updateable:
187
ui->updateButton->setVisible(true);
188
ui->updateButton->setEnabled(true);
189
ui->uninstallButton->setVisible(true);
190
ui->uninstallButton->setEnabled(true);
194
case Entry::Downloadable:
195
ui->installButton->setVisible(true);
196
ui->installButton->setEnabled(true);
199
case Entry::Installing:
200
ui->installButton->setVisible(true);
201
ui->installButton->setEnabled(false);
203
case Entry::Updating:
204
ui->updateButton->setVisible(true);
205
ui->updateButton->setEnabled(false);
206
ui->uninstallButton->setVisible(true);
207
ui->uninstallButton->setEnabled(false);
210
ui->installButton->setVisible(true);
211
ui->installButton->setEnabled(true);
215
if (ui->installButton->menu()) {
216
QMenu *buttonMenu = ui->installButton->menu();
218
ui->installButton->setMenu(0);
219
buttonMenu->deleteLater();
221
if (ui->installButton->isVisible() && m_entry.downloadLinkCount() > 1) {
222
QMenu *installMenu = new QMenu(ui->installButton);
223
foreach (EntryInternal::DownloadLinkInformation info, m_entry.downloadLinkInformationList()) {
224
QString text = info.name;
225
if (!info.distributionType.trimmed().isEmpty()) {
226
text + " (" + info.distributionType.trimmed() + ")";
228
QAction *installAction = installMenu->addAction(QIcon::fromTheme("dialog-ok"), text);
229
installAction->setData(info.id);
231
// qDebug() << "links: " << m_entry.downloadLinkInformationList().size();
232
ui->installButton->setMenu(installMenu);
236
void EntryDetails::install()
238
m_engine->install(m_entry);
241
void EntryDetails::uninstall()
243
m_engine->uninstall(m_entry);
246
void EntryDetails::slotEntryPreviewLoaded(const KNS3::EntryInternal &entry, KNS3::EntryInternal::PreviewType type)
248
if (!(entry == m_entry)) {
253
case EntryInternal::PreviewSmall1:
254
ui->preview1->setImage(entry.previewImage(EntryInternal::PreviewSmall1));
256
case EntryInternal::PreviewSmall2:
257
ui->preview2->setImage(entry.previewImage(EntryInternal::PreviewSmall2));
259
case EntryInternal::PreviewSmall3:
260
ui->preview3->setImage(entry.previewImage(EntryInternal::PreviewSmall3));
262
case EntryInternal::PreviewBig1:
263
m_currentPreview = entry.previewImage(EntryInternal::PreviewBig1);
264
ui->previewBig->setImage(m_currentPreview);
271
void EntryDetails::preview1Selected()
276
void EntryDetails::preview2Selected()
281
void EntryDetails::preview3Selected()
286
void EntryDetails::previewSelected(int current)
288
EntryInternal::PreviewType type = static_cast<EntryInternal::PreviewType>(EntryInternal::PreviewBig1 + current);
289
m_currentPreview = m_entry.previewImage(type);
290
ui->previewBig->setImage(m_currentPreview);
293
void EntryDetails::ratingChanged(uint rating)
295
// engine expects values from 0..100
296
// qDebug() << "rating: " << rating << " -> " << rating*10;
297
m_engine->vote(m_entry, rating * 10);
300
void EntryDetails::becomeFan()
302
m_engine->becomeFan(m_entry);