/** * Setting default values that must be accessible using [NSUserDefaults standardUserDefaults] * * @param property Initial property name to store default value for. */ private void _init(final String property) { if(null == store.objectForKey(property)) { // Set the default value this.setProperty(property, this.getDefault(property)); } }
@Override public List<String> systemLocales() { // Language ordering in system preferences. Can be overridden // using the "AppleLanguages" user default return this.toList(NSLocale.preferredLanguages()); }
this.setDefault("tmp.dir", FoundationKitFunctionsLibrary.NSTemporaryDirectory()); if(Sandbox.get().isSandboxed()) { this.setDefault("local.user.home", SystemB.INSTANCE.getpwuid(LibC.INSTANCE.getuid()).pw_dir); this.setDefault("application.name", bundle.objectForInfoDictionaryKey("CFBundleName").toString()); this.setDefault("application.copyright", bundle.objectForInfoDictionaryKey("NSHumanReadableCopyright").toString()); this.setDefault("application.identifier", bundle.objectForInfoDictionaryKey("CFBundleIdentifier").toString()); this.setDefault("application.version", bundle.objectForInfoDictionaryKey("CFBundleShortVersionString").toString()); this.setDefault("application.revision", bundle.objectForInfoDictionaryKey("CFBundleVersion").toString()); this.setDefault("application.receipt.path", String.format("%s/Contents/_MASReceipt", bundle.bundlePath())); this.setDefault("update.feed.release", "https://version.cyberduck.io/changelog.rss"); this.setDefault("update.feed.beta", "https://version.cyberduck.io/beta/changelog.rss"); this.setDefault("update.feed.nightly", "https://version.cyberduck.io/nightly/changelog.rss"); if(!StringUtils.startsWith(this.getProperty(Updater.PROPERTY_FEED_URL), Scheme.https.name())) { this.deleteProperty(Updater.PROPERTY_FEED_URL); this.save(); this.setDefault("bookmark.import.filezilla.location", "~/.config/filezilla/sitemanager.xml"); this.setDefault("bookmark.import.fetch.location", "~/Library/Preferences/com.fetchsoftworks.Fetch.Shortcuts.plist"); this.setDefault("bookmark.import.flow.location", "~/Library/Application Support/Flow/Bookmarks.plist"); this.setDefault("bookmark.import.interarchy.location", "~/Library/Application Support/Interarchy/Bookmarks.plist");
/** * Load and convert from native storage into cache */ private String loadProperty(final String property) { final NSObject value = store.objectForKey(property); if(null == value) { final String d = this.getDefault(property); return null == d ? MISSING_PROPERTY : d; } // Customized property found if(value.isKindOfClass(Rococoa.createClass("NSString", NSString._Class.class))) { return value.toString(); } if(value.isKindOfClass(Rococoa.createClass("NSArray", NSArray._Class.class))) { return StringUtils.join(this.toList(Rococoa.cast(value, NSArray.class)), LIST_SEPERATOR); } log.warn(String.format("Unknown type for property %s", property)); return value.toString(); }
@Override public void setProperty(final String property, final String value) { if(log.isInfoEnabled()) { log.info(String.format("Set property %s for key %s", value, property)); } if(StringUtils.isNotEmpty(value)) { // Sets the value of the default identified by defaultName in the standard application domain. // Setting a default has no effect on the value returned by the objectForKey method if // the same key exists in a domain that precedes the application domain in the search list. store.setObjectForKey(NSString.stringWithString(value), property); cache.put(property, value); } else { this.deleteProperty(property); } }
@Override protected void setFactories() { super.setFactories();
@Override public List<String> applicationLocales() { return this.toList(bundle.localizations()); }
@Override public String locale() { final NSObject value = store.objectForKey("AppleLanguages"); if(null == value) { return super.locale(); } if(value.isKindOfClass(Rococoa.createClass("NSArray", NSArray._Class.class))) { final List<String> languages = this.toList(Rococoa.cast(value, NSArray.class)); if(null != languages) { return languages.iterator().next(); } } return super.locale(); }