#include "CyclonePreferences.h" #include "ACFString.h" #include "ACFNumber.h" #include "CFObjDel.h" CyclonePreferences::CyclonePreferences(CFStringRef inPrefsIdentifier) : PlistPreferences(inPrefsIdentifier) { Init(); } CyclonePreferences::~CyclonePreferences() { } void CyclonePreferences::Init() { //attribs for original and translation text views ::memset( &mPrefs, 0, sizeof(CyclonePrefs) ); mPrefs.flags = kRunningForTheFirstTime | kSaveLastEncodings | kAutoChangeLineBreaks | kAskEncForEachFile; mPrefs.inputEncoding = kTextEncodingMacRoman; mPrefs.outputEncoding = kTextEncodingMacRoman; mPrefs.theSignature = kAppSignature; mPrefs.lineBreak = kLineBreakNoChange; } void CyclonePreferences::Read() { Init(); ::CFPreferencesAppSynchronize( mPrefsIdentifier ); CFIndex intValue = 1; GetIntegerValueForKey(CFSTR("VERSION"), intValue); if( GetIntegerValueForKey(CFSTR("INPUT_ENCODING"), intValue) ) {//we must cast signed value into unsigned value without altering it mPrefs.inputEncoding = *(TextEncoding *)&intValue; } if( GetIntegerValueForKey(CFSTR("OUTPUT_ENCODING"), intValue) ) {//we must cast signed value into unsigned value without altering it mPrefs.outputEncoding = *(TextEncoding *)&intValue; } GetIntegerValueForKey(CFSTR("LINE_BREAK"), mPrefs.lineBreak); CFPropertyListRef resultRef = CFPreferencesCopyAppValue(CFSTR("OUTPUT_CREATOR"), mPrefsIdentifier); if(resultRef != NULL) { CFObjDel refDel(resultRef); if( ::CFGetTypeID(resultRef) == ::CFStringGetTypeID() ) { CFStringRef theCreator = (CFStringRef)resultRef; mPrefs.theSignature = CFStringToFourCharCode(theCreator); } } Boolean boolValue; if( GetBoolValueForKey(CFSTR("SAVE_LAST_ENCODING"), boolValue) ) { if(boolValue) mPrefs.flags |= kSaveLastEncodings; else mPrefs.flags &= ~kSaveLastEncodings; } if( GetBoolValueForKey(CFSTR("USE_SNIFFERS"), boolValue) ) { if(boolValue) mPrefs.flags |= kUseSniffers; else mPrefs.flags &= ~kUseSniffers; } if( GetBoolValueForKey(CFSTR("AUTO_CHANGE_LINE_BREAKS"), boolValue) ) { if(boolValue) mPrefs.flags |= kAutoChangeLineBreaks; else mPrefs.flags &= ~kAutoChangeLineBreaks; } if( GetBoolValueForKey(CFSTR("ASK_AT_STARTUP"), boolValue) ) { if(boolValue) mPrefs.flags |= kAskAtStartup; else mPrefs.flags &= ~kAskAtStartup; } if( GetBoolValueForKey(CFSTR("SAVE_DONT_ASK"), boolValue) ) { if(boolValue) mPrefs.flags |= kSaveDontAsk; else mPrefs.flags &= ~kSaveDontAsk; } if( GetBoolValueForKey(CFSTR("USE_CUSTOM_SIGNATURE"), boolValue) ) { if(boolValue) mPrefs.flags |= kUseCustomSignature; else mPrefs.flags &= ~kUseCustomSignature; } if( GetBoolValueForKey(CFSTR("KEEP_PARTIAL_FILES"), boolValue) ) { if(boolValue) mPrefs.flags |= kKeepPartialFiles; else mPrefs.flags &= ~kKeepPartialFiles; } if( GetBoolValueForKey(CFSTR("ASK_ENC_FOR_EACH_FILE"), boolValue) ) { if(boolValue) mPrefs.flags |= kAskEncForEachFile; else mPrefs.flags &= ~kAskEncForEachFile; } if( GetBoolValueForKey(CFSTR("SUPR_MSG_GENERATE_LOG"), boolValue) ) { if(boolValue) mPrefs.flags |= kSuppressMsgGenLog; else mPrefs.flags &= ~kSuppressMsgGenLog; } if( GetBoolValueForKey(CFSTR("RUNNING_FIRST_TIME"), boolValue) ) { if(boolValue) mPrefs.flags |= kRunningForTheFirstTime; else mPrefs.flags &= ~kRunningForTheFirstTime; } if( GetBoolValueForKey(CFSTR("EXPLICIT_LINE_BREAKS"), boolValue) ) { if(boolValue) mPrefs.flags |= kExplicitLineBreakChange; else mPrefs.flags &= ~kExplicitLineBreakChange; } } void CyclonePreferences::Save() { mPrefs.flags &= ~kRunningForTheFirstTime;//already launched at least once if we are here so clear the flag CFIndex theVer = 1; SetIntegerValueForKey(CFSTR("VERSION"), theVer); CFIndex signedInt = *(CFIndex *)&(mPrefs.inputEncoding); SetIntegerValueForKey(CFSTR("INPUT_ENCODING"), signedInt); signedInt = *(CFIndex *)&(mPrefs.outputEncoding); SetIntegerValueForKey(CFSTR("OUTPUT_ENCODING"), signedInt); SetIntegerValueForKey(CFSTR("LINE_BREAK"), mPrefs.lineBreak); ACFString theCreator(mPrefs.theSignature); ::CFPreferencesSetAppValue( CFSTR("OUTPUT_CREATOR"), (CFStringRef)theCreator, mPrefsIdentifier ); SetBoolValueForKey( CFSTR("SAVE_LAST_ENCODING"), ((mPrefs.flags & kSaveLastEncodings) != 0)); SetBoolValueForKey( CFSTR("USE_SNIFFERS"), ((mPrefs.flags & kUseSniffers) != 0) ); SetBoolValueForKey( CFSTR("AUTO_CHANGE_LINE_BREAKS"), ((mPrefs.flags & kAutoChangeLineBreaks) != 0) ); SetBoolValueForKey( CFSTR("ASK_AT_STARTUP"), ((mPrefs.flags & kAskAtStartup) != 0) ); SetBoolValueForKey( CFSTR("SAVE_DONT_ASK"), ((mPrefs.flags & kSaveDontAsk) != 0) ); SetBoolValueForKey( CFSTR("USE_CUSTOM_SIGNATURE"), ((mPrefs.flags & kUseCustomSignature) != 0) ); SetBoolValueForKey( CFSTR("KEEP_PARTIAL_FILES"), ((mPrefs.flags & kKeepPartialFiles) != 0) ); SetBoolValueForKey( CFSTR("ASK_ENC_FOR_EACH_FILE"), ((mPrefs.flags & kAskEncForEachFile) != 0) ); SetBoolValueForKey( CFSTR("SUPR_MSG_GENERATE_LOG"), ((mPrefs.flags & kSuppressMsgGenLog) != 0) ); SetBoolValueForKey( CFSTR("RUNNING_FIRST_TIME"), ((mPrefs.flags & kRunningForTheFirstTime) != 0) ); SetBoolValueForKey( CFSTR("EXPLICIT_LINE_BREAKS"), ((mPrefs.flags & kExplicitLineBreakChange) != 0) ); ::CFPreferencesAppSynchronize( mPrefsIdentifier ); }