diff options
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/ui/builtincommandlineoption.cpp | 142 | ||||
| -rw-r--r-- | src/ui/builtincommandlineoption.h | 49 | ||||
| -rw-r--r-- | src/ui/commandlineoption.cpp | 216 | ||||
| -rw-r--r-- | src/ui/commandlineoption.h | 94 | ||||
| -rw-r--r-- | src/ui/mainwindow.cpp | 15 | ||||
| -rw-r--r-- | src/ui/mainwindow.h | 6 | ||||
| -rw-r--r-- | src/ui/qmmpstarter.cpp | 41 | ||||
| -rw-r--r-- | src/ui/qmmpstarter.h | 56 | ||||
| -rw-r--r-- | src/ui/ui.pro | 8 |
10 files changed, 256 insertions, 375 deletions
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/commandlineoption.h b/src/ui/commandlineoption.h deleted file mode 100644 index f5bc78ecf..000000000 --- a/src/ui/commandlineoption.h +++ /dev/null @@ -1,94 +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. * - ***************************************************************************/ - -#ifndef CommandLineOption_H -#define CommandLineOption_H - -#include <QtPlugin> -#include <QString> -#include <QList> - -class MainWindow; - -/** - @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,MainWindow* mw) = 0; - virtual ~CommandLineOption(){;} -}; - -Q_DECLARE_INTERFACE(CommandLineOption,"CommandLineOptionInterface/1.0"); - - - -typedef QList<CommandLineOption*> CommandLineOptionList; - -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; -}; - -/*! - * 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(){;} -}; - -#endif 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/ |
