summaryrefslogtreecommitdiff
path: root/gd_content_interface.h
blob: 5d2626b4daf35241f3aa7fedae4c45f53e21508f (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
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/*! 
 * \file   gd_content_interface.h
 * \brief  Data objects for content (e.g. mp3 files, movies)
 *         for the vdr muggle plugin database
 *          
 * \version $Revision: 1.11 $
 * \date    $Date: 2004/08/30 14:31:43 $
 * \author  Ralf Klueber, Lars von Wedel, Andreas Kellner
 * \author  Responsible author: $Author: LarsAC $
 * 
 * Declares main classes for content items and interfaces to SQL databases
 *
 * This file defines the following classes 
 *  - gdFilterSets:  filters to specifically search for GD items
 *  - mgGdTrack:     a single track (content item). e.g. an mp3 file
 *  - GdTracklist:
 *  - GdPlaylist:
 *  - GdTreeNode:
 */

#ifndef _GD_CONTENT_INTERFACE_H
#define _GD_CONTENT_INTERFACE_H

#include <string>
#include <vector>

#include <mysql/mysql.h>

#include "mg_content_interface.h"
#include "mg_media.h"

#include "mg_playlist.h"
#include "mg_filters.h"
#include "i18n.h"

/*! 
 * \brief Initialize a database for GD use
 * \todo Should be a static member of some GD class
 */
int GdInitDatabase(MYSQL *db);

/*! 
 * \brief Obtain the playlists stored within the GD schema
 * \todo Should be a static member of some GD class
 */
std::vector<std::string> *GdGetStoredPlaylists(MYSQL db);

/*! 
 * \brief A set of filters to search for content
 */
class gdFilterSets : public mgFilterSets 
{

 public:

  /*! \addtogroup Object creation and destruction */
  /*\@{*/

  /*!
   * \brief the default constructor
   *
   * Constructs a number ( >= 1 ) of filter sets where
   * the first (index 0) is active by default.
   */
  gdFilterSets();

  /*!
   * \brief the destructor
   */
  virtual ~gdFilterSets();

  /*\@}*/

  /*!
   * \brief compute restriction w.r.t active filters
   *
   * Computes the (e.g. sql) restrictions specified by
   * the active filter sets.
   *
   * \param viewPort - after call, contains the index of the appropriate default view in  
   * \return  sql string representing the restrictions
   * \todo should viewPort be a reference?
   */
  virtual std::string computeRestriction(int *viewPort);
};


/*! 
 * \brief represents a a single track 
 *
 * This may be any content item. e.g. a mp3 fileselection
 * The object is initially created with a database identifier.
 * The actual data is only read when a content field is accessed for
 * the first time. For subsequent access, cached values are used.
 *
 * \todo does each track node need a reference to the database?
 *       maybe we can use a static db handle in mgDatabase?
 */
class mgGdTrack : public mgContentItem
{
 public:
 
  /*! \addtogroup Object creation and destruction */
  /*\@{*/

  /*! 
   * \brief a constructor 
   * 
   * Creates an invalid item.
   *
   * \todo does this make sense? used anywhere?
   */
  mgGdTrack()
  { 
    m_uniqID = -1;
  }  
  
  /*!
   * \brief a constructor for a specific item
   *
   * The constructor creates a specific item in a given database
   * On creation, the object is only a wrapper without data. Actual 
   * data fields are filled when readData() is called for the first time.
   *
   * \param sqlIdentifier - a unique ID of the item which will be represented
   * \param dbase - the database in which the item exists
   */
  mgGdTrack( int sqlIdentifier, MYSQL dbase );

  /*!
   * \brief a copy constructor
   */
  mgGdTrack(const mgGdTrack&);

  /*!
   * \brief the destructor 
   */
  virtual ~mgGdTrack();

  /*\@}*/
  
  /*!
   * \brief obtain the content type of the item
   */
  virtual mgContentItem::contentType getContentType()
    {
      return mgContentItem::GD_AUDIO;
    }
  
  /*!
   * \brief obtain the associated player object
   *
   * \todo what is this used for?
   */
  virtual mgMediaPlayer getPlayer()
    {
      return mgMediaPlayer();
    }

  /*! \addtogroup Data read access */
  /*\@{*/

  /*!
   * \brief returns a certain field of the item as a string
   *
   *    0 - title
   *    1 - artist
   *    2 - album
   *    3 - genre
   */
  virtual std::string getLabel( int col = 0 );

  /*!
   * \brief returns value for the track title
   */
  virtual std::string getTitle();  

  /*!
   * \brief returns value for the location of the track on disk
   */
  virtual std::string getSourceFile();  

  /*!
   * \brief returns the genre of the track
   */
  virtual std::string getGenre();  

  /*!
   * \brief returns the artist of the track
   */
  std::string getArtist();

  /*!
   * \brief returns value the album to which the track belongs
   */
  std::string getAlbum();

  /*!
   * \brief obtain the location of the image file
   */
  std::string getImageFile();

  /*!
   * \brief obtain the year of the track
   */
  int getYear();

  /*!
   * \brief obtain the duration of the track
   */
  int getDuration();

  /*!
   * \brief obtain the rating of the track
   */
  virtual int getRating();

  /*!
   * \brief obtain the complete track information
   */
  virtual std::vector<mgFilter*> *getTrackInfo();  

  /*\@}*/

  /*! \addtogroup Data write access */ 
  /*\@{*/

  /*!
   * \brief set the title of the track
   */
  void setTitle(std::string new_title);

  /*!
   * \brief set the title of the track
   */
  void setArtist(std::string new_artist);

  /*!
   * \brief set the album name of the track
   */
  void setAlbum(std::string new_album);

  /*!
   * \brief set the genre of the track
   */
  void setGenre(std::string new_genre);

  /*!
   * \brief set the year of the track
   */
  void setYear(int new_year);

  /*!
   * \brief set the rating of the track
   */
  void setRating(int new_rating);

  /*!
   * \brief set complete information of the track
   */
  virtual bool setTrackInfo(std::vector<mgFilter*>*);

  /*!
   * \brief make changes persistent
   *
   * The changes made using the setXxx methods are not
   * stored persistently in the database until writeData
   * is called.
   *
   * \note only the tracks table in the SQL database is updated.
   * Genre and album field information is lost.
   */
  bool writeData();

  /*\@}*/

  //! \brief a special instance denoting an undefined track
  static mgGdTrack UNDEFINED;

private:

  /*! 
   * \brief the database in which the track resides 
   */
  MYSQL m_db;
  
  /*!
   * \brief a dirty flag
   *
   * false, if content field values have not yet been retrieved
   * from the database. Set to true when contents are retrieved
   * (on demand only).
   */
  bool m_retrieved;

  /*! 
   * \brief the artist name
   */
  std::string m_artist;

  /*! 
   * \brief the track title
   */
  std::string m_title;

  /*!
   * \brief the filename
   */
  std::string m_mp3file;

  /*!
   * \brief The album to which the file belongs
   */
  std::string m_album;

  /*!
   * \brief The genre of the music
   */
  std::string m_genre; 
  
  /*!
   * \brief The year in which the track appeared
   */
  int m_year; 
  
  /*!
   * \brief The rating by the user
   */
  int m_rating;
  
  /*!
   * \brief The length of the file in bytes.
   * \todo TODO: is this true? Or what length are we talking about?
   */
  int m_length;

  /*!
   * \brief Access the data of the item from the database and fill actual data fields
   *
   * In order to avoid abundant queries to the database, the content fields
   * of the mgGdTrack object may not be filled upon creation. As soon as the 
   * first content field is needed, this private function is called to fill 
   * all content fields at once.
   */
  bool readData();

};

/* 
 * \brief a list of tracks stored in the databas
 */
class GdTracklist : public mgTracklist
{
 public:

  GdTracklist(MYSQL db_handle, std::string restrictions);
};

/*! 
 * \class GdPlaylist
 *
 * \brief represents a playlist, i.e. an ordered collection of tracks
 */
class  GdPlaylist : public mgPlaylist
{	  
 public:
     
  /*! \addtogroup Object creation and destruction */
  /*\@{*/

  /*! 
   * \brief opens an existing or creates empty playlist by name
   *
   * If the playlist does not yet exist, an empty playlist is created.
   *
   * \param listname  - user-readable identifier of the paylist
   * \param db_handle - database which stores the playlist
   */
  GdPlaylist(std::string listname, MYSQL db_handle);

  /*! 
   * \brief destructor
   *
   * \note the destructor only destroys the in-memory footprint of the playlist,
   *       it does not modify the database.
   */
  virtual ~GdPlaylist();

  /* \@} */
     
  /*!
   * changes the listname of the playlist (and unset the sql id)
   */
  virtual void setListname(std::string name);
  
  /*!
   * returns the total duration of all songs in the list in seconds
   */
  int getPlayTime();
  
  /*! 
   * returns the duration of all remaining songs in the list in seconds 
   */
  int getPlayTimeRemaining();

  /*! 
   * \brief write data back to the database
   */
  bool storePlaylist();

 private:

  /*!
   * \brief reads the track list from the sql database into memory
   */
  int insertDataFromSQL();

  //! \brief the database identifier of the list
  int m_sqlId; 
  
  //! \brief the list type used in GiantDisc db queries
  int m_listtype;

  //! \brief the author of the playlist
  std::string m_author;
  
  //! \brief the handle to the database in which the list is stored
  MYSQL m_db;  
};

/*! 
 * \brief hierarchical representation of a set of tracks
 *
 * The selection can be based on the whole database or a subset of it.
 * Within this selection, the data is organized in a tree hierarchy
 * The levels hof the hierarchy can be expanded dynamically by specifying
 * the database field  for the next expansion step
 * In this way, the expnasion scheme (order of the fields) is not static.
 * When a node is expanded, a list of children is created. 
 * Each child inherits the restrictions of its father and an additional
 * restriction on the recently expanded db field
 */
class GdTreeNode : public mgSelectionTreeNode
{
public:

  /*! \addtogroup Object creation and destruction */
  /*\@{*/

  /*! 
   * \brief Construct a top level tree node in a certain view with certain filters 
   */
  GdTreeNode(MYSQL db, int view, std::string filters);
  
  /*! 
   * \brief Construct a subordinate tree node with given labels and restrictions
   */
  GdTreeNode(mgSelectionTreeNode* parent,
	     std::string id, std::string label, std::string restriction); 

  /*! 
   * \brief destructor to clean up the object
   */
  virtual ~GdTreeNode();

  /* \@} */

  /*! \addtogroup Access node data */
  /*\@{*/

  /*!
   * \brief check, whether the node is a leaf node (i.e. has no more children)
   */
  virtual bool isLeafNode();

  /*!
   * \brief expand the node and generate child nodes according to restrictions passed in the constructor
   */
  virtual bool expand();  

  /*!
   * \brief obtain the tracks in this node
   */
  virtual std::vector<mgContentItem*>* getTracks();

  /*!
   * \brief obtain a single track in this node
   */
  virtual mgContentItem* getSingleTrack();

  /* \@} */
};

/* -------------------- begin CVS log ---------------------------------
 * $Log: gd_content_interface.h,v $
 * Revision 1.11  2004/08/30 14:31:43  LarsAC
 * Documentation added
 *
 * Revision 1.10  2004/08/27 15:19:34  LarsAC
 * Changed formatting and documentation
 *
 * Revision 1.9  2004/07/29 06:17:50  lvw
 * Added todo entries
 *
 * Revision 1.8  2004/07/06 00:20:51  MountainMan
 * loading and saving playlists
 *
 * Revision 1.7  2004/05/28 15:29:18  lvw
 * Merged player branch back on HEAD branch.
 *
 *
 * Revision 1.6  2004/02/23 15:41:21  RaK
 * - first i18n attempt
 *
 * Revision 1.5  2004/02/12 09:15:07  LarsAC
 * Moved filter classes into separate files
 *
 * Revision 1.4.2.6  2004/05/25 00:10:45  lvw
 * Code cleanup and added use of real database source files
 *
 * Revision 1.4.2.5  2004/04/01 21:35:32  lvw
 * Minor corrections, some debugging aid.
 *
 * Revision 1.4.2.4  2004/03/14 17:57:30  lvw
 * Linked against libmad. Introduced config options into code.
 *
 * Revision 1.4.2.3  2004/03/10 13:11:24  lvw
 * Added documentation
 *
 * Revision 1.4.2.2  2004/03/08 07:14:27  lvw
 * Preliminary changes to muggle player
 *
 * Revision 1.4.2.1  2004/03/02 07:05:50  lvw
 * Initial adaptations from MP3 plugin added (untested)
 *
 * Revision 1.6  2004/02/23 15:41:21  RaK
 * - first i18n attempt
 *
 * Revision 1.5  2004/02/12 09:15:07  LarsAC
 * Moved filter classes into separate files
 *
 * Revision 1.4  2004/02/09 19:27:52  MountainMan
 * filter set implemented
 *
 * Revision 1.3  2004/02/02 22:48:04  MountainMan
 *  added CVS $Log
 *
 *
 * --------------------- end CVS log ----------------------------------
 */
#endif  /* END  _GD_CONTENT_INTERFACE_H */