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 VBox custom_vbox;
12 private Entry username_entry;
13 private Entry password_entry;
25 this.title = "Moonshoot";
26 this.position = WindowPosition.CENTER;
27 set_default_size (WINDOW_WIDTH, WINDOW_HEIGHT);
33 private void search_entry_icon_press_cb (EntryIconPosition pos, Gdk.Event event)
35 if (pos == EntryIconPosition.PRIMARY)
37 print ("Search entry icon pressed\n");
41 this.search_entry.set_text ("");
45 private void search_entry_text_changed_cb ()
47 var has_text = this.search_entry.get_text_length () > 0;
48 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, has_text);
49 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, has_text);
51 this.vbox_rigth.set_visible (false);
52 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
55 private bool search_entry_key_press_event_cb (Gdk.EventKey e)
57 if(Gdk.keyval_name(e.keyval) == "Escape")
58 this.search_entry.set_text("");
60 // Continue processing this event, since the
61 // text entry functionality needs to see it too.
65 private IdCard get_id_card ()
67 var id_card = new IdCard ();
68 id_card.issue = "University";
69 id_card.username = "username";
70 id_card.password = "password";
75 private void show_details (IdCard id_card)
77 this.vbox_rigth.set_visible (!vbox_rigth.get_visible ());
79 if (this.vbox_rigth.get_visible () == false)
81 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
85 this.username_entry.set_text (id_card.username);
86 this.password_entry.set_text (id_card.password);
90 private void details_button_clicked_cb ()
92 var id_card = get_id_card ();
93 show_details (id_card);
96 private void add_identity (AddIdentityDialog dialog)
98 var id_card_widget = new IdCardWidget ();
99 var id_card = new IdCard ();
101 id_card.issuer = dialog.issuer;
102 id_card.username = dialog.username;
103 id_card.password = dialog.password;
105 id_card_widget.id_card = id_card;
107 this.custom_vbox.pack_start (id_card_widget, false, false);
109 id_card_widget.details_button.clicked.connect (details_button_clicked_cb);
110 id_card_widget.delete_button.clicked.connect (remove_identity_cb);
113 private void add_identity_cb ()
115 var dialog = new AddIdentityDialog ();
116 var result = dialog.run ();
119 case ResponseType.OK:
120 add_identity (dialog);
128 private void remove_identity ()
132 private void remove_identity_cb ()
134 var dialog = new MessageDialog (null,
135 DialogFlags.DESTROY_WITH_PARENT,
137 Gtk.ButtonsType.YES_NO,
138 _("Are you sure you want to delete this ID Card?"));
139 var result = dialog.run ();
141 case ResponseType.YES:
150 private void label_make_bold (Label label)
152 var font_desc = new Pango.FontDescription ();
154 font_desc.set_weight (Pango.Weight.BOLD);
156 /* This will only affect the weight of the font, the rest is
157 * from the current state of the widget, which comes from the
158 * theme or user prefs, since the font desc only has the
159 * weight flag turned on.
161 label.modify_font (font_desc);
164 private void build_ui()
166 this.search_entry = new Entry();
168 this.search_entry.set_icon_from_icon_name (EntryIconPosition.PRIMARY,
169 "edit-find-symbolic");
170 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, false);
171 this.search_entry.set_icon_tooltip_text (EntryIconPosition.PRIMARY,
172 _("Search identity or service"));
174 this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY,
175 "edit-clear-symbolic");
176 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
177 this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
178 _("Clear the current search"));
180 this.search_entry.icon_press.connect (search_entry_icon_press_cb);
181 this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
182 this.search_entry.key_press_event.connect(search_entry_key_press_event_cb);
184 this.custom_vbox = new VBox (false, 6);
186 var scroll = new ScrolledWindow (null, null);
187 scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
188 scroll.set_shadow_type (ShadowType.IN);
189 scroll.add_with_viewport (custom_vbox);
191 var button_add = new ToolButton (null, null);
192 button_add.set_icon_name ("list-add-symbolic");
193 button_add.clicked.connect (add_identity_cb);
194 var button_toolbar = new Toolbar ();
195 button_toolbar.insert (button_add, 0);
197 var vbox_left = new VBox (false, 0);
198 vbox_left.pack_start (search_entry, false, false, 6);
199 vbox_left.pack_start (scroll, true, true, 0);
200 vbox_left.pack_start (button_toolbar, false, false, 0);
201 vbox_left.set_size_request (WINDOW_WIDTH, 0);
203 var login_vbox_title = new Label (_("Login: "));
204 label_make_bold (login_vbox_title);
205 login_vbox_title.set_alignment (0, (float) 0.5);
206 var username_label = new Label (_("Username:"));
207 username_label.set_alignment (1, (float) 0.5);
208 this.username_entry = new Entry ();
209 var password_label = new Label (_("Password:"));
210 password_label.set_alignment (1, (float) 0.5);
211 this.password_entry = new Entry ();
212 password_entry.set_invisible_char ('*');
213 password_entry.set_visibility (false);
214 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
215 var login_table = new Table (3, 3, false);
216 login_table.set_col_spacings (10);
217 login_table.set_row_spacings (10);
218 login_table.attach_defaults (username_label, 0, 1, 0, 1);
219 login_table.attach_defaults (username_entry, 1, 2, 0, 1);
220 login_table.attach_defaults (password_label, 0, 1, 1, 2);
221 login_table.attach_defaults (password_entry, 1, 2, 1, 2);
222 login_table.attach_defaults (remember_checkbutton, 1, 2, 2, 3);
223 var login_vbox_alignment = new Alignment (0, 0, 0, 0);
224 login_vbox_alignment.set_padding (0, 0, 12, 0);
225 login_vbox_alignment.add (login_table);
226 var login_vbox = new VBox (false, 6);
227 login_vbox.pack_start (login_vbox_title, false, true, 0);
228 login_vbox.pack_start (login_vbox_alignment, false, true, 0);
230 var services_vbox_title = new Label (_("Services:"));
231 label_make_bold (services_vbox_title);
232 services_vbox_title.set_alignment (0, (float) 0.5);
233 var email_label = new Label (_("Email"));
234 var email_remove_button = new Button.from_stock (Stock.REMOVE);
235 var im_label = new Label (_("IM"));
236 var im_remove_button = new Button.from_stock (Stock.REMOVE);
237 var services_table = new Table (2, 2, false);
238 services_table.set_col_spacings (10);
239 services_table.set_row_spacings (10);
240 services_table.attach_defaults (email_label, 0, 1, 0, 1);
241 services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
242 services_table.attach_defaults (im_label, 0, 1, 1, 2);
243 services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
244 var services_vbox_alignment = new Alignment (0, 0, 0, 0);
245 services_vbox_alignment.set_padding (0, 0, 12, 0);
246 services_vbox_alignment.add (services_table);
247 var services_vbox = new VBox (false, 6);
248 services_vbox.pack_start (services_vbox_title, false, true, 0);
249 services_vbox.pack_start (services_vbox_alignment, false, true, 0);
251 this.vbox_rigth = new VBox (false, 18);
252 vbox_rigth.pack_start (login_vbox, false, true, 0);
253 vbox_rigth.pack_start (services_vbox, false, true, 0);
255 var hbox = new HBox (false, 12);
256 hbox.pack_start (vbox_left, false, false, 0);
257 hbox.pack_start (vbox_rigth, false, false, 0);
259 var main_vbox = new VBox (false, 12);
260 main_vbox.pack_start (hbox, true, true, 0);
261 main_vbox.set_border_width (12);
264 main_vbox.show_all();
265 this.vbox_rigth.hide ();
268 private void connect_signals()
270 this.destroy.connect (Gtk.main_quit);
273 public static int main(string[] args)
277 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
278 Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
279 Intl.textdomain (Config.GETTEXT_PACKAGE);
281 var window = new MainWindow();