• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KNewStuff

  • knewstuff
  • knewstuff3
  • ui
entrydetailsdialog.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 Frederik Gladhorn <gladhorn@kde.org>
3
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.
8
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.
13
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/>.
16*/
17
18#include "entrydetailsdialog.h"
19
20#include <kmenu.h>
21#include <kdebug.h>
22
23#include <knewstuff3/core/engine.h>
24#include <knewstuff3/ui/imageloader.h>
25#include <attica/provider.h>
26
27using namespace KNS3;
28
29EntryDetails::EntryDetails(Engine* engine, Ui::DownloadWidget* widget)
30 : QObject(widget->m_listView), m_engine(engine), ui(widget)
31{
32 init();
33}
34
35EntryDetails::~EntryDetails()
36{
37}
38
39void EntryDetails::init()
40{
41 connect(ui->preview1, SIGNAL(clicked()), this, SLOT(preview1Selected()));
42 connect(ui->preview2, SIGNAL(clicked()), this, SLOT(preview2Selected()));
43 connect(ui->preview3, SIGNAL(clicked()), this, SLOT(preview3Selected()));
44
45 ui->ratingWidget->setMaxRating(10);
46 ui->ratingWidget->setHalfStepsEnabled(true);
47
48 updateButtons();
49 connect(ui->installButton, SIGNAL(clicked()), this, SLOT(install()));
50 connect(ui->uninstallButton, SIGNAL(clicked()), this, SLOT(uninstall()));
51 // updating is the same as installing
52 connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(install()));
53 connect(ui->becomeFanButton, SIGNAL(clicked()), this, SLOT(becomeFan()));
54
55 ui->installButton->setIcon(KIcon("dialog-ok"));
56 ui->updateButton->setIcon(KIcon("system-software-update"));
57 ui->uninstallButton->setIcon(KIcon("edit-delete"));
58
59 connect(m_engine, SIGNAL(signalEntryDetailsLoaded(KNS3::EntryInternal)),
60 this, SLOT(entryChanged(KNS3::EntryInternal)));
61 connect(m_engine, SIGNAL(signalEntryChanged(KNS3::EntryInternal)),
62 this, SLOT(entryStatusChanged(KNS3::EntryInternal)));
63 connect(m_engine, SIGNAL(signalEntryPreviewLoaded(KNS3::EntryInternal,KNS3::EntryInternal::PreviewType)),
64 this, SLOT(slotEntryPreviewLoaded(KNS3::EntryInternal,KNS3::EntryInternal::PreviewType)));
65}
66
67void EntryDetails::setEntry(const KNS3::EntryInternal& entry)
68{
69 m_entry = entry;
70 // immediately show something
71 entryChanged(m_entry);
72 // fetch more preview images
73 m_engine->loadDetails(m_entry);
74}
75
76void EntryDetails::entryChanged(const KNS3::EntryInternal& entry)
77{
78 if (ui->detailsStack->currentIndex() == 0) {
79 return;
80 }
81 m_entry = entry;
82
83 // FIXME
84 //ui->ratingWidget->setEditable(m_engine->userCanVote(m_entry));
85
86 if (!m_engine->userCanBecomeFan(m_entry)) {
87 ui->becomeFanButton->setEnabled(false);
88 }
89
90 ui->m_titleWidget->setText(i18n("Details for %1", m_entry.name()));
91 if (!m_entry.author().homepage().isEmpty()) {
92 ui->authorLabel->setText("<a href=\"" + m_entry.author().homepage() + "\">" + m_entry.author().name() + "</a>");
93 } else if (!m_entry.author().email().isEmpty()) {
94 ui->authorLabel->setText("<a href=\"mailto:" + m_entry.author().email() + "\">" + m_entry.author().name() + "</a>");
95 } else {
96 ui->authorLabel->setText(m_entry.author().name());
97 }
98
99 QString summary = replaceBBCode(m_entry.summary()).replace("\n", "<br/>");
100 QString changelog = replaceBBCode(m_entry.changelog()).replace("\n", "<br/>");
101
102 QString description = "<html><body>" + summary;
103 if (!changelog.isEmpty()) {
104 description += "<br/><p><b>" + i18n("Changelog:") + "</b><br/>" + changelog + "</p>";
105 }
106 description += "</body></html>";
107 ui->descriptionLabel->setText(description);
108
109 QString homepageText("<a href=\"" + m_entry.homepage().url() + "\">" +
110 i18nc("A link to the description of this Get Hot New Stuff item", "Homepage") + "</a>");
111
112 if (!m_entry.donationLink().isEmpty()) {
113 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>";
114 }
115 if (!m_entry.knowledgebaseLink().isEmpty()) {
116 homepageText += "<br><a href=\"" + m_entry.knowledgebaseLink() + "\">"
117 + i18ncp("A link to the knowledgebase (like a forum) (opens a web browser)", "Knowledgebase (no entries)", "Knowledgebase (%1 entries)", m_entry.numberKnowledgebaseEntries()) + "</a>";
118 }
119 ui->homepageLabel->setText(homepageText);
120 ui->homepageLabel->setToolTip(i18nc("Tooltip for a link in a dialog", "Opens in a browser window"));
121
122 if (m_entry.rating() > 0) {
123 ui->ratingWidget->setVisible(true);
124 disconnect(ui->ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingChanged(uint)));
125 // Most of the voting is 20 - 80, so rate 20 as 0 stars and 80 as 5 stars
126 int rating = qMax(0, qMin(10, (m_entry.rating()-20)/6));
127 ui->ratingWidget->setRating(rating);
128 connect(ui->ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingChanged(uint)));
129 } else {
130 ui->ratingWidget->setVisible(false);
131 }
132
133 bool hideSmallPreviews = m_entry.previewUrl(EntryInternal::PreviewSmall2).isEmpty()
134 && m_entry.previewUrl(EntryInternal::PreviewSmall3).isEmpty();
135
136 ui->preview1->setVisible(!hideSmallPreviews);
137 ui->preview2->setVisible(!hideSmallPreviews);
138 ui->preview3->setVisible(!hideSmallPreviews);
139
140 // in static xml we often only get a small preview, use that in details
141 if(m_entry.previewUrl(EntryInternal::PreviewBig1).isEmpty() && !m_entry.previewUrl(EntryInternal::PreviewSmall1).isEmpty()) {
142 m_entry.setPreviewUrl(m_entry.previewUrl(EntryInternal::PreviewSmall1), EntryInternal::PreviewBig1);
143 m_entry.setPreviewImage(m_entry.previewImage(EntryInternal::PreviewSmall1), EntryInternal::PreviewBig1);
144 }
145
146 for (int type = EntryInternal::PreviewSmall1; type <= EntryInternal::PreviewBig3; ++type) {
147 if (m_entry.previewUrl(EntryInternal::PreviewSmall1).isEmpty()) {
148 ui->previewBig->setVisible(false);
149 } else
150
151 if (!m_entry.previewUrl((EntryInternal::PreviewType)type).isEmpty()) {
152 kDebug() << "type: " << type << m_entry.previewUrl((EntryInternal::PreviewType)type);
153 if (m_entry.previewImage((EntryInternal::PreviewType)type).isNull()) {
154 m_engine->loadPreview(m_entry, (EntryInternal::PreviewType)type);
155 } else {
156 slotEntryPreviewLoaded(m_entry, (EntryInternal::PreviewType)type);
157 }
158 }
159 }
160
161 updateButtons();
162}
163
164void EntryDetails::entryStatusChanged(const KNS3::EntryInternal& entry)
165{
166 Q_UNUSED(entry);
167 updateButtons();
168}
169
170void EntryDetails::updateButtons()
171{
172 if (ui->detailsStack->currentIndex() == 0) {
173 return;
174 }
175 kDebug() << "update buttons: " << m_entry.status();
176 ui->installButton->setVisible(false);
177 ui->uninstallButton->setVisible(false);
178 ui->updateButton->setVisible(false);
179
180 switch (m_entry.status()) {
181 case Entry::Installed:
182 ui->uninstallButton->setVisible(true);
183 ui->uninstallButton->setEnabled(true);
184 break;
185 case Entry::Updateable:
186 ui->updateButton->setVisible(true);
187 ui->updateButton->setEnabled(true);
188 ui->uninstallButton->setVisible(true);
189 ui->uninstallButton->setEnabled(true);
190 break;
191
192 case Entry::Invalid:
193 case Entry::Downloadable:
194 ui->installButton->setVisible(true);
195 ui->installButton->setEnabled(true);
196 break;
197
198 case Entry::Installing:
199 ui->installButton->setVisible(true);
200 ui->installButton->setEnabled(false);
201 break;
202 case Entry::Updating:
203 ui->updateButton->setVisible(true);
204 ui->updateButton->setEnabled(false);
205 ui->uninstallButton->setVisible(true);
206 ui->uninstallButton->setEnabled(false);
207 break;
208 case Entry::Deleted:
209 ui->installButton->setVisible(true);
210 ui->installButton->setEnabled(true);
211 break;
212 }
213
214 if (ui->installButton->menu()) {
215 QMenu* buttonMenu = ui->installButton->menu();
216 buttonMenu->clear();
217 ui->installButton->setMenu(0);
218 buttonMenu->deleteLater();
219 }
220 if (ui->installButton->isVisible() && m_entry.downloadLinkCount() > 1) {
221 KMenu * installMenu = new KMenu(ui->installButton);
222 foreach (EntryInternal::DownloadLinkInformation info, m_entry.downloadLinkInformationList()) {
223 QString text = info.name;
224 if (!info.distributionType.trimmed().isEmpty()) {
225 text + " (" + info.distributionType.trimmed() + ")";
226 }
227 QAction* installAction = installMenu->addAction(KIcon("dialog-ok"), text);
228 installAction->setData(info.id);
229 }
230 kDebug() << "links: " << m_entry.downloadLinkInformationList().size();
231 ui->installButton->setMenu(installMenu);
232 }
233}
234
235void EntryDetails::install()
236{
237 m_engine->install(m_entry);
238}
239
240void EntryDetails::uninstall()
241{
242 m_engine->uninstall(m_entry);
243}
244
245void EntryDetails::slotEntryPreviewLoaded(const KNS3::EntryInternal& entry, KNS3::EntryInternal::PreviewType type)
246{
247 if (!(entry == m_entry)) {
248 return;
249 }
250
251 switch (type) {
252 case EntryInternal::PreviewSmall1:
253 ui->preview1->setImage(entry.previewImage(EntryInternal::PreviewSmall1));
254 break;
255 case EntryInternal::PreviewSmall2:
256 ui->preview2->setImage(entry.previewImage(EntryInternal::PreviewSmall2));
257 break;
258 case EntryInternal::PreviewSmall3:
259 ui->preview3->setImage(entry.previewImage(EntryInternal::PreviewSmall3));
260 break;
261 case EntryInternal::PreviewBig1:
262 m_currentPreview = entry.previewImage(EntryInternal::PreviewBig1);
263 ui->previewBig->setImage(m_currentPreview);
264 break;
265 default:
266 break;
267 }
268}
269
270void EntryDetails::preview1Selected()
271{
272 previewSelected(0);
273}
274
275void EntryDetails::preview2Selected()
276{
277 previewSelected(1);
278}
279
280void EntryDetails::preview3Selected()
281{
282 previewSelected(2);
283}
284
285void EntryDetails::previewSelected(int current)
286{
287 EntryInternal::PreviewType type = static_cast<EntryInternal::PreviewType>(EntryInternal::PreviewBig1 + current);
288 m_currentPreview = m_entry.previewImage(type);
289 ui->previewBig->setImage(m_currentPreview);
290}
291
292void EntryDetails::ratingChanged(uint rating)
293{
294 // engine expects values from 0..100
295 kDebug() << "rating: " << rating << " -> " << rating*10;
296 m_engine->vote(m_entry, rating*10);
297}
298
299void EntryDetails::becomeFan()
300{
301 m_engine->becomeFan(m_entry);
302}
303
304#include "entrydetailsdialog.moc"
305
KIcon
KMenu
KNS3::Author::homepage
QString homepage() const
Retrieve the author's homepage.
Definition: knewstuff3/core/author.cpp:60
KNS3::Author::name
QString name() const
Retrieve the author's name.
Definition: knewstuff3/core/author.cpp:30
KNS3::Author::email
QString email() const
Retrieve the author's email address.
Definition: knewstuff3/core/author.cpp:40
KNS3::Engine
KNewStuff engine.
Definition: knewstuff3/core/engine.h:53
KNS3::Engine::userCanBecomeFan
bool userCanBecomeFan(const EntryInternal &entry)
Definition: knewstuff3/core/engine.cpp:514
KNS3::Engine::vote
void vote(const EntryInternal &entry, uint rating)
Definition: knewstuff3/core/engine.cpp:508
KNS3::Engine::install
void install(KNS3::EntryInternal entry, int linkId=1)
Installs an entry's payload file.
Definition: knewstuff3/core/engine.cpp:390
KNS3::Engine::becomeFan
void becomeFan(const EntryInternal &entry)
Definition: knewstuff3/core/engine.cpp:520
KNS3::Engine::loadDetails
void loadDetails(const KNS3::EntryInternal &entry)
Definition: knewstuff3/core/engine.cpp:463
KNS3::Engine::uninstall
void uninstall(KNS3::EntryInternal entry)
Uninstalls an entry.
Definition: knewstuff3/core/engine.cpp:432
KNS3::Engine::loadPreview
void loadPreview(const KNS3::EntryInternal &entry, EntryInternal::PreviewType type)
Definition: knewstuff3/core/engine.cpp:469
KNS3::EntryDetails::setEntry
void setEntry(const KNS3::EntryInternal &entry)
Definition: entrydetailsdialog.cpp:67
KNS3::EntryDetails::EntryDetails
EntryDetails(Engine *engine, Ui::DownloadWidget *widget)
Definition: entrydetailsdialog.cpp:29
KNS3::EntryDetails::~EntryDetails
~EntryDetails()
Definition: entrydetailsdialog.cpp:35
KNS3::EntryInternal
KNewStuff data entry container.
Definition: entryinternal.h:55
KNS3::EntryInternal::donationLink
QString donationLink() const
Definition: entryinternal.cpp:314
KNS3::EntryInternal::homepage
KUrl homepage() const
Definition: entryinternal.cpp:164
KNS3::EntryInternal::knowledgebaseLink
QString knowledgebaseLink() const
Definition: entryinternal.cpp:333
KNS3::EntryInternal::downloadLinkCount
int downloadLinkCount() const
Definition: entryinternal.cpp:397
KNS3::EntryInternal::name
QString name() const
Retrieve the name of the data object.
Definition: entryinternal.cpp:124
KNS3::EntryInternal::setPreviewImage
void setPreviewImage(const QImage &image, PreviewType type=PreviewSmall1)
Definition: entryinternal.cpp:279
KNS3::EntryInternal::setPreviewUrl
void setPreviewUrl(const QString &url, PreviewType type=PreviewSmall1)
Sets the object's preview file, if available.
Definition: entryinternal.cpp:269
KNS3::EntryInternal::previewUrl
QString previewUrl(PreviewType type=PreviewSmall1) const
Retrieve the file name of an image containing a preview of the object.
Definition: entryinternal.cpp:264
KNS3::EntryInternal::author
Author author() const
Retrieve the author of the object.
Definition: entryinternal.cpp:174
KNS3::EntryInternal::PreviewType
PreviewType
Definition: entryinternal.h:70
KNS3::EntryInternal::PreviewBig1
@ PreviewBig1
Definition: entryinternal.h:74
KNS3::EntryInternal::PreviewSmall1
@ PreviewSmall1
Definition: entryinternal.h:71
KNS3::EntryInternal::PreviewSmall3
@ PreviewSmall3
Definition: entryinternal.h:73
KNS3::EntryInternal::PreviewSmall2
@ PreviewSmall2
Definition: entryinternal.h:72
KNS3::EntryInternal::PreviewBig3
@ PreviewBig3
Definition: entryinternal.h:76
KNS3::EntryInternal::status
Entry::Status status() const
Retrieves the entry's status.
Definition: entryinternal.cpp:367
KNS3::EntryInternal::rating
int rating() const
Retrieve the rating for the object, which has been determined by its users and thus might change over...
Definition: entryinternal.cpp:284
KNS3::EntryInternal::summary
QString summary() const
Retrieve a short description about the object.
Definition: entryinternal.cpp:194
KNS3::EntryInternal::previewImage
QImage previewImage(PreviewType type=PreviewSmall1) const
This will not be loaded automatically, instead use Engine to load the actual images.
Definition: entryinternal.cpp:274
KNS3::EntryInternal::numberKnowledgebaseEntries
int numberKnowledgebaseEntries() const
Definition: entryinternal.cpp:324
KNS3::EntryInternal::downloadLinkInformationList
QList< DownloadLinkInformation > downloadLinkInformationList() const
Definition: entryinternal.cpp:402
KNS3::EntryInternal::changelog
QString changelog() const
Definition: entryinternal.cpp:209
KNS3::Entry::Installed
@ Installed
Definition: knewstuff3/entry.h:61
KNS3::Entry::Installing
@ Installing
Definition: knewstuff3/entry.h:64
KNS3::Entry::Deleted
@ Deleted
Definition: knewstuff3/entry.h:63
KNS3::Entry::Updateable
@ Updateable
Definition: knewstuff3/entry.h:62
KNS3::Entry::Downloadable
@ Downloadable
Definition: knewstuff3/entry.h:60
KNS3::Entry::Updating
@ Updating
Definition: knewstuff3/entry.h:65
KNS3::Entry::Invalid
@ Invalid
Definition: knewstuff3/entry.h:59
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
QAction
QMenu
QObject
entrydetailsdialog.h
kDebug
#define kDebug
imageloader.h
kdebug.h
i18n
QString i18n(const char *text)
i18nc
QString i18nc(const char *ctxt, const char *text)
i18ncp
QString i18ncp(const char *ctxt, const char *sing, const char *plur, const A1 &a1)
kmenu.h
engine.h
KNS3
Definition: atticaprovider.cpp:36
KNS3::replaceBBCode
QString replaceBBCode(const QString &unformattedText)
function to remove bb code formatting that opendesktop sends
Definition: entryinternal.cpp:586
KNS3::EntryInternal::DownloadLinkInformation
Definition: entryinternal.h:79
KNS3::EntryInternal::DownloadLinkInformation::distributionType
QString distributionType
Definition: entryinternal.h:82
KNS3::EntryInternal::DownloadLinkInformation::id
int id
Definition: entryinternal.h:84
KNS3::EntryInternal::DownloadLinkInformation::name
QString name
Definition: entryinternal.h:80
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal