PageRenderTime 52ms CodeModel.GetById 24ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://macfuse.googlecode.com/
Objective C | 168 lines | 111 code | 34 blank | 23 comment | 13 complexity | add65eb2bbea94698f6e707fb186af74 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//  EditEventWindowController.m
 18//
 19
 20#import "EditEventWindowController.h"
 21
 22
 23@implementation EditEventWindowController
 24
 25- (id)init {
 26  
 27  return [self initWithWindowNibName:@"EditEventWindow"];
 28}
 29
 30- (void)awakeFromNib {
 31  if (mEvent) {
 32    
 33    // copy data from the event to our dialog's controls
 34    NSString *title = [[mEvent title] stringValue];
 35    NSString *desc = [[mEvent content] stringValue];
 36    
 37    GDataDateTime *startTime = nil;
 38    GDataDateTime *endTime = nil;
 39    
 40    NSArray *times = [mEvent times];
 41    GDataWhen *when = nil;
 42    if ([times count] > 0) {
 43      when = [times objectAtIndex:0];
 44      startTime = [when startTime];
 45      endTime = [when endTime];
 46    }
 47    
 48    NSString *reminderMinutesStr = nil;
 49    NSString *reminderMethod = nil;
 50    NSArray *reminders = [when reminders];
 51
 52    if ([reminders count] > 0) {
 53      GDataReminder *reminder = [reminders objectAtIndex:0];
 54      reminderMinutesStr = [reminder minutes]; // note: reminders may be stored other ways too
 55      reminderMethod = [reminder method];
 56    }
 57    
 58    if (title) [mTitleField setStringValue:title];
 59    if (desc) [mDescriptionField setStringValue:desc];
 60    
 61    if (startTime) {
 62      [mStartDatePicker setDateValue:[startTime date]];
 63      [mStartDatePicker setTimeZone:[startTime timeZone]];
 64    }
 65    if (endTime) {
 66      [mEndDatePicker setDateValue:[endTime date]];
 67      [mEndDatePicker setTimeZone:[endTime timeZone]];
 68    }
 69    if (reminderMinutesStr) {
 70      [mReminderMinutesField setStringValue:reminderMinutesStr];
 71    }
 72    if (reminderMethod) {
 73      [mReminderMethodPopup selectItemWithTitle:reminderMethod]; 
 74    }
 75  }
 76}
 77
 78- (void)dealloc {
 79  [mEvent release];
 80  [super dealloc]; 
 81}
 82
 83#pragma mark -
 84
 85- (void)runModalForTarget:(id)target
 86                 selector:(SEL)doneSelector
 87                    event:(GDataEntryCalendarEvent *)event
 88{
 89  
 90  mTarget = target;
 91  mDoneSEL = doneSelector;
 92  mEvent = [event retain];
 93  
 94  [NSApp beginSheet:[self window]
 95     modalForWindow:[mTarget window]
 96      modalDelegate:self
 97     didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
 98        contextInfo:nil];
 99}
100
101- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode  contextInfo:(void  *)contextInfo {
102  
103}
104
105- (void)closeDialog {
106  // call the target to say we're done
107  [mTarget performSelector:mDoneSEL 
108                withObject:[[self retain] autorelease]];
109  
110  [[self window] orderOut:self];
111  [NSApp endSheet:[self window]];
112}
113
114- (IBAction)saveButtonClicked:(id)sender {
115  mWasSaveClicked = YES;
116  [self closeDialog];
117}
118
119- (IBAction)cancelButtonClicked:(id)sender {
120  [self closeDialog];
121}
122
123- (GDataEntryCalendarEvent *)event {
124  
125  // copy from our dialog's controls into a copy of the original event
126  NSString *title = [mTitleField stringValue];
127  NSString *desc = [mDescriptionField stringValue];
128  NSString *reminderMin = [mReminderMinutesField stringValue];
129  NSString *reminderMethod = [[mReminderMethodPopup selectedItem] title];
130  
131  GDataEntryCalendarEvent *newEvent;
132  if (mEvent) {
133    newEvent = [[mEvent copy] autorelease];
134  } else {
135    newEvent = [GDataEntryCalendarEvent calendarEvent];
136  }
137  
138  [newEvent setTitleWithString:title];
139  [newEvent setContentWithString:desc];
140  
141  // times
142  GDataDateTime *startDateTime = [GDataDateTime dateTimeWithDate:[mStartDatePicker dateValue]
143                                                        timeZone:[mStartDatePicker timeZone]];
144  GDataDateTime *endDateTime = [GDataDateTime dateTimeWithDate:[mEndDatePicker dateValue]
145                                                      timeZone:[mEndDatePicker timeZone]];
146  GDataWhen *when = [GDataWhen whenWithStartTime:startDateTime
147                                         endTime:endDateTime];
148
149  // reminders.  Reminders are inside the GDWhen (except for recurring events,
150  // where they're inside the event itself)
151  NSMutableArray *reminders = [NSMutableArray array];
152  if (reminderMin || reminderMethod) {
153    GDataReminder *reminder = [GDataReminder reminder];
154    [reminder setMinutes:reminderMin];
155    [reminder setMethod:reminderMethod];
156    [reminders addObject:reminder];
157  }
158  [when setReminders:reminders];
159
160  [newEvent setTimes:[NSArray arrayWithObject:when]];
161  return newEvent; 
162}
163
164- (BOOL)wasSaveClicked {
165  return mWasSaveClicked; 
166}
167
168@end