Esempio n. 1
0
// Exporting Event data to map. Using the same
// encoding as ODateBookAccessBackend_xml does..
// Thus, we could remove the stuff there and use this
// for it and for all other places..
// Encoding should happen at one place, only ! (eilers)
QMap<int, QString> OEvent::toMap()const {
    QMap<int, QString> retMap;

    retMap.insert( OEvent::FUid, QString::number( uid() ) );
    retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ));
    retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) );
    retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) );
    retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" );
    OPimAlarm alarm = notifiers().alarms()[0];
    retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo(  startDateTime() ) / 60 ) );
    retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" );

    OTimeZone zone(  timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
    retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime(  startDateTime(), OTimeZone::utc() ) ) ) );
    retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime(  endDateTime(), OTimeZone::utc() ) ) ) );
    retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) );
    retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
    if( parent() )
	    retMap.insert( OEvent::FRecParent, QString::number( parent() ) );
    if( children().count() ){
            QArray<int> childr = children();
	    QString buf;
            for ( uint i = 0; i < childr.count(); i++ ) {
		    if ( i != 0 ) buf += " ";
		    buf += QString::number( childr[i] );
            }
	    retMap.insert( OEvent::FRecChildren, buf );
    }

    // Add recurrence stuff
    if( hasRecurrence() ){
	    ORecur recur = recurrence();
	    QMap<int, QString> recFields = recur.toMap();
	    retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
	    retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] );
	    retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] );
	    retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] );
	    retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] );
	    retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] );
	    retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] );
	    retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] );
    } else {
	    ORecur recur = recurrence();
	    QMap<int, QString> recFields = recur.toMap();
	    retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
    }

    return retMap;
}
Esempio n. 2
0
QString LxQtWorldClock::formatDateTime(const QDateTime &datetime, const QString &timeZoneName)
{
    QTimeZone timeZone(timeZoneName.toLatin1());
    QDateTime tzNow = datetime.toTimeZone(timeZone);
    QString result;
    switch (mFormatType)
    {
    case FORMAT_CUSTOM:
        result = tzNow.toString(preformat(mCustomFormat, timeZone, tzNow));
        break;

    case FORMAT_SHORT_TIMEONLY:
    case FORMAT_LONG_TIMEONLY:
        result = tzNow.time().toString(mFormat);
        break;

    case FORMAT_SHORT:
    case FORMAT_LONG:
        result = tzNow.toString(mFormat);
        break;

    default:;
    }

    return result;
}
int LXQtWorldClockConfigurationTimeZones::updateAndExec()
{
    QDateTime now = QDateTime::currentDateTime();

    ui->timeZonesTW->clear();

    QMap<QString, QTreeWidgetItem*> parentItems;

    foreach(QByteArray ba, QTimeZone::availableTimeZoneIds())
    {
        QTimeZone timeZone(ba);
        QString ianaId(ba);
        QStringList qStrings(QString(ba).split(QLatin1Char('/')));

        if ((qStrings.size() == 1) && (qStrings[0].startsWith(QLatin1String("UTC"))))
            qStrings.prepend(tr("UTC"));

        if (qStrings.size() == 1)
            qStrings.prepend(tr("Other"));

        QTreeWidgetItem *tzItem = new QTreeWidgetItem(QStringList() << qStrings[qStrings.length() - 1] << timeZone.displayName(now) << timeZone.comment() << QLocale::countryToString(timeZone.country()));
        tzItem->setData(0, Qt::UserRole, ianaId);

        makeSureParentsExist(qStrings, parentItems)->addChild(tzItem);
    }
Esempio n. 4
0
void LXQtWorldClock::activated(ActivationReason reason)
{
    switch (reason)
    {
    case ILXQtPanelPlugin::Trigger:
    case ILXQtPanelPlugin::MiddleClick:
        break;

    default:
        return;
    }

    if (!mPopup)
    {
        mPopup = new LXQtWorldClockPopup(mContent);
        connect(mPopup, SIGNAL(deactivated()), SLOT(deletePopup()));

        if (reason == ILXQtPanelPlugin::Trigger)
        {
            mPopup->setObjectName(QLatin1String("WorldClockCalendar"));

            mPopup->layout()->setContentsMargins(0, 0, 0, 0);
            QCalendarWidget *calendarWidget = new QCalendarWidget(mPopup);
            mPopup->layout()->addWidget(calendarWidget);

            QString timeZoneName = mActiveTimeZone;
            if (timeZoneName == QLatin1String("local"))
                timeZoneName = QString::fromLatin1(QTimeZone::systemTimeZoneId());

            QTimeZone timeZone(timeZoneName.toLatin1());
            calendarWidget->setFirstDayOfWeek(QLocale(QLocale::AnyLanguage, timeZone.country()).firstDayOfWeek());
            calendarWidget->setSelectedDate(QDateTime::currentDateTime().toTimeZone(timeZone).date());
        }
        else
        {
            mPopup->setObjectName(QLatin1String("WorldClockPopup"));

            mPopupContent = new QLabel(mPopup);
            mPopup->layout()->addWidget(mPopupContent);
            mPopupContent->setAlignment(mContent->alignment());

            updatePopupContent();
        }

        mPopup->adjustSize();
        mPopup->setGeometry(calculatePopupWindowPos(mPopup->size()));

        willShowWindow(mPopup);
        mPopup->show();
    }
    else
    {
        deletePopup();
    }
}
QVariant CalendarItemModel::timeZone( const Calendar *a, int role ) const
{
    //kDebug(planDbg())<<res->name()<<","<<role;
    switch ( role ) {
        case Qt::DisplayRole:
        case Qt::EditRole:
        case Qt::ToolTipRole:
            return i18n( a->timeZone().name().toUtf8() );
        case Role::EnumList: {
            QStringList lst;
            foreach ( const KTimeZone &tz, KSystemTimeZones::timeZones()->zones() ) {
                lst << i18n( tz.name().toUtf8() );
            }
            lst.sort();
            return lst;
        }
        case Role::EnumListValue: {
            QStringList lst = timeZone( a, Role::EnumList ).toStringList();
            return lst.indexOf( i18n ( a->timeZone().name().toUtf8() ) );
        }
        case Qt::StatusTipRole:
        case Qt::WhatsThisRole:
            return QVariant();
    }
Esempio n. 6
0
void OEvent::fromMap( const QMap<int, QString>& map )
{

	// We just want to set the UID if it is really stored.
	if ( !map[OEvent::FUid].isEmpty() )
		setUid( map[OEvent::FUid].toInt() );

	setCategories( idsFromString( map[OEvent::FCategories] ) );
	setDescription( map[OEvent::FDescription] );
	setLocation( map[OEvent::FLocation] );

	if ( map[OEvent::FType] == "AllDay" )
		setAllDay( true );
	else
		setAllDay( false );

	int alarmTime = -1;
	if( !map[OEvent::FAlarm].isEmpty() )
		alarmTime = map[OEvent::FAlarm].toInt();

	int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
	if ( ( alarmTime != -1 )  ){
		QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 );
		OPimAlarm al( sound ,  dt  );
		notifiers().add( al );
	}
	if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){
		setTimeZone( map[OEvent::FTimeZone] );
	}

	time_t start = (time_t) map[OEvent::FStart].toLong();
	time_t end   = (time_t) map[OEvent::FEnd].toLong();

	/* AllDay is always in UTC */
	if ( isAllDay() ) {
		OTimeZone utc = OTimeZone::utc();
		setStartDateTime( utc.fromUTCDateTime( start ) );
		setEndDateTime  ( utc.fromUTCDateTime( end   ) );
		setTimeZone( "UTC"); // make sure it is really utc
	}else {
		/* to current date time */
		// qWarning(" Start is %d", start );
		OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
		QDateTime date = zone.toDateTime( start );
		qWarning(" Start is %s", date.toString().latin1() );
		setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) );

		date = zone.toDateTime( end );
		setEndDateTime  ( zone.toDateTime( date, OTimeZone::current() ) );
	}

	if ( !map[OEvent::FRecParent].isEmpty() )
		setParent( map[OEvent::FRecParent].toInt() );

	if ( !map[OEvent::FRecChildren].isEmpty() ){
		QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] );
		for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
			addChild( (*it).toInt() );
		}
	}

	// Fill recurrence stuff and put it directly into the ORecur-Object using fromMap..
	if( !map[OEvent::FRType].isEmpty() ){
		QMap<int, QString> recFields;
		recFields.insert( ORecur::RType, map[OEvent::FRType] );
		recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] );
		recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] );
		recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] );
		recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] );
		recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] );
		recFields.insert( ORecur::Created, map[OEvent::FRCreated] );
		recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] );
		ORecur recur( recFields );
		setRecurrence( recur );
	}

}
Esempio n. 7
0
QString LXQtWorldClock::formatDateTime(const QDateTime &datetime, const QString &timeZoneName)
{
    QTimeZone timeZone(timeZoneName.toLatin1());
    QDateTime tzNow = datetime.toTimeZone(timeZone);
    return tzNow.toString(preformat(mFormat, timeZone, tzNow));
}
// -----------------------------------------------------------------------------
// CDrmUtilityCommon::GetOmaRightsStatusL
//
// -----------------------------------------------------------------------------
//
EXPORT_C DRM::TDrmRightsInfo DRM::CDrmUtilityCommon::GetOmaRightsStatusL(
    HBufC8*& aContentUri,
    ContentAccess::TIntent aIntent,
    CDRMConstraint* aConstraint )
    {
    CDRMPointerArray<CDRMPermission>* uriList( NULL );
    CDRMPointerArray<HBufC8>* individuals( NULL );
    RDRMClockClient clockClient;
    DRMClock::ESecurityLevel secLevel( DRMClock::KInsecure );
    TTime drmTime( Time::NullTTime() );
    TBool possiblefuture( EFalse );
    CDRMConstraint* constraint( NULL );
    CDRMConstraint* toplevel( NULL );
    TUint32 retval( 0 );
    TInt r( KErrNone );

    r = clockClient.Connect();
    CleanupClosePushL( clockClient );
    if ( !r )
        {
        TInt timeZone( 0 );
        clockClient.GetSecureTime( drmTime, timeZone, secLevel );
        }

    uriList = CDRMPointerArray<CDRMPermission>::NewLC();
    uriList->SetAutoCleanup( ETrue );
    TRAP_IGNORE( iOmaClient.GetDBEntriesL( *aContentUri, *uriList ) );

    if ( !uriList->Count() )
        {
        CleanupStack::PopAndDestroy( 2, &clockClient ); //clockClient, uriList
        return DRM::EURightsInfoMissing;
        }

    individuals = CDRMPointerArray<HBufC8>::NewLC();
    individuals->SetAutoCleanup( ETrue );
    TRAP_IGNORE( iOmaClient.GetSupportedIndividualsL( *individuals ) );

    // Now we have the time, rights and the individual constraints do the
    // checking. The rights are never valid if we get here so we don't have
    // to check for that
    for ( TInt i( 0 ); i < uriList->Count() && !possiblefuture ; i++ )
        {
        toplevel = NULL;
        constraint = NULL;

        // If the toplevel constraint is defined, get it:
        toplevel = (*uriList)[i]->TopLevelConstraint();
        // If constraint for the intent is defined, get it
        constraint = (*uriList)[i]->ConstraintForIntent( aIntent );

        // Top level constraint and constraint for intent, merge them
        if ( toplevel && constraint )
            {
            constraint->Merge( *toplevel );
            }
        // Only constraint for intent, use it
        else if ( constraint )
            {
            }
        // Only top level constraint or no constraints at all, continue
        else
            {
            continue;
            }

        // If the constraint is rejected due to non time reasons or there is no
        // time it can't be future
        constraint->Valid( drmTime, *individuals, retval );
        if ( retval & EConstraintCounter ||
             retval & EConstraintAccumulated ||
             retval & EConstraintTimedCounter ||
             retval & EConstraintIndividual ||
             retval & EConstraintNullDrmTime )
            {
            continue;
            }

        drmTime.HomeTime();

        // If the constrain has active start time and it is not valid,
        // it must be future
        if ( constraint->iActiveConstraints & EConstraintStartTime )
            {
            possiblefuture = ETrue;
            if ( aConstraint )
                {
                aConstraint->DuplicateL( *constraint );
                }
            }

        // If the constrain has active interval and it´s start time is in
        // future, it must be future
        else if ( constraint->iActiveConstraints & EConstraintInterval &&
                  constraint->iIntervalStart > drmTime )
            {
            possiblefuture = ETrue;
            if ( aConstraint )
                {
                aConstraint->DuplicateL( *constraint );
                }
            }
        } // End of for loop

    CleanupStack::PopAndDestroy( 3, &clockClient ); //individuals, urilist,
                                                    //clockClient
    return possiblefuture ? DRM::EURightsInfoFuture : DRM::EURightsInfoExpired;
    }