[lib] Allow disabling of central notification server and fallback to own

This commit is contained in:
Hylke Bons 2011-03-22 13:44:52 +00:00
parent a2472b483f
commit 520d6b8f3f
2 changed files with 44 additions and 8 deletions

View file

@ -25,6 +25,15 @@ using Meebey.SmartIrc4net;
namespace SparkleLib {
public enum NotificationServerType
{
Own,
Central
}
// A persistent connection to the server that
// listens for change notifications
public class SparkleListener {
@ -39,14 +48,23 @@ namespace SparkleLib {
public readonly string Nick;
public SparkleListener (string server, string folder_name, string user_email)
public SparkleListener (string server, string folder_name,
string user_email, NotificationServerType type)
{
// This is SparkleShare's centralized notification service.
// Don't worry, we only use this server as a backup if you
// don't have your own. All data needed to connect is hashed and
// we don't store any personal information ever.
Server = "204.62.14.135";
if (type == NotificationServerType.Own) {
Server = server;
} else {
// This is SparkleShare's centralized notification service.
// Don't worry, we only use this server as a backup if you
// don't have your own. All data needed to connect is hashed and
// we don't store any personal information ever.
Server = "204.62.14.135";
}
if (!user_email.Equals ("") && user_email != null)
Nick = GetSHA1 (folder_name + user_email + "sparkles");

View file

@ -307,7 +307,11 @@ namespace SparkleLib {
// Listen to the irc channel on the server...
Listener = new SparkleListener (Domain, RemoteName, UserEmail);
if (UsesNotificationCenter)
Listener = new SparkleListener (Domain, RemoteName, UserEmail, NotificationServerType.Central);
else
Listener = new SparkleListener (Domain, RemoteName, UserEmail, NotificationServerType.Own);
// ...fetch remote changes every 60 seconds if that fails
RemoteTimer = new Timer () {
@ -1149,13 +1153,27 @@ namespace SparkleLib {
}
public static bool IsRepo (string path) {
public static bool IsRepo (string path)
{
return System.IO.Directory.Exists (Path.Combine (path, ".git"));
}
public bool UsesNotificationCenter
{
get {
string file_path = SparkleHelpers.CombineMore (LocalPath, ".git", "disable_notification_center");
return !File.Exists (file_path);
}
}
// Disposes all resourses of this object
new public void Dispose ()
{