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

KNewStuff

entrydetailsdialog.cpp
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2009 Frederik Gladhorn <gladhorn@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #include "entrydetailsdialog.h"
00019 
00020 #include <kmenu.h>
00021 #include <kdebug.h>
00022 
00023 #include <knewstuff3/core/engine.h>
00024 #include <knewstuff3/ui/imageloader.h>
00025 #include <attica/provider.h>
00026 
00027 using namespace KNS3;
00028 
00029 EntryDetails::EntryDetails(Engine* engine, Ui::DownloadWidget* widget)
00030     : QObject(widget->m_listView), m_engine(engine), ui(widget)
00031 {
00032     init();
00033 }
00034 
00035 EntryDetails::~EntryDetails()
00036 {
00037 }
00038 
00039 void EntryDetails::init()
00040 {
00041     connect(ui->preview1, SIGNAL(clicked()), this, SLOT(preview1Selected()));
00042     connect(ui->preview2, SIGNAL(clicked()), this, SLOT(preview2Selected()));
00043     connect(ui->preview3, SIGNAL(clicked()), this, SLOT(preview3Selected()));
00044 
00045     ui->ratingWidget->setMaxRating(10);
00046     ui->ratingWidget->setHalfStepsEnabled(true);
00047 
00048     updateButtons();
00049     connect(ui->installButton, SIGNAL(clicked()), this, SLOT(install()));
00050     connect(ui->uninstallButton, SIGNAL(clicked()), this, SLOT(uninstall()));
00051     // updating is the same as installing
00052     connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(install()));
00053     connect(ui->becomeFanButton, SIGNAL(clicked()), this, SLOT(becomeFan()));
00054 
00055     ui->installButton->setIcon(KIcon("dialog-ok"));
00056     ui->updateButton->setIcon(KIcon("system-software-update"));
00057     ui->uninstallButton->setIcon(KIcon("edit-delete"));
00058 
00059     connect(m_engine, SIGNAL(signalEntryDetailsLoaded(KNS3::EntryInternal)),
00060             this, SLOT(entryChanged(KNS3::EntryInternal)));
00061     connect(m_engine, SIGNAL(signalEntryChanged(KNS3::EntryInternal)),
00062             this, SLOT(entryStatusChanged(KNS3::EntryInternal)));
00063     connect(m_engine, SIGNAL(signalEntryPreviewLoaded(KNS3::EntryInternal,KNS3::EntryInternal::PreviewType)),
00064             this, SLOT(slotEntryPreviewLoaded(KNS3::EntryInternal,KNS3::EntryInternal::PreviewType)));
00065 }
00066 
00067 void EntryDetails::setEntry(const KNS3::EntryInternal& entry)
00068 {
00069     m_entry = entry;
00070     // immediately show something
00071     entryChanged(m_entry);
00072     // fetch more preview images
00073     m_engine->loadDetails(m_entry);
00074 }
00075 
00076 void EntryDetails::entryChanged(const KNS3::EntryInternal& entry)
00077 {
00078     if (ui->detailsStack->currentIndex() == 0) {
00079         return;
00080     }
00081     m_entry = entry;
00082 
00083     // FIXME
00084     //ui->ratingWidget->setEditable(m_engine->userCanVote(m_entry));
00085 
00086     if (!m_engine->userCanBecomeFan(m_entry)) {
00087         ui->becomeFanButton->setEnabled(false);
00088     }
00089 
00090     ui->m_titleWidget->setText(i18n("Details for %1", m_entry.name()));
00091     if (!m_entry.author().homepage().isEmpty()) {
00092         ui->authorLabel->setText("<a href=\"" + m_entry.author().homepage() + "\">" + m_entry.author().name() + "</a>");
00093     } else if (!m_entry.author().email().isEmpty()) {
00094         ui->authorLabel->setText("<a href=\"mailto:" + m_entry.author().email() + "\">" + m_entry.author().name() + "</a>");
00095     } else {
00096         ui->authorLabel->setText(m_entry.author().name());
00097     }
00098 
00099     QString summary = replaceBBCode(m_entry.summary()).replace("\n", "<br/>");
00100     QString changelog = replaceBBCode(m_entry.changelog()).replace("\n", "<br/>");
00101 
00102     QString description = "<html><body>" + summary;
00103     if (!changelog.isEmpty()) {
00104         description += "<br/><p><b>" + i18n("Changelog:") + "</b><br/>" + changelog + "</p>";
00105     }
00106     description += "</body></html>";
00107     ui->descriptionLabel->setText(description);
00108     
00109     QString homepageText("<a href=\"" + m_entry.homepage().url() + "\">" +
00110                               i18nc("A link to the description of this Get Hot New Stuff item", "Homepage") + "</a>");
00111 
00112     if (!m_entry.donationLink().isEmpty()) {
00113         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>";
00114     }
00115     if (!m_entry.knowledgebaseLink().isEmpty()) {
00116         homepageText += "<br><a href=\"" + m_entry.knowledgebaseLink() + "\">" 
00117             + i18ncp("A link to the knowledgebase (like a forum) (opens a web browser)", "Knowledgebase (no entries)", "Knowledgebase (%1 entries)", m_entry.numberKnowledgebaseEntries()) + "</a>";
00118     }
00119     ui->homepageLabel->setText(homepageText);
00120     ui->homepageLabel->setToolTip(i18nc("Tooltip for a link in a dialog", "Opens in a browser window"));
00121     
00122     if (m_entry.rating() > 0) {
00123         ui->ratingWidget->setVisible(true);
00124         disconnect(ui->ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingChanged(uint)));
00125         // Most of the voting is 20 - 80, so rate 20 as 0 stars and 80 as 5 stars
00126         int rating = qMax(0, qMin(10, (m_entry.rating()-20)/6));
00127         ui->ratingWidget->setRating(rating);
00128         connect(ui->ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingChanged(uint)));
00129     } else {
00130         ui->ratingWidget->setVisible(false);
00131     }
00132 
00133     bool hideSmallPreviews = m_entry.previewUrl(EntryInternal::PreviewSmall2).isEmpty()
00134            && m_entry.previewUrl(EntryInternal::PreviewSmall3).isEmpty();
00135            
00136     ui->preview1->setVisible(!hideSmallPreviews);
00137     ui->preview2->setVisible(!hideSmallPreviews);
00138     ui->preview3->setVisible(!hideSmallPreviews);
00139 
00140     // in static xml we often only get a small preview, use that in details
00141     if(m_entry.previewUrl(EntryInternal::PreviewBig1).isEmpty() && !m_entry.previewUrl(EntryInternal::PreviewSmall1).isEmpty()) {
00142         m_entry.setPreviewUrl(m_entry.previewUrl(EntryInternal::PreviewSmall1), EntryInternal::PreviewBig1);
00143         m_entry.setPreviewImage(m_entry.previewImage(EntryInternal::PreviewSmall1), EntryInternal::PreviewBig1);
00144     }
00145 
00146     for (int type = EntryInternal::PreviewSmall1; type <= EntryInternal::PreviewBig3; ++type) {
00147         if (m_entry.previewUrl(EntryInternal::PreviewSmall1).isEmpty()) {
00148             ui->previewBig->setVisible(false);
00149         } else
00150 
00151         if (!m_entry.previewUrl((EntryInternal::PreviewType)type).isEmpty()) {
00152             kDebug() << "type: " << type << m_entry.previewUrl((EntryInternal::PreviewType)type);
00153             if (m_entry.previewImage((EntryInternal::PreviewType)type).isNull()) {
00154                 m_engine->loadPreview(m_entry, (EntryInternal::PreviewType)type);
00155             } else {
00156                 slotEntryPreviewLoaded(m_entry, (EntryInternal::PreviewType)type);
00157             }
00158         }
00159     }
00160     
00161     updateButtons();
00162 }
00163 
00164 void EntryDetails::entryStatusChanged(const KNS3::EntryInternal& entry)
00165 {
00166     Q_UNUSED(entry);
00167     updateButtons();
00168 }
00169 
00170 void EntryDetails::updateButtons()
00171 {
00172     if (ui->detailsStack->currentIndex() == 0) {
00173         return;
00174     }
00175     kDebug() << "update buttons: " << m_entry.status();
00176     ui->installButton->setVisible(false);
00177     ui->uninstallButton->setVisible(false);
00178     ui->updateButton->setVisible(false);
00179 
00180     switch (m_entry.status()) {
00181         case Entry::Installed:
00182             ui->uninstallButton->setVisible(true);
00183             ui->uninstallButton->setEnabled(true);
00184             break;
00185         case Entry::Updateable:
00186             ui->updateButton->setVisible(true);
00187             ui->updateButton->setEnabled(true);
00188             ui->uninstallButton->setVisible(true);
00189             ui->uninstallButton->setEnabled(true);
00190             break;
00191 
00192         case Entry::Invalid:
00193         case Entry::Downloadable:
00194             ui->installButton->setVisible(true);
00195             ui->installButton->setEnabled(true);
00196             break;
00197 
00198         case Entry::Installing:
00199             ui->installButton->setVisible(true);
00200             ui->installButton->setEnabled(false);
00201             break;
00202         case Entry::Updating:
00203             ui->updateButton->setVisible(true);
00204             ui->updateButton->setEnabled(false);
00205             ui->uninstallButton->setVisible(true);
00206             ui->uninstallButton->setEnabled(false);
00207             break;
00208         case Entry::Deleted:
00209             ui->installButton->setVisible(true);
00210             ui->installButton->setEnabled(true);
00211             break;
00212     }
00213     
00214     if (ui->installButton->menu()) {
00215         QMenu* buttonMenu = ui->installButton->menu();
00216         buttonMenu->clear();
00217         ui->installButton->setMenu(0);
00218         buttonMenu->deleteLater();
00219     }
00220     if (ui->installButton->isVisible() && m_entry.downloadLinkCount() > 1) {
00221         KMenu * installMenu = new KMenu(ui->installButton);
00222         foreach (EntryInternal::DownloadLinkInformation info, m_entry.downloadLinkInformationList()) {
00223             QString text = info.name;
00224             if (!info.distributionType.trimmed().isEmpty()) {
00225                 text + " (" + info.distributionType.trimmed() + ")";
00226             }
00227             QAction* installAction = installMenu->addAction(KIcon("dialog-ok"), text);
00228             installAction->setData(info.id);
00229         }
00230         kDebug() << "links: " << m_entry.downloadLinkInformationList().size();
00231         ui->installButton->setMenu(installMenu);
00232     }
00233 }
00234 
00235 void EntryDetails::install()
00236 {
00237     m_engine->install(m_entry);
00238 }
00239 
00240 void EntryDetails::uninstall()
00241 {
00242     m_engine->uninstall(m_entry);
00243 }
00244 
00245 void EntryDetails::slotEntryPreviewLoaded(const KNS3::EntryInternal& entry, KNS3::EntryInternal::PreviewType type)
00246 {
00247     if (!(entry == m_entry)) {
00248         return;
00249     }
00250 
00251     switch (type) {
00252     case EntryInternal::PreviewSmall1:
00253         ui->preview1->setImage(entry.previewImage(EntryInternal::PreviewSmall1));
00254         break;
00255     case EntryInternal::PreviewSmall2:
00256         ui->preview2->setImage(entry.previewImage(EntryInternal::PreviewSmall2));
00257         break;
00258     case EntryInternal::PreviewSmall3:
00259         ui->preview3->setImage(entry.previewImage(EntryInternal::PreviewSmall3));
00260         break;
00261     case EntryInternal::PreviewBig1:
00262         m_currentPreview = entry.previewImage(EntryInternal::PreviewBig1);
00263         ui->previewBig->setImage(m_currentPreview);
00264         break;
00265     default:
00266         break;
00267     }
00268 }
00269 
00270 void EntryDetails::preview1Selected()
00271 {
00272     previewSelected(0);
00273 }
00274 
00275 void EntryDetails::preview2Selected()
00276 {
00277     previewSelected(1);
00278 }
00279 
00280 void EntryDetails::preview3Selected()
00281 {
00282     previewSelected(2);
00283 }
00284 
00285 void EntryDetails::previewSelected(int current)
00286 {
00287     EntryInternal::PreviewType type = static_cast<EntryInternal::PreviewType>(EntryInternal::PreviewBig1 + current);
00288     m_currentPreview = m_entry.previewImage(type);
00289     ui->previewBig->setImage(m_currentPreview);
00290 }
00291 
00292 void EntryDetails::ratingChanged(uint rating)
00293 {
00294     // engine expects values from 0..100
00295     kDebug() << "rating: " << rating << " -> " << rating*10;
00296     m_engine->vote(m_entry, rating*10);
00297 }
00298 
00299 void EntryDetails::becomeFan()
00300 {
00301     m_engine->becomeFan(m_entry);
00302 }
00303 
00304 #include "entrydetailsdialog.moc"
00305 

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

Skip menu "kdelibs"
  • 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
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal