GSM-Gnokii
view release on metacpan or search on metacpan
void
GetAlarm (self)
HvObject *self;
PPCODE:
gn_calnote_alarm alrm;
if (opt_v) warn ("GetAlarm ()\n");
clear_data ();
data->alarm = &alrm;
if (gn_sm_functions (GN_OP_GetAlarm, data, state) == GN_ERR_NONE) {
char tm[8];
HV *ah = newHV ();
sprintf (tm, "%02d:%02d", alrm.timestamp.hour, alrm.timestamp.minute);
hv_puts (ah, "alarm", tm);
hv_puts (ah, "state", (alrm.enabled ? "on" : "off"));
XS_RETURNr (ah);
}
XSRETURN_UNDEF;
/* GetAlarm */
void
SetAlarm (self, hour, minute)
HvObject *self;
int hour;
int minute;
PPCODE:
gn_calnote_alarm at;
int err;
clear_data ();
if (hour < 0 || hour > 23) {
set_errors ("Alarm hour must be in [0..23]");
XSRETURN_UNDEF;
}
if (minute < 0 || minute > 59) {
set_errors ("Alarm minute must be in [0..59]");
XSRETURN_UNDEF;
}
Zero (&at, 1, gn_calnote_alarm);
at.timestamp.hour = hour;
at.timestamp.minute = minute;
at.timestamp.second = 0;
at.enabled = true;
data->alarm = &at;
err = gn_sm_functions (GN_OP_SetAlarm, data, state);
set_errori (err);
XS_RETURNi (err);
/* SetAlarm */
void
GetCalendarNotes (self, start, end)
HvObject *self;
int start;
int end;
PPCODE:
gn_calnote_list calendarnoteslist;
gn_calnote calendarnote;
int i, err;
AV *cnl = newAV ();
if (opt_v) warn ("GetCalenderNotes (%d, %d)\n", start, end);
if (start < 0) {
set_errors ("calendarnote location should be in positive");
XSRETURN_UNDEF;
}
if (end < 0 || (start && end == 0))
end = INT_MAX;
for (i = start; i <= end; i++) {
clear_data ();
calendarnote.location = i;
data->calnote = &calendarnote;
data->calnote_list = &calendarnoteslist;
err = gn_sm_functions (GN_OP_GetCalendarNote, data, state);
if (err == GN_ERR_INVALIDLOCATION)
break;
if (err == GN_ERR_EMPTYLOCATION) {
av_push (cnl, &PL_sv_undef);
continue;
}
if (err == GN_ERR_NONE) {
HV *note = newHV ();
hv_puti (note, "location", i);
hv_puts (note, "type", gn_calnote_type2str (calendarnote.type));
hv_puts (note, "recurrence", gn_calnote_recurrence2str (calendarnote.recurrence));
if (calendarnote.phone_number[0])
hv_puts (note, "number", calendarnote.phone_number);
if (calendarnote.mlocation[0])
hv_puts (note, "mlocation", calendarnote.mlocation);
hv_puts (note, "text", calendarnote.text);
if (calendarnote.alarm.timestamp.year)
GSMDATE_TO_TM ("alarm", calendarnote.alarm.timestamp, note);
calendarnote.time.second = 0;
calendarnote.time.minute = 0;
calendarnote.time.hour = 0;
GSMDATE_TO_TM ("date", calendarnote.time, note);
av_addr (cnl, note);
}
else
set_errori (err);
}
XS_RETURNr (cnl);
/* GetCalendarNotes */
void
WriteCalendarNote (self, calhash)
HvObject *self;
HV *calhash;
PPCODE:
gn_calnote calnote;
char *buf;
time_t t1, *t2;
gn_timestamp *timestamp;
int err;
SV **value;
clear_data ();
Zero (&calnote, 1, calnote);
if ((value = hv_fetch (calhash, "date", 4, 0)) == NULL) {
set_errors ("date is a required attribute for WriteCalendarNote ()");
XSRETURN_UNDEF;
}
t1 = (time_t)SvIV (*value);
t2 = &t1;
timestamp = &(calnote.time);
HASH_TO_GSMDT (timestamp, t2);
if ((value = hv_fetch (calhash, "text", 4, 0)) == NULL) {
set_errors ("text is a required attribute for WriteCalendarNote ()");
XSRETURN_UNDEF;
}
strcpy (calnote.text, SvPV_nolen (*value));
if ((value = hv_fetch (calhash, "type", 4, 0)) == NULL)
buf = "MEMO";
else
buf = SvPV_nolen (*value);
if (!strncasecmp (buf, "misc", 4) || !strncasecmp (buf, "remi", 4))
calnote.type = GN_CALNOTE_REMINDER;
else if (!strncasecmp (buf, "call", 4))
calnote.type = GN_CALNOTE_CALL;
else if (!strncasecmp (buf, "meet", 4))
calnote.type = GN_CALNOTE_MEETING;
else if (!strncasecmp (buf, "birt", 4))
calnote.type = GN_CALNOTE_BIRTHDAY;
else if (!strncasecmp (buf, "memo", 4))
calnote.type = GN_CALNOTE_MEMO;
value = hv_fetch (calhash, "number", 6, 0);
if (calnote.type == GN_CALNOTE_CALL && !value) {
set_errors ("number is a required attribute for WriteCalendarNote (CALL)");
XSRETURN_UNDEF;
}
( run in 0.492 second using v1.01-cache-2.11-cpan-007c89162af )