diff options
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/generalhandler.cpp | 91 | ||||
| -rw-r--r-- | src/qmmpui/generalhandler.h | 24 |
2 files changed, 93 insertions, 22 deletions
diff --git a/src/qmmpui/generalhandler.cpp b/src/qmmpui/generalhandler.cpp index b371b8253..a7876173e 100644 --- a/src/qmmpui/generalhandler.cpp +++ b/src/qmmpui/generalhandler.cpp @@ -19,6 +19,10 @@ ***************************************************************************/ #include <QDialog> +#include <QMenu> +#include <QWidget> +#include <QAction> + #include "general.h" #include "generalfactory.h" #include "commandlinemanager.h" @@ -31,15 +35,9 @@ GeneralHandler::GeneralHandler(QObject *parent) : QObject(parent) { m_instance = this; - /*m_left = 0; - m_right = 0; - m_time = 0; - m_state = General::Stopped;*/ + m_toolsMenu = 0; + m_playlistMenu = 0; GeneralFactory* factory; - //m_control = new Control(this); - /*connect(m_control, SIGNAL(commandCalled(uint)), SLOT(processCommand(uint))); - connect(m_control, SIGNAL(seekCalled(int)), SIGNAL(seekCalled(int))); - connect(m_control, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int)));*/ foreach(factory, *General::generalFactories()) { if (General::isEnabled(factory)) @@ -67,13 +65,6 @@ void GeneralHandler::setEnabled(GeneralFactory* factory, bool enable) connect (general, SIGNAL(toggleVisibilityCalled()), SIGNAL(toggleVisibilityCalled())); connect (general, SIGNAL(exitCalled()), SIGNAL(exitCalled())); m_generals.insert(factory, general); - //general->setVolume(m_left, m_right); - /*if (m_state != General::Stopped) - { - general->setState(m_state); - general->setSongInfo(m_songInfo); - general->setTime(m_time); - }*/ } else { @@ -96,12 +87,6 @@ void GeneralHandler::showSettings(GeneralFactory* factory, QWidget* parentWidget connect (general, SIGNAL(toggleVisibilityCalled()), SIGNAL(toggleVisibilityCalled())); connect (general, SIGNAL(exitCalled()), SIGNAL(exitCalled())); m_generals[factory] = general; - /*general->setVolume(m_left, m_right); - if (m_state != General::Stopped) - { - general->setState(m_state); - general->setSongInfo(m_songInfo); - }*/ } dialog->deleteLater(); } @@ -119,10 +104,72 @@ bool GeneralHandler::visibilityControl() void GeneralHandler::executeCommand(const QString &opt_str) { - if(CommandLineManager::hasOption(opt_str)) + if (CommandLineManager::hasOption(opt_str)) m_commandLineManager->executeCommand(opt_str); } +void GeneralHandler::addAction(QAction *action, MenuType type) +{ + switch ((int) type) + { + 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); + } +} + +void GeneralHandler::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); +} + +QList<QAction *> GeneralHandler::actions(MenuType type) +{ + if (type == TOOLS_MENU) + return m_toolsActions; + else + return m_playlistActions; +} + +QMenu *GeneralHandler::createMenu(MenuType type, const QString &title, QWidget *parent) +{ + switch ((int) type) + { + 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.data(); + case PLAYLIST_MENU: + if (!m_playlistMenu) + { + m_playlistMenu = new QMenu(title, parent); + m_playlistMenu->addActions(m_toolsActions); + } + else + m_playlistMenu->setTitle(title); + return m_playlistMenu.data(); + } + return 0; +} + GeneralHandler* GeneralHandler::instance() { return m_instance; diff --git a/src/qmmpui/generalhandler.h b/src/qmmpui/generalhandler.h index 689170fce..73386ac0a 100644 --- a/src/qmmpui/generalhandler.h +++ b/src/qmmpui/generalhandler.h @@ -22,6 +22,12 @@ #include <QObject> #include <QMap> +#include <QList> +#include <QPointer> + +class QAction; +class QMenu; +class QWidget; class General; class Control; @@ -31,6 +37,8 @@ class CommandLineManager; /** @author Ilya Kotov <forkotov02@hotmail.ru> */ + +//TODO add documentation class GeneralHandler : public QObject { Q_OBJECT @@ -39,10 +47,22 @@ public: ~GeneralHandler(); + enum MenuType + { + TOOLS_MENU = 0, + PLAYLIST_MENU + }; + void setEnabled(GeneralFactory* factory, bool enable); void showSettings(GeneralFactory* factory, QWidget* parentWidget); bool visibilityControl(); void executeCommand(const QString &opt_str); + //actions + void addAction(QAction *action, MenuType type = TOOLS_MENU); + void removeAction(QAction *action); + QList<QAction *> actions(MenuType type = TOOLS_MENU); + QMenu *createMenu(MenuType type, const QString &title = QString(), QWidget *parent = 0); + static GeneralHandler* instance(); signals: @@ -52,6 +72,10 @@ signals: private: QMap <GeneralFactory*, General*> m_generals; CommandLineManager *m_commandLineManager; + QList <QAction*> m_toolsActions; + QList <QAction*> m_playlistActions; + QPointer<QMenu> m_toolsMenu; + QPointer<QMenu> m_playlistMenu; static GeneralHandler* m_instance; }; |
