statusicon: Shorter status messages

This commit is contained in:
Hylke Bons 2016-04-04 10:26:20 +01:00
parent 4018bfc19c
commit c677df8c51

View file

@ -35,38 +35,38 @@ namespace SparkleShare {
public class ProjectInfo { public class ProjectInfo {
private BaseRepository repo; readonly BaseRepository repo;
public string Name { get { return this.repo.Name; }} public string Name { get { return repo.Name; }}
public string Path { get { return this.repo.LocalPath; }} public string Path { get { return repo.LocalPath; }}
public bool IsPaused { get { return this.repo.Status == SyncStatus.Paused; }} public bool IsPaused { get { return repo.Status == SyncStatus.Paused; }}
public bool HasError { get { return this.repo.Status == SyncStatus.Error; }} public bool HasError { get { return repo.Status == SyncStatus.Error; }}
public string StatusMessage { public string StatusMessage {
get { get {
string status_message = "Waiting to sync"; string status_message = "Waiting to sync";
if (!this.repo.LastSync.Equals (DateTime.MinValue)) if (!repo.LastSync.Equals (DateTime.MinValue))
status_message = string.Format ("✓ Synced {0}", this.repo.LastSync.ToPrettyDate ()); status_message = string.Format ("✓ Synced {0}", repo.LastSync.ToPrettyDate ());
if (this.repo.Status == SyncStatus.SyncUp) if (repo.Status == SyncStatus.SyncUp)
status_message = "Sending changes… " + this.repo.ProgressPercentage + "%"; status_message = "Sending changes… " + repo.ProgressPercentage + "%";
if (this.repo.Status == SyncStatus.SyncDown) if (repo.Status == SyncStatus.SyncDown)
status_message = "Receiving changes… " + this.repo.ProgressPercentage + "%"; status_message = "Receiving changes… " + repo.ProgressPercentage + "%";
if (this.repo.Status == SyncStatus.SyncUp || this.repo.Status == SyncStatus.SyncDown) { if (repo.Status == SyncStatus.SyncUp || repo.Status == SyncStatus.SyncDown) {
if (this.repo.ProgressSpeed > 0) if (repo.ProgressSpeed > 0)
status_message += " " + this.repo.ProgressSpeed.ToSize () + "/s"; status_message += " " + repo.ProgressSpeed.ToSize () + "/s";
} }
if (IsPaused) { if (IsPaused)
return "Paused"; return "Paused";
} else if (HasError) { if (HasError) {
switch (this.repo.Error) { switch (repo.Error) {
case ErrorStatus.HostUnreachable: return "Cant reach the host"; case ErrorStatus.HostUnreachable: return "Cant reach the host";
case ErrorStatus.HostIdentityChanged: return "The hosts identity has changed"; case ErrorStatus.HostIdentityChanged: return "The hosts identity has changed";
case ErrorStatus.AuthenticationFailed: return "Authentication failed"; case ErrorStatus.AuthenticationFailed: return "Authentication failed";
@ -86,7 +86,7 @@ namespace SparkleShare {
public Dictionary<string, string> UnsyncedChangesInfo { public Dictionary<string, string> UnsyncedChangesInfo {
get { get {
Dictionary<string, string> changes_info = new Dictionary<string, string> (); var changes_info = new Dictionary<string, string> ();
int changes_count = 0; int changes_count = 0;
foreach (Change change in repo.UnsyncedChanges) { foreach (Change change in repo.UnsyncedChanges) {
@ -148,14 +148,14 @@ namespace SparkleShare {
get { get {
string progress_speed = ""; string progress_speed = "";
if (SparkleShare.Controller.ProgressSpeedDown == 0 && SparkleShare.Controller.ProgressSpeedUp > 0) { if (SparkleShare.Controller.ProgressSpeedDown == 0.0 && SparkleShare.Controller.ProgressSpeedUp > 0.0) {
progress_speed = SparkleShare.Controller.ProgressSpeedUp.ToSize () + "/s "; progress_speed = SparkleShare.Controller.ProgressSpeedUp.ToSize () + "/s ";
} else if (SparkleShare.Controller.ProgressSpeedUp == 0 && SparkleShare.Controller.ProgressSpeedDown > 0) { } else if (SparkleShare.Controller.ProgressSpeedUp == 0.0 && SparkleShare.Controller.ProgressSpeedDown > 0.0) {
progress_speed = SparkleShare.Controller.ProgressSpeedDown.ToSize () + "/s "; progress_speed = SparkleShare.Controller.ProgressSpeedDown.ToSize () + "/s ";
} else if (SparkleShare.Controller.ProgressSpeedUp > 0 && } else if (SparkleShare.Controller.ProgressSpeedUp > 0.0 &&
SparkleShare.Controller.ProgressSpeedDown > 0) { SparkleShare.Controller.ProgressSpeedDown > 0.0) {
progress_speed = "Up: " + SparkleShare.Controller.ProgressSpeedUp.ToSize () + "/s " + progress_speed = "Up: " + SparkleShare.Controller.ProgressSpeedUp.ToSize () + "/s " +
"Down: " + SparkleShare.Controller.ProgressSpeedDown.ToSize () + "/s"; "Down: " + SparkleShare.Controller.ProgressSpeedDown.ToSize () + "/s";
@ -204,7 +204,6 @@ namespace SparkleShare {
SparkleShare.Controller.OnIdle += delegate { SparkleShare.Controller.OnIdle += delegate {
if (CurrentState != IconState.Error) { if (CurrentState != IconState.Error) {
CurrentState = IconState.Idle; CurrentState = IconState.Idle;
UpdateStateText (); UpdateStateText ();
} }
@ -217,31 +216,31 @@ namespace SparkleShare {
}; };
SparkleShare.Controller.OnSyncing += delegate { SparkleShare.Controller.OnSyncing += delegate {
int repos_syncing_up = 0; int repos_syncing_up = 0;
int repos_syncing_down = 0; int repos_syncing_down = 0;
foreach (BaseRepository repo in SparkleShare.Controller.Repositories) { foreach (BaseRepository repo in SparkleShare.Controller.Repositories) {
if (repo.Status == SyncStatus.SyncUp) if (repo.Status == SyncStatus.SyncUp)
repos_syncing_up++; repos_syncing_up++;
if (repo.Status == SyncStatus.SyncDown) if (repo.Status == SyncStatus.SyncDown)
repos_syncing_down++; repos_syncing_down++;
} }
if (repos_syncing_up > 0 && if (repos_syncing_up > 0 &&
repos_syncing_down > 0) { repos_syncing_down > 0) {
CurrentState = IconState.Syncing; CurrentState = IconState.Syncing;
StateText = "Syncing changes…"; StateText = "Syncing…";
} else if (repos_syncing_down == 0) { } else if (repos_syncing_down == 0) {
CurrentState = IconState.SyncingUp; CurrentState = IconState.SyncingUp;
StateText = "Sending changes…"; StateText = "Sending…";
} else { } else {
CurrentState = IconState.SyncingDown; CurrentState = IconState.SyncingDown;
StateText = "Receiving changes…"; StateText = "Receiving…";
} }
if (ProgressPercentage > 0) if (ProgressPercentage > 0)
StateText += " " + ProgressPercentage + "% " + ProgressSpeed; StateText += " " + ProgressPercentage + "% " + ProgressSpeed;
@ -253,7 +252,7 @@ namespace SparkleShare {
SparkleShare.Controller.OnError += delegate { SparkleShare.Controller.OnError += delegate {
CurrentState = IconState.Error; CurrentState = IconState.Error;
StateText = "Some changes werent synced"; StateText = "Not everything synced";
UpdateFolders (); UpdateFolders ();
@ -266,7 +265,7 @@ namespace SparkleShare {
// FIXME: Work around a race condition causing // FIXME: Work around a race condition causing
// the icon to not always show the right state // the icon to not always show the right state
Timers.Timer timer = new Timers.Timer () { Interval = 30 * 1000 }; var timer = new Timers.Timer { Interval = 30 * 1000 };
timer.Elapsed += delegate { timer.Elapsed += delegate {
UpdateIconEvent (CurrentState); UpdateIconEvent (CurrentState);
@ -282,7 +281,7 @@ namespace SparkleShare {
if (Projects.Length == 0) if (Projects.Length == 0)
return StateText = "Welcome to SparkleShare!"; return StateText = "Welcome to SparkleShare!";
else else
return StateText = "✓ Projects up to date " + GetPausedCount (); return StateText = "✓ Synced " + GetPausedCount ();
} }
@ -391,18 +390,18 @@ namespace SparkleShare {
} }
private Object projects_lock = new Object (); readonly object projects_lock = new object ();
private void UpdateFolders () void UpdateFolders ()
{ {
lock (this.projects_lock) { var projects = new List<ProjectInfo> ();
List<ProjectInfo> projects = new List<ProjectInfo> ();
lock (projects_lock) {
foreach (BaseRepository repo in SparkleShare.Controller.Repositories) foreach (BaseRepository repo in SparkleShare.Controller.Repositories)
projects.Add (new ProjectInfo (repo)); projects.Add (new ProjectInfo (repo));
Projects = projects.ToArray ();
} }
Projects = projects.ToArray ();
} }
} }
} }