working feed operations regarding to sort order, categories and accounts to go
This commit is contained in:
parent
2ef9a373b3
commit
3f59abae2a
@ -1987,28 +1987,31 @@ void DatabaseQueries::createOverwriteCategory(const QSqlDatabase& db, Category*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int parent_id) {
|
void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int new_parent_id) {
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
|
int next_sort_order;
|
||||||
|
|
||||||
|
if ((feed->id() <= 0 && feed->sortOrder() < 0) ||
|
||||||
|
(feed->parent() != nullptr && feed->parent()->id() != new_parent_id)) {
|
||||||
|
// We either insert completely new feed or we move feed
|
||||||
|
// to new parent. Get new viable sort order.
|
||||||
|
q.prepare(QSL("SELECT MAX(ordr) FROM Feeds WHERE account_id = :account_id AND category = :category;"));
|
||||||
|
q.bindValue(QSL(":account_id"), account_id);
|
||||||
|
q.bindValue(QSL(":category"), new_parent_id);
|
||||||
|
|
||||||
|
if (!q.exec() || !q.next()) {
|
||||||
|
throw ApplicationException(q.lastError().text());
|
||||||
|
}
|
||||||
|
|
||||||
|
next_sort_order = (q.value(0).isNull() ? -1 : q.value(0).toInt()) + 1;
|
||||||
|
q.finish();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
next_sort_order = feed->sortOrder();
|
||||||
|
}
|
||||||
|
|
||||||
if (feed->id() <= 0) {
|
if (feed->id() <= 0) {
|
||||||
// We need to insert feed first.
|
// We need to insert feed first.
|
||||||
if (feed->sortOrder() < 0) {
|
|
||||||
q.prepare(QSL("SELECT MAX(ordr) FROM Feeds WHERE account_id = :account_id AND category = :category;"));
|
|
||||||
q.bindValue(QSL(":account_id"), account_id);
|
|
||||||
q.bindValue(QSL(":category"), parent_id);
|
|
||||||
|
|
||||||
if (!q.exec()) {
|
|
||||||
throw ApplicationException(q.lastError().text());
|
|
||||||
}
|
|
||||||
|
|
||||||
q.next();
|
|
||||||
|
|
||||||
int next_order = (q.value(0).isNull() ? -1 : q.value(0).toInt()) + 1;
|
|
||||||
|
|
||||||
feed->setSortOrder(next_order);
|
|
||||||
q.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
q.prepare(QSL("INSERT INTO "
|
q.prepare(QSL("INSERT INTO "
|
||||||
"Feeds (title, ordr, date_created, category, update_type, update_interval, account_id, custom_id) "
|
"Feeds (title, ordr, date_created, category, update_type, update_interval, account_id, custom_id) "
|
||||||
"VALUES ('new', 0, 0, 0, 0, 1, %1, 'new');").arg(QString::number(account_id)));
|
"VALUES ('new', 0, 0, 0, 0, 1, %1, 'new');").arg(QString::number(account_id)));
|
||||||
@ -2024,9 +2027,18 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (feed->parent() != nullptr && feed->parent()->id() != new_parent_id) {
|
||||||
|
// Feed is moving between categories.
|
||||||
|
// 1. Move feed to bottom of current category.
|
||||||
|
// 2. Assign proper new sort order.
|
||||||
|
//
|
||||||
|
// NOTE: The feed will get reassigned to new parent usually after this method
|
||||||
|
// completes by the caller.
|
||||||
|
moveItem(feed, false, true, {}, db);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: pokus se kanál přesouvá mezi kategoriemi či rootem
|
// Restore to correct sort order.
|
||||||
// je třeba nejdříve kanál přesunout na dno a pak ho vložit do nové kategorie
|
feed->setSortOrder(next_sort_order);
|
||||||
|
|
||||||
q.prepare("UPDATE Feeds "
|
q.prepare("UPDATE Feeds "
|
||||||
"SET title = :title, ordr = :ordr, description = :description, date_created = :date_created, "
|
"SET title = :title, ordr = :ordr, description = :description, date_created = :date_created, "
|
||||||
@ -2038,7 +2050,7 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in
|
|||||||
q.bindValue(QSL(":description"), feed->description());
|
q.bindValue(QSL(":description"), feed->description());
|
||||||
q.bindValue(QSL(":date_created"), feed->creationDate().toMSecsSinceEpoch());
|
q.bindValue(QSL(":date_created"), feed->creationDate().toMSecsSinceEpoch());
|
||||||
q.bindValue(QSL(":icon"), qApp->icons()->toByteArray(feed->icon()));
|
q.bindValue(QSL(":icon"), qApp->icons()->toByteArray(feed->icon()));
|
||||||
q.bindValue(QSL(":category"), parent_id);
|
q.bindValue(QSL(":category"), new_parent_id);
|
||||||
q.bindValue(QSL(":source"), feed->source());
|
q.bindValue(QSL(":source"), feed->source());
|
||||||
q.bindValue(QSL(":update_type"), int(feed->autoUpdateType()));
|
q.bindValue(QSL(":update_type"), int(feed->autoUpdateType()));
|
||||||
q.bindValue(QSL(":update_interval"), feed->autoUpdateInitialInterval());
|
q.bindValue(QSL(":update_interval"), feed->autoUpdateInitialInterval());
|
||||||
|
@ -122,7 +122,7 @@ class DatabaseQueries {
|
|||||||
static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id);
|
static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id);
|
||||||
static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id);
|
static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id);
|
||||||
static void storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id);
|
static void storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id);
|
||||||
static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int parent_id);
|
static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int new_parent_id);
|
||||||
static void createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int parent_id);
|
static void createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int parent_id);
|
||||||
static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id);
|
static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id);
|
||||||
static bool deleteCategory(const QSqlDatabase& db, int id);
|
static bool deleteCategory(const QSqlDatabase& db, int id);
|
||||||
|
@ -196,6 +196,7 @@ void StandardFeed::fetchMetadataForItself() {
|
|||||||
setType(metadata->type());
|
setType(metadata->type());
|
||||||
setEncoding(metadata->encoding());
|
setEncoding(metadata->encoding());
|
||||||
setIcon(metadata->icon());
|
setIcon(metadata->icon());
|
||||||
|
|
||||||
metadata->deleteLater();
|
metadata->deleteLater();
|
||||||
|
|
||||||
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
|
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
|
||||||
|
@ -55,9 +55,9 @@ void StandardServiceRoot::start(bool freshly_activated) {
|
|||||||
if (freshly_activated && getSubTreeFeeds().isEmpty()) {
|
if (freshly_activated && getSubTreeFeeds().isEmpty()) {
|
||||||
// In other words, if there are no feeds or categories added.
|
// In other words, if there are no feeds or categories added.
|
||||||
if (MsgBox::show(qApp->mainFormWidget(), QMessageBox::Question, QObject::tr("Load initial set of feeds"),
|
if (MsgBox::show(qApp->mainFormWidget(), QMessageBox::Question, QObject::tr("Load initial set of feeds"),
|
||||||
tr("This new account does not include any feeds. You can now add default set of feeds."),
|
tr("This new account does not include any feeds. You can now add default set of feeds."),
|
||||||
tr("Do you want to load initial set of feeds?"),
|
tr("Do you want to load initial set of feeds?"),
|
||||||
QString(), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
QString(), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
||||||
QString target_opml_file = APP_INITIAL_FEEDS_PATH + QDir::separator() + FEED_INITIAL_OPML_PATTERN;
|
QString target_opml_file = APP_INITIAL_FEEDS_PATH + QDir::separator() + FEED_INITIAL_OPML_PATTERN;
|
||||||
QString current_locale = qApp->localization()->loadedLanguage();
|
QString current_locale = qApp->localization()->loadedLanguage();
|
||||||
QString file_to_load;
|
QString file_to_load;
|
||||||
@ -270,7 +270,7 @@ QList<Message> StandardServiceRoot::obtainNewMessages(Feed* feed,
|
|||||||
QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed* feed) {
|
QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed* feed) {
|
||||||
if (m_feedContextMenu.isEmpty()) {
|
if (m_feedContextMenu.isEmpty()) {
|
||||||
// Initialize.
|
// Initialize.
|
||||||
auto* action_metadata = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")),
|
auto* action_metadata = new QAction(qApp->icons()->fromTheme(QSL("download"), QSL("emblem-downloads")),
|
||||||
tr("Fetch metadata"),
|
tr("Fetch metadata"),
|
||||||
this);
|
this);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user