diff --git a/src/core/rootitem.cpp b/src/core/rootitem.cpp index 47bec016c..e92ef64f4 100755 --- a/src/core/rootitem.cpp +++ b/src/core/rootitem.cpp @@ -42,7 +42,7 @@ RootItem::~RootItem() { qDeleteAll(m_childItems); } -QList RootItem::specificContextMenuActions() { +QList RootItem::contextMenuActions() { return QList(); } diff --git a/src/core/rootitem.h b/src/core/rootitem.h index 5bd5ef8f2..450153e77 100755 --- a/src/core/rootitem.h +++ b/src/core/rootitem.h @@ -77,8 +77,10 @@ class RootItem : public QObject { } // Returns list of specific actions which can be done with the item. + // Do not include general actions here like actions: + // Mark as read, Update, ... // NOTE: Ownership of returned actions is not switched to caller, free them when needed. - virtual QList specificContextMenuActions(); + virtual QList contextMenuActions(); // TODO: pracovat s těmito věcmi virtual bool canBeEdited() { diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index ec213982f..c7879b9c5 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -198,6 +198,39 @@ void FormMain::updateAddItemMenu() { } } +void FormMain::updateServicesMenu() { + m_ui->m_menuServices->clear(); + + foreach (ServiceRoot *activated_root, tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) { + QMenu *root_menu = new QMenu(activated_root->title(), m_ui->m_menuServices); + root_menu->setIcon(activated_root->icon()); + root_menu->setToolTip(activated_root->description()); + + QList root_actions = activated_root->serviceMenu(); + + if (root_actions.isEmpty()) { + QAction *no_action = new QAction(qApp->icons()->fromTheme(QSL("dialog-error")), + tr("No possible actions"), + m_ui->m_menuServices); + no_action->setEnabled(false); + root_menu->addAction(no_action); + } + else { + root_menu->addActions(root_actions); + } + + m_ui->m_menuServices->addMenu(root_menu); + } + + if (!m_ui->m_menuServices->isEmpty()) { + m_ui->m_menuServices->addSeparator(); + } + + m_ui->m_menuServices->addAction(m_ui->m_actionServiceAdd); + m_ui->m_menuServices->addAction(m_ui->m_actionServiceEdit); + m_ui->m_menuServices->addAction(m_ui->m_actionServiceDelete); +} + void FormMain::switchVisibility(bool force_hide) { if (force_hide || isVisible()) { if (SystemTrayIcon::isSystemTrayActivated()) { @@ -363,6 +396,7 @@ void FormMain::createConnections() { connect(m_ui->m_actionFullscreen, SIGNAL(toggled(bool)), m_statusBar->fullscreenSwitcher(), SLOT(setChecked(bool))); connect(m_ui->m_menuAddItem, SIGNAL(aboutToShow()), this, SLOT(updateAddItemMenu())); + connect(m_ui->m_menuServices, SIGNAL(aboutToShow()), this, SLOT(updateServicesMenu())); // Menu "File" connections. connect(m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds())); diff --git a/src/gui/dialogs/formmain.h b/src/gui/dialogs/formmain.h index 2f212f8f8..97149e9c2 100755 --- a/src/gui/dialogs/formmain.h +++ b/src/gui/dialogs/formmain.h @@ -79,6 +79,7 @@ class FormMain : public QMainWindow { private slots: void updateAddItemMenu(); + void updateServicesMenu(); // Loads web browser menu if user selects to change tabs. void loadWebBrowserMenu(int index); diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index c38b2598f..9fac64286 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -491,7 +491,7 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) { m_contextMenuCategories->clear(); } - QList specific_actions = clicked_item->specificContextMenuActions(); + QList specific_actions = clicked_item->contextMenuActions(); m_contextMenuCategories->addActions(QList() << qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << @@ -512,14 +512,10 @@ void FeedsView::initializeContextMenuFeeds(RootItem *clicked_item) { m_contextMenuFeeds = new QMenu(tr("Context menu for categories"), this); } else { - // FIXME: Položky jsou mazány při opětovném otevření kontextového nabíky ale je lepší je mazat - // hned při zavření kontextove nabíky. - - // TODO: clear nevymaže z paměti. m_contextMenuFeeds->clear(); } - QList specific_actions = clicked_item->specificContextMenuActions(); + QList specific_actions = clicked_item->contextMenuActions(); m_contextMenuFeeds->addActions(QList() << qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index 89b47efb0..a8471eea3 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -42,12 +42,17 @@ class ServiceRoot : public RootItem { // NOTE: Caller does NOT take ownership of created menu! virtual QList addItemMenu() = 0; + // Returns list of specific actions to be shown in main window menu + // bar in sections "Services -> 'this service'". + // NOTE: Caller does NOT take ownership of created menu! + virtual QList serviceMenu() = 0; + inline FeedsModel *feedsModel() const { return m_feedsModel; } protected: - FeedsModel *m_feedsModel; + FeedsModel *m_feedsModel; }; #endif // SERVICEROOT_H diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 54ee4c106..530b0a939 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -98,7 +98,7 @@ int StandardFeed::countOfUnreadMessages() const { return m_unreadCount; } -QList StandardFeed::specificContextMenuActions() { +QList StandardFeed::contextMenuActions() { return serviceRoot()->getContextMenuForFeed(this); } diff --git a/src/services/standard/standardfeed.h b/src/services/standard/standardfeed.h index f4c8d0c6a..395710995 100755 --- a/src/services/standard/standardfeed.h +++ b/src/services/standard/standardfeed.h @@ -61,7 +61,7 @@ class StandardFeed : public Feed { int countOfAllMessages() const; int countOfUnreadMessages() const; - QList specificContextMenuActions(); + QList contextMenuActions(); bool canBeEdited() { return true; diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index 2f6b076ac..9bb171d59 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -297,6 +297,10 @@ QList StandardServiceRoot::addItemMenu() { return m_addItemMenu; } +QList StandardServiceRoot::serviceMenu() { + return QList(); +} + void StandardServiceRoot::assembleCategories(CategoryAssignment categories) { QHash assignments; assignments.insert(NO_PARENT_CATEGORY, this); diff --git a/src/services/standard/standardserviceroot.h b/src/services/standard/standardserviceroot.h index 230f40188..406d0e74a 100755 --- a/src/services/standard/standardserviceroot.h +++ b/src/services/standard/standardserviceroot.h @@ -49,6 +49,9 @@ class StandardServiceRoot : public ServiceRoot { // Return "add feed" and "add category" items. QList addItemMenu(); + // Return menu to be shown in "Services -> service" menu. + QList serviceMenu(); + // Returns all standard categories which are lying under given root node. // This does NOT include the root node even if the node is category. QHash categoriesForItem(RootItem *root);