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;
22 this.title = "Moonshoot";
23 this.position = WindowPosition.CENTER;
24 set_default_size (WINDOW_WIDTH, WINDOW_HEIGHT);
30 private void search_entry_icon_press_cb (EntryIconPosition pos, Gdk.Event event)
32 if (pos == EntryIconPosition.PRIMARY)
34 print ("Search entry icon pressed\n");
38 this.search_entry.set_text ("");
42 private void search_entry_text_changed_cb ()
44 var has_text = this.search_entry.get_text_length () > 0;
45 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, has_text);
46 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, has_text);
49 private bool search_entry_key_press_event_cb (Gdk.EventKey e)
51 if(Gdk.keyval_name(e.keyval) == "Escape")
52 this.search_entry.set_text("");
54 // Continue processing this event, since the
55 // text entry functionality needs to see it too.
59 private void details_button_clicked_cb ()
61 this.vbox_rigth.set_visible (!vbox_rigth.get_visible ());
63 if (this.vbox_rigth.get_visible () == false) {
64 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
68 private void add_identity (AddIdentityDialog dialog)
70 var id_card_widget = new IdCardWidget ();
72 this.custom_vbox.pack_start (id_card_widget, false, false);
74 id_card_widget.details_button.clicked.connect (details_button_clicked_cb);
77 private void add_identity_cb ()
79 var dialog = new AddIdentityDialog ();
80 var result = dialog.run ();
84 add_identity (dialog);
92 private IdCard* get_selected_idcard ()
97 private void remove_identity (IdCard id_card)
101 private void remove_identity_cb ()
103 var id_card = get_selected_idcard ();
110 var dialog = new MessageDialog (null,
111 DialogFlags.DESTROY_WITH_PARENT,
113 Gtk.ButtonsType.YES_NO,
114 _("Are you sure you want to delete this ID Card?"));
115 var result = dialog.run ();
117 case ResponseType.YES:
118 remove_identity (id_card);
127 private void label_make_bold (Label label)
129 var font_desc = new Pango.FontDescription ();
131 font_desc.set_weight (Pango.Weight.BOLD);
133 /* This will only affect the weight of the font, the rest is
134 * from the current state of the widget, which comes from the
135 * theme or user prefs, since the font desc only has the
136 * weight flag turned on.
138 label.modify_font (font_desc);
141 private void build_ui()
143 this.search_entry = new Entry();
145 this.search_entry.set_icon_from_icon_name (EntryIconPosition.PRIMARY,
146 "edit-find-symbolic");
147 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, false);
148 this.search_entry.set_icon_tooltip_text (EntryIconPosition.PRIMARY,
149 _("Search identity or service"));
151 this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY,
152 "edit-clear-symbolic");
153 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
154 this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
155 _("Clear the current search"));
157 this.search_entry.icon_press.connect (search_entry_icon_press_cb);
158 this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
159 this.search_entry.key_press_event.connect(search_entry_key_press_event_cb);
161 this.custom_vbox = new VBox (false, 6);
163 var scroll = new ScrolledWindow (null, null);
164 scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
165 scroll.set_shadow_type (ShadowType.IN);
166 scroll.add_with_viewport (custom_vbox);
168 var button_add = new ToolButton (null, null);
169 button_add.set_icon_name ("list-add-symbolic");
170 button_add.clicked.connect (add_identity_cb);
171 var button_remove = new ToolButton (null, null);
172 button_remove.set_icon_name ("list-remove-symbolic");
173 button_remove.clicked.connect (remove_identity_cb);
174 var button_toolbar = new Toolbar ();
175 button_toolbar.insert (button_add, 0);
176 button_toolbar.insert (button_remove, 1);
178 var vbox_left = new VBox (false, 0);
179 vbox_left.pack_start (search_entry, false, false, 6);
180 vbox_left.pack_start (scroll, true, true, 0);
181 vbox_left.pack_start (button_toolbar, false, false, 0);
182 vbox_left.set_size_request (WINDOW_WIDTH, 0);
184 var login_vbox_title = new Label (_("Login: "));
185 label_make_bold (login_vbox_title);
186 login_vbox_title.set_alignment (0, (float) 0.5);
187 var username_label = new Label (_("Username:"));
188 username_label.set_alignment (1, (float) 0.5);
189 var username_entry = new Entry ();
190 var password_label = new Label (_("Password:"));
191 password_label.set_alignment (1, (float) 0.5);
192 var password_entry = new Entry ();
193 password_entry.set_invisible_char ('*');
194 password_entry.set_visibility (false);
195 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
196 var login_table = new Table (3, 3, false);
197 login_table.set_col_spacings (10);
198 login_table.set_row_spacings (10);
199 login_table.attach_defaults (username_label, 0, 1, 0, 1);
200 login_table.attach_defaults (username_entry, 1, 2, 0, 1);
201 login_table.attach_defaults (password_label, 0, 1, 1, 2);
202 login_table.attach_defaults (password_entry, 1, 2, 1, 2);
203 login_table.attach_defaults (remember_checkbutton, 1, 2, 2, 3);
204 var login_vbox_alignment = new Alignment (0, 0, 0, 0);
205 login_vbox_alignment.set_padding (0, 0, 12, 0);
206 login_vbox_alignment.add (login_table);
207 var login_vbox = new VBox (false, 6);
208 login_vbox.pack_start (login_vbox_title, false, true, 0);
209 login_vbox.pack_start (login_vbox_alignment, false, true, 0);
211 var services_vbox_title = new Label (_("Services:"));
212 label_make_bold (services_vbox_title);
213 services_vbox_title.set_alignment (0, (float) 0.5);
214 var email_label = new Label (_("Email"));
215 var email_remove_button = new Button.from_stock (Stock.REMOVE);
216 var im_label = new Label (_("IM"));
217 var im_remove_button = new Button.from_stock (Stock.REMOVE);
218 var services_table = new Table (2, 2, false);
219 services_table.set_col_spacings (10);
220 services_table.set_row_spacings (10);
221 services_table.attach_defaults (email_label, 0, 1, 0, 1);
222 services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
223 services_table.attach_defaults (im_label, 0, 1, 1, 2);
224 services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
225 var services_vbox_alignment = new Alignment (0, 0, 0, 0);
226 services_vbox_alignment.set_padding (0, 0, 12, 0);
227 services_vbox_alignment.add (services_table);
228 var services_vbox = new VBox (false, 6);
229 services_vbox.pack_start (services_vbox_title, false, true, 0);
230 services_vbox.pack_start (services_vbox_alignment, false, true, 0);
232 this.vbox_rigth = new VBox (false, 18);
233 vbox_rigth.pack_start (login_vbox, false, true, 0);
234 vbox_rigth.pack_start (services_vbox, false, true, 0);
236 var hbox = new HBox (false, 12);
237 hbox.pack_start (vbox_left, false, false, 0);
238 hbox.pack_start (vbox_rigth, false, false, 0);
240 var main_vbox = new VBox (false, 12);
241 main_vbox.pack_start (hbox, true, true, 0);
242 main_vbox.set_border_width (12);
245 main_vbox.show_all();
246 this.vbox_rigth.hide ();
249 private void connect_signals()
251 this.destroy.connect (Gtk.main_quit);
254 public static int main(string[] args)
258 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
259 Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
260 Intl.textdomain (Config.GETTEXT_PACKAGE);
262 var window = new MainWindow();