Fix coding style and whitespace of all of SparkleLib

This commit is contained in:
Hylke Bons 2011-05-01 15:40:46 +02:00
parent 7a1f32af71
commit f9b2fbe724
10 changed files with 226 additions and 321 deletions

View file

@ -13,7 +13,6 @@ SOURCES = \
SparkleListener.cs \ SparkleListener.cs \
SparkleOptions.cs \ SparkleOptions.cs \
SparklePaths.cs \ SparklePaths.cs \
SparklePlatform.cs \
SparkleRepo.cs SparkleRepo.cs
SMARTIRC4NET_FILES_EXPANDED = $(foreach file, $(SMARTIRC4NET_FILES), $(top_builddir)/$(file)) SMARTIRC4NET_FILES_EXPANDED = $(foreach file, $(SMARTIRC4NET_FILES), $(top_builddir)/$(file))

View file

@ -14,39 +14,24 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SparkleLib { namespace SparkleLib {
public class SparkleCommit public class SparkleCommit {
{
public string UserName; public string UserName;
public string UserEmail; public string UserEmail;
public DateTime DateTime;
public string Hash; public string Hash;
public bool IsMerge; public DateTime DateTime;
public bool IsMerge = false;
public List <string> Added; public List<string> Added = new List<string> ();
public List <string> Deleted; public List<string> Deleted = new List<string> ();
public List <string> Edited; public List<string> Edited = new List<string> ();
public List <string> MovedFrom; public List<string> MovedFrom = new List<string> ();
public List <string> MovedTo; public List<string> MovedTo = new List<string> ();
public SparkleCommit ()
{
Edited = new List <string> ();
Added = new List <string> ();
Deleted = new List <string> ();
MovedFrom = new List <string> ();
MovedTo = new List <string> ();
IsMerge = false;
} }
}
} }

View file

