[statusicon] Update menu text depending on the syncing state

This commit is contained in:
Hylke Bons 2010-07-23 00:01:57 +01:00
parent 9481449358
commit d349b96334
2 changed files with 62 additions and 46 deletions

View file

@ -27,16 +27,38 @@ namespace SparkleShare {
public class SparkleStatusIcon : StatusIcon public class SparkleStatusIcon : StatusIcon
{ {
private Timer Timer; // private Timer Timer;
private int SyncingState;
public int SyncingReposCount; public int SyncingReposCount;
private Menu Menu;
private MenuItem StatusMenuItem;
private string StateText;
// Short alias for the translations // Short alias for the translations
public static string _ (string s) { public static string _ (string s) {
return Catalog.GetString (s); return Catalog.GetString (s);
} }
public SparkleStatusIcon () : base ()
{
// Timer = new Timer ();
StateText = "";
StatusMenuItem = new MenuItem (StateText);
SyncingReposCount = 0;
CreateMenu ();
Activate += ShowMenu;
SetIdleState ();
ShowState ();
}
public EventHandler CreateWindowDelegate (SparkleRepo SparkleRepo) public EventHandler CreateWindowDelegate (SparkleRepo SparkleRepo)
{ {
return delegate { return delegate {
@ -45,42 +67,13 @@ namespace SparkleShare {
}; };
} }
public SparkleStatusIcon () : base ()
private void CreateMenu ()
{ {
Timer = new Timer (); Menu = new Menu ();
Activate += ShowMenu;
SyncingReposCount = 0; StatusMenuItem = new MenuItem (StateText);
// 0 = Everything up to date
// 1 = Syncing in progress
// -1 = Error syncing
SyncingState = 0;
SetIdleState ();
}
public void ShowMenu (object o, EventArgs Args)
{
Menu Menu = new Menu ();
string StateText = "";
switch (SyncingState) {
case -1:
StateText = _("Error syncing");
break;
case 0:
StateText = _("Everything is up to date");
break;
case 1:
StateText = _("Syncing…");
break;
}
MenuItem StatusMenuItem = new MenuItem (StateText);
StatusMenuItem.Sensitive = false; StatusMenuItem.Sensitive = false;
Menu.Add (StatusMenuItem); Menu.Add (StatusMenuItem);
@ -163,12 +156,30 @@ namespace SparkleShare {
MenuItem QuitItem = new MenuItem (_("Quit")); MenuItem QuitItem = new MenuItem (_("Quit"));
QuitItem.Activated += Quit; QuitItem.Activated += Quit;
Menu.Add (QuitItem); Menu.Add (QuitItem);
Menu.ShowAll ();
Menu.Popup (null, null, SetPosition, 0, Global.CurrentEventTime);
} }
public void UpdateState () private void ShowMenu (object o, EventArgs args)
{
Menu.ShowAll ();
Menu.Popup (null, null, SetPosition, 0, Global.CurrentEventTime);
}
private void UpdateStatusMenuItem ()
{
Label label = (Label) StatusMenuItem.Children [0];
label.Text = StateText;
Menu.ShowAll ();
}
public void ShowState ()
{ {
if (SyncingReposCount > 0) if (SyncingReposCount > 0)
@ -176,14 +187,18 @@ namespace SparkleShare {
else else
SetIdleState (); SetIdleState ();
UpdateStatusMenuItem ();
} }
public void SetIdleState () public void SetIdleState ()
{ {
Timer.Stop (); // Timer.Stop ();
IconName = "folder-sparkleshare";
SyncingState = 0; IconName = "folder-sparkleshare";
StateText = _("Everything is up to date");
} }
// Changes the status icon to the syncing animation // Changes the status icon to the syncing animation
@ -193,8 +208,7 @@ namespace SparkleShare {
{ {
IconName = "view-refresh"; IconName = "view-refresh";
StateText = _("Syncing…");
SyncingState = 1;
/* int CycleDuration = 250; /* int CycleDuration = 250;
int CurrentStep = 0; int CurrentStep = 0;
@ -233,8 +247,10 @@ namespace SparkleShare {
// Changes the status icon to the error icon // Changes the status icon to the error icon
public void SetErrorState () public void SetErrorState ()
{ {
IconName = "folder-sync-error"; IconName = "folder-sync-error";
SyncingState = -1; StateText = _("Error syncing");
} }
public void SetPosition (Menu menu, out int x, out int y, out bool push_in) public void SetPosition (Menu menu, out int x, out int y, out bool push_in)

View file

@ -248,12 +248,12 @@ namespace SparkleShare {
if (args.Message.Equals ("FetchingStarted")) { if (args.Message.Equals ("FetchingStarted")) {
NotificationIcon.SyncingReposCount++; NotificationIcon.SyncingReposCount++;
NotificationIcon.UpdateState (); NotificationIcon.ShowState ();
} }
if (args.Message.Equals ("FetchingFinished")) { if (args.Message.Equals ("FetchingFinished")) {
NotificationIcon.SyncingReposCount--; NotificationIcon.SyncingReposCount--;
NotificationIcon.UpdateState (); NotificationIcon.ShowState ();
} }
} }