Added global service root menu to main form etc.

This commit is contained in:
Martin Rotter 2015-11-09 10:17:48 +01:00
parent 27aa11ff83
commit 9fac1568c5
10 changed files with 56 additions and 11 deletions

View File

@ -42,7 +42,7 @@ RootItem::~RootItem() {
qDeleteAll(m_childItems); qDeleteAll(m_childItems);
} }
QList<QAction *> RootItem::specificContextMenuActions() { QList<QAction*> RootItem::contextMenuActions() {
return QList<QAction*>(); return QList<QAction*>();
} }

View File

@ -77,8 +77,10 @@ class RootItem : public QObject {
} }
// Returns list of specific actions which can be done with the item. // 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. // NOTE: Ownership of returned actions is not switched to caller, free them when needed.
virtual QList<QAction*> specificContextMenuActions(); virtual QList<QAction*> contextMenuActions();
// TODO: pracovat s těmito věcmi // TODO: pracovat s těmito věcmi
virtual bool canBeEdited() { virtual bool canBeEdited() {

View File

@ -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<QAction*> 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) { void FormMain::switchVisibility(bool force_hide) {
if (force_hide || isVisible()) { if (force_hide || isVisible()) {
if (SystemTrayIcon::isSystemTrayActivated()) { 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_actionFullscreen, SIGNAL(toggled(bool)), m_statusBar->fullscreenSwitcher(), SLOT(setChecked(bool)));
connect(m_ui->m_menuAddItem, SIGNAL(aboutToShow()), this, SLOT(updateAddItemMenu())); connect(m_ui->m_menuAddItem, SIGNAL(aboutToShow()), this, SLOT(updateAddItemMenu()));
connect(m_ui->m_menuServices, SIGNAL(aboutToShow()), this, SLOT(updateServicesMenu()));
// Menu "File" connections. // Menu "File" connections.
connect(m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds())); connect(m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds()));

View File

@ -79,6 +79,7 @@ class FormMain : public QMainWindow {
private slots: private slots:
void updateAddItemMenu(); void updateAddItemMenu();
void updateServicesMenu();
// Loads web browser menu if user selects to change tabs. // Loads web browser menu if user selects to change tabs.
void loadWebBrowserMenu(int index); void loadWebBrowserMenu(int index);

View File

@ -491,7 +491,7 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) {
m_contextMenuCategories->clear(); m_contextMenuCategories->clear();
} }
QList<QAction*> specific_actions = clicked_item->specificContextMenuActions(); QList<QAction*> specific_actions = clicked_item->contextMenuActions();
m_contextMenuCategories->addActions(QList<QAction*>() << m_contextMenuCategories->addActions(QList<QAction*>() <<
qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << 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); m_contextMenuFeeds = new QMenu(tr("Context menu for categories"), this);
} }
else { 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(); m_contextMenuFeeds->clear();
} }
QList<QAction*> specific_actions = clicked_item->specificContextMenuActions(); QList<QAction*> specific_actions = clicked_item->contextMenuActions();
m_contextMenuFeeds->addActions(QList<QAction*>() << m_contextMenuFeeds->addActions(QList<QAction*>() <<
qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds <<

View File

@ -42,12 +42,17 @@ class ServiceRoot : public RootItem {
// NOTE: Caller does NOT take ownership of created menu! // NOTE: Caller does NOT take ownership of created menu!
virtual QList<QAction*> addItemMenu() = 0; virtual QList<QAction*> 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<QAction*> serviceMenu() = 0;
inline FeedsModel *feedsModel() const { inline FeedsModel *feedsModel() const {
return m_feedsModel; return m_feedsModel;
} }
protected: protected:
FeedsModel *m_feedsModel; FeedsModel *m_feedsModel;
}; };
#endif // SERVICEROOT_H #endif // SERVICEROOT_H

View File

@ -98,7 +98,7 @@ int StandardFeed::countOfUnreadMessages() const {
return m_unreadCount; return m_unreadCount;
} }
QList<QAction*> StandardFeed::specificContextMenuActions() { QList<QAction*> StandardFeed::contextMenuActions() {
return serviceRoot()->getContextMenuForFeed(this); return serviceRoot()->getContextMenuForFeed(this);
} }

View File

@ -61,7 +61,7 @@ class StandardFeed : public Feed {
int countOfAllMessages() const; int countOfAllMessages() const;
int countOfUnreadMessages() const; int countOfUnreadMessages() const;
QList<QAction*> specificContextMenuActions(); QList<QAction*> contextMenuActions();
bool canBeEdited() { bool canBeEdited() {
return true; return true;

View File

@ -297,6 +297,10 @@ QList<QAction*> StandardServiceRoot::addItemMenu() {
return m_addItemMenu; return m_addItemMenu;
} }
QList<QAction*> StandardServiceRoot::serviceMenu() {
return QList<QAction*>();
}
void StandardServiceRoot::assembleCategories(CategoryAssignment categories) { void StandardServiceRoot::assembleCategories(CategoryAssignment categories) {
QHash<int, RootItem*> assignments; QHash<int, RootItem*> assignments;
assignments.insert(NO_PARENT_CATEGORY, this); assignments.insert(NO_PARENT_CATEGORY, this);

View File

@ -49,6 +49,9 @@ class StandardServiceRoot : public ServiceRoot {
// Return "add feed" and "add category" items. // Return "add feed" and "add category" items.
QList<QAction*> addItemMenu(); QList<QAction*> addItemMenu();
// Return menu to be shown in "Services -> service" menu.
QList<QAction*> serviceMenu();
// Returns all standard categories which are lying under given root node. // Returns all standard categories which are lying under given root node.
// This does NOT include the root node even if the node is category. // This does NOT include the root node even if the node is category.
QHash<int,StandardCategory*> categoriesForItem(RootItem *root); QHash<int,StandardCategory*> categoriesForItem(RootItem *root);