Allow invites and plugins to set a custom <announcements_url>. Closes #562

This commit is contained in:
Hylke Bons 2012-02-24 18:50:05 +01:00
parent 71f938b9da
commit 5d7c9a79ac
7 changed files with 101 additions and 58 deletions

View file

@ -18,8 +18,8 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Xml;
using System.Security.Principal;
using System.Xml;
namespace SparkleLib {
@ -167,7 +167,7 @@ namespace SparkleLib {
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
email_node.InnerText = user.Email;
this.Save ();
Save ();
// ConfigureSSH ();
}
@ -252,7 +252,7 @@ namespace SparkleLib {
XmlNode node_root = SelectSingleNode ("/sparkleshare");
node_root.AppendChild (node_folder);
this.Save ();
Save ();
}
@ -263,32 +263,32 @@ namespace SparkleLib {
SelectSingleNode ("/sparkleshare").RemoveChild (node_folder);
}
this.Save ();
Save ();
}
public bool FolderExists (string name)
{
XmlNode folder = this.GetFolder (name);
XmlNode folder = GetFolder (name);
return (folder != null);
}
public string GetBackendForFolder (string name)
{
return this.GetFolderValue (name, "backend");
return GetFolderValue (name, "backend");
}
public string GetUrlForFolder (string name)
{
return this.GetFolderValue (name, "url");
return GetFolderValue (name, "url");
}
public bool SetFolderOptionalAttribute (string folder_name, string key, string value)
{
XmlNode folder = this.GetFolder (folder_name);
XmlNode folder = GetFolder (folder_name);
if (folder == null)
return false;
@ -302,13 +302,14 @@ namespace SparkleLib {
folder.AppendChild (new_node);
}
Save ();
return true;
}
public string GetFolderOptionalAttribute (string folder_name, string key)
{
XmlNode folder = this.GetFolder (folder_name);
XmlNode folder = GetFolder (folder_name);
if (folder != null) {
if (folder [key] != null)
@ -368,7 +369,7 @@ namespace SparkleLib {
private string GetFolderValue (string name, string key)
{
XmlNode folder = this.GetFolder(name);
XmlNode folder = GetFolder(name);
if ((folder != null) && (folder [key] != null)) {
return folder [key].InnerText;
@ -405,7 +406,7 @@ namespace SparkleLib {
}
SparkleHelpers.DebugInfo ("Config", "Updated " + name + ":" + content);
this.Save ();
Save ();
}
@ -414,7 +415,7 @@ namespace SparkleLib {
if (!File.Exists (FullPath))
throw new ConfigFileNotFoundException (FullPath + " does not exist");
this.Save (FullPath);
Save (FullPath);
SparkleHelpers.DebugInfo ("Config", "Updated \"" + FullPath + "\"");
}

View file

@ -47,10 +47,10 @@ namespace SparkleShare {
// start SparkleShare automatically at login
public override void CreateStartupItem ()
{
// TODO: check whether this still works
string autostart_path = Path.Combine (Environment.GetFolderPath (
Environment.SpecialFolder.ApplicationData), "autostart");
string autostart_path = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"autostart"
);
string desktopfile_path = Path.Combine (autostart_path, "sparkleshare.desktop");
@ -58,22 +58,26 @@ namespace SparkleShare {
Directory.CreateDirectory (autostart_path);
if (!File.Exists (desktopfile_path)) {
TextWriter writer = new StreamWriter (desktopfile_path);
writer.WriteLine ("[Desktop Entry]\n" +
"Type=Application\n" +
"Name=SparkleShare\n" +
"Exec=sparkleshare start\n" +
"Icon=folder-sparkleshare\n" +
"Terminal=false\n" +
"X-GNOME-Autostart-enabled=true\n" +
"Categories=Network");
writer.Close ();
try {
File.WriteAllText (desktopfile_path,
"[Desktop Entry]\n" +
"Type=Application\n" +
"Name=SparkleShare\n" +
"Exec=sparkleshare start\n" +
"Icon=folder-sparkleshare\n" +
"Terminal=false\n" +
"X-GNOME-Autostart-enabled=true\n" +
"Categories=Network");
// Give the launcher the right permissions so it can be launched by the user
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
file_info.Create (FileAccessPermissions.UserReadWriteExecute);
// Give the launcher the right permissions so it can be launched by the user
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
file_info.Create (FileAccessPermissions.UserReadWriteExecute);
SparkleHelpers.DebugInfo ("Controller", "Enabled autostart on login");
SparkleHelpers.DebugInfo ("Controller", "Added " + app_path + " to login items");
} catch (Exception e) {
SparkleHelpers.DebugInfo ("Controller", "Failed adding " + app_path + " to login items: " + e.Message);
}
}
}

View file

@ -174,16 +174,18 @@ namespace SparkleShare {
if (InviteReceived != null) {
SparkleInvite invite = new SparkleInvite (args.FullPath);
if (invite.Valid) {
if (invite.IsValid) {
InviteReceived (invite);
File.Delete (args.FullPath);
} else {
invite = null;
if (AlertNotificationRaised != null)
AlertNotificationRaised ("Oh noes!",
"This invite seems screwed up...");
}
File.Delete (args.FullPath);
}
}
};
@ -965,10 +967,14 @@ namespace SparkleShare {
}
public void FetchFolder (string server, string remote_folder)
public void FetchFolder (string server, string remote_folder, string announcements_url)
{
server = server.Trim ();
remote_folder = remote_folder.Trim ();
server = server.Trim ();
remote_folder = remote_folder.Trim ();
if (announcements_url != null)
announcements_url = announcements_url.Trim ();
string tmp_path = SparkleConfig.DefaultConfig.TmpPath;
if (!Directory.Exists (tmp_path)) {
@ -1038,8 +1044,14 @@ namespace SparkleShare {
try {
Directory.Move (tmp_folder, target_folder_path);
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, this.fetcher.RemoteUrl, backend);
if (!string.IsNullOrEmpty (announcements_url)) {
SparkleConfig.DefaultConfig.SetFolderOptionalAttribute (target_folder_name,
"announcements_url", announcements_url);
}
AddRepository (target_folder_path);
if (FolderFetched != null)

View file

@ -30,8 +30,10 @@ namespace SparkleShare {
public string Address { get; private set; }
public string RemotePath { get; private set; }
public Uri AcceptUrl { get; private set; }
public Uri AnnouncementsUrl { get; private set; }
public bool Valid {
public bool IsValid {
get {
return (!string.IsNullOrEmpty (Address) &&
!string.IsNullOrEmpty (RemotePath));
@ -39,9 +41,17 @@ namespace SparkleShare {
}
public SparkleInvite (string address, string remote_path, string accept_url)
public SparkleInvite (string address, string remote_path,
string accept_url)
{
Initialize (address, remote_path, accept_url);
Initialize (address, remote_path, accept_url, null);
}
public SparkleInvite (string address, string remote_path,
string accept_url, string announcements_url)
{
Initialize (address, remote_path, accept_url, announcements_url);
}
@ -50,10 +60,10 @@ namespace SparkleShare {
XmlDocument xml_document = new XmlDocument ();
XmlNode node;
string address = "";
string remote_path = "";
string accept_url = "";
string address = "";
string remote_path = "";
string accept_url = "";
string announcements_url = "";
try {
xml_document.Load (xml_file_path);
@ -67,7 +77,10 @@ namespace SparkleShare {
node = xml_document.SelectSingleNode ("/sparkleshare/invite/accept_url/text()");
if (node != null) { accept_url = node.Value; }
Initialize (address, remote_path, accept_url);
node = xml_document.SelectSingleNode ("/sparkleshare/invite/announcements_url/text()");
if (node != null) { announcements_url = node.Value; }
Initialize (address, remote_path, accept_url, announcements_url);
} catch (XmlException e) {
SparkleHelpers.DebugInfo ("Invite", "Invalid XML: " + e.Message);
@ -115,11 +128,13 @@ namespace SparkleShare {
}
private void Initialize (string address, string remote_path, string accept_url)
private void Initialize (string address, string remote_path,
string accept_url, string announcements_url)
{
Address = address;
RemotePath = remote_path;
AcceptUrl = new Uri (accept_url);
Address = address;
RemotePath = remote_path;
AcceptUrl = new Uri (accept_url);
AnnouncementsUrl = new Uri (announcements_url);
}
}
}

View file

@ -49,6 +49,12 @@ namespace SparkleShare {
}
}
public string AnnouncementsUrl {
get {
return GetValue ("info", "announcements_url");
}
}
public string Address {
get {
return GetValue ("address", "value");

View file

@ -71,12 +71,12 @@ namespace SparkleShare {
public readonly List<SparklePlugin> Plugins = new List<SparklePlugin> ();
public SparklePlugin SelectedPlugin;
public SparkleInvite PendingInvite { get; private set; }
public int TutorialPageNumber { get; private set; }
public string PreviousUrl { get; private set; }
public string PreviousAddress { get; private set; }
public string PreviousPath { get; private set; }
public string SyncingFolder { get; private set; }
public SparkleInvite PendingInvite;
public int SelectedPluginIndex {
@ -135,8 +135,6 @@ namespace SparkleShare {
Program.Controller.InviteReceived += delegate (SparkleInvite invite) {
PendingInvite = invite;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Invite, null);
@ -154,15 +152,21 @@ namespace SparkleShare {
}
if (page_type == PageType.Add) {
if (TutorialPageNumber < 5) {
if (!Program.Controller.FirstRun &&
(TutorialPageNumber == 0 ||
TutorialPageNumber > 4)) {
if (ChangePageEvent != null)
ChangePageEvent (page_type, null);
if (ShowWindowEvent != null)
ShowWindowEvent ();
return;
} else {
SelectedPluginChanged (SelectedPluginIndex);
}
return;
}
if (ChangePageEvent != null)
@ -332,7 +336,7 @@ namespace SparkleShare {
UpdateProgressBarEvent (percentage);
};
Program.Controller.FetchFolder (address, path);
Program.Controller.FetchFolder (address, path, SelectedPlugin.AnnouncementsUrl);
}
@ -383,7 +387,8 @@ namespace SparkleShare {
UpdateProgressBarEvent (percentage);
};
Program.Controller.FetchFolder (PendingInvite.Address, PendingInvite.RemotePath);
Program.Controller.FetchFolder (PendingInvite.Address,
PendingInvite.RemotePath, PendingInvite.AnnouncementsUrl.ToString ());
}

View file

@ -145,7 +145,7 @@ namespace SparkleShare {
public void AddHostedProjectClicked ()
{
Program.Controller.ShowSetupWindow (PageType.Add);
Program.Controller.ShowSetupWindow (PageType.Add);
}