Back to index

lightning-sunbird  0.9+nobinonly
nsBookmarksService.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef bookmarksservice___h___
00039 #define bookmarksservice___h___
00040 
00041 #include "nsIRDFDataSource.h"
00042 #include "nsIRDFRemoteDataSource.h"
00043 #include "nsIRDFPropagatableDataSource.h"
00044 #include "nsIStreamListener.h"
00045 #include "nsIRDFObserver.h"
00046 #include "nsISupportsArray.h"
00047 #include "nsCOMArray.h"
00048 #include "nsIStringBundle.h"
00049 #include "nsITimer.h"
00050 #include "nsIRDFNode.h"
00051 #include "nsIBookmarksService.h"
00052 #include "nsString.h"
00053 #include "nsIFile.h"
00054 #include "nsIObserver.h"
00055 #include "nsWeakReference.h"
00056 #include "nsCOMArray.h"
00057 #include "nsIIOService.h"
00058 #include "nsICacheService.h"
00059 #include "nsICacheSession.h"
00060 #include "nsITransactionManager.h"
00061 #include "nsICharsetResolver.h"
00062 
00063 class nsIOutputStream;
00064 
00065 #ifdef DEBUG
00066 #if defined(XP_MAC) || defined(XP_MACOSX)
00067 #include <Timer.h>
00068 #endif
00069 #endif
00070 
00071 class nsBookmarksService : public nsIBookmarksService,
00072                            public nsIRDFDataSource,
00073                            public nsIRDFRemoteDataSource,
00074                            public nsIRDFPropagatableDataSource,
00075                            public nsIStreamListener,
00076                            public nsICharsetResolver,
00077                            public nsIRDFObserver,
00078                            public nsIObserver,
00079                            public nsSupportsWeakReference
00080 {
00081 protected:
00082     nsIRDFDataSource*               mInner;
00083     nsCOMPtr<nsIRDFResource>        busyResource;
00084     nsCOMArray<nsIRDFObserver>      mObservers;
00085     nsCOMPtr<nsIStringBundle>       mBundle;
00086     nsCOMPtr<nsITimer>              mTimer;
00087     nsCOMPtr<nsIIOService>          mNetService;
00088     nsCOMPtr<nsICacheService>       mCacheService;
00089     nsCOMPtr<nsICacheSession>       mCacheSession;
00090     nsCOMPtr<nsITransactionManager> mTransactionManager;
00091     nsCOMPtr<nsILocalFile>          mBookmarksFile;
00092 
00093     PRUint32      htmlSize;
00094     PRInt32       mUpdateBatchNest;
00095     nsXPIDLString mPersonalToolbarName;
00096     nsXPIDLString mBookmarksRootName;
00097     PRBool        mDirty;
00098     PRBool        mBrowserIcons;
00099     PRBool        mAlwaysLoadIcons;
00100     PRBool        busySchedule;
00101 
00102     // System Bookmark parsing
00103 #if defined(XP_WIN)
00104     // @param aDirectory      - Favorites Folder to import from.
00105     // @param aParentResource - Folder into which to place imported
00106     //                          Favorites.
00107     nsresult      ParseFavoritesFolder(nsIFile* aDirectory, 
00108                                        nsIRDFResource* aParentResource);
00109 #elif defined(XP_MAC) || defined(XP_MACOSX)
00110     PRBool        mIEFavoritesAvailable;
00111 
00112     nsresult      ReadFavorites();
00113 #endif
00114 
00115 #if defined(XP_WIN) || defined(XP_MAC) || defined(XP_MACOSX)
00116     void          HandleSystemBookmarks(nsIRDFNode* aNode);
00117 #endif
00118 
00119     static void FireTimer(nsITimer* aTimer, void* aClosure);
00120 
00121     nsresult ExamineBookmarkSchedule(nsIRDFResource *theBookmark, PRBool & examineFlag);
00122 
00123     nsresult GetBookmarkToPing(nsIRDFResource **theBookmark);
00124 
00125     nsresult EnsureBookmarksFile();
00126 
00127     nsresult WriteBookmarks(nsIFile* bookmarksFile, nsIRDFDataSource *ds,
00128                             nsIRDFResource *root);
00129 
00130     nsresult WriteBookmarksContainer(nsIRDFDataSource *ds,
00131                                      nsIOutputStream* strm,
00132                                      nsIRDFResource *container,
00133                                      PRInt32 level,
00134                                      nsCOMArray<nsIRDFResource>& parentArray);
00135 
00136     nsresult SerializeBookmarks(nsIURI* aURI);
00137 
00138     nsresult GetTextForNode(nsIRDFNode* aNode, nsString& aResult);
00139 
00140     nsresult GetSynthesizedType(nsIRDFResource *aNode, nsIRDFNode **aType);
00141 
00142     nsresult UpdateBookmarkLastModifiedDate(nsIRDFResource *aSource);
00143 
00144     nsresult WriteBookmarkProperties(nsIRDFDataSource *ds,
00145                                      nsIOutputStream* strm,
00146                                      nsIRDFResource *node,
00147                                      nsIRDFResource *property,
00148                                      const char *htmlAttrib,
00149                                      PRBool isFirst);
00150 
00151     PRBool   CanAccept(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode* aTarget);
00152 
00153     nsresult getArgumentN(nsISupportsArray *arguments, nsIRDFResource *res,
00154                           PRInt32 offset, nsIRDFNode **argValue);
00155 
00156     nsresult insertBookmarkItem(nsIRDFResource *src,
00157                                 nsISupportsArray *aArguments,
00158                                 nsIRDFResource *objType);
00159 
00160     nsresult deleteBookmarkItem(nsIRDFResource *src,
00161                                 nsISupportsArray *aArguments,
00162                                 PRInt32 parentArgIndex);
00163 
00164     nsresult setFolderHint(nsIRDFResource *src, nsIRDFResource *objType);
00165 
00166     nsresult getFolderViaHint(nsIRDFResource *src, PRBool fallbackFlag,
00167                               nsIRDFResource **folder);
00168 
00169     nsresult importBookmarks(nsISupportsArray *aArguments);
00170 
00171     nsresult exportBookmarks(nsISupportsArray *aArguments);
00172 
00173     nsresult ProcessCachedBookmarkIcon(nsIRDFResource* aSource,
00174                                        const PRUnichar *iconURL,
00175                                        nsIRDFNode** aTarget);
00176 
00177     void AnnotateBookmarkSchedule(nsIRDFResource* aSource,
00178                                   PRBool scheduleFlag);
00179 
00180     nsresult InsertResource(nsIRDFResource* aResource,
00181                             nsIRDFResource* aParentFolder, PRInt32 aIndex);
00182 
00183     nsresult getLocaleString(const char *key, nsString &str);
00184 
00185     static int PR_CALLBACK
00186     Compare(const void* aElement1, const void* aElement2, void* aData);
00187 
00188     nsresult
00189     Sort(nsIRDFResource* aFolder, nsIRDFResource* aProperty,
00190          PRInt32 aDirection, PRBool aFoldersFirst, PRBool aRecurse);
00191 
00192     nsresult
00193     GetURLFromResource(nsIRDFResource* aResource, nsAString& aURL);
00194 
00195     nsresult
00196     CopyResource(nsIRDFResource* aOldResource, nsIRDFResource* aNewResource);
00197 
00198     nsresult
00199     SetNewPersonalToolbarFolder(nsIRDFResource* aFolder);
00200 
00201     nsresult LoadBookmarks();
00202     nsresult initDatasource();
00203 
00204     // nsIStreamObserver methods:
00205     NS_DECL_NSIREQUESTOBSERVER
00206 
00207     // nsIStreamListener methods:
00208     NS_DECL_NSISTREAMLISTENER
00209 
00210     NS_DECL_NSICHARSETRESOLVER
00211 
00212     // nsIObserver methods:
00213     NS_DECL_NSIOBSERVER
00214 
00215 public:
00216     nsBookmarksService();
00217     virtual ~nsBookmarksService();
00218     nsresult Init();
00219 
00220     // nsISupports
00221     NS_DECL_ISUPPORTS
00222 
00223     // nsIBookmarksService
00224     NS_DECL_NSIBOOKMARKSSERVICE
00225 
00226     // nsIRDFDataSource
00227     NS_IMETHOD GetURI(char* *uri);
00228 
00229     NS_IMETHOD GetSource(nsIRDFResource* property,
00230                          nsIRDFNode* target,
00231                          PRBool tv,
00232                          nsIRDFResource** source)
00233     {
00234         return mInner->GetSource(property, target, tv, source);
00235     }
00236 
00237     NS_IMETHOD GetSources(nsIRDFResource* property,
00238                           nsIRDFNode* target,
00239                           PRBool tv,
00240                           nsISimpleEnumerator** sources)
00241     {
00242         return mInner->GetSources(property, target, tv, sources);
00243     }
00244 
00245     NS_IMETHOD GetTarget(nsIRDFResource* source,
00246                          nsIRDFResource* property,
00247                          PRBool tv,
00248                          nsIRDFNode** target);
00249 
00250     NS_IMETHOD GetTargets(nsIRDFResource* source,
00251                           nsIRDFResource* property,
00252                           PRBool tv,
00253                           nsISimpleEnumerator** targets)
00254     {
00255         return mInner->GetTargets(source, property, tv, targets);
00256     }
00257 
00258     NS_IMETHOD Assert(nsIRDFResource* aSource,
00259                       nsIRDFResource* aProperty,
00260                       nsIRDFNode* aTarget,
00261                       PRBool aTruthValue);
00262 
00263     NS_IMETHOD Unassert(nsIRDFResource* aSource,
00264                         nsIRDFResource* aProperty,
00265                         nsIRDFNode* aTarget);
00266 
00267     NS_IMETHOD Change(nsIRDFResource* aSource,
00268                       nsIRDFResource* aProperty,
00269                       nsIRDFNode* aOldTarget,
00270                       nsIRDFNode* aNewTarget);
00271     
00272     NS_IMETHOD Move(nsIRDFResource* aOldSource,
00273                     nsIRDFResource* aNewSource,
00274                     nsIRDFResource* aProperty,
00275                     nsIRDFNode* aTarget);
00276             
00277     NS_IMETHOD HasAssertion(nsIRDFResource* source,
00278                             nsIRDFResource* property,
00279                             nsIRDFNode* target,
00280                             PRBool tv,
00281                             PRBool* hasAssertion);
00282 
00283     NS_IMETHOD AddObserver(nsIRDFObserver* aObserver);
00284     NS_IMETHOD RemoveObserver(nsIRDFObserver* aObserver);
00285 
00286     NS_IMETHOD HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *_retval);
00287     NS_IMETHOD HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *_retval);
00288 
00289     NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
00290                            nsISimpleEnumerator** labels)
00291     {
00292         return mInner->ArcLabelsIn(node, labels);
00293     }
00294 
00295     NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
00296                             nsISimpleEnumerator** labels);
00297 
00298     NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult);
00299 
00300     NS_IMETHOD GetAllCmds(nsIRDFResource* source,
00301                           nsISimpleEnumerator/*<nsIRDFResource>*/** commands);
00302 
00303     NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
00304                                 nsIRDFResource*   aCommand,
00305                                 nsISupportsArray/*<nsIRDFResource>*/* aArguments,
00306                                 PRBool* aResult);
00307 
00308     NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
00309                          nsIRDFResource*   aCommand,
00310                          nsISupportsArray/*<nsIRDFResource>*/* aArguments);
00311 
00312     NS_IMETHOD BeginUpdateBatch() {
00313         return mInner->BeginUpdateBatch();
00314     }
00315 
00316     NS_IMETHOD EndUpdateBatch() {
00317         return mInner->EndUpdateBatch();
00318     }
00319 
00320     // nsIRDFRemoteDataSource
00321     NS_DECL_NSIRDFREMOTEDATASOURCE
00322 
00323     // nsIRDFPropagatableDataSource
00324     NS_DECL_NSIRDFPROPAGATABLEDATASOURCE
00325 
00326     // nsIRDFObserver
00327     NS_DECL_NSIRDFOBSERVER
00328 };
00329 
00330 #endif // bookmarksservice___h___