/* 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 . */ 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; } }