Back to index

lightning-sunbird  0.9+nobinonly
calICSService.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Oracle Corporation code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  *  Oracle Corporation
00018  * Portions created by the Initial Developer are Copyright (C) 2004
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Mike Shaver <mike.x.shaver@oracle.com>
00023  *   Daniel Boelzle <daniel.boelzle@sun.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #if !defined(INCLUDED_CALICSSERVICE_H)
00039 #define INCLUDED_CALICSSERVICE_H
00040 
00041 #include "nsCOMPtr.h"
00042 #include "calIICSService.h"
00043 #include "calITimezoneProvider.h"
00044 #include "nsInterfaceHashtable.h"
00045 #include "calUtils.h"
00046 
00047 extern "C" {
00048 #include "ical.h"
00049 }
00050 
00051 class calICSService : public calIICSService,
00052                       public cal::XpcomBase
00053 {
00054 public:
00055     calICSService();
00056 
00057     NS_DECL_ISUPPORTS
00058     NS_DECL_CALIICSSERVICE
00059 };
00060 
00061 class calIcalComponent;
00062 
00063 class calIcalProperty : public calIIcalProperty,
00064                         public cal::XpcomBase
00065 {
00066     friend class calIcalComponent;
00067 public:
00068     calIcalProperty(icalproperty * prop, calIIcalComponent * parent)
00069         : mProperty(prop), mParent(parent) {}
00070 
00071     NS_DECL_ISUPPORTS
00072     NS_DECL_CALIICALPROPERTY
00073 
00074 protected:
00075     virtual ~calIcalProperty();
00076 
00077     static nsresult getDatetime_(calIcalComponent *parent,
00078                                  icalproperty *prop,
00079                                  calIDateTime **dtp);
00080     static nsresult setDatetime_(calIcalComponent *parent,
00081                                  icalproperty *prop,
00082                                  calIDateTime *dt);
00083 
00084     icalproperty *              mProperty;
00085     nsCOMPtr<calIIcalComponent> mParent;
00086 };
00087 
00088 class calIcalComponent : public calIIcalComponent,
00089                          public cal::XpcomBase
00090 {
00091     friend class calIcalProperty;
00092 public:
00093     calIcalComponent(icalcomponent *ical, calIIcalComponent *parent,
00094                      calITimezoneProvider *tzProvider = nsnull)
00095         : mComponent(ical), mTimezone(nsnull), mTzProvider(tzProvider), mParent(parent)
00096     {
00097         mReferencedTimezones.Init();
00098     }
00099 
00100     // VTIMEZONE ctor
00101     calIcalComponent(icaltimezone * icaltz, icalcomponent * ical) : mComponent(ical), mTimezone(icaltz) {
00102         mReferencedTimezones.Init();
00103     }
00104     
00105     NS_DECL_ISUPPORTS
00106     NS_DECL_CALIICALCOMPONENT
00107 
00108 protected:
00109     virtual ~calIcalComponent();
00110 
00111     calITimezoneProvider * getTzProvider() const {
00112         // walk up the parents to find a tz provider:
00113         calIcalComponent const * that = this;
00114         while (that) {
00115             calITimezoneProvider * const ret = that->mTzProvider;
00116             if (ret) {
00117                 return ret;
00118             }
00119             calIIcalComponent * const p = that->mParent;
00120             that = static_cast<calIcalComponent const *>(p);
00121         }
00122         return nsnull;
00123     }
00124 
00125     calIcalComponent * getParentVCalendarOrThis() {
00126         // walk up the parents to find a VCALENDAR:
00127         calIcalComponent * that = this;
00128         while (that && icalcomponent_isa(that->mComponent) != ICAL_VCALENDAR_COMPONENT) {
00129             calIIcalComponent * const p = that->mParent;
00130             that = static_cast<calIcalComponent *>(p);
00131         }
00132         if (!that)
00133             that = this;
00134         return that;
00135     }
00136 
00137     nsresult GetDateTimeAttribute(icalproperty_kind kind, calIDateTime ** dtp);
00138     nsresult SetDateTimeAttribute(icalproperty_kind kind, calIDateTime * dt);
00139 
00140     nsresult SetPropertyValue(icalproperty_kind kind, icalvalue *val);
00141     nsresult SetProperty(icalproperty_kind kind, icalproperty *prop);
00142 
00143     nsresult GetStringProperty(icalproperty_kind kind, nsACString &str);
00144     nsresult SetStringProperty(icalproperty_kind kind, const nsACString &str);
00145 
00146     nsresult GetIntProperty(icalproperty_kind kind, PRInt32 *valp);
00147     nsresult SetIntProperty(icalproperty_kind kind, PRInt32 i);
00148 
00149     void ClearAllProperties(icalproperty_kind kind);
00150 
00151     nsresult Serialize(char ** icalstr);
00152 
00153     nsInterfaceHashtable<nsCStringHashKey, calITimezone> mReferencedTimezones;
00154     icalcomponent *                                      mComponent;
00155     icaltimezone *                                       mTimezone; // set iff VTIMEZONE
00156     nsCOMPtr<calITimezoneProvider> const                 mTzProvider;
00157     nsCOMPtr<calIIcalComponent>                          mParent;
00158 };
00159 
00160 inline calIcalProperty * toIcalProperty(calIIcalProperty * p) {
00161     return static_cast<calIcalProperty *>(p);
00162 }
00163 inline calIcalComponent * toIcalComponent(calIIcalComponent * p) {
00164     return static_cast<calIcalComponent *>(p);
00165 }
00166 
00167 #endif // INCLUDED_CALICSSERVICE_H