2006-08-19 00:55:46 +02:00
|
|
|
/* UIxCalMainView.m - this file is part of SOGo
|
|
|
|
*
|
2009-04-01 15:49:24 +02:00
|
|
|
* Copyright (C) 2006-2009 Inverse inc.
|
2006-08-19 00:55:46 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-08-22 21:24:48 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2009-04-01 15:49:24 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2006-08-22 21:24:48 +02:00
|
|
|
#import <Foundation/NSString.h>
|
2007-09-15 00:01:02 +02:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2006-08-22 21:24:48 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
2007-01-04 15:37:07 +01:00
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2008-02-04 23:22:14 +01:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2006-10-14 01:31:45 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
|
2007-01-04 15:37:07 +01:00
|
|
|
#import <SOGo/SOGoPermissions.h>
|
2006-10-14 01:31:45 +02:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2006-10-14 01:31:45 +02:00
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
|
|
|
|
2006-08-19 00:55:46 +02:00
|
|
|
#import "UIxCalMainView.h"
|
|
|
|
|
2006-10-12 23:00:35 +02:00
|
|
|
#import <Appointments/SOGoAppointmentFolder.h>
|
|
|
|
|
2006-08-19 00:55:46 +02:00
|
|
|
@implementation UIxCalMainView
|
2006-08-22 21:24:48 +02:00
|
|
|
|
2009-08-19 19:19:32 +02:00
|
|
|
- (void) checkDefaultModulePreference
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2009-08-19 19:19:32 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
if ([ud rememberLastModule])
|
|
|
|
[ud setLoginModule: @"Calendar"];
|
2009-08-19 19:19:32 +02:00
|
|
|
}
|
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
- (void) _setupContext
|
|
|
|
{
|
|
|
|
SOGoUser *activeUser;
|
|
|
|
NSString *module;
|
|
|
|
SOGoAppointmentFolders *clientObject;
|
|
|
|
|
2009-08-19 19:19:32 +02:00
|
|
|
[self checkDefaultModulePreference];
|
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
activeUser = [context activeUser];
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
|
|
|
|
module = [clientObject nameInContainer];
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
us = [activeUser userSettings];
|
|
|
|
moduleSettings = [us objectForKey: module];
|
2008-02-04 23:22:14 +01:00
|
|
|
if (!moduleSettings)
|
|
|
|
{
|
2009-03-24 18:33:15 +01:00
|
|
|
moduleSettings = [NSMutableDictionary dictionary];
|
2009-11-29 05:19:32 +01:00
|
|
|
[us setObject: moduleSettings forKey: module];
|
2008-02-04 23:22:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-22 21:24:48 +02:00
|
|
|
- (NSArray *) monthMenuItems
|
|
|
|
{
|
2009-03-24 18:33:15 +01:00
|
|
|
static NSMutableArray *monthMenuItems = nil;
|
2006-08-22 21:24:48 +02:00
|
|
|
unsigned int count;
|
2009-11-29 05:19:32 +01:00
|
|
|
|
2006-08-22 21:24:48 +02:00
|
|
|
if (!monthMenuItems)
|
|
|
|
{
|
2009-03-24 18:33:15 +01:00
|
|
|
monthMenuItems = [[NSMutableArray alloc] initWithCapacity: 12];
|
2006-08-22 21:24:48 +02:00
|
|
|
for (count = 1; count < 13; count++)
|
|
|
|
[monthMenuItems addObject:
|
|
|
|
[NSString stringWithFormat: @"%.2d", count]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return monthMenuItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMonthMenuItem: (NSString *) aMonthMenuItem
|
|
|
|
{
|
|
|
|
monthMenuItem = aMonthMenuItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) monthMenuItem
|
|
|
|
{
|
|
|
|
return monthMenuItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) monthMenuItemLabel
|
|
|
|
{
|
|
|
|
return [self localizedNameForMonthOfYear: [monthMenuItem intValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) yearMenuItems
|
|
|
|
{
|
2009-03-24 18:33:15 +01:00
|
|
|
static NSMutableArray *yearMenuItems = nil;
|
2006-08-22 21:24:48 +02:00
|
|
|
int count, year;
|
|
|
|
|
|
|
|
if (!yearMenuItems)
|
|
|
|
{
|
|
|
|
year = [[NSCalendarDate date] yearOfCommonEra];
|
2009-03-24 18:33:15 +01:00
|
|
|
yearMenuItems = [[NSMutableArray alloc] initWithCapacity: 11];
|
2006-08-22 21:24:48 +02:00
|
|
|
for (count = -5; count < 6; count++)
|
|
|
|
[yearMenuItems addObject: [NSNumber numberWithInt: year + count]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return yearMenuItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setYearMenuItem: (NSNumber *) aYearMenuItem
|
|
|
|
{
|
|
|
|
yearMenuItem = aYearMenuItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) yearMenuItem
|
|
|
|
{
|
|
|
|
return yearMenuItem;
|
|
|
|
}
|
|
|
|
|
2008-03-25 20:59:13 +01:00
|
|
|
- (NSString *) verticalDragHandleStyle
|
2008-02-04 23:22:14 +01:00
|
|
|
{
|
2008-08-30 01:58:16 +02:00
|
|
|
NSString *vertical;
|
|
|
|
|
2008-07-11 19:32:59 +02:00
|
|
|
[self _setupContext];
|
2008-08-30 01:58:16 +02:00
|
|
|
vertical = [moduleSettings objectForKey: @"DragHandleVertical"];
|
2008-02-04 23:22:14 +01:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
return ((vertical && [vertical intValue] > 0) ? (id)[vertical stringByAppendingFormat: @"px"] : nil);
|
2008-03-25 20:59:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) horizontalDragHandleStyle
|
|
|
|
{
|
2008-08-30 01:58:16 +02:00
|
|
|
NSString *horizontal;
|
|
|
|
|
2008-07-11 19:32:59 +02:00
|
|
|
[self _setupContext];
|
2008-08-30 01:58:16 +02:00
|
|
|
horizontal = [moduleSettings objectForKey: @"DragHandleHorizontal"];
|
2008-03-25 20:59:13 +01:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
return ((horizontal && [horizontal intValue] > 0) ? (id)[horizontal stringByAppendingFormat: @"px"] : nil);
|
2008-03-25 20:59:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) eventsListViewStyle
|
|
|
|
{
|
2008-07-11 19:32:59 +02:00
|
|
|
NSString *height;
|
2008-02-04 23:22:14 +01:00
|
|
|
|
2008-07-11 19:32:59 +02:00
|
|
|
[self _setupContext];
|
|
|
|
height = [moduleSettings objectForKey: @"DragHandleVertical"];
|
2008-02-04 23:22:14 +01:00
|
|
|
|
2008-08-30 01:58:16 +02:00
|
|
|
return ((height && [height intValue] > 0) ? [NSString stringWithFormat: @"%ipx", ([height intValue] - 27)] : nil);
|
2008-02-04 23:22:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) saveDragHandleStateAction
|
|
|
|
{
|
|
|
|
WORequest *request;
|
|
|
|
NSString *dragHandle;
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
request = [context request];
|
|
|
|
|
|
|
|
if ((dragHandle = [request formValueForKey: @"vertical"]) != nil)
|
|
|
|
[moduleSettings setObject: dragHandle
|
|
|
|
forKey: @"DragHandleVertical"];
|
|
|
|
else if ((dragHandle = [request formValueForKey: @"horizontal"]) != nil)
|
|
|
|
[moduleSettings setObject: dragHandle
|
|
|
|
forKey: @"DragHandleHorizontal"];
|
|
|
|
else
|
|
|
|
return [self responseWithStatus: 400];
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
[us synchronize];
|
2008-02-04 23:22:14 +01:00
|
|
|
|
|
|
|
return [self responseWithStatus: 204];
|
|
|
|
}
|
|
|
|
|
2008-07-18 21:25:26 +02:00
|
|
|
- (unsigned int) firstDayOfWeek
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
|
|
|
|
return [ud firstDayOfWeek];
|
2008-07-18 21:25:26 +02:00
|
|
|
}
|
|
|
|
|
2008-07-25 20:44:31 +02:00
|
|
|
- (unsigned int) dayStartHour
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
|
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
|
|
|
|
return [ud dayStartHour];
|
2008-07-25 20:44:31 +02:00
|
|
|
}
|
|
|
|
|
2009-06-09 23:25:41 +02:00
|
|
|
- (NSString *) currentView
|
|
|
|
{
|
|
|
|
NSString *view;
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
view = [moduleSettings objectForKey: @"View"];
|
|
|
|
|
|
|
|
return (view ? view : @"weekview");
|
|
|
|
}
|
|
|
|
|
2006-08-19 00:55:46 +02:00
|
|
|
@end
|