Add source selection dialog
authorPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 30 Oct 2009 18:52:10 +0000 (19:52 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Tue, 10 Nov 2009 11:21:15 +0000 (12:21 +0100)
Allows to select the movie source to be displayed in the movie list window.

Makefile.am
po/POTFILES.in
src/movie-list-menu.vala
src/source-dialog.vala [new file with mode: 0644]

index 6991d4b..a0ed6bc 100644 (file)
@@ -33,7 +33,8 @@ cinaest_SOURCES = \
         src/movie-list-view.c \
         src/movie-list-window.c \
         src/plugin-interface.c \
-        src/plugin-registrar.c
+       src/plugin-registrar.c \
+       src/source-dialog.c
 
 cinaest_VALASOURCES = \
         src/main.vala \
@@ -45,7 +46,8 @@ cinaest_VALASOURCES = \
         src/movie-list-view.vala \
         src/movie-list-window.vala \
         src/plugin-interface.vala \
-        src/plugin-registrar.vala
+       src/plugin-registrar.vala \
+       src/source-dialog.vala
 
 ${cinaest_SOURCES}: ${cinaest_VALASOURCES}
        ${VALAC} -C ${cinaest_VALASOURCES} ${cinaest_VALAFLAGS}
index afab376..23d3a0a 100644 (file)
@@ -1,3 +1,4 @@
 src/main.vala
 src/movie-list-menu.vala
 src/movie-list-window.vala
+src/source-dialog.vala
index 5c91f7c..5a79ada 100644 (file)
@@ -59,6 +59,27 @@ public class MovieListMenu : AppMenu {
                add_filter (sort_by_year);
                add_filter (sort_by_rating);
 
+               // Add view menu buttons
+               var select_source = new Hildon.Button.with_text (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL, _("Source"), _("None"));
+
+               select_source.set_style (ButtonStyle.PICKER);
+
+               // Connect signals
+               select_source.clicked.connect (on_select_source_clicked);
+
+               append (select_source);
+
                show_all ();
        }
+
+       public void on_select_source_clicked (Gtk.Button button) {
+               Hildon.Button select_source = (Hildon.Button) button;
+               var dialog = new SourceDialog (movie_list_window);
+
+               var source = movie_list_window.source;
+               dialog.run (ref source);
+               movie_list_window.source = source;
+
+               select_source.value = source.get_name ();
+       }
 }
diff --git a/src/source-dialog.vala b/src/source-dialog.vala
new file mode 100644 (file)
index 0000000..368057b
--- /dev/null
@@ -0,0 +1,82 @@
+/* This file is part of Cinaest.
+ *
+ * Copyright (C) 2009 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 SourceDialog : Gtk.Dialog {
+       List<MovieSource> sources;
+       List<Gtk.Button> buttons;
+
+       public SourceDialog (Gtk.Window window) {
+               set_transient_for (window);
+               set_title (_("Select movie source"));
+
+               VBox vbox;
+               if (CinaestProgram.plugins.length () > 5) {
+                       vbox = new VBox (true, 0);
+
+                       var pannable = new PannableArea ();
+                       pannable.add_with_viewport (vbox);
+
+                       VBox area = (VBox) get_content_area ();
+                       area.pack_start (pannable, true, true, 0);
+                       area.set_size_request (-1, 5*70);
+               } else {
+                       vbox = (VBox) get_content_area ();
+               }
+
+               sources = new List<MovieSource> ();
+               buttons = new List<Hildon.Button> ();
+               foreach (Plugin plugin in CinaestProgram.plugins) {
+                       foreach (MovieSource source in plugin.get_sources ()) {
+                               var button = new Hildon.Button.with_text (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL, source.get_name (), source.get_description ());
+                               button.set_alignment(0, (float) 0.5, 0, 0);
+                               vbox.pack_start (button, true, true, 0);
+
+                               button.clicked.connect (on_source_select);
+
+                               buttons.append (button);
+                               sources.append (source);
+                       }
+               }
+       }
+
+       public void on_source_select (Gtk.Button button) {
+               int n = buttons.index (button);
+
+               response (n);
+       }
+
+       public new int run (ref MovieSource source) {
+               int res = 0;
+
+               show_all ();
+
+               res = base.run ();
+               destroy ();
+
+               if (res >= 0) {
+                       source = sources.nth_data (res);
+                       return 0;
+               }
+
+               return res;
+       }
+}
+