aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/General/hal/halplugin.cpp4
-rw-r--r--src/plugins/General/streambrowser/streambrowser.cpp4
-rw-r--r--src/plugins/General/udisks2/udisks2plugin.cpp2
-rw-r--r--src/plugins/Ui/qsui/mainwindow.cpp3
-rw-r--r--src/plugins/Ui/skinned/playlist.cpp1
-rw-r--r--src/qmmpui/uihelper.cpp77
-rw-r--r--src/qmmpui/uihelper.h16
7 files changed, 51 insertions, 56 deletions
diff --git a/src/plugins/General/hal/halplugin.cpp b/src/plugins/General/hal/halplugin.cpp
index dfea19cf9..cd4ee96de 100644
--- a/src/plugins/General/hal/halplugin.cpp
+++ b/src/plugins/General/hal/halplugin.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2009-2014 by Ilya Kotov *
+ * Copyright (C) 2009-2018 by Ilya Kotov *
* forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -179,7 +179,7 @@ void HalPlugin::updateActions()
action->setIcon(qApp->style()->standardIcon(QStyle::SP_DriveHDIcon));
m_actions->addAction(action);
- UiHelper::instance()->addAction(action, UiHelper::TOOLS_MENU);
+ UiHelper::instance()->addAction(action, UiHelper::ADD_MENU);
addPath(dev_path);
}
}
diff --git a/src/plugins/General/streambrowser/streambrowser.cpp b/src/plugins/General/streambrowser/streambrowser.cpp
index 69fbcd836..87cb86b69 100644
--- a/src/plugins/General/streambrowser/streambrowser.cpp
+++ b/src/plugins/General/streambrowser/streambrowser.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2012 by Ilya Kotov *
+ * Copyright (C) 2012-2018 by Ilya Kotov *
* forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -33,7 +33,7 @@ StreamBrowser::StreamBrowser(QObject *parent) : QObject(parent)
m_action = new QAction(tr("Stream Browser"), this);
m_action->setIcon(QIcon::fromTheme("applications-internet"));
m_action->setShortcut(tr("Ctrl+U"));
- UiHelper::instance()->addAction(m_action, UiHelper::TOOLS_MENU);
+ UiHelper::instance()->addAction(m_action, UiHelper::ADD_MENU);
connect (m_action, SIGNAL(triggered ()), SLOT(showStreamWindow()));
}
diff --git a/src/plugins/General/udisks2/udisks2plugin.cpp b/src/plugins/General/udisks2/udisks2plugin.cpp
index 8a37b00e1..2f1f6d675 100644
--- a/src/plugins/General/udisks2/udisks2plugin.cpp
+++ b/src/plugins/General/udisks2/udisks2plugin.cpp
@@ -153,7 +153,7 @@ void UDisks2Plugin::updateActions()
action->setText(actionText);
action->setData(dev_path);
m_actions->addAction(action);
- UiHelper::instance()->addAction(action, UiHelper::TOOLS_MENU);
+ UiHelper::instance()->addAction(action, UiHelper::ADD_MENU);
addPath(dev_path);
}
}
diff --git a/src/plugins/Ui/qsui/mainwindow.cpp b/src/plugins/Ui/qsui/mainwindow.cpp
index 42a34e1f2..d523aa041 100644
--- a/src/plugins/Ui/qsui/mainwindow.cpp
+++ b/src/plugins/Ui/qsui/mainwindow.cpp
@@ -476,7 +476,8 @@ void MainWindow::createActions()
m_ui.menuFile->addAction(SET_ACTION(ActionManager::PL_ADD_FILE, this, SLOT(addFiles())));
m_ui.menuFile->addAction(SET_ACTION(ActionManager::PL_ADD_DIRECTORY, this, SLOT(addDir())));
m_ui.menuFile->addAction(SET_ACTION(ActionManager::PL_ADD_URL, this, SLOT(addUrl())));
- m_ui.menuFile->addSeparator();
+ QAction *sep = m_ui.menuFile->addSeparator();
+ UiHelper::instance()->registerMenu(UiHelper::ADD_MENU, m_ui.menuFile, sep);
m_ui.menuFile->addAction(SET_ACTION(ActionManager::PL_NEW, m_pl_manager, SLOT(createPlayList())));
m_ui.menuFile->addAction(SET_ACTION(ActionManager::PL_CLOSE, this, SLOT(removePlaylist())));
m_ui.menuFile->addAction(SET_ACTION(ActionManager::PL_RENAME, this, SLOT(renameTab())));
diff --git a/src/plugins/Ui/skinned/playlist.cpp b/src/plugins/Ui/skinned/playlist.cpp
index edb87cc41..67a5b3d93 100644
--- a/src/plugins/Ui/skinned/playlist.cpp
+++ b/src/plugins/Ui/skinned/playlist.cpp
@@ -210,6 +210,7 @@ void PlayList::createActions()
m_addMenu->addAction(SET_ACTION(ActionManager::PL_ADD_FILE, parent(), SLOT(addFile())));
m_addMenu->addAction(SET_ACTION(ActionManager::PL_ADD_DIRECTORY, parent(), SLOT(addDir())));
m_addMenu->addAction(SET_ACTION(ActionManager::PL_ADD_URL, parent(), SLOT(addUrl())));
+ UiHelper::instance()->registerMenu(UiHelper::ADD_MENU, m_addMenu);
//sub menu
m_subMenu->addAction(SET_ACTION(ActionManager::PL_REMOVE_SELECTED, m_pl_manager, SLOT(removeSelected())));
m_subMenu->addAction(SET_ACTION(ActionManager::PL_REMOVE_ALL, m_pl_manager, SLOT(clear())));
diff --git a/src/qmmpui/uihelper.cpp b/src/qmmpui/uihelper.cpp
index 4a6bd6bc2..1d965a9b6 100644
--- a/src/qmmpui/uihelper.cpp
+++ b/src/qmmpui/uihelper.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008-2017 by Ilya Kotov *
+ * Copyright (C) 2008-2018 by Ilya Kotov *
* forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -44,8 +44,6 @@ UiHelper::UiHelper(QObject *parent)
: QObject(parent)
{
m_instance = this;
- m_toolsMenu = 0;
- m_playlistMenu = 0;
m_jumpDialog = 0;
m_model = 0;
General::create(parent);
@@ -73,64 +71,53 @@ bool UiHelper::visibilityControl()
void UiHelper::addAction(QAction *action, MenuType type)
{
connect(action, SIGNAL(destroyed (QObject *)), SLOT(removeAction(QObject*)));
- switch ((int) type)
+
+ if(!m_menus[type].actions.contains(action))
+ m_menus[type].actions.append(action);
+ if(m_menus[type].menu && !m_menus[type].menu->actions().contains(action))
{
- case TOOLS_MENU:
- if (!m_toolsActions.contains(action))
- m_toolsActions.append(action);
- if (m_toolsMenu && !m_toolsMenu->actions ().contains(action))
- m_toolsMenu->addAction(action);
- break;
- case PLAYLIST_MENU:
- if (!m_playlistActions.contains(action))
- m_playlistActions.append(action);
- if (m_playlistMenu && !m_playlistMenu->actions ().contains(action))
- m_playlistMenu->addAction(action);
+ if(m_menus[type].before)
+ m_menus[type].menu->insertAction(m_menus[type].before, action);
+ else
+ m_menus[type].menu->addAction(action);
}
}
void UiHelper::removeAction(QAction *action)
{
- m_toolsActions.removeAll(action);
- if (m_toolsMenu)
- m_toolsMenu->removeAction(action);
- m_playlistActions.removeAll(action);
- if (m_playlistMenu)
- m_playlistMenu->removeAction(action);
+ foreach(MenuType type, m_menus.keys())
+ {
+ m_menus[type].actions.removeAll(action);
+ if(m_menus[type].menu)
+ m_menus[type].menu->removeAction(action);
+ }
}
QList<QAction *> UiHelper::actions(MenuType type)
{
- if (type == TOOLS_MENU)
- return m_toolsActions;
- else
- return m_playlistActions;
+ return m_menus[type].actions;
}
QMenu *UiHelper::createMenu(MenuType type, const QString &title, QWidget *parent)
{
- switch ((int) type)
+ if(m_menus[type].menu)
{
- case TOOLS_MENU:
- if (!m_toolsMenu)
- {
- m_toolsMenu = new QMenu(title, parent);
- m_toolsMenu->addActions(m_toolsActions);
- }
- else
- m_toolsMenu->setTitle(title);
- return m_toolsMenu;
- case PLAYLIST_MENU:
- if (!m_playlistMenu)
- {
- m_playlistMenu = new QMenu(title, parent);
- m_playlistMenu->addActions(m_playlistActions);
- }
- else
- m_playlistMenu->setTitle(title);
- return m_playlistMenu;
+ m_menus[type].menu->setTitle(title);
+ return m_menus[type].menu;
}
- return 0;
+ m_menus[type].menu = new QMenu(title, parent);
+ m_menus[type].menu->addActions(m_menus[type].actions);
+ return m_menus[type].menu;
+}
+
+void UiHelper::registerMenu(UiHelper::MenuType type, QMenu *menu, QAction *before)
+{
+ m_menus[type].menu = menu;
+ m_menus[type].before = before;
+ if(before)
+ m_menus[type].menu->insertActions(before, m_menus[type].actions);
+ else
+ m_menus[type].menu->addActions(m_menus[type].actions);
}
void UiHelper::addFiles(QWidget *parent, PlayListModel *model)
diff --git a/src/qmmpui/uihelper.h b/src/qmmpui/uihelper.h
index 49636d0f7..46844e788 100644
--- a/src/qmmpui/uihelper.h
+++ b/src/qmmpui/uihelper.h
@@ -60,7 +60,8 @@ public:
enum MenuType
{
TOOLS_MENU = 0, /*!< tools menu */
- PLAYLIST_MENU /*!< playlist context menu */
+ PLAYLIST_MENU, /*!< playlist context menu */
+ ADD_MENU
};
/*!
* Returns \b true if one of the general plugin can change visibility, otherwise returns \b false
@@ -88,6 +89,8 @@ public:
* @param parent Parent widget
*/
QMenu *createMenu(MenuType type, const QString &title = QString(), QWidget *parent = 0);
+ void registerMenu(MenuType type, QMenu *menu, QAction *before = 0);
+
/*!
* Opens 'Add Files' dialog
* @param parent Parent widget
@@ -181,10 +184,13 @@ private slots:
private:
QMap <GeneralFactory*, General*> m_generals;
- QList <QAction*> m_toolsActions;
- QList <QAction*> m_playlistActions;
- QPointer<QMenu> m_toolsMenu;
- QPointer<QMenu> m_playlistMenu;
+ struct MenuData
+ {
+ QPointer<QMenu> menu;
+ QPointer<QAction> before;
+ QList<QAction*> actions;
+ };
+ QMap<MenuType, MenuData> m_menus;
QString m_lastDir;
QPointer <JumpToTrackDialog> m_jumpDialog;
PlayListModel *m_model;