2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <NGExtensions/NSCalendarDate+misc.h>
23 #import <NGExtensions/NSObject+Logs.h>
24 #import <NGExtensions/NSNull+misc.h>
26 #import "SOGoAptFormatter.h"
28 @interface SOGoAptFormatter(PrivateAPI)
29 - (NSString *)titleForApt:(id)_apt :(NSCalendarDate *)_refDate;
30 - (NSString *)shortTitleForApt:(id)_apt :(NSCalendarDate *)_refDate;
31 - (NSTimeZone *)displayTZ;
33 - (void)appendTimeInfoForDate:(NSCalendarDate *)_date
34 usingReferenceDate:(NSCalendarDate *)_refDate
35 toBuffer:(NSMutableString *)_buf;
37 - (void)appendTimeInfoFromApt:(id)_apt
38 usingReferenceDate:(NSCalendarDate *)_refDate
39 toBuffer:(NSMutableString *)_buf;
42 // TODO: Clean this up, put it into NGExtensions!
43 @interface NSCalendarDate (UIxCalMonthOverviewExtensions_UsedPrivates)
44 - (BOOL)isDateInSameMonth:(NSCalendarDate *)_other;
47 @implementation SOGoAptFormatter
49 - (id)initWithDisplayTimeZone:(NSTimeZone *)_tz {
50 if ((self = [super init])) {
51 self->tz = [_tz retain];
52 [self setFullDetails];
59 [self->privateTitle release];
60 [self->titlePlaceholder release];
67 self->formatAction = @selector(tooltipForApt::);
70 - (void)setSingleLineFullDetails {
71 self->formatAction = @selector(singleLineFullDetailsForApt::);
74 - (void)setFullDetails {
75 self->formatAction = @selector(fullDetailsForApt::);
78 - (void)setPrivateTooltip {
79 self->formatAction = @selector(tooltipForPrivateApt::);
82 - (void)setPrivateDetails {
83 self->formatAction = @selector(detailsForPrivateApt::);
86 - (void)setTitleOnly {
87 self->formatAction = @selector(titleForApt::);
90 - (void)setShortTitleOnly {
91 self->formatAction = @selector(shortTitleForApt::);
94 - (void)setShortMonthTitleOnly {
95 self->formatAction = @selector(shortMonthTitleForApt::);
98 - (void)setPrivateSuppressAll {
99 self->formatAction = @selector(suppressApt::);
102 - (void)setPrivateTitleOnly {
103 self->formatAction = @selector(titleOnlyForPrivateApt::);
106 - (void)setPrivateTitle:(NSString *)_privateTitle {
107 ASSIGN(self->privateTitle, _privateTitle);
109 - (NSString *)privateTitle {
110 return self->privateTitle;
113 - (void)setTitlePlaceholder:(NSString *)_titlePlaceholder {
114 ASSIGN(self->titlePlaceholder, _titlePlaceholder);
116 - (NSString *)titlePlaceholder {
117 return self->titlePlaceholder;
120 - (void)setOmitsEndDate {
121 self->omitsEndDate = YES;
124 - (NSString *)stringForObjectValue:(id)_obj {
125 [self warnWithFormat:@"%s called, please use "
126 @"stringForObjectValue:referenceDate: instead!",
127 __PRETTY_FUNCTION__];
128 return [self stringForObjectValue:_obj referenceDate:nil];
131 - (NSString *)stringForObjectValue:(id)_obj
132 referenceDate:(NSCalendarDate *)_refDate
134 return [self performSelector:self->formatAction
136 withObject:_refDate];
141 - (NSTimeZone *)displayTZ {
145 - (void)appendTimeInfoForDate:(NSCalendarDate *)_date
146 usingReferenceDate:(NSCalendarDate *)_refDate
147 toBuffer:(NSMutableString *)_buf
152 * 12:00 (07-05) - 13:00 (07-07)
153 * 12:00 (12-30-2004) - 13:00 (01-01-2005)
156 [_buf appendFormat:@"%02i:%02i",
158 [_date minuteOfHour]];
159 if (_refDate && ![_date isDateOnSameDay:_refDate]) {
160 [_buf appendFormat:@" (%02i-%02i",
163 if ([_date yearOfCommonEra] != [_refDate yearOfCommonEra])
164 [_buf appendFormat:@"-%04i", [_date yearOfCommonEra]];
165 [_buf appendString:@")"];
169 - (void)appendTimeInfoFromApt:(id)_apt
170 usingReferenceDate:(NSCalendarDate *)_refDate
171 toBuffer:(NSMutableString *)_buf
173 NSCalendarDate *startDate, *endDate, *date;
178 dtz = [self displayTZ];
179 startDate = [_apt valueForKey:@"startDate"];
180 [startDate setTimeZone:dtz];
181 endDate = [_apt valueForKey:@"endDate"];
183 [endDate setTimeZone:dtz];
184 spansRange = ![endDate isEqualToDate:startDate];
187 [_refDate setTimeZone:dtz];
190 if (!_refDate || [startDate isDateOnSameDay:_refDate])
193 date = [startDate hour:0 minute:0];
198 [self appendTimeInfoForDate:date
199 usingReferenceDate:_refDate
202 if (spansRange && !self->omitsEndDate) {
203 [_buf appendString:@" - "];
205 if (!_refDate || [endDate isDateOnSameDay:_refDate])
208 date = [endDate hour:23 minute:59];
212 [self appendTimeInfoForDate:date
213 usingReferenceDate:_refDate
218 - (NSString *)titleForApt:(id)_apt :(NSCalendarDate *)_refDate {
221 title = [_apt valueForKey:@"title"];
222 if (![title isNotEmpty])
223 title = [self titlePlaceholder];
227 - (NSString *)shortTitleForApt:(id)_apt :(NSCalendarDate *)_refDate {
230 title = [self titleForApt:_apt :_refDate];
231 if ([title length] > 50)
232 title = [[title substringToIndex: 49] stringByAppendingString:@"..."];
237 - (NSString *)shortMonthTitleForApt:(id)_apt :(NSCalendarDate *)_refDate {
238 NSMutableString *title;
239 NSCalendarDate *startDate;
242 title = [NSMutableString new];
245 dtz = [self displayTZ];
246 startDate = [_apt valueForKey: @"startDate"];
247 [startDate setTimeZone:dtz];
248 [self appendTimeInfoForDate: startDate usingReferenceDate: nil
250 [title appendFormat: @" %@", [self titleForApt:_apt :_refDate]];
255 - (NSString *)singleLineFullDetailsForApt:(id)_apt :(NSCalendarDate *)_refDate {
256 NSMutableString *aptDescr;
259 aptDescr = [NSMutableString stringWithCapacity:60];
260 [self appendTimeInfoFromApt:_apt
261 usingReferenceDate:_refDate
263 if ((s = [_apt valueForKey:@"location"]) != nil) {
264 [aptDescr appendFormat:@"; (%@)", s];
266 if ((s = [self titleForApt:_apt :_refDate]) != nil)
267 [aptDescr appendFormat:@"; %@", s];
271 - (NSString *) fullDetailsForApt: (id)_apt
272 : (NSCalendarDate *)_refDate
274 NSMutableString *aptDescr;
277 aptDescr = [NSMutableString stringWithCapacity: 60];
278 [self appendTimeInfoFromApt: _apt
279 usingReferenceDate: _refDate
281 s = [_apt valueForKey: @"location"];
285 s = [[s substringToIndex: 49] stringByAppendingString: @"..."];
286 [aptDescr appendFormat:@" (%@)", s];
288 s = [self shortTitleForApt: _apt : _refDate];
290 [aptDescr appendFormat:@"<br />%@", s];
295 - (NSString *) detailsForPrivateApt: (id) _apt
296 : (NSCalendarDate *) _refDate
298 NSMutableString *aptDescr;
301 aptDescr = [NSMutableString stringWithCapacity:40];
302 [self appendTimeInfoFromApt:_apt
303 usingReferenceDate:_refDate
305 if ((s = [self privateTitle]) != nil)
306 [aptDescr appendFormat:@"<br />%@", s];
310 - (NSString *) titleOnlyForPrivateApt: (id)_apt
311 : (NSCalendarDate *) _refDate
315 s = [self privateTitle];
322 - (NSString *) tooltipForApt: (id)_apt
323 : (NSCalendarDate *) _refDate
325 NSMutableString *aptDescr;
328 aptDescr = [NSMutableString stringWithCapacity: 60];
329 [aptDescr appendString: @"Date: "];
330 [self appendTimeInfoFromApt: _apt
331 usingReferenceDate: _refDate
333 s = [self titleForApt: _apt : _refDate];
335 [aptDescr appendFormat: @"\nTitle: %@", s];
336 s = [_apt valueForKey: @"location"];
338 [aptDescr appendFormat: @"\nLocation: %@", s];
339 s = [_apt valueForKey: @"description"];
341 [aptDescr appendFormat:@"\n%@", s];
346 - (NSString *) tooltipForPrivateApt: (id) _apt
347 : (NSCalendarDate *) _refDate
349 NSMutableString *aptDescr;
352 aptDescr = [NSMutableString stringWithCapacity: 25];
353 [self appendTimeInfoFromApt: _apt
354 usingReferenceDate: _refDate
356 if ((s = [self privateTitle]) != nil)
357 [aptDescr appendFormat:@"\n%@", s];
362 - (NSString *) suppressApt: (id) _apt
363 : (NSCalendarDate *) _refDate
368 @end /* SOGoAptFormatter */