From 21a5c2e0f8f9cd01742c614aa28e6e4fef2fbf5b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 9 Jun 2014 17:13:42 +0200 Subject: hook up screenshot and screencast dbus calls --- src/app/main.js | 8 +++++ src/app/window.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 3 deletions(-) diff --git a/src/app/main.js b/src/app/main.js index 3aea457..f536ca6 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -32,12 +32,14 @@ const Gdk = imports.gi.Gdk; const Gio = imports.gi.Gio; const GLib = imports.gi.GLib; const Gtk = imports.gi.Gtk; +const Gst = imports.gi.Gst; const Lang = imports.lang; const Util = imports.misc.util; const Window = imports.app.window; const Recording = imports.app.recording; +Gst.init(null, 0); function initEnvironment() { window.getApp = function() { @@ -94,6 +96,12 @@ const Application = new Lang.Class({ this.add_accelerator("Escape", "win.selection-mode(false)", null); this.add_accelerator("a", "win.select-all", null); + + this.monitor = Gst.DeviceMonitorFactory.get_by_name("pulsemonitor"); + + let devs = this.monitor.get_devices(); + for (let i = 0; i < devs.length; i++) + print (devs[i].display_name + " " + devs[i].klass); }, _createWindow: function() { diff --git a/src/app/window.js b/src/app/window.js index d32c55d..4c0f14e 100644 --- a/src/app/window.js +++ b/src/app/window.js @@ -17,6 +17,7 @@ // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA const GLib = imports.gi.GLib; +const Gio = imports.gi.Gio; const GObject = imports.gi.GObject; const Gtk = imports.gi.Gtk; const Lang = imports.lang; @@ -33,6 +34,22 @@ const Page = { RECORDINGS: 1 }; +function _selectArea(connection) { + let result = connection.call_sync ('org.gnome.Shell.Screenshot', + '/org/gnome/Shell/Screenshot', + 'org.gnome.Shell.Screenshot', + 'SelectArea', + null, + new GLib.VariantType('(iiii)'), + Gio.DBusConnectionFlags.NONE, + -1, + null, + null); + + return result.deep_unpack(); +} + + const NewScreenshotController = new Lang.Class({ Name: 'NewScreenshotController', @@ -42,6 +59,10 @@ const NewScreenshotController = new Lang.Class({ let builder = Util.loadUI('/org/gnome/ScreenRecorder/Application/new-screenshot-dialog.ui', { 'parent-window': parentWindow }); + this._buttonScreenshotAll = builder.get_object('screenshot-all'); + this._buttonScreenshotWindow = builder.get_object('screenshot-window'); + this._buttonScreenshotArea = builder.get_object('screenshot-area'); + let dialog = builder.get_object('screenshot-dialog'); dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL); @@ -63,7 +84,46 @@ const NewScreenshotController = new Lang.Class({ if (response != Gtk.ResponseType.OK) return; - this._recordingsModel.addScreenshot(location, true); + let connection = Gio.Application.get_default().get_dbus_connection(); + let method_name, method_params; + + if (this._buttonScreenshotAll.get_active()) { + method_name = 'Screenshot'; + method_params = new GLib.Variant ('(bbs)', + [true, /* cursor */ + true, /* flash */ + '/tmp/ss-test']); + } else if (this._buttonScreenshotWindow.get_active()) { + method_name = 'ScreenshotWindow'; + method_params = new GLib.Variant ('(bbbs)', + [true, /* frame */ + true, /* cursor */ + true, /* flash */ + '/tmp/ss-test']); + } else if (this._buttonScreenshotArea.get_active()) { + let area = _selectArea(connection); + + method_name = 'ScreenshotArea'; + method_params = new GLib.Variant ('(iiiibs)', + [area[0], + area[1], + area[2], + area[3], + true, /* flash */ + '/tmp/ss-test-area']); + + } + + connection.call_sync ('org.gnome.Shell.Screenshot', + '/org/gnome/Shell/Screenshot', + 'org.gnome.Shell.Screenshot', + method_name, + method_params, + null, + Gio.DBusConnectionFlags.NONE, + -1, + null, + null); } }); @@ -76,10 +136,13 @@ const NewRecordingController = new Lang.Class({ let builder = Util.loadUI('/org/gnome/ScreenRecorder/Application/new-recording-dialog.ui', { 'parent-window': parentWindow }); + this._buttonRecordAll = builder.get_object('record-all'); + this._buttonRecordArea = builder.get_object('record-area'); + let dialog = builder.get_object('recording-dialog'); dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL); - dialog.add_button(Gtk.STOCK_ADD, Gtk.ResponseType.OK); + dialog.add_button(Gtk.STOCK_MEDIA_RECORD, Gtk.ResponseType.OK); dialog.set_default_response(Gtk.ResponseType.OK); dialog.connect('response', Lang.bind(this, this._onResponse)); @@ -97,7 +160,37 @@ const NewRecordingController = new Lang.Class({ if (response != Gtk.ResponseType.OK) return; - this._recordingsModel.addRecording(location, true); + let connection = Gio.Application.get_default().get_dbus_connection(); + let method_name, method_params; + + if (this._buttonRecordAll.get_active()) { + method_name = 'Screencast'; + method_params = new GLib.Variant ('(sa{sv})', + ['/tmp/sc-test', + null]); + } else if (this._buttonRecordArea.get_active()) { + let area = _selectArea(connection); + + method_name = 'ScreencastArea'; + method_params = new GLib.Variant ('(iiiisa{sv})', + [area[0], + area[1], + area[2], + area[3], + '/tmp/sc-test-area', + null]); + + } + connection.call_sync ('org.gnome.Shell.Screencast', + '/org/gnome/Shell/Screencast', + 'org.gnome.Shell.Screencast', + method_name, + method_params, + null, + Gio.DBusConnectionFlags.NONE, + -1, + null, + null); } }); -- cgit v1.2.3