2 # mEveMon - A character monitor for EVE Online
3 # Copyright (c) 2010 Ryan and Danny Campbell, and the mEveMon Team
5 # mEveMon is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # mEveMon is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 import ui.models as models
25 menu_items = ("Settings", "About", "Refresh")
27 def create_menu(self, window):
28 menu = hildon.AppMenu()
30 for command in self.menu_items:
32 button = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
33 button.set_label(command)
35 if command == "About":
36 button.connect("clicked", self.about_clicked)
37 elif command == "Settings":
38 button.connect("clicked", self.settings_clicked, window)
39 elif command == "Refresh":
40 button.connect("clicked", self.refresh_clicked)
44 # Add entry to the view menu
51 def settings_clicked(self, button, window):
53 RESPONSE_NEW, RESPONSE_EDIT, RESPONSE_DELETE = range(3)
56 dialog.set_transient_for(window)
57 dialog.set_title("Settings")
59 pannable_area = hildon.PannableArea()
61 dialog_vbox = dialog.vbox
63 vbox = gtk.VBox(False, 1)
65 self.accounts_model = models.AccountsModel(self.controller)
67 accounts_treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)
68 accounts_treeview.set_model(self.accounts_model)
69 accounts_treeview.set_headers_visible(True)
70 self.add_columns_to_accounts(accounts_treeview)
71 vbox.pack_start(accounts_treeview, False, False, 1)
73 # all stock responses are negative, so we can use any positive value
74 new_button = dialog.add_button("New", RESPONSE_NEW)
75 #TODO: get edit button working
76 #edit_button = dialog.add_button("Edit", RESPONSE_EDIT)
77 delete_button = dialog.add_button("Delete", RESPONSE_DELETE)
78 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
80 pannable_area.add_with_viewport(vbox)
82 dialog_vbox.pack_start(pannable_area, True, True, 1)
89 while(result != gtk.RESPONSE_DELETE_EVENT):
90 if result == RESPONSE_NEW:
91 self.new_account_clicked(window)
92 #elif result == RESPONSE_EDIT:
93 # # get the selected treeview item and pop up the account_box
94 # self.edit_account(accounts_treeview)
95 elif result == RESPONSE_DELETE:
96 # get the selected treeview item, and delete the gconf keys
97 self.delete_account(accounts_treeview)
98 elif result == gtk.RESPONSE_OK:
99 self.char_model.get_characters()
102 result = dialog.run()
108 def get_selected_item(self, treeview, column):
109 selection = treeview.get_selection()
110 model, miter = selection.get_selected()
112 value = model.get_value(miter, column)
116 def edit_account(self, treeview):
117 uid = self.get_selected_item(treeview, 0)
118 # pop up the account dialog
120 self.accounts_model.get_accounts()
122 def delete_account(self, treeview):
123 uid = self.get_selected_item(treeview, 0)
124 self.controller.remove_account(uid)
126 self.accounts_model.get_accounts()
129 def add_columns_to_accounts(self, treeview):
130 #Column 0 for the treeview
131 renderer = gtk.CellRendererText()
132 column = gtk.TreeViewColumn('User ID', renderer,
133 text=models.AccountsModel.C_UID)
134 column.set_property("expand", True)
135 treeview.append_column(column)
137 #Column 2 (characters) for the treeview
138 column = gtk.TreeViewColumn('Characters', renderer,
139 markup=models.AccountsModel.C_CHARS)
140 column.set_property("expand", True)
141 treeview.append_column(column)
144 def new_account_clicked(self, window):
145 dialog = gtk.Dialog()
147 #get the vbox to pack all the settings into
150 dialog.set_transient_for(window)
151 dialog.set_title("New Account")
153 uidLabel = gtk.Label("User ID:")
154 uidLabel.set_justify(gtk.JUSTIFY_LEFT)
157 uidEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
158 uidEntry.set_placeholder("User ID")
159 uidEntry.set_property('is_focus', False)
163 apiLabel = gtk.Label("API key:")
164 apiLabel.set_justify(gtk.JUSTIFY_LEFT)
167 apiEntry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
168 apiEntry.set_placeholder("API Key")
169 apiEntry.set_property('is_focus', False)
173 ok_button = dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
176 result = dialog.run()
178 valid_credentials = False
180 while not valid_credentials:
181 if result == gtk.RESPONSE_OK:
182 uid = uidEntry.get_text()
183 api_key = apiEntry.get_text()
186 validation.api_key(api_key)
187 except validation.ValidationError, e:
188 self.report_error(e.message)
189 result = dialog.run()
191 valid_credentials = True
192 self.controller.add_account(uid, api_key)
193 self.accounts_model.get_accounts()
200 def report_error(self, error):
201 hildon.hildon_banner_show_information(self.win, '', error)
203 def about_clicked(self, button):
204 dialog = gtk.AboutDialog()
205 dialog.set_website(self.controller.about_website)
206 dialog.set_website_label(self.controller.about_website)
207 dialog.set_name(self.controller.about_name)
208 dialog.set_authors(self.controller.about_authors)
209 dialog.set_comments(self.controller.about_text)
210 dialog.set_version(self.controller.app_version)
214 def add_label(self, text, box, markup=True, align="left", padding=1):
215 label = gtk.Label(text)
217 label.set_use_markup(True)
219 label.set_alignment(0, 0.5)
221 box.pack_start(label, False, False, padding)