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()));
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()));
125 setMinimumSize(700, 400);
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*)));
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) {
186 connect(dxs, SIGNAL(signalComments(QStringList)),
this, SLOT(slotComments(QStringList)));
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();
249void DownloadDialog::slotCollabAction(
QAction * action)
252 QModelIndex currentIndex = m_listView->currentIndex();
253 const ItemsModel * realmodel = qobject_cast<const ItemsModel*>(m_filteredModel->sourceModel());
254 QModelIndex index = m_filteredModel->mapToSource(currentIndex);
256 slotPerformAction(entryAction, entry);
259void DownloadDialog::slotListIndexChanged(
const QModelIndex &index,
const QModelIndex &)
263 m_collaborationButton->setEnabled(m_hasDxs && index.isValid());
276 messageTimer->stop();
279 m_titleWidget->setComment(msg, type);
284 messageTimer->start(timeOutMs);
298 slotEntryChanged(entry);
307void DownloadDialog::slotResetMessage()
309 m_titleWidget->setComment(QString());
312void DownloadDialog::slotNetworkTimeout()
317void 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);
334void 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);
361void DownloadDialog::slotUpdateSearch()
363 m_searchTimer->stop();
364 m_filteredModel->setFilterFixedString(m_searchEdit->text());
365 m_filteredModel->invalidate();
368void DownloadDialog::slotLoadProvidersListDXS()
372void DownloadDialog::slotSearchTextChanged()
374 m_searchTimer->start();
394 slotLoadProviderDXS();
405void DownloadDialog::slotEntriesFailed()
411void 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();
484void DownloadDialog::populateSortCombo(
const Provider * provider)
488 m_providerLinkLabel->hide();
490 m_providerLinkLabel->setText(QString(
"<a href=\"%1\">?</a>").arg(url));
493 QStringList feeds = provider->
feeds();
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]);
502void DownloadDialog::slotInfo(QString provider, QString server, QString version)
504 QString
link = QString(
"<a href=\"%1\">%1</a>").arg(server);
505 QString infostring =
i18n(
"Server: %1", link);
506 infostring +=
i18n(
"<br />Provider: %1", provider);
507 infostring +=
i18n(
"<br />Version: %1", version);
511 i18n(
"Provider information"));
514void 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));
529void DownloadDialog::slotEntryChanged(
KNS::Entry * entry)
532 setCursor(Qt::ArrowCursor);
535void DownloadDialog::slotPayloadFailed(
KNS::Entry * entry)
537 setCursor(Qt::ArrowCursor);
539 i18n(
"Get Hot New Stuff!"));
542void DownloadDialog::slotPayloadLoaded(
KUrl url)
545 setCursor(Qt::ArrowCursor);
548void DownloadDialog::slotProgress(
const QString & text,
int percentage)
550 m_progress->addProgress(text, percentage);
553void DownloadDialog::slotProvidersFailed()
555 kDebug(551) <<
"slotProvidersFailed";
557 i18n(
"There was an error loading data providers."),
558 i18n(
"Get Hot New Stuff"));
585void DownloadDialog::slotFault()
588 i18n(
"A protocol fault has occurred. The request has failed."),
589 i18n(
"Desktop Exchange Service"));
592void DownloadDialog::slotError()
595 i18n(
"A network error has occurred. The request has failed."),
596 i18n(
"Desktop Exchange Service"));
599#include "downloaddialog.moc"
KNewStuff rating submission window.
void setMainWidget(QWidget *widget)
virtual void hideEvent(QHideEvent *)
void saveDialogSize(KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal) const
void restoreDialogSize(const KConfigGroup &config)
void setButtons(ButtonCodes buttonMask)
virtual void setCaption(const QString &caption)
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
QString email() const
Retrieve the author's email address.
KTranslatable name() const
Retrieve the name of the category.
QString id() const
Retrieve the unique id of the category.
KUrl icon() const
Retrieve the icon of the category.
void downloadPayload(Entry *entry)
Downloads a payload file.
bool uninstall(KNS::Entry *entry)
Uninstalls an entry.
virtual void hideEvent(QHideEvent *event)
void displayMessage(const QString &msg, KTitleWidget::MessageType type=KTitleWidget::PlainMessage, int timeOutMs=0)
void installItem(Entry *entry)
void removeItem(Entry *entry)
DownloadDialog(DxsEngine *engine, QWidget *parent)
Dxs * dxsObject(const Provider *provider)
void call_rating(int id, int rating)
void call_comments(int id)
void call_comment(int id, QString comment)
KNewStuff data entry container.
KTranslatable name() const
Retrieve the name of the data object.
Author author() const
Retrieve the author of the object.
KTranslatable name() const
Retrieve the name of the feed.
KNS::Entry * entryForIndex(const QModelIndex &index) const
@ kNameRole
the name of the entry
void addEntry(Entry *entry)
QString representation() const
Returns the string which matches most closely the current language.
KNewStuff provider container.
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.
KTranslatable name() const
Retrieves the common name of the provider.
KUrl webService() const
Retrieves the URL to the DXS Web Service.
QString pathOrUrl() const
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
QPixmap DesktopIcon(const QString &name, int force_size, int state, const QStringList &overlays)
QString i18n(const char *text)
QString i18nc(const char *ctxt, const char *text)
KSharedConfigPtr config()
KComponentData activeComponent()
CopyJob * link(const KUrl &src, const KUrl &destDir, JobFlags flags=DefaultFlags)
const char * name(StandardAction id)