Allow invites and plugins to set a custom <announcements_url>. Closes #562
This commit is contained in:
parent
71f938b9da
commit
5d7c9a79ac
|
@ -18,8 +18,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Xml;
|
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
namespace SparkleLib {
|
namespace SparkleLib {
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ namespace SparkleLib {
|
||||||
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
|
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
|
||||||
email_node.InnerText = user.Email;
|
email_node.InnerText = user.Email;
|
||||||
|
|
||||||
this.Save ();
|
Save ();
|
||||||
|
|
||||||
// ConfigureSSH ();
|
// ConfigureSSH ();
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ namespace SparkleLib {
|
||||||
XmlNode node_root = SelectSingleNode ("/sparkleshare");
|
XmlNode node_root = SelectSingleNode ("/sparkleshare");
|
||||||
node_root.AppendChild (node_folder);
|
node_root.AppendChild (node_folder);
|
||||||
|
|
||||||
this.Save ();
|
Save ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,32 +263,32 @@ namespace SparkleLib {
|
||||||
SelectSingleNode ("/sparkleshare").RemoveChild (node_folder);
|
SelectSingleNode ("/sparkleshare").RemoveChild (node_folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Save ();
|
Save ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool FolderExists (string name)
|
public bool FolderExists (string name)
|
||||||
{
|
{
|
||||||
XmlNode folder = this.GetFolder (name);
|
XmlNode folder = GetFolder (name);
|
||||||
return (folder != null);
|
return (folder != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string GetBackendForFolder (string name)
|
public string GetBackendForFolder (string name)
|
||||||
{
|
{
|
||||||
return this.GetFolderValue (name, "backend");
|
return GetFolderValue (name, "backend");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string GetUrlForFolder (string name)
|
public string GetUrlForFolder (string name)
|
||||||
{
|
{
|
||||||
return this.GetFolderValue (name, "url");
|
return GetFolderValue (name, "url");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool SetFolderOptionalAttribute (string folder_name, string key, string value)
|
public bool SetFolderOptionalAttribute (string folder_name, string key, string value)
|
||||||
{
|
{
|
||||||
XmlNode folder = this.GetFolder (folder_name);
|
XmlNode folder = GetFolder (folder_name);
|
||||||
|
|
||||||
if (folder == null)
|
if (folder == null)
|
||||||
return false;
|
return false;
|
||||||
|
@ -302,13 +302,14 @@ namespace SparkleLib {
|
||||||
folder.AppendChild (new_node);
|
folder.AppendChild (new_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Save ();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string GetFolderOptionalAttribute (string folder_name, string key)
|
public string GetFolderOptionalAttribute (string folder_name, string key)
|
||||||
{
|
{
|
||||||
XmlNode folder = this.GetFolder (folder_name);
|
XmlNode folder = GetFolder (folder_name);
|
||||||
|
|
||||||
if (folder != null) {
|
if (folder != null) {
|
||||||
if (folder [key] != null)
|
if (folder [key] != null)
|
||||||
|
@ -368,7 +369,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
private string GetFolderValue (string name, string key)
|
private string GetFolderValue (string name, string key)
|
||||||
{
|
{
|
||||||
XmlNode folder = this.GetFolder(name);
|
XmlNode folder = GetFolder(name);
|
||||||
|
|
||||||
if ((folder != null) && (folder [key] != null)) {
|
if ((folder != null) && (folder [key] != null)) {
|
||||||
return folder [key].InnerText;
|
return folder [key].InnerText;
|
||||||
|
@ -405,7 +406,7 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Config", "Updated " + name + ":" + content);
|
SparkleHelpers.DebugInfo ("Config", "Updated " + name + ":" + content);
|
||||||
this.Save ();
|
Save ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -414,7 +415,7 @@ namespace SparkleLib {
|
||||||
if (!File.Exists (FullPath))
|
if (!File.Exists (FullPath))
|
||||||
throw new ConfigFileNotFoundException (FullPath + " does not exist");
|
throw new ConfigFileNotFoundException (FullPath + " does not exist");
|
||||||
|
|
||||||
this.Save (FullPath);
|
Save (FullPath);
|
||||||
SparkleHelpers.DebugInfo ("Config", "Updated \"" + FullPath + "\"");
|
SparkleHelpers.DebugInfo ("Config", "Updated \"" + FullPath + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,10 @@ namespace SparkleShare {
|
||||||
// start SparkleShare automatically at login
|
// start SparkleShare automatically at login
|
||||||
public override void CreateStartupItem ()
|
public override void CreateStartupItem ()
|
||||||
{
|
{
|
||||||
// TODO: check whether this still works
|
string autostart_path = Path.Combine (
|
||||||
|
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
|
||||||
string autostart_path = Path.Combine (Environment.GetFolderPath (
|
"autostart"
|
||||||
Environment.SpecialFolder.ApplicationData), "autostart");
|
);
|
||||||
|
|
||||||
string desktopfile_path = Path.Combine (autostart_path, "sparkleshare.desktop");
|
string desktopfile_path = Path.Combine (autostart_path, "sparkleshare.desktop");
|
||||||
|
|
||||||
|
@ -58,22 +58,26 @@ namespace SparkleShare {
|
||||||
Directory.CreateDirectory (autostart_path);
|
Directory.CreateDirectory (autostart_path);
|
||||||
|
|
||||||
if (!File.Exists (desktopfile_path)) {
|
if (!File.Exists (desktopfile_path)) {
|
||||||
TextWriter writer = new StreamWriter (desktopfile_path);
|
try {
|
||||||
writer.WriteLine ("[Desktop Entry]\n" +
|
File.WriteAllText (desktopfile_path,
|
||||||
"Type=Application\n" +
|
"[Desktop Entry]\n" +
|
||||||
"Name=SparkleShare\n" +
|
"Type=Application\n" +
|
||||||
"Exec=sparkleshare start\n" +
|
"Name=SparkleShare\n" +
|
||||||
"Icon=folder-sparkleshare\n" +
|
"Exec=sparkleshare start\n" +
|
||||||
"Terminal=false\n" +
|
"Icon=folder-sparkleshare\n" +
|
||||||
"X-GNOME-Autostart-enabled=true\n" +
|
"Terminal=false\n" +
|
||||||
"Categories=Network");
|
"X-GNOME-Autostart-enabled=true\n" +
|
||||||
writer.Close ();
|
"Categories=Network");
|
||||||
|
|
||||||
// Give the launcher the right permissions so it can be launched by the user
|
// Give the launcher the right permissions so it can be launched by the user
|
||||||
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
|
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
|
||||||
file_info.Create (FileAccessPermissions.UserReadWriteExecute);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,16 +174,18 @@ namespace SparkleShare {
|
||||||
if (InviteReceived != null) {
|
if (InviteReceived != null) {
|
||||||
SparkleInvite invite = new SparkleInvite (args.FullPath);
|
SparkleInvite invite = new SparkleInvite (args.FullPath);
|
||||||
|
|
||||||
if (invite.Valid) {
|
if (invite.IsValid) {
|
||||||
InviteReceived (invite);
|
InviteReceived (invite);
|
||||||
File.Delete (args.FullPath);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
invite = null;
|
||||||
|
|
||||||
if (AlertNotificationRaised != null)
|
if (AlertNotificationRaised != null)
|
||||||
AlertNotificationRaised ("Oh noes!",
|
AlertNotificationRaised ("Oh noes!",
|
||||||
"This invite seems screwed up...");
|
"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 ();
|
server = server.Trim ();
|
||||||
remote_folder = remote_folder.Trim ();
|
remote_folder = remote_folder.Trim ();
|
||||||
|
|
||||||
|
if (announcements_url != null)
|
||||||
|
announcements_url = announcements_url.Trim ();
|
||||||
|
|
||||||
|
|
||||||
string tmp_path = SparkleConfig.DefaultConfig.TmpPath;
|
string tmp_path = SparkleConfig.DefaultConfig.TmpPath;
|
||||||
if (!Directory.Exists (tmp_path)) {
|
if (!Directory.Exists (tmp_path)) {
|
||||||
|
@ -1038,8 +1044,14 @@ namespace SparkleShare {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Directory.Move (tmp_folder, target_folder_path);
|
Directory.Move (tmp_folder, target_folder_path);
|
||||||
|
|
||||||
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, this.fetcher.RemoteUrl, backend);
|
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);
|
AddRepository (target_folder_path);
|
||||||
|
|
||||||
if (FolderFetched != null)
|
if (FolderFetched != null)
|
||||||
|
|
|
@ -30,8 +30,10 @@ 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 Uri AcceptUrl { get; private set; }
|
||||||
|
public Uri AnnouncementsUrl { get; private set; }
|
||||||
|
|
||||||
public bool Valid {
|
|
||||||
|
public bool IsValid {
|
||||||
get {
|
get {
|
||||||
return (!string.IsNullOrEmpty (Address) &&
|
return (!string.IsNullOrEmpty (Address) &&
|
||||||
!string.IsNullOrEmpty (RemotePath));
|
!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 ();
|
XmlDocument xml_document = new XmlDocument ();
|
||||||
XmlNode node;
|
XmlNode node;
|
||||||
|
|
||||||
string address = "";
|
string address = "";
|
||||||
string remote_path = "";
|
string remote_path = "";
|
||||||
string accept_url = "";
|
string accept_url = "";
|
||||||
|
string announcements_url = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
xml_document.Load (xml_file_path);
|
xml_document.Load (xml_file_path);
|
||||||
|
@ -67,7 +77,10 @@ namespace SparkleShare {
|
||||||
node = xml_document.SelectSingleNode ("/sparkleshare/invite/accept_url/text()");
|
node = xml_document.SelectSingleNode ("/sparkleshare/invite/accept_url/text()");
|
||||||
if (node != null) { accept_url = node.Value; }
|
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) {
|
} catch (XmlException e) {
|
||||||
SparkleHelpers.DebugInfo ("Invite", "Invalid XML: " + e.Message);
|
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;
|
Address = address;
|
||||||
RemotePath = remote_path;
|
RemotePath = remote_path;
|
||||||
AcceptUrl = new Uri (accept_url);
|
AcceptUrl = new Uri (accept_url);
|
||||||
|
AnnouncementsUrl = new Uri (announcements_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,12 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string AnnouncementsUrl {
|
||||||
|
get {
|
||||||
|
return GetValue ("info", "announcements_url");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string Address {
|
public string Address {
|
||||||
get {
|
get {
|
||||||
return GetValue ("address", "value");
|
return GetValue ("address", "value");
|
||||||
|
|
|
@ -71,12 +71,12 @@ namespace SparkleShare {
|
||||||
public readonly List<SparklePlugin> Plugins = new List<SparklePlugin> ();
|
public readonly List<SparklePlugin> Plugins = new List<SparklePlugin> ();
|
||||||
public SparklePlugin SelectedPlugin;
|
public SparklePlugin SelectedPlugin;
|
||||||
|
|
||||||
|
public SparkleInvite PendingInvite { get; private set; }
|
||||||
public int TutorialPageNumber { get; private set; }
|
public int TutorialPageNumber { get; private set; }
|
||||||
public string PreviousUrl { get; private set; }
|
public string PreviousUrl { get; private set; }
|
||||||
public string PreviousAddress { get; private set; }
|
public string PreviousAddress { get; private set; }
|
||||||
public string PreviousPath { get; private set; }
|
public string PreviousPath { get; private set; }
|
||||||
public string SyncingFolder { get; private set; }
|
public string SyncingFolder { get; private set; }
|
||||||
public SparkleInvite PendingInvite;
|
|
||||||
|
|
||||||
|
|
||||||
public int SelectedPluginIndex {
|
public int SelectedPluginIndex {
|
||||||
|
@ -135,8 +135,6 @@ 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);
|
||||||
|
|
||||||
|
@ -154,15 +152,21 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page_type == PageType.Add) {
|
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)
|
if (ShowWindowEvent != null)
|
||||||
ShowWindowEvent ();
|
ShowWindowEvent ();
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SelectedPluginChanged (SelectedPluginIndex);
|
SelectedPluginChanged (SelectedPluginIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChangePageEvent != null)
|
if (ChangePageEvent != null)
|
||||||
|
@ -332,7 +336,7 @@ namespace SparkleShare {
|
||||||
UpdateProgressBarEvent (percentage);
|
UpdateProgressBarEvent (percentage);
|
||||||
};
|
};
|
||||||
|
|
||||||
Program.Controller.FetchFolder (address, path);
|
Program.Controller.FetchFolder (address, path, SelectedPlugin.AnnouncementsUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -383,7 +387,8 @@ namespace SparkleShare {
|
||||||
UpdateProgressBarEvent (percentage);
|
UpdateProgressBarEvent (percentage);
|
||||||
};
|
};
|
||||||
|
|
||||||
Program.Controller.FetchFolder (PendingInvite.Address, PendingInvite.RemotePath);
|
Program.Controller.FetchFolder (PendingInvite.Address,
|
||||||
|
PendingInvite.RemotePath, PendingInvite.AnnouncementsUrl.ToString ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public void AddHostedProjectClicked ()
|
public void AddHostedProjectClicked ()
|
||||||
{
|
{
|
||||||
Program.Controller.ShowSetupWindow (PageType.Add);
|
Program.Controller.ShowSetupWindow (PageType.Add);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue