1 /*
2  * Strawberry Music Player
3  * This file was part of Clementine.
4  * Copyright 2010, David Sansome <me@davidsansome.com>
5  *
6  * Strawberry is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Strawberry is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Strawberry.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef COMMANDLINEOPTIONS_H
22 #define COMMANDLINEOPTIONS_H
23 
24 #include "config.h"
25 
26 #include <QDataStream>
27 #include <QByteArray>
28 #include <QList>
29 #include <QString>
30 #include <QUrl>
31 
32 class CommandlineOptions {
33   friend QDataStream &operator<<(QDataStream &s, const CommandlineOptions &a);
34   friend QDataStream &operator>>(QDataStream &s, CommandlineOptions &a);
35 
36  public:
37   explicit CommandlineOptions(int argc = 0, char **argv = nullptr);
38 
39   static const char *kHelpText;
40   static const char *kVersionText;
41 
42   // Don't change the values or order, these get serialised and sent to
43   // possibly a different version of Strawberry
44   enum UrlListAction {
45     UrlList_Append = 0,
46     UrlList_Load = 1,
47     UrlList_None = 2,
48     UrlList_CreateNew = 3,
49   };
50   enum PlayerAction {
51     Player_None = 0,
52     Player_Play = 1,
53     Player_PlayPause = 2,
54     Player_Pause = 3,
55     Player_Stop = 4,
56     Player_Previous = 5,
57     Player_Next = 6,
58     Player_RestartOrPrevious = 7,
59     Player_StopAfterCurrent = 8,
60     Player_PlayPlaylist = 9,
61     Player_ResizeWindow = 10
62   };
63 
64   bool Parse();
65 
66   bool is_empty() const;
67   bool contains_play_options() const;
68 
url_list_action()69   UrlListAction url_list_action() const { return url_list_action_; }
player_action()70   PlayerAction player_action() const { return player_action_; }
set_volume()71   int set_volume() const { return set_volume_; }
volume_modifier()72   int volume_modifier() const { return volume_modifier_; }
seek_to()73   int seek_to() const { return seek_to_; }
seek_by()74   int seek_by() const { return seek_by_; }
play_track_at()75   int play_track_at() const { return play_track_at_; }
show_osd()76   bool show_osd() const { return show_osd_; }
toggle_pretty_osd()77   bool toggle_pretty_osd() const { return toggle_pretty_osd_; }
urls()78   QList<QUrl> urls() const { return urls_; }
language()79   QString language() const { return language_; }
log_levels()80   QString log_levels() const { return log_levels_; }
playlist_name()81   QString playlist_name() const { return playlist_name_; }
window_size()82   QString window_size() const { return window_size_; }
83 
84   QByteArray Serialize() const;
85   void Load(const QByteArray &serialized);
86 
87  private:
88   // These are "invalid" characters to pass to getopt_long for options that shouldn't have a short (single character) option.
89   enum LongOptions {
90     VolumeUp = 256,
91     VolumeDown,
92     SeekTo,
93     SeekBy,
94     Quiet,
95     Verbose,
96     LogLevels,
97     Version,
98     VolumeIncreaseBy,
99     VolumeDecreaseBy,
100     RestartOrPrevious
101   };
102 
103   static QString tr(const char *source_text);
104   void RemoveArg(const QString &starts_with, int count);
105 
106  private:
107   int argc_;
108   char **argv_;
109 
110   UrlListAction url_list_action_;
111   PlayerAction player_action_;
112 
113   // Don't change the type of these.
114   int set_volume_;
115   int volume_modifier_;
116   int seek_to_;
117   int seek_by_;
118   int play_track_at_;
119   bool show_osd_;
120   bool toggle_pretty_osd_;
121   QString language_;
122   QString log_levels_;
123   QString playlist_name_;
124   QString window_size_;
125 
126   QList<QUrl> urls_;
127 };
128 
129 QDataStream &operator<<(QDataStream &s, const CommandlineOptions &a);
130 QDataStream &operator>>(QDataStream &s, CommandlineOptions &a);
131 
132 #endif  // COMMANDLINEOPTIONS_H
133