• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.2 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 
27 using namespace KNS3;
28 
29 EntryDetails::EntryDetails(Engine* engine, Ui::DownloadWidget* widget)
30  : QObject(widget->m_listView), m_engine(engine), ui(widget)
31 {
32  init();
33 }
34 
35 EntryDetails::~EntryDetails()
36 {
37 }
38 
39 void 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 
67 void 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 
76 void 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 
164 void EntryDetails::entryStatusChanged(const KNS3::EntryInternal& entry)
165 {
166  Q_UNUSED(entry);
167  updateButtons();
168 }
169 
170 void 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 
235 void EntryDetails::install()
236 {
237  m_engine->install(m_entry);
238 }
239 
240 void EntryDetails::uninstall()
241 {
242  m_engine->uninstall(m_entry);
243 }
244 
245 void 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 
270 void EntryDetails::preview1Selected()
271 {
272  previewSelected(0);
273 }
274 
275 void EntryDetails::preview2Selected()
276 {
277  previewSelected(1);
278 }
279 
280 void EntryDetails::preview3Selected()
281 {
282  previewSelected(2);
283 }
284 
285 void 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 
292 void 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 
299 void EntryDetails::becomeFan()
300 {
301  m_engine->becomeFan(m_entry);
302 }
303 
304 #include "entrydetailsdialog.moc"
305 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sun Apr 28 2013 14:28:51 by doxygen 1.8.1.1 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.10.2 API Reference

Skip menu "kdelibs-4.10.2 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