[MerlinSkinThemes] - add config option to disable rebuild on boot
[enigma2-plugins.git] / merlinskinthemes / src / plugin.py
1 #######################################################################
2 #
3 #  MerlinSkinThemes for Dreambox/Enigma-2
4 #  Modul PluginStart
5 #  Coded by marthom (c)2012 - 2019
6 #
7 #  Support: www.dreambox-tools.info
8 #  E-Mail: marthom@dreambox-tools.info
9 #
10 #  This plugin is open source but it is NOT free software.
11 #
12 #  This plugin may only be distributed to and executed on hardware which
13 #  is licensed by Dream Multimedia GmbH.
14 #  In other words:
15 #  It's NOT allowed to distribute any parts of this plugin or its source code in ANY way
16 #  to hardware which is NOT licensed by Dream Multimedia GmbH.
17 #  It's NOT allowed to execute this plugin and its source code or even parts of it in ANY way
18 #  on hardware which is NOT licensed by Dream Multimedia GmbH.
19 #
20 #  If you want to use or modify the code or parts of it,
21 #  you have to keep MY license and inform me about the modifications by mail.
22 #
23 #######################################################################
24
25 from Plugins.Plugin import PluginDescriptor
26 from Components.config import config, configfile, ConfigYesNo, ConfigSubsection, getConfigListEntry, ConfigSelection, ConfigNumber, ConfigText, ConfigInteger, ConfigSubDict, ConfigBoolean
27 from Screens.MessageBox import MessageBox
28 from Tools import Notifications
29 from Tools.Directories import resolveFilename, SCOPE_SKIN, fileExists
30 from Tools.HardwareInfo import HardwareInfo
31 from enigma import quitMainloop
32 import xml.etree.cElementTree as Tree
33
34 import MerlinSkinThemes
35
36 try:
37         Notifications.notificationQueue.registerDomain("MerlinSkinThemes", _("MerlinSkinThemes"), deferred_callable = True)
38 except Exception as e:
39         print "[MST] - Error registering Notification-Domain: ", e
40
41 def merlinskinthemes_start(session, **kwargs):
42         reload(MerlinSkinThemes)
43         session.open(MerlinSkinThemes.MerlinSkinThemes)
44
45 def checkSkin(session, **kwargs):
46         if config.plugins.MerlinSkinThemes.rebuildSkinOnBoot.value:
47                 if config.plugins.MerlinSkinThemes.Skin.value == config.skin.primary_skin.value[:-9]:
48                         skinFile = resolveFilename(SCOPE_SKIN) + config.skin.primary_skin.value
49                         if fileExists(skinFile):
50                                 xmlFile = Tree.ElementTree(file=skinFile)
51                                 root = xmlFile.getroot()
52
53                                 if root.find("merlinskinthemes") is not None:
54                                         print "[MST] - skin was edited with MST and tag is present - assume rebuild is not required"
55                                 else:
56                                         if config.plugins.MerlinSkinThemes.applied.value:
57                                                 print "[MST] - skin was edited with MST but tag is not present - assume rebuild required"
58                                                 Notifications.AddNotificationWithCallback(messageBoxCallback, MessageBox, _("Skin was rebuilt and a restart of enigma2 is required. Do you want to restart now?"), MessageBox.TYPE_YESNO, 10, windowTitle="MerlinSkinThemes", domain = "MerlinSkinThemes")
59                                                 # take the configfile and build a dict with all MerlinSkinThemes entries to work around not available ConfigSubDict values              
60                                                 configDict = {} 
61                                                 for line in config.pickle().split("\n"):
62                                                         if line.startswith("config.plugins.MerlinSkinThemes"):
63                                                                 configEntry = line.split("=")
64                                                                 configDict[configEntry[0]]=configEntry[1]
65                                                 MerlinSkinThemes.setThemes(resolveFilename(SCOPE_SKIN) + config.skin.primary_skin.value[:-9] + "/themes.xml", resolveFilename(SCOPE_SKIN) + config.skin.primary_skin.value, configDict)                                                                                 
66                                         else:
67                                                 print "[MST] - skin was not edited with MST"
68
69 def messageBoxCallback(answer=False):
70         if answer == True:
71                 quitMainloop(3)
72
73 def Plugins(**kwargs):
74         return [
75                 PluginDescriptor(name="MerlinSkinThemes", description="MerlinSkinThemes",where = [PluginDescriptor.WHERE_PLUGINMENU], icon = "plugin.png", fnc=merlinskinthemes_start),
76                 PluginDescriptor(name="MerlinSkinThemes", description="MerlinSkinThemes", where = [PluginDescriptor.WHERE_EXTENSIONSMENU], fnc=merlinskinthemes_start),
77                 PluginDescriptor(where = [PluginDescriptor.WHERE_INFOBAR], fnc=checkSkin)
78         ]