Converted custom IDS of feeds/categories to QString from int - probably broken.

This commit is contained in:
Martin Rotter 2017-09-22 15:17:58 +02:00
parent 3e74e54b8c
commit e289da58fc
24 changed files with 221 additions and 94 deletions

View File

@ -55,6 +55,7 @@
#define RESELECT_MESSAGE_THRESSHOLD 500
#define ICON_SIZE_SETTINGS 16
#define NO_PARENT_CATEGORY -1
#define NO_PARENT_CATEGORY_STR ""
#define ID_RECYCLE_BIN -2
#define TRAY_ICON_BUBBLE_TIMEOUT 20000
#define CLOSE_LOCK_TIMEOUT 500

View File

@ -177,9 +177,9 @@ bool DatabaseQueries::purgeRecycleBin(QSqlDatabase db) {
return q.exec();
}
QMap<int, QPair<int, int>> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
bool including_total_counts, bool* ok) {
QMap<int, QPair<int, int>> counts;
QMap<QString, QPair<int, int>> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, const QString& custom_id, int account_id,
bool including_total_counts, bool* ok) {
QMap<QString, QPair<int, int>> counts;
QSqlQuery q(db);
q.setForwardOnly(true);
@ -200,16 +200,16 @@ QMap<int, QPair<int, int>> DatabaseQueries::getMessageCountsForCategory(QSqlData
if (q.exec()) {
while (q.next()) {
int feed_id = q.value(0).toInt();
QString feed_custom_id = q.value(0).toString();
int unread_count = q.value(1).toInt();
if (including_total_counts) {
int total_count = q.value(2).toInt();
counts.insert(feed_id, QPair<int, int>(unread_count, total_count));
counts.insert(feed_custom_id, QPair<int, int>(unread_count, total_count));
}
else {
counts.insert(feed_id, QPair<int, int>(unread_count, 0));
counts.insert(feed_custom_id, QPair<int, int>(unread_count, 0));
}
}
@ -226,9 +226,9 @@ QMap<int, QPair<int, int>> DatabaseQueries::getMessageCountsForCategory(QSqlData
return counts;
}
QMap<int, QPair<int, int>> DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id,
bool including_total_counts, bool* ok) {
QMap<int, QPair<int, int>> counts;
QMap<QString, QPair<int, int>> DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id,
bool including_total_counts, bool* ok) {
QMap<QString, QPair<int, int>> counts;
QSqlQuery q(db);
q.setForwardOnly(true);
@ -248,7 +248,7 @@ QMap<int, QPair<int, int>> DatabaseQueries::getMessageCountsForAccount(QSqlDatab
if (q.exec()) {
while (q.next()) {
int feed_id = q.value(0).toInt();
QString feed_id = q.value(0).toString();
int unread_count = q.value(1).toInt();
if (including_total_counts) {
@ -274,7 +274,7 @@ QMap<int, QPair<int, int>> DatabaseQueries::getMessageCountsForAccount(QSqlDatab
return counts;
}
int DatabaseQueries::getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id,
int DatabaseQueries::getMessageCountsForFeed(QSqlDatabase db, const QString& feed_custom_id,
int account_id, bool including_total_counts, bool* ok) {
QSqlQuery q(db);
@ -340,7 +340,7 @@ int DatabaseQueries::getMessageCountsForBin(QSqlDatabase db, int account_id, boo
}
}
QList<Message> DatabaseQueries::getUndeletedMessagesForFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool* ok) {
QList<Message> DatabaseQueries::getUndeletedMessagesForFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool* ok) {
QList<Message> messages;
QSqlQuery q(db);
@ -442,7 +442,7 @@ QList<Message> DatabaseQueries::getUndeletedMessagesForAccount(QSqlDatabase db,
int DatabaseQueries::updateMessages(QSqlDatabase db,
const QList<Message>& messages,
int feed_custom_id,
const QString& feed_custom_id,
int account_id,
const QString& url,
bool* any_message_changed,
@ -779,7 +779,7 @@ bool DatabaseQueries::storeAccountTree(QSqlDatabase db, RootItem* tree_root, int
query_category.bindValue(QSL(":parent_id"), child->parent()->id());
query_category.bindValue(QSL(":title"), child->title());
query_category.bindValue(QSL(":account_id"), account_id);
query_category.bindValue(QSL(":custom_id"), QString::number(child->toCategory()->customId()));
query_category.bindValue(QSL(":custom_id"), child->toCategory()->customId());
if (query_category.exec()) {
child->setId(query_category.lastInsertId().toInt());
@ -856,7 +856,7 @@ QStringList DatabaseQueries::customIdsOfMessagesFromBin(QSqlDatabase db, int acc
return ids;
}
QStringList DatabaseQueries::customIdsOfMessagesFromFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool* ok) {
QStringList DatabaseQueries::customIdsOfMessagesFromFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool* ok) {
QSqlQuery q(db);
QStringList ids;

View File

@ -49,26 +49,26 @@ class DatabaseQueries {
static bool purgeLeftoverMessages(QSqlDatabase db, int account_id);
// Obtain counts of unread/all messages.
static QMap<int, QPair<int, int>> getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
bool including_total_counts, bool* ok = nullptr);
static QMap<int, QPair<int, int>> getMessageCountsForAccount(QSqlDatabase db, int account_id,
bool including_total_counts, bool* ok = nullptr);
static int getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, int account_id,
static QMap<QString, QPair<int, int>> getMessageCountsForCategory(QSqlDatabase db, const QString& custom_id, int account_id,
bool including_total_counts, bool* ok = nullptr);
static QMap<QString, QPair<int, int>> getMessageCountsForAccount(QSqlDatabase db, int account_id,
bool including_total_counts, bool* ok = nullptr);
static int getMessageCountsForFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id,
bool including_total_counts, bool* ok = nullptr);
static int getMessageCountsForBin(QSqlDatabase db, int account_id, bool including_total_counts, bool* ok = nullptr);
// Get messages (for newspaper view for example).
static QList<Message> getUndeletedMessagesForFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool* ok = nullptr);
static QList<Message> getUndeletedMessagesForFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool* ok = nullptr);
static QList<Message> getUndeletedMessagesForBin(QSqlDatabase db, int account_id, bool* ok = nullptr);
static QList<Message> getUndeletedMessagesForAccount(QSqlDatabase db, int account_id, bool* ok = nullptr);
// Custom ID accumulators.
static QStringList customIdsOfMessagesFromAccount(QSqlDatabase db, int account_id, bool* ok = nullptr);
static QStringList customIdsOfMessagesFromBin(QSqlDatabase db, int account_id, bool* ok = nullptr);
static QStringList customIdsOfMessagesFromFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool* ok = nullptr);
static QStringList customIdsOfMessagesFromFeed(QSqlDatabase db, const QString& feed_custom_id, int account_id, bool* ok = nullptr);
// Common accounts methods.
static int updateMessages(QSqlDatabase db, const QList<Message>& messages, int feed_custom_id,
static int updateMessages(QSqlDatabase db, const QList<Message>& messages, const QString& feed_custom_id,
int account_id, const QString& url, bool* any_message_changed, bool* ok = nullptr);
static bool deleteAccount(QSqlDatabase db, int account_id);
static bool deleteAccountData(QSqlDatabase db, int account_id, bool delete_messages_too);

View File

@ -36,10 +36,10 @@ Category::Category(RootItem* parent) : RootItem(parent) {
Category::Category(const QSqlRecord& record) : Category(nullptr) {
setId(record.value(CAT_DB_ID_INDEX).toInt());
setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toInt());
setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toString());
if (customId() <= 0) {
setCustomId(id());
if (customId().isEmpty()) {
setCustomId(QString::number(id()));
}
setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
@ -71,11 +71,11 @@ void Category::updateCounts(bool including_total_count) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
bool ok;
QMap<int, QPair<int, int>> counts = DatabaseQueries::getMessageCountsForCategory(database,
customId(),
getParentServiceRoot()->accountId(),
including_total_count,
&ok);
QMap<QString, QPair<int, int>> counts = DatabaseQueries::getMessageCountsForCategory(database,
customId(),
getParentServiceRoot()->accountId(),
including_total_count,
&ok);
if (ok) {
foreach (Feed* feed, feeds) {

View File

@ -252,7 +252,7 @@ int Feed::updateMessages(const QList<Message>& messages, bool error_during_obtai
bool ok = true;
if (!messages.isEmpty()) {
int custom_id = customId();
QString custom_id = customId();
int account_id = getParentServiceRoot()->accountId();
QSqlDatabase database = is_main_thread ?
qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings) :

View File

@ -30,7 +30,7 @@ RootItem::RootItem(RootItem* parent_item)
: QObject(nullptr),
m_kind(RootItemKind::Root),
m_id(NO_PARENT_CATEGORY),
m_customId(NO_PARENT_CATEGORY),
m_customId(QSL(NO_PARENT_CATEGORY_STR)),
m_title(QString()),
m_description(QString()),
m_icon(QIcon()),
@ -317,8 +317,8 @@ QHash<int, Category*> RootItem::getHashedSubTreeCategories() const {
while (!traversable_items.isEmpty()) {
RootItem* active_item = traversable_items.takeFirst();
if (active_item->kind() == RootItemKind::Category && !children.contains(active_item->customId())) {
children.insert(active_item->customId(), active_item->toCategory());
if (active_item->kind() == RootItemKind::Category && !children.contains(active_item->id())) {
children.insert(active_item->id(), active_item->toCategory());
}
traversable_items.append(active_item->childItems());
@ -327,8 +327,8 @@ QHash<int, Category*> RootItem::getHashedSubTreeCategories() const {
return children;
}
QHash<int, Feed*> RootItem::getHashedSubTreeFeeds() const {
QHash<int, Feed*> children;
QHash<QString, Feed*> RootItem::getHashedSubTreeFeeds() const {
QHash<QString, Feed*> children;
QList<RootItem*> traversable_items;
traversable_items.append(const_cast<RootItem* const>(this));
@ -448,11 +448,11 @@ bool RootItem::removeChild(RootItem* child) {
return m_childItems.removeOne(child);
}
int RootItem::customId() const {
QString RootItem::customId() const {
return m_customId;
}
void RootItem::setCustomId(int custom_id) {
void RootItem::setCustomId(const QString& custom_id) {
m_customId = custom_id;
}

View File

@ -175,7 +175,7 @@ class RootItem : public QObject {
QList<RootItem*> getSubTree(RootItemKind::Kind kind_of_item) const;
QList<Category*> getSubTreeCategories() const;
QHash<int, Category*> getHashedSubTreeCategories() const;
QHash<int, Feed*> getHashedSubTreeFeeds() const;
QHash<QString, Feed*> getHashedSubTreeFeeds() const;
QList<Feed*> getSubTreeFeeds() const;
// Returns the service root node which is direct or indirect parent of current item.
@ -210,8 +210,8 @@ class RootItem : public QObject {
void setBoldFont(const QFont& bold_font);
// NOTE: For standard feed/category, this WILL equal to id().
int customId() const;
void setCustomId(int custom_id);
QString customId() const;
void setCustomId(const QString& custom_id);
// Converters
Category* toCategory() const;
@ -223,7 +223,7 @@ class RootItem : public QObject {
RootItemKind::Kind m_kind;
int m_id;
int m_customId;
QString m_customId;
QString m_title;
QString m_description;
QIcon m_icon;

View File

@ -104,7 +104,7 @@ void ServiceRoot::updateCounts(bool including_total_count) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
bool ok;
QMap<int, QPair<int, int>> counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok);
QMap<QString, QPair<int, int>> counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok);
if (ok) {
foreach (Feed* feed, feeds) {
@ -229,8 +229,8 @@ void ServiceRoot::requestItemRemoval(RootItem* item) {
emit itemRemovalRequested(item);
}
QMap<int, QVariant> ServiceRoot::storeCustomFeedsData() {
QMap<int, QVariant> custom_data;
QMap<QString, QVariant> ServiceRoot::storeCustomFeedsData() {
QMap<QString, QVariant> custom_data;
foreach (const Feed* feed, getSubTreeFeeds()) {
QVariantMap feed_custom_data;
@ -243,12 +243,12 @@ QMap<int, QVariant> ServiceRoot::storeCustomFeedsData() {
return custom_data;
}
void ServiceRoot::restoreCustomFeedsData(const QMap<int, QVariant>& data, const QHash<int, Feed*>& feeds) {
QMapIterator<int, QVariant> i(data);
void ServiceRoot::restoreCustomFeedsData(const QMap<QString, QVariant>& data, const QHash<QString, Feed*>& feeds) {
QMapIterator<QString, QVariant> i(data);
while (i.hasNext()) {
i.next();
const int custom_id = i.key();
const QString custom_id = i.key();
if (feeds.contains(custom_id)) {
Feed* feed = feeds.value(custom_id);
@ -270,7 +270,7 @@ void ServiceRoot::syncIn() {
if (new_tree != nullptr) {
// Purge old data from SQL and clean all model items.
requestItemExpandStateSave(this);
QMap<int, QVariant> feed_custom_data = storeCustomFeedsData();
QMap<QString, QVariant> feed_custom_data = storeCustomFeedsData();
removeOldFeedTree(false);
cleanAllItems();
restoreCustomFeedsData(feed_custom_data, new_tree->getHashedSubTreeFeeds());
@ -392,7 +392,7 @@ QStringList ServiceRoot::textualFeedIds(const QList<Feed*>& feeds) const {
stringy_ids.reserve(feeds.size());
foreach (const Feed* feed, feeds) {
stringy_ids.append(QString("'%1'").arg(QString::number(feed->customId())));
stringy_ids.append(QString("'%1'").arg(feed->customId()));
}
return stringy_ids;

View File

@ -203,8 +203,8 @@ class ServiceRoot : public RootItem {
void itemRemovalRequested(RootItem* item);
private:
virtual QMap<int, QVariant> storeCustomFeedsData();
virtual void restoreCustomFeedsData(const QMap<int, QVariant>& data, const QHash<int, Feed*>& feeds);
virtual QMap<QString, QVariant> storeCustomFeedsData();
virtual void restoreCustomFeedsData(const QMap<QString, QVariant>& data, const QHash<QString, Feed*>& feeds);
private:
RecycleBin* m_recycleBin;

View File

@ -30,4 +30,7 @@
#define INOREADER_DEFAULT_BATCH_SIZE -1
#define INOREADER_UNLIMITED_BATCH_SIZE -1
#define INOREADER_API_LIST_LABELS "https://www.inoreader.com/reader/api/0/tag/list"
#define INOREADER_API_LIST_FEEDS "https://www.inoreader.com/reader/api/0/subscription/list"
#endif // INOREADER_DEFINITIONS_H

View File

@ -21,13 +21,14 @@
#include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h"
#include "miscellaneous/iconfactory.h"
#include "services/inoreader/gui/formeditinoreaderaccount.h"
#include "services/inoreader/inoreaderentrypoint.h"
#include "services/inoreader/network/inoreadernetworkfactory.h"
InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, RootItem* parent) : ServiceRoot(parent),
m_network(network) {
if (m_network == nullptr) {
m_serviceMenu(QList<QAction*>()), m_network(network) {
if (network == nullptr) {
m_network = new InoreaderNetworkFactory(this);
}
else {
@ -89,14 +90,36 @@ bool InoreaderServiceRoot::supportsCategoryAdding() const {
return false;
}
void InoreaderServiceRoot::start(bool freshly_activated) {}
void InoreaderServiceRoot::start(bool freshly_activated) {
Q_UNUSED(freshly_activated)
//loadFromDatabase();
//loadCacheFromFile(accountId());
m_network->logInIfNeeded();
}
void InoreaderServiceRoot::stop() {}
QList<QAction*> InoreaderServiceRoot::serviceMenu() {
if (m_serviceMenu.isEmpty()) {
QAction* act_sync_in = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Sync in"), this);
connect(act_sync_in, &QAction::triggered, this, &InoreaderServiceRoot::syncIn);
m_serviceMenu.append(act_sync_in);
}
return m_serviceMenu;
}
QString InoreaderServiceRoot::code() const {
return InoreaderEntryPoint().code();
}
RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const {
return m_network->feedsCategories(true);
}
void InoreaderServiceRoot::addNewFeed(const QString& url) {}
void InoreaderServiceRoot::addNewCategory() {}

View File

@ -44,12 +44,18 @@ class InoreaderServiceRoot : public ServiceRoot {
void stop();
QString code() const;
RootItem* obtainNewTreeForSyncIn() const;
public slots:
void addNewFeed(const QString& url);
void addNewCategory();
void updateTitle();
protected:
QList<QAction*> serviceMenu();
private:
QList<QAction*> m_serviceMenu;
InoreaderNetworkFactory* m_network;
};

View File

@ -24,13 +24,19 @@
#include "miscellaneous/application.h"
#include "network-web/silentnetworkaccessmanager.h"
#include "network-web/webfactory.h"
#include "services/abstract/category.h"
#include "services/inoreader/definitions.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QOAuth2AuthorizationCodeFlow>
#include <QOAuthHttpServerReplyHandler>
#include <QUrl>
InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent),
m_batchSize(INOREADER_DEFAULT_BATCH_SIZE), m_oauth2(new QOAuth2AuthorizationCodeFlow(this)) {
m_username(QString()), m_refreshToken(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE),
m_oauth2(new QOAuth2AuthorizationCodeFlow(this)) {
initializeOauth();
}
@ -127,6 +133,93 @@ void InoreaderNetworkFactory::setRefreshToken(const QString& refreshToken) {
m_refreshToken = refreshToken;
}
RootItem* InoreaderNetworkFactory::feedsCategories(bool obtain_icons) {
RootItem* parent = new RootItem();
QMap<QString, RootItem*> cats;
cats.insert(NO_PARENT_CATEGORY_STR, parent);
QNetworkReply* reply = m_oauth2->get(QUrl(INOREADER_API_LIST_LABELS));
QEventLoop loop;
RootItem* result = nullptr;
connect(reply, &QNetworkReply::finished, [&, this]() {
if (reply->error() == QNetworkReply::NoError) {
QByteArray repl_data = reply->readAll();
QJsonArray json = QJsonDocument::fromJson(repl_data).object()["tags"].toArray();
foreach (const QJsonValue& obj, json) {
auto label = obj.toObject();
QString label_id = label["id"].toString();
if (label_id.contains(QSL("/label/"))) {
// We have label (not "state").
Category* category = new Category();
category->setTitle(label_id.mid(label_id.lastIndexOf(QL1C('/')) + 1));
category->setCustomId(label_id);
cats.insert(category->customId(), category);
// All categories in ownCloud are top-level.
parent->appendChild(category);
}
}
}
loop.exit();
});
loop.exec();
return result;
/*
// Process categories first, then process feeds.
foreach (const QJsonValue& cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) {
QJsonObject item = cat.toObject();
Category* category = new Category();
category->setTitle(item["name"].toString());
category->setCustomId(item["id"].toInt());
cats.insert(category->customId(), category);
// All categories in ownCloud are top-level.
parent->appendChild(category);
}*/
/*
// We have categories added, now add all feeds.
foreach (const QJsonValue& fed, QJsonDocument::fromJson(m_contentFeeds.toUtf8()).object()["feeds"].toArray()) {
QJsonObject item = fed.toObject();
OwnCloudFeed* feed = new OwnCloudFeed();
if (obtain_icons) {
QString icon_path = item["faviconLink"].toString();
if (!icon_path.isEmpty()) {
QByteArray icon_data;
if (NetworkFactory::performNetworkOperation(icon_path, DOWNLOAD_TIMEOUT,
QByteArray(), QString(), icon_data,
QNetworkAccessManager::GetOperation).first ==
QNetworkReply::NoError) {
// Icon downloaded, set it up.
QPixmap icon_pixmap;
icon_pixmap.loadFromData(icon_data);
feed->setIcon(QIcon(icon_pixmap));
}
}
}
feed->setUrl(item["link"].toString());
feed->setTitle(item["title"].toString());
feed->setCustomId(item["id"].toInt());
qDebug("Custom ID of next fetched Nextcloud feed is '%d'.", item["id"].toInt());
cats.value(item["folderId"].toInt())->appendChild(feed);
}*/
}
void InoreaderNetworkFactory::setAccessToken(const QString& accessToken) {
m_oauth2->setToken(accessToken);
}

View File

@ -21,7 +21,10 @@
#include <QObject>
#include <QOAuth2AuthorizationCodeFlow>
#include <QNetworkReply>
class RootItem;
class QOAuth2AuthorizationCodeFlow;
class InoreaderNetworkFactory : public QObject {
Q_OBJECT
@ -43,6 +46,11 @@ class InoreaderNetworkFactory : public QObject {
void setAccessToken(const QString& accessToken);
void setRefreshToken(const QString& refreshToken);
// Returns tree of feeds/categories.
// Top-level root of the tree is not needed here.
// Returned items do not have primary IDs assigned.
RootItem* feedsCategories(bool obtain_icons);
public slots:
void logIn();
void logInIfNeeded();
@ -59,9 +67,9 @@ class InoreaderNetworkFactory : public QObject {
void initializeOauth();
private:
int m_batchSize;
QString m_username;
QString m_refreshToken;
int m_batchSize;
QOAuth2AuthorizationCodeFlow* m_oauth2;
};

View File

@ -68,7 +68,7 @@ void FormOwnCloudFeedDetails::apply() {
else {
const RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(
m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
const int category_id = parent->kind() == RootItemKind::ServiceRoot ? 0 : parent->customId();
const int category_id = parent->kind() == RootItemKind::ServiceRoot ? 0 : parent->customId().toInt();
const bool response = qobject_cast<OwnCloudServiceRoot*>(m_serviceRoot)->network()->createFeed(m_ui->m_txtUrl->lineEdit()->text(),
category_id);

View File

@ -173,8 +173,8 @@ OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() {
return OwnCloudGetFeedsCategoriesResponse(content_categories, content_feeds);
}
bool OwnCloudNetworkFactory::deleteFeed(int feed_id) {
QString final_url = m_urlDeleteFeed.arg(QString::number(feed_id));
bool OwnCloudNetworkFactory::deleteFeed(const QString& feed_id) {
QString final_url = m_urlDeleteFeed.arg(feed_id);
QByteArray raw_output;
NetworkResult network_reply = NetworkFactory::performNetworkOperation(final_url,
qApp->settings()->value(GROUP(Feeds),
@ -221,8 +221,8 @@ bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) {
}
}
bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, int feed_id) {
QString final_url = m_urlRenameFeed.arg(QString::number(feed_id));
bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, const QString& custom_feed_id) {
QString final_url = m_urlRenameFeed.arg(custom_feed_id);
QByteArray result_raw;
QJsonObject json;
@ -230,8 +230,7 @@ bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, int feed_id) {
NetworkResult network_reply = NetworkFactory::performNetworkOperation(
final_url,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(),
QJsonDocument(json).toJson(QJsonDocument::Compact),
QSL("application/json"), result_raw,
QNetworkAccessManager::PutOperation,
@ -480,8 +479,8 @@ OwnCloudGetFeedsCategoriesResponse::~OwnCloudGetFeedsCategoriesResponse() {}
RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons) const {
RootItem* parent = new RootItem();
QMap<int, RootItem*>cats;
cats.insert(0, parent);
QMap<QString, RootItem*>cats;
cats.insert(NO_PARENT_CATEGORY_STR, parent);
// Process categories first, then process feeds.
foreach (const QJsonValue& cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) {
@ -489,7 +488,7 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
Category* category = new Category();
category->setTitle(item["name"].toString());
category->setCustomId(item["id"].toInt());
category->setCustomId(item["id"].toString());
cats.insert(category->customId(), category);
// All categories in ownCloud are top-level.
@ -522,9 +521,9 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
feed->setUrl(item["link"].toString());
feed->setTitle(item["title"].toString());
feed->setCustomId(item["id"].toInt());
feed->setCustomId(item["id"].toString());
qDebug("Custom ID of next fetched Nextcloud feed is '%d'.", item["id"].toInt());
cats.value(item["folderId"].toInt())->appendChild(feed);
cats.value(item["folderId"].toString())->appendChild(feed);
}
return parent;

View File

@ -120,9 +120,9 @@ class OwnCloudNetworkFactory {
OwnCloudGetFeedsCategoriesResponse feedsCategories();
// Feed operations.
bool deleteFeed(int feed_id);
bool deleteFeed(const QString& feed_id);
bool createFeed(const QString& url, int parent_id);
bool renameFeed(const QString& new_name, int feed_id);
bool renameFeed(const QString& new_name, const QString& custom_feed_id);
// Get messages for given feed.
OwnCloudGetMessagesResponse getMessages(int feed_id);

View File

@ -34,7 +34,7 @@ OwnCloudFeed::OwnCloudFeed(const QSqlRecord& record) : Feed(nullptr) {
setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
setAutoUpdateType(static_cast<Feed::AutoUpdateType>(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt()));
setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt());
setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toInt());
setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toString());
qDebug("Custom ID of Nextcloud feed when loading from DB is '%s'.", qPrintable(record.value(FDS_DB_CUSTOM_ID_INDEX).toString()));
}
@ -83,7 +83,7 @@ bool OwnCloudFeed::editItself(OwnCloudFeed* new_feed_data) {
bool OwnCloudFeed::removeItself() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
return DatabaseQueries::deleteFeed(database, customId(), serviceRoot()->accountId());
return DatabaseQueries::deleteFeed(database, customId().toInt(), serviceRoot()->accountId());
}
OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const {
@ -91,7 +91,7 @@ OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const {
}
QList<Message> OwnCloudFeed::obtainNewMessages(bool* error_during_obtaining) {
OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customId());
OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customId().toInt());
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) {
setStatus(Feed::NetworkError);

View File

@ -89,7 +89,7 @@ void OwnCloudServiceRoot::start(bool freshly_activated) {
loadFromDatabase();
loadCacheFromFile(accountId());
if (qApp->isFirstRun(QSL("3.1.1")) || (childCount() == 1 && child(0)->kind() == RootItemKind::Bin)) {
if (childCount() <= 1) {
syncIn();
}
}
@ -180,12 +180,6 @@ bool OwnCloudServiceRoot::onBeforeSwitchMessageImportance(RootItem* selected_ite
}
void OwnCloudServiceRoot::updateTitle() {
QString host = QUrl(m_network->url()).host();
if (host.isEmpty()) {
host = m_network->url();
}
setTitle(m_network->authUsername() + QSL(" (Nextcloud News)"));
}

View File

@ -148,7 +148,7 @@ bool StandardCategory::addItself(RootItem* parent) {
}
else {
setId(new_id);
setCustomId(new_id);
setCustomId(QString::number(new_id));
return true;
}
}

View File

@ -323,7 +323,7 @@ bool StandardFeed::performDragDropChange(RootItem* target_item) {
bool StandardFeed::removeItself() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
return DatabaseQueries::deleteFeed(database, customId(), getParentServiceRoot()->accountId());
return DatabaseQueries::deleteFeed(database, customId().toInt(), getParentServiceRoot()->accountId());
}
bool StandardFeed::addItself(RootItem* parent) {
@ -341,7 +341,7 @@ bool StandardFeed::addItself(RootItem* parent) {
else {
// New feed was added, fetch is primary id from the database.
setId(new_id);
setCustomId(new_id);
setCustomId(QString::number(new_id));
return true;
}
}
@ -441,7 +441,7 @@ QNetworkReply::NetworkError StandardFeed::networkError() const {
StandardFeed::StandardFeed(const QSqlRecord& record) : Feed(nullptr) {
setTitle(QString::fromUtf8(record.value(FDS_DB_TITLE_INDEX).toByteArray()));
setId(record.value(FDS_DB_ID_INDEX).toInt());
setCustomId(id());
setCustomId(QString::number(id()));
setDescription(QString::fromUtf8(record.value(FDS_DB_DESCRIPTION_INDEX).toByteArray()));
setCreationDate(TextFactory::parseDateTime(record.value(FDS_DB_DCREATED_INDEX).value<qint64>()).toLocalTime());
setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));

View File

@ -55,7 +55,7 @@ void FormTtRssFeedDetails::apply() {
TtRssServiceRoot* root = qobject_cast<TtRssServiceRoot*>(parent->getParentServiceRoot());
const int category_id = parent->kind() == RootItemKind::ServiceRoot ?
0 :
parent->customId();
parent->customId().toInt();
const TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(m_ui->m_txtUrl->lineEdit()->text(),
category_id,
m_ui->m_gbAuthentication->isChecked(),

View File

@ -505,7 +505,7 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
Category* category = new Category();
category->setTitle(item["name"].toString());
category->setCustomId(item_id);
category->setCustomId(QString::number(item_id));
act_parent->appendChild(category);
if (item.contains("items")) {
@ -540,7 +540,7 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
}
feed->setTitle(item["name"].toString());
feed->setCustomId(item_id);
feed->setCustomId(QString::number(item_id));
act_parent->appendChild(feed);
}
}

View File

@ -39,7 +39,7 @@ TtRssFeed::TtRssFeed(const QSqlRecord& record) : Feed(nullptr) {
setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
setAutoUpdateType(static_cast<Feed::AutoUpdateType>(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt()));
setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt());
setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toInt());
setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toString());
qDebug("Custom ID of TT-RSS feed when loading from DB is '%s'.", qPrintable(record.value(FDS_DB_CUSTOM_ID_INDEX).toString()));
}
@ -65,7 +65,7 @@ bool TtRssFeed::canBeDeleted() const {
}
bool TtRssFeed::deleteViaGui() {
TtRssUnsubscribeFeedResponse response = serviceRoot()->network()->unsubscribeFeed(customId());
TtRssUnsubscribeFeedResponse response = serviceRoot()->network()->unsubscribeFeed(customId().toInt());
if (response.code() == UFF_OK && removeItself()) {
serviceRoot()->requestItemRemoval(this);
@ -98,7 +98,7 @@ QList<Message> TtRssFeed::obtainNewMessages(bool* error_during_obtaining) {
int skip = 0;
do {
TtRssGetHeadlinesResponse headlines = serviceRoot()->network()->getHeadlines(customId(), limit, skip,
TtRssGetHeadlinesResponse headlines = serviceRoot()->network()->getHeadlines(customId().toInt(), limit, skip,
true, true, false);
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) {
@ -123,5 +123,5 @@ QList<Message> TtRssFeed::obtainNewMessages(bool* error_during_obtaining) {
bool TtRssFeed::removeItself() {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
return DatabaseQueries::deleteFeed(database, customId(), serviceRoot()->accountId());
return DatabaseQueries::deleteFeed(database, customId().toInt(), serviceRoot()->accountId());
}