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 #include "SOGoAptFormatter.h"
25 @interface SOGoAptFormatter(PrivateAPI)
26 - (NSString *)titleForApt:(id)_apt :(NSCalendarDate *)_refDate;
27 - (NSString *)shortTitleForApt:(id)_apt :(NSCalendarDate *)_refDate;
28 - (NSTimeZone *)displayTZ;
30 - (void)appendTimeInfoForDate:(NSCalendarDate *)_date
31 usingReferenceDate:(NSCalendarDate *)_refDate
32 toBuffer:(NSMutableString *)_buf;
34 - (void)appendTimeInfoFromApt:(id)_apt
35 usingReferenceDate:(NSCalendarDate *)_refDate
36 toBuffer:(NSMutableString *)_buf;
39 // TODO: Clean this up, put it into NGExtensions!
40 @interface NSCalendarDate (UIxCalMonthOverviewExtensions_UsedPrivates)
41 - (BOOL)isDateInSameMonth:(NSCalendarDate *)_other;
44 @implementation SOGoAptFormatter
46 - (id)initWithDisplayTimeZone:(NSTimeZone *)_tz {
47 if ((self = [super init])) {
48 self->tz = [_tz retain];
49 [self setFullDetails];
56 [self->privateTitle release];
57 [self->titlePlaceholder release];
64 self->formatAction = @selector(tooltipForApt::);
67 - (void)setSingleLineFullDetails {
68 self->formatAction = @selector(singleLineFullDetailsForApt::);
71 - (void)setFullDetails {
72 self->formatAction = @selector(fullDetailsForApt::);
75 - (void)setPrivateTooltip {
76 self->formatAction = @selector(tooltipForPrivateApt::);
79 - (void)setPrivateDetails {
80 self->formatAction = @selector(detailsForPrivateApt::);
83 - (void)setTitleOnly {
84 self->formatAction = @selector(titleForApt::);
87 - (void)setShortTitleOnly {
88 self->formatAction = @selector(shortTitleForApt::);
91 - (void)setPrivateSuppressAll {
92 self->formatAction = @selector(suppressApt::);
95 - (void)setPrivateTitleOnly {
96 self->formatAction = @selector(titleOnlyForPrivateApt::);
99 - (void)setPrivateTitle:(NSString *)_privateTitle {
100 ASSIGN(self->privateTitle, _privateTitle);
102 - (NSString *)privateTitle {
103 return self->privateTitle;
106 - (void)setTitlePlaceholder:(NSString *)_titlePlaceholder {
107 ASSIGN(self->titlePlaceholder, _titlePlaceholder);
109 - (NSString *)titlePlaceholder {
110 return self->titlePlaceholder;
113 - (void)setOmitsEndDate {
114 self->omitsEndDate = YES;
117 - (NSString *)stringForObjectValue:(id)_obj {
118 [self warnWithFormat:@"%s called, please use "
119 @"stringForObjectValue:referenceDate: instead!",
120 __PRETTY_FUNCTION__];
121 return [self stringForObjectValue:_obj referenceDate:nil];
124 - (NSString *)stringForObjectValue:(id)_obj
125 referenceDate:(NSCalendarDate *)_refDate
127 return [self performSelector:self->formatAction
129 withObject:_refDate];
134 - (NSTimeZone *)displayTZ {
138 - (void)appendTimeInfoForDate:(NSCalendarDate *)_date
139 usingReferenceDate:(NSCalendarDate *)_refDate
140 toBuffer:(NSMutableString *)_buf
145 * 12:00 (07-05) - 13:00 (07-07)
146 * 12:00 (12-30-2004) - 13:00 (01-01-2005)
149 [_buf appendFormat:@"%02i:%02i",
151 [_date minuteOfHour]];
152 if (_refDate && ![_date isDateOnSameDay:_refDate]) {
153 [_buf appendFormat:@" (%02i-%02i",
156 if ([_date yearOfCommonEra] != [_refDate yearOfCommonEra])
157 [_buf appendFormat:@"-%04i", [_date yearOfCommonEra]];
158 [_buf appendString:@")"];
162 - (void)appendTimeInfoFromApt:(id)_apt
163 usingReferenceDate:(NSCalendarDate *)_refDate
164 toBuffer:(NSMutableString *)_buf
166 NSCalendarDate *startDate, *endDate, *date;
171 dtz = [self displayTZ];
172 startDate = [_apt valueForKey:@"startDate"];
173 [startDate setTimeZone:dtz];
174 endDate = [_apt valueForKey:@"endDate"];
176 [endDate setTimeZone:dtz];
177 spansRange = ![endDate isEqualToDate:startDate];
180 [_refDate setTimeZone:dtz];
183 if (!_refDate || [startDate isDateOnSameDay:_refDate])
186 date = [startDate hour:0 minute:0];
191 [self appendTimeInfoForDate:date
192 usingReferenceDate:_refDate
195 if (spansRange && !self->omitsEndDate) {
196 [_buf appendString:@" - "];
198 if (!_refDate || [endDate isDateOnSameDay:_refDate])
201 date = [endDate hour:23 minute:59];
205 [self appendTimeInfoForDate:date
206 usingReferenceDate:_refDate
211 - (NSString *)titleForApt:(id)_apt :(NSCalendarDate *)_refDate {
214 title = [_apt valueForKey:@"title"];
215 if (![title isNotEmpty])
216 title = [self titlePlaceholder];
220 - (NSString *)shortTitleForApt:(id)_apt :(NSCalendarDate *)_refDate {
223 title = [self titleForApt:_apt :_refDate];
224 if ([title length] > 12)
225 title = [[title substringToIndex:11] stringByAppendingString:@"..."];
230 - (NSString *)singleLineFullDetailsForApt:(id)_apt :(NSCalendarDate *)_refDate {
231 NSMutableString *aptDescr;
234 aptDescr = [NSMutableString stringWithCapacity:60];
235 [self appendTimeInfoFromApt:_apt
236 usingReferenceDate:_refDate
238 if ((s = [_apt valueForKey:@"location"]) != nil) {
239 [aptDescr appendFormat:@"; (%@)", s];
241 if ((s = [self titleForApt:_apt :_refDate]) != nil)
242 [aptDescr appendFormat:@"; %@", s];
246 - (NSString *)fullDetailsForApt:(id)_apt :(NSCalendarDate *)_refDate {
247 NSMutableString *aptDescr;
250 aptDescr = [NSMutableString stringWithCapacity:60];
251 [self appendTimeInfoFromApt:_apt
252 usingReferenceDate:_refDate
254 if ((s = [_apt valueForKey:@"location"]) != nil) {
256 s = [[s substringToIndex:11] stringByAppendingString:@"..."];
257 [aptDescr appendFormat:@" (%@)", s];
259 if ((s = [self shortTitleForApt:_apt :_refDate]) != nil)
260 [aptDescr appendFormat:@"<br />%@", s];
265 - (NSString *)detailsForPrivateApt:(id)_apt :(NSCalendarDate *)_refDate {
266 NSMutableString *aptDescr;
269 aptDescr = [NSMutableString stringWithCapacity:40];
270 [self appendTimeInfoFromApt:_apt
271 usingReferenceDate:_refDate
273 if ((s = [self privateTitle]) != nil)
274 [aptDescr appendFormat:@"<br />%@", s];
278 - (NSString *)titleOnlyForPrivateApt:(id)_apt :(NSCalendarDate *)_refDate {
281 s = [self privateTitle];
287 - (NSString *)tooltipForApt:(id)_apt :(NSCalendarDate *)_refDate {
288 NSMutableString *aptDescr;
291 aptDescr = [NSMutableString stringWithCapacity:60];
292 [self appendTimeInfoFromApt:_apt
293 usingReferenceDate:_refDate
295 if ((s = [self titleForApt:_apt :_refDate]) != nil)
296 [aptDescr appendFormat:@"\n%@", s];
297 if ((s = [_apt valueForKey:@"location"]) != nil)
298 [aptDescr appendFormat:@"\n%@", s];
303 - (NSString *)tooltipForPrivateApt:(id)_apt :(NSCalendarDate *)_refDate {
304 NSMutableString *aptDescr;
307 aptDescr = [NSMutableString stringWithCapacity:25];
308 [self appendTimeInfoFromApt:_apt
309 usingReferenceDate:_refDate
311 if ((s = [self privateTitle]) != nil)
312 [aptDescr appendFormat:@"\n%@", s];
317 - (NSString *)suppressApt:(id)_apt :(NSCalendarDate *)_refDate {
321 @end /* SOGoAptFormatter */