1 /*
2  * Strawberry Music Player
3  * This file was part of Clementine.
4  * Copyright 2010, David Sansome <me@davidsansome.com>
5  * Copyright 2020-2021, Jonas Kvinge <jonas@jkvinge.net>
6  *
7  * Strawberry is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Strawberry is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Strawberry.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef PLAYLISTSEQUENCE_H
23 #define PLAYLISTSEQUENCE_H
24 
25 #include "config.h"
26 
27 #include <memory>
28 
29 #include <QObject>
30 #include <QWidget>
31 #include <QString>
32 #include <QIcon>
33 #include <QPixmap>
34 
35 class QMenu;
36 class QAction;
37 
38 class SettingsProvider;
39 class Ui_PlaylistSequence;
40 
41 class PlaylistSequence : public QWidget {
42   Q_OBJECT
43 
44  public:
45   explicit PlaylistSequence(QWidget *parent = nullptr, SettingsProvider *settings = nullptr);
46   ~PlaylistSequence() override;
47 
48   enum RepeatMode {
49     Repeat_Off = 0,
50     Repeat_Track = 1,
51     Repeat_Album = 2,
52     Repeat_Playlist = 3,
53     Repeat_OneByOne = 4,
54     Repeat_Intro = 5,
55   };
56   enum ShuffleMode {
57     Shuffle_Off = 0,
58     Shuffle_All = 1,
59     Shuffle_InsideAlbum = 2,
60     Shuffle_Albums = 3,
61   };
62 
63   static const char *kSettingsGroup;
64 
65   RepeatMode repeat_mode() const;
66   ShuffleMode shuffle_mode() const;
67 
repeat_menu()68   QMenu *repeat_menu() const { return repeat_menu_; }
shuffle_menu()69   QMenu *shuffle_menu() const { return shuffle_menu_; }
70 
set_dynamic(const bool dynamic)71   void set_dynamic(const bool dynamic) { dynamic_ = dynamic; }
72 
73  public slots:
74   void SetRepeatMode(const PlaylistSequence::RepeatMode mode);
75   void SetShuffleMode(const PlaylistSequence::ShuffleMode mode);
76   void CycleShuffleMode();
77   void CycleRepeatMode();
78 
79  signals:
80   void RepeatModeChanged(PlaylistSequence::RepeatMode mode);
81   void ShuffleModeChanged(PlaylistSequence::ShuffleMode mode);
82 
83  private slots:
84   void RepeatActionTriggered(QAction *action);
85   void ShuffleActionTriggered(QAction *action);
86 
87  private:
88   void Load();
89   void Save();
90   static QIcon AddDesaturatedIcon(const QIcon &icon);
91   static QPixmap DesaturatedPixmap(const QPixmap &pixmap);
92 
93  private:
94   Ui_PlaylistSequence *ui_;
95   std::unique_ptr<SettingsProvider> settings_;
96 
97   QMenu *repeat_menu_;
98   QMenu *shuffle_menu_;
99 
100   bool loading_;
101   RepeatMode repeat_mode_;
102   ShuffleMode shuffle_mode_;
103   bool dynamic_;
104 };
105 
106 #endif  // PLAYLISTSEQUENCE_H
107