]> err.no Git - scalable-opengroupware.org/blob - SOGo/UI/Scheduler/UIxCalDateLabel.m
d594afc7df5b6d558b7d974ae37a94c5722eddf3
[scalable-opengroupware.org] / SOGo / 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
41 @implementation UIxCalDateLabel
42
43 - (void)dealloc {
44   [self->selection release];
45   [self->startDate release];
46   [self->endDate   release];
47   [super dealloc];
48 }
49
50 /* accessors */
51
52 - (void)setSelection:(NSString *)_selection {
53   ASSIGNCOPY(self->selection, _selection);
54 }
55 - (NSString *)selection {
56   return self->selection;
57 }
58
59 - (void)setStartDate:(NSCalendarDate *)_date {
60   ASSIGN(self->startDate, _date);
61 }
62 - (NSCalendarDate *)startDate {
63   return self->startDate;
64 }
65
66 - (void)setEndDate:(NSCalendarDate *)_date {
67   ASSIGN(self->endDate, _date);
68 }
69 - (NSCalendarDate *)endDate {
70   return self->endDate;
71 }
72
73 - (NSString *)label {
74   NSString *key = [self selection];
75   
76   if([key isEqualToString:@"day"])
77     return [self dayLabel];
78   if ([key isEqualToString:@"week"])
79     return [self weekLabel];
80   if ([key isEqualToString:@"month"])
81     return [self monthLabel];
82   return [self yearLabel];
83 }
84
85 - (NSString *)dayLabel {
86   NSString *fmt;
87   
88   fmt = [self labelForKey:@"dayLabelFormat"];
89   return [self->startDate descriptionWithCalendarFormat:fmt];
90 }
91
92 - (NSString *)weekLabel {
93   NSString *label;
94   
95   label = [self localizedNameForMonthOfYear:[self->startDate monthOfYear]];
96   label = [NSString stringWithFormat:@"%@ %d",
97                     label,
98                     [self->startDate yearOfCommonEra]];
99   if ([self->startDate monthOfYear] != [self->endDate monthOfYear]) {
100     NSString *le;
101     
102     le = [self localizedNameForMonthOfYear:[self->endDate monthOfYear]];
103     label = [NSString stringWithFormat:@"<nobr>%@ / %@ %d</nobr>",
104                       label, le,
105                       [self->endDate yearOfCommonEra]];
106   }
107   return label;
108 }
109
110 - (NSString *)monthLabel {
111   NSString *l;
112   unsigned diff;
113
114   diff = [self->startDate monthsBetweenDate:self->endDate];
115   if (diff == 0) {
116     l = [self localizedNameForMonthOfYear:[self->startDate monthOfYear]];
117   }
118   else {
119     NSCalendarDate *date;
120
121     date = [self->startDate dateByAddingYears:0 months:0 days:15];
122     l    = [self localizedNameForMonthOfYear:[date monthOfYear]];
123   }
124   return [NSString stringWithFormat:@"%@ %d",
125                    l, [self->startDate yearOfCommonEra]];
126 }
127
128 - (NSString *)yearLabel {
129   return [NSString stringWithFormat:@"%d",
130                    [self->startDate yearOfCommonEra]]; 
131 }
132
133 @end /* UIxCalDateLabel */