summaryrefslogtreecommitdiffstats
path: root/kplayer/kplayerplaylist.h
blob: 52908fe03f099fd3cf52a055facecba161a547d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/***************************************************************************
                          kplayerplaylist.h
                          ------------------
    begin                : Wed Sep 3 2003
    copyright            : (C) 2003-2007 by kiriuja
    email                : http://kplayer.sourceforge.net/email.html
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef KPLAYERPLAYLIST_H
#define KPLAYERPLAYLIST_H

#include <tdeaction.h>
#include <kcombobox.h>

#include "kplayerprocess.h"
#include "kplayernode.h"
#include "kplayernodeaction.h"

/**The playlist combobox widget.
  *@author kiriuja
  */
class KPlayerPlaylistCombobox : public TQComboBox
{
  TQ_OBJECT

public:
  /** The KPlayerPlaylistCombobox constructor. */
  KPlayerPlaylistCombobox (TQWidget* parent = 0, const char* name = 0);

  /** Configuration. */
  KPlayerConfiguration* configuration (void) const
    { return KPlayerEngine::engine() -> configuration(); }

  /** Returns the popup menu. */
  TQPopupMenu* popupMenu (void) const
    { return m_popup; }
  /** Sets the popup menu. */
  void setPopupMenu (TQPopupMenu* menu)
    { m_popup = menu; }

  /** The size hint. */
  virtual TQSize sizeHint() const;
  /** The minimum size hint. */
  virtual TQSize minimumSizeHint() const;

protected:
  /** Displays the right click popup menu. */
  virtual void contextMenuEvent (TQContextMenuEvent*);

  /** Popup menu. */
  TQPopupMenu* m_popup;
};

/**Playlist class, contains the list of playlist items.
  *@author kiriuja
  */
class KPlayerPlaylist : public TQObject
{
  TQ_OBJECT

public:
  /** The KPlayerPlaylist constructor. Creates an empty playlist. */
  KPlayerPlaylist (TDEActionCollection* ac, TQObject* parent = 0, const char* name = 0);
  /** The KPlayerPlaylist destructor. */
  virtual ~KPlayerPlaylist();

  /** Initializes playlist. */
  void initialize (TQPopupMenu* menu);
  /** Releases referenced nodes. */
  void terminate (void);

  /** Engine. */
  KPlayerEngine* engine (void) const
    { return KPlayerEngine::engine(); }
  /** Configuration. */
  KPlayerConfiguration* configuration (void) const
    { return engine() -> configuration(); }
  /** Settings. */
  KPlayerSettings* settings (void) const
    { return engine() -> settings(); }
  /** Process. */
  KPlayerProcess* process (void) const
    { return engine() -> process(); }

  /** Now playing node. */
  KPlayerNowPlayingNode* nowplaying (void) const
    { return m_nowplaying; }

  /** Retrieves an action from the actionCollection by name. */
  TDEAction* action (const char* name) const
    { return m_ac -> action (name); }
  /** Retrieves a toggle action from the actionCollection by name. */
  TDEToggleAction* toggleAction (const char* name) const
    { return (TDEToggleAction*) action (name); }

  /** Returns the playlist action list. */
  KPlayerContainerActionList* playlistActionList (void) const
    { return m_playlists; }

  /** Returns the recent action list. */
  KPlayerNodeActionList* recentActionList (void) const
    { return m_recent; }
  /** Recents node. */
  KPlayerRecentsNode* recent (void) const
    { return (KPlayerRecentsNode*) recentActionList() -> node(); }

  /** Returns the devices action list. */
  KPlayerDevicesActionList* devicesActionList (void) const
    { return m_devices; }

  /** Returns the playlist add action list. */
  KPlayerContainerActionList* playlistAddActionList (void) const
    { return m_playlists_add; }

  /** Returns a pointer to the playlist combobox object. */
  KPlayerPlaylistCombobox* playlist (void)
    { return (KPlayerPlaylistCombobox*) ((KWidgetAction*) action ("player_list")) -> widget(); }

  /** List of nodes. */
  const KPlayerPlaylistNodeList& nodes (void) const
    { return m_nodes; }
  /** Returns whether the playlist is empty. */
  bool isEmpty (void) const
   { return nodes().isEmpty(); }
  /** Returns the number of items on the playlist. */
  uint count (void) const
   { return nodes().count(); }

  /** Returns the current node. */
  KPlayerNode* currentNode (void) const
    { return m_current; }
  /** Sets the current node. */
  void setCurrentNode (KPlayerNode* node);

  /** Returns the next node. */
  KPlayerNode* nextNode (void) const
    { return m_next.getFirst(); }
  /** Sets the next nodes. */
  void setNextNodes (const KPlayerNodeList& nodes);
  /** Adds the given nodes to the list of next nodes. */
  void addNextNodes (const KPlayerNodeList& nodes);

