Added support for multiple image sizes. Changed imgfetch to fetchimg.
[mevemon] / mevemon.py
1 import hildon
2 import gtk
3 from eveapi import eveapi
4 import fetchimg
5
6 # we will store our preferences in gconf
7 import gnome.gconf
8
9 #ugly hack to check maemo version. any better way?
10 if hasattr(hildon, "StackableWindow"):
11     from ui.fremantle import ui
12 else:
13     from ui.diablo import ui
14
15 class mEveMon():
16     def __init__(self):
17         self.program = hildon.Program()
18         self.program.__init__()
19         self.config = None
20         self.gconf = gnome.gconf.client_get_default()
21         self.ui = ui.mEveMonUI(self)
22
23
24     def run(self):
25         gtk.main()
26     
27     def quit(self, *args):
28         gtk.main_quit()
29
30     def get_api_key(self):
31         return self.gconf.get_string("/apps/maemo/mevemon/eve_api_key") or ''
32
33     def get_uid(self):
34         return self.gconf.get_string("/apps/maemo/mevemon/eve_uid") or ''
35
36     def set_api_key(self, key):
37         self.gconf.set_string("/apps/maemo/mevemon/eve_api_key", key)
38
39     def set_uid(self, uid):
40         self.gconf.set_string("/apps/maemo/mevemon/eve_uid", uid)
41
42     # really quick hack to get character list. doesn't handle errors well, and if it can't get the gconf settings it just returns the placeholders, when in reality it should tell the UI or something. basically half finished, just uploading to show ry... FIXME --danny
43     def get_characters( self ):
44         ui_char_list = []
45         # error message --danny
46         placeholder_chars = [("Please check your API settings.", "imgs/error.jpg")]
47         api = eveapi.EVEAPIConnection()
48         uid = self.get_uid()
49         api_key = self.get_api_key()
50         # if they are entered into gconf, try getting api data --danny
51         if ( uid and api_key ):
52             auth = api.auth( userID = uid, apiKey = api_key )
53             try:
54                 api_char_list = auth.account.Characters()
55             except eveapi.Error, e:
56                 # if we can't, return the error message/pic --danny
57                 return placeholder_chars
58             except Exception, e:
59                 # unknown exception, dunno if this needs to be here if I just ignore it... probably a bad idea, but it was in the apitest.py example... --danny
60                 return placeholder_chars
61             # append each char we get to the list we'll return to the UI --danny
62             for character in api_char_list.characters:
63                 ui_char_list.append( ( character.name, fetchimg.portrait_filename( character.characterID, 64 ) ) )
64             return ui_char_list
65         # if not entered into gconf, error message --danny
66         else:
67             return placeholder_chars
68         
69 if __name__ == "__main__":
70     app = mEveMon()
71     app.run()