[polari/wip/bastianilso/irc-url-handling: 1/2] app: open IRC links
- From: Bastian Ilsø Hougaard <bastianilso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari/wip/bastianilso/irc-url-handling: 1/2] app: open IRC links
- Date: Tue, 23 Feb 2016 23:41:07 +0000 (UTC)
commit 3b0c88b79d2a25e7e81b7600c3af331e2f44c900
Author: Bastian Ilsø <hougaard junior gmail com>
Date: Thu Feb 11 17:18:16 2016 +0100
app: open IRC links
Register Polari as handler of IRC URLs and add
support for opening IRC URLs pointing to rooms on
the networks the user have added.
data/org.gnome.Polari.desktop.in | 1 +
src/application.js | 60 +++++++++++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 1 deletions(-)
---
diff --git a/data/org.gnome.Polari.desktop.in b/data/org.gnome.Polari.desktop.in
index b505911..3373cb6 100644
--- a/data/org.gnome.Polari.desktop.in
+++ b/data/org.gnome.Polari.desktop.in
@@ -4,6 +4,7 @@ _Comment=An Internet Relay Chat Client for GNOME
Exec=gapplication launch org.gnome.Polari
Icon=polari
Type=Application
+MimeType=x-scheme-handler/irc;
StartupNotify=true
DBusActivatable=true
X-GNOME-UsesNotifications=true
diff --git a/src/application.js b/src/application.js
index 13fa603..8401b30 100644
--- a/src/application.js
+++ b/src/application.js
@@ -26,7 +26,8 @@ const Application = new Lang.Class({
Signals: { 'prepare-shutdown': {} },
_init: function() {
- this.parent({ application_id: 'org.gnome.Polari' });
+ this.parent({ application_id: 'org.gnome.Polari',
+ flags: Gio.ApplicationFlags.HANDLES_OPEN });
GLib.set_application_name('Polari');
this._window = null;
@@ -146,6 +147,63 @@ const Application = new Lang.Class({
this._window.present();
},
+ vfunc_open: function(files) {
+ this.activate();
+
+ let time = Utils.getTpEventTime();
+ let uris = files.map(function(f) { return f.get_uri(); });
+
+ let quark = Tp.AccountManager.get_feature_quark_core();
+ if (this._accountsMonitor.accountManager.is_prepared(quark))
+ this._openURIs(uris, time);
+ else
+ this._accountsMonitor.connect('account-manager-prepared', Lang.bind(this,
+ function(mon) {
+ this._openURIs(uris, time);
+ }));
+ },
+
+ _openURIs: function(uris, time) {
+ let map = {};
+
+ this._accountsMonitor.dupAccounts().forEach(function(a) {
+ if (!a.enabled)
+ return;
+
+ let params = a.dup_parameters_vardict().deep_unpack();
+ map[a.get_object_path()] = params.server.deep_unpack();
+ });
+
+ let action = this.lookup_action('join-room');
+ uris.forEach(Lang.bind(this, function(uri) {
+ let uriRegEx = /^(irc?:\/\/)([\da-z\.-]+):?(\d+)?\/(?:%23)?([\w \. \+-]*)/;
+ let server, port, room;
+ try {
+ [,, server, port, room] = uri.match(uriRegEx);
+ if (!room) throw new Error('No Room');
+ } catch(e) {
+ let label = _("Could not open the link.");
+ let n = new AppNotifications.CloseNotification(label,
+ 'dialog-error-symbolic');
+ this.notificationQueue.addNotification(n);
+ log("Invalid URI");
+ return;
+ }
+
+ let matches = Object.keys(map).filter(function(a) {
+ return map[a] == server;
+ });
+
+ if (!matches.length) {
+ log("No matching account");
+ return;
+ }
+
+ action.activate(new GLib.Variant('(ssu)',
+ [matches[0], '#' + room, time]));
+ }));
+ },
+
_updateAccountAction: function(action) {
action.enabled = this._accountsMonitor.dupAccounts().filter(
function(a) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]