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/app/builtincommandlineoption.cpp | 21 ++- src/app/qmmpstarter.cpp | 4 +- src/plugins/General/covermanager/covermanager.cpp | 7 +- src/plugins/General/fileops/fileops.cpp | 10 +- src/plugins/General/hal/halplugin.cpp | 6 +- src/plugins/General/hotkey/hotkeymanager.cpp | 4 +- src/plugins/General/lyrics/lyrics.cpp | 4 +- src/plugins/General/statusicon/statusicon.cpp | 4 +- src/plugins/General/udisks/udisksplugin.cpp | 6 +- src/plugins/Ui/skinned/configdialog.cpp | 6 +- src/plugins/Ui/skinned/mainwindow.cpp | 6 +- src/plugins/Ui/skinned/mainwindow.h | 4 +- src/plugins/Ui/skinned/playlist.cpp | 4 +- src/plugins/Ui/skinned/pluginitem.cpp | 6 +- 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 ++++++++++++++++ 23 files changed, 373 insertions(+), 382 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 diff --git a/src/app/builtincommandlineoption.cpp b/src/app/builtincommandlineoption.cpp index 68ad43771..f9d246c8f 100644 --- a/src/app/builtincommandlineoption.cpp +++ b/src/app/builtincommandlineoption.cpp @@ -21,7 +21,9 @@ #include #include #include -#include +#include +#include +#include #include "builtincommandlineoption.h" BuiltinCommandLineOption::BuiltinCommandLineOption(QObject *parent) : QObject(parent) @@ -148,21 +150,30 @@ void BuiltinCommandLineOption::executeCommand(const QString &option_string, } else if (option_string == "--quit" || option_string == "-q") { - //mw->close(); qApp->closeAllWindows(); qApp->quit(); } else if (option_string == "--toggle-visibility") { - GeneralHandler::instance()->toggleVisibility(); + UiHelper::instance()->toggleVisibility(); } else if (option_string == "--add-file") { - //mw->addFile(); + QString m_lastDir; + QStringList filters; + filters << tr("All Supported Bitstreams")+" (" + + MetaDataManager::instance()->nameFilters().join (" ") +")"; + filters << MetaDataManager::instance()->filters(); + FileDialog::popup(qApp->activeWindow(), FileDialog::AddDirsFiles, &m_lastDir, + pl_manager->selectedPlayList(), SLOT(add(const QStringList&)), + tr("Select one or more files to open"), filters.join(";;")); } else if (option_string == "--add-dir") { - //mw->addDir(); + QString m_lastDir; + FileDialog::popup(qApp->activeWindow(), FileDialog::AddDirs, &m_lastDir, + pl_manager->selectedPlayList(), SLOT(add(const QStringList&)), + tr("Choose a directory")); } else if (option_string == "--volume" && !args.isEmpty()) { diff --git a/src/app/qmmpstarter.cpp b/src/app/qmmpstarter.cpp index e30036ee4..f62ec79be 100644 --- a/src/app/qmmpstarter.cpp +++ b/src/app/qmmpstarter.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include "qmmpstarter.h" #include "builtincommandlineoption.h" @@ -139,7 +139,7 @@ void QMMPStarter::startPlayer() //additional featuries new PlaylistParser(this); - new GeneralHandler(this); + new UiHelper(this); //interface UiFactory *factory = UiLoader::currentUiFactory(); diff --git a/src/plugins/General/covermanager/covermanager.cpp b/src/plugins/General/covermanager/covermanager.cpp index 5b00b6078..528c6c18d 100644 --- a/src/plugins/General/covermanager/covermanager.cpp +++ b/src/plugins/General/covermanager/covermanager.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009-2010 by Ilya Kotov * + * Copyright (C) 2009-2011 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -21,11 +21,10 @@ #include #include #include -#include +#include #include #include #include -#include #include #include #include "coverwidget.h" @@ -35,7 +34,7 @@ CoverManager::CoverManager(QObject *parent) : General(parent) { m_action = new QAction(tr("Show Cover"), this); m_action->setShortcut(tr("Ctrl+M")); - GeneralHandler::instance()->addAction(m_action, GeneralHandler::PLAYLIST_MENU); + UiHelper::instance()->addAction(m_action, UiHelper::PLAYLIST_MENU); connect (m_action, SIGNAL(triggered ()), SLOT(showWindow())); } diff --git a/src/plugins/General/fileops/fileops.cpp b/src/plugins/General/fileops/fileops.cpp index 1bea2038a..e661b646c 100644 --- a/src/plugins/General/fileops/fileops.cpp +++ b/src/plugins/General/fileops/fileops.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009-2010 by Ilya Kotov * + * Copyright (C) 2009-2011 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -51,7 +51,7 @@ FileOps::FileOps(QObject *parent) settings.beginGroup("FileOps"); int count = settings.value("count", 0).toInt(); if (count > 0) - GeneralHandler::instance()->addAction(separator1, GeneralHandler::PLAYLIST_MENU); + UiHelper::instance()->addAction(separator1, UiHelper::PLAYLIST_MENU); else return; @@ -68,12 +68,12 @@ FileOps::FileOps(QObject *parent) action->setShortcut(settings.value(QString("hotkey_%1").arg(i)).toString()); connect (action, SIGNAL (triggered (bool)), mapper, SLOT (map())); mapper->setMapping(action, i); - GeneralHandler::instance()->addAction(action, GeneralHandler::PLAYLIST_MENU); + UiHelper::instance()->addAction(action, UiHelper::PLAYLIST_MENU); } } settings.endGroup(); connect(mapper, SIGNAL(mapped(int)), SLOT(execAction(int))); - GeneralHandler::instance()->addAction(separator2, GeneralHandler::PLAYLIST_MENU); + UiHelper::instance()->addAction(separator2, UiHelper::PLAYLIST_MENU); } FileOps::~FileOps() diff --git a/src/plugins/General/hal/halplugin.cpp b/src/plugins/General/hal/halplugin.cpp index 7d17b037d..c500ae2b4 100644 --- a/src/plugins/General/hal/halplugin.cpp +++ b/src/plugins/General/hal/halplugin.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -181,7 +181,7 @@ void HalPlugin::updateActions() action->setIcon(qApp->style()->standardIcon(QStyle::SP_DriveHDIcon)); m_actions->addAction(action); - GeneralHandler::instance()->addAction(action, GeneralHandler::TOOLS_MENU); + UiHelper::instance()->addAction(action, UiHelper::TOOLS_MENU); addPath(dev_path); } } @@ -191,7 +191,7 @@ void HalPlugin::updateActions() if (!findDevice(action)) { m_actions->removeAction(action); - GeneralHandler::instance()->removeAction(action); + UiHelper::instance()->removeAction(action); removePath(action->data().toString()); action->deleteLater(); } diff --git a/src/plugins/General/hotkey/hotkeymanager.cpp b/src/plugins/General/hotkey/hotkeymanager.cpp index 9eddce3a0..6a6b3b685 100644 --- a/src/plugins/General/hotkey/hotkeymanager.cpp +++ b/src/plugins/General/hotkey/hotkeymanager.cpp @@ -45,7 +45,7 @@ extern "C" #include #include #include -#include +#include #include "hotkeymanager.h" quint32 Hotkey::defaultKey() @@ -165,7 +165,7 @@ bool HotkeyManager::eventFilter(QObject* o, QEvent* e) MediaPlayer::instance()->previous(); break; case Hotkey::SHOW_HIDE: - GeneralHandler::instance()->toggleVisibility(); + UiHelper::instance()->toggleVisibility(); break; case Hotkey::VOLUME_UP: case Hotkey::VOLUME_DOWN: diff --git a/src/plugins/General/lyrics/lyrics.cpp b/src/plugins/General/lyrics/lyrics.cpp index 779f19cf1..e3fe003c3 100644 --- a/src/plugins/General/lyrics/lyrics.cpp +++ b/src/plugins/General/lyrics/lyrics.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -34,7 +34,7 @@ Lyrics::Lyrics(QObject *parent) { m_action = new QAction(tr("View Lyrics"), this); m_action->setShortcut(tr("Ctrl+L")); - GeneralHandler::instance()->addAction(m_action, GeneralHandler::PLAYLIST_MENU); + UiHelper::instance()->addAction(m_action, UiHelper::PLAYLIST_MENU); connect (m_action, SIGNAL(triggered ()), SLOT(showLyrics())); } diff --git a/src/plugins/General/statusicon/statusicon.cpp b/src/plugins/General/statusicon/statusicon.cpp index 8311f7137..28b765e19 100644 --- a/src/plugins/General/statusicon/statusicon.cpp +++ b/src/plugins/General/statusicon/statusicon.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include "qmmptrayicon.h" #include "statusicon.h" @@ -130,7 +130,7 @@ void StatusIcon::showMetaData() void StatusIcon::trayActivated(QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::Trigger) - GeneralHandler::instance()->toggleVisibility(); + UiHelper::instance()->toggleVisibility(); else if (reason == QSystemTrayIcon::MiddleClick) { if (SoundCore::instance()->state() == Qmmp::Stopped) diff --git a/src/plugins/General/udisks/udisksplugin.cpp b/src/plugins/General/udisks/udisksplugin.cpp index 471d64a41..57b54eb9d 100644 --- a/src/plugins/General/udisks/udisksplugin.cpp +++ b/src/plugins/General/udisks/udisksplugin.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -174,7 +174,7 @@ void UDisksPlugin::updateActions() action->setText(actionText); action->setData(dev_path); m_actions->addAction(action); - GeneralHandler::instance()->addAction(action, GeneralHandler::TOOLS_MENU); + UiHelper::instance()->addAction(action, UiHelper::TOOLS_MENU); addPath(dev_path); } } @@ -184,7 +184,7 @@ void UDisksPlugin::updateActions() if (!findDevice(action)) { m_actions->removeAction(action); - GeneralHandler::instance()->removeAction(action); + UiHelper::instance()->removeAction(action); removePath(action->data().toString()); action->deleteLater(); } diff --git a/src/plugins/Ui/skinned/configdialog.cpp b/src/plugins/Ui/skinned/configdialog.cpp index 26a71e38d..94e32b0f2 100644 --- a/src/plugins/Ui/skinned/configdialog.cpp +++ b/src/plugins/Ui/skinned/configdialog.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -158,8 +158,8 @@ void ConfigDialog::on_contentsWidget_currentItemChanged (QListWidgetItem *curren if (!current) current = previous; ui.stackedWidget->setCurrentIndex (ui.contentsWidget->row (current)); - ui.hiddenCheckBox->setEnabled(GeneralHandler::instance()->visibilityControl()); - ui.hideOnCloseCheckBox->setEnabled(GeneralHandler::instance()->visibilityControl()); + ui.hiddenCheckBox->setEnabled(UiHelper::instance()->visibilityControl()); + ui.hideOnCloseCheckBox->setEnabled(UiHelper::instance()->visibilityControl()); } void ConfigDialog::changeSkin() diff --git a/src/plugins/Ui/skinned/mainwindow.cpp b/src/plugins/Ui/skinned/mainwindow.cpp index 972cf967e..5e54fc1a1 100644 --- a/src/plugins/Ui/skinned/mainwindow.cpp +++ b/src/plugins/Ui/skinned/mainwindow.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -72,7 +72,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) m_pl_manager = PlayListManager::instance(); //additional featuries //new PlaylistParser(this); - m_generalHandler = GeneralHandler::instance(); + m_generalHandler = UiHelper::instance(); //user interface m_skin = new Skin(this); @@ -434,7 +434,7 @@ void MainWindow::createActions() m_visMenu = new VisualMenu(this); m_mainMenu->addMenu(m_visMenu); - m_mainMenu->addMenu(m_generalHandler->createMenu(GeneralHandler::TOOLS_MENU, tr("Tools"), this)); + m_mainMenu->addMenu(m_generalHandler->createMenu(UiHelper::TOOLS_MENU, tr("Tools"), this)); m_mainMenu->addSeparator(); m_mainMenu->addAction(SET_ACTION(ActionManager::SETTINGS, this, SLOT(showSettings()))); m_mainMenu->addSeparator(); diff --git a/src/plugins/Ui/skinned/mainwindow.h b/src/plugins/Ui/skinned/mainwindow.h index 542b154a9..4fa4656c4 100644 --- a/src/plugins/Ui/skinned/mainwindow.h +++ b/src/plugins/Ui/skinned/mainwindow.h @@ -37,7 +37,7 @@ class Skin; class SoundCore; class JumpToTrackDialog; class VisualMenu; -class GeneralHandler; +class UiHelper; class MediaPlayer; class QMenu; class QKeyEvent; @@ -112,7 +112,7 @@ private: JumpToTrackDialog* m_jumpDialog; bool m_hideOnClose, m_startHidden; VisualMenu *m_visMenu; - GeneralHandler *m_generalHandler; + UiHelper *m_generalHandler; MediaPlayer *m_player; }; diff --git a/src/plugins/Ui/skinned/playlist.cpp b/src/plugins/Ui/skinned/playlist.cpp index 75a6110ea..de9fa38a8 100644 --- a/src/plugins/Ui/skinned/playlist.cpp +++ b/src/plugins/Ui/skinned/playlist.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include "dock.h" #include "skin.h" @@ -279,7 +279,7 @@ void PlayList::createActions() m_listWidget->menu()->addAction(ActionManager::instance()->action(ActionManager::PL_SHOW_INFO)); m_listWidget->menu()->addSeparator(); m_listWidget->menu()->addActions (m_subMenu->actions().mid(0,3)); //use 3 first actions - m_listWidget->menu()->addMenu(GeneralHandler::instance()->createMenu(GeneralHandler::PLAYLIST_MENU, + m_listWidget->menu()->addMenu(UiHelper::instance()->createMenu(UiHelper::PLAYLIST_MENU, tr("Actions"), this)); m_listWidget->menu()->addSeparator(); m_listWidget->menu()->addAction(SET_ACTION(ActionManager::PL_ENQUEUE, m_pl_manager, SLOT(addToQueue()))); diff --git a/src/plugins/Ui/skinned/pluginitem.cpp b/src/plugins/Ui/skinned/pluginitem.cpp index 0f0fa1f58..0f2679bb0 100644 --- a/src/plugins/Ui/skinned/pluginitem.cpp +++ b/src/plugins/Ui/skinned/pluginitem.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include "pluginitem.h" @@ -153,7 +153,7 @@ void PluginItem::showSettings(QWidget *parent) Visual::showSettings(static_cast(m_factory), parent); break; case PluginItem::GENERAL: - GeneralHandler::instance()->showSettings(static_cast(m_factory), parent); + UiHelper::instance()->showSettings(static_cast(m_factory), parent); break; default: ; @@ -180,7 +180,7 @@ void PluginItem::setEnabled(bool enabled) Visual::setEnabled(static_cast(m_factory), enabled); break; case PluginItem::GENERAL: - GeneralHandler::instance()->setEnabled(static_cast(m_factory), enabled); + UiHelper::instance()->setEnabled(static_cast(m_factory), enabled); break; default: ; 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