linux: Implement handling of sparkleshare:// links
This commit is contained in:
parent
b9c1424f7c
commit
4c1794e792
|
@ -75,7 +75,31 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public override void InstallProtocolHandler ()
|
public override void InstallProtocolHandler ()
|
||||||
{
|
{
|
||||||
// TODO
|
// sparkleshare-invite-opener.desktop launches the handler on newer
|
||||||
|
// systems (like GNOME 3) that implement the last freedesktop.org specs.
|
||||||
|
// For GNOME 2 however we need to tell gconf about the protocol manually
|
||||||
|
Console.WriteLine ();
|
||||||
|
try {
|
||||||
|
// Add the handler to gconf...
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.FileName = "gconftool-2";
|
||||||
|
process.StartInfo.Arguments =
|
||||||
|
"-s /desktop/gnome/url-handlers/sparkleshare/command 'sparkleshare open %s' --type String";
|
||||||
|
|
||||||
|
process.Start ();
|
||||||
|
process.WaitForExit ();
|
||||||
|
|
||||||
|
|
||||||
|
// ...and enable it
|
||||||
|
process.StartInfo.Arguments =
|
||||||
|
"-s /desktop/gnome/url-handlers/sparkleshare/enabled --type Boolean true";
|
||||||
|
|
||||||
|
process.Start ();
|
||||||
|
process.WaitForExit ();
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
// Pity...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,17 @@ namespace SparkleShare {
|
||||||
if (InviteReceived != null) {
|
if (InviteReceived != null) {
|
||||||
SparkleInvite invite = new SparkleInvite (args.FullPath);
|
SparkleInvite invite = new SparkleInvite (args.FullPath);
|
||||||
|
|
||||||
|
// It may be that the invite we received a path to isn't
|
||||||
|
// fully downloaded yet, so we try to read it several times
|
||||||
|
int tries = 0;
|
||||||
|
while (!invite.IsValid) {
|
||||||
|
Thread.Sleep (1 * 250);
|
||||||
|
invite = new SparkleInvite (args.FullPath);
|
||||||
|
tries++;
|
||||||
|
if (tries > 20)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (invite.IsValid) {
|
if (invite.IsValid) {
|
||||||
InviteReceived (invite);
|
InviteReceived (invite);
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,6 @@ namespace SparkleShare {
|
||||||
new string [] {SparkleUI.AssetsPath, "icons",
|
new string [] {SparkleUI.AssetsPath, "icons",
|
||||||
"hicolor", "12x12", "status", "document-moved.png"}.Combine ());
|
"hicolor", "12x12", "status", "document-moved.png"}.Combine ());
|
||||||
|
|
||||||
Console.WriteLine (html);
|
|
||||||
|
|
||||||
Application.Invoke (delegate {
|
Application.Invoke (delegate {
|
||||||
this.spinner.Stop ();
|
this.spinner.Stop ();
|
||||||
|
|
|
@ -29,8 +29,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public string Address { get; private set; }
|
public string Address { get; private set; }
|
||||||
public string RemotePath { get; private set; }
|
public string RemotePath { get; private set; }
|
||||||
public Uri AcceptUrl { get; private set; }
|
public string AcceptUrl { get; private set; }
|
||||||
public Uri AnnouncementsUrl { get; private set; }
|
public string AnnouncementsUrl { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
public bool IsValid {
|
public bool IsValid {
|
||||||
|
@ -68,6 +68,7 @@ namespace SparkleShare {
|
||||||
try {
|
try {
|
||||||
xml_document.Load (xml_file_path);
|
xml_document.Load (xml_file_path);
|
||||||
|
|
||||||
|
|
||||||
node = xml_document.SelectSingleNode ("/sparkleshare/invite/address/text()");
|
node = xml_document.SelectSingleNode ("/sparkleshare/invite/address/text()");
|
||||||
if (node != null) { address = node.Value; }
|
if (node != null) { address = node.Value; }
|
||||||
|
|
||||||
|
@ -80,6 +81,7 @@ namespace SparkleShare {
|
||||||
node = xml_document.SelectSingleNode ("/sparkleshare/invite/announcements_url/text()");
|
node = xml_document.SelectSingleNode ("/sparkleshare/invite/announcements_url/text()");
|
||||||
if (node != null) { announcements_url = node.Value; }
|
if (node != null) { announcements_url = node.Value; }
|
||||||
|
|
||||||
|
|
||||||
Initialize (address, remote_path, accept_url, announcements_url);
|
Initialize (address, remote_path, accept_url, announcements_url);
|
||||||
|
|
||||||
} catch (XmlException e) {
|
} catch (XmlException e) {
|
||||||
|
@ -91,7 +93,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public bool Accept ()
|
public bool Accept ()
|
||||||
{
|
{
|
||||||
if (AcceptUrl == null)
|
if (string.IsNullOrEmpty (AcceptUrl))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -133,8 +135,8 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
Address = address;
|
Address = address;
|
||||||
RemotePath = remote_path;
|
RemotePath = remote_path;
|
||||||
AcceptUrl = new Uri (accept_url);
|
AcceptUrl = accept_url;
|
||||||
AnnouncementsUrl = new Uri (announcements_url);
|
AnnouncementsUrl = announcements_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,7 +330,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
case PageType.Invite: {
|
case PageType.Invite: {
|
||||||
|
|
||||||
Header = _("You've reveived an invite!");
|
Header = _("You've received an invite!");
|
||||||
Description = _("Do you want to add this project to SparkleShare?");
|
Description = _("Do you want to add this project to SparkleShare?");
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
|
|
||||||
Program.Controller.InviteReceived += delegate (SparkleInvite invite) {
|
Program.Controller.InviteReceived += delegate (SparkleInvite invite) {
|
||||||
|
PendingInvite = invite;
|
||||||
|
|
||||||
if (ChangePageEvent != null)
|
if (ChangePageEvent != null)
|
||||||
ChangePageEvent (PageType.Invite, null);
|
ChangePageEvent (PageType.Invite, null);
|
||||||
|
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
// SparkleShare, a collaboration and sharing tool.
|
|
||||||
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
namespace SparkleShare {
|
|
||||||
|
|
||||||
public class SparkleShare {
|
|
||||||
|
|
||||||
public static void Main (string [] args) {
|
|
||||||
|
|
||||||
new SparkleInviteOpen (args [0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class SparkleInviteOpen {
|
|
||||||
|
|
||||||
public SparkleInviteOpen (string url)
|
|
||||||
{
|
|
||||||
string safe_url = url.Replace ("sparkleshare://", "https://");
|
|
||||||
string unsafe_url = url.Replace ("sparkleshare://", "http://");
|
|
||||||
string xml = "";
|
|
||||||
|
|
||||||
WebClient web_client = new WebClient ();
|
|
||||||
|
|
||||||
try {
|
|
||||||
xml = web_client.DownloadString (safe_url);
|
|
||||||
|
|
||||||
} catch {
|
|
||||||
Console.WriteLine ("Failed downloading invite: " + safe_url);
|
|
||||||
|
|
||||||
try {
|
|
||||||
xml = web_client.DownloadString (safe_url);
|
|
||||||
|
|
||||||
} catch {
|
|
||||||
Console.WriteLine ("Failed downloading invite: " + unsafe_url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string home_path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
|
|
||||||
string target_path = Path.Combine (home_path, "SparkleShare");
|
|
||||||
|
|
||||||
if (xml.Contains ("<sparkleshare>")) {
|
|
||||||
File.WriteAllText (target_path, xml);
|
|
||||||
Console.WriteLine ("Downloaded invite: " + safe_url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,3 +4,4 @@ Name=SparkleShareInviteOpener
|
||||||
Exec=sparkleshare open %U
|
Exec=sparkleshare open %U
|
||||||
Terminal=false
|
Terminal=false
|
||||||
MimeType=application/x-sparkleshare;x-scheme-handler/sparkleshare;
|
MimeType=application/x-sparkleshare;x-scheme-handler/sparkleshare;
|
||||||
|
NoDisplay=true
|
||||||
|
|
|
@ -62,7 +62,8 @@ case $1 in
|
||||||
start
|
start
|
||||||
;;
|
;;
|
||||||
open|--open)
|
open|--open)
|
||||||
curl -o ~/SparkleShare/`date -u +%N`.xml `echo $2 | sed s/sparkleshare:/https:/`
|
invite=`date -u +%N`
|
||||||
|
curl -o ~/SparkleShare/$invite.xml `echo $2 | sed s/sparkleshare:/http:/`
|
||||||
;;
|
;;
|
||||||
help|--help|-h)
|
help|--help|-h)
|
||||||
mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help
|
mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help
|
||||||
|
|
Loading…
Reference in a new issue