sbDirectoryProvider.cpp
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #include "sbDirectoryProvider.h"
26 
27 #include <nsCOMPtr.h>
28 #include <nsServiceManagerUtils.h>
29 #include <nsXPCOMCID.h>
30 #include <nsILocalFile.h>
31 #include <nsStringAPI.h>
32 
33 #if defined(XP_WIN)
34 
35 #include <windows.h>
36 #include <shlobj.h>
37 
38 #include "winGetFolder.h"
39 
40 #endif // XP_WIN
41 
42 NS_IMPL_ISUPPORTS1(sbDirectoryProvider, nsIDirectoryServiceProvider)
43 
45 {
46  /* member initializers and constructor code */
47 }
48 
49 sbDirectoryProvider::~sbDirectoryProvider()
50 {
51  /* destructor code */
52 }
53 
54 nsresult
56 {
57  nsresult rv;
58 
59  nsCOMPtr<nsIDirectoryService> dirService =
60  do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID,
61  &rv);
62  NS_ENSURE_SUCCESS(rv, rv);
63 
64  rv = dirService->RegisterProvider(this);
65  NS_ENSURE_SUCCESS(rv, rv);
66 
67  return NS_OK;
68 }
69 
70 NS_IMETHODIMP
71 sbDirectoryProvider::GetFile(const char *aProp,
72  PRBool *aPersistent,
73  nsIFile **_retval)
74 {
75  NS_ENSURE_ARG(aProp);
76  NS_ENSURE_ARG_POINTER(aPersistent);
77  NS_ENSURE_ARG_POINTER(_retval);
78 
79  nsCOMPtr<nsILocalFile> localFile;
80  nsresult rv = NS_ERROR_FAILURE;
81 
82  *_retval = nsnull;
83  *aPersistent = PR_TRUE;
84 
85 #if defined (XP_WIN)
86  if (strcmp(aProp, NS_WIN_COMMON_DOCUMENTS) == 0)
87  rv = GetWindowsFolder(CSIDL_COMMON_DOCUMENTS, getter_AddRefs(localFile));
88  else if (strcmp(aProp, NS_WIN_COMMON_PICTURES) == 0)
89  rv = GetWindowsFolder(CSIDL_COMMON_PICTURES, getter_AddRefs(localFile));
90  else if (strcmp(aProp, NS_WIN_COMMON_MUSIC) == 0)
91  rv = GetWindowsFolder(CSIDL_COMMON_MUSIC, getter_AddRefs(localFile));
92  else if (strcmp(aProp, NS_WIN_COMMON_VIDEO) == 0)
93  rv = GetWindowsFolder(CSIDL_COMMON_VIDEO, getter_AddRefs(localFile));
94  else if (strcmp(aProp, NS_WIN_DOCUMENTS) == 0)
95  rv = GetWindowsFolder(CSIDL_MYDOCUMENTS, getter_AddRefs(localFile));
96  else if (strcmp(aProp, NS_WIN_PICTURES) == 0)
97  rv = GetWindowsFolder(CSIDL_MYPICTURES, getter_AddRefs(localFile));
98  else if (strcmp(aProp, NS_WIN_MUSIC) == 0)
99  rv = GetWindowsFolder(CSIDL_MYMUSIC, getter_AddRefs(localFile));
100  else if (strcmp(aProp, NS_WIN_VIDEO) == 0)
101  rv = GetWindowsFolder(CSIDL_MYVIDEO, getter_AddRefs(localFile));
102  else if (strcmp(aProp, NS_WIN_DISCBURNING) == 0)
103  rv = GetWindowsFolder(CSIDL_CDBURN_AREA, getter_AddRefs(localFile));
104 #endif // XP_WIN
105 
106  if (NS_SUCCEEDED(rv)) {
107  if (localFile)
108  rv = CallQueryInterface(localFile, _retval);
109  else
110  rv = NS_ERROR_FAILURE;
111  }
112 
113  return rv;
114 }
return NS_OK
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
#define NS_WIN_COMMON_VIDEO
#define NS_WIN_COMMON_PICTURES
#define NS_WIN_VIDEO
#define NS_WIN_COMMON_DOCUMENTS
#define NS_WIN_MUSIC
#define NS_WIN_DOCUMENTS
#define NS_WIN_DISCBURNING
#define NS_WIN_COMMON_MUSIC
#define NS_WIN_PICTURES
static nsresult GetWindowsFolder(int folder, nsILocalFile **aFile)
Definition: winGetFolder.h:48