change text in status menuitem when syncing state changes

This commit is contained in:
Hylke Bons 2010-05-31 21:56:04 +02:00
parent afdcb58c83
commit 7f1800fd9b

View file

@ -27,6 +27,7 @@ namespace SparkleShare {
public class SparkleStatusIcon : StatusIcon { public class SparkleStatusIcon : StatusIcon {
private Timer Timer; private Timer Timer;
private string StateText;
// Short alias for the translations // Short alias for the translations
public static string _ (string s) { public static string _ (string s) {
@ -42,15 +43,20 @@ namespace SparkleShare {
public SparkleStatusIcon () : base () { public SparkleStatusIcon () : base () {
Timer = new Timer (); Activate += ShowMenu;
StateText = "Everything is up to date";
SetSyncingState ();
Activate += delegate { }
public void ShowMenu (object o, EventArgs Args) {
Menu Menu = new Menu (); Menu Menu = new Menu ();
MenuItem StatusItem = new MenuItem (_("Everything is up to date")); MenuItem StatusMenuItem = new MenuItem (StateText);
StatusItem.Sensitive = false; StatusMenuItem.Sensitive = false;
Menu.Add (StatusItem);
Menu.Add (StatusMenuItem);
Menu.Add (new SeparatorMenuItem ()); Menu.Add (new SeparatorMenuItem ());
Action FolderAction = new Action ("", "SparkleShare Folder"); Action FolderAction = new Action ("", "SparkleShare Folder");
@ -133,29 +139,30 @@ namespace SparkleShare {
QuitItem.Activated += delegate { Environment.Exit (0); }; QuitItem.Activated += delegate { Environment.Exit (0); };
Menu.Add (QuitItem); Menu.Add (QuitItem);
Menu.ShowAll (); Menu.ShowAll ();
Menu.Popup ();
// TODO: Make sure the menu never overlaps the status icon // TODO: Make sure the menu never overlaps the status icon
}; Menu.Popup ();
SetIdleState ();
} }
public void SetIdleState () { public void SetIdleState () {
Timer.Stop (); Timer.Stop ();
Pixbuf = SparkleHelpers.GetIcon ("folder-sparkleshare", 24); Pixbuf = SparkleHelpers.GetIcon ("folder-sparkleshare", 24);
StateText = "Everything is up to date";
} }
// Changes the status icon to the suncing antimation
// TODO: There are UI freezes when switching back and forth // TODO: There are UI freezes when switching back and forth
// bewteen syncing and idle state // bewteen syncing and idle state
public void SetSyncingState () { public void SetSyncingState () {
StateText = "Syncing…";
int CycleDuration = 250; int CycleDuration = 250;
int CurrentStep = 0; int CurrentStep = 0;
int Size = 24; int Size = 24;
Gdk.Pixbuf SpinnerGallery = SparkleHelpers.GetIcon ("process-syncing-sparkleshare", Gdk.Pixbuf SpinnerGallery =
Size); SparkleHelpers.GetIcon ("process-syncing-sparkleshare", Size);
int FramesInWidth = SpinnerGallery.Width / Size; int FramesInWidth = SpinnerGallery.Width / Size;
int FramesInHeight = SpinnerGallery.Height / Size; int FramesInHeight = SpinnerGallery.Height / Size;
@ -173,6 +180,7 @@ namespace SparkleShare {
} }
} }
Timer = new Timer ();
Timer.Interval = CycleDuration / NumSteps; Timer.Interval = CycleDuration / NumSteps;
Timer.Elapsed += delegate { Timer.Elapsed += delegate {
if (CurrentStep < NumSteps) if (CurrentStep < NumSteps)
@ -185,8 +193,10 @@ namespace SparkleShare {
} }
// Changes the status icon to the error icon
public void SetErrorState () { public void SetErrorState () {
// IconName = "folder-sync-error"; IconName = "folder-sync-error";
StateText = "Error syncing";
} }
// Quits the program // Quits the program