15995afb665c222a90cbb6552ecfadf5515bd407
[led-pattern-ed] / src / led-pattern-dialog.vala
1 /* This file is part of LED Pattern Editor.
2  *
3  * Copyright (C) 2010 Philipp Zabel
4  *
5  * LED Pattern Editor 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  * LED Pattern Editor 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 LED Pattern Editor. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 class LedPatternDialog : Gtk.Dialog {
20         unowned List<LedPatternRX51> list;
21
22         public LedPatternDialog (List<LedPatternRX51> _list) {
23                 list = _list;
24                 set_title ("LED Patterns");
25
26                 var content = (Gtk.VBox) get_content_area ();
27                 content.set_size_request (-1, 5*70);
28
29                 var pannable = new Hildon.PannableArea ();
30                 var vbox = new Gtk.VBox (false, 0);
31
32                 foreach (LedPatternRX51 pattern in list) {
33                         var button = new Gtk.Button ();
34                         Hildon.gtk_widget_set_theme_size (button, Hildon.SizeType.FINGER_HEIGHT);
35
36                         var hbox = new Gtk.HBox (false, Hildon.MARGIN_DOUBLE);
37
38                         var lpv = new LedPatternView (pattern);
39                         lpv.set_size_request (200, -1);
40                         button.set_data ("pattern", pattern);
41                         button.clicked.connect (on_pattern_clicked);
42                         hbox.pack_start (lpv, false, false, 0);
43
44                         var label = new Gtk.Label (pattern.name.has_prefix ("Pattern") ?
45                                                    pattern.name.offset (7) : pattern.name);
46                         label.set_alignment (0.0f, 0.5f);
47                         hbox.pack_start (label, true, true, 0);
48
49                         button.add (hbox);
50                         vbox.pack_start (button, true, true, 0);
51                 }
52
53                 pannable.add_with_viewport (vbox);
54                 content.pack_start (pannable, true, true, 0);
55                 content.show_all ();
56
57                 add_button ("Save", Gtk.ResponseType.OK);
58         }
59
60         void on_pattern_clicked (Gtk.Button button) {
61                 LedPatternRX51 pattern = button.get_data ("pattern");
62                 var dialog = new LedProgramDialog (pattern);
63                 dialog.set_transient_for (this);
64
65                 int response = 0;
66                 while (response >= 0)
67                         response = dialog.run ();
68                 dialog.destroy ();
69         }
70 }