  /** Plays the given nodes. */
  void play (const KPlayerNodeList& list);
  /** Plays the given nodes after the currently played item finishes playing. */
  void playNext (const KPlayerNodeList& list);
  /** Queues the given nodes. */
  void queue (const KPlayerNodeList& list);
  /** Queues the given nodes for playing after the currently played item finishes playing. */
  void queueNext (const KPlayerNodeList& list);

  /** Puts the given list of URLs on the playlist and starts playback. */
  void playUrls (const KURL::List& list);
  /** Puts the given list of URLs on the playlist and plays them after the currently played item finishes playing. */
  void playNextUrls (const KURL::List& list);
  /** Adds the given list of URLs to the end of the playlist. */
  void queueUrls (const KURL::List& list);
  /** Adds the given list of URLs to the playlist and plays them after the currently played item finishes playing. */
  void queueNextUrls (const KURL::List& list);

  /** Shuffles the playlist entries. */
  void randomize (KPlayerNode* node = 0);

  /** Checks the given list of URLs for validity. */
  static bool checkUrls (const KURL::List& list);

signals:
  /** Emitted when playback starts. */
  void started (void);

  /** Emitted when a new item is chosen from the playlist and loaded into the engine. */
  void activated (void);

  /** Emitted when an item is finished playing and no new item will be loaded. */
  void stopped (void);

  /** Emitted when an action group is enabled or disabled. */
  void enableActionGroup (const TQString& name, bool enable);

public slots:
  /** Plays the given node. */
  void play (KPlayerNode* node);
  /** Plays the selected item. */
  void play (int index);
  /** Plays the current item. */
  void play (void);

  /** Plays the next item. */
  void next (void);
  /** Plays the previous item. */
  void previous (void);

  /** Toggles the option to loop through the playlist. */
  void loop (void);
  /** Toggles the option to play items in random order. */
  void shuffle (void);

  /** Displays the Open File dialog and starts playing the chosen file. */
  void filePlay (void);
  /** Displays the Open URL dialog and starts playing from the entered URL. */
  void filePlayUrl (void);

  /** Displays the Open File dialog and adds the chosen files to the playlist. */
  void addFiles (void);
  /** Displays the Open URL dialog and adds the entered URL to the playlist. */
  void addUrl (void);

  /** Saves the playlist as a new playlist. */
  void addToPlaylists (void);
  /** Adds the playlist items to an existing playlist. */
  void addToPlaylist (KPlayerNode*);
  /** Saves the playlist as a new folder in the collection. */
  void addToCollection (void);

protected slots:
  /** Adds the given nodes to the list. */
  void added (KPlayerContainerNode*, const KPlayerNodeList& nodes, KPlayerNode* after = 0);
  /** Removes the given nodes from the list. */
  void removed (KPlayerContainerNode*, const KPlayerNodeList& nodes);
  /** Updates the given node attributes. */
  void updated (KPlayerContainerNode* parent, KPlayerNode* node);

  /** Updates the playlist combobox. */
  void update (void);

  /** Plays the next item when appropriate. */
  void playerStateChanged (KPlayerProcess::State, KPlayerProcess::State);
  /** Adjusts the playlist to the user preferences. */
  void refreshSettings (void);

protected:
  /** Populates and connects the given node. */
  void attach (KPlayerContainerNode* node);
  /** Vacates and disconnects the given node. */
  void detach (KPlayerContainerNode* node);

  /** Appends the given nodes to the list. */
  void append (const KPlayerNodeList& nodes);
  /** Inserts the given nodes at the given location. */
  int insert (const KPlayerNodeList& nodes, int index);

  /** Enables or disables the next and previous actions according to the current state. */
  void enableNextPrevious (void) const;
  /** Updates actions according to the current state. */
  void updateActions (void) const;

  /** Now Playing node. */
  KPlayerNowPlayingNode* m_nowplaying;
  /** Current node. */
  KPlayerNode* m_current;
  /** Next nodes. */
  KPlayerNodeList m_next;
  /** List of nodes. */
  KPlayerPlaylistNodeList m_nodes;
  /** Action collection. */
  TDEActionCollection* m_ac;
  /** Set next node indicator. */
  bool m_set_next;
  /** Playlist action list. */
  KPlayerContainerActionList* m_playlists;
  /** Recent action list. */
  KPlayerNodeActionList* m_recent;
  /** Devices action list. */
  KPlayerDevicesActionList* m_devices;
  /** Playlist add action list. */
  KPlayerContainerActionList* m_playlists_add;
  /** Play requested indicator. */
  bool m_play_requested;
};

#endif