aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2018-12-24 21:25:49 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2018-12-24 21:25:49 +0000
commit515a1723150c48becd8dca94a9e1d1f9f8b38131 (patch)
treee6642ae149bcaaeb664085db37c147cfdd5ded65
parent7dd05abe318e1026ab254ff70b4c84a9b46cfff9 (diff)
downloadqmmp-515a1723150c48becd8dca94a9e1d1f9f8b38131.tar.gz
qmmp-515a1723150c48becd8dca94a9e1d1f9f8b38131.tar.bz2
qmmp-515a1723150c48becd8dca94a9e1d1f9f8b38131.zip
changed command line plugin api
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8530 90c681e8-e032-0410-971d-27865f9a5e38
-rw-r--r--src/qmmpui/CMakeLists.txt5
-rw-r--r--src/qmmpui/commandlinehandler.cpp58
-rw-r--r--src/qmmpui/commandlinehandler.h (renamed from src/qmmpui/commandlineoption.h)79
-rw-r--r--src/qmmpui/commandlinemanager.cpp29
-rw-r--r--src/qmmpui/commandlinemanager.h12
-rw-r--r--src/qmmpui/qmmpui.pro12
6 files changed, 137 insertions, 58 deletions
diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt
index 6b61f85ab..ffd148b3c 100644
--- a/src/qmmpui/CMakeLists.txt
+++ b/src/qmmpui/CMakeLists.txt
@@ -22,6 +22,7 @@ SET(libqmmpui_SRCS
uihelper.cpp
playlistparser.cpp
commandlinemanager.cpp
+ commandlinehandler.cpp
filedialog.cpp
qtfiledialog.cpp
fileloader.cpp
@@ -63,7 +64,7 @@ SET(libqmmpui_HDRS
generalfactory.h
playlistformat.h
commandlinemanager.h
- commandlineoption.h
+ commandlinehandler.h
filedialogfactory.h
playstate_p.h
playlistitem.h
@@ -86,7 +87,7 @@ SET(libqmmpui_HDRS
SET(libqmmpui_DEVEL_HDRS
commandlinemanager.h
- commandlineoption.h
+ commandlinehandler.h
configdialog.h
detailsdialog.h
filedialogfactory.h
diff --git a/src/qmmpui/commandlinehandler.cpp b/src/qmmpui/commandlinehandler.cpp
new file mode 100644
index 000000000..05dda3c73
--- /dev/null
+++ b/src/qmmpui/commandlinehandler.cpp
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * Copyright (C) 2008-2019 by Ilya Kotov *
+ * forkotov02@ya.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., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "commandlinehandler.h"
+
+QStringList CommandLineHandler::helpString() const
+{
+ QStringList out;
+ foreach (const CommandLineOption &opt, m_options.values())
+ {
+ if(opt.values.isEmpty())
+ out << opt.names.join(", ") + "||" + opt.helpString;
+ else
+ out << opt.names.join(", ") + " <" + opt.values.join("> <") + ">||" + opt.helpString;
+ }
+ return out;
+}
+
+int CommandLineHandler::identify(const QString &name) const
+{
+ foreach (const CommandLineOption &opt, m_options.values())
+ {
+ if(opt.names.contains(name))
+ return m_options.key(opt);
+ }
+ return -1;
+}
+
+void CommandLineHandler::registerOption(int id, const QStringList &names, const QString &helpString)
+{
+ registerOption(id, names, QStringList(), helpString);
+}
+
+void CommandLineHandler::registerOption(int id, const QStringList &names, const QStringList &values, const QString &helpString)
+{
+ CommandLineOption opt;
+ opt.names = names;
+ opt.values = values;
+ opt.helpString = helpString;
+ m_options.insert(id, opt);
+}
diff --git a/src/qmmpui/commandlineoption.h b/src/qmmpui/commandlinehandler.h
index 1b2255dc5..82769a678 100644
--- a/src/qmmpui/commandlineoption.h
+++ b/src/qmmpui/commandlinehandler.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008-2017 by Ilya Kotov *
+ * Copyright (C) 2008-2018 by Ilya Kotov *
* forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -17,59 +17,76 @@
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef COMMANDLINEOPTION_H
-#define COMMANDLINEOPTION_H
+#ifndef COMMANDLINEHANDLER_H
+#define COMMANDLINEHANDLER_H
+#include <QString>
+#include <QMap>
+#include <QStringList>
+#include <QtPlugin>
#include "qmmpui_export.h"
+
class CommandLineManager;
class QString;
class QObject;
class QStringList;
-/*! @brief Helper class to store command line plugin properties.
- * @author Ilya Kotov <forkotov02@ya.ru>
- */
-class CommandLineProperties
-{
-public:
- QString shortName; /*!< Input plugin short name for internal usage */
- QStringList helpString; /*!< A list of specially formatted help strings.
- Example: "--help||Display this text and exit" */
-};
/*! @brief Abstract base class of the command line plugins.
* @author Vladimir Kuznetsov <vovanec@gmail.ru>
*/
-class QMMPUI_EXPORT CommandLineOption
+class QMMPUI_EXPORT CommandLineHandler
{
public:
/*!
- * Returns command line plugin properties.
- */
- virtual CommandLineProperties properties() const = 0;
- /*!
- * Returns \b true if \b opt_str string can be processed,
- * otherise \b false
+ * Object destructor
*/
- virtual bool identify(const QString& opt_str) const = 0;
+ virtual ~CommandLineHandler() {}
/*!
- * Parses \b opt_str args(if needed), executes command.
- * @param opt_str Command to execute
- * @param args Command arguments
- * @return Command output
+ * Returns command line plugin short name for internal usage.
+ * Subclass should reimplement this function.
*/
- virtual QString executeCommand(const QString &opt_str, const QStringList &args) = 0;
+ virtual QString shortName() const = 0;
/*!
- * Object destructor
+ * Returns translation file path without locale code and extension.
+ * Subclass should reimplement this function.
*/
- virtual ~CommandLineOption() {}
+ virtual QString translation() const = 0;
/*!
- * Returns translation file path without locale code and extension
+ * Executes given command.
+ * Subclass should reimplement this function.
+ * @param id Command id to execute
+ * @param args Command arguments
+ * @return Command output
*/
- virtual QString translation() const = 0;
+ virtual QString executeCommand(int id, const QStringList &args) = 0;
+
+ QStringList helpString() const;
+ int identify(const QString &name) const;
+
+protected:
+ void registerOption(int id, const QStringList &names, const QString &helpString);
+ void registerOption(int id, const QStringList &names, const QStringList &values, const QString &helpString);
+
+private:
+ struct CommandLineOption
+ {
+ QStringList names;
+ QStringList values;
+ QString helpString;
+
+ inline bool operator == (const CommandLineOption &opt) const
+ {
+ return names == opt.names &&
+ values == opt.values &&
+ helpString == opt.helpString;
+ }
+ };
+
+ QMap<int, CommandLineOption> m_options;
};
-Q_DECLARE_INTERFACE(CommandLineOption,"CommandLineOptionInterface/1.0")
+Q_DECLARE_INTERFACE(CommandLineHandler,"CommandLineHandlerInterface/1.0")
#endif
diff --git a/src/qmmpui/commandlinemanager.cpp b/src/qmmpui/commandlinemanager.cpp
index f2571839f..f91510f5e 100644
--- a/src/qmmpui/commandlinemanager.cpp
+++ b/src/qmmpui/commandlinemanager.cpp
@@ -34,15 +34,15 @@
using namespace std;
-QList<CommandLineOption *> *CommandLineManager::m_options = 0;
-QHash<CommandLineOption*, QString> *CommandLineManager::m_files = 0;
+QList<CommandLineHandler *> *CommandLineManager::m_options = 0;
+QHash<CommandLineHandler*, QString> *CommandLineManager::m_files = 0;
void CommandLineManager::checkOptions()
{
if (!m_options)
{
- m_options = new QList<CommandLineOption *>;
- m_files = new QHash<CommandLineOption*, QString>;
+ m_options = new QList<CommandLineHandler *>;
+ m_files = new QHash<CommandLineHandler*, QString>;
foreach (QString filePath, Qmmp::findPlugins("CommandLineOptions"))
{
@@ -53,9 +53,9 @@ void CommandLineManager::checkOptions()
else
qWarning("CommandLineManager: %s", qPrintable(loader.errorString ()));
- CommandLineOption *option = 0;
+ CommandLineHandler *option = 0;
if (plugin)
- option = qobject_cast<CommandLineOption *>(plugin);
+ option = qobject_cast<CommandLineHandler *>(plugin);
if (option)
{
@@ -72,7 +72,7 @@ void CommandLineManager::checkOptions()
}
}
-QString CommandLineManager::executeCommand(const QString& opt_str, const QStringList &args)
+QString CommandLineManager::executeCommand(const QString &name, const QStringList &args)
{
checkOptions();
if(!UiHelper::instance() || !SoundCore::instance() || !MediaPlayer::instance())
@@ -80,11 +80,12 @@ QString CommandLineManager::executeCommand(const QString& opt_str, const QString
qWarning("CommandLineManager: player objects are not created");
return QString();
}
- foreach(CommandLineOption *opt, *m_options)
+ foreach(CommandLineHandler *opt, *m_options)
{
- if (opt->identify(opt_str))
+ int id = opt->identify(name);
+ if(id >= 0)
{
- return opt->executeCommand(opt_str, args);
+ return opt->executeCommand(id, args);
}
}
return QString();
@@ -93,9 +94,9 @@ QString CommandLineManager::executeCommand(const QString& opt_str, const QString
bool CommandLineManager::hasOption(const QString &opt_str)
{
checkOptions();
- foreach(CommandLineOption *opt, *m_options)
+ foreach(CommandLineHandler *opt, *m_options)
{
- if (opt->identify(opt_str))
+ if (opt->identify(opt_str) >= 0)
return true;
}
return false;
@@ -104,9 +105,9 @@ bool CommandLineManager::hasOption(const QString &opt_str)
void CommandLineManager::printUsage()
{
checkOptions();
- foreach(CommandLineOption *opt, *m_options)
+ foreach(CommandLineHandler *opt, *m_options)
{
- foreach(QString line, opt->properties().helpString)
+ foreach(QString line, opt->helpString())
{
QString str = formatHelpString(line);
if(!str.isEmpty())
diff --git a/src/qmmpui/commandlinemanager.h b/src/qmmpui/commandlinemanager.h
index 5fecc7467..a57114ff2 100644
--- a/src/qmmpui/commandlinemanager.h
+++ b/src/qmmpui/commandlinemanager.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008-2018 by Ilya Kotov *
+ * Copyright (C) 2008-2019 by Ilya Kotov *
* forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -22,7 +22,7 @@
#include <QHash>
#include "general.h"
-#include "commandlineoption.h"
+#include "commandlinehandler.h"
#include "qmmpui_export.h"
@@ -34,11 +34,11 @@ class QMMPUI_EXPORT CommandLineManager
public:
/*!
* Executes command \b opt_str.
- * @param opt_str Command line option string.
+ * @param name Command line option name.
* @param args Command arguments.
* @return Command output result.
*/
- static QString executeCommand(const QString& opt_str, const QStringList &args = QStringList());
+ static QString executeCommand(const QString& name, const QStringList &args = QStringList());
/*!
* Return \b true if command \b opt_str is supported, otherwise returns \b false.
*/
@@ -55,8 +55,8 @@ public:
private:
static void checkOptions();
- static QList<CommandLineOption *> *m_options;
- static QHash<CommandLineOption*, QString> *m_files;
+ static QList<CommandLineHandler *> *m_options;
+ static QHash<CommandLineHandler*, QString> *m_files;
};
#endif
diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro
index f8b44d392..eef44225c 100644
--- a/src/qmmpui/qmmpui.pro
+++ b/src/qmmpui/qmmpui.pro
@@ -35,7 +35,6 @@ HEADERS += general.h \
playlistformat.h \
playlistparser.h \
commandlinemanager.h \
- commandlineoption.h \
filedialog.h \
filedialogfactory.h \
qtfiledialog_p.h \
@@ -74,7 +73,8 @@ HEADERS += general.h \
coverviewer_p.h \
metadataformattermenu.h \
qmmpui_export.h \
- covereditor_p.h
+ covereditor_p.h \
+ commandlinehandler.h
SOURCES += general.cpp \
playlistparser.cpp \
@@ -114,7 +114,8 @@ SOURCES += general.cpp \
metadatahelper.cpp \
coverviewer.cpp \
metadataformattermenu.cpp \
- covereditor.cpp
+ covereditor.cpp \
+ commandlinehandler.cpp
FORMS += forms/detailsdialog.ui \
forms/tageditor.ui \
@@ -148,12 +149,13 @@ TRANSLATIONS = translations/libqmmpui_ru.ts \
translations/libqmmpui_sr_BA.ts \
translations/libqmmpui_sr_RS.ts
unix {
- devel.files += general.h \
+ devel.files += \
+ commandlinehandler.h
+ general.h \
generalfactory.h \
playlistformat.h \
playlistparser.h \
commandlinemanager.h \
- commandlineoption.h \
filedialog.h \
filedialogfactory.h \
playlistitem.h \