]> err.no Git - scalable-opengroupware.org/blob - SoObjects/Appointments/SOGoAptMailNotification.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1146 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / Appointments / SOGoAptMailNotification.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3  
4   This file is part of OpenGroupware.org.
5  
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import <Foundation/NSCharacterSet.h>
23 #import <Foundation/NSCalendarDate.h>
24 #import <Foundation/NSTimeZone.h>
25
26 #import <NGObjWeb/WOActionResults.h>
27 #import <NGObjWeb/WOMessage.h>
28 #import <NGExtensions/NSObject+Logs.h>
29 #import <NGCards/iCalEntityObject.h>
30
31 #import "SOGoAptMailNotification.h"
32
33 @interface SOGoAptMailNotification (PrivateAPI)
34 - (BOOL)isSubject;
35 - (void)setIsSubject:(BOOL)_isSubject;
36 @end
37
38 @implementation SOGoAptMailNotification
39
40 static NSCharacterSet *wsSet  = nil;
41 static NSTimeZone     *EST = nil;
42
43 + (void)initialize {
44   static BOOL didInit = NO;
45
46   if (didInit) return;
47   didInit = YES;
48
49   wsSet = [[NSCharacterSet whitespaceAndNewlineCharacterSet] retain];
50   EST   = [[NSTimeZone timeZoneWithAbbreviation:@"EST"] retain];
51 }
52
53 - (void)dealloc {
54   [self->oldApt       release];
55   [self->newApt       release];
56   [self->homePageURL  release];
57   [self->viewTZ       release];
58
59   [self->oldStartDate release];
60   [self->newStartDate release];
61   [super dealloc];
62 }
63
64 - (id)oldApt {
65   return self->oldApt;
66 }
67 - (void)setOldApt:(iCalEntityObject *)_oldApt {
68   ASSIGN(self->oldApt, _oldApt);
69 }
70
71 - (id)newApt {
72   return self->newApt;
73 }
74
75 - (void)setNewApt:(iCalEntityObject *) _newApt
76 {
77   ASSIGN(self->newApt, _newApt);
78 }
79
80 - (NSString *)homePageURL {
81   return self->homePageURL;
82 }
83 - (void)setHomePageURL:(NSString *)_homePageURL {
84   ASSIGN(self->homePageURL, _homePageURL);
85 }
86
87 - (NSString *)appointmentURL {
88   NSString *aptUID;
89   
90   aptUID = [[self newApt] uid];
91   return [NSString stringWithFormat:@"%@/Calendar/%@/edit?mail-invitation=yes",
92                                     [self homePageURL],
93                                     aptUID];
94 }
95
96 - (NSTimeZone *)viewTZ {
97   if (self->viewTZ) return self->viewTZ;
98   return EST;
99 }
100 - (void)setViewTZ:(NSTimeZone *)_viewTZ {
101   ASSIGN(self->viewTZ, _viewTZ);
102 }
103
104 - (BOOL)isSubject {
105   return self->isSubject;
106 }
107 - (void)setIsSubject:(BOOL)_isSubject {
108   self->isSubject = _isSubject;
109 }
110
111
112 /* Helpers */
113
114 - (NSCalendarDate *)oldStartDate {
115   if (!self->oldStartDate) {
116     ASSIGN(self->oldStartDate, [[self oldApt] startDate]);
117     [self->oldStartDate setTimeZone:[self viewTZ]];
118   }
119   return self->oldStartDate;
120 }
121
122 - (NSCalendarDate *)newStartDate {
123   if (!self->newStartDate) {
124     ASSIGN(self->newStartDate, [[self newApt] startDate]);
125     [self->newStartDate setTimeZone:[self viewTZ]];
126   }
127   return self->newStartDate;
128 }
129
130 /* Generate Response */
131
132 - (NSString *)getSubject {
133   NSString *subject;
134
135   [self setIsSubject:YES];
136   subject = [[[self generateResponse] contentAsString]
137                                       stringByTrimmingCharactersInSet:wsSet];
138   if (!subject) {
139     [self errorWithFormat:@"Failed to properly generate subject! Please check "
140                           @"template for component '%@'!",
141                           [self name]];
142     subject = @"ERROR: missing subject!";
143   }
144   return subject;
145 }
146
147 - (NSString *)getBody {
148   [self setIsSubject:NO];
149   return [[self generateResponse] contentAsString];
150 }
151
152 @end