[intro] implementation, and fix debug messages in [controller]
This commit is contained in:
parent
5be0c7a404
commit
d3edc8af4a
159
SparkleShare/Mac/SparkleShare/SparkleIntro.cs
Normal file
159
SparkleShare/Mac/SparkleShare/SparkleIntro.cs
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
// SparkleShare, an instant update workflow to Git.
|
||||||
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,7 @@ namespace SparkleShare {
|
||||||
SyncMenuItem.Enabled = false;
|
SyncMenuItem.Enabled = false;
|
||||||
|
|
||||||
SyncMenuItem.Activated += delegate {
|
SyncMenuItem.Activated += delegate {
|
||||||
new SparkleWindow ();
|
new SparkleIntro ();
|
||||||
};
|
};
|
||||||
|
|
||||||
Menu.AddItem (SyncMenuItem);
|
Menu.AddItem (SyncMenuItem);
|
||||||
|
|
|
@ -16,19 +16,29 @@
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using MonoMac.Foundation;
|
using MonoMac.Foundation;
|
||||||
using MonoMac.AppKit;
|
using MonoMac.AppKit;
|
||||||
using MonoMac.ObjCRuntime;
|
using MonoMac.ObjCRuntime;
|
||||||
using MonoMac.WebKit;
|
using MonoMac.WebKit;
|
||||||
|
using Mono.Unix;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleWindow : NSWindow {
|
public class SparkleWindow : NSWindow {
|
||||||
|
|
||||||
public readonly string LocalPath;
|
|
||||||
|
|
||||||
private NSImage SideSplash;
|
private NSImage SideSplash;
|
||||||
|
private NSImageView SideSplashView;
|
||||||
|
|
||||||
|
public List <NSButton> Buttons;
|
||||||
|
public string Header;
|
||||||
|
public string Description;
|
||||||
|
|
||||||
|
private NSTextField HeaderTextField;
|
||||||
|
private NSTextField DescriptionTextField;
|
||||||
|
|
||||||
|
|
||||||
public SparkleWindow () : base ()
|
public SparkleWindow () : base ()
|
||||||
{
|
{
|
||||||
|
@ -46,43 +56,36 @@ namespace SparkleShare {
|
||||||
HasShadow = true;
|
HasShadow = true;
|
||||||
BackingType = NSBackingStore.Buffered;
|
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)
|
||||||
|
|
||||||
NSButtonCell proto = new NSButtonCell {
|
|
||||||
Title = " Github"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NSText text = new NSText (new RectangleF (150,150,350,300)) {
|
SideSplashView = new NSImageView () {
|
||||||
Value = "DDDDDDDD"
|
Image = SideSplash,
|
||||||
|
Frame = new RectangleF (0, 0, 150, 480)
|
||||||
};
|
};
|
||||||
|
|
||||||
proto.SetButtonType (NSButtonType.Radio) ;
|
|
||||||
|
|
||||||
NSButton button = new NSButton (new RectangleF (150, 0, 350, 300)) {
|
Buttons = new List <NSButton> ();
|
||||||
Cell = proto,
|
|
||||||
Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
|
|
||||||
NSFontTraitMask.Bold,
|
HeaderTextField = new NSTextField (new RectangleF (200, Frame.Height - 100, 350, 48)) {
|
||||||
0, 14)
|
BackgroundColor = NSColor.WindowBackground,
|
||||||
|
Bordered = false,
|
||||||
|
Editable = false,
|
||||||
|
Font = NSFontManager.SharedFontManager.FontWithFamily
|
||||||
|
("Lucida Grande", NSFontTraitMask.Bold, 0, 18)
|
||||||
};
|
};
|
||||||
|
|
||||||
NSMatrix matrix = new NSMatrix (new RectangleF (300, 00, 300, 300), NSMatrixMode.Radio, proto, 4, 1);
|
DescriptionTextField = new NSTextField (new RectangleF (200, Frame.Height - 155 , 350, 64)) {
|
||||||
|
BackgroundColor = NSColor.WindowBackground,
|
||||||
|
Bordered = false,
|
||||||
|
Editable = false
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
|
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
|
||||||
|
@ -90,6 +93,48 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Reset () {
|
||||||
|
|
||||||
|
ContentView.Subviews = new NSView [0];
|
||||||
|
Buttons = new List <NSButton> ();
|
||||||
|
|
||||||
|
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++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -849,7 +849,7 @@ namespace SparkleShare {
|
||||||
"\temail = " + user_email);
|
"\temail = " + user_email);
|
||||||
writer.Close ();
|
writer.Close ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created '" + global_config_file_path + "'");
|
SparkleHelpers.DebugInfo ("Config", "Updated '" + global_config_file_path + "'");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,16 +860,27 @@ namespace SparkleShare {
|
||||||
|
|
||||||
string keys_path = SparklePaths.SparkleKeysPath;
|
string keys_path = SparklePaths.SparkleKeysPath;
|
||||||
string key_file_name = "sparkleshare." + UserEmail + ".key";
|
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))
|
if (!Directory.Exists (keys_path))
|
||||||
Directory.CreateDirectory (keys_path);
|
Directory.CreateDirectory (keys_path);
|
||||||
|
|
||||||
if (!File.Exists (key_file_name)) {
|
if (!File.Exists (key_file_name)) {
|
||||||
|
|
||||||
|
Process process = new Process () {
|
||||||
|
EnableRaisingEvents = true
|
||||||
|
};
|
||||||
|
|
||||||
process.StartInfo.WorkingDirectory = keys_path;
|
process.StartInfo.WorkingDirectory = keys_path;
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
@ -884,8 +895,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
process.Exited += delegate {
|
process.Exited += delegate {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created key '" + key_file_name + "'");
|
SparkleHelpers.DebugInfo ("Config", "Created private key '" + key_file_name + "'");
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created key '" + key_file_name + ".pub'");
|
SparkleHelpers.DebugInfo ("Config", "Created public key '" + key_file_name + ".pub'");
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue