diff options
26 files changed, 672 insertions, 418 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index cd8782700..a72b8e51b 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -4,3 +4,4 @@ add_subdirectory(Visual) add_subdirectory(Effect) add_subdirectory(General) add_subdirectory(PlaylistFormats) +add_subdirectory(CommandLineOptions)
\ No newline at end of file diff --git a/src/plugins/CommandLineOptions/CMakeLists.txt b/src/plugins/CommandLineOptions/CMakeLists.txt new file mode 100644 index 000000000..594671745 --- /dev/null +++ b/src/plugins/CommandLineOptions/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(IncDecVolumeOption) + diff --git a/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption.pro b/src/plugins/CommandLineOptions/CommandLineOptions.pro index 1832a0166..1832a0166 100644 --- a/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption.pro +++ b/src/plugins/CommandLineOptions/CommandLineOptions.pro diff --git a/src/plugins/CommandLineOptions/IncDecVolumeOption/CMakeLists.txt b/src/plugins/CommandLineOptions/IncDecVolumeOption/CMakeLists.txt new file mode 100644 index 000000000..542f4fab2 --- /dev/null +++ b/src/plugins/CommandLineOptions/IncDecVolumeOption/CMakeLists.txt @@ -0,0 +1,48 @@ +project(libincdecvolumeoption) + +cmake_minimum_required(VERSION 2.4.0) + +if(COMMAND cmake_policy) +cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +SET(QT_INCLUDES + ${QT_INCLUDES} + ${CMAKE_CURRENT_BINARY_DIR}/../../../ +) + +# libqmmpui +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui) + +SET(libincdecvolumeoption_SRCS + incdecvolumeoption.cpp +) + +SET(libincdecvolumeoption_MOC_HDRS + incdecvolumeoption.h +) + +QT4_ADD_RESOURCES(libincdecvolumeoption_RCC_SRCS ${libincdecvolumeoption_RCCS}) + +QT4_WRAP_CPP(libincdecvolumeoption_MOC_SRCS ${libincdecvolumeoption_MOC_HDRS}) + + +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_LIBRARY(incdecvolumeoption SHARED ${libincdecvolumeoption_SRCS} ${libincdecvolumeoption_MOC_SRCS}) +target_link_libraries(incdecvolumeoption ${QT_LIBRARIES} -lqmmpui) +install(TARGETS incdecvolumeoption DESTINATION ${LIB_DIR}/qmmp/CommandLineOptions) diff --git a/src/plugins/CommandLineOptions/IncDecVolumeOption/IncDecVolumeOption.pro b/src/plugins/CommandLineOptions/IncDecVolumeOption/IncDecVolumeOption.pro new file mode 100644 index 000000000..8b98e14db --- /dev/null +++ b/src/plugins/CommandLineOptions/IncDecVolumeOption/IncDecVolumeOption.pro @@ -0,0 +1,26 @@ +include(../../plugins.pri) + +CONFIG += release \ +warn_on \ +plugin \ + lib + +TARGET =$$PLUGINS_PREFIX/CommandLineOptions/incdecvolumeoption +QMAKE_CLEAN =$$PLUGINS_PREFIX/CommandLineOptions/libincdecvolumeoption.so + +TEMPLATE = lib +QMAKE_LIBDIR += ../../../../lib + +isEmpty(LIB_DIR){ + LIB_DIR = /lib +} +target.path = $$LIB_DIR/qmmp/CommandLineOptions +INSTALLS += target + +INCLUDEPATH += ../../../../src + +LIBS += -lqmmpui + +HEADERS += incdecvolumeoption.h + +SOURCES += incdecvolumeoption.cpp diff --git a/src/plugins/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.cpp b/src/plugins/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.cpp new file mode 100644 index 000000000..93a7dd21d --- /dev/null +++ b/src/plugins/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.cpp @@ -0,0 +1,60 @@ +#include <QtPlugin> +#include <QTranslator> + +#include "incdecvolumeoption.h" + +bool IncDecVolumeCommandLineOption::identify(const QString & str) const +{ + if ( + str == QString("--volume-inc") || + str == QString("--volume-dec") + ) + { + return TRUE; + } + + return FALSE; +} + +const QString IncDecVolumeCommandLineOption::helpString() const +{ + return QString( + "--volume-inc " + tr("Increase volume with step 5")+"\n" + "--volume-dec " + tr("Decrease volume with step 5")+"\n" + ); +} + + +void IncDecVolumeCommandLineOption::executeCommand(const QString& opt_str, CommandLineManager* clm, Control* ctrl) +{ + int volume = qMax(clm->leftVolume(), clm->rightVolume()); + int balance = 0; + int left = clm->leftVolume(); + int right = clm->rightVolume(); + if (left || right) + balance = (right - left)*100/volume; + + if (opt_str == "--volume-inc") + { + volume = qMin (100, volume + 5); + } + else if (opt_str == "--volume-dec") + { + volume = qMax (0, volume - 5); + } + ctrl->setVolume(volume-qMax(balance,0)*volume/100, + volume+qMin(balance,0)*volume/100); +} + +const QString IncDecVolumeCommandLineOption::name() const +{ + return "IncDecVolumeCommandLineOption"; +} + +QTranslator *IncDecVolumeCommandLineOption::createTranslator(QObject *parent) +{ + Q_UNUSED(parent); + return 0; +} + +Q_EXPORT_PLUGIN(IncDecVolumeCommandLineOption) diff --git a/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.h b/src/plugins/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.h index 6fbf3d24a..cc27260f6 100644 --- a/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.h +++ b/src/plugins/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.h @@ -1,12 +1,13 @@ #ifndef IncDecVolumeCommandLineOption_H -#define IncDecVolumeCommandLineOption_H - -#include <commandlineoption.h> +#define IncDecVolumeCommandLineOption_H #include <QString> #include <QObject> -class MainWindow; +#include <qmmpui/commandlineoption.h> +#include <qmmpui/control.h> +#include <qmmpui/commandlinemanager.h> + class IncDecVolumeCommandLineOption : public QObject, public CommandLineOption { @@ -16,7 +17,8 @@ public: virtual bool identify(const QString& opt_str)const; virtual const QString name()const; virtual const QString helpString()const; - virtual void executeCommand(const QString& opt_str,MainWindow* mw); + virtual void executeCommand(const QString& opt_str, CommandLineManager* clm, Control* ctrl); + virtual QTranslator *createTranslator(QObject *parent); }; #endif diff --git a/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption/IncDecVolumeOption.pro b/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption/IncDecVolumeOption.pro deleted file mode 100644 index fdcef5e38..000000000 --- a/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption/IncDecVolumeOption.pro +++ /dev/null @@ -1,26 +0,0 @@ -include(../../../../../qmmp.pri) - -QMMPSRCROOT = ../../../../ - -INCLUDEPATH += $$QMMPSRCROOT/ui \ - $$QMMPSRCROOT/qmmp \ - $$QMMPSRCROOT - -HEADERS += incdecvolumeoption.h \ - $$QMMPSRCROOT/ui/mainwindow.h \ - $$QMMPSRCROOT/qmmp/soundcore.h - -SOURCES += incdecvolumeoption.cpp \ - $$QMMPSRCROOT/qmmp/soundcore.cpp \ - $$QMMPSRCROOT/ui/mainwindow.cpp - -DESTDIR = ../ -QMAKE_CLEAN = ../libincdecvolumeoption.so - - - -CONFIG += release warn_on plugin - -TEMPLATE = lib - - diff --git a/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.cpp b/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.cpp deleted file mode 100644 index 4bd35a910..000000000 --- a/src/plugins/Misc/CommandLineOptions/IncDecVolumeOption/incdecvolumeoption.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include <QtPlugin> - -#include "incdecvolumeoption.h" -#include <soundcore.h> -#include "mainwindow.h" - -bool IncDecVolumeCommandLineOption::identify(const QString & str) const -{ - if( - str == QString("--volume-inc") || - str == QString("--volume-dec") - ) - { - return TRUE; - } - - return FALSE; -} - -const QString IncDecVolumeCommandLineOption::helpString() const -{ - return QString( - "--volume-inc Increase volume with step 10\n" - "--volume-dec Decrease volume with step 10\n" - ); -} - - -void IncDecVolumeCommandLineOption::executeCommand(const QString & option_string, MainWindow *mw) -{ - if (option_string == "--volume-inc") - { - int l = 0; - int r = 0; - mw->soundCore()->volume(&l,&r); - mw->soundCore()->setVolume(l+10,r+10); - } - else if (option_string == "--volume-dec") - { - int l = 0; - int r = 0; - mw->soundCore()->volume(&l,&r); - mw->soundCore()->setVolume(l-10,r-10); - } -} - -const QString IncDecVolumeCommandLineOption::name() const -{ - return "IncDecVolumeCommandLineOption"; -} - -Q_EXPORT_PLUGIN(IncDecVolumeCommandLineOption) - diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index ef6fc9e12..b14a5fc4b 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,8 +1,9 @@ SUBDIRS += Input \ Output \ - Visual \ - Effect \ - General \ - PlaylistFormats + Visual \ + Effect \ + General \ + PlaylistFormats \ + CommandLineOptions TEMPLATE = subdirs 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/ui/commandlineoption.h b/src/qmmpui/commandlineoption.h index f5bc78ecf..bea806bb6 100644 --- a/src/ui/commandlineoption.h +++ b/src/qmmpui/commandlineoption.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007 by Ilya Kotov * + * Copyright (C) 2008 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -17,15 +17,15 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifndef COMMANDLINEOPTION_H +#define COMMANDLINEOPTION_H -#ifndef CommandLineOption_H -#define CommandLineOption_H -#include <QtPlugin> -#include <QString> -#include <QList> - -class MainWindow; +class CommandLineManager; +class Control; +class QTranslator; +class QString; +class QObject; /** @author Vladimir Kuznetsov <vovanec@gmail.ru> @@ -38,57 +38,29 @@ public: * 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,MainWindow* mw) = 0; - virtual ~CommandLineOption(){;} -}; - -Q_DECLARE_INTERFACE(CommandLineOption,"CommandLineOptionInterface/1.0"); - - - -typedef QList<CommandLineOption*> CommandLineOptionList; + 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; -class CommandLineOptionManager -{ -public: - CommandLineOptionManager(); - bool hasOption(const QString& ); - void executeCommand(const QString&,MainWindow* = NULL); - CommandLineOption* operator[](int); - int count()const; -protected: - void registerBuiltingCommandLineOptions(); - void registerExternalCommandLineOptions(); -private: - void _register(CommandLineOption*); -private: - CommandLineOptionList m_options; + virtual ~CommandLineOption() {} }; -/*! - * Represens command line option handling for standard operations. - */ -class BuiltinCommandLineOption : public CommandLineOption -{ - virtual bool identify(const QString& str)const; - virtual const QString helpString()const; - virtual void executeCommand(const QString& option,MainWindow* = NULL); - virtual const QString name()const; - virtual ~BuiltinCommandLineOption(){;} -}; +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 = . diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index e03881bd9..d20634781 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -39,7 +39,7 @@ SET(ui_SRCS addurldialog.cpp balancebar.cpp button.cpp - commandlineoption.cpp + builtincommandlineoption.cpp configdialog.cpp display.cpp dock.cpp @@ -92,7 +92,7 @@ SET(ui_MOC_HDRS addurldialog.h balancebar.h button.h - commandlineoption.h + builtincommandlineoption.h configdialog.h display.h dock.h diff --git a/src/ui/builtincommandlineoption.cpp b/src/ui/builtincommandlineoption.cpp new file mode 100644 index 000000000..15c55a1eb --- /dev/null +++ b/src/ui/builtincommandlineoption.cpp @@ -0,0 +1,142 @@ +/*************************************************************************** + * 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 <qmmp/soundcore.h> + +#include "mainwindow.h" +#include "builtincommandlineoption.h" + +BuiltinCommandLineOption::BuiltinCommandLineOption(QObject *parent) + : QObject(parent) +{ +} + + +BuiltinCommandLineOption::~BuiltinCommandLineOption() +{ +} + +// BuiltinCommandLineOption methods implementation +bool BuiltinCommandLineOption::identify(const QString & str) const +{ + if ( + str == QString("--help") || + str == QString("--next") || + str == QString("--previous") || + str == QString("--play") || + str == QString("--pause") || + str == QString("--play-pause") || + str == QString("--stop") || + str.startsWith("--volume") || + str.startsWith("--jump-to-file") || + str.startsWith("--toggle-visibility") || + str.startsWith("--add-file") || + str.startsWith("--add-dir") + ) + { + return TRUE; + } + + return FALSE; +} + +const QString BuiltinCommandLineOption::helpString() const +{ + return QString( + "--next "+tr("Skip forward in playlist")+ "\n" + + "--previous "+tr("Skip backwards in playlist")+"\n" + + "--play "+tr("Start playing current song")+"\n" + + "--pause "+tr("Pause current song")+ "\n" + "--play-pause "+tr("Pause if playing, play otherwise")+ "\n" + "--stop "+tr("Stop current song")+ "\n" + + "--next "+tr("Skip forward in playlist")+ "\n" + + "--volume "+tr("Set playback volume(example: qmmp --volume20, qmmp --volume100)")+ "\n" + "--jump-to-file "+tr("Display Jump to File dialog")+ "\n" + + "--toggle-visibility "+tr("Show/hide application")+ "\n" + + "--add-file "+tr("Display Add File dialog")+ "\n" + + "--add-dir "+tr("Display Add Directory dialog") + ); +} + +void BuiltinCommandLineOption::executeCommand(const QString & option_string, MainWindow *mw) +{ + if (option_string == "--play") + { + mw->play(); + } + else if (option_string == "--stop") + { + mw->stop(); + mw->mainDisplay()->hideTimeDisplay(); + } + else if (option_string == "--pause") + { + mw->pause(); + } + else if (option_string == "--next") + { + mw->next(); + if (!mw->soundCore()->isInitialized()) + mw->play(); + } + else if (option_string == "--previous") + { + mw->previous(); + if (!mw->soundCore()->isInitialized()) + mw->play(); + } + else if (option_string == "--play-pause") + { + mw->playPause(); + } + else if (option_string == "--jump-to-file") + { + mw->jumpToFile(); + } + else if (option_string == "--toggle-visibility") + { + mw->toggleVisibility(); + } + else if (option_string == "--add-file") + { + mw->addFile(); + } + else if (option_string == "--add-dir") + { + mw->addDir(); + } + else if (option_string.startsWith("--volume")) + { + QString vol_str(option_string); + vol_str.remove("--volume"); + bool ok = FALSE; + int volume = vol_str.toUInt(&ok); + if (ok) + { + mw->soundCore()->setVolume(volume,volume); + } + } +} + +const QString BuiltinCommandLineOption::name() const +{ + return "BuiltinCommandLineOption"; +} + diff --git a/src/ui/builtincommandlineoption.h b/src/ui/builtincommandlineoption.h new file mode 100644 index 000000000..df6c6dfb2 --- /dev/null +++ b/src/ui/builtincommandlineoption.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * 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 BUILTINCOMMANDLINEOPTION_H +#define BUILTINCOMMANDLINEOPTION_H + +#include <QObject> + +class MainWindow; + +/** + @author Vladimir Kuznetsov <vovanec@gmail.ru> +*/ + +/*! + * Represens command line option handling for standard operations. + */ +class BuiltinCommandLineOption : public QObject +{ + Q_OBJECT +public: + BuiltinCommandLineOption(QObject *parent = 0); + + ~BuiltinCommandLineOption(); + + bool identify(const QString& str)const; + const QString helpString()const; + void executeCommand(const QString& option,MainWindow* = NULL); + const QString name()const; + +}; + +#endif diff --git a/src/ui/commandlineoption.cpp b/src/ui/commandlineoption.cpp deleted file mode 100644 index 4ed14e456..000000000 --- a/src/ui/commandlineoption.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 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 <QDir> -#include <QPluginLoader> - -#include "commandlineoption.h" -#include "mainwindow.h" -#include <qmmp/soundcore.h> - - -// Command option manager methods -CommandLineOptionManager::CommandLineOptionManager() -{ - this->registerBuiltingCommandLineOptions(); - this->registerExternalCommandLineOptions(); -} - -bool CommandLineOptionManager::hasOption(const QString &opt) -{ - for(int i = 0; i < m_options.count(); i++) - { - if(m_options[i]->identify(opt)) - { - return true; - } - } - return false; -} - -void CommandLineOptionManager::executeCommand(const QString &opt, MainWindow *mw) -{ - for(int i = 0; i < m_options.count(); i++) - { - if(m_options[i]->identify(opt)) - { - m_options[i]->executeCommand(opt,mw); - } - } -} - -CommandLineOption * CommandLineOptionManager::operator [](int index) -{ - return m_options[index]; -} - -int CommandLineOptionManager::count() const -{ - return m_options.count(); -} - - -void CommandLineOptionManager::registerBuiltingCommandLineOptions() -{ - m_options.append(new BuiltinCommandLineOption()); -} - - -void CommandLineOptionManager::registerExternalCommandLineOptions() -{ - QDir pluginsDir (QDir::homePath()+"/.qmmp/plugins/CommandLineOptions"); - foreach (QString fileName, pluginsDir.entryList(QDir::Files)) - { - QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); - QObject *plugin = loader.instance(); - if (loader.isLoaded()) - qDebug("CommandLineOption: plugin loaded - %s", qPrintable(fileName)); - else - qWarning(qPrintable(loader.errorString())); - - CommandLineOption *cmd_option = 0; - if (plugin) - cmd_option = qobject_cast<CommandLineOption *>(plugin); - - if (cmd_option) - { - foreach(CommandLineOption* opt,m_options) - { - if (opt->name() == cmd_option->name()) - { - qDebug("CommandLineOption: Plugin with name %s is already registered...", - qPrintable(cmd_option->name())); - return; - } - } - m_options.append(cmd_option); - } - } -} - -/////////////////////////////////////////////////////////////////// - - -// BuiltinCommandLineOption methods implementation -bool BuiltinCommandLineOption::identify(const QString & str) const -{ - if( - str == QString("--help") || - str == QString("--next") || - str == QString("--previous") || - str == QString("--play") || - str == QString("--pause") || - str == QString("--play-pause") || - str == QString("--stop") || - str.startsWith("--volume") || - str.startsWith("--jump-to-file") || - str.startsWith("--toggle-visibility") || - str.startsWith("--add-file") - ) - { - return TRUE; - } - - return FALSE; -} - -const QString BuiltinCommandLineOption::helpString() const -{ - return QString( - "--next Skip forward in playlist\n" - "--previous Skip backwards in playlist\n" - "--play Start playing current song\n" - "--pause Pause current song\n" - "--play-pause Pause if playing, play otherwise\n" - "--stop Stop current song\n" - "--next Skip forward in playlist\n" - "--volume Set playback volume(example: qmmp --volume20, qmmp --volume100)\n" - "--jump-to-file Display Jump to File dialog\n" - "--toggle-visibility Show/hide application\n" - "--add-file Display Add File dialog" - ); -} - -void BuiltinCommandLineOption::executeCommand(const QString & option_string, MainWindow *mw) -{ - if (option_string == "--play") - { - mw->play(); - } - else if (option_string == "--stop") - { - mw->stop(); - mw->mainDisplay()->hideTimeDisplay(); - } - else if (option_string == "--pause") - { - mw->pause(); - } - else if (option_string == "--next") - { - mw->next(); - if(!mw->soundCore()->isInitialized()) - mw->play(); - } - else if (option_string == "--previous") - { - mw->previous(); - if(!mw->soundCore()->isInitialized()) - mw->play(); - } - else if (option_string == "--play-pause") - { - mw->playPause(); - } - else if (option_string == "--jump-to-file") - { - mw->jumpToFile(); - } - else if (option_string == "--toggle-visibility") - { - mw->toggleVisibility(); - } - else if (option_string == "--add-file") - { - mw->addFile(); - } - else if (option_string.startsWith("--volume")) - { - QString vol_str(option_string); - vol_str.remove("--volume"); - bool ok = FALSE; - int volume = vol_str.toUInt(&ok); - if(ok) - { - mw->soundCore()->setVolume(volume,volume); - } - } -} - -const QString BuiltinCommandLineOption::name() const -{ - return "BuiltinCommandLineOption"; -} - - - - - - diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 1ffe511cd..f011668b5 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -30,6 +30,7 @@ #include <qmmpui/general.h> #include <qmmpui/playlistparser.h> #include <qmmpui/playlistformat.h> +#include <qmmpui/commandlinemanager.h> #include "textscroller.h" #include "mainwindow.h" @@ -47,11 +48,11 @@ #include "filedialog.h" #include "listwidget.h" #include "visualmenu.h" -#include "commandlineoption.h" +#include "builtincommandlineoption.h" #define KEY_OFFSET 10 -MainWindow::MainWindow(const QStringList& args,CommandLineOptionManager* option_manager, QWidget *parent) +MainWindow::MainWindow(const QStringList& args, BuiltinCommandLineOption* option_manager, QWidget *parent) : QMainWindow(parent) { m_vis = 0; @@ -798,12 +799,12 @@ bool MainWindow::processCommandArgs(const QStringList &slist,const QString& cwd) QString str = slist[0]; if (str.startsWith("--")) // is it a command? { - if (m_option_manager->hasOption(str)) - { + if (CommandLineManager::hasOption(str)) + m_generalHandler->executeCommand(str); + else if (m_option_manager->identify(str)) m_option_manager->executeCommand(str,this); - } else - return false; + return FALSE; } else// maybe it is a list of files or dirs { @@ -819,7 +820,7 @@ bool MainWindow::processCommandArgs(const QStringList &slist,const QString& cwd) setFileList(full_path_list); } } - return true; + return TRUE; } void MainWindow::jumpToFile() diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 4835d5fdf..db8eff765 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -46,14 +46,14 @@ class GeneralHandler; class QMenu; class QKeyEvent; -class CommandLineOptionManager; +class BuiltinCommandLineOption; class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(const QStringList& args,CommandLineOptionManager*, QWidget *parent); + MainWindow(const QStringList& args, BuiltinCommandLineOption*, QWidget *parent); ~MainWindow(); @@ -135,7 +135,7 @@ private: bool m_hideOnClose, m_startHidden; int m_elapsed; VisualMenu *m_visMenu; - CommandLineOptionManager* m_option_manager; + BuiltinCommandLineOption* m_option_manager; GeneralHandler *m_generalHandler; }; diff --git a/src/ui/qmmpstarter.cpp b/src/ui/qmmpstarter.cpp index 4d47ffabd..b2d7ac92c 100644 --- a/src/ui/qmmpstarter.cpp +++ b/src/ui/qmmpstarter.cpp @@ -20,21 +20,26 @@ #include <QApplication> -#include "unixdomainsocket.h" +#include <cstdlib> +#include <iostream> #include <unistd.h> #include <sys/types.h> #include <string.h> +#include <qmmpui/commandlinemanager.h> +#include "unixdomainsocket.h" #include "mainwindow.h" #include "version.h" #include "qmmpstarter.h" -#include "commandlineoption.h" +#include "builtincommandlineoption.h" #define MAXCOMMANDSIZE 1024 -QMMPStarter::QMMPStarter(int argc,char ** argv,QObject* parent) : QObject(parent),mw(NULL) +using namespace std; + +QMMPStarter::QMMPStarter(int argc,char **argv, QObject* parent) : QObject(parent), mw(NULL) { - m_option_manager = new CommandLineOptionManager(); + m_option_manager = new BuiltinCommandLineOption(this); QStringList tmp; for (int i = 1;i < argc;i++) tmp << QString::fromLocal8Bit(argv[i]); @@ -53,8 +58,8 @@ QMMPStarter::QMMPStarter(int argc,char ** argv,QObject* parent) : QObject(parent } if (argString.startsWith("--") && // command? - !m_option_manager->hasOption(argString) - ) + !(m_option_manager->identify(argString) || + CommandLineManager::hasOption(argString))) { qFatal("QMMP: Unknown command..."); exit(1); @@ -132,23 +137,17 @@ void QMMPStarter::readCommand() void QMMPStarter::printUsage() { - qWarning( - "Usage: qmmp [options] [files] \n" - "Options:\n" - "--------\n" - ); - for (int i = 0; i< m_option_manager->count();i++) - { - qWarning(qPrintable((*m_option_manager)[i]->helpString())); - } - qWarning( - "--help Display this text and exit.\n" - "--version Print version number and exit.\n\n" - "Ideas, patches, bugreports send to forkotov02@hotmail.ru\n" - ); + cout << qPrintable(tr("Usage: qmmp [options] [files]")) << endl; + cout << qPrintable(tr("Options:")) << endl; + cout << qPrintable(tr("--------")) << endl; + cout << qPrintable(m_option_manager->helpString()) << endl; + CommandLineManager::printUsage(); + cout << "--help " << qPrintable(tr("Display this text and exit.")) << endl; + cout << "--version " << qPrintable(tr("Print version number and exit")) << endl; + cout << qPrintable(tr("Ideas, patches, bugreports send to forkotov02@hotmail.ru")) << endl; } void QMMPStarter::printVersion() { - qWarning("QMMP version: %s",QMMP_STR_VERSION); + cout << qPrintable(tr("QMMP version: ")) << QMMP_STR_VERSION << endl; } diff --git a/src/ui/qmmpstarter.h b/src/ui/qmmpstarter.h index 010c5385f..022031b2a 100644 --- a/src/ui/qmmpstarter.h +++ b/src/ui/qmmpstarter.h @@ -27,47 +27,47 @@ class UnixDomainSocket; class MainWindow; -class CommandLineOptionManager; +class BuiltinCommandLineOption; /*! - * QMMPStarter represents wrapper object that is responsible - * for proper QMMP initialization(only one instance of running + * QMMPStarter represents wrapper object that is responsible + * for proper QMMP initialization(only one instance of running * MainWindow) and passing command line args to application. * @author Vladimir Kuznetsov <vovanec@gmail.com> */ class QMMPStarter : public QObject { -Q_OBJECT + Q_OBJECT public: QMMPStarter(int argc,char ** argv,QObject* parent = 0); - ~QMMPStarter(); + ~QMMPStarter(); protected slots: - - /*! - * Passes command args to the running application - */ - void writeCommand(); - - void readCommand(); + + /*! + * Passes command args to the running application + */ + void writeCommand(); + + void readCommand(); private: - /*! - * Prints usage - */ - void printUsage(); - - /*! - * Prints version of program - */ - void printVersion(); - - void startMainWindow(); + /*! + * Prints usage + */ + void printUsage(); + + /*! + * Prints version of program + */ + void printVersion(); + + void startMainWindow(); private: - MainWindow* mw; - UnixDomainSocket* m_sock; - QString argString; - CommandLineOptionManager* m_option_manager; + MainWindow* mw; + UnixDomainSocket* m_sock; + QString argString; + BuiltinCommandLineOption* m_option_manager; }; -#endif +#endif diff --git a/src/ui/ui.pro b/src/ui/ui.pro index f01deb926..f6dc9284e 100644 --- a/src/ui/ui.pro +++ b/src/ui/ui.pro @@ -55,14 +55,14 @@ HEADERS += mainwindow.h \ keyboardmanager.h \ filedialog.h \ unixdomainsocket.h \ - commandlineoption.h \ addurldialog.h \ skinreader.h \ visualmenu.h \ titlebarcontrol.h \ shadedvisual.h \ shadedbar.h \ - playlistitem.h + playlistitem.h \ + builtincommandlineoption.h SOURCES += mainwindow.cpp \ mp3player.cpp \ @@ -107,14 +107,14 @@ SOURCES += mainwindow.cpp \ keyboardmanager.cpp \ filedialog.cpp \ unixdomainsocket.cpp \ - commandlineoption.cpp \ addurldialog.cpp \ skinreader.cpp \ visualmenu.cpp \ titlebarcontrol.cpp \ shadedvisual.cpp \ shadedbar.cpp \ - playlistitem.cpp + playlistitem.cpp \ + builtincommandlineoption.cpp #Some conf to redirect intermediate stuff in separate dirs UI_DIR =./.build/ui/ |
