[cheese] Make CheeseMainWindow a template widget



commit db7b638aa5c462441962078477b647458b476508
Author: David King <amigadave amigadave com>
Date:   Mon Nov 11 23:57:13 2013 +0000

    Make CheeseMainWindow a template widget

 Makefile.am                |    3 +-
 data/cheese-main-window.ui |   44 ++++++++++++---
 data/cheese.gresource.xml  |    1 +
 src/cheese-window.vala     |  133 +++++++++++++++++++-------------------------
 4 files changed, 95 insertions(+), 86 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 882308b..b0d5804 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -198,6 +198,7 @@ endif
 noinst_resource_files = \
        data/cheese.css \
        data/cheese-viewport.json \
+       data/cheese-main-window.ui \
        data/cheese-prefs.ui
 
 src/cheese-resource.c src/cheese-resource.h: data/cheese.gresource.xml Makefile $(noinst_resource_files)
@@ -312,8 +313,6 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 gsettings_SCHEMAS = data/org.gnome.Cheese.gschema.xml
 @GSETTINGS_RULES@
 
-dist_pkgdata_DATA = \
-       data/cheese-main-window.ui
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = \
diff --git a/data/cheese-main-window.ui b/data/cheese-main-window.ui
index a7edcab..54800cd 100644
--- a/data/cheese-main-window.ui
+++ b/data/cheese-main-window.ui
@@ -1,45 +1,56 @@
 <?xml version="1.0"?>
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <object class ="GtkHeaderBar" id="header-bar">
+    <template class="CheeseMainWindow" parent="GtkApplicationWindow">
+        <child type="titlebar">
+  <object class="GtkHeaderBar" id="header_bar">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
-    <property name="title" translatable="yes">Take a photo</property>
+    <property name="title" translatable="yes">Take a Photo</property>
     <property name="show-close-button">True</property>
     <style>
       <class name="titlebar"/>
     </style>
   </object>
-  <object class="GtkBox" id="mainbox_normal">
+        </child>
+        <child>
+  <object class="GtkBox" id="main_vbox">
     <property name="orientation">vertical</property>
     <property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+    <property name="visible">True</property>
     <child>
       <object class="GtkBox" id="content_area">
         <property name="vexpand">True</property>
         <property name="hexpand">True</property>
         <property name="orientation">horizontal</property>
+        <property name="visible">True</property>
         <child>
           <object class="GtkBox" id="view_area">
             <property name="orientation">vertical</property>
+            <property name="visible">True</property>
             <child>
-              <object class="GtkClutterEmbed" id="viewport">
+              <object class="GtkClutterEmbed" id="viewport_widget">
                 <property name="vexpand">True</property>
                 <property name="hexpand">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK</property>
                 <property name="height_request">450</property>
                 <property name="width_request">600</property>
+                <property name="visible">True</property>
               </object>
             </child>
             <child>
               <object class="GtkAlignment" id="action_area_alignment">
                 <property name="hexpand">True</property>
+                <property name="visible">True</property>
                 <child>
                   <object class="GtkBox" id="buttons_area">
                     <property name="border-width">6</property>
                     <property name="orientation">horizontal</property>
+                    <property name="visible">True</property>
                     <child>
                       <object class="GtkBox" id="mode_toggle_buttons">
                         <property name="orientation">horizontal</property>
+                        <property name="visible">True</property>
                         <style>
                           <class name="linked"/>
                         </style>
@@ -48,7 +59,8 @@
                             <property name="action-name">app.mode</property>
                             <property name="action-target">"photo"</property>
                             <property name="tooltip_text" translatable="yes">Photo mode</property>
-                           <property name="label" translatable="yes">Photo</property>
+                            <property name="label" translatable="yes">Photo</property>
+                            <property name="visible">True</property>
                           </object>
                         </child>
                         <child>
@@ -57,6 +69,7 @@
                             <property name="action-target">"video"</property>
                             <property name="tooltip_text" translatable="yes">Video mode</property>
                             <property name="label" translatable="yes">Video</property>
+                            <property name="visible">True</property>
                           </object>
                         </child>
                         <child>
@@ -65,6 +78,7 @@
                             <property name="action-target">"burst"</property>
                             <property name="tooltip_text" translatable="yes">Photo burst mode</property>
                             <property name="label" translatable="yes">Burst</property>
+                            <property name="visible">True</property>
                           </object>
                         </child>
                       </object>
@@ -77,13 +91,16 @@
                         <property name="yscale">0</property>
                         <property name="hexpand">True</property>
                         <property name="vexpand">False</property>
