示例#1
0
bool FileStorage::load()
{
  // do we want to silently accept this, or make some noise?  Dunno...
  // it is a semantical thing vs. a practical thing.
  if ( d->mFileName.isEmpty() ) {
    return false;
  }

  // Always try to load with iCalendar. It will detect, if it is actually a
  // vCalendar file.
  bool success;
  // First try the supplied format. Otherwise fall through to iCalendar, then
  // to vCalendar
  success = saveFormat() && saveFormat()->load( calendar(), d->mFileName );
  if ( !success ) {
    ICalFormat iCal;

    success = iCal.load( calendar(), d->mFileName );

    if ( !success ) {
      if ( iCal.exception() ) {
        if ( iCal.exception()->code() == Exception::CalVersion1 ) {
          // Expected non vCalendar file, but detected vCalendar
          kDebug() << "Fallback to VCalFormat";
          VCalFormat vCal;
          success = vCal.load( calendar(), d->mFileName );
          calendar()->setProductId( vCal.productId() );
        } else {
          return false;
        }
      } else {
        kDebug() << "Warning! There should be an exception set.";
        return false;
      }
    } else {
      calendar()->setProductId( iCal.loadedProductId() );
    }
  }

  calendar()->setModified( false );

  return true;
}