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
|
/*! \file mg_media.c
* \brief Top level access to media in vdr plugin muggle
*
* \version $Revision: 1.14 $
* \date $Date$
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner
* \author Responsible author: $Author$
*/
/* makes sure we dont parse the same declarations twice */
#include "mg_media.h"
#include "mg_tools.h"
#include "mg_content_interface.h"
#include "gd_content_interface.h"
#include "vdr_setup.h"
using namespace std;
//-------------------------------------------------------------------
// mgFilterSets
//-------------------------------------------------------------------
/*!
* \brief constructor
*
* constructor of the base class
*/
mgFilterSets::mgFilterSets()
{
// nothing to be done in the base class
}
mgFilterSets::~mgFilterSets()
{
vector<mgFilter*> *set;
for(vector<vector<mgFilter*>*>::iterator iter1 = m_sets.begin();
iter1 != m_sets.end(); iter1++)
{
set = *iter1;
for(vector<mgFilter*>::iterator iter2 = set->begin();
iter2 != set->end(); iter2++)
{
delete (*iter2);
}
set->clear();
delete set;
}
m_sets.clear();
}
/*!
*******************************************************************
* \brief returns the number of available sets
********************************************************************/
int mgFilterSets::numSets()
{
return m_sets.size();
}
/*!
*******************************************************************
* \brief proceeds to the next one in a circular fashion
********************************************************************/
void mgFilterSets::nextSet()
{
m_activeSetId++;
if(m_activeSetId >= (int) m_sets.size())
{
m_activeSetId = 0;
}
m_activeSet = m_sets[m_activeSetId];
}
//
/*!
*******************************************************************
* \brief activates a specific set by index
*
* \par n : index of the set to be activated
*
* If n is not a valid filter set, the first set (index 0 ) is activated
********************************************************************/
void mgFilterSets::select(int n)
{
m_activeSetId = n ;
if(m_activeSetId >= (int) m_sets.size())
{
m_activeSetId = 0;
}
m_activeSet = m_sets[m_activeSetId];
}
/*!
*******************************************************************
* \brief restores the default values for all filter values in the active set
********************************************************************/
void mgFilterSets::clear()
{
for(vector<mgFilter*>::iterator iter = m_activeSet->begin();
iter != m_activeSet->end(); iter++)
{
(*iter)->clear();
}
}
/*!
*******************************************************************
* \brief stores the current filter values
********************************************************************/
void mgFilterSets::accept()
{
for(vector<mgFilter*>::iterator iter = m_activeSet->begin();
iter != m_activeSet->end(); iter++)
{
(*iter)->store();
}
}
/*!
*******************************************************************
* \brief returns the active filter set to the application
*
* the application may temporarily modify the filter values
* accept() needs to be called to memorize the changed values
********************************************************************/
vector<mgFilter*> *mgFilterSets::getFilters()
{
for(vector<mgFilter*>::iterator iter = m_activeSet->begin();
iter != m_activeSet->end(); iter++)
{
(*iter)->restore();
}
return m_activeSet;
}
/*!
* \brief return title of the active filter set
*/
string mgFilterSets::getTitle()
{
if(m_activeSetId < (int) m_titles.size())
{
return m_titles[m_activeSetId];
}
else
{
mgWarning("Implementation error: No title string for filter set %d",
m_activeSetId);
return "NO-TITLE";
}
}
/*!
* \class mgMedia
*
* \brief mein class to access content in the vdr plugin muggle
*/
mgMedia::mgMedia(contentType mediatype)
{
int errval = 0;
m_filters = NULL;
m_mediatype = mediatype;
m_sql_filter = "1";
m_defaultView = 1;
// now initialize the database
mgDebug(1, "Media Type %sselected", getMediaTypeName().c_str());
switch(m_mediatype)
{
case GD_MP3:
{
errval = GdInitDatabase(&m_db);
mgDebug(3, "Successfully connected to sql database %s", the_setup.DbName );
}
}
if(errval < 0)
{
mgError("Error connecting to database\n");
}
mgDebug(3, "Initializing track filters");
switch(m_mediatype)
{
case GD_MP3:
{
errval = GdInitDatabase( &m_db ); // TODO: why duplicate this? LVW
mgDebug(3, "Successfully conntected to sql database %s", the_setup.DbName );
}
}
}
mgMedia::~mgMedia()
{
if( m_filters )
{
delete m_filters;
}
}
string mgMedia::getMediaTypeName()
{
switch(m_mediatype)
{
case GD_MP3:
{
return "GiantDisc";
} break;
}
mgError("implementation Error"); // we should never get here
return "";
}
mgSelectionTreeNode* mgMedia::getSelectionRoot()
{
switch(m_mediatype)
{
case GD_MP3:
return new GdTreeNode(m_db, m_defaultView, m_sql_filter);
}
mgError("implementation Error"); // we should never get here
return NULL;
}
mgPlaylist* mgMedia::createTemporaryPlaylist()
{
string tmpname = "current";
return loadPlaylist( tmpname );
}
mgPlaylist* mgMedia::loadPlaylist(string name)
{
mgPlaylist *list;
switch( m_mediatype )
{
case GD_MP3:
{
list = new GdPlaylist( name, m_db );
list->setDisplayColumns(getDefaultCols());
return list;
} break;
}
mgError("Implementation error: Unknown media type"); // we should never get here
return NULL;
}
/*!
* \brief Obtain a list of stored playlists
*/
vector<string> *mgMedia::getStoredPlaylists()
{
switch(m_mediatype)
{
case GD_MP3:
{
return GdGetStoredPlaylists( m_db );
} break;
}
mgError("implementation Error"); // we should never get here
return new vector<string>();
}
/*!
* \brief obtain the indices of columns which are presented by default
*/
vector<int> mgMedia::getDefaultCols()
{
vector<int> cols;
switch(m_mediatype)
{
case GD_MP3:
{
cols.push_back(1); // artist
cols.push_back(0); // track
return cols;
} break;
}
mgError("implementation Error"); // we should never get here
return cols;
}
/*!
* \brief
*/
mgTracklist* mgMedia::getTracks()
{
mgTracklist *tracks;
switch(m_mediatype)
{
case GD_MP3:
tracks = new GdTracklist(m_db, m_sql_filter);
tracks->setDisplayColumns(getDefaultCols());
return tracks;
}
mgError("implementation Error"); // we should never get here
return NULL;
}
/*!
* \brief creates FiliterSetObject for the selected media type
* and activates set n (if available)
*/
void mgMedia::initFilterSet(int num)
{
switch(m_mediatype)
{
case GD_MP3:
{
m_filters = new gdFilterSets();
m_filters->select(num);
} break;
}
}
/*!
*******************************************************************
* \brief returns pointer to the activen filter set to be modified by the osd
*
* Note: Modifications become only effective by calling applyActiveFilter()
********************************************************************/
vector<mgFilter*> *mgMedia::getActiveFilters()
{
if(!m_filters)
{
mgError("ImplementationError: getActiveFilters m_filters == NULL");
}
return m_filters->getFilters();
}
/*!
* \brief returns title of the active filter set
*/
string mgMedia::getActiveFilterTitle()
{
switch(m_mediatype)
{
case GD_MP3:
{
if( !m_filters )
{
mgError("ImplementationError:getActiveFilterTitle m_filters == NULL");
}
return m_filters->getTitle();
} break;
}
return "";
}
/*!
* \brief proceeds to the next filter set in a cirlucar fashion
*/
void mgMedia::nextFilterSet()
{
if(!m_filters)
{
mgError("ImplementationError: nextFilterSet m_filters == NULL");
}
m_filters->nextSet();
}
/*!
* \brief clears the current filter values and restores defaults
*/
void mgMedia::clearActiveFilter()
{
if( !m_filters )
{
mgError("ImplementationError: clearActiveFilter m_filters == NULL");
}
m_filters->clear();
}
/*!
* \brief Applies the active filter set and returns a root node for the
* selection in the default view for this filter set
*/
mgSelectionTreeNode* mgMedia::applyActiveFilter()
{
int view;
GdTreeNode* node;
switch(m_mediatype)
{
case GD_MP3:
{
if(!m_filters)
{
mgError("ImplementationError: applyActiveFilter() m_filters == NULL");
}
m_filters->accept();
m_sql_filter = m_filters->computeRestriction(&view);
node = new GdTreeNode(m_db, view, m_sql_filter);
node->expand();
return node->getChildren()[0];
} break;
}
return NULL;
}
/* -------------------- begin CVS log ---------------------------------
* $Log: mg_media.c,v $
* Revision 1.14 2004/07/29 06:17:40 lvw
* Added todo entries
*
* Revision 1.13 2004/05/28 15:29:18 lvw
* Merged player branch back on HEAD branch.
*
* Revision 1.12 2004/02/23 16:30:58 RaK
* - album search error because of i18n corrected
*
* Revision 1.11 2004/02/12 09:15:07 LarsAC
* Moved filter classes into separate files
*
* Revision 1.10.2.3 2004/05/25 00:10:45 lvw
* Code cleanup and added use of real database source files
*
* Revision 1.10.2.2 2004/03/14 17:57:30 lvw
* Linked against libmad. Introduced config options into code.
*
* Revision 1.10.2.1 2004/03/02 07:05:50 lvw
* Initial adaptations from MP3 plugin added (untested)
*
* Revision 1.12 2004/02/23 16:30:58 RaK
* - album search error because of i18n corrected
*
* Revision 1.11 2004/02/12 09:15:07 LarsAC
* Moved filter classes into separate files
*
* Revision 1.10 2004/02/10 23:47:23 RaK
* - views konsitent gemacht. siehe FROMJOIN
* - isLeafNode angepasst fuer neue views 4,5,100,101
* - like '%abba%' eingebaut
* - filter ist default mit abba gefuellt, zum leichteren testen.
* - search results werden jetzt gleich im ROOT expanded
*
* Revision 1.9 2004/02/09 19:27:52 MountainMan
* filter set implemented
*
* Revision 1.8 2004/02/02 23:33:41 MountainMan
* impementation of gdTrackFilters
*
* Revision 1.7 2004/02/02 22:48:04 MountainMan
* added CVS $Log
*
* --------------------- end CVS log ----------------------------------
*/
|