Allow initial sync to be cancelled by adding a cancel button. Closes #307

This commit is contained in:
Hylke Bons 2011-08-26 22:47:46 +02:00
parent fd8b1697de
commit 79f3473467
6 changed files with 71 additions and 19 deletions

View file

@ -25,6 +25,9 @@ namespace SparkleLib {
// Sets up a fetcher that can get remote folders
public class SparkleFetcherGit : SparkleFetcherBase {
private SparkleGit git;
public SparkleFetcherGit (string server, string remote_folder, string target_folder) :
base (server, remote_folder, target_folder)
{
@ -73,15 +76,15 @@ namespace SparkleLib {
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 + "\"");
git.Start ();
git.WaitForExit ();
this.git.Start ();
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;
} else {
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
// the newly cloned repository
private void InstallConfiguration ()

View file

@ -95,6 +95,13 @@ namespace SparkleLib {
}
public virtual void Stop ()
{
this.thread.Abort ();
this.thread.Join ();
}
public string RemoteUrl {
get {
return this.remote_url;

View file

@ -49,7 +49,7 @@ namespace SparkleShare {
private NSButtonCell ButtonCellProto;
private NSMatrix Matrix;
private int ServerType;
private Timer timer;
private Timer timer;
public SparkleSetup () : base ()
@ -307,7 +307,16 @@ namespace SparkleShare {
Enabled = false
};
CancelButton = new NSButton () {
Title = "Cancel"
};
CancelButton.Activated += delegate {
Controller.SyncingCancelled ();
};
Buttons.Add (FinishButton);
Buttons.Add (CancelButton);
break;
}

View file

@ -75,7 +75,9 @@ namespace SparkleShare {
public delegate void NotificationRaisedEventHandler (string user_name, string user_email,
string message, string repository_path);
private SparkleFetcherBase fetcher;
// Short alias for the translations
public static string _ (string s)
{
@ -977,7 +979,6 @@ namespace SparkleShare {
string canonical_name = Path.GetFileNameWithoutExtension (remote_folder);
string tmp_folder = Path.Combine (tmp_path, canonical_name);
SparkleFetcherBase fetcher = null;
string backend = null;
/* if (remote_folder.EndsWith (".hg")) {
@ -991,7 +992,7 @@ namespace SparkleShare {
backend = "Scp";
} else {*/
fetcher = new SparkleFetcherGit (server, remote_folder, tmp_folder);
this.fetcher = new SparkleFetcherGit (server, remote_folder, tmp_folder);
backend = "Git";
//}
@ -1011,7 +1012,7 @@ namespace SparkleShare {
if (i > 1)
target_folder_name += " (" + i + ")";
fetcher.Finished += delegate {
this.fetcher.Finished += delegate {
// Needed to do the moving
SparkleHelpers.ClearAttributes (tmp_folder);
@ -1024,7 +1025,7 @@ namespace SparkleShare {
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);
if (FolderFetched != null)
@ -1038,25 +1039,32 @@ namespace SparkleShare {
if (FolderListChanged != null)
FolderListChanged ();
fetcher.Dispose ();
this.fetcher.Dispose ();
if (Directory.Exists (tmp_path))
Directory.Delete (tmp_path, true);
};
fetcher.Failed += delegate {
this.fetcher.Failed += delegate {
if (FolderFetchError != null)
FolderFetchError ();
fetcher.Dispose ();
this.fetcher.Dispose ();
if (Directory.Exists (tmp_path))
Directory.Delete (tmp_path, true);
};
fetcher.Start ();
this.fetcher.Start ();
}
public void StopFetcher ()
{
if (fetcher != null)
fetcher.Stop ();
}

View file

@ -298,16 +298,21 @@ namespace SparkleShare {
Description = _("This may take a while." + Environment.NewLine) +
_("Are you sure its not coffee o'clock?");
Button button = new Button () {
Button finish_button = new Button () {
Sensitive = false,
Label = _("Finish")
};
button.Clicked += delegate {
Close ();
Button cancel_button = new Button () {
Label = _("Cancel")
};
AddButton (button);
cancel_button.Clicked += delegate {
Controller.SyncingCancelled ();
};
AddButton (cancel_button);
AddButton (finish_button);
this.progress_bar_pulse_timer.Elapsed += delegate {
Application.Invoke (delegate {

View file

@ -132,6 +132,15 @@ namespace SparkleShare {
}
public void SyncingCancelled ()
{
SparkleShare.Controller.StopFetcher ();
if (ChangePageEvent != null)
ChangePageEvent (PageType.Add);
}
public void FinishedPageCompleted ()
{
this.previous_server = "";