예제 #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 ;
}
예제 #2
0
파일: tst_events.cpp 프로젝트: cxl000/timed
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;
}
예제 #3
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 ;
}