From 697761cc337aa77a47140c8df50ed84bc25e23f6 Mon Sep 17 00:00:00 2001 From: Hans Petter Date: Thu, 11 Sep 2003 22:04:44 +0000 Subject: Import new libical from mainline HEAD and make appropriate changes to Evolution. svn path=/trunk/; revision=22538 --- .../lib/Net/ICal/Libical/Component.pm | 175 +++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Component.pm (limited to 'libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Component.pm') diff --git a/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Component.pm b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Component.pm new file mode 100644 index 0000000000..c25297c111 --- /dev/null +++ b/libical/src/Net-ICal-Libical/lib/Net/ICal/Libical/Component.pm @@ -0,0 +1,175 @@ +#!/usr/bin/perl +# -*- Mode: perl -*- +#====================================================================== +# FILE: Component.pm +# CREATOR: eric 1 Mar 01 +# +# DESCRIPTION: +# +# +# $Id$ +# $Locker$ +# +# (C) COPYRIGHT 2000, Eric Busboom, eric@softwarestudio.org +# +# This package is free software and is provided "as is" without express +# or implied warranty. It may be used, redistributed and/or modified +# under the same terms as perl itself. ( Either the Artistic License or the +# GPL. ) +# +# +#====================================================================== + + + +package Net::ICal::Libical::Component; +use Net::ICal::Libical; + +use strict; + +sub new{ + my $class = shift; + my $ical_str = shift; # Ical data in string form + my $self = {}; + + $self->{'comp_p'} = Net::ICal::Libical::icalparser_parse_string($ical_str); + + die "Can't parse string into component" if !$self->{'comp_p'}; + + bless $self, $class; +} + +sub new_from_ref { + my $class = shift; + my $r = shift; + my $self = {}; + + $self->{'comp_p'} = $r; + + bless $self, $class; +} + +# Destroy must call icalcomponent_free() if icalcomponent_get_parent() +# returns NULL +sub DESTROY { + my $self = shift; + + my $c = $self->{'comp_p'}; + + if($c && !Net::ICal::Libical::icalcomponent_get_parent($c)){ + Net::ICal::Libical::icalcomponent_free($c); + } + +} + +# Return an array of all properties of the given type +sub properties{ + + my $self = shift; + my $prop_name = shift; + + my @props; + + if(!$prop_name){ + $prop_name = 'ANY'; + } + + # To loop over properties + # $comp_p = $self->{'comp_p'} + # $p = icallangbind_get_first_property($comp_p,$prop_name) + # $p = icallangbind_get_next_property($comp_p,$prop_name) + + my $c = $self->{'comp_p'}; + my $p; + + for($p = Net::ICal::Libical::icallangbind_get_first_property($c,$prop_name); + $p; + $p = Net::ICal::Libical::icallangbind_get_next_property($c,$prop_name)){ + + my $d_string = Net::ICal::Libical::icallangbind_property_eval_string($p,"=>"); + my %dict = %{eval($d_string)}; + + $dict{'ref'} = $p; + + # Now, look at $dict{'value_type'} or $dict{'name'} to construct a + # derived class of Property. I'll do this later. + + my $prop; + + if($dict{'value_type'} eq 'DATE' or $dict{'value_type'} eq 'DATE-TIME'){ + $prop = new Net::ICal::Libical::Time(\%dict); + } elsif($dict{'value_type'} eq 'DURATION' ) { + $prop = new Net::ICal::Libical::Duration(\%dict); + } else { + $prop = new Net::ICal::Libical::Property(\%dict); + } + + push(@props,$prop); + + } + + + return @props; + +} + + +sub add_property { + + # if there is a 'ref' key in the prop's dict, then it is owned by + # an icalcomponent, so dont add it again. But, you may check that + # it is owned by this component with: + # icalproperty_get_parent(p->{'ref'}') != $self->{'comp_p'} + + # If there is no 'ref' key, then create one with $p->{'ref'} = + # icalproperty_new_from_string($p->as_ical_string) + +} + +sub remove_property { + +# If $p->{'ref'} is set, then remove the property with +# icalcomponent_remove_property() } +} + +# Return an array of all components of the given type +sub components { + + my $self = shift; + my $comp_name = shift; + + my @comps; + + if(!$comp_name){ + $comp_name = 'ANY'; + } + + my $c = $self->{'comp_p'}; + my $p; + + for($p = Net::ICal::Libical::icallangbind_get_first_component($c,$comp_name); + $p; + $p = Net::ICal::Libical::icallangbind_get_next_component($c,$comp_name)){ + + push(@comps, Net::ICal::Libical::Component->new_from_ref($p)); + + } + + return @comps; + +} + + +sub add_component {} + +sub remove_component {} + +sub as_ical_string { + my $self = shift; + + return Net::ICal::Libical::icalcomponent_as_ical_string($self->{'comp_p'}) +} + + + +1; -- cgit