3 class MainWindow : Window
6 private Entry search_entry;
7 private TreeView identities_list;
19 this.title = "Moonshoot";
20 this.position = WindowPosition.CENTER;
21 set_default_size (400, 300);
27 private void search_entry_icon_press_cb ()
29 print ("Search entry icon pressed\n");
32 private void search_entry_text_changed_cb ()
34 var has_text = this.search_entry.get_text_length () > 0;
35 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, has_text);
38 private void setup_identities_list ()
40 var listmodel = new ListStore (Columns.N_COLUMNS, typeof (IdCard),
43 this.identities_list.set_model (listmodel);
45 var column = new TreeViewColumn ();
46 var cell_logo = new CellRendererPixbuf ();
47 column.pack_start (cell_logo, false);
48 column.add_attribute (cell_logo, "pixbuf", Columns.LOGO_COL);
49 cell_logo.set ("stock-size", IconSize.MENU);
51 var cell_name = new CellRendererText ();
52 column.pack_start (cell_name, false);
53 column.add_attribute (cell_name, "text", Columns.NAME_COL);
54 cell_name.set ("ellipsize", Pango.EllipsizeMode.END,
57 this.identities_list.append_column (column);
60 private Dialog add_identity_dialog ()
62 var dialog = new Dialog.with_buttons (_("Add ID Card"),
64 DialogFlags.MODAL | DialogFlags.DESTROY_WITH_PARENT,
65 _("Add ID Card"), ResponseType.OK,
66 Stock.CANCEL, ResponseType.CANCEL);
68 var content_area = dialog.get_content_area ();
69 ((Box) content_area).set_spacing (12);
71 var issuer_label = new Label (_("Issuer:"));
72 issuer_label.set_alignment (1, (float) 0.5);
73 var issuer_entry = new Entry ();
74 var username_label = new Label (_("Username:"));
75 username_label.set_alignment (1, (float) 0.5);
76 var username_entry = new Entry ();
77 var password_label = new Label (_("Password:"));
78 password_label.set_alignment (1, (float) 0.5);
79 var password_entry = new Entry ();
80 password_entry.set_invisible_char ('*');
81 password_entry.set_visibility (false);
82 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
83 var table = new Table (4, 4, false);
84 table.set_col_spacings (10);
85 table.set_row_spacings (10);
86 table.attach_defaults (issuer_label, 0, 1, 0, 1);
87 table.attach_defaults (issuer_entry, 1, 2, 0, 1);
88 table.attach_defaults (username_label, 0, 1, 1, 2);
89 table.attach_defaults (username_entry, 1, 2, 1, 2);
90 table.attach_defaults (password_label, 0, 1, 2, 3);
91 table.attach_defaults (password_entry, 1, 2, 2, 3);
92 table.attach_defaults (remember_checkbutton, 1, 2, 3, 4);
94 var vbox = new VBox (false, 0);
95 vbox.set_border_width (6);
96 vbox.pack_start (table, false, false, 0);
98 ((Container) content_area).add (vbox);
100 dialog.set_border_width (6);
101 dialog.set_resizable (false);
107 private void add_identity ()
111 string services = "";
113 var icon_theme = IconTheme.get_default ();
115 var pixbuf = icon_theme.load_icon ("avatar-default",
117 IconLookupFlags.FORCE_SIZE);
119 var id_card = new IdCard ();
120 id_card.name = "University";
121 id_card.services = new string[3];
122 id_card.services[0] = "Sending emails";
123 id_card.services[1] = "Connect to IRC";
124 id_card.services[2] = "Connect to jabber";
125 id_card.number = 123;
127 for (int i = 0; i < id_card.services.length - 1; i++)
129 services = services + "<i>" + id_card.services[i] + "</i>, ";
131 services = services + "<i>" + id_card.services[id_card.services.length - 1] + "</i>";
132 var text = "<b>" + id_card.name + "</b>\n" + services;
134 listmodel = (ListStore) this.identities_list.get_model ();
135 listmodel.append (out iter);
137 Columns.IDCARD_COL, id_card,
138 Columns.LOGO_COL, pixbuf,
139 Columns.NAME_COL, text);
142 private void add_identity_cb ()
144 var dialog = add_identity_dialog ();
145 var result = dialog.run ();
148 case ResponseType.OK:
157 private IdCard* get_selected_idcard ()
163 var selection = this.identities_list.get_selection ();
165 if (selection.get_selected (out model, out iter))
167 model.get (iter, Columns.IDCARD_COL, out id_card);
174 private void remove_identity (IdCard id_card)
180 var selection = this.identities_list.get_selection ();
182 if (selection.get_selected (out model, out iter))
184 model.get (iter, Columns.IDCARD_COL, out id_card_list);
185 if (id_card_list != null && id_card_list.name == id_card.name)
187 ((ListStore) model).remove (iter);
192 private void remove_identity_cb ()
194 var id_card = get_selected_idcard ();
201 var dialog = new MessageDialog (null,
202 DialogFlags.DESTROY_WITH_PARENT,
204 Gtk.ButtonsType.YES_NO,
205 _("Are you sure you want to delete this ID Card?"));
206 var result = dialog.run ();
208 case ResponseType.YES:
209 remove_identity (id_card);
218 private void label_make_bold (Label label)
220 var font_desc = new Pango.FontDescription ();
222 font_desc.set_weight (Pango.Weight.BOLD);
224 /* This will only affect the weight of the font, the rest is
225 * from the current state of the widget, which comes from the
226 * theme or user prefs, since the font desc only has the
227 * weight flag turned on.
229 label.modify_font (font_desc);
232 private void build_ui()
234 var toolbar = new Toolbar ();
235 var open_button = new ToolButton (null, "Open"); //.from_stock (Stock.OPEN);
236 open_button.is_important = true;
237 toolbar.add (open_button);
238 //open_button.clicked.connect (on_open_clicked);
240 this.search_entry = new Entry();
241 this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY,
242 "edit-find-symbolic");
243 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
244 this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
245 _("Search identity or service"));
246 this.search_entry.icon_press.connect (search_entry_icon_press_cb);
247 this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
249 this.identities_list = new TreeView ();
250 this.identities_list.set_headers_visible (false);
251 setup_identities_list ();
253 var scroll = new ScrolledWindow (null, null);
254 scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
255 scroll.set_shadow_type (ShadowType.IN);
256 scroll.add (this.identities_list);
258 var button_add = new ToolButton (null, null);
259 button_add.set_icon_name ("list-add-symbolic");
260 button_add.clicked.connect (add_identity_cb);
261 var button_remove = new ToolButton (null, null);
262 button_remove.set_icon_name ("list-remove-symbolic");
263 button_remove.clicked.connect (remove_identity_cb);
264 var button_toolbar = new Toolbar ();
265 button_toolbar.insert (button_add, 0);
266 button_toolbar.insert (button_remove, 1);
268 var vbox_left = new VBox (false, 0);
269 vbox_left.pack_start (search_entry, false, false, 6);
270 vbox_left.pack_start (scroll, true, true, 0);
271 vbox_left.pack_start (button_toolbar, false, false, 0);
273 var login_vbox_title = new Label (_("Login: "));
274 label_make_bold (login_vbox_title);
275 login_vbox_title.set_alignment (0, (float) 0.5);
276 var username_label = new Label (_("Username:"));
277 username_label.set_alignment (1, (float) 0.5);
278 var username_entry = new Entry ();
279 var password_label = new Label (_("Password:"));
280 password_label.set_alignment (1, (float) 0.5);
281 var password_entry = new Entry ();
282 password_entry.set_invisible_char ('*');
283 password_entry.set_visibility (false);
284 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
285 var login_table = new Table (3, 3, false);
286 login_table.set_col_spacings (10);
287 login_table.set_row_spacings (10);
288 login_table.attach_defaults (username_label, 0, 1, 0, 1);
289 login_table.attach_defaults (username_entry, 1, 2, 0, 1);
290 login_table.attach_defaults (password_label, 0, 1, 1, 2);
291 login_table.attach_defaults (password_entry, 1, 2, 1, 2);
292 login_table.attach_defaults (remember_checkbutton, 1, 2, 2, 3);
293 var login_vbox_alignment = new Alignment (0, 0, 0, 0);
294 login_vbox_alignment.set_padding (0, 0, 12, 0);
295 login_vbox_alignment.add (login_table);
296 var login_vbox = new VBox (false, 6);
297 login_vbox.pack_start (login_vbox_title, false, true, 0);
298 login_vbox.pack_start (login_vbox_alignment, false, true, 0);
300 var services_vbox_title = new Label (_("Services:"));
301 label_make_bold (services_vbox_title);
302 services_vbox_title.set_alignment (0, (float) 0.5);
303 var email_label = new Label (_("Email"));
304 var email_remove_button = new Button.from_stock (Stock.REMOVE);
305 var im_label = new Label (_("IM"));
306 var im_remove_button = new Button.from_stock (Stock.REMOVE);
307 var services_table = new Table (2, 2, false);
308 services_table.set_col_spacings (10);
309 services_table.set_row_spacings (10);
310 services_table.attach_defaults (email_label, 0, 1, 0, 1);
311 services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
312 services_table.attach_defaults (im_label, 0, 1, 1, 2);
313 services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
314 var services_vbox_alignment = new Alignment (0, 0, 0, 0);
315 services_vbox_alignment.set_padding (0, 0, 12, 0);
316 services_vbox_alignment.add (services_table);
317 var services_vbox = new VBox (false, 6);
318 services_vbox.pack_start (services_vbox_title, false, true, 0);
319 services_vbox.pack_start (services_vbox_alignment, false, true, 0);
321 var vbox_rigth = new VBox (false, 18);
322 vbox_rigth.pack_start (login_vbox, false, true, 0);
323 vbox_rigth.pack_start (services_vbox, false, true, 0);
325 var hbox = new HBox (false, 12);
326 hbox.pack_start (vbox_left, true, true, 0);
327 hbox.pack_start (vbox_rigth, true, true, 0);
329 var send_button = new Button.with_label ("Send");
330 var hbox_send_button = new HBox (false, 0);
331 hbox_send_button.pack_end (send_button, false, false, 0);
333 var main_vbox = new VBox (false, 12);
334 main_vbox.pack_start (toolbar, false, true, 0);
335 main_vbox.pack_start (hbox, true, true, 0);
336 main_vbox.pack_start (hbox_send_button, false, false, 0);
337 main_vbox.set_border_width (12);
341 private void connect_signals()
343 this.destroy.connect (Gtk.main_quit);
346 public static int main(string[] args)
350 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
351 Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
352 Intl.textdomain (Config.GETTEXT_PACKAGE);
354 var window = new MainWindow();