3 class MainWindow : Window
5 private const int WINDOW_WIDTH = 400;
6 private const int WINDOW_HEIGHT = 500;
8 private Entry search_entry;
9 private VBox vbox_rigth;
10 private CustomVBox custom_vbox;
12 private Entry username_entry;
13 private Entry password_entry;
15 private ListStore listmodel;
17 private IdentitiesManager identities_manager;
31 this.title = "Moonshoot";
32 this.position = WindowPosition.CENTER;
33 set_default_size (WINDOW_WIDTH, WINDOW_HEIGHT);
36 setup_identities_list();
41 private void search_entry_icon_press_cb (EntryIconPosition pos, Gdk.Event event)
43 if (pos == EntryIconPosition.PRIMARY)
45 print ("Search entry icon pressed\n");
49 this.search_entry.set_text ("");
53 private void search_entry_text_changed_cb ()
55 var has_text = this.search_entry.get_text_length () > 0;
56 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, has_text);
57 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, has_text);
59 this.custom_vbox.new_text_in_search_entry (search_entry.get_text ());
61 this.vbox_rigth.set_visible (false);
62 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
65 private bool search_entry_key_press_event_cb (Gdk.EventKey e)
67 if(Gdk.keyval_name(e.keyval) == "Escape")
68 this.search_entry.set_text("");
70 // Continue processing this event, since the
71 // text entry functionality needs to see it too.
75 private void setup_identities_list ()
77 this.listmodel = new ListStore (Columns.N_COLUMNS, typeof (IdCard),
84 private void load_id_cards ()
86 this.identities_manager = new IdentitiesManager ();
88 foreach (IdCard id_card in identities_manager.id_card_list)
90 add_id_card_widget (id_card);
94 private void fill_details (IdCardWidget id_card_widget)
96 var id_card = id_card_widget.id_card;
97 this.username_entry.set_text (id_card.username);
98 this.password_entry.set_text (id_card.password);
101 private void show_details (IdCard id_card)
103 this.vbox_rigth.set_visible (!vbox_rigth.get_visible ());
105 if (this.vbox_rigth.get_visible () == false)
107 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
111 private void details_identity_cb (IdCardWidget id_card_widget)
113 fill_details (id_card_widget);
114 show_details (id_card_widget.id_card);
117 private IdCard get_id_card_data (AddIdentityDialog dialog)
119 var id_card = new IdCard ();
121 id_card.issuer = dialog.issuer;
122 id_card.username = dialog.username;
123 id_card.password = dialog.password;
125 var icon_theme = IconTheme.get_default ();
128 id_card.pixbuf = icon_theme.load_icon ("avatar-default",
130 IconLookupFlags.FORCE_SIZE);
134 id_card.pixbuf = null;
135 stdout.printf("Error: %s\n", e.message);
138 id_card.services = {"email","jabber","irc"};
143 private void add_id_card_widget (IdCard id_card)
145 var id_card_widget = new IdCardWidget (id_card);
147 this.custom_vbox.add_id_card_widget (id_card_widget);
149 id_card_widget.details_id.connect (details_identity_cb);
150 id_card_widget.remove_id.connect (remove_identity_cb);
151 id_card_widget.expanded.connect (this.custom_vbox.receive_expanded_event);
152 id_card_widget.expanded.connect (fill_details);
155 private void add_identity (AddIdentityDialog dialog)
157 var id_card = get_id_card_data (dialog);
159 this.identities_manager.id_card_list.prepend (id_card);
160 this.identities_manager.store_id_cards ();
162 add_id_card_widget (id_card);
165 private void add_identity_cb ()
167 var dialog = new AddIdentityDialog ();
168 var result = dialog.run ();
171 case ResponseType.OK:
172 add_identity (dialog);
180 private void remove_id_card_widget (IdCardWidget id_card_widget)
182 this.custom_vbox.remove_id_card_widget (id_card_widget);
185 private void remove_identity (IdCardWidget id_card_widget)
187 var id_card = id_card_widget.id_card;
189 this.identities_manager.id_card_list.remove (id_card);
190 this.identities_manager.store_id_cards ();
192 remove_id_card_widget (id_card_widget);
195 private void remove_identity_cb (IdCardWidget id_card_widget)
197 var id_card = id_card_widget.id_card;
199 var dialog = new MessageDialog (null,
200 DialogFlags.DESTROY_WITH_PARENT,
202 Gtk.ButtonsType.YES_NO,
203 _("Are you sure you want to delete %s ID Card?"), id_card.issuer);
204 var result = dialog.run ();
206 case ResponseType.YES:
207 remove_identity (id_card_widget);
215 private void label_make_bold (Label label)
217 var font_desc = new Pango.FontDescription ();
219 font_desc.set_weight (Pango.Weight.BOLD);
221 /* This will only affect the weight of the font, the rest is
222 * from the current state of the widget, which comes from the
223 * theme or user prefs, since the font desc only has the
224 * weight flag turned on.
226 label.modify_font (font_desc);
229 private void build_ui()
231 this.search_entry = new Entry();
233 this.search_entry.set_icon_from_icon_name (EntryIconPosition.PRIMARY,
234 "edit-find-symbolic");
235 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, false);
236 this.search_entry.set_icon_tooltip_text (EntryIconPosition.PRIMARY,
237 _("Search identity or service"));
239 this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY,
240 "edit-clear-symbolic");
241 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
242 this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
243 _("Clear the current search"));
245 this.search_entry.icon_press.connect (search_entry_icon_press_cb);
246 this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
247 this.search_entry.key_press_event.connect(search_entry_key_press_event_cb);
249 this.custom_vbox = new CustomVBox (false, 6);
251 var viewport = new Viewport (null, null);
252 viewport.set_border_width (6);
253 viewport.set_shadow_type (ShadowType.NONE);
254 viewport.add (custom_vbox);
255 var scroll = new ScrolledWindow (null, null);
256 scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
257 scroll.set_shadow_type (ShadowType.IN);
258 scroll.add_with_viewport (viewport);
260 var button_add = new ToolButton (null, null);
261 button_add.set_icon_name ("list-add-symbolic");
262 button_add.clicked.connect (add_identity_cb);
263 var button_toolbar = new Toolbar ();
264 button_toolbar.insert (button_add, 0);
266 var vbox_left = new VBox (false, 0);
267 vbox_left.pack_start (search_entry, false, false, 6);
268 vbox_left.pack_start (scroll, true, true, 0);
269 vbox_left.pack_start (button_toolbar, false, false, 0);
270 vbox_left.set_size_request (WINDOW_WIDTH, 0);
272 var login_vbox_title = new Label (_("Login: "));
273 label_make_bold (login_vbox_title);
274 login_vbox_title.set_alignment (0, (float) 0.5);
275 var username_label = new Label (_("Username:"));
276 username_label.set_alignment (1, (float) 0.5);
277 this.username_entry = new Entry ();
278 var password_label = new Label (_("Password:"));
279 password_label.set_alignment (1, (float) 0.5);
280 this.password_entry = new Entry ();
281 password_entry.set_invisible_char ('*');
282 password_entry.set_visibility (false);
283 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
284 var login_table = new Table (3, 3, false);
285 login_table.set_col_spacings (10);
286 login_table.set_row_spacings (10);
287 login_table.attach_defaults (username_label, 0, 1, 0, 1);
288 login_table.attach_defaults (username_entry, 1, 2, 0, 1);
289 login_table.attach_defaults (password_label, 0, 1, 1, 2);
290 login_table.attach_defaults (password_entry, 1, 2, 1, 2);
291 login_table.attach_defaults (remember_checkbutton, 1, 2, 2, 3);
292 var login_vbox_alignment = new Alignment (0, 0, 0, 0);
293 login_vbox_alignment.set_padding (0, 0, 12, 0);
294 login_vbox_alignment.add (login_table);
295 var login_vbox = new VBox (false, 6);
296 login_vbox.pack_start (login_vbox_title, false, true, 0);
297 login_vbox.pack_start (login_vbox_alignment, false, true, 0);
299 var services_vbox_title = new Label (_("Services:"));
300 label_make_bold (services_vbox_title);
301 services_vbox_title.set_alignment (0, (float) 0.5);
302 var email_label = new Label (_("Email"));
303 var email_remove_button = new Button.from_stock (Stock.REMOVE);
304 var im_label = new Label (_("IM"));
305 var im_remove_button = new Button.from_stock (Stock.REMOVE);
306 var services_table = new Table (2, 2, false);
307 services_table.set_col_spacings (10);
308 services_table.set_row_spacings (10);
309 services_table.attach_defaults (email_label, 0, 1, 0, 1);
310 services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
311 services_table.attach_defaults (im_label, 0, 1, 1, 2);
312 services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
313 var services_vbox_alignment = new Alignment (0, 0, 0, 0);
314 services_vbox_alignment.set_padding (0, 0, 12, 0);
315 services_vbox_alignment.add (services_table);
316 var services_vbox = new VBox (false, 6);
317 services_vbox.pack_start (services_vbox_title, false, true, 0);
318 services_vbox.pack_start (services_vbox_alignment, false, true, 0);
320 this.vbox_rigth = new VBox (false, 18);
321 vbox_rigth.pack_start (login_vbox, false, true, 0);
322 vbox_rigth.pack_start (services_vbox, false, true, 0);
324 var hbox = new HBox (false, 12);
325 hbox.pack_start (vbox_left, false, false, 0);
326 hbox.pack_start (vbox_rigth, false, false, 0);
328 var main_vbox = new VBox (false, 12);
329 main_vbox.pack_start (hbox, true, true, 0);
330 main_vbox.set_border_width (12);
333 main_vbox.show_all();
334 this.vbox_rigth.hide ();
337 private void connect_signals()
339 this.destroy.connect (Gtk.main_quit);
342 public static int main(string[] args)
346 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
347 Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
348 Intl.textdomain (Config.GETTEXT_PACKAGE);
350 var window = new MainWindow();