Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
Silverstone.Manticore.Core.Preferences Class Reference

List of all members.

Public Member Functions

 Preferences ()
void InitializeDefaults ()
void LoadPreferencesFile (String aFile)
void LoadUserPreferences ()
void FlushUserPreferences ()
void OnNodeChanged (object sender, XmlNodeChangedEventArgs e)
void OnNodeRemoved (object sender, XmlNodeChangedEventArgs e)
void OnNodeInserted (object sender, XmlNodeChangedEventArgs e)
void FlushPreferencesFile (String aFile)
PrefBranch GetBranch (String aBranchName)
void RemoveBranch (String aBranchName)
bool GetBoolPref (String aPrefName)
void SetBoolPref (String aPrefName, bool aPrefValue)
void RemovePref (String aPrefName)
int GetIntPref (String aPrefName)
void SetIntPref (String aPrefName, int aPrefValue)
String GetStringPref (String aPrefName)
void SetStringPref (String aPrefName, String aPrefValue)

Static Public Member Functions

static String ResolvePref (XmlElement aElement)

Private Member Functions

void ReadDocument (String aFile, XmlDocument aDocument)
XmlElement CreateBranch (String aPrefName)
XmlElement CreateBranch (String aBranchName, XmlElement aRoot)
XmlElement GetBranchElement (String aBranchName)
XmlElement GetBranch (String aBranchName, XmlElement aRoot)

Private Attributes

XmlDocument mDefaultsDocument
XmlDocument mPrefsDocument

Detailed Description

Definition at line 49 of file preferences.cs.


Constructor & Destructor Documentation

Definition at line 54 of file preferences.cs.

    {
      mDefaultsDocument = new XmlDocument();
      mPrefsDocument = new XmlDocument();
    }

Member Function Documentation

XmlElement Silverstone.Manticore.Core.Preferences.CreateBranch ( String  aPrefName) [inline, private]

Definition at line 152 of file preferences.cs.

    {
      String[] names = aPrefName.Split('.');
      XmlElement elt = mPrefsDocument.DocumentElement;
      for (int i = 0; i < names.Length; ++i)
        elt = CreateBranch(names[i], elt);
      return elt;
    }

Here is the call graph for this function:

XmlElement Silverstone.Manticore.Core.Preferences.CreateBranch ( String  aBranchName,
XmlElement  aRoot 
) [inline, private]

Definition at line 161 of file preferences.cs.

    {
      XmlElement elt = GetBranch(aBranchName, aRoot);
      if (elt == null) {
        elt = mPrefsDocument.CreateElement(aBranchName);
        aRoot.AppendChild(elt);
      }
      return elt;
    }

Definition at line 126 of file preferences.cs.

    {
      UTF8Encoding enc = new UTF8Encoding();
      XmlTextWriter writer = new XmlTextWriter(aFile, enc);
      writer.Formatting = Formatting.Indented;
      mPrefsDocument.WriteTo(writer);
      writer.Flush();
    }

Here is the call graph for this function:

