forked from ebu/MXFTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylistEngine.hpp
446 lines (401 loc) · 12.4 KB
/
playlistEngine.hpp
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#ifndef CPP_PLAYLISTENGINE_CLASS_H
#define CPP_PLAYLISTENGINE_CLASS_H
/*!
* \project_name EBU Player
* \file playlistEngine.hpp
* \brief playlist engine specifications
* \details This class is used to implement the functions required by the playlist
* \authors Marco Dos Santos Oliveira
* \version 0.1
* \date 5 march 2013
* \copyright GNU GPLv3
*
*/
#include <gtkmm/treeview.h>
#include <gtkmm/treemodel.h>
#include <gtkmm/treemodelcolumn.h>
#include <gtkmm/liststore.h>
#include <gtkmm/treeselection.h>
#include <gtkmm/stock.h>
#include <gtkmm/togglebutton.h>
#include <iostream>
#include <fstream>
#include <glibmm/convert.h>
#include "genericFeatures.hpp"
#ifdef _WIN32
#define NEWLINE "\r\n"
#elif defined macintosh // OS 9
#define NEWLINE "\r"
#else
#define NEWLINE "\n" // Mac OS X uses \n
#endif
#define COLORSELECTED "#FF4422"
#define COLORPLAY "#11FF11"
#define COLOREVEN "#F9F9F9"
#define COLORODD "#EEEEEE"
class playlistEngine : public Gtk::TreeView
{
public:
/*!*
* @brief Class constructor
* @brief The playlistEngine class constructor instantiates the features and behavior of the playlist.\n\n
* @param[in] cobject : GObject is the fundamental type providing the common attributes and methods for all object types in GTK+. In this case, cobject define the instantiate gtk widget
* @param[in] refGlade : This is the reference to your glade design
*/
playlistEngine
(
void
);
virtual ~playlistEngine
(
void
);
/**
* @fn void setPlaylist(std::string pathToPlaylist, bool reset = false)
* @brief This function will set the path to the playlist file/directory.
* @brief
* @note needs more documentation
* @param[in] std::string pathToPlaylist : This string is the path to the playlist file/directory
* @param[in] bool reset :By the default, the reset switch of the playlist is set to false; it means that if we open a playlist, it will be appended to the current playlist. If the reset value is set to true, then the current playlist is closed and the new one is opened.
* @return nothing if all is right or an error at compilation time.
*/
void setPlaylist
(
std::string pathToPlaylist,
bool reset = false
);
/**
* @fn void setFile(std::vector<std::string> file)
* @brief This function will add files into the current playlist.
* @brief
* @note needs more documentation
* @param[in] std::vector<std::string> file : a vector with the path to all added files. Each path is a string.
* @return nothing if all is right or an error at compilation time.
*/
void setFile
(
std::vector<std::string> file,
bool reset = false
);
/**
* @fn void writeM3UFile(std::string filename)
* @brief This function will write the current playlist as a M3U playlist
* @brief
* @note needs more documentation
* @param[in] std::string filename : path to the output m3u file
* @return std::string if all is right or an error at compilation time.
*/
void writeM3UFile
(
std::string filename
);
/**
* @fn void removeFile(void)
* @brief This function will remove a file into the playlist.
* @brief The deletion occurs only if a file is currently selected.
* @note needs more documentation
* @param[in] void : no param.
* @return nothing if all is right or an error at compilation time.
*/
void removeFile
(
void
);
/**
* @fn bool isEmpty(void)
* @brief This function will say if the playlist is empty or not.
* @brief
* @note needs more documentation
* @param[in] void : no param.
* @return bool if all is right or an error at compilation time.
*/
bool isEmpty
(
void
);
/**
* @fn void setRefRemoveButton(Gtk::Button & btn)
* @brief This function will say if there are more than one track selected.
* @brief
* @note needs more documentation
* @param[in] void : no param.
* @return bool if all is right or an error at compilation time.
*/
void setRefButton
(
Gtk::Button * del
);
/**
* @fn void setState(const Gtk::StockID& stock_id)
* @brief This callback function will forward the track state to the playlist engine
* @brief
* @note needs more documentation
* @param[in] const Gtk::StockID& stock_id : gtk stock id
* @return nothing if all is right or an error at compilation time.
*/
void setState
(
Gtk::StockID stock_id
);
/**
* @fn Glib::ustring getURItoFile(void)
* @brief This callback function will forward the URI of the current track
* @brief
* @note needs more documentation
* @param[in] void : no paramas
* @return Glib::ustring if all is right or an error at compilation time.
*/
Glib::ustring getURItoFile
(
void
);
/**
* @fn Glib::ustring getNameOfFile(void)
* @brief This callback function will forward the name of the current track
* @brief
* @note needs more documentation
* @param[in] void : no paramas
* @return Glib::ustring if all is right or an error at compilation time.
*/
std::string getNameOfFile
(
void
);
void nextTrack
(
void
);
void previousTrack
(
void
);
void randomTrack
(
void
);
bool isLastTrack
(
void
);
/**
* @fn void setNewTrackState(Gtk::ToggleButton * state)
* @brief This function will indicates when a double-clicked track must be played from the playlist
* @brief
* @note needs more documentation
* @param[in] Gtk::ToggleButton * state : A toggle button supports signal, a simple bool doesn't support it
* @return nothing if all is right or an error at compilation time.
*/
void setNewTrackState
(
Gtk::ToggleButton * state
);
protected:
//Tree model columns
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{
add(playlistidcol);
add(playlistposcol);
add(playlistnamecol);
add(playlistlengthcol);
add(playlistformatcol);
add(playliststatecol);
add(playlistdateofcreationcol);
add(playlisturlcol);
add(playlistcellbgcolorcol);
}
Gtk::TreeModelColumn<std::size_t> playlistidcol;
Gtk::TreeModelColumn<unsigned int> playlistposcol;
Gtk::TreeModelColumn<std::string> playlistnamecol;
Gtk::TreeModelColumn<Glib::ustring> playlistlengthcol;
Gtk::TreeModelColumn<Glib::ustring> playlistformatcol;
Gtk::TreeModelColumn<Glib::RefPtr< Gdk::Pixbuf >> playliststatecol;
Gtk::TreeModelColumn<Glib::ustring> playlistdateofcreationcol;
Gtk::TreeModelColumn<Glib::ustring> playlisturlcol;
Gtk::TreeModelColumn<Glib::ustring> playlistcellbgcolorcol;
};
ModelColumns playlistColumns;
Glib::RefPtr<Gtk::ListStore> playlistStore;
Glib::RefPtr<Gtk::TreeSelection> playlistTreeviewSelection;
std::vector<Gtk::TreeModel::Path> playlistPathList;
std::vector<std::string> pathfilestoplay;
unsigned int selectedTrack;
int position;
std::size_t trackToPlay;
Gtk::StockID trackToPlayState;
Gtk::Button * removeBtn;
Gtk::TreeModel::Row previousRow;
unsigned int previousID;
Glib::RefPtr< Gdk::Pixbuf > stateNull;
Glib::RefPtr< Gdk::Pixbuf > previousState;
Gtk::ToggleButton * playlistNewTrack; /*!< playlistNewTrack boolean to know if a new track is set */
/**
* @fn void configurePlaylistTreeview(void)
* @brief To configure the Gtk treeview which will receives the playlist data structure
* @brief
* @note needs more documentation
* @param[in] void : no params
* @return nothing if all is right or an error at compilation time.
*/
void configurePlaylistTreeview
(
void
);
/**
* @fn std::string writeRelativePath(const std::string& filename, const std::string& path)
* @brief This function will write the path to the file like a relative path
* @brief
* @note needs more documentation
* @param[in] const std::string& filename : the name of the file
* @param[in] const std::string& path : the absolute path to the directory where is the file set by the filename argument
* @return std::string if all is right or an error at compilation time.
*/
std::string writeRelativePath
(
const std::string& filename,
const std::string& path
);
/**
* @fn std::string convertIntoRelativePath(const std::string& filename, const std::string& path)
* @brief This function will convert the absolute file path into relative path.
* @brief
* @note needs more documentation
* @param[in] const std::string& filename : the name of the file
* @param[in] const std::string& path : the absolute path to the directory where is the file set by the filename argument
* @return std::string if all is right or an error at compilation time.
*/
std::string convertIntoRelativePath
(
const std::string& filename,
const std::string& path
);
/**
* @fn unsigned int getSize(void)
* @brief This function will return the size of the current playlist
* @brief
* @param[in] void : no params
* @return int if all is right or an error at compilation time.
*/
unsigned int getSize
(
void
);
void on_treeview_row_activated
(
const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn* column
);
/**
* @fn bool on_playlist_selection_changed(GdkEventButton* event)
* @brief This callback function will detect the file selection changes into the playlist
* @brief
* @note needs more documentation
* @param[in] event : GdkEventButton
* @return bool if all is right or an error at compilation time.
*/
bool on_playlist_selection_changed
(
GdkEventButton* event
);
/**
* @fn bool keyPressed(GdkEventKey *event)
* @brief This callback function will detect when a keyboard button is pressed.
* @brief
* @note needs more documentation
* @param[in] event : GdkEventKey
* @return bool if all is right or an error at compilation time.
*/
bool keyPressed
(
GdkEventKey* event
);
/**
* @fn bool keyReleased(GdkEventKey *event)
* @brief This callback function will detect when a keyboard button is released.
* @brief
* @note needs more documentation
* @param[in] event : GdkEventKey
* @return bool if all is right or an error at compilation time.
*/
bool keyReleased
(
GdkEventKey* event
);
/**
* @fn void on_row_deleted(const Gtk::TreeModel::Path& path)
* @brief This callback function will detect when a file is removed from the playlist
* @brief
* @note needs more documentation
* @param[in] path : const Gtk::TreeModel::Path&
* @return bool if all is right or an error at compilation time.
*/
void on_row_deleted
(
const Gtk::TreeModel::Path& path
);
/**
* @fn void on_row_added(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter)
* @brief This callback function will detect when a file is added to the playlist
* @brief
* @note needs more documentation
* @param[in] path : const Gtk::TreeModel::Path&
* @param[in] iter : const Gtk::TreeModel::iterator&
* @return nothing if all is right or an error at compilation time.
*/
/*void on_row_added
(
const Gtk::TreeModel::Path& path,
const Gtk::TreeModel::iterator& iter
);*/
/**
* @fn void on_row_reordored(const Glib::RefPtr<Gdk::DragContext>& context)
* @brief This callback function will detect when the playlist is reordered.
* @brief
* @note needs more documentation
* @param[in] context : const Glib::RefPtr<Gdk::DragContext>&
* @return nothing if all is right or an error at compilation time.
*/
void on_row_reordered
(
const Glib::RefPtr<Gdk::DragContext>& context
);
/**
* @fn void colorizePlaylist(bool reordered)
* @brief This function will color the playlist rows and update the row id
* @brief
* @note needs more documentation
* @param[in] bool reordered : this boolean will determine if the playlist is being reordered or not
* @return nothing if all is right or an error at compilation time.
*/
void colorizePlaylist
(
bool reordered = false
);
/**
* @fn bool isSelected(void)
* @brief This function will say if a track is selected into the playlist or not.
* @brief
* @note needs more documentation
* @param[in] void : no param.
* @return bool if all is right or an error at compilation time.
*/
bool isSelected
(
void
);
/**
* @fn bool hasMultipleSelection(void)
* @brief This function will say if there are more than one track selected.
* @brief
* @note needs more documentation
* @param[in] void : no param.
* @return bool if all is right or an error at compilation time.
*/
bool hasMultipleSelection
(
void
);
};
#endif /*CPP_PLAYLISTENGINE_CLASS_H*/