Example #1
0
bool tst_Events::addEvent(const qint64 timestamp, const int dueInSeconds, uint &cookie)
{
    Maemo::Timed::Event event = createEvent(timestamp, dueInSeconds);

    // Open a connection to timed and add the event
    Maemo::Timed::Interface timedIface;
    if (!timedIface.isValid()) {
        qWarning() << "Invalid timed interface:" << timedIface.lastError().message();
        return false;
    }

    QDBusReply<uint> reply = timedIface.add_event_sync(event);
    if (!reply.isValid()) {
        qWarning() << "Adding event failed: %1" << reply.error().message();
        return false;
    }
    cookie = reply.value();
    return true;
}
Example #2
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 ;
}