1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef nsFileSystemDataSource_h__
7 #define nsFileSystemDataSource_h__
8 
9 #include "nsIRDFDataSource.h"
10 #include "nsIRDFLiteral.h"
11 #include "nsIRDFResource.h"
12 #include "nsIRDFService.h"
13 #include "nsCOMPtr.h"
14 #include "nsString.h"
15 #include "mozilla/Attributes.h"
16 
17 #if defined(XP_UNIX) || defined(XP_WIN)
18 #define USE_NC_EXTENSION
19 #endif
20 
21 class FileSystemDataSource final : public nsIRDFDataSource
22 {
23 public:
24     NS_DECL_ISUPPORTS
25     NS_DECL_NSIRDFDATASOURCE
26 
27     static nsresult Create(nsISupports* aOuter,
28                            const nsIID& aIID, void **aResult);
29 
30     nsresult Init();
31 
32 private:
FileSystemDataSource()33     FileSystemDataSource() { }
~FileSystemDataSource()34     ~FileSystemDataSource() { }
35 
36     // helper methods
37     bool     isFileURI(nsIRDFResource* aResource);
38     bool     isDirURI(nsIRDFResource* aSource);
39     nsresult GetVolumeList(nsISimpleEnumerator **aResult);
40     nsresult GetFolderList(nsIRDFResource *source, bool allowHidden, bool onlyFirst, nsISimpleEnumerator **aResult);
41     nsresult GetName(nsIRDFResource *source, nsIRDFLiteral** aResult);
42     nsresult GetURL(nsIRDFResource *source, bool *isFavorite, nsIRDFLiteral** aResult);
43     nsresult GetFileSize(nsIRDFResource *source, nsIRDFInt** aResult);
44     nsresult GetLastMod(nsIRDFResource *source, nsIRDFDate** aResult);
45 
46     nsCOMPtr<nsIRDFService>    mRDFService;
47 
48     // pseudo-constants
49     nsCOMPtr<nsIRDFResource>       mNC_FileSystemRoot;
50     nsCOMPtr<nsIRDFResource>       mNC_Child;
51     nsCOMPtr<nsIRDFResource>       mNC_Name;
52     nsCOMPtr<nsIRDFResource>       mNC_URL;
53     nsCOMPtr<nsIRDFResource>       mNC_Icon;
54     nsCOMPtr<nsIRDFResource>       mNC_Length;
55     nsCOMPtr<nsIRDFResource>       mNC_IsDirectory;
56     nsCOMPtr<nsIRDFResource>       mWEB_LastMod;
57     nsCOMPtr<nsIRDFResource>       mNC_FileSystemObject;
58     nsCOMPtr<nsIRDFResource>       mNC_pulse;
59     nsCOMPtr<nsIRDFResource>       mRDF_InstanceOf;
60     nsCOMPtr<nsIRDFResource>       mRDF_type;
61 
62     nsCOMPtr<nsIRDFLiteral>        mLiteralTrue;
63     nsCOMPtr<nsIRDFLiteral>        mLiteralFalse;
64 
65 #ifdef USE_NC_EXTENSION
66     nsresult GetExtension(nsIRDFResource *source, nsIRDFLiteral** aResult);
67     nsCOMPtr<nsIRDFResource>       mNC_extension;
68 #endif
69 
70 #ifdef  XP_WIN
71     bool     isValidFolder(nsIRDFResource *source);
72     nsresult getIEFavoriteURL(nsIRDFResource *source, nsString aFileURL, nsIRDFLiteral **urlLiteral);
73     nsCOMPtr<nsIRDFResource>       mNC_IEFavoriteObject;
74     nsCOMPtr<nsIRDFResource>       mNC_IEFavoriteFolder;
75     nsCString                      ieFavoritesDir;
76 #endif
77 };
78 
79 #endif // nsFileSystemDataSource_h__
80