[totem] orientation: Update for newer video widget API



commit 7d66ae75cedae303bbcfe5d15c9901835922a6e8
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jun 27 20:45:24 2012 +0100

    orientation: Update for newer video widget API

 src/plugins/rotation/Makefile.am                |    4 +-
 src/plugins/rotation/bacon-video.vapi           |   19 +++++
 src/plugins/rotation/totem-rotation-plugin.vala |   89 ++++++-----------------
 3 files changed, 42 insertions(+), 70 deletions(-)
---
diff --git a/src/plugins/rotation/Makefile.am b/src/plugins/rotation/Makefile.am
index 43cf2da..e0d2c63 100644
--- a/src/plugins/rotation/Makefile.am
+++ b/src/plugins/rotation/Makefile.am
@@ -9,11 +9,11 @@ plugin_in_files = rotation.plugin.in
 # because vala still cannot parse the gir
 VALAFLAGS = \
 	--girdir=$(top_srcdir)/src	\
-	--pkg Totem-1.0 --pkg libpeas-1.0 --pkg cogl-pango-1.0 --pkg GtkClutter-1.0 --pkg clutter-1.0 --pkg gtk+-3.0
+	--pkg Totem-1.0 --pkg libpeas-1.0 --pkg cogl-pango-1.0 --pkg GtkClutter-1.0 --pkg Clutter-1.0 --pkg gtk+-3.0 bacon-video.vapi
 
 librotation_la_SOURCES = totem-rotation-plugin.vala
 librotation_la_LDFLAGS = $(plugin_ldflags)
-librotation_la_CFLAGS = $(plugin_cflags) -include $(CONFIG_HEADER)
+librotation_la_CFLAGS = $(plugin_cflags) -include $(CONFIG_HEADER) -I $(top_srcdir)/src/backend
 librotation_la_LIBADD = $(plugin_libadd)
 
 GITIGNOREFILES = \
