From: gilead Date: Sun, 5 Sep 2010 20:27:37 +0000 (+0200) Subject: Minor updates for versions 0.2.1 and 0.2.2. See changelog file. X-Git-Url: http://git.maemo.org/git/?p=movie-schedule;a=commitdiff_plain;h=fbbb2a758b18a7afff51d27852f85977fe796b35;hp=2198ae3ccdffc8b6495ee1f5f91657611808ec93 Minor updates for versions 0.2.1 and 0.2.2. See changelog file. --- diff --git a/debian/changelog b/debian/changelog index c9e0f24..6de16f9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,16 @@ +movie-schedule (0.2.2) unstable; urgency=low + + * Fixed interpretation of schedule times (Closes: #6234) + + -- Jochen Becher Sun, 05 Sep 2010 22:15:00 +0000 + + +movie-schedule (0.2.1) unstable; urgency=low + + * Fixed link to bugtracker in debian/control files (Closes: #6226) + + -- Jochen Becher Fri, 13 Aug 2010 16:35:00 +0000 + movie-schedule (0.2.0) unstable; urgency=low * Fixed trimming of phone numbers before calling cinema (Closes: #6110) diff --git a/debian/control b/debian/control index 0d8ed11..c5af62a 100644 --- a/debian/control +++ b/debian/control @@ -14,7 +14,7 @@ Description: Find movies at cinemas near your town. days or find your preferred time to watch the latest block buster. Don't miss a movie by addding a calendar entry automatically or google for the cinema's or movie's web page. -XSBC-Bugtracker: https://bugs.maemo.org/enter_bug.cgi?product=movie-schedule +XSBC-Bugtracker: https://garage.maemo.org/tracker/?group_id=1781 XSBC-Maemo-Display-Name: MovieSchedule XB-Maemo-Icon-26: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAL 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 diff --git a/src/searchclients/abstractsearchclient.h b/src/searchclients/abstractsearchclient.h index 2cc45bb..123984b 100644 --- a/src/searchclients/abstractsearchclient.h +++ b/src/searchclients/abstractsearchclient.h @@ -53,6 +53,9 @@ protected: Q_SLOT virtual void DownloadProgress(qint64, qint64); Q_SLOT virtual void NetworkError(QNetworkReply::NetworkError); +protected: + QList TimesFromString(const QList &time_strings); + private: void FixLocation(QUrl *url); diff --git a/src/searchclients/movieschedulesearchclient.cpp b/src/searchclients/movieschedulesearchclient.cpp index cb2ac42..7041c5e 100644 --- a/src/searchclients/movieschedulesearchclient.cpp +++ b/src/searchclients/movieschedulesearchclient.cpp @@ -90,7 +90,7 @@ void MovieScheduleSearchClient::ReplyFinished(QNetworkReply *reply) QString theater_name; QString theater_address; QString theater_phone; - QList schedule; + QList schedule; QRegExp time_pattern("\\d+:\\d+([aApP][mM])*"); while (!xml.atEnd()) { QXmlStreamReader::TokenType token = xml.readNext(); @@ -164,8 +164,14 @@ void MovieScheduleSearchClient::ReplyFinished(QNetworkReply *reply) if (!theater_phone.isEmpty()) { cinema->SetTelephone(theater_phone); } - Q_FOREACH(const QTime time, schedule) { - _cinema_schedule->AddSchedule(cinema, movie, time, _date); + QList schedule_times = TimesFromString(schedule); + Q_FOREACH(const QTime time, schedule_times) { + if (time.hour() < 3) { + // interpret very early times as shifted by 1 day (seems to be a Google logic) + _cinema_schedule->AddSchedule(cinema, movie, time, _date.addDays(1)); + } else { + _cinema_schedule->AddSchedule(cinema, movie, time, _date); + } } } } @@ -185,11 +191,8 @@ void MovieScheduleSearchClient::ReplyFinished(QNetworkReply *reply) while ((i = time_pattern.indexIn(t, i)) != -1) { int length = time_pattern.matchedLength(); //std::cout << "time " << qPrintable(t.mid(i, length)) << std::endl; - QTime time = TimeUtils::FromTimeString(t.mid(i, length)); - if (time.isValid()) { - schedule.append(time); - } else { - std::cout << "ERROR: time " << qPrintable(t.mid(i, length)) << " is invalid." << std::endl; + if (length > 0) { + schedule.append(t.mid(i, length)); } i += length; found = true; diff --git a/src/searchclients/theaterschedulesearchclient.cpp b/src/searchclients/theaterschedulesearchclient.cpp index 7e1d0ce..82f8482 100644 --- a/src/searchclients/theaterschedulesearchclient.cpp +++ b/src/searchclients/theaterschedulesearchclient.cpp @@ -92,7 +92,7 @@ void TheaterScheduleSearchClient::ReplyFinished(QNetworkReply *reply) QVector movie_spans; QString theaters_url; double rating = -1.0; - QList schedule; + QList schedule; QRegExp time_pattern("\\d+:\\d+([aApP][mM])*"); QRegExp duration_pattern("((\\d+)hr )?(\\d+)min"); QRegExp reviews_pattern("\\d+ review(s)?"); @@ -202,8 +202,14 @@ void TheaterScheduleSearchClient::ReplyFinished(QNetworkReply *reply) movie->SetComment(s); } } - Q_FOREACH(const QTime time, schedule) { - _cinema_schedule->AddSchedule(cinema, movie, time, _date); + QList schedule_times = TimesFromString(schedule); + Q_FOREACH(const QTime time, schedule_times) { + if (time.hour() < 3) { + // interpret very early times as shifted by 1 day (seems to be a Google logic) + _cinema_schedule->AddSchedule(cinema, movie, time, _date.addDays(1)); + } else { + _cinema_schedule->AddSchedule(cinema, movie, time, _date); + } } } } @@ -228,11 +234,8 @@ void TheaterScheduleSearchClient::ReplyFinished(QNetworkReply *reply) int i = 0; while ((i = time_pattern.indexIn(t, i)) != -1) { int length = time_pattern.matchedLength(); - QTime time = TimeUtils::FromTimeString(t.mid(i, length)); - if (time.isValid()) { - schedule.append(time); - } else { - //std::cout << "ERROR: time " << qPrintable(t.mid(i, length)) << " is invalid." << std::endl; + if (length > 0) { + schedule.append(t.mid(i, length)); } i += length; } diff --git a/src/utils/timeutils.cpp b/src/utils/timeutils.cpp index 3597c40..2af4f7b 100644 --- a/src/utils/timeutils.cpp +++ b/src/utils/timeutils.cpp @@ -34,6 +34,7 @@ QTime TimeUtils::FromTimeString(const QString &time) ++m; } if (m == 0 || pos >= n || time[pos] != ':') { + // syntax error return QTime(); } ++pos; @@ -44,6 +45,7 @@ QTime TimeUtils::FromTimeString(const QString &time) ++m; } if (m == 0) { + // syntax error return QTime(); } if (pos < n) { @@ -53,15 +55,13 @@ QTime TimeUtils::FromTimeString(const QString &time) hours += 12; } } else if (s.compare("am", Qt::CaseInsensitive) == 0) { - // nothing to do + if (hours >= 12) { + hours -= 12; + } } else { + // illegal suffix return QTime(); } - } else { - // assume pm as default - if (hours < 12) { - hours += 12; - } } return QTime(hours, minutes); }