intro statusicon: fix coding style and whitespace
This commit is contained in:
parent
9707481f42
commit
cbe9979324
File diff suppressed because it is too large
Load diff
|
@ -14,374 +14,325 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using Gtk;
|
||||
using Mono.Unix;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Timers;
|
||||
|
||||
using Gtk;
|
||||
using Mono.Unix;
|
||||
|
||||
namespace SparkleShare {
|
||||
|
||||
// The statusicon that stays in the
|
||||
// user's notification area
|
||||
public class SparkleStatusIcon : StatusIcon {
|
||||
// The statusicon that stays in the
|
||||
// user's notification area
|
||||
public class SparkleStatusIcon : StatusIcon {
|
||||
|
||||
private Timer Animation;
|
||||
private Gdk.Pixbuf [] AnimationFrames;
|
||||
private int FrameNumber;
|
||||
private string StateText;
|
||||
private Menu Menu;
|
||||
|
||||
// Short alias for the translations
|
||||
public static string _ (string s)
|
||||
{
|
||||
return Catalog.GetString (s);
|
||||
}
|
||||
|
||||
|
||||
public SparkleStatusIcon () : base ()
|
||||
{
|
||||
AnimationFrames = CreateAnimationFrames ();
|
||||
Animation = CreateAnimation ();
|
||||
|
||||
Activate += ShowMenu; // Primary mouse button click
|
||||
PopupMenu += ShowMenu; // Secondary mouse button click
|
||||
|
||||
SetNormalState ();
|
||||
CreateMenu ();
|
||||
|
||||
SparkleShare.Controller.FolderSizeChanged += delegate {
|
||||
Application.Invoke (delegate {
|
||||
if (!Animation.Enabled)
|
||||
SetNormalState ();
|
||||
|
||||
UpdateMenu ();
|
||||
});
|
||||
};
|
||||
|
||||
SparkleShare.Controller.FolderListChanged += delegate {
|
||||
Application.Invoke (delegate {
|
||||
SetNormalState ();
|
||||
CreateMenu ();
|
||||
});
|
||||
};
|
||||
|
||||
SparkleShare.Controller.OnIdle += delegate {
|
||||
Application.Invoke (delegate {
|
||||
SetNormalState ();
|
||||
UpdateMenu ();
|
||||
});
|
||||
};
|
||||
|
||||
private Timer Animation;
|
||||
private Gdk.Pixbuf [] AnimationFrames;
|
||||
private int FrameNumber;
|
||||
private string StateText;
|
||||
private Menu Menu;
|
||||
SparkleShare.Controller.OnSyncing += delegate {
|
||||
Application.Invoke (delegate {
|
||||
SetAnimationState ();
|
||||
UpdateMenu ();
|
||||
});
|
||||
};
|
||||
|
||||
// Short alias for the translations
|
||||
public static string _ (string s)
|
||||
{
|
||||
return Catalog.GetString (s);
|
||||
}
|
||||
SparkleShare.Controller.OnError += delegate {
|
||||
Application.Invoke (delegate {
|
||||
SetNormalState (true);
|
||||
UpdateMenu ();
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public SparkleStatusIcon () : base ()
|
||||
{
|
||||
|
||||
AnimationFrames = CreateAnimationFrames ();
|
||||
Animation = CreateAnimation ();
|
||||
// Slices up the graphic that contains the
|
||||
// animation frames.
|
||||
private Gdk.Pixbuf [] CreateAnimationFrames ()
|
||||
{
|
||||
Gdk.Pixbuf [] animation_frames = new Gdk.Pixbuf [5];
|
||||
Gdk.Pixbuf frames_pixbuf = SparkleUIHelpers.GetIcon ("process-syncing-sparkleshare", 24);
|
||||
|
||||
Activate += ShowMenu; // Primary mouse button click
|
||||
PopupMenu += ShowMenu; // Secondary mouse button click
|
||||
for (int i = 0; i < animation_frames.Length; i++)
|
||||
animation_frames [i] = new Gdk.Pixbuf (frames_pixbuf, (i * 24), 0, 24, 24);
|
||||
|
||||
SetNormalState ();
|
||||
CreateMenu ();
|
||||
return animation_frames;
|
||||
}
|
||||
|
||||
|
||||
SparkleShare.Controller.FolderSizeChanged += delegate {
|
||||
Application.Invoke (delegate {
|
||||
// Creates the Animation that handles the syncing animation
|
||||
private Timer CreateAnimation ()
|
||||
{
|
||||
FrameNumber = 0;
|
||||
|
||||
if (!Animation.Enabled)
|
||||
SetNormalState ();
|
||||
Timer Animation = new Timer () {
|
||||
Interval = 35
|
||||
};
|
||||
|
||||
UpdateMenu ();
|
||||
Animation.Elapsed += delegate {
|
||||
if (FrameNumber < AnimationFrames.Length - 1)
|
||||
FrameNumber++;
|
||||
else
|
||||
FrameNumber = 0;
|
||||
|
||||
});
|
||||
};
|
||||
Application.Invoke (delegate {
|
||||
Pixbuf = AnimationFrames [FrameNumber];
|
||||
});
|
||||
};
|
||||
|
||||
SparkleShare.Controller.FolderListChanged += delegate {
|
||||
Application.Invoke (delegate {
|
||||
SetNormalState ();
|
||||
CreateMenu ();
|
||||
});
|
||||
};
|
||||
return Animation;
|
||||
}
|
||||
|
||||
SparkleShare.Controller.OnIdle += delegate {
|
||||
Application.Invoke (delegate {
|
||||
SetNormalState ();
|
||||
UpdateMenu ();
|
||||
});
|
||||
};
|
||||
|
||||
SparkleShare.Controller.OnSyncing += delegate {
|
||||
Application.Invoke (delegate {
|
||||
SetAnimationState ();
|
||||
UpdateMenu ();
|
||||
});
|
||||
};
|
||||
// Creates the menu that is popped up when the
|
||||
// user clicks the status icon
|
||||
public void CreateMenu ()
|
||||
{
|
||||
Menu = new Menu ();
|
||||
|
||||
SparkleShare.Controller.OnError += delegate {
|
||||
Application.Invoke (delegate {
|
||||
SetNormalState (true);
|
||||
UpdateMenu ();
|
||||
});
|
||||
};
|
||||
// The menu item showing the status and size of the SparkleShare folder
|
||||
MenuItem status_menu_item = new MenuItem (StateText) {
|
||||
Sensitive = false
|
||||
};
|
||||
|
||||
}
|
||||
Menu.Add (status_menu_item);
|
||||
Menu.Add (new SeparatorMenuItem ());
|
||||
|
||||
ImageMenuItem folder_item = new SparkleMenuItem ("SparkleShare"){
|
||||
Image = new Image (SparkleUIHelpers.GetIcon ("folder-sparkleshare", 16))
|
||||
};
|
||||
|
||||
// Slices up the graphic that contains the
|
||||
// animation frames.
|
||||
private Gdk.Pixbuf [] CreateAnimationFrames ()
|
||||
{
|
||||
folder_item.Activated += delegate {
|
||||
SparkleShare.Controller.OpenSparkleShareFolder ();
|
||||
};
|
||||
|
||||
Gdk.Pixbuf [] animation_frames = new Gdk.Pixbuf [5];
|
||||
Gdk.Pixbuf frames_pixbuf = SparkleUIHelpers.GetIcon ("process-syncing-sparkleshare", 24);
|
||||
Menu.Add (folder_item);
|
||||
|
||||
for (int i = 0; i < animation_frames.Length; i++)
|
||||
animation_frames [i] = new Gdk.Pixbuf (frames_pixbuf, (i * 24), 0, 24, 24);
|
||||
if (SparkleShare.Controller.Folders.Count > 0) {
|
||||
|
||||
return animation_frames;
|
||||
// Creates a menu item for each repository with a link to their logs
|
||||
foreach (string path in SparkleShare.Controller.Folders) {
|
||||
|
||||
}
|
||||
Gdk.Pixbuf folder_icon = IconTheme.Default.LoadIcon ("folder", 16,
|
||||
IconLookupFlags.GenericFallback);
|
||||
|
||||
ImageMenuItem subfolder_item = new SparkleMenuItem (Path.GetFileName (path)) {
|
||||
Image = new Image (folder_icon)
|
||||
};
|
||||
|
||||
// Creates the Animation that handles the syncing animation
|
||||
private Timer CreateAnimation ()
|
||||
{
|
||||
// if (repo.HasUnsyncedChanges)
|
||||
// folder_action.IconName = "dialog-error";
|
||||
|
||||
FrameNumber = 0;
|
||||
subfolder_item.Activated += OpenEventLogDelegate (path);
|
||||
|
||||
Timer Animation = new Timer () {
|
||||
Interval = 35
|
||||
};
|
||||
Menu.Add (subfolder_item);
|
||||
}
|
||||
} else {
|
||||
MenuItem no_folders_item = new MenuItem (_("No Remote Folders Yet")) {
|
||||
Sensitive = false
|
||||
};
|
||||
|
||||
Animation.Elapsed += delegate {
|
||||
Menu.Add (no_folders_item);
|
||||
}
|
||||
|
||||
if (FrameNumber < AnimationFrames.Length - 1)
|
||||
FrameNumber++;
|
||||
else
|
||||
FrameNumber = 0;
|
||||
// Opens the wizard to add a new remote folder
|
||||
MenuItem sync_item = new MenuItem (_("Add Remote Folder…"));
|
||||
|
||||
Application.Invoke (delegate {
|
||||
Pixbuf = AnimationFrames [FrameNumber];
|
||||
});
|
||||
if (SparkleShare.Controller.FirstRun)
|
||||
sync_item.Sensitive = false;
|
||||
|
||||
};
|
||||
sync_item.Activated += delegate {
|
||||
Application.Invoke (delegate {
|
||||
|
||||
return Animation;
|
||||
if (SparkleUI.Intro == null) {
|
||||
SparkleUI.Intro = new SparkleIntro ();
|
||||
SparkleUI.Intro.ShowServerForm (true);
|
||||
}
|
||||
|
||||
}
|
||||
if (!SparkleUI.Intro.Visible)
|
||||
SparkleUI.Intro.ShowServerForm (true);
|
||||
|
||||
SparkleUI.Intro.ShowAll ();
|
||||
SparkleUI.Intro.Present ();
|
||||
});
|
||||
};
|
||||
|
||||
// Creates the menu that is popped up when the
|
||||
// user clicks the status icon
|
||||
public void CreateMenu ()
|
||||
{
|
||||
Menu.Add (sync_item);
|
||||
Menu.Add (new SeparatorMenuItem ());
|
||||
|
||||
Menu = new Menu ();
|
||||
MenuItem notify_item;
|
||||
|
||||
// The menu item showing the status and size of the SparkleShare folder
|
||||
MenuItem status_menu_item = new MenuItem (StateText) {
|
||||
Sensitive = false
|
||||
};
|
||||
if (SparkleShare.Controller.NotificationsEnabled)
|
||||
notify_item = new MenuItem (_("Turn Notifications Off"));
|
||||
else
|
||||
notify_item = new MenuItem (_("Turn Notifications On"));
|
||||
|
||||
Menu.Add (status_menu_item);
|
||||
Menu.Add (new SeparatorMenuItem ());
|
||||
notify_item.Activated += delegate {
|
||||
SparkleShare.Controller.ToggleNotifications ();
|
||||
CreateMenu ();
|
||||
};
|
||||
|
||||
ImageMenuItem folder_item = new SparkleMenuItem ("SparkleShare"){
|
||||
Image = new Image (SparkleUIHelpers.GetIcon ("folder-sparkleshare", 16))
|
||||
};
|
||||
Menu.Add (notify_item);
|
||||
Menu.Add (new SeparatorMenuItem ());
|
||||
|
||||
folder_item.Activated += delegate {
|
||||
SparkleShare.Controller.OpenSparkleShareFolder ();
|
||||
};
|
||||
// A menu item that takes the user to http://www.sparkleshare.org/
|
||||
MenuItem about_item = new MenuItem (_("About SparkleShare"));
|
||||
|
||||
Menu.Add (folder_item);
|
||||
about_item.Activated += delegate {
|
||||
SparkleAbout about = new SparkleAbout ();
|
||||
about.ShowAll ();
|
||||
};
|
||||
|
||||
if (SparkleShare.Controller.Folders.Count > 0) {
|
||||
Menu.Add (about_item);
|
||||
Menu.Add (new SeparatorMenuItem ());
|
||||
|
||||
// Creates a menu item for each repository with a link to their logs
|
||||
foreach (string path in SparkleShare.Controller.Folders) {
|
||||
// A menu item that quits the application
|
||||
MenuItem quit_item = new MenuItem (_("Quit"));
|
||||
|
||||
Gdk.Pixbuf folder_icon = IconTheme.Default.LoadIcon ("folder", 16,
|
||||
IconLookupFlags.GenericFallback);
|
||||
quit_item.Activated += delegate {
|
||||
SparkleShare.Controller.Quit ();
|
||||
};
|
||||
|
||||
ImageMenuItem subfolder_item = new SparkleMenuItem (Path.GetFileName (path)) {
|
||||
Image = new Image (folder_icon)
|
||||
};
|
||||
Menu.Add (quit_item);
|
||||
Menu.ShowAll ();
|
||||
}
|
||||
|
||||
// if (repo.HasUnsyncedChanges)
|
||||
// folder_action.IconName = "dialog-error";
|
||||
|
||||
subfolder_item.Activated += OpenEventLogDelegate (path);
|
||||
// A method reference that makes sure that opening the
|
||||
// event log for each repository works correctly
|
||||
private EventHandler OpenEventLogDelegate (string path)
|
||||
{
|
||||
return delegate {
|
||||
SparkleShare.UI.AddEventLog (path);
|
||||
};
|
||||
}
|
||||
|
||||
Menu.Add (subfolder_item);
|
||||
|
||||
}
|
||||
public void UpdateMenu ()
|
||||
{
|
||||
Menu.Remove (Menu.Children [0]);
|
||||
|
||||
} else {
|
||||
MenuItem status_menu_item = new MenuItem (StateText) {
|
||||
Sensitive = false
|
||||
};
|
||||
|
||||
MenuItem no_folders_item = new MenuItem (_("No Remote Folders Yet")) {
|
||||
Sensitive = false
|
||||
};
|
||||
Menu.Add (status_menu_item);
|
||||
Menu.ReorderChild (status_menu_item, 0);
|
||||
|
||||
Menu.Add (no_folders_item);
|
||||
Menu.ShowAll ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Opens the wizard to add a new remote folder
|
||||
MenuItem sync_item = new MenuItem (_("Add Remote Folder…"));
|
||||
// Makes the menu visible
|
||||
private void ShowMenu (object o, EventArgs args)
|
||||
{
|
||||
Menu.Popup (null, null, SetPosition, 0, Global.CurrentEventTime);
|
||||
}
|
||||
|
||||
if (SparkleShare.Controller.FirstRun)
|
||||
sync_item.Sensitive = false;
|
||||
|
||||
sync_item.Activated += delegate {
|
||||
Application.Invoke (delegate {
|
||||
// Makes sure the menu pops up in the right position
|
||||
private void SetPosition (Menu menu, out int x, out int y, out bool push_in)
|
||||
{
|
||||
PositionMenu (menu, out x, out y, out push_in, Handle);
|
||||
}
|
||||
|
||||
if (SparkleUI.Intro == null) {
|
||||
|
||||
SparkleUI.Intro = new SparkleIntro ();
|
||||
SparkleUI.Intro.ShowServerForm (true);
|
||||
// The state when there's nothing going on
|
||||
private void SetNormalState ()
|
||||
{
|
||||
SetNormalState (false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!SparkleUI.Intro.Visible)
|
||||
SparkleUI.Intro.ShowServerForm (true);
|
||||
// The state when there's nothing going on
|
||||
private void SetNormalState (bool error)
|
||||
{
|
||||
Animation.Stop ();
|
||||
|
||||
SparkleUI.Intro.ShowAll ();
|
||||
SparkleUI.Intro.Present ();
|
||||
if (SparkleShare.Controller.Folders.Count == 0) {
|
||||
StateText = _("Welcome to SparkleShare!");
|
||||
|
||||
});
|
||||
};
|
||||
Application.Invoke (delegate {
|
||||
Pixbuf = AnimationFrames [0];
|
||||
});
|
||||
} else {
|
||||
if (error) {
|
||||
StateText = _("Not everything is synced");
|
||||
|
||||
Menu.Add (sync_item);
|
||||
Menu.Add (new SeparatorMenuItem ());
|
||||
Application.Invoke (delegate {
|
||||
Pixbuf = SparkleUIHelpers.GetIcon ("sparkleshare-syncing-error", 24);
|
||||
});
|
||||
} else {
|
||||
StateText = _("Up to date") + " (" + SparkleShare.Controller.FolderSize + ")";
|
||||
Application.Invoke (delegate {
|
||||
Pixbuf = AnimationFrames [0];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MenuItem notify_item;
|
||||
|
||||
if (SparkleShare.Controller.NotificationsEnabled)
|
||||
notify_item = new MenuItem (_("Turn Notifications Off"));
|
||||
else
|
||||
notify_item = new MenuItem (_("Turn Notifications On"));
|
||||
// The state when animating
|
||||
private void SetAnimationState ()
|
||||
{
|
||||
StateText = _("Syncing…");
|
||||
|
||||
notify_item.Activated += delegate {
|
||||
if (!Animation.Enabled)
|
||||
Animation.Start ();
|
||||
}
|
||||
}
|
||||
|
||||
SparkleShare.Controller.ToggleNotifications ();
|
||||
CreateMenu ();
|
||||
|
||||
};
|
||||
|
||||
Menu.Add (notify_item);
|
||||
Menu.Add (new SeparatorMenuItem ());
|
||||
|
||||
// A menu item that takes the user to http://www.sparkleshare.org/
|
||||
MenuItem about_item = new MenuItem (_("About SparkleShare"));
|
||||
|
||||
about_item.Activated += delegate {
|
||||
|
||||
SparkleAbout about = new SparkleAbout ();
|
||||
about.ShowAll ();
|
||||
|
||||
};
|
||||
|
||||
Menu.Add (about_item);
|
||||
Menu.Add (new SeparatorMenuItem ());
|
||||
|
||||
// A menu item that quits the application
|
||||
MenuItem quit_item = new MenuItem (_("Quit"));
|
||||
|
||||
quit_item.Activated += delegate {
|
||||
SparkleShare.Controller.Quit ();
|
||||
};
|
||||
|
||||
Menu.Add (quit_item);
|
||||
|
||||
Menu.ShowAll ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// A method reference that makes sure that opening the
|
||||
// event log for each repository works correctly
|
||||
private EventHandler OpenEventLogDelegate (string path)
|
||||
{
|
||||
|
||||
return delegate {
|
||||
|
||||
SparkleShare.UI.AddEventLog (path);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void UpdateMenu ()
|
||||
{
|
||||
|
||||
Menu.Remove (Menu.Children [0]);
|
||||
|
||||
MenuItem status_menu_item = new MenuItem (StateText) {
|
||||
Sensitive = false
|
||||
};
|
||||
|
||||
Menu.Add (status_menu_item);
|
||||
Menu.ReorderChild (status_menu_item, 0);
|
||||
|
||||
Menu.ShowAll ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Makes the menu visible
|
||||
private void ShowMenu (object o, EventArgs args)
|
||||
{
|
||||
|
||||
Menu.Popup (null, null, SetPosition, 0, Global.CurrentEventTime);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Makes sure the menu pops up in the right position
|
||||
private void SetPosition (Menu menu, out int x, out int y, out bool push_in)
|
||||
{
|
||||
|
||||
PositionMenu (menu, out x, out y, out push_in, Handle);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// The state when there's nothing going on
|
||||
private void SetNormalState ()
|
||||
{
|
||||
|
||||
SetNormalState (false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// The state when there's nothing going on
|
||||
private void SetNormalState (bool error)
|
||||
{
|
||||
|
||||
Animation.Stop ();
|
||||
|
||||
if (SparkleShare.Controller.Folders.Count == 0) {
|
||||
|
||||
StateText = _("Welcome to SparkleShare!");
|
||||
Application.Invoke (delegate {
|
||||
Pixbuf = AnimationFrames [0];
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
if (error) {
|
||||
|
||||
StateText = _("Not everything is synced");
|
||||
Application.Invoke (delegate {
|
||||
Pixbuf = SparkleUIHelpers.GetIcon ("sparkleshare-syncing-error", 24);
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
StateText = _("Up to date") + " (" + SparkleShare.Controller.FolderSize + ")";
|
||||
Application.Invoke (delegate {
|
||||
Pixbuf = AnimationFrames [0];
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// The state when animating
|
||||
private void SetAnimationState ()
|
||||
{
|
||||
|
||||
StateText = _("Syncing…");
|
||||
|
||||
if (!Animation.Enabled)
|
||||
Animation.Start ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SparkleMenuItem : ImageMenuItem {
|
||||
|
||||
public SparkleMenuItem (string text) : base (text)
|
||||
{
|
||||
|
||||
SetProperty ("always-show-image", new GLib.Value (true));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public class SparkleMenuItem : ImageMenuItem {
|
||||
|
||||
public SparkleMenuItem (string text) : base (text)
|
||||
{
|
||||
SetProperty ("always-show-image", new GLib.Value (true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue