Index: trunk/ChameleonPrefPane/Sources/BootPropertyList.cpp =================================================================== --- trunk/ChameleonPrefPane/Sources/BootPropertyList.cpp (revision 50) +++ trunk/ChameleonPrefPane/Sources/BootPropertyList.cpp (revision 51) @@ -1,27 +0,0 @@ -/* - * BootPropertyList.cpp - * ChameleonPrefPane - * - * Created by Rekursor on 1/22/10. - * - */ - -#include "BootPropertyList.h" - -void BootPropertyList::deleteOptionDesc() -{ - // delete all alloc'ed pointers - std::map::iterator bod; - for (bod=_idToDescDict.begin(); bod!=_idToDescDict.end(); bod++) - if(bod->second) delete bod->second; - for (bod=_contentIdToDescDict.begin(); bod!=_contentIdToDescDict.end(); bod++) - if(bod->second) delete bod->second; -} - -void BootPropertyList::clearOptionDesc() -{ - deleteOptionDesc(); - _idToDescDict.clear(); // now clear the pairs - _contentIdToDescDict.clear(); // now clear the pairs -} - Index: trunk/ChameleonPrefPane/Sources/BootPropertyList.h =================================================================== --- trunk/ChameleonPrefPane/Sources/BootPropertyList.h (revision 50) +++ trunk/ChameleonPrefPane/Sources/BootPropertyList.h (revision 51) @@ -1,122 +0,0 @@ -/* - * BootPropertyList.h - * ChameleonPrefPane - * - * Created by Rekursor on 1/22/10. - * - */ -#ifndef __CHBOOT_PROPERTYLIST_LIST_H -#define __CHBOOT_PROPERTYLIST_LIST_H - -#include "PropertyList.h" -#include - -//-------------------------------------------------------------------------- -// Chameleon Boot options type -typedef enum -{ - OptionYesNo=0, // "Yes" or "No" - OptionString, // String Content - OptionUnix, // Unix like command option like -x, -v ... - OptionKernel, // kernel cmd like "mach_kernel" or "blacklist=0" - OptionKernel1 // kernel cmd like "mach_kernel" or "blacklist=0" - -} BootOptionType; - -typedef enum PropertyKind -{ - KindPreferencesFile, - KindBootConfigFile, - KindSmbiosConfigFile -}; - -struct BootOptionDesc; - -typedef bool (*FieldValidator) (BootOptionDesc* bod); - -//-------------------------------------------------------------------------- -// Boot Option descriptor : used by all derived class to permit parameters handling automation ... -struct BootOptionDesc -{ - BootOptionDesc(void* i, void * c, BootOptionType t, const char* n, const char* d, - FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) : - ID(i), contentID(c), Type(t), Name(n), Default(d), - Validator(validator), Kind(kind) - { - - } - void* ID; // the corresponding button or textfield in the interface - void* contentID; // the corresponding content ID (i.e: the string content for text fields) - BootOptionType Type; - const char * Name; - FieldValidator Validator; - PropertyKind Kind; - const char * Default; - -} ; - -//-------------------------------------------------------------------------- - -/** - * Specialization of PropertyList with Chameleon Boot Config, fast id key to desc search features - */ -class BootPropertyList : public PropertyList -{ -public: - BootPropertyList() { } - virtual ~BootPropertyList() { deleteOptionDesc(); } - - // id to map BootOptionDesc handling - void addOptionDesc(void * ID, void* cID, BootOptionType t, const char * szName, const char* szDefault, - FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) - - { - if (ID) _idToDescDict[ID] = - new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : ""); - if (cID) _contentIdToDescDict[cID] = - new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : ""); - } - - // find the desc corresponding to id: - const BootOptionDesc* findOption(void *ID) const - { - std::map::const_iterator bod; - if (!ID || (bod=_idToDescDict.find(ID))==_idToDescDict.end()) return NULL; - return bod->second; - } - - // find the option bod corresponding to contentID - const BootOptionDesc* findOptionContent(void *cID) const - { - std::map::const_iterator bod; - if (!cID || (bod=_contentIdToDescDict.find(cID))==_contentIdToDescDict.end()) return NULL; - return bod->second; - } - - // opaque enumeration for the map - const BootOptionDesc* firstOption() - { - _bod=_idToDescDict.begin(); - if (_bod!= _idToDescDict.end()) return _bod->second; else return NULL; - } - - const BootOptionDesc* nextOption() - { - if(_bod++ ==_idToDescDict.end()) return NULL; - if (_bod != _idToDescDict.end()) return _bod->second; else return NULL; - } - - - // remove all elements in dict, calls deleteOptionsDesc() - void clearOptionDesc(); - -protected: - void deleteOptionDesc(); - -private: - // dictionary for id -> desc and contentID -> desc association type - std::map _idToDescDict, _contentIdToDescDict; - std::map::const_iterator _bod; -}; - -#endif \ No newline at end of file Index: trunk/ChameleonPrefPane/Sources/AdvancedSetupController.h =================================================================== --- trunk/ChameleonPrefPane/Sources/AdvancedSetupController.h (revision 50) +++ trunk/ChameleonPrefPane/Sources/AdvancedSetupController.h (revision 51) @@ -11,7 +11,7 @@ // TabView subpane controller definition -@interface AdvancedSetupController : PreferencesControllerBase +@interface AdvancedSetupController : PreferencesControllerBase { IBOutlet NSButton* mKernel; IBOutlet NSTextField* mKernelText; @@ -49,6 +49,7 @@ - (IBAction) onCheckButtonChange: (NSButton*) sender; - (IBAction) onTextFiedChange: (NSTextField*) sender; +- (void) setDefaultsValues: (NSMutableDictionary*) dict; + (AdvancedSetupController *)instance; Index: trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.h =================================================================== --- trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.h (revision 0) +++ trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.h (revision 51) @@ -0,0 +1,175 @@ +/* + * ChameleonPropertyList.h + * ChameleonPrefPane + * + * Created by Rekursor on 1/22/10. + * + */ +#ifndef __CHBOOT_PROPERTYLIST_LIST_H +#define __CHBOOT_PROPERTYLIST_LIST_H + +#include "PropertyList.h" +#include + +//-------------------------------------------------------------------------- +// Chameleon Boot options type +//-------------------------------------------------------------------------- +typedef enum +{ + OptionYesNo=0, // "Yes" or "No" + OptionString, // String Content + OptionUnix, // Unix like command option like -x, -v ... + OptionKernel, // kernel cmd like "mach_kernel" or "blacklist=0" + OptionKernel1 // kernel cmd like "mach_kernel" or "blacklist=0" + +} BootOptionType; + +typedef enum PropertyKind +{ + KindPreferencesFile, + KindBootConfigFile, + KindSmbiosConfigFile +}; + +struct BootOptionDesc; + +typedef bool (*FieldValidator) (BootOptionDesc* bod); + +//-------------------------------------------------------------------------- +// Boot Option descriptor : +// used by all derived class to permit parameters handling automation ... +//-------------------------------------------------------------------------- +struct BootOptionDesc +{ + BootOptionDesc(void* i, void * c, BootOptionType t, const char* n, const char* d, + FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) : + ID(i), contentID(c), Type(t), Name(n), Default(d), + Validator(validator), Kind(kind) + { + + } + void* ID; // the corresponding button or textfield in the interface + void* contentID; // the corresponding content ID (i.e: the string content for text fields) + BootOptionType Type; + const char * Name; + FieldValidator Validator; + PropertyKind Kind; + const char * Default; + +} ; + +//-------------------------------------------------------------------------- + +/** + * Specialization of PropertyList with Chameleon Boot Config, fast id key to desc search features + */ +class ChameleonPropertyList : public PropertyList +{ +protected: + ChameleonPropertyList() { } +public: + virtual ~ChameleonPropertyList() { deleteOptionDesc(); } + + // id to map BootOptionDesc handling + void addOptionDesc(void * ID, void* cID, BootOptionType t, const char * szName, const char* szDefault, + FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) + + { + if (ID) _idToDescDict[ID] = + new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : ""); + if (cID) _contentIdToDescDict[cID] = + new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : ""); + } + + // find the desc corresponding to id: + const BootOptionDesc* findOption(void *ID) const + { + std::map::const_iterator bod; + if (!ID || (bod=_idToDescDict.find(ID))==_idToDescDict.end()) return NULL; + return bod->second; + } + + // find the option bod corresponding to contentID + const BootOptionDesc* findOptionContent(void *cID) const + { + std::map::const_iterator bod; + if (!cID || (bod=_contentIdToDescDict.find(cID))==_contentIdToDescDict.end()) return NULL; + return bod->second; + } + + // opaque enumeration for the map + const BootOptionDesc* firstOption() + { + _bod=_idToDescDict.begin(); + if (_bod!= _idToDescDict.end()) return _bod->second; else return NULL; + } + + const BootOptionDesc* nextOption() + { + if(_bod++ ==_idToDescDict.end()) return NULL; + if (_bod != _idToDescDict.end()) return _bod->second; else return NULL; + } + + + // remove all elements in dict, calls deleteOptionsDesc() + void clearOptionDesc(); + +protected: + void deleteOptionDesc(); + + // dictionary for id -> desc and contentID -> desc association type + std::map _idToDescDict, _contentIdToDescDict; + std::map::const_iterator _bod; +}; + +//-------------------------------------------------------------------------- +// Concrete definition of Chameleon property lists +// implements the Singleton DP +//-------------------------------------------------------------------------- + +class BootProp : public ChameleonPropertyList { +public: + static BootProp& instance() + { + return _instance ? *_instance : *(_instance=new BootProp()); + } + +protected: + BootProp() : ChameleonPropertyList() {} + +private: + static BootProp* _instance; +}; + +//-------------------------------------------------------------------------- +class PrefsProp : public ChameleonPropertyList { +public: + static PrefsProp& instance() + { + return _instance ? *_instance : *(_instance=new PrefsProp()); + } + +protected: + PrefsProp() : ChameleonPropertyList() {} + +private: + static PrefsProp* _instance; +}; + +//-------------------------------------------------------------------------- +class SmbiosProp : public ChameleonPropertyList { +public: + static SmbiosProp& instance() + { + return _instance ? *_instance : *(_instance=new SmbiosProp()); + } + +protected: + SmbiosProp() : ChameleonPropertyList() {} + +private: + static SmbiosProp* _instance; +}; + + +#endif \ No newline at end of file Index: trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.mm =================================================================== --- trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.mm (revision 50) +++ trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.mm (revision 51) @@ -11,7 +11,7 @@ #import "AdvancedSetupController.h" #include "ShellProcess.h" -#import "BootPropertyList.h" +#import "ChameleonPropertyList.h" #include //-------------------------------------------------------------------------- @@ -37,7 +37,7 @@ static std::string sCurrentDefaultPartition; PartitionExtractor * partExtractor=NULL; -BootPropertyList * prop = NULL; + static int currentRowSel = -1; static ChameleonPrefPane *gInstance = NULL; @@ -61,10 +61,7 @@ mUnknownImage = [self getImageResource: @"Chameleon" ofType: @"tiff"]; - // create the propertylist object that will handle com.apple.Boot.plist - if(!prop) prop = new BootPropertyList(); - - // create the process that will extract the diskutil list infos + // create the process that will extract the diskutil list infos if(!partExtractor) partExtractor = new PartitionExtractor(); // Retrieve the com.chameleon.prefPane.plist config @@ -91,48 +88,10 @@ } //-------------------------------------------------------------------------- -- (void) loadPreferences +// SFAuthorization implementaion +//-------------------------------------------------------------------------- -{ - id oldGlobalPreferences = [ [NSDictionary dictionaryWithContentsOfFile: - kPreferencesFilePath ] retain]; - - mPartitionsDict = [[NSMutableDictionary alloc] init]; - [mPartitionsDict retain]; - - // Initialize bootConfig desc dict - [PreferencesControllerBase doForEachGroup: AddOptionsDesc withOption: nil]; - - if (oldGlobalPreferences!=nil) - { - mPreferenceFileVersion= [[oldGlobalPreferences objectForKey: keyPreferencesFileVersion] intValue ]; - [PreferencesControllerBase setDefaultValues: oldGlobalPreferences]; - [mPartitionsDict addEntriesFromDictionary: [oldGlobalPreferences objectForKey: keyPartitionsList] ]; - } - else - { // Create a preference plist file with Defaults values - oldGlobalPreferences = [[NSMutableDictionary alloc] init]; - [PreferencesControllerBase doForEachGroup: LoadPreferencesOptions withOption: oldGlobalPreferences]; - - // Initialize defaults - [oldGlobalPreferences setObject: [[NSNumber alloc] initWithInt: CurrentPreferencesFileVersion] - forKey: keyPreferencesFileVersion]; - [oldGlobalPreferences setObject: mPartitionsDict forKey: keyPartitionsList]; - - // Save the preferences file - [ self savePreferences:oldGlobalPreferences ]; - } - - mOptionsDict = [[NSMutableDictionary alloc] init]; - [mOptionsDict addEntriesFromDictionary:oldGlobalPreferences]; - if (mPartitionsDict!=nil) [mPartitionsDict retain]; - [oldGlobalPreferences release]; - } - -//-------------------------------------------------------------------------- -/** - * SFAuthorization delegates - */ +// SFAuthorization delegates - (void)authorizationViewDidAuthorize:(SFAuthorizationView *)view { [self selectDefaultPartition]; [self refreshLockStates]; @@ -145,6 +104,24 @@ } //-------------------------------------------------------------------------- +// Setup security for changing boot options +-(void) initAuthorization +{ + AuthorizationItem items = {kAuthorizationRightExecute, 0, NULL, 0}; + AuthorizationRights rights = {1, &items}; + + [authView setAuthorizationRights:&rights]; + authView.delegate = self; + [authView updateStatus:nil]; +} +//-------------------------------------------------------------------------- +- ( AuthorizationRef) auth +{ + return [self isUnlocked] ? [[authView authorization] authorizationRef] : NULL; + +} + +//-------------------------------------------------------------------------- - (void) refreshLockStates { [mPartitionsTable setEnabled:[self isUnlocked]]; @@ -187,22 +164,56 @@ } //-------------------------------------------------------------------------- +- (void) loadPreferences +{ +// PrefsProp::instance().open([kPreferencesFilePath UTF8String], CreateIfNotExist, +// [self auth]); + + id oldGlobalPreferences = [ [NSDictionary dictionaryWithContentsOfFile: + kPreferencesFilePath ] retain]; + + mPartitionsDict = [[NSMutableDictionary alloc] init]; + [mPartitionsDict retain]; + + // Initialize bootConfig desc dict + [PreferencesControllerBase doForEachGroup: AddOptionsDesc withOption: nil]; + + if (oldGlobalPreferences!=nil) + { + mPreferenceFileVersion= [[oldGlobalPreferences objectForKey: keyPreferencesFileVersion] intValue ]; + [PreferencesControllerBase doForEachGroup: LoadPreferencesOptions withOption: oldGlobalPreferences]; + [mPartitionsDict addEntriesFromDictionary: [oldGlobalPreferences objectForKey: keyPartitionsList] ]; + } + else + { // Create a preference plist file with Defaults values + oldGlobalPreferences = [[NSMutableDictionary alloc] init]; + [PreferencesControllerBase loadAllValues: oldGlobalPreferences]; + + // Initialize defaults + [oldGlobalPreferences setObject: [[NSNumber alloc] initWithInt: CurrentPreferencesFileVersion] + forKey: keyPreferencesFileVersion]; + [oldGlobalPreferences setObject: mPartitionsDict forKey: keyPartitionsList]; + + // Save the preferences file + [ self savePreferences:oldGlobalPreferences ]; + } + + mOptionsDict = [[NSMutableDictionary alloc] init]; + [mOptionsDict addEntriesFromDictionary:oldGlobalPreferences]; + if (mPartitionsDict!=nil) [mPartitionsDict retain]; + [oldGlobalPreferences release]; +} + +//-------------------------------------------------------------------------- - (void) initBootConfig { static bool ft=true; - // Setup security for changing boot options - AuthorizationItem items = {kAuthorizationRightExecute, 0, NULL, 0}; - AuthorizationRights rights = {1, &items}; - - [authView setAuthorizationRights:&rights]; - authView.delegate = self; - [authView updateStatus:nil]; - - if (!prop->isValid()) + [self initAuthorization]; + + if (!BootProp::instance().isValid()) { std::string sPath; - AuthorizationRef auth = [self isUnlocked] ? [[authView authorization] authorizationRef] : NULL; CFStringRef errorString=NULL; bool cont =true; @@ -210,14 +221,14 @@ const char * szForcedPath = sForcedPath!=nil ? [sForcedPath UTF8String] : NULL; if (szForcedPath && *szForcedPath) { - cont = !prop->open(szForcedPath, &errorString, auth); + cont = !BootProp::instance().open(szForcedPath, [self auth]); } else { for(int i=0; szBootPaths[i] && cont; i++) { sPath = szBootPaths[i]; sPath += szPropFileName; - cont = !prop->open(sPath.c_str(), &errorString, auth); + cont = !BootProp::instance().open(sPath.c_str(), [self auth]); } } if (cont) @@ -235,16 +246,19 @@ else { [mStatusText setTextColor: [NSColor grayColor] ]; - NSString* ns = [ [NSString alloc] initWithUTF8String:prop->propFilePath() ]; + NSString* ns = [ [NSString alloc] initWithUTF8String:BootProp::instance().propFilePath() ]; [mStatusText setStringValue: [NSString stringWithFormat: @"bootConfig: %@", ns] ]; + [[BootSetupController instance]->mBootConfigPathText setStringValue: + [[NSString alloc] initWithUTF8String: BootProp::instance().propFilePath()] ]; + } - if (prop->isValid()) + if (BootProp::instance().isValid()) { // read options in the plist file - partExtractor->hidePartitions(prop->getStringForKey(kHidePartition)); - partExtractor->renamedPartitions(prop->getStringForKey(kRenamePartition)); + partExtractor->hidePartitions(BootProp::instance().getStringForKey(kHidePartition)); + partExtractor->renamedPartitions(BootProp::instance().getStringForKey(kRenamePartition)); // partExtractor->resetSwapping(); id val = [mOptionsDict valueForKey: keySwapHD01]; @@ -257,8 +271,8 @@ // Load all boot Options into the interface components [PreferencesControllerBase loadOptionsFromBootFile]; - [self selectDefaultPartition]; + } } @@ -271,9 +285,9 @@ [self refreshLockStates]; // try to get the current default partition if any - if(partExtractor && prop && prop->isValid()) + if(partExtractor && BootProp::instance().isValid()) { - const char *sdp = prop->getStringForKey(kDefaultPartition); + const char *sdp = BootProp::instance().getStringForKey(kDefaultPartition); sCurrentDefaultPartition = sdp ? sdp : ""; if (sCurrentDefaultPartition.size()) { @@ -335,13 +349,13 @@ hd[3]= ('0'+partInfo[currentRowSel].disk()); hd[5]= ('0'+partInfo[currentRowSel].partition()); AuthorizationRef auth= [self isUnlocked] ? [[authView authorization] authorizationRef] : NULL; - if(prop->setStringForKey(kDefaultPartition, hd)) - prop->save(auth); + if(BootProp::instance().setStringForKey(kDefaultPartition, hd)) + BootProp::instance().save(auth); [ PreferencesControllerBase loadOptionsFromBootFile]; } else { // no line selected - prop->removeKeyAndValue(kDefaultPartition); + BootProp::instance().removeKeyAndValue(kDefaultPartition); [ PreferencesControllerBase loadOptionsFromBootFile]; } Index: trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.h =================================================================== --- trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.h (revision 50) +++ trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.h (revision 51) @@ -6,10 +6,11 @@ // #import -#import +#import "ChameleonPrefPane.h" +#import "ChameleonPropertyList.h" +#import "ShellProcess.h" #import "string_util.h" -#import "BootPropertyList.h" -#import +#import "GroupControllerProtocol.h" //-------------------------------------------------------------------------- @@ -31,38 +32,14 @@ // ENHANCE ME: remove this globals and integrate them in ChameleonPrefPane or at least // add function accessor entry points extern PartitionExtractor * partExtractor; -extern BootPropertyList * prop; -// Defintion of the required protocol for any derived classes of PreferencesControllerBase -@protocol PreferenceController - -@required - // must be implemented in all derived classes - -// Called by all buttons of each group in therface -- (IBAction) onCheckButtonChange: (NSButton*) sender; - -// Called by all text fields of each group in therface -- (IBAction) onTextFiedChange: (NSTextField*) sender; - -// Add the boot config options descriptors to the consolidated dictionary -- (void) addOptionsDesc; - -// Set refresh all group states {enabled | disabled} depending on the authorizations state -- (void) refreshLockStates; - -// load the corresponding pref filer options from the interface -- (void) loadOptionsFromPreferencesFile: (NSMutableDictionary*) dict; - -@end - // Define common expected behavior for all derived controllers @interface PreferencesControllerBase : NSObject { } -// from the id to desc map in prop, set all default values for dict -+ (void) setDefaultValues: (NSMutableDictionary*) dict; +// from the id to desc map in BootProp::instance(), load all default values for dict ++ (void) loadAllValues: (NSMutableDictionary*) dict; // Register the Group panel for further automatic iteration matters + (void) registerPreferencesGroup:(id) myGroup; Index: trunk/ChameleonPrefPane/Sources/PeripheralsController.mm =================================================================== --- trunk/ChameleonPrefPane/Sources/PeripheralsController.mm (revision 50) +++ trunk/ChameleonPrefPane/Sources/PeripheralsController.mm (revision 51) @@ -21,19 +21,24 @@ //-------------------------------------------------------------------------- - (void) addOptionsDesc { - prop->addOptionDesc(mLegacyLogo, nil, OptionYesNo, "Legacy Logo", "No"); - prop->addOptionDesc(mBootBanner, nil, OptionYesNo, "Boot Banner", "Yes"); - prop->addOptionDesc(mVBIOS, nil, OptionYesNo, "VBIOS", "No"); - prop->addOptionDesc(mVideoROM, mVideoROMText, OptionString, "VideoROM", ""); - prop->addOptionDesc(mGraphicsMode, mGraphicsModeText, OptionString, "Graphics Mode", ""); - prop->addOptionDesc(mGraphicsEnabler, nil, OptionYesNo, "GraphicsEnabler", "No"); - prop->addOptionDesc(mUSBBusFix, nil, OptionYesNo, "USBBusFix", "No"); - prop->addOptionDesc(mEHCIacquire, nil, OptionYesNo, "EHCIacquire", "No"); - prop->addOptionDesc(mUHCIreset, nil,OptionYesNo, "UHCIreset", "No"); - prop->addOptionDesc(mEthernetBuiltIn, nil, OptionYesNo, "EthernetBuiltIn", "No"); + BootProp::instance().addOptionDesc(mLegacyLogo, nil, OptionYesNo, "Legacy Logo", "No"); + BootProp::instance().addOptionDesc(mBootBanner, nil, OptionYesNo, "Boot Banner", "Yes"); + BootProp::instance().addOptionDesc(mVBIOS, nil, OptionYesNo, "VBIOS", "No"); + BootProp::instance().addOptionDesc(mVideoROM, mVideoROMText, OptionString, "VideoROM", ""); + BootProp::instance().addOptionDesc(mGraphicsMode, mGraphicsModeText, OptionString, "Graphics Mode", ""); + BootProp::instance().addOptionDesc(mGraphicsEnabler, nil, OptionYesNo, "GraphicsEnabler", "No"); + BootProp::instance().addOptionDesc(mUSBBusFix, nil, OptionYesNo, "USBBusFix", "No"); + BootProp::instance().addOptionDesc(mEHCIacquire, nil, OptionYesNo, "EHCIacquire", "No"); + BootProp::instance().addOptionDesc(mUHCIreset, nil,OptionYesNo, "UHCIreset", "No"); + BootProp::instance().addOptionDesc(mEthernetBuiltIn, nil, OptionYesNo, "EthernetBuiltIn", "No"); } //-------------------------------------------------------------------------- +-(void) setDefaultsValues: (NSMutableDictionary*) dict +{ +} + +//-------------------------------------------------------------------------- - (void) refreshLockStates { // automatic, nothing to do Index: trunk/ChameleonPrefPane/Sources/ShellProcess.h =================================================================== --- trunk/ChameleonPrefPane/Sources/ShellProcess.h (revision 50) +++ trunk/ChameleonPrefPane/Sources/ShellProcess.h (revision 51) @@ -14,25 +14,11 @@ #include #include #include - +#include "file_util.h" //---------------------------------------------------------------- const int MAX_HD = 10; //---------------------------------------------------------------- - -/** - * Check whether file exists: - */ -inline bool fileExists(const char * str) -{ - struct stat stFileInfo; - if((stat(str,&stFileInfo)) == 0) return true; - else return false; -} - -inline bool fileExists(std::string str) {return fileExists(str.c_str());} - -//---------------------------------------------------------------- class ShellProcess { public: Index: trunk/ChameleonPrefPane/Sources/BootFlagsController.mm =================================================================== --- trunk/ChameleonPrefPane/Sources/BootFlagsController.mm (revision 50) +++ trunk/ChameleonPrefPane/Sources/BootFlagsController.mm (revision 51) @@ -25,20 +25,24 @@ //-------------------------------------------------------------------------- -(void) addOptionsDesc { - prop->addOptionDesc(mVerbose, nil, OptionUnix, "-v", ""); - prop->addOptionDesc(mSafeBoot, nil, OptionUnix, "-x", ""); - prop->addOptionDesc(mIgnoreBootConfig, nil, OptionUnix, "-F", ""); - prop->addOptionDesc(mSingleUser, nil, OptionUnix, "-s", ""); - prop->addOptionDesc(mTimeOut, mTimeOutText, OptionString,"Timeout", "5"); - prop->addOptionDesc(mQuietBoot, nil, OptionYesNo, "Quiet Boot", "No"); - prop->addOptionDesc(mInstantMenu, nil, OptionYesNo, "Instant Menu", "No"); - prop->addOptionDesc(mWait, nil, OptionYesNo, "Wait", "No"); - prop->addOptionDesc(mRescan, nil, OptionYesNo, "Rescan", "No"); - prop->addOptionDesc(mRescanPrompt, nil, OptionYesNo, "Rescan Prompt", "No"); - prop->addOptionDesc(mRescanSingleDrive, nil, OptionYesNo, "Rescan SingleDrive", "No"); + BootProp::instance().addOptionDesc(mVerbose, nil, OptionUnix, "-v", ""); + BootProp::instance().addOptionDesc(mSafeBoot, nil, OptionUnix, "-x", ""); + BootProp::instance().addOptionDesc(mIgnoreBootConfig, nil, OptionUnix, "-F", ""); + BootProp::instance().addOptionDesc(mSingleUser, nil, OptionUnix, "-s", ""); + BootProp::instance().addOptionDesc(mTimeOut, mTimeOutText, OptionString,"Timeout", "5"); + BootProp::instance().addOptionDesc(mQuietBoot, nil, OptionYesNo, "Quiet Boot", "No"); + BootProp::instance().addOptionDesc(mInstantMenu, nil, OptionYesNo, "Instant Menu", "No"); + BootProp::instance().addOptionDesc(mWait, nil, OptionYesNo, "Wait", "No"); + BootProp::instance().addOptionDesc(mRescan, nil, OptionYesNo, "Rescan", "No"); + BootProp::instance().addOptionDesc(mRescanPrompt, nil, OptionYesNo, "Rescan Prompt", "No"); + BootProp::instance().addOptionDesc(mRescanSingleDrive, nil, OptionYesNo, "Rescan SingleDrive", "No"); } //-------------------------------------------------------------------------- +-(void) setDefaultsValues: (NSMutableDictionary*) dict +{ +} +//-------------------------------------------------------------------------- - (void) refreshLockStates { // automatic, nothing to do Index: trunk/ChameleonPrefPane/Sources/BootSetupController.mm =================================================================== --- trunk/ChameleonPrefPane/Sources/BootSetupController.mm (revision 50) +++ trunk/ChameleonPrefPane/Sources/BootSetupController.mm (revision 51) @@ -25,9 +25,9 @@ //-------------------------------------------------------------------------- - (void) addOptionsDesc { - prop->addOptionDesc(mDefaultPartition, mDefaultPartitionText, OptionString, "Default Partition", ""); - prop->addOptionDesc(mHidePartition , mHidePartitionText, OptionString, "Hide Partition", ""); - prop->addOptionDesc(mRenamePartition , mRenamePartitionText, OptionString, "Rename Partition", ""); + BootProp::instance().addOptionDesc(mDefaultPartition, mDefaultPartitionText, OptionString, "Default Partition", ""); + BootProp::instance().addOptionDesc(mHidePartition , mHidePartitionText, OptionString, "Hide Partition", ""); + BootProp::instance().addOptionDesc(mRenamePartition , mRenamePartitionText, OptionString, "Rename Partition", ""); } //-------------------------------------------------------------------------- @@ -38,22 +38,28 @@ [PreferencesControllerBase refreshLockState: mSwapHD02 ]; [PreferencesControllerBase refreshLockState: mFreezeParts ]; [PreferencesControllerBase refreshLockState: mInjectFrozenParts ]; + [PreferencesControllerBase refreshLockState: mBootConfigPath ]; } //-------------------------------------------------------------------------- --(void) setDefaultsValues: (NSMutableDictionary*) dict +- (void) setDefaultsValues: (NSMutableDictionary*) dict { - [mSwapHD01 setIntValue: [[dict objectForKey: keySwapHD01] intValue]]; - [mSwapHD02 setIntValue: [[dict objectForKey: keySwapHD02] intValue]]; - [mFreezeParts setIntValue: [[dict objectForKey: keyUseFrozenParts] intValue] ]; + [dict setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD01]; + [dict setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD02]; + [dict setObject:[[NSNumber alloc] initWithBool: false] forKey: keyUseFrozenParts]; } //-------------------------------------------------------------------------- -(void) loadOptionsFromPreferencesFile: (NSMutableDictionary*) dict { - [dict setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD01]; - [dict setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD02]; - [dict setObject:[[NSNumber alloc] initWithBool: false] forKey: keyUseFrozenParts]; + [mSwapHD01 setIntValue: [[dict objectForKey: keySwapHD01] intValue]]; + [mSwapHD02 setIntValue: [[dict objectForKey: keySwapHD02] intValue]]; + [mFreezeParts setIntValue: [[dict objectForKey: keyUseFrozenParts] intValue] ]; + id obj = [dict objectForKey: keyForceBootConfigPath]; + [mBootConfigPathText setStringValue: obj ]; + int val = ([[mBootConfigPathText stringValue] length] >0 ? 1 : 0); + [mBootConfigPath setIntValue: val]; + } //-------------------------------------------------------------------------- @@ -106,7 +112,7 @@ //-------------------------------------------------------------------------- - (void) swapDisks: (bool) bSwap src: (int) iSrc dst: (int) iDst; { - if(!partExtractor || !prop || !prop->isValid()) return; + if(!partExtractor || !BootProp::instance().isValid()) return; if (bSwap) { partExtractor->swapHD(iSrc, iDst); @@ -205,19 +211,16 @@ if (sender == mBootConfigPath) { int val = [mBootConfigPath intValue]; - std::string content = [[mBootConfigPathText stringValue] UTF8String]; [mBootConfigPathText setEnabled: val ? true : false]; [mBootConfigPathText setEditable: val ? true : false]; - if (val) - { - - - } + [[self preferencesFile] setObject: + val ? [mBootConfigPathText stringValue] : [[NSString alloc] initWithUTF8String: ""] + forKey: keyForceBootConfigPath]; + } else - { // TextField - - } + [[self preferencesFile] setObject: [mBootConfigPathText stringValue] forKey: keyForceBootConfigPath]; + [self savePreferences ]; [PreferencesControllerBase loadOptionsFromBootFile ]; @@ -249,7 +252,6 @@ || sender == mRenamePartition ) { // sync with other panels [self handleSender:sender]; - [PreferencesControllerBase loadOptionsFromBootFile ]; } else if (sender == mBootConfigPath || (NSTextField*)sender == mBootConfigPathText) { // sync with other panels @@ -266,7 +268,14 @@ sender == mRenamePartitionText ) { [self handleSender:sender]; + [PreferencesControllerBase loadOptionsFromBootFile ]; + partExtractor->extractPartitions( + [[mHidePartitionText stringValue] UTF8String], + [[mRenamePartitionText stringValue] UTF8String] + ); + [self doSwapHD: [mSwapHD01 intValue] save:true src:0 dst:1]; + [self doSwapHD: [mSwapHD02 intValue] save:true src:0 dst:2]; } } Index: trunk/ChameleonPrefPane/Sources/PropertyList.cpp =================================================================== --- trunk/ChameleonPrefPane/Sources/PropertyList.cpp (revision 50) +++ trunk/ChameleonPrefPane/Sources/PropertyList.cpp (revision 51) @@ -5,14 +5,15 @@ * */ -#import "BootPropertyList.h" +#import "ChameleonPropertyList.h" +#include "file_util.h" #include #include -/****************************************************************************/ -/** - * Simple parsing and splitting args function, does handle env. vars - */ + +//-------------------------------------------------------------------------- +// Simple parsing and splitting args function, does handle env. vars +//-------------------------------------------------------------------------- static void parseArgs(const char * args, const char* argv[], int argvlen) { // Create a list of args fron the space delimited args parameters @@ -98,7 +99,9 @@ argv[n]=NULL; } -/****************************************************************************/ +//-------------------------------------------------------------------------- +// Execute a priviledge shell command +//-------------------------------------------------------------------------- bool executePrivilegedCmd(AuthorizationRef auth, const char* pathToTool, const char* args, @@ -118,11 +121,29 @@ return status ? false : true; } +//-------------------------------------------------------------------------- +// Execute priviledged chmod for accessing system files +//-------------------------------------------------------------------------- +bool PropertyList::chmodFile(const char * path, const char * chmodMask, + AuthorizationRef auth, AuthorizationFlags flags) +{ + if (!path || !*path) return false; + + if (auth) + { // give write temporary write rights to the file + std::string args = chmodMask; + args += ' '; + args += path; + if(!executePrivilegedCmd(auth, "/bin/chmod", args.c_str(), flags)) + return false; + } + return true; + +} -/****************************************************************************/ -/** - * Write a property list from a file - */ +//-------------------------------------------------------------------------- +// Write a property list from a file +//-------------------------------------------------------------------------- bool WritePropertyListToFile( CFPropertyListRef propertyList, CFURLRef fileURL ) { CFDataRef xmlData; @@ -143,16 +164,30 @@ return status ? true: false; } -/****************************************************************************/ -/** - * Read a property list from a file - */ -static CFPropertyListRef CreatePropertyListFromFile( CFURLRef fileURL, CFStringRef * errorString ) { +//-------------------------------------------------------------------------- +// Read a property list from a file +//-------------------------------------------------------------------------- +static CFPropertyListRef CreatePropertyListFromFile( CFURLRef fileURL, + const std::string& filePath, + CFStringRef * errorString, + bool createIfNotExist) { CFPropertyListRef propertyList; CFDataRef resourceData; Boolean status; SInt32 errorCode; - + // + if (!fileExists(filePath)) + { + if (createIfNotExist) + { + CFMutableDictionaryRef dict = + CFDictionaryCreateMutable( kCFAllocatorDefault, 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks ); + WritePropertyListToFile(dict, fileURL); + } + + } // Read the XML file. status = CFURLCreateDataAndPropertiesFromResource( kCFAllocatorDefault, @@ -174,10 +209,10 @@ return propertyList; } -/****************************************************************************/ -/* - * Always return a valid static const string, if the CFSTR is not valid, then we return "" - */ +//-------------------------------------------------------------------------- +// Always return a valid static const string, +// if the CFSTR is not valid, then we return "" +//-------------------------------------------------------------------------- static const char * CfsToCs(CFStringRef inRef) { static char buffer[512]=""; @@ -186,38 +221,20 @@ return ""; } -/****************************************************************************/ -/** - * Creates a PropertyList Incstance - */ +//-------------------------------------------------------------------------- +// Destruct a PropertyList Instance +//-------------------------------------------------------------------------- PropertyList::~PropertyList() { if (_CFURLRef) CFRelease(_CFURLRef); if (_proplistRef) CFRelease(_proplistRef); } -bool PropertyList::chmodFile(const char * path, const char * chmodMask, - AuthorizationRef auth, AuthorizationFlags flags) -{ - if (!path || !*path) return false; - - if (auth) - { // give write temporary write rights to the file - std::string args = chmodMask; - args += ' '; - args += path; - if(!executePrivilegedCmd(auth, "/bin/chmod", args.c_str(), flags)) - return false; - } - return true; - -} -/****************************************************************************/ -/** - * Open a properlist from a path name - */ -bool PropertyList::open(const char * path, CFStringRef * errorString, AuthorizationRef auth, AuthorizationFlags flags) +//-------------------------------------------------------------------------- +// Open a property list from a path name with auth +//-------------------------------------------------------------------------- +bool PropertyList::open(const char * path, bool createIfNotExist, AuthorizationRef auth, AuthorizationFlags flags) { bool ret = false; @@ -225,9 +242,6 @@ struct stat st; if(stat(path,&st) != 0) return false; // file does not exist; - // give write temporary write rights to the file - if (!chmodFile(path,"0777", auth, flags)) return false; - _propFilePath = path; CFStringRef cfPath = CFStringCreateWithCString (kCFAllocatorDefault, path, kCFStringEncodingUTF8); @@ -242,23 +256,27 @@ if (_CFURLRef) { CFRetain(_CFURLRef); - _proplistRef = CreatePropertyListFromFile(inURL, errorString); + + // give write temporary write rights to the file + if (!chmodFile(path,"0777", auth, flags)) return false; + _proplistRef = CreatePropertyListFromFile(inURL, _propFilePath, &_errorString, createIfNotExist); + + // restore rights + ret= chmodFile(path,"0644", auth, flags); + if (_proplistRef) { CFRetain(_proplistRef); ret= true; } } - // restore rights - ret= chmodFile(path,"0644", auth, flags); return ret; } -/****************************************************************************/ -/** - * Save the current property list - */ +//-------------------------------------------------------------------------- +// Save the current property list +//-------------------------------------------------------------------------- bool PropertyList::save(AuthorizationRef auth, AuthorizationFlags flags) { bool ret=false; @@ -279,11 +297,10 @@ return ret; } -/****************************************************************************/ -/** - * Extract a sring value from a property list key, - * value returned is not owned by caller, copy it necessary. - */ +//-------------------------------------------------------------------------- +// Get a string value from a property list key, +// value returned is not owned by caller, copy it necessary. +//-------------------------------------------------------------------------- const char * PropertyList::getStringForKey(const char *key) { if (!_proplistRef) return NULL; @@ -300,11 +317,11 @@ if(cfKey) CFRelease(cfKey); return NULL; } -/****************************************************************************/ -/** - * replace a sring value from a property list key, - * value returned is not owned by caller, copy it necessary. - */ + +//-------------------------------------------------------------------------- +// Replace or add a string value from a property list key, +// value returned is not owned by caller, copy it necessary. +//-------------------------------------------------------------------------- bool PropertyList::setStringForKey(const char *key, const char * value) { if (!_proplistRef) return false; @@ -323,10 +340,9 @@ return ret; } -/****************************************************************************/ -/** - * delete a key and its value from the dictionary - */ +//-------------------------------------------------------------------------- +// Delete a key and its value from the dictionary +//-------------------------------------------------------------------------- bool PropertyList::removeKeyAndValue(const char *key) { if (!_proplistRef) return false; Index: trunk/ChameleonPrefPane/Sources/file_util.h =================================================================== --- trunk/ChameleonPrefPane/Sources/file_util.h (revision 0) +++ trunk/ChameleonPrefPane/Sources/file_util.h (revision 51) @@ -0,0 +1,25 @@ +/* + * file_util.h + * ChameleonPrefPane + * + * Created by Rekursor on 1/24/10. + * + */ +#ifndef __CHFILE_UTIL_H +#define __CHFILE_UTIL_H +#include + +/** + * Check whether file exists: + */ +inline bool fileExists(const char * str) +{ + struct stat stFileInfo; + if((stat(str,&stFileInfo)) == 0) return true; + else return false; +} + +inline bool fileExists(std::string str) {return fileExists(str.c_str());} + + +#endif Index: trunk/ChameleonPrefPane/Sources/AdvancedSetupController.mm =================================================================== --- trunk/ChameleonPrefPane/Sources/AdvancedSetupController.mm (revision 50) +++ trunk/ChameleonPrefPane/Sources/AdvancedSetupController.mm (revision 51) @@ -21,25 +21,30 @@ //-------------------------------------------------------------------------- - (void) addOptionsDesc { - prop->addOptionDesc(mKernel, mKernelText, OptionKernel1, "Kernel", "mach_kernel"); // empty field for 1 field only "i.e: mach_kernel" syntax - prop->addOptionDesc(mDeviceRd, mDeviceRdText, OptionKernel, "rd", ""); - prop->addOptionDesc(mArch, mArchText, OptionKernel, "arch", ""); - prop->addOptionDesc(mCPU, mCPUText, OptionKernel, "cpus", ""); - prop->addOptionDesc(mBusRatio, mBusRatioText, OptionKernel, "busratio", ""); - prop->addOptionDesc(mDebug, mDebugText, OptionString, "debug", ""); - prop->addOptionDesc(mIO, mIOText, OptionString, "io", ""); - prop->addOptionDesc(mDisableKextsBlacklisting, nil, OptionString, "blacklist", ""); - prop->addOptionDesc(mDSDTFile, mDSDTFileText, OptionString, "DSDT", ""); - prop->addOptionDesc(mDSDTDrop, nil, OptionYesNo, "DropSSDT", "No"); - prop->addOptionDesc(mSMBIOSFile,mSMBIOSFileText, OptionString, "SMBIOS", ""); - prop->addOptionDesc(mSMBIOSDefaults, nil, OptionYesNo, "SMBIOSdefaults", "No"); - prop->addOptionDesc(mWake, nil, OptionYesNo, "Wake", "No"); - prop->addOptionDesc(mForceWake, nil, OptionYesNo, "ForceWake", "No"); - prop->addOptionDesc(mWakeImage, mWakeImageText, OptionString, "WakeImage", ""); - prop->addOptionDesc(mSystemId, mSystemIdText, OptionString, "SystemId", ""); + BootProp::instance().addOptionDesc(mKernel, mKernelText, OptionKernel1, "Kernel", "mach_kernel"); // empty field for 1 field only "i.e: mach_kernel" syntax + BootProp::instance().addOptionDesc(mDeviceRd, mDeviceRdText, OptionKernel, "rd", ""); + BootProp::instance().addOptionDesc(mArch, mArchText, OptionKernel, "arch", ""); + BootProp::instance().addOptionDesc(mCPU, mCPUText, OptionKernel, "cpus", ""); + BootProp::instance().addOptionDesc(mBusRatio, mBusRatioText, OptionKernel, "busratio", ""); + BootProp::instance().addOptionDesc(mDebug, mDebugText, OptionString, "debug", ""); + BootProp::instance().addOptionDesc(mIO, mIOText, OptionString, "io", ""); + BootProp::instance().addOptionDesc(mDisableKextsBlacklisting, nil, OptionString, "blacklist", ""); + BootProp::instance().addOptionDesc(mDSDTFile, mDSDTFileText, OptionString, "DSDT", ""); + BootProp::instance().addOptionDesc(mDSDTDrop, nil, OptionYesNo, "DropSSDT", "No"); + BootProp::instance().addOptionDesc(mSMBIOSFile,mSMBIOSFileText, OptionString, "SMBIOS", ""); + BootProp::instance().addOptionDesc(mSMBIOSDefaults, nil, OptionYesNo, "SMBIOSdefaults", "No"); + BootProp::instance().addOptionDesc(mWake, nil, OptionYesNo, "Wake", "No"); + BootProp::instance().addOptionDesc(mForceWake, nil, OptionYesNo, "ForceWake", "No"); + BootProp::instance().addOptionDesc(mWakeImage, mWakeImageText, OptionString, "WakeImage", ""); + BootProp::instance().addOptionDesc(mSystemId, mSystemIdText, OptionString, "SystemId", ""); } //-------------------------------------------------------------------------- +-(void) setDefaultsValues: (NSMutableDictionary*) dict +{ +} + +//-------------------------------------------------------------------------- - (void) refreshLockStates { // automatic, nothing to do Index: trunk/ChameleonPrefPane/Sources/PropertyList.h =================================================================== --- trunk/ChameleonPrefPane/Sources/PropertyList.h (revision 50) +++ trunk/ChameleonPrefPane/Sources/PropertyList.h (revision 51) @@ -12,55 +12,76 @@ #include #include -/****************************************************************/ +//---------------------------------------------------------------------------- -/** - * priviledged command run for cmds like property chmods and restard command - */ +static const bool CreateIfNotExist = true; +static const bool DontCreate = false; + + +//---------------------------------------------------------------------------- +/// Run priviledged command for cmds like property chmods and restard command +//---------------------------------------------------------------------------- bool executePrivilegedCmd(AuthorizationRef auth, const char* pathToTool, const char* args=NULL, AuthorizationFlags flags=kAuthorizationFlagDefaults); -/****************************************************************/ -/** - * Simple PropertyList Abstraction - */ +//---------------------------------------------------------------------------- +/// Simple PropertyList Abstraction +//---------------------------------------------------------------------------- class PropertyList { public: + // Create a property list PropertyList() : _proplistRef(0), _CFURLRef(0) { } virtual ~PropertyList(); + /// Tell if a valid property list successfully opened bool isValid() const { return _proplistRef!=NULL;} - bool open(const char *propListPath, CFStringRef* errString, - AuthorizationRef auth=NULL, AuthorizationFlags flags=kAuthorizationFlagDefaults); - bool save(AuthorizationRef auth=NULL, AuthorizationFlags flags=kAuthorizationFlagDefaults); + /// Open a property list + bool open(const char *propListPath, bool createIfNotExist, + AuthorizationRef auth=NULL, + AuthorizationFlags flags=kAuthorizationFlagDefaults); + + /// Save a property list + bool save(AuthorizationRef auth=NULL, + AuthorizationFlags flags=kAuthorizationFlagDefaults); + /// Return last error status, used in open() + CFStringRef lastError() const { return _errorString;} + + /// Get a corresponding string content from a key spec const char * getStringForKey(const char *key); const char * getStringForKey(const std::string& key) { std::string str= key; return getStringForKey(str.c_str()); } + + /// Set a content from a string, at specified key bool setStringForKey(const char* key, const char* value); bool setStringForKey(const std::string& key, const std::string& value) { return setStringForKey(key.c_str(), value.c_str()); } + + /// Remove a key from the Proplist bool removeKeyAndValue(const char *key); + /// Get the property list path const char * propFilePath() const { return _propFilePath.c_str(); } + /// permit to execute a priviledge chmod to access system files static bool chmodFile(const char * path, const char * chmodMask, AuthorizationRef auth, AuthorizationFlags flags=kAuthorizationFlagDefaults); protected: CFPropertyListRef _proplistRef; CFURLRef _CFURLRef; std::string _propFilePath; // keep a track of the proplist filename + CFStringRef _errorString; }; #endif Index: trunk/ChameleonPrefPane/Sources/PeripheralsController.h =================================================================== --- trunk/ChameleonPrefPane/Sources/PeripheralsController.h (revision 50) +++ trunk/ChameleonPrefPane/Sources/PeripheralsController.h (revision 51) @@ -10,7 +10,7 @@ // TabView subpane controller definition -@interface PeripheralsController : PreferencesControllerBase +@interface PeripheralsController : PreferencesControllerBase { IBOutlet NSButton* mLegacyLogo; @@ -33,6 +33,7 @@ - (IBAction) onCheckButtonChange: (NSButton*) sender; - (IBAction) onTextFiedChange: (NSTextField*) sender; +- (void) setDefaultsValues: (NSMutableDictionary*) dict; + (PeripheralsController *)instance; Index: trunk/ChameleonPrefPane/Sources/GroupControllerProtocol.h =================================================================== --- trunk/ChameleonPrefPane/Sources/GroupControllerProtocol.h (revision 0) +++ trunk/ChameleonPrefPane/Sources/GroupControllerProtocol.h (revision 51) @@ -0,0 +1,37 @@ +// +// GroupControllerProtocol.h +// ChameleonPrefPane +// +// Created by Fabien on 1/25/10. +// Copyright 2010 __MyCompanyName__. All rights reserved. +// + +#import + + +// Defintion of the required protocol for any derived classes of PreferencesControllerBase +@protocol GroupControllerProtocol + +@required +// must be implemented in all derived classes + +// Called by all buttons of each group in therface +- (IBAction) onCheckButtonChange: (NSButton*) sender; + +// Called by all text fields of each group in therface +- (IBAction) onTextFiedChange: (NSTextField*) sender; + +// Add the boot config options descriptors to the consolidated dictionary +- (void) addOptionsDesc; + +// Permit to each group to customize his default settings +- (void) setDefaultsValues: (NSMutableDictionary*) dict; + +// Set refresh all group states {enabled | disabled} depending on the authorizations state +- (void) refreshLockStates; + +// load the corresponding pref filer options from the interface +- (void) loadOptionsFromPreferencesFile: (NSMutableDictionary*) dict; + +@end + Index: trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.mm =================================================================== --- trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.mm (revision 50) +++ trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.mm (revision 51) @@ -14,7 +14,7 @@ //-------------------------------------------------------------------------- -static std::list groupList; +static std::list< id > groupList; // for unix-like options types static std::map IdToUCmdList; @@ -39,10 +39,11 @@ } //-------------------------------------------------------------------------- -// from the id to desc map in prop, set all default values for dict -+ (void) setDefaultValues: (NSMutableDictionary*) dict +// from the id to desc map in BootProp()., set all default values for dict ++ (void) loadAllValues: (NSMutableDictionary*) dict { - for(const BootOptionDesc* bod = prop->firstOption();bod; bod=prop->nextOption()) + [self doForEachGroup:LoadPreferencesOptions withOption: dict]; + for(const BootOptionDesc* bod = BootProp::instance().firstOption();bod; bod=BootProp::instance().nextOption()) { switch (bod->Type) { @@ -90,8 +91,9 @@ //-------------------------------------------------------------------------- + (void) refreshLockStates { - - for (const BootOptionDesc* bod=prop->firstOption(); bod; bod=prop->nextOption()) + for (const BootOptionDesc* bod=BootProp::instance().firstOption(); + bod; + bod=BootProp::instance().nextOption()) { [self refreshLockState: (id) bod->ID ]; if (bod->contentID) [self refreshLockState: (id) bod->contentID ]; @@ -106,7 +108,7 @@ { switch (action) { case SetDefaultValues: - [*it setDefaultValues: option]; + [*it setDefaultsValues: option]; break; case RefreshLockStates: [*it refreshLockStates ]; @@ -133,9 +135,11 @@ + (void) loadOptionsFromBootFile { // parse unix like command string: - kernelFlags.parseOptions(prop->getStringForKey(kKernelFlags)); + kernelFlags.parseOptions(BootProp::instance().getStringForKey(kKernelFlags)); - for (const BootOptionDesc* bod=prop->firstOption(); bod; bod=prop->nextOption()) + for (const BootOptionDesc* bod=BootProp::instance().firstOption(); + bod; + bod=BootProp::instance().nextOption()) { [PreferencesControllerBase loadOptionFromBootFile:(id)bod->ID ]; } @@ -145,14 +149,14 @@ + (void) loadOptionFromBootFile:(id) optionID { - const BootOptionDesc* bod = prop->findOption(optionID); + const BootOptionDesc* bod = BootProp::instance().findOption(optionID); if (!bod) { NSRunAlertPanel(@"Error Parsing Option",@"loadOptionFromBootFile failed",@"OK", nil, nil); return; } - const char * stringForKey = prop->getStringForKey(bod->Name); + const char * stringForKey = BootProp::instance().getStringForKey(bod->Name); std::string s = stringForKey ? trim(stringForKey) : ""; switch (bod->Type) @@ -244,6 +248,7 @@ int val = [(NSButton*) sender intValue ]; std::string sDefaultValue = trim(bod->Default ? bod->Default : ""); bool status = false; + std::string name = trim(bod->Name); switch (bod->Type) { case OptionYesNo: @@ -252,30 +257,31 @@ if (sDefaultValue.length()==0) sDefaultValue = "No"; // Avoid populating bootConfig with unnecessary options: if (sVal == sDefaultValue) - status = prop->removeKeyAndValue(bod->Name); + status = BootProp::instance().removeKeyAndValue(name.c_str()); else - status = prop->setStringForKey(bod->Name, sVal.c_str()); + status = BootProp::instance().setStringForKey(name, sVal.c_str()); } break; case OptionUnix: - if (!val) kernelFlags.removeFlag(bod->Name); - else kernelFlags.addFlag(bod->Name); - prop->setStringForKey(kKernelFlags,kernelFlags.options()); + if (!val) kernelFlags.removeFlag(name); + else kernelFlags.addFlag(name); + BootProp::instance().setStringForKey(kKernelFlags,kernelFlags.options()); status = true; break; case OptionKernel: { - std::string contentValue = - [ [(NSTextField*) bod->contentID stringValue] UTF8String ]; + std::string contentValue = trim( + [ [(NSTextField*) bod->contentID stringValue] UTF8String ]); kernelFlags.removeFlag(kernelFlags.stringFromKey(bod->Name)); - if(val) + if(val && contentValue.length()>0) { - std::string concat = bod->Name; + std::string concat = trim(name); concat+= "="; concat+= trim(contentValue); + kernelFlags.addFlag(concat); } - prop->setStringForKey(kKernelFlags,kernelFlags.options()); + BootProp::instance().setStringForKey(kKernelFlags,kernelFlags.options()); status = true; } break; @@ -283,13 +289,13 @@ case OptionString: // Avoid populating bootConfig with unnecessary options: if (val == 0 && bod->Type!=OptionKernel1) - status = prop->removeKeyAndValue(bod->Name); + status = BootProp::instance().removeKeyAndValue(bod->Name); else { std::string contentValue = [ [(NSTextField*) bod->contentID stringValue] UTF8String ]; if (contentValue.length()>0) - status = prop->setStringForKey(bod->Name, contentValue.c_str()); + status = BootProp::instance().setStringForKey(bod->Name, contentValue.c_str()); else { return false; // no content to save so don't save it } @@ -302,7 +308,7 @@ // Now save the bootConfig AuthorizationRef auth = [self getAuthorization ]; - if (status) status = prop->save(auth); + if (status) status = BootProp::instance().save(auth); return status; } @@ -322,10 +328,10 @@ - (bool) handleSender: (id) sender { - const BootOptionDesc * bod = prop->findOption(sender); + const BootOptionDesc * bod = BootProp::instance().findOption(sender); if (!bod) { - bod = prop->findOptionContent(sender); + bod = BootProp::instance().findOptionContent(sender); NSTextField* textField = (NSTextField*) sender; std::string content = [[textField stringValue] UTF8String ]; if(bod->ID!=nil) sender = (id) bod->ID; Index: trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp =================================================================== --- trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp (revision 50) +++ trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp (revision 51) @@ -62,6 +62,7 @@ std::string::size_type found = _options.find(flag); if (found==std::string::npos) return; _options.erase(found, found+flag.length()); + _options = trim(_options); } // remove a flag in the string @@ -71,4 +72,5 @@ if (found!=std::string::npos) return; _options = " " + _options; _options = flag + _options; + _options = trim(_options); } Index: trunk/ChameleonPrefPane/Sources/BootFlagsController.h =================================================================== --- trunk/ChameleonPrefPane/Sources/BootFlagsController.h (revision 50) +++ trunk/ChameleonPrefPane/Sources/BootFlagsController.h (revision 51) @@ -10,7 +10,7 @@ // TabView subpane controller definition -@interface BootFlagsController : PreferencesControllerBase +@interface BootFlagsController : PreferencesControllerBase { IBOutlet NSButton* mVerbose; @@ -32,6 +32,7 @@ - (IBAction) onCheckButtonChange: (NSButton*) sender; - (IBAction) onTextFiedChange: (NSTextField*) sender; +- (void) setDefaultsValues: (NSMutableDictionary*) dict; + (BootFlagsController *)instance; Index: trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.cpp =================================================================== --- trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.cpp (revision 0) +++ trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.cpp (revision 51) @@ -0,0 +1,31 @@ +/* + * ChameleonPropertyList.cpp + * ChameleonPrefPane + * + * Created by Rekursor on 1/22/10. + * + */ + +#include "ChameleonPropertyList.h" + +PrefsProp* PrefsProp::_instance = NULL; +BootProp* BootProp::_instance = NULL; +SmbiosProp* SmbiosProp::_instance = NULL; + +void ChameleonPropertyList::deleteOptionDesc() +{ + // delete all alloc'ed pointers + std::map::iterator bod; + for (bod=_idToDescDict.begin(); bod!=_idToDescDict.end(); bod++) + if(bod->second) delete bod->second; + for (bod=_contentIdToDescDict.begin(); bod!=_contentIdToDescDict.end(); bod++) + if(bod->second) delete bod->second; +} + +void ChameleonPropertyList::clearOptionDesc() +{ + deleteOptionDesc(); + _idToDescDict.clear(); // now clear the pairs + _contentIdToDescDict.clear(); // now clear the pairs +} + Index: trunk/ChameleonPrefPane/Sources/BootSetupController.h =================================================================== --- trunk/ChameleonPrefPane/Sources/BootSetupController.h (revision 50) +++ trunk/ChameleonPrefPane/Sources/BootSetupController.h (revision 51) @@ -14,7 +14,7 @@ static const char* const kRenamePartition = "Rename Partition"; // TabView subpane controller definition -@interface BootSetupController : PreferencesControllerBase +@interface BootSetupController : PreferencesControllerBase { @public IBOutlet NSButton * mSwapHD01; @@ -38,9 +38,10 @@ - (IBAction) onCheckButtonChange: (NSButton*) sender; - (IBAction) onTextFiedChange: (NSTextField*) sender; -- (IBAction) onForceBootConfigPath: (id) sender; +- (void) setDefaultsValues: (NSMutableDictionary*) dict; - (void) doSwapHD: (int) val save: (bool) doSave src: (int) isrc dst: (int) idst; +- (IBAction) onForceBootConfigPath: (id) sender; + (BootSetupController *)instance;