Add movie list menu
[cinaest] / src / movie-list-window.vala
1 /* This file is part of Cinaest.
2  *
3  * Copyright (C) 2009 Philipp Zabel
4  *
5  * Cinaest is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Cinaest is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 using Gtk;
20 using Hildon;
21
22 public class MovieListWindow : StackableWindow {
23         private Hildon.Entry search_field;
24         private Toolbar search_bar;
25
26         construct {
27                 // View menu
28                 var menu = new MovieListMenu ();
29
30                 set_main_menu (menu);
31
32                 // Search bar
33                 search_field = new Hildon.Entry (SizeType.FINGER_HEIGHT);
34
35                 var search_field_item = new ToolItem ();
36                 search_field_item.set_expand (true);
37                 search_field_item.add (search_field);
38
39                 var close_image = new Image.from_file("/usr/share/icons/hicolor/48x48/hildon/general_close.png");
40                 var close_button = new ToolButton (close_image, "Close");
41
42                 search_bar = new Toolbar ();
43                 search_bar.insert (search_field_item, 0);
44                 search_bar.insert (close_button, 1);
45
46                 add_toolbar (search_bar);
47
48                 // Movie list
49                 var movie_list = new MovieListView ();
50
51                 var vbox = new VBox (false, 0);
52                 vbox.pack_start (movie_list, true, true, 0);
53
54                 add (vbox);
55
56                 // Connect signals
57                 close_button.clicked.connect (on_close_button_clicked);
58                 key_press_event.connect (on_key_press_event);
59
60                 search_field.set_flags (WidgetFlags.CAN_DEFAULT);
61                 search_field.grab_default ();
62
63                 show_all ();
64                 search_bar.hide ();
65         }
66
67         private void on_close_button_clicked () {
68                 search_field.set_text ("");
69                 search_bar.hide ();
70         }
71
72         private bool on_key_press_event (Widget widget, Gdk.EventKey event) {
73                 if (event.str != "") {
74                         if (!search_bar.visible) {
75                                 search_bar.show ();
76                         }
77                         search_field.grab_focus ();
78                 }
79
80                 return false;
81         }
82 }
83