aboutsummaryrefslogtreecommitdiff
path: root/addons/service.xbmc.versioncheck/lib/viewer.py
blob: 7410d946000b0c2947889c5bc7507ffce37ba303 (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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#     Copyright (C) 2011-2013 Martijn Kaijser
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program. If not, see <http://www.gnu.org/licenses/>.
#

#import modules
import os
import sys
import xbmc
import xbmcgui
import xbmcaddon

### get addon info
__addon__        = xbmcaddon.Addon('service.xbmc.versioncheck')
__addonversion__ = __addon__.getAddonInfo('version')
__addonname__    = __addon__.getAddonInfo('name')
__addonpath__    = __addon__.getAddonInfo('path').decode('utf-8')
__addonprofile__ = xbmc.translatePath( __addon__.getAddonInfo('profile') ).decode('utf-8')
__icon__         = __addon__.getAddonInfo('icon')

class Viewer:
    # constants
    WINDOW = 10147
    CONTROL_LABEL = 1
    CONTROL_TEXTBOX = 5

    def __init__(self, *args, **kwargs):
        # activate the text viewer window
        xbmc.executebuiltin("ActivateWindow(%d)" % (self.WINDOW,))
        # get window
        self.window = xbmcgui.Window(self.WINDOW)
        # give window time to initialize
        xbmc.sleep(100)
        # set controls
        self.setControls()

    def setControls(self):
        #get header, text
        heading, text = self.getText()
        # set heading
        self.window.getControl(self.CONTROL_LABEL).setLabel("%s : %s" % (__addonname__, heading, ))
        # set text
        self.window.getControl(self.CONTROL_TEXTBOX).setText(text)
        xbmc.sleep(2000)

    def getText(self):
        try:
            if sys.argv[ 1 ] == "gotham-alpha_notice":
                return "Call to Gotham alpha users", self.readFile(os.path.join(__addonpath__ , "resources/gotham-alpha_notice.txt"))
        except Exception, e:
            xbmc.log(__addonname__ + ': ' + str(e), xbmc.LOGERROR)
        return "", ""

    def readFile(self, filename):
        return open(filename).read()

class WebBrowser:
    """ Display url using the default browser. """

    def __init__(self, *args, **kwargs):
        try:
            url = sys.argv[2]
            # notify user
            notification(__addonname__, url)
            xbmc.sleep(100)
            # launch url
            self.launchUrl(url)
        except Exception, e:
            xbmc.log(__addonname__ + ': ' + str(e), xbmc.LOGERROR)

    def launchUrl(self, url):
        import webbrowser
        webbrowser.open(url)

def Main():
    try:
        if sys.argv[ 1 ] == "webbrowser":
            WebBrowser()
        else:
            Viewer()
    except Exception, e:
        xbmc.log(__addonname__ + ': ' + str(e), xbmc.LOGERROR)

if (__name__ == "__main__"):
    Main()