@ -19,25 +19,20 @@ using System;
namespace SparkleLib { namespace SparkleLib {
// Arguments for most events // Arguments for most events
public class SparkleEventArgs : System.EventArgs { public class SparkleEventArgs : EventArgs {
public string Type; public string Type;
public string Message; public string Message;
public SparkleEventArgs (string type) public SparkleEventArgs (string type)
{ {
Type = type; Type = type;
} }
} }
// Arguments for the NewCommit event // Arguments for the NewCommit event
public class NewCommitArgs : System.EventArgs { public class NewCommitArgs : EventArgs {
public string Author; public string Author;
public string Email; public string Email;
@ -46,14 +41,10 @@ namespace SparkleLib {
public NewCommitArgs (string author, string email, string message, string repository_path) public NewCommitArgs (string author, string email, string message, string repository_path)
{ {
Author = author; Author = author;
Email = email; Email = email;
Message = message; Message = message;
RepositoryPath = repository_path; RepositoryPath = repository_path;
} }
} }
} }

View file

@ -18,7 +18,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.Timers;
namespace SparkleLib { namespace SparkleLib {
@ -26,6 +25,7 @@ namespace SparkleLib {
// a remote repository // a remote repository
public class SparkleFetcher { public class SparkleFetcher {
// TODO: remove 'cloning' prefix
public delegate void CloningStartedEventHandler (object o, SparkleEventArgs args); public delegate void CloningStartedEventHandler (object o, SparkleEventArgs args);
public delegate void CloningFinishedEventHandler (object o, SparkleEventArgs args); public delegate void CloningFinishedEventHandler (object o, SparkleEventArgs args);
public delegate void CloningFailedEventHandler (object o, SparkleEventArgs args); public delegate void CloningFailedEventHandler (object o, SparkleEventArgs args);
@ -40,21 +40,19 @@ namespace SparkleLib {
public SparkleFetcher (string url, string folder) public SparkleFetcher (string url, string folder)
{ {
TargetFolder = folder; TargetFolder = folder;
RemoteOriginUrl = url; RemoteOriginUrl = url;
} }
// Clones the remote repository // Clones the remote repository
public void Start () public void Start ()
{ {
SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning Repository");
if (Directory.Exists (TargetFolder)) if (Directory.Exists (TargetFolder))
Directory.Delete (TargetFolder, true); Directory.Delete (TargetFolder, true);
SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning Repository");
if (CloningStarted != null) if (CloningStarted != null)
CloningStarted (this, new SparkleEventArgs ("CloningStarted")); CloningStarted (this, new SparkleEventArgs ("CloningStarted"));
@ -63,18 +61,14 @@ namespace SparkleLib {
"clone \"" + RemoteOriginUrl + "\" " + "\"" + TargetFolder + "\""); "clone \"" + RemoteOriginUrl + "\" " + "\"" + TargetFolder + "\"");
git.Exited += delegate { git.Exited += delegate {
SparkleHelpers.DebugInfo ("Git", "Exit code " + git.ExitCode.ToString ()); SparkleHelpers.DebugInfo ("Git", "Exit code " + git.ExitCode.ToString ());
if (git.ExitCode != 0) { if (git.ExitCode != 0) {
SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning failed"); SparkleHelpers.DebugInfo ("Git", "[" + TargetFolder + "] Cloning failed");
if (CloningFailed != null) if (CloningFailed != null)
CloningFailed (this, new SparkleEventArgs ("CloningFailed")); CloningFailed (this, new SparkleEventArgs ("CloningFailed"));
} else { } else {
InstallConfiguration (); InstallConfiguration ();
InstallExcludeRules (); InstallExcludeRules ();
@ -82,13 +76,10 @@ namespace SparkleLib {
if (CloningFinished != null) if (CloningFinished != null)
CloningFinished (this, new SparkleEventArgs ("CloningFinished")); CloningFinished (this, new SparkleEventArgs ("CloningFinished"));
} }
}; };
git.Start (); git.Start ();
} }
@ -96,18 +87,17 @@ namespace SparkleLib {
// the newly cloned repository // the newly cloned repository
private void InstallConfiguration () private void InstallConfiguration ()
{ {
string global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config");
string global_config_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, "config");
if (File.Exists (global_config_file_path)) { if (File.Exists (global_config_file_path)) {
StreamReader reader = new StreamReader (global_config_file_path); StreamReader reader = new StreamReader (global_config_file_path);
string user_info = reader.ReadToEnd (); string user_info = reader.ReadToEnd ();
reader.Close (); reader.Close ();
string repo_config_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "config"); string repo_config_file_path = SparkleHelpers.CombineMore (TargetFolder, ".git", "config");
string config = String.Join ("\n", File.ReadAllLines (repo_config_file_path)); string config = String.Join ("\n", File.ReadAllLines (repo_config_file_path));
// Be case sensitive explicitly to work on Mac
config = config.Replace ("ignorecase = true", "ignorecase = false"); config = config.Replace ("ignorecase = true", "ignorecase = false");
config += Environment.NewLine + user_info; config += Environment.NewLine + user_info;
@ -116,18 +106,15 @@ namespace SparkleLib {
writer.Close (); writer.Close ();
SparkleHelpers.DebugInfo ("Config", "Added configuration to '" + repo_config_file_path + "'"); SparkleHelpers.DebugInfo ("Config", "Added configuration to '" + repo_config_file_path + "'");
} }
} }
// Add a .gitignore file to the repo // Add a .gitignore file to the repo
private void InstallExcludeRules () private void InstallExcludeRules ()
{ {
string exlude_rules_file_path = SparkleHelpers.CombineMore (
string exlude_rules_file_path = SparkleHelpers.CombineMore TargetFolder, ".git", "info", "exclude");
(TargetFolder, ".git", "info", "exclude");
TextWriter writer = new StreamWriter (exlude_rules_file_path); TextWriter writer = new StreamWriter (exlude_rules_file_path);
@ -167,9 +154,6 @@ namespace SparkleLib {
writer.WriteLine ("*/.svn/*"); writer.WriteLine ("*/.svn/*");
writer.Close (); writer.Close ();
} }
} }
} }

View file

@ -27,10 +27,8 @@ namespace SparkleLib {
public enum NotificationServerType public enum NotificationServerType
{ {
Own, Own,
Central Central
} }
@ -38,10 +36,11 @@ namespace SparkleLib {
// listens for change notifications // listens for change notifications
public class SparkleListener { public class SparkleListener {
private Thread Thread;
// FIXME: The IrcClient is a public property because // FIXME: The IrcClient is a public property because
// extending it causes crashes // extending it causes crashes
public IrcClient Client; public IrcClient Client;
private Thread Thread;
public readonly string Server; public readonly string Server;
public readonly string FallbackServer; public readonly string FallbackServer;
public readonly string Channel; public readonly string Channel;
@ -51,11 +50,8 @@ namespace SparkleLib {
public SparkleListener (string server, string folder_name, public SparkleListener (string server, string folder_name,
string user_email, NotificationServerType type) string user_email, NotificationServerType type)
{ {
if (type == NotificationServerType.Own) { if (type == NotificationServerType.Own) {
Server = server; Server = server;
} else { } else {
// This is SparkleShare's centralized notification service. // This is SparkleShare's centralized notification service.
@ -63,81 +59,64 @@ namespace SparkleLib {
// don't have your own. All data needed to connect is hashed and // don't have your own. All data needed to connect is hashed and
// we don't store any personal information ever. // we don't store any personal information ever.
Server = "204.62.14.135"; Server = "204.62.14.135";
} }
if (!user_email.Equals ("") && user_email != null) if (!String.IsNullOrEmpty (user_email))
Nick = GetSHA1 (folder_name + user_email + "sparkles"); Nick = SHA1 (folder_name + user_email + "sparkles");
else else
Nick = GetSHA1 (DateTime.Now.ToString () + "sparkles"); Nick = SHA1 (DateTime.Now.ToString () + "sparkles");
Nick = "s" + Nick.Substring (0, 7); Nick = "s" + Nick.Substring (0, 7);
Channel = "#" + GetSHA1 (server + folder_name + "sparkles"); Channel = "#" + SHA1 (server + folder_name + "sparkles");
Client = new IrcClient () { Client = new IrcClient () {
PingTimeout = 180, PingTimeout = 180,
PingInterval = 90 PingInterval = 90
}; };
} }
// Starts a new thread and listens to the channel // Starts a new thread and listens to the channel
public void Listen () public void Listen ()
{ {
Thread = new Thread ( Thread = new Thread (
new ThreadStart (delegate { new ThreadStart (delegate {
try { try {
// Connect to the server // Connect, login, and join the channel
Client.Connect (new string [] {Server}, 6667); Client.Connect (new string [] {Server}, 6667);
// Login to the server
Client.Login (Nick, Nick); Client.Login (Nick, Nick);
// Join the channel
Client.RfcJoin (Channel); Client.RfcJoin (Channel);
// List to the channel, this blocks the thread
Client.Listen (); Client.Listen ();
Client.Disconnect (); Client.Disconnect ();
} catch (Meebey.SmartIrc4net.ConnectionException e) { } catch (Meebey.SmartIrc4net.ConnectionException e) {
Console.WriteLine ("Could not connect: " + e.Message); Console.WriteLine ("Could not connect: " + e.Message);
} }
}) })
); );
Thread.Start (); Thread.Start ();
} }
public void Announce (string message) public void Announce (string message)
{ {
Client.SendMessage (SendType.Message, Channel, message); Client.SendMessage (SendType.Message, Channel, message);
} }
// Frees all resources for this Listener // Frees all resources for this Listener
public void Dispose () public void Dispose ()
{ {
Thread.Abort (); Thread.Abort ();
Thread.Join (); Thread.Join ();
} }
// Creates an SHA-1 hash of input // Creates an SHA-1 hash of input
private static string GetSHA1 (string s) private string SHA1 (string s)
{ {
SHA1 sha1 = new SHA1CryptoServiceProvider (); SHA1 sha1 = new SHA1CryptoServiceProvider ();
Byte[] bytes = ASCIIEncoding.Default.GetBytes (s); Byte[] bytes = ASCIIEncoding.Default.GetBytes (s);

View file

@ -26,9 +26,7 @@ namespace SparkleLib {
public static string Name = "Git"; public static string Name = "Git";
public static string Path { public static string Path {
get { get {
string [] possible_git_paths = {"/usr/bin/git", string [] possible_git_paths = {"/usr/bin/git",
"/usr/local/git/bin/git", "/usr/local/git/bin/git",
"/usr/local/bin/git"}; "/usr/local/bin/git"};
@ -38,22 +36,15 @@ namespace SparkleLib {
return git_path; return git_path;
return null; return null;
} }
} }
public static bool IsPresent { public static bool IsPresent {
get { get {
return (Path != null); return (Path != null);
} }
} }
} }
@ -70,5 +61,4 @@ namespace SparkleLib {
public static string SparkleIconPath = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "sparkleshare", "icons"); public static string SparkleIconPath = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "sparkleshare", "icons");
} }
} }

View file

@ -1,28 +0,0 @@
// 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;
namespace SparkleShare {
public static class SparklePlatform {
// Detect OSX, Windows, GNOME or KDE here
public static string Name = "GNOME";
}
}

View file

@ -682,29 +682,23 @@ namespace SparkleShare {
public bool NotificationsEnabled { public bool NotificationsEnabled {
get { get {
string notify_setting_file_path = Path.Combine (SparklePaths.SparkleConfigPath,
string notify_setting_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath,
"sparkleshare.notify"); "sparkleshare.notify");
return File.Exists (notify_setting_file_path); return File.Exists (notify_setting_file_path);
} }
} }
public void ToggleNotifications () { public void ToggleNotifications () {
string notify_setting_file_path = Path.Combine (SparklePaths.SparkleConfigPath,
string notify_setting_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath,
"sparkleshare.notify"); "sparkleshare.notify");
if (File.Exists (notify_setting_file_path)) if (File.Exists (notify_setting_file_path))
File.Delete (notify_setting_file_path); File.Delete (notify_setting_file_path);
else else
File.Create (notify_setting_file_path); File.Create (notify_setting_file_path);
} }

View file

@ -645,6 +645,7 @@ namespace SparkleShare {
}; };
Button button = new Button () { Button button = new Button () {
Sensitive = false, Sensitive = false,
Label = _("Finish") Label = _("Finish")
@ -671,6 +672,16 @@ namespace SparkleShare {
box.PackStart (table, false, false, 0); box.PackStart (table, false, false, 0);
Progressbar bar = new Progressbar ();
box.PackStart (bar, true, true, 0);
Timer timer = new Timer () {
Interval = 500
};
timer.Elapsed += delegate {
bar.Pulse ();
};
timer.Start ();
layout_vertical.PackStart (box, false, false, 0); layout_vertical.PackStart (box, false, false, 0);
Add (layout_vertical); Add (layout_vertical);