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