Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
Silverstone.Manticore.Bookmarks.Bookmarks Class Reference
Inheritance diagram for Silverstone.Manticore.Bookmarks.Bookmarks:
Inheritance graph
[legend]
Collaboration diagram for Silverstone.Manticore.Bookmarks.Bookmarks:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Bookmarks ()
void LoadBookmarks ()
void ImportBookmarks ()
string ResolveKeyword (string aURL)
String CreateBookmark (String aLabel, String aParentID, int aPosition)
void DeleteBookmark (Bookmark aBookmark)
String GetBookmarkAttribute (String aBookmarkID, String aAttribute)
 Retrieve the string value of a given Bookmark property. We expose this API so as not to have to expose the internal DOM implementation of Bookmarks.
void SetBookmarkAttribute (String aBookmarkID, String aAttribute, String aValue)
void GetElements (String aContainerID, out IEnumerator aElements)
void AddObserver (IDataStoreObserver aObserver)
XmlElement GetElementById (String aID)
 XXX This is a hack, is really bad and inefficient and should go away when we figure out how to make XmlDocument.GetElementById to work.

Static Public Member Functions

static String GenerateID ()

Private Member Functions

 ~Bookmarks ()

Private Attributes

XmlDocument mBookmarksDocument
String mBookmarksFile
Queue mObservers = null
bool mBookmarksLoaded = false

Detailed Description

Definition at line 52 of file bookmarks.cs.


Constructor & Destructor Documentation

Definition at line 62 of file bookmarks.cs.

    {
      mBookmarksDocument = new XmlDocument();
    }

Definition at line 67 of file bookmarks.cs.


Member Function Documentation

Implements Silverstone.Manticore.Core.IDataStore.

Definition at line 250 of file bookmarks.cs.

    {
      if (mObservers == null)
        mObservers = new Queue();
      mObservers.Enqueue(aObserver);
    }
String Silverstone.Manticore.Bookmarks.Bookmarks.CreateBookmark ( String  aLabel,
String  aParentID,
int  aPosition 
) [inline]

Definition at line 117 of file bookmarks.cs.

    {
      XmlElement parentElt = GetElementById(aParentID);

      XmlElement childElt = mBookmarksDocument.CreateElement("item");
      childElt.SetAttribute("label", aLabel);
      String bookmarkID = Bookmarks.GenerateID();
      childElt.SetAttribute("id", bookmarkID);
      if (aPosition != -1)
        parentElt.InsertBefore(childElt, parentElt.ChildNodes[aPosition]);
      else
        parentElt.AppendChild(childElt);

      CommandTarget target = new CommandTarget(aLabel, "", bookmarkID, false);
      CommandTarget parentTarget = new CommandTarget("", "", aParentID, true);
      IEnumerator observers = mObservers.GetEnumerator();
      while (observers.MoveNext()) 
      {
        IDataStoreObserver idso = observers.Current as IDataStoreObserver;
        idso.OnNodeAdded(target, parentTarget, -1);
      }
      
      return bookmarkID;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file bookmarks.cs.

    {

    }

Definition at line 213 of file bookmarks.cs.

    {
      // Generate a random ID for a bookmark item
      Random rand = new Random();
      return String.Format("NC:Bookmark${0:X}", rand.Next());
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Retrieve the string value of a given Bookmark property. We expose this API so as not to have to expose the internal DOM implementation of Bookmarks.

Parameters:
aBookmarkID
aAttribute
Returns:

Definition at line 154 of file bookmarks.cs.

    {
      XmlElement elt = GetElementById(aBookmarkID);
      return elt.GetAttribute(aAttribute);
    }

Here is the caller graph for this function:

XXX This is a hack, is really bad and inefficient and should go away when we figure out how to make XmlDocument.GetElementById to work.

Parameters:
aID
Returns:

Definition at line 263 of file bookmarks.cs.

    {
      XmlNodeList list = mBookmarksDocument.GetElementsByTagName("item");
      int count = list.Count;
      for (int i = 0; i < count; ++i) 
      {
        XmlElement elt = list[i] as XmlElement;
        if (elt != null) 
        {
          if (elt.GetAttribute("id") == aID)
            return elt;
        }
      }
      return null;
    }

Here is the call graph for this function:

void Silverstone.Manticore.Bookmarks.Bookmarks.GetElements ( String  aContainerID,
out IEnumerator  aElements 
) [inline]

Implements Silverstone.Manticore.Core.IDataStore.

Definition at line 223 of file bookmarks.cs.

    {
      XmlElement container = GetElementById(aContainerID);
      if (container == null)
        container = mBookmarksDocument.DocumentElement.FirstChild as XmlElement;
      int itemCount = container.ChildNodes.Count;
      Queue items = new Queue();
      for (int i = 0; i < itemCount; ++i) 
      {
        XmlElement currElt = container.ChildNodes[i] as XmlElement;
        // If the bookmark does not have an ID, generate one and set it. 
        if (!currElt.HasAttribute("id") || currElt.GetAttribute("id") == "")
          currElt.SetAttribute("id", Bookmarks.GenerateID());
        
        CommandTarget target = new CommandTarget();
        target.Label = currElt.GetAttribute("label");
        target.AccessKey = currElt.GetAttribute("accesskey");
        target.Data = currElt.GetAttribute("id");
        target.IsContainer = currElt.HasChildNodes;
        target.IconURL = currElt.GetAttribute("icon");
        target.IsOpen = currElt.GetAttribute("open") == "true";
        
        items.Enqueue(target);
      }
      aElements = items.GetEnumerator();
    }

Here is the call graph for this function:

Definition at line 106 of file bookmarks.cs.

    {
      // Import a Netscape bookmarks file.
    }

Definition at line 72 of file bookmarks.cs.

    {
      // First of all, the user may have chosen to place the bookmark file
      // in a specific location.
      mBookmarksFile = ServiceManager.Preferences.GetStringPref("browser.bookmarksfile");

      // Otherwise, look in the profile directory.
      if (mBookmarksFile == "")
        mBookmarksFile = FileLocator.GetManticorePath("LocalBookmarks");

      // Support remote bookmarks by setting up an asynchronous load & parse. 
      try 
      {
        mBookmarksDocument.Load(mBookmarksFile);
      }
      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\bookmarks.xml", mBookmarksFile, true);
        }
        catch (DirectoryNotFoundException) 
        {
          String manticoreAppData = FileLocator.GetManticorePath("AppData");
          Directory.CreateDirectory(manticoreAppData);
          File.Copy(@"defaults\bookmarks.xml", mBookmarksFile, true);
        }
      }
      mBookmarksLoaded = true;
    }

