Mark some strings as translatable
[moonshot-ui.git] / src / moonshot-window.vala
1 using Gtk;
2
3 class MainWindow : Window
4 {
5
6     private Entry search_entry;
7     private TreeView identities_list;
8
9     private enum Columns
10     {
11         CARDID_COL,
12         NAME_COL,
13         N_COLUMNS
14     }
15
16     public MainWindow()
17     {
18         this.title = "Moonshoot";
19         this.position = WindowPosition.CENTER;
20         set_default_size (400, 300);
21
22         build_ui();
23         connect_signals();
24     }
25
26     private void search_entry_icon_press_cb ()
27     {
28         print ("Search entry icon pressed\n");
29     }
30
31     private void search_entry_text_changed_cb ()
32     {
33         var has_text = this.search_entry.get_text_length () > 0;
34         this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, has_text);
35     }
36
37     private void setup_identities_list ()
38     {
39         var listmodel = new ListStore (Columns.N_COLUMNS, typeof (IdCard),
40                                                           typeof (string));
41         this.identities_list.set_model (listmodel);
42
43         var cell = new CellRendererText ();
44         cell.set ("foreground_set", true);
45
46         this.identities_list.insert_column_with_attributes (-1, "Identities", cell,
47                                                             "text", Columns.NAME_COL);
48     }
49
50     private void add_identity_cb ()
51     {
52         ListStore listmodel;
53         TreeIter iter;
54
55         listmodel = (ListStore) this.identities_list.get_model ();
56
57         listmodel.append (out iter);
58         var id_card = new IdCard ();
59         id_card.name = "University";
60         id_card.number = 123;
61         listmodel.set (iter,
62                        Columns.CARDID_COL, id_card,
63                        Columns.NAME_COL, id_card.name);
64     }
65
66     private IdCard* get_selected_idcard ()
67     {
68         TreeModel model;
69         TreeIter iter;
70         IdCard id_card;
71
72         var selection = this.identities_list.get_selection ();
73
74         if (selection.get_selected (out model, out iter))
75         {
76             model.get (iter, Columns.CARDID_COL, out id_card);
77             return id_card;
78         }
79
80         return null;
81     }
82
83     private void remove_identity (IdCard id_card)
84     {
85         TreeModel model;
86         TreeIter iter;
87         IdCard id_card_list;
88
89         var selection = this.identities_list.get_selection ();
90
91         if (selection.get_selected (out model, out iter))
92         {
93             model.get (iter, Columns.CARDID_COL, out id_card_list);
94             if (id_card_list != null && id_card_list.name == id_card.name)
95             {
96                 ((ListStore) model).remove (iter);
97             }
98         }
99     }
100
101     private void remove_identity_cb ()
102     {
103         var id_card = get_selected_idcard ();
104         if (id_card == null)
105         {
106             return;
107         }
108         else
109         {
110             var dialog = new MessageDialog (null,
111                                             DialogFlags.DESTROY_WITH_PARENT,
112                                             MessageType.INFO,
113                                             Gtk.ButtonsType.YES_NO,
114                                             _("Are you sure you want to delete this ID Card?"));
115             var result = dialog.run ();
116             switch (result) {
117             case ResponseType.YES:
118                 remove_identity (id_card);
119                 break;
120             default:
121                 break;
122             }
123             dialog.destroy ();
124         }
125     }
126
127     private void label_make_bold (Label label)
128     {
129         var font_desc = new Pango.FontDescription ();
130
131         font_desc.set_weight (Pango.Weight.BOLD);
132
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.
137          */
138         label.modify_font (font_desc);
139     }
140
141     private void build_ui()
142     {
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);
148
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);
156
157         this.identities_list = new TreeView ();
158         this.identities_list.set_headers_visible (false);
159         setup_identities_list ();
160
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);
165
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);
175
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);
180
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);
202
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);
222
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);
226
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);
230
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);
234
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);
240         add (main_vbox);
241     }
242
243     private void connect_signals()
244     {
245         this.destroy.connect (Gtk.main_quit);
246     }
247
248     public static int main(string[] args)
249     {
250         Gtk.init(ref args);
251
252         Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
253         Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
254         Intl.textdomain (Config.GETTEXT_PACKAGE);
255
256         var window = new MainWindow();
257         window.show_all();
258
259         Gtk.main();
260
261         return 0;
262     }
263 }