~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to kalarm/cal/kaevent.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Kolberg
  • Date: 2011-09-03 13:01:43 UTC
  • mfrom: (0.2.14)
  • Revision ID: package-import@ubuntu.com-20110903130143-5mmx3goibh8sgt9t
Tags: 4:4.7.1-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
996
996
            data.action    = KAAlarmEventBase::T_EMAIL;
997
997
            data.cleanText = alarm->mailText();
998
998
            int i = flags.indexOf(Private::EMAIL_ID_FLAG);
999
 
            if (i >= 0  &&  i + 1 < flags.count())
1000
 
                data.emailFromId = flags[i + 1].toUInt();
 
999
            data.emailFromId = (i >= 0  &&  i + 1 < flags.count()) ? flags[i + 1].toUInt() : 0;
1001
1000
            break;
1002
1001
        }
1003
1002
        case Alarm::Audio:
4325
4324
            /*
4326
4325
             * It's a KAlarm pre-1.4.14 or KAlarm 1.9 series pre-1.9.7 calendar file.
4327
4326
             * For recurring events, convert the main alarm offset to an absolute
4328
 
             * time in the X-KDE-KALARM-NEXTRECUR property, and convert main
4329
 
             * alarm offsets to zero and deferral alarm offsets to be relative to
 
4327
             * time in the X-KDE-KALARM-NEXTRECUR property, and set main alarm
 
4328
             * offsets to zero, and convert deferral alarm offsets to be relative to
4330
4329
             * the next recurrence.
4331
4330
             */
4332
4331
            QStringList flags = event->customProperty(KAlarm::Calendar::APPNAME, Private::FLAGS_PROPERTY).split(Private::SC, QString::SkipEmptyParts);
4346
4345
#endif
4347
4346
                if (!alarm->hasStartOffset())
4348
4347
                    continue;
 
4348
                // Find whether the alarm triggers at the same time as the main
 
4349
                // alarm, in which case its offset needs to be set to 0. The
 
4350
                // following trigger with the main alarm:
 
4351
                //  - Additional audio alarm
 
4352
                //  - PRE_ACTION_TYPE
 
4353
                //  - POST_ACTION_TYPE
 
4354
                //  - DISPLAYING_TYPE
4349
4355
                bool mainAlarm = true;
4350
4356
                QString property = alarm->customProperty(KAlarm::Calendar::APPNAME, Private::TYPE_PROPERTY);
4351
4357
                QStringList types = property.split(QChar(','), QString::SkipEmptyParts);
4352
 
                for (int i = 0;  i < types.count();  ++i)
 
4358
                for (int t = 0;  t < types.count();  ++t)
4353
4359
                {
4354
 
                    QString type = types[i];
 
4360
                    QString type = types[t];
4355
4361
                    if (type == Private::AT_LOGIN_TYPE
4356
4362
                    ||  type == Private::TIME_DEFERRAL_TYPE
4357
4363
                    ||  type == Private::DATE_DEFERRAL_TYPE
4358
4364
                    ||  type == Private::REMINDER_TYPE
4359
 
                    ||  type == REMINDER_ONCE_TYPE
4360
 
                    ||  type == Private::DISPLAYING_TYPE
4361
 
                    ||  type == Private::PRE_ACTION_TYPE
4362
 
                    ||  type == Private::POST_ACTION_TYPE)
 
4365
                    ||  type == REMINDER_ONCE_TYPE)
 
4366
                    {
4363
4367
                        mainAlarm = false;
 
4368
                        break;
 
4369
                    }
4364
4370
                }
4365
4371
                if (mainAlarm)
