| 1 | #!/usr/bin/perl -w | ||
| 2 | # vi:sts=4:shiftwidth=4 | ||
| 3 | # -*- Mode: perl -*- | ||
| 4 | #====================================================================== | ||
| 5 | # | ||
| 6 | # This package is free software and is provided "as is" without | ||
| 7 | # express or implied warranty. It may be used, redistributed and/or | ||
| 8 | # modified under the same terms as perl itself. ( Either the Artistic | ||
| 9 | # License or the GPL. ) | ||
| 10 | # | ||
| 11 | # $Id: Calendar.pm,v 1.19 2001/07/24 02:28:08 srl Exp $ | ||
| 12 | # | ||
| 13 | # (C) COPYRIGHT 2000-2001, Reefknot developers. | ||
| 14 | # | ||
| 15 | # See the AUTHORS file included in the distribution for a full list. | ||
| 16 | #====================================================================== | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | Net::ICal::Calendar -- Hold and manipulate events, todo items and | ||
| 21 | journal entries. | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | package Net::ICal::Calendar; | ||
| 26 | use strict; | ||
| 27 | |||
| 28 | use base qw(Net::ICal::Component); | ||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | use Net::ICal; | ||
| 33 | |||
| 34 | my $cal = new Net::ICal::Calendar( | ||
| 35 | alarms => [ array of alarm objects ], | ||
| 36 | events => [ array of event objects ], | ||
| 37 | todos => [ array of todo objects ], | ||
| 38 | journals => [ array of journal objects ], | ||
| 39 | timezones => [ array of timezone objects ], | ||
| 40 | ); | ||
| 41 | |||
| 42 | =head1 TO BE IMPLEMENTED LATER | ||
| 43 | |||
| 44 | # Has the calendar been modified since we last checked? | ||
| 45 | if( ! ($cal->last_modified() > $our_last_mod_time)){ | ||
| 46 | return; | ||
| 47 | } | ||
| 48 | |||
| 49 | # Only deal with meeting requests from Larry | ||
| 50 | foreach $message ($cal->messages() ){ | ||
| 51 | if($message->method() eq 'REQUEST' && | ||
| 52 | $message->type() eq 'VEVENT' && | ||
| 53 | $message->organizer() eq 'mailto:larray@example.com'){ | ||
| 54 | |||
| 55 | my @overlaps = $cal->overlap_search($message); | ||
| 56 | |||
| 57 | if($#overlaps){ | ||
| 58 | # Reject or counterpropose the request | ||
| 59 | my $new_time = | ||
| 60 | $cal->next_free_time(Net::ICal::Time(time(0), | ||
| 61 | $message->span()->duration(), | ||
| 62 | $message->span()->priority())); | ||
| 63 | } else { | ||
| 64 | # Add it to the calendar | ||
| 65 | $cal->book($message); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | #Now check for any alarms in the next hour | ||
| 70 | @alarms= $cal->alarms(new Net::ICal::Period(time(0),"1h")); | ||
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | |||
| 75 | =head1 DESCRIPTION | ||
| 76 | |||
| 77 | A Net::ICal::Calendar represents Calendar that can hold events, todo | ||
| 78 | items, journal entries (and incoming messages?). | ||
| 79 | |||
| 80 | =cut | ||
| 81 | |||
| 82 | # TODO: what's that about incoming messages? How are we handling those? | ||
| 83 | # I think we should just handle them in the same data structures with | ||
| 84 | # messages that we generate, and use the UID to figure out whether we | ||
| 85 | # generated them or not. --srl | ||
| 86 | |||
| 87 | =head1 METHODS | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | #======================================================================= | ||
| 92 | |||
| 93 | =head2 new() | ||
| 94 | |||
| 95 | Construct a new calendar, given sets of data to put in the calendar. | ||
| 96 | See the example above. | ||
| 97 | |||
| 98 | =begin testing | ||
| 99 | |||
| 100 | use Net::ICal::Calendar; | ||
| 101 | use Net::ICal::Event; | ||
| 102 | |||
| 103 | my $c = Net::ICal::Calendar->new(); | ||
| 104 | |||
| 105 | ok(!(defined($c)), "create fails properly if params are empty"); | ||
| 106 | |||
| 107 | $c = Net::ICal::Calendar->new (events => [ | ||
| 108 | Net::ICal::Event->new(dtstart => '20010402T021030Z') | ||
| 109 | ]); | ||
| 110 | |||
| 111 | ok(defined($c), 'create passes if at least one event'); | ||
| 112 | |||
| 113 | =end testing | ||
| 114 | |||
| 115 | =cut | ||
| 116 | |||
| 117 | #======================================================================= | ||
| 118 | |||
| 119 | sub new { | ||
| 120 | my ($class, %args) = @_; | ||
| 121 | |||
| 122 | |||
| 123 | # one of the following has to be defined. | ||
| 124 | return undef unless ( defined $args{'events'} || | ||
| 125 | defined $args{'journals'} || | ||
| 126 | defined $args{'todos'} || | ||
| 127 | defined $args{'freebusys'} || | ||
| 128 | defined $args{'timezones'} ); | ||
| 129 | #use Data::Dumper; | ||
| 130 | #print Dumper %args; | ||
| 131 | my $self = &_create ($class, %args); | ||
| 132 | |||
| 133 | # set here instead of in the map so we can read in other stuff | ||
| 134 | # in new_from_ical and still check for duplicates by testing | ||
| 135 | # for undef | ||
| 136 | $self->version ('2.0'); | ||
| 137 | # TODO: find out what we have to do to make sure this is unique. | ||
| 138 | $self->prodid ('-//Reefknot Project//NONSGML Net::ICal//EN'); | ||
| 139 | |||
| 140 | return $self; | ||
| 141 | } | ||
| 142 | |||
| 143 | |||
| 144 | # Documentation below swiped from N::I::Component, which this is a child class of. | ||
| 145 | #============================================================================ | ||
| 146 | |||
| 147 | =head2 new_from_ical | ||
| 148 | |||
| 149 | Creates a new Net::ICal::Calendar from an ical stream. | ||
| 150 | Use this to read in a new object before you do things with it. | ||
| 151 | (Inherited from Net::ICal::Component; read its documentation if you're | ||
| 152 | curious.) | ||
| 153 | |||
| 154 | =cut | ||
| 155 | |||
| 156 | #============================================================================ | ||
| 157 | # XXX: this is commented out because right now we're just using the | ||
| 158 | # N::I::Component version of this sub. We might want to run new_from_ical items | ||
| 159 | # through the tests in new(), above, or something, to verify that they're sane | ||
| 160 | # objects. | ||
| 161 | #sub new_from_ical {} | ||
| 162 | |||
| 163 | |||
| 164 | =head1 METHODS FOR INTERNAL USE ONLY | ||
| 165 | |||
| 166 | None of the following methods should be relied on by anything outside | ||
| 167 | this module. Use at your own risk. | ||
| 168 | |||
| 169 | =head2 _create ($class, %args) | ||
| 170 | |||
| 171 | Sets up a Class::MethodMapper map to describe the data in this class, | ||
| 172 | then initialize the object. Takes a classname and a hash of arguments, | ||
| 173 | returns a Net::ICal::Calendar. See the Class::MethodMapper docs if you | ||
| 174 | want to understand what this does slightly better. | ||
| 175 | |||
| 176 | =cut | ||
| 177 | |||
| 178 | sub _create { | ||
| 179 | my ($class, %args) = @_; | ||
| 180 | |||
| 181 | # See the Class::MethodMapper docs to understand more about what this does. | ||
| 182 | # Basically, it sets up a series of accessor functions for various tiny | ||
| 183 | # data elements within a calendar. | ||
| 184 | my $map = { | ||
| 185 | |||
| 186 | # the attributes of the calendar as a whole. See RFC2445 4.7 | ||
| 187 | calscale => { # RFC2445 4.7.1 - OPTIONAL | ||
| 188 | type => 'parameter', | ||
| 189 | doc => 'what sort of calendar is this (default gregorian)', | ||
| 190 | domain => 'enum', | ||
| 191 | # not sure if we should define these enums; gregorian is default, | ||
| 192 | # and I'm not sure if others have been defined by IETF. But | ||
| 193 | # this allows us to handle non-Gregorian calendar concepts. | ||
| 194 | # It might also allow us to define some concept of, say, | ||
| 195 | # 28-hour-6-day weeks, for those who are into that. ;) --srl | ||
| 196 | options => [qw(GREGORIAN ISLAMIC)], | ||
| 197 | value => undef, | ||
| 198 | }, | ||
| 199 | |||
| 200 | method => { # RFC2445 4.7.2 - OPTIONAL | ||
| 201 | # this is a METHOD name as specified in RFC2446 (iTIP). | ||
| 202 | # it lets you say whether this is a request for a meeting, | ||
| 203 | # a response to a request, or what. | ||
| 204 | type => 'parameter', | ||
| 205 | doc => 'RFC2446 method string', | ||
| 206 | value => undef, | ||
| 207 | }, | ||
| 208 | |||
| 209 | prodid => { # RFC2445 4.7.3 - REQUIRED, DEFAULT INCLUDED | ||
| 210 | type => 'parameter', | ||
| 211 | doc => 'what product created this iCalendar', | ||
| 212 | }, | ||
| 213 | |||
| 214 | version => { # RFC2445 4.7.4 - REQUIRED, DEFAULT INCLUDED | ||
| 215 | type => 'parameter', | ||
| 216 | doc => 'version of the iCalendar spec this iCal conforms to', | ||
| 217 | }, | ||
| 218 | |||
| 219 | # things that go 'inside' a calendar object; see RFC2445 4.6 | ||
| 220 | # there should be at least one of these. | ||
| 221 | |||
| 222 | # yes, I know that some of these plurals are strange, but alarm is | ||
| 223 | # a reserved perl keyword. bah. ---srl | ||
| 224 | events => { # RFC 2445 4.6.1 | ||
| 225 | type => 'parameter', | ||
| 226 | doc => 'the events in this calendar', | ||
| 227 | domain => 'ref', | ||
| 228 | options => 'ARRAY', | ||
| 229 | value => undef, | ||
| 230 | }, | ||
| 231 | |||
| 232 | todos => { # RFC 2445 4.6.2 | ||
| 233 | type => 'parameter', | ||
| 234 | doc => 'things to do', | ||
| 235 | domain => 'ref', | ||
| 236 | options => 'ARRAY', | ||
| 237 | value => undef, | ||
| 238 | }, | ||
| 239 | |||
| 240 | journals => { # RFC 2445 4.6.3 | ||
| 241 | type => 'parameter', | ||
| 242 | doc => 'my notes', | ||
| 243 | domain => 'ref', | ||
| 244 | options => 'ARRAY', | ||
| 245 | value => undef, | ||
| 246 | }, | ||
| 247 | |||
| 248 | freebusys => { # RFC2445 4.6.4 | ||
| 249 | type => 'parameter', | ||
| 250 | doc => 'when am i free or busy?', | ||
| 251 | domain => 'ref', | ||
| 252 | options => 'ARRAY', | ||
| 253 | value => undef, | ||
| 254 | }, | ||
| 255 | |||
| 256 | timezones => { # RFC2445 4.6.5 | ||
| 257 | type => 'parameter', | ||
| 258 | doc => 'when am i free or busy?', | ||
| 259 | domain => 'ref', | ||
| 260 | options => 'ARRAY', | ||
| 261 | value => undef, | ||
| 262 | }, | ||
| 263 | |||
| 264 | alarms => { # RFC2445 4.6.6 | ||
| 265 | type => 'parameter', | ||
| 266 | doc => 'warn me when some things happen', | ||
| 267 | domain => 'ref', | ||
| 268 | options => 'ARRAY', | ||
| 269 | value => undef, | ||
| 270 | }, | ||
| 271 | |||
| 272 | }; | ||
| 273 | |||
| 274 | my $self = $class->SUPER::new ('VCALENDAR', $map, %args); | ||
| 275 | |||
| 276 | return $self; | ||
| 277 | } | ||
| 278 | |||
| 279 | # There was more documentation here at CVS version 1.5, but I've | ||
| 280 | # deleted it in preparation for the release of Net::ICal 0.13. | ||
| 281 | # We can always retrieve it from CVS if we want it back. --srl | ||
| 282 | |||
| 283 | 1; | ||
| 284 | |||
| 285 | =head1 SEE ALSO | ||
| 286 | |||
| 287 | More documentation pointers can be found in L<Net::ICal>. | ||
| 288 | |||
| 289 | =cut |