diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp index 3d280a7f8..94e6642cb 100755 --- a/src/core/feedsmodelstandardfeed.cpp +++ b/src/core/feedsmodelstandardfeed.cpp @@ -5,6 +5,7 @@ #include "core/parsingfactory.h" #include "core/databasefactory.h" #include "core/networkfactory.h" +#include "core/textfactory.h" #include "gui/iconfactory.h" #include "gui/iconthemefactory.h" @@ -205,21 +206,36 @@ void FeedsModelStandardFeed::update() { void FeedsModelStandardFeed::updateMessages(const QList &messages) { int feed_id = id(), message_id; + QDateTime message_creation_date; QSqlDatabase database = DatabaseFactory::getInstance()->addConnection("FeedsModelStandardFeed"); // Prepare queries. QSqlQuery query_select(database); QSqlQuery query_insert(database); + QSqlQuery query_update(database); + // Used to check if give feed contains with message with given + // title and url. query_select.setForwardOnly(true); query_select.prepare("SELECT id, feed, date_created FROM Messages " "WHERE feed = :feed AND title = :title AND url = :url;"); + // Used to insert new messages. query_insert.setForwardOnly(true); query_insert.prepare("INSERT INTO Messages " "(feed, title, url, author, date_created, contents) " "VALUES (:feed, :title, :url, :author, :date_created, :contents);"); + // Used to update existing messages of given feed. + // NOTE: Messages are updated if its creation date + // is changed. + query_update.setForwardOnly(true); + query_update.prepare("UPDATE Messages " + "SET title = :title, url = :url, author = :author, " + "date_created = :date_created, contents = :contents, " + "read = 0, important = 0, deleted = 0 " + "WHERE id = :id"); + if (!database.transaction()) { database.rollback(); @@ -236,6 +252,7 @@ void FeedsModelStandardFeed::updateMessages(const QList &messages) { if (query_select.next()) { // Message with this title & url probably exists in current feed. message_id = query_select.value(0).toInt(); + message_creation_date = TextFactory::parseDateTime(query_select.value(2).toString()); } else { message_id = -1; @@ -255,15 +272,28 @@ void FeedsModelStandardFeed::updateMessages(const QList &messages) { query_insert.exec(); query_insert.finish(); } - else { - // Message is already persistently stored. - // TODO: Update message if it got updated in the - // online feed. - if (message.m_createdFromFeed) { - // Creation data of the message was obtained from - // feed itself. + else if (message.m_createdFromFeed && + message_creation_date.isValid() && + message_creation_date > message.m_created) { + qDebug("Message '%s' (id %d) was updated in the feed, updating too.", + qPrintable(message.m_title), + message_id); - } + // TODO: Check if this is actually working. + + // Message with given title/url is already persistently + // stored in given feed. + // Creation data of the message was obtained from + // feed itself. We can update this message. + query_update.bindValue(":title", message.m_title); + query_update.bindValue(":url", message.m_url); + query_update.bindValue(":author", message.m_author); + query_update.bindValue(":date_created", message.m_created.toString(Qt::ISODate)); + query_update.bindValue(":contents", message.m_contents); + query_update.bindValue(":id", message_id); + + query_update.exec(); + query_update.finish(); } } diff --git a/src/core/parsingfactory.cpp b/src/core/parsingfactory.cpp index 916f16617..17fca2ee7 100644 --- a/src/core/parsingfactory.cpp +++ b/src/core/parsingfactory.cpp @@ -33,7 +33,7 @@ QList ParsingFactory::parseAsATOM10(const QString &data) { elem_summary = message_item.namedItem("content").toElement().text(); } - // Now we obtained maximum of informations for title & description. + // Now we obtained maximum of information for title & description. if (elem_title.isEmpty()) { if (elem_summary.isEmpty()) { // BOTH title and description are empty, skip this message. @@ -100,7 +100,7 @@ QList ParsingFactory::parseAsRDF(const QString &data) { QString elem_title = message_item.namedItem("title").toElement().text().simplified(); QString elem_description = message_item.namedItem("description").toElement().text(); - // Now we obtained maximum of informations for title & description. + // Now we obtained maximum of information for title & description. if (elem_title.isEmpty()) { if (elem_description.isEmpty()) { // BOTH title and description are empty, skip this message. @@ -168,7 +168,7 @@ QList ParsingFactory::parseAsRSS20(const QString &data) { elem_description = message_item.namedItem("encoded").toElement().text(); } - // Now we obtained maximum of informations for title & description. + // Now we obtained maximum of information for title & description. if (elem_title.isEmpty()) { if (elem_description.isEmpty()) { // BOTH title and description are empty, skip this message. diff --git a/src/core/silentnetworkaccessmanager.cpp b/src/core/silentnetworkaccessmanager.cpp index 750c792f2..d337b97ad 100644 --- a/src/core/silentnetworkaccessmanager.cpp +++ b/src/core/silentnetworkaccessmanager.cpp @@ -24,6 +24,6 @@ void SilentNetworkAccessManager::onAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator) { Q_UNUSED(authenticator) - qDebug("Authentification problems for '%s'.", + qDebug("Autorization problems for '%s'.", qPrintable(reply->url().toString())); } diff --git a/src/core/textfactory.cpp b/src/core/textfactory.cpp index f0d438c96..6a97360a1 100644 --- a/src/core/textfactory.cpp +++ b/src/core/textfactory.cpp @@ -54,11 +54,11 @@ QString TextFactory::stripTags(QString text) { QString TextFactory::escapeHtml(const QString &html) { QMap sequences; - sequences["<"] = "<"; - sequences[">"] = ">"; - sequences["&"] = "&"; - sequences["""] = "\""; - sequences[" "] = " "; + sequences["<"] = '<'; + sequences[">"] = '>'; + sequences["&"] = '&'; + sequences["""] = '\"'; + sequences[" "] = ' '; sequences["±"] = "±"; sequences["×"] = "×"; diff --git a/src/gui/skinfactory.cpp b/src/gui/skinfactory.cpp index 9e36f9752..277b5b88c 100644 --- a/src/gui/skinfactory.cpp +++ b/src/gui/skinfactory.cpp @@ -4,7 +4,6 @@ #include "core/settings.h" #include -#include #include #include #include