~paulbrianstewart/ubuntu/oneiric/tellico/852247-Formatting-Fix

« back to all changes in this revision

Viewing changes to src/fetch/imdbfetcher.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-31 19:33:05 UTC
  • mfrom: (0.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080131193305-9l01m5gfhykl6pkl
Tags: 1.3-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: build-dep on kdepim-dev
  - debian/control: drop versioned python from tellico-data suggests
  - debian/rules: call dh_icons

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "../imagefactory.h"
22
22
#include "../tellico_utils.h"
23
23
#include "../gui/listboxtext.h"
 
24
#include "../tellico_debug.h"
24
25
 
25
26
#include <klocale.h>
26
27
#include <kdialogbase.h>
96
97
  return type == Data::Collection::Video;
97
98
}
98
99
 
99
 
void IMDBFetcher::readConfigHook(KConfig* config_, const QString& group_) {
100
 
  KConfigGroupSaver groupSaver(config_, group_);
101
 
  QString h = config_->readEntry("Host");
 
100
void IMDBFetcher::readConfigHook(const KConfigGroup& config_) {
 
101
  QString h = config_.readEntry("Host");
102
102
  if(!h.isEmpty()) {
103
103
    m_host = h;
104
104
  }
105
 
  m_numCast = config_->readNumEntry("Max Cast", 10);
106
 
  m_fetchImages = config_->readBoolEntry("Fetch Images", true);
107
 
  m_fields = config_->readListEntry("Custom Fields");
 
105
  m_numCast = config_.readNumEntry("Max Cast", 10);
 
106
  m_fetchImages = config_.readBoolEntry("Fetch Images", true);
 
107
  m_fields = config_.readListEntry("Custom Fields");
108
108
}
109
109
 
110
110
// multiple values not supported
674
674
  doAlsoKnownAs(str_, entry);
675
675
  doPlot(str_, entry, m_url);
676
676
  doLists(str_, entry);
677
 
  doPerson(str_, entry, QString::fromLatin1("Direct"), QString::fromLatin1("director"));
678
 
  doPerson(str_, entry, QString::fromLatin1("Writ"), QString::fromLatin1("writer"));
 
677
  doPerson(str_, entry, QString::fromLatin1("Director"), QString::fromLatin1("director"));
 
678
  doPerson(str_, entry, QString::fromLatin1("Writer"), QString::fromLatin1("writer"));
679
679
  doRating(str_, entry);
680
680
  doCast(str_, entry, m_url);
681
681
  if(m_fetchImages) {
701
701
    const QString cap1 = s_titleRx->cap(1);
702
702
    // titles always have parentheses
703
703
    int pPos = cap1.find('(');
704
 
    entry_->setField(QString::fromLatin1("title"), cap1.left(pPos).stripWhiteSpace());
 
704
    QString title = cap1.left(pPos).stripWhiteSpace();
 
705
    // remove first and last quotes is there
 
706
    if(title.startsWith(QChar('"')) && title.endsWith(QChar('"'))) {
 
707
      title = title.mid(1, title.length()-2);
 
708
    }
 
709
    entry_->setField(QString::fromLatin1("title"), title);
705
710
    // remove parenthesis
706
711
    uint pPos2 = pPos+1;
707
712
    while(pPos2 < cap1.length() && cap1[pPos2].isDigit()) {
820
825
 
821
826
void IMDBFetcher::doPerson(const QString& str_, Data::EntryPtr entry_,
822
827
                           const QString& imdbHeader_, const QString& fieldName_) {
823
 
  int pos = str_.find(imdbHeader_);
824
 
  if(pos > -1) {
825
 
    QStringList people;
 
828
  QRegExp br2Rx(QString::fromLatin1("<br[\\s/]*>\\s*<br[\\s/]*>"), false);
 
829
  br2Rx.setMinimal(true);
 
830
  QRegExp divRx(QString::fromLatin1("<[/]*div"), false);
 
831
  divRx.setMinimal(true);
 
832
  QString name = QString::fromLatin1("/name/");
 
833
 
 
834
  QStringList people;
 
835
  for(int pos = str_.find(imdbHeader_); pos > 0; pos = str_.find(imdbHeader_, pos)) {
826
836
    // loop until repeated <br> tags or </div> tag
827
 
    QRegExp br2Rx(QString::fromLatin1("<br[\\s/]*>\\s*<br[\\s/]*>"), false);
828
 
    br2Rx.setMinimal(true);
829
 
    QRegExp divRx(QString::fromLatin1("<[/]*div"), false);
830
 
    divRx.setMinimal(true);
831
 
 
832
 
    const QString name = QString::fromLatin1("/name/");
833
837
    const int endPos1 = str_.find(br2Rx, pos);
834
838
    const int endPos2 = str_.find(divRx, pos);
835
839
    const int endPos = QMIN(endPos1, endPos2); // ok to be -1
840
844
      }
841
845
      pos = s_anchorRx->search(str_, pos+1);
842
846
    }
843
 
    if(!people.isEmpty()) {
844
 
      entry_->setField(fieldName_, people.join(sep));
845
 
    }
 
847
  }
 
848
  if(!people.isEmpty()) {
 
849
    entry_->setField(fieldName_, people.join(sep));
846
850
  }
847
851
}
848
852
 
862
866
  // be quiet about failure and be sure to translate entities
863
867
  QString castPage = Tellico::decodeHTML(FileHandler::readTextFile(castURL, true));
864
868
 
865
 
  int pos;
 
869
  int pos = -1;
866
870
  // the text to search, depends on which page is being read
867
871
  QString castText = castPage;
868
 
  if(!castText.isEmpty()) {
869
 
    // fragile, the word "cast" appears in the title, but need to find
870
 
    // the one right above the actual cast table
871
 
    // for TV shows, there's a link on the sidebar for "episodes case"
872
 
    // so need to not match that one
873
 
    pos = castText.find(QString::fromLatin1("cast</"), 0, false);
874
 
    if(pos > 9) {
875
 
      // back up 9 places
876
 
      if(castText.mid(pos-9, 9).startsWith(QString::fromLatin1("episodes"))) {
877
 
        // find next cast list
878
 
        pos = castText.find(QString::fromLatin1("cast</"), pos+6, false);
879
 
      }
880
 
    }
881
 
  } else { // fall back to short list
882
 
    pos = str_.find(QString::fromLatin1("cast overview"), 0, false);
 
872
  if(castText.isEmpty()) {
 
873
    // fall back to short list
 
874
    castText = str_;
 
875
    pos = castText.find(QString::fromLatin1("cast overview"), 0, false);
883
876
    if(pos == -1) {
884
 
      pos = str_.find(QString::fromLatin1("credited cast"), 0, false);
885
 
    }
886
 
    castText = str_;
 
877
      pos = castText.find(QString::fromLatin1("credited cast"), 0, false);
 
878
    }
 
879
  } else {
 
880
    // first look for anchor
 
881
    QRegExp castAnchorRx(QString::fromLatin1("<a\\s+name\\s*=\\s*\"cast\""), false);
 
882
    pos = castText.find(castAnchorRx);
 
883
    if(pos < 0) {
 
884
      QRegExp tableClassRx(QString::fromLatin1("<table\\s+class\\s*=\\s*\"cast\""), false);
 
885
      pos = castText.find(tableClassRx);
 
886
      if(pos < 0) {
 
887
        // fragile, the word "cast" appears in the title, but need to find
 
888
        // the one right above the actual cast table
 
889
        // for TV shows, there's a link on the sidebar for "episodes case"
 
890
        // so need to not match that one
 
891
        pos = castText.find(QString::fromLatin1("cast</"), 0, false);
 
892
        if(pos > 9) {
 
893
          // back up 9 places
 
894
          if(castText.mid(pos-9, 9).startsWith(QString::fromLatin1("episodes"))) {
 
895
            // find next cast list
 
896
            pos = castText.find(QString::fromLatin1("cast</"), pos+6, false);
 
897
          }
 
898
        }
 
899
      }
 
900
    }
887
901
  }
888
902
  if(pos == -1) { // no cast list found
 
903
    myDebug() << "IMDBFetcher::doCast() - no cast list found" << endl;
889
904
    return;
890
905
  }
891
906
 
1148
1163
  }
1149
1164
}
1150
1165
 
1151
 
void IMDBFetcher::ConfigWidget::saveConfig(KConfig* config_) {
 
1166
void IMDBFetcher::ConfigWidget::saveConfig(KConfigGroup& config_) {
1152
1167
  QString host = m_hostEdit->text().stripWhiteSpace();
1153
1168
  if(!host.isEmpty()) {
1154
 
    config_->writeEntry("Host", host);
 
1169
    config_.writeEntry("Host", host);
1155
1170
  }
1156
 
  config_->writeEntry("Max Cast", m_numCast->value());
1157
 
  config_->writeEntry("Fetch Images", m_fetchImageCheck->isChecked());
 
1171
  config_.writeEntry("Max Cast", m_numCast->value());
 
1172
  config_.writeEntry("Fetch Images", m_fetchImageCheck->isChecked());
1158
1173
 
1159
1174
  saveFieldsConfig(config_);
1160
1175
  slotSetModified(false);