Merge pull request #4875 from koying/fixdroidremotekeyboard
[vuplus_xbmc] / addons / service.xbmc.versioncheck / lib / common.py
1 # -*- coding: utf-8 -*-
2 #
3 #     Copyright (C) 2013 Team-XBMC
4 #
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.
9 #
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.
14 #
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/>.
17 #
18
19 import os
20 import xbmc
21 import xbmcaddon
22 import xbmcgui
23 import xbmcvfs
24
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')
31
32 def localise(id):
33     string = __addon__.getLocalizedString(id).encode( 'utf-8', 'ignore' )
34     return string
35
36 def log(txt):
37     if isinstance (txt,str):
38         txt = txt.decode("utf-8")
39     message = u'%s: %s' % ("XBMC Version Check", txt)
40     xbmc.log(msg=message.encode("utf-8"), level=xbmc.LOGDEBUG)
41
42 def get_password_from_user():
43     keyboard = xbmc.Keyboard("", __addonname__ + "," +localise(32022), True)
44     keyboard.doModal()
45     if (keyboard.isConfirmed()):
46         pwd = keyboard.getText()
47     return pwd
48
49 def message_upgrade_success():
50     xbmc.executebuiltin("XBMC.Notification(%s, %s, %d, %s)" %(__addonname__,
51                                                               localise(32013),
52                                                               15000,
53                                                               __icon__))
54
55 def message_restart():
56     if dialog_yesno(32014):
57         xbmc.executebuiltin("RestartApp")
58
59 def dialog_yesno(line1 = 0, line2 = 0):
60     return xbmcgui.Dialog().yesno(__addonname__,
61                                   localise(line1),
62                                   localise(line2))
63
64 def upgrade_message(msg, oldversion, upgrade):
65     # Don't show while watching a video
66     while(xbmc.Player().isPlayingVideo() and not xbmc.abortRequested):
67         xbmc.sleep(1000)
68     i = 0
69     while(i < 5 and not xbmc.abortRequested):
70         xbmc.sleep(1000)
71         i += 1
72     if __addon__.getSetting("lastnotified_version") < __addonversion__:
73         xbmcgui.Dialog().ok(__addonname__,
74                     localise(msg),
75                     localise(32001),
76                     localise(32002))
77         __addon__.setSetting("lastnotified_version", __addonversion__)
78     else:
79         log("Already notified one time for upgrading.")