private void LoadConfiguration (Config config) { if (config == null) config = Conf.Get (Conf.Names.NetworkingConfig); if (String.IsNullOrEmpty (name)) // Whats a good default value ? name = config.GetOption (Conf.Names.ServiceName, String.Empty); // Check to see if our enabled status hasn't changed if (enabled != config.GetOption (Conf.Names.ServiceEnabled, enabled)) { enabled = config.GetOption (Conf.Names.ServiceEnabled, enabled); if (enabled) { try { Publish (); } catch (ClientException) { Log.Error ("Could not start avahi"); return; } } else Unpublish (); Logger.Log.Info ("Zeroconf: Index sharing is {0}", enabled ? "enabled" : "disabled"); } // Handle index name changes if (String.Compare (name, config.GetOption (Conf.Names.ServiceName, name)) != 0) Update (); }
private void ReadConf (Config config) { if (config == null || config.Name != "GoogleBackends") return; username = config.GetOption ("GMailUsername", null); search_folder = config.GetOption ("GMailSearchFolder", null); string password_source = config.GetOption ("GMailPasswordSource", "conf-data"); password_source = password_source.ToLower (); switch (password_source) { case "conf-file": password = config.GetOption ("GMailPassword", null); break; case "gnome-keyring": Log.Error ("GMailPasswordSource: gnome-keyring is not supported yet"); break; case "kdewallet": try { password = KdeUtils.ReadPasswordKDEWallet ("beagle", username); } catch (Exception e) { Log.Error (e, "Error in reading password in KDE wallet"); } break; default: Log.Error ("GMailPasswordSource should be one of 'kdewallet,gnome-keyring,conf-file"); break; } valid_account = ( ! String.IsNullOrEmpty (username) && ! String.IsNullOrEmpty (password) && ! String.IsNullOrEmpty (search_folder)); if (! valid_account) Log.Warn ("GMail account information not set. Search is disabled."); else Log.Debug ("GMail account information successfully read."); domain = config.GetOption ("GoogleAppDomainName", null); if (String.IsNullOrEmpty (domain)) domain = GMAIL_DOMAIN; else // Google Apps domain is of form // a/mydomain.name domain = ("a/" + domain); }
private void SetKeyBindings (Config config) { string tip_text = Catalog.GetString ("Desktop Search"); string binding = config.GetOption ("KeyBinding", null); Console.WriteLine ("new binding {0}", binding); if (String.IsNullOrEmpty (binding)) { // Move old preference value to new bool binding_ctrl = config.GetOption (Conf.Names.KeyBinding_Ctrl, false); bool binding_alt = config.GetOption (Conf.Names.KeyBinding_Alt, false); string binding_key = config.GetOption (Conf.Names.KeyBinding_Key, "F12"); KeyBinding show_binding = new KeyBinding (binding_key, binding_ctrl, binding_alt); binding = show_binding.ToString (); } if (!String.IsNullOrEmpty (binding)) { tip_text += String.Format (" ({0})", binding); keybinder.UnbindAll (); keybinder.Bind (binding, OnTrayActivated); } tray.TooltipText = tip_text; }
private void OnConfigurationChanged (Config config) { if (config == null || config.Name != Conf.Names.NetworkingConfig) return; LoadConfiguration (config); }
private void OnConfigurationChanged (Config config) { if (config == null || config.Name != Conf.Names.FilesQueryableConfig) return; bool clear_fs_state = false; List<string[]> values = config.GetListOptionValues (Conf.Names.ExcludeSubdirectory); if (values != null) { ArrayList subdirs = new ArrayList (values.Count); foreach (string[] value in values) { string dir = GetExcludeDirectory (value [0]); if (! String.IsNullOrEmpty (dir)) subdirs.Add (dir); } IList excludes_wanted = subdirs; IList excludes_to_add, excludes_to_remove; ArrayFu.IntersectListChanges (excludes_wanted, exclude_paths, out excludes_to_add, out excludes_to_remove); // Process any excludes we think we should remove foreach (string path in excludes_to_remove) RemoveExcludeDir (path); // Process any excludes we found to be new foreach (string path in excludes_to_add) AddExcludeDir (path); } values = config.GetListOptionValues (Conf.Names.ExcludePattern); if (values != null) { ArrayList patterns = new ArrayList (values.Count); foreach (string[] value in values) patterns.Add (value [0]); IList excludes_wanted = patterns; IList excludes_to_add, excludes_to_remove; ArrayFu.IntersectListChanges (excludes_wanted, exclude_patterns, out excludes_to_add, out excludes_to_remove); // Process any excludes we think we should remove foreach (string pattern in excludes_to_remove) { clear_fs_state = true; RemoveExcludePattern (pattern); } // Process any excludes we found to be new foreach (string pattern in excludes_to_add) AddExcludePattern (pattern); exclude_regex = StringFu.GetPatternRegex (exclude_patterns); } // If an exclude pattern is removed, we need to recrawl everything // so that we can index those files which were previously ignored. if (clear_fs_state) queryable.RecrawlEverything (); }
private void OnConfigurationChanged (Config config) { SetKeyBindings (config); }
// Use this method to send in the xml for a config, and the original config // and the changes from the original to the xml will be added to the original config // Returns false if the read xml does not correspond to the same config as that // was passed, in which case please note that the passed config COULD BE IN A // modified state and should be discarded! public static bool ReadSectionXml (Config config, TextReader reader) { if (config == null) throw new ArgumentException ("config", "config cannot be null"); Config new_config = (Config) conf_ser.Deserialize (reader); foreach (Option new_option in new_config.Options.Values) { Option option = config [new_option.Name] as Option; if (option == null || (option.Type != new_option.Type)) return false; switch (option.Type) { case OptionType.Bool: BoolOption option_bool = (BoolOption) option; BoolOption new_option_bool = (BoolOption) new_option; option_bool.Value = new_option_bool.Value; break; case OptionType.String: StringOption option_str = (StringOption) option; StringOption new_option_str = (StringOption) new_option; option_str.Value = new_option_str.Value; break; case OptionType.List: ListOption option_list = (ListOption) option; ListOption new_option_list = (ListOption) new_option; if (option_list.NumParams != new_option_list.NumParams) return false; option_list.Values = new_option_list.Values; break; } } return true; }
/* External clients can use the following two xml based methods to read/write xml */ // Use this method to write the config in its xml format. public static void WriteSectionXml (Config config, TextWriter writer) { if (config == null) return; // serialize will not serialize global options, // so temporarily make every option global Dictionary<Option, bool> global_options = new Dictionary<Option, bool> (); foreach (Option option in config.Options.Values) { global_options [option] = option.Global; option.Global = false; } conf_ser.Serialize (writer, config); foreach (Option option in config.Options.Values) option.Global = global_options [option]; }
public static void SaveTo (Config config, string path) { if (config == null) return; bool to_save = false; foreach (Option option in config.Options.Values) if (! option.Global) to_save = true; if (! to_save) return; using (StreamWriter writer = new StreamWriter (path)) { conf_ser.Serialize (writer, config); Console.WriteLine ("Done writing to " + path); } }
public static void Save (Config config) { if (config == null) return; bool to_save = false; foreach (Option option in config.Options.Values) if (! option.Global) to_save = true; if (! to_save) return; bool watching_for_updates_current = watching_for_updates; watching_for_updates = false; string filename = Path.Combine (configs_dir, (config.Name + ".xml")); using (StreamWriter writer = new StreamWriter (filename)) { conf_ser.Serialize (writer, config); Log.Debug ("Done writing to " + filename); } watching_for_updates = watching_for_updates_current; }
public static Config LoadNew (string name) { Config config = new Config (); config.Name = name; return config; }
private static void NotifySubscribers (Config config, string name) { ArrayList callbacks = (ArrayList) subscriptions [name]; if (callbacks == null) return; foreach (ConfigUpdateHandler callback in callbacks) callback (config); }
private void ConfigUpdateHandler (Config config) { if (config == null || config.Name != Conf.Names.NetworkingConfig) return; bool to_webinterface = config.GetOption ("WebInterface", false); Log.Debug ("WebInterface option changed to {0}", to_webinterface); if (to_webinterface) StartWebserver (); else StopWebserver (); }
private void OnConfigurationChanged (Config config) { if (config == null || config.Name != Conf.Names.FilesQueryableConfig) return; List<string[]> values = config.GetListOptionValues (Conf.Names.Roots); if (values == null) values = new List<string[]> (0); ArrayList roots_wanted = new ArrayList (values.Count); foreach (string[] root in values) roots_wanted.Add (root [0]); if (config.GetOption (Conf.Names.IndexHomeDir, true)) roots_wanted.Add (PathFinder.HomeDir); IList roots_to_add, roots_to_remove; ArrayFu.IntersectListChanges (roots_wanted, Roots, out roots_to_add, out roots_to_remove); foreach (string root in roots_to_remove) RemoveRoot (root); foreach (string root in roots_to_add) AddRoot (root); }