diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-12-25 20:50:08 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-12-25 20:50:08 +0000 |
| commit | c28061c4cf64e468dd3e230df1b96d1a72e295fd (patch) | |
| tree | 85cdef77d8851ab89e8a57ba1d5f823531a15831 /src/plugins/CommandLineOptions/PlayListOption | |
| parent | 164e24517d01eb95f74563cc66a691adf07ed514 (diff) | |
| download | qmmp-c28061c4cf64e468dd3e230df1b96d1a72e295fd.tar.gz qmmp-c28061c4cf64e468dd3e230df1b96d1a72e295fd.tar.bz2 qmmp-c28061c4cf64e468dd3e230df1b96d1a72e295fd.zip | |
fixed command line plugins
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8532 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/CommandLineOptions/PlayListOption')
| -rw-r--r-- | src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp | 74 | ||||
| -rw-r--r-- | src/plugins/CommandLineOptions/PlayListOption/playlistoption.h | 30 |
2 files changed, 60 insertions, 44 deletions
diff --git a/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp b/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp index cc0ff7cf0..8906e7ea2 100644 --- a/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp +++ b/src/plugins/CommandLineOptions/PlayListOption/playlistoption.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2011-2017 by Ilya Kotov * + * Copyright (C) 2011-2019 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -28,35 +28,39 @@ #include <qmmpui/commandlinemanager.h> #include "playlistoption.h" -CommandLineProperties PlayListOption::properties() const +PlayListOption::PlayListOption() { - CommandLineProperties properties; - properties.shortName = "PlayListOption"; - properties.helpString << QString("--pl-help") + "||" + tr("Show playlist manipulation commands"); - return properties; + registerOption(PL_HELP, "--pl-help", tr("Show playlist manipulation commands")); + registerOption(PL_LIST, "--pl-list", tr("List all available playlists")); + registerOption(PL_DUMP, "--pl-dump", tr("Show playlist content"), QStringList() << "id"); + registerOption(PL_PLAY, "--pl-play", tr("Play track <track> in playlist <id>"), QStringList() << "id" << "track"); + registerOption(PL_CLEAR, "--pl-clear", tr("Clear playlist"), QStringList() << "id"); + registerOption(PL_REPEATE_TOGGLE, "--pl-repeat-toggle", tr("Toggle playlist repeat")); + registerOption(PL_SHUFFLE_TOGGLE, "--pl-shuffle-toggle", tr("Toggle playlist shuffle")); + registerOption(PL_STATE, "--pl-state", tr("Show playlist options")); } -bool PlayListOption::identify(const QString & str) const +QString PlayListOption::shortName() const { - return str == QString("--pl-help") || - str == QString("--pl-list") || - str == QString("--pl-dump") || - str == QString("--pl-play") || - str == QString("--pl-clear") || - str == QString("--pl-repeat-toggle") || - str == QString("--pl-shuffle-toggle") || - str == QString("--pl-state"); + return QLatin1String("PlayListOption"); } -QString PlayListOption::executeCommand(const QString& opt_str, const QStringList &args) +QString PlayListOption::translation() const +{ + return QLatin1String(":/playlist_plugin_"); +} + +QString PlayListOption::executeCommand(int id, const QStringList &args) { - Q_UNUSED(args); QString out; PlayListManager *pl_manager = PlayListManager::instance(); MediaPlayer *player = MediaPlayer::instance(); QmmpUiSettings *ui_settings = QmmpUiSettings::instance(); - if(opt_str == "--pl-help") + + switch (id) + { + case PL_HELP: { QStringList list = QStringList() << QString("--pl-list") + "||" + tr("List all available playlists") @@ -70,7 +74,8 @@ QString PlayListOption::executeCommand(const QString& opt_str, const QStringList foreach (QString line, list) out += CommandLineManager::formatHelpString(line) + "\n"; } - else if(opt_str == "--pl-list") + break; + case PL_LIST: { QStringList names = pl_manager->playListNames(); for(int i = 0; i < names.count(); ++i) @@ -81,7 +86,8 @@ QString PlayListOption::executeCommand(const QString& opt_str, const QStringList out += QString("%1. %2\n").arg(i+1).arg(names.at(i)); } } - else if(opt_str == "--pl-dump") + break; + case PL_DUMP: { MetaDataFormatter formatter("%p%if(%p&%t, - ,)%t%if(%p,,%if(%t,,%f))%if(%l, - %l,)"); int id = args.isEmpty() ? pl_manager->currentPlayListIndex() : args.at(0).toInt() - 1; @@ -99,7 +105,8 @@ QString PlayListOption::executeCommand(const QString& opt_str, const QStringList out += "\n"; } } - else if(opt_str == "--pl-play") + break; + case PL_PLAY: { if(args.count() > 2 || args.isEmpty()) return tr("Invalid number of arguments") + "\n"; @@ -119,7 +126,8 @@ QString PlayListOption::executeCommand(const QString& opt_str, const QStringList model->setCurrent(track); player->play(); } - else if(opt_str == "--pl-clear") + break; + case PL_CLEAR: { int id = args.isEmpty() ? pl_manager->currentPlayListIndex() : args.at(0).toInt() - 1; PlayListModel *model = pl_manager->playListAt(id); @@ -127,29 +135,25 @@ QString PlayListOption::executeCommand(const QString& opt_str, const QStringList return tr("Invalid playlist ID") + "\n"; model->clear(); } - else if(opt_str == "--pl-repeat-toggle") - { + break; + case PL_REPEATE_TOGGLE: ui_settings->setRepeatableList(!ui_settings->isRepeatableList()); - } - else if(opt_str == "--pl-shuffle-toggle") - { + break; + case PL_SHUFFLE_TOGGLE: ui_settings->setShuffle(!ui_settings->isShuffle()); - } - else if(opt_str == "--pl-state") - { + break; + case PL_STATE: out += "SHUFFLE: " + boolToText(ui_settings->isShuffle()) + "\n"; out += "REPEAT PLAYLIST: " + boolToText(ui_settings->isRepeatableList()) + "\n"; out += "REPEAT TRACK: " + boolToText(ui_settings->isRepeatableTrack()) + "\n"; out += "NO PLAYLIST ADVANCE: " + boolToText(ui_settings->isNoPlayListAdvance()) + "\n"; + break; + default: + ; } return out; } -QString PlayListOption::translation() const -{ - return QLatin1String(":/playlist_plugin_"); -} - QString PlayListOption::boolToText(bool enabled) { return QString(enabled ? "[+]" : "[-]"); diff --git a/src/plugins/CommandLineOptions/PlayListOption/playlistoption.h b/src/plugins/CommandLineOptions/PlayListOption/playlistoption.h index 22d67d048..de6d35ae4 100644 --- a/src/plugins/CommandLineOptions/PlayListOption/playlistoption.h +++ b/src/plugins/CommandLineOptions/PlayListOption/playlistoption.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2011-2017 by Ilya Kotov * + * Copyright (C) 2011-2019 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -24,24 +24,36 @@ #include <QString> #include <QObject> #include <QStringList> -#include <qmmpui/commandlineoption.h> +#include <qmmpui/commandlinehandler.h> #include <qmmpui/commandlinemanager.h> /** @author Ilya Kotov <forkotov02@ya.ru> */ -class PlayListOption : public QObject, public CommandLineOption +class PlayListOption : public QObject, public CommandLineHandler { Q_OBJECT -Q_PLUGIN_METADATA(IID "org.qmmp.qmmpui.CommandLineOptionInterface.1.0") -Q_INTERFACES(CommandLineOption) +Q_PLUGIN_METADATA(IID "org.qmmp.qmmpui.CommandLineHandlerInterface.1.0") +Q_INTERFACES(CommandLineHandler) public: - virtual CommandLineProperties properties() const; - virtual bool identify(const QString& opt_str) const; - virtual QString executeCommand(const QString& opt_str, const QStringList &args); - virtual QString translation() const; + PlayListOption(); + QString shortName() const; + QString translation() const; + QString executeCommand(int id, const QStringList &args); private: + enum Command + { + PL_HELP = 0, + PL_LIST, + PL_DUMP, + PL_PLAY, + PL_CLEAR, + PL_REPEATE_TOGGLE, + PL_SHUFFLE_TOGGLE, + PL_STATE + }; + QString boolToText(bool enabled); }; |
