PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  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. // EditACLWindowController.m
  17. //
  18. #import "EditACLWindowController.h"
  19. @implementation EditACLWindowController
  20. - (id)init {
  21. return [self initWithWindowNibName:@"EditACLWindow"];
  22. }
  23. - (void)awakeFromNib {
  24. if (mEntry) {
  25. // copy data from the ACL entry to our dialog's controls
  26. NSString *scopeType = [[mEntry scope] type];
  27. NSString *scopeValue = [[mEntry scope] value];
  28. NSString *roleValue = [[mEntry role] value];
  29. if (scopeType) [mScopeTypeField setStringValue:scopeType];
  30. if (scopeValue) [mScopeValueField setStringValue:scopeValue];
  31. if (roleValue) [mRoleValueField setStringValue:roleValue];
  32. // add standard calendar roles to the combo box's menu
  33. NSArray *items = [NSArray arrayWithObjects:
  34. kGDataRoleCalendarNone, kGDataRoleCalendarRead,
  35. kGDataRoleCalendarFreeBusy, kGDataRoleCalendarRespond,
  36. kGDataRoleCalendarOverride, kGDataRoleCalendarContributor,
  37. kGDataRoleCalendarEditor, kGDataRoleCalendarOwner,
  38. kGDataRoleCalendarRoot, nil];
  39. [mRoleValueField addItemsWithObjectValues:items];
  40. }
  41. }
  42. - (void)dealloc {
  43. [mEntry release];
  44. [super dealloc];
  45. }
  46. #pragma mark -
  47. - (void)runModalForTarget:(id)target
  48. selector:(SEL)doneSelector
  49. ACLEntry:(GDataEntryACL *)entry {
  50. mTarget = target;
  51. mDoneSEL = doneSelector;
  52. mEntry = [entry retain];
  53. [NSApp beginSheet:[self window]
  54. modalForWindow:[mTarget window]
  55. modalDelegate:self
  56. didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
  57. contextInfo:nil];
  58. }
  59. - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
  60. }
  61. - (void)closeDialog {
  62. // call the target to say we're done
  63. [mTarget performSelector:mDoneSEL
  64. withObject:[[self retain] autorelease]];
  65. [[self window] orderOut:self];
  66. [NSApp endSheet:[self window]];
  67. }
  68. - (IBAction)saveButtonClicked:(id)sender {
  69. mWasSaveClicked = YES;
  70. [self closeDialog];
  71. }
  72. - (IBAction)cancelButtonClicked:(id)sender {
  73. [self closeDialog];
  74. }
  75. - (GDataEntryACL *)ACLEntry {
  76. // copy from our dialog's controls into a copy of the original event
  77. NSString *scopeType = [mScopeTypeField stringValue];
  78. NSString *scopeValue = [mScopeValueField stringValue];
  79. NSString *roleValue = [mRoleValueField stringValue];
  80. GDataACLScope *scope = [GDataACLScope scopeWithType:scopeType
  81. value:scopeValue];
  82. GDataACLRole *role = [GDataACLRole roleWithValue:roleValue];
  83. GDataEntryACL *newEntry;
  84. if (mEntry) {
  85. // copy the original entry
  86. newEntry = [[mEntry copy] autorelease];
  87. [newEntry setScope:scope];
  88. [newEntry setRole:role];
  89. } else {
  90. // make a new entry
  91. newEntry = [GDataEntryACL ACLEntryWithScope:scope
  92. role:role];
  93. }
  94. return newEntry;
  95. }
  96. - (BOOL)wasSaveClicked {
  97. return mWasSaveClicked;
  98. }
  99. @end