]> err.no Git - sope/blob - sope-ical/samples/ical3.m
fixed gcc 4.0 warnings
[sope] / sope-ical / samples / ical3.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE 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
9   later version.
10
11   SOPE 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.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with SOPE; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #import <Foundation/Foundation.h>
23
24 @class EOQualifier, NSString, EOSortOrdering;
25
26 @interface iCal3Tool : NSObject
27 {
28   EOQualifier *qualifier;
29   NSString    *entityName;
30   NSArray     *sortOrderings;
31 }
32
33 - (int)runWithArguments:(NSArray *)_args;
34
35 @end
36
37 #include <NGiCal/iCalDataSource.h>
38 #include <NGiCal/iCalObject.h>
39 #include <EOControl/EOQualifier.h>
40 #include <EOControl/EOSortOrdering.h>
41 #include "common.h"
42
43 @implementation iCal3Tool
44
45 - (id)init {
46   if ((self = [super init])) {
47     NSUserDefaults *ud;
48     id tmp;
49     
50     /* collect options */
51     ud = [NSUserDefaults standardUserDefaults];
52
53     self->entityName = [[ud stringForKey:@"entity"] copy];
54     
55     if ((tmp = [ud objectForKey:@"qualifier"]) != nil) {
56       self->qualifier = [[EOQualifier alloc] initWithPropertyList:tmp 
57                                              owner:nil];
58     }
59
60     if ((tmp = [ud objectForKey:@"sort"]) != nil) {
61       tmp = [[EOSortOrdering alloc] initWithPropertyList:tmp owner:nil];
62       if (tmp != nil) {
63         self->sortOrderings = [[NSArray alloc] initWithObjects:&tmp count:1];
64         [tmp release]; tmp = nil;
65       }
66     }
67   }
68   return self;
69 }
70 - (void)dealloc {
71   [self->sortOrderings release];
72   [self->qualifier     release];
73   [self->entityName    release];
74   [super dealloc];
75 }
76
77 /* run */
78
79 - (void)printObject:(id)_object {
80   printf("object: %s\n", [[_object description] cString]);
81 }
82
83 - (int)runWithArguments:(NSArray *)_args {
84   NSEnumerator *args;
85   NSString     *arg;
86   
87   /* begin processing */
88   
89   args = [_args objectEnumerator];
90   [args nextObject]; // process name ...
91   
92   while ((arg = [args nextObject])) {
93     NSAutoreleasePool *pool2;
94     
95     if ([arg hasPrefix:@"-"]) { /* consume defaults */
96       [args nextObject];
97       continue;
98     }
99     
100     pool2 = [[NSAutoreleasePool alloc] init];
101     {    
102       iCalDataSource       *ds;
103       EOFetchSpecification *fspec;
104       NSArray    *objs;
105       iCalObject *obj;
106       
107       /* setup fetch specification */
108       
109       fspec = [[[EOFetchSpecification alloc] init] autorelease];
110       [fspec setEntityName:self->entityName];
111       [fspec setQualifier:self->qualifier];
112       
113       /* setup datasource */
114       
115       ds = [iCalDataSource alloc]; // keep gcc happy
116       ds = [[ds initWithPath:arg] autorelease];
117       [ds setFetchSpecification:fspec];
118
119       /* perform fetch */
120       
121       if ((objs = [ds fetchObjects]) == nil) {
122         /* fetch failed */
123         
124         NSLog(@"fetch on ical file failed: %@", arg);
125       }
126       else {
127         /* process results */
128         NSEnumerator *e;
129         
130         e = [objs objectEnumerator];
131         while ((obj = [e nextObject])) {
132           [self printObject:obj];
133         }
134       }
135     }
136     [pool2 release];
137   }
138   return 0;
139 }
140
141 @end /* iCal3Tool */
142
143 int main(int argc, char **argv, char **env)  {
144   NSAutoreleasePool *pool;
145   iCal3Tool *tool;
146   int rc;
147
148 #if LIB_FOUNDATION_LIBRARY  
149   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
150 #endif
151   
152   pool = [[NSAutoreleasePool alloc] init];
153   
154   if ((tool = [[iCal3Tool alloc] init])) {
155     NS_DURING
156       rc = [tool runWithArguments:[[NSProcessInfo processInfo] arguments]];
157     NS_HANDLER
158       abort();
159     NS_ENDHANDLER;
160     
161     [tool release];
162   }
163   else
164     rc = 1;
165   
166   [pool release];
167   return rc;
168 }