Here is the call graph for this function:

Definition at line 111 of file bookmarks.cs.

    {
      // XXX implement me
      return "";
    }

Here is the caller graph for this function:

void Silverstone.Manticore.Bookmarks.Bookmarks.SetBookmarkAttribute ( String  aBookmarkID,
String  aAttribute,
String  aValue 
) [inline]

Definition at line 160 of file bookmarks.cs.

    {
      XmlElement elt = GetElementById(aBookmarkID);

      CommandTarget oldTarget = new CommandTarget();
      switch (aAttribute) 
      {
        case "label":
          oldTarget.Label = elt.GetAttribute(aAttribute);
          break;
        case "icon":
          oldTarget.IconURL = elt.GetAttribute(aAttribute);
          break;
        case "container":
          oldTarget.IsContainer = elt.GetAttribute(aAttribute) == "true";
          break;
        case "open":
          oldTarget.IsOpen = elt.GetAttribute(aAttribute) == "true";
          break;
      }
      oldTarget.Data = aBookmarkID;

      elt.SetAttribute(aAttribute, aValue);

      // Enumerate the attributes presentation cares about and set the attribute on the
      // target if it is being changed. 
      // XXX could optimize this. 
      CommandTarget newTarget = new CommandTarget();
      switch (aAttribute) 
      {
        case "label":
          newTarget.Label = aValue;
          break;
        case "icon":
          newTarget.IconURL = aValue;
          break;
        case "container":
          newTarget.IsContainer = aValue == "true";
          break;
        case "open":
          newTarget.IsOpen = aValue == "true";
          break;
      }
      newTarget.Data = aBookmarkID;

      IEnumerator observers = mObservers.GetEnumerator();
      while (observers.MoveNext()) 
      {
        IDataStoreObserver idso = observers.Current as IDataStoreObserver;
        idso.OnNodeChanged(oldTarget, newTarget);
      }
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 54 of file bookmarks.cs.

Definition at line 55 of file bookmarks.cs.

Definition at line 57 of file bookmarks.cs.

Definition at line 56 of file bookmarks.cs.


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