From 4be5c939c37f0df4397682da6d3a388298b7af79 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 9 Jul 2008 03:32:17 +0000 Subject: [PATCH] Monotone-Parent: 90c34f3f070d02780a48b3d6cb6c8b55f5610898 Monotone-Revision: e879ac812e9a6a28e427bd5c6c96b5a3be099ad0 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2008-07-09T03:32:17 Monotone-Branch: ca.inverse.sogo --- UI/Contacts/UIxContactFolderActions.h | 39 ++++++++ UI/Contacts/UIxContactFolderActions.m | 128 ++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 UI/Contacts/UIxContactFolderActions.h create mode 100644 UI/Contacts/UIxContactFolderActions.m diff --git a/UI/Contacts/UIxContactFolderActions.h b/UI/Contacts/UIxContactFolderActions.h new file mode 100644 index 000000000..1321163d4 --- /dev/null +++ b/UI/Contacts/UIxContactFolderActions.h @@ -0,0 +1,39 @@ +/* UIxContactFolderActions.h - this file is part of SOGo + * + * Copyright (C) 2008 Inverse groupe conseil + * + * Author: Francis Lachapelle + * + * 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. + */ + +#ifndef UIXCONTACTFOLDERACTIONS_H +#define UIXCONTACTFOLDERACTIONS_H + +#import + +@class WOResponse; + +@interface UIxContactFolderActions : WODirectAction +{ +} + +- (WOResponse *) copyAction; +- (WOResponse *) moveAction; + +@end + +#endif /* UIXCONTACTFOLDERACTIONS_H */ diff --git a/UI/Contacts/UIxContactFolderActions.m b/UI/Contacts/UIxContactFolderActions.m new file mode 100644 index 000000000..4baad2d9c --- /dev/null +++ b/UI/Contacts/UIxContactFolderActions.m @@ -0,0 +1,128 @@ +/* UIxContactFolderActions.m - this file is part of SOGo + * + * Copyright (C) 2008 Inverse groupe conseil + * + * Author: Francis Lachapelle + * + * 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 +#import +#import + +#import +#import +#import + +#import + +#import +#import + +#import +#import +#import +#import +#import +#import + +#import "../Common/WODirectAction+SOGo.h" + +#import "UIxContactFolderActions.h" + +@implementation UIxContactFolderActions + +- (id) init +{ + if ((self = [super init])) + { + } + + return self; +} + +- (void) dealloc +{ + [super dealloc]; +} + +- (WOResponse *) copyAction +{ + WORequest *request; + NSArray *contactsId; + NSEnumerator *uids; + NSString *folderId, *uid, *newUid; + SOGoContactFolders *folders; + SOGoParentFolder *folder, *destinationFolder; + id contact; + SOGoContentObject *newContact; + NGVCard *card; + NSException *ex; + unsigned int errorCount; + + request = [context request]; + errorCount = 0; + + if ((folderId = [request formValueForKey: @"folder"]) && + (contactsId = [request formValuesForKey: @"uid"])) + { + // Search the specified destination folder + folder = [self clientObject]; + folders = [(SOGoUserFolder*)[[folder container] container] privateContacts: @"Contacts" + inContext: nil]; + destinationFolder = [folders lookupName: folderId + inContext: nil + acquire: NO]; + if (destinationFolder) + { + uids = [contactsId objectEnumerator]; + uid = [uids nextObject]; + + while (uid) + { + contact = [folder lookupName: uid + inContext: [self context] + acquire: NO]; + if (![(NSObject*)contact isKindOfClass: [NSException class]]) + { + newUid = [SOGoObject globallyUniqueObjectId]; + card = [contact vCard]; + [card setUid: newUid]; + + //[contact setContent: [card versitString]]; + //[contact copyTo: destinationFolder]; // verify if exception + + newContact = [SOGoContentObject objectWithName: newUid + inContainer: destinationFolder]; + ex = [newContact saveContentString: [card versitString]]; + if (ex != nil) + errorCount++; + } + uid = [uids nextObject]; + } + } + } + + return [self responseWithStatus: 204]; +} + +- (WOResponse *) moveAction +{ + return [self responseWithStatus: 204]; +} + +@end