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