1 /*
2  * Strawberry Music Player
3  * This file was part of Clementine.
4  * Copyright 2010, David Sansome <me@davidsansome.com>
5  * Copyright 2018-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 PLAYLISTCONTAINER_H
23 #define PLAYLISTCONTAINER_H
24 
25 #include "config.h"
26 
27 #include <QObject>
28 #include <QWidget>
29 #include <QString>
30 #include <QIcon>
31 #include <QSettings>
32 
33 class QTimer;
34 class QTimeLine;
35 class QLabel;
36 class QAction;
37 class QEvent;
38 class QKeyEvent;
39 class QResizeEvent;
40 
41 class Playlist;
42 class PlaylistManager;
43 class PlaylistView;
44 
45 class Ui_PlaylistContainer;
46 
47 class PlaylistContainer : public QWidget {
48   Q_OBJECT
49 
50  public:
51   explicit PlaylistContainer(QWidget *parent = nullptr);
52   ~PlaylistContainer() override;
53 
54   static const char *kSettingsGroup;
55 
56   void SetActions(QAction *new_playlist, QAction *load_playlist, QAction *save_playlist, QAction *clear_playlist, QAction *next_playlist, QAction *previous_playlist);
57   void SetManager(PlaylistManager *manager);
58   void ReloadSettings();
59 
60   bool SearchFieldHasFocus() const;
61   void FocusSearchField();
62 
63   PlaylistView *view() const;
64 
65   bool eventFilter(QObject *objectWatched, QEvent *event) override;
66 
67  signals:
68   void TabChanged(int id);
69   void Rename(int id, QString new_name);
70 
71   void UndoRedoActionsChanged(QAction *undo, QAction *redo);
72   void ViewSelectionModelChanged();
73 
74  protected:
75   // QWidget
76   void resizeEvent(QResizeEvent*) override;
77 
78  private slots:
79   void NewPlaylist();
80   void LoadPlaylist();
SaveCurrentPlaylist()81   void SaveCurrentPlaylist() { SavePlaylist(-1); }
82   void SavePlaylist(const int id);
83   void ClearPlaylist();
84   void GoToNextPlaylistTab();
85   void GoToPreviousPlaylistTab();
86 
87   void SetViewModel(Playlist *playlist, const int scroll_position);
88   void PlaylistAdded(const int id, const QString &name, bool favorite);
89   void PlaylistClosed(const int id);
90   void PlaylistRenamed(const int id, const QString &new_name);
91 
92   void Started();
93 
94   void Save();
95 
96   void SetTabBarVisible(const bool visible);
97   void SetTabBarHeight(const int height);
98 
99   void SelectionChanged();
100   void MaybeUpdateFilter();
101   void UpdateFilter();
102   void FocusOnFilter(QKeyEvent *event);
103 
104   void UpdateNoMatchesLabel();
105 
106  public slots:
107   void ActivePlaying();
108   void ActivePaused();
109   void ActiveStopped();
110 
111  private:
112   void UpdateActiveIcon(const QIcon &icon);
113   void RepositionNoMatchesLabel(bool force = false);
114 
115  private:
116   static const int kFilterDelayMs;
117   static const int kFilterDelayPlaylistSizeThreshold;
118 
119   Ui_PlaylistContainer *ui_;
120 
121   PlaylistManager *manager_;
122   QAction *undo_;
123   QAction *redo_;
124   Playlist *playlist_;
125 
126   QSettings settings_;
127   bool starting_up_;
128 
129   bool tab_bar_visible_;
130   QTimeLine *tab_bar_animation_;
131 
132   QLabel *no_matches_label_;
133 
134   QTimer *filter_timer_;
135 };
136 
137 #endif  // PLAYLISTCONTAINER_H
138