Translation update done using Pootle.
[gammu.git] / gammu / memory.c
blob6f387b830ee0f884dcdad75957493c1758766f96
1 #include <string.h>
2 #include <stdarg.h>
3 #include <signal.h>
4 #include <stdlib.h>
5 #include <ctype.h>
7 #include "../helper/locales.h"
9 #include "common.h"
10 #include "memory.h"
11 #include "backup.h"
12 #include "../helper/formats.h"
13 #include "../helper/memory-display.h"
14 #include "../helper/printing.h"
15 #include "../helper/string.h"
16 #include "../helper/cmdline.h"
18 void GetAllMemory(int argc UNUSED, char *argv[])
20 GSM_Error error;
21 GSM_MemoryType MemoryType;
23 signal(SIGINT, interrupt);
24 fprintf(stderr, "%s\n", _("Press Ctrl+C to break..."));
26 MemoryType = GSM_StringToMemoryType(argv[2]);
28 if (MemoryType == 0) {
29 printf_err(_("Unknown memory type (\"%s\")\n"),argv[2]);
30 Terminate(2);
33 GSM_Init(TRUE);
35 #ifdef GSM_ENABLE_BACKUP
36 error = ReadPhonebook(NULL, MemoryType, NULL, 0, PrintMemoryEntryLocation, FALSE);
37 #else
38 error = ERR_DISABLED;
39 #endif
40 Print_Error(error);
42 if (ringtones_info.Ringtone) {
43 free(ringtones_info.Ringtone);
46 GSM_Terminate();
49 void GetMemory(int argc, char *argv[])
51 int j, start, stop, emptynum = 0, fillednum = 0;
52 GSM_MemoryEntry entry;
53 gboolean empty = TRUE;
54 double version;
55 GSM_Error error;
57 entry.MemoryType = GSM_StringToMemoryType(argv[2]);
59 if (entry.MemoryType==0) {
60 printf_err(_("Unknown memory type (\"%s\")\n"),argv[2]);
61 Terminate(2);
64 GetStartStop(&start, &stop, 3, argc, argv);
66 if (argc > 5 && strcmp(argv[5],"")) {
67 if (strcasecmp(argv[5],"-nonempty") == 0) {
68 empty = FALSE;
69 } else {
70 printf_err(_("Unknown parameter (\"%s\")\n"),argv[5]);
71 Terminate(2);
75 GSM_Init(TRUE);
77 if (strcmp(GSM_GetModelInfo(gsm)->model, "3310") == 0) {
78 error = GSM_GetFirmware(gsm, NULL, NULL, &version);
79 if (error == ERR_NONE && version <= 4.06) {
80 printf_warn("%s\n", _("You will have null names in entries. Upgrade firmware in phone to higher than 4.06"));
83 if (strcmp(GSM_GetModelInfo(gsm)->model, "3210") == 0) {
84 error = GSM_GetFirmware(gsm, NULL, NULL, &version);
85 if (error == ERR_NONE && version <= 6.00) {
86 printf_warn("%s\n", _("You will have null names in entries. Upgrade firmware in phone to higher than 6.00"));
90 for (j=start;j<=stop;j++) {
91 if (empty) printf(_("Memory %s, Location %i\n"),argv[2],j);
93 entry.Location=j;
95 error=GSM_GetMemory(gsm, &entry);
96 if (error != ERR_EMPTY) {
97 if (ringtones_info.Ringtone) free(ringtones_info.Ringtone);
98 Print_Error(error);
101 if (error == ERR_EMPTY) {
102 emptynum++;
103 if (empty) {
104 printf("%s\n", _("Entry is empty"));
105 printf("\n");
107 } else {
108 fillednum++;
109 if (!empty) printf(_("Memory %s, Location %i\n"),argv[2],j);
110 error = PrintMemoryEntry(&entry, gsm);
111 GSM_FreeMemoryEntry(&entry);
112 Print_Error(error);
116 printf(_("%i entries empty, %i entries filled\n"),emptynum,fillednum);
118 if (ringtones_info.Ringtone) free(ringtones_info.Ringtone);
120 GSM_Terminate();
123 void DeleteMemory(int argc, char *argv[])
125 int j, start, stop;
126 GSM_MemoryEntry entry;
127 GSM_Error error;
129 entry.MemoryType = GSM_StringToMemoryType(argv[2]);
131 if (entry.MemoryType==0) {
132 printf_err(_("Unknown memory type (\"%s\")\n"),argv[2]);
133 Terminate(2);
136 GetStartStop(&start, &stop, 3, argc, argv);
138 GSM_Init(TRUE);
140 for (j=start;j<=stop;j++) {
141 printf(LISTFORMAT "%i\n", _("Location"), j);
143 entry.Location = j;
145 error = GSM_DeleteMemory(gsm, &entry);
147 if (error != ERR_EMPTY) Print_Error(error);
149 if (error == ERR_EMPTY) {
150 printf("%s\n", _("Entry was empty"));
151 } else {
152 printf("%s\n", _("Entry was deleted"));
154 printf("\n");
157 GSM_Terminate();
160 void DeleteAllMemory(int argc, char *argv[])
162 GSM_MemoryType MemoryType;
163 GSM_Error error;
165 MemoryType = GSM_StringToMemoryType(argv[2]);
167 if (MemoryType == 0) {
168 printf_err(_("Unknown memory type (\"%s\")\n"),argv[2]);
169 Terminate(2);
172 GSM_Init(TRUE);
174 error = GSM_DeleteAllMemory(gsm, MemoryType);
176 if (error != ERR_NONE) Print_Error(error);
178 GSM_Terminate();
182 * Searches if memory entry contains given text.
184 * It prints it in match.
186 void SearchOneEntry(GSM_MemoryEntry *Entry, const unsigned char *Text)
188 int i;
189 GSM_Error error;
191 for (i=0;i<Entry->EntriesNum;i++) {
192 switch (Entry->Entries[i].EntryType) {
193 case PBK_Number_General :
194 case PBK_Number_Mobile :
195 case PBK_Number_Fax :
196 case PBK_Number_Pager :
197 case PBK_Number_Other :
198 case PBK_Number_Messaging:
199 case PBK_Number_Video:
200 case PBK_Text_Note :
201 case PBK_Text_Postal :
202 case PBK_Text_Email :
203 case PBK_Text_Email2 :
204 case PBK_Text_URL :
205 case PBK_Text_LUID :
206 case PBK_Text_VOIP :
207 case PBK_Text_SWIS :
208 case PBK_Text_WVID :
209 case PBK_Text_SIP :
210 case PBK_Text_DTMF :
211 case PBK_Text_Name :
212 case PBK_Text_LastName :
213 case PBK_Text_FirstName :
214 case PBK_Text_SecondName:
215 case PBK_Text_FormalName :
216 case PBK_Text_NamePrefix :
217 case PBK_Text_NameSuffix :
218 case PBK_Text_NickName :
219 case PBK_Text_Company :
220 case PBK_Text_JobTitle :
221 case PBK_Text_StreetAddress :
222 case PBK_Text_City :
223 case PBK_Text_State :
224 case PBK_Text_Zip :
225 case PBK_Text_Country :
226 case PBK_Text_Custom1 :
227 case PBK_Text_Custom2 :
228 case PBK_Text_Custom3 :
229 case PBK_Text_Custom4 :
230 case PBK_Text_UserID:
231 case PBK_Text_PictureName:
232 case PBK_PushToTalkID:
233 if (mywstrstr(Entry->Entries[i].Text, Text) != NULL) {
234 fprintf(stderr,"\n");
235 printf(_("Memory %s, Location %i\n"),GSM_MemoryTypeToString(Entry->MemoryType),Entry->Location);
236 error = PrintMemoryEntry(Entry, gsm);
237 Print_Error(error);
238 return;
240 break;
241 case PBK_Caller_Group:
242 case PBK_Date:
243 case PBK_Category:
244 case PBK_Private:
245 case PBK_RingtoneID:
246 case PBK_PictureID:
247 case PBK_CallLength:
248 case PBK_LastModified:
249 case PBK_Photo:
250 #ifndef CHECK_CASES
251 default:
252 #endif
253 break;
259 * Reads all entries from one memory and searches them for some text.
261 * All matched entries are printed.
263 void SearchOneMemory(GSM_MemoryType MemoryType, const char *Title, const unsigned char *Text)
265 GSM_MemoryEntry Entry;
266 GSM_MemoryStatus Status;
267 int i = 0, l = 1;
268 GSM_Error error;
270 Status.MemoryType = MemoryType;
271 Entry.MemoryType = MemoryType;
272 Entry.Location = 0;
274 if (GSM_GetMemoryStatus(gsm, &Status) == ERR_NONE) {
275 fprintf(stderr,"%c%s: %i%%", 13, Title, (i+1)*100/(Status.MemoryUsed+1));
276 error = GSM_GetNextMemory(gsm, &Entry, TRUE);
277 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) {
278 while (i < Status.MemoryUsed) {
279 if (error == ERR_EMPTY) break;
280 Print_Error(error);
281 SearchOneEntry(&Entry, Text);
282 GSM_FreeMemoryEntry(&Entry);
283 if (gshutdown) return;
284 i++;
285 fprintf(stderr,"\r%s: %i%%", Title, (i+1)*100/(Status.MemoryUsed+1));
286 error = GSM_GetNextMemory(gsm, &Entry, FALSE);
288 } else {
289 while (i < Status.MemoryUsed) {
290 Entry.Location = l;
291 error = GSM_GetMemory(gsm, &Entry);
292 if (error != ERR_EMPTY) {
293 Print_Error(error);
294 i++;
295 SearchOneEntry(&Entry, Text);
296 GSM_FreeMemoryEntry(&Entry);
298 fprintf(stderr,"%c%s: %i%%", 13, Title, (i+1)*100/(Status.MemoryUsed+1));
299 l++;
302 fprintf(stderr,"\n");
306 void SearchMemory(int argc UNUSED, char *argv[])
308 unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1)*2];
309 int Length;
311 signal(SIGINT, interrupt);
312 fprintf(stderr, "%s\n", _("Press Ctrl+C to break..."));
314 Length = strlen(argv[2]);
315 if (Length > GSM_PHONEBOOK_TEXT_LENGTH) {
316 printf(_("Search text too long, truncating to %d chars!\n"), GSM_PHONEBOOK_TEXT_LENGTH);
317 Length = GSM_PHONEBOOK_TEXT_LENGTH;
319 EncodeUnicode(Text, argv[2], Length);
321 GSM_Init(TRUE);
323 if (!gshutdown) SearchOneMemory(MEM_ME, "Phone phonebook", Text);
324 if (!gshutdown) SearchOneMemory(MEM_SM, "SIM phonebook", Text);
325 if (!gshutdown) SearchOneMemory(MEM_ON, "Own numbers", Text);
326 if (!gshutdown) SearchOneMemory(MEM_DC, "Dialled numbers", Text);
327 if (!gshutdown) SearchOneMemory(MEM_RC, "Received numbers", Text);
328 if (!gshutdown) SearchOneMemory(MEM_MC, "Missed numbers", Text);
329 if (!gshutdown) SearchOneMemory(MEM_FD, "Fix dialling", Text);
330 if (!gshutdown) SearchOneMemory(MEM_VM, "Voice mailbox", Text);
331 if (!gshutdown) SearchOneMemory(MEM_SL, "Sent SMS log", Text);
333 GSM_Terminate();
336 void ListMemoryCategoryEntries(int Category)
338 GSM_MemoryEntry Entry;
339 gboolean start = TRUE;
340 int j;
341 GSM_Error error;
343 /* Category can be only for ME stored entries */
344 Entry.MemoryType = MEM_ME;
346 while (!gshutdown) {
347 error = GSM_GetNextMemory(gsm, &Entry, start);
348 if (error == ERR_EMPTY) break;
349 Print_Error(error);
350 for (j=0;j<Entry.EntriesNum;j++) {
351 if (Entry.Entries[j].EntryType == PBK_Category && Entry.Entries[j].Number == Category) {
352 printf(_("Memory %s, Location %i\n"),GSM_MemoryTypeToString(Entry.MemoryType),Entry.Location);
353 error = PrintMemoryEntry(&Entry, gsm);
354 Print_Error(error);
357 GSM_FreeMemoryEntry(&Entry);
358 start = FALSE;
362 void ListMemoryCategory(int argc UNUSED, char *argv[])
364 GSM_Category Category;
365 GSM_CategoryStatus Status;
366 int j, count;
367 GSM_Error error;
369 unsigned char Text[(GSM_MAX_CATEGORY_NAME_LENGTH+1)*2];
370 int Length;
371 gboolean Number = TRUE;;
373 GSM_Init(TRUE);
375 signal(SIGINT, interrupt);
376 fprintf(stderr, "%s\n", _("Press Ctrl+C to break..."));
378 Length = strlen(argv[2]);
379 for (j = 0; j < Length; j++) {
380 if (!isdigit((int)argv[2][j])) {
381 Number = FALSE;
382 break;
386 if (Number) {
387 j = GetInt(argv[2]);
388 if (j > 0) {
389 ListMemoryCategoryEntries(j);
391 } else {
392 if (Length > GSM_MAX_CATEGORY_NAME_LENGTH) {
393 printf(_("Search text too long, truncating to %d chars!\n"), GSM_MAX_CATEGORY_NAME_LENGTH);
394 Length = GSM_MAX_CATEGORY_NAME_LENGTH;
396 EncodeUnicode(Text, argv[2], Length);
398 Category.Type = Category_Phonebook;
399 Status.Type = Category_Phonebook;
401 if (GSM_GetCategoryStatus(gsm, &Status) == ERR_NONE) {
402 for (count=0,j=1;count<Status.Used;j++) {
403 Category.Location=j;
404 error=GSM_GetCategory(gsm, &Category);
406 if (error != ERR_EMPTY) {
407 count++;
408 if (mywstrstr(Category.Name, Text) != NULL) {
409 ListMemoryCategoryEntries(j);
415 GSM_Terminate();
418 /* How should editor hadle tabs in this file? Add editor commands here.
419 * vim: noexpandtab sw=8 ts=8 sts=8: