/** static */ KDateTime AlarmDialog::triggerDateForIncidence( const Incidence::Ptr &incidence, const QDateTime &reminderAt, QString &displayStr ) { KDateTime result; if ( incidence->alarms().isEmpty() ) { return result; } Alarm::Ptr alarm = incidence->alarms().first(); if ( incidence->recurs() ) { result = incidence->recurrence()->getNextDateTime( KDateTime( reminderAt, KDateTime::Spec::LocalZone( ) ) ); displayStr = KGlobal::locale()->formatDateTime( result.toLocalZone() ); } if ( !result.isValid() ) { result = incidence->dateTime( Incidence::RoleAlarm ); displayStr = IncidenceFormatter::dateTimeToString( result, false, true, KDateTime::Spec::LocalZone() ); } return result; }
void AlarmDialog::slotCalendarChanged() { Akonadi::Item::List incidences = mCalendar->incidences(); for ( Akonadi::Item::List::ConstIterator it = incidences.constBegin(); it != incidences.constEnd(); ++it ) { ReminderListItem *item = searchByItem( *it ); if ( item ) { Incidence::Ptr incidence = CalendarSupport::incidence( *it ); QString displayStr; // Yes, alarms can be empty, if someone edited the incidence and removed all alarms if ( !incidence->alarms().isEmpty() ) { const KDateTime dateTime = triggerDateForIncidence( incidence, item->mRemindAt, displayStr ); const QString summary = cleanSummary( incidence->summary() ); if ( displayStr != item->text( 1 ) || summary != item->text( 0 ) ) { item->setText( 1, displayStr ); item->setText( 0, summary ); } } } } }
void CompatOutlook9::fixAlarms( const Incidence::Ptr &incidence ) { if ( !incidence ) { return; } Alarm::List alarms = incidence->alarms(); Alarm::List::Iterator it; for ( it = alarms.begin(); it != alarms.end(); ++it ) { Alarm::Ptr al = *it; if ( al && al->hasStartOffset() ) { Duration offsetDuration = al->startOffset(); int offs = offsetDuration.asSeconds(); if ( offs > 0 ) { offsetDuration = Duration( -offs ); } al->setStartOffset( offsetDuration ); } } }
void AlarmDialog::eventNotification() { bool beeped = false; bool found = false; ReminderList list; QTreeWidgetItemIterator it( mIncidenceTree ); while ( *it ) { ReminderListItem *item = static_cast<ReminderListItem *>( *it ); ++it; if ( item->isDisabled() || item->mNotified ) { //skip suspended reminders or reminders that have been notified continue; } found = true; item->mNotified = true; Incidence::Ptr incidence = CalendarSupport::incidence( item->mIncidence ); Alarm::List alarms = incidence->alarms(); Alarm::List::ConstIterator ait; for ( ait = alarms.constBegin(); ait != alarms.constEnd(); ++ait ) { Alarm::Ptr alarm = *ait; // FIXME: Check whether this should be done for all multiple alarms if ( alarm->type() == Alarm::Procedure ) { // FIXME: Add a message box asking whether the procedure should really be executed kDebug() << "Starting program: '" << alarm->programFile() << "'"; QString program = alarm->programFile(); // if the program name contains spaces escape it if ( program.contains( ' ' ) && !( program.startsWith( '\"' ) && program.endsWith( '\"' ) ) ) { program = '\"' + program + '\"'; } QProcess::startDetached( program + ' ' + alarm->programArguments() ); } else if ( alarm->type() == Alarm::Audio ) { beeped = true; Phonon::MediaObject *player = Phonon::createPlayer( Phonon::NotificationCategory, alarm->audioFile() ); player->setParent( this ); connect( player, SIGNAL(finished()), player, SLOT(deleteLater()) ); player->play(); } else if ( alarm->type() == Alarm::Email ) { QString from = CalendarSupport::KCalPrefs::instance()->email(); Identity id = KOCore::self()->identityManager()->identityForAddress( from ); QString to; if ( alarm->mailAddresses().isEmpty() ) { to = from; } else { const Person::List addresses = alarm->mailAddresses(); QStringList add; for ( Person::List::ConstIterator it = addresses.constBegin(); it != addresses.constEnd(); ++it ) { add << (*it)->fullName(); } to = add.join( ", " ); } QString subject; Akonadi::Item parentItem = mCalendar->itemForIncidenceUid( alarm->parentUid() ); Incidence::Ptr parent = CalendarSupport::incidence( parentItem ); if ( alarm->mailSubject().isEmpty() ) { if ( parent->summary().isEmpty() ) { subject = i18nc( "@title", "Reminder" ); } else { subject = i18nc( "@title", "Reminder: %1", cleanSummary( parent->summary() ) ); } } else { subject = i18nc( "@title", "Reminder: %1", alarm->mailSubject() ); } QString body = IncidenceFormatter::mailBodyStr( parent.staticCast<IncidenceBase>(), KSystemTimeZones::local() ); if ( !alarm->mailText().isEmpty() ) { body += '\n' + alarm->mailText(); } //TODO: support attachments CalendarSupport::MailClient mailer; mailer.send( id, from, to, QString(), subject, body, true, false, QString(), MailTransport::TransportManager::self()->defaultTransportName() ); } } } if ( !beeped && found ) { KNotification::beep(); } }