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->installButton, SIGNAL(triggered(QAction*)), this, SLOT(slotInstallActionTriggered(QAction*))); 00051 connect(ui->uninstallButton, SIGNAL(clicked()), this, SLOT(uninstall())); 00052 // updating is the same as installing 00053 connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(install())); 00054 connect(ui->becomeFanButton, SIGNAL(clicked()), this, SLOT(becomeFan())); 00055 00056 ui->installButton->setIcon(KIcon("dialog-ok")); 00057 ui->updateButton->setIcon(KIcon("system-software-update")); 00058 ui->uninstallButton->setIcon(KIcon("edit-delete")); 00059 00060 connect(m_engine, SIGNAL(signalEntryDetailsLoaded(KNS3::EntryInternal)), 00061 this, SLOT(entryChanged(KNS3::EntryInternal))); 00062 connect(m_engine, SIGNAL(signalEntryChanged(KNS3::EntryInternal)), 00063 this, SLOT(entryStatusChanged(KNS3::EntryInternal))); 00064 connect(m_engine, SIGNAL(signalEntryPreviewLoaded(KNS3::EntryInternal,KNS3::EntryInternal::PreviewType)), 00065 this, SLOT(slotEntryPreviewLoaded(KNS3::EntryInternal,KNS3::EntryInternal::PreviewType))); 00066 } 00067 00068 void EntryDetails::setEntry(const KNS3::EntryInternal& entry) 00069 { 00070 m_entry = entry; 00071 // immediately show something 00072 entryChanged(m_entry); 00073 // fetch more preview images 00074 m_engine->loadDetails(m_entry); 00075 } 00076 00077 void EntryDetails::entryChanged(const KNS3::EntryInternal& entry) 00078 { 00079 if (ui->detailsStack->currentIndex() == 0) { 00080 return; 00081 } 00082 m_entry = entry; 00083 00084 // FIXME 00085 //ui->ratingWidget->setEditable(m_engine->userCanVote(m_entry)); 00086 00087 if (!m_engine->userCanBecomeFan(m_entry)) { 00088 ui->becomeFanButton->setEnabled(false); 00089 } 00090 00091 ui->m_titleWidget->setText(i18n("Details for %1", m_entry.name())); 00092 if (!m_entry.author().homepage().isEmpty()) { 00093 ui->authorLabel->setText("<a href=\"" + m_entry.author().homepage() + "\">" + m_entry.author().name() + "</a>"); 00094 } else if (!m_entry.author().email().isEmpty()) { 00095 ui->authorLabel->setText("<a href=\"mailto:" + m_entry.author().email() + "\">" + m_entry.author().name() + "</a>"); 00096 } else { 00097 ui->authorLabel->setText(m_entry.author().name()); 00098 } 00099 00100 QString summary = replaceBBCode(m_entry.summary()).replace("\n", "<br/>"); 00101 QString changelog = replaceBBCode(m_entry.changelog()).replace("\n", "<br/>"); 00102 00103 QString description = "<html><body>" + summary; 00104 if (!changelog.isEmpty()) { 00105 description += "<br/><p><b>" + i18n("Changelog:") + "</b><br/>" + changelog + "</p>"; 00106 } 00107 description += "</body></html>"; 00108 ui->descriptionLabel->setText(description); 00109 00110 QString homepageText("<a href=\"" + m_entry.homepage().url() + "\">" + 00111 i18nc("A link to the description of this Get Hot New Stuff item", "Homepage") + "</a>"); 00112 00113 if (!m_entry.donationLink().isEmpty()) { 00114 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>"; 00115 } 00116 if (!m_entry.knowledgebaseLink().isEmpty()) { 00117 homepageText += "<br><a href=\"" + m_entry.knowledgebaseLink() + "\">" 00118 + i18ncp("A link to the knowledgebase (like a forum) (opens a web browser)", "Knowledgebase (no entries)", "Knowledgebase (%1 entries)", m_entry.numberKnowledgebaseEntries()) + "</a>"; 00119 } 00120 ui->homepageLabel->setText(homepageText); 00121 ui->homepageLabel->setToolTip(i18nc("Tooltip for a link in a dialog", "Opens in a browser window")); 00122 00123 if (m_entry.rating() > 0) { 00124 ui->ratingWidget->setVisible(true); 00125 disconnect(ui->ratingWidget); 00126 ui->ratingWidget->setRating((m_entry.rating()-20)/6); 00127 connect(ui->ratingWidget, SIGNAL(ratingChanged(uint)), this, SLOT(ratingChanged(uint))); 00128 } else { 00129 ui->ratingWidget->setVisible(false); 00130 } 00131 00132 bool hideSmallPreviews = m_entry.previewUrl(EntryInternal::PreviewSmall2).isEmpty() 00133 && m_entry.previewUrl(EntryInternal::PreviewSmall3).isEmpty(); 00134 00135 ui->preview1->setVisible(!hideSmallPreviews); 00136 ui->preview2->setVisible(!hideSmallPreviews); 00137 ui->preview3->setVisible(!hideSmallPreviews); 00138 00139 // in static xml we often only get a small preview, use that in details 00140 if(m_entry.previewUrl(EntryInternal::PreviewBig1).isEmpty() && !m_entry.previewUrl(EntryInternal::PreviewSmall1).isEmpty()) { 00141 m_entry.setPreviewUrl(m_entry.previewUrl(EntryInternal::PreviewSmall1), EntryInternal::PreviewBig1); 00142 m_entry.setPreviewImage(m_entry.previewImage(EntryInternal::PreviewSmall1), EntryInternal::PreviewBig1); 00143 } 00144 00145 for (int type = EntryInternal::PreviewSmall1; type <= EntryInternal::PreviewBig3; ++type) { 00146 if (m_entry.previewUrl(EntryInternal::PreviewSmall1).isEmpty()) { 00147 ui->previewBig->setVisible(false); 00148 } else 00149 00150 if (!m_entry.previewUrl((EntryInternal::PreviewType)type).isEmpty()) { 00151 kDebug() << "type: " << type << m_entry.previewUrl((EntryInternal::PreviewType)type); 00152 if (m_entry.previewImage((EntryInternal::PreviewType)type).isNull()) { 00153 m_engine->loadPreview(m_entry, (EntryInternal::PreviewType)type); 00154 } else { 00155 slotEntryPreviewLoaded(m_entry, (EntryInternal::PreviewType)type); 00156 } 00157 } 00158 } 00159 00160 updateButtons(); 00161 } 00162 00163 void EntryDetails::entryStatusChanged(const KNS3::EntryInternal& entry) 00164 { 00165 Q_UNUSED(entry); 00166 updateButtons(); 00167 } 00168 00169 void EntryDetails::updateButtons() 00170 { 00171 if (ui->detailsStack->currentIndex() == 0) { 00172 return; 00173 } 00174 kDebug() << "update buttons: " << m_entry.status(); 00175 ui->installButton->setVisible(false); 00176 ui->uninstallButton->setVisible(false); 00177 ui->updateButton->setVisible(false); 00178 00179 switch (m_entry.status()) { 00180 case Entry::Installed: 00181 ui->uninstallButton->setVisible(true); 00182 ui->uninstallButton->setEnabled(true); 00183 break; 00184 case Entry::Updateable: 00185 ui->updateButton->setVisible(true); 00186 ui->updateButton->setEnabled(true); 00187 ui->uninstallButton->setVisible(true); 00188 ui->uninstallButton->setEnabled(true); 00189 break; 00190 00191 case Entry::Invalid: 00192 case Entry::Downloadable: 00193 ui->installButton->setVisible(true); 00194 ui->installButton->setEnabled(true); 00195 break; 00196 00197 case Entry::Installing: 00198 ui->installButton->setVisible(true); 00199 ui->installButton->setEnabled(false); 00200 break; 00201 case Entry::Updating: 00202 ui->updateButton->setVisible(true); 00203 ui->updateButton->setEnabled(false); 00204 ui->uninstallButton->setVisible(true); 00205 ui->uninstallButton->setEnabled(false); 00206 break; 00207 case Entry::Deleted: 00208 ui->installButton->setVisible(true); 00209 ui->installButton->setEnabled(true); 00210 break; 00211 } 00212 00213 if (ui->installButton->menu()) { 00214 QMenu* buttonMenu = ui->installButton->menu(); 00215 buttonMenu->clear(); 00216 ui->installButton->setMenu(0); 00217 buttonMenu->deleteLater(); 00218 } 00219 if (ui->installButton->isVisible() && m_entry.downloadLinkCount() > 1) { 00220 KMenu * installMenu = new KMenu(ui->installButton); 00221 foreach (EntryInternal::DownloadLinkInformation info, m_entry.downloadLinkInformationList()) { 00222 QString text = info.name; 00223 if (!info.distributionType.trimmed().isEmpty()) { 00224 text + " (" + info.distributionType.trimmed() + ")"; 00225 } 00226 QAction* installAction = installMenu->addAction(KIcon("dialog-ok"), text); 00227 installAction->setData(info.id); 00228 } 00229 kDebug() << "links: " << m_entry.downloadLinkInformationList().size(); 00230 ui->installButton->setMenu(installMenu); 00231 } 00232 } 00233 00234 void EntryDetails::install() 00235 { 00236 m_engine->install(m_entry); 00237 } 00238 00239 void EntryDetails::slotInstallActionTriggered(QAction* action) 00240 { 00241 m_engine->install(m_entry, action->data().toInt()); 00242 } 00243 00244 void EntryDetails::uninstall() 00245 { 00246 m_engine->uninstall(m_entry); 00247 } 00248 00249 void EntryDetails::slotEntryPreviewLoaded(const KNS3::EntryInternal& entry, KNS3::EntryInternal::PreviewType type) 00250 { 00251 if (!(entry == m_entry)) { 00252 return; 00253 } 00254 00255 switch (type) { 00256 case EntryInternal::PreviewSmall1: 00257 ui->preview1->setImage(entry.previewImage(EntryInternal::PreviewSmall1)); 00258 break; 00259 case EntryInternal::PreviewSmall2: 00260 ui->preview2->setImage(entry.previewImage(EntryInternal::PreviewSmall2)); 00261 break; 00262 case EntryInternal::PreviewSmall3: 00263 ui->preview3->setImage(entry.previewImage(EntryInternal::PreviewSmall3)); 00264 break; 00265 case EntryInternal::PreviewBig1: 00266 m_currentPreview = entry.previewImage(EntryInternal::PreviewBig1); 00267 ui->previewBig->setImage(m_currentPreview); 00268 break; 00269 default: 00270 break; 00271 } 00272 } 00273 00274 void EntryDetails::preview1Selected() 00275 { 00276 previewSelected(0); 00277 } 00278 00279 void EntryDetails::preview2Selected() 00280 { 00281 previewSelected(1); 00282 } 00283 00284 void EntryDetails::preview3Selected() 00285 { 00286 previewSelected(2); 00287 } 00288 00289 void EntryDetails::previewSelected(int current) 00290 { 00291 EntryInternal::PreviewType type = static_cast<EntryInternal::PreviewType>(EntryInternal::PreviewBig1 + current); 00292 m_currentPreview = m_entry.previewImage(type); 00293 ui->previewBig->setImage(m_currentPreview); 00294 } 00295 00296 void EntryDetails::ratingChanged(uint rating) 00297 { 00298 // engine expects values from 0..100 00299 kDebug() << "rating: " << rating << " -> " << rating*10; 00300 m_engine->vote(m_entry, rating*10); 00301 } 00302 00303 void EntryDetails::becomeFan() 00304 { 00305 m_engine->becomeFan(m_entry); 00306 } 00307 00308 #include "entrydetailsdialog.moc" 00309
KDE 4.6 API Reference