From afb901e71b512334281b48fb5bd2a11272191c5c Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Wed, 3 Jul 2002 06:22:15 +0000 Subject: [PATCH] Changing the home page behaviour. Now, if no user pref is set, we get the default home page from a .strings file, and set this in the user pref. Also using values from CHUserDefaults.h --- camino/CHPreferenceManager.h | 6 ++-- camino/CHPreferenceManager.mm | 31 ++++++++++++++++---- camino/src/preferences/PreferenceManager.h | 6 ++-- camino/src/preferences/PreferenceManager.mm | 31 ++++++++++++++++---- chimera/CHPreferenceManager.h | 6 ++-- chimera/CHPreferenceManager.mm | 31 ++++++++++++++++---- chimera/src/preferences/PreferenceManager.h | 6 ++-- chimera/src/preferences/PreferenceManager.mm | 31 ++++++++++++++++---- 8 files changed, 116 insertions(+), 32 deletions(-) diff --git a/camino/CHPreferenceManager.h b/camino/CHPreferenceManager.h index 56f10f5a1b7c..3063fc19b835 100644 --- a/camino/CHPreferenceManager.h +++ b/camino/CHPreferenceManager.h @@ -39,8 +39,8 @@ #import @interface CHPreferenceManager : NSObject { - NSUserDefaults *defaults; - ICInstance internetConfig; + NSUserDefaults* mDefaults; + ICInstance mInternetConfig; } + (CHPreferenceManager *)sharedInstance; @@ -50,7 +50,7 @@ - (BOOL) initInternetConfig; - (BOOL) initMozillaPrefs; - (void) syncMozillaPrefs; -// - (BOOL) getICBoolPref:(ConstStr255Param) prefKey; + - (NSString *) getICStringPref:(ConstStr255Param) prefKey; - (NSString *) homePage:(BOOL) checkStartupPagePref; diff --git a/camino/CHPreferenceManager.mm b/camino/CHPreferenceManager.mm index 0367cf6ece0d..09acd7f9e468 100644 --- a/camino/CHPreferenceManager.mm +++ b/camino/CHPreferenceManager.mm @@ -37,12 +37,16 @@ #import #import + #import #import "CHPreferenceManager.h" +#import "CHUserDefaults.h" + #include "nsIServiceManager.h" #include "nsIProfile.h" #include "nsIPref.h" #include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsString.h" #include "nsEmbedAPI.h" #include "AppDirServiceProvider.h" @@ -74,6 +78,8 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); // XXXw. throw here too NSLog (@"Failed to initialize mozilla prefs.\n"); } + + mDefaults = [NSUserDefaults standardUserDefaults]; } return self; } @@ -81,7 +87,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); - (void) dealloc { nsresult rv; - ICStop (internetConfig); + ICStop (mInternetConfig); nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID, &rv)); if (!NS_FAILED(rv)) pref->SavePrefFile(nsnull); @@ -91,7 +97,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); - (BOOL) initInternetConfig { OSStatus error; - error = ICStart (&internetConfig, 'CHIM'); + error = ICStart (&mInternetConfig, 'CHIM'); if (error != noErr) { // XXX throw here? NSLog(@"Error initializing IC.\n"); @@ -350,7 +356,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); NSLog (@"malloc failed in [PreferenceManager getICStringPref]."); return nil; } - error = ICGetPref (internetConfig, prefKey, &dummy, buf, &size); + error = ICGetPref (mInternetConfig, prefKey, &dummy, buf, &size); if (error != noErr && error != icTruncatedErr) { free (buf); NSLog (@"[IC error %d in [PreferenceManager getICStringPref].\n", (int) error); @@ -392,8 +398,23 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); if (NS_SUCCEEDED(prefs->GetBoolPref("chimera.use_system_home_page", &boolPref)) && boolPref) return [self getICStringPref:kICWWWHomePage]; - NSString* homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil ); - if ([homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) + nsCOMPtr prefBranch = do_QueryInterface(prefs); + if (!prefBranch) return @"about:blank"; + + NSString* homepagePref = nil; + PRInt32 haveUserPref; + if (NS_FAILED(prefBranch->PrefHasUserValue("browser.startup.homepage", &haveUserPref)) || !haveUserPref) { + // no home page pref is set in user prefs. + homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil); + // and let's copy this into the homepage pref if it's not bad + if (![homepagePref isEqualToString:@"HomePageDefault"]) + prefs->SetCharPref("browser.startup.homepage", [homepagePref cString]); + } + else { + homepagePref = [self getMozillaPrefString:"browser.startup.homepage"]; + } + + if (homepagePref && [homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) return homepagePref; } diff --git a/camino/src/preferences/PreferenceManager.h b/camino/src/preferences/PreferenceManager.h index 56f10f5a1b7c..3063fc19b835 100644 --- a/camino/src/preferences/PreferenceManager.h +++ b/camino/src/preferences/PreferenceManager.h @@ -39,8 +39,8 @@ #import @interface CHPreferenceManager : NSObject { - NSUserDefaults *defaults; - ICInstance internetConfig; + NSUserDefaults* mDefaults; + ICInstance mInternetConfig; } + (CHPreferenceManager *)sharedInstance; @@ -50,7 +50,7 @@ - (BOOL) initInternetConfig; - (BOOL) initMozillaPrefs; - (void) syncMozillaPrefs; -// - (BOOL) getICBoolPref:(ConstStr255Param) prefKey; + - (NSString *) getICStringPref:(ConstStr255Param) prefKey; - (NSString *) homePage:(BOOL) checkStartupPagePref; diff --git a/camino/src/preferences/PreferenceManager.mm b/camino/src/preferences/PreferenceManager.mm index 0367cf6ece0d..09acd7f9e468 100644 --- a/camino/src/preferences/PreferenceManager.mm +++ b/camino/src/preferences/PreferenceManager.mm @@ -37,12 +37,16 @@ #import #import + #import #import "CHPreferenceManager.h" +#import "CHUserDefaults.h" + #include "nsIServiceManager.h" #include "nsIProfile.h" #include "nsIPref.h" #include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsString.h" #include "nsEmbedAPI.h" #include "AppDirServiceProvider.h" @@ -74,6 +78,8 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); // XXXw. throw here too NSLog (@"Failed to initialize mozilla prefs.\n"); } + + mDefaults = [NSUserDefaults standardUserDefaults]; } return self; } @@ -81,7 +87,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); - (void) dealloc { nsresult rv; - ICStop (internetConfig); + ICStop (mInternetConfig); nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID, &rv)); if (!NS_FAILED(rv)) pref->SavePrefFile(nsnull); @@ -91,7 +97,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); - (BOOL) initInternetConfig { OSStatus error; - error = ICStart (&internetConfig, 'CHIM'); + error = ICStart (&mInternetConfig, 'CHIM'); if (error != noErr) { // XXX throw here? NSLog(@"Error initializing IC.\n"); @@ -350,7 +356,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); NSLog (@"malloc failed in [PreferenceManager getICStringPref]."); return nil; } - error = ICGetPref (internetConfig, prefKey, &dummy, buf, &size); + error = ICGetPref (mInternetConfig, prefKey, &dummy, buf, &size); if (error != noErr && error != icTruncatedErr) { free (buf); NSLog (@"[IC error %d in [PreferenceManager getICStringPref].\n", (int) error); @@ -392,8 +398,23 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); if (NS_SUCCEEDED(prefs->GetBoolPref("chimera.use_system_home_page", &boolPref)) && boolPref) return [self getICStringPref:kICWWWHomePage]; - NSString* homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil ); - if ([homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) + nsCOMPtr prefBranch = do_QueryInterface(prefs); + if (!prefBranch) return @"about:blank"; + + NSString* homepagePref = nil; + PRInt32 haveUserPref; + if (NS_FAILED(prefBranch->PrefHasUserValue("browser.startup.homepage", &haveUserPref)) || !haveUserPref) { + // no home page pref is set in user prefs. + homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil); + // and let's copy this into the homepage pref if it's not bad + if (![homepagePref isEqualToString:@"HomePageDefault"]) + prefs->SetCharPref("browser.startup.homepage", [homepagePref cString]); + } + else { + homepagePref = [self getMozillaPrefString:"browser.startup.homepage"]; + } + + if (homepagePref && [homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) return homepagePref; } diff --git a/chimera/CHPreferenceManager.h b/chimera/CHPreferenceManager.h index 56f10f5a1b7c..3063fc19b835 100644 --- a/chimera/CHPreferenceManager.h +++ b/chimera/CHPreferenceManager.h @@ -39,8 +39,8 @@ #import @interface CHPreferenceManager : NSObject { - NSUserDefaults *defaults; - ICInstance internetConfig; + NSUserDefaults* mDefaults; + ICInstance mInternetConfig; } + (CHPreferenceManager *)sharedInstance; @@ -50,7 +50,7 @@ - (BOOL) initInternetConfig; - (BOOL) initMozillaPrefs; - (void) syncMozillaPrefs; -// - (BOOL) getICBoolPref:(ConstStr255Param) prefKey; + - (NSString *) getICStringPref:(ConstStr255Param) prefKey; - (NSString *) homePage:(BOOL) checkStartupPagePref; diff --git a/chimera/CHPreferenceManager.mm b/chimera/CHPreferenceManager.mm index 0367cf6ece0d..09acd7f9e468 100644 --- a/chimera/CHPreferenceManager.mm +++ b/chimera/CHPreferenceManager.mm @@ -37,12 +37,16 @@ #import #import + #import #import "CHPreferenceManager.h" +#import "CHUserDefaults.h" + #include "nsIServiceManager.h" #include "nsIProfile.h" #include "nsIPref.h" #include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsString.h" #include "nsEmbedAPI.h" #include "AppDirServiceProvider.h" @@ -74,6 +78,8 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); // XXXw. throw here too NSLog (@"Failed to initialize mozilla prefs.\n"); } + + mDefaults = [NSUserDefaults standardUserDefaults]; } return self; } @@ -81,7 +87,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); - (void) dealloc { nsresult rv; - ICStop (internetConfig); + ICStop (mInternetConfig); nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID, &rv)); if (!NS_FAILED(rv)) pref->SavePrefFile(nsnull); @@ -91,7 +97,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); - (BOOL) initInternetConfig { OSStatus error; - error = ICStart (&internetConfig, 'CHIM'); + error = ICStart (&mInternetConfig, 'CHIM'); if (error != noErr) { // XXX throw here? NSLog(@"Error initializing IC.\n"); @@ -350,7 +356,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); NSLog (@"malloc failed in [PreferenceManager getICStringPref]."); return nil; } - error = ICGetPref (internetConfig, prefKey, &dummy, buf, &size); + error = ICGetPref (mInternetConfig, prefKey, &dummy, buf, &size); if (error != noErr && error != icTruncatedErr) { free (buf); NSLog (@"[IC error %d in [PreferenceManager getICStringPref].\n", (int) error); @@ -392,8 +398,23 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); if (NS_SUCCEEDED(prefs->GetBoolPref("chimera.use_system_home_page", &boolPref)) && boolPref) return [self getICStringPref:kICWWWHomePage]; - NSString* homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil ); - if ([homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) + nsCOMPtr prefBranch = do_QueryInterface(prefs); + if (!prefBranch) return @"about:blank"; + + NSString* homepagePref = nil; + PRInt32 haveUserPref; + if (NS_FAILED(prefBranch->PrefHasUserValue("browser.startup.homepage", &haveUserPref)) || !haveUserPref) { + // no home page pref is set in user prefs. + homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil); + // and let's copy this into the homepage pref if it's not bad + if (![homepagePref isEqualToString:@"HomePageDefault"]) + prefs->SetCharPref("browser.startup.homepage", [homepagePref cString]); + } + else { + homepagePref = [self getMozillaPrefString:"browser.startup.homepage"]; + } + + if (homepagePref && [homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) return homepagePref; } diff --git a/chimera/src/preferences/PreferenceManager.h b/chimera/src/preferences/PreferenceManager.h index 56f10f5a1b7c..3063fc19b835 100644 --- a/chimera/src/preferences/PreferenceManager.h +++ b/chimera/src/preferences/PreferenceManager.h @@ -39,8 +39,8 @@ #import @interface CHPreferenceManager : NSObject { - NSUserDefaults *defaults; - ICInstance internetConfig; + NSUserDefaults* mDefaults; + ICInstance mInternetConfig; } + (CHPreferenceManager *)sharedInstance; @@ -50,7 +50,7 @@ - (BOOL) initInternetConfig; - (BOOL) initMozillaPrefs; - (void) syncMozillaPrefs; -// - (BOOL) getICBoolPref:(ConstStr255Param) prefKey; + - (NSString *) getICStringPref:(ConstStr255Param) prefKey; - (NSString *) homePage:(BOOL) checkStartupPagePref; diff --git a/chimera/src/preferences/PreferenceManager.mm b/chimera/src/preferences/PreferenceManager.mm index 0367cf6ece0d..09acd7f9e468 100644 --- a/chimera/src/preferences/PreferenceManager.mm +++ b/chimera/src/preferences/PreferenceManager.mm @@ -37,12 +37,16 @@ #import #import + #import #import "CHPreferenceManager.h" +#import "CHUserDefaults.h" + #include "nsIServiceManager.h" #include "nsIProfile.h" #include "nsIPref.h" #include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsString.h" #include "nsEmbedAPI.h" #include "AppDirServiceProvider.h" @@ -74,6 +78,8 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); // XXXw. throw here too NSLog (@"Failed to initialize mozilla prefs.\n"); } + + mDefaults = [NSUserDefaults standardUserDefaults]; } return self; } @@ -81,7 +87,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); - (void) dealloc { nsresult rv; - ICStop (internetConfig); + ICStop (mInternetConfig); nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID, &rv)); if (!NS_FAILED(rv)) pref->SavePrefFile(nsnull); @@ -91,7 +97,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); - (BOOL) initInternetConfig { OSStatus error; - error = ICStart (&internetConfig, 'CHIM'); + error = ICStart (&mInternetConfig, 'CHIM'); if (error != noErr) { // XXX throw here? NSLog(@"Error initializing IC.\n"); @@ -350,7 +356,7 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); NSLog (@"malloc failed in [PreferenceManager getICStringPref]."); return nil; } - error = ICGetPref (internetConfig, prefKey, &dummy, buf, &size); + error = ICGetPref (mInternetConfig, prefKey, &dummy, buf, &size); if (error != noErr && error != icTruncatedErr) { free (buf); NSLog (@"[IC error %d in [PreferenceManager getICStringPref].\n", (int) error); @@ -392,8 +398,23 @@ app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); if (NS_SUCCEEDED(prefs->GetBoolPref("chimera.use_system_home_page", &boolPref)) && boolPref) return [self getICStringPref:kICWWWHomePage]; - NSString* homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil ); - if ([homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) + nsCOMPtr prefBranch = do_QueryInterface(prefs); + if (!prefBranch) return @"about:blank"; + + NSString* homepagePref = nil; + PRInt32 haveUserPref; + if (NS_FAILED(prefBranch->PrefHasUserValue("browser.startup.homepage", &haveUserPref)) || !haveUserPref) { + // no home page pref is set in user prefs. + homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil); + // and let's copy this into the homepage pref if it's not bad + if (![homepagePref isEqualToString:@"HomePageDefault"]) + prefs->SetCharPref("browser.startup.homepage", [homepagePref cString]); + } + else { + homepagePref = [self getMozillaPrefString:"browser.startup.homepage"]; + } + + if (homepagePref && [homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) return homepagePref; }