From 8bad2b6f01af6d47501904475e03a4533a2f28f9 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 15 Apr 2012 22:34:22 +0200 Subject: [PATCH] controller: use User object --- SparkleShare/SparkleControllerBase.cs | 32 ++++++++------------------ SparkleShare/SparkleSetupController.cs | 9 ++++---- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 450d439d..d1593f69 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -510,8 +510,8 @@ namespace SparkleShare { int midnight = (int) (DateTime.Today.AddDays (1) - new DateTime (1970, 1, 1)).TotalSeconds; string html = event_log_html.Replace ("", event_log) - .Replace ("", UserName) - .Replace ("", "file://" + GetAvatar (UserEmail, 48)) + .Replace ("", CurrentUser.Name) + .Replace ("", "file://" + GetAvatar (CurrentUser.Email, 48)) .Replace ("", midnight.ToString ()); return html; @@ -722,7 +722,7 @@ namespace SparkleShare { public void ImportPrivateKey () { string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath); - string key_file_name = "sparkleshare." + UserEmail + ".key"; + string key_file_name = "sparkleshare." + CurrentUser.Email + ".key"; string key_file_path = Path.Combine (keys_path, key_file_name); if (!File.Exists (key_file_path)) { @@ -752,33 +752,19 @@ namespace SparkleShare { // key in the user's SparkleShare folder if (!File.Exists (pubkey_file_path)) File.Copy (pubkey_file_path, - Path.Combine (SparklePath, UserName + "'s key.txt"), + Path.Combine (SparklePath, CurrentUser.Name + "'s key.txt"), true); // Overwriting is allowed } // Looks up the user's name from the global configuration - public string UserName - { + public SparkleUser CurrentUser { get { - return SparkleConfig.DefaultConfig.User.Name; + return SparkleConfig.DefaultConfig.User; } set { - SparkleConfig.DefaultConfig.User = new SparkleUser (value, UserEmail); - } - } - - - // Looks up the user's email from the global configuration - public string UserEmail - { - get { - return SparkleConfig.DefaultConfig.User.Email; - } - - set { - SparkleConfig.DefaultConfig.User = new SparkleUser (UserName, value); + SparkleConfig.DefaultConfig.User = value; } } @@ -787,7 +773,7 @@ namespace SparkleShare { public void GenerateKeyPair () { string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath); - string key_file_name = "sparkleshare." + UserEmail + ".key"; + string key_file_name = "sparkleshare." + CurrentUser.Email + ".key"; string key_file_path = Path.Combine (keys_path, key_file_name); if (File.Exists (key_file_path)) { @@ -824,7 +810,7 @@ namespace SparkleShare { // Create an easily accessible copy of the public // key in the user's SparkleShare folder - File.Copy (key_file_path + ".pub", Path.Combine (SparklePath, UserName + "'s key.txt"), true); + File.Copy (key_file_path + ".pub", Path.Combine (SparklePath, CurrentUser.Name + "'s key.txt"), true); } diff --git a/SparkleShare/SparkleSetupController.cs b/SparkleShare/SparkleSetupController.cs index 9dc44c0d..a611b600 100755 --- a/SparkleShare/SparkleSetupController.cs +++ b/SparkleShare/SparkleSetupController.cs @@ -87,16 +87,16 @@ namespace SparkleShare { public string GuessedUserName { get { - return Program.Controller.UserName; + return Program.Controller.CurrentUser.Name; } } public string GuessedUserEmail { get { - if (Program.Controller.UserEmail.Equals ("Unknown")) + if (Program.Controller.CurrentUser.Email.Equals ("Unknown")) return ""; else - return Program.Controller.UserEmail; + return Program.Controller.CurrentUser.Email; } } @@ -219,8 +219,7 @@ namespace SparkleShare { public void SetupPageCompleted (string full_name, string email) { - Program.Controller.UserName = full_name; - Program.Controller.UserEmail = email; + Program.Controller.CurrentUser = new SparkleUser (full_name, email); new Thread ( new ThreadStart (delegate {