Work on ownCloud etc.

This commit is contained in:
Martin Rotter 2016-02-19 13:50:15 +01:00
parent e98172afaa
commit 21597dcc14
8 changed files with 125 additions and 8 deletions

View File

@ -24,6 +24,7 @@ Fixed:
Changed: Changed:
▪ Increased max feed network download timeout to 45 s.
▪ Adjusted behavior of Google suggestions when no suggestions are available for give text. ▪ Adjusted behavior of Google suggestions when no suggestions are available for give text.
▪ Adjusted soěrting, particularly in message list. ▪ Adjusted soěrting, particularly in message list.
▪ Tweaked "remove duplicates" policy. ▪ Tweaked "remove duplicates" policy.

View File

@ -495,8 +495,8 @@ Authors of this application are NOT responsible for lost data.</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>776</width> <width>167</width>
<height>425</height> <height>219</height>
</rect> </rect>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
@ -1404,7 +1404,7 @@ Authors of this application are NOT responsible for lost data.</string>
<number>100</number> <number>100</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>15000</number> <number>45000</number>
</property> </property>
<property name="singleStep"> <property name="singleStep">
<number>100</number> <number>100</number>

View File

@ -21,6 +21,7 @@
#include "network-web/networkfactory.h" #include "network-web/networkfactory.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/settings.h" #include "miscellaneous/settings.h"
#include "miscellaneous/textfactory.h"
#include "services/abstract/rootitem.h" #include "services/abstract/rootitem.h"
#include "services/owncloud/owncloudcategory.h" #include "services/owncloud/owncloudcategory.h"
#include "services/owncloud/owncloudfeed.h" #include "services/owncloud/owncloudfeed.h"
@ -31,7 +32,7 @@
OwnCloudNetworkFactory::OwnCloudNetworkFactory() OwnCloudNetworkFactory::OwnCloudNetworkFactory()
: m_url(QString()), m_forceServerSideUpdate(false), : m_url(QString()), m_forceServerSideUpdate(false),
m_authUsername(QString()), m_authPassword(QString()), m_urlUser(QString()), m_urlStatus(QString()), m_authUsername(QString()), m_authPassword(QString()), m_urlUser(QString()), m_urlStatus(QString()),
m_urlFolders(QString()), m_urlFeeds(QString()), m_userId(QString()) { m_urlFolders(QString()), m_urlFeeds(QString()), m_urlMessages(QString()), m_userId(QString()) {
} }
OwnCloudNetworkFactory::~OwnCloudNetworkFactory() { OwnCloudNetworkFactory::~OwnCloudNetworkFactory() {
@ -57,6 +58,7 @@ void OwnCloudNetworkFactory::setUrl(const QString &url) {
m_urlStatus = working_url + API_PATH + "status"; m_urlStatus = working_url + API_PATH + "status";
m_urlFolders = working_url + API_PATH + "folders"; m_urlFolders = working_url + API_PATH + "folders";
m_urlFeeds = working_url + API_PATH + "feeds"; m_urlFeeds = working_url + API_PATH + "feeds";
m_urlMessages = working_url + API_PATH + "items?id=%1&batchSize=%2&type=%3";
} }
bool OwnCloudNetworkFactory::forceServerSideUpdate() const { bool OwnCloudNetworkFactory::forceServerSideUpdate() const {
@ -159,6 +161,27 @@ OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() {
return OwnCloudGetFeedsCategoriesResponse(content_categories, content_feeds); return OwnCloudGetFeedsCategoriesResponse(content_categories, content_feeds);
} }
OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) {
QString final_url = m_urlMessages.arg(QString::number(feed_id),
QString::number(-1),
QString::number(0));
QByteArray result_raw;
NetworkResult network_reply = NetworkFactory::downloadFile(final_url,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
result_raw,
true, m_authUsername, m_authPassword,
true);
OwnCloudGetMessagesResponse msgs_response(QString::fromUtf8(result_raw));
if (network_reply.first != QNetworkReply::NoError) {
qWarning("ownCloud: Obtaining messages failed with error %d.", network_reply.first);
}
m_lastError = network_reply.first;
return msgs_response;
}
QString OwnCloudNetworkFactory::userId() const { QString OwnCloudNetworkFactory::userId() const {
return m_userId; return m_userId;
} }
@ -312,3 +335,46 @@ RootItem *OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
return parent; return parent;
} }
OwnCloudGetMessagesResponse::OwnCloudGetMessagesResponse(const QString &raw_content) : OwnCloudResponse(raw_content) {
}
OwnCloudGetMessagesResponse::~OwnCloudGetMessagesResponse() {
}
QList<Message> OwnCloudGetMessagesResponse::messages() const {
QList<Message> msgs;
foreach (QVariant message, m_rawContent["items"].toList()) {
QMap<QString,QVariant> message_map = message.toMap();
Message msg;
msg.m_author = message_map["author"].toString();
msg.m_contents = message_map["body"].toString();
msg.m_created = TextFactory::parseDateTime(message_map["pubDate"].value<qint64>());
msg.m_createdFromFeed = true;
msg.m_customId = message_map["id"].toString();
QString enclosure_link = message_map["enclosureLink"].toString();
if (!enclosure_link.isEmpty()) {
Enclosure enclosure;
enclosure.m_mimeType = message_map["enclosureMime"].toString();
enclosure.m_url = enclosure_link;
msg.m_enclosures.append(enclosure);
}
msg.m_feedId = message_map["feedId"].toString();
msg.m_isImportant = message_map["starred"].toBool();
msg.m_isRead = !message_map["unread"].toBool();
msg.m_title = message_map["title"].toString();
msg.m_url = message_map["url"].toString();
msgs.append(msg);
}
return msgs;
}

