intro statusicon: fix coding style and whitespace

This commit is contained in:
Hylke Bons 2011-05-14 04:05:55 +01:00
parent 17b614121c
commit 16bc6acff4
2 changed files with 940 additions and 1080 deletions

View file

@ -48,16 +48,13 @@ namespace SparkleShare {
public SparkleIntro () : base () public SparkleIntro () : base ()
{ {
ServerFormOnly = false; ServerFormOnly = false;
SecondaryTextColor = SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)); SecondaryTextColor = SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive));
} }
public void ShowAccountForm () public void ShowAccountForm ()
{ {
Reset (); Reset ();
VBox layout_vertical = new VBox (false, 0); VBox layout_vertical = new VBox (false, 0);
@ -117,7 +114,6 @@ namespace SparkleShare {
}; };
NextButton.Clicked += delegate (object o, EventArgs args) { NextButton.Clicked += delegate (object o, EventArgs args) {
NextButton.Remove (NextButton.Child); NextButton.Remove (NextButton.Child);
NextButton.Add (new Label (_("Configuring…"))); NextButton.Add (new Label (_("Configuring…")));
@ -136,7 +132,6 @@ namespace SparkleShare {
Deletable = true; Deletable = true;
ShowServerForm (); ShowServerForm ();
}; };
AddButton (NextButton); AddButton (NextButton);
@ -147,26 +142,20 @@ namespace SparkleShare {
layout_vertical.PackStart (table, false, false, 0); layout_vertical.PackStart (table, false, false, 0);
Add (layout_vertical); Add (layout_vertical);
CheckAccountForm (); CheckAccountForm ();
ShowAll (); ShowAll ();
} }
public void ShowServerForm (bool server_form_only) public void ShowServerForm (bool server_form_only)
{ {
ServerFormOnly = server_form_only; ServerFormOnly = server_form_only;
ShowServerForm (); ShowServerForm ();
} }
public void ShowServerForm () public void ShowServerForm ()
{ {
Reset (); Reset ();
VBox layout_vertical = new VBox (false, 0); VBox layout_vertical = new VBox (false, 0);
@ -230,44 +219,31 @@ namespace SparkleShare {
(radio_button_gitorious.Child as Label).Wrap = true; (radio_button_gitorious.Child as Label).Wrap = true;
radio_button_github.Toggled += delegate { radio_button_github.Toggled += delegate {
if (radio_button_github.Active) if (radio_button_github.Active)
FolderEntry.ExampleText = _("Username/Folder"); FolderEntry.ExampleText = _("Username/Folder");
}; };
radio_button_gitorious.Toggled += delegate { radio_button_gitorious.Toggled += delegate {
if (radio_button_gitorious.Active) if (radio_button_gitorious.Active)
FolderEntry.ExampleText = _("Project/Folder"); FolderEntry.ExampleText = _("Project/Folder");
}; };
radio_button_gnome.Toggled += delegate { radio_button_gnome.Toggled += delegate {
if (radio_button_gnome.Active) if (radio_button_gnome.Active)
FolderEntry.ExampleText = _("Project"); FolderEntry.ExampleText = _("Project");
}; };
radio_button.Toggled += delegate { radio_button.Toggled += delegate {
if (radio_button.Active) { if (radio_button.Active) {
FolderEntry.ExampleText = _("Folder"); FolderEntry.ExampleText = _("Folder");
ServerEntry.Sensitive = true; ServerEntry.Sensitive = true;
CheckServerForm (); CheckServerForm ();
} else { } else {
ServerEntry.Sensitive = false; ServerEntry.Sensitive = false;
CheckServerForm (); CheckServerForm ();
} }
ShowAll (); ShowAll ();
}; };
table.Attach (layout_server, 0, 2, 1, 2); table.Attach (layout_server, 0, 2, 1, 2);
@ -296,7 +272,6 @@ namespace SparkleShare {
SyncButton = new Button (_("Sync")); SyncButton = new Button (_("Sync"));
SyncButton.Clicked += delegate { SyncButton.Clicked += delegate {
string name = FolderEntry.Text; string name = FolderEntry.Text;
// Remove the starting slash if there is one // Remove the starting slash if there is one
@ -327,22 +302,17 @@ namespace SparkleShare {
// Remove the trailing slash if there is one // Remove the trailing slash if there is one
if (server.EndsWith ("/")) if (server.EndsWith ("/"))
server = server.TrimEnd ("/".ToCharArray ()); server = server.TrimEnd ("/".ToCharArray ());
} }
if (radio_button_gitorious.Active) { if (radio_button_gitorious.Active) {
server = "ssh://git@gitorious.org"; server = "ssh://git@gitorious.org";
if (!name.EndsWith (".git")) { if (!name.EndsWith (".git")) {
if (!name.Contains ("/")) if (!name.Contains ("/"))
name = name + "/" + name; name = name + "/" + name;
name += ".git"; name += ".git";
} }
} }
if (radio_button_github.Active) if (radio_button_github.Active)
@ -359,35 +329,24 @@ namespace SparkleShare {
ShowSyncingPage (canonical_name); ShowSyncingPage (canonical_name);
SparkleShare.Controller.FolderFetched += delegate { SparkleShare.Controller.FolderFetched += delegate {
Application.Invoke (delegate { Application.Invoke (delegate {
Deletable = true; Deletable = true;
ShowSuccessPage (name); ShowSuccessPage (name);
}); });
}; };
SparkleShare.Controller.FolderFetchError += delegate { SparkleShare.Controller.FolderFetchError += delegate {
Application.Invoke (delegate { Application.Invoke (delegate {
Deletable = true; Deletable = true;
ShowErrorPage (); ShowErrorPage ();
}); });
}; };
SparkleShare.Controller.FetchFolder (url, name); SparkleShare.Controller.FetchFolder (url, name);
}; };
if (ServerFormOnly) { if (ServerFormOnly) {
Button cancel_button = new Button (_("Cancel")); Button cancel_button = new Button (_("Cancel"));
cancel_button.Clicked += delegate { cancel_button.Clicked += delegate {
@ -395,10 +354,7 @@ namespace SparkleShare {
}; };
AddButton (cancel_button); AddButton (cancel_button);
} else { } else {
Button skip_button = new Button (_("Skip")); Button skip_button = new Button (_("Skip"));
skip_button.Clicked += delegate { skip_button.Clicked += delegate {
@ -406,7 +362,6 @@ namespace SparkleShare {
}; };
AddButton (skip_button); AddButton (skip_button);
} }
AddButton (SyncButton); AddButton (SyncButton);
@ -417,17 +372,13 @@ namespace SparkleShare {
layout_vertical.PackStart (layout_folder, false, false, 6); layout_vertical.PackStart (layout_folder, false, false, 6);
Add (layout_vertical); Add (layout_vertical);
CheckServerForm (); CheckServerForm ();
ShowAll (); ShowAll ();
} }
public void ShowInvitationPage (string server, string folder, string token) public void ShowInvitationPage (string server, string folder, string token)
{ {
VBox layout_vertical = new VBox (false, 0); VBox layout_vertical = new VBox (false, 0);
Label header = new Label ("<span size='large'><b>" + Label header = new Label ("<span size='large'><b>" +
@ -483,26 +434,20 @@ namespace SparkleShare {
}; };
accept_button.Clicked += delegate { accept_button.Clicked += delegate {
string url = "ssh://git@" + server + "/" + folder; string url = "ssh://git@" + server + "/" + folder;
SparkleShare.Controller.FolderFetched += delegate { SparkleShare.Controller.FolderFetched += delegate {
Application.Invoke (delegate { Application.Invoke (delegate {
ShowSuccessPage (folder); ShowSuccessPage (folder);
}); });
}; };
SparkleShare.Controller.FolderFetchError += delegate { SparkleShare.Controller.FolderFetchError += delegate {
Application.Invoke (delegate { ShowErrorPage (); }); Application.Invoke (delegate { ShowErrorPage (); });
}; };
SparkleShare.Controller.FetchFolder (url, folder); SparkleShare.Controller.FetchFolder (url, folder);
}; };
AddButton (reject_button); AddButton (reject_button);
@ -516,16 +461,13 @@ namespace SparkleShare {
layout_vertical.PackStart (question, false, false, 21); layout_vertical.PackStart (question, false, false, 21);
Add (layout_vertical); Add (layout_vertical);
ShowAll (); ShowAll ();
} }
// The page shown when syncing has failed // The page shown when syncing has failed
private void ShowErrorPage () private void ShowErrorPage ()
{ {
Reset (); Reset ();
UrgencyHint = true; UrgencyHint = true;
@ -552,27 +494,22 @@ namespace SparkleShare {
layout_vertical.PackStart (header, false, false, 0); layout_vertical.PackStart (header, false, false, 0);
Add (layout_vertical); Add (layout_vertical);
ShowAll (); ShowAll ();
} }
// The page shown when syncing has succeeded // The page shown when syncing has succeeded
private void ShowSuccessPage (string folder_name) private void ShowSuccessPage (string folder_name)
{ {
Reset (); Reset ();
UrgencyHint = true; UrgencyHint = true;
if (!HasToplevelFocus) { if (!HasToplevelFocus) {
string title = String.Format (_("{0} has been successfully added"), folder_name); string title = String.Format (_("{0} has been successfully added"), folder_name);
string subtext = _(""); string subtext = _("");
new SparkleBubble (title, subtext).Show (); new SparkleBubble (title, subtext).Show ();
} }
VBox layout_vertical = new VBox (false, 0); VBox layout_vertical = new VBox (false, 0);
@ -596,9 +533,7 @@ namespace SparkleShare {
Button open_folder_button = new Button (_("Open Folder")); Button open_folder_button = new Button (_("Open Folder"));
open_folder_button.Clicked += delegate { open_folder_button.Clicked += delegate {
SparkleShare.Controller.OpenSparkleShareFolder (Path.GetFileNameWithoutExtension(folder_name));
SparkleShare.Controller.OpenSparkleShareFolder (System.IO.Path.GetFileNameWithoutExtension(folder_name));
}; };
Button finish_button = new Button (_("Finish")); Button finish_button = new Button (_("Finish"));
@ -614,16 +549,13 @@ namespace SparkleShare {
layout_vertical.PackStart (information, false, false, 21); layout_vertical.PackStart (information, false, false, 21);
Add (layout_vertical); Add (layout_vertical);
ShowAll (); ShowAll ();
} }
// The page shown whilst syncing // The page shown whilst syncing
private void ShowSyncingPage (string name) private void ShowSyncingPage (string name)
{ {
Reset (); Reset ();
Deletable = false; Deletable = false;
@ -644,7 +576,6 @@ namespace SparkleShare {
Xalign = 0 Xalign = 0
}; };
Button button = new Button () { Button button = new Button () {
Sensitive = false, Sensitive = false,
Label = _("Finish") Label = _("Finish")
@ -674,16 +605,13 @@ namespace SparkleShare {
layout_vertical.PackStart (box, false, false, 0); layout_vertical.PackStart (box, false, false, 0);
Add (layout_vertical); Add (layout_vertical);
ShowAll (); ShowAll ();
} }
// The page shown when the setup has been completed // The page shown when the setup has been completed
private void ShowCompletedPage () private void ShowCompletedPage ()
{ {
Reset (); Reset ();
VBox layout_vertical = new VBox (false, 0); VBox layout_vertical = new VBox (false, 0);
@ -723,9 +651,7 @@ namespace SparkleShare {
AddButton (finish_button); AddButton (finish_button);
Add (layout_vertical); Add (layout_vertical);
ShowAll (); ShowAll ();
} }
@ -733,18 +659,13 @@ namespace SparkleShare {
// entries filled in by the user // entries filled in by the user
private void CheckAccountForm () private void CheckAccountForm ()
{ {
if (NameEntry.Text.Length > 0 && if (NameEntry.Text.Length > 0 &&
IsValidEmail (EmailEntry.Text)) { IsValidEmail (EmailEntry.Text)) {
NextButton.Sensitive = true; NextButton.Sensitive = true;
} else { } else {
NextButton.Sensitive = false; NextButton.Sensitive = false;
} }
} }
@ -752,9 +673,7 @@ namespace SparkleShare {
// filled in correctly // filled in correctly
public void CheckServerForm (object o, EventArgs args) public void CheckServerForm (object o, EventArgs args)
{ {
CheckServerForm (); CheckServerForm ();
} }
@ -762,7 +681,6 @@ namespace SparkleShare {
// filled in correctly // filled in correctly
public void CheckServerForm () public void CheckServerForm ()
{ {
SyncButton.Sensitive = false; SyncButton.Sensitive = false;
if (FolderEntry.ExampleTextActive || if (FolderEntry.ExampleTextActive ||
@ -773,28 +691,19 @@ namespace SparkleShare {
bool IsServer = !ServerEntry.Text.Trim ().Equals (""); bool IsServer = !ServerEntry.Text.Trim ().Equals ("");
if (ServerEntry.Sensitive == true) { if (ServerEntry.Sensitive == true) {
if (IsServer && IsFolder) if (IsServer && IsFolder)
SyncButton.Sensitive = true; SyncButton.Sensitive = true;
} else if (IsFolder) { } else if (IsFolder) {
SyncButton.Sensitive = true; SyncButton.Sensitive = true;
} }
} }
// Checks to see if an email address is valid // Checks to see if an email address is valid
private bool IsValidEmail (string email) private bool IsValidEmail (string email)
{ {
Regex regex = new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase); Regex regex = new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase);
return regex.IsMatch (email); return regex.IsMatch (email);
} }
} }
} }

View file

@ -14,12 +14,14 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using Mono.Unix;
using System; using System;
using System.IO; using System.IO;
using System.Timers; using System.Timers;
using Gtk;
using Mono.Unix;
namespace SparkleShare { namespace SparkleShare {
// The statusicon that stays in the // The statusicon that stays in the
@ -41,7 +43,6 @@ namespace SparkleShare {
public SparkleStatusIcon () : base () public SparkleStatusIcon () : base ()
{ {
AnimationFrames = CreateAnimationFrames (); AnimationFrames = CreateAnimationFrames ();
Animation = CreateAnimation (); Animation = CreateAnimation ();
@ -51,15 +52,12 @@ namespace SparkleShare {
SetNormalState (); SetNormalState ();
CreateMenu (); CreateMenu ();
SparkleShare.Controller.FolderSizeChanged += delegate { SparkleShare.Controller.FolderSizeChanged += delegate {
Application.Invoke (delegate { Application.Invoke (delegate {
if (!Animation.Enabled) if (!Animation.Enabled)
SetNormalState (); SetNormalState ();
UpdateMenu (); UpdateMenu ();
}); });
}; };
@ -98,7 +96,6 @@ namespace SparkleShare {
// animation frames. // animation frames.
private Gdk.Pixbuf [] CreateAnimationFrames () private Gdk.Pixbuf [] CreateAnimationFrames ()
{ {
Gdk.Pixbuf [] animation_frames = new Gdk.Pixbuf [5]; Gdk.Pixbuf [] animation_frames = new Gdk.Pixbuf [5];
Gdk.Pixbuf frames_pixbuf = SparkleUIHelpers.GetIcon ("process-syncing-sparkleshare", 24); Gdk.Pixbuf frames_pixbuf = SparkleUIHelpers.GetIcon ("process-syncing-sparkleshare", 24);
@ -106,14 +103,12 @@ namespace SparkleShare {
animation_frames [i] = new Gdk.Pixbuf (frames_pixbuf, (i * 24), 0, 24, 24); animation_frames [i] = new Gdk.Pixbuf (frames_pixbuf, (i * 24), 0, 24, 24);
return animation_frames; return animation_frames;
} }
// Creates the Animation that handles the syncing animation // Creates the Animation that handles the syncing animation
private Timer CreateAnimation () private Timer CreateAnimation ()
{ {
FrameNumber = 0; FrameNumber = 0;
Timer Animation = new Timer () { Timer Animation = new Timer () {
@ -121,7 +116,6 @@ namespace SparkleShare {
}; };
Animation.Elapsed += delegate { Animation.Elapsed += delegate {
if (FrameNumber < AnimationFrames.Length - 1) if (FrameNumber < AnimationFrames.Length - 1)
FrameNumber++; FrameNumber++;
else else
@ -130,11 +124,9 @@ namespace SparkleShare {
Application.Invoke (delegate { Application.Invoke (delegate {
Pixbuf = AnimationFrames [FrameNumber]; Pixbuf = AnimationFrames [FrameNumber];
}); });
}; };
return Animation; return Animation;
} }
@ -142,7 +134,6 @@ namespace SparkleShare {
// user clicks the status icon // user clicks the status icon
public void CreateMenu () public void CreateMenu ()
{ {
Menu = new Menu (); Menu = new Menu ();
// The menu item showing the status and size of the SparkleShare folder // The menu item showing the status and size of the SparkleShare folder
@ -181,17 +172,13 @@ namespace SparkleShare {
subfolder_item.Activated += OpenEventLogDelegate (path); subfolder_item.Activated += OpenEventLogDelegate (path);
Menu.Add (subfolder_item); Menu.Add (subfolder_item);
} }
} else { } else {
MenuItem no_folders_item = new MenuItem (_("No Remote Folders Yet")) { MenuItem no_folders_item = new MenuItem (_("No Remote Folders Yet")) {
Sensitive = false Sensitive = false
}; };
Menu.Add (no_folders_item); Menu.Add (no_folders_item);
} }
// Opens the wizard to add a new remote folder // Opens the wizard to add a new remote folder
@ -204,10 +191,8 @@ namespace SparkleShare {
Application.Invoke (delegate { Application.Invoke (delegate {
if (SparkleUI.Intro == null) { if (SparkleUI.Intro == null) {
SparkleUI.Intro = new SparkleIntro (); SparkleUI.Intro = new SparkleIntro ();
SparkleUI.Intro.ShowServerForm (true); SparkleUI.Intro.ShowServerForm (true);
} }
if (!SparkleUI.Intro.Visible) if (!SparkleUI.Intro.Visible)
@ -215,7 +200,6 @@ namespace SparkleShare {
SparkleUI.Intro.ShowAll (); SparkleUI.Intro.ShowAll ();
SparkleUI.Intro.Present (); SparkleUI.Intro.Present ();
}); });
}; };
@ -230,10 +214,8 @@ namespace SparkleShare {
notify_item = new MenuItem (_("Turn Notifications On")); notify_item = new MenuItem (_("Turn Notifications On"));
notify_item.Activated += delegate { notify_item.Activated += delegate {
SparkleShare.Controller.ToggleNotifications (); SparkleShare.Controller.ToggleNotifications ();
CreateMenu (); CreateMenu ();
}; };
Menu.Add (notify_item); Menu.Add (notify_item);
@ -243,10 +225,8 @@ namespace SparkleShare {
MenuItem about_item = new MenuItem (_("About SparkleShare")); MenuItem about_item = new MenuItem (_("About SparkleShare"));
about_item.Activated += delegate { about_item.Activated += delegate {
SparkleAbout about = new SparkleAbout (); SparkleAbout about = new SparkleAbout ();
about.ShowAll (); about.ShowAll ();
}; };
Menu.Add (about_item); Menu.Add (about_item);
@ -260,9 +240,7 @@ namespace SparkleShare {
}; };
Menu.Add (quit_item); Menu.Add (quit_item);
Menu.ShowAll (); Menu.ShowAll ();
} }
@ -270,19 +248,14 @@ namespace SparkleShare {
// event log for each repository works correctly // event log for each repository works correctly
private EventHandler OpenEventLogDelegate (string path) private EventHandler OpenEventLogDelegate (string path)
{ {
return delegate { return delegate {
SparkleShare.UI.AddEventLog (path); SparkleShare.UI.AddEventLog (path);
}; };
} }
public void UpdateMenu () public void UpdateMenu ()
{ {
Menu.Remove (Menu.Children [0]); Menu.Remove (Menu.Children [0]);
MenuItem status_menu_item = new MenuItem (StateText) { MenuItem status_menu_item = new MenuItem (StateText) {
@ -293,95 +266,73 @@ namespace SparkleShare {
Menu.ReorderChild (status_menu_item, 0); Menu.ReorderChild (status_menu_item, 0);
Menu.ShowAll (); Menu.ShowAll ();
} }
// Makes the menu visible // Makes the menu visible
private void ShowMenu (object o, EventArgs args) private void ShowMenu (object o, EventArgs args)
{ {
Menu.Popup (null, null, SetPosition, 0, Global.CurrentEventTime); Menu.Popup (null, null, SetPosition, 0, Global.CurrentEventTime);
} }
// Makes sure the menu pops up in the right position // 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) 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); PositionMenu (menu, out x, out y, out push_in, Handle);
} }
// The state when there's nothing going on // The state when there's nothing going on
private void SetNormalState () private void SetNormalState ()
{ {
SetNormalState (false); SetNormalState (false);
} }
// The state when there's nothing going on // The state when there's nothing going on
private void SetNormalState (bool error) private void SetNormalState (bool error)
{ {
Animation.Stop (); Animation.Stop ();
if (SparkleShare.Controller.Folders.Count == 0) { if (SparkleShare.Controller.Folders.Count == 0) {
StateText = _("Welcome to SparkleShare!"); StateText = _("Welcome to SparkleShare!");
Application.Invoke (delegate { Application.Invoke (delegate {
Pixbuf = AnimationFrames [0]; Pixbuf = AnimationFrames [0];
}); });
} else { } else {
if (error) { if (error) {
StateText = _("Not everything is synced"); StateText = _("Not everything is synced");
Application.Invoke (delegate { Application.Invoke (delegate {
Pixbuf = SparkleUIHelpers.GetIcon ("sparkleshare-syncing-error", 24); Pixbuf = SparkleUIHelpers.GetIcon ("sparkleshare-syncing-error", 24);
}); });
} else { } else {
StateText = _("Up to date") + " (" + SparkleShare.Controller.FolderSize + ")"; StateText = _("Up to date") + " (" + SparkleShare.Controller.FolderSize + ")";
Application.Invoke (delegate { Application.Invoke (delegate {
Pixbuf = AnimationFrames [0]; Pixbuf = AnimationFrames [0];
}); });
} }
} }
} }
// The state when animating // The state when animating
private void SetAnimationState () private void SetAnimationState ()
{ {
StateText = _("Syncing…"); StateText = _("Syncing…");
if (!Animation.Enabled) if (!Animation.Enabled)
Animation.Start (); Animation.Start ();
} }
} }
public class SparkleMenuItem : ImageMenuItem { public class SparkleMenuItem : ImageMenuItem {
public SparkleMenuItem (string text) : base (text) public SparkleMenuItem (string text) : base (text)
{ {
SetProperty ("always-show-image", new GLib.Value (true)); SetProperty ("always-show-image", new GLib.Value (true));
} }
} }
} }