repo: rename and reduce number of enums in SyncStatus. ditch IsSyncing member

This commit is contained in:
Hylke Bons 2011-05-18 16:34:31 +01:00
parent 04cc6debfd
commit 685fa91e47
2 changed files with 34 additions and 41 deletions

View file

@ -28,13 +28,12 @@ using Mono.Unix;
namespace SparkleLib { namespace SparkleLib {
public enum SyncStatus { public enum SyncStatus {
SyncUpStarted, Idle,
SyncUpFinished, SyncUp,
SyncUpFailed, SyncDown,
SyncDownStarted, Error
SyncDownFinished, }
SyncDownFailed
} // TODO: Idle, Error, SyncingUp, SyncingDown
public class SparkleRepo { public class SparkleRepo {
@ -47,7 +46,6 @@ namespace SparkleLib {
private bool has_changed; private bool has_changed;
private string revision; private string revision;
private bool is_syncing;
private bool is_buffering; private bool is_buffering;
private bool is_polling; private bool is_polling;
private bool server_online; private bool server_online;
@ -81,12 +79,6 @@ namespace SparkleLib {
} }
} }
public bool IsSyncing {
get {
return this.is_syncing;
}
}
public bool HasUnsyncedChanges { public bool HasUnsyncedChanges {
get { get {
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath, string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath,
@ -144,7 +136,6 @@ namespace SparkleLib {
UserEmail = GetUserEmail (); UserEmail = GetUserEmail ();
Backend = backend; Backend = backend;
this.is_syncing = false;
this.is_buffering = false; this.is_buffering = false;
this.is_polling = true; this.is_polling = true;
this.server_online = true; this.server_online = true;
@ -221,7 +212,10 @@ namespace SparkleLib {
// Fetch changes when there is a message in the irc channel // Fetch changes when there is a message in the irc channel
this.listener.RemoteChange += delegate (string change_id) { this.listener.RemoteChange += delegate (string change_id) {
if (!change_id.Equals (this.revision) && change_id.Length == 40) { if (!change_id.Equals (this.revision) && change_id.Length == 40) {
if (!this.is_syncing && !this.is_buffering) { if (Status != SyncStatus.SyncUp &&
Status != SyncStatus.SyncDown &&
!this.is_buffering) {
while (this.listener.ChangesQueue > 0) { while (this.listener.ChangesQueue > 0) {
Fetch (); Fetch ();
this.listener.DecrementChangesQueue (); this.listener.DecrementChangesQueue ();
@ -317,9 +311,9 @@ namespace SparkleLib {
DirectoryInfo dir_info = new DirectoryInfo (LocalPath); DirectoryInfo dir_info = new DirectoryInfo (LocalPath);
this.sizebuffer.Add (CalculateFolderSize (dir_info)); this.sizebuffer.Add (CalculateFolderSize (dir_info));
if ( this.sizebuffer [0].Equals ( this.sizebuffer [1]) && if ( this.sizebuffer [0].Equals (this.sizebuffer [1]) &&
this.sizebuffer [1].Equals ( this.sizebuffer [2]) && this.sizebuffer [1].Equals (this.sizebuffer [2]) &&
this.sizebuffer [2].Equals ( this.sizebuffer [3])) { this.sizebuffer [2].Equals (this.sizebuffer [3])) {
SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes have settled."); SparkleHelpers.DebugInfo ("Local", "[" + Name + "] Changes have settled.");
this.is_buffering = false; this.is_buffering = false;
@ -383,7 +377,7 @@ namespace SparkleLib {
Push (); Push ();
} else { } else {
if (SyncStatusChanged != null) if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncUpFinished); SyncStatusChanged (SyncStatus.Idle); // TODO: in checklocalforchanges
} }
} finally { } finally {
this.remote_timer.Start (); this.remote_timer.Start ();
@ -492,19 +486,16 @@ namespace SparkleLib {
// Fetches changes from the remote repository // Fetches changes from the remote repository
public void Fetch () public void Fetch ()
{ {
this.is_syncing = true;
this.remote_timer.Stop (); this.remote_timer.Stop ();
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes"); SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes");
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master"); SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
if (SyncStatusChanged != null) if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncDownStarted); SyncStatusChanged (SyncStatus.SyncDown);
git.Exited += delegate { git.Exited += delegate {
this.is_syncing = false;
this.revision = GetRevision (); this.revision = GetRevision ();
if (git.ExitCode != 0) { if (git.ExitCode != 0) {
@ -512,13 +503,13 @@ namespace SparkleLib {
this.server_online = false; this.server_online = false;
if (SyncStatusChanged != null) if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncDownFailed); SyncStatusChanged (SyncStatus.Error);
} else { } else {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched"); SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched");
this.server_online = true; this.server_online = true;
if (SyncStatusChanged != null) if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncDownFinished); SyncStatusChanged (SyncStatus.Idle);
} }
this.remote_timer.Start (); this.remote_timer.Start ();
@ -669,24 +660,20 @@ namespace SparkleLib {
// Pushes the changes to the remote repo // Pushes the changes to the remote repo
public void Push () public void Push ()
{ {
this.is_syncing = true;
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes"); SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes");
SparkleGit git = new SparkleGit (LocalPath, "push origin master"); SparkleGit git = new SparkleGit (LocalPath, "push origin master");
if (SyncStatusChanged != null) if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncUpStarted); SyncStatusChanged (SyncStatus.SyncUp);
git.Exited += delegate { git.Exited += delegate {
this.is_syncing = false;
if (git.ExitCode != 0) { if (git.ExitCode != 0) {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes not pushed"); SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes not pushed");
HasUnsyncedChanges = true; HasUnsyncedChanges = true;
if (SyncStatusChanged != null) if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncUpFailed); SyncStatusChanged (SyncStatus.Error);
FetchRebaseAndPush (); FetchRebaseAndPush ();
} else { } else {
@ -695,7 +682,7 @@ namespace SparkleLib {
HasUnsyncedChanges = false; HasUnsyncedChanges = false;
if (SyncStatusChanged != null) if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncDownFinished); SyncStatusChanged (SyncStatus.Idle);
this.listener.Announce (this.revision); this.listener.Announce (this.revision);
} }
@ -704,6 +691,8 @@ namespace SparkleLib {
git.Start (); git.Start ();
git.WaitForExit (); git.WaitForExit ();
// TODO put exit events here instead of in a new Exited thread, for the oter methods too
} }

View file

@ -478,7 +478,10 @@ namespace SparkleShare {
private void UpdateState () private void UpdateState ()
{ {
foreach (SparkleRepo repo in Repositories) { foreach (SparkleRepo repo in Repositories) {
if (repo.IsSyncing || repo.IsBuffering) { if (repo.Status == SyncStatus.SyncDown ||
repo.Status == SyncStatus.SyncUp ||
repo.IsBuffering) {
if (OnSyncing != null) if (OnSyncing != null)
OnSyncing (); OnSyncing ();
@ -527,12 +530,10 @@ namespace SparkleShare {
}; };
repo.SyncStatusChanged += delegate (SyncStatus status) { repo.SyncStatusChanged += delegate (SyncStatus status) {
if (status == SyncStatus.SyncDownFailed || if (status == SyncStatus.Idle ||
status == SyncStatus.SyncDownFinished || status == SyncStatus.SyncUp ||
status == SyncStatus.SyncDownStarted || status == SyncStatus.SyncDown ||
status == SyncStatus.SyncUpFailed || status == SyncStatus.Error) {
status == SyncStatus.SyncUpFinished ||
status == SyncStatus.SyncUpStarted) {
UpdateState (); UpdateState ();
} }
@ -1056,7 +1057,10 @@ namespace SparkleShare {
public void TryQuit () public void TryQuit ()
{ {
foreach (SparkleRepo repo in Repositories) { foreach (SparkleRepo repo in Repositories) {
if (repo.IsSyncing) { if (repo.Status == SyncStatus.SyncUp ||
repo.Status == SyncStatus.SyncDown ||
repo.IsBuffering) {
if (OnQuitWhileSyncing != null) if (OnQuitWhileSyncing != null)
OnQuitWhileSyncing (); OnQuitWhileSyncing ();