From 6f494ba384fabadbe5a03b741218c0ad5372db9f Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 4 Jul 2011 18:52:46 +0100 Subject: [PATCH] Rename intro to setup and add a controller --- SparkleShare/Mac/SparkleIntro.cs | 445 --------------------- SparkleShare/Mac/SparkleSetup.cs | 369 +++++++++++++++++ SparkleShare/Mac/SparkleSetupController.cs | 142 +++++++ SparkleShare/Mac/SparkleShare.csproj | 3 +- SparkleShare/Mac/SparkleStatusIcon.cs | 14 +- SparkleShare/Mac/SparkleUI.cs | 6 +- SparkleShare/SparkleController.cs | 2 +- 7 files changed, 524 insertions(+), 457 deletions(-) delete mode 100644 SparkleShare/Mac/SparkleIntro.cs create mode 100644 SparkleShare/Mac/SparkleSetup.cs create mode 100644 SparkleShare/Mac/SparkleSetupController.cs diff --git a/SparkleShare/Mac/SparkleIntro.cs b/SparkleShare/Mac/SparkleIntro.cs deleted file mode 100644 index 37d25c93..00000000 --- a/SparkleShare/Mac/SparkleIntro.cs +++ /dev/null @@ -1,445 +0,0 @@ -// SparkleShare, a collaboration and sharing tool. -// Copyright (C) 2010 Hylke Bons -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - - -using System; -using System.Drawing; -using System.IO; -using System.Timers; - -using Mono.Unix; -using MonoMac.Foundation; -using MonoMac.AppKit; -using MonoMac.ObjCRuntime; -using MonoMac.WebKit; - -namespace SparkleShare { - - public class SparkleIntro : SparkleWindow { - - private NSButton ContinueButton; - private NSButton SyncButton; - private NSButton TryAgainButton; - private NSButton CancelButton; - private NSButton SkipButton; - private NSButton OpenFolderButton; - private NSButton FinishButton; - private NSForm UserInfoForm; - private NSProgressIndicator ProgressIndicator; - private NSTextField AddressTextField; - private NSTextField FolderNameTextField; - private NSTextField ServerTypeLabel; - private NSTextField AddressLabel; - private NSTextField FolderNameLabel; - private NSTextField FolderNameHelpLabel; - private NSButtonCell ButtonCellProto; - private NSMatrix Matrix; - private int ServerType; - private bool ServerFormOnly; - - - public SparkleIntro () : base () - { - ServerFormOnly = false; - } - - - public void ShowAccountForm () - { - Reset (); - - Header = "Welcome to SparkleShare!"; - Description = "Before we can create a SparkleShare folder on this " + - "computer, we need some information from you."; - - UserInfoForm = new NSForm (new RectangleF (250, 115, 350, 64)); - UserInfoForm.AddEntry ("Full Name:"); - UserInfoForm.AddEntry ("Email Address:"); - UserInfoForm.CellSize = new SizeF (280, 22); - UserInfoForm.IntercellSpacing = new SizeF (4, 4); - UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail; - UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail; - - UserInfoForm.Cells [0].StringValue = SparkleShare.Controller.UserName; - UserInfoForm.Cells [1].StringValue = SparkleShare.Controller.UserEmail; - - ContinueButton = new NSButton () { - Title = "Continue", - Enabled = false - }; - - ContinueButton.Activated += delegate { - SparkleShare.Controller.UserName = UserInfoForm.Cells [0].StringValue.Trim (); - SparkleShare.Controller.UserEmail = UserInfoForm.Cells [1].StringValue.Trim (); - SparkleShare.Controller.GenerateKeyPair (); - SparkleUI.StatusIcon.CreateMenu (); - - InvokeOnMainThread (delegate { - ShowServerForm (); - }); - }; - - // TODO: Ugly hack, do properly with events - Timer timer = new Timer () { - Interval = 50 - }; - - timer.Elapsed += delegate { - InvokeOnMainThread (delegate { - bool name_is_correct = - !UserInfoForm.Cells [0].StringValue.Trim ().Equals (""); - - bool email_is_correct = SparkleShare.Controller.IsValidEmail ( - UserInfoForm.Cells [1].StringValue.Trim ()); - - ContinueButton.Enabled = (name_is_correct && email_is_correct); - }); - }; - - timer.Start (); - - ContentView.AddSubview (UserInfoForm); - Buttons.Add (ContinueButton); - - ShowAll (); - } - - - public void ShowServerForm (bool server_form_only) - { - ServerFormOnly = server_form_only; - ShowServerForm (); - } - - - public void ShowServerForm () - { - Reset (); - - Header = "Where is your remote folder?"; - Description = ""; - - ServerTypeLabel = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (150, Frame.Height - 139 , 160, 17), - StringValue = "Server Type:", - Font = SparkleUI.Font - }; - - AddressLabel = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (150, Frame.Height - 237 , 160, 17), - StringValue = "Address:", - Font = SparkleUI.Font - }; - - FolderNameLabel = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (150, Frame.Height - 264 , 160, 17), - StringValue = "Folder Name:", - Font = SparkleUI.Font - }; - - - AddressTextField = new NSTextField () { - Frame = new RectangleF (320, Frame.Height - 240 , 256, 22), - Font = SparkleUI.Font - }; - - AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; - - FolderNameTextField = new NSTextField () { - Frame = new RectangleF (320, Frame.Height - (240 + 22 + 4) , 256, 22), - StringValue = "" - }; - - FolderNameTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; - - FolderNameHelpLabel = new NSTextField () { - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - TextColor = NSColor.DisabledControlText, - Editable = false, - Frame = new RectangleF (320, Frame.Height - 285 , 200, 17), - StringValue = "e.g. ‘rupert/website-design’" - }; - - - ServerType = 0; - - ButtonCellProto = new NSButtonCell (); - ButtonCellProto.SetButtonType (NSButtonType.Radio) ; - - Matrix = new NSMatrix (new RectangleF (315, 180, 256, 78), - NSMatrixMode.Radio, ButtonCellProto, 4, 1); - - Matrix.CellSize = new SizeF (256, 18); - - Matrix.Cells [0].Title = "My own server"; - Matrix.Cells [1].Title = "Github"; - Matrix.Cells [2].Title = "Gitorious"; - Matrix.Cells [3].Title = "The GNOME Project"; - - foreach (NSCell cell in Matrix.Cells) - cell.Font = SparkleUI.Font; - - // TODO: Ugly hack, do properly with events - Timer timer = new Timer () { - Interval = 50 - }; - - timer.Elapsed += delegate { - - InvokeOnMainThread (delegate { - - if (Matrix.SelectedRow != ServerType) { - ServerType = Matrix.SelectedRow; - - AddressTextField.Enabled = (ServerType == 0); - - switch (ServerType) { - case 0: - AddressTextField.StringValue = ""; - FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’"; - break; - case 1: - AddressTextField.StringValue = "ssh://git@github.com/"; - FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’"; - break; - case 2: - AddressTextField.StringValue = "ssh://git@gitorious.org/"; - FolderNameHelpLabel.StringValue = "e.g. ‘project/website-design’"; - break; - case 3: - AddressTextField.StringValue = "ssh://git@gnome.org/git/"; - FolderNameHelpLabel.StringValue = "e.g. ‘gnome-icon-theme’"; - break; - } - } - - - if (ServerType == 0 && !AddressTextField.StringValue.Trim ().Equals ("") - && !FolderNameTextField.StringValue.Trim ().Equals ("")) { - - SyncButton.Enabled = true; - - } else if (ServerType != 0 && - !FolderNameTextField.StringValue.Trim ().Equals ("")) { - - SyncButton.Enabled = true; - - } else { - SyncButton.Enabled = false; - } - }); - - }; - - timer.Start (); - - ContentView.AddSubview (ServerTypeLabel); - ContentView.AddSubview (Matrix); - - ContentView.AddSubview (AddressLabel); - ContentView.AddSubview (AddressTextField); - - ContentView.AddSubview (FolderNameLabel); - ContentView.AddSubview (FolderNameTextField); - ContentView.AddSubview (FolderNameHelpLabel); - - SyncButton = new NSButton () { - Title = "Sync", - Enabled = false - }; - - SyncButton.Activated += delegate { - string folder_name = FolderNameTextField.StringValue; - string server = AddressTextField.StringValue; - string canonical_name = Path.GetFileNameWithoutExtension (folder_name); - - ShowSyncingPage (canonical_name); - - SparkleShare.Controller.FolderFetched += delegate { - InvokeOnMainThread (delegate { - ShowSuccessPage (canonical_name); - }); - }; - - SparkleShare.Controller.FolderFetchError += delegate { - InvokeOnMainThread (delegate { - ShowErrorPage (); - }); - }; - - SparkleShare.Controller.FetchFolder (server, folder_name); - }; - - Buttons.Add (SyncButton); - - if (ServerFormOnly) { - CancelButton = new NSButton () { - Title = "Cancel" - }; - - CancelButton.Activated += delegate { - InvokeOnMainThread (delegate { - PerformClose (this); - }); - }; - - Buttons.Add (CancelButton); - } else { - SkipButton = new NSButton () { - Title = "Skip" - }; - - SkipButton.Activated += delegate { - InvokeOnMainThread (delegate { - ShowCompletedPage (); - }); - }; - - Buttons.Add (SkipButton); - } - - ShowAll (); - } - - - public void ShowErrorPage () - { - Reset (); - - Header = "Something went wrong…"; - Description = ""; - - TryAgainButton = new NSButton () { - Title = "Try again…" - }; - - TryAgainButton.Activated += delegate { - InvokeOnMainThread (delegate { - ShowServerForm (); - }); - }; - - Buttons.Add (TryAgainButton); - - ShowAll (); - } - - - private void ShowSyncingPage (string name) - { - Reset (); - - Header = "Syncing folder ‘" + name + "’…"; - Description = "This may take a while.\n" + - "Are you sure it’s not coffee o'clock?"; - - ProgressIndicator = new NSProgressIndicator () { - Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20), - Style = NSProgressIndicatorStyle.Bar - }; - - ProgressIndicator.StartAnimation (this); - - ContentView.AddSubview (ProgressIndicator); - - FinishButton = new NSButton () { - Title = "Finish", - Enabled = false - }; - - Buttons.Add (FinishButton); - - ShowAll (); - } - - - public void ShowSuccessPage (string folder_name) - { - Reset (); - - Header = "Folder synced succesfully!"; - Description = "Now you can access the synced files from ‘" + folder_name + "’ in " + - "your SparkleShare folder."; - - FinishButton = new NSButton () { - Title = "Finish" - }; - - FinishButton.Activated += delegate { - InvokeOnMainThread (delegate { - SparkleUI.StatusIcon.CreateMenu (); - PerformClose (this); - }); - }; - - OpenFolderButton = new NSButton () { - Title = "Open Folder" - }; - - OpenFolderButton.Activated += delegate { - SparkleShare.Controller.OpenSparkleShareFolder (folder_name); - }; - - Buttons.Add (FinishButton); - Buttons.Add (OpenFolderButton); - - ShowAll (); - - NSApplication.SharedApplication.RequestUserAttention - (NSRequestUserAttentionType.CriticalRequest); - } - - - private void ShowCompletedPage () - { - Reset (); - - Header = "SparkleShare is ready to go!"; - Description = "Now you can start accepting invitations from others. " + - "Just click on invitations you get by email and " + - "we will take care of the rest."; - - FinishButton = new NSButton () { - Title = "Finish" - }; - - FinishButton.Activated += delegate { - InvokeOnMainThread (delegate { - SparkleUI.StatusIcon.CreateMenu (); - PerformClose (this); - }); - - }; - - Buttons.Add (FinishButton); - - ShowAll (); - } - } -} diff --git a/SparkleShare/Mac/SparkleSetup.cs b/SparkleShare/Mac/SparkleSetup.cs new file mode 100644 index 00000000..9860d1d7 --- /dev/null +++ b/SparkleShare/Mac/SparkleSetup.cs @@ -0,0 +1,369 @@ +// SparkleShare, a collaboration and sharing tool. +// Copyright (C) 2010 Hylke Bons +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + +using System; +using System.Drawing; +using System.IO; +using System.Timers; + +using Mono.Unix; +using MonoMac.Foundation; +using MonoMac.AppKit; +using MonoMac.ObjCRuntime; +using MonoMac.WebKit; + +namespace SparkleShare { + + public class SparkleSetup : SparkleWindow { + + public SparkleSetupController Controller = new SparkleSetupController (); + + private NSButton ContinueButton; + private NSButton SyncButton; + private NSButton TryAgainButton; + private NSButton CancelButton; + private NSButton SkipButton; + private NSButton OpenFolderButton; + private NSButton FinishButton; + private NSForm UserInfoForm; + private NSProgressIndicator ProgressIndicator; + private NSTextField AddressTextField; + private NSTextField FolderNameTextField; + private NSTextField ServerTypeLabel; + private NSTextField AddressLabel; + private NSTextField FolderNameLabel; + private NSTextField FolderNameHelpLabel; + private NSButtonCell ButtonCellProto; + private NSMatrix Matrix; + private int ServerType; + private Timer timer; + + + public SparkleSetup () : base () + { + Controller.ChangePageEvent += delegate (PageType type) { + InvokeOnMainThread (delegate { + Reset (); + + switch (type) { + case PageType.Setup: + + Header = "Welcome to SparkleShare!"; + Description = "Before we can create a SparkleShare folder on this " + + "computer, we need some information from you."; + + UserInfoForm = new NSForm (new RectangleF (250, 115, 350, 64)); + + UserInfoForm.AddEntry ("Full Name:"); + UserInfoForm.AddEntry ("Email Address:"); + + UserInfoForm.CellSize = new SizeF (280, 22); + UserInfoForm.IntercellSpacing = new SizeF (4, 4); + UserInfoForm.Cells [0].LineBreakMode = NSLineBreakMode.TruncatingTail; + UserInfoForm.Cells [1].LineBreakMode = NSLineBreakMode.TruncatingTail; + + UserInfoForm.Cells [0].StringValue = SparkleShare.Controller.UserName; + UserInfoForm.Cells [1].StringValue = SparkleShare.Controller.UserEmail; + + // TODO: Ugly hack, do properly with events + timer = new Timer () { + Interval = 50 + }; + + ContinueButton = new NSButton () { + Title = "Continue", + Enabled = false + }; + + ContinueButton.Activated += delegate { + timer.Stop (); + timer = null; + + string full_name = UserInfoForm.Cells [0].StringValue.Trim (); + string email = UserInfoForm.Cells [1].StringValue.Trim (); + + Controller.SetupPageCompleted (full_name, email); + }; + + timer.Elapsed += delegate { + InvokeOnMainThread (delegate { + bool name_is_valid = !UserInfoForm.Cells [0].StringValue.Trim ().Equals (""); + + bool email_is_valid = SparkleShare.Controller.IsValidEmail ( + UserInfoForm.Cells [1].StringValue.Trim ()); + + ContinueButton.Enabled = (name_is_valid && email_is_valid); + }); + }; + + timer.Start (); + + ContentView.AddSubview (UserInfoForm); + Buttons.Add (ContinueButton); + + break; + + case PageType.Add: + + Header = "Where is your remote folder?"; + Description = ""; + + ServerTypeLabel = new NSTextField () { + Alignment = NSTextAlignment.Right, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (150, Frame.Height - 139 , 160, 17), + StringValue = "Server Type:", + Font = SparkleUI.Font + }; + + AddressLabel = new NSTextField () { + Alignment = NSTextAlignment.Right, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (150, Frame.Height - 237 , 160, 17), + StringValue = "Address:", + Font = SparkleUI.Font + }; + + FolderNameLabel = new NSTextField () { + Alignment = NSTextAlignment.Right, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (150, Frame.Height - 264 , 160, 17), + StringValue = "Folder Name:", + Font = SparkleUI.Font + }; + + + AddressTextField = new NSTextField () { + Frame = new RectangleF (320, Frame.Height - 240 , 256, 22), + Font = SparkleUI.Font, + StringValue = Controller.PreviousServer + }; + + AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; + + FolderNameTextField = new NSTextField () { + Frame = new RectangleF (320, Frame.Height - (240 + 22 + 4) , 256, 22), + StringValue = Controller.PreviousFolder + }; + + FolderNameTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; + + FolderNameHelpLabel = new NSTextField () { + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + TextColor = NSColor.DisabledControlText, + Editable = false, + Frame = new RectangleF (320, Frame.Height - 285 , 200, 17), + StringValue = "e.g. ‘rupert/website-design’" + }; + + ServerType = 0; + + ButtonCellProto = new NSButtonCell (); + ButtonCellProto.SetButtonType (NSButtonType.Radio) ; + + Matrix = new NSMatrix (new RectangleF (315, 180, 256, 78), + NSMatrixMode.Radio, ButtonCellProto, 4, 1); + + Matrix.CellSize = new SizeF (256, 18); + + Matrix.Cells [0].Title = "My own server"; + Matrix.Cells [1].Title = "Github"; + Matrix.Cells [2].Title = "Gitorious"; + Matrix.Cells [3].Title = "The GNOME Project"; + + foreach (NSCell cell in Matrix.Cells) + cell.Font = SparkleUI.Font; + + // TODO: Ugly hack, do properly with events + timer = new Timer () { + Interval = 50 + }; + + timer.Elapsed += delegate { + InvokeOnMainThread (delegate { + if (Matrix.SelectedRow != ServerType) { + ServerType = Matrix.SelectedRow; + + AddressTextField.Enabled = (ServerType == 0); + + switch (ServerType) { + case 0: + AddressTextField.StringValue = ""; + FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’"; + break; + case 1: + AddressTextField.StringValue = "ssh://git@github.com/"; + FolderNameHelpLabel.StringValue = "e.g. ‘rupert/website-design’"; + break; + case 2: + AddressTextField.StringValue = "ssh://git@gitorious.org/"; + FolderNameHelpLabel.StringValue = "e.g. ‘project/website-design’"; + break; + case 3: + AddressTextField.StringValue = "ssh://git@gnome.org/git/"; + FolderNameHelpLabel.StringValue = "e.g. ‘gnome-icon-theme’"; + break; + } + } + + + if (ServerType == 0 && !AddressTextField.StringValue.Trim ().Equals ("") + && !FolderNameTextField.StringValue.Trim ().Equals ("")) { + + SyncButton.Enabled = true; + + } else if (ServerType != 0 && + !FolderNameTextField.StringValue.Trim ().Equals ("")) { + + SyncButton.Enabled = true; + + } else { + SyncButton.Enabled = false; + } + }); + + }; + + timer.Start (); + + ContentView.AddSubview (ServerTypeLabel); + ContentView.AddSubview (Matrix); + + ContentView.AddSubview (AddressLabel); + ContentView.AddSubview (AddressTextField); + + ContentView.AddSubview (FolderNameLabel); + ContentView.AddSubview (FolderNameTextField); + ContentView.AddSubview (FolderNameHelpLabel); + + SyncButton = new NSButton () { + Title = "Sync", + Enabled = false + }; + + SyncButton.Activated += delegate { + timer.Stop (); + timer = null; + + string folder_name = FolderNameTextField.StringValue; + string server = AddressTextField.StringValue; + Controller.AddPageCompleted (server, folder_name); + }; + + Buttons.Add (SyncButton); + + CancelButton = new NSButton () { + Title = "Cancel" + }; + + CancelButton.Activated += delegate { + InvokeOnMainThread (delegate { + PerformClose (this); + }); + }; + + Buttons.Add (CancelButton); + + break; + + case PageType.Syncing: + + Header = "Syncing folder ‘" + Controller.SyncingFolder + "’…"; + Description = "This may take a while.\n" + + "Are you sure it’s not coffee o'clock?"; + + ProgressIndicator = new NSProgressIndicator () { + Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20), + Style = NSProgressIndicatorStyle.Bar + }; + + ProgressIndicator.StartAnimation (this); + ContentView.AddSubview (ProgressIndicator); + + FinishButton = new NSButton () { + Title = "Finish", + Enabled = false + }; + + Buttons.Add (FinishButton); + + break; + + case PageType.Error: + + Header = "Something went wrong…"; + Description = ""; + + TryAgainButton = new NSButton () { + Title = "Try again…" + }; + + TryAgainButton.Activated += delegate { + Controller.ErrorPageCompleted (); + }; + + Buttons.Add (TryAgainButton); + + break; + + case PageType.Finished: + + Header = "Folder synced succesfully!"; + Description = "Now you can access the synced files from " + + "‘" + Controller.SyncingFolder + "’ in " + + "your SparkleShare folder."; + + FinishButton = new NSButton () { + Title = "Finish" + }; + + FinishButton.Activated += delegate { + InvokeOnMainThread (delegate { + PerformClose (this); + }); + }; + + OpenFolderButton = new NSButton () { + Title = "Open Folder" + }; + + OpenFolderButton.Activated += delegate { + SparkleShare.Controller.OpenSparkleShareFolder (Controller.SyncingFolder); + }; + + Buttons.Add (FinishButton); + Buttons.Add (OpenFolderButton); + + NSApplication.SharedApplication.RequestUserAttention + (NSRequestUserAttentionType.CriticalRequest); + + break; + } + + ShowAll (); + }); + }; + } + } +} diff --git a/SparkleShare/Mac/SparkleSetupController.cs b/SparkleShare/Mac/SparkleSetupController.cs new file mode 100644 index 00000000..02cd880e --- /dev/null +++ b/SparkleShare/Mac/SparkleSetupController.cs @@ -0,0 +1,142 @@ +// SparkleShare, a collaboration and sharing tool. +// Copyright (C) 2010 Hylke Bons +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + +using System; +using System.IO; + +namespace SparkleShare { + + public enum PageType { + Setup, + Add, + Syncing, + Error, + Finished + } + + + public class SparkleSetupController { + + public event ChangePageEventHandler ChangePageEvent; + public delegate void ChangePageEventHandler (PageType page); + + public string PreviousServer { + get { + return this.previous_server; + } + } + + public string PreviousFolder { + get { + return this.previous_folder; + } + } + + public string SyncingFolder { + get { + return this.syncing_folder; + } + } + + public PageType PreviousPage { + get { + return this.previous_page; + } + } + + private string previous_server = ""; + private string previous_folder = ""; + private string syncing_folder = ""; + private PageType previous_page; + + public SparkleSetupController () + { + ChangePageEvent += delegate (PageType page) { + this.previous_page = page; + }; + } + + + public void ShowAddPage () + { + if (ChangePageEvent != null) + ChangePageEvent (PageType.Add); + } + + + public void ShowSetupPage () + { + if (ChangePageEvent != null) + ChangePageEvent (PageType.Setup); + } + + + public void SetupPageCompleted (string full_name, string email) + { + SparkleShare.Controller.UserName = full_name; + SparkleShare.Controller.UserEmail = email; + + SparkleShare.Controller.GenerateKeyPair (); + SparkleShare.Controller.UpdateState (); + + if (ChangePageEvent != null) + ChangePageEvent (PageType.Add); + } + + + public void AddPageCompleted (string server, string folder_name) + { + this.syncing_folder = Path.GetFileNameWithoutExtension (folder_name); + this.previous_server = server; + this.previous_folder = folder_name; + + if (ChangePageEvent != null) + ChangePageEvent (PageType.Syncing); + + SparkleShare.Controller.FolderFetched += delegate { + if (ChangePageEvent != null) + ChangePageEvent (PageType.Finished); + + this.syncing_folder = ""; + }; + + SparkleShare.Controller.FolderFetchError += delegate { + if (ChangePageEvent != null) + ChangePageEvent (PageType.Error); + + this.syncing_folder = ""; + }; + + SparkleShare.Controller.FetchFolder (server, this.syncing_folder); + } + + + public void ErrorPageCompleted () + { + if (ChangePageEvent != null) + ChangePageEvent (PageType.Add); + } + + + public void FinishedPageCompleted () + { + this.previous_server = ""; + this.previous_folder = ""; + SparkleShare.Controller.UpdateState (); + } + } +} diff --git a/SparkleShare/Mac/SparkleShare.csproj b/SparkleShare/Mac/SparkleShare.csproj index 8c3a898c..d1c3a5a7 100644 --- a/SparkleShare/Mac/SparkleShare.csproj +++ b/SparkleShare/Mac/SparkleShare.csproj @@ -78,7 +78,6 @@ SparkleController.cs - @@ -93,6 +92,8 @@ + + diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index 4d4b7265..b7c59b6a 100644 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -217,16 +217,16 @@ namespace SparkleShare { InvokeOnMainThread (delegate { NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); - if (SparkleUI.Intro == null) { - SparkleUI.Intro = new SparkleIntro (); - SparkleUI.Intro.ShowServerForm (true); + if (SparkleUI.Setup == null) { + SparkleUI.Setup = new SparkleSetup (); + SparkleUI.Setup.Controller.ShowAddPage (); } - if (!SparkleUI.Intro.IsVisible) - SparkleUI.Intro.ShowServerForm (true); + if (!SparkleUI.Setup.IsVisible) + SparkleUI.Setup.Controller.ShowAddPage (); - SparkleUI.Intro.OrderFrontRegardless (); - SparkleUI.Intro.MakeKeyAndOrderFront (this); + SparkleUI.Setup.OrderFrontRegardless (); + SparkleUI.Setup.MakeKeyAndOrderFront (this); }); }; } diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index 1ac366ef..eb3721aa 100644 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -33,7 +33,7 @@ namespace SparkleShare { public static SparkleStatusIcon StatusIcon; public static SparkleEventLog EventLog; - public static SparkleIntro Intro; + public static SparkleSetup Setup; public static SparkleBubbles Bubbles; public static SparkleAbout About; public static NSFont Font; @@ -80,8 +80,8 @@ namespace SparkleShare { Bubbles = new SparkleBubbles (); if (SparkleShare.Controller.FirstRun) { - Intro = new SparkleIntro (); - Intro.ShowAccountForm (); + Setup = new SparkleSetup (); + Setup.Controller.ShowSetupPage (); } } } diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 1c4377b2..b940d5c6 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -498,7 +498,7 @@ namespace SparkleShare { // Fires events for the current syncing state - private void UpdateState () + public void UpdateState () { foreach (SparkleRepoBase repo in Repositories) { if (repo.Status == SyncStatus.SyncDown ||