diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 53b424c29..e5f73fa0f 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -63,8 +63,6 @@ FeedsModel::FeedsModel(QObject *parent) connect(m_autoUpdateTimer, SIGNAL(timeout()), this, SLOT(executeNextAutoUpdate())); loadActivatedServiceAccounts(); - - // Setup the timer. updateAutoUpdateStatus(); } diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index c1b8e7d60..e9382209a 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -39,6 +39,7 @@ #include "gui/dialogs/formbackupdatabasesettings.h" #include "gui/dialogs/formrestoredatabasesettings.h" #include "gui/notifications/notification.h" +#include "services/abstract/serviceroot.h" #include "services/standard/gui/formstandardimportexport.h" #include @@ -171,6 +172,37 @@ void FormMain::switchMainMenu() { m_ui->m_menuBar->setVisible(m_ui->m_actionSwitchMainMenu->isChecked()); } +void FormMain::updateAddItemMenu() { + // TODO: clear nevymaže z paměti. - edit, stačí nastavit parent na to menu + // a při clear to i vymaže z paměti. + m_ui->m_menuAddItem->clear(); + + foreach (ServiceRoot *activated_root, tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) { + QMenu *root_menu = new QMenu(activated_root->title(), m_ui->m_menuAddItem); + QList root_actions = activated_root->specificAddItemActions(); + + root_menu->setIcon(activated_root->icon()); + root_menu->setToolTip(activated_root->description()); + + if (root_actions.isEmpty()) { + QAction *no_action = new QAction(qApp->icons()->fromTheme(QSL("dialog-error")), + tr("No possible actions"), + m_ui->m_menuAddItem); + no_action->setEnabled(false); + root_menu->addAction(no_action); + } + else { + foreach (QAction *action, root_actions) { + action->setParent(root_menu); + } + + root_menu->addActions(root_actions); + } + + m_ui->m_menuAddItem->addMenu(root_menu); + } +} + void FormMain::switchVisibility(bool force_hide) { if (force_hide || isVisible()) { if (SystemTrayIcon::isSystemTrayActivated()) { @@ -335,6 +367,8 @@ void FormMain::createConnections() { connect(m_statusBar->fullscreenSwitcher(), SIGNAL(toggled(bool)), m_ui->m_actionFullscreen, 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())); + // Menu "File" connections. connect(m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds())); connect(m_ui->m_actionImportFeeds, SIGNAL(triggered()), this, SLOT(importFeeds())); @@ -395,7 +429,6 @@ void FormMain::loadWebBrowserMenu(int index) { } void FormMain::exportFeeds() { - // TODO: crash QPointer form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(), this); form.data()->setMode(FeedsImportExportModel::Export); @@ -404,7 +437,6 @@ void FormMain::exportFeeds() { } void FormMain::importFeeds() { - // TODO: crash QPointer form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(), this); form.data()->setMode(FeedsImportExportModel::Import); diff --git a/src/gui/dialogs/formmain.h b/src/gui/dialogs/formmain.h index 7537acdcd..2f212f8f8 100755 --- a/src/gui/dialogs/formmain.h +++ b/src/gui/dialogs/formmain.h @@ -78,6 +78,8 @@ class FormMain : public QMainWindow { void switchMainMenu(); private slots: + void updateAddItemMenu(); + // 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 759e320fd..d3ba8f629 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -488,6 +488,9 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) { m_contextMenuCategories = new QMenu(tr("Context menu for categories"), this); } else { + + // TODO: clear nevymaže z paměti. + // http://doc.qt.io/qt-4.8/qmenu.html#clear m_contextMenuCategories->clear(); } @@ -503,6 +506,11 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) { if (!specific_actions.isEmpty()) { m_contextMenuCategories->addSeparator(); + + foreach (QAction *action, specific_actions) { + action->setParent(m_contextMenuCategories); + } + m_contextMenuCategories->addActions(specific_actions); } } @@ -514,6 +522,8 @@ void FeedsView::initializeContextMenuFeeds(RootItem *clicked_item) { 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(); } @@ -529,6 +539,11 @@ void FeedsView::initializeContextMenuFeeds(RootItem *clicked_item) { if (!specific_actions.isEmpty()) { m_contextMenuFeeds->addSeparator(); + + foreach (QAction *action, specific_actions) { + action->setParent(m_contextMenuFeeds); + } + m_contextMenuFeeds->addActions(specific_actions); } } diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index c175a1b66..3e59e98c1 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -100,7 +100,7 @@ int StandardFeed::countOfUnreadMessages() const { } QList StandardFeed::specificContextMenuActions() { - return serviceRoot()->getMenuForFeed(this); + return serviceRoot()->getContextMenuForFeed(this); } StandardServiceRoot *StandardFeed::serviceRoot() { diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index 0536b69be..c028dadf3 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -211,7 +211,7 @@ QHash StandardServiceRoot::allCategories() { return categoriesForItem(this); } -QList StandardServiceRoot::getMenuForFeed(StandardFeed *feed) { +QList StandardServiceRoot::getContextMenuForFeed(StandardFeed *feed) { QList list; // Fetch feed metadata. diff --git a/src/services/standard/standardserviceroot.h b/src/services/standard/standardserviceroot.h index 9309b35f3..60409ea29 100755 --- a/src/services/standard/standardserviceroot.h +++ b/src/services/standard/standardserviceroot.h @@ -53,7 +53,8 @@ class StandardServiceRoot : public ServiceRoot { // consists of ID of parent item and pointer to category. QHash allCategories(); - QList getMenuForFeed(StandardFeed *feed); + // Returns context specific menu actions for given feed. + QList getContextMenuForFeed(StandardFeed *feed); // Access to standard recycle bin. StandardRecycleBin *recycleBin() const; @@ -63,6 +64,7 @@ class StandardServiceRoot : public ServiceRoot { // NOTE: This is used for import/export of the model. bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message); + // Return "add feed" and "add category" items. QList specificAddItemActions(); private: