diff --git a/SparkleShare/Mac/SparkleShare/SparkleIntro.cs b/SparkleShare/Mac/SparkleShare/SparkleIntro.cs new file mode 100644 index 00000000..baf970c8 --- /dev/null +++ b/SparkleShare/Mac/SparkleShare/SparkleIntro.cs @@ -0,0 +1,159 @@ +// SparkleShare, an instant update workflow to Git. +// 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.Timers; +using MonoMac.Foundation; +using MonoMac.AppKit; +using MonoMac.ObjCRuntime; +using MonoMac.WebKit; +using Mono.Unix; + +namespace SparkleShare { + + public class SparkleIntro : SparkleWindow { + + private NSButton NextButton; + private NSButton SyncButton; + private NSForm UserInfoForm; + + + public SparkleIntro () : base () + { + + ShowUserForm (); + + } + + + public void ShowUserForm () + { + + Reset (); + + Header = "Welcome to SparkleShare!"; + Description = "Before we can create a SparkleShare folder on this\n" + + "computer, we need a few bits of information from you."; + + + UserInfoForm = new NSForm (new RectangleF (250, 190, 350, 64)); + UserInfoForm.AddEntry ("Full Name:"); + UserInfoForm.AddEntry ("Email Address:"); + UserInfoForm.CellSize = new SizeF (280, 22); + + string login_name = UnixUserInfo.GetLoginName (); + string full_name = new UnixUserInfo (login_name).RealName; + UserInfoForm.Cells [0].StringValue = full_name; + + + NextButton = new NSButton () { + Title = "Next", + Enabled = false + }; + + NextButton.Activated += delegate { + + SparkleShare.Controller.UserName = UserInfoForm.Cells [0].StringValue.Trim (); + SparkleShare.Controller.UserEmail = UserInfoForm.Cells [1].StringValue.Trim (); + + SparkleShare.Controller.GenerateKeyPair (); + + ShowServerForm (); + + }; + + + // TODO: Ugly hack, do properly with events + Timer timer = new Timer () { + Interval = 500 + }; + + timer.Elapsed += delegate { + + InvokeOnMainThread (delegate { + + bool name_is_correct = + !UserInfoForm.Cells [0].StringValue.Trim ().Equals (""); + + bool email_is_correct = + !UserInfoForm.Cells [1].StringValue.Trim ().Equals (""); + + NextButton.Enabled = (name_is_correct && email_is_correct); + + }); + + }; + + timer.Start (); + + ContentView.AddSubview (UserInfoForm); + Buttons.Add (NextButton); + + ShowAll (); + + } + + + public void ShowServerForm () + { + + Reset (); + + Header = "Where is your remote folder?"; + Description = ""; + + + SyncButton = new NSButton () { + Title = "Sync", + Enabled = false + }; + + + Buttons.Add (SyncButton); + + ShowAll (); + + } + + } + +} + + + + + + // proto.SetButtonType (NSButtonType.Radio) ; + + // NSButton button = new NSButton (new RectangleF (150, 0, 350, 300)) { + // Cell = proto, + // Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", + // NSFontTraitMask.Bold, + // 0, 14) + // }; + + // NSMatrix matrix = new NSMatrix (new RectangleF (300, 00, 300, 300), NSMatrixMode.Radio, proto, 4, 1); + + + + // matrix.Cells [0].Title = "My own server:"; + // matrix.Cells [1].Title = "Github\nFree hosting"; + // matrix.Cells [2].Title = "Gitorious"; + // matrix.Cells [3].Title = "The GNOME Project"; + + diff --git a/SparkleShare/Mac/SparkleShare/SparkleLog.cs b/SparkleShare/Mac/SparkleShare/SparkleLog.cs index 33e241e9..da178ce8 100644 --- a/SparkleShare/Mac/SparkleShare/SparkleLog.cs +++ b/SparkleShare/Mac/SparkleShare/SparkleLog.cs @@ -39,7 +39,7 @@ namespace SparkleShare { public SparkleLog (string path) : base () { - + LocalPath = path; Delegate = new LogDelegate (); diff --git a/SparkleShare/Mac/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleShare/SparkleStatusIcon.cs index c8437eb7..2d9c7ec7 100644 --- a/SparkleShare/Mac/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleShare/SparkleStatusIcon.cs @@ -238,7 +238,7 @@ namespace SparkleShare { SyncMenuItem.Enabled = false; SyncMenuItem.Activated += delegate { - new SparkleWindow (); + new SparkleIntro (); }; Menu.AddItem (SyncMenuItem); diff --git a/SparkleShare/Mac/SparkleShare/SparkleWindow.cs b/SparkleShare/Mac/SparkleShare/SparkleWindow.cs index 0cb8dcee..7a326fc7 100644 --- a/SparkleShare/Mac/SparkleShare/SparkleWindow.cs +++ b/SparkleShare/Mac/SparkleShare/SparkleWindow.cs @@ -16,23 +16,33 @@ using System; +using System.Collections.Generic; using System.Drawing; +using System.IO; using MonoMac.Foundation; using MonoMac.AppKit; using MonoMac.ObjCRuntime; using MonoMac.WebKit; +using Mono.Unix; namespace SparkleShare { public class SparkleWindow : NSWindow { - - public readonly string LocalPath; private NSImage SideSplash; + private NSImageView SideSplashView; + + public List Buttons; + public string Header; + public string Description; + + private NSTextField HeaderTextField; + private NSTextField DescriptionTextField; + public SparkleWindow () : base () { - + SetFrame (new RectangleF (0, 0, 640, 480), true); Center (); @@ -46,50 +56,85 @@ namespace SparkleShare { HasShadow = true; BackingType = NSBackingStore.Buffered; - SideSplash = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/side-splash.png"); - SideSplash.Size = new SizeF (150, 480); + + string side_splash_path = Path.Combine (NSBundle.MainBundle.ResourcePath, + "Pixmaps", "side-splash.png"); + + SideSplash = new NSImage (side_splash_path) { + Size = new SizeF (150, 480) + }; + + SideSplashView = new NSImageView () { + Image = SideSplash, + Frame = new RectangleF (0, 0, 150, 480) + }; - - - - NSButtonCell proto = new NSButtonCell { - Title = " Github" - }; - - NSText text = new NSText (new RectangleF (150,150,350,300)) { - Value = "DDDDDDDD" - }; - - proto.SetButtonType (NSButtonType.Radio) ; - - NSButton button = new NSButton (new RectangleF (150, 0, 350, 300)) { - Cell = proto, - Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", - NSFontTraitMask.Bold, - 0, 14) - }; - - NSMatrix matrix = new NSMatrix (new RectangleF (300, 00, 300, 300), NSMatrixMode.Radio, proto, 4, 1); - + Buttons = new List (); - matrix.Cells [0].Title = "My own server:"; - matrix.Cells [1].Title = "Github\nFree hosting"; - matrix.Cells [2].Title = "Gitorious"; - matrix.Cells [3].Title = "The GNOME Project"; - - ContentView.AddSubview (new NSImageView (new RectangleF (0, 0, 150, 480)) { Image = SideSplash}); - ContentView.AddSubview (new NSTextField (new RectangleF (200, 100, 128, 25)) { BezelStyle = NSTextFieldBezelStyle.Square, Editable=false}); - ContentView.AddSubview (button); - ContentView.AddSubview (text); + HeaderTextField = new NSTextField (new RectangleF (200, Frame.Height - 100, 350, 48)) { + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Font = NSFontManager.SharedFontManager.FontWithFamily + ("Lucida Grande", NSFontTraitMask.Bold, 0, 18) + }; + DescriptionTextField = new NSTextField (new RectangleF (200, Frame.Height - 155 , 350, 64)) { + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false + }; + NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); MakeKeyAndOrderFront (this); + + } + + + public void Reset () { + + ContentView.Subviews = new NSView [0]; + Buttons = new List (); + + Header = ""; + Description = ""; } + + public void ShowAll () { + + HeaderTextField.StringValue = Header; + DescriptionTextField.StringValue = Description; + + ContentView.AddSubview (HeaderTextField); + ContentView.AddSubview (DescriptionTextField); + + ContentView.AddSubview (SideSplashView); + + int i = 0; + + if (Buttons.Count > 0) { + + DefaultButtonCell = Buttons [0].Cell; + + foreach (NSButton button in Buttons) { + + button.BezelStyle = NSBezelStyle.Rounded; + button.Frame = new RectangleF (Frame.Width - 20 - (120 * (i + 1)) - (4 * i), 12, 120, 31); + ContentView.AddSubview (button); + + i++; + + } + + } + + } + } } diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index eff4d546..49edf96c 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -849,7 +849,7 @@ namespace SparkleShare { "\temail = " + user_email); writer.Close (); - SparkleHelpers.DebugInfo ("Config", "Created '" + global_config_file_path + "'"); + SparkleHelpers.DebugInfo ("Config", "Updated '" + global_config_file_path + "'"); } @@ -858,18 +858,29 @@ namespace SparkleShare { public void GenerateKeyPair () { - string keys_path = SparklePaths.SparkleKeysPath; + string keys_path = SparklePaths.SparkleKeysPath; string key_file_name = "sparkleshare." + UserEmail + ".key"; + string key_file_path = Path.Combine (keys_path, key_file_name); + + + if (File.Exists (key_file_path)) { + + SparkleHelpers.DebugInfo ("Config", "Key already exists (" + key_file_name + "), " + + "leaving it untouched"); + return; + + } - Process process = new Process () { - EnableRaisingEvents = true - }; if (!Directory.Exists (keys_path)) Directory.CreateDirectory (keys_path); if (!File.Exists (key_file_name)) { + Process process = new Process () { + EnableRaisingEvents = true + }; + process.StartInfo.WorkingDirectory = keys_path; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; @@ -884,8 +895,8 @@ namespace SparkleShare { process.Exited += delegate { - SparkleHelpers.DebugInfo ("Config", "Created key '" + key_file_name + "'"); - SparkleHelpers.DebugInfo ("Config", "Created key '" + key_file_name + ".pub'"); + SparkleHelpers.DebugInfo ("Config", "Created private key '" + key_file_name + "'"); + SparkleHelpers.DebugInfo ("Config", "Created public key '" + key_file_name + ".pub'"); };