From 965364f274b3304d5f283785f5c6b02af3f94860 Mon Sep 17 00:00:00 2001 From: znek Date: Mon, 21 Jun 2004 17:07:58 +0000 Subject: [PATCH] Work in progress. Highlighting works as expected, but Sunday is still broken (Note: we don't need to fix that for agenor) git-svn-id: http://svn.opengroupware.org/SOGo/trunk@56 d1b88da0-ebda-0310-925b-ed51d893ca5b --- ZideStore/UI-X/Common/calendar.css | 26 +- ZideStore/UI-X/Scheduler/GNUmakefile | 1 + .../UI-X/Scheduler/OGoAppointmentFormatter.h | 120 +++++ .../UI-X/Scheduler/OGoAppointmentFormatter.m | 454 ++++++++++++++++++ ZideStore/UI-X/Scheduler/OGoCalMonthView.h | 1 - ZideStore/UI-X/Scheduler/OGoCalView.h | 5 +- ZideStore/UI-X/Scheduler/OGoCalView.m | 13 + ZideStore/UI-X/Scheduler/OGoCalWeekOverview.m | 53 ++ .../UI-X/Scheduler/OGoCalWeekOverview.wox | 21 +- ZideStore/UI-X/Scheduler/OGoCalWeekView.h | 1 - 10 files changed, 687 insertions(+), 8 deletions(-) create mode 100644 ZideStore/UI-X/Scheduler/OGoAppointmentFormatter.h create mode 100644 ZideStore/UI-X/Scheduler/OGoAppointmentFormatter.m diff --git a/ZideStore/UI-X/Common/calendar.css b/ZideStore/UI-X/Common/calendar.css index e2a66ed7..00724bf4 100644 --- a/ZideStore/UI-X/Common/calendar.css +++ b/ZideStore/UI-X/Common/calendar.css @@ -19,9 +19,19 @@ } .weekoverview_title_hilite { + font-size: 10pt; + font-family: Arial, Helvetica, Verdana, Geneva, Tahoma, sans-serif; + letter-spacing: 0pt; + color: #000000; + background-color: #d2d2cc; font-weight: bold; } +.weekoverview_title_hilite a { + color: #0033cc; + text-decoration: none; +} + .weekoverview_title_daylink { font-size: 12pt; color: #0033cc; @@ -32,16 +42,28 @@ font-size: 8pt; } +.weekoverview_holidayinfo { + font-size: 8pt; + font-weight: bold; +} + .weekoverview_content { color: #FFFFFF; background-color: #e8e8e0; } +.weekoverview_content a { + color: #0000FF; + font-family: Arial, Helvetica, Verdana, Geneva, Tahoma, sans-serif; + letter-spacing: 0pt; + text-decoration: none; +} + .weekoverview_content_hilite { - background-color: #f5f5e9; + background-color: #fffff0; } -.weekoverview_content a { +.weekoverview_content_hilite a { color: #0000FF; font-family: Arial, Helvetica, Verdana, Geneva, Tahoma, sans-serif; letter-spacing: 0pt; diff --git a/ZideStore/UI-X/Scheduler/GNUmakefile b/ZideStore/UI-X/Scheduler/GNUmakefile index 1ac7bed9..1e713eb9 100644 --- a/ZideStore/UI-X/Scheduler/GNUmakefile +++ b/ZideStore/UI-X/Scheduler/GNUmakefile @@ -10,6 +10,7 @@ SchedulerUI_PRINCIPAL_CLASS = SchedulerUIProduct SchedulerUI_OBJC_FILES = \ SchedulerUIProduct.m \ + OGoAppointmentFormatter.m \ OGoCalView.m \ OGoCalWeekView.m \ OGoCalMonthView.m \ diff --git a/ZideStore/UI-X/Scheduler/OGoAppointmentFormatter.h b/ZideStore/UI-X/Scheduler/OGoAppointmentFormatter.h new file mode 100644 index 00000000..77f552b5 --- /dev/null +++ b/ZideStore/UI-X/Scheduler/OGoAppointmentFormatter.h @@ -0,0 +1,120 @@ +/* + Copyright (C) 2000-2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#ifndef __OGoAppointmentFormatter_H__ +#define __OGoAppointmentFormatter_H__ + +#import + +/* + Formatter to format appointment-dicts to readable strings: + + %[(dateFormat)]S + - startDate formatted with the dateFormat string + - if no dateFormat is defined, the default formats are used + - !!! dont forget the ()brakes !!! + %[(dateFormat)]E + - endDate formatted with the dateFormat string + - if no dateFormat is defined, the default formats are used + - !!! dont forget the ()brakes !!! + + %[length]T - title with the specified length + - if title has more chars than length overLengthString is appended + - if no length is defined, no limit is set + + %[max]P - participants + - if more than max participants at appointment + moreParticipantsString is appended + - if no max defined no limit is set + + %[length]L - location + - if location has more chars than length overLengthString is + appended + - if no length is defined, no limit is set + + Example: + format: @"%S - %E, \n%T"; + + */ + +@class NSCalendarDate; + +@interface OGoAppointmentFormatter : NSFormatter +{ +@protected + NSString *formatString; // default: @"%S - %E, \n%T" + + NSString *dateFormat; // default: @"%H:%M" + NSString *otherDayDateFormat; // default: @"%H:%M(%m-%d)" + NSString *otherYearDateFormat; // default: @"%H:%M(%Y-%m-%d)" + + NSString *toLongString; // default: @".." + NSString *moreParticipantsString; // default: @"..." + NSString *participantsSeparator; // default: @", " + + NSCalendarDate *relationDate; // if nil, dateFormat used as format + // to know whether its the same day, the same year or another year + + BOOL showFullNames; // try to show full names of participants +} + +//init +- (id)initWithFormat:(NSString *)_format; ++ (OGoAppointmentFormatter *)formatterWithFormat:(NSString *)_format; ++ (OGoAppointmentFormatter *)formatter; + +//accessors +- (void)setFormat:(NSString *)_format; +- (NSString *)format; + +- (void)setDateFormat:(NSString *)_format; +- (NSString *)dateFormat; + +- (void)setOtherDayDateFormat:(NSString *)_format; +- (NSString *)otherDayDateFormat; + +- (void)setOtherYearDateFormat:(NSString *)_format; +- (NSString *)otherYearDateFormat; + +- (void)setToLongString:(NSString *)_toLong; +- (NSString *)toLongString; + +- (void)setMoreParticipantsString:(NSString *)_more; +- (NSString *)moreParticipantsString; + +- (void)setParticipantsSeparator:(NSString *)_sep; +- (NSString *)participantsSeparator; + +- (void)setRelationDate:(NSCalendarDate *)_relation; +- (NSCalendarDate *)relationDate; + +- (void)setShowFullNames:(BOOL)_flag; +- (BOOL)showFullNames; + +// easy switches + +// this resets the date format +- (void)switchToAMPMTimes:(BOOL)_showAMPM; + +@end + +#endif diff --git a/ZideStore/UI-X/Scheduler/OGoAppointmentFormatter.m b/ZideStore/UI-X/Scheduler/OGoAppointmentFormatter.m new file mode 100644 index 00000000..4596cf27 --- /dev/null +++ b/ZideStore/UI-X/Scheduler/OGoAppointmentFormatter.m @@ -0,0 +1,454 @@ +/* + Copyright (C) 2000-2004 SKYRIX Software AG + + This file is part of OpenGroupware.org. + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ +// $Id$ + +#include "OGoAppointmentFormatter.h" +#import +#import +#import + +@implementation OGoAppointmentFormatter + +- (id)init { + if ((self = [super init])) { + [self setFormat:@"%S - %E, \n%T"]; + [self setDateFormat:@"%H:%M"]; + [self setOtherDayDateFormat:@"%H:%M(%m-%d)"]; + [self setOtherYearDateFormat:@"%H:%M(%Y-%m-%d)"]; + [self setToLongString:@".."]; + [self setMoreParticipantsString:@"..."]; + [self setParticipantsSeparator:@", "]; + [self setRelationDate:nil]; + self->showFullNames = NO; + } + return self; +} + +- (id)initWithFormat:(NSString *)_format { + if ((self = [self init])) { + [self setFormat:_format]; + } + return self; +} + ++ (OGoAppointmentFormatter *)formatterWithFormat:(NSString *)_format { + return AUTORELEASE([(OGoAppointmentFormatter *)[OGoAppointmentFormatter alloc] + initWithFormat:_format]); +} + ++ (OGoAppointmentFormatter *)formatter { + return AUTORELEASE([[OGoAppointmentFormatter alloc] init]); +} + +#if !LIB_FOUNDATION_BOEHM_GC +- (void)dealloc { + RELEASE(self->formatString); + RELEASE(self->dateFormat); + RELEASE(self->otherDayDateFormat); + RELEASE(self->otherYearDateFormat); + RELEASE(self->toLongString); + RELEASE(self->moreParticipantsString); + RELEASE(self->participantsSeparator); + RELEASE(self->relationDate); + + [super dealloc]; +} +#endif + +// accessors + +- (void)setFormat:(NSString *)_format { + ASSIGN(self->formatString,_format); +} +- (NSString *)format { + return self->formatString; +} + +- (void)setDateFormat:(NSString *)_format { + ASSIGN(self->dateFormat,_format); +} +- (NSString *)dateFormat { + return self->dateFormat; +} + +- (void)setOtherDayDateFormat:(NSString *)_format { + ASSIGN(self->otherDayDateFormat,_format); +} +- (NSString *)otherDayDateFormat { + return self->otherDayDateFormat; +} + +- (void)setOtherYearDateFormat:(NSString *)_format { + ASSIGN(self->otherYearDateFormat,_format); +} +- (NSString *)otherYearDateFormat { + return self->otherYearDateFormat; +} + +- (void)setToLongString:(NSString *)_toLong { + ASSIGN(self->toLongString,_toLong); +} +- (NSString *)toLongString { + return self->toLongString; +} + +- (void)setMoreParticipantsString:(NSString *)_more { + ASSIGN(self->moreParticipantsString,_more); +} +- (NSString *)moreParticipantsString { + return self->moreParticipantsString; +} + +- (void)setParticipantsSeparator:(NSString *)_sep { + ASSIGN(self->participantsSeparator,_sep); +} +- (NSString *)participantsSeparator { + return self->participantsSeparator; +} + +- (void)setRelationDate:(NSCalendarDate *)_relation { + ASSIGN(self->relationDate,_relation); +} +- (NSCalendarDate *)relationDate { + return self->relationDate; +} + +- (void)setShowFullNames:(BOOL)_flag { + self->showFullNames = _flag; +} +- (BOOL)showFullNames { + return self->showFullNames; +} + +// easy switching +- (void)switchToAMPMTimes:(BOOL)_showAMPM { + if (_showAMPM) { + [self setDateFormat:@"%I:%M %p"]; + [self setOtherDayDateFormat:@"%I:%M %p(%m-%d)"]; + [self setOtherYearDateFormat:@"%I:%M %p(%Y-%m-%d)"]; + } + else { + [self setDateFormat:@"%H:%M"]; + [self setOtherDayDateFormat:@"%H:%M(%m-%d)"]; + [self setOtherYearDateFormat:@"%H:%M(%Y-%m-%d)"]; + } +} + +// formatting helpers + +- (NSString *)formatDate:(NSCalendarDate *)_date + withFormat:(NSString *)_format +{ + NSString *f; + NSCalendarDate *rel; + + rel = self->relationDate; + + if (_format == nil) { + if (rel == nil) { + f = self->dateFormat; + } + else if ([_date isDateOnSameDay:rel]) { + f = self->dateFormat; + } + else if ([_date yearOfCommonEra] == [rel yearOfCommonEra]) { + f = self->otherDayDateFormat; + } + else { + f = self->otherYearDateFormat; + } + } + else { + f = _format; + } + return [_date descriptionWithCalendarFormat:f]; +} + +- (NSString *)formatStartDateFromApt:(id)_apt + withFormat:(NSString *)_format +{ + return [self formatDate:[_apt valueForKey:@"startDate"] + withFormat:_format]; +} + +- (NSString *)formatEndDateFromApt:(id)_apt + withFormat:(NSString *)_format +{ + return [self formatDate:[_apt valueForKey:@"endDate"] + withFormat:_format]; +} + +- (NSString *)stringForParticipant:(id)_part { + id label = nil; + + if ([[_part valueForKey:@"isTeam"] boolValue]) { + if ((label = [_part valueForKey:@"info"]) == nil) + label = [_part valueForKey:@"description"]; + } + else if (self->showFullNames) { + label = [_part valueForKey:@"firstname"]; + label = ([label length]) + ? [label stringByAppendingFormat:@" %@", [_part valueForKey:@"name"]] + : [_part valueForKey:@"name"]; + } + else if ([[_part valueForKey:@"isAccount"] boolValue]) { + label = [_part valueForKey:@"login"]; + } + else { + if ((label = [_part valueForKey:@"name"]) == nil) { + if ((label = [_part valueForKey:@"info"]) == nil) + label = [_part valueForKey:@"description"]; + } + } + + if (![label isNotNull]) + label = @"*"; + + return label; +} + +- (NSString *)participantsForApt:(id)_apt + withMaxCount:(NSString *)_cnt { + NSArray *p; + int max; + int cnt; + NSMutableString *pString; + + pString = [NSMutableString stringWithCapacity:255]; + + if (_cnt == nil) { + max = -1; // no limit + } + else { + max = [_cnt intValue]; + } + + p = [_apt valueForKey:@"participants"]; + + p = [p sortedArrayUsingKeyOrderArray: + [NSArray arrayWithObjects: + [EOSortOrdering sortOrderingWithKey:@"isAccount" + selector:EOCompareAscending], + [EOSortOrdering sortOrderingWithKey:@"login" + selector:EOCompareAscending], + nil]]; + + max = ((max > [p count]) || (max == -1)) + ? [p count] + : max; + + for (cnt = 0; cnt < max; cnt++) { + + if (cnt != 0) + [pString appendString:self->participantsSeparator]; + + [pString appendString: + [self stringForParticipant:[p objectAtIndex:cnt]]]; + } + + if (max < [p count]) { + [pString appendString:self->moreParticipantsString]; + } + + return pString; +} + +- (NSString *)titleForApt:(id)_apt withMaxLength:(NSString *)_length { + NSString *t = nil; + int l; + + l = (_length == nil) + ? -1 + : [_length intValue]; + + t = [_apt valueForKey:@"title"]; + if (!t) return @"*"; + + if (l > 1) { + if ([t length] > l) { + t = [t substringToIndex:(l - 2)]; + t = [t stringByAppendingString:self->toLongString]; + } + } + + if (l == 0) + t = @"*"; + + return t; +} + +- (NSString *)locationForApt:(id)_apt withMaxLength:(NSString *)_length { + NSString *t = nil; + int l; + + l = (_length == nil) + ? -1 + : [_length intValue]; + + t = [_apt valueForKey:@"location"]; + if (![t isNotNull] || + [t length] == 0 || + [t isEqualToString:@" "]) + return @""; + + if (l > 1) { + if ([t length] > l) { + t = [t substringToIndex:(l - 2)]; + t = [t stringByAppendingString:self->toLongString]; + } + } + + if (l == 0) + t = @""; + + return t; +} + +- (NSString *)resourcesForApt:(id)_apt withMaxLength:(NSString *)_length { + NSString *t = nil; + int l; + + l = (_length == nil) + ? -1 + : [_length intValue]; + + t = [_apt valueForKey:@"resourceNames"]; + if (![t isNotNull] || + [t length] == 0 || + [t isEqualToString:@" "]) + return @""; + + if (l > 1) { + if ([t length] > l) { + t = [t substringToIndex:(l - 2)]; + t = [t stringByAppendingString:self->toLongString]; + } + } + + if (l == 0) + t = @""; + + return t; +} + +// NSFormatter stuff + +- (NSString *)stringForObjectValue:(id)_obj { + NSMutableString *newString; + int cnt; + int length; + BOOL replaceMode = NO; + NSString *helper = nil; + NSCharacterSet *digits; + + newString = [NSMutableString stringWithCapacity:255]; + length = [self->formatString length]; + digits = [NSCharacterSet decimalDigitCharacterSet]; + + // NSLog(@"Formatting with format: %@", self->formatString); + + for (cnt = 0; cnt < length; cnt++) { + unichar c; + c = [self->formatString characterAtIndex:cnt]; + // NSLog(@"Character is: %c mode is: %@", c, + // [NSNumber numberWithBool:replaceMode]); + if (replaceMode) { + if (c == 'S') { + [newString appendString: + [self formatStartDateFromApt:_obj withFormat:helper]]; + helper = nil; + replaceMode = NO; + } + else if (c == 'E') { + [newString appendString: + [self formatEndDateFromApt:_obj withFormat:helper]]; + helper = nil; + replaceMode = NO; + } + else if (c == 'P') { + [newString appendString: + [self participantsForApt:_obj withMaxCount:helper]]; + helper = nil; + replaceMode = NO; + } + else if (c == 'T') { + [newString appendString: + [self titleForApt:_obj withMaxLength:helper]]; + helper = nil; + replaceMode = NO; + } + else if (c == 'L') { + NSString *l; + + l = [self locationForApt:_obj withMaxLength:helper]; + + if ([l length] > 0) + [newString appendString:l]; + helper = nil; + replaceMode = NO; + } + else if (c == 'R') { + NSString *r; + + r = [self resourcesForApt:_obj withMaxLength:helper]; + + if ([r length] > 0) + [newString appendString:r]; + helper = nil; + replaceMode = NO; + } + else if (c == '(') { + int end; + NSRange r = NSMakeRange(cnt,length-cnt); + + r = [self->formatString rangeOfString:@")" + options:0 range:r]; + + end = r.location - 1; + r = NSMakeRange(cnt+1, end-cnt-1); + + helper = [self->formatString substringWithRange:r]; + cnt = end + 1; + } + else if ([digits characterIsMember:c]) { + helper = (helper == nil) + ? [NSString stringWithFormat:@"%c",c] + : [NSString stringWithFormat:@"%@%c", helper, c]; + } + else { + NSLog(@"UNKNOWN FORMAT CHARACTER '%c'!!",c); + replaceMode = NO; + helper = nil; + } + } else { + if (c == '%') { + replaceMode = YES; + } + else { + [newString appendFormat:@"%c", c]; + } + } + } + + return newString; +} + +@end diff --git a/ZideStore/UI-X/Scheduler/OGoCalMonthView.h b/ZideStore/UI-X/Scheduler/OGoCalMonthView.h index f2c79e58..59fde93f 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalMonthView.h +++ b/ZideStore/UI-X/Scheduler/OGoCalMonthView.h @@ -16,7 +16,6 @@ } - (NSDictionary *)prevMonthQueryParameters; -- (NSDictionary *)thisMonthQueryParameters; - (NSDictionary *)nextMonthQueryParameters; @end diff --git a/ZideStore/UI-X/Scheduler/OGoCalView.h b/ZideStore/UI-X/Scheduler/OGoCalView.h index 76984038..c65246eb 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalView.h +++ b/ZideStore/UI-X/Scheduler/OGoCalView.h @@ -18,7 +18,10 @@ - (NSArray *)appointments; - (id)appointment; - +- (BOOL)showFullNames; +- (BOOL)showAMPMDates; +- (NSCalendarDate *)referenceDateForFormatter; + /* URLs */ - (NSString *)appointmentViewURL; diff --git a/ZideStore/UI-X/Scheduler/OGoCalView.m b/ZideStore/UI-X/Scheduler/OGoCalView.m index 9f1b9228..ebaeffaf 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalView.m +++ b/ZideStore/UI-X/Scheduler/OGoCalView.m @@ -32,6 +32,19 @@ return self->appointment; } +- (BOOL)showFullNames { + return YES; +} + +- (BOOL)showAMPMDates { + return NO; +} + +- (NSCalendarDate *)referenceDateForFormatter { + return [self selectedDate]; +} + + /* URLs */ - (NSString *)appointmentViewURL { diff --git a/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.m b/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.m index 2f9ec5f3..bcc5abe8 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.m +++ b/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.m @@ -32,6 +32,8 @@ #include "common.h" #include +#include "OGoAppointmentFormatter.h" + @implementation OGoCalWeekOverview @@ -78,4 +80,55 @@ return [self queryParametersBySettingSelectedDate:self->currentDay]; } +/* style sheet */ + +- (NSString *)titleStyle { + if([self->currentDay isToday]) + return @"weekoverview_title_hilite"; + return @"weekoverview_title"; +} + +- (NSString *)contentStyle { + if([self->currentDay isToday]) + return @"weekoverview_content_hilite"; + return @"weekoverview_content"; +} + +- (NSDictionary *)aptTypeDict { + return nil; +} + +- (NSString *)aptTypeLabel { + return @"aptLabel"; +} + +- (NSString *)aptTypeIcon { + return @""; +} + +- (NSString *)shortTextForApt { + OGoAppointmentFormatter *f; + + f = [OGoAppointmentFormatter formatterWithFormat: + @"%S - %E;\n%T;\n%L;\n%5P;\n%50R"]; + [f setRelationDate:[self referenceDateForFormatter]]; + [f setShowFullNames:[self showFullNames]]; + if([self showAMPMDates]) + [f switchToAMPMTimes:YES]; + + return [NSString stringWithFormat:@"%@:\n%@", + [self aptTypeLabel], + [f stringForObjectValue:self->appointment]]; +} + +- (BOOL)hasDayInfo { + return YES: +} + +- (BOOL)hasHoldidayInfo { +} + +- (NSArray *)allDayApts { +} + @end /* OGoCalWeekOverview */ diff --git a/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.wox b/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.wox index 39b0dbed..39753fbd 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.wox +++ b/ZideStore/UI-X/Scheduler/OGoCalWeekOverview.wox @@ -68,7 +68,7 @@
- printview + printview proposal @@ -86,10 +86,15 @@ const:startDateKey="startDate" const:endDateKey="endDate" const:titleStyle="weekoverview_title" - const:contentStyle="weekoverview_content" + contentStyle="contentStyle" > - +
+ + + + + + + + + + diff --git a/ZideStore/UI-X/Scheduler/OGoCalWeekView.h b/ZideStore/UI-X/Scheduler/OGoCalWeekView.h index c01f9507..c1fde865 100644 --- a/ZideStore/UI-X/Scheduler/OGoCalWeekView.h +++ b/ZideStore/UI-X/Scheduler/OGoCalWeekView.h @@ -12,7 +12,6 @@ /* Query Parameters */ - (NSDictionary *)prevWeekQueryParameters; -- (NSDictionary *)thisWeekQueryParameters; - (NSDictionary *)nextWeekQueryParameters; @end -- 2.39.5