cad6ba3ca26eb00eb6b45a471e05089e752db27b
[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 void remove_identity_cb ()
67     {
68         TreeModel model;
69         TreeIter iter;
70
71         var selection = identities_list.get_selection ();
72
73         if (selection.get_selected (out model, out iter))
74         {
75             ((ListStore) model).remove (iter);
76         }
77     }
78
79     private void label_make_bold (Label label)
80     {
81         var font_desc = new Pango.FontDescription ();
82
83         font_desc.set_weight (Pango.Weight.BOLD);
84
85         /* This will only affect the weight of the font, the rest is
86          * from the current state of the widget, which comes from the
87          * theme or user prefs, since the font desc only has the
88          * weight flag turned on.
89          */
90         label.modify_font (font_desc);
91     }
92
93     private void build_ui()
94     {
95         var toolbar = new Toolbar ();
96         var open_button = new ToolButton (null, "Open"); //.from_stock (Stock.OPEN);
97         open_button.is_important = true;
98         toolbar.add (open_button);
99         //open_button.clicked.connect (on_open_clicked);
100
101         this.search_entry = new Entry();
102         this.search_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY, "system-search");
103         this.search_entry.set_icon_sensitive (EntryIconPosition.SECONDARY, false);
104         this.search_entry.set_icon_tooltip_text (EntryIconPosition.SECONDARY,
105                                                  "Search identity or service");
106         this.search_entry.icon_press.connect (search_entry_icon_press_cb);
107         this.search_entry.notify["text"].connect (search_entry_text_changed_cb);
108
109         this.identities_list = new TreeView ();
110         this.identities_list.set_headers_visible (false);
111         setup_identities_list ();
112
113         var scroll = new ScrolledWindow (null, null);
114         scroll.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
115         scroll.set_shadow_type (ShadowType.IN);
116         scroll.add (this.identities_list);
117
118         var button_add = new ToolButton (null, null);
119         button_add.set_icon_name ("gtk-add");
120         button_add.clicked.connect (add_identity_cb);
121         var button_remove = new ToolButton (null, null);
122         button_remove.set_icon_name ("gtk-remove");
123         button_remove.clicked.connect (remove_identity_cb);
124         var button_toolbar = new Toolbar ();
125         button_toolbar.insert (button_add, 0);
126         button_toolbar.insert (button_remove, 1);
127
128         var vbox_left = new VBox (false, 0);
129         vbox_left.pack_start (search_entry, false, false, 6);
130         vbox_left.pack_start (scroll, true, true, 0);
131         vbox_left.pack_start (button_toolbar, false, false, 0);
132
133         var login_vbox_title = new Label ("Login: ");
134         label_make_bold (login_vbox_title);
135         login_vbox_title.set_alignment (0, 0);
136         var username_label = new Label ("Username:");
137         var username_entry = new Entry ();
138         var password_label = new Label ("Password:");
139         var password_entry = new Entry ();
140         var remember_checkbutton = new CheckButton.with_label ("Remember password");
141         var login_table = new Table (3, 3, false);
142         login_table.set_col_spacings (6);
143         login_table.attach_defaults (username_label, 0, 1, 0, 1);
144         login_table.attach_defaults (username_entry, 1, 2, 0, 1);
145         login_table.attach_defaults (password_label, 0, 1, 1, 2);
146         login_table.attach_defaults (password_entry, 1, 2, 1, 2);
147         login_table.attach_defaults (remember_checkbutton,  0, 2, 2, 3);
148         var login_vbox_alignment = new Alignment (0, 0, 0, 0);
149         login_vbox_alignment.set_padding (0, 0, 12, 0);
150         login_vbox_alignment.add (login_table);
151         var login_vbox = new VBox (false, 6);
152         login_vbox.pack_start (login_vbox_title, false, true, 0);
153         login_vbox.pack_start (login_vbox_alignment, false, true, 0);
154
155         var services_vbox_title = new Label ("Services:");
156         label_make_bold (services_vbox_title);
157         services_vbox_title.set_alignment (0, 0);
158         var email_label = new Label ("Email");
159         var email_remove_button = new Button.from_stock (Stock.REMOVE);
160         var im_label = new Label ("IM");
161         var im_remove_button = new Button.from_stock (Stock.REMOVE);
162         var services_table = new Table (2, 2, false);
163         services_table.set_col_spacings (6);
164         services_table.attach_defaults (email_label, 0, 1, 0, 1);
165         services_table.attach_defaults (email_remove_button, 1, 2, 0, 1);
166         services_table.attach_defaults (im_label, 0, 1, 1, 2);
167         services_table.attach_defaults (im_remove_button, 1, 2, 1, 2);
168         var services_vbox_alignment = new Alignment (0, 0, 0, 0);
169         services_vbox_alignment.set_padding (0, 0, 12, 0);
170         services_vbox_alignment.add (services_table);
171         var services_vbox = new VBox (false, 6);
172         services_vbox.pack_start (services_vbox_title, false, true, 0);
173         services_vbox.pack_start (services_vbox_alignment, false, true, 0);
174
175         var vbox_rigth = new VBox (false, 18);
176         vbox_rigth.pack_start (login_vbox, false, true, 0);
177         vbox_rigth.pack_start (services_vbox, false, true, 0);
178
179         var hbox = new HBox (false, 12);
180         hbox.pack_start (vbox_left, true, true, 0);
181         hbox.pack_start (vbox_rigth, true, true, 0);
182
183         var send_button = new Button.with_label ("Send");
184         var hbox_send_button = new HBox (false, 0);
185         hbox_send_button.pack_end (send_button, false, false, 0);
186
187         var main_vbox = new VBox (false, 12);
188         main_vbox.pack_start (toolbar, false, true, 0);
189         main_vbox.pack_start (hbox, true, true, 0);
190         main_vbox.pack_start (hbox_send_button, false, false, 0);
191         main_vbox.set_border_width (12);
192         add (main_vbox);
193     }
194
195     private void connect_signals()
196     {
197         this.destroy.connect (Gtk.main_quit);
198     }
199
200     public static int main(string[] args)
201     {
202         Gtk.init(ref args);
203
204         Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
205         Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
206         Intl.textdomain (Config.GETTEXT_PACKAGE);
207
208         var window = new MainWindow();
209         window.show_all();
210
211         Gtk.main();
212
213         return 0;
214     }
215 }