Esempio n. 1
0
int replace(int ac, char **av)
{
  int cookie ;
  if(!pcrecpp::RE("([0-9]+)").FullMatch(av[0], &cookie))
  {
    qDebug() << "invalid integer:" << av[0] ;
    return 1 ;
  }
  QString title = QString("replacement_of_%1").arg(cookie) ;
  Maemo::Timed::Event e ;
  Maemo::Timed::Event::Action &a = e.addAction() ;
  a.whenTriggered() ;
  a.setSendCookieFlag() ;
  a.runCommand(QString("echo cookie=[COOKIE] (%1) TRIGGERED $(date) >> /tmp/aa").arg(title)) ;

  e.setAttribute("TITLE", title) ;
  e.setTicker(time(NULL)+10) ;

  Maemo::Timed::Interface timed ;
  if(!timed.isValid())
  {
    qDebug() << "not valid interface:" << timed.lastError() ;
    return 1 ;
  }

  QDBusReply<uint> res = timed.replace_event_sync(e, cookie) ;
  if(!res.isValid())
  {
    qDebug() << "replace_event call failed:" << res.error().message() ;
    return 1 ;
  }

  qDebug() << "new event cookie:" << res.value() ;
  return 0 ;
}
Esempio n. 2
0
Maemo::Timed::Event tst_Events::createEvent(const qint64 timestamp, const int dueInSeconds)
{
    // Create an event, which will go off in dueInSeconds
    Maemo::Timed::Event event;
    event.setAttribute("APPLICATION", APPNAME);
    event.setAttribute("TITLE", QString("%1").arg(timestamp));
    event.setAlarmFlag();
    event.setReminderFlag();
    QDateTime dateTime;
    dateTime.setMSecsSinceEpoch(timestamp);
    event.setTicker(dateTime.toTime_t() + dueInSeconds);

    // Add an action to the event, the action writes a message to a file when the event is triggered
    Maemo::Timed::Event::Action &act = event.addAction();
    act.setSendCookieFlag();
    // Timed will replace <COOKIE> with the cookie of the event that triggers this action
    QString message = QString(ACTIONSTRING).arg(timestamp).arg("<COOKIE>");
    act.runCommand(QString("echo -n %1 > %2")
                   .arg(message)
                   .arg(PATH));
    act.whenTriggered();

    return event;
}
void AlarmObject::save()
{
    try {
        Maemo::Timed::Event ev;
        // Keep the event after it has triggered
        ev.setKeepAliveFlag();
        // Trigger the voland alarm/reminder dialog
        ev.setReminderFlag();
        if (!m_title.isEmpty())
            ev.setAttribute(QLatin1String("TITLE"), m_title);

        ev.setAttribute(QLatin1String("timeOfDay"), QString::number(m_hour * 60 + m_minute));
        ev.setAttribute(QLatin1String("APPLICATION"), QLatin1String("nemoalarms"));
        ev.setAttribute(QLatin1String("createdDate"), QString::number(m_createdDate.toMSecsSinceEpoch()));
        ev.setAlarmFlag();

        if (!m_countdown) {
            ev.setBootFlag();

            if (!m_daysOfWeek.isEmpty())
                ev.setAttribute(QLatin1String("daysOfWeek"), m_daysOfWeek);

            if (m_enabled) {
                Maemo::Timed::Event::Recurrence rec = ev.addRecurrence();
                rec.addHour(m_hour);
                rec.addMinute(m_minute);
                rec.everyDayOfMonth();
                rec.everyMonth();

                // Single-shot alarms are done with a recurrence and the single-shot
                // flag, which removes recurrence information after the first trigger.
                if (m_daysOfWeek.isEmpty()) {
                    rec.everyDayOfWeek();
                    ev.setSingleShotFlag();
                }

                // Map characters to numeric weekdays used by libtimed
                QString weekdayMap(QLatin1String("SmtwTfs"));
                for (int i = 0; i < m_daysOfWeek.size(); i++) {
                    int day = weekdayMap.indexOf(m_daysOfWeek[i]);
                    if (day >= 0)
                        rec.addDayOfWeek(day);
                }
            }
            ev.setAttribute(QLatin1String("type"), QLatin1String("clock"));
        } else {
            uint duration = m_hour * 3600 + m_minute * 60;
            QDateTime now = QDateTime::currentDateTimeUtc();
            if (m_enabled) {
                QDateTime triggerDateTime = now.addSecs(duration - m_elapsed);
                m_triggerTime = triggerDateTime.toTime_t();
                ev.setTicker(triggerDateTime.toTime_t());
            } else {
                if (m_triggerTime > 0) {
                    m_elapsed = (duration - (m_triggerTime - now.toTime_t()));
                    m_triggerTime = 0;
                } else {
                    m_elapsed = 0;
                }
                emit elapsedChanged();
                ev.setAttribute(QLatin1String("elapsed"), QString::number(m_elapsed));
            }
            emit triggerTimeChanged();
            ev.setAttribute(QLatin1String("triggerTime"), QString::number(m_triggerTime));
            ev.setAttribute(QLatin1String("type"), QLatin1String("countdown"));
        }

        QDBusPendingCallWatcher *w;
        if (m_cookie)
            w = new QDBusPendingCallWatcher(TimedInterface::instance()->replace_event_async(ev, m_cookie), this);
        else
            w = new QDBusPendingCallWatcher(TimedInterface::instance()->add_event_async(ev), this);
        connect(w, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(saveReply(QDBusPendingCallWatcher*)));

        // Emit the updated signal immediately to update UI
        emit updated();
    } catch (Maemo::Timed::Exception &e) {
        qWarning() << "org.nemomobile.alarms: Cannot sync alarm to timed:" << e.what();
    }
}
Esempio n. 4
0
int add_event(const char *title)
{
  bool need_ui = title != NULL ;
  bool recurrence = false ;
  int time_shift = 8 ;

  Maemo::Timed::Event e ;
  Maemo::Timed::Event::Action &a_trig = e.addAction() ;
  a_trig.whenTriggered() ;
  a_trig.setSendCookieFlag() ;
  a_trig.runCommand("echo cookie=[COOKIE]=<COOKIE> TRIGGERED $(date) >> " TRIGGER_FILE) ;

  if(title!=NULL)
  {
    e.setAttribute("TITLE", title) ;

    if(pcrecpp::RE("boot").PartialMatch(title))
      e.setBootFlag() ;

    if(pcrecpp::RE("alarm").PartialMatch(title))
      e.setAlarmFlag() ;

    if(pcrecpp::RE("usermode").PartialMatch(title))
      e.setUserModeFlag() ;

    if(pcrecpp::RE("silent").PartialMatch(title))
      need_ui = false ;

    if(pcrecpp::RE("recur").PartialMatch(title))
      recurrence = true ;

    if(pcrecpp::RE("calendar").PartialMatch(title))
      e.setAttribute("PLUGIN", "libCalendarReminder") ;

    int time_to_wait ;
    if(pcrecpp::RE("/(-?\\d+)/").PartialMatch(title, &time_to_wait))
      time_shift = time_to_wait ;
  }

  if(need_ui)
  {
    e.setAlignedSnoozeFlag() ;

    Maemo::Timed::Event::Button &b1 = e.addButton() ;
    Maemo::Timed::Event::Button &b2 = e.addButton() ;
    Maemo::Timed::Event::Button &b3 = e.addButton() ;
    Maemo::Timed::Event::Button &b4 = e.addButton() ;

    b1.setSnooze(10) ;
    b2.setSnooze(17) ;
    b3.setSnooze(60) ;
    (void)b4 ;
    // b4 doesn't snooze: it closes the dialog

    Maemo::Timed::Event::Action &a1 = e.addAction() ;
    a1.runCommand("echo [COOKIE] BUTTON #1 $(date) >> " TRIGGER_FILE) ;
    a1.setSendCookieFlag() ;
    a1.whenButton(b1) ;

    Maemo::Timed::Event::Action &a2 = e.addAction() ;
    a2.runCommand("echo [COOKIE] BUTTON #2 $(date) >> " TRIGGER_FILE) ;
    a2.setSendCookieFlag() ;
    a2.whenButton(b2) ;

    Maemo::Timed::Event::Action &a3 = e.addAction() ;
    a3.runCommand("echo [COOKIE] BUTTON #3 $(date) >> " TRIGGER_FILE) ;
    a3.setSendCookieFlag() ;
    a3.whenButton(b3) ;

    Maemo::Timed::Event::Action &a4 = e.addAction() ;
    a4.runCommand("echo [COOKIE] BUTTON #4 $(date) >> " TRIGGER_FILE) ;
    a4.setSendCookieFlag() ;
    a4.whenButton(b1) ;

    Maemo::Timed::Event::Action &a_0 = e.addAction() ;
    a_0.runCommand("echo [COOKIE] CANCELED BY USER $(date) >> " TRIGGER_FILE) ;
    a_0.setSendCookieFlag() ;
    a_0.whenSysButton(0) ;

    Maemo::Timed::Event::Action &a_sys1 = e.addAction() ;
    a_sys1.runCommand("echo [COOKIE] FIRST SYSTEM BYTTON $(date) >> " TRIGGER_FILE);
    a_sys1.setSendCookieFlag() ;
    a_sys1.whenSysButton(1) ;

    Maemo::Timed::Event::Action &a_sys2 = e.addAction() ;
    a_sys2.runCommand("echo [COOKIE] SECOND SYSTEM BYTTON $(date) >> " TRIGGER_FILE) ;
    a_sys2.setSendCookieFlag() ;
    a_sys2.whenSysButton(2) ;
  }

  if(recurrence) // add a recurrence at 12:34 every day
  {
    Maemo::Timed::Event::Recurrence &r = e.addRecurrence() ;
    r.everyMonth() ;
    r.everyDayOfMonth() ;
    r.everyDayOfWeek() ;
    r.addHour(12), r.addMinute(34) ;
  }

  e.setTicker(time(NULL)+time_shift) ;
  e.setAttribute("APPLICATION", "simple_client") ;

  Maemo::Timed::Interface ifc ;
  if(!ifc.isValid())
  {
    qDebug() << "not valid interface:" << ifc.lastError() ;
    return 1 ;
  }

  QDBusReply<uint> res = ifc.add_event_sync(e) ;
  if(!res.isValid())
  {
    qDebug() << "call failed:" << res.error().message() ;
    return 1 ;
  }

  qDebug() << "added event, cookie:" << res.value() ;
  return 0 ;
}