3 # mEveMon - A character monitor for EVE Online
4 # Copyright (c) 2010 Ryan and Danny Campbell, and the mEveMon Team
6 # mEveMon is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # mEveMon is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 from eveapi import eveapi
28 # we will store our preferences in gconf
31 #ugly hack to check maemo version. any better way?
32 if hasattr(hildon, "StackableWindow"):
33 from ui.fremantle import gui
36 from ui.diablo import gui
41 self.program = hildon.Program()
42 self.program.__init__()
43 self.gconf = gnome.gconf.client_get_default()
44 self.cached_api = eveapi.EVEAPIConnection( cacheHandler = \
45 apicache.cache_handler(debug=False))
46 self.gui = gui.mEveMonUI(self)
51 def quit(self, *args):
54 def get_accounts(self):
56 entries = self.gconf.all_entries("/apps/maemo/mevemon/accounts")
59 key = os.path.basename(entry.get_key())
60 value = entry.get_value().to_string()
65 def get_api_key(self, uid):
66 return self.gconf.get_string("/apps/maemo/mevemon/accounts/%s" % uid) or ''
68 def remove_account(self, uid):
69 self.gconf.unset("/apps/maemo/mevemon/accounts/%s" % uid)
71 def add_account(self, uid, api_key):
72 self.gconf.set_string("/apps/maemo/mevemon/accounts/%s" % uid, api_key)
75 def get_auth(self, uid):
77 api_key = self.get_api_key(uid)
80 auth = self.cached_api.auth(userID=uid, apiKey=api_key)
81 except eveapi.Error, e:
86 def get_char_sheet(self, uid, charID):
88 sheet = self.get_auth(uid).character(charID).CharacterSheet()
89 except eveapi.Error, e:
90 # we should really have a logger that logs this error somewhere
95 def char_id2name(self, charID):
96 # the api can take a comma-seperated list of ids, but we'll just take
99 chars = self.cached_api.eve.CharacterName(ids=charID).characters
100 name = chars[0].characterName
101 except eveapi.Error, e:
106 def char_name2id(self, name):
107 # the api can take a comma-seperated list of names, but we'll just take
108 # a single name for now
110 chars = self.cached_api.eve.CharacterID(names=name).characters
111 char_id = chars[0].characterID
112 except eveapi.Error, e:
118 def get_characters(self):
120 returns a list containing a single character with an error message for a
121 name, if there's a problem. FIXME --danny
124 err_img = "/usr/share/mevemon/imgs/error.jpg"
126 placeholder_chars = ("Please check your API settings.", err_img, "0")
128 acct_dict = self.get_accounts()
130 return [placeholder_chars]
132 for uid, apiKey in acct_dict.items():
133 auth = self.cached_api.auth(userID=uid, apiKey=apiKey)
135 api_char_list = auth.account.Characters()
136 # append each char we get to the list we'll return to the
138 for character in api_char_list.characters:
139 ui_char_list.append( ( character.name, fetchimg.portrait_filename( character.characterID, 64 ), uid) )
140 except eveapi.Error, e:
141 # again, we need to handle this... --danny
142 ui_char_list.append(placeholder_chars)
146 def get_portrait(self, char_name, size):
148 returns the relative path of the retrieved portrait
150 charID = self.char_name2id(char_name)
151 return fetchimg.portrait_filename(charID, size)
153 def get_skill_tree(self):
155 tree = self.cached_api.eve.SkillTree()
156 except eveapi.Error, e:
162 def get_skill_in_training(self, uid, charID):
164 skill = self.get_auth(uid).character(charID).SkillInTraining()
172 if __name__ == "__main__":