From: Andrew M. <fit...@us...> - 2006-04-25 18:14:32
|
Update of /cvsroot/radmind/radmind-assistant/rte In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9615 Modified Files: RXPrefs.h RXPrefs.m Log Message: Multi-paned pref panel (General, Advanced). sessionrights interface. Index: RXPrefs.m =================================================================== RCS file: /cvsroot/radmind/radmind-assistant/rte/RXPrefs.m,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RXPrefs.m 24 Feb 2006 21:49:00 -0000 1.7 --- RXPrefs.m 25 Apr 2006 18:14:26 -0000 1.8 *************** *** 24,27 **** --- 24,37 ---- #import "RXPrefs.h" + #import "NSPanel(Resizing).h" + + #include <CoreFoundation/CoreFoundation.h> + #include <Security/Authorization.h> + #include <Security/AuthorizationDB.h> + + #include "sessionrights.h" + + #define RTEPrefToolbarGeneralIdentifier @"RTEPrefToolbarGeneral" + #define RTEPrefToolbarAdvancedIdentifier @"RTEPrefToolbarAdvanced" @implementation RXPrefs *************** *** 34,42 **** --- 44,199 ---- } + - ( void )toolbarSetup + { + NSToolbar *preftbar = [[[ NSToolbar alloc ] initWithIdentifier: + @"RTEPrefToolbar" ] autorelease ]; + + [ preftbar setAllowsUserCustomization: NO ]; + [ preftbar setAutosavesConfiguration: NO ]; + [ preftbar setDisplayMode: NSToolbarDisplayModeIconAndLabel ]; + + [ preftbar setDelegate: self ]; + [ prefPanel setToolbar: preftbar ]; + } + - ( void )awakeFromNib { + [ self toolbarSetup ]; + [ self showGeneralPreferences: nil ]; + + /* select the General prefs (10.3 only) */ + if ( [ prefPanel toolbar ] != nil && + [[ prefPanel toolbar ] respondsToSelector: + @selector( setSelectedItemIdentifier: ) ] ) { + [[ prefPanel toolbar ] setSelectedItemIdentifier: + RTEPrefToolbarGeneralIdentifier ]; + } + [ prefPanel center ]; } + - ( NSToolbarItem * )toolbar: ( NSToolbar * )toolbar + itemForItemIdentifier: ( NSString * )itemIdent + willBeInsertedIntoToolbar: ( BOOL )flag + { + NSToolbarItem *preftbarItem = [[[ NSToolbarItem alloc ] + initWithItemIdentifier: itemIdent ] autorelease ]; + + if ( [ itemIdent isEqualToString: RTEPrefToolbarGeneralIdentifier ] ) { + [ preftbarItem setLabel: + NSLocalizedString( @"General", @"General" ) ]; + [ preftbarItem setPaletteLabel: + NSLocalizedString( @"General", @"General" ) ]; + [ preftbarItem setToolTip: + NSLocalizedString( @"Show General Preferences", + @"Show General Preferences" ) ]; + [ preftbarItem setImage: [ NSImage imageNamed: @"generalprefs.png" ]]; + [ preftbarItem setAction: @selector( showGeneralPreferences: ) ]; + [ preftbarItem setTarget: self ]; + } else if ( [ itemIdent isEqualToString: RTEPrefToolbarAdvancedIdentifier ] ) { + [ preftbarItem setLabel: + NSLocalizedString( @"Advanced", @"Advanced" ) ]; + [ preftbarItem setPaletteLabel: + NSLocalizedString( @"Advanced", @"Advanced" ) ]; + [ preftbarItem setToolTip: + NSLocalizedString( @"Show Advanced Preferences", + @"Show Advanced Preferences" ) ]; + [ preftbarItem setImage: [ NSImage imageNamed: @"advancedprefs.png" ]]; + [ preftbarItem setAction: @selector( showAdvancedPreferences: ) ]; + [ preftbarItem setTarget: self ]; + } + + return( preftbarItem ); + } + + - ( BOOL )validateToolbarItem: ( NSToolbarItem * )tItem + { + return( YES ); + } + + - ( NSArray * )toolbarDefaultItemIdentifiers: ( NSToolbar * )toolbar + { + NSArray *tmp = [ NSArray arrayWithObjects: + RTEPrefToolbarGeneralIdentifier, + RTEPrefToolbarAdvancedIdentifier, nil ]; + + return( tmp ); + } + + - ( NSArray * )toolbarAllowedItemIdentifiers: ( NSToolbar * )toolbar + { + NSArray *tmp = [ NSArray arrayWithObjects: + RTEPrefToolbarGeneralIdentifier, + RTEPrefToolbarAdvancedIdentifier, nil ]; + + return( tmp ); + } + + /* 10.3+ only */ + - ( NSArray * )toolbarSelectableItemIdentifiers: ( NSToolbar * )toolbar + { + NSArray *tmp = [ NSArray arrayWithObjects: + RTEPrefToolbarGeneralIdentifier, + RTEPrefToolbarAdvancedIdentifier, nil ]; + + return( tmp ); + } + /* end required toolbar delegate methods */ + + - ( void )showGeneralPreferences: ( id )sender + { + NSTabViewItem *item; + int index; + + index = [ prefTabView indexOfTabViewItemWithIdentifier: @"General" ]; + item = [ prefTabView tabViewItemAtIndex: index ]; + + [ prefTabView selectTabViewItemWithIdentifier: @"DummyTab" ]; + [ prefPanel resizeForContentView: prefGeneralPreferencesBox ]; + [ item setView: prefGeneralPreferencesBox ]; + [ prefTabView selectTabViewItemWithIdentifier: @"General" ]; + [ prefPanel setTitle: NSLocalizedString( @"General Preferences", + @"General Preferences" ) ]; + } + + - ( void )showAdvancedPreferences: ( id )sender + { + CFDictionaryRef dict = NULL; + NSTabViewItem *item; + int index; + + index = [ prefTabView indexOfTabViewItemWithIdentifier: @"Advanced" ]; + item = [ prefTabView tabViewItemAtIndex: index ]; + + [ prefDefineRightsSwitch setState: NSOffState ]; + [ prefTimeoutStepper setEnabled: YES ]; + + if ( getright( RADMIND_RIGHT_GENERIC, &dict )) { + if ( [ ( NSDictionary * )dict count ] ) { + int timeout; + + [ prefDefineRightsSwitch setState: NSOnState ]; + + timeout = [[ ( NSDictionary * )dict objectForKey: + @"timeout" ] intValue ]; + timeout /= 60; + + [ prefTimeoutField setIntValue: timeout ]; + [ prefTimeoutStepper setIntValue: timeout ]; + [ prefTimeoutStepper setEnabled: NO ]; + } + } + if ( dict != NULL ) { + CFRelease( dict ); + } + + [ prefTabView selectTabViewItemWithIdentifier: @"DummyTab" ]; + [ prefPanel resizeForContentView: prefAdvancedPreferencesBox ]; + [ item setView: prefAdvancedPreferencesBox ]; + [ prefTabView selectTabViewItemWithIdentifier: @"Advanced" ]; + [ prefPanel setTitle: NSLocalizedString( @"Advanced Preferences", + @"Advanced Preferences" ) ]; + } + - ( void )reloadDefaults { *************** *** 134,136 **** --- 291,341 ---- } + /* advanced preferences */ + - ( IBAction )toggleSessionRights: ( id )sender + { + if ( [ sender state ] == NSOffState ) { + if ( ! removeright( RADMIND_RIGHT_EDIT )) { + NSLog( @"Failed to remove right" ); + return; + } + [ prefTimeoutStepper setEnabled: YES ]; + } else if ( [ sender state ] == NSOnState ) { + int timeout = [ prefTimeoutField intValue ]; + + if ( timeout == INT_MAX || timeout == INT_MIN ) { + NSBeep(); + [ sender setState: NSOffState ]; + NSLog( @"Invalid timeout value %@", + [ prefTimeoutField stringValue ] ); + return; + } + + /* timeout value in auth db is in seconds */ + timeout *= 60; + + if ( AuthorizationRightGet( RADMIND_RIGHT_EDIT, NULL ) + == errAuthorizationSuccess ) { + NSLog( @"%s is already in auth db", RADMIND_RIGHT_EDIT ); + return; + } + + if ( ! setright( RADMIND_RIGHT_EDIT, timeout )) { + NSLog( @"Failed to set right" ); + return; + } + + [ prefTimeoutStepper setEnabled: NO ]; + } + } + + - ( IBAction )setAuthorizationTimeout: ( id )sender + { + if ( ! [ sender isKindOfClass: [ NSStepper class ]] ) { + NSBeep(); + return; + } + + [ prefTimeoutField setIntValue: [ sender intValue ]]; + } + @end Index: RXPrefs.h =================================================================== RCS file: /cvsroot/radmind/radmind-assistant/rte/RXPrefs.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RXPrefs.h 24 Feb 2006 21:49:00 -0000 1.7 --- RXPrefs.h 25 Apr 2006 18:14:26 -0000 1.8 *************** *** 30,40 **** { IBOutlet NSPanel *prefPanel; ! IBOutlet NSButton *prefWarnDirDelete; ! IBOutlet NSPopUpButton *prefBasePathPopUp; ! IBOutlet NSButton *prefWildcardSwitch; ! IBOutlet NSTextField *prefTranscriptFontSize; ! IBOutlet NSStepper *prefTranscriptFontSizeStepper; } - ( IBAction )prefSetBasePath: ( id )sender; - ( IBAction )toggleWildcardSearches: ( id )sender; --- 30,55 ---- { IBOutlet NSPanel *prefPanel; ! IBOutlet NSTabView *prefTabView; ! /* IBOutlet NSButton *prefWarnDirDelete; */ ! ! /* general preferences */ ! IBOutlet NSBox *prefGeneralPreferencesBox; ! IBOutlet NSPopUpButton *prefBasePathPopUp; ! IBOutlet NSButton *prefWildcardSwitch; ! IBOutlet NSTextField *prefTranscriptFontSize; ! IBOutlet NSStepper *prefTranscriptFontSizeStepper; ! ! /* advanced preferences */ ! IBOutlet NSBox *prefAdvancedPreferencesBox; ! IBOutlet NSButton *prefDefineRightsSwitch; ! IBOutlet NSTextField *prefTimeoutField; ! IBOutlet NSStepper *prefTimeoutStepper; } + - ( void )displayPreferencesPane; + - ( void )showGeneralPreferences: ( id )sender; + - ( void )showAdvancedPreferences: ( id )sender; + + /* general preferences actions */ - ( IBAction )prefSetBasePath: ( id )sender; - ( IBAction )toggleWildcardSearches: ( id )sender; *************** *** 42,46 **** - ( IBAction )changeTranscriptFontSize: ( id )sender; ! - ( void )displayPreferencesPane; @end --- 57,63 ---- - ( IBAction )changeTranscriptFontSize: ( id )sender; ! /* advanced preferences actions */ ! - ( IBAction )toggleSessionRights: ( id )sender; ! - ( IBAction )setAuthorizationTimeout: ( id )sender; @end |