From 18e76dbd53d284d7f0943a6f2d5f89f12e20ef51 Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Tue, 1 Mar 2005 01:03:33 +0000 Subject: [PATCH] Bug 241245. Make 'Desk' a supported system directory on Unix, and make it fully cross-platform. r+sr=darin --- xpcom/io/SpecialSystemDirectory.cpp | 63 +++++++++++++++++++---------- xpcom/io/SpecialSystemDirectory.h | 1 + xpcom/io/nsDirectoryService.cpp | 48 +++++++++------------- xpcom/io/nsDirectoryService.h | 10 +---- xpcom/io/nsDirectoryServiceDefs.h | 23 ++++++----- 5 files changed, 77 insertions(+), 68 deletions(-) diff --git a/xpcom/io/SpecialSystemDirectory.cpp b/xpcom/io/SpecialSystemDirectory.cpp index e0de3d0bd33..edb5e246e1b 100644 --- a/xpcom/io/SpecialSystemDirectory.cpp +++ b/xpcom/io/SpecialSystemDirectory.cpp @@ -258,6 +258,28 @@ GetBeOSFolder( directory_which which, dev_t volume, nsILocalFile** aFile) } #endif // XP_BEOS +#if defined(XP_UNIX) +static nsresult +GetUnixHomeDir(nsILocalFile** aFile) +{ +#ifdef VMS + char *pHome; + pHome = getenv("HOME"); + if (*pHome == '/') { + return NS_NewNativeLocalFile(nsDependentCString(pHome), + PR_TRUE, + aFile); + } else { + return NS_NewNativeLocalFile(nsDependentCString(decc$translate_vms(pHome)), + PR_TRUE, + aFile); + } +#else + return NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), + PR_TRUE, aFile); +#endif +} +#endif nsresult GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory, @@ -639,32 +661,29 @@ GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory, aFile); case Unix_HomeDirectory: -#ifdef VMS + return GetUnixHomeDir(aFile); + + case Unix_DesktopDirectory: { - char *pHome; - pHome = getenv("HOME"); - if (*pHome == '/') { - return NS_NewNativeLocalFile(nsDependentCString(pHome), - PR_TRUE, - aFile); - - } - else - { - return NS_NewNativeLocalFile(nsDependentCString(decc$translate_vms(pHome)), - PR_TRUE, - aFile); - } + nsCOMPtr home; + nsresult rv = GetUnixHomeDir(getter_AddRefs(home)); + if (NS_FAILED(rv)) + return rv; + rv = home->AppendNative(NS_LITERAL_CSTRING("Desktop")); + if (NS_FAILED(rv)) + return rv; + PRBool exists; + rv = home->Exists(&exists); + if (NS_FAILED(rv)) + return rv; + if (!exists) + return GetUnixHomeDir(aFile); + + NS_ADDREF(*aFile = home); + return NS_OK; } -#else - return NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), - PR_TRUE, - aFile); - #endif -#endif - #ifdef XP_BEOS case BeOS_SettingsDirectory: { diff --git a/xpcom/io/SpecialSystemDirectory.h b/xpcom/io/SpecialSystemDirectory.h index 1a5a9e398da..46247dda895 100644 --- a/xpcom/io/SpecialSystemDirectory.h +++ b/xpcom/io/SpecialSystemDirectory.h @@ -111,6 +111,7 @@ enum SystemDirectories { Unix_LocalDirectory = 301, Unix_LibDirectory = 302, Unix_HomeDirectory = 303, + Unix_DesktopDirectory = 304, BeOS_SettingsDirectory = 401, BeOS_HomeDirectory = 402, diff --git a/xpcom/io/nsDirectoryService.cpp b/xpcom/io/nsDirectoryService.cpp index 62618225611..6e928e3ca12 100644 --- a/xpcom/io/nsDirectoryService.cpp +++ b/xpcom/io/nsDirectoryService.cpp @@ -326,9 +326,10 @@ nsIAtom* nsDirectoryService::sOS_DriveDirectory = nsnull; nsIAtom* nsDirectoryService::sOS_TemporaryDirectory = nsnull; nsIAtom* nsDirectoryService::sOS_CurrentProcessDirectory = nsnull; nsIAtom* nsDirectoryService::sOS_CurrentWorkingDirectory = nsnull; +nsIAtom* nsDirectoryService::sOS_DesktopDirectory = nsnull; +nsIAtom* nsDirectoryService::sOS_HomeDirectory = nsnull; #if defined (XP_MACOSX) nsIAtom* nsDirectoryService::sDirectory = nsnull; -nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull; nsIAtom* nsDirectoryService::sTrashDirectory = nsnull; nsIAtom* nsDirectoryService::sStartupDirectory = nsnull; nsIAtom* nsDirectoryService::sShutdownDirectory = nsnull; @@ -340,7 +341,6 @@ nsIAtom* nsDirectoryService::sPreferencesDirectory = nsnull; nsIAtom* nsDirectoryService::sDocumentsDirectory = nsnull; nsIAtom* nsDirectoryService::sInternetSearchDirectory = nsnull; nsIAtom* nsDirectoryService::sUserLibDirectory = nsnull; -nsIAtom* nsDirectoryService::sHomeDirectory = nsnull; nsIAtom* nsDirectoryService::sDefaultDownloadDirectory = nsnull; nsIAtom* nsDirectoryService::sUserDesktopDirectory = nsnull; nsIAtom* nsDirectoryService::sLocalDesktopDirectory = nsnull; @@ -361,7 +361,6 @@ nsIAtom* nsDirectoryService::sInternetSitesDirectory = nsnull; #elif defined (XP_WIN) nsIAtom* nsDirectoryService::sSystemDirectory = nsnull; nsIAtom* nsDirectoryService::sWindowsDirectory = nsnull; -nsIAtom* nsDirectoryService::sHomeDirectory = nsnull; nsIAtom* nsDirectoryService::sDesktop = nsnull; nsIAtom* nsDirectoryService::sPrograms = nsnull; nsIAtom* nsDirectoryService::sControls = nsnull; @@ -389,16 +388,11 @@ nsIAtom* nsDirectoryService::sWinCookiesDirectory = nsnull; #elif defined (XP_UNIX) nsIAtom* nsDirectoryService::sLocalDirectory = nsnull; nsIAtom* nsDirectoryService::sLibDirectory = nsnull; -nsIAtom* nsDirectoryService::sHomeDirectory = nsnull; #elif defined (XP_OS2) nsIAtom* nsDirectoryService::sSystemDirectory = nsnull; nsIAtom* nsDirectoryService::sOS2Directory = nsnull; -nsIAtom* nsDirectoryService::sHomeDirectory = nsnull; -nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull; #elif defined (XP_BEOS) nsIAtom* nsDirectoryService::sSettingsDirectory = nsnull; -nsIAtom* nsDirectoryService::sHomeDirectory = nsnull; -nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull; nsIAtom* nsDirectoryService::sSystemDirectory = nsnull; #endif @@ -434,10 +428,11 @@ static const nsStaticAtom directory_atoms[] = { { NS_OS_TEMP_DIR, &nsDirectoryService::sOS_TemporaryDirectory }, { NS_OS_CURRENT_PROCESS_DIR, &nsDirectoryService::sOS_CurrentProcessDirectory }, { NS_OS_CURRENT_WORKING_DIR, &nsDirectoryService::sOS_CurrentWorkingDirectory }, + { NS_OS_HOME_DIR, &nsDirectoryService::sOS_HomeDirectory }, + { NS_OS_DESKTOP_DIR, &nsDirectoryService::sOS_DesktopDirectory }, { NS_XPCOM_INIT_CURRENT_PROCESS_DIR, nsnull }, #if defined (XP_MACOSX) { NS_OS_SYSTEM_DIR, &nsDirectoryService::sDirectory }, - { NS_MAC_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory }, { NS_MAC_TRASH_DIR, &nsDirectoryService::sTrashDirectory }, { NS_MAC_STARTUP_DIR, &nsDirectoryService::sStartupDirectory }, { NS_MAC_SHUTDOWN_DIR, &nsDirectoryService::sShutdownDirectory }, @@ -449,7 +444,6 @@ static const nsStaticAtom directory_atoms[] = { { NS_MAC_DOCUMENTS_DIR, &nsDirectoryService::sDocumentsDirectory }, { NS_MAC_INTERNET_SEARCH_DIR, &nsDirectoryService::sInternetSearchDirectory }, { NS_MAC_USER_LIB_DIR, &nsDirectoryService::sUserLibDirectory }, - { NS_OSX_HOME_DIR, &nsDirectoryService::sHomeDirectory }, { NS_OSX_DEFAULT_DOWNLOAD_DIR, &nsDirectoryService::sDefaultDownloadDirectory }, { NS_OSX_USER_DESKTOP_DIR, &nsDirectoryService::sUserDesktopDirectory }, { NS_OSX_LOCAL_DESKTOP_DIR, &nsDirectoryService::sLocalDesktopDirectory }, @@ -470,7 +464,6 @@ static const nsStaticAtom directory_atoms[] = { #elif defined (XP_WIN) { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory }, { NS_WIN_WINDOWS_DIR, &nsDirectoryService::sWindowsDirectory }, - { NS_WIN_HOME_DIR, &nsDirectoryService::sHomeDirectory }, { NS_WIN_DESKTOP_DIR, &nsDirectoryService::sDesktop }, { NS_WIN_PROGRAMS_DIR, &nsDirectoryService::sPrograms }, { NS_WIN_CONTROLS_DIR, &nsDirectoryService::sControls }, @@ -498,17 +491,12 @@ static const nsStaticAtom directory_atoms[] = { #elif defined (XP_UNIX) { NS_UNIX_LOCAL_DIR, &nsDirectoryService::sLocalDirectory }, { NS_UNIX_LIB_DIR, &nsDirectoryService::sLibDirectory }, - { NS_UNIX_HOME_DIR, &nsDirectoryService::sHomeDirectory }, #elif defined (XP_OS2) { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory }, { NS_OS2_DIR, &nsDirectoryService::sOS2Directory }, - { NS_OS2_HOME_DIR, &nsDirectoryService::sHomeDirectory }, - { NS_OS2_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory }, #elif defined (XP_BEOS) { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory }, { NS_BEOS_SETTINGS_DIR, &nsDirectoryService::sSettingsDirectory }, - { NS_BEOS_HOME_DIR, &nsDirectoryService::sHomeDirectory }, - { NS_BEOS_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory }, #endif }; @@ -814,10 +802,6 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { rv = GetOSXFolderType(kClassicDomain, kSystemFolderType, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sDesktopDirectory) - { - rv = GetOSXFolderType(kClassicDomain, kDesktopFolderType, getter_AddRefs(localFile)); - } else if (inAtom == nsDirectoryService::sTrashDirectory) { rv = GetOSXFolderType(kClassicDomain, kTrashFolderType, getter_AddRefs(localFile)); @@ -862,7 +846,7 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { rv = GetOSXFolderType(kUserDomain, kDomainLibraryFolderType, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sHomeDirectory) + else if (inAtom == nsDirectoryService::sOS_HomeDirectory) { rv = GetOSXFolderType(kUserDomain, kDomainTopLevelFolderType, getter_AddRefs(localFile)); } @@ -919,7 +903,8 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret // Negligible perf hit as this directory is only requested for downloads *persistent = PR_FALSE; } - else if (inAtom == nsDirectoryService::sUserDesktopDirectory) + else if (inAtom == nsDirectoryService::sUserDesktopDirectory || + inAtom == nsDirectoryService::sOS_DesktopDirectory) { rv = GetOSXFolderType(kUserDomain, kDesktopFolderType, getter_AddRefs(localFile)); } @@ -992,7 +977,7 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { rv = GetSpecialSystemDirectory(Win_WindowsDirectory, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sHomeDirectory) + else if (inAtom == nsDirectoryService::sOS_HomeDirectory) { rv = GetSpecialSystemDirectory(Win_HomeDirectory, getter_AddRefs(localFile)); } @@ -1040,7 +1025,8 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { rv = GetSpecialSystemDirectory(Win_Startmenu, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sDesktopdirectory) + else if (inAtom == nsDirectoryService::sDesktopdirectory || + inAtom == nsDirectoryService::sOS_DesktopDirectory) { rv = GetSpecialSystemDirectory(Win_Desktopdirectory, getter_AddRefs(localFile)); } @@ -1102,10 +1088,14 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { rv = GetSpecialSystemDirectory(Unix_LibDirectory, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sHomeDirectory) + else if (inAtom == nsDirectoryService::sOS_HomeDirectory) { rv = GetSpecialSystemDirectory(Unix_HomeDirectory, getter_AddRefs(localFile)); } + else if (inAtom == nsDirectoryService::sOS_DesktopDirectory) + { + rv = GetSpecialSystemDirectory(Unix_DesktopDirectory, getter_AddRefs(localFile)); + } #elif defined (XP_OS2) else if (inAtom == nsDirectoryService::sSystemDirectory) { @@ -1115,11 +1105,11 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { rv = GetSpecialSystemDirectory(OS2_OS2Directory, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sHomeDirectory) + else if (inAtom == nsDirectoryService::sOS_HomeDirectory) { rv = GetSpecialSystemDirectory(OS2_HomeDirectory, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sDesktopDirectory) + else if (inAtom == nsDirectoryService::sOS_DesktopDirectory) { rv = GetSpecialSystemDirectory(OS2_DesktopDirectory, getter_AddRefs(localFile)); } @@ -1128,11 +1118,11 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { rv = GetSpecialSystemDirectory(BeOS_SettingsDirectory, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sHomeDirectory) + else if (inAtom == nsDirectoryService::sOS_HomeDirectory) { rv = GetSpecialSystemDirectory(BeOS_HomeDirectory, getter_AddRefs(localFile)); } - else if (inAtom == nsDirectoryService::sDesktopDirectory) + else if (inAtom == nsDirectoryService::sOS_DesktopDirectory) { rv = GetSpecialSystemDirectory(BeOS_DesktopDirectory, getter_AddRefs(localFile)); } diff --git a/xpcom/io/nsDirectoryService.h b/xpcom/io/nsDirectoryService.h index 67e6e3714ec..5150e837c8f 100644 --- a/xpcom/io/nsDirectoryService.h +++ b/xpcom/io/nsDirectoryService.h @@ -93,9 +93,10 @@ public: static nsIAtom *sOS_TemporaryDirectory; static nsIAtom *sOS_CurrentProcessDirectory; static nsIAtom *sOS_CurrentWorkingDirectory; + static nsIAtom *sOS_DesktopDirectory; + static nsIAtom *sOS_HomeDirectory; #if defined (XP_MACOSX) static nsIAtom *sDirectory; - static nsIAtom *sDesktopDirectory; static nsIAtom *sTrashDirectory; static nsIAtom *sStartupDirectory; static nsIAtom *sShutdownDirectory; @@ -107,7 +108,6 @@ public: static nsIAtom *sDocumentsDirectory; static nsIAtom *sInternetSearchDirectory; static nsIAtom *sUserLibDirectory; - static nsIAtom *sHomeDirectory; static nsIAtom *sDefaultDownloadDirectory; static nsIAtom *sUserDesktopDirectory; static nsIAtom *sLocalDesktopDirectory; @@ -128,7 +128,6 @@ public: #elif defined (XP_WIN) static nsIAtom *sSystemDirectory; static nsIAtom *sWindowsDirectory; - static nsIAtom *sHomeDirectory; static nsIAtom *sDesktop; static nsIAtom *sPrograms; static nsIAtom *sControls; @@ -156,16 +155,11 @@ public: #elif defined (XP_UNIX) static nsIAtom *sLocalDirectory; static nsIAtom *sLibDirectory; - static nsIAtom *sHomeDirectory; #elif defined (XP_OS2) static nsIAtom *sSystemDirectory; static nsIAtom *sOS2Directory; - static nsIAtom *sHomeDirectory; - static nsIAtom *sDesktopDirectory; #elif defined (XP_BEOS) static nsIAtom *sSettingsDirectory; - static nsIAtom *sHomeDirectory; - static nsIAtom *sDesktopDirectory; static nsIAtom *sSystemDirectory; #endif diff --git a/xpcom/io/nsDirectoryServiceDefs.h b/xpcom/io/nsDirectoryServiceDefs.h index 6b3e749a464..04cc94c53cc 100755 --- a/xpcom/io/nsDirectoryServiceDefs.h +++ b/xpcom/io/nsDirectoryServiceDefs.h @@ -57,6 +57,10 @@ #define NS_OS_HOME_DIR "Home" #define NS_OS_TEMP_DIR "TmpD" #define NS_OS_CURRENT_WORKING_DIR "CurWorkD" +/* Files stored in this directory will appear on the user's desktop, + * if there is one, otherwise it's just the same as "Home" + */ +#define NS_OS_DESKTOP_DIR "Desk" /* Property returns the directory in which the procces was started from. * On Unix this will be the path in the MOZILLA_FIVE_HOME env var and if @@ -115,7 +119,7 @@ #endif #if defined (XP_MACOSX) - #define NS_MAC_DESKTOP_DIR "Desk" + #define NS_MAC_DESKTOP_DIR NS_OS_DESKTOP_DIR #define NS_MAC_TRASH_DIR "Trsh" #define NS_MAC_STARTUP_DIR "Strt" #define NS_MAC_SHUTDOWN_DIR "Shdwn" @@ -126,8 +130,8 @@ #define NS_MAC_PREFS_DIR "Prfs" #define NS_MAC_DOCUMENTS_DIR "Docs" #define NS_MAC_INTERNET_SEARCH_DIR "ISrch" - #define NS_OSX_HOME_DIR "Home" - #define NS_MAC_HOME_DIR NS_OSX_HOME_DIR + #define NS_OSX_HOME_DIR NS_OS_HOME_DIR + #define NS_MAC_HOME_DIR NS_OS_HOME_DIR #define NS_MAC_DEFAULT_DOWNLOAD_DIR "DfltDwnld" #define NS_MAC_USER_LIB_DIR "ULibDir" // Only available under OS X #define NS_OSX_DEFAULT_DOWNLOAD_DIR NS_MAC_DEFAULT_DOWNLOAD_DIR @@ -149,7 +153,7 @@ #define NS_OSX_INTERNET_SITES_DIR "IntrntSts" #elif defined (XP_WIN) #define NS_WIN_WINDOWS_DIR "WinD" - #define NS_WIN_HOME_DIR "Home" + #define NS_WIN_HOME_DIR NS_OS_HOME_DIR #define NS_WIN_DESKTOP_DIR "DeskV" // virtual folder at the root of the namespace #define NS_WIN_PROGRAMS_DIR "Progs" #define NS_WIN_CONTROLS_DIR "Cntls" @@ -161,6 +165,7 @@ #define NS_WIN_SEND_TO_DIR "SndTo" #define NS_WIN_BITBUCKET_DIR "Buckt" #define NS_WIN_STARTMENU_DIR "Strt" +// This gives the same thing as NS_OS_DESKTOP_DIR #define NS_WIN_DESKTOP_DIRECTORY "DeskP" // file sys dir which physically stores objects on desktop #define NS_WIN_DRIVES_DIR "Drivs" #define NS_WIN_NETWORK_DIR "NetW" @@ -177,15 +182,15 @@ #elif defined (XP_UNIX) #define NS_UNIX_LOCAL_DIR "Locl" #define NS_UNIX_LIB_DIR "LibD" - #define NS_UNIX_HOME_DIR "Home" + #define NS_UNIX_HOME_DIR NS_OS_HOME_DIR #elif defined (XP_OS2) #define NS_OS2_DIR "OS2Dir" - #define NS_OS2_HOME_DIR "Home" - #define NS_OS2_DESKTOP_DIR "Desk" + #define NS_OS2_HOME_DIR NS_OS_HOME_DIR + #define NS_OS2_DESKTOP_DIR NS_OS_DESKTOP_DIR #elif defined (XP_BEOS) #define NS_BEOS_SETTINGS_DIR "Setngs" - #define NS_BEOS_HOME_DIR "Home" - #define NS_BEOS_DESKTOP_DIR "Desk" + #define NS_BEOS_HOME_DIR NS_OS_HOME_DIR + #define NS_BEOS_DESKTOP_DIR NS_OS_DESKTOP_DIR #endif /* Deprecated */