Finish support for invite.xml files dropped in ~/SparkleShare

This commit is contained in:
Hylke Bons 2012-02-17 00:51:44 +01:00
parent 2db5c8366c
commit 44298936ec
8 changed files with 371 additions and 318 deletions

View file

@ -33,10 +33,9 @@ namespace SparkleShare {
public SparkleSetupController Controller = new SparkleSetupController (); public SparkleSetupController Controller = new SparkleSetupController ();
private NSButton ContinueButton; private NSButton ContinueButton;
private NSButton SyncButton; private NSButton AddButton;
private NSButton TryAgainButton; private NSButton TryAgainButton;
private NSButton CancelButton; private NSButton CancelButton;
private NSButton AcceptButton;
private NSButton SkipTutorialButton; private NSButton SkipTutorialButton;
private NSButton OpenFolderButton; private NSButton OpenFolderButton;
private NSButton FinishButton; private NSButton FinishButton;
@ -65,6 +64,18 @@ namespace SparkleShare {
public SparkleSetup () : base () public SparkleSetup () : base ()
{ {
Controller.HideWindowEvent += delegate {
InvokeOnMainThread (delegate {
PerformClose (this);
});
};
Controller.ShowWindowEvent += delegate {
InvokeOnMainThread (delegate {
OrderFrontRegardless ();
});
};
Controller.ChangePageEvent += delegate (PageType type, string [] warnings) { Controller.ChangePageEvent += delegate (PageType type, string [] warnings) {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
Reset (); Reset ();
@ -72,6 +83,7 @@ namespace SparkleShare {
switch (type) { switch (type) {
case PageType.Setup: { case PageType.Setup: {
// TODO: Improve text
Header = "Welcome to SparkleShare!"; Header = "Welcome to SparkleShare!";
Description = "We'll need some info to mark your changes in the event log. " + Description = "We'll need some info to mark your changes in the event log. " +
"Don't worry, this stays between you and your peers."; "Don't worry, this stays between you and your peers.";
@ -165,25 +177,70 @@ namespace SparkleShare {
Description = "Do you want to add this project to SparkleShare?"; Description = "Do you want to add this project to SparkleShare?";
AddressLabel = new NSTextField () {
Alignment = NSTextAlignment.Right,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (165, Frame.Height - 240, 160, 17),
StringValue = "Address:",
Font = SparkleUI.Font
};
PathLabel = new NSTextField () {
Alignment = NSTextAlignment.Right,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (165, Frame.Height - 264, 160, 17),
StringValue = "Remote Path:",
Font = SparkleUI.Font
};
AddressTextField = new NSTextField () {
Alignment = NSTextAlignment.Left,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (330, Frame.Height - 240, 260, 17),
StringValue = Controller.PendingInvite.Address,
Font = SparkleUI.BoldFont
};
PathTextField = new NSTextField () {
Alignment = NSTextAlignment.Left,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (330, Frame.Height - 264, 260, 17),
StringValue = Controller.PendingInvite.RemotePath,
Font = SparkleUI.BoldFont
};
ContentView.AddSubview (AddressLabel);
ContentView.AddSubview (PathLabel);
ContentView.AddSubview (AddressTextField);
ContentView.AddSubview (PathTextField);
CancelButton = new NSButton () { CancelButton = new NSButton () {
Title = "Cancel" Title = "Cancel"
}; };
CancelButton.Activated += delegate { CancelButton.Activated += delegate {
InvokeOnMainThread (delegate { Controller.PageCancelled ();
PerformClose (this);
});
}; };
AcceptButton = new NSButton () { AddButton = new NSButton () {
Title = "Accept" Title = "Add"
}; };
AcceptButton.Activated += delegate { AddButton.Activated += delegate {
Controller.InvitePageCompleted (); Controller.InvitePageCompleted ();
}; };
Buttons.Add (AcceptButton); Buttons.Add (AddButton);
Buttons.Add (CancelButton); Buttons.Add (CancelButton);
break; break;
@ -201,7 +258,7 @@ namespace SparkleShare {
Editable = false, Editable = false,
Frame = new RectangleF (190, Frame.Height - 308, 160, 17), Frame = new RectangleF (190, Frame.Height - 308, 160, 17),
StringValue = "Address:", StringValue = "Address:",
Font = SparkleUI.Font Font = SparkleUI.BoldFont
}; };
AddressTextField = new NSTextField () { AddressTextField = new NSTextField () {
@ -220,7 +277,7 @@ namespace SparkleShare {
Editable = false, Editable = false,
Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17), Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
StringValue = "Remote Path:", StringValue = "Remote Path:",
Font = SparkleUI.Font Font = SparkleUI.BoldFont
}; };
PathTextField = new NSTextField () { PathTextField = new NSTextField () {
@ -345,7 +402,7 @@ namespace SparkleShare {
Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) { Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
SyncButton.Enabled = button_enabled; AddButton.Enabled = button_enabled;
}); });
}; };
@ -357,28 +414,26 @@ namespace SparkleShare {
ContentView.AddSubview (PathTextField); ContentView.AddSubview (PathTextField);
ContentView.AddSubview (PathHelpLabel); ContentView.AddSubview (PathHelpLabel);
SyncButton = new NSButton () { AddButton = new NSButton () {
Title = "Add", Title = "Add",
Enabled = false Enabled = false
}; };
SyncButton.Activated += delegate { AddButton.Activated += delegate {
Controller.AddPageCompleted ( Controller.AddPageCompleted (
AddressTextField.StringValue, AddressTextField.StringValue,
PathTextField.StringValue PathTextField.StringValue
); );
}; };
Buttons.Add (SyncButton); Buttons.Add (AddButton);
CancelButton = new NSButton () { CancelButton = new NSButton () {
Title = "Cancel" Title = "Cancel"
}; };
CancelButton.Activated += delegate { CancelButton.Activated += delegate {
InvokeOnMainThread (delegate { Controller.PageCancelled ();
PerformClose (this);
});
}; };
Buttons.Add (CancelButton); Buttons.Add (CancelButton);
@ -524,10 +579,7 @@ namespace SparkleShare {
}; };
FinishButton.Activated += delegate { FinishButton.Activated += delegate {
InvokeOnMainThread (delegate { Controller.FinishPageCompleted ();
Controller.FinishedPageCompleted ();
PerformClose (this);
});
}; };
OpenFolderButton = new NSButton () { OpenFolderButton = new NSButton () {
@ -674,9 +726,7 @@ namespace SparkleShare {
}; };
FinishButton.Activated += delegate { FinishButton.Activated += delegate {
InvokeOnMainThread (delegate { Controller.TutorialPageCompleted ();
PerformClose (this);
});
}; };
string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,

View file

@ -83,11 +83,6 @@ namespace SparkleShare {
Font = SparkleUI.Font Font = SparkleUI.Font
}; };
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
MakeKeyAndOrderFront (this);
OrderFrontRegardless ();
if (Program.UI != null) if (Program.UI != null)
Program.UI.UpdateDockIconVisibility (); Program.UI.UpdateDockIconVisibility ();
} }
@ -140,6 +135,9 @@ namespace SparkleShare {
public override void OrderFrontRegardless () public override void OrderFrontRegardless ()
{ {
NSApplication.SharedApplication.AddWindowsItem (this, "SparkleShare Setup", false); NSApplication.SharedApplication.AddWindowsItem (this, "SparkleShare Setup", false);
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
MakeKeyAndOrderFront (this);
base.OrderFrontRegardless (); base.OrderFrontRegardless ();
} }

View file

@ -236,20 +236,7 @@ namespace SparkleShare {
if (!Program.Controller.FirstRun) { if (!Program.Controller.FirstRun) {
SyncMenuItem.Activated += delegate { SyncMenuItem.Activated += delegate {
InvokeOnMainThread (delegate { Controller.AddHostedProjectClicked ();
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
if (SparkleUI.Setup == null) {
SparkleUI.Setup = new SparkleSetup ();
SparkleUI.Setup.Controller.ShowAddPage ();
}
if (!SparkleUI.Setup.IsVisible)
SparkleUI.Setup.Controller.ShowAddPage ();
SparkleUI.Setup.OrderFrontRegardless ();
SparkleUI.Setup.MakeKeyAndOrderFront (this);
});
}; };
} }
@ -262,7 +249,9 @@ namespace SparkleShare {
}; };
if (Controller.Folders.Length > 0) { if (Controller.Folders.Length > 0) {
// TODO: move this logic
RecentEventsMenuItem.Activated += delegate { RecentEventsMenuItem.Activated += delegate {
// Controller.OpenRecentEventsClicked ()
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
@ -305,7 +294,9 @@ namespace SparkleShare {
Enabled = true Enabled = true
}; };
// TODO: move this logic
AboutMenuItem.Activated += delegate { AboutMenuItem.Activated += delegate {
// Controller.AboutClicked ();
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);

View file

@ -65,11 +65,11 @@ namespace SparkleShare {
StatusIcon = new SparkleStatusIcon (); StatusIcon = new SparkleStatusIcon ();
Bubbles = new SparkleBubbles (); Bubbles = new SparkleBubbles ();
Setup = new SparkleSetup ();
// About = new SparkleAbout ();
if (Program.Controller.FirstRun) { if (Program.Controller.FirstRun) {
Setup = new SparkleSetup (); Program.Controller.ShowSetupWindow (PageType.Setup);
Setup.Controller.ShowSetupPage ();
UpdateDockIconVisibility (); UpdateDockIconVisibility ();
} }
} }

View file

@ -40,6 +40,17 @@ namespace SparkleShare {
public double ProgressPercentage = 0.0; public double ProgressPercentage = 0.0;
public string ProgressSpeed = ""; public string ProgressSpeed = "";
public event ShowSetupWindowEventHandler ShowSetupWindowEvent;
public delegate void ShowSetupWindowEventHandler (PageType page_type);
public event ShowAboutWindowEventHandler ShowAboutWindowEvent;
public delegate void ShowAboutWindowEventHandler ();
public event ShowEventsWindowEventHandler ShowEventsWindowEvent;
public delegate void ShowEventsWindowEventHandler ();
public event FolderFetchedEventHandler FolderFetched; public event FolderFetchedEventHandler FolderFetched;
public delegate void FolderFetchedEventHandler (string [] warnings); public delegate void FolderFetchedEventHandler (string [] warnings);
@ -64,8 +75,8 @@ namespace SparkleShare {
public event OnErrorHandler OnError; public event OnErrorHandler OnError;
public delegate void OnErrorHandler (); public delegate void OnErrorHandler ();
public event OnInviteHandler OnInvite; public event InviteReceivedHandler InviteReceived;
public delegate void OnInviteHandler (SparkleInvite invite); public delegate void InviteReceivedHandler (SparkleInvite invite);
public event NotificationRaisedEventHandler NotificationRaised; public event NotificationRaisedEventHandler NotificationRaised;
public delegate void NotificationRaisedEventHandler (SparkleChangeSet change_set); public delegate void NotificationRaisedEventHandler (SparkleChangeSet change_set);
@ -130,7 +141,7 @@ namespace SparkleShare {
if (!args.FullPath.EndsWith (".xml")) if (!args.FullPath.EndsWith (".xml"))
return; return;
if (this.fetcher == null || if (this.fetcher != null &&
this.fetcher.IsActive) { this.fetcher.IsActive) {
if (AlertNotificationRaised != null) if (AlertNotificationRaised != null)
@ -138,8 +149,12 @@ namespace SparkleShare {
"Please try again later"); "Please try again later");
} else { } else {
if (OnInvite != null) if (InviteReceived != null) {
OnInvite (new SparkleInvite (args.FullPath)); SparkleInvite invite = new SparkleInvite (args.FullPath);
if (invite.Valid)
InviteReceived (invite);
}
} }
}; };
@ -154,39 +169,6 @@ namespace SparkleShare {
} }
// Uploads the user's public key to the server TODO
public bool AcceptInvitation (string server, string folder, string token)
{
// The location of the user's public key for SparkleShare
string public_key_file_path = SparkleHelpers.CombineMore (SparkleConfig.DefaultConfig.HomePath,
".ssh", "sparkleshare." + UserEmail + ".key.pub");
if (!File.Exists (public_key_file_path))
return false;
StreamReader reader = new StreamReader (public_key_file_path);
string public_key = reader.ReadToEnd ();
reader.Close ();
string url = "https://" + server + "/?folder=" + folder +
"&token=" + token + "&pubkey=" + public_key;
SparkleHelpers.DebugInfo ("WebRequest", url);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK) {
response.Close ();
return true;
} else {
response.Close ();
return false;
}
}
public List<string> Folders { public List<string> Folders {
get { get {
List<string> folders = SparkleConfig.DefaultConfig.Folders; List<string> folders = SparkleConfig.DefaultConfig.Folders;
@ -202,6 +184,7 @@ namespace SparkleShare {
List<string> hosts = SparkleConfig.DefaultConfig.HostsWithUsername; List<string> hosts = SparkleConfig.DefaultConfig.HostsWithUsername;
hosts.AddRange(SparkleConfig.DefaultConfig.Hosts); hosts.AddRange(SparkleConfig.DefaultConfig.Hosts);
hosts.Sort (); hosts.Sort ();
return hosts; return hosts;
} }
} }
@ -221,6 +204,28 @@ namespace SparkleShare {
} }
public void ShowSetupWindow (PageType page_type)
{
if (ShowSetupWindowEvent != null)
ShowSetupWindowEvent (page_type);
}
public void ShowAboutWindow ()
{
if (ShowAboutWindowEvent != null)
ShowAboutWindowEvent ();
}
public void ShowEventsWindow ()
{
if (ShowEventsWindowEvent != null)
ShowEventsWindowEvent ();
}
public List<SparkleChangeSet> GetLog () public List<SparkleChangeSet> GetLog ()
{ {
List<SparkleChangeSet> list = new List<SparkleChangeSet> (); List<SparkleChangeSet> list = new List<SparkleChangeSet> ();

View file

@ -16,12 +16,8 @@
using System; using System;
using System.IO;
using System.Net; using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Xml; using System.Xml;
using System.Threading;
using SparkleLib; using SparkleLib;
@ -29,22 +25,22 @@ namespace SparkleShare {
public class SparkleInvite { public class SparkleInvite {
public readonly string Address; public string Address { get; private set; }
public readonly string RemotePath; public string RemotePath { get; private set; }
public readonly Uri AcceptUrl; public Uri AcceptUrl { get; private set; }
public bool Valid {
get {
return (!string.IsNullOrEmpty (Address) &&
!string.IsNullOrEmpty (RemotePath) &&
!string.IsNullOrEmpty (AcceptUrl.ToString ()));
}
}
public SparkleInvite (string address, string remote_path, string accept_url) public SparkleInvite (string address, string remote_path, string accept_url)
{ {
if (remote_path.StartsWith ("/")) Initialize (address, remote_path, accept_url);
remote_path = remote_path.Substring (1);
if (!address.EndsWith ("/"))
address = address + "/";
Address = address;
RemotePath = remote_path;
AcceptUrl = new Uri (accept_url);
} }
@ -53,7 +49,10 @@ namespace SparkleShare {
XmlDocument xml_document = new XmlDocument (); XmlDocument xml_document = new XmlDocument ();
XmlNode node; XmlNode node;
string address = "", remote_path = "", accept_url = ""; string address = "";
string remote_path = "";
string accept_url = "";
try { try {
xml_document.Load (xml_file_path); xml_document.Load (xml_file_path);
@ -67,21 +66,12 @@ 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);
} catch (XmlException e) { } catch (XmlException e) {
SparkleHelpers.DebugInfo ("Invite", "Invalid XML: " + e.Message); SparkleHelpers.DebugInfo ("Invite", "Invalid XML: " + e.Message);
return; return;
} }
if (remote_path.StartsWith ("/"))
remote_path = remote_path.Substring (1);
if (!address.EndsWith ("/"))
address = address + "/";
Address = address;
RemotePath = remote_path;
AcceptUrl = new Uri (accept_url);
} }
@ -102,5 +92,19 @@ namespace SparkleShare {
return false; return false;
} }
} }
private void Initialize (string address, string remote_path, string accept_url)
{/*
if (!remote_path.StartsWith ("/"))
remote_path = "/" + remote_path;
if (!address.EndsWith ("/"))
address = address + "/";
*/
Address = address;
RemotePath = remote_path;
AcceptUrl = new Uri (accept_url);
}
} }
} }

View file

@ -43,6 +43,12 @@ namespace SparkleShare {
public class SparkleSetupController { public class SparkleSetupController {
public event ShowWindowEventHandler ShowWindowEvent;
public delegate void ShowWindowEventHandler ();
public event HideWindowEventHandler HideWindowEvent;
public delegate void HideWindowEventHandler ();
public event ChangePageEventHandler ChangePageEvent; public event ChangePageEventHandler ChangePageEvent;
public delegate void ChangePageEventHandler (PageType page, string [] warnings); public delegate void ChangePageEventHandler (PageType page, string [] warnings);
@ -60,12 +66,17 @@ namespace SparkleShare {
string example_text, FieldState state); string example_text, FieldState state);
public event ChangePathFieldEventHandler ChangePathFieldEvent; public event ChangePathFieldEventHandler ChangePathFieldEvent;
public delegate void ChangePathFieldEventHandler (string text, public delegate void ChangePathFieldEventHandler (string text, string example_text, FieldState state);
string example_text, FieldState state);
public readonly List<SparklePlugin> Plugins = new List<SparklePlugin> (); public readonly List<SparklePlugin> Plugins = new List<SparklePlugin> ();
public SparklePlugin SelectedPlugin; public SparklePlugin SelectedPlugin;
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 int SelectedPluginIndex { public int SelectedPluginIndex {
get { get {
@ -73,42 +84,6 @@ namespace SparkleShare {
} }
} }
public int TutorialPageNumber {
get {
return this.tutorial_page_number;
}
}
public string PreviousUrl {
get {
return this.previous_url;
}
}
public string PreviousAddress {
get {
return this.previous_address;
}
}
public string PreviousPath {
get {
return this.previous_path;
}
}
public string SyncingFolder {
get {
return this.syncing_folder;
}
}
public PageType PreviousPage {
get {
return this.previous_page;
}
}
public string GuessedUserName { public string GuessedUserName {
get { get {
return Program.Controller.UserName; return Program.Controller.UserName;
@ -125,16 +100,14 @@ namespace SparkleShare {
} }
private string previous_address = "";
private string previous_path = "";
private string previous_url = "";
private string syncing_folder = "";
private int tutorial_page_number = 1;
private PageType previous_page;
public SparkleSetupController () public SparkleSetupController ()
{ {
TutorialPageNumber = 1;
PreviousAddress = "";
PreviousPath = "";
PreviousUrl = "";
SyncingFolder = "";
string local_plugins_path = SparkleHelpers.CombineMore ( string local_plugins_path = SparkleHelpers.CombineMore (
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"sparkleshare", "plugins"); "sparkleshare", "plugins");
@ -154,16 +127,37 @@ namespace SparkleShare {
SelectedPlugin = Plugins [0]; SelectedPlugin = Plugins [0];
ChangePageEvent += delegate (PageType page, string [] warning) {
this.previous_page = page; Program.Controller.InviteReceived += delegate (SparkleInvite invite) {
PendingInvite = invite;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Invite, null);
if (ShowWindowEvent != null)
ShowWindowEvent ();
};
Program.Controller.ShowSetupWindowEvent += delegate (PageType page_type) {
if (ChangePageEvent != null)
ChangePageEvent (page_type, null);
if (ShowWindowEvent != null)
ShowWindowEvent ();
if (page_type == PageType.Add)
SelectedPluginChanged (SelectedPluginIndex);
}; };
} }
public void ShowSetupPage () public void PageCancelled ()
{ {
if (ChangePageEvent != null) // PendingInvite = null;
ChangePageEvent (PageType.Setup, null);
if (HideWindowEvent != null)
HideWindowEvent ();
} }
@ -194,171 +188,27 @@ namespace SparkleShare {
} }
public void TutorialPageCompleted ()
{
this.tutorial_page_number++;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Tutorial, null);
}
public void TutorialSkipped () public void TutorialSkipped ()
{ {
this.tutorial_page_number = 4; TutorialPageNumber = 4;
if (ChangePageEvent != null) if (ChangePageEvent != null)
ChangePageEvent (PageType.Tutorial, null); ChangePageEvent (PageType.Tutorial, null);
} }
public void ShowAddPage () public void TutorialPageCompleted ()
{ {
if (ChangePageEvent != null) TutorialPageNumber++;
ChangePageEvent (PageType.Invite, null);
SelectedPluginChanged (SelectedPluginIndex); if (TutorialPageNumber == 4) {
if (HideWindowEvent != null)
HideWindowEvent ();
} else {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Tutorial, null);
} }
public void CheckAddPage (string address, string remote_path, int selected_plugin)
{
if (SelectedPluginIndex != selected_plugin)
SelectedPluginChanged (selected_plugin);
address = address.Trim ();
remote_path = remote_path.Trim ();
bool fields_valid = address != null && address.Trim().Length > 0 &&
remote_path != null && remote_path.Trim().Length > 0;
if (UpdateAddProjectButtonEvent != null)
UpdateAddProjectButtonEvent (fields_valid);
}
public void AddPageCompleted (string address, string path)
{
this.syncing_folder = Path.GetFileNameWithoutExtension (path);
this.previous_address = address;
this.previous_path = path;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Syncing, null);
// TODO: Remove events afterwards
Program.Controller.FolderFetched += delegate (string [] warnings) {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Finished, warnings);
this.previous_address = "";
this.syncing_folder = "";
this.previous_url = "";
SelectedPlugin = Plugins [0];
};
Program.Controller.FolderFetchError += delegate (string remote_url) {
Thread.Sleep (1000);
this.previous_url = remote_url;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Error, null);
this.syncing_folder = "";
};
Program.Controller.FolderFetching += delegate (double percentage) {
if (UpdateProgressBarEvent != null)
UpdateProgressBarEvent (percentage);
};
Program.Controller.FetchFolder (address, path);
}
public SparkleInvite PendingInvite = new SparkleInvite ("ssh://git@sparkleshare.org/",
"/home/stuff/",
"http://www.sparkleshare.org/");
public void InvitePageCompleted ()
{
if (ChangePageEvent != null)
ChangePageEvent (PageType.Syncing, null);
if (!PendingInvite.Accept ()) {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Error, null);
return;
}
// TODO: Remove events afterwards
Program.Controller.FolderFetched += delegate (string [] warnings) {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Finished, warnings);
this.previous_address = "";
this.syncing_folder = "";
this.previous_url = "";
SelectedPlugin = Plugins [0];
};
Program.Controller.FolderFetchError += delegate (string remote_url) {
Thread.Sleep (1000);
this.previous_url = remote_url;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Error, null);
this.syncing_folder = "";
};
Program.Controller.FolderFetching += delegate (double percentage) {
if (UpdateProgressBarEvent != null)
UpdateProgressBarEvent (percentage);
};
Program.Controller.FetchFolder (PendingInvite.Address, PendingInvite.RemotePath);
}
public void ErrorPageCompleted ()
{
if (ChangePageEvent == null)
return;
if (PendingInvite != null)
ChangePageEvent (PageType.Invite, null);
else
ChangePageEvent (PageType.Add, null);
}
public void SyncingCancelled ()
{
Program.Controller.StopFetcher ();
if (ChangePageEvent == null)
return;
if (PendingInvite != null)
ChangePageEvent (PageType.Invite, null);
else
ChangePageEvent (PageType.Add, null);
}
// TODO: public void WindowClosed () { }
public void FinishedPageCompleted ()
{
this.previous_address = "";
this.previous_path = "";
Program.Controller.UpdateState ();
} }
@ -393,6 +243,155 @@ namespace SparkleShare {
} }
public void CheckAddPage (string address, string remote_path, int selected_plugin)
{
if (SelectedPluginIndex != selected_plugin)
SelectedPluginChanged (selected_plugin);
address = address.Trim ();
remote_path = remote_path.Trim ();
bool fields_valid = address != null && address.Trim().Length > 0 &&
remote_path != null && remote_path.Trim().Length > 0;
if (UpdateAddProjectButtonEvent != null)
UpdateAddProjectButtonEvent (fields_valid);
}
public void AddPageCompleted (string address, string path)
{
SyncingFolder = Path.GetFileNameWithoutExtension (path);
PreviousAddress = address;
PreviousPath = path;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Syncing, null);
// TODO: Remove events afterwards
Program.Controller.FolderFetched += delegate (string [] warnings) {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Finished, warnings);
PreviousAddress = "";
SyncingFolder = "";
PreviousUrl = "";
SelectedPlugin = Plugins [0];
};
Program.Controller.FolderFetchError += delegate (string remote_url) {
Thread.Sleep (1000);
PreviousUrl = remote_url;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Error, null);
SyncingFolder = "";
};
Program.Controller.FolderFetching += delegate (double percentage) {
if (UpdateProgressBarEvent != null)
UpdateProgressBarEvent (percentage);
};
Program.Controller.FetchFolder (address, path);
}
// TODO: trailing slash should work
public SparkleInvite PendingInvite = new SparkleInvite ("ssh://git@github.com/",
"/hbons/Stuff", "http://www.sparkleshare.org/");
public void InvitePageCompleted ()
{
SyncingFolder = Path.GetFileNameWithoutExtension (PendingInvite.RemotePath);
PreviousAddress = PendingInvite.Address;
PreviousPath = PendingInvite.RemotePath;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Syncing, null);
if (!PendingInvite.Accept ()) {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Error, null);
return;
}
// TODO: Remove events afterwards
Program.Controller.FolderFetched += delegate (string [] warnings) {
if (ChangePageEvent != null)
ChangePageEvent (PageType.Finished, warnings);
PreviousAddress = "";
SyncingFolder = "";
PreviousUrl = "";
SelectedPlugin = Plugins [0];
PendingInvite = null;
};
Program.Controller.FolderFetchError += delegate (string remote_url) {
Thread.Sleep (1000);
PreviousUrl = remote_url;
if (ChangePageEvent != null)
ChangePageEvent (PageType.Error, null);
SyncingFolder = "";
};
Program.Controller.FolderFetching += delegate (double percentage) {
if (UpdateProgressBarEvent != null)
UpdateProgressBarEvent (percentage);
};
Program.Controller.FetchFolder (PendingInvite.Address, PendingInvite.RemotePath);
}
public void SyncingCancelled ()
{
Program.Controller.StopFetcher ();
if (ChangePageEvent == null)
return;
if (PendingInvite != null)
ChangePageEvent (PageType.Invite, null);
else
ChangePageEvent (PageType.Add, null);
}
public void ErrorPageCompleted ()
{
if (ChangePageEvent == null)
return;
if (PendingInvite != null)
ChangePageEvent (PageType.Invite, null);
else
ChangePageEvent (PageType.Add, null);
}
public void FinishPageCompleted ()
{
PreviousAddress = "";
PreviousPath = "";
Program.Controller.UpdateState ();
if (HideWindowEvent != null)
HideWindowEvent ();
}
private bool IsValidEmail (string email) private bool IsValidEmail (string email)
{ {
Regex regex = new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", Regex regex = new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$",

View file

@ -129,5 +129,11 @@ namespace SparkleShare {
UpdateMenuEvent (IconState.Error); UpdateMenuEvent (IconState.Error);
}; };
} }
public void AddHostedProjectClicked ()
{
Program.Controller.ShowSetupWindow (PageType.Add);
}
} }
} }