Qmmp
commandlinehandler.h
1 /***************************************************************************
2  * Copyright (C) 2008-2019 by Ilya Kotov *
3  * forkotov02@ya.ru *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef COMMANDLINEHANDLER_H
21 #define COMMANDLINEHANDLER_H
22 
23 #include <QString>
24 #include <QMap>
25 #include <QStringList>
26 #include <QtPlugin>
27 #include <QFlags>
28 #include "qmmpui_export.h"
29 
33 class QMMPUI_EXPORT CommandLineHandler
34 {
35 public:
39  virtual ~CommandLineHandler() {}
43  virtual void registerOprions() = 0;
48  virtual QString shortName() const = 0;
53  virtual QString translation() const = 0;
61  virtual QString executeCommand(int id, const QStringList &args) = 0;
65  QStringList helpString() const;
71  QString helpString(int id) const;
77  int identify(const QString &name) const;
83  {
84  HIDDEN_FROM_HELP = 0x1,
85  NO_START = 0x2
86  };
87  Q_DECLARE_FLAGS(OptionFlags, OptionFlag)
92  CommandLineHandler::OptionFlags flags(int id) const;
93 
94 protected:
102  void registerOption(int id, const QString &name, const QString &helpString, const QStringList &values = QStringList());
110  void registerOption(int id, const QStringList &names, const QString &helpString, const QStringList &values = QStringList());
116  void setOptionFlags(int id, OptionFlags flags);
117 
118 private:
119  struct CommandLineOption
120  {
121  QStringList names;
122  QStringList values;
123  QString helpString;
124  OptionFlags flags;
125 
126  inline bool operator == (const CommandLineOption &opt) const
127  {
128  return names == opt.names &&
129  values == opt.values &&
130  helpString == opt.helpString &&
131  flags == opt.flags;
132  }
133  };
134 
135  QMap<int, CommandLineOption> m_options;
136 };
137 
138 Q_DECLARE_OPERATORS_FOR_FLAGS(CommandLineHandler::OptionFlags)
139 Q_DECLARE_INTERFACE(CommandLineHandler,"CommandLineHandlerInterface/1.0")
140 
141 #endif
virtual ~CommandLineHandler()
Definition: commandlinehandler.h:39
Abstract base class of the command line plugins.
Definition: commandlinehandler.h:33
OptionFlag
Definition: commandlinehandler.h:82