diff options
Diffstat (limited to 'src/qmmpui')
| -rw-r--r-- | src/qmmpui/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/qmmpui/commandlinemanager.cpp | 162 | ||||
| -rw-r--r-- | src/qmmpui/commandlinemanager.h | 65 | ||||
| -rw-r--r-- | src/qmmpui/commandlineoption.h | 66 | ||||
| -rw-r--r-- | src/qmmpui/generalhandler.cpp | 9 | ||||
| -rw-r--r-- | src/qmmpui/generalhandler.h | 4 | ||||
| -rw-r--r-- | src/qmmpui/qmmpui.pro | 9 |
7 files changed, 315 insertions, 3 deletions
diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt index b9cc441a6..6d98e5e56 100644 --- a/src/qmmpui/CMakeLists.txt +++ b/src/qmmpui/CMakeLists.txt @@ -28,6 +28,7 @@ SET(libqmmpui_SRCS songinfo.cpp control.cpp playlistparser.cpp + commandlinemanager.cpp ) SET(libqmmpui_MOC_HDRS @@ -38,6 +39,8 @@ SET(libqmmpui_MOC_HDRS control.h playlistparser.h playlistformat.h + commandlinemanager.h + commandlineoption.h ) QT4_WRAP_CPP(libqmmpui_MOC_SRCS ${libqmmpui_MOC_HDRS}) diff --git a/src/qmmpui/commandlinemanager.cpp b/src/qmmpui/commandlinemanager.cpp new file mode 100644 index 000000000..5bc7b6d90 --- /dev/null +++ b/src/qmmpui/commandlinemanager.cpp @@ -0,0 +1,162 @@ +/*************************************************************************** + * Copyright (C) 2008 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 <QtGui> +#include <QObject> +#include <QList> +#include <QApplication> + +#include <cstdlib> +#include <iostream> + +#include "control.h" + +#include "commandlinemanager.h" + +using namespace std; + +static QList<CommandLineOption *> *options = 0; +static QStringList files; + +static void checkOptions() +{ + if (! options) + { + files.clear(); + options = new QList<CommandLineOption *>; + + QDir pluginsDir (qApp->applicationDirPath()); + pluginsDir.cdUp(); + pluginsDir.cd("./"LIB_DIR"/qmmp/CommandLineOptions"); + foreach (QString fileName, pluginsDir.entryList(QDir::Files)) + { + QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); + QObject *plugin = loader.instance(); + if (loader.isLoaded()) + ;//qDebug("CommandLineManager: plugin loaded - %s", qPrintable(fileName)); + else + qWarning("CommandLineManager: %s", qPrintable(loader.errorString ())); + + CommandLineOption *option = 0; + if (plugin) + option = qobject_cast<CommandLineOption *>(plugin); + + if (option) + { + options->append(option); + files << pluginsDir.absoluteFilePath(fileName); + qApp->installTranslator(option->createTranslator(qApp)); + } + } + } +} + +CommandLineManager::CommandLineManager(QObject *parent) + : General(parent) +{ + m_state = General::Stopped; + m_left = 0; + m_right = 0; + m_time = 0; +} + + +CommandLineManager::~CommandLineManager() +{ +} + +void CommandLineManager::setState(const uint& state) +{ + if (state == General::Stopped) + m_time = 0; + m_state = state; +} + +void CommandLineManager::setSongInfo(const SongInfo &song) +{ + m_song = song; +} + +void CommandLineManager::setTime(int time) +{ + m_time = time; +} + +void CommandLineManager::setVolume(int left, int right) +{ + m_left = left; + m_right = right; +} + +uint CommandLineManager::state() +{ + return m_state; +} + +SongInfo *CommandLineManager::info() +{ + return &m_song; +} + +int CommandLineManager::elapsed() +{ + return m_time; +} + +int CommandLineManager::leftVolume() +{ + return m_left; +} + +int CommandLineManager::rightVolume() +{ + return m_right; +} + +void CommandLineManager::executeCommand(const QString& opt_str, Control* ctrl) +{ + checkOptions(); + foreach(CommandLineOption *opt, *options) + { + if (opt->identify(opt_str)) + { + opt->executeCommand(opt_str, this, ctrl); + return; + } + } +} + +bool CommandLineManager::hasOption(const QString &opt_str) +{ + checkOptions(); + foreach(CommandLineOption *opt, *options) + { + if (opt->identify(opt_str)) + return TRUE; + } + return FALSE; +} + +void CommandLineManager::printUsage() +{ + checkOptions(); + foreach(CommandLineOption *opt, *options) + cout << qPrintable(opt->helpString()); +} diff --git a/src/qmmpui/commandlinemanager.h b/src/qmmpui/commandlinemanager.h new file mode 100644 index 000000000..4e99ba35d --- /dev/null +++ b/src/qmmpui/commandlinemanager.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (C) 2008 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 COMMANDLINEMANAGER_H +#define COMMANDLINEMANAGER_H + +#include "general.h" +#include "commandlineoption.h" + + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class CommandLineManager : public General +{ +Q_OBJECT +public: + CommandLineManager(QObject *parent = 0); + + ~CommandLineManager(); + + //general + void setState(const uint &state); + void setSongInfo(const SongInfo &song); + void setVolume(int left, int right); + void setTime(int time); + + //properties + uint state(); + SongInfo *info(); + int elapsed(); + int leftVolume(); + int rightVolume(); + + //command line + void executeCommand(const QString& opt_str, Control* ctrl); + + //static methods + static bool hasOption(const QString &opt_str); + static void printUsage(); + +private: + uint m_state; + SongInfo m_song; + int m_left, m_right; + int m_time; +}; + +#endif diff --git a/src/qmmpui/commandlineoption.h b/src/qmmpui/commandlineoption.h new file mode 100644 index 000000000..bea806bb6 --- /dev/null +++ b/src/qmmpui/commandlineoption.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2008 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 COMMANDLINEOPTION_H +#define COMMANDLINEOPTION_H + + +class CommandLineManager; +class Control; +class QTranslator; +class QString; +class QObject; + +/** + @author Vladimir Kuznetsov <vovanec@gmail.ru> + */ +class CommandLineOption +{ +public: + /*! + * Returns \b true if \b opt_str string can be processed, + * otherise \b false + */ + virtual bool identify(const QString& opt_str)const = 0; + + /*! + * Command line option name + */ + virtual const QString name()const = 0; + + /*! + * Help string. + */ + virtual const QString helpString()const = 0; + + /*! + * Parses \b opt_str args(if needed), executes command. + */ + virtual void executeCommand(const QString& opt_str, CommandLineManager* clm, Control* ctrl) = 0; + /*! + * Creates translator with parent object \b parent + */ + virtual QTranslator *createTranslator(QObject *parent) = 0; + + virtual ~CommandLineOption() {} +}; + +Q_DECLARE_INTERFACE(CommandLineOption,"CommandLineOptionInterface/1.0"); + +#endif diff --git a/src/qmmpui/generalhandler.cpp b/src/qmmpui/generalhandler.cpp index 54e5a8652..02ca51e15 100644 --- a/src/qmmpui/generalhandler.cpp +++ b/src/qmmpui/generalhandler.cpp @@ -22,6 +22,7 @@ #include "general.h" #include "generalfactory.h" #include "control.h" +#include "commandlinemanager.h" #include "generalhandler.h" @@ -48,6 +49,8 @@ GeneralHandler::GeneralHandler(QObject *parent) m_generals.insert(factory, general); } } + m_commandLineManager = new CommandLineManager(this); + m_generals.insert(0, m_commandLineManager); } GeneralHandler::~GeneralHandler() @@ -165,6 +168,12 @@ bool GeneralHandler::visibilityControl() return FALSE; } +void GeneralHandler::executeCommand(const QString &opt_str) +{ + if(CommandLineManager::hasOption(opt_str)) + m_commandLineManager->executeCommand(opt_str, m_control); +} + GeneralHandler* GeneralHandler::instance() { return m_instance; diff --git a/src/qmmpui/generalhandler.h b/src/qmmpui/generalhandler.h index 0fb57c0de..a238e639c 100644 --- a/src/qmmpui/generalhandler.h +++ b/src/qmmpui/generalhandler.h @@ -27,6 +27,7 @@ class General; class Control; class GeneralFactory; +class CommandLineManager; /** @author Ilya Kotov <forkotov02@hotmail.ru> @@ -46,6 +47,7 @@ public: void setEnabled(GeneralFactory* factory, bool enable); void showSettings(GeneralFactory* factory, QWidget* parentWidget); bool visibilityControl(); + void executeCommand(const QString &opt_str); static GeneralHandler* instance(); signals: @@ -73,8 +75,8 @@ private: int m_time; uint m_state; int m_left, m_right; + CommandLineManager *m_commandLineManager; static GeneralHandler* m_instance; - }; #endif diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro index 2d09e43ae..5e6bbde87 100644 --- a/src/qmmpui/qmmpui.pro +++ b/src/qmmpui/qmmpui.pro @@ -21,6 +21,8 @@ contains(CONFIG, SVN_VERSION){ DEFINES += QMMP_STR_VERSION=\\\"$$QMMP_VERSION\\\" } +VERSION = $$QMMP_VERSION + target.path = $$LIB_DIR INSTALLS += target HEADERS += general.h \ @@ -29,12 +31,15 @@ HEADERS += general.h \ songinfo.h \ control.h \ playlistformat.h \ - playlistparser.h + playlistparser.h \ + commandlinemanager.h \ + commandlineoption.h SOURCES += general.cpp \ generalhandler.cpp \ songinfo.cpp \ control.cpp \ - playlistparser.cpp + playlistparser.cpp \ + commandlinemanager.cpp DESTDIR = . |
