Files
sogo/SoObjects/Appointments/SOGoWebAppointmentFolder.m
C Robert a30d27177f Added error management for invalid urls
Monotone-Parent: bb2513b08d345dfc89b0cd702a39ac0eeb276c3d
Monotone-Revision: 44a5709167b1e665fbba7b3e8f30b4e8796d21b2

Monotone-Author: crobert@inverse.ca
Monotone-Date: 2009-09-10T17:49:07
Monotone-Branch: ca.inverse.sogo
2009-09-10 17:49:07 +00:00

89 lines
2.3 KiB
Objective-C

/* SOGoWebAppointmentFolder.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 <NGCards/iCalCalendar.h>
#import <GDLContentStore/GCSFolder.h>
#import <NGObjWeb/WOContext+SoObjects.h>
#import <SoObjects/SOGo/SOGoUser.h>
#import "SOGoWebAppointmentFolder.h"
@implementation SOGoWebAppointmentFolder
- (int) loadWebCalendar: (NSString *) location
{
NSURL *url;
NSData *data;
NSString *contents;
iCalCalendar *calendar;
int imported = 0;
url = [NSURL URLWithString: location];
if (url)
{
data = [NSData dataWithContentsOfURL: url];
contents = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
[contents autorelease];
calendar = [iCalCalendar parseSingleFromSource: contents];
if (calendar)
{
[[self ocsFolder] deleteAllContent];
imported = [self importCalendar: calendar];
}
else
{
imported = -1;
}
}
return imported;
}
- (NSException *) delete
{
NSException *error;
NSUserDefaults *settings;
NSMutableDictionary *calSettings, *webCalendars;
NSString *name;
settings = [[context activeUser] userSettings];
calSettings = [settings objectForKey: @"Calendar"];
webCalendars = [calSettings objectForKey: @"WebCalendars"];
name = [self nameInContainer];
error = [super delete];
if (!error)
{
[webCalendars removeObjectForKey: name];
[settings synchronize];
}
return error;
}
@end /* SOGoAppointmentFolder */