diff --git a/src/plugins/rotation/bacon-video.vapi b/src/plugins/rotation/bacon-video.vapi
new file mode 100644
index 0000000..a17a6bf
--- /dev/null
+++ b/src/plugins/rotation/bacon-video.vapi
@@ -0,0 +1,19 @@
+[CCode (cprefix = "Bacon", lower_case_cprefix = "bacon_")]
+
+namespace Bacon {
+	[CCode (cheader_filename = "bacon-video-widget.h")]
+	public class VideoWidget : Gtk.Widget {
+    [CCode (has_construct_function = false)]
+		public VideoWidget () throws GLib.Error;
+
+    public Rotation get_rotation ();
+    public void set_rotation (Rotation rotation);
+	}
+  [CCode (cname="BvwRotation", cprefix = "BVW_ROTATION_", cheader_filename = "bacon-video-widget.h")]
+  public enum Rotation {
+    R_0   = 0,
+    R_90R = 1,
+    R_180 = 2,
+    R_90L = 3
+  }
+}
diff --git a/src/plugins/rotation/totem-rotation-plugin.vala b/src/plugins/rotation/totem-rotation-plugin.vala
index 8ecfcd0..43d19b4 100644
--- a/src/plugins/rotation/totem-rotation-plugin.vala
+++ b/src/plugins/rotation/totem-rotation-plugin.vala
@@ -26,29 +26,19 @@ public const string GIO_ROTATION_FILE_ATTRIBUTE = "metadata::totem::rotation";
 
 class RotationPlugin: GLib.Object, Peas.Activatable
 {
-    private enum Rotation
-    {
-        _IDENTITY = 0,
-        _90R = 1,
-        _180 = 2,
-        _90L = 3
-    }
     private const int STATE_COUNT = 4;
     public GLib.Object object { owned get; construct; }
-    private weak Clutter.Actor video = null;
+    private Bacon.VideoWidget bvw = null;
     private uint ui_id;
     private Gtk.ActionGroup action_group;
-    private Rotation state = Rotation._IDENTITY;
-    private float width;
-    private float height;
 
     public void activate ()
     {
         Totem.Object t = (Totem.Object) this.object;
-        GtkClutter.Embed bvw = (GtkClutter.Embed) Totem.get_video_widget (t);
-        unowned Clutter.Stage stage = (Clutter.Stage) bvw.get_stage ();
         string mrl = t.get_current_mrl ();
 
+        this.bvw = Totem.get_video_widget (t) as Bacon.VideoWidget;
+
         // add interface elements to control the rotation
         unowned Gtk.UIManager ui_manager = t.get_ui_manager ();
         this.ui_id = ui_manager.new_merge_id ();
@@ -70,30 +60,13 @@ class RotationPlugin: GLib.Object, Peas.Activatable
         }
         ui_manager.insert_action_group (this.action_group, 0);
 
-        // search for the actor which contains the video
-        for (int i = 0; i < stage.get_n_children (); i++) {
-            Clutter.Actor actor = stage.get_nth_child (i);
-            if (actor.name == "frame") {
-                this.video = actor;
-                break;
-            }
-        }
-
-        if (video == null) {
-            GLib.critical ("Could not find the clutter actor 'frame'.");
-            return;
-        }
-
-        this.width = this.video.width;
-        this.height = this.video.height;
-
         // read the state of the current video from the GIO attribute
         if (mrl != null) {
             this.try_restore_state (mrl);
         }
 
         // get notified if the video gets resized
-        this.video.allocation_changed.connect (this.cb_allocation_changed);
+        //this.video.allocation_changed.connect (this.cb_allocation_changed);
 
         t.file_closed.connect (this.cb_file_closed);
         t.file_opened.connect (this.cb_file_opened);
@@ -104,7 +77,7 @@ class RotationPlugin: GLib.Object, Peas.Activatable
         Totem.Object t = (Totem.Object) this.object;
 
         // disconnect callbacks
-        this.video.allocation_changed.disconnect (this.cb_allocation_changed);
+        //this.video.allocation_changed.disconnect (this.cb_allocation_changed);
         t.file_closed.disconnect (this.cb_file_closed);
         t.file_opened.disconnect (this.cb_file_opened);
 
@@ -114,61 +87,39 @@ class RotationPlugin: GLib.Object, Peas.Activatable
         ui_manager.remove_action_group (this.action_group);
 
         // undo transformations
-        this.state = Rotation._IDENTITY;
-        this.video.set_rotation (Clutter.RotateAxis.Z_AXIS, 0, 0, 0, 0);
-        this.video.set_scale_full (1, 1, 0, 0);
+        this.bvw.set_rotation (Bacon.Rotation.R_0);
     }
 
     public void update_state ()
     {
-        this.update_video_geometry ();
-    }
-
-    private void update_video_geometry ()
-    {
-        float center_x = this.width * 0.5f;
-        float center_y = this.height * 0.5f;
-        double scale = 1.0;
-
-        // scale so that the larger side fits the smaller side
-        if (this.state % 2 == 1) { // _90R or _90L
-            if (this.width > this.height) {
-                scale = this.height / (double) this.width;
-            } else {
-                scale = this.width / (double) this.height;
-            }
-        }
-
-        this.video.set_rotation (Clutter.RotateAxis.Z_AXIS, 90.0 * this.state, center_x, center_y, 0);
-        this.video.set_scale_full (scale, scale, center_x, center_y);
+        //this.update_video_geometry ();
     }
 
     private void cb_allocation_changed (Clutter.ActorBox box, Clutter.AllocationFlags flags)
     {
-        this.width = box.x2 - box.x1;
-        this.height = box.y2 - box.y1;
-        this.update_video_geometry ();
+        //this.width = box.x2 - box.x1;
+        //this.height = box.y2 - box.y1;
+        //this.update_video_geometry ();
     }
 
     private void cb_rotate_left ()
     {
-        this.state = (this.state - 1) % STATE_COUNT;
-        this.update_video_geometry ();
+        int state = (this.bvw.get_rotation() - 1) % STATE_COUNT;
+        this.bvw.set_rotation ((Bacon.Rotation) state);
         this.store_state ();
     }
 
     private void cb_rotate_right ()
     {
-        this.state = (this.state + 1) % STATE_COUNT;
-        this.update_video_geometry ();
+        int state = (this.bvw.get_rotation() + 1) % STATE_COUNT;
+        this.bvw.set_rotation ((Bacon.Rotation) state);
         this.store_state ();
     }
 
     private void cb_file_closed ()
     {
         // reset the rotation
-        this.state = Rotation._IDENTITY;
-        this.update_video_geometry ();
+        this.bvw.set_rotation (Bacon.Rotation.R_0);
         this.action_group.sensitive = false;
     }
 
@@ -189,12 +140,14 @@ class RotationPlugin: GLib.Object, Peas.Activatable
 
         var file = GLib.File.new_for_uri (mrl);
         try {
+            Bacon.Rotation rotation;
             var file_info = yield file.query_info_async (GIO_ROTATION_FILE_ATTRIBUTE,
                     GLib.FileQueryInfoFlags.NONE);
 
             string state_str = "";
-            if (this.state != Rotation._IDENTITY) {
-                state_str = "%u".printf ((uint) this.state);
+            rotation = this.bvw.get_rotation ();
+            if (rotation != Bacon.Rotation.R_0) {
+                state_str = "%u".printf ((uint) rotation);
             }
             file_info.set_attribute_string (GIO_ROTATION_FILE_ATTRIBUTE, state_str);
             yield file.set_attributes_async (file_info, GLib.FileQueryInfoFlags.NONE,
@@ -212,8 +165,8 @@ class RotationPlugin: GLib.Object, Peas.Activatable
                     GLib.FileQueryInfoFlags.NONE);
             string state_str = file_info.get_attribute_string (GIO_ROTATION_FILE_ATTRIBUTE);
             if (state_str != null) {
-                this.state = (Rotation) uint64.parse (state_str);
-                this.update_video_geometry ();
+                int state = (Bacon.Rotation) uint64.parse (state_str);
+                this.bvw.set_rotation ((Bacon.Rotation) state);
             }
         } catch (GLib.Error e) {
             GLib.warning ("Could not query file attribute: %s", e.message);



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