From b04a2a981a91ed58e55a275402cb2f9f73bd85a2 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 6 Apr 2013 17:42:47 +0200 Subject: timezone issue was tapatalk plugin bug, so remove workaround --- fetchforumsaction.cpp | 6 +++--- fetchforumsaction.h | 2 +- fetchpostsaction.cpp | 27 ++++++++++----------------- fetchpostsaction.h | 7 +++---- fetchtopicsaction.cpp | 15 ++++----------- fetchtopicsaction.h | 3 +-- i18n/en.qm | Bin 419 -> 612 bytes i18n/en.ts | 21 +++++++++++++++++---- i18n/es.qm | Bin 423 -> 640 bytes i18n/es.ts | 21 +++++++++++++++++---- tapasboard.pro | 3 +++ xmlrpcpendingcall.cpp | 42 ++++++++++++++++++++++++++++++------------ xmlrpcpendingcall.h | 1 + 13 files changed, 90 insertions(+), 58 deletions(-) diff --git a/fetchforumsaction.cpp b/fetchforumsaction.cpp index 8bbe23b..814ae02 100644 --- a/fetchforumsaction.cpp +++ b/fetchforumsaction.cpp @@ -58,8 +58,8 @@ void FetchForumsAction::handleFinishedCall() query.bindValue(":forum_id", forum_id); query.bindValue(":parent_id", parent_id); - query.bindValue(":forum_name", unencodeForumText(map["forum_name"])); - query.bindValue(":description", unencodeForumText(map["description"])); + query.bindValue(":forum_name", decodeForumText(map["forum_name"])); + query.bindValue(":description", decodeForumText(map["description"])); query.bindValue(":logo_url", map["logo_url"].toString()); query.bindValue(":new_post", map["new_post"].toBool() ? 1 : 0); query.bindValue(":is_protected", map["is_protected"].toBool() ? 1 : 0); @@ -109,7 +109,7 @@ QList FetchForumsAction::flattenForumList(const QVariantList &list, return flattened; } -QString FetchForumsAction::unencodeForumText(const QVariant &v) +QString FetchForumsAction::decodeForumText(const QVariant &v) { QByteArray ba = v.toByteArray(); return QString::fromUtf8(ba.constData(), ba.length()); diff --git a/fetchforumsaction.h b/fetchforumsaction.h index b047bcb..3652492 100644 --- a/fetchforumsaction.h +++ b/fetchforumsaction.h @@ -21,7 +21,7 @@ private slots: private: static QList flattenForumList(const QVariantList& list, int *order); - static QString unencodeForumText(const QVariant& v); + static QString decodeForumText(const QVariant& v); private: diff --git a/fetchpostsaction.cpp b/fetchpostsaction.cpp index dbfaf41..d293129 100644 --- a/fetchpostsaction.cpp +++ b/fetchpostsaction.cpp @@ -83,7 +83,7 @@ void FetchPostsAction::handleFinishedCall() // Not fatal, just assume it's the one we requested topic_id = _topicId; } - const QString topic_title = unencodePostText(map["topic_title"]); + const QString topic_title = decodePostText(map["topic_title"]); const int unread_position = map["position"].toInt() - 1; const int total_post_num = map["total_post_num"].toInt(); @@ -126,13 +126,13 @@ void FetchPostsAction::handleFinishedCall() query.bindValue(":topic_id", topic_id); query.bindValue(":post_id", post_id); - query.bindValue(":post_title", unencodePostTitle(post["post_title"], topic_title)); - query.bindValue(":post_content", unencodePostContent(post["post_content"])); + query.bindValue(":post_title", decodePostTitle(post["post_title"], topic_title)); + query.bindValue(":post_content", decodePostContent(post["post_content"])); query.bindValue(":post_author_id", post["post_author_id"].toInt()); - query.bindValue(":post_author_name", unencodePostText(post["post_author_name"])); + query.bindValue(":post_author_name", decodePostText(post["post_author_name"])); query.bindValue(":can_edit", post["can_edit"].toBool() ? 1 : 0); query.bindValue(":icon_url", post["icon_url"].toString()); - query.bindValue(":post_time", unencodeDateTime(post["post_time"])); + query.bindValue(":post_time", post["post_time"].toDateTime().toUTC()); query.bindValue(":position", position); query.bindValue(":last_update_time", QDateTime::currentDateTimeUtc()); @@ -176,15 +176,15 @@ void FetchPostsAction::handleFinishedCall() _call->deleteLater(); } -QString FetchPostsAction::unencodePostText(const QVariant &v) +QString FetchPostsAction::decodePostText(const QVariant &v) { QByteArray ba = v.toByteArray(); return QString::fromUtf8(ba.constData(), ba.length()); } -QString FetchPostsAction::unencodePostTitle(const QVariant &v, const QString &topicTitle) +QString FetchPostsAction::decodePostTitle(const QVariant &v, const QString &topicTitle) { - QString title = unencodePostText(v); + QString title = decodePostText(v); if (QString::compare(title, "Re: " + topicTitle, Qt::CaseInsensitive) == 0) { // Hack to disable the useless "Re: $TOPIC_TITLE" post titles everywhere return QString(); @@ -192,15 +192,8 @@ QString FetchPostsAction::unencodePostTitle(const QVariant &v, const QString &to return title; } -QString FetchPostsAction::unencodePostContent(const QVariant &v) +QString FetchPostsAction::decodePostContent(const QVariant &v) { - QString richText = _board->bbcodeToRichText(unencodePostText(v)); + QString richText = _board->bbcodeToRichText(decodePostText(v)); return _board->parseSmilies(richText); } - -QDateTime FetchPostsAction::unencodeDateTime(const QVariant &v) -{ - QDateTime dt = v.toDateTime(); - dt.setTimeSpec(Qt::UTC); - return dt; -} diff --git a/fetchpostsaction.h b/fetchpostsaction.h index f8ad03e..6586ae6 100644 --- a/fetchpostsaction.h +++ b/fetchpostsaction.h @@ -28,10 +28,9 @@ private slots: void handleFinishedCall(); private: - static QString unencodePostText(const QVariant& v); - static QString unencodePostTitle(const QVariant& v, const QString& topicTitle); - QString unencodePostContent(const QVariant& v); - static QDateTime unencodeDateTime(const QVariant& v); + static QString decodePostText(const QVariant& v); + static QString decodePostTitle(const QVariant& v, const QString& topicTitle); + QString decodePostContent(const QVariant& v); private: XmlRpcPendingCall *_call; diff --git a/fetchtopicsaction.cpp b/fetchtopicsaction.cpp index d71bdca..9e42723 100644 --- a/fetchtopicsaction.cpp +++ b/fetchtopicsaction.cpp @@ -85,13 +85,13 @@ void FetchTopicsAction::handleFinishedCall() query.bindValue(":forum_id", forum_id); query.bindValue(":topic_id", topic_id); - query.bindValue(":topic_title", unencodeTopicText(topic["topic_title"])); + query.bindValue(":topic_title", decodeTopicText(topic["topic_title"])); query.bindValue(":topic_author_id", topic["topic_author_id"].toInt()); - query.bindValue(":topic_author_name", unencodeTopicText(topic["topic_author_name"])); + query.bindValue(":topic_author_name", decodeTopicText(topic["topic_author_name"])); query.bindValue(":is_subscribed", topic["is_subscribed"].toBool() ? 1 : 0); query.bindValue(":is_closed", topic["is_closed"].toBool() ? 1 : 0); query.bindValue(":icon_url", topic["icon_url"].toString()); - query.bindValue(":last_reply_time", unencodeDateTime(topic["last_reply_time"])); + query.bindValue(":last_reply_time", topic["last_reply_time"].toDateTime().toUTC()); query.bindValue(":reply_number", topic["reply_number"].toInt()); query.bindValue(":new_post", topic["new_post"].toBool() ? 1 : 0); query.bindValue(":position", position); @@ -130,15 +130,8 @@ void FetchTopicsAction::handleFinishedCall() _call->deleteLater(); } -QString FetchTopicsAction::unencodeTopicText(const QVariant &v) +QString FetchTopicsAction::decodeTopicText(const QVariant &v) { QByteArray ba = v.toByteArray(); return QString::fromUtf8(ba.constData(), ba.length()); } - -QDateTime FetchTopicsAction::unencodeDateTime(const QVariant &v) -{ - QDateTime dt = v.toDateTime(); - dt.setTimeSpec(Qt::UTC); - return dt; -} diff --git a/fetchtopicsaction.h b/fetchtopicsaction.h index 0519e0c..87b756f 100644 --- a/fetchtopicsaction.h +++ b/fetchtopicsaction.h @@ -25,8 +25,7 @@ private slots: void handleFinishedCall(); private: - static QString unencodeTopicText(const QVariant& v); - static QDateTime unencodeDateTime(const QVariant& v); + static QString decodeTopicText(const QVariant& v); private: XmlRpcPendingCall *_call; diff --git a/i18n/en.qm b/i18n/en.qm index c8f4d42..1304d18 100644 Binary files a/i18n/en.qm and b/i18n/en.qm differ diff --git a/i18n/en.ts b/i18n/en.ts index 104f908..2704bf2 100644 --- a/i18n/en.ts +++ b/i18n/en.ts @@ -4,22 +4,22 @@ Board - + Today Today - + Yesterday Yesterday - + Just now Just now - + %n second(s) ago %n seconds ago @@ -35,4 +35,17 @@ + + BoardPage + + + Mark all forums read + Mark all forums read + + + + Mark subforums read + Mark subforums read + + diff --git a/i18n/es.qm b/i18n/es.qm index a41c85c..238d330 100644 Binary files a/i18n/es.qm and b/i18n/es.qm differ diff --git a/i18n/es.ts b/i18n/es.ts index 47c3b9d..acb10ce 100644 --- a/i18n/es.ts +++ b/i18n/es.ts @@ -4,22 +4,22 @@ Board - + Today Hoy - + Yesterday Ayer - + Just now Ahora mismo - + %n second(s) ago hace %n segundo @@ -35,4 +35,17 @@ + + BoardPage + + + Mark all forums read + Marcar foros como leídos + + + + Mark subforums read + Marcar subforos como leídos + + diff --git a/tapasboard.pro b/tapasboard.pro index 33c2306..5d9bd08 100644 --- a/tapasboard.pro +++ b/tapasboard.pro @@ -76,6 +76,9 @@ HEADERS += \ TRANSLATIONS += i18n/en.ts i18n/es.ts +# Uncomment this while working on the translations +# lupdate_hack { SOURCES += qml/*.qml } + OTHER_FILES += \ qtc_packaging/debian_harmattan/rules \ qtc_packaging/debian_harmattan/README \ diff --git a/xmlrpcpendingcall.cpp b/xmlrpcpendingcall.cpp index 8f318bd..f6e4e60 100644 --- a/xmlrpcpendingcall.cpp +++ b/xmlrpcpendingcall.cpp @@ -73,18 +73,7 @@ QVariant XmlRpcPendingCall::decodeValue(QXmlStreamReader *r) if (!ok) value.clear(); } else if (r->name() == "dateTime.iso8601") { QString text = r->readElementText(); - QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate); - if (!dateTime.isValid()) { - // Qt seems not be happy without dashes - text.insert(4, '-'); - text.insert(7, '-'); - dateTime = QDateTime::fromString(text, Qt::ISODate); - if (!dateTime.isValid()) { - qWarning() << "Invalid dateTime format" << text; - return QVariant(); - } - } - value = QVariant::fromValue(dateTime); + value = QVariant::fromValue(decodeISODate(text)); } else if (r->name() == "base64") { QByteArray data = r->readElementText().toAscii(); value = QVariant::fromValue(QByteArray::fromBase64(data)); @@ -150,6 +139,35 @@ QVariant XmlRpcPendingCall::decodeValue(QXmlStreamReader *r) } } +QDateTime XmlRpcPendingCall::decodeISODate(QString text) +{ + if (text.length() < 8) { + // Too short! + return QDateTime(); + } + if (text[4].isNumber() && text[7].isNumber()) { + // Qt seems not be happy without dashes (YYYYMMDD vs YYYY-MM-DD) + text.insert(4, '-'); + text.insert(7, '-'); + } + // Qt will consider UTC offset "+00:00" invalid, so we replace it by "Z". + if (text.endsWith("+00:00") || text.endsWith("-00:00")) { + const int len = 6; // "+00:00" + const int pos = text.length() - len; + text.replace(pos, len, "Z"); + } else if (text.endsWith("+0000") || text.endsWith("-0000")) { + const int len = 5; // "+0000" + const int pos = text.length() - len; + text.replace(pos, len, "Z"); + } else if (text.endsWith("+00") || text.endsWith("-00")) { + const int len = 3; // "+00" + const int pos = text.length() - len; + text.replace(pos, len, "Z"); + } + QDateTime dt = QDateTime::fromString(text, Qt::ISODate); + return dt; +} + void XmlRpcPendingCall::handleRequestFinished() { Q_ASSERT(_state == StateWaitingReply); diff --git a/xmlrpcpendingcall.h b/xmlrpcpendingcall.h index 620ddc4..8c72bc6 100644 --- a/xmlrpcpendingcall.h +++ b/xmlrpcpendingcall.h @@ -30,6 +30,7 @@ signals: private: bool decodeMethodResponse(QXmlStreamReader* r); static QVariant decodeValue(QXmlStreamReader* r); + static QDateTime decodeISODate(QString text); private slots: void handleRequestFinished(); -- cgit v1.2.3