summaryrefslogtreecommitdiff
path: root/config.c
blob: b870cecc909d151013841b66cb472ae730953461 (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
#include "config.h"
#include "libcore/helpers.h"
#include "libcore/imageloader.h"

cDesignerConfig::cDesignerConfig() {
    tmplGlobals = NULL;
    epgImagePathSet = false;
    skinPathSet = false;
    logoPathSet = false;
    //Common
    numLogosPerSizeInitial = 30;
    limitLogoCache = 1;
    numLogosMax = 200;
    debugImageLoading = 0;
    replaceDecPoint = false;
    //settings for rerun display
    rerunAmount = 10;
    rerunDistance = 2;
    rerunMaxChannel = 0;
    //menu display style, display menu items 
    //one after each other or in one step
    blockFlush = 1;
    //frames per second for fading and shifting
    framesPerSecond = 40;
    //remember current skin and theme, osd size and osd fonts
    SetSkin();
    SetOSDSize();
    SetOSDFonts();
    osdLanguage = "";
    setupCloseDoReload = false;
}

cDesignerConfig::~cDesignerConfig() {
    ClearSkinSetups();
}

void cDesignerConfig::SetPathes(void) {
    if (!skinPathSet)
        skinPath = cString::sprintf("%s/skins/", cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
    if (!logoPathSet) 
        logoPath = cString::sprintf("%s/logos/", cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
    if (!epgImagePathSet)
        epgImagePath = cString::sprintf("%s/epgimages/", cPlugin::CacheDirectory(PLUGIN_NAME_I18N));

    dsyslog("skindesigner: using Skin Directory %s", *skinPath);
    dsyslog("skindesigner: using common ChannelLogo Directory %s", *logoPath);
    dsyslog("skindesigner: using EPG Images Directory %s", *epgImagePath);
}

void cDesignerConfig::SetSkinPath(cString path) {
    skinPath = CheckSlashAtEnd(*path);
    skinPathSet = true;
}

void cDesignerConfig::SetLogoPath(cString path) {
    logoPath = CheckSlashAtEnd(*path);
    logoPathSet = true;
}

void cDesignerConfig::SetEpgImagePath(cString path) {
    epgImagePath = CheckSlashAtEnd(*path);
    epgImagePathSet = true;
}

void cDesignerConfig::ReadSkins(void) {
    DIR *folder = NULL;
    struct dirent *dirEntry;
    folder = opendir(skinPath);
    if (!folder) {
        esyslog("skindesigner: no skins found in %s", *skinPath);
        return;
    }
    while (dirEntry = readdir(folder)) {
        string dirEntryName = dirEntry->d_name;
        int dirEntryType = dirEntry->d_type;
        if (!dirEntryName.compare(".") || !dirEntryName.compare("..") || dirEntryType != DT_DIR)
            continue;
        skins.push_back(dirEntryName);
    }
    dsyslog("skindesigner %ld skins found in %s", skins.size(), *skinPath);
}

void cDesignerConfig::ClearSkinSetups(void) {
    for (map < string, cSkinSetup* >::iterator it = skinSetups.begin(); it != skinSetups.end(); it++) {
        delete it->second;
    }
    skinSetups.clear();
}

void cDesignerConfig::DebugSkinSetups(void) {
    dsyslog("skindesigner: skin setups:");
    InitSetupIterator();
    cSkinSetup *skinSetup = NULL;
    while (skinSetup = GetNextSkinSetup()) {
        skinSetup->Debug();
    }    
}

void cDesignerConfig::DebugSkinSetupParameters(void) {
    dsyslog("skindesigner: skin setup parameters:");
    for (vector<pair<string, int> >::iterator it = skinSetupParameters.begin(); it != skinSetupParameters.end(); it++) {
        dsyslog("skindesigner: parameter %s value %d", (*it).first.c_str(), (*it).second);
    }
}

void cDesignerConfig::ReadSkinSetup(string skin) {
    cSkinSetup *skinSetup = new cSkinSetup(skin);
    if (skinSetup->ReadFromXML()) {
        //skinSetup->Debug();
        skinSetups.insert(pair<string, cSkinSetup* >(skin, skinSetup));
    }
}

bool cDesignerConfig::GetSkin(string &skin) {
    if (skinIterator == skins.end()) {
        return false;
    }
    skin = *skinIterator;
    skinIterator++;
    return true;
}

cSkinSetup* cDesignerConfig::GetSkinSetup(string &skin) {
    map< string, cSkinSetup* >::iterator hit = skinSetups.find(skin);
    if (hit != skinSetups.end()) {
        return hit->second;
    }
    return NULL;
}

cSkinSetup* cDesignerConfig::GetNextSkinSetup(void) {
    if (setupIt == skinSetups.end()) {
        return NULL;
    }
    cSkinSetup* skinSetup = setupIt->second;
    setupIt++;
    return skinSetup;
}

cSkinSetupMenu* cDesignerConfig::GetSkinSetupMenu(string &skin, string &menu) {
    cSkinSetup *skinSetup = GetSkinSetup(skin);
    if (!skinSetup)
        return NULL;
    esyslog("skindesigner: skinsetup found");
    return skinSetup->GetMenu(menu);
}


void cDesignerConfig::TranslateSetup(void) {
    for (map< string, cSkinSetup* >::iterator it = skinSetups.begin(); it != skinSetups.end(); it++) {
        (it->second)->TranslateSetup();
    }
}

void cDesignerConfig::UpdateSkinSetupParameter(string name, int value) {
    vector<pair<string,int> >::iterator hit;
    for (hit = skinSetupParameters.begin(); hit != skinSetupParameters.end(); hit++) {
        if (!name.compare((*hit).first)) {
            skinSetupParameters.erase(hit);
            break;
        }
    }
    skinSetupParameters.push_back(pair<string,int>(name, value));
}

void cDesignerConfig::SetSkinSetupParameters(void) {
    for (vector < pair <string, int> >::iterator it = skinSetupParameters.begin(); it != skinSetupParameters.end(); it++) {
        string name = (*it).first;
        int value = (*it).second;

        InitSkinIterator();
        string activeSkin = "";
        bool skinFound = false;
        while (GetSkin(activeSkin)) {
            stringstream checkString;
            checkString << activeSkin << ".";
            size_t hit = name.find(checkString.str());
            if (hit != 0)
                continue;
            skinFound = true;
            break;
        }
        if (skinFound) {
            cSkinSetup* skinSetup = GetSkinSetup(activeSkin);
            if (skinSetup != NULL) {
                string paramName = name.substr(activeSkin.size()+1);
                cSkinSetupParameter *skinSetupParam = skinSetup->GetParameter(paramName);
                if (skinSetupParam) {
                    skinSetupParam->value = value;
                    continue;
                }
            }
        }
        esyslog("skindesigner: ERROR Unknown Setup Parameter %s", name.c_str());
    }
}

void cDesignerConfig::UpdateGlobals(void) {
    string activeSkin = Setup.OSDSkin;
    cSkinSetup *skinSetupActiveSkin = GetSkinSetup(activeSkin);
    if (skinSetupActiveSkin && tmplGlobals) {
        dsyslog("skindesigner: globals for skin %s adapted to skin setup", activeSkin.c_str());
        skinSetupActiveSkin->AddToGlobals(tmplGlobals);
    }
}

void cDesignerConfig::CheckDecimalPoint(void) {
    struct lconv *pLocInfo;
    pLocInfo = localeconv();
    string decimalPoint = pLocInfo->decimal_point;
    if (decimalPoint.compare(".")) {
        dsyslog("skindesigner: using decimal point %s", decimalPoint.c_str());
        replaceDecPoint = true;
        decPoint = decimalPoint[0];
    }
}

void cDesignerConfig::SetSkin(void) {
    osdSkin =  Setup.OSDSkin;
    osdTheme = Setup.OSDTheme;
}

bool cDesignerConfig::SkinChanged(void) {
    bool changed = false;
    if (osdSkin.compare(Setup.OSDSkin) != 0) {
        dsyslog("skindesigner: skin changed from %s to %s", osdSkin.c_str(), Setup.OSDSkin);
        changed = true;
    }
    if (osdTheme.compare(Setup.OSDTheme) != 0) {
        dsyslog("skindesigner: theme changed from %s to %s", osdTheme.c_str(), Setup.OSDTheme);
        changed = true;
    }
    if (changed)
        SetSkin();
    return changed;
}

void cDesignerConfig::SetOSDSize(void) {
    osdSize.SetWidth(cOsd::OsdWidth());
    osdSize.SetHeight(cOsd::OsdHeight());
    osdSize.SetX(cOsd::OsdLeft());
    osdSize.SetY(cOsd::OsdTop());
}

bool cDesignerConfig::OsdSizeChanged(void) {
   if ((osdSize.Width() != cOsd::OsdWidth()) ||
        (osdSize.Height() != cOsd::OsdHeight()) ||
        (osdSize.X() != cOsd::OsdLeft()) ||
        (osdSize.Y() != cOsd::OsdTop())) {
        dsyslog("skindesigner: osd size changed");
        dsyslog("skindesigner: old osd size: top %d left %d size %d * %d", osdSize.X(), osdSize.Y(), osdSize.Width(), osdSize.Height());
        SetOSDSize();
        dsyslog("skindesigner: new osd size: top %d left %d size %d * %d", osdSize.X(), osdSize.Y(), osdSize.Width(), osdSize.Height());
        return true;
    }
    return false; 
}

void cDesignerConfig::SetOSDFonts(void) {
    fontFix = Setup.FontFix;
    fontOsd = Setup.FontOsd;
    fontSml = Setup.FontSml;
}

bool cDesignerConfig::OsdFontsChanged(void) {
    bool changed = false;
    if (fontFix.compare(Setup.FontFix) != 0) {
        changed = true;
    }
    if (fontOsd.compare(Setup.FontOsd) != 0) {
        changed = true;
    }
    if (fontSml.compare(Setup.FontSml) != 0) {
        changed = true;
    }
    if (changed)
        SetOSDFonts();
    return changed;
}

bool cDesignerConfig::OsdLanguageChanged(void) {
    if (osdLanguage.compare(Setup.OSDLanguage)) {
        osdLanguage = Setup.OSDLanguage;
        return true;
    }
    return false;
}

cString cDesignerConfig::GetSkinRessourcePath(void) {
    return cString::sprintf("%s%s", *skinPath, osdSkin.c_str());
}

void cDesignerConfig::AddPluginMenus(string name, map< int, string > menus) {
    pluginMenus.insert(pair< string, map < int, string > >(name, menus));
}

void cDesignerConfig::AddPluginViews(string name, 
                                     map< int, string > views,
                                     multimap< int, pair <int, string> > subViews,
                                     map< int, map <int, string> > viewElements,
                                     map< int, map <int, string> > viewGrids) {
    pluginViews.insert(pair< string, map < int, string > >(name, views));
    pluginSubViews.insert(pair< string, multimap< int, pair <int, string> > >(name, subViews));
    pluginViewElements.insert(pair< string, map< int, map <int, string> > >(name, viewElements));
    pluginViewGrids.insert(pair< string, map< int, map <int, string> > >(name, viewGrids));
}

void cDesignerConfig::InitPluginMenuIterator(void) {
    plugMenuIt = pluginMenus.begin();
}

map <int,string> *cDesignerConfig::GetPluginTemplates(string &name) {
    if (plugMenuIt == pluginMenus.end())
        return NULL;
    name = plugMenuIt->first;
    map <int,string> *templates = &plugMenuIt->second;
    plugMenuIt++;
    return templates; 
}

void cDesignerConfig::InitPluginViewIterator(void) {
    plugViewIt = pluginViews.begin();
}

map <int,string> *cDesignerConfig::GetPluginViews(string &name) {
    if (plugViewIt == pluginViews.end())
        return NULL;
    name = plugViewIt->first;
    map <int,string> *views = &plugViewIt->second;
    plugViewIt++;
    return views; 
}

map <int,string> cDesignerConfig::GetPluginSubViews(string name, int viewID) {
    map <int,string> subViews;

    map < string, multimap< int, pair <int, string> > >::iterator hit = pluginSubViews.find(name);
    if (hit == pluginSubViews.end())
        return subViews;

    multimap< int, pair<int, string> > subs = hit->second;

    pair < multimap< int, pair<int, string> >::iterator, multimap< int, pair<int, string> >::iterator> viewSubViews;
    viewSubViews = subs.equal_range(viewID); 

    for (multimap< int, pair<int, string> >::iterator it=viewSubViews.first; it!=viewSubViews.second; ++it) {
        pair<int, string> subViewFound = it->second;
        subViews.insert(pair<int,string>(subViewFound.first, subViewFound.second));
    }
    return subViews;
}

int cDesignerConfig::GetPluginViewElementID(string pluginName, string viewElementName, int viewID) {
    map < string, map< int, map <int, string> > >::iterator hit = pluginViewElements.find(pluginName);
    if (hit == pluginViewElements.end())
        return -1;
    map< int, map <int, string> >::iterator hit2 = (hit->second).find(viewID);
    if (hit2 == (hit->second).end())
        return -1;
    
    map <int, string> viewElements = hit2->second;
    for (map <int, string>::iterator it = viewElements.begin(); it != viewElements.end(); it++) {
        if (!(it->second).compare(viewElementName))
            return it->first;
    }
    return -1;
}

int cDesignerConfig::GetPluginViewGridID(string pluginName, string viewGridName, int viewID) {
    map < string, map< int, map <int, string> > >::iterator hit = pluginViewGrids.find(pluginName);
    if (hit == pluginViewGrids.end())
        return -1;
    map< int, map <int, string> >::iterator hit2 = (hit->second).find(viewID);
    if (hit2 == (hit->second).end())
        return -1;
    
    map <int, string> viewGrids = hit2->second;
    for (map <int, string>::iterator it = viewGrids.begin(); it != viewGrids.end(); it++) {
        if (!(it->second).compare(viewGridName))
            return it->first;
    }
    return -1;
}

cString cDesignerConfig::CheckSlashAtEnd(std::string path) {
    try {
        if (!(path.at(path.size()-1) == '/'))
            return cString::sprintf("%s/", path.c_str());
    } catch (...) {return path.c_str();}
    return path.c_str();
}

bool cDesignerConfig::SetupParse(const char *Name, const char *Value) {
    bool pluginSetupParam = true;
    if      (!strcasecmp(Name, "DebugImageLoading"))       debugImageLoading = atoi(Value);
    else if (!strcasecmp(Name, "LimitChannelLogoCache"))   limitLogoCache = atoi(Value);
    else if (!strcasecmp(Name, "NumberLogosInitially"))    numLogosPerSizeInitial = atoi(Value);
    else if (!strcasecmp(Name, "NumberLogosMax"))          numLogosMax = atoi(Value);
    else if (!strcasecmp(Name, "RerunAmount"))             rerunAmount = atoi(Value);
    else if (!strcasecmp(Name, "RerunDistance"))           rerunDistance = atoi(Value);
    else if (!strcasecmp(Name, "RerunMaxChannel"))         rerunMaxChannel = atoi(Value);
    else if (!strcasecmp(Name, "BlockFlush"))              blockFlush = atoi(Value);
    else if (!strcasecmp(Name, "FramesPerSecond"))         framesPerSecond = atoi(Value);
    else pluginSetupParam = false;

    if (!pluginSetupParam) {
        skinSetupParameters.push_back(pair <string, int>(Name, atoi(Value)));
    }

    return true;
}