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

tdenewstuff

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

tdenewstuff

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

tdenewstuff

Skip menu "tdenewstuff"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdenewstuff by doxygen 1.9.4
This website is maintained by Timothy Pearson.