]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalAptListView.m
92d227d8f678d3569b511fdae4304ccbc858c0b4
[scalable-opengroupware.org] / UI / Scheduler / UIxCalAptListView.m
1 /* UIxCalAptListView.m - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSDate.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSString.h>
26
27 #import <NGExtensions/NSCalendarDate+misc.h>
28 #import <Appointments/SOGoAppointmentFolder.h>
29
30 #import <SOGoUI/SOGoDateFormatter.h>
31
32 #import "UIxCalAptListView.h"
33
34 @implementation UIxCalAptListView
35
36 - (id) init
37 {
38   if ((self = [super init]))
39     {
40       startDate = nil;
41       endDate = nil;
42     }
43
44   return self;
45 }
46
47 - (void) setCurrentAppointment: (NSDictionary *) apt
48 {
49   currentAppointment = apt;
50 }
51
52 - (NSDictionary *) currentAppointment
53 {
54   return currentAppointment;
55 }
56
57 - (NSCalendarDate *) startDate
58 {
59   NSCalendarDate *today;
60   NSString *filterPopup;
61
62   if (!startDate)
63     {
64       filterPopup = [self queryParameterForKey: @"filterpopup"];
65       today = [[NSCalendarDate date] beginOfDay];
66       if (!filterPopup || ![filterPopup length])
67         startDate = today;
68       else if ([filterPopup isEqualToString: @"view_selectedday"])
69         startDate = [[self selectedDate] beginOfDay];
70       else if ([filterPopup isEqualToString: @"view_thismonth"])
71         startDate = [today firstDayOfMonth];
72       else if ([filterPopup isEqualToString: @"view_all"])
73         startDate = [NSCalendarDate dateWithTimeIntervalSince1970: 0];
74       else
75         startDate = today;
76     }
77
78   return startDate;
79 }
80
81 - (NSCalendarDate *) endDate
82 {
83   NSCalendarDate *today;
84   NSString *filterPopup;
85
86   if (!endDate)
87     {
88       filterPopup = [self queryParameterForKey: @"filterpopup"];
89
90       today = [[NSCalendarDate date] endOfDay];
91       if (!filterPopup || ![filterPopup length]
92           || [filterPopup isEqualToString: @"view_today"])
93         endDate = today;
94       else if ([filterPopup isEqualToString: @"view_all"]
95                || [filterPopup isEqualToString: @"view_future"])
96         endDate = [NSCalendarDate dateWithTimeIntervalSince1970: 0x7fffffff];
97       else if ([filterPopup isEqualToString: @"view_thismonth"])
98         endDate = [today lastDayOfMonth];
99       else if ([filterPopup isEqualToString: @"view_selectedday"])
100         endDate = [[self selectedDate] endOfDay];
101       else if ([filterPopup isEqualToString: @"view_next7"])
102         endDate = [today dateByAddingYears: 0 months: 0 days: 7];
103       else if ([filterPopup isEqualToString: @"view_next14"])
104         endDate = [today dateByAddingYears: 0 months: 0 days: 14];
105       else if ([filterPopup isEqualToString: @"view_next31"])
106         endDate = [today dateByAddingYears: 0 months: 1 days: 0];
107       else
108         endDate = today;
109     }
110
111   return endDate;
112 }
113
114 - (SOGoDateFormatter *) itemDateFormatter
115 {
116   SOGoDateFormatter *fmt;
117   
118   fmt = [[SOGoDateFormatter alloc] initWithLocale: [self locale]];
119   [fmt autorelease];
120   [fmt setFullWeekdayNameAndDetails];
121
122   return fmt;
123 }
124
125 - (NSString *) currentStartTime
126 {
127   NSCalendarDate *date;
128
129   date = [NSCalendarDate dateWithTimeIntervalSince1970:
130                            [[currentAppointment objectForKey: @"startdate"]
131                              intValue]];
132   [date setTimeZone: timeZone];
133
134   return [[self itemDateFormatter] stringForObjectValue: date];
135 }
136
137 - (NSString *) currentEndTime
138 {
139   NSCalendarDate *date;
140
141   date = [NSCalendarDate dateWithTimeIntervalSince1970:
142                            [[currentAppointment objectForKey: @"enddate"]
143                              intValue]];
144   [date setTimeZone: timeZone];
145
146   return [[self itemDateFormatter] stringForObjectValue: date];
147 }
148
149 - (NSString *) currentLocation
150 {
151   return [currentAppointment objectForKey: @"location"];
152 }
153
154 - (NSString *) currentSerialDay
155 {
156   NSCalendarDate *date;
157   int intDate;
158
159   intDate = [[currentAppointment objectForKey: @"startdate"] intValue];
160   date = [NSCalendarDate dateWithTimeIntervalSince1970: intDate];
161   [date setTimeZone: timeZone];
162
163   return [NSString stringWithFormat: @"%d%.2d%.2d",
164                    [date yearOfCommonEra],
165                    [date monthOfYear],
166                    [date dayOfMonth]];
167 }
168
169 - (NSString *) currentSerialHour
170 {
171   NSCalendarDate *date;
172   int intDate;
173
174   intDate = [[currentAppointment objectForKey: @"startdate"] intValue];
175   date = [NSCalendarDate dateWithTimeIntervalSince1970: intDate];
176   [date setTimeZone: timeZone];
177
178   return [NSString stringWithFormat: @"%.2d%.2d",
179                    [date hourOfDay],
180                    [date minuteOfHour]];
181 }
182
183 @end