mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-31 01:24:49 +01:00
Work on menus - 2.
This commit is contained in:
parent
fa976120b8
commit
2d97915d86
@ -77,9 +77,7 @@ class RootItem : public QObject {
|
||||
}
|
||||
|
||||
// Returns list of specific actions which can be done with the item.
|
||||
// NOTE: This method should always create new actions in memory
|
||||
// before returning them because caller takes ownership of any
|
||||
// actions returned from here.
|
||||
// NOTE: Ownership of returned actions is not switched to caller, free them when needed.
|
||||
virtual QList<QAction*> specificContextMenuActions();
|
||||
|
||||
// TODO: pracovat s těmito věcmi
|
||||
|
@ -177,19 +177,22 @@ void FormMain::updateAddItemMenu() {
|
||||
m_ui->m_menuAddItem->clear();
|
||||
|
||||
foreach (ServiceRoot *activated_root, tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) {
|
||||
QMenu *root_menu = activated_root->addItemMenu();
|
||||
QMenu *root_menu = new QMenu(activated_root->title(), m_ui->m_menuAddItem);
|
||||
root_menu->setIcon(activated_root->icon());
|
||||
root_menu->setToolTip(activated_root->description());
|
||||
|
||||
if (root_menu == NULL) {
|
||||
root_menu = new QMenu(activated_root->title(), m_ui->m_menuAddItem);
|
||||
root_menu->setIcon(activated_root->icon());
|
||||
root_menu->setToolTip(activated_root->description());
|
||||
QList<QAction*> root_actions = activated_root->addItemMenu();
|
||||
|
||||
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 {
|
||||
root_menu->addActions(root_actions);
|
||||
}
|
||||
|
||||
m_ui->m_menuAddItem->addMenu(root_menu);
|
||||
}
|
||||
|
@ -488,9 +488,6 @@ 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();
|
||||
}
|
||||
|
||||
@ -506,11 +503,6 @@ 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);
|
||||
}
|
||||
}
|
||||
@ -539,11 +531,6 @@ 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);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
class FeedsModel;
|
||||
class QMenu;
|
||||
class QAction;
|
||||
|
||||
// THIS IS the root node of the service.
|
||||
// NOTE: The root usually contains some core functionality of the
|
||||
@ -40,9 +40,7 @@ class ServiceRoot : public RootItem {
|
||||
// b) Add new category
|
||||
// c) ...
|
||||
// NOTE: Caller does NOT take ownership of created menu!
|
||||
virtual QMenu* addItemMenu() = 0;
|
||||
|
||||
// TODO: dodělat menu, které se zobrazi v menubaru "Services -> tato služba".
|
||||
virtual QList<QAction*> addItemMenu() = 0;
|
||||
|
||||
inline FeedsModel *feedsModel() const {
|
||||
return m_feedsModel;
|
||||
|
@ -32,11 +32,12 @@
|
||||
#include <QSqlError>
|
||||
#include <QStack>
|
||||
#include <QCoreApplication>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
|
||||
StandardServiceRoot::StandardServiceRoot(bool load_from_db, FeedsModel *feeds_model, RootItem *parent)
|
||||
: ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)), m_addItemMenu(NULL) {
|
||||
: ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)),
|
||||
m_addItemMenu(QList<QAction*>()), m_feedContextMenu(QList<QAction*>()), m_actionFeedFetchMetadata(NULL) {
|
||||
m_title = qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME);
|
||||
m_icon = StandardServiceEntryPoint().icon();
|
||||
m_description = tr("This is obligatory service account for standard RSS/RDF/ATOM feeds.");
|
||||
@ -48,9 +49,8 @@ StandardServiceRoot::StandardServiceRoot(bool load_from_db, FeedsModel *feeds_mo
|
||||
}
|
||||
|
||||
StandardServiceRoot::~StandardServiceRoot() {
|
||||
if (m_addItemMenu != NULL) {
|
||||
delete m_addItemMenu;
|
||||
}
|
||||
qDeleteAll(m_addItemMenu);
|
||||
qDeleteAll(m_feedContextMenu);
|
||||
}
|
||||
|
||||
bool StandardServiceRoot::canBeEdited() {
|
||||
@ -216,14 +216,17 @@ QHash<int,StandardCategory*> StandardServiceRoot::allCategories() {
|
||||
}
|
||||
|
||||
QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed *feed) {
|
||||
QList<QAction*> list;
|
||||
if (m_feedContextMenu.isEmpty()) {
|
||||
// Initialize.
|
||||
m_actionFeedFetchMetadata = new QAction(qApp->icons()->fromTheme(QSL("download-manager")), tr("Fetch metadata"), NULL);
|
||||
m_feedContextMenu.append(m_actionFeedFetchMetadata);
|
||||
}
|
||||
|
||||
// Fetch feed metadata.
|
||||
QAction *action_fetch_metadata = new QAction(qApp->icons()->fromTheme(QSL("download-manager")), tr("Fetch metadata"), NULL);
|
||||
connect(action_fetch_metadata, SIGNAL(triggered()), feed, SLOT(fetchMetadataForItself()));
|
||||
// Make connections.
|
||||
disconnect(m_actionFeedFetchMetadata, SIGNAL(triggered()), 0, 0);
|
||||
connect(m_actionFeedFetchMetadata, SIGNAL(triggered()), feed, SLOT(fetchMetadataForItself()));
|
||||
|
||||
list.append(action_fetch_metadata);
|
||||
return list;
|
||||
return m_feedContextMenu;
|
||||
}
|
||||
|
||||
void StandardServiceRoot::assembleFeeds(FeedAssignment feeds) {
|
||||
@ -328,14 +331,10 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model,
|
||||
return !some_feed_category_error;
|
||||
}
|
||||
|
||||
QMenu *StandardServiceRoot::addItemMenu() {
|
||||
if (m_addItemMenu == NULL) {
|
||||
m_addItemMenu = new QMenu(title(), NULL);
|
||||
m_addItemMenu->setIcon(icon());
|
||||
m_addItemMenu->setToolTip(description());
|
||||
|
||||
QList<QAction*> StandardServiceRoot::addItemMenu() {
|
||||
if (m_addItemMenu.isEmpty()) {
|
||||
// TODO: Add items.
|
||||
m_addItemMenu->addAction(new QAction("abc", m_addItemMenu));
|
||||
m_addItemMenu.append(new QAction("abc", this));
|
||||
}
|
||||
|
||||
return m_addItemMenu;
|
||||
|
@ -66,7 +66,7 @@ class StandardServiceRoot : public ServiceRoot {
|
||||
bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message);
|
||||
|
||||
// Return "add feed" and "add category" items.
|
||||
QMenu *addItemMenu();
|
||||
QList<QAction*> addItemMenu();
|
||||
|
||||
private:
|
||||
void loadFromDatabase();
|
||||
@ -79,7 +79,10 @@ class StandardServiceRoot : public ServiceRoot {
|
||||
StandardRecycleBin *m_recycleBin;
|
||||
|
||||
// Menus.
|
||||
QMenu *m_addItemMenu;
|
||||
QList<QAction*> m_addItemMenu;
|
||||
QList<QAction*> m_feedContextMenu;
|
||||
|
||||
QAction *m_actionFeedFetchMetadata;
|
||||
};
|
||||
|
||||
#endif // STANDARDSERVICEROOT_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user