diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-03-04 16:31:05 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2010-03-04 16:31:05 +0000 |
| commit | 2d833f47171ad6ed35da3aeb34d753ff1f2a34ca (patch) | |
| tree | e6f02edd1a3483a2f3f3e71bcd07d8ee9aaece3f | |
| parent | dca857498e15d000b6ba27dd07380302a47d1fcc (diff) | |
| download | qmmp-2d833f47171ad6ed35da3aeb34d753ff1f2a34ca.tar.gz qmmp-2d833f47171ad6ed35da3aeb34d753ff1f2a34ca.tar.bz2 qmmp-2d833f47171ad6ed35da3aeb34d753ff1f2a34ca.zip | |
added seek support for command line interface (Closes issue 121)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1598 90c681e8-e032-0410-971d-27865f9a5e38
18 files changed, 464 insertions, 3 deletions
diff --git a/src/plugins/CommandLineOptions/CMakeLists.txt b/src/plugins/CommandLineOptions/CMakeLists.txt index 594671745..558dfd0ea 100644 --- a/src/plugins/CommandLineOptions/CMakeLists.txt +++ b/src/plugins/CommandLineOptions/CMakeLists.txt @@ -1,2 +1,2 @@ add_subdirectory(IncDecVolumeOption) - +add_subdirectory(SeekOption) diff --git a/src/plugins/CommandLineOptions/CommandLineOptions.pro b/src/plugins/CommandLineOptions/CommandLineOptions.pro index 1832a0166..1f4ed9c33 100644 --- a/src/plugins/CommandLineOptions/CommandLineOptions.pro +++ b/src/plugins/CommandLineOptions/CommandLineOptions.pro @@ -1,2 +1,4 @@ TEMPLATE = subdirs -SUBDIRS = IncDecVolumeOption +SUBDIRS = IncDecVolumeOption \ + SeekOption + diff --git a/src/plugins/CommandLineOptions/SeekOption/CMakeLists.txt b/src/plugins/CommandLineOptions/SeekOption/CMakeLists.txt new file mode 100644 index 000000000..6fdfdc123 --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/CMakeLists.txt @@ -0,0 +1,52 @@ +project(seekoption) + +cmake_minimum_required(VERSION 2.4.7) + +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_SOURCE_DIR}/../../../ +) + +# libqmmpui +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) + +SET(seekoption_SRCS + seekoption.cpp +) + +SET(seekoption_MOC_HDRS + seekoption.h +) + +SET(seekoption_RCCS translations/translations.qrc) + +QT4_ADD_RESOURCES(seekoption_RCC_SRCS ${seekoption_RCCS}) + +QT4_WRAP_CPP(seekoption_MOC_SRCS ${seekoption_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(seekoption MODULE ${seekoption_SRCS} ${seekoption_MOC_SRCS} ${seekoption_RCC_SRCS}) +add_dependencies(seekoption qmmpui) +target_link_libraries(seekoption ${QT_LIBRARIES} -lqmmpui -lqmmp) +install(TARGETS seekoption DESTINATION ${LIB_DIR}/qmmp/CommandLineOptions) diff --git a/src/plugins/CommandLineOptions/SeekOption/SeekOption.pro b/src/plugins/CommandLineOptions/SeekOption/SeekOption.pro new file mode 100644 index 000000000..617b91124 --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/SeekOption.pro @@ -0,0 +1,39 @@ +include(../../plugins.pri) + +CONFIG += release \ +warn_on \ +plugin \ + lib + +TARGET = $$PLUGINS_PREFIX/CommandLineOptions/seekoption +QMAKE_CLEAN = $$PLUGINS_PREFIX/CommandLineOptions/libseekoption.so + +TEMPLATE = lib +QMAKE_LIBDIR += ../../../../lib + +TRANSLATIONS = translations/seek_plugin_cs.ts \ + translations/seek_plugin_de.ts \ + translations/seek_plugin_pl.ts \ + translations/seek_plugin_ru.ts \ + translations/seek_plugin_uk_UA.ts \ + translations/seek_plugin_zh_TW.ts \ + translations/seek_plugin_zh_CN.ts \ + translations/seek_plugin_it.ts \ + translations/seek_plugin_tr.ts \ + translations/seek_plugin_lt.ts + +RESOURCES = translations/translations.qrc + +isEmpty(LIB_DIR){ + LIB_DIR = /lib +} +target.path = $$LIB_DIR/qmmp/CommandLineOptions +INSTALLS += target + +INCLUDEPATH += ../../../../src + +LIBS += -lqmmpui -lqmmp + +HEADERS += seekoption.h + +SOURCES += seekoption.cpp diff --git a/src/plugins/CommandLineOptions/SeekOption/seekoption.cpp b/src/plugins/CommandLineOptions/SeekOption/seekoption.cpp new file mode 100644 index 000000000..444bc73be --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/seekoption.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + * Copyright (C) 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 <QtPlugin> +#include <QTranslator> +#include <QLocale> +#include <QRegExp> +#include <qmmp/soundcore.h> +#include "seekoption.h" + +bool SeekOption::identify(const QString &str) const +{ + QStringList opts; + opts << "--seek" << "--seek-fwd" << "--seek-bwd"; + return opts.contains(str); +} + +const QString SeekOption::helpString() const +{ + QString help; + help += QString("--seek <time> ") + tr("Seek to position in the current track") + "\n"; + help += QString("--seek-fwd <time> ") + tr("Seek forward") + "\n"; + help += QString("--seek-bwd <time> ") + tr("Seek backwards") + "\n"; + return help; +} + +void SeekOption::executeCommand(const QString &opt_str, const QStringList &args) +{ + SoundCore *core = SoundCore::instance(); + if(core->state() != Qmmp::Playing && core->totalTime()) + return; + if(args.isEmpty()) + return; + + int seek_pos = -1; + int elapsed = core->elapsed()/1000; + + QRegExp seek_regexp1 ("^([0-9]{1,4})$"); + QRegExp seek_regexp2 ("^([0-9]{1,2}):([0-9]{1,2})$"); + + if(seek_regexp1.indexIn(args.at(0)) != -1) + seek_pos = seek_regexp1.cap(1).toInt(); + else if(seek_regexp2.indexIn(args.at(0)) != -1) + seek_pos = seek_regexp2.cap(1).toInt()*60 + seek_regexp2.cap(2).toInt(); + + //seek absolute + if(opt_str == "--seek") + ; + else if(opt_str == "--seek-fwd") + seek_pos += elapsed; + else if(opt_str == "--seek-bwd") + seek_pos = elapsed - seek_pos; + qDebug("SeekOption: position = %d", seek_pos); + + if(seek_pos >= 0 && seek_pos < core->totalTime()) + core->seek(seek_pos * 1000); +} + +const QString SeekOption::name() const +{ + return "SeekOption"; +} + +QTranslator *SeekOption::createTranslator(QObject *parent) +{ + QTranslator *translator = new QTranslator(parent); + QString locale = Qmmp::systemLanguageID(); + translator->load(QString(":/seek_plugin_") + locale); + return translator; +} + +Q_EXPORT_PLUGIN2(seekoption, SeekOption) diff --git a/src/plugins/CommandLineOptions/SeekOption/seekoption.h b/src/plugins/CommandLineOptions/SeekOption/seekoption.h new file mode 100644 index 000000000..544819d63 --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/seekoption.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 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 SEEKOPTION_H +#define SEEKOPTION_H + +#include <QString> +#include <QObject> +#include <QStringList> +#include <qmmpui/commandlineoption.h> +#include <qmmpui/commandlinemanager.h> + + +class SeekOption : public QObject, public CommandLineOption +{ +Q_OBJECT +Q_INTERFACES(CommandLineOption) +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, const QStringList &args); + virtual QTranslator *createTranslator(QObject *parent); +}; + +#endif + diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_cs.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_cs.ts new file mode 100644 index 000000000..7b8c6954e --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_cs.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="cs_CZ"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_de.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_de.ts new file mode 100644 index 000000000..353ceb55c --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_de.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="de_DE"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_it.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_it.ts new file mode 100644 index 000000000..6c3d147a3 --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_it.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="it_IT"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_lt.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_lt.ts new file mode 100644 index 000000000..cc2a40cb5 --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_lt.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="lt_LT"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_pl.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_pl.ts new file mode 100644 index 000000000..a64a64339 --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_pl.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="pl_PL"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_ru.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_ru.ts new file mode 100644 index 000000000..b7e7bdabb --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_ru.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="ru_RU"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation>Перейти к позиции внутри текущего трека</translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation>Перейти вперёд</translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation>Перейти назад</translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_tr.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_tr.ts new file mode 100644 index 000000000..e435b589b --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_tr.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="tr_TR"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_uk_UA.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_uk_UA.ts new file mode 100644 index 000000000..897bf3716 --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_uk_UA.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="uk_UA"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_zh_CN.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_zh_CN.ts new file mode 100644 index 000000000..3d16e469b --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_zh_CN.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="zh_CN"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_zh_TW.ts b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_zh_TW.ts new file mode 100644 index 000000000..07bd47b7e --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/seek_plugin_zh_TW.ts @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="zh_TW"> +<context> + <name>SeekOption</name> + <message> + <location filename="../seekoption.cpp" line="38"/> + <source>Seek to position in the current track</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="39"/> + <source>Seek forward</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../seekoption.cpp" line="40"/> + <source>Seek backwards</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/src/plugins/CommandLineOptions/SeekOption/translations/translations.qrc b/src/plugins/CommandLineOptions/SeekOption/translations/translations.qrc new file mode 100644 index 000000000..e6f0345cf --- /dev/null +++ b/src/plugins/CommandLineOptions/SeekOption/translations/translations.qrc @@ -0,0 +1,15 @@ +<!DOCTYPE RCC> +<RCC version="1.0"> + <qresource> + <file>seek_plugin_it.qm</file> + <file>seek_plugin_pl.qm</file> + <file>seek_plugin_ru.qm</file> + <file>seek_plugin_de.qm</file> + <file>seek_plugin_cs.qm</file> + <file>seek_plugin_uk_UA.qm</file> + <file>seek_plugin_zh_TW.qm</file> + <file>seek_plugin_zh_CN.qm</file> + <file>seek_plugin_tr.qm</file> + <file>seek_plugin_lt.qm</file> + </qresource> +</RCC> diff --git a/src/ui/translations/qmmp_ru.ts b/src/ui/translations/qmmp_ru.ts index 5e28a9171..6df48129b 100644 --- a/src/ui/translations/qmmp_ru.ts +++ b/src/ui/translations/qmmp_ru.ts @@ -1600,7 +1600,7 @@ <message> <location filename="../qmmpstarter.cpp" line="72"/> <source>Unknown command</source> - <translation type="unfinished"></translation> + <translation>Неизвестная команда</translation> </message> <message> <location filename="../qmmpstarter.cpp" line="174"/> |
