Minor updates for versions 0.2.1 and 0.2.2. See changelog file.
authorgilead <j.becher@ovi.com>
Sun, 5 Sep 2010 20:27:37 +0000 (22:27 +0200)
committergilead <j.becher@ovi.com>
Sun, 5 Sep 2010 20:27:37 +0000 (22:27 +0200)
debian/changelog
debian/control
src/searchclients/abstractsearchclient.cpp
src/searchclients/abstractsearchclient.h
src/searchclients/movieschedulesearchclient.cpp
src/searchclients/theaterschedulesearchclient.cpp
src/utils/timeutils.cpp

index c9e0f24..6de16f9 100644 (file)
@@ -1,3 +1,16 @@
+movie-schedule (0.2.2) unstable; urgency=low
+
+  * Fixed interpretation of schedule times (Closes: #6234)
+
+ -- Jochen Becher <j.becher@ovi.com>  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 <j.becher@ovi.com>  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)
 movie-schedule (0.2.0) unstable; urgency=low
 
   * Fixed trimming of phone numbers before calling cinema (Closes: #6110)
index 0d8ed11..c5af62a 100644 (file)
@@ -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.
  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
 XSBC-Maemo-Display-Name: MovieSchedule
 XB-Maemo-Icon-26:
  iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAL
index dc1219f..c19b7bc 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "abstractsearchclient.h"
 
 
 #include "abstractsearchclient.h"
 
+#include "utils/timeutils.h"
+
 #include <QMutexLocker>
 #include <iostream>
 
 #include <QMutexLocker>
 #include <iostream>
 
@@ -27,7 +29,7 @@ AbstractSearchClient::AbstractSearchClient(QObject *parent)
     _start(0)
 {
     connect(_network, SIGNAL(finished(QNetworkReply *)),
     _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++;
     {
         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();
 }
 
     deleteLater();
 }
 
+QList<QTime> AbstractSearchClient::TimesFromString(const QList<QString> &time_strings)
+{
+    QList<QTime> 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
 void AbstractSearchClient::FixLocation(QUrl *url)
 {
     // Try to fix the Google url which returns
index 2cc45bb..123984b 100644 (file)
@@ -53,6 +53,9 @@ protected:
     Q_SLOT virtual void DownloadProgress(qint64, qint64);
     Q_SLOT virtual void NetworkError(QNetworkReply::NetworkError);
 
     Q_SLOT virtual void DownloadProgress(qint64, qint64);
     Q_SLOT virtual void NetworkError(QNetworkReply::NetworkError);
 
+protected:
+    QList<QTime> TimesFromString(const QList<QString> &time_strings);
+
 private:
     void FixLocation(QUrl *url);
 
 private:
     void FixLocation(QUrl *url);
 
index cb2ac42..7041c5e 100644 (file)
@@ -90,7 +90,7 @@ void MovieScheduleSearchClient::ReplyFinished(QNetworkReply *reply)
     QString theater_name;
     QString theater_address;
     QString theater_phone;
     QString theater_name;
     QString theater_address;
     QString theater_phone;
-    QList<QTime> schedule;
+    QList<QString> schedule;
     QRegExp time_pattern("\\d+:\\d+([aApP][mM])*");
     while (!xml.atEnd()) {
         QXmlStreamReader::TokenType token = xml.readNext();
     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);
                             }
                             if (!theater_phone.isEmpty()) {
                                 cinema->SetTelephone(theater_phone);
                             }
-                            Q_FOREACH(const QTime time, schedule) {
-                                _cinema_schedule->AddSchedule(cinema, movie, time, _date);
+                            QList<QTime> 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;
                 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;
                     }
                     i += length;
                     found = true;
index 7e1d0ce..82f8482 100644 (file)
@@ -92,7 +92,7 @@ void TheaterScheduleSearchClient::ReplyFinished(QNetworkReply *reply)
     QVector<QString> movie_spans;
     QString theaters_url;
     double rating = -1.0;
     QVector<QString> movie_spans;
     QString theaters_url;
     double rating = -1.0;
-    QList<QTime> schedule;
+    QList<QString> schedule;
     QRegExp time_pattern("\\d+:\\d+([aApP][mM])*");
     QRegExp duration_pattern("((\\d+)hr )?(\\d+)min");
     QRegExp reviews_pattern("\\d+ review(s)?");
     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);
                                 }
                             }
                                     movie->SetComment(s);
                                 }
                             }
-                            Q_FOREACH(const QTime time, schedule) {
-                                _cinema_schedule->AddSchedule(cinema, movie, time, _date);
+                            QList<QTime> 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();
                 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;
                 }
                     }
                     i += length;
                 }
index 3597c40..2af4f7b 100644 (file)
@@ -34,6 +34,7 @@ QTime TimeUtils::FromTimeString(const QString &time)
         ++m;
     }
     if (m == 0 || pos >= n || time[pos] != ':') {
         ++m;
     }
     if (m == 0 || pos >= n || time[pos] != ':') {
+        // syntax error
         return QTime();
     }
     ++pos;
         return QTime();
     }
     ++pos;
@@ -44,6 +45,7 @@ QTime TimeUtils::FromTimeString(const QString &time)
         ++m;
     }
     if (m == 0) {
         ++m;
     }
     if (m == 0) {
+        // syntax error
         return QTime();
     }
     if (pos < n) {
         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) {
                 hours += 12;
             }
         } else if (s.compare("am", Qt::CaseInsensitive) == 0) {
-            // nothing to do
+            if (hours >= 12) {
+                hours -= 12;
+            }
         } else {
         } else {
+            // illegal suffix
             return QTime();
         }
             return QTime();
         }
-    } else {
-        // assume pm as default
-        if (hours < 12) {
-            hours += 12;
-        }
     }
     return QTime(hours, minutes);
 }
     }
     return QTime(hours, minutes);
 }