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.custom_vbox.new_text_in_search_entry (search_entry.get_text ());
58 this.vbox_rigth.set_visible (false);
59 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
62 private bool search_entry_key_press_event_cb (Gdk.EventKey e)
64 if(Gdk.keyval_name(e.keyval) == "Escape")
65 this.search_entry.set_text("");
67 // Continue processing this event, since the
68 // text entry functionality needs to see it too.
72 private void setup_identities_list ()
74 this.listmodel = new ListStore (Columns.N_COLUMNS, typeof (IdCard),
81 private void fill_details (IdCardWidget id_card_widget)
83 var id_card = id_card_widget.id_card;
84 this.username_entry.set_text (id_card.username);
85 this.password_entry.set_text (id_card.password);
88 private void show_details (IdCard id_card)
90 this.vbox_rigth.set_visible (!vbox_rigth.get_visible ());
92 if (this.vbox_rigth.get_visible () == false)
94 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
98 private void details_identity_cb (IdCardWidget id_card_widget)
100 fill_details (id_card_widget);
101 show_details (id_card_widget.id_card);
104 private IdCard get_id_card_data (AddIdentityDialog dialog)
106 var id_card = new IdCard ();
108 id_card.issuer = dialog.issuer;
109 id_card.username = dialog.username;
110 id_card.password = dialog.password;
112 var icon_theme = IconTheme.get_default ();
115 id_card.pixbuf = icon_theme.load_icon ("avatar-default",
117 IconLookupFlags.FORCE_SIZE);
121 id_card.pixbuf = null;
122 stdout.printf("Error: %s\n", e.message);
125 id_card.services = {"email","jabber","irc"};
130 private void add_identity (AddIdentityDialog dialog)
132 var id_card = get_id_card_data (dialog);
134 var id_card_widget = new IdCardWidget (id_card);
136 this.custom_vbox.add_id_card_widget (id_card_widget);
138 id_card_widget.details_id.connect (details_identity_cb);
139 id_card_widget.remove_id.connect (remove_identity_cb);
140 id_card_widget.expanded.connect (this.custom_vbox.receive_expanded_event);
141 id_card_widget.expanded.connect (fill_details);
144 private void add_identity_cb ()
146 var dialog = new AddIdentityDialog ();
147 var result = dialog.run ();
150 case ResponseType.OK:
151 add_identity (dialog);
159 private void remove_identity (IdCardWidget id_card_widget)
161 this.custom_vbox.remove_id_card_widget (id_card_widget);
164 private void remove_identity_cb (IdCardWidget id_card_widget)
166 var id_card = id_card_widget.id_card;
168 var dialog = new MessageDialog (null,
169 DialogFlags.DESTROY_WITH_PARENT,
171 Gtk.ButtonsType.YES_NO,
172 _("Are you sure you want to delete %s ID Card?"), id_card.issuer);
173 var result = dialog.run ();
175 case ResponseType.YES:
176 remove_identity (id_card_widget);
184 private void label_make_bold (Label label)
186 var font_desc = new Pango.FontDescription ();
188 font_desc.set_weight (Pango.Weight.BOLD);
190 /* This will only affect the weight of the font, the rest is
191 * from the current state of the widget, which comes from the
192 * theme or user prefs, since the font desc only has the
193 * weight flag turned on.
195 label.modify_font (font_desc);
198 private void build_ui()
200 this.search_entry = new Entry();
202 this.search_entry.set_icon_from_icon_name (EntryIconPosition.PRIMARY,
203 "edit-find-symbolic");
204 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, false);
205 this.search_entry.set_icon_tooltip_text (EntryIconPosition.PRIMARY,
206 _("Search identity or service"));
208 this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY,
209 "edit-clear-symbolic");
210 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
211 this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
212 _("Clear the current search"));
214 this.search_entry.icon_press.connect (search_entry_icon_press_cb);
215 this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
216 this.search_entry.key_press_event.connect(search_entry_key_press_event_cb);
218 this.custom_vbox = new CustomVBox (false, 6);
220 var viewport = new Viewport (null, null);
221 viewport.set_border_width (6);
222 viewport.set_shadow_type (ShadowType.NONE);
223 viewport.add (custom_vbox);
224 var scroll = new ScrolledWindow (null, null);
225 scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
226 scroll.set_shadow_type (ShadowType.IN);
227 scroll.add_with_viewport (viewport);
229 var button_add = new ToolButton (null, null);
230 button_add.set_icon_name ("list-add-symbolic");
231 button_add.clicked.connect (add_identity_cb);
232 var button_toolbar = new Toolbar ();
233 button_toolbar.insert (button_add, 0);
235 var vbox_left = new VBox (false, 0);
236 vbox_left.pack_start (search_entry, false, false, 6);
237 vbox_left.pack_start (scroll, true, true, 0);
238 vbox_left.pack_start (button_toolbar, false, false, 0);
239 vbox_left.set_size_request (WINDOW_WIDTH, 0);
241 var login_vbox_title = new Label (_("Login: "));
242 label_make_bold (login_vbox_title);
243 login_vbox_title.set_alignment (0, (float) 0.5);
244 var username_label = new Label (_("Username:"));
245 username_label.set_alignment (1, (float) 0.5);
246 this.username_entry = new Entry ();
247 var password_label = new Label (_("Password:"));
248 password_label.set_alignment (1, (float) 0.5);
249 this.password_entry = new Entry ();
250 password_entry.set_invisible_char ('*');
251 password_entry.set_visibility (false);
252 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
253 var login_table = new Table (3, 3, false);
254 login_table.set_col_spacings (10);
255 login_table.set_row_spacings (10);
256 login_table.attach_defaults (username_label, 0, 1, 0, 1);
257 login_table.attach_defaults (username_entry, 1, 2, 0, 1);
258 login_table.attach_defaults (password_label, 0, 1, 1, 2);
259 login_table.attach_defaults (password_entry, 1, 2, 1, 2);
260 login_table.attach_defaults (remember_checkbutton, 1, 2, 2, 3);
261 var login_vbox_alignment = new Alignment (0, 0, 0, 0);
262 login_vbox_alignment.set_padding (0, 0, 12, 0);
263 login_vbox_alignment.add (login_table);
264 var login_vbox = new VBox (false, 6);
265 login_vbox.pack_start (login_vbox_title, false, true, 0);
266 login_vbox.pack_start (login_vbox_alignment, false, true, 0);
268 var services_vbox_title = new Label (_("Services:"));
269 label_make_bold (services_vbox_title);
270 services_vbox_title.set_alignment (0, (float) 0.5);
271 var email_label = new Label (_("Email"));
272 var email_remove_button = new Button.from_stock (Stock.REMOVE);
273 var im_label = new Label (_("IM"));
274 var im_remove_button = new Button.from_stock (Stock.REMOVE);
275 var services_table = new Table (2, 2, false);
276 services_table.set_col_spacings (10);
277 services_table.set_row_spacings (10);
278 services_table.attach_defaults (email_label, 0, 1, 0, 1);
279 services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
280 services_table.attach_defaults (im_label, 0, 1, 1, 2);
281 services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
282 var services_vbox_alignment = new Alignment (0, 0, 0, 0);
283 services_vbox_alignment.set_padding (0, 0, 12, 0);
284 services_vbox_alignment.add (services_table);
285 var services_vbox = new VBox (false, 6);
286 services_vbox.pack_start (services_vbox_title, false, true, 0);
287 services_vbox.pack_start (services_vbox_alignment, false, true, 0);
289 this.vbox_rigth = new VBox (false, 18);
290 vbox_rigth.pack_start (login_vbox, false, true, 0);
291 vbox_rigth.pack_start (services_vbox, false, true, 0);
293 var hbox = new HBox (false, 12);
294 hbox.pack_start (vbox_left, false, false, 0);
295 hbox.pack_start (vbox_rigth, false, false, 0);
297 var main_vbox = new VBox (false, 12);
298 main_vbox.pack_start (hbox, true, true, 0);
299 main_vbox.set_border_width (12);
302 main_vbox.show_all();
303 this.vbox_rigth.hide ();
306 private void connect_signals()
308 this.destroy.connect (Gtk.main_quit);
311 public static int main(string[] args)
315 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
316 Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
317 Intl.textdomain (Config.GETTEXT_PACKAGE);
319 var window = new MainWindow();