Add movie edit dialog
authorPhilipp Zabel <philipp.zabel@gmail.com>
Tue, 13 Jul 2010 16:17:34 +0000 (18:17 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 5 Aug 2010 19:04:59 +0000 (21:04 +0200)
Makefile.am
src/movie-edit-dialog.vala [new file with mode: 0644]
src/movie-menu.vala

index c8ee810..1c6e11c 100644 (file)
@@ -49,6 +49,7 @@ pkgconfig_DATA = cinaest.pc
 cinaest_SOURCES = \
         src/main.c \
        src/genre-filter-dialog.c \
 cinaest_SOURCES = \
         src/main.c \
        src/genre-filter-dialog.c \
+       src/movie-edit-dialog.c \
         src/movie-list-menu.c \
         src/movie-list-store.c \
         src/movie-list-view.c \
         src/movie-list-menu.c \
         src/movie-list-store.c \
         src/movie-list-view.c \
@@ -66,6 +67,7 @@ cinaest_SOURCES = \
 cinaest_VALASOURCES = \
         src/main.vala \
        src/genre-filter-dialog.vala \
 cinaest_VALASOURCES = \
         src/main.vala \
        src/genre-filter-dialog.vala \
+       src/movie-edit-dialog.vala \
         src/movie-list-menu.vala \
         src/movie-list-store.vala \
         src/movie-list-view.vala \
         src/movie-list-menu.vala \
         src/movie-list-store.vala \
         src/movie-list-view.vala \
diff --git a/src/movie-edit-dialog.vala b/src/movie-edit-dialog.vala
new file mode 100644 (file)
index 0000000..141a590
--- /dev/null
@@ -0,0 +1,134 @@
+/* This file is part of Cinaest.
+ *
+ * Copyright (C) 2010 Philipp Zabel
+ *
+ * Cinaest is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cinaest is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Hildon;
+using Gtk;
+
+class MovieEditDialog : Gtk.Dialog {
+       Movie movie;
+       int rating;
+       Date date;
+       Hildon.Entry title_entry;
+       Hildon.Button rating_button;
+
+       public MovieEditDialog (Gtk.Window window, Movie _movie) {
+               movie = _movie;
+               set_transient_for (window);
+               set_title (movie == null ? _("Add movie") : _("Edit movie"));
+
+               var content = (VBox) get_content_area ();
+       //      content.set_size_request (-1, 5*70);
+
+               var size_group = new SizeGroup (SizeGroupMode.HORIZONTAL);
+
+               var hbox = new HBox (false, MARGIN_DOUBLE);
+               var label = new Label (_("Title"));
+               label.set_alignment (0.0f, 0.5f);
+               size_group.add_widget (label);
+               title_entry = new Hildon.Entry (SizeType.FINGER_HEIGHT);
+               title_entry.set_text (movie.title);
+               hbox.pack_start (label, false, false, 0);
+               hbox.pack_start (title_entry, true, true, 0);
+               content.pack_start (hbox, true, true, 0);
+
+               var button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
+               button.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
+               button.add_title_size_group (size_group);
+               button.set_style (ButtonStyle.PICKER);
+               button.set_title (_("Original title"));
+               button.set_value ("%s (%d)".printf (movie.title, movie.year));
+               content.pack_start (button);
+
+               rating_button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
+               rating_button.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
+               rating_button.add_title_size_group (size_group);
+               rating_button.set_style (ButtonStyle.PICKER);
+               rating_button.set_title (_("Rating"));
+               rating_button.set_value ("6.0");
+               rating_button.set_value ("%.1f".printf (movie.rating/10.0));
+               content.pack_start (rating_button);
+/*
+               button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
+               button.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
+               button.add_title_size_group (size_group);
+               button.set_style (ButtonStyle.PICKER);
+               button.set_title (_("Medium"));
+               button.set_value ("Blu-ray Disc");
+               content.pack_start (button);
+
+               button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
+               button.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
+               button.add_title_size_group (size_group);
+               button.set_style (ButtonStyle.PICKER);
+               button.set_title (_("ASIN"));
+               button.set_value ("B003CJSTKO");
+               content.pack_start (button);
+*/
+               add_button (_("Save"), ResponseType.OK);
+
+               rating_button.clicked.connect (on_rate_movie);
+               content.show_all ();
+       }
+
+       private void on_rate_movie (Gtk.Button button) {
+               var dialog = new Gtk.Dialog ();
+               dialog.set_title (_("Set rating"));
+
+               var rating_widget = new RatingWidget ();
+               var date = new Hildon.DateButton (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL);
+               date.set_title (_("Rated on"));
+               date.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
+
+               var content = (Gtk.VBox) dialog.get_content_area ();
+               content.pack_start (rating_widget, true, false, 0);
+               content.pack_start (date, true, false, 0);
+
+               dialog.add_button (_("Done"), Gtk.ResponseType.OK);
+               dialog.show_all ();
+               var res = dialog.run ();
+               dialog.destroy ();
+               if (res == Gtk.ResponseType.OK) {
+                       rating = rating_widget.rating;
+                       rating_button.set_value ("%.1f".printf (rating/10.0));
+               }
+       }
+
+       private void date_button_to_date (DateButton button, out Date date) {
+               uint year;
+               uint month;
+               uint day;
+               button.get_date (out year, out month, out day);
+               date.set_dmy ((DateDay) day, (DateMonth) month + DateMonth.JANUARY, (DateYear) year);
+       }
+
+       public new int run () {
+               int res = base.run ();
+
+               if (res == ResponseType.OK) {
+                       if (movie.title != title_entry.get_text ())
+                               movie.title = title_entry.get_text ();
+                       if (movie.rating != rating)
+                               movie.rating = rating;
+                       if (date.valid () && movie.julian_date != date.get_julian ())
+                               movie.julian_date = date.get_julian ();
+               }
+               destroy ();
+
+               return res;
+       }
+}
index a6f6a40..8891626 100644 (file)
@@ -50,7 +50,10 @@ public class MovieMenu : AppMenu {
                        append (button);
                }
                if (store.get_editable ()) {
                        append (button);
                }
                if (store.get_editable ()) {
-                       var button = new Gtk.Button.with_label (_("Delete movie"));
+                       var button = new Gtk.Button.with_label (_("Edit movie"));
+                       button.clicked.connect (on_edit_movie);
+                       append (button);
+                       button = new Gtk.Button.with_label (_("Delete movie"));
                        button.clicked.connect (on_delete_movie);
                        append (button);
                }
                        button.clicked.connect (on_delete_movie);
                        append (button);
                }
@@ -108,5 +111,10 @@ public class MovieMenu : AppMenu {
                        movie_deleted ();
                }
        }
                        movie_deleted ();
                }
        }
+
+       private void on_edit_movie () {
+               var dialog = new MovieEditDialog (parent_window, movie);
+               var res = dialog.run ();
+       }
 }
 
 }