View File

@ -24,6 +24,7 @@
#include <QNetworkReply> #include <QNetworkReply>
#include "qt-json/json.h" #include "qt-json/json.h"
#include "core/message.h"
class OwnCloudResponse { class OwnCloudResponse {
@ -49,6 +50,14 @@ class OwnCloudUserResponse : public OwnCloudResponse {
QIcon avatar() const; QIcon avatar() const;
}; };
class OwnCloudGetMessagesResponse : public OwnCloudResponse {
public:
explicit OwnCloudGetMessagesResponse(const QString &raw_content = QString());
virtual ~OwnCloudGetMessagesResponse();
QList<Message> messages() const;
};
class OwnCloudStatusResponse : public OwnCloudResponse { class OwnCloudStatusResponse : public OwnCloudResponse {
public: public:
explicit OwnCloudStatusResponse(const QString &raw_content = QString()); explicit OwnCloudStatusResponse(const QString &raw_content = QString());
@ -109,6 +118,9 @@ class OwnCloudNetworkFactory {
// Get feeds & categories (used for sync-in). // Get feeds & categories (used for sync-in).
OwnCloudGetFeedsCategoriesResponse feedsCategories(); OwnCloudGetFeedsCategoriesResponse feedsCategories();
// Get messages for given feed.
OwnCloudGetMessagesResponse getMessages(int feed_id);
private: private:
QString m_url; QString m_url;
bool m_forceServerSideUpdate; bool m_forceServerSideUpdate;
@ -121,6 +133,7 @@ class OwnCloudNetworkFactory {
QString m_urlStatus; QString m_urlStatus;
QString m_urlFolders; QString m_urlFolders;
QString m_urlFeeds; QString m_urlFeeds;
QString m_urlMessages;
QString m_userId; QString m_userId;
}; };

View File

@ -18,6 +18,8 @@
#include "owncloudfeed.h" #include "owncloudfeed.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "services/owncloud/owncloudserviceroot.h"
#include "services/owncloud/network/owncloudnetworkfactory.h"
OwnCloudFeed::OwnCloudFeed(RootItem *parent) : Feed(parent) { OwnCloudFeed::OwnCloudFeed(RootItem *parent) : Feed(parent) {
@ -35,9 +37,37 @@ OwnCloudFeed::OwnCloudFeed(const QSqlRecord &record) : Feed(NULL) {
OwnCloudFeed::~OwnCloudFeed() { OwnCloudFeed::~OwnCloudFeed() {
} }
OwnCloudServiceRoot *OwnCloudFeed::serviceRoot() const {
return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot());
}
int OwnCloudFeed::update() { int OwnCloudFeed::update() {
// TODO: TODO OwnCloudGetMessagesResponse headlines = serviceRoot()->network()->getMessages(customId());
return 0;
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) {
setStatus(Feed::Error);
serviceRoot()->itemChanged(QList<RootItem*>() << this);
return 0;
}
else {
return 0;
// TODO: TODO
// Udělat změnu tuto v tabulkách které mají sloupec custom_id
// Udělat to tak, že custom_id se bude vyplňovat pro všechny
// položky v Feeds, Categories a Messages
// taky tu property budou mít všechny příslušné objekty
// u standardních Feeds, Categories a Message se custom_id == id
//
// toto pak umožní přesunout všechny metody, které budou s custom ID a ID
// pracovat, do třídy předka a ušetřit kód.
//
/*
*UPDATE Categories
SET custom_id = (SELECT id FROM Categories t WHERE t.id = Categories.id)
WHERE Categories.custom_id IS NULL;
*
* //return updateMessages(headlines.messages());
}
} }
int OwnCloudFeed::messageForeignKeyId() const { int OwnCloudFeed::messageForeignKeyId() const {

View File

@ -21,12 +21,15 @@
#include "services/abstract/feed.h" #include "services/abstract/feed.h"
class OwnCloudServiceRoot;
class OwnCloudFeed : public Feed { class OwnCloudFeed : public Feed {
public: public:
explicit OwnCloudFeed(RootItem *parent = NULL); explicit OwnCloudFeed(RootItem *parent = NULL);
explicit OwnCloudFeed(const QSqlRecord &record); explicit OwnCloudFeed(const QSqlRecord &record);
virtual ~OwnCloudFeed(); virtual ~OwnCloudFeed();
OwnCloudServiceRoot *serviceRoot() const;
int update(); int update();
int messageForeignKeyId() const; int messageForeignKeyId() const;
}; };

View File

@ -610,7 +610,11 @@ int StandardFeed::messageForeignKeyId() const {
} }
int StandardFeed::updateMessages(const QList<Message> &messages) { int StandardFeed::updateMessages(const QList<Message> &messages) {
int feed_id = id(); if (messages.isEmpty()) {
return 0;
}
int feed_id = messageForeignKeyId();
int updated_messages = 0; int updated_messages = 0;
bool anything_duplicated = false; bool anything_duplicated = false;
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);

View File

@ -298,7 +298,7 @@ int TtRssFeed::updateMessages(const QList<Message> &messages) {
return 0; return 0;
} }
int feed_id = customId(); int feed_id = messageForeignKeyId();
int updated_messages = 0; int updated_messages = 0;
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
int account_id = serviceRoot()->accountId(); int account_id = serviceRoot()->accountId();