+                        <property name="visible">True</property>
                         <child>
                           <object class="GtkButton" id="take_action_button">
                             <property name="action-name">app.shoot</property>
                             <property name="tooltip_text" translatable="yes">Take a photo using a 
webcam</property>
+                            <property name="visible">True</property>
                             <child>
-                              <object class="GtkImage" id="take_action_button_internal_image">
-                                <property name="icon_name">camera-web-symbolic</property>
+                              <object class="GtkImage" id="take_action_button_image">
+                                <property name="icon-name">camera-web-symbolic</property>
+                                <property name="visible">True</property>
                               </object>
                             </child>
                           </object>
@@ -93,6 +110,7 @@
                     <child>
                       <object class="GtkBox" id="effects_actions_pack">
                         <property name="orientation">horizontal</property>
+                        <property name="visible">True</property>
                         <style>
                           <class name="linked"/>
                         </style>
@@ -100,9 +118,11 @@
                           <object class="GtkButton" id="effects_prev_page_button">
                             <property name="action-name">win.effects-previous</property>
                             <property name="tooltip_text" translatable="yes">Navigate to the previous page 
of effects</property>
+                            <property name="visible">True</property>
                             <child>
                               <object class="GtkImage" id="effects_prev_page_button_image">
                                 <property name="icon_name">go-previous-symbolic</property>
+                                <property name="visible">True</property>
                               </object>
                             </child>
                           </object>
@@ -113,6 +133,7 @@
                             <property name="hexpand">False</property>
                             <property name="action-name">app.effects</property>
                             <property name="tooltip_text" translatable="yes">Effects</property>
+                            <property name="visible">True</property>
                             <child>
                               <object class="GtkBox" id="effects_toggle_button_internal_hbox">
                                 <property name="orientation">horizontal</property>
@@ -122,6 +143,7 @@
                                   <object class="GtkLabel" id="effects_toggle_button_internal_label">
                                     <property name="label" translatable="yes">_Effects</property>
                                     <property name="use_underline">True</property>
+                                    <property name="visible">True</property>
                                   </object>
                                 </child>
                               </object>
@@ -133,9 +155,11 @@
                             <property name="use-action-appearance">False</property>
                             <property name="action-name">win.effects-next</property>
                             <property name="tooltip_text" translatable="yes">Navigate to the next page of 
effects</property>
+                            <property name="visible">True</property>
                             <child>
                               <object class="GtkImage" id="effects_prev_next_button_image">
-                                <property name="icon_name">go-next-symbolic</property>
+                                <property name="icon-name">go-next-symbolic</property>
+                                <property name="visible">True</property>
                               </object>
                             </child>
                           </object>
@@ -143,7 +167,7 @@
                       </object>
                     </child>
                     <child>
-                      <object class="GtkBox" id="leave_fullscreen_button_bin">
+                      <object class="GtkBox" id="leave_fullscreen_button_box">
                         <property name="orientation">horizontal</property>
                         <property name="visible">False</property>
                         <property name="no-show-all">True</property>
@@ -189,6 +213,8 @@
       </object>
     </child>
   </object>
+        </child>
+    </template>
   <object class="GtkSizeGroup" id="button_sizegroup">
     <property name="mode">GTK_SIZE_GROUP_HORIZONTAL</property>
     <widgets>
diff --git a/data/cheese.gresource.xml b/data/cheese.gresource.xml
index 9c42497..306e856 100644
--- a/data/cheese.gresource.xml
+++ b/data/cheese.gresource.xml
@@ -3,6 +3,7 @@
   <gresource prefix='/org/gnome/Cheese'>
     <file>cheese.css</file>
     <file>cheese-viewport.json</file>
+    <file preprocess="xml-stripblanks">cheese-main-window.ui</file>
     <file preprocess="xml-stripblanks">cheese-prefs.ui</file>
   </gresource>
 </gresources>
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
index 0577297..3c93917 100644
--- a/src/cheese-window.vala
+++ b/src/cheese-window.vala
@@ -31,6 +31,7 @@ using CanberraGtk;
 const int FULLSCREEN_TIMEOUT_INTERVAL = 5 * 1000;
 const uint EFFECTS_PER_PAGE = 9;
 
