From 57a8e6d933f74a19bb16ff7a7ac0f51438c5ba1a Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Thu, 15 Oct 2020 16:21:46 +0200 Subject: [PATCH] Add about dialog --- clapper_src/app.js | 34 +++++++++++++++++++-------------- clapper_src/controls.js | 6 ------ clapper_src/debug.js | 10 ++++------ clapper_src/headerbar.js | 16 +++++++++++++--- clapper_src/menu.js | 41 ++++++++++++++++++++++++++++++++++++++++ meson.build | 1 + ui/clapper.ui | 17 +++++++++++++++++ 7 files changed, 96 insertions(+), 29 deletions(-) create mode 100644 clapper_src/menu.js create mode 100644 ui/clapper.ui diff --git a/clapper_src/app.js b/clapper_src/app.js index 53a69a8c..e429e57c 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -1,8 +1,9 @@ -const { Gdk, GLib, GObject, Gtk, GstPlayer } = imports.gi; +const { Gdk, Gio, GLib, GObject, Gtk, GstPlayer } = imports.gi; const Debug = imports.clapper_src.debug; const { HeaderBar } = imports.clapper_src.headerbar; const { Interface } = imports.clapper_src.interface; const { Player } = imports.clapper_src.player; +const Menu = imports.clapper_src.menu; const { Window } = imports.clapper_src.window; const APP_NAME = pkg.name.substring( @@ -59,21 +60,26 @@ var App = GObject.registerClass({ 'close-request', this._onWindowCloseRequest.bind(this) ); - this.interface = new Interface(); + for(let action of Menu.actions) { + let simpleAction = new Gio.SimpleAction({ + name: action.name + }); + simpleAction.connect('activate', () => action(this.active_window, APP_NAME)); + this.add_action(simpleAction); + } + let uiBuilder = Gtk.Builder.new_from_file( + `${pkg.datadir}/${pkg.name}/ui/clapper.ui` + ); + let models = { + settingsMenu: uiBuilder.get_object('settingsMenu') + }; + let headerBar = new HeaderBar(this.window, models); - let headerStart = []; - let headerEnd = [ - this.interface.controls.openMenuButton, - this.interface.controls.fullscreenButton - ]; - let headerBar = new HeaderBar(this.window, headerStart, headerEnd); + this.interface = new Interface(); this.interface.addHeaderBar(headerBar, APP_NAME); - this.interface.controls.fullscreenButton.connect( - 'clicked', () => this.activeWindow.fullscreen() - ); this.interface.controls.unfullscreenButton.connect( - 'clicked', () => this.activeWindow.unfullscreen() + 'clicked', () => this.active_window.unfullscreen() ); this.window.set_titlebar(this.interface.headerBar); @@ -358,7 +364,7 @@ var App = GObject.registerClass({ _onPlayerDragUpdate(gesture, offsetX, offsetY) { - if(!this.dragAllowed || this.activeWindow.isFullscreen) + if(!this.dragAllowed || this.active_window.isFullscreen) return; let { gtk_double_click_distance } = this.player.widget.get_settings(); @@ -370,7 +376,7 @@ var App = GObject.registerClass({ let [isActive, startX, startY] = gesture.get_start_point(); if(!isActive) return; - this.activeWindow.get_surface().begin_move( + this.active_window.get_surface().begin_move( gesture.get_device(), gesture.get_current_button(), startX, diff --git a/clapper_src/controls.js b/clapper_src/controls.js index 96608eb2..52b33fa4 100644 --- a/clapper_src/controls.js +++ b/clapper_src/controls.js @@ -54,12 +54,6 @@ var Controls = GObject.registerClass({ 'view-restore-symbolic', ); this.unfullscreenButton.set_visible(false); - this.fullscreenButton = Gtk.Button.new_from_icon_name( - 'view-fullscreen-symbolic', - ); - this.openMenuButton = Gtk.Button.new_from_icon_name( - 'open-menu-symbolic', - ); this.add_css_class('playercontrols'); diff --git a/clapper_src/debug.js b/clapper_src/debug.js index f9537f13..b151b9f2 100644 --- a/clapper_src/debug.js +++ b/clapper_src/debug.js @@ -1,7 +1,5 @@ const { GLib, Gst } = imports.gi; - -const GST_VERSION = Gst.version(); -const REQ_GST_VER_MINOR = 16; +const REQ_GST_VERSION_MINOR = 16; function debug(msg, levelName) { @@ -20,13 +18,13 @@ function debug(msg, levelName) function gstVersionCheck() { - if(GST_VERSION[1] >= REQ_GST_VER_MINOR) + if(Gst.VERSION_MINOR >= REQ_GST_VERSION_MINOR) return; debug( 'clapper interface was designed to' + - ` work with GStreamer 1.${REQ_GST_VER_MINOR} or later.` + - ` Your version is ${GST_VERSION[0]}.${GST_VERSION[1]}.` + + ` work with GStreamer 1.${REQ_GST_VERSION_MINOR} or later.` + + ` Your version is ${Gst.VERSION_MAJOR}.${Gst.VERSION_MINOR}.` + ' Please update GStreamer or expect some things to be broken.', 'LEVEL_WARNING' ); diff --git a/clapper_src/headerbar.js b/clapper_src/headerbar.js index 2fdbffa2..4202098c 100644 --- a/clapper_src/headerbar.js +++ b/clapper_src/headerbar.js @@ -3,15 +3,25 @@ const { GLib, GObject, Gtk, Pango } = imports.gi; var HeaderBar = GObject.registerClass( class ClapperHeaderBar extends Gtk.HeaderBar { - _init(window, startButtons, endButtons) + _init(window, models) { super._init({ can_focus: false, }); this.set_title_widget(this._createWidgetForWindow(window)); - startButtons.forEach(btn => this.pack_start(btn)); - endButtons.forEach(btn => this.pack_end(btn)); + + let openMenuButton = new Gtk.MenuButton({ + icon_name: 'open-menu-symbolic' + }); + openMenuButton.set_menu_model(models.settingsMenu); + this.pack_end(openMenuButton); + + let fullscreenButton = new Gtk.Button({ + icon_name: 'view-fullscreen-symbolic' + }); + fullscreenButton.connect('clicked', () => this.get_parent().fullscreen()); + this.pack_end(fullscreenButton); } updateHeaderBar(mediaInfo) diff --git a/clapper_src/menu.js b/clapper_src/menu.js new file mode 100644 index 00000000..b75726f2 --- /dev/null +++ b/clapper_src/menu.js @@ -0,0 +1,41 @@ +const { GObject, Gst, Gtk } = imports.gi; + +var actions = [ + about +]; + +var accels = [ + ['app.quit', ['q']], +]; + +function about(window, appName) +{ + let gstVer = [ + Gst.VERSION_MAJOR, Gst.VERSION_MINOR, Gst.VERSION_MICRO + ].join('.'); + + let gtkVer = [ + Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION + ].join('.'); + + let osInfo = [ + 'GTK version' + ': ' + gtkVer, + 'GStreamer version' + ': ' + gstVer + ].join('\n'); + + let aboutDialog = new Gtk.AboutDialog({ + program_name: appName, + comments: 'A GNOME media player powered by GStreamer', + version: pkg.version, + authors: ['Rafał Dzięgiel'], + artists: ['Rafał Dzięgiel'], + license_type: Gtk.License.GPL_3_0, + logo_icon_name: pkg.name, + website: 'https://github.com/Rafostar/clapper', + modal: true, + system_information: osInfo, + transient_for: window + }); + + aboutDialog.present(); +} diff --git a/meson.build b/meson.build index 0d9aed0b..beee3093 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,7 @@ subdir('data') installdir = join_paths(get_option('prefix'), 'share', meson.project_name()) install_subdir('clapper_src', install_dir : installdir) install_subdir('css', install_dir : installdir) +install_subdir('ui', install_dir : installdir) install_data('main.js', install_dir : installdir) meson.add_install_script('build-aux/meson/postinstall.py') diff --git a/ui/clapper.ui b/ui/clapper.ui new file mode 100644 index 00000000..fcf46626 --- /dev/null +++ b/ui/clapper.ui @@ -0,0 +1,17 @@ + + + +
+ + + About Clapper + app.about + +
+
+