mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
Open files via native file chooser
This commit is contained in:
@@ -45,7 +45,8 @@ class ClapperApp extends Gtk.Application
|
||||
`${clapperPath}/ui/clapper.ui`
|
||||
);
|
||||
let models = {
|
||||
settingsMenu: uiBuilder.get_object('settingsMenu')
|
||||
addMediaMenu: uiBuilder.get_object('addMediaMenu'),
|
||||
settingsMenu: uiBuilder.get_object('settingsMenu'),
|
||||
};
|
||||
let headerBar = new HeaderBar(window, models);
|
||||
window.set_titlebar(headerBar);
|
||||
|
46
clapper_src/filechooser.js
Normal file
46
clapper_src/filechooser.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const { Gio, GObject, Gtk } = imports.gi;
|
||||
|
||||
var FileChooser = GObject.registerClass(
|
||||
class ClapperFileChooser extends Gtk.FileChooserNative
|
||||
{
|
||||
_init(window, appName)
|
||||
{
|
||||
super._init({
|
||||
transient_for: window,
|
||||
});
|
||||
|
||||
let filter = new Gtk.FileFilter({
|
||||
name: 'Media Files',
|
||||
});
|
||||
filter.add_mime_type('video/*');
|
||||
filter.add_mime_type('audio/*');
|
||||
filter.add_mime_type('application/claps');
|
||||
this.add_filter(filter);
|
||||
|
||||
this.responseSignal = this.connect('response', this._onResponse.bind(this));
|
||||
}
|
||||
|
||||
present()
|
||||
{
|
||||
/* File chooser closes itself when nobody is holding its ref */
|
||||
this.ref();
|
||||
|
||||
super.show();
|
||||
}
|
||||
|
||||
_onResponse(filechooser, response)
|
||||
{
|
||||
this.disconnect(this.responseSignal);
|
||||
this.responseSignal = null;
|
||||
|
||||
if(response === Gtk.ResponseType.ACCEPT) {
|
||||
let file = this.get_file();
|
||||
let { player } = this.get_transient_for().get_child();
|
||||
|
||||
player.set_media(file.get_uri());
|
||||
}
|
||||
|
||||
this.unref();
|
||||
this.run_dispose();
|
||||
}
|
||||
});
|
@@ -11,15 +11,22 @@ class ClapperHeaderBar extends Gtk.HeaderBar
|
||||
|
||||
this.set_title_widget(this._createWidgetForWindow(window));
|
||||
|
||||
let addMediaButton = new Gtk.MenuButton({
|
||||
icon_name: 'list-add-symbolic',
|
||||
});
|
||||
let addMediaPopover = new HeaderBarPopover(models.addMediaMenu);
|
||||
addMediaButton.set_popover(addMediaPopover);
|
||||
this.pack_start(addMediaButton);
|
||||
|
||||
let openMenuButton = new Gtk.MenuButton({
|
||||
icon_name: 'open-menu-symbolic'
|
||||
icon_name: 'open-menu-symbolic',
|
||||
});
|
||||
let settingsPopover = new HeaderBarPopover(models.settingsMenu);
|
||||
openMenuButton.set_popover(settingsPopover);
|
||||
this.pack_end(openMenuButton);
|
||||
|
||||
let fullscreenButton = new Gtk.Button({
|
||||
icon_name: 'view-fullscreen-symbolic'
|
||||
icon_name: 'view-fullscreen-symbolic',
|
||||
});
|
||||
fullscreenButton.connect('clicked', () => this.get_parent().fullscreen());
|
||||
this.pack_end(fullscreenButton);
|
||||
|
@@ -1,8 +1,10 @@
|
||||
const { GObject, Gst, Gtk } = imports.gi;
|
||||
const Misc = imports.clapper_src.misc;
|
||||
const Prefs = imports.clapper_src.prefs;
|
||||
const { FileChooser } = imports.clapper_src.filechooser;
|
||||
|
||||
var actions = [
|
||||
openLocal,
|
||||
prefs,
|
||||
about,
|
||||
];
|
||||
@@ -11,6 +13,12 @@ var accels = [
|
||||
['app.quit', ['q']],
|
||||
];
|
||||
|
||||
function openLocal(window, appName)
|
||||
{
|
||||
let fileChooser = new FileChooser(window);
|
||||
fileChooser.present();
|
||||
}
|
||||
|
||||
function prefs(window, appName)
|
||||
{
|
||||
let prefsWidget = Prefs.buildPrefsWidget();
|
||||
|
@@ -278,8 +278,10 @@ var Widget = GObject.registerClass({
|
||||
{
|
||||
switch(state) {
|
||||
case GstPlayer.PlayerState.BUFFERING:
|
||||
if(!player.is_local_file)
|
||||
if(!player.is_local_file) {
|
||||
this.needsTracksUpdate = true;
|
||||
}
|
||||
debug('player state changed to: BUFFERING');
|
||||
break;
|
||||
case GstPlayer.PlayerState.STOPPED:
|
||||
this.controls.currentPosition = 0;
|
||||
@@ -290,8 +292,12 @@ var Widget = GObject.registerClass({
|
||||
player.disconnect(this.mediaInfoSignal);
|
||||
this.mediaInfoSignal = null;
|
||||
}
|
||||
this.controls.togglePlayButton.setPrimaryIcon();
|
||||
debug('player state changed to: STOPPED');
|
||||
break;
|
||||
case GstPlayer.PlayerState.PAUSED:
|
||||
this.controls.togglePlayButton.setPrimaryIcon();
|
||||
debug('player state changed to: PAUSED');
|
||||
break;
|
||||
case GstPlayer.PlayerState.PLAYING:
|
||||
this.controls.togglePlayButton.setSecondaryIcon();
|
||||
@@ -301,6 +307,7 @@ var Widget = GObject.registerClass({
|
||||
'media_info_updated', this._onMediaInfoUpdated.bind(this)
|
||||
);
|
||||
}
|
||||
debug('player state changed to: PLAYING');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
Reference in New Issue
Block a user