summaryrefslogtreecommitdiff
path: root/muggle-plugin/sh_dummy_content.c
blob: 1ccfe9e24c5d9e18357b999c48c2f6a1fd759f0e (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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/*******************************************************************/
/*! \file  content_interface.cpp
 * \brief  Data Objects for content (e.g. mp3 files, movies)
 * for the vdr muggle plugindatabase
 ******************************************************************** 
 * \version $Revision: 1.3 $
 * \date    $Date: 2004/02/02 22:48:04 $
 * \author  Ralf Klueber, Lars von Wedel, Andreas Kellner
 * \author  file owner: $Author: MountainMan $
 *
 * DUMMY
 * 
 * 
 * Dummy artists: Artist_1, Artist_2, Artist_3
 * Dummy albums by ArtistX: Album_X1, .... AlbumX3
 * Dummy Tracks On Album_XY: Track_XY1,... Track_XY5
 *
 */
/*******************************************************************/
#define DEBUG

#include "sh_dummy_content.h"
#include "mg_tools.h"

#include <strstream>
#include <string>
#define GD_PLAYLIST_TYPE 0 // listtype for giant disc db

// some dummies to keep the compiler happy
#define DUMMY_CONDITION true // we use that as dummy condition to satisfy C++ syntax
#define DUMMY
#define NUM_ARTISTS 5
#define NUM_ALBUMS_PER_ARTIST 3
#define NUM_TRACKS_PER_ALBUM 9

int DummyInitDatabase(MYSQL *db){return 0;}
vector<string> *DummyGetStoredPlaylists(MYSQL db){ return new vector<string>();}

/*******************************************************************/
/* class mgTack                                                    */
/********************************************************************/
DummyTrack DummyTrack::UNDEFINED =  DummyTrack();

/*!
 *****************************************************************************
 * \brief Constructor: creates a DummyTrack obect
 *
 * \param sqlIdentifier identifies a unique row in the track database
 * \param dbase  database which stores the track table
 *
 * On creation, the object contains only the idea. The actual data fields
 * are filled when readData() is called for the first time.
 ****************************************************************************/
DummyTrack::DummyTrack(int sqlIdentifier, MYSQL dbase)
{
  m_uniqID = sqlIdentifier;
  char buf[255];

  mgDebug(9, "Creating dumy track %d", sqlIdentifier);
  // create dummy value based on the id
  sprintf(buf, "ArtistName_%d", (int)  m_uniqID / 100);
  m_artist  = buf;
  sprintf(buf,"Album_%d",  (int)  m_uniqID / 10); 
  m_album   =  buf;
  sprintf(buf,"Track_%d",m_uniqID);
  m_title   =  buf;
  sprintf(buf,"sourcefile_%d", m_uniqID);
  m_mp3file =  buf;
  m_genre   =  "unknown_genre";
  m_year = 1970 + (m_uniqID%35); 
  m_rating = 2;
  m_length = 180;
}

/*!
 *****************************************************************************
 * \brief copy constructor
 *
 ****************************************************************************/
DummyTrack::DummyTrack(const DummyTrack& org)
{
  m_uniqID = org.m_uniqID;
  m_db    = org.m_db;

  mgDebug(9, 
	"Creating a TrackCopy for track '%s' (is this really necessary?",
	org.m_title.c_str());

  m_artist = org.m_artist;
  m_title = org.m_title;
  m_mp3file = org.m_mp3file;
  m_album = org.m_album;
  m_genre = org.m_genre; 
  m_year = org.m_year; 
  m_rating = org.m_rating;  

}
  

/*!
 *****************************************************************************
 * \brief destructor
 *
 ****************************************************************************/
DummyTrack::~DummyTrack()
{
  // nothing to be done
}

/*!
 *****************************************************************************
 * \brief returns value for _mp3file
 ****************************************************************************/
string DummyTrack::getSourceFile()
{
    return m_mp3file;
}

/*!
 *****************************************************************************
 * \brief returns value for m_title
 ****************************************************************************/
string DummyTrack::getTitle()
{
    return m_title;
}

/*!
 *****************************************************************************
 * \brief returns value for m_artist
 ****************************************************************************/
string DummyTrack::getArtist()
{
    return m_artist;
}
string DummyTrack::getLabel(int col)
{
    switch(col)
    {
	case 0:
	  return m_artist;
	  break;
        case 1:
	  return  m_title;
	  break;
    default:
      return "";
    }
}
string DummyTrack::getDescription()
{
    return m_artist + " - " +  m_title;
}

/*!
 *****************************************************************************
 * \brief returns value for m_album
 ****************************************************************************/
string DummyTrack::getAlbum()
{
    return m_album;
}
  
/*!
 *****************************************************************************
 * \brief returns value for m_genre
 ****************************************************************************/
string DummyTrack::getGenre()
{
    return m_genre;
}

/*!
 *****************************************************************************
 * \brief returns value for m_year
 ****************************************************************************/
int DummyTrack::getYear()
{
    return m_year;
}

/*!
 *****************************************************************************
 * \brief returns value for m_rating
 *
 * If value has not been retrieved from the database, radData() is called first
 ****************************************************************************/
int DummyTrack::getRating()
{
    return m_rating;
}

int DummyTrack::getDuration()
{
    return m_rating;
}

/*!
 *****************************************************************************
 * \brief sets the field for m_title to the specified value
 *
 * Note: The new value is not stored in the database. 
 * This is only done, when writeData() is called
 ****************************************************************************/
void DummyTrack::setTitle(string new_title)
{
    m_title = new_title;
}

/*!
 *****************************************************************************
 * \brief sets the field for m_artist to the specified value
 *
 * Note: The new value is not stored in the database. 
 * This is only done, when writeData() is called
 ****************************************************************************/
void DummyTrack::setArtist(string new_artist)
{
    m_artist =  new_artist;
}


/*!
 *****************************************************************************
 * \brief sets the field for m_album to the specified value
 *
 * Note: The new value is not stored in the database. 
 * This is only done, when writeData() is called
 ****************************************************************************/
void DummyTrack::setAlbum(string new_album)
{
    m_album = new_album;
}


/*!
 *****************************************************************************
 * \brief sets the field for m_genre to the specified value
 *
 * Note: The new value is not stored in the database. 
 * This is only done, when writeData() is called
 ****************************************************************************/
void DummyTrack::setGenre(string new_genre)
{
    m_genre = new_genre;
}


/*!
 *****************************************************************************
 * \brief sets the field for m_year to the specified value
 *
 * Note: The new value is not stored in the database. 
 * This is only done, when writeData() is called
 ****************************************************************************/
void DummyTrack::setYear(int new_year)
{
    m_year = new_year;
}


/*!
 *****************************************************************************
 * \brief sets the field for m_rating to the specified value
 *
 * Note: The new value is not stored in the database. 
 * This is only done, when writeData() is called
 ****************************************************************************/
void DummyTrack::setRating(int new_rating)
{
    m_rating = new_rating;
}


/*!
 *****************************************************************************
 * \brief stores current values in the sql database
 *
 * Note: At the moment, only the values stored directly in the 'tracks' 
 * database are updated 
 ****************************************************************************/
bool DummyTrack::writeData()
{
    return true;
}

DummyTracklist::DummyTracklist(MYSQL db_handle, string restrictions)
{
}

/*******************************************************************/
/* class DummyPlaylist                                              */
/********************************************************************/

/*!
 *****************************************************************************
 * \brief Constructor: opens playlist by name 
 *
 * \param listname user-readable identifier of the paylist
 * \param db_handl database which stores the playlist
 *
 * If the playlist does not yet exist, an empty playlist is created
 ****************************************************************************/
DummyPlaylist::DummyPlaylist(string listname, MYSQL db_handle)
{
    m_db = db_handle;

    //
    // check, if the database really exists 
    //
    if(listname =="EXISTS")
    {
	
	m_author = "DUMMY_author";
	m_listname = listname;
	createDummyPlaylist(1);
    }
    else
    {
	// new Playlist 	
	m_author = "VDR";
	m_listname = listname;

    }
    	
}

/*!
 *****************************************************************************
 * \brief Constructor: construct playlist object from existing sql playlist
 *
 * \param sql_identifier: sql internal identifier for the playlist 
 * \param db_handl database which stores the playlist
 *
 * This constructor is typically used when a playlist is selected from an
 * internal list of playlists 
 ****************************************************************************/
DummyPlaylist::DummyPlaylist(unsigned int sql_identifier, MYSQL db_handle)
{
    m_db = db_handle;
    char buf[256];

    m_author = "DUMMY_author";
    sprintf(buf, "Dummylist_%d", sql_identifier);
    m_listname =  buf;
    createDummyPlaylist(sql_identifier);
}

void DummyPlaylist::createDummyPlaylist(int start)
{
    DummyTrack* trackptr;
    for(int id=start; id < start+20; id++)
    {  
	trackptr = new DummyTrack(id, m_db);
	m_list.push_back(trackptr);
    }
}

/*!
 *****************************************************************************
 * \brief empty destructor
 *
 * Nothing to be done. The actual data is stored in the sql db
 ****************************************************************************/
DummyPlaylist::~DummyPlaylist()
{
    // nothing to be done
}

bool DummyPlaylist::storePlaylist()
{
    mgDebug(1, "Storing Playlist #%s'", m_listname.c_str());
    return true;
}
/*!
 *****************************************************************************
 * \brief returns the total duration of all songs in the list in seconds 
 *
 ****************************************************************************/
int DummyPlaylist::getPlayTime()
{
    return m_list.size()* 180;
}

/*!
 *****************************************************************************
 * \brief returns the duration of all remaining songs in the list in seconds
 *
 ****************************************************************************/
int DummyPlaylist::getPlayTimeRemaining()
{
  return 0; // dummy 
}

/*******************************************************************/
/* class DummyTreeNode                                       */
/*******************************************************************/

DummyTreeNode::DummyTreeNode(MYSQL db, int view)
  :  mgSelectionTreeNode(db, view)
{
    // create a root node
    // everything is done in the parent class
    m_restriction ="1";
}

DummyTreeNode::DummyTreeNode(mgSelectionTreeNode* parent,
			     string id, string label, string restriction)
  :  mgSelectionTreeNode(parent, id, label)
{
    m_restriction = restriction;
    // everything else is done in the parent class
}


/*!
 *****************************************************************************
 * \brief destructor
 *
 ****************************************************************************/
DummyTreeNode::~DummyTreeNode()
{
  m_children.clear();
}

/*!
 *****************************************************************************
 * \brief checks if this node can be further expandded or not
 * \true, if node ia leaf node, false if node can be expanded
 *
 ****************************************************************************/
bool DummyTreeNode::isLeafNode()
{
    switch(m_view)
     {
	 case 1: // artist -> album -> title
	     if( m_level <= 3 )
	     {
		 return true;
	     }
	     break;
	 default:
	     mgError("View '%d' not yet implemented", m_view);
     }
    return false;
}


/*!
 *****************************************************************************
 * \brief compute children on the fly 
 *
 ****************************************************************************/
bool DummyTreeNode::expand()
{
  char buf[20];
  if (m_expanded)
  {
      mgWarning("Node already expanded\n");
      return true;
  }
  m_expanded = true;

  mgDebug(5, "Expanding level %d\n", m_level);
  switch(m_view)
  {
    case 1: // artist -> album -> title
     if(m_level == 0) // root, expand artist
     {
       for(int artnum=1; artnum <= NUM_ARTISTS; artnum++)
       {
	 sprintf(buf, "%d", artnum);
	 m_children.push_back(new DummyTreeNode(this, m_id+ (string) buf,
					       "Artist "+ (string)buf,
					       m_restriction + " AND album.artist='Artist "+(string) buf+"'"));
       }

     }
     else if(m_level == 1) // artist, expand album
     {
	 // create album names in the form Album_x1, ... Album_x3
	 // where x is the artist ID
	 // for normal usage: _restrictions should now hold:
	 // album.artist = XYZ
       for(int albnum=1; albnum <= NUM_ALBUMS_PER_ARTIST; albnum++)
       {
	 sprintf(buf, "%d", albnum);
	 
	 m_children.push_back(new DummyTreeNode(this, m_id+ (string) buf,
					       "Album_"+ m_id +  (string) buf,
					       m_restriction + " AND track.sourceid='0x00"+ m_id + (string) buf +"'"));
       }
       break;
     }
     else if(m_level == 2) // artist -> album, expand title
     {
	 // create track names in the form Track_xy1, ... Track_xy5
	 // where x is the artist ID and y is the album id
	 // for normal usage: _restrictions should now hold:
	 // album.artist = ... AND track.sourceid='0x00XY
       for(int tracknum=1; tracknum <= NUM_TRACKS_PER_ALBUM; tracknum++)
       {
	 sprintf(buf, "%d", tracknum);
	 m_children.push_back(new DummyTreeNode(this, m_id+ (string) buf,
					       "Track_"+m_id+ (string) buf,
					       m_restriction + " AND track.id=tr"+ m_id + (string) buf + "'" ));
       }
       break;
     }
     else
     {
	 mgWarning("View #%d level %d' not yet implemented", m_view, m_level);
	 m_expanded = false;
	 return false;
     }
     break;
   default:
       mgError("View '%d' not yet implemented", m_view);
  }
  mgDebug(5, "%d children expanded\n", m_children.size());
  return true;
}

/*!
 *****************************************************************************
 * \brief go over all children recursively to find the tracks
 *
 ****************************************************************************/
vector<mgContentItem*>* DummyTreeNode::getTracks()
{
  vector<mgContentItem*>* dummy;
  string sql;
 
  int artistnum;
  int albumnum;
  int tracknum;
  dummy = new  vector<mgContentItem*>();
  
  sql = m_restriction;
  mgDebug(5, "QUERY:\n%s\n", sql.c_str());

  artistnum = 0;
  do  // artist_loop
  {
      if(m_level >=1)
	  artistnum = m_id[0]-'0'; // we have a unique artist
      else
	  artistnum++; // we are in a loop

      albumnum = 0;
      do  // album_loop
      { 
	  if(m_level >=2)
	      albumnum = m_id[1]-'0';  // we have a unique album
	  else
	      albumnum++; // we are in a loop
        
	  tracknum =0;
	  do  // track_loop
	  {
	      if(m_level ==3)
		  tracknum = m_id[2]-'0';  // we have a unique track
	      else
		  tracknum++; // we are in a loop
	      dummy->push_back(new DummyTrack(artistnum*100+albumnum*10+tracknum, m_db));
	  }while ((m_level < 3) && (tracknum<  NUM_TRACKS_PER_ALBUM));
      }while ((m_level < 2) && (albumnum < NUM_ALBUMS_PER_ARTIST));
  }while ((m_level < 1) && (artistnum < NUM_ARTISTS ));

  return  dummy;
}

/*!
 *****************************************************************************
 * \brief returns the first track matchin the restrictions of this node
 * assuming we are in a leaf node, this returns the track represented by the
 * the leaf 
 ****************************************************************************/
mgContentItem* DummyTreeNode::getSingleTrack()
{
    // get all tracks satisying the restrictions of this node
    mgDebug(5, "getTracks(): query '%s'", m_restriction.c_str());
    
    mgContentItem* track = new DummyTrack(atoi(m_id.c_str()), m_db);

    return  track;
}

/* -------------------- begin CVS log ---------------------------------
 * $Log: sh_dummy_content.c,v $
 * Revision 1.3  2004/02/02 22:48:04  MountainMan
 *  added CVS $Log
 *
 *
 * --------------------- end CVS log ----------------------------------
 */