Ejemplo n.º 1
0
/******************************************************************************
 * Initialise the recurrence from an iCalendar RRULE string.
 */
bool KARecurrence::set(const QString &icalRRULE)
{
    static QString RRULE = QString::fromLatin1("RRULE:");
    mCachedType = -1;
    clear();
    if(icalRRULE.isEmpty())
        return true;
    ICalFormat format;
    if(!format.fromString(defaultRRule(true),
                          (icalRRULE.startsWith(RRULE) ? icalRRULE.mid(RRULE.length()) : icalRRULE)))
        return false;
    fix();
    return true;
}
void ResourceGroupware::slotJobResult( KJob *job )
{
  kDebug() <<"ResourceGroupware::slotJobResult():";

  if ( job->error() ) {
    mIsShowingError = true;
    loadError( job->errorString() );
    mIsShowingError = false;
  } else {
    disableChangeNotification();

    clearCache();

     // FIXME: This does not take into account the time zone!
    CalendarLocal calendar;
    ICalFormat ical;
    if ( !ical.fromString( &calendar, mJobData ) ) {
      loadError( i18n("Error parsing calendar data.") );
    } else {
      Incidence::List incidences = calendar.incidences();
      Incidence::List::ConstIterator it;
      for( it = incidences.begin(); it != incidences.end(); ++it ) {
//        kDebug() <<"INCIDENCE:" << (*it)->summary();
        Incidence *i = (*it)->clone();
        QString remote = (*it)->customProperty( "GWRESOURCE", "UID" );
        QString local = idMapper().localId( remote );
        if ( local.isEmpty() ) {
          idMapper().setRemoteId( i->uid(), remote );
        } else {
          i->setUid( local );
        }
        addIncidence( i );
      }
    }
    saveToCache();
    enableChangeNotification();

    clearChanges();

    emit resourceChanged( this );
    emit resourceLoaded( this );
  }

  mDownloadJob = 0;
  if ( mProgress ) mProgress->setComplete();
  mProgress = 0;
}
Ejemplo n.º 3
0
void ICalFormatTest::testCharsets()
{
  ICalFormat format;
  const QDate currentDate = QDate::currentDate();
  Event::Ptr event = Event::Ptr( new Event() );
  event->setUid( "12345" );
  event->setDtStart( KDateTime( currentDate ) );
  event->setDtEnd( KDateTime( currentDate.addDays( 1 ) ) );

  // ü
  const QChar latin1_umlaut[] = { 0xFC, '\0' };
  event->setSummary( QString( latin1_umlaut ) );

  // Test if toString( Incidence ) didn't mess charsets
  const QString serialized = format.toString( event.staticCast<Incidence>() );
  const QChar utf_umlaut[] = { 0xC3, 0XBC, '\0' };
  QVERIFY( serialized.toUtf8().contains( QString( utf_umlaut ).toLatin1().constData() ) );
  QVERIFY( !serialized.toUtf8().contains( QString( latin1_umlaut ).toLatin1().constData() ) );
  QVERIFY( serialized.toLatin1().contains( QString( latin1_umlaut ).toLatin1().constData() ) );
  QVERIFY( !serialized.toLatin1().contains( QString( utf_umlaut ).toLatin1().constData() ) );

  // test fromString( QString )
  const QString serializedCalendar =
    "BEGIN:VCALENDAR\nPRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\nVERSION:2.0\n" +
    serialized +
    "\nEND:VCALENDAR";

  Incidence::Ptr event2 = format.fromString( serializedCalendar );
  QVERIFY( event->summary() == event2->summary() );
  QVERIFY( event2->summary().toUtf8() ==
           QByteArray( QString( utf_umlaut ).toLatin1().constData() ) );

  // test save()
  MemoryCalendar::Ptr calendar( new MemoryCalendar( "UTC" ) );
  calendar->addIncidence( event );
  QVERIFY( format.save( calendar, "hommer.ics" ) );

  // Make sure hommer.ics is in UTF-8
  QFile file( "hommer.ics" );
  QVERIFY( file.open( QIODevice::ReadOnly | QIODevice::Text ) );

  const QByteArray bytesFromFile = file.readAll();
  QVERIFY( bytesFromFile.contains( QString( utf_umlaut ).toLatin1().constData() ) );
  QVERIFY( !bytesFromFile.contains( QString( latin1_umlaut ).toLatin1().constData() ) );
  file.close();

  // Test load:
  MemoryCalendar::Ptr calendar2( new MemoryCalendar( "UTC" ) );
  QVERIFY( format.load( calendar2, "hommer.ics" ) );
  QVERIFY( calendar2->incidences().count() == 1 );

  // kDebug() << format.toString( event.staticCast<Incidence>() );
  // kDebug() << format.toString( calendar2->incidences().first() );

  Event::Ptr loadedEvent = calendar2->incidences().first().staticCast<Event>();
  QVERIFY( loadedEvent->summary().toUtf8() ==
           QByteArray( QString( utf_umlaut ).toLatin1().constData() ) );
  QVERIFY( *loadedEvent == *event );

  // Test fromRawString()
  MemoryCalendar::Ptr calendar3( new MemoryCalendar( "UTC" ) );
  format.fromRawString( calendar3, bytesFromFile );
  QVERIFY( calendar3->incidences().count() == 1 );
  QVERIFY( *calendar3->incidences().first() == *event );

  unlink( "hommer.ics" );
}