00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "downloaddialog.h"
00022 #include "downloaddialog.moc"
00023
00024 #include <klocale.h>
00025 #include <klistview.h>
00026 #include <kdebug.h>
00027 #include <kio/job.h>
00028 #include <kio/netaccess.h>
00029 #include <kmessagebox.h>
00030 #include <kurl.h>
00031 #include <kconfig.h>
00032 #include <kapplication.h>
00033 #include <kiconloader.h>
00034
00035 #include <knewstuff/entry.h>
00036 #include <knewstuff/knewstuffgeneric.h>
00037 #include <knewstuff/engine.h>
00038
00039 #include <qlayout.h>
00040 #include <qpushbutton.h>
00041 #include <qdom.h>
00042 #include <qlabel.h>
00043 #include <qtextbrowser.h>
00044 #include <qtabwidget.h>
00045 #include <qtimer.h>
00046
00047 using namespace KNS;
00048
00049 struct DownloadDialog::Private
00050 {
00051 QString m_providerlist;
00052 QWidget *m_page;
00053 KListView *m_lvtmp_r, *m_lvtmp_d, *m_lvtmp_l;
00054 QPtrList<Entry> m_installlist;
00055 QMap<KIO::Job*, Provider*> m_variantjobs;
00056 QMap<KIO::Job*, QStringList> m_variants;
00057 QMap<Provider*, Provider*> m_newproviders;
00058 };
00059
00060 class NumSortListViewItem : public KListViewItem
00061 {
00062 public:
00063 NumSortListViewItem( QListView * parent, QString label1, QString label2 = QString::null, QString label3 = QString::null, QString label4 = QString::null, QString label5 = QString::null, QString label6 = QString::null, QString label7 = QString::null, QString label8 = QString::null ) :
00064 KListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
00065 {
00066 }
00067
00068 QString key(int col, bool asc) const {
00069 if (col == 2)
00070 {
00071 QString s;
00072 s.sprintf("%08d", text(col).toInt());
00073 return s;
00074 }
00075 return KListViewItem::key( col, asc );
00076 }
00077 };
00078
00079 class DateSortListViewItem : public KListViewItem
00080 {
00081 public:
00082 DateSortListViewItem( QListView * parent, QString label1, QString label2 = QString::null, QString label3 = QString::null, QString label4 = QString::null, QString label5 = QString::null, QString label6 = QString::null, QString label7 = QString::null, QString label8 = QString::null ) :
00083 KListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
00084 {
00085 }
00086
00087 QString key(int col, bool asc) const {
00088 if (col == 2)
00089 {
00090 QString s;
00091 QDate date = KGlobal::locale()->readDate(text(col));
00092 s.sprintf("%08d", date.year() * 366 + date.dayOfYear());
00093 return s;
00094 }
00095 return KListViewItem::key( col, asc );
00096 }
00097 };
00098
00099
00100 DownloadDialog::DownloadDialog(Engine *engine, QWidget *)
00101 : KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"),
00102 KDialogBase::Close, KDialogBase::Close)
00103 {
00104 init(engine);
00105 }
00106
00107 DownloadDialog::DownloadDialog(QWidget *)
00108 : KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"),
00109 KDialogBase::Close, KDialogBase::Close)
00110 {
00111 init(0);
00112 }
00113
00114 void DownloadDialog::open(QString type)
00115 {
00116 DownloadDialog d;
00117 d.setType(type);
00118 d.load();
00119 d.exec();
00120 }
00121
00122
00123 DownloadDialog::DownloadDialog(Engine *engine, QWidget *, const QString& caption)
00124 : KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption),
00125 KDialogBase::Close, KDialogBase::Close)
00126 {
00127 init(engine);
00128 }
00129
00130 DownloadDialog::DownloadDialog(QWidget *, const QString& caption)
00131 : KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption),
00132 KDialogBase::Close, KDialogBase::Close)
00133 {
00134 init(0);
00135 }
00136
00137 void DownloadDialog::init(Engine *engine)
00138 {
00139 resize(700, 400);
00140 d = new Private();
00141
00142 m_engine = engine;
00143 d->m_page = NULL;
00144
00145 connect(this, SIGNAL(aboutToShowPage(QWidget*)), SLOT(slotPage(QWidget*)));
00146
00147 if(!engine)
00148 {
00149 m_loader = new ProviderLoader(this);
00150 connect(m_loader, SIGNAL(providersLoaded(Provider::List*)), SLOT(slotProviders(Provider::List*)));
00151 }
00152
00153 m_entries.setAutoDelete(true);
00154 }
00155
00156 DownloadDialog::~DownloadDialog()
00157 {
00158 for (QMap<QWidget *, QValueList<QPushButton *>* >::const_iterator it = m_buttons.constBegin(); it != m_buttons.constEnd(); ++it)
00159 delete it.data();
00160 for (QMap<QWidget *, QValueList<KListView *>* >::const_iterator it = m_map.constBegin(); it != m_map.constEnd(); ++it)
00161 delete it.data();
00162 delete d;
00163 }
00164
00165 void DownloadDialog::load()
00166 {
00167 m_loader->load(m_filter, d->m_providerlist);
00168 }
00169
00170 void DownloadDialog::load(QString providerList)
00171 {
00172 m_loader->load(m_filter, providerList);
00173 }
00174
00175 void DownloadDialog::clear()
00176 {
00177 QMap<QWidget*, QValueList<KListView*>* >::Iterator it;
00178 QMap<QWidget*, QValueList<KListView*>* >::Iterator end(m_map.end());
00179 for(it = m_map.begin(); it != end; ++it)
00180 {
00181 QValueList<KListView*> *v = it.data();
00182 kdDebug() << "clear listviews in " << v << endl;
00183 if(v)
00184 {
00185 (*(v->at(0)))->clear();
00186 (*(v->at(1)))->clear();
00187 (*(v->at(2)))->clear();
00188
00189
00190 }
00191
00192 delete it.key();
00193 }
00194 m_map.clear();
00195 }
00196
00197 void DownloadDialog::slotProviders(Provider::List *list)
00198 {
00199 Provider *p;
00200
00201
00202 for(p = list->first(); p; p = list->next())
00203 {
00204 kdDebug() << "++ provider ++ " << p->name() << endl;
00205
00206 if(!m_filter.isEmpty())
00207 loadProvider(p);
00208 else
00209 addProvider(p);
00210
00211
00212 }
00213 }
00214
00215 void DownloadDialog::addProvider(Provider *p)
00216 {
00217 QFrame *frame;
00218 QTabWidget *ctl;
00219 QWidget *w_d, *w_r, *w_l;
00220 QWidget *w2;
00221 QTextBrowser *rt;
00222 QString tmp;
00223 int ret;
00224 QPixmap pix;
00225
00226 if(m_map.count() == 0)
00227 {
00228 frame = addPage(i18n("Welcome"), i18n("Welcome"), QPixmap(""));
00229 delete frame;
00230 }
00231
00232 kdDebug() << "addProvider()/begin" << endl;
00233
00234 ret = true;
00235 if(p->icon().path().isEmpty()) ret = false;
00236 else
00237 {
00238 if(!p->icon().protocol().isEmpty())
00239 {
00240 ret = KIO::NetAccess::download(p->icon(), tmp, this);
00241 if(ret) pix = QPixmap(tmp);
00242 }
00243 else
00244 {
00245 pix = KGlobal::iconLoader()->loadIcon(p->icon().path(), KIcon::Panel);
00246 ret = true;
00247 }
00248 }
00249 if(!ret) pix = KGlobal::iconLoader()->loadIcon("knewstuff", KIcon::Panel);
00250 frame = addPage(p->name(), p->name(), pix);
00251 m_frame = frame;
00252
00253 w2 = new QWidget(frame);
00254 w_d = new QWidget(frame);
00255 w_r = new QWidget(frame);
00256 w_l = new QWidget(frame);
00257
00258 ctl = new QTabWidget(frame);
00259 ctl->addTab(w_r, i18n("Highest Rated"));
00260 ctl->addTab(w_d, i18n("Most Downloads"));
00261 ctl->addTab(w_l, i18n("Latest"));
00262
00263 m_curtab = 0;
00264 connect(ctl, SIGNAL(currentChanged(QWidget *)), SLOT(slotTab()));
00265
00266 QHBoxLayout *box = new QHBoxLayout(frame);
00267 box->add(ctl);
00268
00269 d->m_lvtmp_r = new KListView(w_r);
00270 d->m_lvtmp_r->addColumn(i18n("Name"));
00271 d->m_lvtmp_r->addColumn(i18n("Version"));
00272 d->m_lvtmp_r->addColumn(i18n("Rating"));
00273 d->m_lvtmp_r->setSorting(2, false);
00274
00275 d->m_lvtmp_d = new KListView(w_d);
00276 d->m_lvtmp_d->addColumn(i18n("Name"));
00277 d->m_lvtmp_d->addColumn(i18n("Version"));
00278 d->m_lvtmp_d->addColumn(i18n("Downloads"));
00279 d->m_lvtmp_d->setSorting(2, false);
00280
00281 d->m_lvtmp_l = new KListView(w_l);
00282 d->m_lvtmp_l->addColumn(i18n("Name"));
00283 d->m_lvtmp_l->addColumn(i18n("Version"));
00284 d->m_lvtmp_l->addColumn(i18n("Release Date"));
00285 d->m_lvtmp_l->setSorting(2, false);
00286
00287 connect(d->m_lvtmp_r, SIGNAL(clicked(QListViewItem*)), SLOT(slotSelected()));
00288 connect(d->m_lvtmp_d, SIGNAL(clicked(QListViewItem*)), SLOT(slotSelected()));
00289 connect(d->m_lvtmp_l, SIGNAL(clicked(QListViewItem*)), SLOT(slotSelected()));
00290
00291 rt = new QTextBrowser(frame);
00292 rt->setMinimumWidth(150);
00293
00294 QPushButton *in = new QPushButton(i18n("Install"), frame);
00295 QPushButton *de = new QPushButton(i18n("Details"), frame);
00296 in->setEnabled(false);
00297 de->setEnabled(false);
00298
00299 box->addSpacing(spacingHint());
00300 QVBoxLayout *vbox = new QVBoxLayout(box);
00301 vbox->add(rt);
00302 vbox->addSpacing(spacingHint());
00303 vbox->add(de);
00304 vbox->add(in);
00305
00306 connect(rt, SIGNAL(linkClicked(const QString&)), SLOT(slotEmail(const QString&)));
00307
00308 connect(in, SIGNAL(clicked()), SLOT(slotInstall()));
00309 connect(de, SIGNAL(clicked()), SLOT(slotDetails()));
00310
00311 QVBoxLayout *box2 = new QVBoxLayout(w_r);
00312 box2->add(d->m_lvtmp_r);
00313 QVBoxLayout *box3 = new QVBoxLayout(w_d);
00314 box3->add(d->m_lvtmp_d);
00315 QVBoxLayout *box4 = new QVBoxLayout(w_l);
00316 box4->add(d->m_lvtmp_l);
00317
00318 QValueList<KListView*> *v = new QValueList<KListView*>;
00319 *v << d->m_lvtmp_r << d->m_lvtmp_d << d->m_lvtmp_l;
00320 m_map[frame] = v;
00321 m_rts[frame] = rt;
00322 QValueList<QPushButton*> *vb = new QValueList<QPushButton*>;
00323 *vb << in << de;
00324 m_buttons[frame] = vb;
00325 m_providers[frame] = p;
00326
00327 kdDebug() << "addProvider()/end; d->m_lvtmp_r = " << d->m_lvtmp_r << endl;
00328
00329 if(m_engine) slotPage(frame);
00330
00331 QTimer::singleShot(100, this, SLOT(slotFinish()));
00332 }
00333
00334 void DownloadDialog::slotResult(KIO::Job *job)
00335 {
00336 QDomDocument dom;
00337 QDomElement knewstuff;
00338
00339 kdDebug() << "got data: " << m_data[job] << endl;
00340
00341 kapp->config()->setGroup("KNewStuffStatus");
00342
00343 dom.setContent(m_data[job]);
00344 knewstuff = dom.documentElement();
00345
00346 for(QDomNode pn = knewstuff.firstChild(); !pn.isNull(); pn = pn.nextSibling())
00347 {
00348 QDomElement stuff = pn.toElement();
00349
00350 kdDebug() << "element: " << stuff.tagName() << endl;
00351
00352 if(stuff.tagName() == "stuff")
00353 {
00354 Entry *entry = new Entry(stuff);
00355 kdDebug() << "TYPE::" << entry->type() << " FILTER::" << m_filter << endl;
00356 if(!entry->type().isEmpty())
00357 {
00358 if((!m_filter.isEmpty()) && (entry->type() != m_filter)) continue;
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 if((!m_filter.isEmpty()) && (d->m_variantjobs[job]))
00372 {
00373 Provider *p = d->m_variantjobs[job];
00374 if(d->m_newproviders[p])
00375 {
00376 addProvider(p);
00377 slotPage(m_frame);
00378 d->m_newproviders[p] = 0;
00379 }
00380 }
00381
00382
00383
00384 if(d->m_variantjobs[job]) addEntry(entry, d->m_variants[job]);
00385 }
00386 }
00387 }
00388
00389 int DownloadDialog::installStatus(Entry *entry)
00390 {
00391 QDate date;
00392 QString datestring;
00393 int installed;
00394
00395 QString lang = KGlobal::locale()->language();
00396
00397 kapp->config()->setGroup("KNewStuffStatus");
00398 datestring = kapp->config()->readEntry(entry->name(lang));
00399 if(datestring.isNull()) installed = 0;
00400 else
00401 {
00402 date = QDate::fromString(datestring, Qt::ISODate);
00403 if(!date.isValid()) installed = 0;
00404 else if(date < entry->releaseDate()) installed = -1;
00405 else installed = 1;
00406 }
00407
00408 return installed;
00409 }
00410
00411 void DownloadDialog::addEntry(Entry *entry, const QStringList& variants)
00412 {
00413 QPixmap pix;
00414 int installed;
00415
00416 installed = installStatus(entry);
00417
00418 if(installed > 0) pix = KGlobal::iconLoader()->loadIcon("ok", KIcon::Small);
00419 else if(installed < 0) pix = KGlobal::iconLoader()->loadIcon("history", KIcon::Small);
00420 else pix = QPixmap();
00421
00422 QString lang = KGlobal::locale()->language();
00423
00424 if(variants.contains("score"))
00425 {
00426 KListViewItem *tmp_r = new NumSortListViewItem(lv_r,
00427 entry->name(lang), entry->version(), QString("%1").arg(entry->rating()));
00428 tmp_r->setPixmap(0, pix);
00429 }
00430 if(variants.contains("downloads"))
00431 {
00432 KListViewItem *tmp_d = new NumSortListViewItem(lv_d,
00433 entry->name(lang), entry->version(), QString("%1").arg(entry->downloads()));
00434 tmp_d->setPixmap(0, pix);
00435 }
00436 if(variants.contains("latest"))
00437 {
00438 KListViewItem *tmp_l = new DateSortListViewItem(lv_l,
00439 entry->name(lang), entry->version(), KGlobal::locale()->formatDate(entry->releaseDate()));
00440 tmp_l->setPixmap(0, pix);
00441 }
00442
00443 m_entries.append(entry);
00444
00445 kdDebug() << "added entry " << entry->name() << " for variants " << variants << endl;
00446 }
00447
00448 void DownloadDialog::addEntry(Entry *entry)
00449 {
00450 QStringList variants;
00451
00452 variants << "score";
00453 variants << "downloads";
00454 variants << "latest";
00455
00456 addEntry(entry, variants);
00457
00458
00459 kdDebug() << "added entry " << entry->name() << endl;
00460 }
00461
00462 void DownloadDialog::slotData(KIO::Job *job, const QByteArray &a)
00463 {
00464 QCString tmp(a, a.size() + 1);
00465 m_data[job].append(QString::fromUtf8(tmp));
00466 }
00467
00468 void DownloadDialog::slotDetails()
00469 {
00470 Entry *e = getEntry();
00471 if(!e) return;
00472
00473 QString lang = KGlobal::locale()->language();
00474
00475 QString info = i18n
00476 (
00477 "Name: %1\n"
00478 "Author: %2\n"
00479 "License: %3\n"
00480 "Version: %4\n"
00481 "Release: %5\n"
00482 "Rating: %6\n"
00483 "Downloads: %7\n"
00484 "Release date: %8\n"
00485 "Summary: %9\n"
00486 ).arg(e->name(lang)
00487 ).arg(e->author()
00488 ).arg(e->license()
00489 ).arg(e->version()
00490 ).arg(e->release()
00491 ).arg(e->rating()
00492 ).arg(e->downloads()
00493 ).arg(KGlobal::locale()->formatDate(e->releaseDate())
00494 ).arg(e->summary(lang)
00495 );
00496
00497 info.append(i18n
00498 (
00499 "Preview: %1\n"
00500 "Payload: %2\n"
00501 ).arg(e->preview().url()
00502 ).arg(e->payload().url()
00503 ));
00504
00505 KMessageBox::information(this, info, i18n("Details"));
00506 }
00507
00508 QListViewItem *DownloadDialog::currentEntryItem()
00509 {
00510 if((m_curtab == 0) && (lv_r->selectedItem())) return lv_r->selectedItem();
00511 if((m_curtab == 1) && (lv_d->selectedItem())) return lv_d->selectedItem();
00512 if((m_curtab == 2) && (lv_l->selectedItem())) return lv_l->selectedItem();
00513
00514 return 0;
00515 }
00516
00517 void DownloadDialog::slotInstall()
00518 {
00519 Entry *e = getEntry();
00520 if(!e) return;
00521
00522 d->m_lvtmp_r->setEnabled( false );
00523 d->m_lvtmp_l->setEnabled( false );
00524 d->m_lvtmp_d->setEnabled( false );
00525 m_entryitem = currentEntryItem();
00526 m_entryname = m_entryitem->text(0);
00527
00528 kdDebug() << "download entry now" << endl;
00529
00530 if(m_engine)
00531 {
00532 m_engine->download(e);
00533 install(e);
00534 }
00535 else
00536 {
00537 m_s = new KNewStuffGeneric(e->type(), this);
00538 m_entry = e;
00539 KURL source = e->payload();
00540 KURL dest = KURL(m_s->downloadDestination(e));
00541
00542 KIO::FileCopyJob *job = KIO::file_copy(source, dest, -1, true);
00543 connect(job, SIGNAL(result(KIO::Job*)), SLOT(slotInstalled(KIO::Job*)));
00544 }
00545 }
00546
00547 void DownloadDialog::install(Entry *e)
00548 {
00549 kapp->config()->setGroup("KNewStuffStatus");
00550 kapp->config()->writeEntry(m_entryname, e->releaseDate().toString(Qt::ISODate));
00551 kapp->config()->sync();
00552
00553 QPixmap pix = KGlobal::iconLoader()->loadIcon("ok", KIcon::Small);
00554
00555 QString lang = KGlobal::locale()->language();
00556
00557 if(m_entryitem)
00558 {
00559 m_entryitem->setPixmap(0, pix);
00560
00561 QListViewItem *item;
00562 item = lv_r->findItem(e->name(lang), 0);
00563 if(item) item->setPixmap(0, pix);
00564 item = lv_d->findItem(e->name(lang), 0);
00565 if(item) item->setPixmap(0, pix);
00566 item = lv_l->findItem(e->name(lang), 0);
00567 if(item) item->setPixmap(0, pix);
00568 }
00569
00570 if(currentEntryItem() == m_entryitem)
00571 {
00572 QPushButton *in;
00573 in = *(m_buttons[d->m_page]->at(0));
00574 if(in) in->setEnabled(false);
00575 }
00576
00577 d->m_installlist.append(e);
00578 d->m_lvtmp_r->setEnabled( true );
00579 d->m_lvtmp_l->setEnabled( true );
00580 d->m_lvtmp_d->setEnabled( true );
00581 }
00582
00583 void DownloadDialog::slotInstalled(KIO::Job *job)
00584 {
00585 bool ret = job && (job->error() == 0);
00586 if(ret)
00587 {
00588 KIO::FileCopyJob *cjob = ::qt_cast<KIO::FileCopyJob*>(job);
00589 if(cjob)
00590 {
00591 ret = m_s->install(cjob->destURL().path());
00592 }
00593 else ret = false;
00594 }
00595
00596 if(ret)
00597 {
00598 install(m_entry);
00599
00600 KMessageBox::information(this, i18n("Installation successful."), i18n("Installation"));
00601 }
00602 else KMessageBox::error(this, i18n("Installation failed."), i18n("Installation"));
00603 d->m_lvtmp_r->setEnabled( true );
00604 d->m_lvtmp_l->setEnabled( true );
00605 d->m_lvtmp_d->setEnabled( true );
00606
00607 delete m_s;
00608 }
00609
00610 void DownloadDialog::slotTab()
00611 {
00612 int tab = static_cast<const QTabWidget *>(sender())->currentPageIndex();
00613 kdDebug() << "switch tab to: " << tab << endl;
00614
00615 Entry *eold = getEntry();
00616 m_curtab = tab;
00617 Entry *e = getEntry();
00618
00619 if(e == eold) return;
00620
00621 if(e)
00622 {
00623 slotSelected();
00624 }
00625 else
00626 {
00627 QPushButton *de, *in;
00628 in = *(m_buttons[d->m_page]->at(0));
00629 de = *(m_buttons[d->m_page]->at(1));
00630
00631 if(in) in->setEnabled(false);
00632 if(de) de->setEnabled(false);
00633
00634 m_rt->clear();
00635 }
00636 }
00637
00638 void DownloadDialog::slotSelected()
00639 {
00640 QString tmp;
00641 bool enabled;
00642 Entry *e = getEntry();
00643 QString lang = KGlobal::locale()->language();
00644 bool ret;
00645
00646 if(e)
00647 {
00648 QString lang = KGlobal::locale()->language();
00649
00650 QListViewItem *item;
00651 if(m_curtab != 0)
00652 {
00653 lv_r->clearSelection();
00654 item = lv_r->findItem(e->name(lang), 0);
00655 if(item) lv_r->setSelected(item, true);
00656 }
00657 if(m_curtab != 1)
00658 {
00659 lv_d->clearSelection();
00660 item = lv_d->findItem(e->name(lang), 0);
00661 if(item) lv_d->setSelected(item, true);
00662 }
00663 if(m_curtab != 2)
00664 {
00665 lv_l->clearSelection();
00666 item = lv_l->findItem(e->name(lang), 0);
00667 if(item) lv_l->setSelected(item, true);
00668 }
00669
00670 if(!e->preview(lang).isValid())
00671 {
00672 ret = 0;
00673 }
00674 else
00675 {
00676 ret = KIO::NetAccess::download(e->preview(lang), tmp, this);
00677 }
00678
00679 QString desc = QString("<b>%1</b><br>").arg(e->name(lang));
00680 if(!e->authorEmail().isNull())
00681 {
00682 desc += QString("<a href='mailto:" + e->authorEmail() + "'>" + e->author() + "</a>");
00683 }
00684 else
00685 {
00686 desc += QString("%1").arg(e->author());
00687 }
00688 desc += QString("<br>%1").arg(KGlobal::locale()->formatDate(e->releaseDate()));
00689 desc += QString("<br><br>");
00690 if(ret)
00691 {
00692 desc += QString("<img src='%1'>").arg(tmp);
00693 }
00694 else
00695 {
00696 desc += i18n("Preview not available.");
00697 }
00698 desc += QString("<br><i>%1</i>").arg(e->summary(lang));
00699 desc += QString("<br>(%1)").arg(e->license());
00700
00701 m_rt->clear();
00702 m_rt->setText(desc);
00703
00704 if(installStatus(e) == 1) enabled = false;
00705 else enabled = true;
00706
00707 QPushButton *de, *in;
00708 in = *(m_buttons[d->m_page]->at(0));
00709 de = *(m_buttons[d->m_page]->at(1));
00710 if(in) in->setEnabled(enabled);
00711 if(de) de->setEnabled(true);
00712 }
00713 }
00714
00715 void DownloadDialog::slotEmail(const QString& link)
00716 {
00717 kdDebug() << "EMAIL: " << link << endl;
00718 kapp->invokeMailer(link);
00719 slotSelected();
00720 }
00721
00722 Entry *DownloadDialog::getEntry()
00723 {
00724 QListViewItem *entryItem = currentEntryItem();
00725
00726 if(!entryItem)
00727 return 0;
00728
00729 QString entryName = entryItem->text(0);
00730
00731 QString lang = KGlobal::locale()->language();
00732
00733 for(Entry *e = m_entries.first(); e; e = m_entries.next())
00734 if(e->name(lang) == entryName)
00735 return e;
00736
00737 return 0;
00738 }
00739
00740 void DownloadDialog::slotPage(QWidget *w)
00741 {
00742 Provider *p;
00743
00744 kdDebug() << "changed widget!!!" << endl;
00745
00746 if(m_map.find(w) == m_map.end()) return;
00747
00748 d->m_page = w;
00749
00750 lv_r = *(m_map[w]->at(0));
00751 lv_d = *(m_map[w]->at(1));
00752 lv_l = *(m_map[w]->at(2));
00753 p = m_providers[w];
00754 m_rt = m_rts[w];
00755
00756 kdDebug() << "valid change!!!; lv_r = " << lv_r << endl;
00757
00758 if(m_engine) return;
00759
00760 if(!m_filter.isEmpty()) return;
00761
00762 lv_r->clear();
00763 lv_d->clear();
00764 lv_l->clear();
00765
00766 kdDebug() << "-- fetch -- " << p->downloadUrl() << endl;
00767
00768 loadProvider(p);
00769 }
00770
00771 void DownloadDialog::loadProvider(Provider *p)
00772 {
00773 QMap<KIO::Job*, Provider*>::Iterator it;
00774
00775 for(it = d->m_variantjobs.begin(); it != d->m_variantjobs.end(); it++)
00776 {
00777 if(it.data() == p)
00778 {
00779 kdDebug() << "-- found provider data in cache" << endl;
00780 slotResult(it.key());
00781 return;
00782 }
00783 }
00784
00785 QStringList variants;
00786 variants << "score";
00787 variants << "downloads";
00788 variants << "latest";
00789
00790
00791
00792 QMap<QString, QStringList> urls;
00793
00794 for(QStringList::Iterator it = variants.begin(); it != variants.end(); it++)
00795 {
00796 QString url = p->downloadUrlVariant((*it)).url();
00797 if(!urls.contains(url))
00798 {
00799 urls[url] = QStringList();
00800 }
00801 urls[url] << (*it);
00802
00803 it = variants.remove(it);
00804 }
00805
00806
00807
00808 for(QMap<QString, QStringList>::Iterator it = urls.begin(); it != urls.end(); it++)
00809 {
00810 QString url = it.key();
00811 QStringList urlvariants = it.data();
00812
00813 KIO::TransferJob *variantjob = KIO::get(url);
00814 d->m_newproviders[p] = p;
00815 d->m_variantjobs[variantjob] = p;
00816 d->m_variants[variantjob] = urlvariants;
00817 m_data[variantjob] = "";
00818
00819 connect(variantjob, SIGNAL(result(KIO::Job*)), SLOT(slotResult(KIO::Job*)));
00820 connect(variantjob, SIGNAL(data(KIO::Job*, const QByteArray&)),
00821 SLOT(slotData(KIO::Job*, const QByteArray&)));
00822 }
00823
00824 if(variants.count() == 0) return;
00825
00826
00827
00828 kdDebug() << "-- reached old downloadurl section; variants left: " << variants.count() << endl;
00829
00830 KIO::TransferJob *job = KIO::get(p->downloadUrl());
00831
00832 d->m_newproviders[p] = p;
00833 d->m_variantjobs[job] = p;
00834 d->m_variants[job] = variants;
00835
00836 m_data[job] = "";
00837
00838 connect(job, SIGNAL(result(KIO::Job*)), SLOT(slotResult(KIO::Job*)));
00839 connect(job, SIGNAL(data(KIO::Job*, const QByteArray&)),
00840 SLOT(slotData(KIO::Job*, const QByteArray&)));
00841 }
00842
00843 void DownloadDialog::setType(QString type)
00844 {
00845 m_filter = type;
00846 }
00847
00848 void DownloadDialog::setProviderList(const QString& providerList)
00849 {
00850 d->m_providerlist = providerList;
00851 }
00852
00853 void DownloadDialog::slotOk()
00854 {
00855 }
00856
00857 void DownloadDialog::slotApply()
00858 {
00859 }
00860
00861 void DownloadDialog::open(const QString& type, const QString& caption)
00862 {
00863 DownloadDialog d(0, caption);
00864 d.setType(type);
00865 d.load();
00866 d.exec();
00867 }
00868
00869 void DownloadDialog::slotFinish()
00870 {
00871 showPage(1);
00872
00873 }
00874
00875 QPtrList<Entry> DownloadDialog::installedEntries()
00876 {
00877 return d->m_installlist;
00878 }