1 #include <string.h>
2 #include <stdarg.h>
3 #include <signal.h>
4 #include <stdlib.h>
5 #include <ctype.h>
6 
7 #include <gammu.h>
8 
9 #include "locales.h"
10 
11 #include "memory-display.h"
12 #include "formats.h"
13 
14 #define GAMMU_CALLER_GROUPS	20
15 
16 static GSM_Bitmap		caller[GAMMU_CALLER_GROUPS];
17 GSM_AllRingtonesInfo 	ringtones_info = {0, NULL};
18 static gboolean			callerinit[GAMMU_CALLER_GROUPS] = {FALSE, FALSE, FALSE, FALSE, FALSE};
19 static gboolean			ringinit = FALSE;
20 
PrintMemorySubEntry(GSM_SubMemoryEntry * entry,GSM_StateMachine * sm)21 GSM_Error PrintMemorySubEntry(GSM_SubMemoryEntry *entry, GSM_StateMachine *sm)
22 {
23 	GSM_Category	Category;
24 	int		z;
25 	GSM_Error error;
26 	gboolean show_location = TRUE;
27 
28 	switch (entry->EntryType) {
29 	case PBK_CallLength:
30 		printf(LISTFORMAT, _("Call length"));
31 		/* l10n: Call length format string hour:minute:second*/
32 		printf(_("%02i:%02i:%02i\n"),
33 			entry->CallLength / (60 * 60),
34 			entry->CallLength / 60,
35 			entry->CallLength % 60);
36 		return ERR_NONE;
37 	case PBK_Date:
38 		printf(LISTFORMAT "%s\n", _("Date and time"),OSDateTime(entry->Date,FALSE));
39 		return ERR_NONE;
40 	case PBK_LastModified:
41 		printf(LISTFORMAT "%s\n", _("Last modified"), OSDateTime(entry->Date,FALSE));
42 		return ERR_NONE;
43 	case PBK_Category:
44 		if (entry->Number == -1) {
45 			printf(LISTFORMAT "\"%s\"\n", _("Category"), DecodeUnicodeConsole(entry->Text));
46 		} else {
47 			if (sm == NULL) {
48 				error = ERR_NOTSUPPORTED;
49 			} else {
50 				Category.Location = entry->Number;
51 				Category.Type = Category_Phonebook;
52 				error=GSM_GetCategory(sm, &Category);
53 			}
54 			if (error == ERR_NONE) {
55 				printf(LISTFORMAT "\"%s\" (%i)\n", _("Category"), DecodeUnicodeConsole(Category.Name), entry->Number);
56 			} else {
57 				printf(LISTFORMAT "%i\n", _("Category"), entry->Number);
58 			}
59 		}
60 		return ERR_NONE;
61 	case PBK_Private:
62 		printf(LISTFORMAT "%s\n", _("Private"), entry->Number == 1 ? "Yes" : "No");
63 		return ERR_NONE;
64 	case PBK_Caller_Group       :
65 		if (sm == NULL) {
66 			printf(LISTFORMAT "\"%d\"\n", _("Caller group"),entry->Number);
67 			return ERR_NONE;
68 		}
69 		if (entry->Number >= GAMMU_CALLER_GROUPS) {
70 			printf(LISTFORMAT "\"%d\"\n", _("Caller group"),entry->Number);
71 			fprintf(stderr, "%s\n", _("Caller group number too high, please increase buffer in sources!"));
72 			return ERR_MOREMEMORY;
73 		}
74 		if (!callerinit[entry->Number-1]) {
75 			caller[entry->Number-1].Type	    = GSM_CallerGroupLogo;
76 			caller[entry->Number-1].Location = entry->Number;
77 			error=GSM_GetBitmap(sm,&caller[entry->Number-1]);
78 			if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
79 				printf(LISTFORMAT "\"%d\"\n", _("Caller group"), entry->Number);
80 				return ERR_NONE;
81 			}
82 			if (error != ERR_NONE) {
83 				return error;
84 			}
85 			if (caller[entry->Number-1].DefaultName) {
86 				NOKIA_GetDefaultCallerGroupName(&caller[entry->Number-1]);
87 			}
88 			callerinit[entry->Number-1]=TRUE;
89 		}
90 		printf(LISTFORMAT "\"%s\"\n", _("Caller group"),DecodeUnicodeConsole(caller[entry->Number-1].Text));
91 		return ERR_NONE;
92 	case PBK_RingtoneID	     :
93 		if (!ringinit && sm != NULL) {
94 			error=GSM_GetRingtonesInfo(sm,&ringtones_info);
95 			if (error == ERR_NONE) {
96 				ringinit = TRUE;
97 			} else if (error != ERR_NOTSUPPORTED) {
98 				return error;
99 			}
100 		}
101 		if (ringinit) {
102 			for (z=0;z<ringtones_info.Number;z++) {
103 				if (ringtones_info.Ringtone[z].ID == entry->Number) {
104 					printf(LISTFORMAT "\"%s\"\n", _("Ringtone"),DecodeUnicodeConsole(ringtones_info.Ringtone[z].Name));
105 					break;
106 				}
107 			}
108 		} else {
109 			printf(LISTFORMAT "%i\n", _("Ringtone ID"),entry->Number);
110 		}
111 		return ERR_NONE;
112 	case PBK_Text_UserID:
113 		printf(LISTFORMAT "%s\n", _("User ID"),DecodeUnicodeString(entry->Text));
114 		return ERR_NONE;
115 	case PBK_Text_PictureName:
116 		printf(LISTFORMAT "%s\n", _("Picture name"),DecodeUnicodeString(entry->Text));
117 		return ERR_NONE;
118 	case PBK_PictureID	     :
119 		printf(LISTFORMAT "0x%x\n", _("Picture ID"),entry->Number);
120 		return ERR_NONE;
121 	case PBK_Photo:
122 		printf(LISTFORMAT "%s\n", _("Photo"), _("Displaying not supported"));
123 		return ERR_NONE;
124 	case PBK_Number_Messaging   : printf(LISTFORMAT, _("Favorite messaging number")); break;
125 	case PBK_Number_General     :
126 		show_location = FALSE;
127 		switch (entry->Location) {
128 			case PBK_Location_Home:
129 				printf(LISTFORMAT, _("Home number"));
130 				break;
131 			case PBK_Location_Work:
132 				printf(LISTFORMAT, _("Work number"));
133 				break;
134 			case PBK_Location_Unknown:
135 				printf(LISTFORMAT, _("General number"));
136 				break;
137 		}
138 		break;
139 	case PBK_Number_Video     : printf(LISTFORMAT, _("Video number")); break;
140 	case PBK_Number_Mobile      :
141 		show_location = FALSE;
142 		switch (entry->Location) {
143 			case PBK_Location_Home:
144 				printf(LISTFORMAT, _("Home mobile number"));
145 				break;
146 			case PBK_Location_Work:
147 				printf(LISTFORMAT, _("Work mobile number"));
148 				break;
149 			case PBK_Location_Unknown:
150 				printf(LISTFORMAT, _("Mobile number"));
151 				break;
152 		}
153 		break;
154 	case PBK_Number_Fax         :
155 		show_location = FALSE;
156 		switch (entry->Location) {
157 			case PBK_Location_Home:
158 				printf(LISTFORMAT, _("Home fax number"));
159 				break;
160 			case PBK_Location_Work:
161 				printf(LISTFORMAT, _("Work fax number"));
162 				break;
163 			case PBK_Location_Unknown:
164 				printf(LISTFORMAT, _("Fax number"));
165 				break;
166 		}
167 		break;
168 	case PBK_Number_Pager       : printf(LISTFORMAT, _("Pager number")); break;
169 	case PBK_Number_Other       : printf(LISTFORMAT, _("Other number")); break;
170 	case PBK_Text_Note          : printf(LISTFORMAT, _("Text")); break;
171 	case PBK_Text_Postal        :
172 		show_location = FALSE;
173 		switch (entry->Location) {
174 			case PBK_Location_Home:
175 				printf(LISTFORMAT, _("Home address"));
176 				break;
177 			case PBK_Location_Work:
178 				printf(LISTFORMAT, _("Work address"));
179 				break;
180 			case PBK_Location_Unknown:
181 				printf(LISTFORMAT, _("Address"));
182 				break;
183 		}
184 		break;
185 	case PBK_Text_Email         :
186 		show_location = FALSE;
187 		switch (entry->Location) {
188 			case PBK_Location_Home:
189 				printf(LISTFORMAT, _("Home email"));
190 				break;
191 			case PBK_Location_Work:
192 				printf(LISTFORMAT, _("Work email"));
193 				break;
194 			case PBK_Location_Unknown:
195 				printf(LISTFORMAT, _("Email"));
196 				break;
197 		}
198 		break;
199 	case PBK_Text_Email2        : printf(LISTFORMAT, _("Email address 2")); break;
200 	case PBK_Text_URL           :
201 		show_location = FALSE;
202 		switch (entry->Location) {
203 			case PBK_Location_Home:
204 				printf(LISTFORMAT, _("Home website"));
205 				break;
206 			case PBK_Location_Work:
207 				printf(LISTFORMAT, _("Work website"));
208 				break;
209 			case PBK_Location_Unknown:
210 				printf(LISTFORMAT, _("Website"));
211 				break;
212 		}
213 		break;
214 	case PBK_Text_LUID          : printf(LISTFORMAT, _("LUID")); break;
215 	case PBK_Text_VOIP          : printf(LISTFORMAT, _("VOIP")); break;
216 	case PBK_Text_SWIS          : printf(LISTFORMAT, _("SWIS")); break;
217 	case PBK_Text_WVID          : printf(LISTFORMAT, _("WVID")); break;
218 	case PBK_Text_SIP          : printf(LISTFORMAT, _("SIP")); break;
219 	case PBK_Text_DTMF          : printf(LISTFORMAT, _("DTMF")); break;
220 	case PBK_Text_Name          : printf(LISTFORMAT, _("Name")); break;
221 	case PBK_Text_LastName      : printf(LISTFORMAT, _("Last name")); break;
222 	case PBK_Text_FirstName     : printf(LISTFORMAT, _("First name")); break;
223 	case PBK_Text_SecondName     : printf(LISTFORMAT, _("Second name")); break;
224 	case PBK_Text_FormalName     : printf(LISTFORMAT, _("Formal name")); break;
225 	case PBK_Text_NamePrefix     : printf(LISTFORMAT, _("Name prefix")); break;
226 	case PBK_Text_NameSuffix     : printf(LISTFORMAT, _("Name suffix")); break;
227 	case PBK_Text_NickName     : printf(LISTFORMAT, _("Nick name")); break;
228 	case PBK_Text_Company       : printf(LISTFORMAT, _("Company")); break;
229 	case PBK_Text_JobTitle      : printf(LISTFORMAT, _("Job title")); break;
230 	case PBK_Text_StreetAddress : printf(LISTFORMAT, _("Street address")); break;
231 	case PBK_Text_City          : printf(LISTFORMAT, _("City")); break;
232 	case PBK_Text_State         : printf(LISTFORMAT, _("State")); break;
233 	case PBK_Text_Zip           : printf(LISTFORMAT, _("Zip code")); break;
234 	case PBK_Text_Country       : printf(LISTFORMAT, _("Country")); break;
235 	case PBK_Text_Custom1       : printf(LISTFORMAT, _("Custom text 1")); break;
236 	case PBK_Text_Custom2       : printf(LISTFORMAT, _("Custom text 2")); break;
237 	case PBK_Text_Custom3       : printf(LISTFORMAT, _("Custom text 3")); break;
238 	case PBK_Text_Custom4       : printf(LISTFORMAT, _("Custom text 4")); break;
239 	case PBK_PushToTalkID       : printf(LISTFORMAT, _("Push to talk ID")); break;
240 #ifndef CHECK_CASES
241 	default:
242 		printf("%s\n", _("unknown field type"));
243 		return ERR_NONE;
244 #endif
245 	}
246 	if (show_location) {
247 		switch (entry->Location) {
248 			case PBK_Location_Home:
249 				printf("[%s]", _("home"));
250 				break;
251 			case PBK_Location_Work:
252 				printf("[%s]", _("work"));
253 				break;
254 			case PBK_Location_Unknown:
255 				break;
256 		}
257 	}
258 	printf("\"%s\"\n", DecodeUnicodeConsole(entry->Text));
259 	return ERR_NONE;
260 }
261 
PrintMemoryEntry(GSM_MemoryEntry * entry,GSM_StateMachine * sm)262 GSM_Error PrintMemoryEntry(GSM_MemoryEntry *entry, GSM_StateMachine *sm)
263 {
264 	int i;
265 	GSM_Error error;
266 
267 	for (i = 0; i < entry->EntriesNum; i++) {
268 		error = PrintMemorySubEntry(&entry->Entries[i], sm);
269 		if (error != ERR_NONE) return error;
270 	}
271 	printf("\n");
272 	return ERR_NONE;
273 }
274 
PrintMemoryEntryLocation(GSM_MemoryEntry * entry,GSM_StateMachine * sm)275 GSM_Error PrintMemoryEntryLocation(GSM_MemoryEntry *entry, GSM_StateMachine *sm)
276 {
277 	printf(_("Memory %s, Location %i\n"), GSM_MemoryTypeToString(entry->MemoryType), entry->Location);
278 	return PrintMemoryEntry(entry, sm);
279 }
280 
281 /* How should editor hadle tabs in this file? Add editor commands here.
282  * vim: noexpandtab sw=8 ts=8 sts=8:
283  */
284 
285