2009-09-10 19:26:57 +02:00
|
|
|
/* UIxCalMainActions.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Inverse inc.
|
|
|
|
*
|
|
|
|
* Author: Cyril Robert <crobert@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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <Appointments/SOGoWebAppointmentFolder.h>
|
|
|
|
#import <Appointments/SOGoAppointmentFolders.h>
|
2009-09-10 19:26:57 +02:00
|
|
|
|
|
|
|
#import "UIxCalMainActions.h"
|
|
|
|
|
|
|
|
@implementation UIxCalMainActions
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (NSString *) displayNameForUrl: (NSString *) calendarURL
|
|
|
|
{
|
|
|
|
NSString *rc, *tmp;
|
|
|
|
|
|
|
|
tmp = [calendarURL lastPathComponent];
|
|
|
|
if (tmp)
|
|
|
|
{
|
|
|
|
if ([[tmp pathExtension] caseInsensitiveCompare: @"ics"] == NSOrderedSame)
|
|
|
|
rc = [tmp substringToIndex: [tmp length] - 4];
|
|
|
|
else
|
|
|
|
rc = tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = [self labelForKey: @"Web Calendar"];
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-09-10 19:26:57 +02:00
|
|
|
- (WOResponse *) addWebCalendarAction
|
|
|
|
{
|
|
|
|
WORequest *r;
|
|
|
|
WOResponse *response;
|
|
|
|
SOGoWebAppointmentFolder *folder;
|
|
|
|
NSURL *url;
|
2010-06-11 20:43:46 +02:00
|
|
|
NSString *urlString, *displayName;
|
2009-09-10 19:26:57 +02:00
|
|
|
NSMutableDictionary *rc;
|
2009-09-23 17:00:50 +02:00
|
|
|
SOGoAppointmentFolders *folders;
|
2009-09-10 19:26:57 +02:00
|
|
|
int imported = 0;
|
|
|
|
|
|
|
|
r = [context request];
|
|
|
|
rc = [NSMutableDictionary dictionary];
|
|
|
|
|
|
|
|
// Just a check
|
2010-06-11 20:43:46 +02:00
|
|
|
urlString = [r formValueForKey: @"url"];
|
|
|
|
url = [NSURL URLWithString: urlString];
|
2009-09-10 19:26:57 +02:00
|
|
|
if (url)
|
|
|
|
{
|
2009-09-23 17:00:50 +02:00
|
|
|
folders = [self clientObject];
|
2009-09-21 16:10:16 +02:00
|
|
|
displayName = [self displayNameForUrl: [r formValueForKey: @"url"]];
|
2010-06-11 20:43:46 +02:00
|
|
|
folder = [folders newWebCalendarWithName: displayName
|
|
|
|
atURL: urlString];
|
2009-09-10 19:26:57 +02:00
|
|
|
if (folder)
|
|
|
|
{
|
2010-06-11 20:43:46 +02:00
|
|
|
imported = [folder loadWebCalendar];
|
2009-09-10 19:49:07 +02:00
|
|
|
if (imported >= 0)
|
|
|
|
{
|
2009-09-21 16:10:16 +02:00
|
|
|
[rc setObject: displayName forKey: @"displayname"];
|
2010-06-11 20:43:46 +02:00
|
|
|
[rc setObject: [folder nameInContainer] forKey: @"name"];
|
2009-09-10 19:49:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[folder delete];
|
|
|
|
}
|
2009-09-10 19:26:57 +02:00
|
|
|
[rc setObject: [NSNumber numberWithInt: imported]
|
|
|
|
forKey: @"imported"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response = [self responseWithStatus: 200];
|
|
|
|
[response appendContentString: [rc jsonRepresentation]];
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) reloadWebCalendarsAction
|
|
|
|
{
|
2010-04-19 23:30:25 +02:00
|
|
|
[[self clientObject] reloadWebCalendars: YES];
|
2009-09-10 19:26:57 +02:00
|
|
|
|
|
|
|
return [self responseWith204];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|