From b54ab2026d75301b0948a9152c1108f02356c360 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Tue, 30 Nov 1999 11:33:44 +0000 Subject: [PATCH] Working on code to enumerate installed skins, packages, and locales. r=gimpy git-svn-id: svn://10.0.0.236/trunk@54744 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/chrome/public/nsIChromeRegistry.idl | 6 +- mozilla/chrome/src/nsChromeRegistry.cpp | 201 +++++++++++++++++- .../rdf/chrome/public/nsIChromeRegistry.idl | 6 +- mozilla/rdf/chrome/src/nsChromeRegistry.cpp | 201 +++++++++++++++++- 4 files changed, 386 insertions(+), 28 deletions(-) diff --git a/mozilla/chrome/public/nsIChromeRegistry.idl b/mozilla/chrome/public/nsIChromeRegistry.idl index 23ca18d3919..e9a27d707a8 100644 --- a/mozilla/chrome/public/nsIChromeRegistry.idl +++ b/mozilla/chrome/public/nsIChromeRegistry.idl @@ -42,9 +42,9 @@ interface nsIChromeRegistry : nsISupports void setDefaultSkin(in wstring skinName, in wstring packageName); void setDefaultLocale(in wstring localeName, in wstring packageName); - readonly attribute nsISupportsArray skins; - readonly attribute nsISupportsArray packages; - readonly attribute nsISupportsArray locales; + nsISimpleEnumerator getSkins(); + nsISimpleEnumerator getPackages(); + nsISimpleEnumerator getLocales(); }; diff --git a/mozilla/chrome/src/nsChromeRegistry.cpp b/mozilla/chrome/src/nsChromeRegistry.cpp index ad9f6219497..f639f2ba657 100644 --- a/mozilla/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/chrome/src/nsChromeRegistry.cpp @@ -83,6 +83,10 @@ DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, name); void BreakProviderAndRemainingFromPath(const char* i_path, char** o_provider, char** o_remaining); //////////////////////////////////////////////////////////////////////////////// + +// XXX Both overlayEnumerator and chromeEntryEnumerator must take two sets of +// arcs rather than one, and they must be able to move to the second set after +// finishing the first. class nsOverlayEnumerator : public nsISimpleEnumerator { public: @@ -157,6 +161,98 @@ NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult) return NS_OK; } +class nsChromeEntryEnumerator : public nsISimpleEnumerator +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSISIMPLEENUMERATOR + + nsChromeEntryEnumerator(nsISimpleEnumerator *aProfileArcs, + nsISimpleEnumerator *aInstallArcs); + virtual ~nsChromeEntryEnumerator(); + +private: + nsCOMPtr mProfileArcs; + nsCOMPtr mInstallArcs; + nsCOMPtr mCurrentArcs; +}; + +NS_IMPL_ISUPPORTS1(nsChromeEntryEnumerator, nsISimpleEnumerator) + +nsChromeEntryEnumerator::nsChromeEntryEnumerator(nsISimpleEnumerator *aProfileArcs, + nsISimpleEnumerator *aInstallArcs) +{ + NS_INIT_REFCNT(); + mProfileArcs = aProfileArcs; + mInstallArcs = aInstallArcs; + mCurrentArcs = mProfileArcs; +} + +nsChromeEntryEnumerator::~nsChromeEntryEnumerator() +{ +} + +NS_IMETHODIMP nsChromeEntryEnumerator::HasMoreElements(PRBool *aIsTrue) +{ + *aIsTrue = PR_FALSE; + + if (!mProfileArcs) { + if (!mInstallArcs) + return NS_OK; // Default value of FALSE for no arcs in either places + return mInstallArcs->HasMoreElements(aIsTrue); // No profile arcs means check install + } + else { + nsresult rv = mProfileArcs->HasMoreElements(aIsTrue); + if (*aIsTrue || !mInstallArcs) // Have profile elts or no install arcs means bail. + return rv; + + return mInstallArcs->HasMoreElements(aIsTrue); // Otherwise just use install arcs. + } + + return NS_OK; +} + +NS_IMETHODIMP nsChromeEntryEnumerator::GetNext(nsISupports **aResult) +{ + nsresult rv; + *aResult = nsnull; + + if (!mCurrentArcs) { + mCurrentArcs = mInstallArcs; + if (!mInstallArcs) + return NS_ERROR_FAILURE; + } + else if (mCurrentArcs == mProfileArcs) { + PRBool hasMore; + mProfileArcs->HasMoreElements(&hasMore); + if (!hasMore) + mCurrentArcs = mInstallArcs; + if (!mInstallArcs) + return NS_ERROR_FAILURE; + } + + nsCOMPtr supports; + mCurrentArcs->GetNext(getter_AddRefs(supports)); + + nsCOMPtr value = do_QueryInterface(supports, &rv); + if (NS_FAILED(rv)) + return NS_OK; + + const PRUnichar* valueStr; + rv = value->GetValueConst(&valueStr); + if (NS_FAILED(rv)) + return rv; +/* + nsCOMPtr sup; + sup = do_QueryInterface(url, &rv); + if (NS_FAILED(rv)) + return NS_OK; + + *aResult = sup; + NS_ADDREF(*aResult); +*/ + return NS_OK; +} class nsChromeRegistry : public nsIChromeRegistry { @@ -204,6 +300,8 @@ protected: nsIRDFContainer *aContainer, nsIRDFDataSource *aDataSource); + NS_IMETHOD GetEnumeratorForType(const nsCAutoString& type, nsISimpleEnumerator** aResult); + private: NS_IMETHOD ReallyRemoveOverlayFromDataSource(const PRUnichar *aDocURI, char *aOverlayURI); NS_IMETHOD LoadDataSource(const nsCAutoString &aFileName, nsIRDFDataSource **aResult, @@ -1263,22 +1361,103 @@ nsChromeRegistry::ReloadChrome() } NS_IMETHODIMP -nsChromeRegistry::GetSkins(nsISupportsArray** aResult) +nsChromeRegistry::GetEnumeratorForType(const nsCAutoString& type, nsISimpleEnumerator** aResult) { - // XXX Fill in. - return NS_OK; -} + // Load the data source. + nsCAutoString chromeFile("chrome/"); + chromeFile += type; + chromeFile += ".rdf"; + + // Get the profile root for the first set of arcs. + nsCAutoString profileKey; + GetProfileRoot(profileKey); + profileKey += chromeFile; + + // Use the install root for the second set of arcs. + nsCAutoString installKey("resource:/"); + installKey += chromeFile; + + nsCOMPtr profileDataSource; + nsCOMPtr installDataSource; + + nsresult rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, + nsnull, + NS_GET_IID(nsIRDFDataSource), + (void**) getter_AddRefs(profileDataSource)); + if (NS_FAILED(rv)) return rv; + + rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, + nsnull, + NS_GET_IID(nsIRDFDataSource), + (void**) getter_AddRefs(installDataSource)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr remoteProfile = do_QueryInterface(profileDataSource); + nsCOMPtr remoteInstall = do_QueryInterface(installDataSource); + + nsCAutoString fileURL; + nsCOMPtr fl; + + rv = nsComponentManager::CreateInstance("component://netscape/filelocator", + nsnull, + NS_GET_IID(nsIFileLocator), + getter_AddRefs(fl)); + + if (NS_FAILED(rv)) + return NS_OK; + + // Build a fileSpec that points to the destination + // (profile dir + chrome + package + provider + chrome.rdf) + nsCOMPtr chromeFileInterface; + fl->GetFileLocation(nsSpecialFileSpec::App_UserProfileDirectory50, getter_AddRefs(chromeFileInterface)); + nsFileSpec fileSpec; + + PRBool exists = PR_FALSE; + if (chromeFileInterface) { + // Read in the profile data source (or try to anyway) + chromeFileInterface->GetFileSpec(&fileSpec); + fileSpec += "/"; + fileSpec += (const char*)chromeFile; + + nsFileURL fileURL(fileSpec); + const char* fileStr = fileURL.GetURLString(); + nsCAutoString fileURLStr = fileStr; + fileURLStr += chromeFile; + + remoteProfile->Init(fileURLStr); + remoteProfile->Refresh(PR_TRUE); + } + + // Read in the install data source. + nsCAutoString fileURLStr = "resource:/"; + fileURLStr += chromeFile; + remoteInstall->Init(fileURLStr); + remoteInstall->Refresh(PR_TRUE); + + // Get some arcs from each data source. + + // Build an nsChromeEntryEnumerator and return it. -NS_IMETHODIMP -nsChromeRegistry::GetPackages(nsISupportsArray** aResult) -{ - // XXX Fill in. return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::GetLocales(nsISupportsArray** aResult) +nsChromeRegistry::GetSkins(nsISimpleEnumerator** aResult) { - // XXX Fill in. - return NS_OK; + nsCAutoString type("skins"); + return GetEnumeratorForType(type, aResult); +} + +NS_IMETHODIMP +nsChromeRegistry::GetPackages(nsISimpleEnumerator** aResult) +{ + nsCAutoString type("packages"); + return GetEnumeratorForType(type, aResult); +} + +NS_IMETHODIMP +nsChromeRegistry::GetLocales(nsISimpleEnumerator** aResult) +{ + nsCAutoString type("locales"); + return GetEnumeratorForType(type, aResult); } diff --git a/mozilla/rdf/chrome/public/nsIChromeRegistry.idl b/mozilla/rdf/chrome/public/nsIChromeRegistry.idl index 23ca18d3919..e9a27d707a8 100644 --- a/mozilla/rdf/chrome/public/nsIChromeRegistry.idl +++ b/mozilla/rdf/chrome/public/nsIChromeRegistry.idl @@ -42,9 +42,9 @@ interface nsIChromeRegistry : nsISupports void setDefaultSkin(in wstring skinName, in wstring packageName); void setDefaultLocale(in wstring localeName, in wstring packageName); - readonly attribute nsISupportsArray skins; - readonly attribute nsISupportsArray packages; - readonly attribute nsISupportsArray locales; + nsISimpleEnumerator getSkins(); + nsISimpleEnumerator getPackages(); + nsISimpleEnumerator getLocales(); }; diff --git a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp index ad9f6219497..f639f2ba657 100644 --- a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp @@ -83,6 +83,10 @@ DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, name); void BreakProviderAndRemainingFromPath(const char* i_path, char** o_provider, char** o_remaining); //////////////////////////////////////////////////////////////////////////////// + +// XXX Both overlayEnumerator and chromeEntryEnumerator must take two sets of +// arcs rather than one, and they must be able to move to the second set after +// finishing the first. class nsOverlayEnumerator : public nsISimpleEnumerator { public: @@ -157,6 +161,98 @@ NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult) return NS_OK; } +class nsChromeEntryEnumerator : public nsISimpleEnumerator +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSISIMPLEENUMERATOR + + nsChromeEntryEnumerator(nsISimpleEnumerator *aProfileArcs, + nsISimpleEnumerator *aInstallArcs); + virtual ~nsChromeEntryEnumerator(); + +private: + nsCOMPtr mProfileArcs; + nsCOMPtr mInstallArcs; + nsCOMPtr mCurrentArcs; +}; + +NS_IMPL_ISUPPORTS1(nsChromeEntryEnumerator, nsISimpleEnumerator) + +nsChromeEntryEnumerator::nsChromeEntryEnumerator(nsISimpleEnumerator *aProfileArcs, + nsISimpleEnumerator *aInstallArcs) +{ + NS_INIT_REFCNT(); + mProfileArcs = aProfileArcs; + mInstallArcs = aInstallArcs; + mCurrentArcs = mProfileArcs; +} + +nsChromeEntryEnumerator::~nsChromeEntryEnumerator() +{ +} + +NS_IMETHODIMP nsChromeEntryEnumerator::HasMoreElements(PRBool *aIsTrue) +{ + *aIsTrue = PR_FALSE; + + if (!mProfileArcs) { + if (!mInstallArcs) + return NS_OK; // Default value of FALSE for no arcs in either places + return mInstallArcs->HasMoreElements(aIsTrue); // No profile arcs means check install + } + else { + nsresult rv = mProfileArcs->HasMoreElements(aIsTrue); + if (*aIsTrue || !mInstallArcs) // Have profile elts or no install arcs means bail. + return rv; + + return mInstallArcs->HasMoreElements(aIsTrue); // Otherwise just use install arcs. + } + + return NS_OK; +} + +NS_IMETHODIMP nsChromeEntryEnumerator::GetNext(nsISupports **aResult) +{ + nsresult rv; + *aResult = nsnull; + + if (!mCurrentArcs) { + mCurrentArcs = mInstallArcs; + if (!mInstallArcs) + return NS_ERROR_FAILURE; + } + else if (mCurrentArcs == mProfileArcs) { + PRBool hasMore; + mProfileArcs->HasMoreElements(&hasMore); + if (!hasMore) + mCurrentArcs = mInstallArcs; + if (!mInstallArcs) + return NS_ERROR_FAILURE; + } + + nsCOMPtr supports; + mCurrentArcs->GetNext(getter_AddRefs(supports)); + + nsCOMPtr value = do_QueryInterface(supports, &rv); + if (NS_FAILED(rv)) + return NS_OK; + + const PRUnichar* valueStr; + rv = value->GetValueConst(&valueStr); + if (NS_FAILED(rv)) + return rv; +/* + nsCOMPtr sup; + sup = do_QueryInterface(url, &rv); + if (NS_FAILED(rv)) + return NS_OK; + + *aResult = sup; + NS_ADDREF(*aResult); +*/ + return NS_OK; +} class nsChromeRegistry : public nsIChromeRegistry { @@ -204,6 +300,8 @@ protected: nsIRDFContainer *aContainer, nsIRDFDataSource *aDataSource); + NS_IMETHOD GetEnumeratorForType(const nsCAutoString& type, nsISimpleEnumerator** aResult); + private: NS_IMETHOD ReallyRemoveOverlayFromDataSource(const PRUnichar *aDocURI, char *aOverlayURI); NS_IMETHOD LoadDataSource(const nsCAutoString &aFileName, nsIRDFDataSource **aResult, @@ -1263,22 +1361,103 @@ nsChromeRegistry::ReloadChrome() } NS_IMETHODIMP -nsChromeRegistry::GetSkins(nsISupportsArray** aResult) +nsChromeRegistry::GetEnumeratorForType(const nsCAutoString& type, nsISimpleEnumerator** aResult) { - // XXX Fill in. - return NS_OK; -} + // Load the data source. + nsCAutoString chromeFile("chrome/"); + chromeFile += type; + chromeFile += ".rdf"; + + // Get the profile root for the first set of arcs. + nsCAutoString profileKey; + GetProfileRoot(profileKey); + profileKey += chromeFile; + + // Use the install root for the second set of arcs. + nsCAutoString installKey("resource:/"); + installKey += chromeFile; + + nsCOMPtr profileDataSource; + nsCOMPtr installDataSource; + + nsresult rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, + nsnull, + NS_GET_IID(nsIRDFDataSource), + (void**) getter_AddRefs(profileDataSource)); + if (NS_FAILED(rv)) return rv; + + rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, + nsnull, + NS_GET_IID(nsIRDFDataSource), + (void**) getter_AddRefs(installDataSource)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr remoteProfile = do_QueryInterface(profileDataSource); + nsCOMPtr remoteInstall = do_QueryInterface(installDataSource); + + nsCAutoString fileURL; + nsCOMPtr fl; + + rv = nsComponentManager::CreateInstance("component://netscape/filelocator", + nsnull, + NS_GET_IID(nsIFileLocator), + getter_AddRefs(fl)); + + if (NS_FAILED(rv)) + return NS_OK; + + // Build a fileSpec that points to the destination + // (profile dir + chrome + package + provider + chrome.rdf) + nsCOMPtr chromeFileInterface; + fl->GetFileLocation(nsSpecialFileSpec::App_UserProfileDirectory50, getter_AddRefs(chromeFileInterface)); + nsFileSpec fileSpec; + + PRBool exists = PR_FALSE; + if (chromeFileInterface) { + // Read in the profile data source (or try to anyway) + chromeFileInterface->GetFileSpec(&fileSpec); + fileSpec += "/"; + fileSpec += (const char*)chromeFile; + + nsFileURL fileURL(fileSpec); + const char* fileStr = fileURL.GetURLString(); + nsCAutoString fileURLStr = fileStr; + fileURLStr += chromeFile; + + remoteProfile->Init(fileURLStr); + remoteProfile->Refresh(PR_TRUE); + } + + // Read in the install data source. + nsCAutoString fileURLStr = "resource:/"; + fileURLStr += chromeFile; + remoteInstall->Init(fileURLStr); + remoteInstall->Refresh(PR_TRUE); + + // Get some arcs from each data source. + + // Build an nsChromeEntryEnumerator and return it. -NS_IMETHODIMP -nsChromeRegistry::GetPackages(nsISupportsArray** aResult) -{ - // XXX Fill in. return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::GetLocales(nsISupportsArray** aResult) +nsChromeRegistry::GetSkins(nsISimpleEnumerator** aResult) { - // XXX Fill in. - return NS_OK; + nsCAutoString type("skins"); + return GetEnumeratorForType(type, aResult); +} + +NS_IMETHODIMP +nsChromeRegistry::GetPackages(nsISimpleEnumerator** aResult) +{ + nsCAutoString type("packages"); + return GetEnumeratorForType(type, aResult); +} + +NS_IMETHODIMP +nsChromeRegistry::GetLocales(nsISimpleEnumerator** aResult) +{ + nsCAutoString type("locales"); + return GetEnumeratorForType(type, aResult); }