[sushi/wip/cosimoc/no-clutter: 27/36] gst: use SushiMediaBin instead of ClutterGst



commit 0842b838cf8c37e696c690b77e2eec5ae83fd3aa
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Apr 2 13:02:12 2017 -0700

    gst: use SushiMediaBin instead of ClutterGst
    
    This removes the use of Clutter for this functionality.

 src/js/viewers/gst.js |  173 ++++---------------------------------------------
 1 files changed, 14 insertions(+), 159 deletions(-)
---
diff --git a/src/js/viewers/gst.js b/src/js/viewers/gst.js
index 6e8545f..858f391 100644
--- a/src/js/viewers/gst.js
+++ b/src/js/viewers/gst.js
@@ -23,17 +23,10 @@
  *
  */
 
-imports.gi.versions.ClutterGst = '3.0';
-const ClutterGst = imports.gi.ClutterGst;
-const Clutter = imports.gi.Clutter;
-const Gdk = imports.gi.Gdk;
-const GObject = imports.gi.GObject;
-const Gtk = imports.gi.Gtk;
-const GtkClutter = imports.gi.GtkClutter;
+const Sushi = imports.gi.Sushi;
 
 const Lang = imports.lang;
 
-const Constants = imports.util.constants;
 const MimeHandler = imports.ui.mimeHandler;
 const TotemMimeTypes = imports.util.totemMimeTypes;
 const Utils = imports.ui.utils;
@@ -43,170 +36,32 @@ const GstRenderer = new Lang.Class({
 
     _init : function(args) {
         this.moveOnClick = true;
-        this.canFullScreen = true;
+        // fullscreen is handled internally by the widget
+        this.canFullScreen = false;
     },
 
     prepare : function(file, mainWindow, callback) {
-        this._mainWindow = mainWindow;
-        this._file = file;
-        this._callback = callback;
-
-        this._createVideo(file);
-        this._callback();
+        this._player = new Sushi.MediaBin({ uri: file.get_uri() });
+        this._player.play();
+        this._player.connect('size-change', function() {
+            mainWindow.refreshSize();
+        });
+        callback();
     },
 
     render : function() {
-        return this._video;
+        return this._player;
     },
 
     clear : function() {
-        this._player.playing = false;
-    },
-
-    _createVideo : function(file) {
-        this._player = new ClutterGst.Playback();
-        this._video = new Clutter.Actor({
-            content: new ClutterGst.Aspectratio({
-                player: this._player
-            })
-        });
-
-        this._player.set_uri(file.get_uri());
-        this._player.playing = true;
-
-        this._videoSizeChangeId =
-            this._player.connect('size-change',
-                                 Lang.bind(this,
-                                           this._onVideoSizeChange));
-        this._player.connect('notify::playing',
-                             Lang.bind(this,
-                                       this._onVideoPlayingChange));
-        this._player.connect('notify::progress',
-                             Lang.bind(this,
-                                       this._onVideoProgressChange));
-        this._player.connect('notify::duration',
-                             Lang.bind(this,
-                                       this._onVideoDurationChange));
-    },
-
-    _updateProgressBar : function() {
-        if (!this._mainToolbar)
-            return;
-
-        this._isSettingValue = true;
-        this._progressBar.set_value(this._player.progress * 1000);
-        this._isSettingValue = false;
-    },
-
-    _updateCurrentLabel : function() {
-        if (!this._mainToolbar)
-            return;
-
-        let currentTime =
-            Math.floor(this._player.duration * this._player.progress);
-
-        this._currentLabel.set_text(Utils.formatTimeString(currentTime));
-    },
-
-    _updateDurationLabel : function() {
-        if (!this._mainToolbar)
-            return;
-
-        let totalTime = this._player.duration;
-
-        this._durationLabel.set_text(Utils.formatTimeString(totalTime));
-    },
-
-    _onVideoProgressChange : function() {
-        this._updateCurrentLabel();
-        this._updateProgressBar();
-    },
-
-    _onVideoDurationChange : function() {
-        this._updateDurationLabel();
-    },
-
-    _onVideoPlayingChange : function() {
-        if (this._player.playing)
-            this._toolbarPlay.set_icon_name('media-playback-pause-symbolic');
-        else
-        {
-            let iconName = 'media-playback-start-symbolic';
-            this._toolbarPlay.set_icon_name(iconName);
-        }
+        this._player.stop();
     },
 
     getSizeForAllocation : function(allocation) {
-        if (!this._videoWidth ||
-            !this._videoHeight) {
-            return [ Constants.VIEW_MIN, Constants.VIEW_MIN ];
-        }
-
-        let baseSize = [ this._videoWidth, this._videoHeight ];
-
+        let baseSize = [this._player.get_preferred_width()[1],
+                        this._player.get_preferred_height()[1]];
         return Utils.getScaledSize(baseSize, allocation, true);
-    },
-
-    createToolbar : function () {
-        this._mainToolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU,
-                                              hexpand: true });
-        this._mainToolbar.get_style_context().add_class('osd');
-        this._mainToolbar.set_show_arrow(false);
-        this._mainToolbar.show();
-
-        this._toolbarPlay = new Gtk.ToolButton({ icon_name: 'media-playback-pause-symbolic' });
-        this._toolbarPlay.show();
-        this._mainToolbar.insert(this._toolbarPlay, 0);
-
-        this._currentLabel = new Gtk.Label({ margin_start: 6,
-                                             margin_end: 3 });
-        let item = new Gtk.ToolItem();
-        item.add(this._currentLabel);
-        item.show_all();
-        this._mainToolbar.insert(item, 1);
-
-        this._toolbarPlay.connect('clicked',
-                                  Lang.bind(this, function () {
-                                      let playing = !this._player.playing;
-                                      this._player.playing = playing;
-                                  }));
-
-        this._progressBar =
-            Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL,
-                                     0, 1000, 10);
-        this._progressBar.set_value(0);
-        this._progressBar.set_draw_value(false);
-        this._progressBar.connect('value-changed',
-                                  Lang.bind(this, function() {
-                                      if(!this._isSettingValue)
-                                          this._player.progress = this._progressBar.get_value() / 1000;
-                                  }));
-
-        item = new Gtk.ToolItem();
-        item.set_expand(true);
-        item.add(this._progressBar);
-        item.show_all();
-        this._mainToolbar.insert(item, 2);
-
-        this._durationLabel = new Gtk.Label({ margin_start: 3,
-                                              margin_end: 6 });
-        item = new Gtk.ToolItem();
-        item.add(this._durationLabel);
-        item.show_all();
-        this._mainToolbar.insert(item, 3);
-
-        this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
-        this._mainToolbar.insert(this._toolbarZoom, 4);
-
-        return this._mainToolbar;
-    },
-
-    _onVideoSizeChange : function(player, width, height) {
-        this._videoWidth = width;
-        this._videoHeight = height;
-
-        this._mainWindow.refreshSize();
-    },
+    }
 });
 
 let handler = new MimeHandler.MimeHandler();


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