Use autotools and intltools, translate user interface, add German translation
[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         public enum Response {
21                 HELP = 1,
22                 RESTORE = 2
23         }
24
25         private unowned Osso.Context osso_context;
26         private unowned List<LedPattern> list;
27         private bool close = false;
28
29         public LedPatternDialog (List<LedPattern> _list, Osso.Context osso) {
30                 list = _list;
31                 osso_context = osso;
32                 set_title (_("LED Patterns"));
33
34                 var content = (Gtk.VBox) get_content_area ();
35                 content.set_size_request (-1, 5*70);
36
37                 var pannable = new Hildon.PannableArea ();
38                 var vbox = new Gtk.VBox (false, 0);
39
40                 foreach (LedPattern pattern in list) {
41                         var button = new LedPatternButton (pattern);
42                         Hildon.gtk_widget_set_theme_size (button, Hildon.SizeType.FINGER_HEIGHT);
43                         button.set_data ("pattern", pattern);
44                         button.clicked.connect (on_pattern_clicked);
45                         vbox.pack_start (button, true, true, 0);
46                 }
47
48                 pannable.add_with_viewport (vbox);
49                 content.pack_start (pannable, true, true, 0);
50                 content.show_all ();
51
52                 var button_help = new Gtk.Button.with_label ("Help");
53                 Hildon.gtk_widget_set_theme_size (button_help, Hildon.SizeType.FINGER_HEIGHT);
54
55                 var label = new Gtk.Label (_("Restore original\npatterns"));
56                 label.justify = Gtk.Justification.CENTER;
57                 var button_restore = new Gtk.Button ();
58                 button_restore.add (label);
59                 Hildon.helper_set_logical_font (button_restore, "SmallSystemFont");
60                 Hildon.gtk_widget_set_theme_size (button_restore, Hildon.SizeType.FINGER_HEIGHT);
61
62                 add_action_widget (button_help, Response.HELP);
63                 add_action_widget (button_restore, Response.RESTORE);
64
65                 var action_area = (Gtk.ButtonBox) get_action_area ();
66                 action_area.set_child_secondary (button_help, true);
67                 action_area.show_all ();
68
69                 add_button (_("Save"), Gtk.ResponseType.OK);
70
71                 response.connect (on_response);
72         }
73
74         public int run () {
75                 int response = 0;
76                 while (response >= 0) {
77                         response = base.run ();
78                         if (close)
79                                 return response;
80                 }
81                 return response;
82         }
83
84         private void on_pattern_clicked (Gtk.Button button) {
85                 LedPattern pattern = button.get_data ("pattern");
86                 if (pattern is LedPatternRX51) {
87                         var dialog = new LedProgramDialog ((LedPatternRX51) pattern);
88                         dialog.set_transient_for (this);
89
90                         int response = 0;
91                         while (response >= 0)
92                                 response = dialog.run ();
93                         dialog.destroy ();
94                 }
95         }
96
97         private void on_response (int response_id) {
98                 if (response_id == Response.HELP) {
99                         var url = "http://wiki.maemo.org/LED_Pattern_Editor";
100                         var status = osso_context.rpc_run_with_defaults ("osso_browser", "open_new_window", null, 's', url, 'b', false);
101                         if (status != Osso.Status.OK)
102                                 Hildon.Banner.show_information (this, null, _("Failed to open browser."));
103                 } else if (response_id == Response.RESTORE) {
104                         var note = new Hildon.Note.confirmation (this, _("Restore original patterns? All user-created patterns will be lost."));
105                         response_id = note.run ();
106                         note.destroy ();
107                         if (response_id == Gtk.ResponseType.OK)
108                                 close = true;
109                 }
110         }
111 }