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;
29 this.title = "Moonshoot";
30 this.position = WindowPosition.CENTER;
31 set_default_size (WINDOW_WIDTH, WINDOW_HEIGHT);
34 setup_identities_list();
38 private void search_entry_icon_press_cb (EntryIconPosition pos, Gdk.Event event)
40 if (pos == EntryIconPosition.PRIMARY)
42 print ("Search entry icon pressed\n");
46 this.search_entry.set_text ("");
50 private void search_entry_text_changed_cb ()
52 var has_text = this.search_entry.get_text_length () > 0;
53 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, has_text);
54 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, has_text);
56 this.vbox_rigth.set_visible (false);
57 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
60 private bool search_entry_key_press_event_cb (Gdk.EventKey e)
62 if(Gdk.keyval_name(e.keyval) == "Escape")
63 this.search_entry.set_text("");
65 // Continue processing this event, since the
66 // text entry functionality needs to see it too.
70 private void setup_identities_list ()
72 this.listmodel = new ListStore (Columns.N_COLUMNS, typeof (IdCard),
79 private void fill_details (IdCardWidget id_card_widget)
81 var id_card = id_card_widget.id_card;
82 this.username_entry.set_text (id_card.username);
83 this.password_entry.set_text (id_card.password);
86 private void show_details (IdCard id_card)
88 this.vbox_rigth.set_visible (!vbox_rigth.get_visible ());
90 if (this.vbox_rigth.get_visible () == false)
92 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
96 private void details_identity_cb (IdCardWidget id_card_widget)
98 fill_details (id_card_widget);
99 show_details (id_card_widget.id_card);
102 private IdCard get_id_card_data (AddIdentityDialog dialog)
104 var id_card = new IdCard ();
106 id_card.issuer = dialog.issuer;
107 id_card.username = dialog.username;
108 id_card.password = dialog.password;
110 var icon_theme = IconTheme.get_default ();
113 id_card.pixbuf = icon_theme.load_icon ("avatar-default",
115 IconLookupFlags.FORCE_SIZE);
119 id_card.pixbuf = null;
120 stdout.printf("Error: %s\n", e.message);
123 id_card.services = {"email","jabber","irc"};
128 private void add_identity (AddIdentityDialog dialog)
130 var id_card = get_id_card_data (dialog);
132 var id_card_widget = new IdCardWidget (id_card);
134 this.custom_vbox.add_id_card_widget (id_card_widget);
136 id_card_widget.details_id.connect (details_identity_cb);
137 id_card_widget.remove_id.connect (remove_identity_cb);
138 id_card_widget.expanded.connect (this.custom_vbox.receive_expanded_event);
139 id_card_widget.expanded.connect (fill_details);
142 private void add_identity_cb ()
144 var dialog = new AddIdentityDialog ();
145 var result = dialog.run ();
148 case ResponseType.OK:
149 add_identity (dialog);
157 private void remove_identity (IdCardWidget id_card_widget)
159 this.custom_vbox.remove_id_card_widget (id_card_widget);
162 private void remove_identity_cb (IdCardWidget id_card_widget)
164 var id_card = id_card_widget.id_card;
166 var dialog = new MessageDialog (null,
167 DialogFlags.DESTROY_WITH_PARENT,
169 Gtk.ButtonsType.YES_NO,
170 _("Are you sure you want to delete %s ID Card?"), id_card.issuer);
171 var result = dialog.run ();
173 case ResponseType.YES:
174 remove_identity (id_card_widget);
182 private void label_make_bold (Label label)
184 var font_desc = new Pango.FontDescription ();
186 font_desc.set_weight (Pango.Weight.BOLD);
188 /* This will only affect the weight of the font, the rest is
189 * from the current state of the widget, which comes from the
190 * theme or user prefs, since the font desc only has the
191 * weight flag turned on.
193 label.modify_font (font_desc);
196 private void build_ui()
198 this.search_entry = new Entry();
200 this.search_entry.set_icon_from_icon_name (EntryIconPosition.PRIMARY,
201 "edit-find-symbolic");
202 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, false);
203 this.search_entry.set_icon_tooltip_text (EntryIconPosition.PRIMARY,
204 _("Search identity or service"));
206 this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY,
207 "edit-clear-symbolic");
208 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
209 this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
210 _("Clear the current search"));
212 this.search_entry.icon_press.connect (search_entry_icon_press_cb);
213 this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
214 this.search_entry.key_press_event.connect(search_entry_key_press_event_cb);
216 this.custom_vbox = new CustomVBox (false, 6);
218 var viewport = new Viewport (null, null);
219 viewport.set_border_width (6);
220 viewport.set_shadow_type (ShadowType.NONE);
221 viewport.add (custom_vbox);
222 var scroll = new ScrolledWindow (null, null);
223 scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
224 scroll.set_shadow_type (ShadowType.IN);
225 scroll.add_with_viewport (viewport);
227 var button_add = new ToolButton (null, null);
228 button_add.set_icon_name ("list-add-symbolic");
229 button_add.clicked.connect (add_identity_cb);
230 var button_toolbar = new Toolbar ();
231 button_toolbar.insert (button_add, 0);
233 var vbox_left = new VBox (false, 0);
234 vbox_left.pack_start (search_entry, false, false, 6);
235 vbox_left.pack_start (scroll, true, true, 0);
236 vbox_left.pack_start (button_toolbar, false, false, 0);
237 vbox_left.set_size_request (WINDOW_WIDTH, 0);
239 var login_vbox_title = new Label (_("Login: "));
240 label_make_bold (login_vbox_title);
241 login_vbox_title.set_alignment (0, (float) 0.5);
242 var username_label = new Label (_("Username:"));
243 username_label.set_alignment (1, (float) 0.5);
244 this.username_entry = new Entry ();
245 var password_label = new Label (_("Password:"));
246 password_label.set_alignment (1, (float) 0.5);
247 this.password_entry = new Entry ();
248 password_entry.set_invisible_char ('*');
249 password_entry.set_visibility (false);
250 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
251 var login_table = new Table (3, 3, false);
252 login_table.set_col_spacings (10);
253 login_table.set_row_spacings (10);
254 login_table.attach_defaults (username_label, 0, 1, 0, 1);
255 login_table.attach_defaults (username_entry, 1, 2, 0, 1);
256 login_table.attach_defaults (password_label, 0, 1, 1, 2);
257 login_table.attach_defaults (password_entry, 1, 2, 1, 2);
258 login_table.attach_defaults (remember_checkbutton, 1, 2, 2, 3);
259 var login_vbox_alignment = new Alignment (0, 0, 0, 0);
260 login_vbox_alignment.set_padding (0, 0, 12, 0);
261 login_vbox_alignment.add (login_table);
262 var login_vbox = new VBox (false, 6);
263 login_vbox.pack_start (login_vbox_title, false, true, 0);
264 login_vbox.pack_start (login_vbox_alignment, false, true, 0);
266 var services_vbox_title = new Label (_("Services:"));
267 label_make_bold (services_vbox_title);
268 services_vbox_title.set_alignment (0, (float) 0.5);
269 var email_label = new Label (_("Email"));
270 var email_remove_button = new Button.from_stock (Stock.REMOVE);
271 var im_label = new Label (_("IM"));
272 var im_remove_button = new Button.from_stock (Stock.REMOVE);
273 var services_table = new Table (2, 2, false);
274 services_table.set_col_spacings (10);
275 services_table.set_row_spacings (10);
276 services_table.attach_defaults (email_label, 0, 1, 0, 1);
277 services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
278 services_table.attach_defaults (im_label, 0, 1, 1, 2);
279 services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
280 var services_vbox_alignment = new Alignment (0, 0, 0, 0);
281 services_vbox_alignment.set_padding (0, 0, 12, 0);
282 services_vbox_alignment.add (services_table);
283 var services_vbox = new VBox (false, 6);
284 services_vbox.pack_start (services_vbox_title, false, true, 0);
285 services_vbox.pack_start (services_vbox_alignment, false, true, 0);
287 this.vbox_rigth = new VBox (false, 18);
288 vbox_rigth.pack_start (login_vbox, false, true, 0);
289 vbox_rigth.pack_start (services_vbox, false, true, 0);
291 var hbox = new HBox (false, 12);
292 hbox.pack_start (vbox_left, false, false, 0);
293 hbox.pack_start (vbox_rigth, false, false, 0);
295 var main_vbox = new VBox (false, 12);
296 main_vbox.pack_start (hbox, true, true, 0);
297 main_vbox.set_border_width (12);
300 main_vbox.show_all();
301 this.vbox_rigth.hide ();
304 private void connect_signals()
306 this.destroy.connect (Gtk.main_quit);
309 public static int main(string[] args)
313 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
314 Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
315 Intl.textdomain (Config.GETTEXT_PACKAGE);
317 var window = new MainWindow();