~ubuntu-branches/ubuntu/karmic/tellico/karmic

« back to all changes in this revision

Viewing changes to src/fetch/fetchmanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Regis Boudin
  • Date: 2008-05-23 21:28:59 UTC
  • mfrom: (0.1.14 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20080523212859-n0gl4ap37xb0uj1a
Tags: 1.3.2-1
* New upstream release.
* Recommend khelpcenter for acces to the help (Closes: #478975).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "../tellico_utils.h"
23
23
#include "../tellico_debug.h"
24
24
 
25
 
#if AMAZON_SUPPORT
 
25
#ifdef AMAZON_SUPPORT
26
26
#include "amazonfetcher.h"
27
27
#endif
28
 
#if IMDB_SUPPORT
 
28
#ifdef IMDB_SUPPORT
29
29
#include "imdbfetcher.h"
30
30
#endif
31
 
#if HAVE_YAZ
 
31
#ifdef HAVE_YAZ
32
32
#include "z3950fetcher.h"
33
33
#endif
34
34
#include "srufetcher.h"
43
43
#include "arxivfetcher.h"
44
44
#include "citebasefetcher.h"
45
45
#include "bibsonomyfetcher.h"
 
46
#include "googlescholarfetcher.h"
 
47
#include "discogsfetcher.h"
46
48
 
47
49
#include <kglobal.h>
48
50
#include <kconfig.h>
57
59
#include <qfileinfo.h>
58
60
#include <qdir.h>
59
61
 
 
62
#define LOAD_ICON(name, group, size) \
 
63
  KGlobal::iconLoader()->loadIcon(name, static_cast<KIcon::Group>(group), size_)
 
64
 
60
65
using Tellico::Fetch::Manager;
61
66
Manager* Manager::s_self = 0;
62
67
 
73
78
  m_keyMap.insert(DOI,        i18n("DOI"));
74
79
  m_keyMap.insert(ArxivID,    i18n("arXiv ID"));
75
80
  m_keyMap.insert(PubmedID,   i18n("Pubmed ID"));
 
81
  // to keep from having a new i18n string, just remove octothorpe
 
82
  m_keyMap.insert(LCCN,       i18n("LCCN#").remove('#'));
76
83
  m_keyMap.insert(Raw,        i18n("Raw Query"));
77
84
//  m_keyMap.insert(FetchLast,  QString::null);
78
85
}
245
252
  Fetcher::Ptr f = 0;
246
253
  switch(fetchType) {
247
254
    case Amazon:
248
 
#if AMAZON_SUPPORT
 
255
#ifdef AMAZON_SUPPORT
249
256
      {
250
257
        int site = config.readNumEntry("Site", AmazonFetcher::Unknown);
251
258
        if(site == AmazonFetcher::Unknown) {
258
265
      break;
259
266
 
260
267
    case IMDB:
261
 
#if IMDB_SUPPORT
 
268
#ifdef IMDB_SUPPORT
262
269
      f = new IMDBFetcher(this);
263
270
#endif
264
271
      break;
265
272
 
266
273
    case Z3950:
267
 
#if HAVE_YAZ
 
274
#ifdef HAVE_YAZ
268
275
      f = new Z3950Fetcher(this);
269
276
#endif
270
277
      break;
317
324
      f = new BibsonomyFetcher(this);
318
325
      break;
319
326
 
 
327
    case GoogleScholar:
 
328
      f = new GoogleScholarFetcher(this);
 
329
      break;
 
330
 
 
331
    case Discogs:
 
332
      f = new DiscogsFetcher(this);
 
333
      break;
 
334
 
320
335
    case Unknown:
321
336
    default:
322
337
      break;
330
345
// static
331
346
Tellico::Fetch::FetcherVec Manager::defaultFetchers() {
332
347
  FetcherVec vec;
333
 
#if AMAZON_SUPPORT
 
348
#ifdef AMAZON_SUPPORT
334
349
  vec.append(new AmazonFetcher(AmazonFetcher::US, this));
335
350
#endif
336
 
#if IMDB_SUPPORT
 
351
#ifdef IMDB_SUPPORT
337
352
  vec.append(new IMDBFetcher(this));
338
353
#endif
339
354
  vec.append(SRUFetcher::libraryOfCongress(this));
341
356
  vec.append(new YahooFetcher(this));
342
357
  vec.append(new AnimeNfoFetcher(this));
343
358
  vec.append(new ArxivFetcher(this));
 
359
  vec.append(new GoogleScholarFetcher(this));
 
360
  vec.append(new DiscogsFetcher(this));
344
361
// only add IBS if user includes italian
345
362
  if(KGlobal::locale()->languagesTwoAlpha().contains(QString::fromLatin1("it"))) {
346
363
    vec.append(new IBSFetcher(this));
367
384
  return vec;
368
385
}
369
386
 
370
 
Tellico::Fetch::FetcherVec Manager::createUpdateFetchers(int collType_, Type type_) {
 
387
Tellico::Fetch::FetcherVec Manager::createUpdateFetchers(int collType_, FetchKey key_) {
371
388
  FetcherVec fetchers;
372
389
  // creates new fetchers
373
390
  FetcherVec allFetchers = createUpdateFetchers(collType_);
374
391
  for(Fetch::FetcherVec::Iterator it = allFetchers.begin(); it != allFetchers.end(); ++it) {
375
 
    if(it->type() == type_) {
 
392
    if(it->canSearch(key_)) {
376
393
      fetchers.append(it);
377
394
    }
378
395
  }
398
415
 
399
416
Tellico::Fetch::TypePairList Manager::typeList() {
400
417
  Fetch::TypePairList list;
401
 
#if AMAZON_SUPPORT
 
418
#ifdef AMAZON_SUPPORT
402
419
  list.append(TypePair(AmazonFetcher::defaultName(), Amazon));
403
420
#endif
404
 
#if IMDB_SUPPORT
 
421
#ifdef IMDB_SUPPORT
405
422
  list.append(TypePair(IMDBFetcher::defaultName(),         IMDB));
406
423
#endif
407
 
#if HAVE_YAZ
 
424
#ifdef HAVE_YAZ
408
425
  list.append(TypePair(Z3950Fetcher::defaultName(),        Z3950));
409
426
#endif
410
427
  list.append(TypePair(SRUFetcher::defaultName(),          SRU));
419
436
  list.append(TypePair(ArxivFetcher::defaultName(),        Arxiv));
420
437
  list.append(TypePair(CitebaseFetcher::defaultName(),     Citebase));
421
438
  list.append(TypePair(BibsonomyFetcher::defaultName(),    Bibsonomy));
 
439
  list.append(TypePair(GoogleScholarFetcher::defaultName(),GoogleScholar));
 
440
  list.append(TypePair(DiscogsFetcher::defaultName(),      Discogs));
422
441
 
423
442
  // now find all the scripts distributed with tellico
424
443
  QStringList files = KGlobal::dirs()->findAllResources("appdata", QString::fromLatin1("data-sources/*.spec"),
447
466
Tellico::Fetch::ConfigWidget* Manager::configWidget(QWidget* parent_, Type type_, const QString& name_) {
448
467
  ConfigWidget* w = 0;
449
468
  switch(type_) {
450
 
#if AMAZON_SUPPORT
 
469
#ifdef AMAZON_SUPPORT
451
470
    case Amazon:
452
471
      w = new AmazonFetcher::ConfigWidget(parent_);
453
472
      break;
454
473
#endif
455
 
#if IMDB_SUPPORT
 
474
#ifdef IMDB_SUPPORT
456
475
    case IMDB:
457
476
      w = new IMDBFetcher::ConfigWidget(parent_);
458
477
      break;
459
478
#endif
460
 
#if HAVE_YAZ
 
479
#ifdef HAVE_YAZ
461
480
    case Z3950:
462
481
      w = new Z3950Fetcher::ConfigWidget(parent_);
463
482
      break;
519
538
    case Bibsonomy:
520
539
      w = new BibsonomyFetcher::ConfigWidget(parent_);
521
540
      break;
522
 
    default:
 
541
    case GoogleScholar:
 
542
      w = new GoogleScholarFetcher::ConfigWidget(parent_);
 
543
      break;
 
544
    case Discogs:
 
545
      w = new DiscogsFetcher::ConfigWidget(parent_);
 
546
      break;
 
547
    case Unknown:
523
548
      kdWarning() << "Fetch::Manager::configWidget() - no widget defined for type = " << type_ << endl;
524
549
  }
525
550
  return w;
528
553
// static
529
554
QString Manager::typeName(Fetch::Type type_) {
530
555
  switch(type_) {
531
 
#if AMAZON_SUPPORT
 
556
#ifdef AMAZON_SUPPORT
532
557
    case Amazon: return AmazonFetcher::defaultName();
533
558
#endif
534
 
#if IMDB_SUPPORT
 
559
#ifdef IMDB_SUPPORT
535
560
    case IMDB: return IMDBFetcher::defaultName();
536
561
#endif
537
 
#if HAVE_YAZ
 
562
#ifdef HAVE_YAZ
538
563
    case Z3950: return Z3950Fetcher::defaultName();
539
564
#endif
540
565
    case SRU: return SRUFetcher::defaultName();
549
574
    case Arxiv: return ArxivFetcher::defaultName();
550
575
    case Citebase: return CitebaseFetcher::defaultName();
551
576
    case Bibsonomy: return BibsonomyFetcher::defaultName();
552
 
    default: break;
 
577
    case GoogleScholar: return GoogleScholarFetcher::defaultName();
 
578
    case Discogs: return DiscogsFetcher::defaultName();
 
579
    case Unknown: break;
553
580
  }
554
581
  myWarning() << "Manager::typeName() - none found for " << type_ << endl;
555
582
  return QString::null;
556
583
}
557
584
 
558
 
QPixmap Manager::fetcherIcon(Fetch::Fetcher::CPtr fetcher_) {
559
 
#if HAVE_YAZ
 
585
QPixmap Manager::fetcherIcon(Fetch::Fetcher::CPtr fetcher_, int group_, int size_) {
 
586
#ifdef HAVE_YAZ
560
587
  if(fetcher_->type() == Fetch::Z3950) {
561
588
    const Fetch::Z3950Fetcher* f = static_cast<const Fetch::Z3950Fetcher*>(fetcher_.data());
562
589
    KURL u;
564
591
    u.setHost(f->host());
565
592
    QString icon = favIcon(u);
566
593
    if(u.isValid() && !icon.isEmpty()) {
567
 
      return SmallIcon(icon);
 
594
      return LOAD_ICON(icon, group_, size_);
568
595
    }
569
596
  } else
570
597
#endif
581
608
    } else if(p.find(QString::fromLatin1("boardgamegeek")) > -1) {
582
609
      u = QString::fromLatin1("http://www.boardgamegeek.com");
583
610
    } else if(f->source().find(QString::fromLatin1("amarok"), 0, false /*case-sensitive*/) > -1) {
584
 
      return SmallIcon(QString::fromLatin1("amarok"));
 
611
      return LOAD_ICON(QString::fromLatin1("amarok"), group_, size_);
585
612
    }
586
613
    if(!u.isEmpty() && u.isValid()) {
587
614
      QString icon = favIcon(u);
588
615
      if(!icon.isEmpty()) {
589
 
        return SmallIcon(icon);
 
616
        return LOAD_ICON(icon, group_, size_);
590
617
      }
591
618
    }
592
619
  }
593
 
  return fetcherIcon(fetcher_->type());
 
620
  return fetcherIcon(fetcher_->type(), group_);
594
621
}
595
622
 
596
 
QPixmap Manager::fetcherIcon(Fetch::Type type_) {
 
623
QPixmap Manager::fetcherIcon(Fetch::Type type_, int group_, int size_) {
597
624
  QString name;
598
625
  switch(type_) {
599
626
    case Amazon:
626
653
      name = favIcon("http://citebase.org"); break;
627
654
    case Bibsonomy:
628
655
      name = favIcon("http://bibsonomy.org"); break;
629
 
    default:
 
656
    case GoogleScholar:
 
657
      name = favIcon("http://scholar.google.com"); break;
 
658
    case Discogs:
 
659
      name = favIcon("http://www.discogs.com"); break;
 
660
    case Unknown:
630
661
      kdWarning() << "Fetch::Manager::fetcherIcon() - no pixmap defined for type = " << type_ << endl;
631
662
  }
632
663
 
633
 
  return name.isEmpty() ? QPixmap() : SmallIcon(name);
 
664
  return name.isEmpty() ? QPixmap() : LOAD_ICON(name, group_, size_);
634
665
}
635
666
 
636
667
QString Manager::favIcon(const KURL& url_) {