3 class MainWindow : Window
6 private Entry search_entry;
7 private TreeView identities_list;
18 this.title = "Moonshoot";
19 this.position = WindowPosition.CENTER;
20 set_default_size (400, 300);
26 private void search_entry_icon_press_cb ()
28 print ("Search entry icon pressed\n");
31 private void search_entry_text_changed_cb ()
33 var has_text = this.search_entry.get_text_length () > 0;
34 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, has_text);
37 private void setup_identities_list ()
39 var listmodel = new ListStore (Columns.N_COLUMNS, typeof (IdCard),
41 this.identities_list.set_model (listmodel);
43 var cell = new CellRendererText ();
44 cell.set ("foreground_set", true);
46 this.identities_list.insert_column_with_attributes (-1, "Identities", cell,
47 "text", Columns.NAME_COL);
50 private void add_identity_cb ()
55 listmodel = (ListStore) this.identities_list.get_model ();
57 listmodel.append (out iter);
58 var id_card = new IdCard ();
59 id_card.name = "University";
62 Columns.CARDID_COL, id_card,
63 Columns.NAME_COL, id_card.name);
66 private IdCard* get_selected_idcard ()
72 var selection = this.identities_list.get_selection ();
74 if (selection.get_selected (out model, out iter))
76 model.get (iter, Columns.CARDID_COL, out id_card);
83 private void remove_identity (IdCard id_card)
89 var selection = this.identities_list.get_selection ();
91 if (selection.get_selected (out model, out iter))
93 model.get (iter, Columns.CARDID_COL, out id_card_list);
94 if (id_card_list != null && id_card_list.name == id_card.name)
96 ((ListStore) model).remove (iter);
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 var toolbar = new Toolbar ();
144 var open_button = new ToolButton (null, "Open"); //.from_stock (Stock.OPEN);
145 open_button.is_important = true;
146 toolbar.add (open_button);
147 //open_button.clicked.connect (on_open_clicked);
149 this.search_entry = new Entry();
150 this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY, "system-search");
151 this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
152 this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
153 _("Search identity or service"));
154 this.search_entry.icon_press.connect (search_entry_icon_press_cb);
155 this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
157 this.identities_list = new TreeView ();
158 this.identities_list.set_headers_visible (false);
159 setup_identities_list ();
161 var scroll = new ScrolledWindow (null, null);
162 scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
163 scroll.set_shadow_type (ShadowType.IN);
164 scroll.add (this.identities_list);
166 var button_add = new ToolButton (null, null);
167 button_add.set_icon_name ("gtk-add");
168 button_add.clicked.connect (add_identity_cb);
169 var button_remove = new ToolButton (null, null);
170 button_remove.set_icon_name ("gtk-remove");
171 button_remove.clicked.connect (remove_identity_cb);
172 var button_toolbar = new Toolbar ();
173 button_toolbar.insert (button_add, 0);
174 button_toolbar.insert (button_remove, 1);
176 var vbox_left = new VBox (false, 0);
177 vbox_left.pack_start (search_entry, false, false, 6);
178 vbox_left.pack_start (scroll, true, true, 0);
179 vbox_left.pack_start (button_toolbar, false, false, 0);
181 var login_vbox_title = new Label (_("Login: "));
182 label_make_bold (login_vbox_title);
183 login_vbox_title.set_alignment (0, 0);
184 var username_label = new Label (_("Username:"));
185 var username_entry = new Entry ();
186 var password_label = new Label (_("Password:"));
187 var password_entry = new Entry ();
188 var remember_checkbutton = new CheckButton.with_label (_("Remember password"));
189 var login_table = new Table (3, 3, false);
190 login_table.set_col_spacings (6);
191 login_table.attach_defaults (username_label, 0, 1, 0, 1);
192 login_table.attach_defaults (username_entry, 1, 2, 0, 1);
193 login_table.attach_defaults (password_label, 0, 1, 1, 2);
194 login_table.attach_defaults (password_entry, 1, 2, 1, 2);
195 login_table.attach_defaults (remember_checkbutton, 0, 2, 2, 3);
196 var login_vbox_alignment = new Alignment (0, 0, 0, 0);
197 login_vbox_alignment.set_padding (0, 0, 12, 0);
198 login_vbox_alignment.add (login_table);
199 var login_vbox = new VBox (false, 6);
200 login_vbox.pack_start (login_vbox_title, false, true, 0);
201 login_vbox.pack_start (login_vbox_alignment, false, true, 0);
203 var services_vbox_title = new Label (_("Services:"));
204 label_make_bold (services_vbox_title);
205 services_vbox_title.set_alignment (0, 0);
206 var email_label = new Label (_("Email"));
207 var email_remove_button = new Button.from_stock (Stock.REMOVE);
208 var im_label = new Label (_("IM"));
209 var im_remove_button = new Button.from_stock (Stock.REMOVE);
210 var services_table = new Table (2, 2, false);
211 services_table.set_col_spacings (6);
212 services_table.attach_defaults (email_label, 0, 1, 0, 1);
213 services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
214 services_table.attach_defaults (im_label, 0, 1, 1, 2);
215 services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
216 var services_vbox_alignment = new Alignment (0, 0, 0, 0);
217 services_vbox_alignment.set_padding (0, 0, 12, 0);
218 services_vbox_alignment.add (services_table);
219 var services_vbox = new VBox (false, 6);
220 services_vbox.pack_start (services_vbox_title, false, true, 0);
221 services_vbox.pack_start (services_vbox_alignment, false, true, 0);
223 var vbox_rigth = new VBox (false, 18);
224 vbox_rigth.pack_start (login_vbox, false, true, 0);
225 vbox_rigth.pack_start (services_vbox, false, true, 0);
227 var hbox = new HBox (false, 12);
228 hbox.pack_start (vbox_left, true, true, 0);
229 hbox.pack_start (vbox_rigth, true, true, 0);
231 var send_button = new Button.with_label ("Send");
232 var hbox_send_button = new HBox (false, 0);
233 hbox_send_button.pack_end (send_button, false, false, 0);
235 var main_vbox = new VBox (false, 12);
236 main_vbox.pack_start (toolbar, false, true, 0);
237 main_vbox.pack_start (hbox, true, true, 0);
238 main_vbox.pack_start (hbox_send_button, false, false, 0);
239 main_vbox.set_border_width (12);
243 private void connect_signals()
245 this.destroy.connect (Gtk.main_quit);
248 public static int main(string[] args)
252 Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
253 Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
254 Intl.textdomain (Config.GETTEXT_PACKAGE);
256 var window = new MainWindow();