X-Git-Url: http://git.maemo.org/git/?p=movie-schedule;a=blobdiff_plain;f=src%2Fsearchclients%2Fabstractsearchclient.cpp;h=c19b7bcbc7df25434bbb33966b204f14fbbd1a8d;hp=dc1219f1032893843fc0d8154ee0673185a2fd4c;hb=fbbb2a758b18a7afff51d27852f85977fe796b35;hpb=2198ae3ccdffc8b6495ee1f5f91657611808ec93 diff --git a/src/searchclients/abstractsearchclient.cpp b/src/searchclients/abstractsearchclient.cpp index dc1219f..c19b7bc 100644 --- a/src/searchclients/abstractsearchclient.cpp +++ b/src/searchclients/abstractsearchclient.cpp @@ -17,6 +17,8 @@ #include "abstractsearchclient.h" +#include "utils/timeutils.h" + #include #include @@ -27,7 +29,7 @@ AbstractSearchClient::AbstractSearchClient(QObject *parent) _start(0) { connect(_network, SIGNAL(finished(QNetworkReply *)), - this, SLOT(ReplyFinished(QNetworkReply*))); + this, SLOT(ReplyFinished(QNetworkReply*))); { QMutexLocker locker(&_next_search_task_id_mutex); _search_task_id = _next_search_task_id++; @@ -83,6 +85,65 @@ void AbstractSearchClient::NetworkError(QNetworkReply::NetworkError error) deleteLater(); } +QList AbstractSearchClient::TimesFromString(const QList &time_strings) +{ + QList schedule_times; + bool am_pm = false; + Q_FOREACH(const QString time_str, time_strings) { + if (time_str.endsWith("am", Qt::CaseInsensitive) || time_str.endsWith("pm", Qt::CaseInsensitive)) { + am_pm = true; + } + } + if (am_pm) { + int i = 0; + bool am = true; + while (i < time_strings.length()) { + int j = i; + while (i < time_strings.length()) { + if (time_strings[i].endsWith("am", Qt::CaseInsensitive)) { + am = true; + break; + } else if (time_strings[i].endsWith("pm", Qt::CaseInsensitive)) { + am = false; + break; + } + ++i; + } + while (j < i) { + QString time_str = time_strings[j] + (am ? "am" : "pm"); + QTime time = TimeUtils::FromTimeString(time_str); + if (time.isValid()) { + schedule_times.append(time); + } else { + std::cout << "ERROR: time " << qPrintable(time_str) << " is invalid." << std::endl; + } + ++j; + } + if (i < time_strings.length()) { + QString time_str = time_strings[i]; + QTime time = TimeUtils::FromTimeString(time_str); + if (time.isValid()) { + schedule_times.append(time); + } else { + std::cout << "ERROR: time " << qPrintable(time_str) << " is invalid." << std::endl; + } + schedule_times.append(time); + } + ++i; + } + } else { + Q_FOREACH(const QString time_str, time_strings) { + QTime time = TimeUtils::FromTimeString(time_str); + if (time.isValid()) { + schedule_times.append(time); + } else { + std::cout << "ERROR: time " << qPrintable(time_str) << " is invalid." << std::endl; + } + } + } + return schedule_times; +} + void AbstractSearchClient::FixLocation(QUrl *url) { // Try to fix the Google url which returns