Added get_characters() function in controller. Very rough, needs work.
[mevemon] / mevemon.py
1 import hildon
2 import gtk
3 from eveapi import eveapi
4
5 # we will store our preferences in gconf
6 import gnome.gconf
7
8 #ugly hack to check maemo version. any better way?
9 if hasattr(hildon, "StackableWindow"):
10     from ui.fremantle import ui
11 else:
12     from ui.diablo import ui
13
14 class mEveMon():
15     def __init__(self):
16         self.program = hildon.Program()
17         self.program.__init__()
18         self.config = None
19         self.gconf = gnome.gconf.client_get_default()
20         self.ui = ui.mEveMonUI(self)
21
22
23     def run(self):
24         gtk.main()
25     
26     def quit(self, *args):
27         gtk.main_quit()
28
29     def get_api_key(self):
30         return self.gconf.get_string("/apps/maemo/mevemon/eve_api_key") or ''
31
32     def get_uid(self):
33         return self.gconf.get_string("/apps/maemo/mevemon/eve_uid") or ''
34
35     def set_api_key(self, key):
36         self.gconf.set_string("/apps/maemo/mevemon/eve_api_key", key)
37
38     def set_uid(self, uid):
39         self.gconf.set_string("/apps/maemo/mevemon/eve_uid", uid)
40
41     # 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
42     def get_characters( self ):
43         ui_char_list = []
44         print 'get_characters() called.'
45         placeholder_chars = [("Character 1", "avatar.png"), ("Character 2", "avatar.png")]
46         api = eveapi.EVEAPIConnection()
47         uid = self.get_uid()
48         api_key = self.get_api_key()
49         if ( uid and api_key ):
50             auth = api.auth( userID = uid, apiKey = api_key )
51             try:
52                 api_char_list = auth.account.Characters()
53             except eveapi.Error, e:
54                 print "Sorry, eveapi returned error code %s." % e.code
55                 print '"' + e.message + '"'
56                 return placeholder_chars
57             except Exception, e:
58                 print "The sky is falling! Unknown error: ", str( e )
59                 raise
60             print "grabbing character list:"
61             for character in api_char_list.characters:
62                 print character
63                 ui_char_list.append( ( character.name, "avatar.png" ) )
64             return ui_char_list
65         else:
66             return placeholder_chars
67         
68 if __name__ == "__main__":
69     app = mEveMon()
70     app.run()