4366
4372
                {
4367
 
                    mainExpired = false;
4368
 
                    nextMainDateTime = alarm->time();
4369
 
                    nextMainDateTime.setDateOnly(dateOnly);
4370
 
                    nextMainDateTime = nextMainDateTime.toTimeSpec(startDateTime);
4371
 
                    if (nextMainDateTime != startDateTime)
 
4373
                    if (mainExpired)
4372
4374
                    {
4373
 
                        QDateTime dt = nextMainDateTime.dateTime();
4374
 
                        event->setCustomProperty(KAlarm::Calendar::APPNAME, Private::NEXT_RECUR_PROPERTY,
4375
 
                                                 dt.toString(dateOnly ? "yyyyMMdd" : "yyyyMMddThhmmss"));
 
4375
                        // All main alarms are supposed to be at the same time, so
 
4376
                        // don't readjust the event's time for subsequent main alarms.
 
4377
                        mainExpired = false;
 
4378
                        nextMainDateTime = alarm->time();
 
4379
                        nextMainDateTime.setDateOnly(dateOnly);
 
4380
                        nextMainDateTime = nextMainDateTime.toTimeSpec(startDateTime);
 
4381
                        if (nextMainDateTime != startDateTime)
 
4382
                        {
 
4383
                            QDateTime dt = nextMainDateTime.dateTime();
 
4384
                            event->setCustomProperty(KAlarm::Calendar::APPNAME, Private::NEXT_RECUR_PROPERTY,
 
4385
                                                     dt.toString(dateOnly ? "yyyyMMdd" : "yyyyMMddThhmmss"));
 
4386
                        }
4376
4387
                    }
4377
4388
                    alarm->setStartOffset(0);
4378
4389
                    converted = true;
4404
4415
                        continue;
4405
4416
                    QString property = alarm->customProperty(KAlarm::Calendar::APPNAME, Private::TYPE_PROPERTY);
4406
4417
                    QStringList types = property.split(QChar(','), QString::SkipEmptyParts);
4407
 
                    for (int i = 0;  i < types.count();  ++i)
 
4418
                    for (int t = 0;  t < types.count();  ++t)
4408
4419
                    {
4409
 
                        QString type = types[i];
 
4420
                        QString type = types[t];
4410
4421
                        if (type == Private::TIME_DEFERRAL_TYPE
4411
4422
                        ||  type == Private::DATE_DEFERRAL_TYPE)
4412
4423
                        {
4615
4626
                    continue;
4616
4627
                if (data.type & KAAlarm::TIMED_DEFERRAL_FLAG)
4617
4628
                {
4618
 
                    // Timed deferral alarm, so adjust the offset
 
4629
                    // Found a timed deferral alarm, so adjust the offset
4619
4630
                    deferralOffset = data.alarm->startOffset().asSeconds();
4620
4631
#ifdef USE_AKONADI
4621
 
                    constCast<Alarm::Ptr>(data.alarm)->setStartOffset(deferralOffset - adjustment);
 
4632
                    const_cast<Alarm*>(data.alarm.data())->setStartOffset(deferralOffset - adjustment);
4622
4633
#else
4623
4634
                    const_cast<Alarm*>(data.alarm)->setStartOffset(deferralOffset - adjustment);
4624
4635
#endif
4626
4637
                else if (data.type == KAAlarm::AUDIO__ALARM
4627
4638
                &&       data.alarm->startOffset().asSeconds() == deferralOffset)
4628
4639
                {
4629
 
                    // Audio alarm is set for the same time as the deferral alarm
 
4640
                    // Audio alarm is set for the same time as the above deferral alarm
4630
4641
#ifdef USE_AKONADI
4631
 
                    constCast<Alarm::Ptr>(data.alarm)->setStartOffset(deferralOffset - adjustment);
 
4642
                    const_cast<Alarm*>(data.alarm.data())->setStartOffset(deferralOffset - adjustment);
4632
4643
#else
4633
4644
                    const_cast<Alarm*>(data.alarm)->setStartOffset(deferralOffset - adjustment);
4634
4645
#endif
4640
4651
    else
4641
4652
    {
4642
4653
        // It's a timed event. Fix any untimed alarms.
 
4654
        bool foundDeferral = false;
4643
4655
        int deferralOffset = 0;
4644
4656
        int newDeferralOffset = 0;
4645
4657
        DateTime start;
4654
4666
            if ((data.type & KAAlarm::DEFERRED_ALARM)
4655
4667
            &&  !(data.type & KAAlarm::TIMED_DEFERRAL_FLAG))
4656
4668
            {
4657
 
                // Date-only deferral alarm, so adjust its time
 
4669
                // Found a date-only deferral alarm, so adjust its time
4658
4670
                KDateTime altime = data.alarm->startOffset().end(nextMainDateTime);
4659
4671
                altime.setTime(midnight);
4660
4672
                deferralOffset = data.alarm->startOffset().asSeconds();
4661
4673
                newDeferralOffset = event->dtStart().secsTo(altime);
4662
4674
#ifdef USE_AKONADI
4663
 
                constCast<Alarm::Ptr>(data.alarm)->setStartOffset(newDeferralOffset);
 
4675
                const_cast<Alarm*>(data.alarm.data())->setStartOffset(newDeferralOffset);
4664
4676
#else
4665
4677
                const_cast<Alarm*>(data.alarm)->setStartOffset(newDeferralOffset);
4666
4678
#endif
 
4679
                foundDeferral = true;
4667
4680
                changed = true;
4668
4681
            }
4669
 
            else if (data.type == KAAlarm::AUDIO__ALARM
4670
 
            &&       data.alarm->startOffset().asSeconds() == deferralOffset)
 
4682
            else if (foundDeferral
 
4683
                 &&  data.type == KAAlarm::AUDIO__ALARM
 
4684
                 &&  data.alarm->startOffset().asSeconds() == deferralOffset)
4671
4685
            {
4672
 
                // Audio alarm is set for the same time as the deferral alarm
 
4686
                // Audio alarm is set for the same time as the above deferral alarm
4673
4687
#ifdef USE_AKONADI
4674
 
                constCast<Alarm::Ptr>(data.alarm)->setStartOffset(newDeferralOffset);
 
4688
                const_cast<Alarm*>(data.alarm.data())->setStartOffset(newDeferralOffset);
4675
4689
#else
4676
4690
                const_cast<Alarm*>(data.alarm)->setStartOffset(newDeferralOffset);
4677
4691
#endif