26 #include <QtCore/QTimer>
27 #include <QtGui/QPixmap>
28 #include <QtGui/QSortFilterProxyModel>
45 #include "ui_DownloadDialog.h"
62 connect(m_engine, SIGNAL(signalProgress(
QString,
int)), SLOT(slotProgress(
QString,
int)));
64 connect(m_engine, SIGNAL(signalPayloadFailed(
KNS::Entry*)), SLOT(slotPayloadFailed(
KNS::Entry*)));
65 connect(m_engine, SIGNAL(signalPayloadLoaded(
KUrl)), SLOT(slotPayloadLoaded(
KUrl)));
66 connect(m_engine, SIGNAL(signalProvidersFailed()), SLOT(slotProvidersFailed()));
67 connect(m_engine, SIGNAL(signalEntriesFailed()), SLOT(slotEntriesFailed()));
75 messageTimer =
new QTimer(
this);
76 messageTimer->setSingleShot(
true);
77 connect(messageTimer, SIGNAL(
timeout()), SLOT(slotResetMessage()));
79 networkTimer =
new QTimer(
this);
80 connect(networkTimer, SIGNAL(
timeout()), SLOT(slotNetworkTimeout()));
82 m_searchTimer =
new QTimer(
this);
83 m_searchTimer->setSingleShot(
true);
84 m_searchTimer->setInterval(1000);
85 connect(m_searchTimer, SIGNAL(
timeout()), SLOT(slotUpdateSearch()));
89 setMainWidget(_mainWidget);
94 m_listView->setItemDelegate(mDelegate);
101 m_filteredModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
102 m_listView->setModel(m_filteredModel);
103 connect(m_listView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
104 this, SLOT(slotListIndexChanged(QModelIndex,QModelIndex)));
113 connect(m_sourceCombo, SIGNAL(currentIndexChanged(
int)), SLOT(slotLoadProviderDXS()));
114 connect(m_sortCombo, SIGNAL(currentIndexChanged(
int)), SLOT(slotSortingSelected(
int)));
115 connect(m_searchEdit, SIGNAL(textChanged(
QString)), SLOT(slotSearchTextChanged()));
116 connect(m_searchEdit, SIGNAL(editingFinished()), SLOT(slotUpdateSearch()));
124 restoreDialogSize(group);
125 setMinimumSize(700, 400);
127 setCaption(
i18n(
"Get Hot New Stuff"));
128 m_titleWidget->setText(
i18nc(
"Program name followed by 'Add On Installer'",
129 "%1 Add-On Installer",
133 connect(m_buttonBox, SIGNAL(rejected()),
this, SLOT(accept()));
135 KMenu * collabMenu =
new KMenu(m_collaborationButton);
136 QAction * action_collabrating = collabMenu->addAction(
i18n(
"Add Rating"));
139 QAction * action_collabcomment = collabMenu->addAction(
i18n(
"Add Comment"));
142 QAction * action_comment = collabMenu->addAction(
SmallIcon(
"help-about"),
i18n(
"View Comments"));
156 m_collaborationButton->setMenu(collabMenu);
157 connect(m_collaborationButton, SIGNAL(triggered(
QAction*)),
this, SLOT(slotCollabAction(
QAction*)));
163 saveDialogSize(group, KConfigBase::Persistent);
168 kDebug(551) <<
"perform action: " << action;
169 const Provider * provider = m_providers.contains(entry) ? m_providers[entry] : NULL;
173 if (provider && dxs) {
185 if (provider && dxs) {
211 setCursor(Qt::WaitCursor);
213 setCursor(Qt::ArrowCursor);
217 setCursor(Qt::WaitCursor);
222 QPointer<KDXSComment> commentDialog =
new KDXSComment(
this);
223 int ret = commentDialog->exec();
224 if (ret == QDialog::Accepted) {
225 QString s = commentDialog->comment();
226 if (dxs && !s.isEmpty()) {
230 delete commentDialog;
235 QPointer<KDXSRating> ratingDialog =
new KDXSRating(
this);
236 int ret = ratingDialog->exec();
237 if (ret == QDialog::Accepted) {
238 int rating = ratingDialog->rating();
249 void DownloadDialog::slotCollabAction(
QAction * action)
252 QModelIndex currentIndex = m_listView->currentIndex();
254 QModelIndex index = m_filteredModel->mapToSource(currentIndex);
256 slotPerformAction(entryAction, entry);
259 void DownloadDialog::slotListIndexChanged(
const QModelIndex &index,
const QModelIndex &)
263 m_collaborationButton->setEnabled(m_hasDxs && index.isValid());
269 saveDialogSize(group, KConfigBase::Persistent);
270 KDialog::hideEvent(event);
276 messageTimer->stop();
279 m_titleWidget->setComment(msg, type);
284 messageTimer->start(timeOutMs);
298 slotEntryChanged(entry);
307 void DownloadDialog::slotResetMessage()
309 m_titleWidget->setComment(
QString());
312 void DownloadDialog::slotNetworkTimeout()
317 void DownloadDialog::slotSortingSelected(
int sortType)
321 QString feedName = m_sortCombo->currentText();
322 QString feedType = m_sortCombo->itemData(sortType).toString();
324 const Provider * currentProvider = m_entriesByProvider.keys()[m_sourceCombo->currentIndex()];
326 m_filteredModel->setSourceModel(m_models.value(selectedFeed));
327 m_collaborationButton->setEnabled(
false);
334 void DownloadDialog::slotLoadProviderDXS()
336 kDebug(551) <<
"slotLoadProviderDXS called";
339 QString providerName = m_sourceCombo->currentText();
344 for (
int i = 0; i < providers.size(); ++i) {
345 if (providers[i]->
name().representation() == providerName) {
346 provider = providers[i];
348 populateSortCombo(providers[i]);
350 Feed * selectedFeed = providers[i]->downloadUrlFeed(m_sortCombo->itemData(m_sortCombo->currentIndex()).toString());
351 m_filteredModel->setSourceModel(m_models.value(selectedFeed));
357 m_hasDxs = (provider && m_engine->
dxsObject(provider) != NULL);
358 m_collaborationButton->setEnabled(m_hasDxs);
361 void DownloadDialog::slotUpdateSearch()
363 m_searchTimer->stop();
364 m_filteredModel->setFilterFixedString(m_searchEdit->text());
365 m_filteredModel->invalidate();
368 void DownloadDialog::slotLoadProvidersListDXS()
372 void DownloadDialog::slotSearchTextChanged()
374 m_searchTimer->start();
394 slotLoadProviderDXS();
405 void DownloadDialog::slotEntriesFailed()
411 void DownloadDialog::slotEntryLoaded(
Entry *entry,
const Feed *feed,
const Provider *provider)
417 if (!m_entriesByProvider.contains(provider)) {
421 m_entriesByProvider[provider].append(entry);
424 m_providers[entry] = provider;
428 if (!m_models.value(feed)) {
430 kDebug(551) <<
"making a new model for this feed" << feed;
432 connect(m_engine, SIGNAL(signalEntryChanged(
KNS::Entry*)),
433 m_models[feed], SLOT(slotEntryChanged(
KNS::Entry*)));
436 populateSortCombo(provider);
443 Q_ASSERT(thisModel != NULL);
449 Q_ASSERT(m_models[feed] != NULL);
451 m_models[feed]->removeEntry(entry);
456 m_sourceCombo->clear();
458 Q_ASSERT(m_entriesByProvider.keys().size() > 0);
460 for (
int i = 0; i < m_entriesByProvider.keys().count(); i++) {
461 const Provider *provider = m_entriesByProvider.keys().at(i);
472 slotLoadProviderDXS();
484 void DownloadDialog::populateSortCombo(
const Provider * provider)
488 m_providerLinkLabel->hide();
490 m_providerLinkLabel->setText(
QString(
"<a href=\"%1\">?</a>").arg(url));
494 m_sortCombo->clear();
495 for (
int i = 0; i < feeds.size(); ++i) {
497 kDebug(551) <<
"adding feed " << feeds[i] <<
" to combobox";
498 m_sortCombo->addItem(feedName, feeds[i]);
506 infostring +=
i18n(
"<br />Provider: %1", provider);
507 infostring +=
i18n(
"<br />Version: %1", version);
511 i18n(
"Provider information"));
514 void DownloadDialog::slotComments(
QStringList comments)
516 QPointer<KDXSComments> commentsdlg =
new KDXSComments(
this);
518 for (QStringList::const_iterator it = comments.constBegin(); it != comments.constEnd(); ++it) {
520 commentsdlg->addComment(
"foo", (*it));
529 void DownloadDialog::slotEntryChanged(
KNS::Entry * entry)
532 setCursor(Qt::ArrowCursor);
537 setCursor(Qt::ArrowCursor);
539 i18n(
"Get Hot New Stuff!"));
542 void DownloadDialog::slotPayloadLoaded(
KUrl url)
545 setCursor(Qt::ArrowCursor);
550 m_progress->addProgress(text, percentage);
553 void DownloadDialog::slotProvidersFailed()
555 kDebug(551) <<
"slotProvidersFailed";
557 i18n(
"There was an error loading data providers."),
558 i18n(
"Get Hot New Stuff"));
585 void DownloadDialog::slotFault()
588 i18n(
"A protocol fault has occurred. The request has failed."),
589 i18n(
"Desktop Exchange Service"));
592 void DownloadDialog::slotError()
595 i18n(
"A network error has occurred. The request has failed."),
596 i18n(
"Desktop Exchange Service"));
599 #include "downloaddialog.moc"
QString i18n(const char *text)
void call_comments(int id)
void call_rating(int id, int rating)
Change the rating.
void displayMessage(const QString &msg, KTitleWidget::MessageType type=KTitleWidget::PlainMessage, int timeOutMs=0)
KTranslatable name() const
Retrieves the common name of the provider.
QPixmap DesktopIcon(const QString &name, int force_size, int state, const QStringList &overlays)
void call_comment(int id, QString comment)
KTranslatable name() const
Retrieve the name of the feed.
KNewStuff data entry container.
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
const char * name(StandardAction id)
QString email() const
Retrieve the author's email address.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KTranslatable name() const
Retrieve the name of the data object.
QString i18nc(const char *ctxt, const char *text)
KSharedConfigPtr config()
Dxs * dxsObject(const Provider *provider)
virtual void hideEvent(QHideEvent *event)
KNewStuff rating submission window.
Feed * downloadUrlFeed(const QString &feedtype) const
Feed to retrieve for the given feed type.
KUrl webAccess() const
Retrieves the web frontend URL.
QStringList feeds() const
Returns a list of all feeds.
Author author() const
Retrieve the author of the object.
DownloadDialog(DxsEngine *engine, QWidget *parent)
QString pathOrUrl() const
KComponentData activeComponent()
void addEntry(Entry *entry)
CopyJob * link(const KUrl &src, const KUrl &destDir, JobFlags flags=DefaultFlags)
bool uninstall(KNS::Entry *entry)
Uninstalls an entry.
QString representation() const
Returns the string which matches most closely the current language.
void installItem(Entry *entry)
QString id() const
Retrieve the unique id of the category.
KNS::Entry * entryForIndex(const QModelIndex &index) const
void removeItem(Entry *entry)
KTranslatable name() const
Retrieve the name of the category.
KUrl icon() const
Retrieve the icon of the category.
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
KUrl webService() const
Retrieves the URL to the DXS Web Service.
KNewStuff provider container.
KNewStuff download dialog.
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
void downloadPayload(Entry *entry)
Downloads a payload file.