[Kde-bindings] KDE/kdepimlibs/kcalcore

Allen Winter winter at kde.org
Sun Nov 14 01:00:26 UTC 2010


SVN commit 1196755 by winterz:

NEW API ALERT!

from the Meego version:
* Add new public timezone parse() methods that create ICalTimeZone instances
  from QString timezone names.
  Will be used in the VCalFormat class to provide better timezone support there.

CCMAIL: kde-bindings at kde.org, alvaro.manera at nokia.com


 M  +62 -2     icaltimezones.cpp  
 M  +24 -0     icaltimezones.h  


--- trunk/KDE/kdepimlibs/kcalcore/icaltimezones.cpp #1196754:1196755
@@ -993,13 +993,13 @@
 
   QList<QByteArray> standardAbbrevs;
   standardAbbrevs += tz->StandardName.toAscii();
-  KTimeZone::Phase standardPhase( ( tz->Bias + tz->StandardBias ) * 60, standardAbbrevs, false,
+  KTimeZone::Phase standardPhase( ( tz->Bias + tz->StandardBias ) * -60, standardAbbrevs, false,
                                   "Microsoft TIME_ZONE_INFORMATION" );
   phases += standardPhase;
 
   QList<QByteArray> daylightAbbrevs;
   daylightAbbrevs += tz->DaylightName.toAscii();
-  KTimeZone::Phase daylightPhase( ( tz->Bias + tz->DaylightBias ) * 60, daylightAbbrevs, true,
+  KTimeZone::Phase daylightPhase( ( tz->Bias + tz->DaylightBias ) * -60, daylightAbbrevs, true,
                                   "Microsoft TIME_ZONE_INFORMATION" );
   phases += daylightPhase;
 
@@ -1021,6 +1021,66 @@
   return ICalTimeZone( this, name, idata );
 }
 
+ICalTimeZone ICalTimeZoneSource::parse( const QString &name, const QStringList &tzList,
+                                        ICalTimeZones &zones )
+{
+  ICalTimeZone zone = parse( name, tzList );
+  if ( !zone.isValid() ) {
+    return ICalTimeZone(); // error
+  }
+
+  ICalTimeZone oldzone = zones.zone( zone );
+  // First off see if the zone is same as oldzone - _exactly_ same
+  if ( oldzone.isValid() ) {
+    return oldzone;
+  }
+
+  oldzone = zones.zone( name );
+  if ( oldzone.isValid() ) {
+    // The zone already exists, so update
+    oldzone.update( zone );
+    return zone;
+  } else if ( zones.add( zone ) ) {
+    // No similar zone, add and return new one.
+    return zone;
+  }
+  return ICalTimeZone(); // error
+}
+
+ICalTimeZone ICalTimeZoneSource::parse( const QString &name, const QStringList &tzList )
+{
+  ICalTimeZoneData kdata;
+  QList<KTimeZone::Phase> phases;
+  QList<KTimeZone::Transition> transitions;
+  bool daylight;
+
+  for ( QStringList::ConstIterator it = tzList.begin(); it != tzList.end(); ++it ) {
+    QString value = *it;
+    daylight = false;
+    QString tzName = value.mid( 0, value.indexOf( ";" ) );
+    value = value.mid( ( value.indexOf( ";" ) + 1 ) );
+    QString tzOffset = value.mid( 0, value.indexOf( ";" ) );
+    value = value.mid( ( value.indexOf( ";" ) + 1 ) );
+    QString tzDaylight = value.mid( 0, value.indexOf( ";" ) );
+    KDateTime tzDate = KDateTime::fromString( value.mid( ( value.lastIndexOf( ";" ) + 1 ) ) );
+    if ( tzDaylight == "true" ) {
+      daylight = true;
+    }
+
+    KTimeZone::Phase tzPhase( tzOffset.toInt(),
+                              QByteArray( tzName.toAscii() ), daylight, "VCAL_TZ_INFORMATION" );
+    phases += tzPhase;
+    transitions += KTimeZone::Transition( tzDate.dateTime(), tzPhase );
+  }
+
+  kdata.setPhases( phases, 0 );
+  qSort( transitions );
+  kdata.setTransitions( transitions );
+
+  ICalTimeZoneData *idata = new ICalTimeZoneData( kdata, KTimeZone( name ), QDate() );
+  return ICalTimeZone( this, name, idata );
+}
+
 //@cond PRIVATE
 void ICalTimeZoneSourcePrivate::parseTransitions( const MSSystemTime &date,
                                                   const KTimeZone::Phase &phase, int prevOffset,
--- trunk/KDE/kdepimlibs/kcalcore/icaltimezones.h #1196754:1196755
@@ -461,6 +461,30 @@
     ICalTimeZone parse( MSTimeZone *tz, ICalTimeZones &zones );
 
     /**
+     * Creates an ICalTimeZone instance and adds it to a ICalTimeZones
+     * collection or returns an existing instance for the vcal component.
+     *
+     * @param name     the name of timezone
+     * @param tzList   the QStringList to parse
+     * @param zones    the time zones collection to which the ICalTimeZone
+     *                 instances are to be added
+     * @return an ICalTimeZone instance containing the time zone data, or invalid on error
+     * @since 4.6
+     */
+    ICalTimeZone parse( const QString &name, const QStringList &tzList, ICalTimeZones &zones );
+
+    /**
+     * Creates an ICalTimeZone instance containing the detailed information
+     * contained in an QStringList produced by vcalformat.
+     *
+     * @param name   the name of timezone
+     * @param tzList the QStringList from which data is to be extracted
+     * @return an ICalTimeZone instance containing the time zone data, or invalid on error
+     * @since 4.6
+     */
+    ICalTimeZone parse( const QString &name, const QStringList &tzList );
+
+    /**
      * Reads an iCalendar file and creates an ICalTimeZone instance for each
      * VTIMEZONE component within it. The ICalTimeZone instances are added to a
      * ICalTimeZones collection.



More information about the Kde-bindings mailing list