2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #import <Foundation/Foundation.h>
25 @class EOQualifier, NSString, EOSortOrdering;
27 @interface iCal3Tool : NSObject
29 EOQualifier *qualifier;
31 NSArray *sortOrderings;
34 - (int)runWithArguments:(NSArray *)_args;
38 #include <NGiCal/iCalDataSource.h>
39 #include <NGiCal/iCalObject.h>
40 #include <EOControl/EOQualifier.h>
41 #include <EOControl/EOSortOrdering.h>
44 @implementation iCal3Tool
47 if ((self = [super init])) {
52 ud = [NSUserDefaults standardUserDefaults];
54 self->entityName = [[ud stringForKey:@"entity"] copy];
56 if ((tmp = [ud objectForKey:@"qualifier"]))
57 self->qualifier = [[EOQualifier alloc] initWithPropertyList:tmp];
59 if ((tmp = [ud objectForKey:@"sort"])) {
60 if ((tmp = [[EOSortOrdering alloc] initWithPropertyList:tmp])) {
61 self->sortOrderings = [[NSArray alloc] initWithObjects:tmp,nil];
69 [self->sortOrderings release];
70 [self->qualifier release];
71 [self->entityName release];
77 - (void)printObject:(id)_object {
78 printf("object: %s\n", [[_object description] cString]);
81 - (int)runWithArguments:(NSArray *)_args {
85 /* begin processing */
87 args = [_args objectEnumerator];
88 [args nextObject]; // process name ...
90 while ((arg = [args nextObject])) {
91 NSAutoreleasePool *pool2;
93 if ([arg hasPrefix:@"-"]) { /* consume defaults */
98 pool2 = [[NSAutoreleasePool alloc] init];
101 EOFetchSpecification *fspec;
105 /* setup fetch specification */
107 fspec = [[[EOFetchSpecification alloc] init] autorelease];
108 [fspec setEntityName:self->entityName];
109 [fspec setQualifier:self->qualifier];
111 /* setup datasource */
113 ds = [[[iCalDataSource alloc] initWithPath:arg] autorelease];
114 [ds setFetchSpecification:fspec];
118 if ((objs = [ds fetchObjects]) == nil) {
121 NSLog(@"fetch on ical file failed: %@", arg);
124 /* process results */
127 e = [objs objectEnumerator];
128 while ((obj = [e nextObject])) {
129 [self printObject:obj];
140 int main(int argc, char **argv, char **env) {
141 NSAutoreleasePool *pool;
145 #if LIB_FOUNDATION_LIBRARY
146 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
149 pool = [[NSAutoreleasePool alloc] init];
151 if ((tool = [[iCal3Tool alloc] init])) {
153 rc = [tool runWithArguments:[[NSProcessInfo processInfo] arguments]];