Allow initial sync to be cancelled by adding a cancel button. Closes #307
This commit is contained in:
parent
1707de4e1c
commit
9aeb848d33
|
@ -25,6 +25,9 @@ namespace SparkleLib {
|
||||||
// Sets up a fetcher that can get remote folders
|
// Sets up a fetcher that can get remote folders
|
||||||
public class SparkleFetcherGit : SparkleFetcherBase {
|
public class SparkleFetcherGit : SparkleFetcherBase {
|
||||||
|
|
||||||
|
private SparkleGit git;
|
||||||
|
|
||||||
|
|
||||||
public SparkleFetcherGit (string server, string remote_folder, string target_folder) :
|
public SparkleFetcherGit (string server, string remote_folder, string target_folder) :
|
||||||
base (server, remote_folder, target_folder)
|
base (server, remote_folder, target_folder)
|
||||||
{
|
{
|
||||||
|
@ -73,15 +76,15 @@ namespace SparkleLib {
|
||||||
|
|
||||||
public override bool Fetch ()
|
public override bool Fetch ()
|
||||||
{
|
{
|
||||||
SparkleGit git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||||
"clone \"" + base.remote_url + "\" " + "\"" + base.target_folder + "\"");
|
"clone \"" + base.remote_url + "\" " + "\"" + base.target_folder + "\"");
|
||||||
|
|
||||||
git.Start ();
|
this.git.Start ();
|
||||||
git.WaitForExit ();
|
this.git.WaitForExit ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "Exit code " + git.ExitCode.ToString ());
|
SparkleHelpers.DebugInfo ("Git", "Exit code " + this.git.ExitCode.ToString ());
|
||||||
|
|
||||||
if (git.ExitCode != 0) {
|
if (this.git.ExitCode != 0) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
InstallConfiguration ();
|
InstallConfiguration ();
|
||||||
|
@ -91,6 +94,17 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void Stop ()
|
||||||
|
{
|
||||||
|
if (this.git != null) {
|
||||||
|
this.git.Kill ();
|
||||||
|
this.git.Dispose ();
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Stop ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Install the user's name and email and some config into
|
// Install the user's name and email and some config into
|
||||||
// the newly cloned repository
|
// the newly cloned repository
|
||||||
private void InstallConfiguration ()
|
private void InstallConfiguration ()
|
||||||
|
|
|
@ -95,6 +95,13 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public virtual void Stop ()
|
||||||
|
{
|
||||||
|
this.thread.Abort ();
|
||||||
|
this.thread.Join ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public string RemoteUrl {
|
public string RemoteUrl {
|
||||||
get {
|
get {
|
||||||
return this.remote_url;
|
return this.remote_url;
|
||||||
|
|
|
@ -307,7 +307,16 @@ namespace SparkleShare {
|
||||||
Enabled = false
|
Enabled = false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CancelButton = new NSButton () {
|
||||||
|
Title = "Cancel"
|
||||||
|
};
|
||||||
|
|
||||||
|
CancelButton.Activated += delegate {
|
||||||
|
Controller.SyncingCancelled ();
|
||||||
|
};
|
||||||
|
|
||||||
Buttons.Add (FinishButton);
|
Buttons.Add (FinishButton);
|
||||||
|
Buttons.Add (CancelButton);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,8 @@ namespace SparkleShare {
|
||||||
public delegate void NotificationRaisedEventHandler (string user_name, string user_email,
|
public delegate void NotificationRaisedEventHandler (string user_name, string user_email,
|
||||||
string message, string repository_path);
|
string message, string repository_path);
|
||||||
|
|
||||||
|
private SparkleFetcherBase fetcher;
|
||||||
|
|
||||||
|
|
||||||
// Short alias for the translations
|
// Short alias for the translations
|
||||||
public static string _ (string s)
|
public static string _ (string s)
|
||||||
|
@ -977,7 +979,6 @@ namespace SparkleShare {
|
||||||
string canonical_name = Path.GetFileNameWithoutExtension (remote_folder);
|
string canonical_name = Path.GetFileNameWithoutExtension (remote_folder);
|
||||||
string tmp_folder = Path.Combine (tmp_path, canonical_name);
|
string tmp_folder = Path.Combine (tmp_path, canonical_name);
|
||||||
|
|
||||||
SparkleFetcherBase fetcher = null;
|
|
||||||
string backend = null;
|
string backend = null;
|
||||||
|
|
||||||
/* if (remote_folder.EndsWith (".hg")) {
|
/* if (remote_folder.EndsWith (".hg")) {
|
||||||
|
@ -991,7 +992,7 @@ namespace SparkleShare {
|
||||||
backend = "Scp";
|
backend = "Scp";
|
||||||
|
|
||||||
} else {*/
|
} else {*/
|
||||||
fetcher = new SparkleFetcherGit (server, remote_folder, tmp_folder);
|
this.fetcher = new SparkleFetcherGit (server, remote_folder, tmp_folder);
|
||||||
backend = "Git";
|
backend = "Git";
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
@ -1011,7 +1012,7 @@ namespace SparkleShare {
|
||||||
if (i > 1)
|
if (i > 1)
|
||||||
target_folder_name += " (" + i + ")";
|
target_folder_name += " (" + i + ")";
|
||||||
|
|
||||||
fetcher.Finished += delegate {
|
this.fetcher.Finished += delegate {
|
||||||
|
|
||||||
// Needed to do the moving
|
// Needed to do the moving
|
||||||
SparkleHelpers.ClearAttributes (tmp_folder);
|
SparkleHelpers.ClearAttributes (tmp_folder);
|
||||||
|
@ -1024,7 +1025,7 @@ namespace SparkleShare {
|
||||||
SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message);
|
SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, fetcher.RemoteUrl, backend);
|
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, this.fetcher.RemoteUrl, backend);
|
||||||
AddRepository (target_folder_path);
|
AddRepository (target_folder_path);
|
||||||
|
|
||||||
if (FolderFetched != null)
|
if (FolderFetched != null)
|
||||||
|
@ -1038,25 +1039,32 @@ namespace SparkleShare {
|
||||||
if (FolderListChanged != null)
|
if (FolderListChanged != null)
|
||||||
FolderListChanged ();
|
FolderListChanged ();
|
||||||
|
|
||||||
fetcher.Dispose ();
|
this.fetcher.Dispose ();
|
||||||
|
|
||||||
if (Directory.Exists (tmp_path))
|
if (Directory.Exists (tmp_path))
|
||||||
Directory.Delete (tmp_path, true);
|
Directory.Delete (tmp_path, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
fetcher.Failed += delegate {
|
this.fetcher.Failed += delegate {
|
||||||
if (FolderFetchError != null)
|
if (FolderFetchError != null)
|
||||||
FolderFetchError ();
|
FolderFetchError ();
|
||||||
|
|
||||||
fetcher.Dispose ();
|
this.fetcher.Dispose ();
|
||||||
|
|
||||||
if (Directory.Exists (tmp_path))
|
if (Directory.Exists (tmp_path))
|
||||||
Directory.Delete (tmp_path, true);
|
Directory.Delete (tmp_path, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
fetcher.Start ();
|
this.fetcher.Start ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void StopFetcher ()
|
||||||
|
{
|
||||||
|
if (fetcher != null)
|
||||||
|
fetcher.Stop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -298,16 +298,21 @@ namespace SparkleShare {
|
||||||
Description = _("This may take a while." + Environment.NewLine) +
|
Description = _("This may take a while." + Environment.NewLine) +
|
||||||
_("Are you sure it’s not coffee o'clock?");
|
_("Are you sure it’s not coffee o'clock?");
|
||||||
|
|
||||||
Button button = new Button () {
|
Button finish_button = new Button () {
|
||||||
Sensitive = false,
|
Sensitive = false,
|
||||||
Label = _("Finish")
|
Label = _("Finish")
|
||||||
};
|
};
|
||||||
|
|
||||||
button.Clicked += delegate {
|
Button cancel_button = new Button () {
|
||||||
Close ();
|
Label = _("Cancel")
|
||||||
};
|
};
|
||||||
|
|
||||||
AddButton (button);
|
cancel_button.Clicked += delegate {
|
||||||
|
Controller.SyncingCancelled ();
|
||||||
|
};
|
||||||
|
|
||||||
|
AddButton (cancel_button);
|
||||||
|
AddButton (finish_button);
|
||||||
|
|
||||||
this.progress_bar_pulse_timer.Elapsed += delegate {
|
this.progress_bar_pulse_timer.Elapsed += delegate {
|
||||||
Application.Invoke (delegate {
|
Application.Invoke (delegate {
|
||||||
|
|
|
@ -132,6 +132,15 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void SyncingCancelled ()
|
||||||
|
{
|
||||||
|
SparkleShare.Controller.StopFetcher ();
|
||||||
|
|
||||||
|
if (ChangePageEvent != null)
|
||||||
|
ChangePageEvent (PageType.Add);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void FinishedPageCompleted ()
|
public void FinishedPageCompleted ()
|
||||||
{
|
{
|
||||||
this.previous_server = "";
|
this.previous_server = "";
|
||||||
|
|
Loading…
Reference in a new issue