1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2013 Team-XBMC
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ADDON = xbmcaddon.Addon()
26 ADDONVERSION = ADDON.getAddonInfo('version')
27 ADDONNAME = ADDON.getAddonInfo('name')
28 ADDONPATH = ADDON.getAddonInfo('path').decode('utf-8')
29 ADDONPROFILE = xbmc.translatePath( ADDON.getAddonInfo('profile') ).decode('utf-8')
30 ICON = ADDON.getAddonInfo('icon')
32 monitor = xbmc.Monitor()
34 # Fixes unicode problems
35 def string_unicode(text, encoding='utf-8'):
37 text = unicode( text, encoding )
42 def normalize_string(text):
44 text = unicodedata.normalize('NFKD', string_unicode(text)).encode('ascii', 'ignore')
50 string = normalize_string(ADDON.getLocalizedString(id))
54 if isinstance (txt,str):
55 txt = txt.decode("utf-8")
56 message = u'%s: %s' % ("Version Check", txt)
57 xbmc.log(msg=message.encode("utf-8"), level=xbmc.LOGDEBUG)
59 def get_password_from_user():
60 keyboard = xbmc.Keyboard("", ADDONNAME + "," +localise(32022), True)
62 if (keyboard.isConfirmed()):
63 pwd = keyboard.getText()
66 def message_upgrade_success():
67 xbmc.executebuiltin("XBMC.Notification(%s, %s, %d, %s)" %(ADDONNAME,
72 def message_restart():
73 if dialog_yesno(32014):
74 xbmc.executebuiltin("RestartApp")
76 def dialog_yesno(line1 = 0, line2 = 0):
77 return xbmcgui.Dialog().yesno(ADDONNAME,
81 def upgrade_message(msg, oldversion, upgrade, msg_current, msg_available):
82 wait_for_end_of_video()
84 if ADDON.getSetting("lastnotified_version") < ADDONVERSION:
85 xbmcgui.Dialog().ok(ADDONNAME,
89 #ADDON.setSetting("lastnotified_version", ADDONVERSION)
91 log("Already notified one time for upgrading.")
93 def upgrade_message2( version_installed, version_available, version_stable, oldversion, upgrade,):
94 # shorten releasecandidate to rc
95 if version_installed['tag'] == 'releasecandidate':
96 version_installed['tag'] = 'rc'
97 if version_available['tag'] == 'releasecandidate':
98 version_available['tag'] = 'rc'
99 # convert json-rpc result to strings for usage
100 msg_current = '%i.%i %s%s' %(version_installed['major'],
101 version_installed['minor'],
102 version_installed['tag'],
103 version_installed.get('tagversion',''))
104 msg_available = version_available['major'] + '.' + version_available['minor'] + ' ' + version_available['tag'] + version_available.get('tagversion','')
105 msg_stable = version_stable['major'] + '.' + version_stable['minor'] + ' ' + version_stable['tag'] + version_stable.get('tagversion','')
106 msg = localise(32034) %(msg_current, msg_available)
108 wait_for_end_of_video()
110 # hack: convert current version number to stable string
111 # so users don't get notified again. remove in future
112 if ADDON.getSetting("lastnotified_version") == '0.1.24':
113 ADDON.setSetting("lastnotified_stable", msg_stable)
115 # Show different dialogs depending if there's a newer stable available.
116 # Also split them between xbmc and kodi notifications to reduce possible confusion.
117 # People will find out once they visit the website.
118 # For stable only notify once and when there's a newer stable available.
119 # Ignore any add-on updates as those only count for != stable
120 if oldversion == 'stable' and ADDON.getSetting("lastnotified_stable") != msg_stable:
121 if xbmcaddon.Addon('xbmc.addon').getAddonInfo('version') < "13.9.0":
122 xbmcgui.Dialog().ok(ADDONNAME,
127 xbmcgui.Dialog().ok(ADDONNAME,
131 ADDON.setSetting("lastnotified_stable", msg_stable)
133 elif oldversion != 'stable' and ADDON.getSetting("lastnotified_version") != msg_available:
134 if xbmcaddon.Addon('xbmc.addon').getAddonInfo('version') < "13.9.0":
135 # point them to xbmc.org
136 xbmcgui.Dialog().ok(ADDONNAME,
142 xbmcgui.Dialog().ok(ADDONNAME,
147 # older skins don't support a text field in the OK dialog.
148 # let's use split lines for now. see code above.
150 msg = localise(32034) %(msg_current, msg_available)
151 if oldversion == 'stable':
152 msg = msg + ' ' + localise(32030)
154 msg = msg + ' ' + localise(32035)
155 msg = msg + ' ' + localise(32031)
156 xbmcgui.Dialog().ok(ADDONNAME, msg)
157 #ADDON.setSetting("lastnotified_version", ADDONVERSION)
159 ADDON.setSetting("lastnotified_version", msg_available)
162 log("Already notified one time for upgrading.")
165 def wait_for_end_of_video():
166 # Don't show notify while watching a video
167 while xbmc.Player().isPlayingVideo() and not monitor.abortRequested():
168 if monitor.waitForAbort(1):
169 # Abort was requested while waiting. We should exit
172 while i < 10 and not monitor.abortRequested():
173 if monitor.waitForAbort(1):
174 # Abort was requested while waiting. We should exit