Czech translation update (via transifex.net)
[cinaest] / src / movie-edit-dialog.vala
1 /* This file is part of Cinaest.
2  *
3  * Copyright (C) 2010 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 Hildon;
20 using Gtk;
21
22 class MovieEditDialog : Gtk.Dialog {
23         Movie movie;
24         int rating;
25         Date date;
26         Hildon.Entry title_entry;
27         Hildon.Button rating_button;
28
29         public MovieEditDialog (Gtk.Window window, Movie _movie) {
30                 movie = _movie;
31                 set_transient_for (window);
32                 set_title (movie == null ? _("Add movie") : _("Edit movie"));
33
34                 var content = (VBox) get_content_area ();
35         //      content.set_size_request (-1, 5*70);
36
37                 var size_group = new SizeGroup (SizeGroupMode.HORIZONTAL);
38
39                 var hbox = new HBox (false, MARGIN_DOUBLE);
40                 var label = new Label (_("Title"));
41                 label.set_alignment (0.0f, 0.5f);
42                 size_group.add_widget (label);
43                 title_entry = new Hildon.Entry (SizeType.FINGER_HEIGHT);
44                 title_entry.set_text (movie.title);
45                 hbox.pack_start (label, false, false, 0);
46                 hbox.pack_start (title_entry, true, true, 0);
47                 content.pack_start (hbox, true, true, 0);
48
49                 var button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
50                 button.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
51                 button.add_title_size_group (size_group);
52                 button.set_style (ButtonStyle.PICKER);
53                 button.set_title (_("Original title"));
54                 button.set_value ("%s (%d)".printf (movie.title, movie.year));
55                 content.pack_start (button);
56
57                 rating_button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
58                 rating_button.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
59                 rating_button.add_title_size_group (size_group);
60                 rating_button.set_style (ButtonStyle.PICKER);
61                 rating_button.set_title (_("Rating"));
62                 rating_button.set_value ("6.0");
63                 rating_button.set_value ("%.1f".printf (movie.rating/10.0));
64                 content.pack_start (rating_button);
65 /*
66                 button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
67                 button.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
68                 button.add_title_size_group (size_group);
69                 button.set_style (ButtonStyle.PICKER);
70                 button.set_title (_("Medium"));
71                 button.set_value ("Blu-ray Disc");
72                 content.pack_start (button);
73
74                 button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
75                 button.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
76                 button.add_title_size_group (size_group);
77                 button.set_style (ButtonStyle.PICKER);
78                 button.set_title (_("ASIN"));
79                 button.set_value ("B003CJSTKO");
80                 content.pack_start (button);
81 */
82                 add_button (_("Save"), ResponseType.OK);
83
84                 rating_button.clicked.connect (on_rate_movie);
85                 content.show_all ();
86         }
87
88         private void on_rate_movie (Gtk.Button button) {
89                 var dialog = new Gtk.Dialog ();
90                 dialog.set_title (_("Set rating"));
91
92                 var rating_widget = new RatingWidget ();
93                 var date = new Hildon.DateButton (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL);
94                 date.set_title (_("Rated on"));
95                 date.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
96
97                 var content = (Gtk.VBox) dialog.get_content_area ();
98                 content.pack_start (rating_widget, true, false, 0);
99                 content.pack_start (date, true, false, 0);
100
101                 dialog.add_button (_("Done"), Gtk.ResponseType.OK);
102                 dialog.show_all ();
103                 var res = dialog.run ();
104                 dialog.destroy ();
105                 if (res == Gtk.ResponseType.OK) {
106                         rating = rating_widget.rating;
107                         rating_button.set_value ("%.1f".printf (rating/10.0));
108                 }
109         }
110
111         private void date_button_to_date (DateButton button, out Date date) {
112                 uint year;
113                 uint month;
114                 uint day;
115                 button.get_date (out year, out month, out day);
116                 date.set_dmy ((DateDay) day, (DateMonth) month + DateMonth.JANUARY, (DateYear) year);
117         }
118
119         public new int run () {
120                 int res = base.run ();
121
122                 if (res == ResponseType.OK) {
123                         if (movie.title != title_entry.get_text ())
124                                 movie.title = title_entry.get_text ();
125                         if (movie.rating != rating)
126                                 movie.rating = rating;
127                         if (date.valid () && movie.julian_date != date.get_julian ())
128                                 movie.julian_date = date.get_julian ();
129                 }
130                 destroy ();
131
132                 return res;
133         }
134 }