• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • knewstuff
 

knewstuff

  • knewstuff
downloaddialog.cpp
1 /*
2  This file is part of KNewStuff.
3  Copyright (c) 2003 Josef Spillner <spillner@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "downloaddialog.h"
22 #include "downloaddialog.moc"
23 
24 #include <klocale.h>
25 #include <klistview.h>
26 #include <kdebug.h>
27 #include <kio/job.h>
28 #include <kio/netaccess.h>
29 #include <kmessagebox.h>
30 #include <kurl.h>
31 #include <kconfig.h>
32 #include <kapplication.h>
33 #include <kiconloader.h>
34 
35 #include <knewstuff/entry.h>
36 #include <knewstuff/knewstuffgeneric.h>
37 #include <knewstuff/engine.h>
38 
39 #include <tqlayout.h>
40 #include <tqpushbutton.h>
41 #include <tqdom.h>
42 #include <tqlabel.h>
43 #include <tqtextbrowser.h>
44 #include <tqtabwidget.h>
45 #include <tqtimer.h> // hack
46 
47 using namespace KNS;
48 
49 struct DownloadDialog::Private
50 {
51  TQString m_providerlist;
52  TQWidget *m_page;
53  KListView *m_lvtmp_r, *m_lvtmp_d, *m_lvtmp_l;
54  TQPtrList<Entry> m_installlist;
55  TQMap<KIO::Job*, Provider*> m_variantjobs;
56  TQMap<KIO::Job*, TQStringList> m_variants;
57  TQMap<Provider*, Provider*> m_newproviders;
58 };
59 
60 class NumSortListViewItem : public KListViewItem
61 {
62  public:
63  NumSortListViewItem( TQListView * parent, TQString label1, TQString label2 = TQString::null, TQString label3 = TQString::null, TQString label4 = TQString::null, TQString label5 = TQString::null, TQString label6 = TQString::null, TQString label7 = TQString::null, TQString label8 = TQString::null ) :
64  KListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
65  {
66  }
67 
68  TQString key(int col, bool asc) const {
69  if (col == 2)
70  {
71  TQString s;
72  s.sprintf("%08d", text(col).toInt());
73  return s;
74  }
75  return KListViewItem::key( col, asc );
76  }
77 };
78 
79 class DateSortListViewItem : public KListViewItem
80 {
81  public:
82  DateSortListViewItem( TQListView * parent, TQString label1, TQString label2 = TQString::null, TQString label3 = TQString::null, TQString label4 = TQString::null, TQString label5 = TQString::null, TQString label6 = TQString::null, TQString label7 = TQString::null, TQString label8 = TQString::null ) :
83  KListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
84  {
85  }
86 
87  TQString key(int col, bool asc) const {
88  if (col == 2)
89  {
90  TQString s;
91  TQDate date = KGlobal::locale()->readDate(text(col));
92  s.sprintf("%08d", date.year() * 366 + date.dayOfYear());
93  return s;
94  }
95  return KListViewItem::key( col, asc );
96  }
97 };
98 
99 // BEGIN deprecated for KDE 4
100 DownloadDialog::DownloadDialog(Engine *engine, TQWidget *)
101 : KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"),
102  KDialogBase::Close, KDialogBase::Close)
103 {
104  init(engine);
105 }
106 
107 DownloadDialog::DownloadDialog(TQWidget *)
108 : KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"),
109  KDialogBase::Close, KDialogBase::Close)
110 {
111  init(0);
112 }
113 
114 void DownloadDialog::open(TQString type)
115 {
116  DownloadDialog d;
117  d.setType(type);
118  d.load();
119  d.exec();
120 }
121 // END deprecated for KDE 4
122 
123 DownloadDialog::DownloadDialog(Engine *engine, TQWidget *, const TQString& caption)
124 : KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption),
125  KDialogBase::Close, KDialogBase::Close)
126 {
127  init(engine);
128 }
129 
130 DownloadDialog::DownloadDialog(TQWidget *, const TQString& caption)
131 : KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption),
132  KDialogBase::Close, KDialogBase::Close)
133 {
134  init(0);
135 }
136 
137 void DownloadDialog::init(Engine *engine)
138 {
139  resize(700, 400);
140  d = new Private();
141 
142  m_engine = engine;
143  d->m_page = NULL;
144 
145  connect(this, TQT_SIGNAL(aboutToShowPage(TQWidget*)), TQT_SLOT(slotPage(TQWidget*)));
146 
147  if(!engine)
148  {
149  m_loader = new ProviderLoader(this);
150  connect(m_loader, TQT_SIGNAL(providersLoaded(Provider::List*)), TQT_SLOT(slotProviders(Provider::List*)));
151  }
152 
153  m_entries.setAutoDelete(true);
154 }
155 
156 DownloadDialog::~DownloadDialog()
157 {
158  for (TQMap<TQWidget *, TQValueList<TQPushButton *>* >::const_iterator it = m_buttons.constBegin(); it != m_buttons.constEnd(); ++it)
159  delete it.data();
160  for (TQMap<TQWidget *, TQValueList<KListView *>* >::const_iterator it = m_map.constBegin(); it != m_map.constEnd(); ++it)
161  delete it.data();
162  delete d;
163 }
164 
165 void DownloadDialog::load()
166 {
167  m_loader->load(m_filter, d->m_providerlist);
168 }
169 
170 void DownloadDialog::load(TQString providerList)
171 {
172  m_loader->load(m_filter, providerList);
173 }
174 
175 void DownloadDialog::clear()
176 {
177  TQMap<TQWidget*, TQValueList<KListView*>* >::Iterator it;
178  TQMap<TQWidget*, TQValueList<KListView*>* >::Iterator end(m_map.end());
179  for(it = m_map.begin(); it != end; ++it)
180  {
181  TQValueList<KListView*> *v = it.data();
182  kdDebug() << "clear listviews in " << v << endl;
183  if(v)
184  {
185  (*(v->at(0)))->clear();
186  (*(v->at(1)))->clear();
187  (*(v->at(2)))->clear();
188 
189  //delete (*it);
190  }
191 
192  delete it.key();
193  }
194  m_map.clear();
195 }
196 
197 void DownloadDialog::slotProviders(Provider::List *list)
198 {
199  Provider *p;
200  /*TQFrame *frame;*/
201 
202  for(p = list->first(); p; p = list->next())
203  {
204  kdDebug() << "++ provider ++ " << p->name() << endl;
205 
206  if(!m_filter.isEmpty())
207  loadProvider(p);
208  else
209  addProvider(p);
210  /*if(p == list->getFirst())
211  slotPage(m_frame);*/ // only if !qtbug
212  }
213 }
214 
215 void DownloadDialog::addProvider(Provider *p)
216 {
217  TQFrame *frame;
218  TQTabWidget *ctl;
219  TQWidget *w_d, *w_r, *w_l;
220  TQWidget *w2;
221  TQTextBrowser *rt;
222  TQString tmp;
223  int ret;
224  TQPixmap pix;
225 
226  if(m_map.count() == 0)
227  {
228  frame = addPage(i18n("Welcome"), i18n("Welcome"), TQPixmap(TQString("")));
229  delete frame;
230  }
231 
232  kdDebug() << "addProvider()/begin" << endl;
233 
234  ret = true;
235  if(p->icon().path().isEmpty()) ret = false;
236  else
237  {
238  if(!p->icon().protocol().isEmpty())
239  {
240  ret = KIO::NetAccess::download(p->icon(), tmp, this);
241  if(ret) pix = TQPixmap(tmp);
242  }
243  else
244  {
245  pix = KGlobal::iconLoader()->loadIcon(p->icon().path(), KIcon::Panel);
246  ret = true;
247  }
248  }
249  if(!ret) pix = KGlobal::iconLoader()->loadIcon("knewstuff", KIcon::Panel);
250  frame = addPage(p->name(), p->name(), pix);
251  m_frame = frame;
252 
253  w2 = new TQWidget(frame);
254  w_d = new TQWidget(frame);
255  w_r = new TQWidget(frame);
256  w_l = new TQWidget(frame);
257 
258  ctl = new TQTabWidget(frame);
259  ctl->addTab(w_r, i18n("Highest Rated"));
260  ctl->addTab(w_d, i18n("Most Downloads"));
261  ctl->addTab(w_l, i18n("Latest"));
262 
263  m_curtab = 0;
264  connect(ctl, TQT_SIGNAL(currentChanged(TQWidget *)), TQT_SLOT(slotTab()));
265 
266  TQHBoxLayout *box = new TQHBoxLayout(frame);
267  box->add(ctl);
268 
269  d->m_lvtmp_r = new KListView(w_r);
270  d->m_lvtmp_r->addColumn(i18n("Name"));
271  d->m_lvtmp_r->addColumn(i18n("Version"));
272  d->m_lvtmp_r->addColumn(i18n("Rating"));
273  d->m_lvtmp_r->setSorting(2, false);
274 
275  d->m_lvtmp_d = new KListView(w_d);
276  d->m_lvtmp_d->addColumn(i18n("Name"));
277  d->m_lvtmp_d->addColumn(i18n("Version"));
278  d->m_lvtmp_d->addColumn(i18n("Downloads"));
279  d->m_lvtmp_d->setSorting(2, false);
280 
281  d->m_lvtmp_l = new KListView(w_l);
282  d->m_lvtmp_l->addColumn(i18n("Name"));
283  d->m_lvtmp_l->addColumn(i18n("Version"));
284  d->m_lvtmp_l->addColumn(i18n("Release Date"));
285  d->m_lvtmp_l->setSorting(2, false);
286 
287  connect(d->m_lvtmp_r, TQT_SIGNAL(clicked(TQListViewItem*)), TQT_SLOT(slotSelected()));
288  connect(d->m_lvtmp_d, TQT_SIGNAL(clicked(TQListViewItem*)), TQT_SLOT(slotSelected()));
289  connect(d->m_lvtmp_l, TQT_SIGNAL(clicked(TQListViewItem*)), TQT_SLOT(slotSelected()));
290 
291  rt = new TQTextBrowser(frame);
292  rt->setMinimumWidth(150);
293 
294  TQPushButton *in = new TQPushButton(i18n("Install"), frame);
295  TQPushButton *de = new TQPushButton(i18n("Details"), frame);
296  in->setEnabled(false);
297  de->setEnabled(false);
298 
299  box->addSpacing(spacingHint());
300  TQVBoxLayout *vbox = new TQVBoxLayout(box);
301  vbox->add(rt);
302  vbox->addSpacing(spacingHint());
303  vbox->add(de);
304  vbox->add(in);
305 
306  connect(rt, TQT_SIGNAL(linkClicked(const TQString&)), TQT_SLOT(slotEmail(const TQString&)));
307 
308  connect(in, TQT_SIGNAL(clicked()), TQT_SLOT(slotInstall()));
309  connect(de, TQT_SIGNAL(clicked()), TQT_SLOT(slotDetails()));
310 
311  TQVBoxLayout *box2 = new TQVBoxLayout(w_r);
312  box2->add(d->m_lvtmp_r);
313  TQVBoxLayout *box3 = new TQVBoxLayout(w_d);
314  box3->add(d->m_lvtmp_d);
315  TQVBoxLayout *box4 = new TQVBoxLayout(w_l);
316  box4->add(d->m_lvtmp_l);
317 
318  TQValueList<KListView*> *v = new TQValueList<KListView*>;
319  *v << d->m_lvtmp_r << d->m_lvtmp_d << d->m_lvtmp_l;
320  m_map[frame] = v;
321  m_rts[frame] = rt;
322  TQValueList<TQPushButton*> *vb = new TQValueList<TQPushButton*>;
323  *vb << in << de;
324  m_buttons[frame] = vb;
325  m_providers[frame] = p;
326 
327  kdDebug() << "addProvider()/end; d->m_lvtmp_r = " << d->m_lvtmp_r << endl;
328 
329  if(m_engine) slotPage(frame);
330 
331  TQTimer::singleShot(100, this, TQT_SLOT(slotFinish()));
332 }
333 
334 void DownloadDialog::slotResult(KIO::Job *job)
335 {
336  TQDomDocument dom;
337  TQDomElement knewstuff;
338 
339  kdDebug() << "got data: " << m_data[job] << endl;
340 
341  kapp->config()->setGroup("KNewStuffStatus");
342 
343  dom.setContent(m_data[job]);
344  knewstuff = dom.documentElement();
345 
346  for(TQDomNode pn = knewstuff.firstChild(); !pn.isNull(); pn = pn.nextSibling())
347  {
348  TQDomElement stuff = pn.toElement();
349 
350  kdDebug() << "element: " << stuff.tagName() << endl;
351 
352  if(stuff.tagName() == "stuff")
353  {
354  Entry *entry = new Entry(stuff);
355  kdDebug() << "TYPE::" << entry->type() << " FILTER::" << m_filter << endl;
356  if(!entry->type().isEmpty())
357  {
358  if((!m_filter.isEmpty()) && (entry->type() != m_filter)) continue;
359  }
360 
361  /*if((!m_filter.isEmpty()) && (m_jobs[job]))
362  {
363  Provider *p = m_jobs[job];
364  if(d->m_newproviders[p])
365  {
366  addProvider(p);
367  slotPage(m_frame);
368  d->m_newproviders[p] = 0;
369  }
370  }*/
371  if((!m_filter.isEmpty()) && (d->m_variantjobs[job]))
372  {
373  Provider *p = d->m_variantjobs[job];
374  if(d->m_newproviders[p])
375  {
376  addProvider(p);
377  slotPage(m_frame);
378  d->m_newproviders[p] = 0;
379  }
380  }
381 
382  /*if(m_jobs[job]) addEntry(entry);
383  else*/
384  if(d->m_variantjobs[job]) addEntry(entry, d->m_variants[job]);
385  }
386  }
387 }
388 
389 int DownloadDialog::installStatus(Entry *entry)
390 {
391  TQDate date;
392  TQString datestring;
393  int installed;
394 
395  TQString lang = KGlobal::locale()->language();
396 
397  kapp->config()->setGroup("KNewStuffStatus");
398  datestring = kapp->config()->readEntry(entry->name(lang));
399  if(datestring.isNull()) installed = 0;
400  else
401  {
402  date = TQT_TQDATE_OBJECT(TQDate::fromString(datestring, Qt::ISODate));
403  if(!date.isValid()) installed = 0;
404  else if(date < entry->releaseDate()) installed = -1;
405  else installed = 1;
406  }
407 
408  return installed;
409 }
410 
411 void DownloadDialog::addEntry(Entry *entry, const TQStringList& variants)
412 {
413  TQPixmap pix;
414  int installed;
415 
416  installed = installStatus(entry);
417 
418  if(installed > 0) pix = KGlobal::iconLoader()->loadIcon("ok", KIcon::Small);
419  else if(installed < 0) pix = KGlobal::iconLoader()->loadIcon("history", KIcon::Small);
420  else pix = TQPixmap();
421 
422  TQString lang = KGlobal::locale()->language();
423 
424  if(variants.contains("score"))
425  {
426  KListViewItem *tmp_r = new NumSortListViewItem(lv_r,
427  entry->name(lang), entry->version(), TQString("%1").arg(entry->rating()));
428  tmp_r->setPixmap(0, pix);
429  }
430  if(variants.contains("downloads"))
431  {
432  KListViewItem *tmp_d = new NumSortListViewItem(lv_d,
433  entry->name(lang), entry->version(), TQString("%1").arg(entry->downloads()));
434  tmp_d->setPixmap(0, pix);
435  }
436  if(variants.contains("latest"))
437  {
438  KListViewItem *tmp_l = new DateSortListViewItem(lv_l,
439  entry->name(lang), entry->version(), KGlobal::locale()->formatDate(entry->releaseDate()));
440  tmp_l->setPixmap(0, pix);
441  }
442 
443  m_entries.append(entry);
444 
445  kdDebug() << "added entry " << entry->name() << " for variants " << variants << endl;
446 }
447 
448 void DownloadDialog::addEntry(Entry *entry)
449 {
450  TQStringList variants;
451 
452  variants << "score";
453  variants << "downloads";
454  variants << "latest";
455 
456  addEntry(entry, variants);
457 
458  // not used anymore due to variants (but still used by engine)
459  kdDebug() << "added entry " << entry->name() << endl;
460 }
461 
462 void DownloadDialog::slotData(KIO::Job *job, const TQByteArray &a)
463 {
464  TQCString tmp(a, a.size() + 1);
465  m_data[job].append(TQString::fromUtf8(tmp));
466 }
467 
468 void DownloadDialog::slotDetails()
469 {
470  Entry *e = getEntry();
471  if(!e) return;
472 
473  TQString lang = KGlobal::locale()->language();
474 
475  TQString info = i18n
476  (
477  "Name: %1\n"
478  "Author: %2\n"
479  "License: %3\n"
480  "Version: %4\n"
481  "Release: %5\n"
482  "Rating: %6\n"
483  "Downloads: %7\n"
484  "Release date: %8\n"
485  "Summary: %9\n"
486  ).arg(e->name(lang)
487  ).arg(e->author()
488  ).arg(e->license()
489  ).arg(e->version()
490  ).arg(e->release()
491  ).arg(e->rating()
492  ).arg(e->downloads()
493  ).arg(KGlobal::locale()->formatDate(e->releaseDate())
494  ).arg(e->summary(lang)
495  );
496 
497  info.append(i18n
498  (
499  "Preview: %1\n"
500  "Payload: %2\n"
501  ).arg(e->preview().url()
502  ).arg(e->payload().url()
503  ));
504 
505  KMessageBox::information(this, info, i18n("Details"));
506 }
507 
508 TQListViewItem *DownloadDialog::currentEntryItem()
509 {
510  if((m_curtab == 0) && (lv_r->selectedItem())) return lv_r->selectedItem();
511  if((m_curtab == 1) && (lv_d->selectedItem())) return lv_d->selectedItem();
512  if((m_curtab == 2) && (lv_l->selectedItem())) return lv_l->selectedItem();
513 
514  return 0;
515 }
516 
517 void DownloadDialog::slotInstall()
518 {
519  Entry *e = getEntry();
520  if(!e) return;
521 
522  d->m_lvtmp_r->setEnabled( false );
523  d->m_lvtmp_l->setEnabled( false );
524  d->m_lvtmp_d->setEnabled( false );
525  m_entryitem = currentEntryItem();
526  m_entryname = m_entryitem->text(0);
527 
528  kdDebug() << "download entry now" << endl;
529 
530  if(m_engine)
531  {
532  m_engine->download(e);
533  install(e);
534  }
535  else
536  {
537  m_s = new KNewStuffGeneric(e->type(), this);
538  m_entry = e;
539  KURL source = e->payload();
540  KURL dest = KURL(m_s->downloadDestination(e));
541 
542  KIO::FileCopyJob *job = KIO::file_copy(source, dest, -1, true);
543  connect(job, TQT_SIGNAL(result(KIO::Job*)), TQT_SLOT(slotInstalled(KIO::Job*)));
544  }
545 }
546 
547 void DownloadDialog::install(Entry *e)
548 {
549  kapp->config()->setGroup("KNewStuffStatus");
550  kapp->config()->writeEntry(m_entryname, TQString(e->releaseDate().toString(Qt::ISODate)));
551  kapp->config()->sync();
552 
553  TQPixmap pix = KGlobal::iconLoader()->loadIcon("ok", KIcon::Small);
554 
555  TQString lang = KGlobal::locale()->language();
556 
557  if(m_entryitem)
558  {
559  m_entryitem->setPixmap(0, pix);
560 
561  TQListViewItem *item;
562  item = lv_r->findItem(e->name(lang), 0);
563  if(item) item->setPixmap(0, pix);
564  item = lv_d->findItem(e->name(lang), 0);
565  if(item) item->setPixmap(0, pix);
566  item = lv_l->findItem(e->name(lang), 0);
567  if(item) item->setPixmap(0, pix);
568  }
569 
570  if(currentEntryItem() == m_entryitem)
571  {
572  TQPushButton *in;
573  in = *(m_buttons[d->m_page]->at(0));
574  if(in) in->setEnabled(false);
575  }
576 
577  d->m_installlist.append(e);
578  d->m_lvtmp_r->setEnabled( true );
579  d->m_lvtmp_l->setEnabled( true );
580  d->m_lvtmp_d->setEnabled( true );
581 }
582 
583 void DownloadDialog::slotInstalled(KIO::Job *job)
584 {
585  bool ret = job && (job->error() == 0);
586  if(ret)
587  {
588  KIO::FileCopyJob *cjob = ::tqqt_cast<KIO::FileCopyJob*>(job);
589  if(cjob)
590  {
591  ret = m_s->install(cjob->destURL().path());
592  }
593  else ret = false;
594  }
595 
596  if(ret)
597  {
598  install(m_entry);
599 
600  KMessageBox::information(this, i18n("Installation successful."), i18n("Installation"));
601  }
602  else KMessageBox::error(this, i18n("Installation failed."), i18n("Installation"));
603  d->m_lvtmp_r->setEnabled( true );
604  d->m_lvtmp_l->setEnabled( true );
605  d->m_lvtmp_d->setEnabled( true );
606 
607  delete m_s;
608 }
609 
610 void DownloadDialog::slotTab()
611 {
612  int tab = static_cast<const TQTabWidget *>(sender())->currentPageIndex();
613  kdDebug() << "switch tab to: " << tab << endl;
614 
615  Entry *eold = getEntry();
616  m_curtab = tab;
617  Entry *e = getEntry();
618 
619  if(e == eold) return;
620 
621  if(e)
622  {
623  slotSelected();
624  }
625  else
626  {
627  TQPushButton *de, *in;
628  in = *(m_buttons[d->m_page]->at(0));
629  de = *(m_buttons[d->m_page]->at(1));
630 
631  if(in) in->setEnabled(false);
632  if(de) de->setEnabled(false);
633 
634  m_rt->clear();
635  }
636 }
637 
638 void DownloadDialog::slotSelected()
639 {
640  TQString tmp;
641  bool enabled;
642  Entry *e = getEntry();
643  TQString lang = KGlobal::locale()->language();
644  bool ret;
645 
646  if(e)
647  {
648  TQString lang = KGlobal::locale()->language();
649 
650  TQListViewItem *item;
651  if(m_curtab != 0)
652  {
653  lv_r->clearSelection();
654  item = lv_r->findItem(e->name(lang), 0);
655  if(item) lv_r->setSelected(item, true);
656  }
657  if(m_curtab != 1)
658  {
659  lv_d->clearSelection();
660  item = lv_d->findItem(e->name(lang), 0);
661  if(item) lv_d->setSelected(item, true);
662  }
663  if(m_curtab != 2)
664  {
665  lv_l->clearSelection();
666  item = lv_l->findItem(e->name(lang), 0);
667  if(item) lv_l->setSelected(item, true);
668  }
669 
670  if(!e->preview(lang).isValid())
671  {
672  ret = 0;
673  }
674  else
675  {
676  ret = KIO::NetAccess::download(e->preview(lang), tmp, this);
677  }
678 
679  TQString desc = TQString("<b>%1</b><br>").arg(e->name(lang));
680  if(!e->authorEmail().isNull())
681  {
682  desc += TQString("<a href='mailto:" + e->authorEmail() + "'>" + e->author() + "</a>");
683  }
684  else
685  {
686  desc += TQString("%1").arg(e->author());
687  }
688  desc += TQString("<br>%1").arg(KGlobal::locale()->formatDate(e->releaseDate()));
689  desc += TQString("<br><br>");
690  if(ret)
691  {
692  desc += TQString("<img src='%1'>").arg(tmp);
693  }
694  else
695  {
696  desc += i18n("Preview not available.");
697  }
698  desc += TQString("<br><i>%1</i>").arg(e->summary(lang));
699  desc += TQString("<br>(%1)").arg(e->license());
700 
701  m_rt->clear();
702  m_rt->setText(desc);
703 
704  if(installStatus(e) == 1) enabled = false;
705  else enabled = true;
706 
707  TQPushButton *de, *in;
708  in = *(m_buttons[d->m_page]->at(0));
709  de = *(m_buttons[d->m_page]->at(1));
710  if(in) in->setEnabled(enabled);
711  if(de) de->setEnabled(true);
712  }
713 }
714 
715 void DownloadDialog::slotEmail(const TQString& link)
716 {
717  kdDebug() << "EMAIL: " << link << endl;
718  kapp->invokeMailer(link);
719  slotSelected(); // TQTextBrowser oddity workaround as it cannot handle mailto: URLs
720 }
721 
722 Entry *DownloadDialog::getEntry()
723 {
724  TQListViewItem *entryItem = currentEntryItem();
725 
726  if(!entryItem)
727  return 0;
728 
729  TQString entryName = entryItem->text(0);
730 
731  TQString lang = KGlobal::locale()->language();
732 
733  for(Entry *e = m_entries.first(); e; e = m_entries.next())
734  if(e->name(lang) == entryName)
735  return e;
736 
737  return 0;
738 }
739 
740 void DownloadDialog::slotPage(TQWidget *w)
741 {
742  Provider *p;
743 
744  kdDebug() << "changed widget!!!" << endl;
745 
746  if(m_map.find(w) == m_map.end()) return;
747 
748  d->m_page = w;
749 
750  lv_r = *(m_map[w]->at(0));
751  lv_d = *(m_map[w]->at(1));
752  lv_l = *(m_map[w]->at(2));
753  p = m_providers[w];
754  m_rt = m_rts[w];
755 
756  kdDebug() << "valid change!!!; lv_r = " << lv_r << endl;
757 
758  if(m_engine) return;
759 
760  if(!m_filter.isEmpty()) return;
761 
762  lv_r->clear();
763  lv_d->clear();
764  lv_l->clear();
765 
766  kdDebug() << "-- fetch -- " << p->downloadUrl() << endl;
767 
768  loadProvider(p);
769 }
770 
771 void DownloadDialog::loadProvider(Provider *p)
772 {
773  TQMap<KIO::Job*, Provider*>::Iterator it;
774 
775  for(it = d->m_variantjobs.begin(); it != d->m_variantjobs.end(); it++)
776  {
777  if(it.data() == p)
778  {
779  kdDebug() << "-- found provider data in cache" << endl;
780  slotResult(it.key());
781  return;
782  }
783  }
784 
785  TQStringList variants;
786  variants << "score";
787  variants << "downloads";
788  variants << "latest";
789 
790  // Optimise URLs so each unique URL only gets fetched once
791 
792  TQMap<TQString, TQStringList> urls;
793 
794  for(TQStringList::Iterator it = variants.begin(); it != variants.end(); it++)
795  {
796  TQString url = p->downloadUrlVariant((*it)).url();
797  if(!urls.contains(url))
798  {
799  urls[url] = TQStringList();
800  }
801  urls[url] << (*it);
802 
803  it = variants.remove(it);
804  }
805 
806  // Now fetch the URLs while keeping the variant list for each attached
807 
808  for(TQMap<TQString, TQStringList>::Iterator it = urls.begin(); it != urls.end(); it++)
809  {
810  TQString url = it.key();
811  TQStringList urlvariants = it.data();
812 
813  KIO::TransferJob *variantjob = KIO::get(url);
814  d->m_newproviders[p] = p;
815  d->m_variantjobs[variantjob] = p;
816  d->m_variants[variantjob] = urlvariants;
817  m_data[variantjob] = "";
818 
819  connect(variantjob, TQT_SIGNAL(result(KIO::Job*)), TQT_SLOT(slotResult(KIO::Job*)));
820  connect(variantjob, TQT_SIGNAL(data(KIO::Job*, const TQByteArray&)),
821  TQT_SLOT(slotData(KIO::Job*, const TQByteArray&)));
822  }
823 
824  if(variants.count() == 0) return;
825 
826  // If not all variants are given, use default URL for those
827 
828  kdDebug() << "-- reached old downloadurl section; variants left: " << variants.count() << endl;
829 
830  KIO::TransferJob *job = KIO::get(p->downloadUrl());
831 
832  d->m_newproviders[p] = p;
833  d->m_variantjobs[job] = p;
834  d->m_variants[job] = variants;
835  //m_jobs[job] = p; // not used anymore due to variants
836  m_data[job] = "";
837 
838  connect(job, TQT_SIGNAL(result(KIO::Job*)), TQT_SLOT(slotResult(KIO::Job*)));
839  connect(job, TQT_SIGNAL(data(KIO::Job*, const TQByteArray&)),
840  TQT_SLOT(slotData(KIO::Job*, const TQByteArray&)));
841 }
842 
843 void DownloadDialog::setType(TQString type)
844 {
845  m_filter = type;
846 }
847 
848 void DownloadDialog::setProviderList(const TQString& providerList)
849 {
850  d->m_providerlist = providerList;
851 }
852 
853 void DownloadDialog::slotOk()
854 {
855 }
856 
857 void DownloadDialog::slotApply()
858 {
859 }
860 
861 void DownloadDialog::open(const TQString& type, const TQString& caption)
862 {
863  DownloadDialog d(0, caption);
864  d.setType(type);
865  d.load();
866  d.exec();
867 }
868 
869 void DownloadDialog::slotFinish()
870 {
871  showPage(1);
872  //updateBackground();
873 }
874 
875 TQPtrList<Entry> DownloadDialog::installedEntries()
876 {
877  return d->m_installlist;
878 }
KNS::Entry::author
TQString author() const
Retrieve the author&#39;s name of the object.
Definition: entry.cpp:148
KNS::Entry::payload
KURL payload(const TQString &lang=TQString::null) const
Retrieve the file name of the object.
Definition: entry.cpp:227
KNS::Engine::download
void download()
Initiates the download process, retrieving provider lists and invoking the download dialog...
Definition: engine.cpp:81
KNS::Entry::downloads
int downloads()
Retrieve the download count for the object, which has been determined by its hosting sites and thus m...
Definition: entry.cpp:282
KNS::DownloadDialog::~DownloadDialog
~DownloadDialog()
Destructor.
Definition: downloaddialog.cpp:156
KNS::Entry::rating
int rating()
Retrieve the rating for the object, which has been determined by its users and thus might change over...
Definition: entry.cpp:271
KNewStuffGeneric::install
bool install(const TQString &fileName)
Installs a downloaded file according to the application&#39;s configuration.
Definition: knewstuffgeneric.cpp:50
KNS::Provider::icon
KURL icon() const
Retrieves the icon URL for this provider.
Definition: provider.cpp:121
KNS::Entry
KNewStuff data entry container.
Definition: entry.h:44
KNS::DownloadDialog::addProvider
void addProvider(Provider *p)
Adds another provider to the download dialog.
Definition: downloaddialog.cpp:215
KNS::DownloadDialog::load
void load()
Fetches descriptions of all available data, optionally considering a previously set type...
Definition: downloaddialog.cpp:165
KNS::Entry::license
TQString license() const
Retrieve the license name of the object.
Definition: entry.cpp:159
KNS::DownloadDialog::setType
void setType(TQString type)
Restricts the display of available data to a certain data type.
Definition: downloaddialog.cpp:843
KNS::ProviderLoader::load
void load(const TQString &type, const TQString &providerList=TQString::null)
Starts asynchronously loading the list of providers of the specified type.
Definition: provider.cpp:215
KNS::Provider::downloadUrlVariant
KURL downloadUrlVariant(TQString variant) const
Variant to retrieve &#39;tagged&#39; download URLs.
Definition: provider.cpp:65
KNewStuffGeneric::downloadDestination
TQString downloadDestination(KNS::Entry *entry)
Queries the preferred destination file for a download.
Definition: knewstuffgeneric.cpp:133
KNS::DownloadDialog::installedEntries
TQPtrList< Entry > installedEntries()
Returns the list of installed data entries.
Definition: downloaddialog.cpp:875
KNS::Entry::type
TQString type() const
Retrieve the type of the data object.
Definition: entry.cpp:137
KNS::DownloadDialog::setProviderList
void setProviderList(const TQString &providerList)
Explicitly uses this provider list instead of the one read from the application configuration.
Definition: downloaddialog.cpp:848
KNS::Provider::name
TQString name() const
Retrieves the common name of the provider.
Definition: provider.cpp:110
KNS::DownloadDialog::clear
void clear()
Clears the entry list of the current provider.
Definition: downloaddialog.cpp:175
KNS::DownloadDialog::addEntry
void addEntry(Entry *entry)
Adds an additional entry to the current provider.
Definition: downloaddialog.cpp:448
KNS::Provider::downloadUrl
KURL downloadUrl() const
Retrieves the download URL.
Definition: provider.cpp:132
KNS::Entry::preview
KURL preview(const TQString &lang=TQString::null) const
Retrieve the file name of an image containing a preview of the object.
Definition: entry.cpp:250
KNS::Entry::summary
TQString summary(const TQString &lang=TQString::null) const
Retrieve a short description about the object.
Definition: entry.cpp:172
KNS::Entry::release
int release() const
Retrieve the release number of the object.
Definition: entry.cpp:203
KNewStuffGeneric
Basic KNewStuff class with predefined actions.
Definition: knewstuffgeneric.h:42
KNS::DownloadDialog::slotProviders
void slotProviders(Provider::List *list)
Availability of the provider list.
Definition: downloaddialog.cpp:197
KNS::Entry::authorEmail
TQString authorEmail() const
Retrieve the author&#39;s email address of the object.
Definition: entry.cpp:59
KNS::ProviderLoader
KNewStuff provider loader.
Definition: provider.h:172
KNS
Handles security releated issues, like signing, verifying.
Definition: downloaddialog.h:36
KNS::Entry::releaseDate
TQDate releaseDate() const
Retrieve the date of the object&#39;s publication.
Definition: entry.cpp:214
KNS::DownloadDialog::open
static void open(const TQString &type, const TQString &caption)
Opens the download dialog.
Definition: downloaddialog.cpp:861
KNS::Engine
Central class combining all possible KNewStuff operations.
Definition: engine.h:51
KNS::DownloadDialog::DownloadDialog
DownloadDialog(Engine *engine, TQWidget *parent, const TQString &caption)
Constructor.
Definition: downloaddialog.cpp:123
KNS::Entry::version
TQString version() const
Retrieve the version string of the object.
Definition: entry.cpp:192
KNS::Provider
KNewStuff provider container.
Definition: provider.h:46
KNS::Entry::name
TQString name() const
Retrieve the name of the data object.
Definition: entry.cpp:126
KNS::DownloadDialog
Common download dialog for data browsing and installation.
Definition: downloaddialog.h:57

knewstuff

Skip menu "knewstuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

knewstuff

Skip menu "knewstuff"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for knewstuff by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |