1 #include "../helper/locales.h"
3 #define _GNU_SOURCE /* For strcasestr */
14 #include "../helper/formats.h"
15 #include "../helper/cmdline.h"
17 void PrintNoteType(GSM_CalendarNoteType Type
)
19 printf(LISTFORMAT
, _("Note type"));
21 case GSM_CAL_REMINDER
:
22 printf("%s\n", _("Reminder (Date)"));
25 printf("%s\n", _("Call"));
28 printf("%s\n", _("Meeting"));
30 case GSM_CAL_BIRTHDAY
:
31 printf("%s\n", _("Birthday (Anniversary)"));
34 printf("%s\n", _("Memo (Miscellaneous)"));
37 printf("%s\n", _("Travel"));
39 case GSM_CAL_VACATION
:
40 printf("%s\n", _("Vacation"));
43 printf("%s\n", _("Alarm"));
45 case GSM_CAL_SHOPPING
:
46 printf("%s\n", _("Shopping"));
48 case GSM_CAL_DAILY_ALARM
:
49 printf("%s\n", _("Daily alarm"));
52 printf("%s\n", _("Training/Athletism"));
55 printf("%s\n", _("Training/Ball Games"));
58 printf("%s\n", _("Training/Cycling"));
61 printf("%s\n", _("Training/Budo"));
64 printf("%s\n", _("Training/Dance"));
67 printf("%s\n", _("Training/Extreme Sports"));
70 printf("%s\n", _("Training/Football"));
73 printf("%s\n", _("Training/Golf"));
76 printf("%s\n", _("Training/Gym"));
79 printf("%s\n", _("Training/Horse Races"));
82 printf("%s\n", _("Training/Hockey"));
85 printf("%s\n", _("Training/Races"));
88 printf("%s\n", _("Training/Rugby"));
91 printf("%s\n", _("Training/Sailing"));
94 printf("%s\n", _("Training/Street Games"));
97 printf("%s\n", _("Training/Swimming"));
100 printf("%s\n", _("Training/Tennis"));
103 printf("%s\n", _("Training/Travels"));
106 printf("%s\n", _("Training/Winter Games"));
110 printf("%s\n", _("unknown type!"));
115 void PrintCalendar(GSM_CalendarEntry
* Note
)
119 GSM_DateTime Alarm
, DateTime
;
120 GSM_MemoryEntry entry
;
123 gboolean repeating
= FALSE
;
124 int repeat_dayofweek
= -1;
126 int repeat_dayofyear
= -1;
127 int repeat_weekofmonth
= -1;
128 int repeat_month
= -1;
129 int repeat_count
= -1;
130 int repeat_frequency
= -1;
131 GSM_DateTime repeat_startdate
= { 0, 0, 0, 0, 0, 0, 0 };
132 GSM_DateTime repeat_stopdate
= { 0, 0, 0, 0, 0, 0, 0 };
134 PrintNoteType(Note
->Type
);
144 repeat_dayofweek
= -1;
146 repeat_dayofyear
= -1;
147 repeat_weekofmonth
= -1;
149 repeat_frequency
= -1;
150 repeat_startdate
.Day
= 0;
151 repeat_stopdate
.Day
= 0;
153 for (i
= 0; i
< Note
->EntriesNum
; i
++) {
154 switch (Note
->Entries
[i
].EntryType
) {
155 case CAL_START_DATETIME
:
156 printf(LISTFORMAT
"%s\n", _("Start"),
157 OSDateTime(Note
->Entries
[i
].Date
,
159 memcpy(&DateTime
, &Note
->Entries
[i
].Date
,
160 sizeof(GSM_DateTime
));
162 case CAL_END_DATETIME
:
163 printf(LISTFORMAT
"%s\n", _("Stop"),
164 OSDateTime(Note
->Entries
[i
].Date
,
166 memcpy(&DateTime
, &Note
->Entries
[i
].Date
,
167 sizeof(GSM_DateTime
));
169 case CAL_LAST_MODIFIED
:
170 printf(LISTFORMAT
"%s\n", _("Last modified"),
171 OSDateTime(Note
->Entries
[i
].Date
,
174 case CAL_TONE_ALARM_DATETIME
:
175 if (Note
->Type
== GSM_CAL_BIRTHDAY
) {
176 printf(LISTFORMAT
, _("Tone alarm"));
178 ("forever on each %i. day of %s"),
179 Note
->Entries
[i
].Date
.Day
,
180 GetMonthName(Note
->Entries
[i
].
182 printf(" %02i:%02i:%02i\n",
183 Note
->Entries
[i
].Date
.Hour
,
184 Note
->Entries
[i
].Date
.Minute
,
185 Note
->Entries
[i
].Date
.Second
);
187 printf(LISTFORMAT
"%s\n",
189 OSDateTime(Note
->Entries
[i
].Date
,
192 memcpy(&Alarm
, &Note
->Entries
[i
].Date
,
193 sizeof(GSM_DateTime
));
195 case CAL_SILENT_ALARM_DATETIME
:
196 if (Note
->Type
== GSM_CAL_BIRTHDAY
) {
197 printf(LISTFORMAT
, _("Silent alarm"));
199 ("forever on each %i. day of %s"),
200 Note
->Entries
[i
].Date
.Day
,
201 GetMonthName(Note
->Entries
[i
].
203 printf(" %02i:%02i:%02i\n",
204 Note
->Entries
[i
].Date
.Hour
,
205 Note
->Entries
[i
].Date
.Minute
,
206 Note
->Entries
[i
].Date
.Second
);
208 printf(LISTFORMAT
"%s\n",
210 OSDateTime(Note
->Entries
[i
].Date
,
213 memcpy(&Alarm
, &Note
->Entries
[i
].Date
,
214 sizeof(GSM_DateTime
));
217 printf(LISTFORMAT
"\"%s\"\n", _("Text"),
218 DecodeUnicodeConsole(Note
->Entries
[i
].
221 case CAL_DESCRIPTION
:
222 printf(LISTFORMAT
"\"%s\"\n", _("Description"),
223 DecodeUnicodeConsole(Note
->Entries
[i
].
227 printf(LISTFORMAT
"\"%s\"\n", _("LUID"),
228 DecodeUnicodeConsole(Note
->Entries
[i
].
232 printf(LISTFORMAT
"\"%s\"\n", _("Location"),
233 DecodeUnicodeConsole(Note
->Entries
[i
].
237 printf(LISTFORMAT
"\"%s\"\n", _("Phone"),
238 DecodeUnicodeConsole(Note
->Entries
[i
].
242 printf(LISTFORMAT
"%s\n", _("Private"),
243 Note
->Entries
[i
].Number
==
244 1 ? _("Yes") : _("No"));
247 entry
.Location
= Note
->Entries
[i
].Number
;
248 entry
.MemoryType
= MEM_ME
;
249 error
= GSM_GetMemory(gsm
, &entry
);
250 if (error
== ERR_NONE
) {
252 GSM_PhonebookGetEntryName(&entry
);
259 Note
->Entries
[i
].Number
);
261 printf(LISTFORMAT
"%d\n",
263 Note
->Entries
[i
].Number
);
266 printf(LISTFORMAT
"%d\n",
268 Note
->Entries
[i
].Number
);
271 case CAL_REPEAT_DAYOFWEEK
:
272 repeat_dayofweek
= Note
->Entries
[i
].Number
;
276 repeat_day
= Note
->Entries
[i
].Number
;
279 case CAL_REPEAT_DAYOFYEAR
:
280 repeat_dayofyear
= Note
->Entries
[i
].Number
;
283 case CAL_REPEAT_WEEKOFMONTH
:
284 repeat_weekofmonth
= Note
->Entries
[i
].Number
;
287 case CAL_REPEAT_MONTH
:
288 repeat_month
= Note
->Entries
[i
].Number
;
291 case CAL_REPEAT_FREQUENCY
:
292 repeat_frequency
= Note
->Entries
[i
].Number
;
295 case CAL_REPEAT_COUNT
:
296 repeat_count
= Note
->Entries
[i
].Number
;
299 case CAL_REPEAT_STARTDATE
:
300 repeat_startdate
= Note
->Entries
[i
].Date
;
303 case CAL_REPEAT_STOPDATE
:
304 repeat_stopdate
= Note
->Entries
[i
].Date
;
310 printf(LISTFORMAT
, _("Repeating"));
311 if (repeat_count
> 0) {
313 ("for %d time ", "for %d times ", repeat_count
),
316 if ((repeat_startdate
.Day
== 0) && (repeat_stopdate
.Day
== 0)) {
317 printf("%s", _("forever"));
318 } else if (repeat_startdate
.Day
== 0) {
319 printf(_("till %s"), OSDate(repeat_stopdate
));
320 } else if (repeat_stopdate
.Day
== 0) {
321 printf(_("since %s"), OSDate(repeat_startdate
));
323 printf(_("since %s till %s"), OSDate(repeat_startdate
),
324 OSDate(repeat_stopdate
));
326 if (repeat_frequency
!= -1) {
327 if (repeat_frequency
== 1) {
328 printf("%s", _(" on each "));
330 printf(_(" on each %d. "), repeat_frequency
);
332 if (repeat_dayofweek
> 0) {
333 printf("%s", GetDayName(repeat_dayofweek
));
334 if (repeat_weekofmonth
> 0) {
335 printf(_(" in %d. week of "),
338 printf("%s", _(" in "));
340 if (repeat_month
> 0) {
342 GetMonthName(repeat_month
));
344 printf("%s", _("each month"));
346 } else if (repeat_day
> 0) {
347 printf(_("%d. day of "), repeat_day
);
348 if (repeat_month
> 0) {
350 GetMonthName(repeat_month
));
352 printf("%s", _("each month"));
354 } else if (repeat_dayofyear
> 0) {
355 printf(_("%d. day of year"), repeat_dayofyear
);
357 printf("%s", _("day"));
362 if (Note
->Type
== GSM_CAL_BIRTHDAY
) {
363 if (Alarm
.Year
== 0x00)
364 GSM_GetCurrentDateTime(&Alarm
);
365 if (DateTime
.Year
!= 0) {
366 i_age
= Alarm
.Year
- DateTime
.Year
;
367 if (DateTime
.Month
< Alarm
.Month
)
369 if (DateTime
.Month
== Alarm
.Month
&&
370 DateTime
.Day
< Alarm
.Day
) {
373 printf(LISTFORMAT
, _("Age"));
381 void GetDateTime(int argc UNUSED
, char *argv
[]UNUSED
)
384 GSM_DateTime date_time
;
389 error
= GSM_GetDateTime(gsm
, &date_time
);
392 printf("%s\n", _("Date and time not set in phone"));
395 printf(_("Phone time is %s\n"),
396 OSDateTime(date_time
, FALSE
));
402 error
= GSM_GetLocale(gsm
, &locale
);
404 case ERR_NOTSUPPORTED
:
405 case ERR_NOTIMPLEMENTED
:
409 printf("%s", _("Time format is "));
410 if (locale
.AMPMTime
) {
411 /* l10n: AM/PM time */
412 printf("%s\n", _("12 hours"));
414 /* l10n: 24 hours time */
415 printf("%s\n", _("24 hours"));
417 printf("%s", _("Date format is "));
418 switch (locale
.DateFormat
) {
419 case GSM_Date_DDMMYYYY
:
420 printf("%s", _("DD MM YYYY"));
422 case GSM_Date_MMDDYYYY
:
423 printf("%s", _("MM DD YYYY"));
425 case GSM_Date_YYYYMMDD
:
426 printf("%s", _("YYYY MM DD"));
428 case GSM_Date_DDMMMYY
:
429 printf("%s", _("DD MMM YY"));
431 case GSM_Date_MMDDYY
:
432 printf("%s", _("MM DD YY"));
434 case GSM_Date_DDMMYY
:
435 printf("%s", _("DD MM YY"));
437 case GSM_Date_YYMMDD
:
438 printf("%s", _("YY MM DD"));
441 printf("%s", _("OFF"));
446 printf(_(", date separator is %c\n"),
447 locale
.DateSeparator
);
453 void SetDateTime(int argc
, char *argv
[])
455 GSM_DateTime date_time
;
456 char shift
, *parse
, *parse2
;
462 /* set datetime to the current datetime in the PC */
463 printf("%s\n", _("Setting time in phone to the same time as is set in computer."));
464 GSM_GetCurrentDateTime(&date_time
);
466 /* update only parts the user specified,
467 leave the rest in the phone as is */
468 error
= GSM_GetDateTime(gsm
, &date_time
);
471 if (error
== ERR_NONE
) {
473 error
= ERR_INVALIDDATETIME
;
474 parse
= strchr(argv
[2], ':');
477 date_time
.Hour
= GetInt(argv
[2]);
478 parse2
= strchr(parse
+ 1, ':');
479 if (parse2
!= NULL
) {
481 date_time
.Second
= GetInt(parse2
+ 1);
483 date_time
.Minute
= GetInt(parse
+ 1);
485 if (CheckTime(&date_time
)) {
488 error
= ERR_INVALIDDATETIME
;
491 if (argc
- 1 >= 2 + shift
) {
492 parse
= strchr(argv
[2 + shift
], '/');
495 date_time
.Year
= GetInt(argv
[2 + shift
]);
496 parse2
= strchr(parse
+ 1, '/');
497 if (parse2
!= NULL
) {
499 date_time
.Day
= GetInt(parse2
+ 1);
501 date_time
.Month
= GetInt(parse
+ 1);
502 if (CheckDate(&date_time
)) {
505 error
= ERR_INVALIDDATETIME
;
509 /* we got the timezone from the phone */
512 if (error
== ERR_NONE
) {
513 printf("%s\n", _("Updating specified parts of date and time in phone."));
514 error
= GSM_SetDateTime(gsm
, &date_time
);
521 void GetAlarm(int argc
, char *argv
[])
531 Alarm
.Location
= GetInt(argv
[2]);
533 error
= GSM_GetAlarm(gsm
, &Alarm
);
536 printf(_("Alarm (%i) not set in phone\n"),
540 printf(_("Alarm in location %i:\n"), Alarm
.Location
);
541 if (Alarm
.Repeating
) {
542 printf(LISTFORMAT
"%s\n", _("Date"),
544 } else if (Alarm
.DateTime
.Day
!= 0) {
545 printf(LISTFORMAT
"%s\n", _("Date"),
546 OSDate(Alarm
.DateTime
));
548 printf(_("Time: %02d:%02d\n"), Alarm
.DateTime
.Hour
,
549 Alarm
.DateTime
.Minute
);
550 if (Alarm
.Text
[0] != 0 || Alarm
.Text
[1] != 0) {
551 printf(LISTFORMAT
"\"%s\"\n", _("Text"),
552 DecodeUnicodeConsole(Alarm
.Text
));
562 void SetAlarm(int argc UNUSED
, char *argv
[])
567 Alarm
.DateTime
.Hour
= GetInt(argv
[2]);
568 Alarm
.DateTime
.Minute
= GetInt(argv
[3]);
569 Alarm
.DateTime
.Second
= 0;
571 Alarm
.Repeating
= TRUE
;
577 error
= GSM_SetAlarm(gsm
, &Alarm
);
583 void GetCalendar(int argc UNUSED
, char *argv
[])
586 GSM_CalendarEntry Note
;
589 GetStartStop(&start
, &stop
, 2, argc
, argv
);
593 for (i
= start
; i
<= stop
; i
++) {
595 error
= GSM_GetCalendar(gsm
, &Note
);
596 if (error
== ERR_EMPTY
)
599 printf(LISTFORMAT
"%d\n", _("Location"), Note
.Location
);
600 PrintCalendar(&Note
);
606 void DeleteCalendar(int argc
, char *argv
[])
609 GSM_CalendarEntry Note
;
612 GetStartStop(&start
, &stop
, 2, argc
, argv
);
616 for (i
= start
; i
<= stop
; i
++) {
618 error
= GSM_DeleteCalendar(gsm
, &Note
);
625 void GetAllCalendar(int argc UNUSED
, char *argv
[]UNUSED
)
628 GSM_CalendarEntry Note
;
629 gboolean refresh
= TRUE
;
631 signal(SIGINT
, interrupt
);
632 fprintf(stderr
, "%s\n", _("Press Ctrl+C to break..."));
639 error
= GSM_GetNextCalendar(gsm
, &Note
, refresh
);
640 if (error
== ERR_EMPTY
)
643 printf(LISTFORMAT
"%d\n", _("Location"), Note
.Location
);
644 PrintCalendar(&Note
);
651 void GetCalendarSettings(int argc UNUSED
, char *argv
[]UNUSED
)
654 GSM_CalendarSettings settings
;
658 error
= GSM_GetCalendarSettings(gsm
, &settings
);
661 if (settings
.AutoDelete
== 0) {
662 printf("%s", _("Auto deleting disabled"));
664 printf(_("Auto deleting notes after %i day(s)"),
665 settings
.AutoDelete
);
668 printf(_("Week starts on %s"), GetDayName(settings
.StartDay
));
674 void DeleteToDo(int argc
, char *argv
[])
681 GetStartStop(&start
, &stop
, 2, argc
, argv
);
685 for (i
= start
; i
<= stop
; i
++) {
687 printf(LISTFORMAT
"%i\n", _("Location"), i
);
688 error
= GSM_DeleteToDo(gsm
, &ToDo
);
689 if (error
!= ERR_EMPTY
)
692 if (error
== ERR_EMPTY
) {
693 printf("%s\n", _("Entry was empty"));
695 printf("%s\n", _("Entry was deleted"));
703 void PrintToDo(GSM_ToDoEntry
* ToDo
)
707 GSM_MemoryEntry entry
;
709 GSM_Category Category
;
711 printf(LISTFORMAT
"%i\n", _("Location"), ToDo
->Location
);
712 PrintNoteType(ToDo
->Type
);
713 printf(LISTFORMAT
, _("Priority"));
714 switch (ToDo
->Priority
) {
715 case GSM_Priority_Low
:
716 printf("%s\n", _("Low"));
718 case GSM_Priority_Medium
:
719 printf("%s\n", _("Medium"));
721 case GSM_Priority_High
:
722 printf("%s\n", _("High"));
724 case GSM_Priority_None
:
725 printf("%s\n", _("None"));
729 printf("%s\n", _("Unknown"));
733 for (j
= 0; j
< ToDo
->EntriesNum
; j
++) {
734 switch (ToDo
->Entries
[j
].EntryType
) {
735 case TODO_END_DATETIME
:
736 printf(LISTFORMAT
"%s\n", _("Due time"),
737 OSDateTime(ToDo
->Entries
[j
].Date
,
740 case TODO_START_DATETIME
:
741 printf(LISTFORMAT
"%s\n", _("Start time"),
742 OSDateTime(ToDo
->Entries
[j
].Date
,
745 case TODO_COMPLETED_DATETIME
:
746 printf(LISTFORMAT
"%s\n", _("Completed time"),
747 OSDateTime(ToDo
->Entries
[j
].Date
,
751 printf(LISTFORMAT
"%s\n", _("Completed"),
752 ToDo
->Entries
[j
].Number
==
755 case TODO_ALARM_DATETIME
:
756 printf(LISTFORMAT
"%s\n", _("Alarm"),
757 OSDateTime(ToDo
->Entries
[j
].Date
,
760 case TODO_SILENT_ALARM_DATETIME
:
761 printf(LISTFORMAT
"%s\n", _("Silent alarm"),
762 OSDateTime(ToDo
->Entries
[j
].Date
,
765 case TODO_LAST_MODIFIED
:
766 printf(LISTFORMAT
"%s\n", _("Last modified"),
767 OSDateTime(ToDo
->Entries
[j
].Date
,
771 printf(LISTFORMAT
"\"%s\"\n", _("Text"),
772 DecodeUnicodeConsole(ToDo
->Entries
[j
].
776 printf(LISTFORMAT
"%s\n", _("Private"),
777 ToDo
->Entries
[j
].Number
==
781 Category
.Location
= ToDo
->Entries
[j
].Number
;
782 Category
.Type
= Category_ToDo
;
783 error
= GSM_GetCategory(gsm
, &Category
);
784 if (error
== ERR_NONE
) {
785 printf(LISTFORMAT
"\"%s\" (%i)\n",
787 DecodeUnicodeConsole(Category
.
789 ToDo
->Entries
[j
].Number
);
791 printf(LISTFORMAT
"%i\n", _("Category"),
792 ToDo
->Entries
[j
].Number
);
796 entry
.Location
= ToDo
->Entries
[j
].Number
;
797 entry
.MemoryType
= MEM_ME
;
798 error
= GSM_GetMemory(gsm
, &entry
);
799 if (error
== ERR_NONE
) {
801 GSM_PhonebookGetEntryName(&entry
);
808 ToDo
->Entries
[j
].Number
);
810 printf(LISTFORMAT
"%d\n",
812 ToDo
->Entries
[j
].Number
);
815 printf(LISTFORMAT
"%d\n", _("Contact"),
816 ToDo
->Entries
[j
].Number
);
820 printf(LISTFORMAT
"\"%s\"\n", _("Phone"),
821 DecodeUnicodeConsole(ToDo
->Entries
[j
].
824 case TODO_DESCRIPTION
:
825 printf(LISTFORMAT
"\"%s\"\n", _("Description"),
826 DecodeUnicodeConsole(ToDo
->Entries
[j
].
830 printf(LISTFORMAT
"\"%s\"\n", _("Location"),
831 DecodeUnicodeConsole(ToDo
->Entries
[j
].
835 printf(LISTFORMAT
"\"%s\"\n", _("LUID"),
836 DecodeUnicodeConsole(ToDo
->Entries
[j
].
844 void ListToDoCategoryEntries(int Category
)
848 gboolean start
= TRUE
;
854 error
= GSM_GetNextToDo(gsm
, &Entry
, start
);
855 if (error
== ERR_EMPTY
)
858 for (j
= 0; j
< Entry
.EntriesNum
; j
++) {
859 if (Entry
.Entries
[j
].EntryType
== TODO_CATEGORY
860 && Entry
.Entries
[j
].Number
==
861 (unsigned int)Category
)
868 void ListToDoCategory(int argc UNUSED
, char *argv
[])
871 GSM_Category Category
;
872 GSM_CategoryStatus Status
;
875 unsigned char Text
[(GSM_MAX_CATEGORY_NAME_LENGTH
+ 1) * 2];
877 gboolean Number
= TRUE
;;
881 signal(SIGINT
, interrupt
);
882 fprintf(stderr
, "%s\n", _("Press Ctrl+C to break..."));
884 Length
= strlen(argv
[2]);
885 for (j
= 0; j
< Length
; j
++) {
886 if (!isdigit((int)argv
[2][j
])) {
895 ListToDoCategoryEntries(j
);
898 if (Length
> GSM_MAX_CATEGORY_NAME_LENGTH
) {
900 ("Search text too long, truncating to %d chars!\n"),
901 GSM_MAX_CATEGORY_NAME_LENGTH
);
902 Length
= GSM_MAX_CATEGORY_NAME_LENGTH
;
904 EncodeUnicode(Text
, argv
[2], Length
);
906 Category
.Type
= Category_ToDo
;
907 Status
.Type
= Category_ToDo
;
909 if (GSM_GetCategoryStatus(gsm
, &Status
) == ERR_NONE
) {
910 for (count
= 0, j
= 1; count
< Status
.Used
; j
++) {
911 Category
.Location
= j
;
912 error
= GSM_GetCategory(gsm
, &Category
);
914 if (error
!= ERR_EMPTY
) {
916 if (mywstrstr(Category
.Name
, Text
) !=
918 ListToDoCategoryEntries(j
);
927 void GetToDo(int argc
, char *argv
[])
934 GetStartStop(&start
, &stop
, 2, argc
, argv
);
938 for (i
= start
; i
<= stop
; i
++) {
940 error
= GSM_GetToDo(gsm
, &ToDo
);
941 if (error
== ERR_EMPTY
)
950 void GetAllToDo(int argc UNUSED
, char *argv
[]UNUSED
)
954 gboolean start
= TRUE
;
956 signal(SIGINT
, interrupt
);
957 fprintf(stderr
, "%s\n", _("Press Ctrl+C to break..."));
964 error
= GSM_GetNextToDo(gsm
, &ToDo
, start
);
965 if (error
== ERR_EMPTY
)
975 void GetAllNotes(int argc UNUSED
, char *argv
[]UNUSED
)
979 gboolean start
= TRUE
;
981 signal(SIGINT
, interrupt
);
982 fprintf(stderr
, "%s\n", _("Press Ctrl+C to break..."));
989 error
= GSM_GetNextNote(gsm
, &Note
, start
);
990 if (error
== ERR_EMPTY
)
993 printf(LISTFORMAT
"\"%s\"\n", _("Text"),
994 DecodeUnicodeConsole(Note
.Text
));
1001 /* How should editor hadle tabs in this file? Add editor commands here.
1002 * vim: noexpandtab sw=8 ts=8 sts=8: