Add open URI dialog

This commit is contained in:
Rafostar
2020-11-03 20:56:21 +01:00
parent dbb25ce474
commit 23b39e5f3b
5 changed files with 84 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
const { Gio, GObject, Gtk } = imports.gi;
const { GObject, Gtk } = imports.gi;
var FileChooser = GObject.registerClass(
class ClapperFileChooser extends Gtk.FileChooserNative

View File

@@ -2,9 +2,11 @@ const { GObject, Gst, Gtk } = imports.gi;
const Misc = imports.clapper_src.misc;
const Prefs = imports.clapper_src.prefs;
const { FileChooser } = imports.clapper_src.filechooser;
const { UriDialog } = imports.clapper_src.uridialog;
var actions = [
openLocal,
openUri,
prefs,
about,
];
@@ -19,6 +21,12 @@ function openLocal(window, appName)
fileChooser.present();
}
function openUri(window, appName)
{
let uriDialog = new UriDialog(window);
uriDialog.present();
}
function prefs(window, appName)
{
let prefsWidget = Prefs.buildPrefsWidget();

66
clapper_src/uridialog.js Normal file
View File

@@ -0,0 +1,66 @@
const { GObject, Gtk, Gst } = imports.gi;
var UriDialog = GObject.registerClass(
class ClapperUriDialog extends Gtk.Dialog
{
_init(window, appName)
{
super._init({
transient_for: window,
title: 'Open URI',
default_width: 460,
});
let box = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
valign: Gtk.Align.CENTER,
spacing: 6,
});
box.add_css_class('uridialogbox');
let linkEntry = new Gtk.Entry({
activates_default: true,
truncate_multiline: true,
width_request: 220,
height_request: 36,
hexpand: true,
});
linkEntry.set_placeholder_text("Enter or drop URI here");
linkEntry.connect('notify::text', this._onTextNotify.bind(this));
box.append(linkEntry);
let openButton = new Gtk.Button({
label: "Open",
halign: Gtk.Align.END,
sensitive: false,
});
openButton.connect('clicked', this._onOpenButtonClicked.bind(this));
box.append(openButton);
this.set_child(box);
}
openUri(uri)
{
let { player } = this.get_transient_for().get_child();
player.set_media(uri);
this.close();
}
_onTextNotify(entry)
{
let isUriValid = (entry.text.length)
? Gst.uri_is_valid(entry.text)
: false;
let button = entry.get_next_sibling();
button.set_sensitive(isUriValid);
}
_onOpenButtonClicked(button)
{
let entry = button.get_prev_sibling();
this.openUri(entry.text);
}
});