listener factory: allow setting of a global notification service for all the folders

This commit is contained in:
Hylke Bons 2012-02-06 13:04:12 +01:00
parent aa82b3441f
commit c43abafdab
2 changed files with 13 additions and 6 deletions

View file

@ -29,6 +29,7 @@ namespace SparkleLib {
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"sparkleshare");
// TODO: declare elsewhere
public static SparkleConfig DefaultConfig = new SparkleConfig (default_config_path, "config.xml");
public static bool DebugMode = true;

View file

@ -42,12 +42,16 @@ namespace SparkleLib {
public static SparkleListenerBase CreateListener (string folder_name, string folder_identifier)
{
// TODO: Allow a different announcements uri for each folder
// next to a global one
string uri = SparkleConfig.DefaultConfig.GetFolderOptionalAttribute (
folder_name, "announcements_url");
// Check if the user wants to use a global custom notification service
string uri = SparkleConfig.DefaultConfig.GetConfigOption ("announcements_url");
if (uri == null) {
// Check if the user wants a use a custom notification service for this folder
if (string.IsNullOrEmpty (uri))
uri = SparkleConfig.DefaultConfig.GetFolderOptionalAttribute (
folder_name, "announcements_url");
// Fall back to the fallback service is neither is the case
if (string.IsNullOrEmpty (uri)) {
// This is SparkleShare's centralized notification service.
// It communicates "It's time to sync!" signals between clients.
//
@ -65,7 +69,7 @@ namespace SparkleLib {
Uri announce_uri = new Uri (uri);
// We use only one listener per server to keep
// We use only one listener per notification service to keep
// the number of connections as low as possible
foreach (SparkleListenerBase listener in listeners) {
if (listener.Server.Equals (announce_uri)) {
@ -73,6 +77,8 @@ namespace SparkleLib {
"Refered to existing " + announce_uri.Scheme +
" listener for " + announce_uri);
// We already seem to have a listener for this server,
// refer to the existing one instead
listener.AlsoListenToBase (folder_identifier);
return (SparkleListenerBase) listener;
}