~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-ical/samples/icalds.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  pool = [[NSAutoreleasePool alloc] init];
 
149
#if LIB_FOUNDATION_LIBRARY  
 
150
  [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
 
151
#endif
 
152
  
 
153
  if ((tool = [[iCal3Tool alloc] init])) {
 
154
    NS_DURING
 
155
      rc = [tool runWithArguments:[[NSProcessInfo processInfo] arguments]];
 
156
    NS_HANDLER
 
157
      abort();
 
158
    NS_ENDHANDLER;
 
159
    
 
160
    [tool release];
 
161
  }
 
162
  else
 
163
    rc = 1;
 
164
  
 
165
  [pool release];
 
166
  return rc;
 
167
}