mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-01 02:48:05 +01:00
Finalized SQL refactoring.
This commit is contained in:
parent
73241e4bb7
commit
a822d6b8c6
@ -25,6 +25,10 @@
|
||||
#include "services/standard/standardserviceroot.h"
|
||||
#include "services/standard/standardcategory.h"
|
||||
#include "services/standard/standardfeed.h"
|
||||
#include "services/tt-rss/ttrssserviceroot.h"
|
||||
#include "services/tt-rss/ttrsscategory.h"
|
||||
#include "services/tt-rss/ttrssfeed.h"
|
||||
#include "services/tt-rss/network/ttrssnetworkfactory.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
@ -823,6 +827,42 @@ QList<ServiceRoot*> DatabaseQueries::getOwnCloudAccounts(QSqlDatabase db, bool *
|
||||
return roots;
|
||||
}
|
||||
|
||||
QList<ServiceRoot*> DatabaseQueries::getTtRssAccounts(QSqlDatabase db, bool *ok) {
|
||||
QSqlQuery query(db);
|
||||
QList<ServiceRoot*> roots;
|
||||
|
||||
if (query.exec("SELECT * FROM TtRssAccounts;")) {
|
||||
while (query.next()) {
|
||||
TtRssServiceRoot *root = new TtRssServiceRoot();
|
||||
root->setId(query.value(0).toInt());
|
||||
root->setAccountId(query.value(0).toInt());
|
||||
root->network()->setUsername(query.value(1).toString());
|
||||
root->network()->setPassword(TextFactory::decrypt(query.value(2).toString()));
|
||||
root->network()->setAuthIsUsed(query.value(3).toBool());
|
||||
root->network()->setAuthUsername(query.value(4).toString());
|
||||
root->network()->setAuthPassword(TextFactory::decrypt(query.value(5).toString()));
|
||||
root->network()->setUrl(query.value(6).toString());
|
||||
root->network()->setForceServerSideUpdate(query.value(7).toBool());
|
||||
|
||||
root->updateTitle();
|
||||
roots.append(root);
|
||||
}
|
||||
|
||||
if (ok != NULL) {
|
||||
*ok = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
qWarning("TT-RSS: Getting list of activated accounts failed: '%s'.", qPrintable(query.lastError().text()));
|
||||
|
||||
if (ok != NULL) {
|
||||
*ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
return roots;
|
||||
}
|
||||
|
||||
bool DatabaseQueries::deleteOwnCloudAccount(QSqlDatabase db, int account_id) {
|
||||
QSqlQuery q(db);
|
||||
|
||||
@ -1164,6 +1204,22 @@ bool DatabaseQueries::editFeed(QSqlDatabase db, int parent_id, int feed_id, cons
|
||||
return q.exec();
|
||||
}
|
||||
|
||||
bool DatabaseQueries::editBaseFeed(QSqlDatabase db, int feed_id, Feed::AutoUpdateType auto_update_type,
|
||||
int auto_update_interval) {
|
||||
QSqlQuery q(db);
|
||||
|
||||
q.setForwardOnly(true);
|
||||
q.prepare("UPDATE Feeds "
|
||||
"SET update_type = :update_type, update_interval = :update_interval "
|
||||
"WHERE id = :id;");
|
||||
|
||||
q.bindValue(QSL(":update_type"), (int) auto_update_type);
|
||||
q.bindValue(QSL(":update_interval"), auto_update_interval);
|
||||
q.bindValue(QSL(":id"), feed_id);
|
||||
|
||||
return q.exec();
|
||||
}
|
||||
|
||||
QList<ServiceRoot*> DatabaseQueries::getAccounts(QSqlDatabase db, bool *ok) {
|
||||
QSqlQuery q(db);
|
||||
QList<ServiceRoot*> roots;
|
||||
@ -1209,9 +1265,10 @@ Assignment DatabaseQueries::getCategories(QSqlDatabase db, int account_id, bool
|
||||
*ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok != NULL) {
|
||||
*ok = true;
|
||||
else {
|
||||
if (ok != NULL) {
|
||||
*ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
while (q.next()) {
|
||||
@ -1272,5 +1329,136 @@ Assignment DatabaseQueries::getFeeds(QSqlDatabase db, int account_id, bool *ok)
|
||||
return feeds;
|
||||
}
|
||||
|
||||
bool DatabaseQueries::deleteTtRssAccount(QSqlDatabase db, int account_id) {
|
||||
QSqlQuery q(db);
|
||||
|
||||
q.setForwardOnly(true);
|
||||
q.prepare(QSL("DELETE FROM TtRssAccounts WHERE id = :id;"));
|
||||
q.bindValue(QSL(":id"), account_id);
|
||||
|
||||
// Remove extra entry in "Tiny Tiny RSS accounts list" and then delete
|
||||
// all the categories/feeds and messages.
|
||||
return q.exec();
|
||||
}
|
||||
|
||||
bool DatabaseQueries::overwriteTtRssAccount(QSqlDatabase db, const QString &username, const QString &password,
|
||||
bool auth_protected, const QString &auth_username, const QString &auth_password,
|
||||
const QString &url, bool force_server_side_feed_update, int account_id) {
|
||||
QSqlQuery q(db);
|
||||
|
||||
q.prepare("UPDATE TtRssAccounts "
|
||||
"SET username = :username, password = :password, url = :url, auth_protected = :auth_protected, "
|
||||
"auth_username = :auth_username, auth_password = :auth_password, force_update = :force_update "
|
||||
"WHERE id = :id;");
|
||||
q.bindValue(QSL(":username"), username);
|
||||
q.bindValue(QSL(":password"), TextFactory::encrypt(password));
|
||||
q.bindValue(QSL(":url"), url);
|
||||
q.bindValue(QSL(":auth_protected"), auth_protected ? 1 : 0);
|
||||
q.bindValue(QSL(":auth_username"), auth_username);
|
||||
q.bindValue(QSL(":auth_password"), TextFactory::encrypt(auth_password));
|
||||
q.bindValue(QSL(":force_update"), force_server_side_feed_update ? 1 : 0);
|
||||
q.bindValue(QSL(":id"), account_id);
|
||||
|
||||
if (q.exec()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
qWarning("TT-RSS: Updating account failed: '%s'.", qPrintable(q.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DatabaseQueries::createTtRssAccount(QSqlDatabase db, int id_to_assign, const QString &username,
|
||||
const QString &password, bool auth_protected, const QString &auth_username,
|
||||
const QString &auth_password, const QString &url,
|
||||
bool force_server_side_feed_update) {
|
||||
QSqlQuery q(db);
|
||||
|
||||
q.prepare("INSERT INTO TtRssAccounts (id, username, password, auth_protected, auth_username, auth_password, url, force_update) "
|
||||
"VALUES (:id, :username, :password, :auth_protected, :auth_username, :auth_password, :url, :force_update);");
|
||||
q.bindValue(QSL(":id"), id_to_assign);
|
||||
q.bindValue(QSL(":username"), username);
|
||||
q.bindValue(QSL(":password"), TextFactory::encrypt(password));
|
||||
q.bindValue(QSL(":auth_protected"), auth_protected ? 1 : 0);
|
||||
q.bindValue(QSL(":auth_username"), auth_username);
|
||||
q.bindValue(QSL(":auth_password"), TextFactory::encrypt(auth_password));
|
||||
q.bindValue(QSL(":url"), url);
|
||||
q.bindValue(QSL(":force_update"), force_server_side_feed_update ? 1 : 0);
|
||||
|
||||
if (q.exec()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
qWarning("TT-RSS: Saving of new account failed: '%s'.", qPrintable(q.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Assignment DatabaseQueries::getTtRssCategories(QSqlDatabase db, int account_id, bool *ok) {
|
||||
Assignment categories;
|
||||
|
||||
// Obtain data for categories from the database.
|
||||
QSqlQuery query_categories(db);
|
||||
query_categories.setForwardOnly(true);
|
||||
query_categories.prepare(QSL("SELECT * FROM Categories WHERE account_id = :account_id;"));
|
||||
query_categories.bindValue(QSL(":account_id"), account_id);
|
||||
|
||||
if (!query_categories.exec()) {
|
||||
qFatal("Query for obtaining categories failed. Error message: '%s'.", qPrintable(query_categories.lastError().text()));
|
||||
|
||||
if (ok != NULL) {
|
||||
*ok = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ok != NULL) {
|
||||
*ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
while (query_categories.next()) {
|
||||
AssignmentItem pair;
|
||||
pair.first = query_categories.value(CAT_DB_PARENT_ID_INDEX).toInt();
|
||||
pair.second = new TtRssCategory(query_categories.record());
|
||||
|
||||
categories << pair;
|
||||
}
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
Assignment DatabaseQueries::getTtRssFeeds(QSqlDatabase db, int account_id, bool *ok) {
|
||||
Assignment feeds;
|
||||
|
||||
// All categories are now loaded.
|
||||
QSqlQuery query_feeds(db);
|
||||
query_feeds.setForwardOnly(true);
|
||||
query_feeds.prepare(QSL("SELECT * FROM Feeds WHERE account_id = :account_id;"));
|
||||
query_feeds.bindValue(QSL(":account_id"), account_id);
|
||||
|
||||
if (!query_feeds.exec()) {
|
||||
qFatal("Query for obtaining feeds failed. Error message: '%s'.", qPrintable(query_feeds.lastError().text()));
|
||||
|
||||
if (ok != NULL) {
|
||||
*ok = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ok != NULL) {
|
||||
*ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
while (query_feeds.next()) {
|
||||
AssignmentItem pair;
|
||||
pair.first = query_feeds.value(FDS_DB_CATEGORY_INDEX).toInt();
|
||||
pair.second = new TtRssFeed(query_feeds.record());
|
||||
|
||||
feeds << pair;
|
||||
}
|
||||
|
||||
return feeds;
|
||||
}
|
||||
|
||||
DatabaseQueries::DatabaseQueries() {
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ class DatabaseQueries {
|
||||
static QStringList customIdsOfMessagesFromBin(QSqlDatabase db, int account_id, bool *ok = NULL);
|
||||
static QStringList customIdsOfMessagesFromFeed(QSqlDatabase db, int feed_custom_id, int account_id, bool *ok = NULL);
|
||||
static QList<ServiceRoot*> getOwnCloudAccounts(QSqlDatabase db, bool *ok = NULL);
|
||||
static QList<ServiceRoot*> getTtRssAccounts(QSqlDatabase db, bool *ok = NULL);
|
||||
static bool deleteOwnCloudAccount(QSqlDatabase db, int account_id);
|
||||
static bool overwriteOwnCloudAccount(QSqlDatabase db, const QString &username, const QString &password,
|
||||
const QString &url, bool force_server_side_feed_update, int account_id);
|
||||
@ -76,19 +77,31 @@ class DatabaseQueries {
|
||||
static bool editCategory(QSqlDatabase db, int parent_id, int category_id,
|
||||
const QString &title, const QString &description, const QIcon &icon);
|
||||
static int addFeed(QSqlDatabase db, int parent_id, int account_id, const QString &title,
|
||||
const QString &description, QDateTime creation_date, const QIcon &icon,
|
||||
const QString &encoding, const QString &url, bool is_protected,
|
||||
const QString &username, const QString &password,
|
||||
Feed::AutoUpdateType auto_update_type,
|
||||
int auto_update_interval, StandardFeed::Type feed_format, bool *ok = NULL);
|
||||
const QString &description, QDateTime creation_date, const QIcon &icon,
|
||||
const QString &encoding, const QString &url, bool is_protected,
|
||||
const QString &username, const QString &password,
|
||||
Feed::AutoUpdateType auto_update_type,
|
||||
int auto_update_interval, StandardFeed::Type feed_format, bool *ok = NULL);
|
||||
static bool editFeed(QSqlDatabase db, int parent_id, int feed_id, const QString &title,
|
||||
const QString &description, const QIcon &icon,
|
||||
const QString &encoding, const QString &url, bool is_protected,
|
||||
const QString &username, const QString &password, Feed::AutoUpdateType auto_update_type,
|
||||
int auto_update_interval, StandardFeed::Type feed_format);
|
||||
static bool editBaseFeed(QSqlDatabase db, int feed_id, Feed::AutoUpdateType auto_update_type,
|
||||
int auto_update_interval);
|
||||
static QList<ServiceRoot*> getAccounts(QSqlDatabase db, bool *ok = NULL);
|
||||
static Assignment getCategories(QSqlDatabase db, int account_id, bool *ok = NULL);
|
||||
static Assignment getFeeds(QSqlDatabase db, int account_id, bool *ok = NULL);
|
||||
static bool deleteTtRssAccount(QSqlDatabase db, int account_id);
|
||||
static bool overwriteTtRssAccount(QSqlDatabase db, const QString &username, const QString &password,
|
||||
bool auth_protected, const QString &auth_username, const QString &auth_password,
|
||||
const QString &url, bool force_server_side_feed_update, int account_id);
|
||||
static bool createTtRssAccount(QSqlDatabase db, int id_to_assign, const QString &username,
|
||||
const QString &password, bool auth_protected, const QString &auth_username,
|
||||
const QString &auth_password, const QString &url,
|
||||
bool force_server_side_feed_update);
|
||||
static Assignment getTtRssCategories(QSqlDatabase db, int account_id, bool *ok = NULL);
|
||||
static Assignment getTtRssFeeds(QSqlDatabase db, int account_id, bool *ok = NULL);
|
||||
|
||||
private:
|
||||
explicit DatabaseQueries();
|
||||
|
@ -168,10 +168,9 @@ void OwnCloudServiceRoot::updateTitle() {
|
||||
}
|
||||
|
||||
void OwnCloudServiceRoot::saveAccountDataToDatabase() {
|
||||
if (accountId() != NO_PARENT_CATEGORY) {
|
||||
// We are overwritting previously saved data.
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
if (accountId() != NO_PARENT_CATEGORY) {
|
||||
if (DatabaseQueries::overwriteOwnCloudAccount(database, m_network->authUsername(),
|
||||
m_network->authPassword(), m_network->url(),
|
||||
m_network->forceServerSideUpdate(), accountId())) {
|
||||
@ -180,8 +179,6 @@ void OwnCloudServiceRoot::saveAccountDataToDatabase() {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// We are probably saving newly added account.
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
bool saved;
|
||||
int id_to_assign = DatabaseQueries::createAccount(database, code(), &saved);
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/databasefactory.h"
|
||||
#include "miscellaneous/databasequeries.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
@ -30,8 +29,6 @@
|
||||
#include "services/tt-rss/gui/formeditfeed.h"
|
||||
#include "services/tt-rss/network/ttrssnetworkfactory.h"
|
||||
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
#include <QPointer>
|
||||
|
||||
|
||||
@ -145,21 +142,11 @@ bool TtRssFeed::cleanMessages(bool clear_only_read) {
|
||||
|
||||
bool TtRssFeed::editItself(TtRssFeed *new_feed_data) {
|
||||
QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings);
|
||||
QSqlQuery query_update(database);
|
||||
|
||||
query_update.setForwardOnly(true);
|
||||
query_update.prepare("UPDATE Feeds "
|
||||
"SET update_type = :update_type, update_interval = :update_interval "
|
||||
"WHERE id = :id;");
|
||||
|
||||
query_update.bindValue(QSL(":update_type"), (int) new_feed_data->autoUpdateType());
|
||||
query_update.bindValue(QSL(":update_interval"), new_feed_data->autoUpdateInitialInterval());
|
||||
query_update.bindValue(QSL(":id"), id());
|
||||
|
||||
if (query_update.exec()) {
|
||||
if (DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(),
|
||||
new_feed_data->autoUpdateInitialInterval())) {
|
||||
setAutoUpdateType(new_feed_data->autoUpdateType());
|
||||
setAutoUpdateInitialInterval(new_feed_data->autoUpdateInitialInterval());
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -18,18 +18,14 @@
|
||||
#include "services/tt-rss/ttrssserviceentrypoint.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "miscellaneous/databasequeries.h"
|
||||
#include "gui/dialogs/formmain.h"
|
||||
#include "services/tt-rss/definitions.h"
|
||||
#include "services/tt-rss/gui/formeditaccount.h"
|
||||
#include "services/tt-rss/ttrssserviceroot.h"
|
||||
#include "services/tt-rss/network/ttrssnetworkfactory.h"
|
||||
#include "services/tt-rss/gui/formeditaccount.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
|
||||
|
||||
TtRssServiceEntryPoint::TtRssServiceEntryPoint(){
|
||||
@ -37,7 +33,6 @@ TtRssServiceEntryPoint::TtRssServiceEntryPoint(){
|
||||
|
||||
|
||||
TtRssServiceEntryPoint::~TtRssServiceEntryPoint() {
|
||||
|
||||
}
|
||||
|
||||
bool TtRssServiceEntryPoint::isSingleInstanceService() const {
|
||||
@ -79,29 +74,6 @@ ServiceRoot *TtRssServiceEntryPoint::createNewRoot() const {
|
||||
QList<ServiceRoot*> TtRssServiceEntryPoint::initializeSubtree() const {
|
||||
// Check DB if standard account is enabled.
|
||||
QSqlDatabase database = qApp->database()->connection(QSL("TtRssServiceEntryPoint"), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
QList<ServiceRoot*> roots;
|
||||
|
||||
if (query.exec("SELECT * FROM TtRssAccounts;")) {
|
||||
while (query.next()) {
|
||||
TtRssServiceRoot *root = new TtRssServiceRoot();
|
||||
root->setId(query.value(0).toInt());
|
||||
root->setAccountId(query.value(0).toInt());
|
||||
root->network()->setUsername(query.value(1).toString());
|
||||
root->network()->setPassword(TextFactory::decrypt(query.value(2).toString()));
|
||||
root->network()->setAuthIsUsed(query.value(3).toBool());
|
||||
root->network()->setAuthUsername(query.value(4).toString());
|
||||
root->network()->setAuthPassword(TextFactory::decrypt(query.value(5).toString()));
|
||||
root->network()->setUrl(query.value(6).toString());
|
||||
root->network()->setForceServerSideUpdate(query.value(7).toBool());
|
||||
|
||||
root->updateTitle();
|
||||
roots.append(root);
|
||||
}
|
||||
}
|
||||
else {
|
||||
qWarning("TT-RSS: Getting list of activated accounts failed: '%s'.", qPrintable(query.lastError().text()));
|
||||
}
|
||||
|
||||
return roots;
|
||||
return DatabaseQueries::getTtRssAccounts(database);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "miscellaneous/settings.h"
|
||||
#include "miscellaneous/mutex.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "miscellaneous/databasequeries.h"
|
||||
#include "gui/dialogs/formmain.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
#include "services/tt-rss/ttrssserviceentrypoint.h"
|
||||
@ -33,8 +34,6 @@
|
||||
#include "services/tt-rss/gui/formeditfeed.h"
|
||||
|
||||
#include <QSqlTableModel>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
#include <QPair>
|
||||
#include <QClipboard>
|
||||
|
||||
@ -76,16 +75,11 @@ bool TtRssServiceRoot::editViaGui() {
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::deleteViaGui() {
|
||||
QSqlDatabase connection = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(connection);
|
||||
|
||||
query.setForwardOnly(true);
|
||||
query.prepare(QSL("DELETE FROM TtRssAccounts WHERE id = :id;"));
|
||||
query.bindValue(QSL(":id"), accountId());
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
// Remove extra entry in "Tiny Tiny RSS accounts list" and then delete
|
||||
// all the categories/feeds and messages.
|
||||
if (query.exec()) {
|
||||
if (DatabaseQueries::deleteTtRssAccount(database, accountId())) {
|
||||
return ServiceRoot::deleteViaGui();
|
||||
}
|
||||
else {
|
||||
@ -223,116 +217,39 @@ TtRssNetworkFactory *TtRssServiceRoot::network() const {
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::saveAccountDataToDatabase() {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
|
||||
if (accountId() != NO_PARENT_CATEGORY) {
|
||||
// We are overwritting previously saved data.
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
|
||||
query.prepare("UPDATE TtRssAccounts "
|
||||
"SET username = :username, password = :password, url = :url, auth_protected = :auth_protected, "
|
||||
"auth_username = :auth_username, auth_password = :auth_password, force_update = :force_update "
|
||||
"WHERE id = :id;");
|
||||
query.bindValue(QSL(":username"), m_network->username());
|
||||
query.bindValue(QSL(":password"), TextFactory::encrypt(m_network->password()));
|
||||
query.bindValue(QSL(":url"), m_network->url());
|
||||
query.bindValue(QSL(":auth_protected"), (int) m_network->authIsUsed());
|
||||
query.bindValue(QSL(":auth_username"), m_network->authUsername());
|
||||
query.bindValue(QSL(":auth_password"), TextFactory::encrypt(m_network->authPassword()));
|
||||
query.bindValue(QSL(":force_update"), (int) m_network->forceServerSideUpdate());
|
||||
query.bindValue(QSL(":id"), accountId());
|
||||
|
||||
if (query.exec()) {
|
||||
if (DatabaseQueries::overwriteTtRssAccount(database, m_network->username(), m_network->password(),
|
||||
m_network->authIsUsed(), m_network->authUsername(),
|
||||
m_network->authPassword(), m_network->url(),
|
||||
m_network->forceServerSideUpdate(), accountId())) {
|
||||
updateTitle();
|
||||
itemChanged(QList<RootItem*>() << this);
|
||||
}
|
||||
else {
|
||||
qWarning("TT-RSS: Updating account failed: '%s'.", qPrintable(query.lastError().text()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// We are probably saving newly added account.
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query(database);
|
||||
|
||||
// First obtain the ID, which can be assigned to this new account.
|
||||
if (!query.exec("SELECT max(id) FROM Accounts;") || !query.next()) {
|
||||
qWarning("TT-RSS: Getting max ID from Accounts table failed: '%s'.", qPrintable(query.lastError().text()));
|
||||
return;
|
||||
}
|
||||
|
||||
int id_to_assign = query.value(0).toInt() + 1;
|
||||
bool saved = true;
|
||||
|
||||
query.prepare(QSL("INSERT INTO Accounts (id, type) VALUES (:id, :type);"));
|
||||
query.bindValue(QSL(":id"), id_to_assign);
|
||||
query.bindValue(QSL(":type"), code());
|
||||
|
||||
saved &= query.exec();
|
||||
|
||||
query.prepare("INSERT INTO TtRssAccounts (id, username, password, auth_protected, auth_username, auth_password, url, force_update) "
|
||||
"VALUES (:id, :username, :password, :auth_protected, :auth_username, :auth_password, :url, :force_update);");
|
||||
query.bindValue(QSL(":id"), id_to_assign);
|
||||
query.bindValue(QSL(":username"), m_network->username());
|
||||
query.bindValue(QSL(":password"), TextFactory::encrypt(m_network->password()));
|
||||
query.bindValue(QSL(":auth_protected"), (int) m_network->authIsUsed());
|
||||
query.bindValue(QSL(":auth_username"), m_network->authUsername());
|
||||
query.bindValue(QSL(":auth_password"), TextFactory::encrypt(m_network->authPassword()));
|
||||
query.bindValue(QSL(":url"), m_network->url());
|
||||
query.bindValue(QSL(":force_update"), (int) m_network->forceServerSideUpdate());
|
||||
|
||||
saved &= query.exec();
|
||||
bool saved;
|
||||
int id_to_assign = DatabaseQueries::createAccount(database, code(), &saved);
|
||||
|
||||
if (saved) {
|
||||
setId(id_to_assign);
|
||||
setAccountId(id_to_assign);
|
||||
updateTitle();
|
||||
}
|
||||
else {
|
||||
qWarning("TT-RSS: Saving of new account failed: '%s'.", qPrintable(query.lastError().text()));
|
||||
if (DatabaseQueries::createTtRssAccount(database, id_to_assign, m_network->username(),
|
||||
m_network->password(), m_network->authIsUsed(),
|
||||
m_network->authUsername(), m_network->authPassword(),
|
||||
m_network->url(), m_network->forceServerSideUpdate())) {
|
||||
setId(id_to_assign);
|
||||
setAccountId(id_to_assign);
|
||||
updateTitle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::loadFromDatabase() {
|
||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||
Assignment categories;
|
||||
Assignment feeds;
|
||||
|
||||
// Obtain data for categories from the database.
|
||||
QSqlQuery query_categories(database);
|
||||
query_categories.setForwardOnly(true);
|
||||
query_categories.prepare(QSL("SELECT * FROM Categories WHERE account_id = :account_id;"));
|
||||
query_categories.bindValue(QSL(":account_id"), accountId());
|
||||
|
||||
if (!query_categories.exec()) {
|
||||
qFatal("Query for obtaining categories failed. Error message: '%s'.", qPrintable(query_categories.lastError().text()));
|
||||
}
|
||||
|
||||
while (query_categories.next()) {
|
||||
AssignmentItem pair;
|
||||
pair.first = query_categories.value(CAT_DB_PARENT_ID_INDEX).toInt();
|
||||
pair.second = new TtRssCategory(query_categories.record());
|
||||
|
||||
categories << pair;
|
||||
}
|
||||
|
||||
// All categories are now loaded.
|
||||
QSqlQuery query_feeds(database);
|
||||
query_feeds.setForwardOnly(true);
|
||||
query_feeds.prepare(QSL("SELECT * FROM Feeds WHERE account_id = :account_id;"));
|
||||
query_feeds.bindValue(QSL(":account_id"), accountId());
|
||||
|
||||
if (!query_feeds.exec()) {
|
||||
qFatal("Query for obtaining feeds failed. Error message: '%s'.", qPrintable(query_feeds.lastError().text()));
|
||||
}
|
||||
|
||||
while (query_feeds.next()) {
|
||||
AssignmentItem pair;
|
||||
pair.first = query_feeds.value(FDS_DB_CATEGORY_INDEX).toInt();
|
||||
pair.second = new TtRssFeed(query_feeds.record());
|
||||
|
||||
feeds << pair;
|
||||
}
|
||||
Assignment categories = DatabaseQueries::getTtRssCategories(database, accountId());
|
||||
Assignment feeds = DatabaseQueries::getTtRssFeeds(database, accountId());
|
||||
|
||||
// All data are now obtained, lets create the hierarchy.
|
||||
assembleCategories(categories);
|
||||
|
Loading…
Reference in New Issue
Block a user