diff options
Diffstat (limited to 'src/fetch/ibsfetcher.cpp')
-rw-r--r-- | src/fetch/ibsfetcher.cpp | 186 |
1 files changed, 93 insertions, 93 deletions
diff --git a/src/fetch/ibsfetcher.cpp b/src/fetch/ibsfetcher.cpp index b11258b..855d2f0 100644 --- a/src/fetch/ibsfetcher.cpp +++ b/src/fetch/ibsfetcher.cpp @@ -26,10 +26,10 @@ #include <kconfig.h> #include <kio/job.h> -#include <qregexp.h> -#include <qlayout.h> -#include <qlabel.h> -#include <qfile.h> +#include <tqregexp.h> +#include <tqlayout.h> +#include <tqlabel.h> +#include <tqfile.h> //#define IBS_TEST @@ -39,15 +39,15 @@ namespace { using Tellico::Fetch::IBSFetcher; -IBSFetcher::IBSFetcher(QObject* parent_, const char* name_ /*=0*/) - : Fetcher(parent_, name_), m_started(false) { +IBSFetcher::IBSFetcher(TQObject* tqparent_, const char* name_ /*=0*/) + : Fetcher(tqparent_, name_), m_started(false) { } -QString IBSFetcher::defaultName() { +TQString IBSFetcher::defaultName() { return i18n("Internet Bookshop (ibs.it)"); } -QString IBSFetcher::source() const { +TQString IBSFetcher::source() const { return m_name.isEmpty() ? defaultName() : m_name; } @@ -59,46 +59,46 @@ void IBSFetcher::readConfigHook(const KConfigGroup& config_) { Q_UNUSED(config_); } -void IBSFetcher::search(FetchKey key_, const QString& value_) { +void IBSFetcher::search(FetchKey key_, const TQString& value_) { m_started = true; m_matches.clear(); #ifdef IBS_TEST - KURL u = KURL::fromPathOrURL(QString::fromLatin1("/home/robby/ibs.html")); + KURL u = KURL::fromPathOrURL(TQString::tqfromLatin1("/home/robby/ibs.html")); #else - KURL u(QString::fromLatin1(IBS_BASE_URL)); + KURL u(TQString::tqfromLatin1(IBS_BASE_URL)); if(!canFetch(Kernel::self()->collectionType())) { - message(i18n("%1 does not allow searching for this collection type.").arg(source()), MessageHandler::Warning); + message(i18n("%1 does not allow searching for this collection type.").tqarg(source()), MessageHandler::Warning); stop(); return; } switch(key_) { case Title: - u.addQueryItem(QString::fromLatin1("Type"), QString::fromLatin1("keyword")); - u.addQueryItem(QString::fromLatin1("T"), value_); + u.addQueryItem(TQString::tqfromLatin1("Type"), TQString::tqfromLatin1("keyword")); + u.addQueryItem(TQString::tqfromLatin1("T"), value_); break; case Person: - u.addQueryItem(QString::fromLatin1("Type"), QString::fromLatin1("keyword")); - u.addQueryItem(QString::fromLatin1("A"), value_); + u.addQueryItem(TQString::tqfromLatin1("Type"), TQString::tqfromLatin1("keyword")); + u.addQueryItem(TQString::tqfromLatin1("A"), value_); break; case ISBN: { - QString s = value_; + TQString s = value_; s.remove('-'); // limit to first isbn s = s.section(';', 0, 0); - u.setFileName(QString::fromLatin1("serdsp.asp")); - u.addQueryItem(QString::fromLatin1("isbn"), s); + u.setFileName(TQString::tqfromLatin1("serdsp.asp")); + u.addQueryItem(TQString::tqfromLatin1("isbn"), s); } break; case Keyword: - u.addQueryItem(QString::fromLatin1("Type"), QString::fromLatin1("keyword")); - u.addQueryItem(QString::fromLatin1("S"), value_); + u.addQueryItem(TQString::tqfromLatin1("Type"), TQString::tqfromLatin1("keyword")); + u.addQueryItem(TQString::tqfromLatin1("S"), value_); break; default: @@ -110,12 +110,12 @@ void IBSFetcher::search(FetchKey key_, const QString& value_) { // myDebug() << "IBSFetcher::search() - url: " << u.url() << endl; m_job = KIO::get(u, false, false); - connect(m_job, SIGNAL(data(KIO::Job*, const QByteArray&)), - SLOT(slotData(KIO::Job*, const QByteArray&))); + connect(m_job, TQT_SIGNAL(data(KIO::Job*, const TQByteArray&)), + TQT_SLOT(slotData(KIO::Job*, const TQByteArray&))); if(key_ == ISBN) { - connect(m_job, SIGNAL(result(KIO::Job*)), SLOT(slotCompleteISBN(KIO::Job*))); + connect(m_job, TQT_SIGNAL(result(KIO::Job*)), TQT_SLOT(slotCompleteISBN(KIO::Job*))); } else { - connect(m_job, SIGNAL(result(KIO::Job*)), SLOT(slotComplete(KIO::Job*))); + connect(m_job, TQT_SIGNAL(result(KIO::Job*)), TQT_SLOT(slotComplete(KIO::Job*))); } } @@ -133,8 +133,8 @@ void IBSFetcher::stop() { emit signalDone(this); } -void IBSFetcher::slotData(KIO::Job*, const QByteArray& data_) { - QDataStream stream(m_data, IO_WriteOnly | IO_Append); +void IBSFetcher::slotData(KIO::Job*, const TQByteArray& data_) { + TQDataStream stream(m_data, IO_WriteOnly | IO_Append); stream.writeRawBytes(data_.data(), data_.size()); } @@ -154,28 +154,28 @@ void IBSFetcher::slotComplete(KIO::Job* job_) { return; } - QString s = Tellico::decodeHTML(QString(m_data)); + TQString s = Tellico::decodeHTML(TQString(m_data)); // really specific regexp - QString pat = QString::fromLatin1("http://www.internetbookshop.it/code/"); - QRegExp anchorRx(QString::fromLatin1("<a\\s+[^>]*href\\s*=\\s*[\"'](") + - QRegExp::escape(pat) + - QString::fromLatin1("[^\"]*)\"[^>]*><b>([^<]+)<"), false); + TQString pat = TQString::tqfromLatin1("http://www.internetbookshop.it/code/"); + TQRegExp anchorRx(TQString::tqfromLatin1("<a\\s+[^>]*href\\s*=\\s*[\"'](") + + TQRegExp::escape(pat) + + TQString::tqfromLatin1("[^\"]*)\"[^>]*><b>([^<]+)<"), false); anchorRx.setMinimal(true); - QRegExp tagRx(QString::fromLatin1("<.*>")); + TQRegExp tagRx(TQString::tqfromLatin1("<.*>")); tagRx.setMinimal(true); - QString u, t, d; + TQString u, t, d; int pos2; for(int pos = anchorRx.search(s); m_started && pos > -1; pos = anchorRx.search(s, pos+anchorRx.matchedLength())) { if(!u.isEmpty()) { - SearchResult* r = new SearchResult(this, t, d, QString()); + SearchResult* r = new SearchResult(this, t, d, TQString()); emit signalResultFound(r); #ifdef IBS_TEST - KURL url = KURL::fromPathOrURL(QString::fromLatin1("/home/robby/ibs2.html")); + KURL url = KURL::fromPathOrURL(TQString::tqfromLatin1("/home/robby/ibs2.html")); #else - // the url probable contains & so be careful - KURL url = u.replace(QString::fromLatin1("&"), QChar('&')); + // the url probable tqcontains & so be careful + KURL url = u.tqreplace(TQString::tqfromLatin1("&"), TQChar('&')); #endif m_matches.insert(r->uid, url); @@ -185,9 +185,9 @@ void IBSFetcher::slotComplete(KIO::Job* job_) { } u = anchorRx.cap(1); t = anchorRx.cap(2); - pos2 = s.find(QString::fromLatin1("<br>"), pos, false); + pos2 = s.tqfind(TQString::tqfromLatin1("<br>"), pos, false); if(pos2 > -1) { - int pos3 = s.find(QString::fromLatin1("<br>"), pos2+1, false); + int pos3 = s.tqfind(TQString::tqfromLatin1("<br>"), pos2+1, false); if(pos3 > -1) { d = s.mid(pos2, pos3-pos2).remove(tagRx).simplifyWhiteSpace(); } @@ -195,9 +195,9 @@ void IBSFetcher::slotComplete(KIO::Job* job_) { } #ifndef IBS_TEST if(!u.isEmpty()) { - SearchResult* r = new SearchResult(this, t, d, QString()); + SearchResult* r = new SearchResult(this, t, d, TQString()); emit signalResultFound(r); - m_matches.insert(r->uid, u.replace(QString::fromLatin1("&"), QChar('&'))); + m_matches.insert(r->uid, u.tqreplace(TQString::tqfromLatin1("&"), TQChar('&'))); } #endif @@ -220,16 +220,16 @@ void IBSFetcher::slotCompleteISBN(KIO::Job* job_) { return; } - QString str = Tellico::decodeHTML(QString(m_data)); - if(str.find(QString::fromLatin1("Libro non presente"), 0, false /* cas-sensitive */) > -1) { + TQString str = Tellico::decodeHTML(TQString(m_data)); + if(str.tqfind(TQString::tqfromLatin1("Libro non presente"), 0, false /* cas-sensitive */) > -1) { stop(); return; } Data::EntryPtr entry = parseEntry(str); if(entry) { - QString desc = entry->field(QString::fromLatin1("author")) - + '/' + entry->field(QString::fromLatin1("publisher")); - SearchResult* r = new SearchResult(this, entry->title(), desc, entry->field(QString::fromLatin1("isbn"))); + TQString desc = entry->field(TQString::tqfromLatin1("author")) + + '/' + entry->field(TQString::tqfromLatin1("publisher")); + SearchResult* r = new SearchResult(this, entry->title(), desc, entry->field(TQString::tqfromLatin1("isbn"))); emit signalResultFound(r); m_matches.insert(r->uid, static_cast<KIO::TransferJob*>(job_)->url().url()); } @@ -250,7 +250,7 @@ Tellico::Data::EntryPtr IBSFetcher::fetchEntry(uint uid_) { return 0; } - QString results = Tellico::decodeHTML(FileHandler::readTextFile(url, true)); + TQString results = Tellico::decodeHTML(FileHandler::readTextFile(url, true)); if(results.isEmpty()) { myDebug() << "IBSFetcher::fetchEntry() - no text results" << endl; return 0; @@ -259,10 +259,10 @@ Tellico::Data::EntryPtr IBSFetcher::fetchEntry(uint uid_) { // myDebug() << url.url() << endl; #if 0 kdWarning() << "Remove debug from ibsfetcher.cpp" << endl; - QFile f(QString::fromLatin1("/tmp/test.html")); + TQFile f(TQString::tqfromLatin1("/tmp/test.html")); if(f.open(IO_WriteOnly)) { - QTextStream t(&f); - t.setEncoding(QTextStream::UnicodeUTF8); + TQTextStream t(&f); + t.setEncoding(TQTextStream::UnicodeUTF8); t << results; } f.close(); @@ -277,13 +277,13 @@ Tellico::Data::EntryPtr IBSFetcher::fetchEntry(uint uid_) { return entry; } -Tellico::Data::EntryPtr IBSFetcher::parseEntry(const QString& str_) { +Tellico::Data::EntryPtr IBSFetcher::parseEntry(const TQString& str_) { // myDebug() << "IBSFetcher::parseEntry()" << endl; // class might be anime_info_top - QString pat = QString::fromLatin1("%1(?:<[^>]+>)+([^<>\\s][^<>]+)"); + TQString pat = TQString::tqfromLatin1("%1(?:<[^>]+>)+([^<>\\s][^<>]+)"); - QRegExp isbnRx(QString::fromLatin1("isbn=([\\dxX]{13})"), false); - QString isbn; + TQRegExp isbnRx(TQString::tqfromLatin1("isbn=([\\dxX]{13})"), false); + TQString isbn; int pos = isbnRx.search(str_); if(pos > -1) { isbn = isbnRx.cap(1); @@ -292,26 +292,26 @@ Tellico::Data::EntryPtr IBSFetcher::parseEntry(const QString& str_) { Data::CollPtr coll = new Data::BookCollection(true); // map captions in HTML to field names - QMap<QString, QString> fieldMap; - fieldMap.insert(QString::fromLatin1("Titolo"), QString::fromLatin1("title")); - fieldMap.insert(QString::fromLatin1("Autore"), QString::fromLatin1("author")); - fieldMap.insert(QString::fromLatin1("Anno"), QString::fromLatin1("pub_year")); - fieldMap.insert(QString::fromLatin1("Categoria"), QString::fromLatin1("genre")); - fieldMap.insert(QString::fromLatin1("Rilegatura"), QString::fromLatin1("binding")); - fieldMap.insert(QString::fromLatin1("Editore"), QString::fromLatin1("publisher")); - fieldMap.insert(QString::fromLatin1("Dati"), QString::fromLatin1("edition")); - - QRegExp pagesRx(QString::fromLatin1("(\\d+) p\\.(\\s*,\\s*)?")); + TQMap<TQString, TQString> fieldMap; + fieldMap.insert(TQString::tqfromLatin1("Titolo"), TQString::tqfromLatin1("title")); + fieldMap.insert(TQString::tqfromLatin1("Autore"), TQString::tqfromLatin1("author")); + fieldMap.insert(TQString::tqfromLatin1("Anno"), TQString::tqfromLatin1("pub_year")); + fieldMap.insert(TQString::tqfromLatin1("Categoria"), TQString::tqfromLatin1("genre")); + fieldMap.insert(TQString::tqfromLatin1("Rilegatura"), TQString::tqfromLatin1("binding")); + fieldMap.insert(TQString::tqfromLatin1("Editore"), TQString::tqfromLatin1("publisher")); + fieldMap.insert(TQString::tqfromLatin1("Dati"), TQString::tqfromLatin1("edition")); + + TQRegExp pagesRx(TQString::tqfromLatin1("(\\d+) p\\.(\\s*,\\s*)?")); Data::EntryPtr entry = new Data::Entry(coll); - for(QMap<QString, QString>::Iterator it = fieldMap.begin(); it != fieldMap.end(); ++it) { - QRegExp infoRx(pat.arg(it.key())); + for(TQMap<TQString, TQString>::Iterator it = fieldMap.begin(); it != fieldMap.end(); ++it) { + TQRegExp infoRx(pat.tqarg(it.key())); pos = infoRx.search(str_); if(pos > -1) { if(it.data() == Latin1Literal("edition")) { int pos2 = pagesRx.search(infoRx.cap(1)); if(pos2 > -1) { - entry->setField(QString::fromLatin1("pages"), pagesRx.cap(1)); + entry->setField(TQString::tqfromLatin1("pages"), pagesRx.cap(1)); entry->setField(it.data(), infoRx.cap(1).remove(pagesRx)); } else { entry->setField(it.data(), infoRx.cap(1)); @@ -324,70 +324,70 @@ Tellico::Data::EntryPtr IBSFetcher::parseEntry(const QString& str_) { // image if(!isbn.isEmpty()) { - entry->setField(QString::fromLatin1("isbn"), isbn); + entry->setField(TQString::tqfromLatin1("isbn"), isbn); #if 1 - QString imgURL = QString::fromLatin1("http://giotto.ibs.it/cop/copt13.asp?f=%1").arg(isbn); + TQString imgURL = TQString::tqfromLatin1("http://giotto.ibs.it/cop/copt13.asp?f=%1").tqarg(isbn); myLog() << "IBSFetcher() - cover = " << imgURL << endl; - QString id = ImageFactory::addImage(imgURL, true, QString::fromLatin1("http://internetbookshop.it")); + TQString id = ImageFactory::addImage(imgURL, true, TQString::tqfromLatin1("http://internetbookshop.it")); if(!id.isEmpty()) { - entry->setField(QString::fromLatin1("cover"), id); + entry->setField(TQString::tqfromLatin1("cover"), id); } #else - QRegExp imgRx(QString::fromLatin1("<img\\s+[^>]*\\s*src\\s*=\\s*\"(http://[^/]*\\.ibs\\.it/[^\"]+e=%1)").arg(isbn)); + TQRegExp imgRx(TQString::tqfromLatin1("<img\\s+[^>]*\\s*src\\s*=\\s*\"(http://[^/]*\\.ibs\\.it/[^\"]+e=%1)").tqarg(isbn)); imgRx.setMinimal(true); pos = imgRx.search(str_); if(pos > -1) { myLog() << "IBSFetcher() - cover = " << imgRx.cap(1) << endl; - QString id = ImageFactory::addImage(imgRx.cap(1), true, QString::fromLatin1("http://internetbookshop.it")); + TQString id = ImageFactory::addImage(imgRx.cap(1), true, TQString::tqfromLatin1("http://internetbookshop.it")); if(!id.isEmpty()) { - entry->setField(QString::fromLatin1("cover"), id); + entry->setField(TQString::tqfromLatin1("cover"), id); } } #endif } // now look for description - QRegExp descRx(QString::fromLatin1("Descrizione(?:<[^>]+>)+([^<>\\s].+)</span>"), false); + TQRegExp descRx(TQString::tqfromLatin1("Descrizione(?:<[^>]+>)+([^<>\\s].+)</span>"), false); descRx.setMinimal(true); pos = descRx.search(str_); if(pos == -1) { - descRx.setPattern(QString::fromLatin1("In sintesi(?:<[^>]+>)+([^<>\\s].+)</span>")); + descRx.setPattern(TQString::tqfromLatin1("In sintesi(?:<[^>]+>)+([^<>\\s].+)</span>")); pos = descRx.search(str_); } if(pos > -1) { - Data::FieldPtr f = new Data::Field(QString::fromLatin1("plot"), i18n("Plot Summary"), Data::Field::Para); + Data::FieldPtr f = new Data::Field(TQString::tqfromLatin1("plot"), i18n("Plot Summary"), Data::Field::Para); coll->addField(f); entry->setField(f, descRx.cap(1).simplifyWhiteSpace()); } // IBS switches the surname and family name of the author - QStringList names = entry->fields(QString::fromLatin1("author"), false); + TQStringList names = entry->fields(TQString::tqfromLatin1("author"), false); if(!names.isEmpty() && !names[0].isEmpty()) { - for(QStringList::Iterator it = names.begin(); it != names.end(); ++it) { - if((*it).find(',') > -1) { + for(TQStringList::Iterator it = names.begin(); it != names.end(); ++it) { + if((*it).tqfind(',') > -1) { continue; // skip if it has a comma } - QStringList words = QStringList::split(' ', *it); + TQStringList words = TQStringList::split(' ', *it); if(words.isEmpty()) { continue; } // put first word in back words.append(words[0]); words.pop_front(); - *it = words.join(QChar(' ')); + *it = words.join(TQChar(' ')); } - entry->setField(QString::fromLatin1("author"), names.join(QString::fromLatin1("; "))); + entry->setField(TQString::tqfromLatin1("author"), names.join(TQString::tqfromLatin1("; "))); } return entry; } void IBSFetcher::updateEntry(Data::EntryPtr entry_) { - QString isbn = entry_->field(QString::fromLatin1("isbn")); + TQString isbn = entry_->field(TQString::tqfromLatin1("isbn")); if(!isbn.isEmpty()) { search(Fetch::ISBN, isbn); return; } - QString t = entry_->field(QString::fromLatin1("title")); + TQString t = entry_->field(TQString::tqfromLatin1("title")); if(!t.isEmpty()) { search(Fetch::Title, t); return; @@ -397,18 +397,18 @@ void IBSFetcher::updateEntry(Data::EntryPtr entry_) { emit signalDone(this); // always need to emit this if not continuing with the search } -Tellico::Fetch::ConfigWidget* IBSFetcher::configWidget(QWidget* parent_) const { - return new IBSFetcher::ConfigWidget(parent_); +Tellico::Fetch::ConfigWidget* IBSFetcher::configWidget(TQWidget* tqparent_) const { + return new IBSFetcher::ConfigWidget(tqparent_); } -IBSFetcher::ConfigWidget::ConfigWidget(QWidget* parent_) - : Fetch::ConfigWidget(parent_) { - QVBoxLayout* l = new QVBoxLayout(optionsWidget()); - l->addWidget(new QLabel(i18n("This source has no options."), optionsWidget())); +IBSFetcher::ConfigWidget::ConfigWidget(TQWidget* tqparent_) + : Fetch::ConfigWidget(tqparent_) { + TQVBoxLayout* l = new TQVBoxLayout(optionsWidget()); + l->addWidget(new TQLabel(i18n("This source has no options."), optionsWidget())); l->addStretch(); } -QString IBSFetcher::ConfigWidget::preferredName() const { +TQString IBSFetcher::ConfigWidget::preferredName() const { return IBSFetcher::defaultName(); } |