Translation update done using Pootle.
[gammu.git] / gammu / backupsms.c
blob9c18b4d317eeb00148978c596163aa64a76324b8
1 #include "../helper/locales.h"
3 #include <gammu.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <signal.h>
8 #include "backup.h"
9 #include "memory.h"
10 #include "message.h"
11 #include "common.h"
12 #include "../helper/formats.h"
13 #include "../helper/cmdline.h"
15 #include "../helper/message-display.h"
16 #include "../helper/printing.h"
17 #include "../helper/string.h"
19 void BackupSMS(int argc UNUSED, char *argv[])
21 GSM_Error error;
22 GSM_SMS_Backup Backup;
23 GSM_MultiSMSMessage sms;
24 GSM_SMSFolders folders;
25 gboolean BackupFromFolder[GSM_MAX_SMS_FOLDERS];
26 gboolean start = TRUE;
27 gboolean DeleteAfter = FALSE, askdelete = TRUE;
28 int j, smsnum = 0;
30 if (argc == 4) {
31 if (strcasecmp(argv[3],"-yes") == 0) {
32 always_answer_yes = TRUE;
34 if (strcasecmp(argv[3],"-all") == 0) {
35 always_answer_yes = TRUE;
36 askdelete = FALSE;
37 DeleteAfter = FALSE;
41 GSM_Init(TRUE);
43 Backup.SMS[0] = NULL;
44 sms.SMS[0].Location = 0;
45 sms.Number = 0;
47 error=GSM_GetSMSFolders(gsm, &folders);
48 Print_Error(error);
50 if (askdelete) {
51 DeleteAfter = answer_yes("%s", _("Delete each sms after backup?"));
54 for (j=0;j<folders.Number;j++) {
55 BackupFromFolder[j] = FALSE;
56 if (answer_yes(_("Backup sms from folder \"%s\"%s?"),
57 DecodeUnicodeConsole(folders.Folder[j].Name),
58 folders.Folder[j].Memory == MEM_SM ? _(" (SIM)") : ""
60 BackupFromFolder[j] = TRUE;
63 while (error == ERR_NONE) {
64 sms.SMS[0].Folder=0x00;
65 error=GSM_GetNextSMS(gsm, &sms, start);
66 switch (error) {
67 case ERR_EMPTY:
68 break;
69 default:
70 Print_Error(error);
71 for (j=0;j<sms.Number;j++) {
72 if (BackupFromFolder[sms.SMS[j].Folder-1]) {
73 switch (sms.SMS[j].PDU) {
74 case SMS_Status_Report:
75 break;
76 case SMS_Submit:
77 case SMS_Deliver:
78 if (sms.SMS[j].Length == 0) break;
79 if (smsnum < GSM_BACKUP_MAX_SMS) {
80 Backup.SMS[smsnum] = malloc(sizeof(GSM_SMSMessage));
81 if (Backup.SMS[smsnum] == NULL) Print_Error(ERR_MOREMEMORY);
82 Backup.SMS[smsnum + 1] = NULL;
83 } else {
84 printf(_(" Increase %s\n") , "GSM_BACKUP_MAX_SMS");
85 GSM_Terminate();
86 Terminate(1);
88 *Backup.SMS[smsnum] = sms.SMS[j];
89 smsnum++;
90 break;
95 start=FALSE;
98 error = GSM_AddSMSBackupFile(argv[2],&Backup);
99 Print_Error(error);
101 if (DeleteAfter) {
102 for (j=0;j<smsnum;j++) {
103 Backup.SMS[j]->Folder = 0;
104 error=GSM_DeleteSMS(gsm, Backup.SMS[j]);
105 Print_Error(error);
106 fprintf(stderr, "\r");
107 fprintf(stderr, "%s ", _("Deleting:"));
108 fprintf(stderr, _("%i percent"),
109 (j + 1) * 100 / smsnum);
113 GSM_FreeSMSBackup(&Backup);
115 GSM_Terminate();
118 void AddSMS(int argc UNUSED, char *argv[])
120 GSM_Error error;
121 GSM_MultiSMSMessage SMS;
122 GSM_SMS_Backup Backup;
123 int smsnum = 0;
124 int folder;
126 if (argc == 5 && strcasecmp(argv[4],"-yes") == 0) always_answer_yes = TRUE;
128 folder = GetInt(argv[2]);
130 error = GSM_ReadSMSBackupFile(argv[3], &Backup);
131 Print_Error(error);
133 GSM_Init(TRUE);
135 while (Backup.SMS[smsnum] != NULL) {
136 Backup.SMS[smsnum]->Folder = folder;
137 Backup.SMS[smsnum]->SMSC.Location = 1;
138 SMS.Number = 1;
139 SMS.SMS[0] = *Backup.SMS[smsnum];
140 DisplayMultiSMSInfo(&SMS,FALSE,FALSE,NULL, gsm);
141 if (answer_yes("%s", _("Restore message?"))) {
142 error=GSM_AddSMS(gsm, Backup.SMS[smsnum]);
143 Print_Error(error);
145 smsnum++;
148 /* We don't need this anymore */
149 GSM_FreeSMSBackup(&Backup);
151 GSM_Terminate();
154 void RestoreSMS(int argc, char *argv[])
156 GSM_Error error;
157 GSM_MultiSMSMessage SMS;
158 GSM_SMS_Backup Backup;
159 GSM_SMSFolders folders;
160 int smsnum = 0;
161 gboolean restore8bit;
163 if (argc == 4 && strcasecmp(argv[3],"-yes") == 0) always_answer_yes = TRUE;
165 error = GSM_ReadSMSBackupFile(argv[2], &Backup);
166 Print_Error(error);
168 restore8bit = answer_yes("%s", _("Do you want to restore binary SMS?"));
170 GSM_Init(TRUE);
172 error = GSM_GetSMSFolders(gsm, &folders);
173 Print_Error(error);
175 while (Backup.SMS[smsnum] != NULL) {
176 if (restore8bit || Backup.SMS[smsnum]->Coding != SMS_Coding_8bit) {
177 SMS.Number = 1;
178 memcpy(&SMS.SMS[0],Backup.SMS[smsnum],sizeof(GSM_SMSMessage));
179 DisplayMultiSMSInfo(&SMS,FALSE,FALSE,NULL, gsm);
180 if (answer_yes(_("Restore %03i sms to folder \"%s\"%s?"),
181 smsnum + 1,
182 DecodeUnicodeConsole(folders.Folder[Backup.SMS[smsnum]->Folder - 1].Name),
183 folders.Folder[Backup.SMS[smsnum]->Folder - 1].Memory == MEM_SM ? _(" (SIM)") : "")) {
184 smprintf(gsm, _("saving %i SMS\n"),smsnum);
185 error = GSM_AddSMS(gsm, Backup.SMS[smsnum]);
186 Print_Error(error);
189 smsnum++;
192 /* We don't need this anymore */
193 GSM_FreeSMSBackup(&Backup);
195 GSM_Terminate();
198 /* How should editor hadle tabs in this file? Add editor commands here.
199 * vim: noexpandtab sw=8 ts=8 sts=8: