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);
48 this.vbox_rigth.set_visible (false);
49 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
52 private bool search_entry_key_press_event_cb (Gdk.EventKey e)
54 if(Gdk.keyval_name(e.keyval) == "Escape")
55 this.search_entry.set_text("");
57 // Continue processing this event, since the
58 // text entry functionality needs to see it too.
62 private void details_button_clicked_cb ()
64 this.vbox_rigth.set_visible (!vbox_rigth.get_visible ());
66 if (this.vbox_rigth.get_visible () == false) {
67 this.resize (WINDOW_WIDTH, WINDOW_HEIGHT);
71 private void add_identity (AddIdentityDialog dialog)
73 var id_card_widget = new IdCardWidget ();
75 this.custom_vbox.pack_start (id_card_widget, false, false);
77 id_card_widget.details_button.clicked.connect (details_button_clicked_cb);
78 id_card_widget.delete_button.clicked.connect (remove_identity_cb);
81 private void add_identity_cb ()
83 var dialog = new AddIdentityDialog ();
84 var result = dialog.run ();
88 add_identity (dialog);
96 private void remove_identity ()
100 private void remove_identity_cb ()
102 var dialog = new MessageDialog (null,
103 DialogFlags.DESTROY_WITH_PARENT,
105 Gtk.ButtonsType.YES_NO,
106 _("Are you sure you want to delete this ID Card?"));
107 var result = dialog.run ();
109 case ResponseType.YES:
118 private void label_make_bold (Label label)
120 var font_desc = new Pango.FontDescription ();
122 font_desc.set_weight (Pango.Weight.BOLD);
124 /* This will only affect the weight of the font, the rest is
125 * from the current state of the widget, which comes from the
126 * theme or user prefs, since the font desc only has the
127 * weight flag turned on.
129 label.modify_font (font_desc);
132 private void build_ui()
134 this.search_entry = new Entry();
136 this.search_entry.set_icon_from_icon_name (EntryIconPosition.PRIMARY,
137 "edit-find-symbolic");
138 this.search_entry.set_icon_sensitive (EntryIconPosition.PRIMARY, false);
139 this.search_entry.set_icon_tooltip_text (EntryIconPosition.PRIMARY,
140 _("Search identity or service"));
142 this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY,
143 "edit-clear-symbolic");
144 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
145 this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
146 _("Clear the current search"));
148 this.search_entry.icon_press.connect (search_entry_icon_press_cb);
149 this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
150 this.search_entry.key_press_event.connect(search_entry_key_press_event_cb);
152 this.custom_vbox = new VBox (false, 6);
154 var scroll = new ScrolledWindow (null, null);
155 scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
156 scroll.set_shadow_type (ShadowType.IN);
157 scroll.add_with_viewport (custom_vbox);
159 var button_add = new ToolButton (null, null);
160 button_add.set_icon_name ("list-add-symbolic");
161 button_add.clicked.connect (add_identity_cb);
162 var button_toolbar = new Toolbar ();
163 button_toolbar.insert (button_add, 0);
165 var vbox_left = new VBox (false, 0);
166 vbox_left.pack_start (search_entry, false, false, 6);
167 vbox_left.pack_start (scroll, true, true, 0);
168 vbox_left.pack_start (button_toolbar, false, false, 0);
169 vbox_left.set_size_request (WINDOW_WIDTH, 0);
171 var login_vbox_title = new Label (_("Login: "));
172 label_make_bold (login_vbox_title);
173 login_vbox_title.set_alignment (0, (float) 0.5);
174 var username_label = new Label (_("Username:"));
175 username_label.set_alignment (1, (float) 0.5);
176 var username_entry = new Entry ();
177 var password_label = new Label (_("Password:"));
178 password_label.set_alignment (1, (float) 0.5);
179 var password_entry = new Entry ();
180 password_entry.set_invisible_char ('*');
181 password_entry.set_visibility (false);
182 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
183 var login_table = new Table (3, 3, false);
184 login_table.set_col_spacings (10);
185 login_table.set_row_spacings (10);
186 login_table.attach_defaults (username_label, 0, 1, 0, 1);
187 login_table.attach_defaults (username_entry, 1, 2, 0, 1);
188 login_table.attach_defaults (password_label, 0, 1, 1, 2);
189 login_table.attach_defaults (password_entry, 1, 2, 1, 2);
190 login_table.attach_defaults (remember_checkbutton, 1, 2, 2, 3);
191 var login_vbox_alignment = new Alignment (0, 0, 0, 0);
192 login_vbox_alignment.set_padding (0, 0, 12, 0);
193 login_vbox_alignment.add (login_table);
194 var login_vbox = new VBox (false, 6);
195 login_vbox.pack_start (login_vbox_title, false, true, 0);
196 login_vbox.pack_start (login_vbox_alignment, false, true, 0);
198 var services_vbox_title = new Label (_("Services:"));
199 label_make_bold (services_vbox_title);
200 services_vbox_title.set_alignment (0, (float) 0.5);
201 var email_label = new Label (_("Email"));
202 var email_remove_button = new Button.from_stock (Stock.REMOVE);
203 var im_label = new Label (_("IM"));
204 var im_remove_button = new Button.from_stock (Stock.REMOVE);
205 var services_table = new Table (2, 2, false);
206 services_table.set_col_spacings (10);
207 services_table.set_row_spacings (10);
208 services_table.attach_defaults (email_label, 0, 1, 0, 1);
209 services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
210 services_table.attach_defaults (im_label, 0, 1, 1, 2);
211 services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
212 var services_vbox_alignment = new Alignment (0, 0, 0, 0);
213 services_vbox_alignment.set_padding (0, 0, 12, 0);
214 services_vbox_alignment.add (services_table);
215 var services_vbox = new VBox (false, 6);
216 services_vbox.pack_start (services_vbox_title, false, true, 0);
217 services_vbox.pack_start (services_vbox_alignment, false, true, 0);
219 this.vbox_rigth = new VBox (false, 18);
220 vbox_rigth.pack_start (login_vbox, false, true, 0);
221 vbox_rigth.pack_start (services_vbox, false, true, 0);
223 var hbox = new HBox (false, 12);
224 hbox.pack_start (vbox_left, false, false, 0);
225 hbox.pack_start (vbox_rigth, false, false, 0);
227 var main_vbox = new VBox (false, 12);
228 main_vbox.pack_start (hbox, true, true, 0);
229 main_vbox.set_border_width (12);
232 main_vbox.show_all();
233 this.vbox_rigth.hide ();
236 private void connect_signals()
238 this.destroy.connect (Gtk.main_quit);
241 public static int main(string[] args)
245 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
246 Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
247 Intl.textdomain (Config.GETTEXT_PACKAGE);
249 var window = new MainWindow();