Example #1
0
int KMobileGnokii::storeCalendarEntry( int index, const KCal::Event &event )
{
  if (index < 0 || index >= GN_CALNOTE_MAX_NUMBER)
	return KIO::ERR_DOES_NOT_EXIST;

  gn_error error;
  gn_calnote entry;

  gn_data_clear(&data);
  memset(&entry, 0, sizeof(entry));
  entry.location = index+1;
  data.calnote = &entry;
  data.calnote_list = &calnote_list;

  // read first
  error = gn_sm_functions(GN_OP_GetCalendarNote, &data, &state);
  // GNOKII_CHECK_ERROR(error);

  QDateTime_2_timestamp( event.dtStart(), entry.time );
  strncpy(entry.text, event.summary().utf8(), sizeof(entry.text)-1);

  // type:
  entry.type = GN_CALNOTE_MEETING;
  if (event.categories().findIndex(i18n("MEETING")) != -1) {
	entry.type = GN_CALNOTE_MEETING;
  } else if (event.categories().findIndex(i18n("PHONE CALL")) != -1) {
	entry.type = GN_CALNOTE_CALL;
  	strncpy(entry.phone_number, event.description().utf8(), sizeof(entry.phone_number)-1);
  } else if (event.categories().findIndex(i18n("BIRTHDAY")) != -1) {
	entry.type = GN_CALNOTE_BIRTHDAY;
  } else { // assume i18n("REMINDER")
	entry.type = GN_CALNOTE_REMINDER;
  }

  // alarm:
  entry.alarm.enabled = 0;
  if (event.isAlarmEnabled()) {
	const KCal::Alarm *eventalarm = *event.alarms().at(0);
	if (eventalarm) {
		if (eventalarm->hasTime()) {

		   QDateTime_2_timestamp( eventalarm->time(), entry.alarm.timestamp );
		} else
		if (eventalarm->hasStartOffset()) {
		   QDateTime dt = event.dtStart();
		   dt = dt.addSecs(-eventalarm->startOffset().asSeconds());
		   QDateTime_2_timestamp( dt, entry.alarm.timestamp );
		}
	}
  }

  // recurrence:
  switch (event.recurrence()->recurrenceType()) {
  case KCal::Recurrence::rNone:
  default:
		entry.recurrence = GN_CALNOTE_NEVER;
		break;
  case KCal::Recurrence::rHourly:
		entry.recurrence = (gn_calnote_recurrence) (event.recurrence()->frequency());
		break;
  case KCal::Recurrence::rDaily:
		entry.recurrence = GN_CALNOTE_DAILY;
		break;
  case KCal::Recurrence::rWeekly:
		entry.recurrence = (gn_calnote_recurrence) (GN_CALNOTE_WEEKLY * event.recurrence()->frequency());
		break;
  case KCal::Recurrence::rMonthlyPos:
  case KCal::Recurrence::rMonthlyDay:
		entry.recurrence = GN_CALNOTE_MONTHLY;
		break;
  case KCal::Recurrence::rYearlyMonth:
  case KCal::Recurrence::rYearlyDay:
  case KCal::Recurrence::rYearlyPos:
		entry.recurrence = GN_CALNOTE_YEARLY;
		break;
  }

  print_calnote( entry );

return 0; // XXX

  error = gn_sm_functions(GN_OP_WriteCalendarNote, &data, &state);
  GNOKII_CHECK_ERROR(error);

  return 0;
}
Example #2
0
/******************************************************************************
* Check if any alarms are pending for a specified calendar, and display the
* pending alarms.
*/
void AlarmDaemon::checkAlarms(ADCalendar *cal)
{
    kdDebug(5901) << "AlarmDaemons::checkAlarms(" << cal->urlString() << ")" << endl;
    if(!cal->loaded()  ||  !cal->enabled())
        return;

    QDateTime now  = QDateTime::currentDateTime();
    kdDebug(5901) << "  To: " << now.toString() << endl;
    QValueList<KCal::Alarm *> alarms = cal->alarmsTo(now);
    if(!alarms.count())
        return;
    QValueList<KCal::Event *> eventsDone;
    for(QValueList<KCal::Alarm *>::ConstIterator it = alarms.begin();  it != alarms.end();  ++it)
    {
        KCal::Event *event = dynamic_cast<KCal::Event *>((*it)->parent());
        if(!event  ||  eventsDone.find(event) != eventsDone.end())
            continue;   // either not an event, or the event has already been processed
        eventsDone += event;
        const QString &eventID = event->uid();
        kdDebug(5901) << "AlarmDaemon::checkAlarms(): event " << eventID  << endl;

        // Check which of the alarms for this event are due.
        // The times in 'alarmtimes' corresponding to due alarms are set.
        // The times for non-due alarms are set invalid in 'alarmtimes'.
        bool recurs = event->doesRecur();
        const QStringList cats = event->categories();
        bool floats = (cats.find(QString::fromLatin1("DATE")) != cats.end());
        QDateTime nextDateTime = event->dtStart();
        if(recurs)
        {
            QString prop = event->customProperty("KALARM", "NEXTRECUR");
            if(prop.length() >= 8)
            {
                // The next due recurrence time is specified
                QDate d(prop.left(4).toInt(), prop.mid(4, 2).toInt(), prop.mid(6, 2).toInt());
                if(d.isValid())
                {
                    if(floats  &&  prop.length() == 8)
                        nextDateTime = d;
                    else if(!floats  &&  prop.length() == 15  &&  prop[8] == QChar('T'))
                    {
                        QTime t(prop.mid(9, 2).toInt(), prop.mid(11, 2).toInt(), prop.mid(13, 2).toInt());
                        if(t.isValid())
                            nextDateTime = QDateTime(d, t);
                    }
                }
            }
        }
        if(floats)
            nextDateTime.setTime(mStartOfDay);
        QValueList<QDateTime> alarmtimes;
        KCal::Alarm::List alarms = event->alarms();
        for(KCal::Alarm::List::ConstIterator al = alarms.begin();  al != alarms.end();  ++al)
        {
            KCal::Alarm *alarm = *al;
            QDateTime dt;
            if(alarm->enabled())
            {
                QDateTime dt1;
                if(!alarm->hasTime())
                {
                    // Find the latest recurrence for the alarm.
                    // Need to do this for alarms with offsets in order to detect
                    // reminders due for recurrences.
                    int offset = alarm->hasStartOffset() ? alarm->startOffset().asSeconds()
                                 : alarm->endOffset().asSeconds() + event->dtStart().secsTo(event->dtEnd());
                    if(offset)
                    {
                        dt1 = nextDateTime.addSecs(floats ? (offset / SECS_PER_DAY) * SECS_PER_DAY : offset);
                        if(dt1 > now)
                            dt1 = QDateTime();
                    }
                }
                // Get latest due repetition, or the recurrence time if none
                dt = nextDateTime;
                if(nextDateTime <= now  &&  alarm->repeatCount() > 0)
                {
                    int snoozeSecs = alarm->snoozeTime() * 60;
                    int offset = alarm->repeatCount() * snoozeSecs;
                    QDateTime lastRepetition = nextDateTime.addSecs(floats ? (offset / SECS_PER_DAY) * SECS_PER_DAY : offset);
                    if(lastRepetition <= now)
                        dt = lastRepetition;
                    else
                    {
                        int repetition = nextDateTime.secsTo(now) / snoozeSecs;
                        int offset = repetition * snoozeSecs;
                        dt = nextDateTime.addSecs(floats ? (offset / SECS_PER_DAY) * SECS_PER_DAY : offset);
                    }
                }
                if(!dt.isValid()  ||  dt > now
                        ||  dt1.isValid()  &&  dt1 > dt)  // already tested dt1 <= now
                    dt = dt1;
            }
            alarmtimes.append(dt);
        }
        if(!cal->eventHandled(event, alarmtimes))
        {
            if(notifyEvent(cal, eventID))
                cal->setEventPending(event, alarmtimes);
        }
    }
}