This commit is contained in:
Martin Rotter 2023-04-21 13:06:53 +02:00
parent e33599b862
commit 7868342a80
8 changed files with 68 additions and 0 deletions

View File

@ -455,6 +455,18 @@ void FeedsModel::changeSortOrder(RootItem* item, bool move_top, bool move_bottom
DatabaseQueries::moveItem(item, move_top, move_bottom, new_sort_order, db); DatabaseQueries::moveItem(item, move_top, move_bottom, new_sort_order, db);
} }
void FeedsModel::sortDirectDescendants(RootItem* item, RootItem::Kind kind_to_sort) {
auto childs = item->childItems(kind_to_sort);
std::sort(childs.begin(), childs.end(), [](RootItem* lhs, RootItem* rhs) {
return lhs->title().compare(rhs->title(), Qt::CaseSensitivity::CaseInsensitive) < 0;
});
for (RootItem* it : childs) {
changeSortOrder(it, false, true);
}
}
void FeedsModel::loadActivatedServiceAccounts() { void FeedsModel::loadActivatedServiceAccounts() {
auto serv = qApp->feedReader()->feedServices(); auto serv = qApp->feedReader()->feedServices();

View File

@ -107,6 +107,10 @@ class RSSGUARD_DLLSPEC FeedsModel : public QAbstractItemModel {
void changeSortOrder(RootItem* item, bool move_top, bool move_bottom, int new_sort_order = {}); void changeSortOrder(RootItem* item, bool move_top, bool move_bottom, int new_sort_order = {});
// Takes direct descendants (but only categories or feeds)
// and rearranges them alphabetically.
void sortDirectDescendants(RootItem* item, RootItem::Kind kind_to_sort);
// Feeds operations. // Feeds operations.
bool markItemRead(RootItem* item, RootItem::ReadStatus read); bool markItemRead(RootItem* item, RootItem::ReadStatus read);
bool markItemCleared(RootItem* item, bool clean_read_only); bool markItemCleared(RootItem* item, bool clean_read_only);

View File

@ -480,6 +480,8 @@ void FormMain::updateFeedButtonsAvailability() {
const bool service_selected = anything_selected && selected_item->kind() == RootItem::Kind::ServiceRoot; const bool service_selected = anything_selected && selected_item->kind() == RootItem::Kind::ServiceRoot;
const bool manual_feed_sort = !m_ui->m_actionSortFeedsAlphabetically->isChecked(); const bool manual_feed_sort = !m_ui->m_actionSortFeedsAlphabetically->isChecked();
m_ui->m_actionRearrangeFeeds->setEnabled(manual_feed_sort && (service_selected || category_selected));
m_ui->m_actionRearrangeCategories->setEnabled(manual_feed_sort && (service_selected || category_selected));
m_ui->m_actionStopRunningItemsUpdate->setEnabled(is_update_running); m_ui->m_actionStopRunningItemsUpdate->setEnabled(is_update_running);
m_ui->m_actionBackupDatabaseSettings->setEnabled(!critical_action_running); m_ui->m_actionBackupDatabaseSettings->setEnabled(!critical_action_running);
m_ui->m_actionCleanupDatabase->setEnabled(!critical_action_running); m_ui->m_actionCleanupDatabase->setEnabled(!critical_action_running);
@ -892,6 +894,15 @@ void FormMain::createConnections() {
&QAction::triggered, &QAction::triggered,
tabWidget()->feedMessageViewer()->feedsView(), tabWidget()->feedMessageViewer()->feedsView(),
&FeedsView::updateSelectedItems); &FeedsView::updateSelectedItems);
connect(m_ui->m_actionRearrangeCategories,
&QAction::triggered,
tabWidget()->feedMessageViewer()->feedsView(),
&FeedsView::rearrangeCategoriesOfSelectedItem);
connect(m_ui->m_actionRearrangeFeeds,
&QAction::triggered,
tabWidget()->feedMessageViewer()->feedsView(),
&FeedsView::rearrangeFeedsOfSelectedItem);
connect(m_ui->m_actionUpdateAllItems, &QAction::triggered, qApp->feedReader(), &FeedReader::updateAllFeeds); connect(m_ui->m_actionUpdateAllItems, &QAction::triggered, qApp->feedReader(), &FeedReader::updateAllFeeds);
connect(m_ui->m_actionUpdateSelectedItemsWithCustomTimers, connect(m_ui->m_actionUpdateSelectedItemsWithCustomTimers,
&QAction::triggered, &QAction::triggered,

13
src/librssguard/gui/dialogs/formmain.ui Normal file → Executable file
View File

@ -128,6 +128,9 @@
<addaction name="m_actionDeleteSelectedItem"/> <addaction name="m_actionDeleteSelectedItem"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="m_actionSortFeedsAlphabetically"/> <addaction name="m_actionSortFeedsAlphabetically"/>
<addaction name="m_actionRearrangeCategories"/>
<addaction name="m_actionRearrangeFeeds"/>
<addaction name="separator"/>
<addaction name="m_actionShowOnlyUnreadItems"/> <addaction name="m_actionShowOnlyUnreadItems"/>
<addaction name="m_actionAutoExpandItemsWhenSelected"/> <addaction name="m_actionAutoExpandItemsWhenSelected"/>
<addaction name="m_actionShowTreeBranches"/> <addaction name="m_actionShowTreeBranches"/>
@ -918,6 +921,16 @@
<string>Scroll &amp;down browser</string> <string>Scroll &amp;down browser</string>
</property> </property>
</action> </action>
<action name="m_actionRearrangeCategories">
<property name="text">
<string>Rearrange &amp;subcategories alphabetically</string>
</property>
</action>
<action name="m_actionRearrangeFeeds">
<property name="text">
<string>Rearrange &amp;feeds alphabetically</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -315,6 +315,16 @@ void FeedsView::moveSelectedItemDown() {
m_proxyModel->invalidate(); m_proxyModel->invalidate();
} }
void FeedsView::rearrangeCategoriesOfSelectedItem() {
m_sourceModel->sortDirectDescendants(selectedItem(), RootItem::Kind::Category);
m_proxyModel->invalidate();
}
void FeedsView::rearrangeFeedsOfSelectedItem() {
m_sourceModel->sortDirectDescendants(selectedItem(), RootItem::Kind::Feed);
m_proxyModel->invalidate();
}
void FeedsView::markSelectedItemReadStatus(RootItem::ReadStatus read) { void FeedsView::markSelectedItemReadStatus(RootItem::ReadStatus read) {
m_sourceModel->markItemRead(selectedItem(), read); m_sourceModel->markItemRead(selectedItem(), read);
} }
@ -469,6 +479,8 @@ QMenu* FeedsView::initializeContextMenuService(RootItem* clicked_item) {
qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode, qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode,
qApp->mainForm()->m_ui->m_actionExpandCollapseItem, qApp->mainForm()->m_ui->m_actionExpandCollapseItem,
qApp->mainForm()->m_ui->m_actionExpandCollapseItemRecursively, qApp->mainForm()->m_ui->m_actionExpandCollapseItemRecursively,
qApp->mainForm()->m_ui->m_actionRearrangeCategories,
qApp->mainForm()->m_ui->m_actionRearrangeFeeds,
qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsRead, qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsRead,
qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsUnread, qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsUnread,
qApp->mainForm()->m_ui->m_actionDeleteSelectedItem}); qApp->mainForm()->m_ui->m_actionDeleteSelectedItem});
@ -691,6 +703,8 @@ QMenu* FeedsView::initializeContextMenuCategories(RootItem* clicked_item) {
qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode, qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode,
qApp->mainForm()->m_ui->m_actionExpandCollapseItem, qApp->mainForm()->m_ui->m_actionExpandCollapseItem,
qApp->mainForm()->m_ui->m_actionExpandCollapseItemRecursively, qApp->mainForm()->m_ui->m_actionExpandCollapseItemRecursively,
qApp->mainForm()->m_ui->m_actionRearrangeCategories,
qApp->mainForm()->m_ui->m_actionRearrangeFeeds,
qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsRead, qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsRead,
qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsUnread, qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsUnread,
qApp->mainForm()->m_ui->m_actionDeleteSelectedItem}); qApp->mainForm()->m_ui->m_actionDeleteSelectedItem});

