2 Copyright (C) 2004 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
23 #include "SOGoAptFormatter.h"
26 @interface SOGoAptFormatter(PrivateAPI)
27 - (NSString *)titleForApt:(id)_apt;
28 - (NSString *)shortTitleForApt:(id)_apt;
29 - (NSTimeZone *)displayTZ;
30 - (void)appendTimeInfoFromApt:(id)_apt toBuffer:(NSMutableString *)_buf;
33 @implementation SOGoAptFormatter
35 - (id)initWithDisplayTimeZone:(NSTimeZone *)_tz {
36 if ((self = [super init])) {
37 self->tz = [_tz retain];
38 [self setFullDetails];
45 [self->privateTitle release];
52 self->formatAction = @selector(tooltipForApt:);
55 - (void)setFullDetails {
56 self->formatAction = @selector(fullDetailsForApt:);
59 - (void)setPrivateTooltip {
60 self->formatAction = @selector(tooltipForPrivateApt:);
63 - (void)setPrivateDetails {
64 self->formatAction = @selector(detailsForPrivateApt:);
67 - (void)setTitleOnly {
68 self->formatAction = @selector(titleForApt:);
71 - (void)setShortTitleOnly {
72 self->formatAction = @selector(shortTitleForApt:);
75 - (void)setPrivateSuppressAll {
76 self->formatAction = @selector(suppressApt:);
79 - (void)setPrivateTitle:(NSString *)_privateTitle {
80 ASSIGN(self->privateTitle, _privateTitle);
82 - (NSString *)privateTitle {
83 return self->privateTitle;
86 - (NSString *)stringForObjectValue:(id)_obj {
87 return [self performSelector:self->formatAction withObject:_obj];
92 - (NSTimeZone *)displayTZ {
96 - (void)appendTimeInfoFromApt:(id)_apt toBuffer:(NSMutableString *)_buf {
97 NSCalendarDate *startDate, *endDate;
101 startDate = [_apt valueForKey:@"startDate"];
102 [startDate setTimeZone:[self displayTZ]];
103 endDate = [_apt valueForKey:@"endDate"];
105 [endDate setTimeZone:[self displayTZ]];
106 spansRange = ![endDate isEqualToDate:startDate];
108 [_buf appendFormat:@"%02i:%02i",
109 [startDate hourOfDay],
110 [startDate minuteOfHour]];
112 [_buf appendFormat:@", %02i:%02i",
114 [endDate minuteOfHour]];
118 - (NSString *)titleForApt:(id)_apt {
119 return [_apt valueForKey:@"title"];
122 - (NSString *)shortTitleForApt:(id)_apt {
125 title = [self titleForApt:_apt];
126 if ([title length] > 12)
127 title = [[title substringToIndex:11] stringByAppendingString:@"..."];
132 - (NSString *)fullDetailsForApt:(id)_apt {
133 NSMutableString *aptDescr;
136 aptDescr = [NSMutableString stringWithCapacity:60];
137 [self appendTimeInfoFromApt:_apt toBuffer:aptDescr];
138 if ((s = [_apt valueForKey:@"location"]) != nil) {
140 s = [[s substringToIndex:11] stringByAppendingString:@"..."];
141 [aptDescr appendFormat:@" (%@)", s];
143 if ((s = [_apt valueForKey:@"title"]) != nil)
144 [aptDescr appendFormat:@"<br />%@", [self shortTitleForApt:_apt]];
149 - (NSString *)detailsForPrivateApt:(id)_apt {
150 NSMutableString *aptDescr;
153 aptDescr = [NSMutableString stringWithCapacity:40];
154 [self appendTimeInfoFromApt:_apt toBuffer:aptDescr];
155 if ((s = [self privateTitle]) != nil)
156 [aptDescr appendFormat:@"<br />%@", s];
160 - (NSString *)tooltipForApt:(id)_apt {
161 NSCalendarDate *startDate, *endDate;
162 NSMutableString *aptDescr;
167 startDate = [_apt valueForKey:@"startDate"];
168 [startDate setTimeZone:[self displayTZ]];
169 endDate = [_apt valueForKey:@"endDate"];
171 [endDate setTimeZone:[self displayTZ]];
172 spansRange = ![endDate isEqualToDate:startDate];
174 aptDescr = [NSMutableString stringWithCapacity:60];
175 [aptDescr appendString:@"appointment"];
176 [aptDescr appendFormat:@"\n%02i:%02i",
177 [startDate hourOfDay],
178 [startDate minuteOfHour]];
180 [aptDescr appendFormat:@" - %02i:%02i",
182 [endDate minuteOfHour]];
185 if ((s = [_apt valueForKey:@"title"]) != nil)
186 [aptDescr appendFormat:@"\n%@", s];
187 if ((s = [_apt valueForKey:@"location"]) != nil)
188 [aptDescr appendFormat:@"\n%@", s];
193 - (NSString *)tooltipForPrivateApt:(id)_apt {
194 NSCalendarDate *startDate, *endDate;
195 NSMutableString *aptDescr;
200 startDate = [_apt valueForKey:@"startDate"];
201 [startDate setTimeZone:[self displayTZ]];
202 endDate = [_apt valueForKey:@"endDate"];
204 [endDate setTimeZone:[self displayTZ]];
205 spansRange = ![endDate isEqualToDate:startDate];
207 aptDescr = [NSMutableString stringWithCapacity:25];
208 [aptDescr appendString:@"appointment"];
209 [aptDescr appendFormat:@"\n%02i:%02i",
210 [startDate hourOfDay],
211 [startDate minuteOfHour]];
213 [aptDescr appendFormat:@" - %02i:%02i",
215 [endDate minuteOfHour]];
218 if ((s = [self privateTitle]) != nil)
219 [aptDescr appendFormat:@"\n%@", s];
224 - (NSString *)suppressApt:(id)_apt {
228 @end /* SOGoAptFormatter */