PageRenderTime 39ms CodeModel.GetById 1ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Examples/CalendarSample/EditACLWindowController.m

http://macfuse.googlecode.com/
Objective C | 128 lines | 76 code | 29 blank | 23 comment | 6 complexity | d5bb8901a38f36224c6754d1c014d167 MD5 | raw file
  1/* Copyright (c) 2007 Google Inc.
  2 *
  3 * Licensed under the Apache License, Version 2.0 (the "License");
  4 * you may not use this file except in compliance with the License.
  5 * You may obtain a copy of the License at
  6 *
  7 *     http://www.apache.org/licenses/LICENSE-2.0
  8 *
  9 * Unless required by applicable law or agreed to in writing, software
 10 * distributed under the License is distributed on an "AS IS" BASIS,
 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12 * See the License for the specific language governing permissions and
 13 * limitations under the License.
 14 */
 15
 16//
 17//  EditACLWindowController.m
 18//
 19
 20#import "EditACLWindowController.h"
 21
 22
 23@implementation EditACLWindowController
 24
 25- (id)init {
 26  
 27  return [self initWithWindowNibName:@"EditACLWindow"];
 28}
 29
 30- (void)awakeFromNib {
 31  if (mEntry) {
 32    
 33    // copy data from the ACL entry to our dialog's controls
 34    NSString *scopeType = [[mEntry scope] type];
 35    NSString *scopeValue = [[mEntry scope] value];
 36    NSString *roleValue = [[mEntry role] value];
 37    
 38    if (scopeType) [mScopeTypeField setStringValue:scopeType];
 39    if (scopeValue) [mScopeValueField setStringValue:scopeValue];
 40    if (roleValue) [mRoleValueField setStringValue:roleValue];
 41    
 42    // add standard calendar roles to the combo box's menu
 43    NSArray *items = [NSArray arrayWithObjects:
 44      kGDataRoleCalendarNone, kGDataRoleCalendarRead, 
 45      kGDataRoleCalendarFreeBusy, kGDataRoleCalendarRespond, 
 46      kGDataRoleCalendarOverride, kGDataRoleCalendarContributor, 
 47      kGDataRoleCalendarEditor, kGDataRoleCalendarOwner, 
 48      kGDataRoleCalendarRoot, nil];
 49      
 50    [mRoleValueField addItemsWithObjectValues:items];
 51  }
 52}
 53
 54- (void)dealloc {
 55  [mEntry release];
 56  [super dealloc]; 
 57}
 58
 59#pragma mark -
 60
 61- (void)runModalForTarget:(id)target
 62                 selector:(SEL)doneSelector
 63                 ACLEntry:(GDataEntryACL *)entry {
 64  mTarget = target;
 65  mDoneSEL = doneSelector;
 66  mEntry = [entry retain];
 67
 68  [NSApp beginSheet:[self window]
 69     modalForWindow:[mTarget window]
 70      modalDelegate:self
 71     didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
 72        contextInfo:nil];
 73}
 74
 75- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode  contextInfo:(void  *)contextInfo {
 76  
 77}
 78
 79- (void)closeDialog {
 80  // call the target to say we're done
 81  [mTarget performSelector:mDoneSEL 
 82                withObject:[[self retain] autorelease]];
 83  
 84  [[self window] orderOut:self];
 85  [NSApp endSheet:[self window]];
 86}
 87
 88- (IBAction)saveButtonClicked:(id)sender {
 89  mWasSaveClicked = YES;
 90  [self closeDialog];
 91}
 92
 93- (IBAction)cancelButtonClicked:(id)sender {
 94  [self closeDialog];
 95}
 96
 97- (GDataEntryACL *)ACLEntry {
 98  
 99  // copy from our dialog's controls into a copy of the original event
100  
101  NSString *scopeType = [mScopeTypeField stringValue];
102  NSString *scopeValue = [mScopeValueField stringValue];
103  NSString *roleValue = [mRoleValueField stringValue];
104  
105  GDataACLScope *scope = [GDataACLScope scopeWithType:scopeType
106                                                value:scopeValue];
107  GDataACLRole *role = [GDataACLRole roleWithValue:roleValue];
108  
109  GDataEntryACL *newEntry;
110  if (mEntry) {
111    // copy the original entry
112    newEntry = [[mEntry copy] autorelease];  
113    [newEntry setScope:scope];
114    [newEntry setRole:role];
115  } else {
116    // make a new entry
117    newEntry = [GDataEntryACL ACLEntryWithScope:scope
118                                           role:role];
119  }
120  
121  return newEntry; 
122}
123
124- (BOOL)wasSaveClicked {
125  return mWasSaveClicked; 
126}
127
128@end