+[GtkTemplate (ui = "/org/gnome/Cheese/cheese-main-window.ui")]
 public class Cheese.MainWindow : Gtk.ApplicationWindow
 {
     private const GLib.ActionEntry actions[] = {
@@ -44,39 +45,43 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
 
     private MediaMode current_mode;
 
-  private Gtk.Builder    gtk_builder;
-  private Clutter.Script clutter_builder;
-
-  private Gtk.HeaderBar header_bar;
-  private GLib.Settings settings;
-
-  private Gtk.Widget       thumbnails;
-  private GtkClutter.Embed viewport_widget;
-  private Gtk.Widget main_vbox;
-  private Eog.ThumbNav     thumb_nav;
-  private Cheese.ThumbView thumb_view;
-  private Gtk.Alignment    thumbnails_right;
-  private Gtk.Alignment    thumbnails_bottom;
-    private Gtk.Widget leave_fullscreen_button_container;
-  private Gtk.ToggleButton photo_toggle_button;
-  private Gtk.ToggleButton video_toggle_button;
-  private Gtk.ToggleButton burst_toggle_button;
-  private Gtk.Button       take_action_button;
-  private Gtk.Label        take_action_button_label;
-  private Gtk.Image        take_action_button_image;
-  private Gtk.ToggleButton effects_toggle_button;
-  private Gtk.Button       leave_fullscreen_button;
+    private Clutter.Script clutter_builder;
+
+    [GtkChild]
+    private Gtk.HeaderBar header_bar;
+
+    private GLib.Settings settings;
+
+    [GtkChild]
+    private GtkClutter.Embed viewport_widget;
+    [GtkChild]
+    private Gtk.Widget main_vbox;
+    private Eog.ThumbNav thumb_nav;
+    private Cheese.ThumbView thumb_view;
+    [GtkChild]
+    private Gtk.Alignment thumbnails_right;
+    [GtkChild]
+    private Gtk.Alignment thumbnails_bottom;
+    [GtkChild]
+    private Gtk.Widget leave_fullscreen_button_box;
+    [GtkChild]
+    private Gtk.Button take_action_button;
+    [GtkChild]
+    private Gtk.Image take_action_button_image;
+    [GtkChild]
+    private Gtk.ToggleButton effects_toggle_button;
+    [GtkChild]
     private Gtk.Widget buttons_area;
-  private Gtk.Menu         thumbnail_popup;
+    private Gtk.Menu thumbnail_popup;
 
-  private Clutter.Stage     viewport;
-  private Clutter.Actor viewport_layout;
-  private Clutter.Texture   video_preview;
-  private Clutter.BinLayout viewport_layout_manager;
-  private Clutter.Text      countdown_layer;
-  private Clutter.Actor background_layer;
-  private Clutter.Text      error_layer;
-  private Clutter.Text      timeout_layer;
+    private Clutter.Stage viewport;
+    private Clutter.Actor viewport_layout;
+    private Clutter.Texture video_preview;
+    private Clutter.BinLayout viewport_layout_manager;
+    private Clutter.Text countdown_layer;
+    private Clutter.Actor background_layer;
+    private Clutter.Text error_layer;
+    private Clutter.Text timeout_layer;
 
   private Clutter.Actor current_effects_grid;
   private uint current_effects_page = 0;
@@ -491,8 +496,8 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
   private void set_fullscreen_mode (bool fullscreen)
   {
     /* After the first time the window has been shown using this.show_all (),
-     * the value of leave_fullscreen_button_container.no_show_all should be set to false
-     * So that the next time leave_fullscreen_button_container.show_all () is called, the button is actually 
shown
+     * the value of leave_fullscreen_button_box.no_show_all should be set to false
+     * So that the next time leave_fullscreen_button_box.show_all () is called, the button is actually shown
      * FIXME: If this code can be made cleaner/clearer, please do */
 
     is_fullscreen = fullscreen;
@@ -506,8 +511,8 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
       {
         thumbnails_bottom.hide ();
       }
-      leave_fullscreen_button_container.no_show_all = false;
-      leave_fullscreen_button_container.show_all ();
+      leave_fullscreen_button_box.no_show_all = false;
+      leave_fullscreen_button_box.show_all ();
 
       this.fullscreen ();
       viewport_widget.motion_notify_event.connect (fullscreen_motion_notify_callback);
@@ -523,7 +528,7 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
       {
         thumbnails_bottom.show_all ();
       }
-      leave_fullscreen_button_container.hide ();
+      leave_fullscreen_button_box.hide ();
 
       /* Stop timer so buttons_area does not get hidden after returning from
        * fullscreen mode */
@@ -1135,7 +1140,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
    */
   public void setup_ui ()
   {
-    gtk_builder     = new Gtk.Builder ();
         clutter_builder = new Clutter.Script ();
     fileutil        = new FileUtil ();
     flash           = new Flash (this);
@@ -1160,41 +1164,24 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
 
         this.add_action_entries (actions, this);
 
-    try {
-      gtk_builder.add_from_file (GLib.Path.build_filename (Config.PACKAGE_DATADIR, "cheese-main-window.ui"));
-      gtk_builder.connect_signals (this);
-
+        try
+        {
             clutter_builder.load_from_resource ("/org/gnome/Cheese/cheese-viewport.json");
-    } catch (Error err)
-    {
-      error ("Error: %s", err.message);
-    }
+        }
+        catch (Error err)
+        {
+            error ("Error: %s", err.message);
+        }
 
-        main_vbox = gtk_builder.get_object ("mainbox_normal") as Gtk.Widget;
-    thumbnails                        = gtk_builder.get_object ("thumbnails") as Gtk.Widget;
-    viewport_widget                   = gtk_builder.get_object ("viewport") as GtkClutter.Embed;
-    viewport                          = viewport_widget.get_stage () as Clutter.Stage;
-    thumbnails_right                  = gtk_builder.get_object ("thumbnails_right") as Gtk.Alignment;
-    thumbnails_bottom                 = gtk_builder.get_object ("thumbnails_bottom") as Gtk.Alignment;
-    leave_fullscreen_button_container = gtk_builder.get_object ("leave_fullscreen_button_bin") as Gtk.Widget;
-    photo_toggle_button               = gtk_builder.get_object ("photo_toggle_button") as Gtk.ToggleButton;
-    video_toggle_button               = gtk_builder.get_object ("video_toggle_button") as Gtk.ToggleButton;
-    burst_toggle_button               = gtk_builder.get_object ("burst_toggle_button") as Gtk.ToggleButton;
-    take_action_button                = gtk_builder.get_object ("take_action_button") as Gtk.Button;
-    take_action_button_label          = gtk_builder.get_object ("take_action_button_internal_label") as 
Gtk.Label;
-    take_action_button_image          = gtk_builder.get_object ("take_action_button_internal_image") as 
Gtk.Image;
-    effects_toggle_button             = gtk_builder.get_object ("effects_toggle_button") as Gtk.ToggleButton;
-    leave_fullscreen_button           = gtk_builder.get_object ("leave_fullscreen_button") as Gtk.Button;
-        buttons_area = gtk_builder.get_object ("buttons_area") as Gtk.Widget;
-        header_bar = gtk_builder.get_object ("header-bar") as Gtk.HeaderBar;
-
-    video_preview           = clutter_builder.get_object ("video_preview") as Clutter.Texture;
-    viewport_layout = clutter_builder.get_object ("viewport_layout") as Clutter.Actor;
-    viewport_layout_manager = clutter_builder.get_object ("viewport_layout_manager") as Clutter.BinLayout;
-    countdown_layer         = clutter_builder.get_object ("countdown_layer") as Clutter.Text;
-    background_layer = clutter_builder.get_object ("background") as Clutter.Actor;
-    error_layer             = clutter_builder.get_object ("error_layer") as Clutter.Text;
-    timeout_layer           = clutter_builder.get_object ("timeout_layer") as Clutter.Text;
+        viewport = viewport_widget.get_stage () as Clutter.Stage;
+
+        video_preview = clutter_builder.get_object ("video_preview") as Clutter.Texture;
+        viewport_layout = clutter_builder.get_object ("viewport_layout") as Clutter.Actor;
+        viewport_layout_manager = clutter_builder.get_object ("viewport_layout_manager") as 
Clutter.BinLayout;
+        countdown_layer = clutter_builder.get_object ("countdown_layer") as Clutter.Text;
+        background_layer = clutter_builder.get_object ("background") as Clutter.Actor;
+        error_layer = clutter_builder.get_object ("error_layer") as Clutter.Text;
+        timeout_layer = clutter_builder.get_object ("timeout_layer") as Clutter.Text;
 
     video_preview.keep_aspect_ratio = true;
     video_preview.request_mode      = Clutter.RequestMode.HEIGHT_FOR_WIDTH;
@@ -1227,10 +1214,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
 
     thumb_view.button_press_event.connect (on_thumbnail_button_press_event);
 
-    this.add (main_vbox);
-    main_vbox.show_all ();
-    this.set_titlebar(header_bar);
-
     /* needed for the sizing tricks in set_wide_mode (allocation is 0
      * if the widget is not realized */
     viewport_widget.realize ();
@@ -1290,7 +1273,7 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
      /**
      * Set the header bar title.
      */
-    public void update_header_bar_title ()
+    private void update_header_bar_title ()
     {
         if (is_effects_selector_active)
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]