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)
74 def get_auth(self, uid):
76 api_key = self.get_api_key(uid)
79 auth = self.cached_api.auth(userID=uid, apiKey=api_key)
80 except eveapi.Error, e:
85 def get_char_sheet(self, uid, charID):
87 sheet = self.get_auth(uid).character(charID).CharacterSheet()
88 except eveapi.Error, e:
89 # we should really have a logger that logs this error somewhere
94 def char_id2name(self, charID):
95 # the api can take a comma-seperated list of ids, but we'll just take
98 chars = self.cached_api.eve.CharacterName(ids=charID).characters
99 name = chars[0].characterName
100 except eveapi.Error, e:
105 def char_name2id(self, name):
106 # the api can take a comma-seperated list of names, but we'll just take
107 # a single name for now
109 chars = self.cached_api.eve.CharacterID(names=name).characters
110 char_id = chars[0].characterID
111 except eveapi.Error, e:
117 def get_characters(self):
119 returns a list containing a single character with an error message for a
120 name, if there's a problem. FIXME --danny
123 err_img = "/usr/share/mevemon/imgs/error.jpg"
125 placeholder_chars = ("Please check your API settings.", err_img, "0")
127 acct_dict = self.get_accounts()
129 return [placeholder_chars]
131 for uid, apiKey in acct_dict.items():
132 auth = self.cached_api.auth(userID=uid, apiKey=apiKey)
134 api_char_list = auth.account.Characters()
135 # append each char we get to the list we'll return to the
137 for character in api_char_list.characters:
138 ui_char_list.append( ( character.name, fetchimg.portrait_filename( character.characterID, 64 ), uid) )
139 except eveapi.Error, e:
140 # again, we need to handle this... --danny
141 ui_char_list.append(placeholder_chars)
145 def get_portrait(self, char_name, size):
147 returns the relative path of the retrieved portrait
149 charID = self.char_name2id(char_name)
150 return fetchimg.portrait_filename(charID, size)
152 def get_skill_tree(self):
154 tree = self.cached_api.eve.SkillTree()
155 except eveapi.Error, e:
161 def get_skill_in_training(self, uid, charID):
163 skill = self.get_auth(uid).character(charID).SkillInTraining()
171 if __name__ == "__main__":