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
35 from ui.diablo import gui
39 The controller class for mEvemon. The intent is to help
40 abstract the EVE API and settings code from the UI code.
44 self.program = hildon.Program()
45 self.program.__init__()
46 self.gconf = gnome.gconf.client_get_default()
47 self.cached_api = eveapi.EVEAPIConnection( cacheHandler = \
48 apicache.cache_handler(debug=False))
49 self.gui = gui.mEveMonUI(self)
54 def quit(self, *args):
57 def get_accounts(self):
59 Returns a dictionary containing uid:api_key pairs gathered from gconf
62 entries = self.gconf.all_entries("/apps/maemo/mevemon/accounts")
65 key = os.path.basename(entry.get_key())
66 value = entry.get_value().to_string()
71 def get_api_key(self, uid):
73 Returns the api key associated with the given uid.
75 return self.gconf.get_string("/apps/maemo/mevemon/accounts/%s" % uid) or ''
77 def remove_account(self, uid):
79 Removes the provided uid key from gconf
81 self.gconf.unset("/apps/maemo/mevemon/accounts/%s" % uid)
83 def add_account(self, uid, api_key):
85 Adds the provided uid:api_key pair to gconf.
87 self.gconf.set_string("/apps/maemo/mevemon/accounts/%s" % uid, api_key)
89 def get_auth(self, uid):
91 Returns an authentication object to be used for eveapi calls
92 that require authentication.
94 api_key = self.get_api_key(uid)
97 auth = self.cached_api.auth(userID=uid, apiKey=api_key)
103 def get_char_sheet(self, uid, char_id):
105 Returns an object containing information about the character specified
106 by the provided character ID.
109 sheet = self.get_auth(uid).character(char_id).CharacterSheet()
111 # TODO: we should really have a logger that logs this error somewhere
116 def charid2uid(self, char_id):
118 Takes a character ID and returns the user ID of the account containing
121 Returns None if the character isn't found in any of the registered accounts.
124 acct_dict = self.get_accounts()
126 for uid, api_key in acct_dict.items():
127 auth = self.cached_api.auth(userID=uid, apiKey=api_key)
128 api_char_list = auth.account.Characters()
130 for character in api_char_list.characters:
131 if character.characterID == char_id:
137 def char_id2name(self, char_id):
139 Takes a character ID and returns the character name associated with
141 The EVE API accepts a comma-separated list of IDs, but for now we
142 will just handle a single ID.
145 chars = self.cached_api.eve.CharacterName(ids=char_id).characters
146 name = chars[0].characterName
152 def char_name2id(self, name):
154 Takes the name of an EVE character and returns the characterID.
156 The EVE api accepts a comma separated list of names, but for now
157 we will just handle single names/
160 chars = self.cached_api.eve.CharacterID(names=name).characters
161 char_id = chars[0].characterID
168 def get_characters(self):
170 Returns a list of (character_name, image_path) pairs from all the
171 accounts that are registered to mEveMon.
173 If there is an authentication issue, then instead of adding a valid
174 pair to the list, it appends an 'error message'
178 err_img = "/usr/share/mevemon/imgs/error.jpg"
180 placeholder_chars = ("Please check your API settings.", err_img, "0")
182 acct_dict = self.get_accounts()
184 return [placeholder_chars]
186 for uid, api_key in acct_dict.items():
187 auth = self.cached_api.auth(userID=uid, apiKey=api_key)
189 api_char_list = auth.account.Characters()
190 # append each char we get to the list we'll return to the
192 for character in api_char_list.characters:
193 ui_char_list.append( ( character.name, fetchimg.portrait_filename( character.characterID, 64 ), uid) )
195 ui_char_list.append(placeholder_chars)
199 def get_portrait(self, char_name, size):
201 Returns the relative path of the retrieved portrait
203 char_id = self.char_name2id(char_name)
204 return fetchimg.portrait_filename(char_id, size)
206 def get_skill_tree(self):
208 Returns an object from eveapi containing skill tree info
211 tree = self.cached_api.eve.SkillTree()
217 def get_skill_in_training(self, uid, char_id):
219 Returns an object from eveapi containing information about the
220 current skill in training
224 skill = self.get_auth(uid).character(char_id).SkillInTraining()
231 if __name__ == "__main__":