From d184b2acecd3a7437ca78a163411d50f6935e55f Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 3 Jul 2011 09:41:52 +0000 Subject: renamed GeneralHandler git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2260 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmpui/CMakeLists.txt | 6 +- src/qmmpui/commandlinemanager.cpp | 4 +- src/qmmpui/general.cpp | 5 -- src/qmmpui/general.h | 15 ---- src/qmmpui/generalhandler.cpp | 179 -------------------------------------- src/qmmpui/generalhandler.h | 131 ---------------------------- src/qmmpui/qmmpui.pro | 12 +-- src/qmmpui/uihelper.cpp | 175 +++++++++++++++++++++++++++++++++++++ src/qmmpui/uihelper.h | 136 +++++++++++++++++++++++++++++ 9 files changed, 322 insertions(+), 341 deletions(-) delete mode 100644 src/qmmpui/generalhandler.cpp delete mode 100644 src/qmmpui/generalhandler.h create mode 100644 src/qmmpui/uihelper.cpp create mode 100644 src/qmmpui/uihelper.h (limited to 'src/qmmpui') diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt index f4692e4fd..0f7884c23 100644 --- a/src/qmmpui/CMakeLists.txt +++ b/src/qmmpui/CMakeLists.txt @@ -24,7 +24,7 @@ link_directories(${CMAKE_CURRENT_BINARY_DIR}/../qmmp) SET(libqmmpui_SRCS general.cpp - generalhandler.cpp + uihelper.cpp playlistparser.cpp commandlinemanager.cpp filedialog.cpp @@ -46,7 +46,7 @@ SET(libqmmpui_SRCS SET(libqmmpui_MOC_HDRS generalfactory.h general.h - generalhandler.h + uihelper.h playlistparser.h playlistformat.h commandlinemanager.h @@ -72,7 +72,7 @@ SET(libqmmpui_MOC_HDRS SET(libqmmpui_DEVEL_HDRS generalfactory.h general.h - generalhandler.h + uihelper.h playlistformat.h playlistparser.h commandlinemanager.h diff --git a/src/qmmpui/commandlinemanager.cpp b/src/qmmpui/commandlinemanager.cpp index fde1da6d4..e4e8dfab1 100644 --- a/src/qmmpui/commandlinemanager.cpp +++ b/src/qmmpui/commandlinemanager.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include "commandlinemanager.h" @@ -70,7 +70,7 @@ void CommandLineManager::checkOptions() QString CommandLineManager::executeCommand(const QString& opt_str, const QStringList &args) { checkOptions(); - if(!GeneralHandler::instance() || !SoundCore::instance() || !MediaPlayer::instance()) + if(!UiHelper::instance() || !SoundCore::instance() || !MediaPlayer::instance()) { qWarning("CommandLineManager: player objects are not created"); return QString(); diff --git a/src/qmmpui/general.cpp b/src/qmmpui/general.cpp index 2c9bef7c4..ebe462715 100644 --- a/src/qmmpui/general.cpp +++ b/src/qmmpui/general.cpp @@ -69,11 +69,6 @@ General::General(QObject *parent) General::~General() {} -void General::exit() -{ - emit exitCalled(); -} - QList *General::factories() { checkFactories(); diff --git a/src/qmmpui/general.h b/src/qmmpui/general.h index 4c80c3de1..96d69b72a 100644 --- a/src/qmmpui/general.h +++ b/src/qmmpui/general.h @@ -61,21 +61,6 @@ public: */ static bool isEnabled(GeneralFactory* factory); -signals: - /*! - * Emitted when exit() slot is called. - */ - void exitCalled(); - /*! - * Emitted when toggleVisibility() slot is called. - */ - void toggleVisibilityCalled(); - -public slots: - /*! - * Tells the player to exit. - */ - void exit(); private: QMap m_strValues; diff --git a/src/qmmpui/generalhandler.cpp b/src/qmmpui/generalhandler.cpp deleted file mode 100644 index 5494b4d22..000000000 --- a/src/qmmpui/generalhandler.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2010 by Ilya Kotov * - * forkotov02@hotmail.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include - -#include "general.h" -#include "generalfactory.h" -#include "commandlinemanager.h" - -#include "generalhandler.h" - -GeneralHandler *GeneralHandler::m_instance = 0; - -GeneralHandler::GeneralHandler(QObject *parent) - : QObject(parent) -{ - m_instance = this; - m_toolsMenu = 0; - m_playlistMenu = 0; - GeneralFactory* factory; - foreach(factory, *General::factories()) - { - if (General::isEnabled(factory)) - { - General *general = factory->create(parent); - connect (general, SIGNAL(toggleVisibilityCalled()), SIGNAL(toggleVisibilityCalled())); - connect (general, SIGNAL(exitCalled()), SIGNAL(exitCalled())); - m_generals.insert(factory, general); - } - } -} - -GeneralHandler::~GeneralHandler() -{} - -void GeneralHandler::setEnabled(GeneralFactory* factory, bool enable) -{ - if (enable == m_generals.keys().contains(factory)) - return; - if (enable) - { - General *general = factory->create(parent()); - connect (general, SIGNAL(toggleVisibilityCalled()), SIGNAL(toggleVisibilityCalled())); - connect (general, SIGNAL(exitCalled()), SIGNAL(exitCalled())); - m_generals.insert(factory, general); - } - else - { - delete m_generals.value(factory); - m_generals.remove(factory); - } - General::setEnabled(factory, enable); -} - -void GeneralHandler::showSettings(GeneralFactory* factory, QWidget* parentWidget) -{ - QDialog *dialog = factory->createConfigDialog(parentWidget); - if (!dialog) - return; - - if (dialog->exec() == QDialog::Accepted && m_generals.keys().contains(factory)) - { - delete m_generals.value(factory); - General *general = factory->create(parent()); - connect (general, SIGNAL(toggleVisibilityCalled()), SIGNAL(toggleVisibilityCalled())); - connect (general, SIGNAL(exitCalled()), SIGNAL(exitCalled())); - m_generals[factory] = general; - } - dialog->deleteLater(); -} - -bool GeneralHandler::visibilityControl() -{ - GeneralFactory* factory; - foreach(factory, *General::factories()) - { - if (General::isEnabled(factory) && factory->properties().visibilityControl) - return true; - } - return false; -} - -void GeneralHandler::addAction(QAction *action, MenuType type) -{ - connect(action, SIGNAL(destroyed (QObject *)), SLOT(removeAction(QObject*))); - 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 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; - 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; - } - return 0; -} - -void GeneralHandler::toggleVisibility() -{ - emit toggleVisibilityCalled(); -} - -GeneralHandler* GeneralHandler::instance() -{ - return m_instance; -} - -void GeneralHandler::removeAction(QObject *action) -{ - removeAction((QAction *) action); -} diff --git a/src/qmmpui/generalhandler.h b/src/qmmpui/generalhandler.h deleted file mode 100644 index 209652434..000000000 --- a/src/qmmpui/generalhandler.h +++ /dev/null @@ -1,131 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2010 by Ilya Kotov * - * forkotov02@hotmail.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef GENERALHANDLER_H -#define GENERALHANDLER_H - -#include -#include -#include -#include -#include - -class QAction; -class QMenu; -class QWidget; -class General; -class Control; -class GeneralFactory; - -/*! @brief The GeneralHandler class provides simple api to access general and command line plugins. - * @author Ilya Kotov - */ -class GeneralHandler : public QObject -{ - Q_OBJECT -public: - /*! - * Object constructor, - * @param parent Parent object - */ - GeneralHandler(QObject *parent = 0); - /*! - * Destructor - */ - ~GeneralHandler(); - /*! - * Enum of menu type - */ - enum MenuType - { - TOOLS_MENU = 0, /*!< tools menu */ - PLAYLIST_MENU /*!< playlist context menu */ - }; - /*! - * Sets whether the general plugin is enabled. - * @param factory General plugin factory. - * @param enable Plugin enable state (\b true - enable, \b false - disable) - */ - void setEnabled(GeneralFactory* factory, bool enable); - /*! - * Shows configuration dialog and updates settings automatically. - * @param factory General plugin factory. - * @param parentWidget Parent widget. - */ - void showSettings(GeneralFactory* factory, QWidget* parentWidget); - /*! - * Returns \b true if one of the general plugin can change visibility, otherwise returns \b false - */ - bool visibilityControl(); - /*! - * Adds the newly created action to the menu with type \b type. - * Menu with type \b type should be created first. - * @param action Pointer of action. - * @param type Menu type. - */ - void addAction(QAction *action, MenuType type = TOOLS_MENU); - /*! - * Removes action \b action from created menus. - */ - void removeAction(QAction *action); - /*! - * Returns a list of actions of the menu type \b type - */ - QList actions(MenuType type = TOOLS_MENU); - /*! - * Creates menu with type \b type - * @param type Menu type. - * @param title Menu title. - * @param parent Parent widget - */ - QMenu *createMenu(MenuType type, const QString &title = QString(), QWidget *parent = 0); - /*! - * Toggles player window visibility. - */ - void toggleVisibility(); - /*! - * Returns a pointer to the object's instance. - */ - static GeneralHandler* instance(); - -signals: - /*! - * Emitted when some general plugin requires to exit. - * Use it to quit application. - */ - void exitCalled(); - /*! - * Emitted when some general plugin requires to toggle visibility. - * Use it to show/hide player's window. - */ - void toggleVisibilityCalled(); - -private slots: - void removeAction(QObject *action); - -private: - QMap m_generals; - QList m_toolsActions; - QList m_playlistActions; - QPointer m_toolsMenu; - QPointer m_playlistMenu; - static GeneralHandler* m_instance; -}; - -#endif diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index b5fa05251..01bda0ae2 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -20,7 +20,6 @@ VERSION = $$QMMP_VERSION unix:target.path = $$LIB_DIR HEADERS += general.h \ generalfactory.h \ - generalhandler.h \ playlistformat.h \ playlistparser.h \ commandlinemanager.h \ @@ -40,9 +39,9 @@ HEADERS += general.h \ metadataformatter.h \ templateeditor.h \ uifactory.h \ - uiloader.h + uiloader.h \ + uihelper.h SOURCES += general.cpp \ - generalhandler.cpp \ playlistparser.cpp \ commandlinemanager.cpp \ filedialog.cpp \ @@ -58,7 +57,8 @@ SOURCES += general.cpp \ playlistmanager.cpp \ metadataformatter.cpp \ templateeditor.cpp \ - uiloader.cpp + uiloader.cpp \ + uihelper.cpp FORMS += forms/detailsdialog.ui \ forms/tageditor.ui \ forms/templateeditor.ui @@ -81,7 +81,6 @@ TRANSLATIONS = translations/libqmmpui_ru.ts \ unix { devel.files += general.h \ generalfactory.h \ - generalhandler.h \ playlistformat.h \ playlistparser.h \ commandlinemanager.h \ @@ -96,7 +95,8 @@ unix { metadataformatter.h \ templateeditor.h \ uifactory.h \ - uiloader.h + uiloader.h \ + uihelper.h devel.path = /include/qmmpui INSTALLS += target \ devel diff --git a/src/qmmpui/uihelper.cpp b/src/qmmpui/uihelper.cpp new file mode 100644 index 000000000..5448725aa --- /dev/null +++ b/src/qmmpui/uihelper.cpp @@ -0,0 +1,175 @@ +/*************************************************************************** + * Copyright (C) 2008-2011 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include "general.h" +#include "generalfactory.h" +#include "uihelper.h" + +UiHelper *UiHelper::m_instance = 0; + +UiHelper::UiHelper(QObject *parent) + : QObject(parent) +{ + m_instance = this; + m_toolsMenu = 0; + m_playlistMenu = 0; + GeneralFactory* factory; + foreach(factory, *General::factories()) + { + if (General::isEnabled(factory)) + { + General *general = factory->create(parent); + m_generals.insert(factory, general); + } + } +} + +UiHelper::~UiHelper() +{} + +void UiHelper::setEnabled(GeneralFactory* factory, bool enable) +{ + if (enable == m_generals.keys().contains(factory)) + return; + if (enable) + { + General *general = factory->create(parent()); + m_generals.insert(factory, general); + } + else + { + delete m_generals.value(factory); + m_generals.remove(factory); + } + General::setEnabled(factory, enable); +} + +void UiHelper::showSettings(GeneralFactory* factory, QWidget* parentWidget) +{ + QDialog *dialog = factory->createConfigDialog(parentWidget); + if (!dialog) + return; + + if (dialog->exec() == QDialog::Accepted && m_generals.keys().contains(factory)) + { + delete m_generals.value(factory); + General *general = factory->create(parent()); + m_generals[factory] = general; + } + dialog->deleteLater(); +} + +bool UiHelper::visibilityControl() +{ + GeneralFactory* factory; + foreach(factory, *General::factories()) + { + if (General::isEnabled(factory) && factory->properties().visibilityControl) + return true; + } + return false; +} + +void UiHelper::addAction(QAction *action, MenuType type) +{ + connect(action, SIGNAL(destroyed (QObject *)), SLOT(removeAction(QObject*))); + 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 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); +} + +QList UiHelper::actions(MenuType type) +{ + if (type == TOOLS_MENU) + return m_toolsActions; + else + return m_playlistActions; +} + +QMenu *UiHelper::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; + 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; + } + return 0; +} + +void UiHelper::toggleVisibility() +{ + emit toggleVisibilityCalled(); +} + +void UiHelper::exit() +{ + emit exitCalled(); +} + +UiHelper* UiHelper::instance() +{ + return m_instance; +} + +void UiHelper::removeAction(QObject *action) +{ + removeAction((QAction *) action); +} diff --git a/src/qmmpui/uihelper.h b/src/qmmpui/uihelper.h new file mode 100644 index 000000000..a44fd22f7 --- /dev/null +++ b/src/qmmpui/uihelper.h @@ -0,0 +1,136 @@ +/*************************************************************************** + * Copyright (C) 2008-2011 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef UiHelper_H +#define UiHelper_H + +#include +#include +#include +#include +#include + +class QAction; +class QMenu; +class QWidget; +class General; +class GeneralFactory; + +/*! @brief The UiHelper class provides simple api to access general plugins and some gui features. + * @author Ilya Kotov + */ +class UiHelper : public QObject +{ + Q_OBJECT +public: + /*! + * Object constructor, + * @param parent Parent object + */ + UiHelper(QObject *parent = 0); + /*! + * Destructor + */ + ~UiHelper(); + /*! + * Enum of menu type + */ + enum MenuType + { + TOOLS_MENU = 0, /*!< tools menu */ + PLAYLIST_MENU /*!< playlist context menu */ + }; + /*! + * Sets whether the general plugin is enabled. + * @param factory General plugin factory. + * @param enable Plugin enable state (\b true - enable, \b false - disable) + */ + void setEnabled(GeneralFactory* factory, bool enable); + /*! + * Shows configuration dialog and updates settings automatically. + * @param factory General plugin factory. + * @param parentWidget Parent widget. + */ + void showSettings(GeneralFactory* factory, QWidget* parentWidget); + /*! + * Returns \b true if one of the general plugin can change visibility, otherwise returns \b false + */ + bool visibilityControl(); + /*! + * Adds the newly created action to the menu with type \b type. + * Menu with type \b type should be created first. + * @param action Pointer of action. + * @param type Menu type. + */ + void addAction(QAction *action, MenuType type = TOOLS_MENU); + /*! + * Removes action \b action from created menus. + */ + void removeAction(QAction *action); + /*! + * Returns a list of actions of the menu type \b type + */ + QList actions(MenuType type = TOOLS_MENU); + /*! + * Creates menu with type \b type + * @param type Menu type. + * @param title Menu title. + * @param parent Parent widget + */ + QMenu *createMenu(MenuType type, const QString &title = QString(), QWidget *parent = 0); + /*! + * Returns a pointer to the object's instance. + */ + static UiHelper* instance(); + +public slots: + /*! + * Toggles player window visibility. + */ + void toggleVisibility(); + /*! + * Tells the player to exit. + */ + void exit(); + +signals: + /*! + * Emitted when some general plugin requires to exit. + * Use it to quit application. + */ + void exitCalled(); + /*! + * Emitted when some general plugin requires to toggle visibility. + * Use it to show/hide player's window. + */ + void toggleVisibilityCalled(); + +private slots: + void removeAction(QObject *action); + +private: + QMap m_generals; + QList m_toolsActions; + QList m_playlistActions; + QPointer m_toolsMenu; + QPointer m_playlistMenu; + static UiHelper* m_instance; +}; + +#endif -- cgit v1.2.3-13-gbd6f