controller: Code cleanups

This commit is contained in:
Hylke Bons 2012-07-17 15:09:57 +02:00
parent 8ca3bd3b6b
commit 2ca2c12475
13 changed files with 167 additions and 239 deletions

View file

@ -105,7 +105,6 @@ namespace SparkleLib {
CreateInitialConfig ();
} catch (XmlException) {
FileInfo file = new FileInfo (FullPath);
if (file.Length == 0) {
@ -180,10 +179,10 @@ namespace SparkleLib {
set {
SparkleUser user = (SparkleUser) value;
XmlNode name_node = SelectSingleNode ("/sparkleshare/user/name/text()");
XmlNode name_node = SelectSingleNode ("/sparkleshare/user/name/text()");
name_node.InnerText = user.Name;
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
email_node.InnerText = user.Email;
Save ();
@ -205,16 +204,16 @@ namespace SparkleLib {
public void AddFolder (string name, string identifier, string url, string backend)
{
XmlNode node_name = CreateElement ("name");
XmlNode node_name = CreateElement ("name");
node_name.InnerText = name;
XmlNode node_identifier = CreateElement ("identifier");
XmlNode node_identifier = CreateElement ("identifier");
node_identifier.InnerText = identifier;
XmlNode node_url = CreateElement ("url");
XmlNode node_url = CreateElement ("url");
node_url.InnerText = url;
XmlNode node_backend = CreateElement ("backend");
XmlNode node_backend = CreateElement ("backend");
node_backend.InnerText = backend;
XmlNode node_folder = CreateNode (XmlNodeType.Element, "folder", null);
@ -365,7 +364,7 @@ namespace SparkleLib {
node_root.AppendChild (node);
}
SparkleHelpers.DebugInfo ("Config", "Updated " + name + ":" + content);
SparkleHelpers.DebugInfo ("Config", "Updated option " + name + ":" + content);
Save ();
}
@ -373,19 +372,10 @@ namespace SparkleLib {
private void Save ()
{
if (!File.Exists (FullPath))
throw new ConfigFileNotFoundException (FullPath + " does not exist");
throw new FileNotFoundException (FullPath + " does not exist");
Save (FullPath);
SparkleHelpers.DebugInfo ("Config", "Updated \"" + FullPath + "\"");
}
}
public class ConfigFileNotFoundException : Exception {
public ConfigFileNotFoundException (string message) : base (message)
{
SparkleHelpers.DebugInfo ("Config", "Writen to '" + FullPath + "'");
}
}
}

View file

@ -36,14 +36,14 @@ namespace SparkleLib {
public readonly Uri Server;
public abstract void Connect ();
public abstract bool IsConnected { get; }
public abstract bool IsConnecting { get; }
protected abstract void AnnounceInternal (SparkleAnnouncement announcent);
protected abstract void AlsoListenToInternal (string folder_identifier);
protected List<string> channels = new List<string> ();
@ -52,11 +52,8 @@ namespace SparkleLib {
private Dictionary<string, List<SparkleAnnouncement>> recent_announcements =
new Dictionary<string, List<SparkleAnnouncement>> ();
private Dictionary<string, SparkleAnnouncement> queue_up =
new Dictionary<string, SparkleAnnouncement> ();
private Dictionary<string, SparkleAnnouncement> queue_down =
new Dictionary<string, SparkleAnnouncement> ();
private Dictionary<string, SparkleAnnouncement> queue_up = new Dictionary<string, SparkleAnnouncement> ();
private Dictionary<string, SparkleAnnouncement> queue_down = new Dictionary<string, SparkleAnnouncement> ();
private Timer reconnect_timer = new Timer {
Interval = 60 * 1000,
@ -82,25 +79,20 @@ namespace SparkleLib {
{
if (!IsRecentAnnouncement (announcement)) {
if (IsConnected) {
SparkleHelpers.DebugInfo ("Listener",
"Announcing message " + announcement.Message + " to " +
announcement.FolderIdentifier + " on " + Server);
SparkleHelpers.DebugInfo ("Listener", "Announcing message " + announcement.Message +
" to " + announcement.FolderIdentifier + " on " + Server);
AnnounceInternal (announcement);
AddRecentAnnouncement (announcement);
} else {
SparkleHelpers.DebugInfo ("Listener",
"Can't send message to " +
Server + ". Queuing message");
SparkleHelpers.DebugInfo ("Listener", "Can't send message to " + Server + ". Queuing message");
this.queue_up [announcement.FolderIdentifier] = announcement;
}
} else {
SparkleHelpers.DebugInfo ("Listener",
"Already processed message " + announcement.Message + " to " +
announcement.FolderIdentifier + " from " + Server);
SparkleHelpers.DebugInfo ("Listener", "Already processed message " + announcement.Message +
" to " + announcement.FolderIdentifier + " from " + Server);
}
}
@ -108,8 +100,7 @@ namespace SparkleLib {
public void AlsoListenTo (string channel)
{
if (!this.channels.Contains (channel) && IsConnected) {
SparkleHelpers.DebugInfo ("Listener",
"Subscribing to channel " + channel + " on " + Server);
SparkleHelpers.DebugInfo ("Listener", "Subscribing to channel " + channel + " on " + Server);
this.channels.Add (channel);
AlsoListenToInternal (channel);
@ -132,8 +123,7 @@ namespace SparkleLib {
Connected ();
if (this.queue_up.Count > 0) {
SparkleHelpers.DebugInfo ("Listener",
"Delivering " + this.queue_up.Count + " queued messages...");
SparkleHelpers.DebugInfo ("Listener", "Delivering " + this.queue_up.Count + " queued messages...");
foreach (KeyValuePair<string, SparkleAnnouncement> item in this.queue_up) {
SparkleAnnouncement announcement = item.Value;
@ -161,15 +151,13 @@ namespace SparkleLib {
announcement.FolderIdentifier + " on " + Server);
if (IsRecentAnnouncement (announcement)) {
SparkleHelpers.DebugInfo ("Listener",
"Ignoring previously processed message " + announcement.Message +
SparkleHelpers.DebugInfo ("Listener", "Ignoring previously processed message " + announcement.Message +
" from " + announcement.FolderIdentifier + " on " + Server);
return;
}
SparkleHelpers.DebugInfo ("Listener",
"Processing message " + announcement.Message + " from " +
SparkleHelpers.DebugInfo ("Listener", "Processing message " + announcement.Message + " from " +
announcement.FolderIdentifier + " on " + Server);
AddRecentAnnouncement (announcement);
@ -188,16 +176,12 @@ namespace SparkleLib {
private bool IsRecentAnnouncement (SparkleAnnouncement announcement)
{
if (!this.recent_announcements
.ContainsKey (announcement.FolderIdentifier)) {
if (!this.recent_announcements.ContainsKey (announcement.FolderIdentifier)) {
return false;
} else {
foreach (SparkleAnnouncement recent_announcement in
GetRecentAnnouncements (announcement.FolderIdentifier)) {
if (recent_announcement.Message.Equals (announcement.Message))
foreach (SparkleAnnouncement recent_announcement in GetRecentAnnouncements (announcement.FolderIdentifier)) {
if (recent_announcement.Message.Equals (recent_announcement.Message))
return true;
}
@ -211,7 +195,7 @@ namespace SparkleLib {
if (!this.recent_announcements.ContainsKey (folder_identifier))
this.recent_announcements [folder_identifier] = new List<SparkleAnnouncement> ();
return (List<SparkleAnnouncement>) this.recent_announcements [folder_identifier];
return this.recent_announcements [folder_identifier];
}
@ -224,8 +208,7 @@ namespace SparkleLib {
recent_announcements.Add (announcement);
if (recent_announcements.Count > this.max_recent_announcements)
recent_announcements.RemoveRange (0,
(recent_announcements.Count - this.max_recent_announcements));
recent_announcements.RemoveRange (0, recent_announcements.Count - this.max_recent_announcements);
}
}
}

View file

@ -31,8 +31,7 @@ namespace SparkleLib {
private DateTime last_ping = DateTime.Now;
public SparkleListenerTcp (Uri server, string folder_identifier) :
base (server, folder_identifier)
public SparkleListenerTcp (Uri server, string folder_identifier) : base (server, folder_identifier)
{
}
@ -179,12 +178,9 @@ namespace SparkleLib {
string folder_identifier = line.Substring (0, line.IndexOf ("!"));
string message = CleanMessage (line.Substring (line.IndexOf ("!") + 1));
if (!folder_identifier.Equals ("debug") &&
!String.IsNullOrEmpty (message)) {
// We have a message!
// We have a message!
if (!folder_identifier.Equals ("debug") && !String.IsNullOrEmpty (message))
OnAnnouncement (new SparkleAnnouncement (folder_identifier, message));
}
}
}
});
@ -212,8 +208,7 @@ namespace SparkleLib {
protected override void AnnounceInternal (SparkleAnnouncement announcement)
{
string to_send = "announce " + announcement.FolderIdentifier
+ " " + announcement.Message + "\n";
string to_send = "announce " + announcement.FolderIdentifier + " " + announcement.Message + "\n";
try {
if (this.socket != null)
@ -244,9 +239,9 @@ namespace SparkleLib {
private string CleanMessage (string message)
{
return message.Trim ()
.Replace ("\n", "")
.Replace ("\0", "");
message = message.Replace ("\n", "");
message = message.Replace ("\0", "");
return message.Trim ();
}
}
}

View file

@ -116,8 +116,11 @@ namespace SparkleLib {
private string identifier;
private SparkleListenerBase listener;
private TimeSpan poll_interval = PollInterval.Short;
private DateTime last_poll = DateTime.Now;
private TimeSpan poll_interval = PollInterval.Short;
private DateTime last_poll = DateTime.Now;
private DateTime progress_last_change = DateTime.Now;
private TimeSpan progress_change_interval = new TimeSpan (0, 0, 0, 1);
private Timers.Timer remote_timer = new Timers.Timer () {
Interval = 5000
@ -138,22 +141,19 @@ namespace SparkleLib {
public SparkleRepoBase (string path, SparkleConfig config)
{
this.local_config = config;
LocalPath = path;
Name = Path.GetFileName (LocalPath);
RemoteUrl = new Uri (this.local_config.GetUrlForFolder (Name));
IsBuffering = false;
ServerOnline = true;
LocalPath = path;
Name = Path.GetFileName (LocalPath);
RemoteUrl = new Uri (this.local_config.GetUrlForFolder (Name));
IsBuffering = false;
ServerOnline = true;
this.identifier = Identifier;
ChangeSets = GetChangeSets ();
SyncStatusChanged += delegate (SyncStatus status) {
Status = status;
};
this.identifier = Identifier;
ChangeSets = GetChangeSets ();
SparkleWatcherFactory.CreateWatcher (this);
new Thread (() => CreateListener ()).Start ();
this.remote_timer.Elapsed += delegate {
@ -252,7 +252,6 @@ namespace SparkleLib {
} while (IsBuffering);
this.remote_timer.Start ();
}
@ -264,6 +263,25 @@ namespace SparkleLib {
}
protected void OnProgressChanged (double progress_percentage, string progress_speed)
{
// Only trigger the ProgressChanged event once per second
if (DateTime.Compare (this.progress_last_change, DateTime.Now.Subtract (this.progress_change_interval)) >= 0)
return;
if (ProgressChanged != null) {
if (progress_percentage == 100.0)
progress_percentage = 99.0;
ProgressPercentage = progress_percentage;
ProgressSpeed = progress_speed;
this.progress_last_change = DateTime.Now;
ProgressChanged (progress_percentage, progress_speed);
}
}
private void SyncUpBase ()
{
SparkleHelpers.DebugInfo ("SyncUp", Name + " | Initiated");
@ -274,7 +292,6 @@ namespace SparkleLib {
if (SyncStatusChanged != null)
SyncStatusChanged (SyncStatus.SyncUp);
if (SyncUp ()) {
SparkleHelpers.DebugInfo ("SyncUp", Name + " | Done");
HasUnsyncedChanges = false;
@ -442,29 +459,6 @@ namespace SparkleLib {
}
private DateTime progress_last_change = DateTime.Now;
private TimeSpan progress_change_interval = new TimeSpan (0, 0, 0, 1);
protected void OnProgressChanged (double progress_percentage, string progress_speed)
{
// Only trigger the ProgressChanged event once per second
if (DateTime.Compare (this.progress_last_change, DateTime.Now.Subtract (this.progress_change_interval)) >= 0)
return;
if (ProgressChanged != null) {
if (progress_percentage == 100.0)
progress_percentage = 99.0;
ProgressPercentage = progress_percentage;
ProgressSpeed = progress_speed;
this.progress_last_change = DateTime.Now;
ProgressChanged (progress_percentage, progress_speed);
}
}
// Recursively gets a folder's size in bytes
private double CalculateSize (DirectoryInfo parent)
{

View file

@ -39,19 +39,20 @@ namespace SparkleShare {
public static void Main (string [] args)
{
if (args.Length != 0 && !args [0].Equals ("start")) {
Console.WriteLine (" ");
Console.WriteLine ("SparkleShare is a collaboration and sharing tool that is ");
Console.WriteLine ("designed to keep things simple and to stay out of your way.");
Console.WriteLine (" ");
Console.WriteLine ("Version: " + SparkleLib.SparkleBackend.Version);
Console.WriteLine ("Copyright (C) 2010 Hylke Bons");
Console.WriteLine (" ");
Console.WriteLine ("This program comes with ABSOLUTELY NO WARRANTY.");
Console.WriteLine (" ");
Console.WriteLine ("This is free software, and you are welcome to redistribute it ");
Console.WriteLine ("under certain conditions. Please read the GNU GPLv3 for details.");
Console.WriteLine (" ");
Console.WriteLine ("Usage: sparkleshare [start|stop|restart]");
string n = Environment.NewLine;
Console.WriteLine (n +
"SparkleShare is a collaboration and sharing tool that is" + n +
"designed to keep things simple and to stay out of your way." + n +
n +
"Version: " + SparkleLib.SparkleBackend.Version + n +
"Copyright (C) 2010 Hylke Bons" + n +
"This program comes with ABSOLUTELY NO WARRANTY." + n +
n +
"This is free software, and you are welcome to redistribute it" + n +
"under certain conditions. Please read the GNU GPLv3 for details." + n +
n +
"Usage: sparkleshare [start|stop|restart]");
Environment.Exit (-1);
}

View file

@ -99,12 +99,12 @@ namespace SparkleShare {
int running_major;
int running_minor;
int running_build;
int running_micro;
try {
string[] running_split = running_version_string.Split ('.');
string [] running_split = running_version_string.Split ('.');
running_major = int.Parse (running_split [0]);
running_minor = int.Parse (running_split [1]);
running_build = int.Parse (running_split [2]);
running_micro = int.Parse (running_split [2]);
} catch (Exception e) {
throw new FormatException ("running_version_string", e);
@ -112,12 +112,12 @@ namespace SparkleShare {
int latest_major;
int latest_minor;
int latest_build;
int latest_micro;
try {
string[] latest_split = latest_version_string.Split ('.');
string [] latest_split = latest_version_string.Split ('.');
latest_major = int.Parse (latest_split [0]);
latest_minor = int.Parse (latest_split [1]);
latest_build = int.Parse (latest_split [2]);
latest_micro = int.Parse (latest_split [2]);
} catch (Exception e) {
throw new FormatException ("latest_version_string", e);
@ -125,9 +125,9 @@ namespace SparkleShare {
bool higher_major = latest_major > running_major;
bool higher_minor = latest_major == running_major && latest_minor > running_minor;
bool higher_build = latest_major == running_major && latest_minor == running_minor && latest_build > running_build;
bool higher_micro = latest_major == running_major && latest_minor == running_minor && latest_micro > running_micro;
return higher_major || higher_minor || higher_build;
return (higher_major || higher_minor || higher_micro);
}
}
}
}

View file

@ -33,9 +33,8 @@ namespace SparkleShare {
};
Program.Controller.NotificationRaised += delegate (SparkleChangeSet change_set) {
if (Program.Controller.NotificationsEnabled)
ShowBubble (change_set.User.Name, FormatMessage (change_set),
Program.Controller.GetAvatar (change_set.User.Email, 48));
ShowBubble (change_set.User.Name, FormatMessage (change_set),
Program.Controller.GetAvatar (change_set.User.Email, 48));
};
}
@ -55,29 +54,23 @@ namespace SparkleShare {
private string FormatMessage (SparkleChangeSet change_set)
{
string message = "";
string message = "added {0}";
if (change_set.Changes [0].Type == SparkleChangeType.Deleted)
message = string.Format ("moved {0}", change_set.Changes [0].Path);
if (change_set.Changes [0].Type == SparkleChangeType.Moved)
message = string.Format ("moved {0}", change_set.Changes [0].Path);
if (change_set.Changes [0].Type == SparkleChangeType.Added)
message = string.Format ("added {0}", change_set.Changes [0].Path);
if (change_set.Changes [0].Type == SparkleChangeType.Edited)
message = string.Format ("moved {0}", change_set.Changes [0].Path);
if (change_set.Changes.Count > 0) {
string msg = string.Format ("and {0} more", change_set.Changes.Count);
message = message + " " + string.Format (msg, change_set.Changes.Count);
} else {
message = "did something magical";
switch (change_set.Changes [0].Type) {
case SparkleChangeType.Edited: message = "edited {0}"; break;
case SparkleChangeType.Deleted: message = "deleted {0}"; break;
case SparkleChangeType.Moved: message = "moved {0}"; break;
}
return message;
if (change_set.Changes.Count == 1) {
return message = string.Format (message, change_set.Changes [0].Path);
} else if (change_set.Changes.Count > 1) {
return string.Format (message + " and {0} more", change_set.Changes.Count - 1);
} else {
return "did something magical";
}
}
}
}

View file

@ -218,7 +218,6 @@ namespace SparkleShare {
// key in the user's SparkleShare folder
if (File.Exists (pubkey_file_path) && !File.Exists (link_code_file_path))
File.Copy (pubkey_file_path, link_code_file_path, true /* Overwriting allowed */ );
}
SparkleKeys.ListPrivateKeys ();
@ -241,20 +240,19 @@ namespace SparkleShare {
public void UIHasLoaded ()
{
if (FirstRun)
if (FirstRun) {
ShowSetupWindow (PageType.Setup);
else
new Thread (() => PopulateRepositories ()).Start ();
}
} else {
new Thread (() => {
CheckRepositories ();
RepositoriesLoaded = true;
private void PopulateRepositories ()
{
CheckRepositories ();
RepositoriesLoaded = true;
if (FolderListChanged != null)
FolderListChanged ();
if (FolderListChanged != null)
FolderListChanged ();
}).Start ();
}
}
@ -304,7 +302,7 @@ namespace SparkleShare {
};
repo.NewChangeSet += delegate (SparkleChangeSet change_set) {
if (NotificationRaised != null)
if (NotificationsEnabled && NotificationRaised != null)
NotificationRaised (change_set);
};
@ -406,17 +404,14 @@ namespace SparkleShare {
}
}
if (has_syncing_repos) {
if (OnSyncing != null)
OnSyncing ();
if (has_syncing_repos && OnSyncing != null) {
OnSyncing ();
} else if (has_unsynced_repos) {
if (OnError != null)
OnError ();
} else if (has_unsynced_repos && OnError != null) {
OnError ();
} else {
if (OnIdle != null)
OnIdle ();
} else if (OnIdle != null) {
OnIdle ();
}
}
@ -441,6 +436,7 @@ namespace SparkleShare {
}
}
public void HandleInvite (FileSystemEventArgs args)
{
if (this.fetcher != null &&
@ -458,22 +454,21 @@ namespace SparkleShare {
// fully downloaded yet, so we try to read it several times
int tries = 0;
while (!invite.IsValid) {
Thread.Sleep (1 * 250);
Thread.Sleep (250);
invite = new SparkleInvite (args.FullPath);
tries++;
if (tries > 20)
if (tries > 20) {
if (AlertNotificationRaised != null)
AlertNotificationRaised ("Oh noes!", "This invite seems screwed up...");
break;
}
}
if (invite.IsValid) {
if (invite.IsValid)
InviteReceived (invite);
} else {
if (AlertNotificationRaised != null)
AlertNotificationRaised ("Oh noes!",
"This invite seems screwed up...");
}
File.Delete (args.FullPath);
}
}
@ -681,11 +676,7 @@ namespace SparkleShare {
public void ToggleNotifications () {
bool notifications_enabled = this.config.GetConfigOption ("notifications").Equals (bool.TrueString);
if (notifications_enabled)
this.config.SetConfigOption ("notifications", bool.FalseString);
else
this.config.SetConfigOption ("notifications", bool.TrueString);
this.config.SetConfigOption ("notifications", (!notifications_enabled).ToString ());
}

View file

@ -111,9 +111,10 @@ namespace SparkleShare {
double size = 0;
foreach (SparkleRepoBase repo in Program.Controller.Repositories) {
if (this.selected_folder == null)
if (this.selected_folder == null) {
size += repo.Size;
else if (this.selected_folder.Equals (repo.Name)) {
} else if (this.selected_folder.Equals (repo.Name)) {
if (repo.Size == 0)
return "???";
else
@ -133,9 +134,10 @@ namespace SparkleShare {
double size = 0;
foreach (SparkleRepoBase repo in Program.Controller.Repositories) {
if (this.selected_folder == null)
if (this.selected_folder == null) {
size += repo.HistorySize;
else if (this.selected_folder.Equals (repo.Name)) {
} else if (this.selected_folder.Equals (repo.Name)) {
if (repo.HistorySize == 0)
return "???";
else
@ -178,11 +180,8 @@ namespace SparkleShare {
};
Program.Controller.FolderListChanged += delegate {
if (this.selected_folder != null &&
!Program.Controller.Folders.Contains (this.selected_folder)) {
if (this.selected_folder != null && !Program.Controller.Folders.Contains (this.selected_folder))
this.selected_folder = null;
}
if (UpdateChooserEvent != null)
UpdateChooserEvent (Folders);
@ -325,8 +324,10 @@ namespace SparkleShare {
string timestamp = change_set.Timestamp.ToString ("H:mm");
if (!change_set.FirstTimestamp.Equals (new DateTime ()) &&
!change_set.Timestamp.ToString ("H:mm").Equals (change_set.FirstTimestamp.ToString ("H:mm")))
!change_set.Timestamp.ToString ("H:mm").Equals (change_set.FirstTimestamp.ToString ("H:mm"))) {
timestamp = change_set.FirstTimestamp.ToString ("H:mm") + " " + timestamp;
}
event_entries += event_entry_html.Replace ("<!-- $event-entry-content -->", event_entry)
.Replace ("<!-- $event-user-name -->", change_set.User.Name)
@ -345,16 +346,18 @@ namespace SparkleShare {
today.Year == activity_day.Date.Year) {
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
"<span id='today' name='" + activity_day.Date.ToString ("dddd, MMMM d") + "'>"
+ "Today" + "</span>");
"<span id='today' name='" +
activity_day.Date.ToString ("dddd, MMMM d") + "'>" + "Today" +
"</span>");
} else if (yesterday.Day == activity_day.Date.Day &&
yesterday.Month == activity_day.Date.Month &&
yesterday.Year == activity_day.Date.Year) {
day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
"<span id='yesterday' name='" + activity_day.Date.ToString ("dddd, MMMM d") + "'>"
+ "Yesterday" + "</span>");
"<span id='yesterday' name='" + activity_day.Date.ToString ("dddd, MMMM d") + "'>" +
"Yesterday" +
"</span>");
} else {
if (activity_day.Date.Year != DateTime.Now.Year) {
@ -372,8 +375,8 @@ namespace SparkleShare {
int midnight = (int) (DateTime.Today.AddDays (1) - new DateTime (1970, 1, 1)).TotalSeconds;
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log)
.Replace ("<!-- $midnight -->", midnight.ToString ());
string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log);
html = html.Replace ("<!-- $midnight -->", midnight.ToString ());
return html;
}

View file

@ -22,7 +22,7 @@ namespace SparkleShare {
public static class Extensions {
public static string Combine (this String [] parts)
public static string Combine (this string [] parts)
{
string new_path = "";

View file

@ -36,8 +36,7 @@ namespace SparkleShare {
public bool IsValid {
get {
return (!string.IsNullOrEmpty (Address) &&
!string.IsNullOrEmpty (RemotePath));
return (!string.IsNullOrEmpty (Address) && !string.IsNullOrEmpty (RemotePath));
}
}
@ -101,7 +100,6 @@ namespace SparkleShare {
WebResponse response = request.GetResponse ();
response.Close ();
if ((response as HttpWebResponse).StatusCode == HttpStatusCode.OK) {
SparkleHelpers.DebugInfo ("Invite", "Uploaded public key to " + AcceptUrl);
return true;
@ -113,7 +111,6 @@ namespace SparkleShare {
} catch (WebException e) {
SparkleHelpers.DebugInfo ("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message);
return false;
}
}

View file

@ -164,7 +164,6 @@ namespace SparkleShare {
SelectedPlugin = Plugins [0];
Program.Controller.InviteReceived += delegate (SparkleInvite invite) {
PendingInvite = invite;
@ -175,7 +174,6 @@ namespace SparkleShare {
ShowWindowEvent ();
};
Program.Controller.ShowSetupWindowEvent += delegate (PageType page_type) {
if (page_type == PageType.CryptoSetup || page_type == PageType.CryptoPassword) {
if (ChangePageEvent != null)
@ -263,8 +261,7 @@ namespace SparkleShare {
full_name = full_name.Trim ();
email = email.Trim ();
bool fields_valid = (!string.IsNullOrEmpty (full_name) &&
IsValidEmail (email));
bool fields_valid = (!string.IsNullOrEmpty (full_name) && IsValidEmail (email));
if (UpdateSetupContinueButtonEvent != null)
UpdateSetupContinueButtonEvent (fields_valid);
@ -544,13 +541,12 @@ namespace SparkleShare {
{
Program.Controller.StopFetcher ();
if (ChangePageEvent == null)
return;
if (PendingInvite != null)
ChangePageEvent (PageType.Invite, null);
else
ChangePageEvent (PageType.Add, null);
if (ChangePageEvent != null) {
if (PendingInvite != null)
ChangePageEvent (PageType.Invite, null);
else
ChangePageEvent (PageType.Add, null);
}
}
@ -610,9 +606,7 @@ namespace SparkleShare {
public void OpenFolderClicked ()
{
Program.Controller.OpenSparkleShareFolder (
Path.GetFileName (PreviousPath));
Program.Controller.OpenSparkleShareFolder (Path.GetFileName (PreviousPath));
FinishPageCompleted ();
}
@ -629,17 +623,12 @@ namespace SparkleShare {
if (HideWindowEvent != null)
HideWindowEvent ();
//Program.Controller.UpdateState (); TODO: still relevant?
}
private bool IsValidEmail (string email)
{
Regex regex = new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$",
RegexOptions.IgnoreCase);
return regex.IsMatch (email);
return new Regex (@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$", RegexOptions.IgnoreCase).IsMatch (email);
}
}
}

View file

@ -55,16 +55,16 @@ namespace SparkleShare {
public string StateText = "Welcome to SparkleShare!";
public readonly int MenuOverFlowThreshold = 9;
public readonly int MenuOverflowThreshold = 9;
public readonly int MinSubmenuOverflowCount = 3;
public string [] Folders {
get {
int overflow_count = (Program.Controller.Folders.Count - MenuOverFlowThreshold);
int overflow_count = (Program.Controller.Folders.Count - MenuOverflowThreshold);
if (overflow_count >= MinSubmenuOverflowCount)
return Program.Controller.Folders.GetRange (0, MenuOverFlowThreshold).ToArray ();
return Program.Controller.Folders.GetRange (0, MenuOverflowThreshold).ToArray ();
else
return Program.Controller.Folders.ToArray ();
}
@ -72,16 +72,15 @@ namespace SparkleShare {
public string [] OverflowFolders {
get {
int overflow_count = (Program.Controller.Folders.Count - MenuOverFlowThreshold);
int overflow_count = (Program.Controller.Folders.Count - MenuOverflowThreshold);
if (overflow_count >= MinSubmenuOverflowCount)
return Program.Controller.Folders.GetRange (MenuOverFlowThreshold, overflow_count).ToArray ();
return Program.Controller.Folders.GetRange (MenuOverflowThreshold, overflow_count).ToArray ();
else
return new string [0];
}
}
public string FolderSize {
get {
double size = 0;
@ -110,21 +109,17 @@ namespace SparkleShare {
public bool QuitItemEnabled {
get {
return (CurrentState != IconState.Syncing &&
CurrentState != IconState.SyncingDown &&
CurrentState != IconState.SyncingUp);
return (CurrentState == IconState.Idle || CurrentState == IconState.Error);
}
}
public bool OpenRecentEventsItemEnabled {
get {
return (Program.Controller.RepositoriesLoaded &&
Program.Controller.Folders.Count > 0);
return (Program.Controller.RepositoriesLoaded && Program.Controller.Folders.Count > 0);
}
}
private Timer animation;
private int animation_frame_number;
@ -254,10 +249,7 @@ namespace SparkleShare {
public void OpenRecentEventsClicked ()
{
new Threading.Thread (() => {
Program.Controller.ShowEventLogWindow ();
}).Start ();
new Threading.Thread (() => Program.Controller.ShowEventLogWindow ()).Start ();
}