View File

@ -72,6 +72,8 @@ class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView {
void moveSelectedItemTop(); void moveSelectedItemTop();
void moveSelectedItemBottom(); void moveSelectedItemBottom();
void moveSelectedItemDown(); void moveSelectedItemDown();
void rearrangeCategoriesOfSelectedItem();
void rearrangeFeedsOfSelectedItem();
// Selects next/previous item (feed/category) in the list. // Selects next/previous item (feed/category) in the list.
void selectNextItem(); void selectNextItem();

View File

@ -639,3 +639,13 @@ RootItem::Kind operator|(RootItem::Kind a, RootItem::Kind b) {
RootItem::Kind operator&(RootItem::Kind a, RootItem::Kind b) { RootItem::Kind operator&(RootItem::Kind a, RootItem::Kind b) {
return static_cast<RootItem::Kind>(static_cast<int>(a) & static_cast<int>(b)); return static_cast<RootItem::Kind>(static_cast<int>(a) & static_cast<int>(b));
} }
QList<RootItem*> RootItem::childItems(Kind kind) const {
auto linq = boolinq::from(m_childItems)
.where([=](RootItem* it) {
return it->kind() == kind;
})
.toStdList();
return FROM_STD_LIST(QList<RootItem*>, linq);
}

View File

@ -112,6 +112,8 @@ class RSSGUARD_DLLSPEC RootItem : public QObject {
RootItem* child(int row); RootItem* child(int row);
int childCount() const; int childCount() const;
void appendChild(RootItem* child); void appendChild(RootItem* child);
QList<RootItem*> childItems(RootItem::Kind kind) const;
QList<RootItem*> childItems() const; QList<RootItem*> childItems() const;
QList<RootItem*>& childItems(); QList<RootItem*>& childItems();