Definition at line 109 of file preferences.cs.

    {
      FlushPreferencesFile(FileLocator.GetManticorePath("UserPrefs"));
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 222 of file preferences.cs.

    {
      XmlElement elt = GetBranchElement(aPrefName);
      return elt != null ? elt.GetAttribute("value") == "true" : false;
    }

Here is the caller graph for this function:

XmlElement Silverstone.Manticore.Core.Preferences.GetBranch ( String  aBranchName,
XmlElement  aRoot 
) [inline, private]

Definition at line 189 of file preferences.cs.

    {
      // First, check to see if the specified root already has a branch
      // specified. If it exists, hand that root back. 
      int childCount = aRoot.ChildNodes.Count;
      for (int i = 0; i < childCount; ++i) {
        if (aRoot.ChildNodes[i].LocalName == aBranchName)
          return aRoot.ChildNodes[i] as XmlElement;
      }
      return null;
    }

Here is the caller graph for this function:

Definition at line 201 of file preferences.cs.

    {
      return new PrefBranch(aBranchName, GetBranchElement(aBranchName));
    }
XmlElement Silverstone.Manticore.Core.Preferences.GetBranchElement ( String  aBranchName) [inline, private]

Definition at line 171 of file preferences.cs.

    {
      String[] names = aBranchName.Split('.');
      XmlElement elt = mPrefsDocument.DocumentElement;
      for (int i = 0; i < names.Length && elt != null; ++i)
        elt = GetBranch(names[i], elt);
      
      // The preference wasn't found in the user preferences
      // file, look in the default preferences file. 
      if (elt == null) {
        elt = mDefaultsDocument.DocumentElement;
        for (int i = 0; i < names.Length; ++i)
          elt = GetBranch(names[i], elt);
      }

      return elt;
    }

Here is the call graph for this function:

Definition at line 240 of file preferences.cs.

    {
      XmlElement elt = GetBranchElement(aPrefName);
      return elt != null ? Int32.Parse(elt.GetAttribute("value")) : 0;
    }

Here is the caller graph for this function:

Definition at line 255 of file preferences.cs.

    {
      XmlElement elt = GetBranchElement(aPrefName);
      return elt != null ? elt.GetAttribute("value") : "";
    }

Here is the caller graph for this function:

Definition at line 60 of file preferences.cs.

    {
      // Do we ever want to support multiple defaults files? For now, no.
      // XXX need a better place for this file.
      ReadDocument(@"defaults\default-prefs.xml", mDefaultsDocument);
    }

Definition at line 78 of file preferences.cs.

    {
      ReadDocument(aFile, mPrefsDocument);

      mPrefsDocument.NodeChanged += new XmlNodeChangedEventHandler(OnNodeChanged);
      mPrefsDocument.NodeRemoved += new XmlNodeChangedEventHandler(OnNodeRemoved);
      mPrefsDocument.NodeInserted += new XmlNodeChangedEventHandler(OnNodeInserted);
    }

Definition at line 87 of file preferences.cs.

    {
      String manticoreAppData = FileLocator.GetManticorePath("AppData");
      String prefPath = FileLocator.GetManticorePath("UserPrefs");
      try {
        LoadPreferencesFile(prefPath);
      }
      catch (XmlException) {
        // Something went wrong, we'll just assume a malformed or non-existant 
        // preferences file, blow it away and insert a new one. Could potentially
        // be dangerous. 
        try {
          File.Copy(@"defaults\user-prefs.xml", prefPath, true);
        }
        catch (DirectoryNotFoundException) {
          Directory.CreateDirectory(manticoreAppData);
          File.Copy(@"defaults\user-prefs.xml", prefPath, true);
        }
        LoadPreferencesFile(prefPath);
      }
    }

Here is the call graph for this function:

void Silverstone.Manticore.Core.Preferences.OnNodeChanged ( object  sender,
XmlNodeChangedEventArgs  e 
) [inline]

Definition at line 114 of file preferences.cs.

    {
    }
void Silverstone.Manticore.Core.Preferences.OnNodeInserted ( object  sender,
XmlNodeChangedEventArgs  e 
) [inline]

Definition at line 122 of file preferences.cs.

    {
    }
void Silverstone.Manticore.Core.Preferences.OnNodeRemoved ( object  sender,
XmlNodeChangedEventArgs  e 
) [inline]

Definition at line 118 of file preferences.cs.

    {
    }
void Silverstone.Manticore.Core.Preferences.ReadDocument ( String  aFile,
XmlDocument  aDocument 
) [inline, private]

Definition at line 67 of file preferences.cs.

    {
      XmlTextReader reader = new XmlTextReader(aFile);
      reader.WhitespaceHandling = WhitespaceHandling.None;
      reader.MoveToContent();
      String xml = reader.ReadOuterXml();
      reader.Close();
      aDocument.LoadXml(xml);
    }

Here is the call graph for this function:

Definition at line 206 of file preferences.cs.

    {
      XmlElement elt = GetBranchElement(aBranchName);
      XmlNode parent = elt.ParentNode;
      parent.RemoveChild(elt);
      while (parent != null && 
             parent != (mPrefsDocument.DocumentElement as XmlNode)) {
        if (!parent.HasChildNodes) {
          parent.ParentNode.RemoveChild(parent);
          parent = parent.ParentNode;
        }
        else 
          break;
      }
    }

Here is the caller graph for this function:

Definition at line 235 of file preferences.cs.

    {
      RemoveBranch(aPrefName);
    }
static String Silverstone.Manticore.Core.Preferences.ResolvePref ( XmlElement  aElement) [inline, static]

Definition at line 268 of file preferences.cs.

    {
      String rv = aElement.LocalName;
      XmlElement temp = aElement;
      while (true) {
        temp = temp.ParentNode as XmlElement;
        if (temp == null || temp.LocalName == "preferences")
          break;
        rv = temp.LocalName + "." + rv;
      }
      return rv;
    }

Here is the call graph for this function:

void Silverstone.Manticore.Core.Preferences.SetBoolPref ( String  aPrefName,
bool  aPrefValue 
) [inline]

Definition at line 228 of file preferences.cs.

    {
      XmlElement childElt = CreateBranch(aPrefName);
      if (childElt != null) 
        childElt.SetAttribute("value", aPrefValue ? "true" : "false");
    }
void Silverstone.Manticore.Core.Preferences.SetIntPref ( String  aPrefName,
int  aPrefValue 
) [inline]

Definition at line 246 of file preferences.cs.

    {
      XmlElement elt = CreateBranch(aPrefName);
      if (elt != null) {
        Object o = aPrefValue;
        elt.SetAttribute("value", o.ToString());
      }
    }

Here is the caller graph for this function:

void Silverstone.Manticore.Core.Preferences.SetStringPref ( String  aPrefName,
String  aPrefValue 
) [inline]

Definition at line 261 of file preferences.cs.

    {
      XmlElement elt = CreateBranch(aPrefName);
      if (elt != null)
        elt.SetAttribute("value", aPrefValue);
    }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 51 of file preferences.cs.

Definition at line 52 of file preferences.cs.


The documentation for this class was generated from the following file: