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
|
/*!
* \file muggle.c
* \brief Implements a plugin for browsing media libraries within VDR
*
* \version $Revision: 1.10 $
* \date $Date$
* \author Ralf Klueber, Lars von Wedel, Andreas Kellner, Wolfgang Rohdewald
* \author Responsible author: $Author$
*
* $Id$
*/
#include "muggle.h"
#include "vdr_menu.h"
#include "vdr_setup.h"
#include "mg_tools.h"
#include "i18n.h"
#include <getopt.h>
#include <config.h>
static const char *VERSION = "0.1.6";
static const char *DESCRIPTION = "Media juggle plugin for VDR";
static const char *MAINMENUENTRY = "Muggle";
const char *
mgMuggle::Version (void)
{
return VERSION;
}
const char *
mgMuggle::Description (void)
{
return DESCRIPTION;
}
const char *
mgMuggle::MainMenuEntry (void)
{
return MAINMENUENTRY;
}
mgMuggle::mgMuggle (void)
{
// defaults for database arguments
the_setup.DbHost = 0;
the_setup.DbSocket = 0;
the_setup.DbPort = 0;
the_setup.DbName = strdup ("GiantDisc");
the_setup.DbUser = 0;
the_setup.DbPass = 0;
the_setup.GdCompatibility = false;
the_setup.ToplevelDir = strdup ("/mnt/music/");
#ifndef HAVE_ONLY_SERVER
char *buf;
asprintf(&buf,"%s/.muggle",getenv("HOME"));
set_datadir(buf);
free(buf);
#endif
}
void
mgMuggle::Stop (void)
{
free(the_setup.DbHost);
free(the_setup.DbName);
free(the_setup.DbUser);
free(the_setup.DbPass);
free(the_setup.ToplevelDir);
}
const char *
mgMuggle::CommandLineHelp (void)
{
// Return a string that describes all known command line options.
return
#ifdef HAVE_ONLY_SERVER
" -h HHHH, --host=HHHH specify database host (default is localhost)\n"
#else
" -h HHHH, --host=HHHH specify database host (default is mysql embedded)\n"
#endif
" -s SSSS --socket=PATH specify database socket\n"
" -n NNNN, --name=NNNN specify database name (overridden by -g)\n"
" -p PPPP, --port=PPPP specify port of database server (default is )\n"
" -u UUUU, --user=UUUU specify database user (default is )\n"
" -w WWWW, --password=WWWW specify database password (default is empty)\n"
" -t TTTT, --toplevel=TTTT specify toplevel directory for music (default is /mnt/music)\n"
#ifndef HAVE_ONLY_SERVER
" -d DIRN, --datadir=DIRN specify directory for embedded sql data (default is $HOME/.muggle)\n"
#endif
" -g, --giantdisc enable full Giantdisc compatibility mode\n"
" -v, --verbose specify debug level. The higher the more. Default is 1\n"
"\n"
"if the specified host is localhost, sockets will be used if possible.\n"
"Otherwise the -s parameter will be ignored";
}
bool mgMuggle::ProcessArgs (int argc, char *argv[])
{
mgSetDebugLevel (1);
char b[1000];
sprintf(b,"mgMuggle::ProcessArgs ");
for (int i=1;i<argc;i++)
{
if (strlen(b)+strlen(argv[i]+2)>1000) break;;
strcat(b," ");
strcat(b,argv[i]);
}
mgDebug(1,b);
// Implement command line argument processing here if applicable.
static struct option
long_options[] =
{
{"host", required_argument, NULL, 'h'},
{"socket", required_argument, NULL, 's'},
{"name", required_argument, NULL, 'n'},
{"port", required_argument, NULL, 'p'},
{"user", required_argument, NULL, 'u'},
{"password", required_argument, NULL, 'w'},
#ifndef HAVE_ONLY_SERVER
{"datadir", required_argument, NULL, 'd'},
#endif
{"toplevel", required_argument, NULL, 't'},
{"giantdisc", no_argument, NULL, 'g'},
{NULL}
};
int
c,
option_index = 0;
while ((c =
#ifndef HAVE_ONLY_SERVER
getopt_long (argc, argv, "gh:s:n:p:t:u:w:d:v:", long_options,
#else
getopt_long (argc, argv, "gh:s:n:p:t:u:w:v:", long_options,
#endif
&option_index)) != -1)
{
switch (c)
{
case 'h':
{
the_setup.DbHost = strcpyrealloc (the_setup.DbHost, optarg);
}
break;
case 's':
{
the_setup.DbSocket = strcpyrealloc (the_setup.DbSocket, optarg);
}
break;
case 'n':
{
the_setup.DbName = strcpyrealloc (the_setup.DbName, optarg);
}
break;
case 'p':
{
the_setup.DbPort = atoi (optarg);
}
break;
case 'u':
{
the_setup.DbUser = strcpyrealloc (the_setup.DbUser, optarg);
}
break;
case 'w':
{
the_setup.DbPass = strcpyrealloc (the_setup.DbPass, optarg);
}
break;
#ifndef HAVE_ONLY_SERVER
case 'd':
{
set_datadir(optarg);
}
break;
#endif
case 'v':
{
mgSetDebugLevel (atol(optarg));
}
break;
case 't':
{
if (optarg[strlen (optarg) - 1] != '/')
{
std::string res = std::string (optarg) + "/";
the_setup.ToplevelDir = strdup (res.c_str ());
}
else
{
the_setup.ToplevelDir =
strcpyrealloc (the_setup.ToplevelDir, optarg);
}
}
break;
case 'g':
{
the_setup.DbName = strcpyrealloc (the_setup.DbName, "GiantDisc");
the_setup.GdCompatibility = true;
}
break;
default:
return false;
}
}
return true;
}
bool mgMuggle::Initialize (void)
{
// Initialize any background activities the plugin shall perform.
return true;
}
bool mgMuggle::Start (void)
{
// Start any background activities the plugin shall perform.
RegisterI18n (Phrases);
return true;
}
void
mgMuggle::Housekeeping (void)
{
// Perform any cleanup or other regular tasks.
}
cOsdObject *
mgMuggle::MainMenuAction (void)
{
// Perform the action when selected from the main VDR menu.
return new mgMainMenu ();
}
cMenuSetupPage *
mgMuggle::SetupMenu (void)
{
return new mgMenuSetup ();
}
bool mgMuggle::SetupParse (const char *Name, const char *Value)
{
if (!strcasecmp (Name, "InitLoopMode"))
the_setup.InitLoopMode = atoi (Value);
else if (!strcasecmp (Name, "InitShuffleMode"))
the_setup.InitShuffleMode = atoi (Value);
else if (!strcasecmp (Name, "AudioMode"))
the_setup.AudioMode = atoi (Value);
else if (!strcasecmp (Name, "DisplayMode"))
the_setup.DisplayMode = atoi (Value);
else if (!strcasecmp (Name, "BackgrMode"))
the_setup.BackgrMode = atoi (Value);
else if (!strcasecmp (Name, "TargetLevel"))
the_setup.TargetLevel = atoi (Value);
else if (!strcasecmp (Name, "LimiterLevel"))
the_setup.LimiterLevel = atoi (Value);
else if (!strcasecmp (Name, "Only48kHz"))
the_setup.Only48kHz = atoi (Value);
else
return false;
return true;
}
VDRPLUGINCREATOR (mgMuggle); // Don't touch this!
|