From f5ef7c71e74722d8f7c00d7c27f1a4486e88a402 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Wed, 26 Jan 2011 19:17:27 +0000 Subject: Setting/Loading more options. Also loading urldb and cookies. svn path=/trunk/netsurf/; revision=11503 --- cocoa/BrowserWindowController.m | 6 ++--- cocoa/NetSurf.xcodeproj/project.pbxproj | 2 ++ cocoa/NetSurfAppDelegate.m | 12 ++------- cocoa/NetsurfApp.m | 43 +++++++++++++++++++++++++++++++++ cocoa/gui.h | 26 ++++++++++++++++++++ cocoa/gui.m | 25 ++++++++++++++++--- 6 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 cocoa/gui.h (limited to 'cocoa') diff --git a/cocoa/BrowserWindowController.m b/cocoa/BrowserWindowController.m index 32cb57e9a..4ed220015 100644 --- a/cocoa/BrowserWindowController.m +++ b/cocoa/BrowserWindowController.m @@ -24,6 +24,7 @@ #import "URLFieldCell.h" #import "desktop/browser.h" +#import "desktop/options.h" @implementation BrowserWindowController @@ -105,12 +106,9 @@ } } -extern NSString * const kHomepageURL; - (IBAction) newTab: (id) sender; { - NSString *homepageURL = [[NSUserDefaults standardUserDefaults] objectForKey: kHomepageURL]; - struct browser_window *clone = [[[tabView selectedTabViewItem] identifier] browser]; - browser_window_create( [homepageURL UTF8String], clone, NULL, false, true ); + browser_window_create( option_homepage_url, [activeBrowser browser], NULL, false, true ); } - (IBAction) closeCurrentTab: (id) sender; diff --git a/cocoa/NetSurf.xcodeproj/project.pbxproj b/cocoa/NetSurf.xcodeproj/project.pbxproj index 26b0c43b3..22188e5a9 100644 --- a/cocoa/NetSurf.xcodeproj/project.pbxproj +++ b/cocoa/NetSurf.xcodeproj/project.pbxproj @@ -322,6 +322,7 @@ 262711BE12DDDD1500B2FA62 /* release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = release.xcconfig; sourceTree = ""; }; 262711C212DDDDC300B2FA62 /* NetSurf.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = NetSurf.xcconfig; sourceTree = ""; }; 262711D412DDDEEE00B2FA62 /* common.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = common.xcconfig; sourceTree = ""; }; + 264C344112F0987E00D11246 /* gui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gui.h; sourceTree = ""; }; 265F30A712D6637E0048B600 /* NetSurf-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "NetSurf-Info.plist"; sourceTree = ""; }; 265F30AB12D6637E0048B600 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = ""; }; 265F311912D663F50048B600 /* gui.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = gui.m; sourceTree = ""; }; @@ -846,6 +847,7 @@ 26CDD26912E7446E004FC66B /* Platform Interface */ = { isa = PBXGroup; children = ( + 264C344112F0987E00D11246 /* gui.h */, 265F311912D663F50048B600 /* gui.m */, 261223CB12D7805300E10F91 /* plotter.h */, 265F314712D666660048B600 /* plotter.m */, diff --git a/cocoa/NetSurfAppDelegate.m b/cocoa/NetSurfAppDelegate.m index 3900ec985..1d9df1ff2 100644 --- a/cocoa/NetSurfAppDelegate.m +++ b/cocoa/NetSurfAppDelegate.m @@ -19,6 +19,7 @@ #import "NetSurfAppDelegate.h" #import "desktop/browser.h" +#import "desktop/options.h" @interface NetSurfAppDelegate () @@ -29,21 +30,12 @@ @implementation NetSurfAppDelegate -NSString * const kHomepageURL = @"HomepageURL"; @synthesize historyWindow; -+ (void) initialize; -{ - [[NSUserDefaults standardUserDefaults] registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys: - @"http://netsurf-browser.org/welcome/", kHomepageURL, - nil]]; -} - - (void) newDocument: (id) sender; { - NSString *homepageURL = [[NSUserDefaults standardUserDefaults] objectForKey: kHomepageURL]; - browser_window_create( [homepageURL UTF8String], NULL, NULL, true, false ); + browser_window_create( option_homepage_url, NULL, NULL, true, false ); } - (void) openDocument: (id) sender; diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index e82856704..245302962 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -18,6 +18,8 @@ #import "NetsurfApp.h" +#import "cocoa/gui.h" + #import "desktop/gui.h" #include "content/urldb.h" #include "content/fetch.h" @@ -36,14 +38,55 @@ #include "utils/log.h" #include "utils/messages.h" #include "utils/utils.h" +#import "css/utils.h" +#ifndef NETSURF_HOMEPAGE +#define NETSURF_HOMEPAGE "http://www.netsurf-browser.org/welcome/" +#endif @implementation NetSurfApp +- (void) loadOptions; +{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [defaults registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys: + cocoa_get_user_path( @"Cookies" ), kCookiesFileOption, + cocoa_get_user_path( @"URLs" ), kURLsFileOption, + cocoa_get_user_path( @"Hotlist" ), kHotlistFileOption, + [NSString stringWithUTF8String: NETSURF_HOMEPAGE], kHomepageURLOption, + nil]]; + + + if (NULL == option_cookie_file) { + option_cookie_file = strdup( [[defaults objectForKey: kCookiesFileOption] UTF8String] ); + } + + if (NULL == option_cookie_jar) { + option_cookie_jar = strdup( option_cookie_file ); + } + + if (NULL == option_homepage_url) { + option_homepage_url = strdup( [[defaults objectForKey: kHomepageURLOption] UTF8String] ); + } + + nscss_screen_dpi = FLTTOFIX( 72.0 * [[NSScreen mainScreen] userSpaceScaleFactor] ); + + urldb_load( [[defaults objectForKey: kURLsFileOption] UTF8String] ); + urldb_load_cookies( option_cookie_file ); +} + +- (void) saveOptions; +{ + urldb_save_cookies( option_cookie_file ); + urldb_save( [[[NSUserDefaults standardUserDefaults] objectForKey: kURLsFileOption] UTF8String] ); +} + - (void) run; { [self finishLaunching]; + [self loadOptions]; netsurf_main_loop(); + [self saveOptions]; } -(void) terminate: (id)sender; diff --git a/cocoa/gui.h b/cocoa/gui.h new file mode 100644 index 000000000..ba72456fa --- /dev/null +++ b/cocoa/gui.h @@ -0,0 +1,26 @@ +/* + * Copyright 2011 Sven Weidauer + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#import + +NSString *cocoa_get_user_path( NSString *fileName ); + +extern NSString * const kCookiesFileOption; +extern NSString * const kURLsFileOption; +extern NSString * const kHotlistFileOption; +extern NSString * const kHomepageURLOption; diff --git a/cocoa/gui.m b/cocoa/gui.m index 57b7cc479..f6c0870e3 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -18,6 +18,8 @@ #import +#import "cocoa/gui.h" + #import "BrowserView.h" #import "BrowserViewController.h" #import "BrowserWindowController.h" @@ -31,13 +33,17 @@ #import "desktop/selection.h" #import "desktop/401login.h" #import "utils/utils.h" - #import "image/ico.h" char *default_stylesheet_url; char *adblock_stylesheet_url; char *quirks_stylesheet_url; +NSString * const kCookiesFileOption = @"CookiesFile"; +NSString * const kURLsFileOption = @"URLsFile"; +NSString * const kHotlistFileOption = @"Hotlist"; +NSString * const kHomepageURLOption = @"HomepageURL"; + #define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ ) void gui_multitask(void) @@ -375,10 +381,21 @@ static NSString *cocoa_get_preferences_path( void ) return netsurfPath; } +NSString *cocoa_get_user_path( NSString *fileName ) +{ + return [cocoa_get_preferences_path() stringByAppendingPathComponent: fileName]; +} + +NSString * const kClassicOptionsFile = @"ClassicOptionsFile"; + static const char *cocoa_get_options_file( void ) { - NSString *prefPath = [cocoa_get_preferences_path() stringByAppendingPathComponent: @"options"]; - return [prefPath UTF8String]; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [defaults registerDefaults: [NSDictionary dictionaryWithObjectsAndKeys: + cocoa_get_user_path( @"Options" ), kClassicOptionsFile, + nil]]; + + return [[defaults objectForKey: kClassicOptionsFile] UTF8String]; } int main( int argc, char **argv ) @@ -404,7 +421,7 @@ int main( int argc, char **argv ) [mainNib instantiateNibWithOwner:NSApp topLevelObjects:nil]; [mainNib release]; - [NSApp performSelectorOnMainThread:@selector(run) withObject:nil waitUntilDone:YES]; + [NSApp run]; netsurf_exit(); -- cgit v1.2.3