| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/services/abstract/labelsnode.cpp`/ |
| 2 | |
| 3 | #include "services/abstract/labelsnode.h"cxx . . $ `<file>/src/librssguard/services/abstract/labelsnode.h`/ |
| 4 | |
| 5 | #include "3rd-party/boolinq/boolinq.h"cxx . . $ `<file>/src/librssguard/3rd-party/boolinq/boolinq.h`/ |
| 6 | #include "database/databasefactory.h"cxx . . $ `<file>/src/librssguard/database/databasefactory.h`/ |
| 7 | #include "database/databasequeries.h"cxx . . $ `<file>/src/librssguard/database/databasequeries.h`/ |
| 8 | #include "definitions/globals.h"cxx . . $ `<file>/src/librssguard/definitions/globals.h`/ |
| 9 | #include "exceptions/applicationexception.h"cxx . . $ `<file>/src/librssguard/exceptions/applicationexception.h`/ |
| 10 | #include "miscellaneous/application.h"cxx . . $ `<file>/src/librssguard/miscellaneous/application.h`/ |
| 11 | #include "miscellaneous/iconfactory.h"cxx . . $ `<file>/src/librssguard/miscellaneous/iconfactory.h`/ |
| 12 | #include "services/abstract/gui/formaddeditlabel.h"cxx . . $ `<file>/src/librssguard/services/abstract/gui/formaddeditlabel.h`/ |
| 13 | #include "services/abstract/serviceroot.h"cxx . . $ `<file>/src/librssguard/services/abstract/serviceroot.h`/ |
| 14 | |
| 15 | LabelsNodecxx . . $ LabelsNode#::LabelsNodecxx . . $ LabelsNode#LabelsNode(cb16baca005cfe86).(RootItemcxx . . $ RootItem#* parent_item) : RootItemcxx . . $ RootItem#(parent_item), m_actLabelNewcxx . . $ LabelsNode#m_actLabelNew.(nullptr) { |
| 16 | setKindcxx . . $ RootItem#setKind(77afe77d4ce7bfe8).(RootItemcxx . . $ RootItem#::Kindcxx . . $ RootItem#Kind#::Labelscxx . . $ RootItem#Kind#Labels.); |
| 17 | setIdcxx . . $ RootItem#setId(d4f767463ce0a6b3).(ID_LABELScxx . . $ `src/librssguard/definitions/definitions.h:45:9`!); |
| 18 | setIconcxx . . $ RootItem#setIcon(71dcdac178620ed6).(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->iconscxx . . $ Application#icons(d976db2a0d825b70).()->fromThemecxx . . $ IconFactory#fromTheme(e457fbbee8993f3).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("tag-folder"), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("emblem-favorite"))); |
| 19 | setTitlecxx . . $ RootItem#setTitle(3520e46b33348bf6).(trcxx . . $ LabelsNode#tr(75d9f1c324b4579d).("Labels")); |
| 20 | setDescriptioncxx . . $ RootItem#setDescription(3520e46b33348bf6).(trcxx . . $ LabelsNode#tr(75d9f1c324b4579d).("You can see all your labels (tags) here.")); |
| 21 | } |
| 22 | |
| 23 | void LabelsNodecxx . . $ LabelsNode#::loadLabelscxx . . $ LabelsNode#loadLabels(d049bd89a20e2c3b).(const QListcxx . . $ QList#<Labelcxx . . $ Label#*>& labels) { |
| 24 | for (Labelcxx . . $ Label#* lbl : labels) { |
| 25 | appendChildcxx . . $ RootItem#appendChild(cb16baca005cfe86).(lbl); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | QListcxx . . $ QList#<Messagecxx . . $ Message#> LabelsNodecxx . . $ LabelsNode#::undeletedMessagescxx . . $ LabelsNode#undeletedMessages(96785ab56182243a).() const { |
| 30 | QSqlDatabasecxx . . $ QSqlDatabase# database = qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->databasecxx . . $ Application#database(4a253a6ca99872d8).()->drivercxx . . $ DatabaseFactory#driver(5299be7c9afd522d).()->connectioncxx . . $ DatabaseDriver#connection(32d6d64cc6e35a97).(metaObjectcxx . . $ QString#QString(85c52e162fed56f9).()->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).()); |
| 31 | |
| 32 | return DatabaseQueriescxx . . $ DatabaseQueries#::getUndeletedLabelledMessagescxx . . $ DatabaseQueries#getUndeletedLabelledMessages(4df15bb3942892d6).(database, getParentServiceRootcxx . . $ RootItem#getParentServiceRoot(56209a8cf0725652).()->accountIdcxx . . $ ServiceRoot#accountId(455f465bc33b4cdf).()); |
| 33 | } |
| 34 | |
| 35 | void LabelsNodecxx . . $ LabelsNode#::updateCountscxx . . $ LabelsNode#updateCounts(b45ddcbc8423892c).(bool including_total_count) { |
| 36 | // TODO: This is still rather slow because this is automatically |
| 37 | // called when message is marked (un)read or starred. |
| 38 | // It would be enough if only labels which are assigned to article |
| 39 | // are recounted, not all. |
| 40 | |
| 41 | QSqlDatabasecxx . . $ QSqlDatabase# database = qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->databasecxx . . $ Application#database(4a253a6ca99872d8).()->drivercxx . . $ DatabaseFactory#driver(5299be7c9afd522d).()->threadSafeConnectioncxx . . $ DatabaseDriver#threadSafeConnection(32d6d64cc6e35a97).(metaObjectcxx . . $ QString#QString(85c52e162fed56f9).()->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).()); |
| 42 | int account_id = getParentServiceRootcxx . . $ RootItem#getParentServiceRoot(56209a8cf0725652).()->accountIdcxx . . $ ServiceRoot#accountId(455f465bc33b4cdf).(); |
| 43 | auto acc = DatabaseQueriescxx . . $ DatabaseQueries#::getMessageCountsForAllLabelscxx . . $ DatabaseQueries#getMessageCountsForAllLabels(cf849f4456795efd).(database, account_id); |
| 44 | |
| 45 | for (Labelcxx . . $ Label#* lbl : labelscxx . . $ LabelsNode#labels(fd3f29dd0362ab36).()) { |
| 46 | if (!acc.containscxx . . $ QMap#contains(8877ebe272b9620d).(lbl->customIdcxx . . $ RootItem#customId(6ef7b6c27b00b43d).())) { |
| 47 | if (including_total_count) { |
| 48 | lbl->setCountOfAllMessagescxx . . $ Label#setCountOfAllMessages(d4f767463ce0a6b3).(0); |
| 49 | } |
| 50 | |
| 51 | lbl->setCountOfUnreadMessagescxx . . $ Label#setCountOfUnreadMessages(d4f767463ce0a6b3).(0); |
| 52 | } |
| 53 | else { |
| 54 | auto ac = acc.valuecxx . . $ QMap#value(6f0b2e7f225a8193).(lbl->customIdcxx . . $ RootItem#customId(6ef7b6c27b00b43d).()); |
| 55 | |
| 56 | if (including_total_count) { |
| 57 | lbl->setCountOfAllMessagescxx . . $ Label#setCountOfAllMessages(d4f767463ce0a6b3).(ac.m_totalcxx . . $ ArticleCounts#m_total.); |
| 58 | } |
| 59 | |
| 60 | lbl->setCountOfUnreadMessagescxx . . $ Label#setCountOfUnreadMessages(d4f767463ce0a6b3).(ac.m_unreadcxx . . $ ArticleCounts#m_unread.); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | Labelcxx . . $ Label#* LabelsNodecxx . . $ LabelsNode#::labelByIdcxx . . $ LabelsNode#labelById(c478fee671b86778).(const QStringcxx . . $ QString#& custom_id) { |
| 66 | auto chi = childItemscxx . . $ RootItem#childItems(f275a58a8bc5f139).(); |
| 67 | |
| 68 | return qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<Labelcxx . . $ Label#*>(boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(chi).firstOrDefaultcxx . . $ boolinq/Linq#firstOrDefault(72be2761f3eff290).([cxx . . $ std/function#function(bdc3712e480e4d04).custom_idcxx . . $ QString#QString(132dd6869045752b).](RootItemcxx . . $ RootItem#* it) { |
| 69 | return it->customIdcxx . . $ RootItem#customId(6ef7b6c27b00b43d).() ==cxx . . $ `operator==`(5bc2975d2d751687). custom_id; |
| 70 | })); |
| 71 | } |
| 72 | |
| 73 | QListcxx . . $ QList#<Labelcxx . . $ Label#*> LabelsNodecxx . . $ LabelsNode#::labelscxx . . $ LabelsNode#labels(fd3f29dd0362ab36).() const { |
| 74 | auto list = boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(childItemscxx . . $ RootItem#childItems(8f33d497292471a8).()) |
| 75 | .selectcxx . . $ boolinq/Linq#select(a3f5bd4cd382e0ee).([](RootItemcxx . . $ RootItem#* it) { |
| 76 | return static_cast<Labelcxx . . $ Label#*>(it); |
| 77 | }) |
| 78 | .toStdListcxx . . $ boolinq/Linq#toStdList(2989115be80c3067).(); |
| 79 | |
| 80 | return FROM_STD_LISTcxx . . $ `src/librssguard/definitions/definitions.h:405:9`!(QList<Label*>, list); |
| 81 | } |
| 82 | |
| 83 | QListcxx . . $ QList#<QActioncxx . . $ QAction#*> LabelsNodecxx . . $ LabelsNode#::contextMenuFeedsListcxx . . $ LabelsNode#contextMenuFeedsList(c4b3bc0793dee689).() { |
| 84 | if (m_actLabelNewcxx . . $ LabelsNode#m_actLabelNew. == nullptr) { |
| 85 | // Initialize it all. |
| 86 | m_actLabelNewcxx . . $ LabelsNode#m_actLabelNew. = new QActioncxx . . $ QAction#QAction(ef44fe276c987e61).(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->iconscxx . . $ Application#icons(d976db2a0d825b70).()->fromThemecxx . . $ IconFactory#fromTheme(e457fbbee8993f3).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("tag-new")), trcxx . . $ LabelsNode#tr(75d9f1c324b4579d).("New label"), this); |
| 87 | |
| 88 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(m_actLabelNewcxx . . $ LabelsNode#m_actLabelNew., &QActioncxx . . $ QAction#::triggeredcxx . . $ QAction#triggered(b45ddcbc8423892c)., this, &LabelsNodecxx . . $ LabelsNode#::createLabelcxx . . $ LabelsNode#createLabel(49f6e7a06ebc5aa8).); |
| 89 | } |
| 90 | |
| 91 | return QListcxx . . $ QList#QList(b6da5b9a9f304025).<QActioncxx . . $ QAction#*>{m_actLabelNewcxx . . $ LabelsNode#m_actLabelNew.}; |
| 92 | } |
| 93 | |
| 94 | void LabelsNodecxx . . $ LabelsNode#::createLabelcxx . . $ LabelsNode#createLabel(49f6e7a06ebc5aa8).() { |
| 95 | if (Globalscxx . . $ Globals#::hasFlagcxx . . $ Globals#hasFlag(e81494ae8084f6ba).(getParentServiceRootcxx . . $ RootItem#getParentServiceRoot(56209a8cf0725652).()->supportedLabelOperationscxx . . $ ServiceRoot#supportedLabelOperations(a2eb219fd1bf9aba).(), ServiceRootcxx . . $ ServiceRoot#::LabelOperationcxx . . $ ServiceRoot#LabelOperation#::Addingcxx . . $ ServiceRoot#LabelOperation#Adding.)) { |
| 96 | FormAddEditLabelcxx . . $ FormAddEditLabel# frmcxx . . $ FormAddEditLabel#FormAddEditLabel(108f35f7aa7f3cf9).(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->mainFormWidgetcxx . . $ Application#mainFormWidget(9b769eeb00a33a04).()); |
| 97 | Labelcxx . . $ Label#* new_lbl = frm.execForAddcxx . . $ FormAddEditLabel#execForAdd(d44e39ca48f6ab51).(); |
| 98 | |
| 99 | if (new_lbl != nullptr) { |
| 100 | QSqlDatabasecxx . . $ QSqlDatabase# db = qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->databasecxx . . $ Application#database(4a253a6ca99872d8).()->drivercxx . . $ DatabaseFactory#driver(5299be7c9afd522d).()->connectioncxx . . $ DatabaseDriver#connection(32d6d64cc6e35a97).(metaObjectcxx . . $ QString#QString(85c52e162fed56f9).()->classNamecxx . . $ QMetaObject#className(a9f41ea0e82d88cf).()); |
| 101 | |
| 102 | try { |
| 103 | DatabaseQueriescxx . . $ DatabaseQueries#::createLabelcxx . . $ DatabaseQueries#createLabel(73c307d30be60cd2).(db, new_lbl, getParentServiceRootcxx . . $ RootItem#getParentServiceRoot(56209a8cf0725652).()->accountIdcxx . . $ ServiceRoot#accountId(455f465bc33b4cdf).()); |
| 104 | |
| 105 | getParentServiceRootcxx . . $ RootItem#getParentServiceRoot(56209a8cf0725652).()->requestItemReassignmentcxx . . $ ServiceRoot#requestItemReassignment(a5628b38272995c3).(new_lbl, this); |
| 106 | getParentServiceRootcxx . . $ RootItem#getParentServiceRoot(56209a8cf0725652).()->requestItemExpandcxx . . $ ServiceRoot#requestItemExpand(8e785c59da43649).({cxx . . $ QList#QList(b6da5b9a9f304025).this}, true); |
| 107 | } |
| 108 | catch (const ApplicationExceptioncxx . . $ ApplicationException#&) { |
| 109 | new_lbl->deleteLatercxx . . $ QObject#deleteLater(49f6e7a06ebc5aa8).(); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | else { |
| 114 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->showGuiMessagecxx . . $ Application#showGuiMessage(cf433640a87c3b52).(Notificationcxx . . $ Notification#::Eventcxx . . $ Notification#Event#::GeneralEventcxx . . $ Notification#Event#GeneralEvent., |
| 115 | {cxx . . $ GuiMessage#GuiMessage(b833bfd374dccacd).trcxx . . $ LabelsNode#tr(75d9f1c324b4579d).("This account does not allow you to create labels."), |
| 116 | trcxx . . $ LabelsNode#tr(75d9f1c324b4579d).("Not allowed"), |
| 117 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon#::Criticalcxx . . $ QSystemTrayIcon#Critical.}); |
| 118 | } |
| 119 | } |