]> err.no Git - scalable-opengroupware.org/blob - UI/Scheduler/UIxCalDateLabel.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1045 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / Scheduler / UIxCalDateLabel.m
1 /*
2   Copyright (C) 2004 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 // $Id$
22
23 #include <SOGoUI/UIxComponent.h>
24
25 @interface UIxCalDateLabel : UIxComponent
26 {
27   NSString       *selection;
28   NSCalendarDate *startDate;
29   NSCalendarDate *endDate;
30 }
31
32 - (NSString *)dayLabel;
33 - (NSString *)weekLabel;
34 - (NSString *)monthLabel;
35 - (NSString *)yearLabel;
36
37 @end
38
39 #include "common.h"
40 #include <NGCards/NGCards.h>
41
42 @implementation UIxCalDateLabel
43
44 - (void)dealloc {
45   [self->selection release];
46   [self->startDate release];
47   [self->endDate   release];
48   [super dealloc];
49 }
50
51 /* accessors */
52
53 - (void)setSelection:(NSString *)_selection {
54   ASSIGNCOPY(self->selection, _selection);
55 }
56 - (NSString *)selection {
57   return self->selection;
58 }
59
60 - (void)setStartDate:(NSCalendarDate *)_date {
61   ASSIGN(self->startDate, _date);
62 }
63 - (NSCalendarDate *)startDate {
64   return self->startDate;
65 }
66
67 - (void)setEndDate:(NSCalendarDate *)_date {
68   ASSIGN(self->endDate, _date);
69 }
70 - (NSCalendarDate *)endDate {
71   return self->endDate;
72 }
73
74 - (NSString *)label {
75   NSString *key = [self selection];
76   
77   if([key isEqualToString:@"day"])
78     return [self dayLabel];
79   if ([key isEqualToString:@"week"])
80     return [self weekLabel];
81   if ([key isEqualToString:@"month"])
82     return [self monthLabel];
83   return [self yearLabel];
84 }
85
86 - (NSString *)dayLabel {
87   NSString *fmt;
88   
89   fmt = [self labelForKey:@"dayLabelFormat"];
90   return [self->startDate descriptionWithCalendarFormat:fmt];
91 }
92
93 - (NSString *)weekLabel {
94   NSString *label, *le;
95   
96   if ([self->startDate monthOfYear] == [self->endDate monthOfYear])
97     label = [NSString stringWithFormat:@"%@ %d",
98                       [self localizedNameForMonthOfYear: [self->startDate monthOfYear]],
99                       [self->startDate yearOfCommonEra]];
100   else
101     {
102       le = [self localizedNameForMonthOfYear:[self->endDate monthOfYear]];
103       label = [NSString stringWithFormat:@"<nobr>%@ / %@ %d</nobr>",
104                         label, le,
105                         [self->endDate yearOfCommonEra]];
106     }
107
108   return label;
109 }
110
111 - (NSString *)monthLabel {
112   NSString *l;
113   unsigned diff;
114
115   diff = [self->startDate monthsBetweenDate:self->endDate];
116   if (diff == 0) {
117     l = [self localizedNameForMonthOfYear:[self->startDate monthOfYear]];
118   }
119   else {
120     NSCalendarDate *date;
121
122     date = [self->startDate dateByAddingYears:0 months:0 days:15];
123     l    = [self localizedNameForMonthOfYear:[date monthOfYear]];
124   }
125   return [NSString stringWithFormat:@"%@ %d",
126                    l, [self->startDate yearOfCommonEra]];
127 }
128
129 - (NSString *)yearLabel {
130   return [NSString stringWithFormat:@"%d",
131                    [self->startDate yearOfCommonEra]]; 
132 }
133
134 @end /* UIxCalDateLabel */