summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/service/gsmmisc.c4
-rw-r--r--gammu/emb/common/service/gsmpbk.c17
-rw-r--r--gammu/emb/gammu/gammu.c2
-rw-r--r--kabc/addressbook.cpp148
-rw-r--r--kabc/addressbook.h2
-rw-r--r--kabc/addressee.cpp46
-rw-r--r--kabc/addressee.h1
-rw-r--r--kabc/phonenumber.cpp4
-rw-r--r--kaddressbook/kabcore.cpp86
-rw-r--r--libkdepim/ksyncprefsdialog.cpp11
10 files changed, 217 insertions, 104 deletions
diff --git a/gammu/emb/common/service/gsmmisc.c b/gammu/emb/common/service/gsmmisc.c
index 6959a22..1c6ec8b 100644
--- a/gammu/emb/common/service/gsmmisc.c
+++ b/gammu/emb/common/service/gsmmisc.c
@@ -1,262 +1,262 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#include <string.h> 3#include <string.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <sys/stat.h> 5#include <sys/stat.h>
6#ifdef WIN32 6#ifdef WIN32
7# include <io.h> 7# include <io.h>
8# include <fcntl.h> 8# include <fcntl.h>
9#endif 9#endif
10 10
11#include "../misc/coding/coding.h" 11#include "../misc/coding/coding.h"
12#include "../gsmcomon.h" 12#include "../gsmcomon.h"
13#include "gsmmisc.h" 13#include "gsmmisc.h"
14 14
15struct keys_table_position { 15struct keys_table_position {
16 char whatchar; 16 char whatchar;
17 int whatcode; 17 int whatcode;
18}; 18};
19 19
20static struct keys_table_position Keys[] = { 20static struct keys_table_position Keys[] = {
21 {'m',GSM_KEY_MENU}, {'M',GSM_KEY_MENU}, 21 {'m',GSM_KEY_MENU}, {'M',GSM_KEY_MENU},
22 {'n',GSM_KEY_NAMES}, {'N',GSM_KEY_NAMES}, 22 {'n',GSM_KEY_NAMES}, {'N',GSM_KEY_NAMES},
23 {'p',GSM_KEY_POWER}, {'P',GSM_KEY_POWER}, 23 {'p',GSM_KEY_POWER}, {'P',GSM_KEY_POWER},
24 {'u',GSM_KEY_UP}, {'U',GSM_KEY_UP}, 24 {'u',GSM_KEY_UP}, {'U',GSM_KEY_UP},
25 {'d',GSM_KEY_DOWN}, {'D',GSM_KEY_DOWN}, 25 {'d',GSM_KEY_DOWN}, {'D',GSM_KEY_DOWN},
26 {'+',GSM_KEY_INCREASEVOLUME},{'-',GSM_KEY_DECREASEVOLUME}, 26 {'+',GSM_KEY_INCREASEVOLUME},{'-',GSM_KEY_DECREASEVOLUME},
27 {'1',GSM_KEY_1}, {'2',GSM_KEY_2},{'3',GSM_KEY_3}, 27 {'1',GSM_KEY_1}, {'2',GSM_KEY_2},{'3',GSM_KEY_3},
28 {'4',GSM_KEY_4}, {'5',GSM_KEY_5},{'6',GSM_KEY_6}, 28 {'4',GSM_KEY_4}, {'5',GSM_KEY_5},{'6',GSM_KEY_6},
29 {'7',GSM_KEY_7}, {'8',GSM_KEY_8},{'9',GSM_KEY_9}, 29 {'7',GSM_KEY_7}, {'8',GSM_KEY_8},{'9',GSM_KEY_9},
30 {'*',GSM_KEY_ASTERISK}, {'0',GSM_KEY_0},{'#',GSM_KEY_HASH}, 30 {'*',GSM_KEY_ASTERISK}, {'0',GSM_KEY_0},{'#',GSM_KEY_HASH},
31 {'g',GSM_KEY_GREEN}, {'G',GSM_KEY_GREEN}, 31 {'g',GSM_KEY_GREEN}, {'G',GSM_KEY_GREEN},
32 {'r',GSM_KEY_RED}, {'R',GSM_KEY_RED}, 32 {'r',GSM_KEY_RED}, {'R',GSM_KEY_RED},
33 {' ',0} 33 {' ',0}
34}; 34};
35 35
36GSM_Error MakeKeySequence(char *text, GSM_KeyCode *KeyCode, int *Length) 36GSM_Error MakeKeySequence(char *text, GSM_KeyCode *KeyCode, int *Length)
37{ 37{
38 int i,j; 38 int i,j;
39 unsigned char key; 39 unsigned char key;
40 40
41 for (i=0;i<(int)(strlen(text));i++) { 41 for (i=0;i<(int)(strlen(text));i++) {
42 key = text[i]; 42 key = text[i];
43 KeyCode[i] = GSM_KEY_NONE; 43 KeyCode[i] = GSM_KEY_NONE;
44 j = 0; 44 j = 0;
45 while (Keys[j].whatchar!=' ') { 45 while (Keys[j].whatchar!=' ') {
46 if (Keys[j].whatchar==key) { 46 if (Keys[j].whatchar==key) {
47 KeyCode[i]=Keys[j].whatcode; 47 KeyCode[i]=Keys[j].whatcode;
48 break; 48 break;
49 } 49 }
50 j++; 50 j++;
51 } 51 }
52 if (KeyCode[i] == GSM_KEY_NONE) { 52 if (KeyCode[i] == GSM_KEY_NONE) {
53 *Length = i; 53 *Length = i;
54 return ERR_NOTSUPPORTED; 54 return ERR_NOTSUPPORTED;
55 } 55 }
56 } 56 }
57 *Length = i; 57 *Length = i;
58 return ERR_NONE; 58 return ERR_NONE;
59} 59}
60 60
61GSM_Error GSM_ReadFile(char *FileName, GSM_File *File) 61GSM_Error GSM_ReadFile(char *FileName, GSM_File *File)
62{ 62{
63 int i = 1000; 63 int i = 1000;
64 FILE *file; 64 FILE *file;
65 struct statfileinfo; 65 struct statfileinfo;
66 66
67 if (FileName[0] == 0x00) return ERR_UNKNOWN; 67 if (FileName[0] == 0x00) return ERR_UNKNOWN;
68 file = fopen(FileName,"rb"); 68 file = fopen(FileName,"rb");
69 if (file == NULL) return ERR_CANTOPENFILE; 69 if (file == NULL) return ERR_CANTOPENFILE;
70 70
71 free(File->Buffer); 71 free(File->Buffer);
72 File->Buffer = NULL; 72 File->Buffer = NULL;
73 File->Used = 0; 73 File->Used = 0;
74 while (i == 1000) { 74 while (i == 1000) {
75 File->Buffer = realloc(File->Buffer,File->Used + 1000); 75 File->Buffer = realloc(File->Buffer,File->Used + 1000);
76 i = fread(File->Buffer+File->Used,1,1000,file); 76 i = fread(File->Buffer+File->Used,1,1000,file);
77 File->Used = File->Used + i; 77 File->Used = File->Used + i;
78 } 78 }
79 File->Buffer = realloc(File->Buffer,File->Used); 79 File->Buffer = realloc(File->Buffer,File->Used);
80 fclose(file); 80 fclose(file);
81 81
82 File->ModifiedEmpty = true; 82 File->ModifiedEmpty = true;
83 if (stat(FileName,&fileinfo) == 0) { 83 if (stat(FileName,&fileinfo) == 0) {
84 File->ModifiedEmpty = false; 84 File->ModifiedEmpty = false;
85 dbgprintf("File info read correctly\n"); 85 dbgprintf("File info read correctly\n");
86 //st_mtime is time of last modification of file 86 //st_mtime is time of last modification of file
87 Fill_GSM_DateTime(&File->Modified, fileinfo.st_mtime); 87 Fill_GSM_DateTime(&File->Modified, fileinfo.st_mtime);
88 File->Modified.Year = File->Modified.Year + 1900; 88 File->Modified.Year = File->Modified.Year + 1900;
89 dbgprintf("FileTime: %02i-%02i-%04i %02i:%02i:%02i\n", 89 dbgprintf("FileTime: %02i-%02i-%04i %02i:%02i:%02i\n",
90 File->Modified.Day,File->Modified.Month,File->Modified.Year, 90 File->Modified.Day,File->Modified.Month,File->Modified.Year,
91 File->Modified.Hour,File->Modified.Minute,File->Modified.Second); 91 File->Modified.Hour,File->Modified.Minute,File->Modified.Second);
92 } 92 }
93 93
94 return ERR_NONE; 94 return ERR_NONE;
95} 95}
96 96
97static void GSM_JADFindLine(GSM_File File, char *Name, char *Value) 97static void GSM_JADFindLine(GSM_File File, char *Name, char *Value)
98{ 98{
99 unsigned char Line[2000]; 99 unsigned char Line[2000];
100 int Pos = 0; 100 int Pos = 0;
101 101
102 Value[0] = 0; 102 Value[0] = 0;
103 103
104 while (1) { 104 while (1) {
105 MyGetLine(File.Buffer, &Pos, Line, File.Used); 105 MyGetLine(File.Buffer, &Pos, Line, File.Used);
106 if (strlen(Line) == 0) break; 106 if (strlen(Line) == 0) break;
107 if (!strncmp(Line,Name,strlen(Name))) { 107 if (!strncmp(Line,Name,strlen(Name))) {
108 Pos = strlen(Name); 108 Pos = strlen(Name);
109 while (Line[Pos] == 0x20) Pos++; 109 while (Line[Pos] == 0x20) Pos++;
110 strcpy(Value,Line+Pos); 110 strcpy(Value,Line+Pos);
111 return; 111 return;
112 } 112 }
113 } 113 }
114} 114}
115 115
116GSM_Error GSM_JADFindData(GSM_File File, char *Vendor, char *Name, char *JAR, char *Version, int *Size) 116GSM_Error GSM_JADFindData(GSM_File File, char *Vendor, char *Name, char *JAR, char *Version, int *Size)
117{ 117{
118 char Size2[200]; 118 char Size2[200];
119 119
120 GSM_JADFindLine(File, "MIDlet-Vendor:", Vendor); 120 GSM_JADFindLine(File, "MIDlet-Vendor:", Vendor);
121 if (Vendor[0] == 0x00) return ERR_FILENOTSUPPORTED; 121 if (Vendor[0] == 0x00) return ERR_FILENOTSUPPORTED;
122 dbgprintf("Vendor: \"%s\"\n",Vendor); 122 dbgprintf("Vendor: \"%s\"\n",Vendor);
123 123
124 GSM_JADFindLine(File, "MIDlet-Name:", Name); 124 GSM_JADFindLine(File, "MIDlet-Name:", Name);
125 if (Name[0] == 0x00) return ERR_FILENOTSUPPORTED; 125 if (Name[0] == 0x00) return ERR_FILENOTSUPPORTED;
126 dbgprintf("Name: \"%s\"\n",Name); 126 dbgprintf("Name: \"%s\"\n",Name);
127 127
128 GSM_JADFindLine(File, "MIDlet-Jar-URL:", JAR); 128 GSM_JADFindLine(File, "MIDlet-Jar-URL:", JAR);
129 if (JAR[0] == 0x00) return ERR_FILENOTSUPPORTED; 129 if (JAR[0] == 0x00) return ERR_FILENOTSUPPORTED;
130 dbgprintf("JAR file URL: \"%s\"\n",JAR); 130 dbgprintf("JAR file URL: \"%s\"\n",JAR);
131 131
132 GSM_JADFindLine(File, "MIDlet-Jar-Size:", Size2); 132 GSM_JADFindLine(File, "MIDlet-Jar-Size:", Size2);
133 *Size = -1; 133 *Size = -1;
134 if (Size2[0] == 0x00) return ERR_FILENOTSUPPORTED; 134 if (Size2[0] == 0x00) return ERR_FILENOTSUPPORTED;
135 dbgprintf("JAR size: \"%s\"\n",Size2); 135 dbgprintf("JAR size: \"%s\"\n",Size2);
136 (*Size) = atoi(Size2); 136 (*Size) = atoi(Size2);
137 137
138 GSM_JADFindLine(File, "MIDlet-Version:", Version); 138 GSM_JADFindLine(File, "MIDlet-Version:", Version);
139 dbgprintf("Version: \"%s\"\n",Version); 139 dbgprintf("Version: \"%s\"\n",Version);
140 140
141 return ERR_NONE; 141 return ERR_NONE;
142} 142}
143 143
144void GSM_IdentifyFileFormat(GSM_File *File) 144void GSM_IdentifyFileFormat(GSM_File *File)
145{ 145{
146 File->Type = GSM_File_Other; 146 File->Type = GSM_File_Other;
147 if (File->Used > 2) { 147 if (File->Used > 2) {
148 if (memcmp(File->Buffer, "BM",2)==0) { 148 if (memcmp(File->Buffer, "BM",2)==0) {
149 File->Type = GSM_File_Image_BMP; 149 File->Type = GSM_File_Image_BMP;
150 } else if (memcmp(File->Buffer, "GIF",3)==0) { 150 } else if (memcmp(File->Buffer, "GIF",3)==0) {
151 File->Type = GSM_File_Image_GIF; 151 File->Type = GSM_File_Image_GIF;
152 } else if (File->Buffer[0] == 0x00 && File->Buffer[1] == 0x00) { 152 } else if (File->Buffer[0] == 0x00 && File->Buffer[1] == 0x00) {
153 File->Type = GSM_File_Image_WBMP; 153 File->Type = GSM_File_Image_WBMP;
154 } else if (memcmp(File->Buffer+1, "PNG",3)==0) { 154 } else if (memcmp(File->Buffer+1, "PNG",3)==0) {
155 File->Type = GSM_File_Image_PNG; 155 File->Type = GSM_File_Image_PNG;
156 } else if (File->Buffer[0] == 0xFF && File->Buffer[1] == 0xD8) { 156 } else if (File->Buffer[0] == 0xFF && File->Buffer[1] == 0xD8) {
157 File->Type = GSM_File_Image_JPG; 157 File->Type = GSM_File_Image_JPG;
158 } else if (memcmp(File->Buffer, "MThd",4)==0) { 158 } else if (memcmp(File->Buffer, "MThd",4)==0) {
159 File->Type = GSM_File_Sound_MIDI; 159 File->Type = GSM_File_Sound_MIDI;
160 } else if (File->Buffer[0] == 0x00 && File->Buffer[1] == 0x02) { 160 } else if (File->Buffer[0] == 0x00 && File->Buffer[1] == 0x02) {
161 File->Type = GSM_File_Sound_NRT; 161 File->Type = GSM_File_Sound_NRT;
162 } 162 }
163 } 163 }
164} 164}
165 165
166void SaveVCALDateTime(char *Buffer, int *Length, GSM_DateTime *Date, char *Start) 166void SaveVCALDateTime(char *Buffer, int *Length, GSM_DateTime *Date, char *Start)
167{ 167{
168 if (Start != NULL) { 168 if (Start != NULL) {
169 *Length+=sprintf(Buffer+(*Length), "%s:",Start); 169 *Length+=sprintf(Buffer+(*Length), "%s:",Start);
170 } 170 }
171 *Length+=sprintf(Buffer+(*Length), "%04d%02d%02dT%02d%02d%02d%c%c", 171 *Length+=sprintf(Buffer+(*Length), "%04d%02d%02dT%02d%02d%02d%c%c",
172 Date->Year, Date->Month, Date->Day, 172 Date->Year, Date->Month, Date->Day,
173 Date->Hour, Date->Minute, Date->Second,13,10); 173 Date->Hour, Date->Minute, Date->Second,13,10);
174} 174}
175 175
176void ReadVCALDateTime(char *Buffer, GSM_DateTime *dt) 176void ReadVCALDateTime(char *Buffer, GSM_DateTime *dt)
177{ 177{
178 char year[5]="", month[3]="", day[3]="", hour[3]="", minute[3]="", second[3]=""; 178 char year[5]="", month[3]="", day[3]="", hour[3]="", minute[3]="", second[3]="";
179 179
180 memset(dt,0,sizeof(dt)); 180 memset(dt,0,sizeof(dt));
181 181
182 strncpy(year, Buffer, 4); 182 strncpy(year, Buffer, 4);
183 strncpy(month, Buffer+4, 2); 183 strncpy(month, Buffer+4, 2);
184 strncpy(day, Buffer+6, 2); 184 strncpy(day, Buffer+6, 2);
185 strncpy(hour, Buffer+9,2); 185 strncpy(hour, Buffer+9,2);
186 strncpy(minute, Buffer+11,2); 186 strncpy(minute, Buffer+11,2);
187 strncpy(second, Buffer+13,2); 187 strncpy(second, Buffer+13,2);
188 188
189 /* FIXME: Should check ranges... */ 189 /* FIXME: Should check ranges... */
190 dt->Year= atoi(year); 190 dt->Year= atoi(year);
191 dt->Month= atoi(month); 191 dt->Month= atoi(month);
192 dt->Day = atoi(day); 192 dt->Day = atoi(day);
193 dt->Hour= atoi(hour); 193 dt->Hour= atoi(hour);
194 dt->Minute= atoi(minute); 194 dt->Minute= atoi(minute);
195 dt->Second= atoi(second); 195 dt->Second= atoi(second);
196 /* FIXME */ 196 /* FIXME */
197 dt->Timezone= 0; 197 dt->Timezone= 0;
198} 198}
199 199
200void SaveVCALText(char *Buffer, int *Length, char *Text, char *Start) 200void SaveVCALText(char *Buffer, int *Length, char *Text, char *Start)
201{ 201{
202 char buffer[1000]; 202 char buffer[1000];
203 203
204 if (UnicodeLength(Text) != 0) { 204 if (UnicodeLength(Text) != 0) {
205 EncodeUTF8QuotedPrintable(buffer,Text); 205 EncodeUTF8(buffer,Text);
206 if (UnicodeLength(Text)==strlen(buffer)) { 206 if (UnicodeLength(Text)==strlen(buffer)) {
207 *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,DecodeUnicodeString(Text),13,10); 207 *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,DecodeUnicodeString(Text),13,10);
208 } else { 208 } else {
209 *Length+=sprintf(Buffer+(*Length), "%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:%s%c%c",Start,buffer,13,10); 209 *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,buffer,13,10);
210 } 210 }
211 } 211 }
212} 212}
213 213
214bool ReadVCALText(char *Buffer, char *Start, char *Value) 214bool ReadVCALText(char *Buffer, char *Start, char *Value)
215{ 215{
216 unsigned char buff[200]; 216 unsigned char buff[200];
217 217
218 Value[0] = 0x00; 218 Value[0] = 0x00;
219 Value[1] = 0x00; 219 Value[1] = 0x00;
220 220
221 strcpy(buff,Start); 221 strcpy(buff,Start);
222 strcat(buff,":"); 222 strcat(buff,":");
223 if (!strncmp(Buffer,buff,strlen(buff))) { 223 if (!strncmp(Buffer,buff,strlen(buff))) {
224 EncodeUnicode(Value,Buffer+strlen(Start)+1,strlen(Buffer)-(strlen(Start)+1)); 224 EncodeUnicode(Value,Buffer+strlen(Start)+1,strlen(Buffer)-(strlen(Start)+1));
225 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value)); 225 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
226 return true; 226 return true;
227 } 227 }
228 /* SE T68i */ 228 /* SE T68i */
229 strcpy(buff,Start); 229 strcpy(buff,Start);
230 strcat(buff,";ENCODING=QUOTED-PRINTABLE:"); 230 strcat(buff,";ENCODING=QUOTED-PRINTABLE:");
231 if (!strncmp(Buffer,buff,strlen(buff))) { 231 if (!strncmp(Buffer,buff,strlen(buff))) {
232 DecodeUTF8QuotedPrintable(Value,Buffer+strlen(Start)+27,strlen(Buffer)-(strlen(Start)+27)); 232 DecodeUTF8QuotedPrintable(Value,Buffer+strlen(Start)+27,strlen(Buffer)-(strlen(Start)+27));
233 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value)); 233 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
234 return true; 234 return true;
235 } 235 }
236 strcpy(buff,Start); 236 strcpy(buff,Start);
237 strcat(buff,";CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:"); 237 strcat(buff,";CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:");
238 if (!strncmp(Buffer,buff,strlen(buff))) { 238 if (!strncmp(Buffer,buff,strlen(buff))) {
239 DecodeUTF8QuotedPrintable(Value,Buffer+strlen(Start)+41,strlen(Buffer)-(strlen(Start)+41)); 239 DecodeUTF8QuotedPrintable(Value,Buffer+strlen(Start)+41,strlen(Buffer)-(strlen(Start)+41));
240 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value)); 240 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
241 return true; 241 return true;
242 } 242 }
243 strcpy(buff,Start); 243 strcpy(buff,Start);
244 strcat(buff,";CHARSET=UTF-8:"); 244 strcat(buff,";CHARSET=UTF-8:");
245 if (!strncmp(Buffer,buff,strlen(buff))) { 245 if (!strncmp(Buffer,buff,strlen(buff))) {
246 DecodeUTF8(Value,Buffer+strlen(Start)+15,strlen(Buffer)-(strlen(Start)+15)); 246 DecodeUTF8(Value,Buffer+strlen(Start)+15,strlen(Buffer)-(strlen(Start)+15));
247 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value)); 247 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
248 return true; 248 return true;
249 } 249 }
250 strcpy(buff,Start); 250 strcpy(buff,Start);
251 strcat(buff,";CHARSET=UTF-7:"); 251 strcat(buff,";CHARSET=UTF-7:");
252 if (!strncmp(Buffer,buff,strlen(buff))) { 252 if (!strncmp(Buffer,buff,strlen(buff))) {
253 DecodeUTF7(Value,Buffer+strlen(Start)+15,strlen(Buffer)-(strlen(Start)+15)); 253 DecodeUTF7(Value,Buffer+strlen(Start)+15,strlen(Buffer)-(strlen(Start)+15));
254 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value)); 254 dbgprintf("ReadVCalText is \"%s\"\n",DecodeUnicodeConsole(Value));
255 return true; 255 return true;
256 } 256 }
257 return false; 257 return false;
258} 258}
259 259
260/* How should editor hadle tabs in this file? Add editor commands here. 260/* How should editor hadle tabs in this file? Add editor commands here.
261 * vim: noexpandtab sw=8 ts=8 sts=8: 261 * vim: noexpandtab sw=8 ts=8 sts=8:
262 */ 262 */
diff --git a/gammu/emb/common/service/gsmpbk.c b/gammu/emb/common/service/gsmpbk.c
index 05e5cb9..f7cf7d7 100644
--- a/gammu/emb/common/service/gsmpbk.c
+++ b/gammu/emb/common/service/gsmpbk.c
@@ -1,370 +1,371 @@
1/* (c) 2001-2003 by Marcin Wiacek,... */ 1/* (c) 2001-2003 by Marcin Wiacek,... */
2 2
3#include <string.h> 3#include <string.h>
4 4
5#include "../misc/coding/coding.h" 5#include "../misc/coding/coding.h"
6#include "gsmpbk.h" 6#include "gsmpbk.h"
7#include "gsmmisc.h" 7#include "gsmmisc.h"
8 8
9unsigned char *GSM_PhonebookGetEntryName (GSM_MemoryEntry *entry) 9unsigned char *GSM_PhonebookGetEntryName (GSM_MemoryEntry *entry)
10{ 10{
11 /* We possibly store here "LastName, FirstName" so allocate enough memory */ 11 /* We possibly store here "LastName, FirstName" so allocate enough memory */
12 static char dest[(GSM_PHONEBOOK_TEXT_LENGTH*2+2+1)*2]; 12 static char dest[(GSM_PHONEBOOK_TEXT_LENGTH*2+2+1)*2];
13 static char split[] = { '\0', ',', '\0', ' ', '\0', '\0'}; 13 static char split[] = { '\0', ',', '\0', ' ', '\0', '\0'};
14 int i; 14 int i;
15 int first = -1, last = -1, name = -1; 15 int first = -1, last = -1, name = -1;
16 int len = 0; 16 int len = 0;
17 17
18 for (i = 0; i < entry->EntriesNum; i++) { 18 for (i = 0; i < entry->EntriesNum; i++) {
19 switch (entry->Entries[i].EntryType) { 19 switch (entry->Entries[i].EntryType) {
20 case PBK_Text_LastName: 20 case PBK_Text_LastName:
21 last = i; 21 last = i;
22 break; 22 break;
23 case PBK_Text_FirstName: 23 case PBK_Text_FirstName:
24 first = i; 24 first = i;
25 break; 25 break;
26 case PBK_Text_Name: 26 case PBK_Text_Name:
27 name = i; 27 name = i;
28 break; 28 break;
29 default: 29 default:
30 break; 30 break;
31 } 31 }
32 } 32 }
33 33
34 if (name != -1) { 34 if (name != -1) {
35 CopyUnicodeString(dest, entry->Entries[name].Text); 35 CopyUnicodeString(dest, entry->Entries[name].Text);
36 } else { 36 } else {
37 if (last != -1 && first != -1) { 37 if (last != -1 && first != -1) {
38 len = UnicodeLength(entry->Entries[last].Text); 38 len = UnicodeLength(entry->Entries[last].Text);
39 CopyUnicodeString(dest, entry->Entries[last].Text); 39 CopyUnicodeString(dest, entry->Entries[last].Text);
40 CopyUnicodeString(dest + 2*len, split); 40 CopyUnicodeString(dest + 2*len, split);
41 CopyUnicodeString(dest + 2*len + 4, entry->Entries[first].Text); 41 CopyUnicodeString(dest + 2*len + 4, entry->Entries[first].Text);
42 } else if (last != -1) { 42 } else if (last != -1) {
43 CopyUnicodeString(dest, entry->Entries[last].Text); 43 CopyUnicodeString(dest, entry->Entries[last].Text);
44 } else if (first != -1) { 44 } else if (first != -1) {
45 CopyUnicodeString(dest, entry->Entries[first].Text); 45 CopyUnicodeString(dest, entry->Entries[first].Text);
46 } else { 46 } else {
47 return NULL; 47 return NULL;
48 } 48 }
49 } 49 }
50 50
51 return dest; 51 return dest;
52} 52}
53 53
54void GSM_PhonebookFindDefaultNameNumberGroup(GSM_MemoryEntry *entry, int *Name, int *Number, int *Group) 54void GSM_PhonebookFindDefaultNameNumberGroup(GSM_MemoryEntry *entry, int *Name, int *Number, int *Group)
55{ 55{
56 int i; 56 int i;
57 57
58 *Name = -1; 58 *Name = -1;
59 *Number = -1; 59 *Number = -1;
60 *Group = -1; 60 *Group = -1;
61 for (i = 0; i < entry->EntriesNum; i++) { 61 for (i = 0; i < entry->EntriesNum; i++) {
62 switch (entry->Entries[i].EntryType) { 62 switch (entry->Entries[i].EntryType) {
63 case PBK_Number_General : if (*Number == -1) *Number = i; break; 63 case PBK_Number_General : if (*Number == -1) *Number = i; break;
64 case PBK_Text_Name : if (*Name == -1) *Name = i; break; 64 case PBK_Text_Name : if (*Name == -1) *Name = i; break;
65 case PBK_Caller_Group : if (*Group == -1) *Group = i; break; 65 case PBK_Caller_Group : if (*Group == -1) *Group = i; break;
66 default : break; 66 default : break;
67 } 67 }
68 } 68 }
69 if ((*Number) == -1) { 69 if ((*Number) == -1) {
70 for (i = 0; i < entry->EntriesNum; i++) { 70 for (i = 0; i < entry->EntriesNum; i++) {
71 switch (entry->Entries[i].EntryType) { 71 switch (entry->Entries[i].EntryType) {
72 case PBK_Number_Mobile: 72 case PBK_Number_Mobile:
73 case PBK_Number_Work: 73 case PBK_Number_Work:
74 case PBK_Number_Fax: 74 case PBK_Number_Fax:
75 case PBK_Number_Home: 75 case PBK_Number_Home:
76 case PBK_Number_Pager: 76 case PBK_Number_Pager:
77 case PBK_Number_Other: 77 case PBK_Number_Other:
78 *Number = i; 78 *Number = i;
79 break; 79 break;
80 default: 80 default:
81 break; 81 break;
82 } 82 }
83 if (*Number != -1) break; 83 if (*Number != -1) break;
84 } 84 }
85 } 85 }
86 if ((*Name) == -1) { 86 if ((*Name) == -1) {
87 for (i = 0; i < entry->EntriesNum; i++) { 87 for (i = 0; i < entry->EntriesNum; i++) {
88 if (entry->Entries[i].EntryType != PBK_Text_LastName) continue; 88 if (entry->Entries[i].EntryType != PBK_Text_LastName) continue;
89 *Name = i; 89 *Name = i;
90 break; 90 break;
91 } 91 }
92 } 92 }
93 if ((*Name) == -1) { 93 if ((*Name) == -1) {
94 for (i = 0; i < entry->EntriesNum; i++) { 94 for (i = 0; i < entry->EntriesNum; i++) {
95 if (entry->Entries[i].EntryType != PBK_Text_FirstName) continue; 95 if (entry->Entries[i].EntryType != PBK_Text_FirstName) continue;
96 *Name = i; 96 *Name = i;
97 break; 97 break;
98 } 98 }
99 } 99 }
100} 100}
101 101
102void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool header, GSM_VCardVersion Version) 102void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool header, GSM_VCardVersion Version)
103{ 103{
104 int Name, Number, Group, i; 104 int Name, Number, Group, i;
105 bool ignore; 105 bool ignore;
106 106
107 GSM_PhonebookFindDefaultNameNumberGroup(pbk, &Name, &Number, &Group); 107 GSM_PhonebookFindDefaultNameNumberGroup(pbk, &Name, &Number, &Group);
108 108
109 if (Version == Nokia_VCard10) { 109 if (Version == Nokia_VCard10) {
110 if (header) *Length+=sprintf(Buffer+(*Length),"BEGIN:VCARD%c%c",13,10); 110 if (header) *Length+=sprintf(Buffer+(*Length),"BEGIN:VCARD%c%c",13,10);
111 if (Name != -1) { 111 if (Name != -1) {
112 *Length+=sprintf(Buffer+(*Length),"N:%s%c%c",DecodeUnicodeString(pbk->Entries[Name].Text),13,10); 112 *Length+=sprintf(Buffer+(*Length),"N:%s%c%c",DecodeUnicodeString(pbk->Entries[Name].Text),13,10);
113 } 113 }
114 if (Number != -1) { 114 if (Number != -1) {
115 *Length +=sprintf(Buffer+(*Length),"TEL:%s%c%c",DecodeUnicodeString(pbk->Entries[Number].Text),13,10); 115 *Length +=sprintf(Buffer+(*Length),"TEL:%s%c%c",DecodeUnicodeString(pbk->Entries[Number].Text),13,10);
116 } 116 }
117 if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10); 117 if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10);
118 } else if (Version == Nokia_VCard21) { 118 } else if (Version == Nokia_VCard21) {
119 if (header) *Length+=sprintf(Buffer+(*Length),"BEGIN:VCARD%c%cVERSION:2.1%c%c",13,10,13,10); 119 if (header) *Length+=sprintf(Buffer+(*Length),"BEGIN:VCARD%c%cVERSION:2.1%c%c",13,10,13,10);
120 if (Name != -1) { 120 if (Name != -1) {
121 SaveVCALText(Buffer, Length, pbk->Entries[Name].Text, "N"); 121 SaveVCALText(Buffer, Length, pbk->Entries[Name].Text, "N");
122 } 122 }
123 for (i=0; i < pbk->EntriesNum; i++) { 123 for (i=0; i < pbk->EntriesNum; i++) {
124 if (i != Name) { 124 if (i != Name) {
125 ignore = false; 125 ignore = false;
126 switch(pbk->Entries[i].EntryType) { 126 switch(pbk->Entries[i].EntryType) {
127 case PBK_Text_Name : 127 case PBK_Text_Name :
128 case PBK_Date : 128 case PBK_Date :
129 case PBK_Caller_Group : 129 case PBK_Caller_Group :
130 ignore = true; 130 ignore = true;
131 break; 131 break;
132 case PBK_Number_General : 132 case PBK_Number_General :
133 *Length+=sprintf(Buffer+(*Length),"TEL"); 133 *Length+=sprintf(Buffer+(*Length),"TEL");
134 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 134 (*Length)+=sprintf(Buffer+(*Length),";PREF");
135 break; 135 break;
136 case PBK_Number_Mobile : 136 case PBK_Number_Mobile :
137 *Length+=sprintf(Buffer+(*Length),"TEL"); 137 *Length+=sprintf(Buffer+(*Length),"TEL");
138 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 138 //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
139 *Length+=sprintf(Buffer+(*Length),";CELL"); 139 *Length+=sprintf(Buffer+(*Length),";CELL");
140 break; 140 break;
141 case PBK_Number_Work : 141 case PBK_Number_Work :
142 *Length+=sprintf(Buffer+(*Length),"TEL"); 142 *Length+=sprintf(Buffer+(*Length),"TEL");
143 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 143 //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
144 *Length+=sprintf(Buffer+(*Length),";WORK;VOICE"); 144 *Length+=sprintf(Buffer+(*Length),";WORK");
145 break; 145 break;
146 case PBK_Number_Fax : 146 case PBK_Number_Fax :
147 *Length+=sprintf(Buffer+(*Length),"TEL"); 147 *Length+=sprintf(Buffer+(*Length),"TEL");
148 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 148 //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
149 *Length+=sprintf(Buffer+(*Length),";FAX"); 149 *Length+=sprintf(Buffer+(*Length),";FAX");
150 break; 150 break;
151 case PBK_Number_Home : 151 case PBK_Number_Home :
152 *Length+=sprintf(Buffer+(*Length),"TEL"); 152 *Length+=sprintf(Buffer+(*Length),"TEL");
153 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 153 //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
154 *Length+=sprintf(Buffer+(*Length),";HOME;VOICE"); 154 *Length+=sprintf(Buffer+(*Length),";HOME");
155 break; 155 break;
156 case PBK_Text_Note : 156 case PBK_Text_Note :
157 *Length+=sprintf(Buffer+(*Length),"NOTE"); 157 *Length+=sprintf(Buffer+(*Length),"NOTE");
158 break; 158 break;
159 case PBK_Text_Postal : 159 case PBK_Text_Postal :
160 /* Don't ask why. Nokia phones save postal address 160 /* Don't ask why. Nokia phones save postal address
161 * double - once like LABEL, second like ADR 161 * double - once like LABEL, second like ADR
162 */ 162 */
163 SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "LABEL"); 163 //SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "LABEL");
164 *Length+=sprintf(Buffer+(*Length),"ADR"); 164 *Length+=sprintf(Buffer+(*Length),"ADR");
165 break; 165 break;
166 case PBK_Text_Email : 166 case PBK_Text_Email :
167 case PBK_Text_Email2 : 167 case PBK_Text_Email2 :
168 *Length+=sprintf(Buffer+(*Length),"EMAIL"); 168 *Length+=sprintf(Buffer+(*Length),"EMAIL");
169 break; 169 break;
170 case PBK_Text_URL : 170 case PBK_Text_URL :
171 *Length+=sprintf(Buffer+(*Length),"URL"); 171 *Length+=sprintf(Buffer+(*Length),"URL");
172 break; 172 break;
173 default : 173 default :
174 ignore = true; 174 ignore = true;
175 break; 175 break;
176 } 176 }
177 if (!ignore) { 177 if (!ignore) {
178 SaveVCALText(Buffer, Length, pbk->Entries[i].Text, ""); 178 SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "");
179 } 179 }
180 } 180 }
181 } 181 }
182 *Length+=sprintf(Buffer+(*Length), "X-KADDRESSBOOK-X-ExternalID:%d%c%c",pbk->Location,13,10);
182 if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10); 183 if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10);
183 } 184 }
184} 185}
185 186
186GSM_Error GSM_DecodeVCARD(unsigned char *Buffer, int *Pos, GSM_MemoryEntry *Pbk, GSM_VCardVersion Version) 187GSM_Error GSM_DecodeVCARD(unsigned char *Buffer, int *Pos, GSM_MemoryEntry *Pbk, GSM_VCardVersion Version)
187{ 188{
188 unsigned char Line[2000],Buff[2000]; 189 unsigned char Line[2000],Buff[2000];
189 int Level = 0; 190 int Level = 0;
190 191
191 Buff[0] = 0; 192 Buff[0] = 0;
192 Pbk->EntriesNum = 0; 193 Pbk->EntriesNum = 0;
193 194
194 while (1) { 195 while (1) {
195 MyGetLine(Buffer, Pos, Line, strlen(Buffer)); 196 MyGetLine(Buffer, Pos, Line, strlen(Buffer));
196 if (strlen(Line) == 0) break; 197 if (strlen(Line) == 0) break;
197 switch (Level) { 198 switch (Level) {
198 case 0: 199 case 0:
199 if (strstr(Line,"BEGIN:VCARD")) Level = 1; 200 if (strstr(Line,"BEGIN:VCARD")) Level = 1;
200 break; 201 break;
201 case 1: 202 case 1:
202 if (strstr(Line,"END:VCARD")) { 203 if (strstr(Line,"END:VCARD")) {
203 if (Pbk->EntriesNum == 0) return ERR_EMPTY; 204 if (Pbk->EntriesNum == 0) return ERR_EMPTY;
204 return ERR_NONE; 205 return ERR_NONE;
205 } 206 }
206 if (ReadVCALText(Line, "N", Buff)) { 207 if (ReadVCALText(Line, "N", Buff)) {
207 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 208 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
208 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Name; 209 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Name;
209 Pbk->EntriesNum++; 210 Pbk->EntriesNum++;
210 } 211 }
211 if (ReadVCALText(Line, "TEL", Buff) || 212 if (ReadVCALText(Line, "TEL", Buff) ||
212 ReadVCALText(Line, "TEL;VOICE", Buff) || 213 ReadVCALText(Line, "TEL;VOICE", Buff) ||
213 ReadVCALText(Line, "TEL;PREF", Buff) || 214 ReadVCALText(Line, "TEL;PREF", Buff) ||
214 ReadVCALText(Line, "TEL;PREF;VOICE", Buff)) { 215 ReadVCALText(Line, "TEL;PREF;VOICE", Buff)) {
215 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 216 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
216 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_General; 217 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_General;
217 Pbk->EntriesNum++; 218 Pbk->EntriesNum++;
218 } 219 }
219 if (ReadVCALText(Line, "TEL;CELL", Buff) || 220 if (ReadVCALText(Line, "TEL;CELL", Buff) ||
220 ReadVCALText(Line, "TEL;CELL;VOICE", Buff) || 221 ReadVCALText(Line, "TEL;CELL;VOICE", Buff) ||
221 ReadVCALText(Line, "TEL;PREF;CELL", Buff) || 222 ReadVCALText(Line, "TEL;PREF;CELL", Buff) ||
222 ReadVCALText(Line, "TEL;PREF;CELL;VOICE", Buff)) { 223 ReadVCALText(Line, "TEL;PREF;CELL;VOICE", Buff)) {
223 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 224 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
224 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Mobile; 225 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Mobile;
225 Pbk->EntriesNum++; 226 Pbk->EntriesNum++;
226 } 227 }
227 if (ReadVCALText(Line, "TEL;WORK", Buff) || 228 if (ReadVCALText(Line, "TEL;WORK", Buff) ||
228 ReadVCALText(Line, "TEL;PREF;WORK", Buff) || 229 ReadVCALText(Line, "TEL;PREF;WORK", Buff) ||
229 ReadVCALText(Line, "TEL;WORK;VOICE", Buff) || 230 ReadVCALText(Line, "TEL;WORK;VOICE", Buff) ||
230 ReadVCALText(Line, "TEL;PREF;WORK;VOICE", Buff)) { 231 ReadVCALText(Line, "TEL;PREF;WORK;VOICE", Buff)) {
231 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 232 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
232 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Work; 233 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Work;
233 Pbk->EntriesNum++; 234 Pbk->EntriesNum++;
234 } 235 }
235 if (ReadVCALText(Line, "TEL;FAX", Buff) || 236 if (ReadVCALText(Line, "TEL;FAX", Buff) ||
236 ReadVCALText(Line, "TEL;PREF;FAX", Buff) || 237 ReadVCALText(Line, "TEL;PREF;FAX", Buff) ||
237 ReadVCALText(Line, "TEL;FAX;VOICE", Buff) || 238 ReadVCALText(Line, "TEL;FAX;VOICE", Buff) ||
238 ReadVCALText(Line, "TEL;PREF;FAX;VOICE", Buff)) { 239 ReadVCALText(Line, "TEL;PREF;FAX;VOICE", Buff)) {
239 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 240 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
240 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Fax; 241 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Fax;
241 Pbk->EntriesNum++; 242 Pbk->EntriesNum++;
242 } 243 }
243 if (ReadVCALText(Line, "TEL;HOME", Buff) || 244 if (ReadVCALText(Line, "TEL;HOME", Buff) ||
244 ReadVCALText(Line, "TEL;PREF;HOME", Buff) || 245 ReadVCALText(Line, "TEL;PREF;HOME", Buff) ||
245 ReadVCALText(Line, "TEL;HOME;VOICE", Buff) || 246 ReadVCALText(Line, "TEL;HOME;VOICE", Buff) ||
246 ReadVCALText(Line, "TEL;PREF;HOME;VOICE", Buff)) { 247 ReadVCALText(Line, "TEL;PREF;HOME;VOICE", Buff)) {
247 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 248 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
248 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Home; 249 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Home;
249 Pbk->EntriesNum++; 250 Pbk->EntriesNum++;
250 } 251 }
251 if (ReadVCALText(Line, "NOTE", Buff)) { 252 if (ReadVCALText(Line, "NOTE", Buff)) {
252 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 253 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
253 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Note; 254 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Note;
254 Pbk->EntriesNum++; 255 Pbk->EntriesNum++;
255 } 256 }
256 if (ReadVCALText(Line, "ADR", Buff)) { 257 if (ReadVCALText(Line, "ADR", Buff)) {
257 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 258 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
258 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Postal; 259 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Postal;
259 Pbk->EntriesNum++; 260 Pbk->EntriesNum++;
260 } 261 }
261 if (ReadVCALText(Line, "EMAIL", Buff)) { 262 if (ReadVCALText(Line, "EMAIL", Buff)) {
262 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 263 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
263 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Email; 264 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Email;
264 Pbk->EntriesNum++; 265 Pbk->EntriesNum++;
265 } 266 }
266 if (ReadVCALText(Line, "URL", Buff)) { 267 if (ReadVCALText(Line, "URL", Buff)) {
267 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff); 268 CopyUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text,Buff);
268 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_URL; 269 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_URL;
269 Pbk->EntriesNum++; 270 Pbk->EntriesNum++;
270 } 271 }
271 break; 272 break;
272 } 273 }
273 } 274 }
274 275
275 if (Pbk->EntriesNum == 0) return ERR_EMPTY; 276 if (Pbk->EntriesNum == 0) return ERR_EMPTY;
276 return ERR_NONE; 277 return ERR_NONE;
277} 278}
278 279
279/* -------------- OLD functions (c) by Timo Teras -------------------------- */ 280/* -------------- OLD functions (c) by Timo Teras -------------------------- */
280 281
281#ifndef ENABLE_LGPL 282#ifndef ENABLE_LGPL
282 283
283static void ParseVCardLine(char **pos, char *Name, char *Parameters, char *Value) 284static void ParseVCardLine(char **pos, char *Name, char *Parameters, char *Value)
284{ 285{
285 int i; 286 int i;
286 287
287 Name[0] = Parameters[0] = Value[0] = 0; 288 Name[0] = Parameters[0] = Value[0] = 0;
288 289
289 if (**pos == 0) return; 290 if (**pos == 0) return;
290 291
291 for (i=0; **pos && **pos != ':' && **pos != ';'; i++, (*pos)++) Name[i] = **pos; 292 for (i=0; **pos && **pos != ':' && **pos != ';'; i++, (*pos)++) Name[i] = **pos;
292 Name[i] = 0; 293 Name[i] = 0;
293 294
294 //dbgprintf("ParseVCardLine: name tag = '%s'\n", Name); 295 //dbgprintf("ParseVCardLine: name tag = '%s'\n", Name);
295 if (**pos == ';') { 296 if (**pos == ';') {
296 (*pos)++; 297 (*pos)++;
297 for (i=0; **pos && **pos != ':'; i++, (*pos)++) Parameters[i] = **pos; 298 for (i=0; **pos && **pos != ':'; i++, (*pos)++) Parameters[i] = **pos;
298 Parameters[i] = ';'; 299 Parameters[i] = ';';
299 Parameters[i+1] = 0; 300 Parameters[i+1] = 0;
300 //dbgprintf("ParseVCardLine: parameter tag = '%s'\n", Parameters); 301 //dbgprintf("ParseVCardLine: parameter tag = '%s'\n", Parameters);
301 } 302 }
302 303
303 if (**pos != 0) (*pos)++; 304 if (**pos != 0) (*pos)++;
304 305
305 i=0; 306 i=0;
306 while (**pos) { 307 while (**pos) {
307 if ((*pos)[0] == '\x0d' && (*pos)[1] == '\x0a') { 308 if ((*pos)[0] == '\x0d' && (*pos)[1] == '\x0a') {
308 (*pos) += 2; 309 (*pos) += 2;
309 if (**pos != '\t' && **pos != ' ') break; 310 if (**pos != '\t' && **pos != ' ') break;
310 while (**pos == '\t' || **pos == ' ') (*pos)++; 311 while (**pos == '\t' || **pos == ' ') (*pos)++;
311 continue; 312 continue;
312 } 313 }
313 Value[i++] = **pos; 314 Value[i++] = **pos;
314 (*pos)++; 315 (*pos)++;
315 } 316 }
316 Value[i] = 0; 317 Value[i] = 0;
317 318
318 //dbgprintf("ParseVCardLine: value tag = '%s'\n", Value); 319 //dbgprintf("ParseVCardLine: value tag = '%s'\n", Value);
319} 320}
320 321
321void DecodeVCARD21Text(char *VCard, GSM_MemoryEntry *pbk) 322void DecodeVCARD21Text(char *VCard, GSM_MemoryEntry *pbk)
322{ 323{
323 char *pos = VCard; 324 char *pos = VCard;
324 char Name[32], Parameters[256], Value[1024]; 325 char Name[32], Parameters[256], Value[1024];
325 326
326 dbgprintf("Parsing VCard:\n%s\n", VCard); 327 dbgprintf("Parsing VCard:\n%s\n", VCard);
327 328
328 ParseVCardLine(&pos, Name, Parameters, Value); 329 ParseVCardLine(&pos, Name, Parameters, Value);
329 if (!mystrncasecmp(Name, "BEGIN", 0) || !mystrncasecmp(Value, "VCARD", 0)) { 330 if (!mystrncasecmp(Name, "BEGIN", 0) || !mystrncasecmp(Value, "VCARD", 0)) {
330 dbgprintf("No valid VCARD signature\n"); 331 dbgprintf("No valid VCARD signature\n");
331 return; 332 return;
332 } 333 }
333 334
334 while (1) { 335 while (1) {
335 GSM_SubMemoryEntry *pbe = &pbk->Entries[pbk->EntriesNum]; 336 GSM_SubMemoryEntry *pbe = &pbk->Entries[pbk->EntriesNum];
336 337
337 ParseVCardLine(&pos, Name, Parameters, Value); 338 ParseVCardLine(&pos, Name, Parameters, Value);
338 if (Name[0] == 0x00 || 339 if (Name[0] == 0x00 ||
339 (mystrncasecmp(Name, "END", 0) && mystrncasecmp(Value, "VCARD", 0))) 340 (mystrncasecmp(Name, "END", 0) && mystrncasecmp(Value, "VCARD", 0)))
340 return; 341 return;
341 342
342 if (mystrncasecmp(Name, "N", 0)) { 343 if (mystrncasecmp(Name, "N", 0)) {
343 //FIXME: Name is tagged field which should be parsed 344 //FIXME: Name is tagged field which should be parsed
344 pbe->EntryType = PBK_Text_Name; 345 pbe->EntryType = PBK_Text_Name;
345 EncodeUnicode(pbe->Text, Value, strlen(Value)); 346 EncodeUnicode(pbe->Text, Value, strlen(Value));
346 pbk->EntriesNum++; 347 pbk->EntriesNum++;
347 } else if (mystrncasecmp(Name, "EMAIL", 0)) { 348 } else if (mystrncasecmp(Name, "EMAIL", 0)) {
348 pbe->EntryType = PBK_Text_Email; 349 pbe->EntryType = PBK_Text_Email;
349 EncodeUnicode(pbe->Text, Value, strlen(Value)); 350 EncodeUnicode(pbe->Text, Value, strlen(Value));
350 pbk->EntriesNum++; 351 pbk->EntriesNum++;
351 } else if (mystrncasecmp(Name, "TEL", 0)) { 352 } else if (mystrncasecmp(Name, "TEL", 0)) {
352 if (strstr(Parameters, "WORK;")) 353 if (strstr(Parameters, "WORK;"))
353 pbe->EntryType = PBK_Number_Work; 354 pbe->EntryType = PBK_Number_Work;
354 else if (strstr(Name, "HOME;")) 355 else if (strstr(Name, "HOME;"))
355 pbe->EntryType = PBK_Number_Home; 356 pbe->EntryType = PBK_Number_Home;
356 else if (strstr(Name, "FAX;")) 357 else if (strstr(Name, "FAX;"))
357 pbe->EntryType = PBK_Number_Fax; 358 pbe->EntryType = PBK_Number_Fax;
358 else pbe->EntryType = PBK_Number_General; 359 else pbe->EntryType = PBK_Number_General;
359 360
360 EncodeUnicode(pbe->Text, Value, strlen(Value)); 361 EncodeUnicode(pbe->Text, Value, strlen(Value));
361 pbk->EntriesNum++; 362 pbk->EntriesNum++;
362 } 363 }
363 } 364 }
364} 365}
365 366
366#endif 367#endif
367 368
368/* How should editor hadle tabs in this file? Add editor commands here. 369/* How should editor hadle tabs in this file? Add editor commands here.
369 * vim: noexpandtab sw=8 ts=8 sts=8: 370 * vim: noexpandtab sw=8 ts=8 sts=8:
370 */ 371 */
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c
index 8db9afb..684e67c 100644
--- a/gammu/emb/gammu/gammu.c
+++ b/gammu/emb/gammu/gammu.c
@@ -4177,1025 +4177,1025 @@ static void Backup(int argc, char *argv[])
4177 exit(-1); 4177 exit(-1);
4178 } 4178 }
4179 *Backup.ToDo[used]=ToDo; 4179 *Backup.ToDo[used]=ToDo;
4180 used ++; 4180 used ++;
4181 error=Phone->GetNextToDo(&s,&ToDo,false); 4181 error=Phone->GetNextToDo(&s,&ToDo,false);
4182 printmsgerr("%c Reading: %i percent",13,used*100/ToDoStatus.Used); 4182 printmsgerr("%c Reading: %i percent",13,used*100/ToDoStatus.Used);
4183 if (gshutdown) { 4183 if (gshutdown) {
4184 GSM_Terminate(); 4184 GSM_Terminate();
4185 exit(0); 4185 exit(0);
4186 } 4186 }
4187 } 4187 }
4188 printmsgerr("\n"); 4188 printmsgerr("\n");
4189 } 4189 }
4190 DoBackup = false; 4190 DoBackup = false;
4191 if (Info.Note) { 4191 if (Info.Note) {
4192 printmsg("Checking notes\n"); 4192 printmsg("Checking notes\n");
4193 error=Phone->GetNextNote(&s,&Note,true); 4193 error=Phone->GetNextNote(&s,&Note,true);
4194 if (error==ERR_NONE) { 4194 if (error==ERR_NONE) {
4195 if (answer_yes(" Backup notes")) DoBackup = true; 4195 if (answer_yes(" Backup notes")) DoBackup = true;
4196 } 4196 }
4197 } 4197 }
4198 if (DoBackup) { 4198 if (DoBackup) {
4199 used = 0; 4199 used = 0;
4200 printmsgerr(" Reading : "); 4200 printmsgerr(" Reading : ");
4201 while (error == ERR_NONE) { 4201 while (error == ERR_NONE) {
4202 if (used < GSM_BACKUP_MAX_NOTE) { 4202 if (used < GSM_BACKUP_MAX_NOTE) {
4203 Backup.Note[used] = malloc(sizeof(GSM_NoteEntry)); 4203 Backup.Note[used] = malloc(sizeof(GSM_NoteEntry));
4204 if (Backup.Note[used] == NULL) Print_Error(ERR_MOREMEMORY); 4204 if (Backup.Note[used] == NULL) Print_Error(ERR_MOREMEMORY);
4205 Backup.Note[used+1] = NULL; 4205 Backup.Note[used+1] = NULL;
4206 } else { 4206 } else {
4207 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_NOTE"); 4207 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_NOTE");
4208 GSM_Terminate(); 4208 GSM_Terminate();
4209 exit(-1); 4209 exit(-1);
4210 } 4210 }
4211 *Backup.Note[used]=Note; 4211 *Backup.Note[used]=Note;
4212 used ++; 4212 used ++;
4213 error=Phone->GetNextNote(&s,&Note,false); 4213 error=Phone->GetNextNote(&s,&Note,false);
4214 printmsgerr("*"); 4214 printmsgerr("*");
4215 if (gshutdown) { 4215 if (gshutdown) {
4216 GSM_Terminate(); 4216 GSM_Terminate();
4217 exit(0); 4217 exit(0);
4218 } 4218 }
4219 } 4219 }
4220 printmsgerr("\n"); 4220 printmsgerr("\n");
4221 } 4221 }
4222 DoBackup = false; 4222 DoBackup = false;
4223 if (Info.CallerLogos) { 4223 if (Info.CallerLogos) {
4224 printmsg("Checking caller logos\n"); 4224 printmsg("Checking caller logos\n");
4225 Bitmap.Type = GSM_CallerGroupLogo; 4225 Bitmap.Type = GSM_CallerGroupLogo;
4226 Bitmap.Location = 1; 4226 Bitmap.Location = 1;
4227 error=Phone->GetBitmap(&s,&Bitmap); 4227 error=Phone->GetBitmap(&s,&Bitmap);
4228 if (error == ERR_NONE) { 4228 if (error == ERR_NONE) {
4229 if (answer_yes(" Backup caller groups and logos")) DoBackup = true; 4229 if (answer_yes(" Backup caller groups and logos")) DoBackup = true;
4230 } 4230 }
4231 } 4231 }
4232 if (DoBackup) { 4232 if (DoBackup) {
4233 printmsgerr(" Reading : "); 4233 printmsgerr(" Reading : ");
4234 error = ERR_NONE; 4234 error = ERR_NONE;
4235 used = 0; 4235 used = 0;
4236 while (error == ERR_NONE) { 4236 while (error == ERR_NONE) {
4237 if (used < GSM_BACKUP_MAX_CALLER) { 4237 if (used < GSM_BACKUP_MAX_CALLER) {
4238 Backup.CallerLogos[used] = malloc(sizeof(GSM_Bitmap)); 4238 Backup.CallerLogos[used] = malloc(sizeof(GSM_Bitmap));
4239 if (Backup.CallerLogos[used] == NULL) Print_Error(ERR_MOREMEMORY); 4239 if (Backup.CallerLogos[used] == NULL) Print_Error(ERR_MOREMEMORY);
4240 Backup.CallerLogos[used+1] = NULL; 4240 Backup.CallerLogos[used+1] = NULL;
4241 } else { 4241 } else {
4242 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CALLER"); 4242 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CALLER");
4243 GSM_Terminate(); 4243 GSM_Terminate();
4244 exit(-1); 4244 exit(-1);
4245 } 4245 }
4246 *Backup.CallerLogos[used] = Bitmap; 4246 *Backup.CallerLogos[used] = Bitmap;
4247 used ++; 4247 used ++;
4248 Bitmap.Location = used + 1; 4248 Bitmap.Location = used + 1;
4249 error=Phone->GetBitmap(&s,&Bitmap); 4249 error=Phone->GetBitmap(&s,&Bitmap);
4250 printmsgerr("*"); 4250 printmsgerr("*");
4251 if (gshutdown) { 4251 if (gshutdown) {
4252 GSM_Terminate(); 4252 GSM_Terminate();
4253 exit(0); 4253 exit(0);
4254 } 4254 }
4255 } 4255 }
4256 printmsgerr("\n"); 4256 printmsgerr("\n");
4257 } 4257 }
4258 DoBackup = false; 4258 DoBackup = false;
4259 if (Info.SMSC) { 4259 if (Info.SMSC) {
4260 printmsg("Checking SMS profiles\n"); 4260 printmsg("Checking SMS profiles\n");
4261 if (answer_yes(" Backup SMS profiles")) DoBackup = true; 4261 if (answer_yes(" Backup SMS profiles")) DoBackup = true;
4262 } 4262 }
4263 if (DoBackup) { 4263 if (DoBackup) {
4264 used = 0; 4264 used = 0;
4265 printmsgerr(" Reading: "); 4265 printmsgerr(" Reading: ");
4266 while (true) { 4266 while (true) {
4267 SMSC.Location = used + 1; 4267 SMSC.Location = used + 1;
4268 error = Phone->GetSMSC(&s,&SMSC); 4268 error = Phone->GetSMSC(&s,&SMSC);
4269 if (error != ERR_NONE) break; 4269 if (error != ERR_NONE) break;
4270 if (used < GSM_BACKUP_MAX_SMSC) { 4270 if (used < GSM_BACKUP_MAX_SMSC) {
4271 Backup.SMSC[used] = malloc(sizeof(GSM_SMSC)); 4271 Backup.SMSC[used] = malloc(sizeof(GSM_SMSC));
4272 if (Backup.SMSC[used] == NULL) Print_Error(ERR_MOREMEMORY); 4272 if (Backup.SMSC[used] == NULL) Print_Error(ERR_MOREMEMORY);
4273 Backup.SMSC[used + 1] = NULL; 4273 Backup.SMSC[used + 1] = NULL;
4274 } else { 4274 } else {
4275 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SMSC"); 4275 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SMSC");
4276 GSM_Terminate(); 4276 GSM_Terminate();
4277 exit(-1); 4277 exit(-1);
4278 } 4278 }
4279 *Backup.SMSC[used]=SMSC; 4279 *Backup.SMSC[used]=SMSC;
4280 used++; 4280 used++;
4281 printmsgerr("*"); 4281 printmsgerr("*");
4282 } 4282 }
4283 printmsgerr("\n"); 4283 printmsgerr("\n");
4284 } 4284 }
4285 DoBackup = false; 4285 DoBackup = false;
4286 if (Info.StartupLogo) { 4286 if (Info.StartupLogo) {
4287 printmsg("Checking startup text\n"); 4287 printmsg("Checking startup text\n");
4288 Bitmap.Type = GSM_WelcomeNote_Text; 4288 Bitmap.Type = GSM_WelcomeNote_Text;
4289 error = Phone->GetBitmap(&s,&Bitmap); 4289 error = Phone->GetBitmap(&s,&Bitmap);
4290 if (error == ERR_NONE) { 4290 if (error == ERR_NONE) {
4291 if (answer_yes(" Backup startup logo/text")) DoBackup = true; 4291 if (answer_yes(" Backup startup logo/text")) DoBackup = true;
4292 } 4292 }
4293 } 4293 }
4294 if (DoBackup) { 4294 if (DoBackup) {
4295 Backup.StartupLogo = malloc(sizeof(GSM_Bitmap)); 4295 Backup.StartupLogo = malloc(sizeof(GSM_Bitmap));
4296 if (Backup.StartupLogo == NULL) Print_Error(ERR_MOREMEMORY); 4296 if (Backup.StartupLogo == NULL) Print_Error(ERR_MOREMEMORY);
4297 *Backup.StartupLogo = Bitmap; 4297 *Backup.StartupLogo = Bitmap;
4298 if (Bitmap.Text[0]==0 && Bitmap.Text[1]==0) { 4298 if (Bitmap.Text[0]==0 && Bitmap.Text[1]==0) {
4299 Bitmap.Type = GSM_StartupLogo; 4299 Bitmap.Type = GSM_StartupLogo;
4300 error = Phone->GetBitmap(&s,&Bitmap); 4300 error = Phone->GetBitmap(&s,&Bitmap);
4301 if (error == ERR_NONE) *Backup.StartupLogo = Bitmap; 4301 if (error == ERR_NONE) *Backup.StartupLogo = Bitmap;
4302 } 4302 }
4303 } 4303 }
4304 DoBackup = false; 4304 DoBackup = false;
4305 if (Info.OperatorLogo) { 4305 if (Info.OperatorLogo) {
4306 printmsg("Checking operator logo\n"); 4306 printmsg("Checking operator logo\n");
4307 Bitmap.Type = GSM_OperatorLogo; 4307 Bitmap.Type = GSM_OperatorLogo;
4308 error=Phone->GetBitmap(&s,&Bitmap); 4308 error=Phone->GetBitmap(&s,&Bitmap);
4309 if (error == ERR_NONE) { 4309 if (error == ERR_NONE) {
4310 if (strcmp(Bitmap.NetworkCode,"000 00")!=0) { 4310 if (strcmp(Bitmap.NetworkCode,"000 00")!=0) {
4311 if (answer_yes(" Backup operator logo")) DoBackup = true; 4311 if (answer_yes(" Backup operator logo")) DoBackup = true;
4312 } 4312 }
4313 } 4313 }
4314 } 4314 }
4315 if (DoBackup) { 4315 if (DoBackup) {
4316 Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap)); 4316 Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap));
4317 if (Backup.OperatorLogo == NULL) Print_Error(ERR_MOREMEMORY); 4317 if (Backup.OperatorLogo == NULL) Print_Error(ERR_MOREMEMORY);
4318 *Backup.OperatorLogo = Bitmap; 4318 *Backup.OperatorLogo = Bitmap;
4319 } 4319 }
4320 DoBackup = false; 4320 DoBackup = false;
4321 if (Info.WAPBookmark) { 4321 if (Info.WAPBookmark) {
4322 printmsg("Checking WAP bookmarks\n"); 4322 printmsg("Checking WAP bookmarks\n");
4323 Bookmark.Location = 1; 4323 Bookmark.Location = 1;
4324 error=Phone->GetWAPBookmark(&s,&Bookmark); 4324 error=Phone->GetWAPBookmark(&s,&Bookmark);
4325 if (error==ERR_NONE) { 4325 if (error==ERR_NONE) {
4326 if (answer_yes(" Backup WAP bookmarks")) DoBackup = true; 4326 if (answer_yes(" Backup WAP bookmarks")) DoBackup = true;
4327 } 4327 }
4328 } 4328 }
4329 if (DoBackup) { 4329 if (DoBackup) {
4330 used = 0; 4330 used = 0;
4331 printmsgerr(" Reading : "); 4331 printmsgerr(" Reading : ");
4332 while (error == ERR_NONE) { 4332 while (error == ERR_NONE) {
4333 if (used < GSM_BACKUP_MAX_WAPBOOKMARK) { 4333 if (used < GSM_BACKUP_MAX_WAPBOOKMARK) {
4334 Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark)); 4334 Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark));
4335 if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY); 4335 if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY);
4336 Backup.WAPBookmark[used+1] = NULL; 4336 Backup.WAPBookmark[used+1] = NULL;
4337 } else { 4337 } else {
4338 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK"); 4338 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK");
4339 GSM_Terminate(); 4339 GSM_Terminate();
4340 exit(-1); 4340 exit(-1);
4341 } 4341 }
4342 *Backup.WAPBookmark[used]=Bookmark; 4342 *Backup.WAPBookmark[used]=Bookmark;
4343 used ++; 4343 used ++;
4344 Bookmark.Location = used+1; 4344 Bookmark.Location = used+1;
4345 error=Phone->GetWAPBookmark(&s,&Bookmark); 4345 error=Phone->GetWAPBookmark(&s,&Bookmark);
4346 printmsgerr("*"); 4346 printmsgerr("*");
4347 if (gshutdown) { 4347 if (gshutdown) {
4348 GSM_Terminate(); 4348 GSM_Terminate();
4349 exit(0); 4349 exit(0);
4350 } 4350 }
4351 } 4351 }
4352 printmsgerr("\n"); 4352 printmsgerr("\n");
4353 } 4353 }
4354 DoBackup = false; 4354 DoBackup = false;
4355 if (Info.WAPSettings) { 4355 if (Info.WAPSettings) {
4356 printmsg("Checking WAP settings\n"); 4356 printmsg("Checking WAP settings\n");
4357 Settings.Location = 1; 4357 Settings.Location = 1;
4358 error=Phone->GetWAPSettings(&s,&Settings); 4358 error=Phone->GetWAPSettings(&s,&Settings);
4359 if (error==ERR_NONE) { 4359 if (error==ERR_NONE) {
4360 if (answer_yes(" Backup WAP settings")) DoBackup = true; 4360 if (answer_yes(" Backup WAP settings")) DoBackup = true;
4361 } 4361 }
4362 } 4362 }
4363 if (DoBackup) { 4363 if (DoBackup) {
4364 used = 0; 4364 used = 0;
4365 printmsgerr(" Reading : "); 4365 printmsgerr(" Reading : ");
4366 while (error == ERR_NONE) { 4366 while (error == ERR_NONE) {
4367 if (used < GSM_BACKUP_MAX_WAPSETTINGS) { 4367 if (used < GSM_BACKUP_MAX_WAPSETTINGS) {
4368 Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); 4368 Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
4369 if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); 4369 if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4370 Backup.WAPSettings[used+1] = NULL; 4370 Backup.WAPSettings[used+1] = NULL;
4371 } else { 4371 } else {
4372 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS"); 4372 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS");
4373 GSM_Terminate(); 4373 GSM_Terminate();
4374 exit(-1); 4374 exit(-1);
4375 } 4375 }
4376 *Backup.WAPSettings[used]=Settings; 4376 *Backup.WAPSettings[used]=Settings;
4377 used ++; 4377 used ++;
4378 Settings.Location = used+1; 4378 Settings.Location = used+1;
4379 error=Phone->GetWAPSettings(&s,&Settings); 4379 error=Phone->GetWAPSettings(&s,&Settings);
4380 printmsgerr("*"); 4380 printmsgerr("*");
4381 if (gshutdown) { 4381 if (gshutdown) {
4382 GSM_Terminate(); 4382 GSM_Terminate();
4383 exit(0); 4383 exit(0);
4384 } 4384 }
4385 } 4385 }
4386 printmsgerr("\n"); 4386 printmsgerr("\n");
4387 } 4387 }
4388 DoBackup = false; 4388 DoBackup = false;
4389 if (Info.MMSSettings) { 4389 if (Info.MMSSettings) {
4390 printmsg("Checking MMS settings\n"); 4390 printmsg("Checking MMS settings\n");
4391 Settings.Location = 1; 4391 Settings.Location = 1;
4392 error=Phone->GetMMSSettings(&s,&Settings); 4392 error=Phone->GetMMSSettings(&s,&Settings);
4393 if (error==ERR_NONE) { 4393 if (error==ERR_NONE) {
4394 if (answer_yes(" Backup MMS settings")) DoBackup = true; 4394 if (answer_yes(" Backup MMS settings")) DoBackup = true;
4395 } 4395 }
4396 } 4396 }
4397 if (DoBackup) { 4397 if (DoBackup) {
4398 used = 0; 4398 used = 0;
4399 printmsgerr(" Reading : "); 4399 printmsgerr(" Reading : ");
4400 while (error == ERR_NONE) { 4400 while (error == ERR_NONE) {
4401 if (used < GSM_BACKUP_MAX_MMSSETTINGS) { 4401 if (used < GSM_BACKUP_MAX_MMSSETTINGS) {
4402 Backup.MMSSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); 4402 Backup.MMSSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
4403 if (Backup.MMSSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); 4403 if (Backup.MMSSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4404 Backup.MMSSettings[used+1] = NULL; 4404 Backup.MMSSettings[used+1] = NULL;
4405 } else { 4405 } else {
4406 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_MMSSETTINGS"); 4406 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_MMSSETTINGS");
4407 GSM_Terminate(); 4407 GSM_Terminate();
4408 exit(-1); 4408 exit(-1);
4409 } 4409 }
4410 *Backup.MMSSettings[used]=Settings; 4410 *Backup.MMSSettings[used]=Settings;
4411 used ++; 4411 used ++;
4412 Settings.Location = used+1; 4412 Settings.Location = used+1;
4413 error=Phone->GetMMSSettings(&s,&Settings); 4413 error=Phone->GetMMSSettings(&s,&Settings);
4414 printmsgerr("*"); 4414 printmsgerr("*");
4415 if (gshutdown) { 4415 if (gshutdown) {
4416 GSM_Terminate(); 4416 GSM_Terminate();
4417 exit(0); 4417 exit(0);
4418 } 4418 }
4419 } 4419 }
4420 printmsgerr("\n"); 4420 printmsgerr("\n");
4421 } 4421 }
4422 DoBackup = false; 4422 DoBackup = false;
4423 if (Info.ChatSettings) { 4423 if (Info.ChatSettings) {
4424 printmsg("Checking Chat settings\n"); 4424 printmsg("Checking Chat settings\n");
4425 Chat.Location = 1; 4425 Chat.Location = 1;
4426 error=Phone->GetChatSettings(&s,&Chat); 4426 error=Phone->GetChatSettings(&s,&Chat);
4427 if (error==ERR_NONE) { 4427 if (error==ERR_NONE) {
4428 if (answer_yes(" Backup Chat settings")) DoBackup = true; 4428 if (answer_yes(" Backup Chat settings")) DoBackup = true;
4429 } 4429 }
4430 } 4430 }
4431 if (DoBackup) { 4431 if (DoBackup) {
4432 used = 0; 4432 used = 0;
4433 printmsgerr(" Reading : "); 4433 printmsgerr(" Reading : ");
4434 while (error == ERR_NONE) { 4434 while (error == ERR_NONE) {
4435 if (used < GSM_BACKUP_MAX_CHATSETTINGS) { 4435 if (used < GSM_BACKUP_MAX_CHATSETTINGS) {
4436 Backup.ChatSettings[used] = malloc(sizeof(GSM_ChatSettings)); 4436 Backup.ChatSettings[used] = malloc(sizeof(GSM_ChatSettings));
4437 if (Backup.ChatSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); 4437 if (Backup.ChatSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4438 Backup.ChatSettings[used+1] = NULL; 4438 Backup.ChatSettings[used+1] = NULL;
4439 } else { 4439 } else {
4440 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CHATSETTINGS"); 4440 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CHATSETTINGS");
4441 GSM_Terminate(); 4441 GSM_Terminate();
4442 exit(-1); 4442 exit(-1);
4443 } 4443 }
4444 *Backup.ChatSettings[used]=Chat; 4444 *Backup.ChatSettings[used]=Chat;
4445 used ++; 4445 used ++;
4446 Chat.Location = used+1; 4446 Chat.Location = used+1;
4447 error=Phone->GetChatSettings(&s,&Chat); 4447 error=Phone->GetChatSettings(&s,&Chat);
4448 printmsgerr("*"); 4448 printmsgerr("*");
4449 if (gshutdown) { 4449 if (gshutdown) {
4450 GSM_Terminate(); 4450 GSM_Terminate();
4451 exit(0); 4451 exit(0);
4452 } 4452 }
4453 } 4453 }
4454 printmsgerr("\n"); 4454 printmsgerr("\n");
4455 } 4455 }
4456 DoBackup = false; 4456 DoBackup = false;
4457 if (Info.SyncMLSettings) { 4457 if (Info.SyncMLSettings) {
4458 printmsg("Checking SyncML settings\n"); 4458 printmsg("Checking SyncML settings\n");
4459 SyncML.Location = 1; 4459 SyncML.Location = 1;
4460 error=Phone->GetSyncMLSettings(&s,&SyncML); 4460 error=Phone->GetSyncMLSettings(&s,&SyncML);
4461 if (error==ERR_NONE) { 4461 if (error==ERR_NONE) {
4462 if (answer_yes(" Backup SyncML settings")) DoBackup = true; 4462 if (answer_yes(" Backup SyncML settings")) DoBackup = true;
4463 } 4463 }
4464 } 4464 }
4465 if (DoBackup) { 4465 if (DoBackup) {
4466 used = 0; 4466 used = 0;
4467 printmsgerr(" Reading : "); 4467 printmsgerr(" Reading : ");
4468 while (error == ERR_NONE) { 4468 while (error == ERR_NONE) {
4469 if (used < GSM_BACKUP_MAX_SYNCMLSETTINGS) { 4469 if (used < GSM_BACKUP_MAX_SYNCMLSETTINGS) {
4470 Backup.SyncMLSettings[used] = malloc(sizeof(GSM_SyncMLSettings)); 4470 Backup.SyncMLSettings[used] = malloc(sizeof(GSM_SyncMLSettings));
4471 if (Backup.SyncMLSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); 4471 if (Backup.SyncMLSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4472 Backup.SyncMLSettings[used+1] = NULL; 4472 Backup.SyncMLSettings[used+1] = NULL;
4473 } else { 4473 } else {
4474 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SYNCMLSETTINGS"); 4474 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SYNCMLSETTINGS");
4475 GSM_Terminate(); 4475 GSM_Terminate();
4476 exit(-1); 4476 exit(-1);
4477 } 4477 }
4478 *Backup.SyncMLSettings[used]=SyncML; 4478 *Backup.SyncMLSettings[used]=SyncML;
4479 used ++; 4479 used ++;
4480 SyncML.Location = used+1; 4480 SyncML.Location = used+1;
4481 error=Phone->GetSyncMLSettings(&s,&SyncML); 4481 error=Phone->GetSyncMLSettings(&s,&SyncML);
4482 printmsgerr("*"); 4482 printmsgerr("*");
4483 if (gshutdown) { 4483 if (gshutdown) {
4484 GSM_Terminate(); 4484 GSM_Terminate();
4485 exit(0); 4485 exit(0);
4486 } 4486 }
4487 } 4487 }
4488 printmsgerr("\n"); 4488 printmsgerr("\n");
4489 } 4489 }
4490 DoBackup = false; 4490 DoBackup = false;
4491 if (Info.Ringtone) { 4491 if (Info.Ringtone) {
4492 printmsg("Checking user ringtones\n"); 4492 printmsg("Checking user ringtones\n");
4493 Ringtone.Location = 1; 4493 Ringtone.Location = 1;
4494 Ringtone.Format = 0; 4494 Ringtone.Format = 0;
4495 error=Phone->GetRingtone(&s,&Ringtone,false); 4495 error=Phone->GetRingtone(&s,&Ringtone,false);
4496 if (error==ERR_EMPTY || error == ERR_NONE) { 4496 if (error==ERR_EMPTY || error == ERR_NONE) {
4497 if (answer_yes(" Backup user ringtones")) DoBackup = true; 4497 if (answer_yes(" Backup user ringtones")) DoBackup = true;
4498 } 4498 }
4499 } 4499 }
4500 if (DoBackup) { 4500 if (DoBackup) {
4501 used = 0; 4501 used = 0;
4502 i= 1; 4502 i= 1;
4503 printmsgerr(" Reading : "); 4503 printmsgerr(" Reading : ");
4504 while (error == ERR_NONE || error == ERR_EMPTY) { 4504 while (error == ERR_NONE || error == ERR_EMPTY) {
4505 if (error == ERR_NONE) { 4505 if (error == ERR_NONE) {
4506 if (used < GSM_BACKUP_MAX_RINGTONES) { 4506 if (used < GSM_BACKUP_MAX_RINGTONES) {
4507 Backup.Ringtone[used] = malloc(sizeof(GSM_Ringtone)); 4507 Backup.Ringtone[used] = malloc(sizeof(GSM_Ringtone));
4508 if (Backup.Ringtone[used] == NULL) Print_Error(ERR_MOREMEMORY); 4508 if (Backup.Ringtone[used] == NULL) Print_Error(ERR_MOREMEMORY);
4509 Backup.Ringtone[used+1] = NULL; 4509 Backup.Ringtone[used+1] = NULL;
4510 } else { 4510 } else {
4511 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_RINGTONES"); 4511 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_RINGTONES");
4512 GSM_Terminate(); 4512 GSM_Terminate();
4513 exit(-1); 4513 exit(-1);
4514 } 4514 }
4515 *Backup.Ringtone[used]=Ringtone; 4515 *Backup.Ringtone[used]=Ringtone;
4516 used ++; 4516 used ++;
4517 } 4517 }
4518 i++; 4518 i++;
4519 Ringtone.Location = i; 4519 Ringtone.Location = i;
4520 Ringtone.Format = 0; 4520 Ringtone.Format = 0;
4521 error=Phone->GetRingtone(&s,&Ringtone,false); 4521 error=Phone->GetRingtone(&s,&Ringtone,false);
4522 printmsgerr("*"); 4522 printmsgerr("*");
4523 if (gshutdown) { 4523 if (gshutdown) {
4524 GSM_Terminate(); 4524 GSM_Terminate();
4525 exit(0); 4525 exit(0);
4526 } 4526 }
4527 } 4527 }
4528 printmsgerr("\n"); 4528 printmsgerr("\n");
4529 } 4529 }
4530 DoBackup = false; 4530 DoBackup = false;
4531 if (Info.Profiles) { 4531 if (Info.Profiles) {
4532 printmsg("Checking phone profiles\n"); 4532 printmsg("Checking phone profiles\n");
4533 Profile.Location = 1; 4533 Profile.Location = 1;
4534 error = Phone->GetProfile(&s,&Profile); 4534 error = Phone->GetProfile(&s,&Profile);
4535 if (error == ERR_NONE) { 4535 if (error == ERR_NONE) {
4536 if (answer_yes(" Backup phone profiles")) DoBackup = true; 4536 if (answer_yes(" Backup phone profiles")) DoBackup = true;
4537 } 4537 }
4538 } 4538 }
4539 if (DoBackup) { 4539 if (DoBackup) {
4540 used = 0; 4540 used = 0;
4541 printmsgerr(" Reading: "); 4541 printmsgerr(" Reading: ");
4542 while (true) { 4542 while (true) {
4543 Profile.Location = used + 1; 4543 Profile.Location = used + 1;
4544 error = Phone->GetProfile(&s,&Profile); 4544 error = Phone->GetProfile(&s,&Profile);
4545 if (error != ERR_NONE) break; 4545 if (error != ERR_NONE) break;
4546 if (used < GSM_BACKUP_MAX_PROFILES) { 4546 if (used < GSM_BACKUP_MAX_PROFILES) {
4547 Backup.Profiles[used] = malloc(sizeof(GSM_Profile)); 4547 Backup.Profiles[used] = malloc(sizeof(GSM_Profile));
4548 if (Backup.Profiles[used] == NULL) Print_Error(ERR_MOREMEMORY); 4548 if (Backup.Profiles[used] == NULL) Print_Error(ERR_MOREMEMORY);
4549 Backup.Profiles[used + 1] = NULL; 4549 Backup.Profiles[used + 1] = NULL;
4550 } else { 4550 } else {
4551 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PROFILES"); 4551 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PROFILES");
4552 GSM_Terminate(); 4552 GSM_Terminate();
4553 exit(-1); 4553 exit(-1);
4554 } 4554 }
4555 *Backup.Profiles[used]=Profile; 4555 *Backup.Profiles[used]=Profile;
4556 used++; 4556 used++;
4557 printmsgerr("*"); 4557 printmsgerr("*");
4558 } 4558 }
4559 printmsgerr("\n"); 4559 printmsgerr("\n");
4560 } 4560 }
4561 DoBackup = false; 4561 DoBackup = false;
4562 if (Info.FMStation) { 4562 if (Info.FMStation) {
4563 printmsg("Checking FM stations\n"); 4563 printmsg("Checking FM stations\n");
4564 FMStation.Location = 1; 4564 FMStation.Location = 1;
4565 error = Phone->GetFMStation(&s,&FMStation); 4565 error = Phone->GetFMStation(&s,&FMStation);
4566 if (error == ERR_NONE || error == ERR_EMPTY) { 4566 if (error == ERR_NONE || error == ERR_EMPTY) {
4567 if (answer_yes(" Backup phone FM stations")) DoBackup=true; 4567 if (answer_yes(" Backup phone FM stations")) DoBackup=true;
4568 } 4568 }
4569 } 4569 }
4570 if (DoBackup) { 4570 if (DoBackup) {
4571 used= 0; 4571 used= 0;
4572 i = 1; 4572 i = 1;
4573 printmsgerr(" Reading: "); 4573 printmsgerr(" Reading: ");
4574 while (error == ERR_NONE || error == ERR_EMPTY) { 4574 while (error == ERR_NONE || error == ERR_EMPTY) {
4575 error = Phone->GetFMStation(&s,&FMStation); 4575 error = Phone->GetFMStation(&s,&FMStation);
4576 if (error == ERR_NONE) { 4576 if (error == ERR_NONE) {
4577 if (used < GSM_BACKUP_MAX_FMSTATIONS) { 4577 if (used < GSM_BACKUP_MAX_FMSTATIONS) {
4578 Backup.FMStation[used] = malloc(sizeof(GSM_FMStation)); 4578 Backup.FMStation[used] = malloc(sizeof(GSM_FMStation));
4579 if (Backup.FMStation[used] == NULL) Print_Error(ERR_MOREMEMORY); 4579 if (Backup.FMStation[used] == NULL) Print_Error(ERR_MOREMEMORY);
4580 Backup.FMStation[used + 1] = NULL; 4580 Backup.FMStation[used + 1] = NULL;
4581 } else { 4581 } else {
4582 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_FMSTATIONS"); 4582 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_FMSTATIONS");
4583 GSM_Terminate(); 4583 GSM_Terminate();
4584 exit(-1); 4584 exit(-1);
4585 } 4585 }
4586 *Backup.FMStation[used]=FMStation; 4586 *Backup.FMStation[used]=FMStation;
4587 used++; 4587 used++;
4588 } 4588 }
4589 i++; 4589 i++;
4590 FMStation.Location = i; 4590 FMStation.Location = i;
4591 printmsgerr("*"); 4591 printmsgerr("*");
4592 } 4592 }
4593 printmsgerr("\n"); 4593 printmsgerr("\n");
4594 } 4594 }
4595 DoBackup = false; 4595 DoBackup = false;
4596 if (Info.GPRSPoint) { 4596 if (Info.GPRSPoint) {
4597 printmsg("Checking GPRS access points\n"); 4597 printmsg("Checking GPRS access points\n");
4598 GPRSPoint.Location = 1; 4598 GPRSPoint.Location = 1;
4599 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint); 4599 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
4600 if (error == ERR_NONE || error == ERR_EMPTY) { 4600 if (error == ERR_NONE || error == ERR_EMPTY) {
4601 if (answer_yes(" Backup GPRS access points")) DoBackup = true; 4601 if (answer_yes(" Backup GPRS access points")) DoBackup = true;
4602 } 4602 }
4603 } 4603 }
4604 if (DoBackup) { 4604 if (DoBackup) {
4605 used= 0; 4605 used= 0;
4606 i = 1; 4606 i = 1;
4607 printmsgerr(" Reading: "); 4607 printmsgerr(" Reading: ");
4608 while (error == ERR_NONE || error == ERR_EMPTY) { 4608 while (error == ERR_NONE || error == ERR_EMPTY) {
4609 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint); 4609 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
4610 if (error == ERR_NONE) { 4610 if (error == ERR_NONE) {
4611 if (used < GSM_BACKUP_MAX_GPRSPOINT) { 4611 if (used < GSM_BACKUP_MAX_GPRSPOINT) {
4612 Backup.GPRSPoint[used] = malloc(sizeof(GSM_GPRSAccessPoint)); 4612 Backup.GPRSPoint[used] = malloc(sizeof(GSM_GPRSAccessPoint));
4613 if (Backup.GPRSPoint[used] == NULL) Print_Error(ERR_MOREMEMORY); 4613 if (Backup.GPRSPoint[used] == NULL) Print_Error(ERR_MOREMEMORY);
4614 Backup.GPRSPoint[used + 1] = NULL; 4614 Backup.GPRSPoint[used + 1] = NULL;
4615 } else { 4615 } else {
4616 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_GPRSPOINT"); 4616 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_GPRSPOINT");
4617 GSM_Terminate(); 4617 GSM_Terminate();
4618 exit(-1); 4618 exit(-1);
4619 } 4619 }
4620 *Backup.GPRSPoint[used]=GPRSPoint; 4620 *Backup.GPRSPoint[used]=GPRSPoint;
4621 used++; 4621 used++;
4622 } 4622 }
4623 i++; 4623 i++;
4624 GPRSPoint.Location = i; 4624 GPRSPoint.Location = i;
4625 printmsgerr("*"); 4625 printmsgerr("*");
4626 } 4626 }
4627 printmsgerr("\n"); 4627 printmsgerr("\n");
4628 } 4628 }
4629 4629
4630 GSM_Terminate(); 4630 GSM_Terminate();
4631 4631
4632 GSM_SaveBackupFile(argv[2],&Backup, Info.UseUnicode); 4632 GSM_SaveBackupFile(argv[2],&Backup, Info.UseUnicode);
4633 GSM_FreeBackup(&Backup); 4633 GSM_FreeBackup(&Backup);
4634} 4634}
4635 4635
4636static void Restore(int argc, char *argv[]) 4636static void Restore(int argc, char *argv[])
4637{ 4637{
4638 GSM_Backup Backup; 4638 GSM_Backup Backup;
4639 GSM_FMStation FMStation; 4639 GSM_FMStation FMStation;
4640 GSM_DateTime date_time; 4640 GSM_DateTime date_time;
4641 GSM_CalendarEntryCalendar; 4641 GSM_CalendarEntryCalendar;
4642 GSM_Bitmap Bitmap; 4642 GSM_Bitmap Bitmap;
4643 GSM_Ringtone Ringtone; 4643 GSM_Ringtone Ringtone;
4644 GSM_MemoryEntry Pbk; 4644 GSM_MemoryEntry Pbk;
4645 GSM_MemoryStatusMemStatus; 4645 GSM_MemoryStatusMemStatus;
4646 GSM_ToDoEntry ToDo; 4646 GSM_ToDoEntry ToDo;
4647 GSM_ToDoStatus ToDoStatus; 4647 GSM_ToDoStatus ToDoStatus;
4648 GSM_Profile Profile; 4648 GSM_Profile Profile;
4649 GSM_MultiWAPSettingsSettings; 4649 GSM_MultiWAPSettingsSettings;
4650 GSM_GPRSAccessPointGPRSPoint; 4650 GSM_GPRSAccessPointGPRSPoint;
4651 GSM_WAPBookmark Bookmark; 4651 GSM_WAPBookmark Bookmark;
4652 int i, used, max = 0; 4652 int i, used, max = 0;
4653 bool Past = true; 4653 bool Past = true;
4654 bool Found, DoRestore; 4654 bool Found, DoRestore;
4655 4655
4656 error=GSM_ReadBackupFile(argv[2],&Backup); 4656 error=GSM_ReadBackupFile(argv[2],&Backup);
4657 if (error!=ERR_NOTIMPLEMENTED) { 4657 if (error!=ERR_NOTIMPLEMENTED) {
4658 Print_Error(error); 4658 Print_Error(error);
4659 } else { 4659 } else {
4660 printmsgerr("WARNING: Some data not read from file. It can be damaged or restoring some settings from this file format not implemented (maybe higher Gammu required ?)\n"); 4660 printmsgerr("WARNING: Some data not read from file. It can be damaged or restoring some settings from this file format not implemented (maybe higher Gammu required ?)\n");
4661 } 4661 }
4662 4662
4663 signal(SIGINT, interrupt); 4663 signal(SIGINT, interrupt);
4664 printmsgerr("Press Ctrl+C to break...\n"); 4664 printmsgerr("Press Ctrl+C to break...\n");
4665 4665
4666 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); 4666 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
4667 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); 4667 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
4668 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); 4668 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI);
4669 if (Backup.Creator[0]!=0) printmsgerr("File created by : %s\n",Backup.Creator); 4669 if (Backup.Creator[0]!=0) printmsgerr("File created by : %s\n",Backup.Creator);
4670 4670
4671 if (Backup.MD5Calculated[0]!=0) { 4671 if (Backup.MD5Calculated[0]!=0) {
4672 dbgprintf("\"%s\"\n",Backup.MD5Original); 4672 dbgprintf("\"%s\"\n",Backup.MD5Original);
4673 dbgprintf("\"%s\"\n",Backup.MD5Calculated); 4673 dbgprintf("\"%s\"\n",Backup.MD5Calculated);
4674 if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) { 4674 if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) {
4675 if (!answer_yes("Checksum in backup file do not match. Continue")) return; 4675 if (!answer_yes("Checksum in backup file do not match. Continue")) return;
4676 } 4676 }
4677 } 4677 }
4678 4678
4679 GSM_Init(true); 4679 GSM_Init(true);
4680 4680
4681 DoRestore = false; 4681 DoRestore = false;
4682 if (Backup.PhonePhonebook[0] != NULL) { 4682 if (Backup.PhonePhonebook[0] != NULL) {
4683 MemStatus.MemoryType = MEM_ME; 4683 MemStatus.MemoryType = MEM_ME;
4684 error=Phone->GetMemoryStatus(&s, &MemStatus); 4684 error=Phone->GetMemoryStatus(&s, &MemStatus);
4685 if (error==ERR_NONE) { 4685 if (error==ERR_NONE) {
4686 max = 0; 4686 max = 0;
4687 while (Backup.PhonePhonebook[max]!=NULL) max++; 4687 while (Backup.PhonePhonebook[max]!=NULL) max++;
4688 printmsgerr("%i entries in backup file\n",max); 4688 printmsgerr("%i entries in backup file\n",max);
4689 if (answer_yes("Restore phone phonebook")) DoRestore = true; 4689 /* LR if (answer_yes("Restore phone phonebook")) */DoRestore = true;
4690 } 4690 }
4691 } 4691 }
4692 if (DoRestore) { 4692 if (DoRestore) {
4693 used = 0; 4693 used = 0;
4694 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { 4694 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
4695 Pbk.MemoryType = MEM_ME; 4695 Pbk.MemoryType = MEM_ME;
4696 Pbk.Location= i + 1; 4696 Pbk.Location= i + 1;
4697 Pbk.EntriesNum= 0; 4697 Pbk.EntriesNum= 0;
4698 if (used<max) { 4698 if (used<max) {
4699 if (Backup.PhonePhonebook[used]->Location == Pbk.Location) { 4699 if (Backup.PhonePhonebook[used]->Location == Pbk.Location) {
4700 Pbk = *Backup.PhonePhonebook[used]; 4700 Pbk = *Backup.PhonePhonebook[used];
4701 used++; 4701 used++;
4702 dbgprintf("Location %i\n",Pbk.Location); 4702 dbgprintf("Location %i\n",Pbk.Location);
4703 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); 4703 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk);
4704 } 4704 }
4705 } 4705 }
4706 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); 4706 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk);
4707 Print_Error(error); 4707 Print_Error(error);
4708 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); 4708 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree));
4709 if (gshutdown) { 4709 if (gshutdown) {
4710 GSM_Terminate(); 4710 GSM_Terminate();
4711 exit(0); 4711 exit(0);
4712 } 4712 }
4713 } 4713 }
4714 printmsgerr("\n"); 4714 printmsgerr("\n");
4715 } 4715 }
4716 4716
4717 DoRestore = false; 4717 DoRestore = false;
4718 if (Backup.SIMPhonebook[0] != NULL) { 4718 if (Backup.SIMPhonebook[0] != NULL) {
4719 MemStatus.MemoryType = MEM_SM; 4719 MemStatus.MemoryType = MEM_SM;
4720 error=Phone->GetMemoryStatus(&s, &MemStatus); 4720 error=Phone->GetMemoryStatus(&s, &MemStatus);
4721 if (error==ERR_NONE) { 4721 if (error==ERR_NONE) {
4722 max = 0; 4722 max = 0;
4723 while (Backup.SIMPhonebook[max]!=NULL) max++; 4723 while (Backup.SIMPhonebook[max]!=NULL) max++;
4724 printmsgerr("%i entries in backup file\n",max); 4724 printmsgerr("%i entries in backup file\n",max);
4725 if (answer_yes("Restore SIM phonebook")) DoRestore = true; 4725 if (answer_yes("Restore SIM phonebook")) DoRestore = true;
4726 } 4726 }
4727 } 4727 }
4728 if (DoRestore) { 4728 if (DoRestore) {
4729 used = 0; 4729 used = 0;
4730 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { 4730 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
4731 Pbk.MemoryType = MEM_SM; 4731 Pbk.MemoryType = MEM_SM;
4732 Pbk.Location= i + 1; 4732 Pbk.Location= i + 1;
4733 Pbk.EntriesNum= 0; 4733 Pbk.EntriesNum= 0;
4734 if (used<max) { 4734 if (used<max) {
4735 if (Backup.SIMPhonebook[used]->Location == Pbk.Location) { 4735 if (Backup.SIMPhonebook[used]->Location == Pbk.Location) {
4736 Pbk = *Backup.SIMPhonebook[used]; 4736 Pbk = *Backup.SIMPhonebook[used];
4737 used++; 4737 used++;
4738 dbgprintf("Location %i\n",Pbk.Location); 4738 dbgprintf("Location %i\n",Pbk.Location);
4739 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); 4739 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk);
4740 } 4740 }
4741 } 4741 }
4742 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); 4742 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk);
4743 Print_Error(error); 4743 Print_Error(error);
4744 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); 4744 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree));
4745 if (gshutdown) { 4745 if (gshutdown) {
4746 GSM_Terminate(); 4746 GSM_Terminate();
4747 exit(0); 4747 exit(0);
4748 } 4748 }
4749 } 4749 }
4750 printmsgerr("\n"); 4750 printmsgerr("\n");
4751 } 4751 }
4752 4752
4753 DoRestore = false; 4753 DoRestore = false;
4754 if (Backup.CallerLogos[0] != NULL) { 4754 if (Backup.CallerLogos[0] != NULL) {
4755 Bitmap.Type = GSM_CallerGroupLogo; 4755 Bitmap.Type = GSM_CallerGroupLogo;
4756 Bitmap.Location = 1; 4756 Bitmap.Location = 1;
4757 error=Phone->GetBitmap(&s,&Bitmap); 4757 error=Phone->GetBitmap(&s,&Bitmap);
4758 if (error == ERR_NONE) { 4758 if (error == ERR_NONE) {
4759 if (answer_yes("Restore caller groups and logos")) DoRestore = true; 4759 if (answer_yes("Restore caller groups and logos")) DoRestore = true;
4760 } 4760 }
4761 } 4761 }
4762 if (DoRestore) { 4762 if (DoRestore) {
4763 max = 0; 4763 max = 0;
4764 while (Backup.CallerLogos[max]!=NULL) max++; 4764 while (Backup.CallerLogos[max]!=NULL) max++;
4765 for (i=0;i<max;i++) { 4765 for (i=0;i<max;i++) {
4766 error=Phone->SetBitmap(&s,Backup.CallerLogos[i]); 4766 error=Phone->SetBitmap(&s,Backup.CallerLogos[i]);
4767 Print_Error(error); 4767 Print_Error(error);
4768 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4768 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4769 if (gshutdown) { 4769 if (gshutdown) {
4770 GSM_Terminate(); 4770 GSM_Terminate();
4771 exit(0); 4771 exit(0);
4772 } 4772 }
4773 } 4773 }
4774 printmsgerr("\n"); 4774 printmsgerr("\n");
4775 } 4775 }
4776 4776
4777 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) { 4777 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) {
4778 if ( true /*LRanswer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")*/) { 4778 if ( true /*LRanswer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")*/) {
4779 GSM_GetCurrentDateTime(&date_time); 4779 GSM_GetCurrentDateTime(&date_time);
4780 4780
4781 error=Phone->SetDateTime(&s, &date_time); 4781 error=Phone->SetDateTime(&s, &date_time);
4782 Print_Error(error); 4782 Print_Error(error);
4783 } 4783 }
4784 } 4784 }
4785 DoRestore = false; 4785 DoRestore = false;
4786 if (Backup.Calendar[0] != NULL) { 4786 if (Backup.Calendar[0] != NULL) {
4787 /* N6110 doesn't support getting calendar status */ 4787 /* N6110 doesn't support getting calendar status */
4788 error = Phone->GetNextCalendar(&s,&Calendar,true); 4788 error = Phone->GetNextCalendar(&s,&Calendar,true);
4789 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { 4789 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) {
4790 max = 0; 4790 max = 0;
4791 while (Backup.Calendar[max] != NULL) max++; 4791 while (Backup.Calendar[max] != NULL) max++;
4792 printmsgerr("%i entries in backup file\n",max); 4792 printmsgerr("%i entries in backup file\n",max);
4793 // LR 4793 // LR
4794 //if (answer_yes("Restore calendar notes")) { 4794 //if (answer_yes("Restore calendar notes")) {
4795 //Past = answer_yes("Restore notes from the past"); 4795 //Past = answer_yes("Restore notes from the past");
4796 DoRestore = true; 4796 DoRestore = true;
4797 //} 4797 //}
4798 } 4798 }
4799 } 4799 }
4800 if (DoRestore) { 4800 if (DoRestore) {
4801 printmsgerr("Deleting old notes: "); 4801 printmsgerr("Deleting old notes: ");
4802 error = Phone->DeleteAllCalendar(&s); 4802 error = Phone->DeleteAllCalendar(&s);
4803 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 4803 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
4804 while (1) { 4804 while (1) {
4805 error = Phone->GetNextCalendar(&s,&Calendar,true); 4805 error = Phone->GetNextCalendar(&s,&Calendar,true);
4806 if (error != ERR_NONE) break; 4806 if (error != ERR_NONE) break;
4807 error = Phone->DeleteCalendar(&s,&Calendar); 4807 error = Phone->DeleteCalendar(&s,&Calendar);
4808 Print_Error(error); 4808 Print_Error(error);
4809 printmsgerr("*"); 4809 printmsgerr("*");
4810 } 4810 }
4811 printmsgerr("\n"); 4811 printmsgerr("\n");
4812 } else { 4812 } else {
4813 printmsgerr("Done\n"); 4813 printmsgerr("Done\n");
4814 Print_Error(error); 4814 Print_Error(error);
4815 } 4815 }
4816 4816
4817 for (i=0;i<max;i++) { 4817 for (i=0;i<max;i++) {
4818 if (!Past && IsCalendarNoteFromThePast(Backup.Calendar[i])) continue; 4818 if (!Past && IsCalendarNoteFromThePast(Backup.Calendar[i])) continue;
4819 4819
4820 Calendar = *Backup.Calendar[i]; 4820 Calendar = *Backup.Calendar[i];
4821 error=Phone->AddCalendar(&s,&Calendar); 4821 error=Phone->AddCalendar(&s,&Calendar);
4822 Print_Error(error); 4822 Print_Error(error);
4823 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4823 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4824 if (gshutdown) { 4824 if (gshutdown) {
4825 GSM_Terminate(); 4825 GSM_Terminate();
4826 exit(0); 4826 exit(0);
4827 } 4827 }
4828 } 4828 }
4829 printmsgerr("\n"); 4829 printmsgerr("\n");
4830 } 4830 }
4831 4831
4832 DoRestore = false; 4832 DoRestore = false;
4833 if (Backup.ToDo[0] != NULL) { 4833 if (Backup.ToDo[0] != NULL) {
4834 error = Phone->GetToDoStatus(&s,&ToDoStatus); 4834 error = Phone->GetToDoStatus(&s,&ToDoStatus);
4835 if (error == ERR_NONE) { 4835 if (error == ERR_NONE) {
4836 max = 0; 4836 max = 0;
4837 while (Backup.ToDo[max]!=NULL) max++; 4837 while (Backup.ToDo[max]!=NULL) max++;
4838 printmsgerr("%i entries in backup file\n",max); 4838 printmsgerr("%i entries in backup file\n",max);
4839 4839
4840 //LR if (answer_yes("Restore ToDo")) 4840 //LR if (answer_yes("Restore ToDo"))
4841 DoRestore = true; 4841 DoRestore = true;
4842 } 4842 }
4843 } 4843 }
4844 if (DoRestore) { 4844 if (DoRestore) {
4845 ToDo = *Backup.ToDo[0]; 4845 ToDo = *Backup.ToDo[0];
4846 error = Phone->SetToDo(&s,&ToDo); 4846 error = Phone->SetToDo(&s,&ToDo);
4847 } 4847 }
4848 if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) { 4848 if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) {
4849 printmsgerr("Deleting old ToDo: "); 4849 printmsgerr("Deleting old ToDo: ");
4850 error=Phone->DeleteAllToDo(&s); 4850 error=Phone->DeleteAllToDo(&s);
4851 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 4851 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
4852 while (1) { 4852 while (1) {
4853 error = Phone->GetNextToDo(&s,&ToDo,true); 4853 error = Phone->GetNextToDo(&s,&ToDo,true);
4854 if (error != ERR_NONE) break; 4854 if (error != ERR_NONE) break;
4855 error = Phone->DeleteToDo(&s,&ToDo); 4855 error = Phone->DeleteToDo(&s,&ToDo);
4856 Print_Error(error); 4856 Print_Error(error);
4857 printmsgerr("*"); 4857 printmsgerr("*");
4858 } 4858 }
4859 printmsgerr("\n"); 4859 printmsgerr("\n");
4860 } else { 4860 } else {
4861 printmsgerr("Done\n"); 4861 printmsgerr("Done\n");
4862 Print_Error(error); 4862 Print_Error(error);
4863 } 4863 }
4864 4864
4865 for (i=0;i<max;i++) { 4865 for (i=0;i<max;i++) {
4866 ToDo = *Backup.ToDo[i]; 4866 ToDo = *Backup.ToDo[i];
4867 ToDo.Location = 0; 4867 ToDo.Location = 0;
4868 error=Phone->AddToDo(&s,&ToDo); 4868 error=Phone->AddToDo(&s,&ToDo);
4869 Print_Error(error); 4869 Print_Error(error);
4870 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4870 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4871 if (gshutdown) { 4871 if (gshutdown) {
4872 GSM_Terminate(); 4872 GSM_Terminate();
4873 exit(0); 4873 exit(0);
4874 } 4874 }
4875 } 4875 }
4876 printmsgerr("\n"); 4876 printmsgerr("\n");
4877 } else if (DoRestore) { 4877 } else if (DoRestore) {
4878 /* At first delete entries, that were deleted */ 4878 /* At first delete entries, that were deleted */
4879 used = 0; 4879 used = 0;
4880 error = Phone->GetNextToDo(&s,&ToDo,true); 4880 error = Phone->GetNextToDo(&s,&ToDo,true);
4881 while (error == ERR_NONE) { 4881 while (error == ERR_NONE) {
4882 used++; 4882 used++;
4883 Found = false; 4883 Found = false;
4884 for (i=0;i<max;i++) { 4884 for (i=0;i<max;i++) {
4885 if (Backup.ToDo[i]->Location == ToDo.Location) { 4885 if (Backup.ToDo[i]->Location == ToDo.Location) {
4886 Found = true; 4886 Found = true;
4887 break; 4887 break;
4888 } 4888 }
4889 } 4889 }
4890 if (!Found) { 4890 if (!Found) {
4891 error=Phone->DeleteToDo(&s,&ToDo); 4891 error=Phone->DeleteToDo(&s,&ToDo);
4892 Print_Error(error); 4892 Print_Error(error);
4893 } 4893 }
4894 error = Phone->GetNextToDo(&s,&ToDo,false); 4894 error = Phone->GetNextToDo(&s,&ToDo,false);
4895 printmsgerr("%cCleaning: %i percent",13,used*100/ToDoStatus.Used); 4895 printmsgerr("%cCleaning: %i percent",13,used*100/ToDoStatus.Used);
4896 if (gshutdown) { 4896 if (gshutdown) {
4897 GSM_Terminate(); 4897 GSM_Terminate();
4898 exit(0); 4898 exit(0);
4899 } 4899 }
4900 } 4900 }
4901 printmsgerr("\n"); 4901 printmsgerr("\n");
4902 4902
4903 /* Now write modified/new entries */ 4903 /* Now write modified/new entries */
4904 for (i=0;i<max;i++) { 4904 for (i=0;i<max;i++) {
4905 ToDo = *Backup.ToDo[i]; 4905 ToDo = *Backup.ToDo[i];
4906 error = Phone->SetToDo(&s,&ToDo); 4906 error = Phone->SetToDo(&s,&ToDo);
4907 Print_Error(error); 4907 Print_Error(error);
4908 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4908 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4909 if (gshutdown) { 4909 if (gshutdown) {
4910 GSM_Terminate(); 4910 GSM_Terminate();
4911 exit(0); 4911 exit(0);
4912 } 4912 }
4913 } 4913 }
4914 printmsgerr("\n"); 4914 printmsgerr("\n");
4915 } 4915 }
4916 4916
4917 if (Backup.SMSC[0] != NULL && answer_yes("Restore SMSC profiles")) { 4917 if (Backup.SMSC[0] != NULL && answer_yes("Restore SMSC profiles")) {
4918 max = 0; 4918 max = 0;
4919 while (Backup.SMSC[max]!=NULL) max++; 4919 while (Backup.SMSC[max]!=NULL) max++;
4920 for (i=0;i<max;i++) { 4920 for (i=0;i<max;i++) {
4921 error=Phone->SetSMSC(&s,Backup.SMSC[i]); 4921 error=Phone->SetSMSC(&s,Backup.SMSC[i]);
4922 Print_Error(error); 4922 Print_Error(error);
4923 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4923 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4924 if (gshutdown) { 4924 if (gshutdown) {
4925 GSM_Terminate(); 4925 GSM_Terminate();
4926 exit(0); 4926 exit(0);
4927 } 4927 }
4928 } 4928 }
4929 printmsgerr("\n"); 4929 printmsgerr("\n");
4930 } 4930 }
4931 if (Backup.StartupLogo != NULL && answer_yes("Restore startup logo/text")) { 4931 if (Backup.StartupLogo != NULL && answer_yes("Restore startup logo/text")) {
4932 error=Phone->SetBitmap(&s,Backup.StartupLogo); 4932 error=Phone->SetBitmap(&s,Backup.StartupLogo);
4933 Print_Error(error); 4933 Print_Error(error);
4934 } 4934 }
4935 if (Backup.OperatorLogo != NULL && answer_yes("Restore operator logo")) { 4935 if (Backup.OperatorLogo != NULL && answer_yes("Restore operator logo")) {
4936 error=Phone->SetBitmap(&s,Backup.OperatorLogo); 4936 error=Phone->SetBitmap(&s,Backup.OperatorLogo);
4937 Print_Error(error); 4937 Print_Error(error);
4938 } 4938 }
4939 DoRestore = false; 4939 DoRestore = false;
4940 if (Backup.WAPBookmark[0] != NULL) { 4940 if (Backup.WAPBookmark[0] != NULL) {
4941 Bookmark.Location = 1; 4941 Bookmark.Location = 1;
4942 error = Phone->GetWAPBookmark(&s,&Bookmark); 4942 error = Phone->GetWAPBookmark(&s,&Bookmark);
4943 if (error == ERR_NONE || error == ERR_INVALIDLOCATION) { 4943 if (error == ERR_NONE || error == ERR_INVALIDLOCATION) {
4944 if (answer_yes("Restore WAP bookmarks")) DoRestore = true; 4944 if (answer_yes("Restore WAP bookmarks")) DoRestore = true;
4945 } 4945 }
4946 } 4946 }
4947 if (DoRestore) { 4947 if (DoRestore) {
4948 printmsgerr("Deleting old bookmarks: "); 4948 printmsgerr("Deleting old bookmarks: ");
4949 /* One thing to explain: DCT4 phones seems to have bug here. 4949 /* One thing to explain: DCT4 phones seems to have bug here.
4950 * When delete for example first bookmark, phone change 4950 * When delete for example first bookmark, phone change
4951 * numeration for getting frame, not for deleting. So, we try to 4951 * numeration for getting frame, not for deleting. So, we try to
4952 * get 1'st bookmark. Inside frame is "correct" location. We use 4952 * get 1'st bookmark. Inside frame is "correct" location. We use
4953 * it later 4953 * it later
4954 */ 4954 */
4955 while (error==ERR_NONE) { 4955 while (error==ERR_NONE) {
4956 error = Phone->DeleteWAPBookmark(&s,&Bookmark); 4956 error = Phone->DeleteWAPBookmark(&s,&Bookmark);
4957 Bookmark.Location = 1; 4957 Bookmark.Location = 1;
4958 error = Phone->GetWAPBookmark(&s,&Bookmark); 4958 error = Phone->GetWAPBookmark(&s,&Bookmark);
4959 printmsgerr("*"); 4959 printmsgerr("*");
4960 } 4960 }
4961 printmsgerr("\n"); 4961 printmsgerr("\n");
4962 max = 0; 4962 max = 0;
4963 while (Backup.WAPBookmark[max]!=NULL) max++; 4963 while (Backup.WAPBookmark[max]!=NULL) max++;
4964 for (i=0;i<max;i++) { 4964 for (i=0;i<max;i++) {
4965 Bookmark = *Backup.WAPBookmark[i]; 4965 Bookmark = *Backup.WAPBookmark[i];
4966 Bookmark.Location = 0; 4966 Bookmark.Location = 0;
4967 error=Phone->SetWAPBookmark(&s,&Bookmark); 4967 error=Phone->SetWAPBookmark(&s,&Bookmark);
4968 Print_Error(error); 4968 Print_Error(error);
4969 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4969 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4970 if (gshutdown) { 4970 if (gshutdown) {
4971 GSM_Terminate(); 4971 GSM_Terminate();
4972 exit(0); 4972 exit(0);
4973 } 4973 }
4974 } 4974 }
4975 printmsgerr("\n"); 4975 printmsgerr("\n");
4976 } 4976 }
4977 DoRestore = false; 4977 DoRestore = false;
4978 if (Backup.WAPSettings[0] != NULL) { 4978 if (Backup.WAPSettings[0] != NULL) {
4979 Settings.Location = 1; 4979 Settings.Location = 1;
4980 error = Phone->GetWAPSettings(&s,&Settings); 4980 error = Phone->GetWAPSettings(&s,&Settings);
4981 if (error == ERR_NONE) { 4981 if (error == ERR_NONE) {
4982 if (answer_yes("Restore WAP settings")) DoRestore = true; 4982 if (answer_yes("Restore WAP settings")) DoRestore = true;
4983 } 4983 }
4984 } 4984 }
4985 if (DoRestore) { 4985 if (DoRestore) {
4986 max = 0; 4986 max = 0;
4987 while (Backup.WAPSettings[max]!=NULL) max++; 4987 while (Backup.WAPSettings[max]!=NULL) max++;
4988 for (i=0;i<max;i++) { 4988 for (i=0;i<max;i++) {
4989 error=Phone->SetWAPSettings(&s,Backup.WAPSettings[i]); 4989 error=Phone->SetWAPSettings(&s,Backup.WAPSettings[i]);
4990 Print_Error(error); 4990 Print_Error(error);
4991 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4991 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4992 if (gshutdown) { 4992 if (gshutdown) {
4993 GSM_Terminate(); 4993 GSM_Terminate();
4994 exit(0); 4994 exit(0);
4995 } 4995 }
4996 } 4996 }
4997 printmsgerr("\n"); 4997 printmsgerr("\n");
4998 } 4998 }
4999 DoRestore = false; 4999 DoRestore = false;
5000 if (Backup.MMSSettings[0] != NULL) { 5000 if (Backup.MMSSettings[0] != NULL) {
5001 Settings.Location = 1; 5001 Settings.Location = 1;
5002 error = Phone->GetMMSSettings(&s,&Settings); 5002 error = Phone->GetMMSSettings(&s,&Settings);
5003 if (error == ERR_NONE) { 5003 if (error == ERR_NONE) {
5004 if (answer_yes("Restore MMS settings")) DoRestore = true; 5004 if (answer_yes("Restore MMS settings")) DoRestore = true;
5005 } 5005 }
5006 } 5006 }
5007 if (DoRestore) { 5007 if (DoRestore) {
5008 max = 0; 5008 max = 0;
5009 while (Backup.MMSSettings[max]!=NULL) max++; 5009 while (Backup.MMSSettings[max]!=NULL) max++;
5010 for (i=0;i<max;i++) { 5010 for (i=0;i<max;i++) {
5011 error=Phone->SetMMSSettings(&s,Backup.MMSSettings[i]); 5011 error=Phone->SetMMSSettings(&s,Backup.MMSSettings[i]);
5012 Print_Error(error); 5012 Print_Error(error);
5013 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5013 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5014 if (gshutdown) { 5014 if (gshutdown) {
5015 GSM_Terminate(); 5015 GSM_Terminate();
5016 exit(0); 5016 exit(0);
5017 } 5017 }
5018 } 5018 }
5019 printmsgerr("\n"); 5019 printmsgerr("\n");
5020 } 5020 }
5021 DoRestore = false; 5021 DoRestore = false;
5022 if (Backup.Ringtone[0] != NULL) { 5022 if (Backup.Ringtone[0] != NULL) {
5023 Ringtone.Location = 1; 5023 Ringtone.Location = 1;
5024 Ringtone.Format = 0; 5024 Ringtone.Format = 0;
5025 error = Phone->GetRingtone(&s,&Ringtone,false); 5025 error = Phone->GetRingtone(&s,&Ringtone,false);
5026 if (error == ERR_NONE || error ==ERR_EMPTY) { 5026 if (error == ERR_NONE || error ==ERR_EMPTY) {
5027 if (Phone->DeleteUserRingtones != NOTSUPPORTED) { 5027 if (Phone->DeleteUserRingtones != NOTSUPPORTED) {
5028 if (answer_yes("Delete all user ringtones")) DoRestore = true; 5028 if (answer_yes("Delete all user ringtones")) DoRestore = true;
5029 } 5029 }
5030 } 5030 }
5031 } 5031 }
5032 if (DoRestore) { 5032 if (DoRestore) {
5033 printmsgerr("Deleting: "); 5033 printmsgerr("Deleting: ");
5034 error=Phone->DeleteUserRingtones(&s); 5034 error=Phone->DeleteUserRingtones(&s);
5035 Print_Error(error); 5035 Print_Error(error);
5036 printmsgerr("Done\n"); 5036 printmsgerr("Done\n");
5037 DoRestore = false; 5037 DoRestore = false;
5038 if (answer_yes("Restore user ringtones")) DoRestore = true; 5038 if (answer_yes("Restore user ringtones")) DoRestore = true;
5039 } 5039 }
5040 if (DoRestore) { 5040 if (DoRestore) {
5041 max = 0; 5041 max = 0;
5042 while (Backup.Ringtone[max]!=NULL) max++; 5042 while (Backup.Ringtone[max]!=NULL) max++;
5043 for (i=0;i<max;i++) { 5043 for (i=0;i<max;i++) {
5044 error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format); 5044 error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format);
5045 Print_Error(error); 5045 Print_Error(error);
5046 error=Phone->SetRingtone(&s,&Ringtone,&i); 5046 error=Phone->SetRingtone(&s,&Ringtone,&i);
5047 Print_Error(error); 5047 Print_Error(error);
5048 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5048 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5049 if (gshutdown) { 5049 if (gshutdown) {
5050 GSM_Terminate(); 5050 GSM_Terminate();
5051 exit(0); 5051 exit(0);
5052 } 5052 }
5053 } 5053 }
5054 printmsgerr("\n"); 5054 printmsgerr("\n");
5055 } 5055 }
5056 DoRestore = false; 5056 DoRestore = false;
5057 if (Backup.Profiles[0] != NULL) { 5057 if (Backup.Profiles[0] != NULL) {
5058 Profile.Location = 1; 5058 Profile.Location = 1;
5059 error = Phone->GetProfile(&s,&Profile); 5059 error = Phone->GetProfile(&s,&Profile);
5060 if (error == ERR_NONE) { 5060 if (error == ERR_NONE) {
5061 if (answer_yes("Restore profiles")) DoRestore = true; 5061 if (answer_yes("Restore profiles")) DoRestore = true;
5062 } 5062 }
5063 } 5063 }
5064 if (DoRestore) { 5064 if (DoRestore) {
5065 Profile.Location= 0; 5065 Profile.Location= 0;
5066 max = 0; 5066 max = 0;
5067 while (Backup.Profiles[max]!=NULL) max++; 5067 while (Backup.Profiles[max]!=NULL) max++;
5068 for (i=0;i<max;i++) { 5068 for (i=0;i<max;i++) {
5069 Profile= *Backup.Profiles[i]; 5069 Profile= *Backup.Profiles[i];
5070 error=Phone->SetProfile(&s,&Profile); 5070 error=Phone->SetProfile(&s,&Profile);
5071 Print_Error(error); 5071 Print_Error(error);
5072 if (gshutdown) { 5072 if (gshutdown) {
5073 GSM_Terminate(); 5073 GSM_Terminate();
5074 exit(0); 5074 exit(0);
5075 } 5075 }
5076 } 5076 }
5077 printmsgerr("\n"); 5077 printmsgerr("\n");
5078 } 5078 }
5079 DoRestore = false; 5079 DoRestore = false;
5080 if (Backup.FMStation[0] != NULL) { 5080 if (Backup.FMStation[0] != NULL) {
5081 FMStation.Location = 1; 5081 FMStation.Location = 1;
5082 error = Phone->GetFMStation(&s,&FMStation); 5082 error = Phone->GetFMStation(&s,&FMStation);
5083 if (error == ERR_NONE || error == ERR_EMPTY) { 5083 if (error == ERR_NONE || error == ERR_EMPTY) {
5084 if (answer_yes("Restore FM stations")) DoRestore = true; 5084 if (answer_yes("Restore FM stations")) DoRestore = true;
5085 } 5085 }
5086 } 5086 }
5087 if (DoRestore) { 5087 if (DoRestore) {
5088 printmsgerr("Deleting old FM stations: "); 5088 printmsgerr("Deleting old FM stations: ");
5089 error=Phone->ClearFMStations(&s); 5089 error=Phone->ClearFMStations(&s);
5090 Print_Error(error); 5090 Print_Error(error);
5091 printmsgerr("Done\n"); 5091 printmsgerr("Done\n");
5092 max = 0; 5092 max = 0;
5093 while (Backup.FMStation[max]!=NULL) max++; 5093 while (Backup.FMStation[max]!=NULL) max++;
5094 for (i=0;i<max;i++) { 5094 for (i=0;i<max;i++) {
5095 FMStation = *Backup.FMStation[i]; 5095 FMStation = *Backup.FMStation[i];
5096 error=Phone->SetFMStation(&s,&FMStation); 5096 error=Phone->SetFMStation(&s,&FMStation);
5097 Print_Error(error); 5097 Print_Error(error);
5098 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5098 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5099 if (gshutdown) { 5099 if (gshutdown) {
5100 GSM_Terminate(); 5100 GSM_Terminate();
5101 exit(0); 5101 exit(0);
5102 } 5102 }
5103 } 5103 }
5104 printmsgerr("\n"); 5104 printmsgerr("\n");
5105 } 5105 }
5106 DoRestore = false; 5106 DoRestore = false;
5107 if (Backup.GPRSPoint[0] != NULL) { 5107 if (Backup.GPRSPoint[0] != NULL) {
5108 GPRSPoint.Location = 1; 5108 GPRSPoint.Location = 1;
5109 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint); 5109 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
5110 if (error == ERR_NONE || error == ERR_EMPTY) { 5110 if (error == ERR_NONE || error == ERR_EMPTY) {
5111 if (answer_yes("Restore GPRS Points")) DoRestore = true; 5111 if (answer_yes("Restore GPRS Points")) DoRestore = true;
5112 } 5112 }
5113 } 5113 }
5114 if (DoRestore) { 5114 if (DoRestore) {
5115 max = 0; 5115 max = 0;
5116 while (Backup.GPRSPoint[max]!=NULL) max++; 5116 while (Backup.GPRSPoint[max]!=NULL) max++;
5117 for (i=0;i<max;i++) { 5117 for (i=0;i<max;i++) {
5118 error=Phone->SetGPRSAccessPoint(&s,Backup.GPRSPoint[i]); 5118 error=Phone->SetGPRSAccessPoint(&s,Backup.GPRSPoint[i]);
5119 Print_Error(error); 5119 Print_Error(error);
5120 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5120 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5121 if (gshutdown) { 5121 if (gshutdown) {
5122 GSM_Terminate(); 5122 GSM_Terminate();
5123 exit(0); 5123 exit(0);
5124 } 5124 }
5125 } 5125 }
5126 printmsgerr("\n"); 5126 printmsgerr("\n");
5127 } 5127 }
5128 5128
5129 GSM_Terminate(); 5129 GSM_Terminate();
5130} 5130}
5131 5131
5132static void AddNew(int argc, char *argv[]) 5132static void AddNew(int argc, char *argv[])
5133{ 5133{
5134 GSM_Backup Backup; 5134 GSM_Backup Backup;
5135 GSM_DateTime date_time; 5135 GSM_DateTime date_time;
5136 GSM_MemoryEntry Pbk; 5136 GSM_MemoryEntry Pbk;
5137 GSM_MemoryStatusMemStatus; 5137 GSM_MemoryStatusMemStatus;
5138 GSM_ToDoEntry ToDo; 5138 GSM_ToDoEntry ToDo;
5139 GSM_ToDoStatus ToDoStatus; 5139 GSM_ToDoStatus ToDoStatus;
5140 GSM_CalendarEntryCalendar; 5140 GSM_CalendarEntryCalendar;
5141 GSM_WAPBookmark Bookmark; 5141 GSM_WAPBookmark Bookmark;
5142 int i, max, j; 5142 int i, max, j;
5143 5143
5144 error=GSM_ReadBackupFile(argv[2],&Backup); 5144 error=GSM_ReadBackupFile(argv[2],&Backup);
5145 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); 5145 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
5146 5146
5147 signal(SIGINT, interrupt); 5147 signal(SIGINT, interrupt);
5148 printmsgerr("Press Ctrl+C to break...\n"); 5148 printmsgerr("Press Ctrl+C to break...\n");
5149 5149
5150 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); 5150 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
5151 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); 5151 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
5152 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); 5152 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI);
5153 5153
5154 GSM_Init(true); 5154 GSM_Init(true);
5155 5155
5156 if (Backup.PhonePhonebook[0] != NULL) { 5156 if (Backup.PhonePhonebook[0] != NULL) {
5157 MemStatus.MemoryType = MEM_ME; 5157 MemStatus.MemoryType = MEM_ME;
5158 error=Phone->GetMemoryStatus(&s, &MemStatus); 5158 error=Phone->GetMemoryStatus(&s, &MemStatus);
5159 if (error==ERR_NONE) { 5159 if (error==ERR_NONE) {
5160 max = 0; 5160 max = 0;
5161 while (Backup.PhonePhonebook[max]!=NULL) max++; 5161 while (Backup.PhonePhonebook[max]!=NULL) max++;
5162 printmsgerr("%i entries in backup file\n",max); 5162 printmsgerr("%i entries in backup file\n",max);
5163 if (MemStatus.MemoryFree < max) { 5163 if (MemStatus.MemoryFree < max) {
5164 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.MemoryFree); 5164 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.MemoryFree);
5165 } else if (answer_yes("Add phone phonebook entries")) { 5165 } else if (answer_yes("Add phone phonebook entries")) {
5166 for (i=0;i<max;i++) { 5166 for (i=0;i<max;i++) {
5167 Pbk = *Backup.PhonePhonebook[i]; 5167 Pbk = *Backup.PhonePhonebook[i];
5168 Pbk.MemoryType = MEM_ME; 5168 Pbk.MemoryType = MEM_ME;
5169 error=Phone->AddMemory(&s, &Pbk); 5169 error=Phone->AddMemory(&s, &Pbk);
5170 Print_Error(error); 5170 Print_Error(error);
5171 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5171 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5172 if (gshutdown) { 5172 if (gshutdown) {
5173 GSM_Terminate(); 5173 GSM_Terminate();
5174 exit(0); 5174 exit(0);
5175 } 5175 }
5176 } 5176 }
5177 printmsgerr("\n"); 5177 printmsgerr("\n");
5178 } 5178 }
5179 } 5179 }
5180 } 5180 }
5181 if (Backup.SIMPhonebook[0] != NULL) { 5181 if (Backup.SIMPhonebook[0] != NULL) {
5182 MemStatus.MemoryType = MEM_SM; 5182 MemStatus.MemoryType = MEM_SM;
5183 error=Phone->GetMemoryStatus(&s, &MemStatus); 5183 error=Phone->GetMemoryStatus(&s, &MemStatus);
5184 if (error==ERR_NONE) { 5184 if (error==ERR_NONE) {
5185 max = 0; 5185 max = 0;
5186 while (Backup.SIMPhonebook[max]!=NULL) max++; 5186 while (Backup.SIMPhonebook[max]!=NULL) max++;
5187 printmsgerr("%i entries in backup file\n",max); 5187 printmsgerr("%i entries in backup file\n",max);
5188 if (MemStatus.MemoryFree < max) { 5188 if (MemStatus.MemoryFree < max) {
5189 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.MemoryFree); 5189 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.MemoryFree);
5190 } else if (answer_yes("Add SIM phonebook entries")) { 5190 } else if (answer_yes("Add SIM phonebook entries")) {
5191 j = 1; 5191 j = 1;
5192 for (i=0;i<max;i++) { 5192 for (i=0;i<max;i++) {
5193 Pbk = *Backup.SIMPhonebook[i]; 5193 Pbk = *Backup.SIMPhonebook[i];
5194 Pbk.MemoryType = MEM_SM; 5194 Pbk.MemoryType = MEM_SM;
5195 error=Phone->AddMemory(&s, &Pbk); 5195 error=Phone->AddMemory(&s, &Pbk);
5196 Print_Error(error); 5196 Print_Error(error);
5197 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5197 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5198 if (gshutdown) { 5198 if (gshutdown) {
5199 GSM_Terminate(); 5199 GSM_Terminate();
5200 exit(0); 5200 exit(0);
5201 } 5201 }
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index d037d2f..ad0f702 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,1076 +1,1198 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45#include <kglobal.h> 45#include <kglobal.h>
46#include <klocale.h> 46#include <klocale.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
50#include <libkdepim/phoneaccess.h> 50#include <libkdepim/phoneaccess.h>
51#include "addressbook.h" 51#include "addressbook.h"
52#include "resource.h" 52#include "resource.h"
53#include "vcardconverter.h" 53#include "vcardconverter.h"
54#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
55 55
56//US #include "addressbook.moc" 56//US #include "addressbook.moc"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
61{ 61{
62 Addressee::List mAddressees; 62 Addressee::List mAddressees;
63 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
64 Field::List mAllFields; 64 Field::List mAllFields;
65 KConfig *mConfig; 65 KConfig *mConfig;
66 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
67//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
68}; 68};
69 69
70struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
71{ 71{
72 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
73}; 73};
74 74
75struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
76{ 76{
77 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
78}; 78};
79 79
80AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
81{ 81{
82 d = new IteratorData; 82 d = new IteratorData;
83} 83}
84 84
85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
86{ 86{
87 d = new IteratorData; 87 d = new IteratorData;
88 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
89} 89}
90 90
91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
92{ 92{
93 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
94 delete d; // delete the old data the Iterator was completely constructed before 94 delete d; // delete the old data the Iterator was completely constructed before
95 d = new IteratorData; 95 d = new IteratorData;
96 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
97 return *this; 97 return *this;
98} 98}
99 99
100AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
101{ 101{
102 delete d; 102 delete d;
103} 103}
104 104
105const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
106{ 106{
107 return *(d->mIt); 107 return *(d->mIt);
108} 108}
109 109
110Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
111{ 111{
112 return *(d->mIt); 112 return *(d->mIt);
113} 113}
114 114
115Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
116{ 116{
117 return &(*(d->mIt)); 117 return &(*(d->mIt));
118} 118}
119 119
120AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
121{ 121{
122 (d->mIt)++; 122 (d->mIt)++;
123 return *this; 123 return *this;
124} 124}
125 125
126AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
127{ 127{
128 (d->mIt)++; 128 (d->mIt)++;
129 return *this; 129 return *this;
130} 130}
131 131
132AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
133{ 133{
134 (d->mIt)--; 134 (d->mIt)--;
135 return *this; 135 return *this;
136} 136}
137 137
138AddressBook::Iterator &AddressBook::Iterator::operator--(int) 138AddressBook::Iterator &AddressBook::Iterator::operator--(int)
139{ 139{
140 (d->mIt)--; 140 (d->mIt)--;
141 return *this; 141 return *this;
142} 142}
143 143
144bool AddressBook::Iterator::operator==( const Iterator &it ) 144bool AddressBook::Iterator::operator==( const Iterator &it )
145{ 145{
146 return ( d->mIt == it.d->mIt ); 146 return ( d->mIt == it.d->mIt );
147} 147}
148 148
149bool AddressBook::Iterator::operator!=( const Iterator &it ) 149bool AddressBook::Iterator::operator!=( const Iterator &it )
150{ 150{
151 return ( d->mIt != it.d->mIt ); 151 return ( d->mIt != it.d->mIt );
152} 152}
153 153
154 154
155AddressBook::ConstIterator::ConstIterator() 155AddressBook::ConstIterator::ConstIterator()
156{ 156{
157 d = new ConstIteratorData; 157 d = new ConstIteratorData;
158} 158}
159 159
160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
161{ 161{
162 d = new ConstIteratorData; 162 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
164} 164}
165 165
166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
167{ 167{
168 if( this == &i ) return *this; // guard for self assignment 168 if( this == &i ) return *this; // guard for self assignment
169 delete d; // delete the old data because the Iterator was really constructed before 169 delete d; // delete the old data because the Iterator was really constructed before
170 d = new ConstIteratorData; 170 d = new ConstIteratorData;
171 d->mIt = i.d->mIt; 171 d->mIt = i.d->mIt;
172 return *this; 172 return *this;
173} 173}
174 174
175AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
176{ 176{
177 delete d; 177 delete d;
178} 178}
179 179
180const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
181{ 181{
182 return *(d->mIt); 182 return *(d->mIt);
183} 183}
184 184
185const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
186{ 186{
187 return &(*(d->mIt)); 187 return &(*(d->mIt));
188} 188}
189 189
190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
191{ 191{
192 (d->mIt)++; 192 (d->mIt)++;
193 return *this; 193 return *this;
194} 194}
195 195
196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
197{ 197{
198 (d->mIt)++; 198 (d->mIt)++;
199 return *this; 199 return *this;
200} 200}
201 201
202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
203{ 203{
204 (d->mIt)--; 204 (d->mIt)--;
205 return *this; 205 return *this;
206} 206}
207 207
208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
209{ 209{
210 (d->mIt)--; 210 (d->mIt)--;
211 return *this; 211 return *this;
212} 212}
213 213
214bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
215{ 215{
216 return ( d->mIt == it.d->mIt ); 216 return ( d->mIt == it.d->mIt );
217} 217}
218 218
219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
220{ 220{
221 return ( d->mIt != it.d->mIt ); 221 return ( d->mIt != it.d->mIt );
222} 222}
223 223
224 224
225AddressBook::AddressBook() 225AddressBook::AddressBook()
226{ 226{
227 init(0, "contact"); 227 init(0, "contact");
228} 228}
229 229
230AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
231{ 231{
232 init(config, "contact"); 232 init(config, "contact");
233} 233}
234 234
235AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::AddressBook( const QString &config, const QString &family )
236{ 236{
237 init(config, family); 237 init(config, family);
238 238
239} 239}
240 240
241// the default family is "contact" 241// the default family is "contact"
242void AddressBook::init(const QString &config, const QString &family ) 242void AddressBook::init(const QString &config, const QString &family )
243{ 243{
244 blockLSEchange = false; 244 blockLSEchange = false;
245 d = new AddressBookData; 245 d = new AddressBookData;
246 QString fami = family; 246 QString fami = family;
247 if (config != 0) { 247 if (config != 0) {
248 if ( family == "syncContact" ) { 248 if ( family == "syncContact" ) {
249 qDebug("creating sync config "); 249 qDebug("creating sync config ");
250 fami = "contact"; 250 fami = "contact";
251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
252 con->setGroup( "General" ); 252 con->setGroup( "General" );
253 con->writeEntry( "ResourceKeys", QString("sync") ); 253 con->writeEntry( "ResourceKeys", QString("sync") );
254 con->writeEntry( "Standard", QString("sync") ); 254 con->writeEntry( "Standard", QString("sync") );
255 con->setGroup( "Resource_sync" ); 255 con->setGroup( "Resource_sync" );
256 con->writeEntry( "FileName", config ); 256 con->writeEntry( "FileName", config );
257 con->writeEntry( "FileFormat", QString("vcard") ); 257 con->writeEntry( "FileFormat", QString("vcard") );
258 con->writeEntry( "ResourceIdentifier", QString("sync") ); 258 con->writeEntry( "ResourceIdentifier", QString("sync") );
259 con->writeEntry( "ResourceName", QString("sync_res") ); 259 con->writeEntry( "ResourceName", QString("sync_res") );
260 if ( config.right(4) == ".xml" ) 260 if ( config.right(4) == ".xml" )
261 con->writeEntry( "ResourceType", QString("qtopia") ); 261 con->writeEntry( "ResourceType", QString("qtopia") );
262 else if ( config == "sharp" ) { 262 else if ( config == "sharp" ) {
263 con->writeEntry( "ResourceType", QString("sharp") ); 263 con->writeEntry( "ResourceType", QString("sharp") );
264 } else { 264 } else {
265 con->writeEntry( "ResourceType", QString("file") ); 265 con->writeEntry( "ResourceType", QString("file") );
266 } 266 }
267 //con->sync(); 267 //con->sync();
268 d->mConfig = con; 268 d->mConfig = con;
269 } 269 }
270 else 270 else
271 d->mConfig = new KConfig( locateLocal("config", config) ); 271 d->mConfig = new KConfig( locateLocal("config", config) );
272// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 272// qDebug("AddressBook::init 1 config=%s",config.latin1() );
273 } 273 }
274 else { 274 else {
275 d->mConfig = 0; 275 d->mConfig = 0;
276// qDebug("AddressBook::init 1 config=0"); 276// qDebug("AddressBook::init 1 config=0");
277 } 277 }
278 278
279//US d->mErrorHandler = 0; 279//US d->mErrorHandler = 0;
280 d->mManager = new KRES::Manager<Resource>( fami, false ); 280 d->mManager = new KRES::Manager<Resource>( fami, false );
281 d->mManager->readConfig( d->mConfig ); 281 d->mManager->readConfig( d->mConfig );
282 if ( family == "syncContact" ) { 282 if ( family == "syncContact" ) {
283 KRES::Manager<Resource> *manager = d->mManager; 283 KRES::Manager<Resource> *manager = d->mManager;
284 KRES::Manager<Resource>::ActiveIterator it; 284 KRES::Manager<Resource>::ActiveIterator it;
285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
286 (*it)->setAddressBook( this ); 286 (*it)->setAddressBook( this );
287 if ( !(*it)->open() ) 287 if ( !(*it)->open() )
288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
289 } 289 }
290 Resource *res = standardResource(); 290 Resource *res = standardResource();
291 if ( !res ) { 291 if ( !res ) {
292 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
293 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
294 if ( res ) 294 if ( res )
295 { 295 {
296 addResource( res ); 296 addResource( res );
297 } 297 }
298 else 298 else
299 qDebug(" No resource available!!!"); 299 qDebug(" No resource available!!!");
300 } 300 }
301 setStandardResource( res ); 301 setStandardResource( res );
302 manager->writeConfig(); 302 manager->writeConfig();
303 } 303 }
304 addCustomField( i18n( "Department" ), KABC::Field::Organization, 304 addCustomField( i18n( "Department" ), KABC::Field::Organization,
305 "X-Department", "KADDRESSBOOK" ); 305 "X-Department", "KADDRESSBOOK" );
306 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 306 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
307 "X-Profession", "KADDRESSBOOK" ); 307 "X-Profession", "KADDRESSBOOK" );
308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
309 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
311 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
313 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
314 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
315 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
317 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
319 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
320 320
321 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
322 // values can be "female" or "male" or "". An empty field represents undefined. 322 // values can be "female" or "male" or "". An empty field represents undefined.
323 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
324 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
325 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
326 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
328 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
330 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
331} 331}
332 332
333AddressBook::~AddressBook() 333AddressBook::~AddressBook()
334{ 334{
335 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
336 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
337//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
338 delete d; d = 0; 338 delete d; d = 0;
339} 339}
340 340
341bool AddressBook::load() 341bool AddressBook::load()
342{ 342{
343 343
344
345 clear(); 344 clear();
346
347 KRES::Manager<Resource>::ActiveIterator it; 345 KRES::Manager<Resource>::ActiveIterator it;
348 bool ok = true; 346 bool ok = true;
349 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
350 if ( !(*it)->load() ) { 348 if ( !(*it)->load() ) {
351 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
352 ok = false; 350 ok = false;
351 } else {
352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
353 } 353 }
354
355 // mark all addressees as unchanged 354 // mark all addressees as unchanged
356 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
357 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
358 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
359 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
360 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
361 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
362 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
363 } 362 }
364 } 363 }
365 blockLSEchange = true; 364 blockLSEchange = true;
366 return ok; 365 return ok;
367} 366}
368 367
369bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
370{ 369{
371 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
372 371
373 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
374 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
375 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
376 } 375 }
377 376
378 return false; 377 return false;
379} 378}
380void AddressBook::export2File( QString fileName ) 379void AddressBook::export2File( QString fileName )
381{ 380{
382 381
383 QFile outFile( fileName ); 382 QFile outFile( fileName );
384 if ( !outFile.open( IO_WriteOnly ) ) { 383 if ( !outFile.open( IO_WriteOnly ) ) {
385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 384 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
386 KMessageBox::error( 0, text.arg( fileName ) ); 385 KMessageBox::error( 0, text.arg( fileName ) );
387 return ; 386 return ;
388 } 387 }
389 QTextStream t( &outFile ); 388 QTextStream t( &outFile );
390 t.setEncoding( QTextStream::UnicodeUTF8 ); 389 t.setEncoding( QTextStream::UnicodeUTF8 );
391 Iterator it; 390 Iterator it;
392 KABC::VCardConverter::Version version; 391 KABC::VCardConverter::Version version;
393 version = KABC::VCardConverter::v3_0; 392 version = KABC::VCardConverter::v3_0;
394 for ( it = begin(); it != end(); ++it ) { 393 for ( it = begin(); it != end(); ++it ) {
395 if ( !(*it).IDStr().isEmpty() ) { 394 if ( !(*it).IDStr().isEmpty() ) {
396 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
397 } 396 }
398 KABC::VCardConverter converter; 397 KABC::VCardConverter converter;
399 QString vcard; 398 QString vcard;
400 //Resource *resource() const; 399 //Resource *resource() const;
401 converter.addresseeToVCard( *it, vcard, version ); 400 converter.addresseeToVCard( *it, vcard, version );
402 t << vcard << "\r\n"; 401 t << vcard << "\r\n";
403 } 402 }
404 t << "\r\n\r\n"; 403 t << "\r\n\r\n";
405 outFile.close(); 404 outFile.close();
406} 405}
406// if QStringList uids is empty, all are exported
407bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
408{
409 KABC::VCardConverter converter;
410 QString datastream;
411 Iterator it;
412 bool all = uids.isEmpty();
413 for ( it = begin(); it != end(); ++it ) {
414 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
415 if ( ! all ) {
416 if ( ! ( uids.contains((*it).uid() ) ))
417 continue;
418 }
419 KABC::Addressee a = ( *it );
420 if ( a.isEmpty() )
421 continue;
422 a.simplifyEmails();
423 a.simplifyPhoneNumbers();
424 a.simplifyPhoneNumberTypes();
425 a.simplifyAddresses();
426
427 QString vcard;
428 QString vcardnew;
429 converter.addresseeToVCard( a, vcard );
430 int start = 0;
431 int next;
432 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
433 int semi = vcard.find(";", next);
434 int dopp = vcard.find(":", next);
435 int sep;
436 if ( semi < dopp && semi >= 0 )
437 sep = semi ;
438 else
439 sep = dopp;
440 vcardnew +=vcard.mid( start, next - start);
441 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
442 start = sep;
443 }
444 vcardnew += vcard.mid( start,vcard.length() );
445 vcard = "";
446 start = 0;
447 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
448 int sep = vcardnew.find(":", next);
449 vcard +=vcardnew.mid( start, next - start+3);
450 start = sep;
451 }
452 vcard += vcardnew.mid( start,vcardnew.length() );
453 vcard.replace ( QRegExp(";;;") , "" );
454 vcard.replace ( QRegExp(";;") , "" );
455 datastream += vcard;
456
457 }
458
459 QFile outFile(fileName);
460 if ( outFile.open(IO_WriteOnly) ) {
461 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
462 QTextStream t( &outFile ); // use a text stream
463 t.setEncoding( QTextStream::UnicodeUTF8 );
464 t <<datastream;
465 t << "\r\n\r\n";
466 outFile.close();
467
468 } else {
469 qDebug("Error open temp file ");
470 return false;
471 }
472 return true;
473
474}
407void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 475void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
408{ 476{
409 477
410 if ( removeOld ) 478 if ( removeOld )
411 setUntagged(); 479 setUntagged();
412 KABC::Addressee::List list; 480 KABC::Addressee::List list;
413 QFile file( fileName ); 481 QFile file( fileName );
414 file.open( IO_ReadOnly ); 482 file.open( IO_ReadOnly );
415 QByteArray rawData = file.readAll(); 483 QByteArray rawData = file.readAll();
416 file.close(); 484 file.close();
417 QString data; 485 QString data;
418 if ( replaceLabel ) { 486 if ( replaceLabel ) {
419 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 487 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
420 data.replace ( QRegExp("LABEL") , "ADR" ); 488 data.replace ( QRegExp("LABEL") , "ADR" );
421 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 489 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
422 } else 490 } else
423 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 491 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
424 KABC::VCardTool tool; 492 KABC::VCardTool tool;
425 list = tool.parseVCards( data ); 493 list = tool.parseVCards( data );
426 KABC::Addressee::List::Iterator it; 494 KABC::Addressee::List::Iterator it;
427 for ( it = list.begin(); it != list.end(); ++it ) { 495 for ( it = list.begin(); it != list.end(); ++it ) {
496 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
497 if ( !id.isEmpty() )
498 (*it).setIDStr(id );
428 (*it).setResource( 0 ); 499 (*it).setResource( 0 );
429 if ( replaceLabel ) 500 if ( replaceLabel )
430 (*it).removeVoice(); 501 (*it).removeVoice();
431 if ( removeOld ) 502 if ( removeOld )
432 (*it).setTagged( true ); 503 (*it).setTagged( true );
433 insertAddressee( (*it), false, true ); 504 insertAddressee( (*it), false, true );
434 } 505 }
435 if ( removeOld ) 506 if ( removeOld )
436 removeUntagged(); 507 removeUntagged();
437} 508}
438void AddressBook::setUntagged() 509void AddressBook::setUntagged()
439{ 510{
440 Iterator ait; 511 Iterator ait;
441 for ( ait = begin(); ait != end(); ++ait ) { 512 for ( ait = begin(); ait != end(); ++ait ) {
442 (*ait).setTagged( false ); 513 (*ait).setTagged( false );
443 } 514 }
444} 515}
445void AddressBook::removeUntagged() 516void AddressBook::removeUntagged()
446{ 517{
447 Iterator ait; 518 Iterator ait;
448 bool todelete = false; 519 bool todelete = false;
449 Iterator todel; 520 Iterator todel;
450 for ( ait = begin(); ait != end(); ++ait ) { 521 for ( ait = begin(); ait != end(); ++ait ) {
451 if ( todelete ) 522 if ( todelete )
452 removeAddressee( todel ); 523 removeAddressee( todel );
453 if (!(*ait).tagged()) { 524 if (!(*ait).tagged()) {
454 todelete = true; 525 todelete = true;
455 todel = ait; 526 todel = ait;
456 } else 527 } else
457 todelete = false; 528 todelete = false;
458 } 529 }
459 if ( todelete ) 530 if ( todelete )
460 removeAddressee( todel ); 531 removeAddressee( todel );
461 deleteRemovedAddressees(); 532 deleteRemovedAddressees();
462} 533}
463void AddressBook::smplifyAddressees() 534void AddressBook::smplifyAddressees()
464{ 535{
465 Iterator ait; 536 Iterator ait;
466 for ( ait = begin(); ait != end(); ++ait ) { 537 for ( ait = begin(); ait != end(); ++ait ) {
467 (*ait).simplifyEmails(); 538 (*ait).simplifyEmails();
468 (*ait).simplifyPhoneNumbers(); 539 (*ait).simplifyPhoneNumbers();
469 (*ait).simplifyPhoneNumberTypes(); 540 (*ait).simplifyPhoneNumberTypes();
470 (*ait).simplifyAddresses(); 541 (*ait).simplifyAddresses();
471 } 542 }
472} 543}
473void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 544void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
474{ 545{
475 Iterator ait; 546 Iterator ait;
476 for ( ait = begin(); ait != end(); ++ait ) { 547 for ( ait = begin(); ait != end(); ++ait ) {
477 QString id = (*ait).IDStr(); 548 QString id = (*ait).IDStr();
478 (*ait).setIDStr( ":"); 549 (*ait).setIDStr( ":");
479 (*ait).setExternalUID( id ); 550 (*ait).setExternalUID( id );
480 (*ait).setOriginalExternalUID( id ); 551 (*ait).setOriginalExternalUID( id );
481 if ( isPreSync ) 552 if ( isPreSync )
482 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 553 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
483 else 554 else {
484 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 555 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
556 (*ait).setID( currentSyncDevice,id );
557
558 }
559 }
560}
561void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
562{
563
564 setUntagged();
565 KABC::Addressee::List list;
566 QFile file( fileName );
567 file.open( IO_ReadOnly );
568 QByteArray rawData = file.readAll();
569 file.close();
570 QString data;
571
572 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
573 KABC::VCardTool tool;
574 list = tool.parseVCards( data );
575 KABC::Addressee::List::Iterator it;
576 for ( it = list.begin(); it != list.end(); ++it ) {
577 Iterator ait;
578 for ( ait = begin(); ait != end(); ++ait ) {
579 if ( !(*ait).tagged() ) {
580 if ( (*ait).containsAdr(*it)) {
581 (*ait).setTagged(true);
582 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
583 (*it).setIDStr( ":");
584 (*it).setID( currentSyncDevice,id );
585 (*it).setExternalUID( id );
586 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
587 (*it).setUid( ( (*ait).uid() ));
588 break;
589 }
590 }
591
592 }
593 if ( ait == end() )
594 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
595 }
596 clear();
597 for ( it = list.begin(); it != list.end(); ++it ) {
598 insertAddressee( (*it) );
485 } 599 }
486} 600}
601
487bool AddressBook::saveABphone( QString fileName ) 602bool AddressBook::saveABphone( QString fileName )
488{ 603{
489 smplifyAddressees(); 604 //smplifyAddressees();
490 qDebug("saveABphone:: saving AB... "); 605 qDebug("saveABphone:: saving AB... ");
491 if ( ! saveAB() ) 606 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
492 return false; 607 return false;
493 qDebug("saveABphone:: writing to phone... "); 608 qDebug("saveABphone:: writing to phone... ");
494 if ( !PhoneAccess::writeToPhone( fileName) ) { 609 if ( !PhoneAccess::writeToPhone( fileName) ) {
495 return false; 610 return false;
496 } 611 }
497 qDebug("saveABphone:: re-reading from phone... "); 612 qDebug("saveABphone:: re-reading from phone... ");
498 if ( !PhoneAccess::readFromPhone( fileName) ) { 613 if ( !PhoneAccess::readFromPhone( fileName) ) {
499 return false; 614 return false;
500 } 615 }
501 qDebug("reloading phone book... ");
502 if ( !load() )
503 return false;
504 return true; 616 return true;
505} 617}
506bool AddressBook::saveAB() 618bool AddressBook::saveAB()
507{ 619{
508 bool ok = true; 620 bool ok = true;
509 621
510 deleteRemovedAddressees(); 622 deleteRemovedAddressees();
511 Iterator ait; 623 Iterator ait;
512 for ( ait = begin(); ait != end(); ++ait ) { 624 for ( ait = begin(); ait != end(); ++ait ) {
513 if ( !(*ait).IDStr().isEmpty() ) { 625 if ( !(*ait).IDStr().isEmpty() ) {
514 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 626 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
515 } 627 }
516 } 628 }
517 KRES::Manager<Resource>::ActiveIterator it; 629 KRES::Manager<Resource>::ActiveIterator it;
518 KRES::Manager<Resource> *manager = d->mManager; 630 KRES::Manager<Resource> *manager = d->mManager;
631 qDebug("SaveAB::saving..." );
519 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 632 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
633 qDebug("SaveAB::checking resource..." );
634 if ( (*it)->readOnly() )
635 qDebug("readonly." );
636 if ( (*it)->isOpen() )
637 qDebug("open" );
638
520 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 639 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
521 Ticket *ticket = requestSaveTicket( *it ); 640 Ticket *ticket = requestSaveTicket( *it );
522// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 641 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
523 if ( !ticket ) { 642 if ( !ticket ) {
524 error( i18n( "Unable to save to resource '%1'. It is locked." ) 643 qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
525 .arg( (*it)->resourceName() ) ); 644 .arg( (*it)->resourceName() ) );
526 return false; 645 return false;
527 } 646 }
528 647
529 //if ( !save( ticket ) ) 648 //if ( !save( ticket ) )
530 if ( ticket->resource() ) { 649 if ( ticket->resource() ) {
531 if ( ! ticket->resource()->save( ticket ) ) 650 if ( ! ticket->resource()->save( ticket ) )
532 ok = false; 651 ok = false;
652 else
653 qDebug("StdAddressBook::saved '%s'", ticket->resource()->resourceName().latin1() );
654
533 } else 655 } else
534 ok = false; 656 ok = false;
535 657
536 } 658 }
537 } 659 }
538 return ok; 660 return ok;
539} 661}
540 662
541AddressBook::Iterator AddressBook::begin() 663AddressBook::Iterator AddressBook::begin()
542{ 664{
543 Iterator it = Iterator(); 665 Iterator it = Iterator();
544 it.d->mIt = d->mAddressees.begin(); 666 it.d->mIt = d->mAddressees.begin();
545 return it; 667 return it;
546} 668}
547 669
548AddressBook::ConstIterator AddressBook::begin() const 670AddressBook::ConstIterator AddressBook::begin() const
549{ 671{
550 ConstIterator it = ConstIterator(); 672 ConstIterator it = ConstIterator();
551 it.d->mIt = d->mAddressees.begin(); 673 it.d->mIt = d->mAddressees.begin();
552 return it; 674 return it;
553} 675}
554 676
555AddressBook::Iterator AddressBook::end() 677AddressBook::Iterator AddressBook::end()
556{ 678{
557 Iterator it = Iterator(); 679 Iterator it = Iterator();
558 it.d->mIt = d->mAddressees.end(); 680 it.d->mIt = d->mAddressees.end();
559 return it; 681 return it;
560} 682}
561 683
562AddressBook::ConstIterator AddressBook::end() const 684AddressBook::ConstIterator AddressBook::end() const
563{ 685{
564 ConstIterator it = ConstIterator(); 686 ConstIterator it = ConstIterator();
565 it.d->mIt = d->mAddressees.end(); 687 it.d->mIt = d->mAddressees.end();
566 return it; 688 return it;
567} 689}
568 690
569void AddressBook::clear() 691void AddressBook::clear()
570{ 692{
571 d->mAddressees.clear(); 693 d->mAddressees.clear();
572} 694}
573 695
574Ticket *AddressBook::requestSaveTicket( Resource *resource ) 696Ticket *AddressBook::requestSaveTicket( Resource *resource )
575{ 697{
576 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 698 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
577 699
578 if ( !resource ) 700 if ( !resource )
579 { 701 {
580 qDebug("AddressBook::requestSaveTicket no resource" ); 702 qDebug("AddressBook::requestSaveTicket no resource" );
581 resource = standardResource(); 703 resource = standardResource();
582 } 704 }
583 705
584 KRES::Manager<Resource>::ActiveIterator it; 706 KRES::Manager<Resource>::ActiveIterator it;
585 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 707 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
586 if ( (*it) == resource ) { 708 if ( (*it) == resource ) {
587 if ( (*it)->readOnly() || !(*it)->isOpen() ) 709 if ( (*it)->readOnly() || !(*it)->isOpen() )
588 return 0; 710 return 0;
589 else 711 else
590 return (*it)->requestSaveTicket(); 712 return (*it)->requestSaveTicket();
591 } 713 }
592 } 714 }
593 715
594 return 0; 716 return 0;
595} 717}
596 718//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
597void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 719void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
598{ 720{
599 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 721 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
600 //qDebug("block insert "); 722 //qDebug("block insert ");
601 return; 723 return;
602 } 724 }
603 //qDebug("inserting.... %s ",a.uid().latin1() ); 725 //qDebug("inserting.... %s ",a.uid().latin1() );
604 bool found = false; 726 bool found = false;
605 Addressee::List::Iterator it; 727 Addressee::List::Iterator it;
606 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 728 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
607 if ( a.uid() == (*it).uid() ) { 729 if ( a.uid() == (*it).uid() ) {
608 730
609 bool changed = false; 731 bool changed = false;
610 Addressee addr = a; 732 Addressee addr = a;
611 if ( addr != (*it) ) 733 if ( addr != (*it) )
612 changed = true; 734 changed = true;
613 735
614 if ( takeResource ) { 736 if ( takeResource ) {
615 Resource * res = (*it).resource(); 737 Resource * res = (*it).resource();
616 (*it) = a; 738 (*it) = a;
617 (*it).setResource( res ); 739 (*it).setResource( res );
618 } else { 740 } else {
619 (*it) = a; 741 (*it) = a;
620 if ( (*it).resource() == 0 ) 742 if ( (*it).resource() == 0 )
621 (*it).setResource( standardResource() ); 743 (*it).setResource( standardResource() );
622 } 744 }
623 if ( changed ) { 745 if ( changed ) {
624 if ( setRev ) { 746 if ( setRev ) {
625 747
626 // get rid of micro seconds 748 // get rid of micro seconds
627 QDateTime dt = QDateTime::currentDateTime(); 749 QDateTime dt = QDateTime::currentDateTime();
628 QTime t = dt.time(); 750 QTime t = dt.time();
629 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 751 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
630 (*it).setRevision( dt ); 752 (*it).setRevision( dt );
631 } 753 }
632 (*it).setChanged( true ); 754 (*it).setChanged( true );
633 } 755 }
634 756
635 found = true; 757 found = true;
636 } else { 758 } else {
637 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 759 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
638 QString name = (*it).uid().mid( 19 ); 760 QString name = (*it).uid().mid( 19 );
639 Addressee b = a; 761 Addressee b = a;
640 QString id = b.getID( name ); 762 QString id = b.getID( name );
641 if ( ! id.isEmpty() ) { 763 if ( ! id.isEmpty() ) {
642 QString des = (*it).note(); 764 QString des = (*it).note();
643 int startN; 765 int startN;
644 if( (startN = des.find( id ) ) >= 0 ) { 766 if( (startN = des.find( id ) ) >= 0 ) {
645 int endN = des.find( ",", startN+1 ); 767 int endN = des.find( ",", startN+1 );
646 des = des.left( startN ) + des.mid( endN+1 ); 768 des = des.left( startN ) + des.mid( endN+1 );
647 (*it).setNote( des ); 769 (*it).setNote( des );
648 } 770 }
649 } 771 }
650 } 772 }
651 } 773 }
652 } 774 }
653 if ( found ) 775 if ( found )
654 return; 776 return;
655 d->mAddressees.append( a ); 777 d->mAddressees.append( a );
656 Addressee& addr = d->mAddressees.last(); 778 Addressee& addr = d->mAddressees.last();
657 if ( addr.resource() == 0 ) 779 if ( addr.resource() == 0 )
658 addr.setResource( standardResource() ); 780 addr.setResource( standardResource() );
659 781
660 addr.setChanged( true ); 782 addr.setChanged( true );
661} 783}
662 784
663void AddressBook::removeAddressee( const Addressee &a ) 785void AddressBook::removeAddressee( const Addressee &a )
664{ 786{
665 Iterator it; 787 Iterator it;
666 Iterator it2; 788 Iterator it2;
667 bool found = false; 789 bool found = false;
668 for ( it = begin(); it != end(); ++it ) { 790 for ( it = begin(); it != end(); ++it ) {
669 if ( a.uid() == (*it).uid() ) { 791 if ( a.uid() == (*it).uid() ) {
670 found = true; 792 found = true;
671 it2 = it; 793 it2 = it;
672 } else { 794 } else {
673 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 795 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
674 QString name = (*it).uid().mid( 19 ); 796 QString name = (*it).uid().mid( 19 );
675 Addressee b = a; 797 Addressee b = a;
676 QString id = b.getID( name ); 798 QString id = b.getID( name );
677 if ( ! id.isEmpty() ) { 799 if ( ! id.isEmpty() ) {
678 QString des = (*it).note(); 800 QString des = (*it).note();
679 if( des.find( id ) < 0 ) { 801 if( des.find( id ) < 0 ) {
680 des += id + ","; 802 des += id + ",";
681 (*it).setNote( des ); 803 (*it).setNote( des );
682 } 804 }
683 } 805 }
684 } 806 }
685 807
686 } 808 }
687 } 809 }
688 810
689 if ( found ) 811 if ( found )
690 removeAddressee( it2 ); 812 removeAddressee( it2 );
691 813
692} 814}
693 815
694void AddressBook::removeSyncAddressees( bool removeDeleted ) 816void AddressBook::removeSyncAddressees( bool removeDeleted )
695{ 817{
696 Iterator it = begin(); 818 Iterator it = begin();
697 Iterator it2 ; 819 Iterator it2 ;
698 QDateTime dt ( QDate( 2004,1,1) ); 820 QDateTime dt ( QDate( 2004,1,1) );
699 while ( it != end() ) { 821 while ( it != end() ) {
700 (*it).setRevision( dt ); 822 (*it).setRevision( dt );
701 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 823 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
702 (*it).setIDStr(""); 824 (*it).setIDStr("");
703 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 825 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
704 it2 = it; 826 it2 = it;
705 //qDebug("removing %s ",(*it).uid().latin1() ); 827 //qDebug("removing %s ",(*it).uid().latin1() );
706 ++it; 828 ++it;
707 removeAddressee( it2 ); 829 removeAddressee( it2 );
708 } else { 830 } else {
709 //qDebug("skipping %s ",(*it).uid().latin1() ); 831 //qDebug("skipping %s ",(*it).uid().latin1() );
710 ++it; 832 ++it;
711 } 833 }
712 } 834 }
713 deleteRemovedAddressees(); 835 deleteRemovedAddressees();
714} 836}
715 837
716void AddressBook::removeAddressee( const Iterator &it ) 838void AddressBook::removeAddressee( const Iterator &it )
717{ 839{
718 d->mRemovedAddressees.append( (*it) ); 840 d->mRemovedAddressees.append( (*it) );
719 d->mAddressees.remove( it.d->mIt ); 841 d->mAddressees.remove( it.d->mIt );
720} 842}
721 843
722AddressBook::Iterator AddressBook::find( const Addressee &a ) 844AddressBook::Iterator AddressBook::find( const Addressee &a )
723{ 845{
724 Iterator it; 846 Iterator it;
725 for ( it = begin(); it != end(); ++it ) { 847 for ( it = begin(); it != end(); ++it ) {
726 if ( a.uid() == (*it).uid() ) { 848 if ( a.uid() == (*it).uid() ) {
727 return it; 849 return it;
728 } 850 }
729 } 851 }
730 return end(); 852 return end();
731} 853}
732 854
733Addressee AddressBook::findByUid( const QString &uid ) 855Addressee AddressBook::findByUid( const QString &uid )
734{ 856{
735 Iterator it; 857 Iterator it;
736 for ( it = begin(); it != end(); ++it ) { 858 for ( it = begin(); it != end(); ++it ) {
737 if ( uid == (*it).uid() ) { 859 if ( uid == (*it).uid() ) {
738 return *it; 860 return *it;
739 } 861 }
740 } 862 }
741 return Addressee(); 863 return Addressee();
742} 864}
743void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) 865void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
744{ 866{
745 //qDebug("AddressBook::preExternSync "); 867 //qDebug("AddressBook::preExternSync ");
746 AddressBook::Iterator it; 868 AddressBook::Iterator it;
747 for ( it = begin(); it != end(); ++it ) { 869 for ( it = begin(); it != end(); ++it ) {
748 (*it).setID( csd, (*it).externalUID() ); 870 (*it).setID( csd, (*it).externalUID() );
749 (*it).computeCsum( csd ); 871 (*it).computeCsum( csd );
750 } 872 }
751 mergeAB( aBook ,csd ); 873 mergeAB( aBook ,csd );
752} 874}
753void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 875void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
754{ 876{
755 //qDebug("AddressBook::postExternSync "); 877 //qDebug("AddressBook::postExternSync ");
756 AddressBook::Iterator it; 878 AddressBook::Iterator it;
757 for ( it = begin(); it != end(); ++it ) { 879 for ( it = begin(); it != end(); ++it ) {
758 // qDebug("check uid %s ", (*it).uid().latin1() ); 880 // qDebug("check uid %s ", (*it).uid().latin1() );
759 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 881 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
760 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 882 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
761 Addressee ad = aBook->findByUid( ( (*it).uid() )); 883 Addressee ad = aBook->findByUid( ( (*it).uid() ));
762 if ( ad.isEmpty() ) { 884 if ( ad.isEmpty() ) {
763 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 885 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
764 } else { 886 } else {
765 (*it).computeCsum( csd ); 887 (*it).computeCsum( csd );
766 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 888 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
767 ad.setID( csd, (*it).externalUID() ); 889 ad.setID( csd, (*it).externalUID() );
768 ad.setCsum( csd, (*it).getCsum( csd ) ); 890 ad.setCsum( csd, (*it).getCsum( csd ) );
769 aBook->insertAddressee( ad ); 891 aBook->insertAddressee( ad );
770 } 892 }
771 } 893 }
772 } 894 }
773} 895}
774 896
775bool AddressBook::containsExternalUid( const QString& uid ) 897bool AddressBook::containsExternalUid( const QString& uid )
776{ 898{
777 Iterator it; 899 Iterator it;
778 for ( it = begin(); it != end(); ++it ) { 900 for ( it = begin(); it != end(); ++it ) {
779 if ( uid == (*it).externalUID( ) ) 901 if ( uid == (*it).externalUID( ) )
780 return true; 902 return true;
781 } 903 }
782 return false; 904 return false;
783} 905}
784Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 906Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
785{ 907{
786 Iterator it; 908 Iterator it;
787 for ( it = begin(); it != end(); ++it ) { 909 for ( it = begin(); it != end(); ++it ) {
788 if ( uid == (*it).getID( profile ) ) 910 if ( uid == (*it).getID( profile ) )
789 return (*it); 911 return (*it);
790 } 912 }
791 return Addressee(); 913 return Addressee();
792} 914}
793void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) 915void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
794{ 916{
795 Iterator it; 917 Iterator it;
796 Addressee ad; 918 Addressee ad;
797 for ( it = begin(); it != end(); ++it ) { 919 for ( it = begin(); it != end(); ++it ) {
798 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 920 ad = aBook->findByExternUid( (*it).externalUID(), profile );
799 if ( !ad.isEmpty() ) { 921 if ( !ad.isEmpty() ) {
800 (*it).mergeContact( ad ); 922 (*it).mergeContact( ad );
801 } 923 }
802 } 924 }
803#if 0 925#if 0
804 // test only 926 // test only
805 for ( it = begin(); it != end(); ++it ) { 927 for ( it = begin(); it != end(); ++it ) {
806 928
807 qDebug("uid %s ", (*it).uid().latin1()); 929 qDebug("uid %s ", (*it).uid().latin1());
808 } 930 }
809#endif 931#endif
810} 932}
811 933
812#if 0 934#if 0
813Addressee::List AddressBook::getExternLastSyncAddressees() 935Addressee::List AddressBook::getExternLastSyncAddressees()
814{ 936{
815 Addressee::List results; 937 Addressee::List results;
816 938
817 Iterator it; 939 Iterator it;
818 for ( it = begin(); it != end(); ++it ) { 940 for ( it = begin(); it != end(); ++it ) {
819 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 941 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
820 if ( (*it).familyName().left(4) == "!E: " ) 942 if ( (*it).familyName().left(4) == "!E: " )
821 results.append( *it ); 943 results.append( *it );
822 } 944 }
823 } 945 }
824 946
825 return results; 947 return results;
826} 948}
827#endif 949#endif
828void AddressBook::resetTempSyncStat() 950void AddressBook::resetTempSyncStat()
829{ 951{
830 Iterator it; 952 Iterator it;
831 for ( it = begin(); it != end(); ++it ) { 953 for ( it = begin(); it != end(); ++it ) {
832 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 954 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
833 } 955 }
834 956
835} 957}
836 958
837QStringList AddressBook:: uidList() 959QStringList AddressBook:: uidList()
838{ 960{
839 QStringList results; 961 QStringList results;
840 Iterator it; 962 Iterator it;
841 for ( it = begin(); it != end(); ++it ) { 963 for ( it = begin(); it != end(); ++it ) {
842 results.append( (*it).uid() ); 964 results.append( (*it).uid() );
843 } 965 }
844 return results; 966 return results;
845} 967}
846 968
847 969
848Addressee::List AddressBook::allAddressees() 970Addressee::List AddressBook::allAddressees()
849{ 971{
850 return d->mAddressees; 972 return d->mAddressees;
851 973
852} 974}
853 975
854Addressee::List AddressBook::findByName( const QString &name ) 976Addressee::List AddressBook::findByName( const QString &name )
855{ 977{
856 Addressee::List results; 978 Addressee::List results;
857 979
858 Iterator it; 980 Iterator it;
859 for ( it = begin(); it != end(); ++it ) { 981 for ( it = begin(); it != end(); ++it ) {
860 if ( name == (*it).realName() ) { 982 if ( name == (*it).realName() ) {
861 results.append( *it ); 983 results.append( *it );
862 } 984 }
863 } 985 }
864 986
865 return results; 987 return results;
866} 988}
867 989
868Addressee::List AddressBook::findByEmail( const QString &email ) 990Addressee::List AddressBook::findByEmail( const QString &email )
869{ 991{
870 Addressee::List results; 992 Addressee::List results;
871 QStringList mailList; 993 QStringList mailList;
872 994
873 Iterator it; 995 Iterator it;
874 for ( it = begin(); it != end(); ++it ) { 996 for ( it = begin(); it != end(); ++it ) {
875 mailList = (*it).emails(); 997 mailList = (*it).emails();
876 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 998 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
877 if ( email == (*ite) ) { 999 if ( email == (*ite) ) {
878 results.append( *it ); 1000 results.append( *it );
879 } 1001 }
880 } 1002 }
881 } 1003 }
882 1004
883 return results; 1005 return results;
884} 1006}
885 1007
886Addressee::List AddressBook::findByCategory( const QString &category ) 1008Addressee::List AddressBook::findByCategory( const QString &category )
887{ 1009{
888 Addressee::List results; 1010 Addressee::List results;
889 1011
890 Iterator it; 1012 Iterator it;
891 for ( it = begin(); it != end(); ++it ) { 1013 for ( it = begin(); it != end(); ++it ) {
892 if ( (*it).hasCategory( category) ) { 1014 if ( (*it).hasCategory( category) ) {
893 results.append( *it ); 1015 results.append( *it );
894 } 1016 }
895 } 1017 }
896 1018
897 return results; 1019 return results;
898} 1020}
899 1021
900void AddressBook::dump() const 1022void AddressBook::dump() const
901{ 1023{
902 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1024 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
903 1025
904 ConstIterator it; 1026 ConstIterator it;
905 for( it = begin(); it != end(); ++it ) { 1027 for( it = begin(); it != end(); ++it ) {
906 (*it).dump(); 1028 (*it).dump();
907 } 1029 }
908 1030
909 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1031 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
910} 1032}
911 1033
912QString AddressBook::identifier() 1034QString AddressBook::identifier()
913{ 1035{
914 QStringList identifier; 1036 QStringList identifier;
915 1037
916 1038
917 KRES::Manager<Resource>::ActiveIterator it; 1039 KRES::Manager<Resource>::ActiveIterator it;
918 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1040 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
919 if ( !(*it)->identifier().isEmpty() ) 1041 if ( !(*it)->identifier().isEmpty() )
920 identifier.append( (*it)->identifier() ); 1042 identifier.append( (*it)->identifier() );
921 } 1043 }
922 1044
923 return identifier.join( ":" ); 1045 return identifier.join( ":" );
924} 1046}
925 1047
926Field::List AddressBook::fields( int category ) 1048Field::List AddressBook::fields( int category )
927{ 1049{
928 if ( d->mAllFields.isEmpty() ) { 1050 if ( d->mAllFields.isEmpty() ) {
929 d->mAllFields = Field::allFields(); 1051 d->mAllFields = Field::allFields();
930 } 1052 }
931 1053
932 if ( category == Field::All ) return d->mAllFields; 1054 if ( category == Field::All ) return d->mAllFields;
933 1055
934 Field::List result; 1056 Field::List result;
935 Field::List::ConstIterator it; 1057 Field::List::ConstIterator it;
936 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1058 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
937 if ( (*it)->category() & category ) result.append( *it ); 1059 if ( (*it)->category() & category ) result.append( *it );
938 } 1060 }
939 1061
940 return result; 1062 return result;
941} 1063}
942 1064
943bool AddressBook::addCustomField( const QString &label, int category, 1065bool AddressBook::addCustomField( const QString &label, int category,
944 const QString &key, const QString &app ) 1066 const QString &key, const QString &app )
945{ 1067{
946 if ( d->mAllFields.isEmpty() ) { 1068 if ( d->mAllFields.isEmpty() ) {
947 d->mAllFields = Field::allFields(); 1069 d->mAllFields = Field::allFields();
948 } 1070 }
949//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1071//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
950 QString a = app.isNull() ? KGlobal::getAppName() : app; 1072 QString a = app.isNull() ? KGlobal::getAppName() : app;
951 1073
952 QString k = key.isNull() ? label : key; 1074 QString k = key.isNull() ? label : key;
953 1075
954 Field *field = Field::createCustomField( label, category, k, a ); 1076 Field *field = Field::createCustomField( label, category, k, a );
955 1077
956 if ( !field ) return false; 1078 if ( !field ) return false;
957 1079
958 d->mAllFields.append( field ); 1080 d->mAllFields.append( field );
959 1081
960 return true; 1082 return true;
961} 1083}
962 1084
963QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1085QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
964{ 1086{
965 if (!ab.d) return s; 1087 if (!ab.d) return s;
966 1088
967 return s << ab.d->mAddressees; 1089 return s << ab.d->mAddressees;
968} 1090}
969 1091
970QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1092QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
971{ 1093{
972 if (!ab.d) return s; 1094 if (!ab.d) return s;
973 1095
974 s >> ab.d->mAddressees; 1096 s >> ab.d->mAddressees;
975 1097
976 return s; 1098 return s;
977} 1099}
978 1100
979bool AddressBook::addResource( Resource *resource ) 1101bool AddressBook::addResource( Resource *resource )
980{ 1102{
981 if ( !resource->open() ) { 1103 if ( !resource->open() ) {
982 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1104 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
983 return false; 1105 return false;
984 } 1106 }
985 1107
986 resource->setAddressBook( this ); 1108 resource->setAddressBook( this );
987 1109
988 d->mManager->add( resource ); 1110 d->mManager->add( resource );
989 return true; 1111 return true;
990} 1112}
991 1113
992bool AddressBook::removeResource( Resource *resource ) 1114bool AddressBook::removeResource( Resource *resource )
993{ 1115{
994 resource->close(); 1116 resource->close();
995 1117
996 if ( resource == standardResource() ) 1118 if ( resource == standardResource() )
997 d->mManager->setStandardResource( 0 ); 1119 d->mManager->setStandardResource( 0 );
998 1120
999 resource->setAddressBook( 0 ); 1121 resource->setAddressBook( 0 );
1000 1122
1001 d->mManager->remove( resource ); 1123 d->mManager->remove( resource );
1002 return true; 1124 return true;
1003} 1125}
1004 1126
1005QPtrList<Resource> AddressBook::resources() 1127QPtrList<Resource> AddressBook::resources()
1006{ 1128{
1007 QPtrList<Resource> list; 1129 QPtrList<Resource> list;
1008 1130
1009// qDebug("AddressBook::resources() 1"); 1131// qDebug("AddressBook::resources() 1");
1010 1132
1011 KRES::Manager<Resource>::ActiveIterator it; 1133 KRES::Manager<Resource>::ActiveIterator it;
1012 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1134 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1013 list.append( *it ); 1135 list.append( *it );
1014 1136
1015 return list; 1137 return list;
1016} 1138}
1017 1139
1018/*US 1140/*US
1019void AddressBook::setErrorHandler( ErrorHandler *handler ) 1141void AddressBook::setErrorHandler( ErrorHandler *handler )
1020{ 1142{
1021 delete d->mErrorHandler; 1143 delete d->mErrorHandler;
1022 d->mErrorHandler = handler; 1144 d->mErrorHandler = handler;
1023} 1145}
1024*/ 1146*/
1025 1147
1026void AddressBook::error( const QString& msg ) 1148void AddressBook::error( const QString& msg )
1027{ 1149{
1028/*US 1150/*US
1029 if ( !d->mErrorHandler ) // create default error handler 1151 if ( !d->mErrorHandler ) // create default error handler
1030 d->mErrorHandler = new ConsoleErrorHandler; 1152 d->mErrorHandler = new ConsoleErrorHandler;
1031 1153
1032 if ( d->mErrorHandler ) 1154 if ( d->mErrorHandler )
1033 d->mErrorHandler->error( msg ); 1155 d->mErrorHandler->error( msg );
1034 else 1156 else
1035 kdError(5700) << "no error handler defined" << endl; 1157 kdError(5700) << "no error handler defined" << endl;
1036*/ 1158*/
1037 kdDebug(5700) << "msg" << endl; 1159 kdDebug(5700) << "msg" << endl;
1038 qDebug(msg); 1160 qDebug(msg);
1039} 1161}
1040 1162
1041void AddressBook::deleteRemovedAddressees() 1163void AddressBook::deleteRemovedAddressees()
1042{ 1164{
1043 Addressee::List::Iterator it; 1165 Addressee::List::Iterator it;
1044 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1166 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1045 Resource *resource = (*it).resource(); 1167 Resource *resource = (*it).resource();
1046 if ( resource && !resource->readOnly() && resource->isOpen() ) 1168 if ( resource && !resource->readOnly() && resource->isOpen() )
1047 resource->removeAddressee( *it ); 1169 resource->removeAddressee( *it );
1048 } 1170 }
1049 1171
1050 d->mRemovedAddressees.clear(); 1172 d->mRemovedAddressees.clear();
1051} 1173}
1052 1174
1053void AddressBook::setStandardResource( Resource *resource ) 1175void AddressBook::setStandardResource( Resource *resource )
1054{ 1176{
1055// qDebug("AddressBook::setStandardResource 1"); 1177// qDebug("AddressBook::setStandardResource 1");
1056 d->mManager->setStandardResource( resource ); 1178 d->mManager->setStandardResource( resource );
1057} 1179}
1058 1180
1059Resource *AddressBook::standardResource() 1181Resource *AddressBook::standardResource()
1060{ 1182{
1061 return d->mManager->standardResource(); 1183 return d->mManager->standardResource();
1062} 1184}
1063 1185
1064KRES::Manager<Resource> *AddressBook::resourceManager() 1186KRES::Manager<Resource> *AddressBook::resourceManager()
1065{ 1187{
1066 return d->mManager; 1188 return d->mManager;
1067} 1189}
1068 1190
1069void AddressBook::cleanUp() 1191void AddressBook::cleanUp()
1070{ 1192{
1071 KRES::Manager<Resource>::ActiveIterator it; 1193 KRES::Manager<Resource>::ActiveIterator it;
1072 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1194 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1073 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1195 if ( !(*it)->readOnly() && (*it)->isOpen() )
1074 (*it)->cleanUp(); 1196 (*it)->cleanUp();
1075 } 1197 }
1076} 1198}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index cc755d1..df9048b 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,346 +1,348 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_ADDRESSBOOK_H 28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H 29#define KABC_ADDRESSBOOK_H
30 30
31#include <qobject.h> 31#include <qobject.h>
32 32
33#include <kresources/manager.h> 33#include <kresources/manager.h>
34#include <qptrlist.h> 34#include <qptrlist.h>
35 35
36#include "addressee.h" 36#include "addressee.h"
37#include "field.h" 37#include "field.h"
38 38
39namespace KABC { 39namespace KABC {
40 40
41class ErrorHandler; 41class ErrorHandler;
42class Resource; 42class Resource;
43class Ticket; 43class Ticket;
44 44
45/** 45/**
46 @short Address Book 46 @short Address Book
47 47
48 This class provides access to a collection of address book entries. 48 This class provides access to a collection of address book entries.
49*/ 49*/
50class AddressBook : public QObject 50class AddressBook : public QObject
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 friend QDataStream &operator<<( QDataStream &, const AddressBook & ); 54 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
55 friend QDataStream &operator>>( QDataStream &, AddressBook & ); 55 friend QDataStream &operator>>( QDataStream &, AddressBook & );
56 friend class StdAddressBook; 56 friend class StdAddressBook;
57 57
58 public: 58 public:
59 /** 59 /**
60 @short Address Book Iterator 60 @short Address Book Iterator
61 61
62 This class provides an iterator for address book entries. 62 This class provides an iterator for address book entries.
63 */ 63 */
64 class Iterator 64 class Iterator
65 { 65 {
66 public: 66 public:
67 Iterator(); 67 Iterator();
68 Iterator( const Iterator & ); 68 Iterator( const Iterator & );
69 ~Iterator(); 69 ~Iterator();
70 70
71 Iterator &operator=( const Iterator & ); 71 Iterator &operator=( const Iterator & );
72 const Addressee &operator*() const; 72 const Addressee &operator*() const;
73 Addressee &operator*(); 73 Addressee &operator*();
74 Addressee* operator->(); 74 Addressee* operator->();
75 Iterator &operator++(); 75 Iterator &operator++();
76 Iterator &operator++(int); 76 Iterator &operator++(int);
77 Iterator &operator--(); 77 Iterator &operator--();
78 Iterator &operator--(int); 78 Iterator &operator--(int);
79 bool operator==( const Iterator &it ); 79 bool operator==( const Iterator &it );
80 bool operator!=( const Iterator &it ); 80 bool operator!=( const Iterator &it );
81 81
82 struct IteratorData; 82 struct IteratorData;
83 IteratorData *d; 83 IteratorData *d;
84 }; 84 };
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 bool saveABphone( QString fileName ); 145 bool saveABphone( QString fileName );
146 void smplifyAddressees(); 146 void smplifyAddressees();
147 void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); 147 void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
148 void export2File( QString fileName ); 148 void export2File( QString fileName );
149 bool export2PhoneFormat( QStringList uids ,QString fileName );
149 void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); 150 void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
150 void setUntagged(); 151 void setUntagged();
151 void removeUntagged(); 152 void removeUntagged();
153 void findNewExtIds( QString fileName, QString currentSyncDevice );
152 /** 154 /**
153 Returns a iterator for first entry of address book. 155 Returns a iterator for first entry of address book.
154 */ 156 */
155 Iterator begin(); 157 Iterator begin();
156 158
157 /** 159 /**
158 Returns a const iterator for first entry of address book. 160 Returns a const iterator for first entry of address book.
159 */ 161 */
160 ConstIterator begin() const; 162 ConstIterator begin() const;
161 163
162 /** 164 /**
163 Returns a iterator for first entry of address book. 165 Returns a iterator for first entry of address book.
164 */ 166 */
165 Iterator end(); 167 Iterator end();
166 168
167 /** 169 /**
168 Returns a const iterator for first entry of address book. 170 Returns a const iterator for first entry of address book.
169 */ 171 */
170 ConstIterator end() const; 172 ConstIterator end() const;
171 173
172 /** 174 /**
173 Removes all entries from address book. 175 Removes all entries from address book.
174 */ 176 */
175 void clear(); 177 void clear();
176 178
177 /** 179 /**
178 Insert an Addressee object into address book. If an object with the same 180 Insert an Addressee object into address book. If an object with the same
179 unique id already exists in the address book it it replaced by the new 181 unique id already exists in the address book it it replaced by the new
180 one. If not the new object is appended to the address book. 182 one. If not the new object is appended to the address book.
181 */ 183 */
182 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 184 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
183 185
184 /** 186 /**
185 Removes entry from the address book. 187 Removes entry from the address book.
186 */ 188 */
187 void removeAddressee( const Addressee & ); 189 void removeAddressee( const Addressee & );
188 190
189 /** 191 /**
190 This is like @ref removeAddressee() just above, with the difference that 192 This is like @ref removeAddressee() just above, with the difference that
191 the first element is a iterator, returned by @ref begin(). 193 the first element is a iterator, returned by @ref begin().
192 */ 194 */
193 void removeAddressee( const Iterator & ); 195 void removeAddressee( const Iterator & );
194 196
195 /** 197 /**
196 Find the specified entry in address book. Returns end(), if the entry 198 Find the specified entry in address book. Returns end(), if the entry
197 couldn't be found. 199 couldn't be found.
198 */ 200 */
199 Iterator find( const Addressee & ); 201 Iterator find( const Addressee & );
200 202
201 /** 203 /**
202 Find the entry specified by an unique id. Returns an empty Addressee 204 Find the entry specified by an unique id. Returns an empty Addressee
203 object, if the address book does not contain an entry with this id. 205 object, if the address book does not contain an entry with this id.
204 */ 206 */
205 Addressee findByUid( const QString & ); 207 Addressee findByUid( const QString & );
206 208
207 209
208 /** 210 /**
209 Returns a list of all addressees in the address book. This list can 211 Returns a list of all addressees in the address book. This list can
210 be sorted with @ref KABC::AddresseeList for example. 212 be sorted with @ref KABC::AddresseeList for example.
211 */ 213 */
212 Addressee::List allAddressees(); 214 Addressee::List allAddressees();
213 215
214 /** 216 /**
215 Find all entries with the specified name in the address book. Returns 217 Find all entries with the specified name in the address book. Returns
216 an empty list, if no entries could be found. 218 an empty list, if no entries could be found.
217 */ 219 */
218 Addressee::List findByName( const QString & ); 220 Addressee::List findByName( const QString & );
219 221
220 /** 222 /**
221 Find all entries with the specified email address in the address book. 223 Find all entries with the specified email address in the address book.
222 Returns an empty list, if no entries could be found. 224 Returns an empty list, if no entries could be found.
223 */ 225 */
224 Addressee::List findByEmail( const QString & ); 226 Addressee::List findByEmail( const QString & );
225 227
226 /** 228 /**
227 Find all entries wich have the specified category in the address book. 229 Find all entries wich have the specified category in the address book.
228 Returns an empty list, if no entries could be found. 230 Returns an empty list, if no entries could be found.
229 */ 231 */
230 Addressee::List findByCategory( const QString & ); 232 Addressee::List findByCategory( const QString & );
231 233
232 /** 234 /**
233 Return a string identifying this addressbook. 235 Return a string identifying this addressbook.
234 */ 236 */
235 virtual QString identifier(); 237 virtual QString identifier();
236 238
237 /** 239 /**
238 Used for debug output. 240 Used for debug output.
239 */ 241 */
240 void dump() const; 242 void dump() const;
241 243
242 void emitAddressBookLocked() { emit addressBookLocked( this ); } 244 void emitAddressBookLocked() { emit addressBookLocked( this ); }
243 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 245 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
244 void emitAddressBookChanged() { emit addressBookChanged( this ); } 246 void emitAddressBookChanged() { emit addressBookChanged( this ); }
245 247
246 /** 248 /**
247 Return list of all Fields known to the address book which are associated 249 Return list of all Fields known to the address book which are associated
248 with the given field category. 250 with the given field category.
249 */ 251 */
250 Field::List fields( int category = Field::All ); 252 Field::List fields( int category = Field::All );
251 253
252 /** 254 /**
253 Add custom field to address book. 255 Add custom field to address book.
254 256
255 @param label User visible label of the field. 257 @param label User visible label of the field.
256 @param category Ored list of field categories. 258 @param category Ored list of field categories.
257 @param key Identifier used as key for reading and writing the field. 259 @param key Identifier used as key for reading and writing the field.
258 @param app String used as application key for reading and writing 260 @param app String used as application key for reading and writing
259 the field. 261 the field.
260 */ 262 */
261 bool addCustomField( const QString &label, int category = Field::All, 263 bool addCustomField( const QString &label, int category = Field::All,
262 const QString &key = QString::null, 264 const QString &key = QString::null,
263 const QString &app = QString::null ); 265 const QString &app = QString::null );
264 266
265 267
266 /** 268 /**
267 Add address book resource. 269 Add address book resource.
268 */ 270 */
269 bool addResource( Resource * ); 271 bool addResource( Resource * );
270 272
271 /** 273 /**
272 Remove address book resource. 274 Remove address book resource.
273 */ 275 */
274 bool removeResource( Resource * ); 276 bool removeResource( Resource * );
275 277
276 /** 278 /**
277 Return pointer list of all resources. 279 Return pointer list of all resources.
278 */ 280 */
279 QPtrList<Resource> resources(); 281 QPtrList<Resource> resources();
280 282
281 /** 283 /**
282 Set the @p ErrorHandler, that is used by @ref error() to 284 Set the @p ErrorHandler, that is used by @ref error() to
283 provide gui-independend error messages. 285 provide gui-independend error messages.
284 */ 286 */
285 void setErrorHandler( ErrorHandler * ); 287 void setErrorHandler( ErrorHandler * );
286 288
287 /** 289 /**
288 Shows gui independend error messages. 290 Shows gui independend error messages.
289 */ 291 */
290 void error( const QString& ); 292 void error( const QString& );
291 293
292 /** 294 /**
293 Query all resources to clean up their lock files 295 Query all resources to clean up their lock files
294 */ 296 */
295 void cleanUp(); 297 void cleanUp();
296 298
297 // sync stuff 299 // sync stuff
298 //Addressee::List getExternLastSyncAddressees(); 300 //Addressee::List getExternLastSyncAddressees();
299 void resetTempSyncStat(); 301 void resetTempSyncStat();
300 QStringList uidList(); 302 QStringList uidList();
301 void removeSyncAddressees( bool removeDeleted = false ); 303 void removeSyncAddressees( bool removeDeleted = false );
302 void mergeAB( AddressBook *aBook, const QString& profile ); 304 void mergeAB( AddressBook *aBook, const QString& profile );
303 Addressee findByExternUid( const QString& uid , const QString& profile ); 305 Addressee findByExternUid( const QString& uid , const QString& profile );
304 bool containsExternalUid( const QString& uid ); 306 bool containsExternalUid( const QString& uid );
305 307
306 void preExternSync( AddressBook* aBook, const QString& csd ); 308 void preExternSync( AddressBook* aBook, const QString& csd );
307 void postExternSync( AddressBook* aBook, const QString& csd ); 309 void postExternSync( AddressBook* aBook, const QString& csd );
308 signals: 310 signals:
309 /** 311 /**
310 Emitted, when the address book has changed on disk. 312 Emitted, when the address book has changed on disk.
311 */ 313 */
312 void addressBookChanged( AddressBook * ); 314 void addressBookChanged( AddressBook * );
313 315
314 /** 316 /**
315 Emitted, when the address book has been locked for writing. 317 Emitted, when the address book has been locked for writing.
316 */ 318 */
317 void addressBookLocked( AddressBook * ); 319 void addressBookLocked( AddressBook * );
318 320
319 /** 321 /**
320 Emitted, when the address book has been unlocked. 322 Emitted, when the address book has been unlocked.
321 */ 323 */
322 void addressBookUnlocked( AddressBook * ); 324 void addressBookUnlocked( AddressBook * );
323 325
324 protected: 326 protected:
325 void deleteRemovedAddressees(); 327 void deleteRemovedAddressees();
326 void setStandardResource( Resource * ); 328 void setStandardResource( Resource * );
327 Resource *standardResource(); 329 Resource *standardResource();
328 KRES::Manager<Resource> *resourceManager(); 330 KRES::Manager<Resource> *resourceManager();
329 331
330 void init(const QString &config, const QString &family); 332 void init(const QString &config, const QString &family);
331 333
332 private: 334 private:
333//US QPtrList<Resource> mDummy; // Remove in KDE 4 335//US QPtrList<Resource> mDummy; // Remove in KDE 4
334 336
335 337
336 struct AddressBookData; 338 struct AddressBookData;
337 AddressBookData *d; 339 AddressBookData *d;
338 bool blockLSEchange; 340 bool blockLSEchange;
339}; 341};
340 342
341QDataStream &operator<<( QDataStream &, const AddressBook & ); 343QDataStream &operator<<( QDataStream &, const AddressBook & );
342QDataStream &operator>>( QDataStream &, AddressBook & ); 344QDataStream &operator>>( QDataStream &, AddressBook & );
343 345
344} 346}
345 347
346#endif 348#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 607ae26..548305a 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,855 +1,895 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46static bool matchBinaryPatternA( int value, int pattern ); 46static bool matchBinaryPatternA( int value, int pattern );
47static bool matchBinaryPatternP( int value, int pattern ); 47static bool matchBinaryPatternP( int value, int pattern );
48 48
49struct Addressee::AddresseeData : public KShared 49struct Addressee::AddresseeData : public KShared
50{ 50{
51 QString uid; 51 QString uid;
52 QString name; 52 QString name;
53 QString formattedName; 53 QString formattedName;
54 QString familyName; 54 QString familyName;
55 QString givenName; 55 QString givenName;
56 QString additionalName; 56 QString additionalName;
57 QString prefix; 57 QString prefix;
58 QString suffix; 58 QString suffix;
59 QString nickName; 59 QString nickName;
60 QDateTime birthday; 60 QDateTime birthday;
61 QString mailer; 61 QString mailer;
62 TimeZone timeZone; 62 TimeZone timeZone;
63 Geo geo; 63 Geo geo;
64 QString title; 64 QString title;
65 QString role; 65 QString role;
66 QString organization; 66 QString organization;
67 QString note; 67 QString note;
68 QString productId; 68 QString productId;
69 QDateTime revision; 69 QDateTime revision;
70 QString sortString; 70 QString sortString;
71 QString externalUID; 71 QString externalUID;
72 QString originalExternalUID; 72 QString originalExternalUID;
73 KURL url; 73 KURL url;
74 Secrecy secrecy; 74 Secrecy secrecy;
75 Picture logo; 75 Picture logo;
76 Picture photo; 76 Picture photo;
77 Sound sound; 77 Sound sound;
78 Agent agent; 78 Agent agent;
79 QString mExternalId; 79 QString mExternalId;
80 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
81 Address::List addresses; 81 Address::List addresses;
82 Key::List keys; 82 Key::List keys;
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1; 91 bool tagged :1;
92}; 92};
93 93
94Addressee::Addressee() 94Addressee::Addressee()
95{ 95{
96 mData = new AddresseeData; 96 mData = new AddresseeData;
97 mData->empty = true; 97 mData->empty = true;
98 mData->changed = false; 98 mData->changed = false;
99 mData->resource = 0; 99 mData->resource = 0;
100 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
101 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
103} 103}
104 104
105Addressee::~Addressee() 105Addressee::~Addressee()
106{ 106{
107} 107}
108 108
109Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
110{ 110{
111 mData = a.mData; 111 mData = a.mData;
112} 112}
113 113
114Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
115{ 115{
116 mData = a.mData; 116 mData = a.mData;
117 return (*this); 117 return (*this);
118} 118}
119 119
120Addressee Addressee::copy() 120Addressee Addressee::copy()
121{ 121{
122 Addressee a; 122 Addressee a;
123 *(a.mData) = *mData; 123 *(a.mData) = *mData;
124 return a; 124 return a;
125} 125}
126 126
127void Addressee::detach() 127void Addressee::detach()
128{ 128{
129 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
130 *this = copy(); 130 *this = copy();
131} 131}
132 132
133bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
134{ 134{
135 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
136 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
137 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
138 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
139 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
140 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
141 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
142 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
143 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
144 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
145 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
146 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
147 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
148 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
149 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
150 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
151 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
152 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
153 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
154 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
155 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
156 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
157 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
158 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
159 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
161 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
163 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
164 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
165 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
166 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
167 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
168 168
169 return true; 169 return true;
170} 170}
171 171
172bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
173{ 173{
174 return !( a == *this ); 174 return !( a == *this );
175} 175}
176 176
177bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
178{ 178{
179 return mData->empty; 179 return mData->empty;
180} 180}
181ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
182{ 182{
183 int max = attList.count(); 183 int max = attList.count();
184 ulong cSum = 0; 184 ulong cSum = 0;
185 int j,k,i; 185 int j,k,i;
186 int add; 186 int add;
187 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
188 QString s = attList[i]; 188 QString s = attList[i];
189 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
190 j = s.length(); 190 j = s.length();
191 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
192 int mul = k +1; 192 int mul = k +1;
193 add = s[k].unicode (); 193 add = s[k].unicode ();
194 if ( k < 16 ) 194 if ( k < 16 )
195 mul = mul * mul; 195 mul = mul * mul;
196 int ii = i+1; 196 int ii = i+1;
197 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
198 cSum += add; 198 cSum += add;
199 } 199 }
200 } 200 }
201 201
202 } 202 }
203 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
204 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
205 205
206 return cSum; 206 return cSum;
207 207
208} 208}
209void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
210{ 210{
211 QStringList l; 211 QStringList l;
212 if ( !mData->name.isEmpty() ) l.append(mData->name); 212 if ( !mData->name.isEmpty() ) l.append(mData->name);
213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
216 if ( !mData->additionalName ) l.append( mData->additionalName ); 216 if ( !mData->additionalName ) l.append( mData->additionalName );
217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
224 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
225 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
226 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
227 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
228 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
231 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
232 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
233 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
234 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
235 //if ( mData->url.isValid() ) l.append( ); 235 //if ( mData->url.isValid() ) l.append( );
236#if 0 236#if 0
237 if ( !mData->phoneNumbers.isEmpty() ) l.append( ); 237 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
238 if ( !mData->addresses.isEmpty() ) l.append( ); 238 if ( !mData->addresses.isEmpty() ) l.append( );
239 //if ( !mData->keys.isEmpty() ) l.append( ); 239 //if ( !mData->keys.isEmpty() ) l.append( );
240 if ( !mData->emails.isEmpty() ) l.append( ); 240 if ( !mData->emails.isEmpty() ) l.append( );
241 if ( !mData->categories .isEmpty() ) l.append( ); 241 if ( !mData->categories .isEmpty() ) l.append( );
242 if ( !mData->custom.isEmpty() ) l.append( ); 242 if ( !mData->custom.isEmpty() ) l.append( );
243#endif 243#endif
244 KABC::PhoneNumber::List phoneNumbers; 244 KABC::PhoneNumber::List phoneNumbers;
245 KABC::PhoneNumber::List::Iterator phoneIter; 245 KABC::PhoneNumber::List::Iterator phoneIter;
246 246
247 QStringList t; 247 QStringList t;
248 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 248 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
249 ++phoneIter ) 249 ++phoneIter )
250 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 250 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
251 t.sort(); 251 t.sort();
252 uint iii; 252 uint iii;
253 for ( iii = 0; iii < t.count(); ++iii) 253 for ( iii = 0; iii < t.count(); ++iii)
254 l.append( t[iii] ); 254 l.append( t[iii] );
255 t = mData->emails; 255 t = mData->emails;
256 t.sort(); 256 t.sort();
257 for ( iii = 0; iii < t.count(); ++iii) 257 for ( iii = 0; iii < t.count(); ++iii)
258 l.append( t[iii] ); 258 l.append( t[iii] );
259 t = mData->categories; 259 t = mData->categories;
260 t.sort(); 260 t.sort();
261 for ( iii = 0; iii < t.count(); ++iii) 261 for ( iii = 0; iii < t.count(); ++iii)
262 l.append( t[iii] ); 262 l.append( t[iii] );
263 t = mData->custom; 263 t = mData->custom;
264 t.sort(); 264 t.sort();
265 for ( iii = 0; iii < t.count(); ++iii) 265 for ( iii = 0; iii < t.count(); ++iii)
266 l.append( t[iii] ); 266 l.append( t[iii] );
267 KABC::Address::List::Iterator addressIter; 267 KABC::Address::List::Iterator addressIter;
268 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 268 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
269 ++addressIter ) { 269 ++addressIter ) {
270 t = (*addressIter).asList(); 270 t = (*addressIter).asList();
271 t.sort(); 271 t.sort();
272 for ( iii = 0; iii < t.count(); ++iii) 272 for ( iii = 0; iii < t.count(); ++iii)
273 l.append( t[iii] ); 273 l.append( t[iii] );
274 } 274 }
275 uint cs = getCsum4List(l); 275 uint cs = getCsum4List(l);
276 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 276 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
277 setCsum( dev, QString::number (cs )); 277 setCsum( dev, QString::number (cs ));
278} 278}
279 279
280void Addressee::mergeContact( const Addressee& ad ) 280void Addressee::mergeContact( const Addressee& ad )
281{ 281{
282 282
283 detach(); 283 detach();
284 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 284 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
285 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 285 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
286 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 286 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
287 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 287 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
288 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 288 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
289 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 289 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
290 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 290 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
291 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 291 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
292 if ( !mData->birthday.isValid() ) 292 if ( !mData->birthday.isValid() )
293 if ( ad.mData->birthday.isValid()) 293 if ( ad.mData->birthday.isValid())
294 mData->birthday = ad.mData->birthday; 294 mData->birthday = ad.mData->birthday;
295 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 295 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
296 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 296 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
297 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 297 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
298 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 298 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
299 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 299 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
300 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 300 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
301 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 301 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
302 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 302 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
303 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 303 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
304 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 304 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
305 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 305 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
306 PhoneNumber::List phoneAD = phoneNumbers();
307 PhoneNumber::List::Iterator phoneItAD;
308 bool found = false;
309 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
306 310
311
312 }
307 // pending: 313 // pending:
308 // merging phonenumbers 314 // merging phonenumbers
309 // merging addresses 315 // merging addresses
310 // merging emails; 316 // merging emails;
311 // merging categories; 317 // merging categories;
312 // merging custom; 318 // merging custom;
313 // merging keys 319 // merging keys
314 qDebug("merge contact %s ", ad.uid().latin1()); 320 //qDebug("merge contact %s ", ad.uid().latin1());
315 setUid( ad.uid() ); 321 setUid( ad.uid() );
316 setRevision( ad.revision() ); 322 setRevision( ad.revision() );
317} 323}
318 324
319bool Addressee::removeVoice() 325bool Addressee::removeVoice()
320{ 326{
321 PhoneNumber::List phoneN = phoneNumbers(); 327 PhoneNumber::List phoneN = phoneNumbers();
322 PhoneNumber::List::Iterator phoneIt; 328 PhoneNumber::List::Iterator phoneIt;
323 bool found = false; 329 bool found = false;
324 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 330 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
325 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 331 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
326 if ((*phoneIt).type() - PhoneNumber::Voice ) { 332 if ((*phoneIt).type() - PhoneNumber::Voice ) {
327 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 333 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
328 insertPhoneNumber( (*phoneIt) ); 334 insertPhoneNumber( (*phoneIt) );
329 found = true; 335 found = true;
330 } 336 }
331 } 337 }
332 338
333 } 339 }
334 return found; 340 return found;
335} 341}
342
343bool Addressee::containsAdr(const Addressee& ad )
344{
345 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
346 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
347 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
348 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
349 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
350 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
351 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
352
353 // compare phone numbers
354 PhoneNumber::List phoneN = ad.phoneNumbers();
355 PhoneNumber::List::Iterator phoneIt;
356 bool found = false;
357 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
358 bool found = false;
359 PhoneNumber::List phoneL = ad.phoneNumbers();
360 PhoneNumber::List::Iterator phoneItL;
361 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
362 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
363 found = true;
364 break;
365 }
366 }
367 if ( ! found )
368 return false;
369 }
370 return true;
371
372}
336void Addressee::simplifyAddresses() 373void Addressee::simplifyAddresses()
337{ 374{
338 if ( mData->addresses.count() < 3 ) return ; 375 int max = 2;
376 if ( mData->url.isValid() )
377 max = 1;
378 if ( mData->addresses.count() <= max ) return ;
339 int count = 0; 379 int count = 0;
340 Address::List list; 380 Address::List list;
341 Address::List::Iterator it; 381 Address::List::Iterator it;
342 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 382 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
343 if ( count > 1 ) 383 if ( count >= max )
344 list.append( *it ); 384 list.append( *it );
345 ++count; 385 ++count;
346 } 386 }
347 for( it = list.begin(); it != list.end(); ++it ) { 387 for( it = list.begin(); it != list.end(); ++it ) {
348 removeAddress( (*it) ); 388 removeAddress( (*it) );
349 } 389 }
350} 390}
351 391
352// removes all emails but the first 392// removes all emails but the first
353// needed by phone sync 393// needed by phone sync
354void Addressee::simplifyEmails() 394void Addressee::simplifyEmails()
355{ 395{
356 if ( mData->emails.count() == 0 ) return ; 396 if ( mData->emails.count() == 0 ) return ;
357 QString email = mData->emails.first(); 397 QString email = mData->emails.first();
358 detach(); 398 detach();
359 mData->emails.clear(); 399 mData->emails.clear();
360 mData->emails.append( email ); 400 mData->emails.append( email );
361} 401}
362 402
363void Addressee::simplifyPhoneNumbers() 403void Addressee::simplifyPhoneNumbers()
364{ 404{
365 KABC::PhoneNumber::List removeNumbers; 405 KABC::PhoneNumber::List removeNumbers;
366 KABC::PhoneNumber::List::Iterator phoneIter; 406 KABC::PhoneNumber::List::Iterator phoneIter;
367 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 407 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
368 ++phoneIter ) { 408 ++phoneIter ) {
369 if ( ! ( *phoneIter ).simplifyNumber() ) 409 if ( ! ( *phoneIter ).simplifyNumber() )
370 removeNumbers.append( ( *phoneIter ) ); 410 removeNumbers.append( ( *phoneIter ) );
371 } 411 }
372 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 412 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
373 ++phoneIter ) { 413 ++phoneIter ) {
374 removePhoneNumber(( *phoneIter )); 414 removePhoneNumber(( *phoneIter ));
375 } 415 }
376} 416}
377void Addressee::simplifyPhoneNumberTypes() 417void Addressee::simplifyPhoneNumberTypes()
378{ 418{
379 KABC::PhoneNumber::List::Iterator phoneIter; 419 KABC::PhoneNumber::List::Iterator phoneIter;
380 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 420 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
381 ++phoneIter ) 421 ++phoneIter )
382 ( *phoneIter ).simplifyType(); 422 ( *phoneIter ).simplifyType();
383} 423}
384void Addressee::removeID(const QString &prof) 424void Addressee::removeID(const QString &prof)
385{ 425{
386 detach(); 426 detach();
387 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 427 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
388 428
389} 429}
390void Addressee::setID( const QString & prof , const QString & id ) 430void Addressee::setID( const QString & prof , const QString & id )
391{ 431{
392 detach(); 432 detach();
393 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 433 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
394 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 434 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
395} 435}
396void Addressee::setTempSyncStat( int id ) 436void Addressee::setTempSyncStat( int id )
397{ 437{
398 if ( mData->mTempSyncStat == id ) return; 438 if ( mData->mTempSyncStat == id ) return;
399 detach(); 439 detach();
400 mData->mTempSyncStat = id; 440 mData->mTempSyncStat = id;
401} 441}
402int Addressee::tempSyncStat() const 442int Addressee::tempSyncStat() const
403{ 443{
404 return mData->mTempSyncStat; 444 return mData->mTempSyncStat;
405} 445}
406 446
407QString Addressee::getID( const QString & prof) 447QString Addressee::getID( const QString & prof)
408{ 448{
409 return KIdManager::getId ( mData->mExternalId, prof ); 449 return KIdManager::getId ( mData->mExternalId, prof );
410} 450}
411 451
412void Addressee::setCsum( const QString & prof , const QString & id ) 452void Addressee::setCsum( const QString & prof , const QString & id )
413{ 453{
414 detach(); 454 detach();
415 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 455 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
416 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 456 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
417 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 457 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
418} 458}
419 459
420QString Addressee::getCsum( const QString & prof) 460QString Addressee::getCsum( const QString & prof)
421{ 461{
422 return KIdManager::getCsum ( mData->mExternalId, prof ); 462 return KIdManager::getCsum ( mData->mExternalId, prof );
423} 463}
424 464
425void Addressee::setIDStr( const QString & s ) 465void Addressee::setIDStr( const QString & s )
426{ 466{
427 detach(); 467 detach();
428 mData->mExternalId = s; 468 mData->mExternalId = s;
429} 469}
430 470
431QString Addressee::IDStr() const 471QString Addressee::IDStr() const
432{ 472{
433 return mData->mExternalId; 473 return mData->mExternalId;
434} 474}
435 475
436void Addressee::setExternalUID( const QString &id ) 476void Addressee::setExternalUID( const QString &id )
437{ 477{
438 if ( id == mData->externalUID ) return; 478 if ( id == mData->externalUID ) return;
439 detach(); 479 detach();
440 mData->empty = false; 480 mData->empty = false;
441 mData->externalUID = id; 481 mData->externalUID = id;
442} 482}
443 483
444QString Addressee::externalUID() const 484QString Addressee::externalUID() const
445{ 485{
446 return mData->externalUID; 486 return mData->externalUID;
447} 487}
448void Addressee::setOriginalExternalUID( const QString &id ) 488void Addressee::setOriginalExternalUID( const QString &id )
449{ 489{
450 if ( id == mData->originalExternalUID ) return; 490 if ( id == mData->originalExternalUID ) return;
451 detach(); 491 detach();
452 mData->empty = false; 492 mData->empty = false;
453 //qDebug("*******Set orig uid %s ", id.latin1()); 493 //qDebug("*******Set orig uid %s ", id.latin1());
454 mData->originalExternalUID = id; 494 mData->originalExternalUID = id;
455} 495}
456 496
457QString Addressee::originalExternalUID() const 497QString Addressee::originalExternalUID() const
458{ 498{
459 return mData->originalExternalUID; 499 return mData->originalExternalUID;
460} 500}
461 501
462void Addressee::setUid( const QString &id ) 502void Addressee::setUid( const QString &id )
463{ 503{
464 if ( id == mData->uid ) return; 504 if ( id == mData->uid ) return;
465 detach(); 505 detach();
466 //qDebug("****setuid %s ", id.latin1()); 506 //qDebug("****setuid %s ", id.latin1());
467 mData->empty = false; 507 mData->empty = false;
468 mData->uid = id; 508 mData->uid = id;
469} 509}
470 510
471QString Addressee::uid() const 511QString Addressee::uid() const
472{ 512{
473 if ( mData->uid.isEmpty() ) 513 if ( mData->uid.isEmpty() )
474 mData->uid = KApplication::randomString( 10 ); 514 mData->uid = KApplication::randomString( 10 );
475 515
476 return mData->uid; 516 return mData->uid;
477} 517}
478 518
479QString Addressee::uidLabel() 519QString Addressee::uidLabel()
480{ 520{
481 return i18n("Unique Identifier"); 521 return i18n("Unique Identifier");
482} 522}
483 523
484void Addressee::setName( const QString &name ) 524void Addressee::setName( const QString &name )
485{ 525{
486 if ( name == mData->name ) return; 526 if ( name == mData->name ) return;
487 detach(); 527 detach();
488 mData->empty = false; 528 mData->empty = false;
489 mData->name = name; 529 mData->name = name;
490} 530}
491 531
492QString Addressee::name() const 532QString Addressee::name() const
493{ 533{
494 return mData->name; 534 return mData->name;
495} 535}
496 536
497QString Addressee::nameLabel() 537QString Addressee::nameLabel()
498{ 538{
499 return i18n("Name"); 539 return i18n("Name");
500} 540}
501 541
502 542
503void Addressee::setFormattedName( const QString &formattedName ) 543void Addressee::setFormattedName( const QString &formattedName )
504{ 544{
505 if ( formattedName == mData->formattedName ) return; 545 if ( formattedName == mData->formattedName ) return;
506 detach(); 546 detach();
507 mData->empty = false; 547 mData->empty = false;
508 mData->formattedName = formattedName; 548 mData->formattedName = formattedName;
509} 549}
510 550
511QString Addressee::formattedName() const 551QString Addressee::formattedName() const
512{ 552{
513 return mData->formattedName; 553 return mData->formattedName;
514} 554}
515 555
516QString Addressee::formattedNameLabel() 556QString Addressee::formattedNameLabel()
517{ 557{
518 return i18n("Formatted Name"); 558 return i18n("Formatted Name");
519} 559}
520 560
521 561
522void Addressee::setFamilyName( const QString &familyName ) 562void Addressee::setFamilyName( const QString &familyName )
523{ 563{
524 if ( familyName == mData->familyName ) return; 564 if ( familyName == mData->familyName ) return;
525 detach(); 565 detach();
526 mData->empty = false; 566 mData->empty = false;
527 mData->familyName = familyName; 567 mData->familyName = familyName;
528} 568}
529 569
530QString Addressee::familyName() const 570QString Addressee::familyName() const
531{ 571{
532 return mData->familyName; 572 return mData->familyName;
533} 573}
534 574
535QString Addressee::familyNameLabel() 575QString Addressee::familyNameLabel()
536{ 576{
537 return i18n("Family Name"); 577 return i18n("Family Name");
538} 578}
539 579
540 580
541void Addressee::setGivenName( const QString &givenName ) 581void Addressee::setGivenName( const QString &givenName )
542{ 582{
543 if ( givenName == mData->givenName ) return; 583 if ( givenName == mData->givenName ) return;
544 detach(); 584 detach();
545 mData->empty = false; 585 mData->empty = false;
546 mData->givenName = givenName; 586 mData->givenName = givenName;
547} 587}
548 588
549QString Addressee::givenName() const 589QString Addressee::givenName() const
550{ 590{
551 return mData->givenName; 591 return mData->givenName;
552} 592}
553 593
554QString Addressee::givenNameLabel() 594QString Addressee::givenNameLabel()
555{ 595{
556 return i18n("Given Name"); 596 return i18n("Given Name");
557} 597}
558 598
559 599
560void Addressee::setAdditionalName( const QString &additionalName ) 600void Addressee::setAdditionalName( const QString &additionalName )
561{ 601{
562 if ( additionalName == mData->additionalName ) return; 602 if ( additionalName == mData->additionalName ) return;
563 detach(); 603 detach();
564 mData->empty = false; 604 mData->empty = false;
565 mData->additionalName = additionalName; 605 mData->additionalName = additionalName;
566} 606}
567 607
568QString Addressee::additionalName() const 608QString Addressee::additionalName() const
569{ 609{
570 return mData->additionalName; 610 return mData->additionalName;
571} 611}
572 612
573QString Addressee::additionalNameLabel() 613QString Addressee::additionalNameLabel()
574{ 614{
575 return i18n("Additional Names"); 615 return i18n("Additional Names");
576} 616}
577 617
578 618
579void Addressee::setPrefix( const QString &prefix ) 619void Addressee::setPrefix( const QString &prefix )
580{ 620{
581 if ( prefix == mData->prefix ) return; 621 if ( prefix == mData->prefix ) return;
582 detach(); 622 detach();
583 mData->empty = false; 623 mData->empty = false;
584 mData->prefix = prefix; 624 mData->prefix = prefix;
585} 625}
586 626
587QString Addressee::prefix() const 627QString Addressee::prefix() const
588{ 628{
589 return mData->prefix; 629 return mData->prefix;
590} 630}
591 631
592QString Addressee::prefixLabel() 632QString Addressee::prefixLabel()
593{ 633{
594 return i18n("Honorific Prefixes"); 634 return i18n("Honorific Prefixes");
595} 635}
596 636
597 637
598void Addressee::setSuffix( const QString &suffix ) 638void Addressee::setSuffix( const QString &suffix )
599{ 639{
600 if ( suffix == mData->suffix ) return; 640 if ( suffix == mData->suffix ) return;
601 detach(); 641 detach();
602 mData->empty = false; 642 mData->empty = false;
603 mData->suffix = suffix; 643 mData->suffix = suffix;
604} 644}
605 645
606QString Addressee::suffix() const 646QString Addressee::suffix() const
607{ 647{
608 return mData->suffix; 648 return mData->suffix;
609} 649}
610 650
611QString Addressee::suffixLabel() 651QString Addressee::suffixLabel()
612{ 652{
613 return i18n("Honorific Suffixes"); 653 return i18n("Honorific Suffixes");
614} 654}
615 655
616 656
617void Addressee::setNickName( const QString &nickName ) 657void Addressee::setNickName( const QString &nickName )
618{ 658{
619 if ( nickName == mData->nickName ) return; 659 if ( nickName == mData->nickName ) return;
620 detach(); 660 detach();
621 mData->empty = false; 661 mData->empty = false;
622 mData->nickName = nickName; 662 mData->nickName = nickName;
623} 663}
624 664
625QString Addressee::nickName() const 665QString Addressee::nickName() const
626{ 666{
627 return mData->nickName; 667 return mData->nickName;
628} 668}
629 669
630QString Addressee::nickNameLabel() 670QString Addressee::nickNameLabel()
631{ 671{
632 return i18n("Nick Name"); 672 return i18n("Nick Name");
633} 673}
634 674
635 675
636void Addressee::setBirthday( const QDateTime &birthday ) 676void Addressee::setBirthday( const QDateTime &birthday )
637{ 677{
638 if ( birthday == mData->birthday ) return; 678 if ( birthday == mData->birthday ) return;
639 detach(); 679 detach();
640 mData->empty = false; 680 mData->empty = false;
641 mData->birthday = birthday; 681 mData->birthday = birthday;
642} 682}
643 683
644QDateTime Addressee::birthday() const 684QDateTime Addressee::birthday() const
645{ 685{
646 return mData->birthday; 686 return mData->birthday;
647} 687}
648 688
649QString Addressee::birthdayLabel() 689QString Addressee::birthdayLabel()
650{ 690{
651 return i18n("Birthday"); 691 return i18n("Birthday");
652} 692}
653 693
654 694
655QString Addressee::homeAddressStreetLabel() 695QString Addressee::homeAddressStreetLabel()
656{ 696{
657 return i18n("Home Address Street"); 697 return i18n("Home Address Street");
658} 698}
659 699
660 700
661QString Addressee::homeAddressLocalityLabel() 701QString Addressee::homeAddressLocalityLabel()
662{ 702{
663 return i18n("Home Address Locality"); 703 return i18n("Home Address Locality");
664} 704}
665 705
666 706
667QString Addressee::homeAddressRegionLabel() 707QString Addressee::homeAddressRegionLabel()
668{ 708{
669 return i18n("Home Address Region"); 709 return i18n("Home Address Region");
670} 710}
671 711
672 712
673QString Addressee::homeAddressPostalCodeLabel() 713QString Addressee::homeAddressPostalCodeLabel()
674{ 714{
675 return i18n("Home Address Postal Code"); 715 return i18n("Home Address Postal Code");
676} 716}
677 717
678 718
679QString Addressee::homeAddressCountryLabel() 719QString Addressee::homeAddressCountryLabel()
680{ 720{
681 return i18n("Home Address Country"); 721 return i18n("Home Address Country");
682} 722}
683 723
684 724
685QString Addressee::homeAddressLabelLabel() 725QString Addressee::homeAddressLabelLabel()
686{ 726{
687 return i18n("Home Address Label"); 727 return i18n("Home Address Label");
688} 728}
689 729
690 730
691QString Addressee::businessAddressStreetLabel() 731QString Addressee::businessAddressStreetLabel()
692{ 732{
693 return i18n("Business Address Street"); 733 return i18n("Business Address Street");
694} 734}
695 735
696 736
697QString Addressee::businessAddressLocalityLabel() 737QString Addressee::businessAddressLocalityLabel()
698{ 738{
699 return i18n("Business Address Locality"); 739 return i18n("Business Address Locality");
700} 740}
701 741
702 742
703QString Addressee::businessAddressRegionLabel() 743QString Addressee::businessAddressRegionLabel()
704{ 744{
705 return i18n("Business Address Region"); 745 return i18n("Business Address Region");
706} 746}
707 747
708 748
709QString Addressee::businessAddressPostalCodeLabel() 749QString Addressee::businessAddressPostalCodeLabel()
710{ 750{
711 return i18n("Business Address Postal Code"); 751 return i18n("Business Address Postal Code");
712} 752}
713 753
714 754
715QString Addressee::businessAddressCountryLabel() 755QString Addressee::businessAddressCountryLabel()
716{ 756{
717 return i18n("Business Address Country"); 757 return i18n("Business Address Country");
718} 758}
719 759
720 760
721QString Addressee::businessAddressLabelLabel() 761QString Addressee::businessAddressLabelLabel()
722{ 762{
723 return i18n("Business Address Label"); 763 return i18n("Business Address Label");
724} 764}
725 765
726 766
727QString Addressee::homePhoneLabel() 767QString Addressee::homePhoneLabel()
728{ 768{
729 return i18n("Home Phone"); 769 return i18n("Home Phone");
730} 770}
731 771
732 772
733QString Addressee::businessPhoneLabel() 773QString Addressee::businessPhoneLabel()
734{ 774{
735 return i18n("Business Phone"); 775 return i18n("Business Phone");
736} 776}
737 777
738 778
739QString Addressee::mobilePhoneLabel() 779QString Addressee::mobilePhoneLabel()
740{ 780{
741 return i18n("Mobile Phone"); 781 return i18n("Mobile Phone");
742} 782}
743 783
744 784
745QString Addressee::homeFaxLabel() 785QString Addressee::homeFaxLabel()
746{ 786{
747 return i18n("Home Fax"); 787 return i18n("Home Fax");
748} 788}
749 789
750 790
751QString Addressee::businessFaxLabel() 791QString Addressee::businessFaxLabel()
752{ 792{
753 return i18n("Business Fax"); 793 return i18n("Business Fax");
754} 794}
755 795
756 796
757QString Addressee::carPhoneLabel() 797QString Addressee::carPhoneLabel()
758{ 798{
759 return i18n("Car Phone"); 799 return i18n("Car Phone");
760} 800}
761 801
762 802
763QString Addressee::isdnLabel() 803QString Addressee::isdnLabel()
764{ 804{
765 return i18n("ISDN"); 805 return i18n("ISDN");
766} 806}
767 807
768 808
769QString Addressee::pagerLabel() 809QString Addressee::pagerLabel()
770{ 810{
771 return i18n("Pager"); 811 return i18n("Pager");
772} 812}
773 813
774QString Addressee::sipLabel() 814QString Addressee::sipLabel()
775{ 815{
776 return i18n("SIP"); 816 return i18n("SIP");
777} 817}
778 818
779QString Addressee::emailLabel() 819QString Addressee::emailLabel()
780{ 820{
781 return i18n("Email Address"); 821 return i18n("Email Address");
782} 822}
783 823
784 824
785void Addressee::setMailer( const QString &mailer ) 825void Addressee::setMailer( const QString &mailer )
786{ 826{
787 if ( mailer == mData->mailer ) return; 827 if ( mailer == mData->mailer ) return;
788 detach(); 828 detach();
789 mData->empty = false; 829 mData->empty = false;
790 mData->mailer = mailer; 830 mData->mailer = mailer;
791} 831}
792 832
793QString Addressee::mailer() const 833QString Addressee::mailer() const
794{ 834{
795 return mData->mailer; 835 return mData->mailer;
796} 836}
797 837
798QString Addressee::mailerLabel() 838QString Addressee::mailerLabel()
799{ 839{
800 return i18n("Mail Client"); 840 return i18n("Mail Client");
801} 841}
802 842
803 843
804void Addressee::setTimeZone( const TimeZone &timeZone ) 844void Addressee::setTimeZone( const TimeZone &timeZone )
805{ 845{
806 if ( timeZone == mData->timeZone ) return; 846 if ( timeZone == mData->timeZone ) return;
807 detach(); 847 detach();
808 mData->empty = false; 848 mData->empty = false;
809 mData->timeZone = timeZone; 849 mData->timeZone = timeZone;
810} 850}
811 851
812TimeZone Addressee::timeZone() const 852TimeZone Addressee::timeZone() const
813{ 853{
814 return mData->timeZone; 854 return mData->timeZone;
815} 855}
816 856
817QString Addressee::timeZoneLabel() 857QString Addressee::timeZoneLabel()
818{ 858{
819 return i18n("Time Zone"); 859 return i18n("Time Zone");
820} 860}
821 861
822 862
823void Addressee::setGeo( const Geo &geo ) 863void Addressee::setGeo( const Geo &geo )
824{ 864{
825 if ( geo == mData->geo ) return; 865 if ( geo == mData->geo ) return;
826 detach(); 866 detach();
827 mData->empty = false; 867 mData->empty = false;
828 mData->geo = geo; 868 mData->geo = geo;
829} 869}
830 870
831Geo Addressee::geo() const 871Geo Addressee::geo() const
832{ 872{
833 return mData->geo; 873 return mData->geo;
834} 874}
835 875
836QString Addressee::geoLabel() 876QString Addressee::geoLabel()
837{ 877{
838 return i18n("Geographic Position"); 878 return i18n("Geographic Position");
839} 879}
840 880
841 881
842void Addressee::setTitle( const QString &title ) 882void Addressee::setTitle( const QString &title )
843{ 883{
844 if ( title == mData->title ) return; 884 if ( title == mData->title ) return;
845 detach(); 885 detach();
846 mData->empty = false; 886 mData->empty = false;
847 mData->title = title; 887 mData->title = title;
848} 888}
849 889
850QString Addressee::title() const 890QString Addressee::title() const
851{ 891{
852 return mData->title; 892 return mData->title;
853} 893}
854 894
855QString Addressee::titleLabel() 895QString Addressee::titleLabel()
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0aa2c51..03138f6 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -1,636 +1,637 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#ifndef KABC_ADDRESSEE_H 29#ifndef KABC_ADDRESSEE_H
30#define KABC_ADDRESSEE_H 30#define KABC_ADDRESSEE_H
31 31
32#include <qdatetime.h> 32#include <qdatetime.h>
33#include <qstring.h> 33#include <qstring.h>
34#include <qstringlist.h> 34#include <qstringlist.h>
35#include <qvaluelist.h> 35#include <qvaluelist.h>
36 36
37#include <ksharedptr.h> 37#include <ksharedptr.h>
38#include <kurl.h> 38#include <kurl.h>
39 39
40#include "address.h" 40#include "address.h"
41#include "agent.h" 41#include "agent.h"
42#include "geo.h" 42#include "geo.h"
43#include "key.h" 43#include "key.h"
44#include "phonenumber.h" 44#include "phonenumber.h"
45#include "picture.h" 45#include "picture.h"
46#include "secrecy.h" 46#include "secrecy.h"
47#include "sound.h" 47#include "sound.h"
48#include "timezone.h" 48#include "timezone.h"
49 49
50namespace KABC { 50namespace KABC {
51 51
52class Resource; 52class Resource;
53 53
54/** 54/**
55 @short address book entry 55 @short address book entry
56 56
57 This class represents an entry in the address book. 57 This class represents an entry in the address book.
58 58
59 The data of this class is implicitly shared. You can pass this class by value. 59 The data of this class is implicitly shared. You can pass this class by value.
60 60
61 If you need the name of a field for presenting it to the user you should use 61 If you need the name of a field for presenting it to the user you should use
62 the functions ending in Label(). They return a translated string which can be 62 the functions ending in Label(). They return a translated string which can be
63 used as label for the corresponding field. 63 used as label for the corresponding field.
64 64
65 About the name fields: 65 About the name fields:
66 66
67 givenName() is the first name and familyName() the last name. In some 67 givenName() is the first name and familyName() the last name. In some
68 countries the family name comes first, that's the reason for the 68 countries the family name comes first, that's the reason for the
69 naming. formattedName() is the full name with the correct formatting. 69 naming. formattedName() is the full name with the correct formatting.
70 It is used as an override, when the correct formatting can't be generated 70 It is used as an override, when the correct formatting can't be generated
71 from the other name fields automatically. 71 from the other name fields automatically.
72 72
73 realName() returns a fully formatted name(). It uses formattedName, if set, 73 realName() returns a fully formatted name(). It uses formattedName, if set,
74 otherwise it constucts the name from the name fields. As fallback, if 74 otherwise it constucts the name from the name fields. As fallback, if
75 nothing else is set it uses name(). 75 nothing else is set it uses name().
76 76
77 name() is the NAME type of RFC2426. It can be used as internal name for the 77 name() is the NAME type of RFC2426. It can be used as internal name for the
78 data enty, but shouldn't be used for displaying the data to the user. 78 data enty, but shouldn't be used for displaying the data to the user.
79 */ 79 */
80class Addressee 80class Addressee
81{ 81{
82 friend QDataStream &operator<<( QDataStream &, const Addressee & ); 82 friend QDataStream &operator<<( QDataStream &, const Addressee & );
83 friend QDataStream &operator>>( QDataStream &, Addressee & ); 83 friend QDataStream &operator>>( QDataStream &, Addressee & );
84 84
85 public: 85 public:
86 typedef QValueList<Addressee> List; 86 typedef QValueList<Addressee> List;
87 87
88 /** 88 /**
89 Construct an empty address book entry. 89 Construct an empty address book entry.
90 */ 90 */
91 Addressee(); 91 Addressee();
92 ~Addressee(); 92 ~Addressee();
93 93
94 Addressee( const Addressee & ); 94 Addressee( const Addressee & );
95 Addressee &operator=( const Addressee & ); 95 Addressee &operator=( const Addressee & );
96 96
97 bool operator==( const Addressee & ) const; 97 bool operator==( const Addressee & ) const;
98 bool operator!=( const Addressee & ) const; 98 bool operator!=( const Addressee & ) const;
99 // sync stuff 99 // sync stuff
100 void setTempSyncStat(int id); 100 void setTempSyncStat(int id);
101 int tempSyncStat() const; 101 int tempSyncStat() const;
102 void setIDStr( const QString & ); 102 void setIDStr( const QString & );
103 QString IDStr() const; 103 QString IDStr() const;
104 void setID( const QString &, const QString & ); 104 void setID( const QString &, const QString & );
105 QString getID( const QString & ); 105 QString getID( const QString & );
106 void setCsum( const QString &, const QString & ); 106 void setCsum( const QString &, const QString & );
107 QString getCsum( const QString & ); 107 QString getCsum( const QString & );
108 void removeID(const QString &); 108 void removeID(const QString &);
109 void computeCsum(const QString &dev); 109 void computeCsum(const QString &dev);
110 ulong getCsum4List( const QStringList & attList); 110 ulong getCsum4List( const QStringList & attList);
111 /** 111 /**
112 Return, if the address book entry is empty. 112 Return, if the address book entry is empty.
113 */ 113 */
114 bool isEmpty() const; 114 bool isEmpty() const;
115 void setExternalUID( const QString &id ); 115 void setExternalUID( const QString &id );
116 QString externalUID() const; 116 QString externalUID() const;
117 void setOriginalExternalUID( const QString &id ); 117 void setOriginalExternalUID( const QString &id );
118 QString originalExternalUID() const; 118 QString originalExternalUID() const;
119 void mergeContact( const Addressee& ad ); 119 void mergeContact( const Addressee& ad );
120 void simplifyEmails(); 120 void simplifyEmails();
121 void simplifyAddresses(); 121 void simplifyAddresses();
122 void simplifyPhoneNumbers(); 122 void simplifyPhoneNumbers();
123 void simplifyPhoneNumberTypes(); 123 void simplifyPhoneNumberTypes();
124 bool removeVoice(); 124 bool removeVoice();
125 bool containsAdr(const Addressee& addr );
125 126
126 /** 127 /**
127 Set unique identifier. 128 Set unique identifier.
128 */ 129 */
129 void setUid( const QString &uid ); 130 void setUid( const QString &uid );
130 /** 131 /**
131 Return unique identifier. 132 Return unique identifier.
132 */ 133 */
133 QString uid() const; 134 QString uid() const;
134 /** 135 /**
135 Return translated label for uid field. 136 Return translated label for uid field.
136 */ 137 */
137 static QString uidLabel(); 138 static QString uidLabel();
138 139
139 /** 140 /**
140 Set name. 141 Set name.
141 */ 142 */
142 void setName( const QString &name ); 143 void setName( const QString &name );
143 /** 144 /**
144 Return name. 145 Return name.
145 */ 146 */
146 QString name() const; 147 QString name() const;
147 /** 148 /**
148 Return translated label for name field. 149 Return translated label for name field.
149 */ 150 */
150 static QString nameLabel(); 151 static QString nameLabel();
151 152
152 /** 153 /**
153 Set formatted name. 154 Set formatted name.
154 */ 155 */
155 void setFormattedName( const QString &formattedName ); 156 void setFormattedName( const QString &formattedName );
156 /** 157 /**
157 Return formatted name. 158 Return formatted name.
158 */ 159 */
159 QString formattedName() const; 160 QString formattedName() const;
160 /** 161 /**
161 Return translated label for formattedName field. 162 Return translated label for formattedName field.
162 */ 163 */
163 static QString formattedNameLabel(); 164 static QString formattedNameLabel();
164 165
165 /** 166 /**
166 Set family name. 167 Set family name.
167 */ 168 */
168 void setFamilyName( const QString &familyName ); 169 void setFamilyName( const QString &familyName );
169 /** 170 /**
170 Return family name. 171 Return family name.
171 */ 172 */
172 QString familyName() const; 173 QString familyName() const;
173 /** 174 /**
174 Return translated label for familyName field. 175 Return translated label for familyName field.
175 */ 176 */
176 static QString familyNameLabel(); 177 static QString familyNameLabel();
177 178
178 /** 179 /**
179 Set given name. 180 Set given name.
180 */ 181 */
181 void setGivenName( const QString &givenName ); 182 void setGivenName( const QString &givenName );
182 /** 183 /**
183 Return given name. 184 Return given name.
184 */ 185 */
185 QString givenName() const; 186 QString givenName() const;
186 /** 187 /**
187 Return translated label for givenName field. 188 Return translated label for givenName field.
188 */ 189 */
189 static QString givenNameLabel(); 190 static QString givenNameLabel();
190 191
191 /** 192 /**
192 Set additional names. 193 Set additional names.
193 */ 194 */
194 void setAdditionalName( const QString &additionalName ); 195 void setAdditionalName( const QString &additionalName );
195 /** 196 /**
196 Return additional names. 197 Return additional names.
197 */ 198 */
198 QString additionalName() const; 199 QString additionalName() const;
199 /** 200 /**
200 Return translated label for additionalName field. 201 Return translated label for additionalName field.
201 */ 202 */
202 static QString additionalNameLabel(); 203 static QString additionalNameLabel();
203 204
204 /** 205 /**
205 Set honorific prefixes. 206 Set honorific prefixes.
206 */ 207 */
207 void setPrefix( const QString &prefix ); 208 void setPrefix( const QString &prefix );
208 /** 209 /**
209 Return honorific prefixes. 210 Return honorific prefixes.
210 */ 211 */
211 QString prefix() const; 212 QString prefix() const;
212 /** 213 /**
213 Return translated label for prefix field. 214 Return translated label for prefix field.
214 */ 215 */
215 static QString prefixLabel(); 216 static QString prefixLabel();
216 217
217 /** 218 /**
218 Set honorific suffixes. 219 Set honorific suffixes.
219 */ 220 */
220 void setSuffix( const QString &suffix ); 221 void setSuffix( const QString &suffix );
221 /** 222 /**
222 Return honorific suffixes. 223 Return honorific suffixes.
223 */ 224 */
224 QString suffix() const; 225 QString suffix() const;
225 /** 226 /**
226 Return translated label for suffix field. 227 Return translated label for suffix field.
227 */ 228 */
228 static QString suffixLabel(); 229 static QString suffixLabel();
229 230
230 /** 231 /**
231 Set nick name. 232 Set nick name.
232 */ 233 */
233 void setNickName( const QString &nickName ); 234 void setNickName( const QString &nickName );
234 /** 235 /**
235 Return nick name. 236 Return nick name.
236 */ 237 */
237 QString nickName() const; 238 QString nickName() const;
238 /** 239 /**
239 Return translated label for nickName field. 240 Return translated label for nickName field.
240 */ 241 */
241 static QString nickNameLabel(); 242 static QString nickNameLabel();
242 243
243 /** 244 /**
244 Set birthday. 245 Set birthday.
245 */ 246 */
246 void setBirthday( const QDateTime &birthday ); 247 void setBirthday( const QDateTime &birthday );
247 /** 248 /**
248 Return birthday. 249 Return birthday.
249 */ 250 */
250 QDateTime birthday() const; 251 QDateTime birthday() const;
251 /** 252 /**
252 Return translated label for birthday field. 253 Return translated label for birthday field.
253 */ 254 */
254 static QString birthdayLabel(); 255 static QString birthdayLabel();
255 256
256 /** 257 /**
257 Return translated label for homeAddressStreet field. 258 Return translated label for homeAddressStreet field.
258 */ 259 */
259 static QString homeAddressStreetLabel(); 260 static QString homeAddressStreetLabel();
260 261
261 /** 262 /**
262 Return translated label for homeAddressLocality field. 263 Return translated label for homeAddressLocality field.
263 */ 264 */
264 static QString homeAddressLocalityLabel(); 265 static QString homeAddressLocalityLabel();
265 266
266 /** 267 /**
267 Return translated label for homeAddressRegion field. 268 Return translated label for homeAddressRegion field.
268 */ 269 */
269 static QString homeAddressRegionLabel(); 270 static QString homeAddressRegionLabel();
270 271
271 /** 272 /**
272 Return translated label for homeAddressPostalCode field. 273 Return translated label for homeAddressPostalCode field.
273 */ 274 */
274 static QString homeAddressPostalCodeLabel(); 275 static QString homeAddressPostalCodeLabel();
275 276
276 /** 277 /**
277 Return translated label for homeAddressCountry field. 278 Return translated label for homeAddressCountry field.
278 */ 279 */
279 static QString homeAddressCountryLabel(); 280 static QString homeAddressCountryLabel();
280 281
281 /** 282 /**
282 Return translated label for homeAddressLabel field. 283 Return translated label for homeAddressLabel field.
283 */ 284 */
284 static QString homeAddressLabelLabel(); 285 static QString homeAddressLabelLabel();
285 286
286 /** 287 /**
287 Return translated label for businessAddressStreet field. 288 Return translated label for businessAddressStreet field.
288 */ 289 */
289 static QString businessAddressStreetLabel(); 290 static QString businessAddressStreetLabel();
290 291
291 /** 292 /**
292 Return translated label for businessAddressLocality field. 293 Return translated label for businessAddressLocality field.
293 */ 294 */
294 static QString businessAddressLocalityLabel(); 295 static QString businessAddressLocalityLabel();
295 296
296 /** 297 /**
297 Return translated label for businessAddressRegion field. 298 Return translated label for businessAddressRegion field.
298 */ 299 */
299 static QString businessAddressRegionLabel(); 300 static QString businessAddressRegionLabel();
300 301
301 /** 302 /**
302 Return translated label for businessAddressPostalCode field. 303 Return translated label for businessAddressPostalCode field.
303 */ 304 */
304 static QString businessAddressPostalCodeLabel(); 305 static QString businessAddressPostalCodeLabel();
305 306
306 /** 307 /**
307 Return translated label for businessAddressCountry field. 308 Return translated label for businessAddressCountry field.
308 */ 309 */
309 static QString businessAddressCountryLabel(); 310 static QString businessAddressCountryLabel();
310 311
311 /** 312 /**
312 Return translated label for businessAddressLabel field. 313 Return translated label for businessAddressLabel field.
313 */ 314 */
314 static QString businessAddressLabelLabel(); 315 static QString businessAddressLabelLabel();
315 316
316 /** 317 /**
317 Return translated label for homePhone field. 318 Return translated label for homePhone field.
318 */ 319 */
319 static QString homePhoneLabel(); 320 static QString homePhoneLabel();
320 321
321 /** 322 /**
322 Return translated label for businessPhone field. 323 Return translated label for businessPhone field.
323 */ 324 */
324 static QString businessPhoneLabel(); 325 static QString businessPhoneLabel();
325 326
326 /** 327 /**
327 Return translated label for mobilePhone field. 328 Return translated label for mobilePhone field.
328 */ 329 */
329 static QString mobilePhoneLabel(); 330 static QString mobilePhoneLabel();
330 331
331 /** 332 /**
332 Return translated label for homeFax field. 333 Return translated label for homeFax field.
333 */ 334 */
334 static QString homeFaxLabel(); 335 static QString homeFaxLabel();
335 336
336 /** 337 /**
337 Return translated label for businessFax field. 338 Return translated label for businessFax field.
338 */ 339 */
339 static QString businessFaxLabel(); 340 static QString businessFaxLabel();
340 341
341 /** 342 /**
342 Return translated label for carPhone field. 343 Return translated label for carPhone field.
343 */ 344 */
344 static QString carPhoneLabel(); 345 static QString carPhoneLabel();
345 346
346 /** 347 /**
347 Return translated label for isdn field. 348 Return translated label for isdn field.
348 */ 349 */
349 static QString isdnLabel(); 350 static QString isdnLabel();
350 351
351 /** 352 /**
352 Return translated label for pager field. 353 Return translated label for pager field.
353 */ 354 */
354 static QString pagerLabel(); 355 static QString pagerLabel();
355 356
356 /** 357 /**
357 Return translated label for sip field. 358 Return translated label for sip field.
358 */ 359 */
359 static QString sipLabel(); 360 static QString sipLabel();
360 361
361 /** 362 /**
362 Return translated label for email field. 363 Return translated label for email field.
363 */ 364 */
364 static QString emailLabel(); 365 static QString emailLabel();
365 366
366 /** 367 /**
367 Set mail client. 368 Set mail client.
368 */ 369 */
369 void setMailer( const QString &mailer ); 370 void setMailer( const QString &mailer );
370 /** 371 /**
371 Return mail client. 372 Return mail client.
372 */ 373 */
373 QString mailer() const; 374 QString mailer() const;
374 /** 375 /**
375 Return translated label for mailer field. 376 Return translated label for mailer field.
376 */ 377 */
377 static QString mailerLabel(); 378 static QString mailerLabel();
378 379
379 /** 380 /**
380 Set time zone. 381 Set time zone.
381 */ 382 */
382 void setTimeZone( const TimeZone &timeZone ); 383 void setTimeZone( const TimeZone &timeZone );
383 /** 384 /**
384 Return time zone. 385 Return time zone.
385 */ 386 */
386 TimeZone timeZone() const; 387 TimeZone timeZone() const;
387 /** 388 /**
388 Return translated label for timeZone field. 389 Return translated label for timeZone field.
389 */ 390 */
390 static QString timeZoneLabel(); 391 static QString timeZoneLabel();
391 392
392 /** 393 /**
393 Set geographic position. 394 Set geographic position.
394 */ 395 */
395 void setGeo( const Geo &geo ); 396 void setGeo( const Geo &geo );
396 /** 397 /**
397 Return geographic position. 398 Return geographic position.
398 */ 399 */
399 Geo geo() const; 400 Geo geo() const;
400 /** 401 /**
401 Return translated label for geo field. 402 Return translated label for geo field.
402 */ 403 */
403 static QString geoLabel(); 404 static QString geoLabel();
404 405
405 /** 406 /**
406 Set title. 407 Set title.
407 */ 408 */
408 void setTitle( const QString &title ); 409 void setTitle( const QString &title );
409 /** 410 /**
410 Return title. 411 Return title.
411 */ 412 */
412 QString title() const; 413 QString title() const;
413 /** 414 /**
414 Return translated label for title field. 415 Return translated label for title field.
415 */ 416 */
416 static QString titleLabel(); 417 static QString titleLabel();
417 418
418 /** 419 /**
419 Set role. 420 Set role.
420 */ 421 */
421 void setRole( const QString &role ); 422 void setRole( const QString &role );
422 /** 423 /**
423 Return role. 424 Return role.
424 */ 425 */
425 QString role() const; 426 QString role() const;
426 /** 427 /**
427 Return translated label for role field. 428 Return translated label for role field.
428 */ 429 */
429 static QString roleLabel(); 430 static QString roleLabel();
430 431
431 /** 432 /**
432 Set organization. 433 Set organization.
433 */ 434 */
434 void setOrganization( const QString &organization ); 435 void setOrganization( const QString &organization );
435 /** 436 /**
436 Return organization. 437 Return organization.
437 */ 438 */
438 QString organization() const; 439 QString organization() const;
439 /** 440 /**
440 Return translated label for organization field. 441 Return translated label for organization field.
441 */ 442 */
442 static QString organizationLabel(); 443 static QString organizationLabel();
443 444
444 /** 445 /**
445 Set note. 446 Set note.
446 */ 447 */
447 void setNote( const QString &note ); 448 void setNote( const QString &note );
448 /** 449 /**
449 Return note. 450 Return note.
450 */ 451 */
451 QString note() const; 452 QString note() const;
452 /** 453 /**
453 Return translated label for note field. 454 Return translated label for note field.
454 */ 455 */
455 static QString noteLabel(); 456 static QString noteLabel();
456 457
457 /** 458 /**
458 Set product identifier. 459 Set product identifier.
459 */ 460 */
460 void setProductId( const QString &productId ); 461 void setProductId( const QString &productId );
461 /** 462 /**
462 Return product identifier. 463 Return product identifier.
463 */ 464 */
464 QString productId() const; 465 QString productId() const;
465 /** 466 /**
466 Return translated label for productId field. 467 Return translated label for productId field.
467 */ 468 */
468 static QString productIdLabel(); 469 static QString productIdLabel();
469 470
470 /** 471 /**
471 Set revision date. 472 Set revision date.
472 */ 473 */
473 void setRevision( const QDateTime &revision ); 474 void setRevision( const QDateTime &revision );
474 /** 475 /**
475 Return revision date. 476 Return revision date.
476 */ 477 */
477 QDateTime revision() const; 478 QDateTime revision() const;
478 /** 479 /**
479 Return translated label for revision field. 480 Return translated label for revision field.
480 */ 481 */
481 static QString revisionLabel(); 482 static QString revisionLabel();
482 483
483 /** 484 /**
484 Set sort string. 485 Set sort string.
485 */ 486 */
486 void setSortString( const QString &sortString ); 487 void setSortString( const QString &sortString );
487 /** 488 /**
488 Return sort string. 489 Return sort string.
489 */ 490 */
490 QString sortString() const; 491 QString sortString() const;
491 /** 492 /**
492 Return translated label for sortString field. 493 Return translated label for sortString field.
493 */ 494 */
494 static QString sortStringLabel(); 495 static QString sortStringLabel();
495 496
496 /** 497 /**
497 Set URL. 498 Set URL.
498 */ 499 */
499 void setUrl( const KURL &url ); 500 void setUrl( const KURL &url );
500 /** 501 /**
501 Return URL. 502 Return URL.
502 */ 503 */
503 KURL url() const; 504 KURL url() const;
504 /** 505 /**
505 Return translated label for url field. 506 Return translated label for url field.
506 */ 507 */
507 static QString urlLabel(); 508 static QString urlLabel();
508 509
509 /** 510 /**
510 Set security class. 511 Set security class.
511 */ 512 */
512 void setSecrecy( const Secrecy &secrecy ); 513 void setSecrecy( const Secrecy &secrecy );
513 /** 514 /**
514 Return security class. 515 Return security class.
515 */ 516 */
516 Secrecy secrecy() const; 517 Secrecy secrecy() const;
517 /** 518 /**
518 Return translated label for secrecy field. 519 Return translated label for secrecy field.
519 */ 520 */
520 static QString secrecyLabel(); 521 static QString secrecyLabel();
521 522
522 /** 523 /**
523 Set logo. 524 Set logo.
524 */ 525 */
525 void setLogo( const Picture &logo ); 526 void setLogo( const Picture &logo );
526 /** 527 /**
527 Return logo. 528 Return logo.
528 */ 529 */
529 Picture logo() const; 530 Picture logo() const;
530 /** 531 /**
531 Return translated label for logo field. 532 Return translated label for logo field.
532 */ 533 */
533 static QString logoLabel(); 534 static QString logoLabel();
534 535
535 /** 536 /**
536 Set photo. 537 Set photo.
537 */ 538 */
538 void setPhoto( const Picture &photo ); 539 void setPhoto( const Picture &photo );
539 /** 540 /**
540 Return photo. 541 Return photo.
541 */ 542 */
542 Picture photo() const; 543 Picture photo() const;
543 /** 544 /**
544 Return translated label for photo field. 545 Return translated label for photo field.
545 */ 546 */
546 static QString photoLabel(); 547 static QString photoLabel();
547 548
548 /** 549 /**
549 Set sound. 550 Set sound.
550 */ 551 */
551 void setSound( const Sound &sound ); 552 void setSound( const Sound &sound );
552 /** 553 /**
553 Return sound. 554 Return sound.
554 */ 555 */
555 Sound sound() const; 556 Sound sound() const;
556 /** 557 /**
557 Return translated label for sound field. 558 Return translated label for sound field.
558 */ 559 */
559 static QString soundLabel(); 560 static QString soundLabel();
560 561
561 /** 562 /**
562 Set agent. 563 Set agent.
563 */ 564 */
564 void setAgent( const Agent &agent ); 565 void setAgent( const Agent &agent );
565 /** 566 /**
566 Return agent. 567 Return agent.
567 */ 568 */
568 Agent agent() const; 569 Agent agent() const;
569 /** 570 /**
570 Return translated label for agent field. 571 Return translated label for agent field.
571 */ 572 */
572 static QString agentLabel(); 573 static QString agentLabel();
573 574
574 /** 575 /**
575 Set name fields by parsing the given string and trying to associate the 576 Set name fields by parsing the given string and trying to associate the
576 parts of the string with according fields. This function should probably 577 parts of the string with according fields. This function should probably
577 be a bit more clever. 578 be a bit more clever.
578 */ 579 */
579 void setNameFromString( const QString & ); 580 void setNameFromString( const QString & );
580 581
581 /** 582 /**
582 Return the name of the addressee. This is calculated from all the name 583 Return the name of the addressee. This is calculated from all the name
583 fields. 584 fields.
584 */ 585 */
585 QString realName() const; 586 QString realName() const;
586 587
587 /** 588 /**
588 Return the name that consists of all name parts. 589 Return the name that consists of all name parts.
589 */ 590 */
590 QString assembledName() const; 591 QString assembledName() const;
591 592
592 /** 593 /**
593 Return email address including real name. 594 Return email address including real name.
594 595
595 @param email Email address to be used to construct the full email string. 596 @param email Email address to be used to construct the full email string.
596 If this is QString::null the preferred email address is used. 597 If this is QString::null the preferred email address is used.
597 */ 598 */
598 QString fullEmail( const QString &email=QString::null ) const; 599 QString fullEmail( const QString &email=QString::null ) const;
599 600
600 /** 601 /**
601 Insert an email address. If the email address already exists in this 602 Insert an email address. If the email address already exists in this
602 addressee it is not duplicated. 603 addressee it is not duplicated.
603 604
604 @param email Email address 605 @param email Email address
605 @param preferred Set to true, if this is the preferred email address of 606 @param preferred Set to true, if this is the preferred email address of
606 the addressee. 607 the addressee.
607 */ 608 */
608 void insertEmail( const QString &email, bool preferred=false ); 609 void insertEmail( const QString &email, bool preferred=false );
609 610
610 /** 611 /**
611 Remove email address. If the email address doesn't exist, nothing happens. 612 Remove email address. If the email address doesn't exist, nothing happens.
612 */ 613 */
613 void removeEmail( const QString &email ); 614 void removeEmail( const QString &email );
614 615
615 /** 616 /**
616 Return preferred email address. This is the first email address or the 617 Return preferred email address. This is the first email address or the
617 last one added with @ref insertEmail() with a set preferred parameter. 618 last one added with @ref insertEmail() with a set preferred parameter.
618 */ 619 */
619 QString preferredEmail() const; 620 QString preferredEmail() const;
620 621
621 /** 622 /**
622 Return list of all email addresses. 623 Return list of all email addresses.
623 */ 624 */
624 QStringList emails() const; 625 QStringList emails() const;
625 626
626 /** 627 /**
627 Set the emails to @param. 628 Set the emails to @param.
628 The first email address gets the preferred one! 629 The first email address gets the preferred one!
629 @param list The list of email addresses. 630 @param list The list of email addresses.
630 */ 631 */
631 void setEmails( const QStringList& list); 632 void setEmails( const QStringList& list);
632 633
633 /** 634 /**
634 Insert a phone number. If a phone number with the same id already exists 635 Insert a phone number. If a phone number with the same id already exists
635 in this addressee it is not duplicated. 636 in this addressee it is not duplicated.
636 */ 637 */
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index e5abc0e..6e94c7e 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,225 +1,223 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <kapplication.h> 28#include <kapplication.h>
29#include <klocale.h> 29#include <klocale.h>
30 30
31#include "phonenumber.h" 31#include "phonenumber.h"
32 32
33using namespace KABC; 33using namespace KABC;
34 34
35PhoneNumber::PhoneNumber() : 35PhoneNumber::PhoneNumber() :
36 mType( Home ) 36 mType( Home )
37{ 37{
38 init(); 38 init();
39} 39}
40 40
41PhoneNumber::PhoneNumber( const QString &number, int type ) : 41PhoneNumber::PhoneNumber( const QString &number, int type ) :
42 mType( type ), mNumber( number ) 42 mType( type ), mNumber( number )
43{ 43{
44 init(); 44 init();
45} 45}
46 46
47PhoneNumber::~PhoneNumber() 47PhoneNumber::~PhoneNumber()
48{ 48{
49} 49}
50 50
51void PhoneNumber::init() 51void PhoneNumber::init()
52{ 52{
53 mId = KApplication::randomString( 8 ); 53 mId = KApplication::randomString( 8 );
54} 54}
55 55
56bool PhoneNumber::operator==( const PhoneNumber &p ) const 56bool PhoneNumber::operator==( const PhoneNumber &p ) const
57{ 57{
58 if ( mNumber != p.mNumber ) return false; 58 if ( mNumber != p.mNumber ) return false;
59 if ( mType != p.mType ) return false; 59 if ( mType != p.mType ) return false;
60 60
61 return true; 61 return true;
62} 62}
63 63
64bool PhoneNumber::operator!=( const PhoneNumber &p ) const 64bool PhoneNumber::operator!=( const PhoneNumber &p ) const
65{ 65{
66 return !( p == *this ); 66 return !( p == *this );
67} 67}
68 68
69bool PhoneNumber::simplifyNumber() 69bool PhoneNumber::simplifyNumber()
70{ 70{
71 QString Number; 71 QString Number;
72 int i; 72 int i;
73 Number = mNumber.stripWhiteSpace (); 73 Number = mNumber.stripWhiteSpace ();
74 mNumber = ""; 74 mNumber = "";
75 if ( Number.at(0) == '+' )
76 mNumber += "+";
77 for ( i = 0; i < Number.length(); ++i) { 75 for ( i = 0; i < Number.length(); ++i) {
78 if ( Number.at(i).isDigit() ) 76 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' )
79 mNumber += Number.at(i); 77 mNumber += Number.at(i);
80 } 78 }
81 return ( mNumber.length() > 0 ); 79 return ( mNumber.length() > 0 );
82} 80}
83// make cellphone compatible 81// make cellphone compatible
84void PhoneNumber::simplifyType() 82void PhoneNumber::simplifyType()
85{ 83{
86 if ( mType & Fax ) mType = Fax; 84 if ( mType & Fax ) mType = Fax;
87 else if ( mType & Cell ) mType = Cell; 85 else if ( mType & Cell ) mType = Cell;
88 else if ( mType & Work ) mType = Work ; 86 else if ( mType & Work ) mType = Work ;
89 else if ( mType & Home ) mType = Home; 87 else if ( mType & Home ) mType = Home;
90 else mType = Pref; 88 else mType = Pref;
91} 89}
92void PhoneNumber::setId( const QString &id ) 90void PhoneNumber::setId( const QString &id )
93{ 91{
94 mId = id; 92 mId = id;
95} 93}
96 94
97QString PhoneNumber::id() const 95QString PhoneNumber::id() const
98{ 96{
99 return mId; 97 return mId;
100} 98}
101 99
102void PhoneNumber::setNumber( const QString &number ) 100void PhoneNumber::setNumber( const QString &number )
103{ 101{
104 mNumber = number; 102 mNumber = number;
105} 103}
106 104
107QString PhoneNumber::number() const 105QString PhoneNumber::number() const
108{ 106{
109 return mNumber; 107 return mNumber;
110} 108}
111 109
112void PhoneNumber::setType( int type ) 110void PhoneNumber::setType( int type )
113{ 111{
114 mType = type; 112 mType = type;
115} 113}
116 114
117int PhoneNumber::type() const 115int PhoneNumber::type() const
118{ 116{
119 return mType; 117 return mType;
120} 118}
121 119
122QString PhoneNumber::typeLabel() const 120QString PhoneNumber::typeLabel() const
123{ 121{
124 QString label; 122 QString label;
125 bool first = true; 123 bool first = true;
126 124
127 TypeList list = typeList(); 125 TypeList list = typeList();
128 126
129 TypeList::Iterator it; 127 TypeList::Iterator it;
130 for ( it = list.begin(); it != list.end(); ++it ) { 128 for ( it = list.begin(); it != list.end(); ++it ) {
131 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
132 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
133 if ( first ) 131 if ( first )
134 first = false; 132 first = false;
135 } 133 }
136 } 134 }
137 135
138 return label; 136 return label;
139} 137}
140 138
141QString PhoneNumber::label() const 139QString PhoneNumber::label() const
142{ 140{
143 return typeLabel( type() ); 141 return typeLabel( type() );
144} 142}
145 143
146PhoneNumber::TypeList PhoneNumber::typeList() 144PhoneNumber::TypeList PhoneNumber::typeList()
147{ 145{
148 TypeList list; 146 TypeList list;
149 147
150 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video 148 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
151 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip; 149 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip;
152 150
153 return list; 151 return list;
154} 152}
155 153
156QString PhoneNumber::label( int type ) 154QString PhoneNumber::label( int type )
157{ 155{
158 return typeLabel( type ); 156 return typeLabel( type );
159} 157}
160 158
161QString PhoneNumber::typeLabel( int type ) 159QString PhoneNumber::typeLabel( int type )
162{ 160{
163 QString typeString; 161 QString typeString;
164 162
165 if ((type & Home) == Home) 163 if ((type & Home) == Home)
166 typeString += i18n("Home"); 164 typeString += i18n("Home");
167 else if ((type & Work) == Work) 165 else if ((type & Work) == Work)
168 typeString += i18n("Work"); 166 typeString += i18n("Work");
169 167
170 if (!typeString.isEmpty()) 168 if (!typeString.isEmpty())
171 typeString += " "; 169 typeString += " ";
172 170
173 if ((type & Cell) == Cell) 171 if ((type & Cell) == Cell)
174 typeString += i18n("Mobile"); 172 typeString += i18n("Mobile");
175 else if ((type & Fax) == Fax) 173 else if ((type & Fax) == Fax)
176 typeString += i18n("Fax"); 174 typeString += i18n("Fax");
177 else if ((type & Msg) == Msg) 175 else if ((type & Msg) == Msg)
178 typeString += i18n("Messenger"); 176 typeString += i18n("Messenger");
179 else if ((type & Voice) == Voice) { 177 else if ((type & Voice) == Voice) {
180// add nothing in case of the Voice flag 178// add nothing in case of the Voice flag
181// typeString += i18n("Voice"); 179// typeString += i18n("Voice");
182 } 180 }
183 else if ((type & Video) == Video) 181 else if ((type & Video) == Video)
184 typeString += i18n("Video"); 182 typeString += i18n("Video");
185 else if ((type & Bbs) == Bbs) 183 else if ((type & Bbs) == Bbs)
186 typeString += i18n("Mailbox"); 184 typeString += i18n("Mailbox");
187 else if ((type & Modem) == Modem) 185 else if ((type & Modem) == Modem)
188 typeString += i18n("Modem"); 186 typeString += i18n("Modem");
189 else if ((type & Car) == Car) 187 else if ((type & Car) == Car)
190 typeString += i18n("Car"); 188 typeString += i18n("Car");
191 else if ((type & Isdn) == Isdn) 189 else if ((type & Isdn) == Isdn)
192 typeString += i18n("ISDN"); 190 typeString += i18n("ISDN");
193 else if ((type & Pcs) == Pcs) 191 else if ((type & Pcs) == Pcs)
194 typeString += i18n("PCS"); 192 typeString += i18n("PCS");
195 else if ((type & Pager) == Pager) 193 else if ((type & Pager) == Pager)
196 typeString += i18n("Pager"); 194 typeString += i18n("Pager");
197 else if ((type & Sip) == Sip) 195 else if ((type & Sip) == Sip)
198 typeString += i18n("SIP"); 196 typeString += i18n("SIP");
199 197
200 // add the prefered flag 198 // add the prefered flag
201 if (!typeString.isEmpty()) 199 if (!typeString.isEmpty())
202 typeString += " "; 200 typeString += " ";
203 201
204 if ((type & Pref) == Pref) 202 if ((type & Pref) == Pref)
205 typeString += i18n("(p)"); 203 typeString += i18n("(p)");
206 204
207 //if we still have no match, return "other" 205 //if we still have no match, return "other"
208 if (typeString.isEmpty()) 206 if (typeString.isEmpty())
209 return i18n("Other"); 207 return i18n("Other");
210 208
211 209
212 return typeString; 210 return typeString;
213} 211}
214 212
215QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) 213QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
216{ 214{
217 return s << phone.mId << phone.mType << phone.mNumber; 215 return s << phone.mId << phone.mType << phone.mNumber;
218} 216}
219 217
220QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) 218QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
221{ 219{
222 s >> phone.mId >> phone.mType >> phone.mNumber; 220 s >> phone.mId >> phone.mType >> phone.mNumber;
223 221
224 return s; 222 return s;
225} 223}
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index a7967cb..cd261f6 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,1276 +1,1221 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24/*s 24/*s
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include "kabcore.h" 31#include "kabcore.h"
32 32
33#include <stdaddressbook.h> 33#include <stdaddressbook.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kfiledialog.h> 35#include <kfiledialog.h>
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qlabel.h> 37#include <qlabel.h>
38#include <qregexp.h> 38#include <qregexp.h>
39#include <qlineedit.h> 39#include <qlineedit.h>
40#include <qcheckbox.h> 40#include <qcheckbox.h>
41#include <qpushbutton.h> 41#include <qpushbutton.h>
42#include <qprogressbar.h> 42#include <qprogressbar.h>
43#include <libkdepim/phoneaccess.h> 43#include <libkdepim/phoneaccess.h>
44 44
45#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
46#include <qclipboard.h> 46#include <qclipboard.h>
47#include <qdir.h> 47#include <qdir.h>
48#include <qfile.h> 48#include <qfile.h>
49#include <qapplicaton.h> 49#include <qapplicaton.h>
50#include <qprogressbar.h> 50#include <qprogressbar.h>
51#include <qlayout.h> 51#include <qlayout.h>
52#include <qregexp.h> 52#include <qregexp.h>
53#include <qvbox.h> 53#include <qvbox.h>
54#include <kabc/addresseelist.h> 54#include <kabc/addresseelist.h>
55#include <kabc/errorhandler.h> 55#include <kabc/errorhandler.h>
56#include <kabc/resource.h> 56#include <kabc/resource.h>
57#include <kabc/vcardconverter.h> 57#include <kabc/vcardconverter.h>
58#include <kapplication.h> 58#include <kapplication.h>
59#include <kactionclasses.h> 59#include <kactionclasses.h>
60#include <kcmultidialog.h> 60#include <kcmultidialog.h>
61#include <kdebug.h> 61#include <kdebug.h>
62#include <kdeversion.h> 62#include <kdeversion.h>
63#include <kkeydialog.h> 63#include <kkeydialog.h>
64#include <kmessagebox.h> 64#include <kmessagebox.h>
65#include <kprinter.h> 65#include <kprinter.h>
66#include <kprotocolinfo.h> 66#include <kprotocolinfo.h>
67#include <kresources/selectdialog.h> 67#include <kresources/selectdialog.h>
68#include <kstandarddirs.h> 68#include <kstandarddirs.h>
69#include <ktempfile.h> 69#include <ktempfile.h>
70#include <kxmlguiclient.h> 70#include <kxmlguiclient.h>
71#include <kaboutdata.h> 71#include <kaboutdata.h>
72#include <libkdepim/categoryselectdialog.h> 72#include <libkdepim/categoryselectdialog.h>
73 73
74#include "addresseeutil.h" 74#include "addresseeutil.h"
75#include "addresseeeditordialog.h" 75#include "addresseeeditordialog.h"
76#include "extensionmanager.h" 76#include "extensionmanager.h"
77#include "kstdaction.h" 77#include "kstdaction.h"
78#include "kaddressbookservice.h" 78#include "kaddressbookservice.h"
79#include "ldapsearchdialog.h" 79#include "ldapsearchdialog.h"
80#include "printing/printingwizard.h" 80#include "printing/printingwizard.h"
81#else // KAB_EMBEDDED 81#else // KAB_EMBEDDED
82 82
83#include <kapplication.h> 83#include <kapplication.h>
84#include "KDGanttMinimizeSplitter.h" 84#include "KDGanttMinimizeSplitter.h"
85#include "kaddressbookmain.h" 85#include "kaddressbookmain.h"
86#include "kactioncollection.h" 86#include "kactioncollection.h"
87#include "addresseedialog.h" 87#include "addresseedialog.h"
88//US 88//US
89#include <addresseeview.h> 89#include <addresseeview.h>
90 90
91#include <qapp.h> 91#include <qapp.h>
92#include <qmenubar.h> 92#include <qmenubar.h>
93//#include <qtoolbar.h> 93//#include <qtoolbar.h>
94#include <qmessagebox.h> 94#include <qmessagebox.h>
95#include <kdebug.h> 95#include <kdebug.h>
96#include <kiconloader.h> // needed for SmallIcon 96#include <kiconloader.h> // needed for SmallIcon
97#include <kresources/kcmkresources.h> 97#include <kresources/kcmkresources.h>
98#include <ktoolbar.h> 98#include <ktoolbar.h>
99 99
100 100
101//#include <qlabel.h> 101//#include <qlabel.h>
102 102
103 103
104#ifndef DESKTOP_VERSION 104#ifndef DESKTOP_VERSION
105#include <qpe/ir.h> 105#include <qpe/ir.h>
106#include <qpe/qpemenubar.h> 106#include <qpe/qpemenubar.h>
107#include <qtopia/qcopenvelope_qws.h> 107#include <qtopia/qcopenvelope_qws.h>
108#else 108#else
109 109
110#include <qmenubar.h> 110#include <qmenubar.h>
111#endif 111#endif
112 112
113#endif // KAB_EMBEDDED 113#endif // KAB_EMBEDDED
114#include "kcmconfigs/kcmkabconfig.h" 114#include "kcmconfigs/kcmkabconfig.h"
115#include "kcmconfigs/kcmkdepimconfig.h" 115#include "kcmconfigs/kcmkdepimconfig.h"
116#include "kpimglobalprefs.h" 116#include "kpimglobalprefs.h"
117#include "externalapphandler.h" 117#include "externalapphandler.h"
118 118
119 119
120#include <kresources/selectdialog.h> 120#include <kresources/selectdialog.h>
121#include <kmessagebox.h> 121#include <kmessagebox.h>
122 122
123#include <picture.h> 123#include <picture.h>
124#include <resource.h> 124#include <resource.h>
125 125
126//US#include <qsplitter.h> 126//US#include <qsplitter.h>
127#include <qmap.h> 127#include <qmap.h>
128#include <qdir.h> 128#include <qdir.h>
129#include <qfile.h> 129#include <qfile.h>
130#include <qvbox.h> 130#include <qvbox.h>
131#include <qlayout.h> 131#include <qlayout.h>
132#include <qclipboard.h> 132#include <qclipboard.h>
133#include <qtextstream.h> 133#include <qtextstream.h>
134 134
135#include <libkdepim/categoryselectdialog.h> 135#include <libkdepim/categoryselectdialog.h>
136#include <kabc/vcardconverter.h> 136#include <kabc/vcardconverter.h>
137 137
138 138
139#include "addresseeutil.h" 139#include "addresseeutil.h"
140#include "undocmds.h" 140#include "undocmds.h"
141#include "addresseeeditordialog.h" 141#include "addresseeeditordialog.h"
142#include "viewmanager.h" 142#include "viewmanager.h"
143#include "details/detailsviewcontainer.h" 143#include "details/detailsviewcontainer.h"
144#include "kabprefs.h" 144#include "kabprefs.h"
145#include "xxportmanager.h" 145#include "xxportmanager.h"
146#include "incsearchwidget.h" 146#include "incsearchwidget.h"
147#include "jumpbuttonbar.h" 147#include "jumpbuttonbar.h"
148#include "extensionmanager.h" 148#include "extensionmanager.h"
149#include "addresseeconfig.h" 149#include "addresseeconfig.h"
150#include <kcmultidialog.h> 150#include <kcmultidialog.h>
151 151
152#ifdef _WIN32_ 152#ifdef _WIN32_
153 153
154#include "kaimportoldialog.h" 154#include "kaimportoldialog.h"
155#else 155#else
156#include <unistd.h> 156#include <unistd.h>
157#endif 157#endif
158// sync includes 158// sync includes
159#include <libkdepim/ksyncprofile.h> 159#include <libkdepim/ksyncprofile.h>
160#include <libkdepim/ksyncprefsdialog.h> 160#include <libkdepim/ksyncprefsdialog.h>
161 161
162class KAex2phonePrefs : public QDialog 162class KAex2phonePrefs : public QDialog
163{ 163{
164 public: 164 public:
165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : 165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
166 QDialog( parent, name, true ) 166 QDialog( parent, name, true )
167 { 167 {
168 setCaption( i18n("Export to phone options") ); 168 setCaption( i18n("Export to phone options") );
169 QVBoxLayout* lay = new QVBoxLayout( this ); 169 QVBoxLayout* lay = new QVBoxLayout( this );
170 lay->setSpacing( 3 ); 170 lay->setSpacing( 3 );
171 lay->setMargin( 3 ); 171 lay->setMargin( 3 );
172 QLabel *lab; 172 QLabel *lab;
173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); 173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
174 lab->setAlignment (AlignHCenter ); 174 lab->setAlignment (AlignHCenter );
175 QHBox* temphb; 175 QHBox* temphb;
176 temphb = new QHBox( this ); 176 temphb = new QHBox( this );
177 new QLabel( i18n("I/O device: "), temphb ); 177 new QLabel( i18n("I/O device: "), temphb );
178 mPhoneDevice = new QLineEdit( temphb); 178 mPhoneDevice = new QLineEdit( temphb);
179 lay->addWidget( temphb ); 179 lay->addWidget( temphb );
180 temphb = new QHBox( this ); 180 temphb = new QHBox( this );
181 new QLabel( i18n("Connection: "), temphb ); 181 new QLabel( i18n("Connection: "), temphb );
182 mPhoneConnection = new QLineEdit( temphb); 182 mPhoneConnection = new QLineEdit( temphb);
183 lay->addWidget( temphb ); 183 lay->addWidget( temphb );
184 temphb = new QHBox( this ); 184 temphb = new QHBox( this );
185 new QLabel( i18n("Model(opt.): "), temphb ); 185 new QLabel( i18n("Model(opt.): "), temphb );
186 mPhoneModel = new QLineEdit( temphb); 186 mPhoneModel = new QLineEdit( temphb);
187 lay->addWidget( temphb ); 187 lay->addWidget( temphb );
188 mWriteToSim= new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); 188 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
189 lay->addWidget( mWriteToSim ); 189 // lay->addWidget( mWriteToSim );
190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); 190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
191 lab->setAlignment (AlignHCenter ); 191 lab->setAlignment (AlignHCenter );
192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
193 lay->addWidget( ok ); 193 lay->addWidget( ok );
194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
195 lay->addWidget( cancel ); 195 lay->addWidget( cancel );
196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
198 resize( 220, 240 ); 198 resize( 220, 240 );
199 199
200 } 200 }
201 201
202public: 202public:
203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; 203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
204 QCheckBox* mWriteToSim; 204 QCheckBox* mWriteToSim;
205}; 205};
206 206
207bool pasteWithNewUid = true; 207bool pasteWithNewUid = true;
208 208
209#ifdef KAB_EMBEDDED 209#ifdef KAB_EMBEDDED
210KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 210KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
211 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 211 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
212 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 212 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
213 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 213 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
214#else //KAB_EMBEDDED 214#else //KAB_EMBEDDED
215KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 215KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
216 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 216 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
217 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 217 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
218 mReadWrite( readWrite ), mModified( false ) 218 mReadWrite( readWrite ), mModified( false )
219#endif //KAB_EMBEDDED 219#endif //KAB_EMBEDDED
220{ 220{
221 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 221 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
222 // syncManager->setBlockSave(false); 222 // syncManager->setBlockSave(false);
223 mExtensionBarSplitter = 0; 223 mExtensionBarSplitter = 0;
224 mIsPart = !parent->inherits( "KAddressBookMain" ); 224 mIsPart = !parent->inherits( "KAddressBookMain" );
225 225
226 mAddressBook = KABC::StdAddressBook::self(); 226 mAddressBook = KABC::StdAddressBook::self();
227 KABC::StdAddressBook::setAutomaticSave( false ); 227 KABC::StdAddressBook::setAutomaticSave( false );
228 228
229#ifndef KAB_EMBEDDED 229#ifndef KAB_EMBEDDED
230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
231#endif //KAB_EMBEDDED 231#endif //KAB_EMBEDDED
232 232
233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
234 SLOT( addressBookChanged() ) ); 234 SLOT( addressBookChanged() ) );
235 235
236#if 0 236#if 0
237 // LP moved to addressbook init method 237 // LP moved to addressbook init method
238 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 238 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
239 "X-Department", "KADDRESSBOOK" ); 239 "X-Department", "KADDRESSBOOK" );
240 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, 240 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
241 "X-Profession", "KADDRESSBOOK" ); 241 "X-Profession", "KADDRESSBOOK" );
242 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 242 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
243 "X-AssistantsName", "KADDRESSBOOK" ); 243 "X-AssistantsName", "KADDRESSBOOK" );
244 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 244 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
245 "X-ManagersName", "KADDRESSBOOK" ); 245 "X-ManagersName", "KADDRESSBOOK" );
246 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 246 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
247 "X-SpousesName", "KADDRESSBOOK" ); 247 "X-SpousesName", "KADDRESSBOOK" );
248 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, 248 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
249 "X-Office", "KADDRESSBOOK" ); 249 "X-Office", "KADDRESSBOOK" );
250 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 250 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
251 "X-IMAddress", "KADDRESSBOOK" ); 251 "X-IMAddress", "KADDRESSBOOK" );
252 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 252 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
253 "X-Anniversary", "KADDRESSBOOK" ); 253 "X-Anniversary", "KADDRESSBOOK" );
254 254
255 //US added this field to become compatible with Opie/qtopia addressbook 255 //US added this field to become compatible with Opie/qtopia addressbook
256 // values can be "female" or "male" or "". An empty field represents undefined. 256 // values can be "female" or "male" or "". An empty field represents undefined.
257 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, 257 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
258 "X-Gender", "KADDRESSBOOK" ); 258 "X-Gender", "KADDRESSBOOK" );
259 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, 259 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal,
260 "X-Children", "KADDRESSBOOK" ); 260 "X-Children", "KADDRESSBOOK" );
261 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 261 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
262 "X-FreeBusyUrl", "KADDRESSBOOK" ); 262 "X-FreeBusyUrl", "KADDRESSBOOK" );
263#endif 263#endif
264 initGUI(); 264 initGUI();
265 265
266 mIncSearchWidget->setFocus(); 266 mIncSearchWidget->setFocus();
267 267
268 268
269 connect( mViewManager, SIGNAL( selected( const QString& ) ), 269 connect( mViewManager, SIGNAL( selected( const QString& ) ),
270 SLOT( setContactSelected( const QString& ) ) ); 270 SLOT( setContactSelected( const QString& ) ) );
271 connect( mViewManager, SIGNAL( executed( const QString& ) ), 271 connect( mViewManager, SIGNAL( executed( const QString& ) ),
272 SLOT( executeContact( const QString& ) ) ); 272 SLOT( executeContact( const QString& ) ) );
273 273
274 connect( mViewManager, SIGNAL( deleteRequest( ) ), 274 connect( mViewManager, SIGNAL( deleteRequest( ) ),
275 SLOT( deleteContacts( ) ) ); 275 SLOT( deleteContacts( ) ) );
276 connect( mViewManager, SIGNAL( modified() ), 276 connect( mViewManager, SIGNAL( modified() ),
277 SLOT( setModified() ) ); 277 SLOT( setModified() ) );
278 278
279 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); 279 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
280 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); 280 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) );
281 281
282 connect( mXXPortManager, SIGNAL( modified() ), 282 connect( mXXPortManager, SIGNAL( modified() ),
283 SLOT( setModified() ) ); 283 SLOT( setModified() ) );
284 284
285 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), 285 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
286 SLOT( incrementalSearch( const QString& ) ) ); 286 SLOT( incrementalSearch( const QString& ) ) );
287 connect( mIncSearchWidget, SIGNAL( fieldChanged() ), 287 connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
288 mJumpButtonBar, SLOT( recreateButtons() ) ); 288 mJumpButtonBar, SLOT( recreateButtons() ) );
289 289
290 connect( mDetails, SIGNAL( sendEmail( const QString& ) ), 290 connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
291 SLOT( sendMail( const QString& ) ) ); 291 SLOT( sendMail( const QString& ) ) );
292 292
293 293
294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&)));
295 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); 295 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)));
296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); 296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&)));
297 297
298 298
299#ifndef KAB_EMBEDDED 299#ifndef KAB_EMBEDDED
300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
301 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 301 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
302 302
303 connect( mDetails, SIGNAL( browse( const QString& ) ), 303 connect( mDetails, SIGNAL( browse( const QString& ) ),
304 SLOT( browse( const QString& ) ) ); 304 SLOT( browse( const QString& ) ) );
305 305
306 306
307 mAddressBookService = new KAddressBookService( this ); 307 mAddressBookService = new KAddressBookService( this );
308 308
309#endif //KAB_EMBEDDED 309#endif //KAB_EMBEDDED
310 mEditorDialog = 0; 310 mEditorDialog = 0;
311 createAddresseeEditorDialog( this ); 311 createAddresseeEditorDialog( this );
312 setModified( false ); 312 setModified( false );
313} 313}
314 314
315KABCore::~KABCore() 315KABCore::~KABCore()
316{ 316{
317 // save(); 317 // save();
318 //saveSettings(); 318 //saveSettings();
319 //KABPrefs::instance()->writeConfig(); 319 //KABPrefs::instance()->writeConfig();
320 delete AddresseeConfig::instance(); 320 delete AddresseeConfig::instance();
321 mAddressBook = 0; 321 mAddressBook = 0;
322 KABC::StdAddressBook::close(); 322 KABC::StdAddressBook::close();
323 323
324 delete syncManager; 324 delete syncManager;
325 325
326} 326}
327 327
328void KABCore::recieve( QString fn ) 328void KABCore::recieve( QString fn )
329{ 329{
330 //qDebug("KABCore::recieve "); 330 //qDebug("KABCore::recieve ");
331 mAddressBook->importFromFile( fn, true ); 331 mAddressBook->importFromFile( fn, true );
332 mViewManager->refreshView(); 332 mViewManager->refreshView();
333 topLevelWidget()->raise(); 333 topLevelWidget()->raise();
334} 334}
335void KABCore::restoreSettings() 335void KABCore::restoreSettings()
336{ 336{
337 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 337 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
338 338
339 bool state; 339 bool state;
340 340
341 if (mMultipleViewsAtOnce) 341 if (mMultipleViewsAtOnce)
342 state = KABPrefs::instance()->mDetailsPageVisible; 342 state = KABPrefs::instance()->mDetailsPageVisible;
343 else 343 else
344 state = false; 344 state = false;
345 345
346 mActionDetails->setChecked( state ); 346 mActionDetails->setChecked( state );
347 setDetailsVisible( state ); 347 setDetailsVisible( state );
348 348
349 state = KABPrefs::instance()->mJumpButtonBarVisible; 349 state = KABPrefs::instance()->mJumpButtonBarVisible;
350 350
351 mActionJumpBar->setChecked( state ); 351 mActionJumpBar->setChecked( state );
352 setJumpButtonBarVisible( state ); 352 setJumpButtonBarVisible( state );
353/*US 353/*US
354 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 354 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
355 if ( splitterSize.count() == 0 ) { 355 if ( splitterSize.count() == 0 ) {
356 splitterSize.append( width() / 2 ); 356 splitterSize.append( width() / 2 );
357 splitterSize.append( width() / 2 ); 357 splitterSize.append( width() / 2 );
358 } 358 }
359 mMiniSplitter->setSizes( splitterSize ); 359 mMiniSplitter->setSizes( splitterSize );
360 if ( mExtensionBarSplitter ) { 360 if ( mExtensionBarSplitter ) {
361 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 361 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
362 if ( splitterSize.count() == 0 ) { 362 if ( splitterSize.count() == 0 ) {
363 splitterSize.append( width() / 2 ); 363 splitterSize.append( width() / 2 );
364 splitterSize.append( width() / 2 ); 364 splitterSize.append( width() / 2 );
365 } 365 }
366 mExtensionBarSplitter->setSizes( splitterSize ); 366 mExtensionBarSplitter->setSizes( splitterSize );
367 367
368 } 368 }
369*/ 369*/
370 mViewManager->restoreSettings(); 370 mViewManager->restoreSettings();
371 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 371 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
372 mExtensionManager->restoreSettings(); 372 mExtensionManager->restoreSettings();
373#ifdef DESKTOP_VERSION 373#ifdef DESKTOP_VERSION
374 int wid = width(); 374 int wid = width();
375 if ( wid < 10 ) 375 if ( wid < 10 )
376 wid = 400; 376 wid = 400;
377#else 377#else
378 int wid = QApplication::desktop()->width(); 378 int wid = QApplication::desktop()->width();
379 if ( wid < 640 ) 379 if ( wid < 640 )
380 wid = QApplication::desktop()->height(); 380 wid = QApplication::desktop()->height();
381#endif 381#endif
382 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 382 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
383 if ( true /*splitterSize.count() == 0*/ ) { 383 if ( true /*splitterSize.count() == 0*/ ) {
384 splitterSize.append( wid / 2 ); 384 splitterSize.append( wid / 2 );
385 splitterSize.append( wid / 2 ); 385 splitterSize.append( wid / 2 );
386 } 386 }
387 mMiniSplitter->setSizes( splitterSize ); 387 mMiniSplitter->setSizes( splitterSize );
388 if ( mExtensionBarSplitter ) { 388 if ( mExtensionBarSplitter ) {
389 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 389 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
390 if ( true /*splitterSize.count() == 0*/ ) { 390 if ( true /*splitterSize.count() == 0*/ ) {
391 splitterSize.append( wid / 2 ); 391 splitterSize.append( wid / 2 );
392 splitterSize.append( wid / 2 ); 392 splitterSize.append( wid / 2 );
393 } 393 }
394 mExtensionBarSplitter->setSizes( splitterSize ); 394 mExtensionBarSplitter->setSizes( splitterSize );
395 395
396 } 396 }
397 397
398 398
399} 399}
400 400
401void KABCore::saveSettings() 401void KABCore::saveSettings()
402{ 402{
403 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 403 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
404 if ( mExtensionBarSplitter ) 404 if ( mExtensionBarSplitter )
405 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 405 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
406 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 406 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
407 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 407 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
408#ifndef KAB_EMBEDDED 408#ifndef KAB_EMBEDDED
409 409
410 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 410 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
411 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 411 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
412#endif //KAB_EMBEDDED 412#endif //KAB_EMBEDDED
413 mExtensionManager->saveSettings(); 413 mExtensionManager->saveSettings();
414 mViewManager->saveSettings(); 414 mViewManager->saveSettings();
415 415
416 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 416 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
417} 417}
418 418
419KABC::AddressBook *KABCore::addressBook() const 419KABC::AddressBook *KABCore::addressBook() const
420{ 420{
421 return mAddressBook; 421 return mAddressBook;
422} 422}
423 423
424KConfig *KABCore::config() 424KConfig *KABCore::config()
425{ 425{
426#ifndef KAB_EMBEDDED 426#ifndef KAB_EMBEDDED
427 return KABPrefs::instance()->config(); 427 return KABPrefs::instance()->config();
428#else //KAB_EMBEDDED 428#else //KAB_EMBEDDED
429 return KABPrefs::instance()->getConfig(); 429 return KABPrefs::instance()->getConfig();
430#endif //KAB_EMBEDDED 430#endif //KAB_EMBEDDED
431} 431}
432 432
433KActionCollection *KABCore::actionCollection() const 433KActionCollection *KABCore::actionCollection() const
434{ 434{
435 return mGUIClient->actionCollection(); 435 return mGUIClient->actionCollection();
436} 436}
437 437
438KABC::Field *KABCore::currentSearchField() const 438KABC::Field *KABCore::currentSearchField() const
439{ 439{
440 if (mIncSearchWidget) 440 if (mIncSearchWidget)
441 return mIncSearchWidget->currentField(); 441 return mIncSearchWidget->currentField();
442 else 442 else
443 return 0; 443 return 0;
444} 444}
445 445
446QStringList KABCore::selectedUIDs() const 446QStringList KABCore::selectedUIDs() const
447{ 447{
448 return mViewManager->selectedUids(); 448 return mViewManager->selectedUids();
449} 449}
450 450
451KABC::Resource *KABCore::requestResource( QWidget *parent ) 451KABC::Resource *KABCore::requestResource( QWidget *parent )
452{ 452{
453 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 453 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
454 454
455 QPtrList<KRES::Resource> kresResources; 455 QPtrList<KRES::Resource> kresResources;
456 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 456 QPtrListIterator<KABC::Resource> resIt( kabcResources );
457 KABC::Resource *resource; 457 KABC::Resource *resource;
458 while ( ( resource = resIt.current() ) != 0 ) { 458 while ( ( resource = resIt.current() ) != 0 ) {
459 ++resIt; 459 ++resIt;
460 if ( !resource->readOnly() ) { 460 if ( !resource->readOnly() ) {
461 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 461 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
462 if ( res ) 462 if ( res )
463 kresResources.append( res ); 463 kresResources.append( res );
464 } 464 }
465 } 465 }
466 466
467 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 467 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
468 return static_cast<KABC::Resource*>( res ); 468 return static_cast<KABC::Resource*>( res );
469} 469}
470 470
471#ifndef KAB_EMBEDDED 471#ifndef KAB_EMBEDDED
472KAboutData *KABCore::createAboutData() 472KAboutData *KABCore::createAboutData()
473#else //KAB_EMBEDDED 473#else //KAB_EMBEDDED
474void KABCore::createAboutData() 474void KABCore::createAboutData()
475#endif //KAB_EMBEDDED 475#endif //KAB_EMBEDDED
476{ 476{
477#ifndef KAB_EMBEDDED 477#ifndef KAB_EMBEDDED
478 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), 478 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
479 "3.1", I18N_NOOP( "The KDE Address Book" ), 479 "3.1", I18N_NOOP( "The KDE Address Book" ),
480 KAboutData::License_GPL_V2, 480 KAboutData::License_GPL_V2,
481 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); 481 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
482 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); 482 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
483 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); 483 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
484 about->addAuthor( "Cornelius Schumacher", 484 about->addAuthor( "Cornelius Schumacher",
485 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), 485 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
486 "schumacher@kde.org" ); 486 "schumacher@kde.org" );
487 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), 487 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
488 "mpilone@slac.com" ); 488 "mpilone@slac.com" );
489 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); 489 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
490 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); 490 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
491 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), 491 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
492 "michel@klaralvdalens-datakonsult.se" ); 492 "michel@klaralvdalens-datakonsult.se" );
493 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), 493 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
494 "hansen@kde.org" ); 494 "hansen@kde.org" );
495 495
496 return about; 496 return about;
497#endif //KAB_EMBEDDED 497#endif //KAB_EMBEDDED
498 498
499 QString version; 499 QString version;
500#include <../version> 500#include <../version>
501 QMessageBox::about( this, "About KAddressbook/Pi", 501 QMessageBox::about( this, "About KAddressbook/Pi",
502 "KAddressbook/Platform-independent\n" 502 "KAddressbook/Platform-independent\n"
503 "(KA/Pi) " +version + " - " + 503 "(KA/Pi) " +version + " - " +
504#ifdef DESKTOP_VERSION 504#ifdef DESKTOP_VERSION
505 "Desktop Edition\n" 505 "Desktop Edition\n"
506#else 506#else
507 "PDA-Edition\n" 507 "PDA-Edition\n"
508 "for: Zaurus 5500 / 7x0 / 8x0\n" 508 "for: Zaurus 5500 / 7x0 / 8x0\n"
509#endif 509#endif
510 510
511 "(c) 2004 Ulf Schenk\n" 511 "(c) 2004 Ulf Schenk\n"
512 "(c) 2004 Lutz Rogowski\n" 512 "(c) 2004 Lutz Rogowski\n"
513 "(c) 1997-2003, The KDE PIM Team\n" 513 "(c) 1997-2003, The KDE PIM Team\n"
514 "Tobias Koenig Current maintainer\ntokoe@kde.org\n" 514 "Tobias Koenig Current maintainer\ntokoe@kde.org\n"
515 "Don Sanders Original author\n" 515 "Don Sanders Original author\n"
516 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" 516 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n"
517 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" 517 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n"
518 "Greg Stern DCOP interface\n" 518 "Greg Stern DCOP interface\n"
519 "Mark Westcot Contact pinning\n" 519 "Mark Westcot Contact pinning\n"
520 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" 520 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
521 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" 521 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n"
522#ifdef _WIN32_ 522#ifdef _WIN32_
523 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 523 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
524#endif 524#endif
525 ); 525 );
526} 526}
527 527
528void KABCore::setContactSelected( const QString &uid ) 528void KABCore::setContactSelected( const QString &uid )
529{ 529{
530 KABC::Addressee addr = mAddressBook->findByUid( uid ); 530 KABC::Addressee addr = mAddressBook->findByUid( uid );
531 if ( !mDetails->isHidden() ) 531 if ( !mDetails->isHidden() )
532 mDetails->setAddressee( addr ); 532 mDetails->setAddressee( addr );
533 533
534 if ( !addr.isEmpty() ) { 534 if ( !addr.isEmpty() ) {
535 emit contactSelected( addr.formattedName() ); 535 emit contactSelected( addr.formattedName() );
536 KABC::Picture pic = addr.photo(); 536 KABC::Picture pic = addr.photo();
537 if ( pic.isIntern() ) { 537 if ( pic.isIntern() ) {
538//US emit contactSelected( pic.data() ); 538//US emit contactSelected( pic.data() );
539//US instead use: 539//US instead use:
540 QPixmap px; 540 QPixmap px;
541 if (pic.data().isNull() != true) 541 if (pic.data().isNull() != true)
542 { 542 {
543 px.convertFromImage(pic.data()); 543 px.convertFromImage(pic.data());
544 } 544 }
545 545
546 emit contactSelected( px ); 546 emit contactSelected( px );
547 } 547 }
548 } 548 }
549 549
550 550
551 mExtensionManager->setSelectionChanged(); 551 mExtensionManager->setSelectionChanged();
552 552
553 // update the actions 553 // update the actions
554 bool selected = !uid.isEmpty(); 554 bool selected = !uid.isEmpty();
555 555
556 if ( mReadWrite ) { 556 if ( mReadWrite ) {
557 mActionCut->setEnabled( selected ); 557 mActionCut->setEnabled( selected );
558 mActionPaste->setEnabled( selected ); 558 mActionPaste->setEnabled( selected );
559 } 559 }
560 560
561 mActionCopy->setEnabled( selected ); 561 mActionCopy->setEnabled( selected );
562 mActionDelete->setEnabled( selected ); 562 mActionDelete->setEnabled( selected );
563 mActionEditAddressee->setEnabled( selected ); 563 mActionEditAddressee->setEnabled( selected );
564 mActionMail->setEnabled( selected ); 564 mActionMail->setEnabled( selected );
565 mActionMailVCard->setEnabled( selected ); 565 mActionMailVCard->setEnabled( selected );
566 //if (mActionBeam) 566 //if (mActionBeam)
567 //mActionBeam->setEnabled( selected ); 567 //mActionBeam->setEnabled( selected );
568 568
569 if (mActionBeamVCard) 569 if (mActionBeamVCard)
570 mActionBeamVCard->setEnabled( selected ); 570 mActionBeamVCard->setEnabled( selected );
571 571
572 mActionExport2phone->setEnabled( selected ); 572 mActionExport2phone->setEnabled( selected );
573 mActionWhoAmI->setEnabled( selected ); 573 mActionWhoAmI->setEnabled( selected );
574 mActionCategories->setEnabled( selected ); 574 mActionCategories->setEnabled( selected );
575} 575}
576 576
577void KABCore::sendMail() 577void KABCore::sendMail()
578{ 578{
579 sendMail( mViewManager->selectedEmails().join( ", " ) ); 579 sendMail( mViewManager->selectedEmails().join( ", " ) );
580} 580}
581 581
582void KABCore::sendMail( const QString& emaillist ) 582void KABCore::sendMail( const QString& emaillist )
583{ 583{
584 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 584 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
585 if (emaillist.contains(",") > 0) 585 if (emaillist.contains(",") > 0)
586 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 586 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
587 else 587 else
588 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 588 ExternalAppHandler::instance()->mailToOneContact( emaillist );
589} 589}
590 590
591 591
592 592
593void KABCore::mailVCard() 593void KABCore::mailVCard()
594{ 594{
595 QStringList uids = mViewManager->selectedUids(); 595 QStringList uids = mViewManager->selectedUids();
596 if ( !uids.isEmpty() ) 596 if ( !uids.isEmpty() )
597 mailVCard( uids ); 597 mailVCard( uids );
598} 598}
599 599
600void KABCore::mailVCard( const QStringList& uids ) 600void KABCore::mailVCard( const QStringList& uids )
601{ 601{
602 QStringList urls; 602 QStringList urls;
603 603
604// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 604// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
605 605
606 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 606 QString dirName = "/tmp/" + KApplication::randomString( 8 );
607 607
608 608
609 609
610 QDir().mkdir( dirName, true ); 610 QDir().mkdir( dirName, true );
611 611
612 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 612 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
613 KABC::Addressee a = mAddressBook->findByUid( *it ); 613 KABC::Addressee a = mAddressBook->findByUid( *it );
614 614
615 if ( a.isEmpty() ) 615 if ( a.isEmpty() )
616 continue; 616 continue;
617 617
618 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 618 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
619 619
620 QString fileName = dirName + "/" + name; 620 QString fileName = dirName + "/" + name;
621 621
622 QFile outFile(fileName); 622 QFile outFile(fileName);
623 623
624 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 624 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
625 KABC::VCardConverter converter; 625 KABC::VCardConverter converter;
626 QString vcard; 626 QString vcard;
627 627
628 converter.addresseeToVCard( a, vcard ); 628 converter.addresseeToVCard( a, vcard );
629 629
630 QTextStream t( &outFile ); // use a text stream 630 QTextStream t( &outFile ); // use a text stream
631 t.setEncoding( QTextStream::UnicodeUTF8 ); 631 t.setEncoding( QTextStream::UnicodeUTF8 );
632 t << vcard; 632 t << vcard;
633 633
634 outFile.close(); 634 outFile.close();
635 635
636 urls.append( fileName ); 636 urls.append( fileName );
637 } 637 }
638 } 638 }
639 639
640 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 640 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
641 641
642 642
643/*US 643/*US
644 kapp->invokeMailer( QString::null, QString::null, QString::null, 644 kapp->invokeMailer( QString::null, QString::null, QString::null,
645 QString::null, // subject 645 QString::null, // subject
646 QString::null, // body 646 QString::null, // body
647 QString::null, 647 QString::null,
648 urls ); // attachments 648 urls ); // attachments
649*/ 649*/
650 650
651} 651}
652 652
653/** 653/**
654 Beams the "WhoAmI contact. 654 Beams the "WhoAmI contact.
655*/ 655*/
656void KABCore::beamMySelf() 656void KABCore::beamMySelf()
657{ 657{
658 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 658 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
659 if (!a.isEmpty()) 659 if (!a.isEmpty())
660 { 660 {
661 QStringList uids; 661 QStringList uids;
662 uids << a.uid(); 662 uids << a.uid();
663 663
664 beamVCard(uids); 664 beamVCard(uids);
665 } else { 665 } else {
666 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 666 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
667 667
668 668
669 } 669 }
670} 670}
671 671
672void KABCore::export2phone() 672void KABCore::export2phone()
673{ 673{
674 674
675 KAex2phonePrefs ex2phone; 675 KAex2phonePrefs ex2phone;
676 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); 676 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
677 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); 677 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
678 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); 678 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
679 679
680 if ( !ex2phone.exec() ) { 680 if ( !ex2phone.exec() ) {
681 return; 681 return;
682 } 682 }
683 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); 683 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
684 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); 684 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
685 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); 685 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
686 686
687 687
688 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, 688 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
689 KPimGlobalPrefs::instance()->mEx2PhoneConnection, 689 KPimGlobalPrefs::instance()->mEx2PhoneConnection,
690 KPimGlobalPrefs::instance()->mEx2PhoneModel ); 690 KPimGlobalPrefs::instance()->mEx2PhoneModel );
691 691
692 QStringList uids = mViewManager->selectedUids(); 692 QStringList uids = mViewManager->selectedUids();
693 if ( uids.isEmpty() ) 693 if ( uids.isEmpty() )
694 return; 694 return;
695 695
696#ifdef _WIN32_ 696#ifdef _WIN32_
697 QString fileName = locateLocal("tmp", "tempfile.vcf"); 697 QString fileName = locateLocal("tmp", "phonefile.vcf");
698#else 698#else
699 QString fileName = "/tmp/kdepimtemp.vcf"; 699 QString fileName = "/tmp/phonefile.vcf";
700#endif 700#endif
701 701
702 KABC::VCardConverter converter; 702 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) )
703 QString description;
704 QString datastream;
705 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
706 KABC::Addressee a = mAddressBook->findByUid( *it );
707
708 if ( a.isEmpty() )
709 continue;
710 a.simplifyEmails();
711 a.simplifyPhoneNumbers();
712 a.simplifyPhoneNumberTypes();
713 a.simplifyAddresses();
714
715 if (description.isEmpty())
716 description = a.formattedName();
717 QString vcard;
718 QString vcardnew;
719 converter.addresseeToVCard( a, vcard );
720 int start = 0;
721 int next;
722 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
723 int semi = vcard.find(";", next);
724 int dopp = vcard.find(":", next);
725 int sep;
726 if ( semi < dopp && semi >= 0 )
727 sep = semi ;
728 else
729 sep = dopp;
730 vcardnew +=vcard.mid( start, next - start);
731 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
732 start = sep;
733 }
734 vcardnew += vcard.mid( start,vcard.length() );
735 vcard = "";
736 start = 0;
737 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
738 int sep = vcardnew.find(":", next);
739 vcard +=vcardnew.mid( start, next - start+3);
740 start = sep;
741 }
742 vcard += vcardnew.mid( start,vcardnew.length() );
743 vcard.replace ( QRegExp(";;;") , "" );
744 vcard.replace ( QRegExp(";;") , "" );
745 datastream += vcard;
746
747 }
748 QFile outFile(fileName);
749 if ( outFile.open(IO_WriteOnly) ) {
750 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
751 QTextStream t( &outFile ); // use a text stream
752 t.setEncoding( QTextStream::UnicodeUTF8 );
753 t <<datastream;
754 outFile.close();
755 if ( PhoneAccess::writeToPhone( fileName ) )
756 qDebug("Export okay ");
757 else
758 qDebug("Error export contacts ");
759
760 } else {
761 qDebug("Error open temp file ");
762 return; 703 return;
763 } 704
764 705 if ( PhoneAccess::writeToPhone( fileName ) )
706 qDebug("Export okay ");
707 else
708 qDebug("Error export contacts ");
709
765 710
766#if 0 711#if 0
767 712
768 setCaption( i18n("Writing to phone...")); 713 setCaption( i18n("Writing to phone..."));
769 if ( PhoneFormat::writeToPhone( cal ) ) 714 if ( PhoneFormat::writeToPhone( cal ) )
770 setCaption( i18n("Export to phone successful!")); 715 setCaption( i18n("Export to phone successful!"));
771 else 716 else
772 setCaption( i18n("Error exporting to phone!")); 717 setCaption( i18n("Error exporting to phone!"));
773#endif 718#endif
774 719
775 720
776} 721}
777void KABCore::beamVCard() 722void KABCore::beamVCard()
778{ 723{
779 QStringList uids = mViewManager->selectedUids(); 724 QStringList uids = mViewManager->selectedUids();
780 if ( !uids.isEmpty() ) 725 if ( !uids.isEmpty() )
781 beamVCard( uids ); 726 beamVCard( uids );
782} 727}
783 728
784 729
785void KABCore::beamVCard(const QStringList& uids) 730void KABCore::beamVCard(const QStringList& uids)
786{ 731{
787/*US 732/*US
788 QString beamFilename; 733 QString beamFilename;
789 Opie::OPimContact c; 734 Opie::OPimContact c;
790 if ( actionPersonal->isOn() ) { 735 if ( actionPersonal->isOn() ) {
791 beamFilename = addressbookPersonalVCardName(); 736 beamFilename = addressbookPersonalVCardName();
792 if ( !QFile::exists( beamFilename ) ) 737 if ( !QFile::exists( beamFilename ) )
793 return; // can't beam a non-existent file 738 return; // can't beam a non-existent file
794 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 739 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
795 beamFilename ); 740 beamFilename );
796 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 741 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
797 Opie::OPimContactAccess::List allList = access->allRecords(); 742 Opie::OPimContactAccess::List allList = access->allRecords();
798 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first 743 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
799 c = *it; 744 c = *it;
800 745
801 delete access; 746 delete access;
802 } else { 747 } else {
803 unlink( beamfile ); // delete if exists 748 unlink( beamfile ); // delete if exists
804 mkdir("/tmp/obex/", 0755); 749 mkdir("/tmp/obex/", 0755);
805 c = m_abView -> currentEntry(); 750 c = m_abView -> currentEntry();
806 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 751 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
807 beamfile ); 752 beamfile );
808 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 753 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
809 access->add( c ); 754 access->add( c );
810 access->save(); 755 access->save();
811 delete access; 756 delete access;
812 757
813 beamFilename = beamfile; 758 beamFilename = beamfile;
814 } 759 }
815 760
816 owarn << "Beaming: " << beamFilename << oendl; 761 owarn << "Beaming: " << beamFilename << oendl;
817*/ 762*/
818 763
819#if 0 764#if 0
820 QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 765 QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
821 766
822 QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); 767 QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
823 768
824 QString name = "contact.vcf"; 769 QString name = "contact.vcf";
825 770
826 QString fileName = dirName + "/" + name; 771 QString fileName = dirName + "/" + name;
827#endif 772#endif
828 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory 773 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory
829 // 774 //
830 QString fileName = "/tmp/kapibeamfile.vcf"; 775 QString fileName = "/tmp/kapibeamfile.vcf";
831 776
832 777
833 //QDir().mkdir( dirName, true ); 778 //QDir().mkdir( dirName, true );
834 779
835 780
836 KABC::VCardConverter converter; 781 KABC::VCardConverter converter;
837 QString description; 782 QString description;
838 QString datastream; 783 QString datastream;
839 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 784 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
840 KABC::Addressee a = mAddressBook->findByUid( *it ); 785 KABC::Addressee a = mAddressBook->findByUid( *it );
841 786
842 if ( a.isEmpty() ) 787 if ( a.isEmpty() )
843 continue; 788 continue;
844 789
845 if (description.isEmpty()) 790 if (description.isEmpty())
846 description = a.formattedName(); 791 description = a.formattedName();
847 792
848 QString vcard; 793 QString vcard;
849 converter.addresseeToVCard( a, vcard ); 794 converter.addresseeToVCard( a, vcard );
850 int start = 0; 795 int start = 0;
851 int next; 796 int next;
852 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 797 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
853 int semi = vcard.find(";", next); 798 int semi = vcard.find(";", next);
854 int dopp = vcard.find(":", next); 799 int dopp = vcard.find(":", next);
855 int sep; 800 int sep;
856 if ( semi < dopp && semi >= 0 ) 801 if ( semi < dopp && semi >= 0 )
857 sep = semi ; 802 sep = semi ;
858 else 803 else
859 sep = dopp; 804 sep = dopp;
860 datastream +=vcard.mid( start, next - start); 805 datastream +=vcard.mid( start, next - start);
861 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 806 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
862 start = sep; 807 start = sep;
863 } 808 }
864 datastream += vcard.mid( start,vcard.length() ); 809 datastream += vcard.mid( start,vcard.length() );
865 } 810 }
866#ifndef DESKTOP_VERSION 811#ifndef DESKTOP_VERSION
867 QFile outFile(fileName); 812 QFile outFile(fileName);
868 if ( outFile.open(IO_WriteOnly) ) { 813 if ( outFile.open(IO_WriteOnly) ) {
869 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 814 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
870 QTextStream t( &outFile ); // use a text stream 815 QTextStream t( &outFile ); // use a text stream
871 t.setEncoding( QTextStream::UnicodeUTF8 ); 816 t.setEncoding( QTextStream::UnicodeUTF8 );
872 t <<datastream; 817 t <<datastream;
873 outFile.close(); 818 outFile.close();
874 Ir *ir = new Ir( this ); 819 Ir *ir = new Ir( this );
875 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 820 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
876 ir->send( fileName, description, "text/x-vCard" ); 821 ir->send( fileName, description, "text/x-vCard" );
877 } else { 822 } else {
878 qDebug("Error open temp beam file "); 823 qDebug("Error open temp beam file ");
879 return; 824 return;
880 } 825 }
881#endif 826#endif
882 827
883} 828}
884 829
885void KABCore::beamDone( Ir *ir ) 830void KABCore::beamDone( Ir *ir )
886{ 831{
887#ifndef DESKTOP_VERSION 832#ifndef DESKTOP_VERSION
888 delete ir; 833 delete ir;
889#endif 834#endif
890} 835}
891 836
892 837
893void KABCore::browse( const QString& url ) 838void KABCore::browse( const QString& url )
894{ 839{
895#ifndef KAB_EMBEDDED 840#ifndef KAB_EMBEDDED
896 kapp->invokeBrowser( url ); 841 kapp->invokeBrowser( url );
897#else //KAB_EMBEDDED 842#else //KAB_EMBEDDED
898 qDebug("KABCore::browse must be fixed"); 843 qDebug("KABCore::browse must be fixed");
899#endif //KAB_EMBEDDED 844#endif //KAB_EMBEDDED
900} 845}
901 846
902void KABCore::selectAllContacts() 847void KABCore::selectAllContacts()
903{ 848{
904 mViewManager->setSelected( QString::null, true ); 849 mViewManager->setSelected( QString::null, true );
905} 850}
906 851
907void KABCore::deleteContacts() 852void KABCore::deleteContacts()
908{ 853{
909 QStringList uidList = mViewManager->selectedUids(); 854 QStringList uidList = mViewManager->selectedUids();
910 deleteContacts( uidList ); 855 deleteContacts( uidList );
911} 856}
912 857
913void KABCore::deleteContacts( const QStringList &uids ) 858void KABCore::deleteContacts( const QStringList &uids )
914{ 859{
915 if ( uids.count() > 0 ) { 860 if ( uids.count() > 0 ) {
916 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 861 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
917 UndoStack::instance()->push( command ); 862 UndoStack::instance()->push( command );
918 RedoStack::instance()->clear(); 863 RedoStack::instance()->clear();
919 864
920 // now if we deleted anything, refresh 865 // now if we deleted anything, refresh
921 setContactSelected( QString::null ); 866 setContactSelected( QString::null );
922 setModified( true ); 867 setModified( true );
923 } 868 }
924} 869}
925 870
926void KABCore::copyContacts() 871void KABCore::copyContacts()
927{ 872{
928 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 873 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
929 874
930 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 875 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
931 876
932 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 877 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
933 878
934 QClipboard *cb = QApplication::clipboard(); 879 QClipboard *cb = QApplication::clipboard();
935 cb->setText( clipText ); 880 cb->setText( clipText );
936} 881}
937 882
938void KABCore::cutContacts() 883void KABCore::cutContacts()
939{ 884{
940 QStringList uidList = mViewManager->selectedUids(); 885 QStringList uidList = mViewManager->selectedUids();
941 886
942//US if ( uidList.size() > 0 ) { 887//US if ( uidList.size() > 0 ) {
943 if ( uidList.count() > 0 ) { 888 if ( uidList.count() > 0 ) {
944 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 889 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
945 UndoStack::instance()->push( command ); 890 UndoStack::instance()->push( command );
946 RedoStack::instance()->clear(); 891 RedoStack::instance()->clear();
947 892
948 setModified( true ); 893 setModified( true );
949 } 894 }
950} 895}
951 896
952void KABCore::pasteContacts() 897void KABCore::pasteContacts()
953{ 898{
954 QClipboard *cb = QApplication::clipboard(); 899 QClipboard *cb = QApplication::clipboard();
955 900
956 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 901 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
957 902
958 pasteContacts( list ); 903 pasteContacts( list );
959} 904}
960 905
961void KABCore::pasteContacts( KABC::Addressee::List &list ) 906void KABCore::pasteContacts( KABC::Addressee::List &list )
962{ 907{
963 KABC::Resource *resource = requestResource( this ); 908 KABC::Resource *resource = requestResource( this );
964 KABC::Addressee::List::Iterator it; 909 KABC::Addressee::List::Iterator it;
965 for ( it = list.begin(); it != list.end(); ++it ) 910 for ( it = list.begin(); it != list.end(); ++it )
966 (*it).setResource( resource ); 911 (*it).setResource( resource );
967 912
968 PwPasteCommand *command = new PwPasteCommand( this, list ); 913 PwPasteCommand *command = new PwPasteCommand( this, list );
969 UndoStack::instance()->push( command ); 914 UndoStack::instance()->push( command );
970 RedoStack::instance()->clear(); 915 RedoStack::instance()->clear();
971 916
972 setModified( true ); 917 setModified( true );
973} 918}
974 919
975void KABCore::setWhoAmI() 920void KABCore::setWhoAmI()
976{ 921{
977 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 922 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
978 923
979 if ( addrList.count() > 1 ) { 924 if ( addrList.count() > 1 ) {
980 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 925 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
981 return; 926 return;
982 } 927 }
983 928
984 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 929 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
985 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 930 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
986 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 931 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
987} 932}
988 933
989void KABCore::setCategories() 934void KABCore::setCategories()
990{ 935{
991 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 936 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
992 if ( !dlg.exec() ) 937 if ( !dlg.exec() )
993 return; 938 return;
994 939
995 bool merge = false; 940 bool merge = false;
996 QString msg = i18n( "Merge with existing categories?" ); 941 QString msg = i18n( "Merge with existing categories?" );
997 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 942 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
998 merge = true; 943 merge = true;
999 944
1000 QStringList categories = dlg.selectedCategories(); 945 QStringList categories = dlg.selectedCategories();
1001 946
1002 QStringList uids = mViewManager->selectedUids(); 947 QStringList uids = mViewManager->selectedUids();
1003 QStringList::Iterator it; 948 QStringList::Iterator it;
1004 for ( it = uids.begin(); it != uids.end(); ++it ) { 949 for ( it = uids.begin(); it != uids.end(); ++it ) {
1005 KABC::Addressee addr = mAddressBook->findByUid( *it ); 950 KABC::Addressee addr = mAddressBook->findByUid( *it );
1006 if ( !addr.isEmpty() ) { 951 if ( !addr.isEmpty() ) {
1007 if ( !merge ) 952 if ( !merge )
1008 addr.setCategories( categories ); 953 addr.setCategories( categories );
1009 else { 954 else {
1010 QStringList addrCategories = addr.categories(); 955 QStringList addrCategories = addr.categories();
1011 QStringList::Iterator catIt; 956 QStringList::Iterator catIt;
1012 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 957 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
1013 if ( !addrCategories.contains( *catIt ) ) 958 if ( !addrCategories.contains( *catIt ) )
1014 addrCategories.append( *catIt ); 959 addrCategories.append( *catIt );
1015 } 960 }
1016 addr.setCategories( addrCategories ); 961 addr.setCategories( addrCategories );
1017 } 962 }
1018 963
1019 mAddressBook->insertAddressee( addr ); 964 mAddressBook->insertAddressee( addr );
1020 } 965 }
1021 } 966 }
1022 967
1023 if ( uids.count() > 0 ) 968 if ( uids.count() > 0 )
1024 setModified( true ); 969 setModified( true );
1025} 970}
1026 971
1027void KABCore::setSearchFields( const KABC::Field::List &fields ) 972void KABCore::setSearchFields( const KABC::Field::List &fields )
1028{ 973{
1029 mIncSearchWidget->setFields( fields ); 974 mIncSearchWidget->setFields( fields );
1030} 975}
1031 976
1032void KABCore::incrementalSearch( const QString& text ) 977void KABCore::incrementalSearch( const QString& text )
1033{ 978{
1034 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 979 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
1035} 980}
1036 981
1037void KABCore::setModified() 982void KABCore::setModified()
1038{ 983{
1039 setModified( true ); 984 setModified( true );
1040} 985}
1041 986
1042void KABCore::setModifiedWOrefresh() 987void KABCore::setModifiedWOrefresh()
1043{ 988{
1044 // qDebug("KABCore::setModifiedWOrefresh() "); 989 // qDebug("KABCore::setModifiedWOrefresh() ");
1045 mModified = true; 990 mModified = true;
1046 mActionSave->setEnabled( mModified ); 991 mActionSave->setEnabled( mModified );
1047#ifdef DESKTOP_VERSION 992#ifdef DESKTOP_VERSION
1048 mDetails->refreshView(); 993 mDetails->refreshView();
1049#endif 994#endif
1050 995
1051} 996}
1052void KABCore::setModified( bool modified ) 997void KABCore::setModified( bool modified )
1053{ 998{
1054 mModified = modified; 999 mModified = modified;
1055 mActionSave->setEnabled( mModified ); 1000 mActionSave->setEnabled( mModified );
1056 1001
1057 if ( modified ) 1002 if ( modified )
1058 mJumpButtonBar->recreateButtons(); 1003 mJumpButtonBar->recreateButtons();
1059 1004
1060 mViewManager->refreshView(); 1005 mViewManager->refreshView();
1061 mDetails->refreshView(); 1006 mDetails->refreshView();
1062 1007
1063} 1008}
1064 1009
1065bool KABCore::modified() const 1010bool KABCore::modified() const
1066{ 1011{
1067 return mModified; 1012 return mModified;
1068} 1013}
1069 1014
1070void KABCore::contactModified( const KABC::Addressee &addr ) 1015void KABCore::contactModified( const KABC::Addressee &addr )
1071{ 1016{
1072 1017
1073 Command *command = 0; 1018 Command *command = 0;
1074 QString uid; 1019 QString uid;
1075 1020
1076 // check if it exists already 1021 // check if it exists already
1077 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 1022 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
1078 if ( origAddr.isEmpty() ) 1023 if ( origAddr.isEmpty() )
1079 command = new PwNewCommand( mAddressBook, addr ); 1024 command = new PwNewCommand( mAddressBook, addr );
1080 else { 1025 else {
1081 command = new PwEditCommand( mAddressBook, origAddr, addr ); 1026 command = new PwEditCommand( mAddressBook, origAddr, addr );
1082 uid = addr.uid(); 1027 uid = addr.uid();
1083 } 1028 }
1084 1029
1085 UndoStack::instance()->push( command ); 1030 UndoStack::instance()->push( command );
1086 RedoStack::instance()->clear(); 1031 RedoStack::instance()->clear();
1087 1032
1088 setModified( true ); 1033 setModified( true );
1089} 1034}
1090 1035
1091void KABCore::newContact() 1036void KABCore::newContact()
1092{ 1037{
1093 1038
1094 1039
1095 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 1040 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
1096 1041
1097 QPtrList<KRES::Resource> kresResources; 1042 QPtrList<KRES::Resource> kresResources;
1098 QPtrListIterator<KABC::Resource> it( kabcResources ); 1043 QPtrListIterator<KABC::Resource> it( kabcResources );
1099 KABC::Resource *resource; 1044 KABC::Resource *resource;
1100 while ( ( resource = it.current() ) != 0 ) { 1045 while ( ( resource = it.current() ) != 0 ) {
1101 ++it; 1046 ++it;
1102 if ( !resource->readOnly() ) { 1047 if ( !resource->readOnly() ) {
1103 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 1048 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
1104 if ( res ) 1049 if ( res )
1105 kresResources.append( res ); 1050 kresResources.append( res );
1106 } 1051 }
1107 } 1052 }
1108 1053
1109 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 1054 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
1110 resource = static_cast<KABC::Resource*>( res ); 1055 resource = static_cast<KABC::Resource*>( res );
1111 1056
1112 if ( resource ) { 1057 if ( resource ) {
1113 KABC::Addressee addr; 1058 KABC::Addressee addr;
1114 addr.setResource( resource ); 1059 addr.setResource( resource );
1115 mEditorDialog->setAddressee( addr ); 1060 mEditorDialog->setAddressee( addr );
1116 KApplication::execDialog ( mEditorDialog ); 1061 KApplication::execDialog ( mEditorDialog );
1117 1062
1118 } else 1063 } else
1119 return; 1064 return;
1120 1065
1121 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 1066 // mEditorDict.insert( dialog->addressee().uid(), dialog );
1122 1067
1123 1068
1124} 1069}
1125 1070
1126void KABCore::addEmail( QString aStr ) 1071void KABCore::addEmail( QString aStr )
1127{ 1072{
1128#ifndef KAB_EMBEDDED 1073#ifndef KAB_EMBEDDED
1129 QString fullName, email; 1074 QString fullName, email;
1130 1075
1131 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 1076 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
1132 1077
1133 // Try to lookup the addressee matching the email address 1078 // Try to lookup the addressee matching the email address
1134 bool found = false; 1079 bool found = false;
1135 QStringList emailList; 1080 QStringList emailList;
1136 KABC::AddressBook::Iterator it; 1081 KABC::AddressBook::Iterator it;
1137 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 1082 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
1138 emailList = (*it).emails(); 1083 emailList = (*it).emails();
1139 if ( emailList.contains( email ) > 0 ) { 1084 if ( emailList.contains( email ) > 0 ) {
1140 found = true; 1085 found = true;
1141 (*it).setNameFromString( fullName ); 1086 (*it).setNameFromString( fullName );
1142 editContact( (*it).uid() ); 1087 editContact( (*it).uid() );
1143 } 1088 }
1144 } 1089 }
1145 1090
1146 if ( !found ) { 1091 if ( !found ) {
1147 KABC::Addressee addr; 1092 KABC::Addressee addr;
1148 addr.setNameFromString( fullName ); 1093 addr.setNameFromString( fullName );
1149 addr.insertEmail( email, true ); 1094 addr.insertEmail( email, true );
1150 1095
1151 mAddressBook->insertAddressee( addr ); 1096 mAddressBook->insertAddressee( addr );
1152 mViewManager->refreshView( addr.uid() ); 1097 mViewManager->refreshView( addr.uid() );
1153 editContact( addr.uid() ); 1098 editContact( addr.uid() );
1154 } 1099 }
1155#else //KAB_EMBEDDED 1100#else //KAB_EMBEDDED
1156 qDebug("KABCore::addEmail finsih method"); 1101 qDebug("KABCore::addEmail finsih method");
1157#endif //KAB_EMBEDDED 1102#endif //KAB_EMBEDDED
1158} 1103}
1159 1104
1160void KABCore::importVCard( const KURL &url, bool showPreview ) 1105void KABCore::importVCard( const KURL &url, bool showPreview )
1161{ 1106{
1162 mXXPortManager->importVCard( url, showPreview ); 1107 mXXPortManager->importVCard( url, showPreview );
1163} 1108}
1164void KABCore::importFromOL() 1109void KABCore::importFromOL()
1165{ 1110{
1166#ifdef _WIN32_ 1111#ifdef _WIN32_
1167 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 1112 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
1168 idgl->exec(); 1113 idgl->exec();
1169 KABC::Addressee::List list = idgl->getAddressList(); 1114 KABC::Addressee::List list = idgl->getAddressList();
1170 if ( list.count() > 0 ) { 1115 if ( list.count() > 0 ) {
1171 KABC::Addressee::List listNew; 1116 KABC::Addressee::List listNew;
1172 KABC::Addressee::List listExisting; 1117 KABC::Addressee::List listExisting;
1173 KABC::Addressee::List::Iterator it; 1118 KABC::Addressee::List::Iterator it;
1174 KABC::AddressBook::Iterator iter; 1119 KABC::AddressBook::Iterator iter;
1175 for ( it = list.begin(); it != list.end(); ++it ) { 1120 for ( it = list.begin(); it != list.end(); ++it ) {
1176 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1121 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1177 listNew.append( (*it) ); 1122 listNew.append( (*it) );
1178 else 1123 else
1179 listExisting.append( (*it) ); 1124 listExisting.append( (*it) );
1180 } 1125 }
1181 if ( listExisting.count() > 0 ) 1126 if ( listExisting.count() > 0 )
1182 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1127 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1183 if ( listNew.count() > 0 ) { 1128 if ( listNew.count() > 0 ) {
1184 pasteWithNewUid = false; 1129 pasteWithNewUid = false;
1185 pasteContacts( listNew ); 1130 pasteContacts( listNew );
1186 pasteWithNewUid = true; 1131 pasteWithNewUid = true;
1187 } 1132 }
1188 } 1133 }
1189 delete idgl; 1134 delete idgl;
1190#endif 1135#endif
1191} 1136}
1192 1137
1193void KABCore::importVCard( const QString &vCard, bool showPreview ) 1138void KABCore::importVCard( const QString &vCard, bool showPreview )
1194{ 1139{
1195 mXXPortManager->importVCard( vCard, showPreview ); 1140 mXXPortManager->importVCard( vCard, showPreview );
1196} 1141}
1197 1142
1198//US added a second method without defaultparameter 1143//US added a second method without defaultparameter
1199void KABCore::editContact2() { 1144void KABCore::editContact2() {
1200 editContact( QString::null ); 1145 editContact( QString::null );
1201} 1146}
1202 1147
1203void KABCore::editContact( const QString &uid ) 1148void KABCore::editContact( const QString &uid )
1204{ 1149{
1205 1150
1206 if ( mExtensionManager->isQuickEditVisible() ) 1151 if ( mExtensionManager->isQuickEditVisible() )
1207 return; 1152 return;
1208 1153
1209 // First, locate the contact entry 1154 // First, locate the contact entry
1210 QString localUID = uid; 1155 QString localUID = uid;
1211 if ( localUID.isNull() ) { 1156 if ( localUID.isNull() ) {
1212 QStringList uidList = mViewManager->selectedUids(); 1157 QStringList uidList = mViewManager->selectedUids();
1213 if ( uidList.count() > 0 ) 1158 if ( uidList.count() > 0 )
1214 localUID = *( uidList.at( 0 ) ); 1159 localUID = *( uidList.at( 0 ) );
1215 } 1160 }
1216 1161
1217 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1162 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1218 if ( !addr.isEmpty() ) { 1163 if ( !addr.isEmpty() ) {
1219 mEditorDialog->setAddressee( addr ); 1164 mEditorDialog->setAddressee( addr );
1220 KApplication::execDialog ( mEditorDialog ); 1165 KApplication::execDialog ( mEditorDialog );
1221 } 1166 }
1222} 1167}
1223 1168
1224/** 1169/**
1225 Shows or edits the detail view for the given uid. If the uid is QString::null, 1170 Shows or edits the detail view for the given uid. If the uid is QString::null,
1226 the method will try to find a selected addressee in the view. 1171 the method will try to find a selected addressee in the view.
1227 */ 1172 */
1228void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1173void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1229{ 1174{
1230 if ( mMultipleViewsAtOnce ) 1175 if ( mMultipleViewsAtOnce )
1231 { 1176 {
1232 editContact( uid ); 1177 editContact( uid );
1233 } 1178 }
1234 else 1179 else
1235 { 1180 {
1236 setDetailsVisible( true ); 1181 setDetailsVisible( true );
1237 mActionDetails->setChecked(true); 1182 mActionDetails->setChecked(true);
1238 } 1183 }
1239 1184
1240} 1185}
1241 1186
1242void KABCore::save() 1187void KABCore::save()
1243{ 1188{
1244 if (syncManager->blockSave()) 1189 if (syncManager->blockSave())
1245 return; 1190 return;
1246 if ( !mModified ) 1191 if ( !mModified )
1247 return; 1192 return;
1248 1193
1249 syncManager->setBlockSave(true); 1194 syncManager->setBlockSave(true);
1250 QString text = i18n( "There was an error while attempting to save\n the " 1195 QString text = i18n( "There was an error while attempting to save\n the "
1251 "address book. Please check that some \nother application is " 1196 "address book. Please check that some \nother application is "
1252 "not using it. " ); 1197 "not using it. " );
1253 statusMessage(i18n("Saving addressbook ... ")); 1198 statusMessage(i18n("Saving addressbook ... "));
1254#ifndef KAB_EMBEDDED 1199#ifndef KAB_EMBEDDED
1255 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1200 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1256 if ( !b || !b->save() ) { 1201 if ( !b || !b->save() ) {
1257 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1202 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1258 } 1203 }
1259#else //KAB_EMBEDDED 1204#else //KAB_EMBEDDED
1260 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1205 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1261 if ( !b || !b->save() ) { 1206 if ( !b || !b->save() ) {
1262 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1207 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1263 } 1208 }
1264#endif //KAB_EMBEDDED 1209#endif //KAB_EMBEDDED
1265 1210
1266 statusMessage(i18n("Addressbook saved!")); 1211 statusMessage(i18n("Addressbook saved!"));
1267 setModified( false ); 1212 setModified( false );
1268 syncManager->setBlockSave(false); 1213 syncManager->setBlockSave(false);
1269} 1214}
1270 1215
1271void KABCore::statusMessage(QString mess , int time ) 1216void KABCore::statusMessage(QString mess , int time )
1272{ 1217{
1273 //topLevelWidget()->setCaption( mess ); 1218 //topLevelWidget()->setCaption( mess );
1274 // pending setting timer to revome message 1219 // pending setting timer to revome message
1275} 1220}
1276void KABCore::undo() 1221void KABCore::undo()
@@ -2334,591 +2279,594 @@ void KABCore::requestForDetails(const QString& sourceChannel, const QString& ses
2334 2279
2335void KABCore::faq() 2280void KABCore::faq()
2336{ 2281{
2337 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2282 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2338} 2283}
2339 2284
2340#include <libkcal/syncdefines.h> 2285#include <libkcal/syncdefines.h>
2341 2286
2342KABC::Addressee KABCore::getLastSyncAddressee() 2287KABC::Addressee KABCore::getLastSyncAddressee()
2343{ 2288{
2344 Addressee lse; 2289 Addressee lse;
2345 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2290 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2346 2291
2347 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2292 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2348 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2293 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2349 if (lse.isEmpty()) { 2294 if (lse.isEmpty()) {
2350 qDebug("Creating new last-syncAddressee "); 2295 qDebug("Creating new last-syncAddressee ");
2351 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2296 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2352 QString sum = ""; 2297 QString sum = "";
2353 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2298 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2354 sum = "E: "; 2299 sum = "E: ";
2355 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2300 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2356 lse.setRevision( mLastAddressbookSync ); 2301 lse.setRevision( mLastAddressbookSync );
2357 lse.setCategories( i18n("SyncEvent") ); 2302 lse.setCategories( i18n("SyncEvent") );
2358 mAddressBook->insertAddressee( lse ); 2303 mAddressBook->insertAddressee( lse );
2359 } 2304 }
2360 return lse; 2305 return lse;
2361} 2306}
2362int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2307int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2363{ 2308{
2364 2309
2365 //void setZaurusId(int id); 2310 //void setZaurusId(int id);
2366 // int zaurusId() const; 2311 // int zaurusId() const;
2367 // void setZaurusUid(int id); 2312 // void setZaurusUid(int id);
2368 // int zaurusUid() const; 2313 // int zaurusUid() const;
2369 // void setZaurusStat(int id); 2314 // void setZaurusStat(int id);
2370 // int zaurusStat() const; 2315 // int zaurusStat() const;
2371 // 0 equal 2316 // 0 equal
2372 // 1 take local 2317 // 1 take local
2373 // 2 take remote 2318 // 2 take remote
2374 // 3 cancel 2319 // 3 cancel
2375 QDateTime lastSync = mLastAddressbookSync; 2320 QDateTime lastSync = mLastAddressbookSync;
2376 QDateTime localMod = local->revision(); 2321 QDateTime localMod = local->revision();
2377 QDateTime remoteMod = remote->revision(); 2322 QDateTime remoteMod = remote->revision();
2378 2323
2379 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2324 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2380 2325
2381 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2326 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2382 bool remCh, locCh; 2327 bool remCh, locCh;
2383 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2328 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2384 2329
2385 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2330 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2386 locCh = ( localMod > mLastAddressbookSync ); 2331 locCh = ( localMod > mLastAddressbookSync );
2387 if ( !remCh && ! locCh ) { 2332 if ( !remCh && ! locCh ) {
2388 //qDebug("both not changed "); 2333 //qDebug("both not changed ");
2389 lastSync = localMod.addDays(1); 2334 lastSync = localMod.addDays(1);
2390 if ( mode <= SYNC_PREF_ASK ) 2335 if ( mode <= SYNC_PREF_ASK )
2391 return 0; 2336 return 0;
2392 } else { 2337 } else {
2393 if ( locCh ) { 2338 if ( locCh ) {
2394 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2339 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2395 lastSync = localMod.addDays( -1 ); 2340 lastSync = localMod.addDays( -1 );
2396 if ( !remCh ) 2341 if ( !remCh )
2397 remoteMod =( lastSync.addDays( -1 ) ); 2342 remoteMod =( lastSync.addDays( -1 ) );
2398 } else { 2343 } else {
2399 //qDebug(" not loc changed "); 2344 //qDebug(" not loc changed ");
2400 lastSync = localMod.addDays( 1 ); 2345 lastSync = localMod.addDays( 1 );
2401 if ( remCh ) 2346 if ( remCh )
2402 remoteMod =( lastSync.addDays( 1 ) ); 2347 remoteMod =( lastSync.addDays( 1 ) );
2403 2348
2404 } 2349 }
2405 } 2350 }
2406 full = true; 2351 full = true;
2407 if ( mode < SYNC_PREF_ASK ) 2352 if ( mode < SYNC_PREF_ASK )
2408 mode = SYNC_PREF_ASK; 2353 mode = SYNC_PREF_ASK;
2409 } else { 2354 } else {
2410 if ( localMod == remoteMod ) 2355 if ( localMod == remoteMod )
2411 return 0; 2356 return 0;
2412 2357
2413 } 2358 }
2414 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2359 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2415 2360
2416 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 2361 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2417 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2362 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2418 //full = true; //debug only 2363 //full = true; //debug only
2419 if ( full ) { 2364 if ( full ) {
2420 bool equ = ( (*local) == (*remote) ); 2365 bool equ = ( (*local) == (*remote) );
2421 if ( equ ) { 2366 if ( equ ) {
2422 //qDebug("equal "); 2367 //qDebug("equal ");
2423 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2368 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2424 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2369 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2425 } 2370 }
2426 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2371 if ( mode < SYNC_PREF_FORCE_LOCAL )
2427 return 0; 2372 return 0;
2428 2373
2429 }//else //debug only 2374 }//else //debug only
2430 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2375 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2431 } 2376 }
2432 int result; 2377 int result;
2433 bool localIsNew; 2378 bool localIsNew;
2434 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2379 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2435 2380
2436 if ( full && mode < SYNC_PREF_NEWEST ) 2381 if ( full && mode < SYNC_PREF_NEWEST )
2437 mode = SYNC_PREF_ASK; 2382 mode = SYNC_PREF_ASK;
2438 2383
2439 switch( mode ) { 2384 switch( mode ) {
2440 case SYNC_PREF_LOCAL: 2385 case SYNC_PREF_LOCAL:
2441 if ( lastSync > remoteMod ) 2386 if ( lastSync > remoteMod )
2442 return 1; 2387 return 1;
2443 if ( lastSync > localMod ) 2388 if ( lastSync > localMod )
2444 return 2; 2389 return 2;
2445 return 1; 2390 return 1;
2446 break; 2391 break;
2447 case SYNC_PREF_REMOTE: 2392 case SYNC_PREF_REMOTE:
2448 if ( lastSync > remoteMod ) 2393 if ( lastSync > remoteMod )
2449 return 1; 2394 return 1;
2450 if ( lastSync > localMod ) 2395 if ( lastSync > localMod )
2451 return 2; 2396 return 2;
2452 return 2; 2397 return 2;
2453 break; 2398 break;
2454 case SYNC_PREF_NEWEST: 2399 case SYNC_PREF_NEWEST:
2455 if ( localMod > remoteMod ) 2400 if ( localMod > remoteMod )
2456 return 1; 2401 return 1;
2457 else 2402 else
2458 return 2; 2403 return 2;
2459 break; 2404 break;
2460 case SYNC_PREF_ASK: 2405 case SYNC_PREF_ASK:
2461 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2406 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2462 if ( lastSync > remoteMod ) 2407 if ( lastSync > remoteMod )
2463 return 1; 2408 return 1;
2464 if ( lastSync > localMod ) 2409 if ( lastSync > localMod )
2465 return 2; 2410 return 2;
2466 localIsNew = localMod >= remoteMod; 2411 localIsNew = localMod >= remoteMod;
2467 //qDebug("conflict! ************************************** "); 2412 //qDebug("conflict! ************************************** ");
2468 { 2413 {
2469 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2414 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2470 result = acd.executeD(localIsNew); 2415 result = acd.executeD(localIsNew);
2471 return result; 2416 return result;
2472 } 2417 }
2473 break; 2418 break;
2474 case SYNC_PREF_FORCE_LOCAL: 2419 case SYNC_PREF_FORCE_LOCAL:
2475 return 1; 2420 return 1;
2476 break; 2421 break;
2477 case SYNC_PREF_FORCE_REMOTE: 2422 case SYNC_PREF_FORCE_REMOTE:
2478 return 2; 2423 return 2;
2479 break; 2424 break;
2480 2425
2481 default: 2426 default:
2482 // SYNC_PREF_TAKE_BOTH not implemented 2427 // SYNC_PREF_TAKE_BOTH not implemented
2483 break; 2428 break;
2484 } 2429 }
2485 return 0; 2430 return 0;
2486} 2431}
2487 2432
2488 2433
2489bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2434bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2490{ 2435{
2491 bool syncOK = true; 2436 bool syncOK = true;
2492 int addedAddressee = 0; 2437 int addedAddressee = 0;
2493 int addedAddresseeR = 0; 2438 int addedAddresseeR = 0;
2494 int deletedAddresseeR = 0; 2439 int deletedAddresseeR = 0;
2495 int deletedAddresseeL = 0; 2440 int deletedAddresseeL = 0;
2496 int changedLocal = 0; 2441 int changedLocal = 0;
2497 int changedRemote = 0; 2442 int changedRemote = 0;
2498 2443
2499 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2444 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2500 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2445 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2501 2446
2502 //QPtrList<Addressee> el = local->rawAddressees(); 2447 //QPtrList<Addressee> el = local->rawAddressees();
2503 Addressee addresseeR; 2448 Addressee addresseeR;
2504 QString uid; 2449 QString uid;
2505 int take; 2450 int take;
2506 Addressee addresseeL; 2451 Addressee addresseeL;
2507 Addressee addresseeRSync; 2452 Addressee addresseeRSync;
2508 Addressee addresseeLSync; 2453 Addressee addresseeLSync;
2509 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2454 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2510 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2455 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2511 bool fullDateRange = false; 2456 bool fullDateRange = false;
2512 local->resetTempSyncStat(); 2457 local->resetTempSyncStat();
2513 mLastAddressbookSync = QDateTime::currentDateTime(); 2458 mLastAddressbookSync = QDateTime::currentDateTime();
2514 QDateTime modifiedCalendar = mLastAddressbookSync;; 2459 QDateTime modifiedCalendar = mLastAddressbookSync;;
2515 addresseeLSync = getLastSyncAddressee(); 2460 addresseeLSync = getLastSyncAddressee();
2516 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2461 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2517 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2462 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2518 if ( !addresseeR.isEmpty() ) { 2463 if ( !addresseeR.isEmpty() ) {
2519 addresseeRSync = addresseeR; 2464 addresseeRSync = addresseeR;
2520 remote->removeAddressee(addresseeR ); 2465 remote->removeAddressee(addresseeR );
2521 2466
2522 } else { 2467 } else {
2523 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2468 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2524 addresseeRSync = addresseeLSync ; 2469 addresseeRSync = addresseeLSync ;
2525 } else { 2470 } else {
2526 qDebug("FULLDATE 1"); 2471 qDebug("FULLDATE 1");
2527 fullDateRange = true; 2472 fullDateRange = true;
2528 Addressee newAdd; 2473 Addressee newAdd;
2529 addresseeRSync = newAdd; 2474 addresseeRSync = newAdd;
2530 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2475 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2531 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2476 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2532 addresseeRSync.setRevision( mLastAddressbookSync ); 2477 addresseeRSync.setRevision( mLastAddressbookSync );
2533 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2478 addresseeRSync.setCategories( i18n("SyncAddressee") );
2534 } 2479 }
2535 } 2480 }
2536 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2481 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2537 qDebug("FULLDATE 2"); 2482 qDebug("FULLDATE 2");
2538 fullDateRange = true; 2483 fullDateRange = true;
2539 } 2484 }
2540 if ( ! fullDateRange ) { 2485 if ( ! fullDateRange ) {
2541 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2486 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2542 2487
2543 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2488 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2544 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2489 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2545 fullDateRange = true; 2490 fullDateRange = true;
2546 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2491 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2547 } 2492 }
2548 } 2493 }
2549 // fullDateRange = true; // debug only! 2494 // fullDateRange = true; // debug only!
2550 if ( fullDateRange ) 2495 if ( fullDateRange )
2551 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2496 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2552 else 2497 else
2553 mLastAddressbookSync = addresseeLSync.revision(); 2498 mLastAddressbookSync = addresseeLSync.revision();
2554 // for resyncing if own file has changed 2499 // for resyncing if own file has changed
2555 // PENDING fixme later when implemented 2500 // PENDING fixme later when implemented
2556#if 0 2501#if 0
2557 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2502 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2558 mLastAddressbookSync = loadedFileVersion; 2503 mLastAddressbookSync = loadedFileVersion;
2559 qDebug("setting mLastAddressbookSync "); 2504 qDebug("setting mLastAddressbookSync ");
2560 } 2505 }
2561#endif 2506#endif
2562 2507
2563 //qDebug("*************************** "); 2508 //qDebug("*************************** ");
2564 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2509 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2565 QStringList er = remote->uidList(); 2510 QStringList er = remote->uidList();
2566 Addressee inR ;//= er.first(); 2511 Addressee inR ;//= er.first();
2567 Addressee inL; 2512 Addressee inL;
2568 2513
2569 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2514 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2570 2515
2571 int modulo = (er.count()/10)+1; 2516 int modulo = (er.count()/10)+1;
2572 int incCounter = 0; 2517 int incCounter = 0;
2573 while ( incCounter < er.count()) { 2518 while ( incCounter < er.count()) {
2574 if (syncManager->isProgressBarCanceled()) 2519 if (syncManager->isProgressBarCanceled())
2575 return false; 2520 return false;
2576 if ( incCounter % modulo == 0 ) 2521 if ( incCounter % modulo == 0 )
2577 syncManager->showProgressBar(incCounter); 2522 syncManager->showProgressBar(incCounter);
2578 2523
2579 uid = er[ incCounter ]; 2524 uid = er[ incCounter ];
2580 bool skipIncidence = false; 2525 bool skipIncidence = false;
2581 if ( uid.left(19) == QString("last-syncAddressee-") ) 2526 if ( uid.left(19) == QString("last-syncAddressee-") )
2582 skipIncidence = true; 2527 skipIncidence = true;
2583 QString idS,OidS; 2528 QString idS,OidS;
2584 qApp->processEvents(); 2529 qApp->processEvents();
2585 if ( !skipIncidence ) { 2530 if ( !skipIncidence ) {
2586 inL = local->findByUid( uid ); 2531 inL = local->findByUid( uid );
2587 inR = remote->findByUid( uid ); 2532 inR = remote->findByUid( uid );
2588 //inL.setResource( 0 ); 2533 //inL.setResource( 0 );
2589 //inR.setResource( 0 ); 2534 //inR.setResource( 0 );
2590 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2535 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2591 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2536 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2592 //qDebug("take %d %s ", take, inL.summary().latin1()); 2537 //qDebug("take %d %s ", take, inL.summary().latin1());
2593 if ( take == 3 ) 2538 if ( take == 3 )
2594 return false; 2539 return false;
2595 if ( take == 1 ) {// take local 2540 if ( take == 1 ) {// take local
2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2541 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2597 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2542 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2598 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2543 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2599 local->insertAddressee( inL, false ); 2544 local->insertAddressee( inL, false );
2600 idS = inR.externalUID(); 2545 idS = inR.externalUID();
2601 OidS = inR.originalExternalUID(); 2546 OidS = inR.originalExternalUID();
2602 } 2547 }
2603 else 2548 else
2604 idS = inR.IDStr(); 2549 idS = inR.IDStr();
2605 remote->removeAddressee( inR ); 2550 remote->removeAddressee( inR );
2606 inR = inL; 2551 inR = inL;
2607 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2552 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2608 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2553 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2609 inR.setOriginalExternalUID( OidS ); 2554 inR.setOriginalExternalUID( OidS );
2610 inR.setExternalUID( idS ); 2555 inR.setExternalUID( idS );
2611 } else { 2556 } else {
2612 inR.setIDStr( idS ); 2557 inR.setIDStr( idS );
2613 } 2558 }
2614 inR.setResource( 0 ); 2559 inR.setResource( 0 );
2615 remote->insertAddressee( inR , false); 2560 remote->insertAddressee( inR , false);
2616 ++changedRemote; 2561 ++changedRemote;
2617 } else { // take == 2 take remote 2562 } else { // take == 2 take remote
2618 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2563 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2619 if ( inR.revision().date().year() < 2004 ) 2564 if ( inR.revision().date().year() < 2004 )
2620 inR.setRevision( modifiedCalendar ); 2565 inR.setRevision( modifiedCalendar );
2621 } 2566 }
2622 idS = inL.IDStr(); 2567 idS = inL.IDStr();
2623 local->removeAddressee( inL ); 2568 local->removeAddressee( inL );
2624 inL = inR; 2569 inL = inR;
2625 inL.setIDStr( idS ); 2570 inL.setIDStr( idS );
2626 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2571 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2627 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2572 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2628 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2573 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2629 } 2574 }
2630 inL.setResource( 0 ); 2575 inL.setResource( 0 );
2631 local->insertAddressee( inL , false ); 2576 local->insertAddressee( inL , false );
2632 ++changedLocal; 2577 ++changedLocal;
2633 } 2578 }
2634 } 2579 }
2635 } else { // no conflict 2580 } else { // no conflict
2636 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2581 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2637 QString des = addresseeLSync.note(); 2582 QString des = addresseeLSync.note();
2638 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2583 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2639 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2584 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2640 remote->insertAddressee( inR, false ); 2585 remote->insertAddressee( inR, false );
2641 ++deletedAddresseeR; 2586 ++deletedAddresseeR;
2642 } else { 2587 } else {
2643 inR.setRevision( modifiedCalendar ); 2588 inR.setRevision( modifiedCalendar );
2644 remote->insertAddressee( inR, false ); 2589 remote->insertAddressee( inR, false );
2645 inL = inR; 2590 inL = inR;
2646 inL.setResource( 0 ); 2591 inL.setResource( 0 );
2647 local->insertAddressee( inL , false); 2592 local->insertAddressee( inL , false);
2648 ++addedAddressee; 2593 ++addedAddressee;
2649 } 2594 }
2650 } else { 2595 } else {
2651 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2596 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2652 inR.setRevision( modifiedCalendar ); 2597 inR.setRevision( modifiedCalendar );
2653 remote->insertAddressee( inR, false ); 2598 remote->insertAddressee( inR, false );
2654 inR.setResource( 0 ); 2599 inR.setResource( 0 );
2655 local->insertAddressee( inR, false ); 2600 local->insertAddressee( inR, false );
2656 ++addedAddressee; 2601 ++addedAddressee;
2657 } else { 2602 } else {
2658 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2603 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2659 remote->removeAddressee( inR ); 2604 remote->removeAddressee( inR );
2660 ++deletedAddresseeR; 2605 ++deletedAddresseeR;
2661 } 2606 }
2662 } 2607 }
2663 } 2608 }
2664 } 2609 }
2665 ++incCounter; 2610 ++incCounter;
2666 } 2611 }
2667 er.clear(); 2612 er.clear();
2668 QStringList el = local->uidList(); 2613 QStringList el = local->uidList();
2669 modulo = (el.count()/10)+1; 2614 modulo = (el.count()/10)+1;
2670 2615
2671 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2616 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2672 incCounter = 0; 2617 incCounter = 0;
2673 while ( incCounter < el.count()) { 2618 while ( incCounter < el.count()) {
2674 qApp->processEvents(); 2619 qApp->processEvents();
2675 if (syncManager->isProgressBarCanceled()) 2620 if (syncManager->isProgressBarCanceled())
2676 return false; 2621 return false;
2677 if ( incCounter % modulo == 0 ) 2622 if ( incCounter % modulo == 0 )
2678 syncManager->showProgressBar(incCounter); 2623 syncManager->showProgressBar(incCounter);
2679 uid = el[ incCounter ]; 2624 uid = el[ incCounter ];
2680 bool skipIncidence = false; 2625 bool skipIncidence = false;
2681 if ( uid.left(19) == QString("last-syncAddressee-") ) 2626 if ( uid.left(19) == QString("last-syncAddressee-") )
2682 skipIncidence = true; 2627 skipIncidence = true;
2683 if ( !skipIncidence ) { 2628 if ( !skipIncidence ) {
2684 inL = local->findByUid( uid ); 2629 inL = local->findByUid( uid );
2685 inR = remote->findByUid( uid ); 2630 inR = remote->findByUid( uid );
2686 if ( inR.isEmpty() ) { 2631 if ( inR.isEmpty() ) {
2687 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2632 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2688 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2633 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2689 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2634 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2690 local->removeAddressee( inL ); 2635 local->removeAddressee( inL );
2691 ++deletedAddresseeL; 2636 ++deletedAddresseeL;
2692 } else { 2637 } else {
2693 if ( ! syncManager->mWriteBackExistingOnly ) { 2638 if ( ! syncManager->mWriteBackExistingOnly ) {
2694 inL.removeID(mCurrentSyncDevice ); 2639 inL.removeID(mCurrentSyncDevice );
2695 ++addedAddresseeR; 2640 ++addedAddresseeR;
2696 inL.setRevision( modifiedCalendar ); 2641 inL.setRevision( modifiedCalendar );
2697 local->insertAddressee( inL, false ); 2642 local->insertAddressee( inL, false );
2698 inR = inL; 2643 inR = inL;
2699 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2644 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2700 inR.setResource( 0 ); 2645 inR.setResource( 0 );
2701 remote->insertAddressee( inR, false ); 2646 remote->insertAddressee( inR, false );
2702 } 2647 }
2703 } 2648 }
2704 } else { 2649 } else {
2705 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2650 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2706 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2651 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2707 local->removeAddressee( inL ); 2652 local->removeAddressee( inL );
2708 ++deletedAddresseeL; 2653 ++deletedAddresseeL;
2709 } else { 2654 } else {
2710 if ( ! syncManager->mWriteBackExistingOnly ) { 2655 if ( ! syncManager->mWriteBackExistingOnly ) {
2711 ++addedAddresseeR; 2656 ++addedAddresseeR;
2712 inL.setRevision( modifiedCalendar ); 2657 inL.setRevision( modifiedCalendar );
2713 local->insertAddressee( inL, false ); 2658 local->insertAddressee( inL, false );
2714 inR = inL; 2659 inR = inL;
2715 inR.setResource( 0 ); 2660 inR.setResource( 0 );
2716 remote->insertAddressee( inR, false ); 2661 remote->insertAddressee( inR, false );
2717 } 2662 }
2718 } 2663 }
2719 } 2664 }
2720 } 2665 }
2721 } 2666 }
2722 ++incCounter; 2667 ++incCounter;
2723 } 2668 }
2724 el.clear(); 2669 el.clear();
2725 syncManager->hideProgressBar(); 2670 syncManager->hideProgressBar();
2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2671 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2727 // get rid of micro seconds 2672 // get rid of micro seconds
2728 QTime t = mLastAddressbookSync.time(); 2673 QTime t = mLastAddressbookSync.time();
2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2674 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2730 addresseeLSync.setRevision( mLastAddressbookSync ); 2675 addresseeLSync.setRevision( mLastAddressbookSync );
2731 addresseeRSync.setRevision( mLastAddressbookSync ); 2676 addresseeRSync.setRevision( mLastAddressbookSync );
2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2677 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2678 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2679 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2680 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2681 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2682 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2738 addresseeRSync.setNote( "" ) ; 2683 addresseeRSync.setNote( "" ) ;
2739 addresseeLSync.setNote( "" ); 2684 addresseeLSync.setNote( "" );
2740 2685
2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2686 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2742 remote->insertAddressee( addresseeRSync, false ); 2687 remote->insertAddressee( addresseeRSync, false );
2743 local->insertAddressee( addresseeLSync, false ); 2688 local->insertAddressee( addresseeLSync, false );
2744 QString mes; 2689 QString mes;
2745 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2690 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2746 if ( syncManager->mShowSyncSummary ) { 2691 if ( syncManager->mShowSyncSummary ) {
2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2692 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2748 } 2693 }
2749 qDebug( mes ); 2694 qDebug( mes );
2750 return syncOK; 2695 return syncOK;
2751} 2696}
2752 2697
2753 2698
2754//this is a overwritten callbackmethods from the syncinterface 2699//this is a overwritten callbackmethods from the syncinterface
2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2700bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2756{ 2701{
2757 2702
2758 //pending prepare addresseeview for output 2703 //pending prepare addresseeview for output
2759 //pending detect, if remote file has REV field. if not switch to external sync 2704 //pending detect, if remote file has REV field. if not switch to external sync
2760 mGlobalSyncMode = SYNC_MODE_NORMAL; 2705 mGlobalSyncMode = SYNC_MODE_NORMAL;
2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2706 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2762 2707
2763 AddressBook abLocal(filename,"syncContact"); 2708 AddressBook abLocal(filename,"syncContact");
2764 bool syncOK = false; 2709 bool syncOK = false;
2765 if ( abLocal.load() ) { 2710 if ( abLocal.load() ) {
2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2711 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2767 bool external = false; 2712 bool external = false;
2768 bool isXML = false; 2713 bool isXML = false;
2769 if ( filename.right(4) == ".xml") { 2714 if ( filename.right(4) == ".xml") {
2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2715 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2771 isXML = true; 2716 isXML = true;
2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2717 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2773 } else { 2718 } else {
2774 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2719 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2775 if ( ! lse.isEmpty() ) { 2720 if ( ! lse.isEmpty() ) {
2776 if ( lse.familyName().left(4) == "!E: " ) 2721 if ( lse.familyName().left(4) == "!E: " )
2777 external = true; 2722 external = true;
2778 } else { 2723 } else {
2779 bool found = false; 2724 bool found = false;
2780 AddressBook::Iterator it; 2725 AddressBook::Iterator it;
2781 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2726 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2782 if ( (*it).revision().date().year() > 2003 ) { 2727 if ( (*it).revision().date().year() > 2003 ) {
2783 found = true; 2728 found = true;
2784 break; 2729 break;
2785 } 2730 }
2786 } 2731 }
2787 external = ! found; 2732 external = ! found;
2788 } 2733 }
2789 2734
2790 if ( external ) { 2735 if ( external ) {
2791 qDebug("Setting vcf mode to external "); 2736 qDebug("Setting vcf mode to external ");
2792 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2737 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2793 AddressBook::Iterator it; 2738 AddressBook::Iterator it;
2794 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2739 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2795 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2740 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2796 (*it).computeCsum( mCurrentSyncDevice ); 2741 (*it).computeCsum( mCurrentSyncDevice );
2797 } 2742 }
2798 } 2743 }
2799 } 2744 }
2800 //AddressBook::Iterator it; 2745 //AddressBook::Iterator it;
2801 //QStringList vcards; 2746 //QStringList vcards;
2802 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2747 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2803 // qDebug("Name %s ", (*it).familyName().latin1()); 2748 // qDebug("Name %s ", (*it).familyName().latin1());
2804 //} 2749 //}
2805 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2750 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2806 if ( syncOK ) { 2751 if ( syncOK ) {
2807 if ( syncManager->mWriteBackFile ) 2752 if ( syncManager->mWriteBackFile )
2808 { 2753 {
2809 if ( external ) 2754 if ( external )
2810 abLocal.removeSyncAddressees( !isXML); 2755 abLocal.removeSyncAddressees( !isXML);
2811 qDebug("Saving remote AB "); 2756 qDebug("Saving remote AB ");
2812 if ( ! abLocal.saveAB()) 2757 if ( ! abLocal.saveAB())
2813 qDebug("Error writing back AB to file "); 2758 qDebug("Error writing back AB to file ");
2814 if ( isXML ) { 2759 if ( isXML ) {
2815 // afterwrite processing 2760 // afterwrite processing
2816 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2761 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2817 } 2762 }
2818 } 2763 }
2819 } 2764 }
2820 setModified(); 2765 setModified();
2821 2766
2822 } 2767 }
2823 if ( syncOK ) 2768 if ( syncOK )
2824 mViewManager->refreshView(); 2769 mViewManager->refreshView();
2825 return syncOK; 2770 return syncOK;
2826 2771
2827} 2772}
2828 2773
2829 2774
2830//this is a overwritten callbackmethods from the syncinterface 2775//this is a overwritten callbackmethods from the syncinterface
2831bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2776bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2832{ 2777{
2833 if ( resource == "phone" ) 2778 if ( resource == "phone" )
2834 return syncPhone(); 2779 return syncPhone();
2835 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2780 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2836 2781
2837 AddressBook abLocal( resource,"syncContact"); 2782 AddressBook abLocal( resource,"syncContact");
2838 bool syncOK = false; 2783 bool syncOK = false;
2839 if ( abLocal.load() ) { 2784 if ( abLocal.load() ) {
2840 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2785 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2841 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2786 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2842 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2787 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2843 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2788 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2844 if ( syncOK ) { 2789 if ( syncOK ) {
2845 if ( syncManager->mWriteBackFile ) { 2790 if ( syncManager->mWriteBackFile ) {
2791 abLocal.removeSyncAddressees( false );
2846 abLocal.saveAB(); 2792 abLocal.saveAB();
2847 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2793 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2848 } 2794 }
2849 } 2795 }
2850 setModified(); 2796 setModified();
2851 } 2797 }
2852 if ( syncOK ) 2798 if ( syncOK )
2853 mViewManager->refreshView(); 2799 mViewManager->refreshView();
2854 return syncOK; 2800 return syncOK;
2855 2801
2856} 2802}
2857void KABCore::message( QString m ) 2803void KABCore::message( QString m )
2858{ 2804{
2859 2805
2860 topLevelWidget()->setCaption( m ); 2806 topLevelWidget()->setCaption( m );
2861 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); 2807 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
2862} 2808}
2863bool KABCore::syncPhone() 2809bool KABCore::syncPhone()
2864{ 2810{
2865 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2811 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2866 QString fileName; 2812 QString fileName;
2867#ifdef _WIN32_ 2813#ifdef _WIN32_
2868 fileName = locateLocal("tmp", "phonefile.vcf"); 2814 fileName = locateLocal("tmp", "phonefile.vcf");
2869#else 2815#else
2870 fileName = "/tmp/phonefile.vcf"; 2816 fileName = "/tmp/phonefile.vcf";
2871#endif 2817#endif
2872 if ( !PhoneAccess::readFromPhone( fileName) ) { 2818 if ( !PhoneAccess::readFromPhone( fileName) ) {
2873 message(i18n("Phone access failed!")); 2819 message(i18n("Phone access failed!"));
2874 return false; 2820 return false;
2875 } 2821 }
2876 AddressBook abLocal( fileName,"syncContact"); 2822 AddressBook abLocal( fileName,"syncContact");
2877 bool syncOK = false; 2823 bool syncOK = false;
2878 if ( abLocal.load() ) { 2824 {
2825 abLocal.importFromFile( fileName );
2879 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2826 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2880 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2827 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2881 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2828 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2882 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2829 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2883 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2830 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2884 if ( syncOK ) { 2831 if ( syncOK ) {
2885 if ( syncManager->mWriteBackFile ) { 2832 if ( syncManager->mWriteBackFile ) {
2833 abLocal.removeSyncAddressees( true );
2886 abLocal.saveABphone( fileName ); 2834 abLocal.saveABphone( fileName );
2887 abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2835 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2888 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2836 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2889 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2837 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2890 } 2838 }
2891 } 2839 }
2892 setModified(); 2840 setModified();
2893 } 2841 }
2894 if ( syncOK ) 2842 if ( syncOK )
2895 mViewManager->refreshView(); 2843 mViewManager->refreshView();
2896 return syncOK; 2844 return syncOK;
2897} 2845}
2898void KABCore::getFile( bool success ) 2846void KABCore::getFile( bool success )
2899{ 2847{
2900 if ( ! success ) { 2848 if ( ! success ) {
2901 message( i18n("Error receiving file. Nothing changed!") ); 2849 message( i18n("Error receiving file. Nothing changed!") );
2902 return; 2850 return;
2903 } 2851 }
2904 mAddressBook->importFromFile( sentSyncFile() , false, true ); 2852 mAddressBook->importFromFile( sentSyncFile() , false, true );
2905 message( i18n("Pi-Sync successful!") ); 2853 message( i18n("Pi-Sync successful!") );
2906 mViewManager->refreshView(); 2854 mViewManager->refreshView();
2907} 2855}
2908void KABCore::syncFileRequest() 2856void KABCore::syncFileRequest()
2909{ 2857{
2910 mAddressBook->export2File( sentSyncFile() ); 2858 mAddressBook->export2File( sentSyncFile() );
2911} 2859}
2912QString KABCore::sentSyncFile() 2860QString KABCore::sentSyncFile()
2913{ 2861{
2914#ifdef _WIN32_ 2862#ifdef _WIN32_
2915 return locateLocal( "tmp", "copysyncab.vcf" ); 2863 return locateLocal( "tmp", "copysyncab.vcf" );
2916#else 2864#else
2917 return QString( "/tmp/copysyncab.vcf" ); 2865 return QString( "/tmp/copysyncab.vcf" );
2918#endif 2866#endif
2919} 2867}
2920 2868
2921void KABCore::setCaptionBack() 2869void KABCore::setCaptionBack()
2922{ 2870{
2923 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2871 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2924} 2872}
diff --git a/libkdepim/ksyncprefsdialog.cpp b/libkdepim/ksyncprefsdialog.cpp
index 84cc448..cf8f996 100644
--- a/libkdepim/ksyncprefsdialog.cpp
+++ b/libkdepim/ksyncprefsdialog.cpp
@@ -1,731 +1,732 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> 3 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qgroupbox.h> 26#include <qgroupbox.h>
27#include <qbuttongroup.h> 27#include <qbuttongroup.h>
28#include <qlineedit.h> 28#include <qlineedit.h>
29#include <qfont.h> 29#include <qfont.h>
30#include <qslider.h> 30#include <qslider.h>
31#include <qfile.h> 31#include <qfile.h>
32#include <qdir.h> 32#include <qdir.h>
33#include <qtextstream.h> 33#include <qtextstream.h>
34#include <qcombobox.h> 34#include <qcombobox.h>
35#include <qvbox.h> 35#include <qvbox.h>
36#include <qhbox.h> 36#include <qhbox.h>
37#include <qspinbox.h> 37#include <qspinbox.h>
38#include <qdatetime.h> 38#include <qdatetime.h>
39#include <qcheckbox.h> 39#include <qcheckbox.h>
40#include <qradiobutton.h> 40#include <qradiobutton.h>
41#include <qpushbutton.h> 41#include <qpushbutton.h>
42#include <qstrlist.h> 42#include <qstrlist.h>
43#include <qapplication.h> 43#include <qapplication.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qscrollview.h> 45#include <qscrollview.h>
46 46
47#include <kcolorbutton.h> 47#include <kcolorbutton.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <klocale.h> 49#include <klocale.h>
50#include <kglobal.h> 50#include <kglobal.h>
51#include <kfontdialog.h> 51#include <kfontdialog.h>
52#include <kmessagebox.h> 52#include <kmessagebox.h>
53#include <kcolordialog.h> 53#include <kcolordialog.h>
54#include <kiconloader.h> 54#include <kiconloader.h>
55#include <kemailsettings.h> 55#include <kemailsettings.h>
56#include <kstandarddirs.h> 56#include <kstandarddirs.h>
57#include <kfiledialog.h> 57#include <kfiledialog.h>
58#include <kmessagebox.h> 58#include <kmessagebox.h>
59 59
60//#include <kurlrequester.h> 60//#include <kurlrequester.h>
61#include <klineedit.h> 61#include <klineedit.h>
62#include "ksyncprofile.h" 62#include "ksyncprofile.h"
63 63
64 64
65//#include "koprefs.h" 65//#include "koprefs.h"
66 66
67#include "ksyncprefsdialog.h" 67#include "ksyncprefsdialog.h"
68//#include "koglobals.h" 68//#include "koglobals.h"
69 69
70 70
71KSyncPrefsDialog::KSyncPrefsDialog(QWidget *parent, char *name, bool modal) : 71KSyncPrefsDialog::KSyncPrefsDialog(QWidget *parent, char *name, bool modal) :
72 KDialog(parent,name,true) 72 KDialog(parent,name,true)
73{ 73{
74 74
75 setCaption( i18n("Synchronization Preferences")); 75 setCaption( i18n("Synchronization Preferences"));
76 76
77 mSyncProfiles.setAutoDelete( true ); 77 mSyncProfiles.setAutoDelete( true );
78 setupSyncAlgTab(); 78 setupSyncAlgTab();
79} 79}
80 80
81 81
82KSyncPrefsDialog::~KSyncPrefsDialog() 82KSyncPrefsDialog::~KSyncPrefsDialog()
83{ 83{
84} 84}
85 85
86void KSyncPrefsDialog::setupSyncAlgTab() 86void KSyncPrefsDialog::setupSyncAlgTab()
87{ 87{
88 QLabel * lab; 88 QLabel * lab;
89 //QFrame *page = addPage(i18n("Sync Prefs"),0,0); 89 //QFrame *page = addPage(i18n("Sync Prefs"),0,0);
90 QVBox * mainbox = new QVBox( this ); 90 QVBox * mainbox = new QVBox( this );
91 QScrollView* sv = new QScrollView( mainbox ); 91 QScrollView* sv = new QScrollView( mainbox );
92 QHBoxLayout * lay = new QHBoxLayout( this ); 92 QHBoxLayout * lay = new QHBoxLayout( this );
93 lay->addWidget( mainbox ); 93 lay->addWidget( mainbox );
94 QHBox * b_box = new QHBox( mainbox ); 94 QHBox * b_box = new QHBox( mainbox );
95 95
96 QPushButton* button = new QPushButton( i18n("Ok"), b_box ); 96 QPushButton* button = new QPushButton( i18n("Ok"), b_box );
97 connect ( button, SIGNAL( clicked()), this, SLOT (slotOK() ) ); 97 connect ( button, SIGNAL( clicked()), this, SLOT (slotOK() ) );
98 button = new QPushButton( i18n("Cancel"), b_box ); 98 button = new QPushButton( i18n("Cancel"), b_box );
99 connect ( button, SIGNAL( clicked()), this, SLOT (reject() ) ); 99 connect ( button, SIGNAL( clicked()), this, SLOT (reject() ) );
100 //QBoxLayout * sl = new QVBoxLayout(this ); 100 //QBoxLayout * sl = new QVBoxLayout(this );
101 //sl->addWidget ( sv ); 101 //sl->addWidget ( sv );
102 sv->setResizePolicy ( QScrollView::AutoOneFit ); 102 sv->setResizePolicy ( QScrollView::AutoOneFit );
103 QFrame *topFrame = new QFrame ( sv ); 103 QFrame *topFrame = new QFrame ( sv );
104 sv->addChild( topFrame ); 104 sv->addChild( topFrame );
105 mSetupSyncAlgTab = topFrame; 105 mSetupSyncAlgTab = topFrame;
106 QGridLayout *topLayout = new QGridLayout(topFrame,6,2); 106 QGridLayout *topLayout = new QGridLayout(topFrame,6,2);
107 topLayout->setSpacing(spacingHint()); 107 topLayout->setSpacing(spacingHint());
108 topLayout->setMargin(marginHint()); 108 topLayout->setMargin(marginHint());
109 109
110 //lab = new QLabel(i18n("Sync settings not yet implemented. DO NOT USE!"), topFrame); 110 //lab = new QLabel(i18n("Sync settings not yet implemented. DO NOT USE!"), topFrame);
111 int iii = 0; 111 int iii = 0;
112 //topLayout->addMultiCellWidget(lab , iii,iii,0,1); 112 //topLayout->addMultiCellWidget(lab , iii,iii,0,1);
113 //++iii; 113 //++iii;
114 114
115 mMyMachineName = new QLineEdit(topFrame); 115 mMyMachineName = new QLineEdit(topFrame);
116 lab = new QLabel(mMyMachineName, i18n("Local device name:"), topFrame); 116 lab = new QLabel(mMyMachineName, i18n("Local device name:"), topFrame);
117 topLayout->addWidget(lab ,iii,0); 117 topLayout->addWidget(lab ,iii,0);
118 topLayout->addWidget(mMyMachineName,iii,1); 118 topLayout->addWidget(mMyMachineName,iii,1);
119 ++iii; 119 ++iii;
120 120
121 QHBox* buttonbox = new QHBox( topFrame); 121 QHBox* buttonbox = new QHBox( topFrame);
122 topLayout->addMultiCellWidget(buttonbox, iii,iii,0,1); 122 topLayout->addMultiCellWidget(buttonbox, iii,iii,0,1);
123 ++iii; 123 ++iii;
124 button = new QPushButton( i18n("New profile"), buttonbox ); 124 button = new QPushButton( i18n("New profile"), buttonbox );
125 connect ( button, SIGNAL( clicked()), this, SLOT (newProfile() ) ); 125 connect ( button, SIGNAL( clicked()), this, SLOT (newProfile() ) );
126 126
127 button = new QPushButton( i18n("Clone profile"), buttonbox ); 127 button = new QPushButton( i18n("Clone profile"), buttonbox );
128 connect ( button, SIGNAL( clicked()), this, SLOT ( cloneProfile() ) ); 128 connect ( button, SIGNAL( clicked()), this, SLOT ( cloneProfile() ) );
129 129
130 button = new QPushButton( i18n("Delete profile"), buttonbox ); 130 button = new QPushButton( i18n("Delete profile"), buttonbox );
131 connect ( button, SIGNAL( clicked()), this, SLOT (deleteProfile() ) ); 131 connect ( button, SIGNAL( clicked()), this, SLOT (deleteProfile() ) );
132 132
133 mProfileBox = new QComboBox(topFrame); 133 mProfileBox = new QComboBox(topFrame);
134 mProfileBox->setEditable ( true ); 134 mProfileBox->setEditable ( true );
135 mProfileBox->setInsertionPolicy(QComboBox::NoInsertion); 135 mProfileBox->setInsertionPolicy(QComboBox::NoInsertion);
136 connect ( mProfileBox, SIGNAL(activated ( int ) ), this, SLOT (profileChanged( int ) ) ); 136 connect ( mProfileBox, SIGNAL(activated ( int ) ), this, SLOT (profileChanged( int ) ) );
137 connect ( mProfileBox, SIGNAL( textChanged ( const QString & ) ), this, SLOT (textChanged( const QString & ) ) ); 137 connect ( mProfileBox, SIGNAL( textChanged ( const QString & ) ), this, SLOT (textChanged( const QString & ) ) );
138 138
139 lab = new QLabel(mProfileBox, i18n("Profile:"), topFrame); 139 lab = new QLabel(mProfileBox, i18n("Profile:"), topFrame);
140 topLayout->addWidget(lab ,iii,0); 140 topLayout->addWidget(lab ,iii,0);
141 topLayout->addWidget(mProfileBox, iii,1); 141 topLayout->addWidget(mProfileBox, iii,1);
142 ++iii; 142 ++iii;
143 143
144 QHBox *iims = new QHBox( topFrame ); 144 QHBox *iims = new QHBox( topFrame );
145 new QLabel( i18n("Include in multiple "), iims ); 145 new QLabel( i18n("Include in multiple "), iims );
146 mIncludeInRing = new QCheckBox( i18n("calendar "), iims ); 146 mIncludeInRing = new QCheckBox( i18n("calendar "), iims );
147 mIncludeInRingAB = new QCheckBox( i18n("addressbook "), iims ); 147 mIncludeInRingAB = new QCheckBox( i18n("addressbook "), iims );
148 mIncludeInRingPWM = new QCheckBox( i18n("pwmanager"), iims ); 148 mIncludeInRingPWM = new QCheckBox( i18n("pwmanager"), iims );
149 new QLabel( i18n(" sync"), iims ); 149 new QLabel( i18n(" sync"), iims );
150 topLayout->addMultiCellWidget(iims, iii,iii,0,1); 150 topLayout->addMultiCellWidget(iims, iii,iii,0,1);
151 ++iii; 151 ++iii;
152 152
153 mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), topFrame ); 153 mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), topFrame );
154 topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1); 154 topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1);
155 ++iii; 155 ++iii;
156 QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync preferences"), topFrame); 156 QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync preferences"), topFrame);
157 topLayout->addMultiCellWidget(gr, iii,iii,0,1); 157 topLayout->addMultiCellWidget(gr, iii,iii,0,1);
158 ++iii; 158 ++iii;
159 loc = new QRadioButton ( i18n("Take local entry on conflict"), gr ); 159 loc = new QRadioButton ( i18n("Take local entry on conflict"), gr );
160 rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr ); 160 rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr );
161 newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr ); 161 newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr );
162 ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr ); 162 ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr );
163 f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr ); 163 f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr );
164 f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr ); 164 f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr );
165 // both = new QRadioButton ( i18n("Take both on conflict"), gr ); 165 // both = new QRadioButton ( i18n("Take both on conflict"), gr );
166 166
167 mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), topFrame ); 167 mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), topFrame );
168 topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1); 168 topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1);
169 ++iii; 169 ++iii;
170 170
171 mWriteBackFile = new QCheckBox( i18n("Write back synced data"), topFrame ); 171 mWriteBackFile = new QCheckBox( i18n("Write back synced data"), topFrame );
172 topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1); 172 topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1);
173 ++iii; 173 ++iii;
174 174
175 mWriteBackExisting= new QCheckBox( i18n("-- Write back (on remote) existing entries only"), topFrame ); 175 mWriteBackExisting= new QCheckBox( i18n("-- Write back (on remote) existing entries only"), topFrame );
176 topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1); 176 topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1);
177 ++iii; 177 ++iii;
178 178
179 mWriteBackFuture= new QCheckBox( i18n("-- Write back (calendar) entries in future only"), topFrame ); 179 mWriteBackFuture= new QCheckBox( i18n("-- Write back (calendar) entries in future only"), topFrame );
180 topLayout->addMultiCellWidget(mWriteBackFuture, iii,iii,0,1); 180 topLayout->addMultiCellWidget(mWriteBackFuture, iii,iii,0,1);
181 ++iii; 181 ++iii;
182 topLayout->addMultiCellWidget(new QLabel( i18n("---- Max. weeks in future: ") , topFrame ), iii,iii,0,0); 182 topLayout->addMultiCellWidget(new QLabel( i18n("---- Max. weeks in future: ") , topFrame ), iii,iii,0,0);
183 mWriteBackFutureWeeks= new QSpinBox(1,104, 1, topFrame); 183 mWriteBackFutureWeeks= new QSpinBox(1,104, 1, topFrame);
184 topLayout->addMultiCellWidget(mWriteBackFutureWeeks, iii,iii,1,1); 184 topLayout->addMultiCellWidget(mWriteBackFutureWeeks, iii,iii,1,1);
185 ++iii; 185 ++iii;
186 186
187 proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), topFrame); 187 proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), topFrame);
188 gr = proGr; 188 gr = proGr;
189 topLayout->addMultiCellWidget(gr, iii,iii,0,1); 189 topLayout->addMultiCellWidget(gr, iii,iii,0,1);
190 ++iii; 190 ++iii;
191 mIsLocal = new QRadioButton ( i18n("Local file"), gr ); 191 mIsLocal = new QRadioButton ( i18n("Local file"), gr );
192 mIsPi = new QRadioButton ( i18n("Pi-Sync ( direct Kx/Pi to Kx/Pi sync )"), gr ); 192 mIsPi = new QRadioButton ( i18n("Pi-Sync ( direct Kx/Pi to Kx/Pi sync )"), gr );
193 connect (mIsPi, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) ); 193 connect (mIsPi, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) );
194 mIsNotLocal = new QRadioButton ( i18n("Remote file (w down/upload command)"), gr ); 194 mIsNotLocal = new QRadioButton ( i18n("Remote file (w down/upload command)"), gr );
195 connect (mIsLocal, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) ); 195 connect (mIsLocal, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) );
196 mIsPhone = new QRadioButton ( i18n("Mobile device (cell phone)"), gr ); 196 mIsPhone = new QRadioButton ( i18n("Mobile device (cell phone)"), gr );
197 connect (mIsPhone, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) ); 197 connect (mIsPhone, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) );
198 198
199 199
200 phoneWidget = new QVBox( topFrame); 200 phoneWidget = new QVBox( topFrame);
201 topLayout->addMultiCellWidget(phoneWidget, iii,iii,0,1); 201 topLayout->addMultiCellWidget(phoneWidget, iii,iii,0,1);
202 ++iii; 202 ++iii;
203 mWriteContactToSIM= new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget ); 203 mWriteContactToSIM = 0;//new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget );
204 QHBox* temphb = new QHBox( phoneWidget ); 204 QHBox* temphb = new QHBox( phoneWidget );
205 new QLabel( i18n("I/O device: "), temphb ); 205 new QLabel( i18n("I/O device: "), temphb );
206 mPhoneDevice = new QLineEdit( temphb); 206 mPhoneDevice = new QLineEdit( temphb);
207 button = new QPushButton( i18n("Help..."), temphb ); 207 button = new QPushButton( i18n("Help..."), temphb );
208 connect ( button, SIGNAL( clicked()), this, SLOT ( helpDevice() ) ); 208 connect ( button, SIGNAL( clicked()), this, SLOT ( helpDevice() ) );
209 209
210 210
211 temphb = new QHBox( phoneWidget ); 211 temphb = new QHBox( phoneWidget );
212 new QLabel( i18n("Connection: "), temphb ); 212 new QLabel( i18n("Connection: "), temphb );
213 mPhoneConnection = new QLineEdit( temphb); 213 mPhoneConnection = new QLineEdit( temphb);
214 button = new QPushButton( i18n("Help..."), temphb ); 214 button = new QPushButton( i18n("Help..."), temphb );
215 connect ( button, SIGNAL( clicked()), this, SLOT ( helpConnection() ) ); 215 connect ( button, SIGNAL( clicked()), this, SLOT ( helpConnection() ) );
216 216
217 217
218 temphb = new QHBox( phoneWidget ); 218 temphb = new QHBox( phoneWidget );
219 new QLabel( i18n("Model(opt.): "), temphb ); 219 new QLabel( i18n("Model(opt.): "), temphb );
220 mPhoneModel = new QLineEdit( temphb); 220 mPhoneModel = new QLineEdit( temphb);
221 button = new QPushButton( i18n("Help..."), temphb ); 221 button = new QPushButton( i18n("Help..."), temphb );
222 connect ( button, SIGNAL( clicked()), this, SLOT ( helpModel() ) ); 222 connect ( button, SIGNAL( clicked()), this, SLOT ( helpModel() ) );
223 223
224 // *** local 224 // *** local
225 localFileWidget = new QVBox( topFrame); 225 localFileWidget = new QVBox( topFrame);
226 topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1); 226 topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1);
227 ++iii; 227 ++iii;
228 temphb = new QHBox( localFileWidget ); 228 temphb = new QHBox( localFileWidget );
229 229
230 lab = new QLabel( i18n("Local file Cal:"), temphb ); 230 lab = new QLabel( i18n("Local file Cal:"), temphb );
231 lab = new QLabel( i18n("Local file ABook:"), temphb ); 231 lab = new QLabel( i18n("Local file ABook:"), temphb );
232 lab = new QLabel( i18n("Local file PWMgr:"), temphb ); 232 lab = new QLabel( i18n("Local file PWMgr:"), temphb );
233 temphb = new QHBox( localFileWidget ); 233 temphb = new QHBox( localFileWidget );
234 button = new QPushButton( i18n("Choose..."), temphb ); 234 button = new QPushButton( i18n("Choose..."), temphb );
235 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) ); 235 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) );
236 button = new QPushButton( i18n("Choose..."), temphb ); 236 button = new QPushButton( i18n("Choose..."), temphb );
237 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFileAB() ) ); 237 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFileAB() ) );
238 button = new QPushButton( i18n("Choose..."), temphb ); 238 button = new QPushButton( i18n("Choose..."), temphb );
239 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFilePWM() ) ); 239 connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFilePWM() ) );
240 temphb = new QHBox( localFileWidget ); 240 temphb = new QHBox( localFileWidget );
241 241
242 mRemoteFile = new QLineEdit( temphb); 242 mRemoteFile = new QLineEdit( temphb);
243 mRemoteFileAB = new QLineEdit( temphb); 243 mRemoteFileAB = new QLineEdit( temphb);
244 mRemoteFilePWM = new QLineEdit( temphb); 244 mRemoteFilePWM = new QLineEdit( temphb);
245 245
246 // *** remote 246 // *** remote
247 remoteFileWidget = new QVBox( topFrame); 247 remoteFileWidget = new QVBox( topFrame);
248 topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1); 248 topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1);
249 ++iii; 249 ++iii;
250 temphb = new QHBox( remoteFileWidget ); 250 temphb = new QHBox( remoteFileWidget );
251 new QLabel( i18n("Calendar:"), temphb); 251 new QLabel( i18n("Calendar:"), temphb);
252 new QLabel( i18n("AddressBook:"), temphb); 252 new QLabel( i18n("AddressBook:"), temphb);
253 new QLabel( i18n("PWManager:"), temphb); 253 new QLabel( i18n("PWManager:"), temphb);
254 254
255 lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget); 255 lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget);
256 temphb = new QHBox( remoteFileWidget ); 256 temphb = new QHBox( remoteFileWidget );
257 mRemotePrecommand = new QLineEdit(temphb); 257 mRemotePrecommand = new QLineEdit(temphb);
258 mRemotePrecommandAB = new QLineEdit(temphb); 258 mRemotePrecommandAB = new QLineEdit(temphb);
259 mRemotePrecommandPWM = new QLineEdit(temphb); 259 mRemotePrecommandPWM = new QLineEdit(temphb);
260 260
261 lab = new QLabel( i18n("Local temp file:"), remoteFileWidget); 261 lab = new QLabel( i18n("Local temp file:"), remoteFileWidget);
262 temphb = new QHBox( remoteFileWidget ); 262 temphb = new QHBox( remoteFileWidget );
263 mLocalTempFile = new QLineEdit(temphb); 263 mLocalTempFile = new QLineEdit(temphb);
264 mLocalTempFileAB = new QLineEdit(temphb); 264 mLocalTempFileAB = new QLineEdit(temphb);
265 mLocalTempFilePWM = new QLineEdit(temphb); 265 mLocalTempFilePWM = new QLineEdit(temphb);
266 266
267 lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget); 267 lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget);
268 temphb = new QHBox( remoteFileWidget ); 268 temphb = new QHBox( remoteFileWidget );
269 mRemotePostcommand = new QLineEdit(temphb ); 269 mRemotePostcommand = new QLineEdit(temphb );
270 mRemotePostcommandAB = new QLineEdit(temphb ); 270 mRemotePostcommandAB = new QLineEdit(temphb );
271 mRemotePostcommandPWM = new QLineEdit(temphb ); 271 mRemotePostcommandPWM = new QLineEdit(temphb );
272 272
273 lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget); 273 lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget);
274 temphb = new QHBox( remoteFileWidget ); 274 temphb = new QHBox( remoteFileWidget );
275 button = new QPushButton( i18n("ssh/scp"), temphb ); 275 button = new QPushButton( i18n("ssh/scp"), temphb );
276 connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) ); 276 connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) );
277 button = new QPushButton( i18n("ftp"), temphb ); 277 button = new QPushButton( i18n("ftp"), temphb );
278 connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) ); 278 connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) );
279 lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget); 279 lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget);
280 280
281 // *** pi-sync 281 // *** pi-sync
282 piWidget = new QVBox( topFrame); 282 piWidget = new QVBox( topFrame);
283 topLayout->addMultiCellWidget(piWidget, iii,iii,0,1); 283 topLayout->addMultiCellWidget(piWidget, iii,iii,0,1);
284 ++iii; 284 ++iii;
285 temphb = new QHBox( piWidget ); 285 temphb = new QHBox( piWidget );
286 new QLabel( i18n("Calendar:"), temphb); 286 new QLabel( i18n("Calendar:"), temphb);
287 new QLabel( i18n("AddressBook:"), temphb); 287 new QLabel( i18n("AddressBook:"), temphb);
288 new QLabel( i18n("PWManager:"), temphb); 288 new QLabel( i18n("PWManager:"), temphb);
289 289
290 lab = new QLabel( i18n("Password for remote access: (could be the same for each)"), piWidget); 290 lab = new QLabel( i18n("Password for remote access: (could be the same for each)"), piWidget);
291 temphb = new QHBox( piWidget ); 291 temphb = new QHBox( piWidget );
292 mRemotePw = new QLineEdit(temphb); 292 mRemotePw = new QLineEdit(temphb);
293 mRemotePwAB = new QLineEdit(temphb); 293 mRemotePwAB = new QLineEdit(temphb);
294 mRemotePwPWM = new QLineEdit(temphb); 294 mRemotePwPWM = new QLineEdit(temphb);
295 295
296 lab = new QLabel( i18n("Remote IP address: (could be the same for each)"), piWidget); 296 lab = new QLabel( i18n("Remote IP address: (could be the same for each)"), piWidget);
297 temphb = new QHBox( piWidget ); 297 temphb = new QHBox( piWidget );
298 mRemoteIP = new QLineEdit(temphb); 298 mRemoteIP = new QLineEdit(temphb);
299 mRemoteIPAB = new QLineEdit(temphb); 299 mRemoteIPAB = new QLineEdit(temphb);
300 mRemoteIPPWM = new QLineEdit(temphb); 300 mRemoteIPPWM = new QLineEdit(temphb);
301 301
302 lab = new QLabel( i18n("Remote port number: (should be different for each)"), piWidget); 302 lab = new QLabel( i18n("Remote port number: (should be different for each)"), piWidget);
303 temphb = new QHBox( piWidget ); 303 temphb = new QHBox( piWidget );
304 mRemotePort = new QLineEdit(temphb); 304 mRemotePort = new QLineEdit(temphb);
305 mRemotePortAB = new QLineEdit(temphb); 305 mRemotePortAB = new QLineEdit(temphb);
306 mRemotePortPWM = new QLineEdit(temphb); 306 mRemotePortPWM = new QLineEdit(temphb);
307 307
308} 308}
309 309
310 310
311 311
312 312
313 313
314void KSyncPrefsDialog::slotOK() 314void KSyncPrefsDialog::slotOK()
315{ 315{
316 if ( mMyMachineName->text() == "undefined" ) { 316 if ( mMyMachineName->text() == "undefined" ) {
317 KMessageBox::error(this,i18n("Local device name undefined!\nPlease define device name!"),i18n("KO/Pi config error")); 317 KMessageBox::error(this,i18n("Local device name undefined!\nPlease define device name!"),i18n("KO/Pi config error"));
318 return; 318 return;
319 } 319 }
320 int i; 320 int i;
321 for (i = 0; i < mSyncProfileNames.count(); ++ i) { 321 for (i = 0; i < mSyncProfileNames.count(); ++ i) {
322 if ( mSyncProfileNames.contains( mSyncProfileNames[i]) > 1 ) { 322 if ( mSyncProfileNames.contains( mSyncProfileNames[i]) > 1 ) {
323 KMessageBox::error(this,i18n("Multiple profiles with same name!\nPlease use unique profile names!"),i18n("KO/Pi config error")); 323 KMessageBox::error(this,i18n("Multiple profiles with same name!\nPlease use unique profile names!"),i18n("KO/Pi config error"));
324 return; 324 return;
325 } 325 }
326 } 326 }
327 usrWriteConfig(); 327 usrWriteConfig();
328 QDialog::accept(); 328 QDialog::accept();
329} 329}
330void KSyncPrefsDialog::accept() 330void KSyncPrefsDialog::accept()
331{ 331{
332 slotOK(); 332 slotOK();
333} 333}
334void KSyncPrefsDialog::chooseFile() 334void KSyncPrefsDialog::chooseFile()
335{ 335{
336 QString fn = QDir::homeDirPath(); 336 QString fn = QDir::homeDirPath();
337 337
338 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 338 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
339 if ( fn == "" ) 339 if ( fn == "" )
340 return; 340 return;
341 mRemoteFile->setText( fn ); 341 mRemoteFile->setText( fn );
342} 342}
343 343
344void KSyncPrefsDialog::chooseFileAB() 344void KSyncPrefsDialog::chooseFileAB()
345{ 345{
346 QString fn = QDir::homeDirPath(); 346 QString fn = QDir::homeDirPath();
347 347
348 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.vcf)"), this ); 348 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.vcf)"), this );
349 if ( fn == "" ) 349 if ( fn == "" )
350 return; 350 return;
351 mRemoteFileAB->setText( fn ); 351 mRemoteFileAB->setText( fn );
352} 352}
353 353
354void KSyncPrefsDialog::chooseFilePWM() 354void KSyncPrefsDialog::chooseFilePWM()
355{ 355{
356 QString fn = QDir::homeDirPath(); 356 QString fn = QDir::homeDirPath();
357 357
358 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.pwm)"), this ); 358 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.pwm)"), this );
359 if ( fn == "" ) 359 if ( fn == "" )
360 return; 360 return;
361 mRemoteFilePWM->setText( fn ); 361 mRemoteFilePWM->setText( fn );
362} 362}
363 363
364void KSyncPrefsDialog::textChanged( const QString & s ) 364void KSyncPrefsDialog::textChanged( const QString & s )
365{ 365{
366 if ( mProfileBox->count() == 0 ) 366 if ( mProfileBox->count() == 0 )
367 return; 367 return;
368 if ( currentSelection < 3 ) { 368 if ( currentSelection < 3 ) {
369 //KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error")); 369 //KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error"));
370 mProfileBox->blockSignals( true ); 370 mProfileBox->blockSignals( true );
371 mProfileBox->setCurrentItem(mProfileBox-> currentItem ()); 371 mProfileBox->setCurrentItem(mProfileBox-> currentItem ());
372 mProfileBox->blockSignals( false ); 372 mProfileBox->blockSignals( false );
373 return; 373 return;
374 } 374 }
375 //qDebug("cur i %d ",mProfileBox-> currentItem () ); 375 //qDebug("cur i %d ",mProfileBox-> currentItem () );
376 mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ; 376 mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ;
377 KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ; 377 KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ;
378 prof->setName( s ); 378 prof->setName( s );
379 mSyncProfileNames[mProfileBox-> currentItem ()] = s; 379 mSyncProfileNames[mProfileBox-> currentItem ()] = s;
380} 380}
381void KSyncPrefsDialog::profileChanged( int item ) 381void KSyncPrefsDialog::profileChanged( int item )
382{ 382{
383 //qDebug("KSyncPrefsDialog::profileChanged before %d, count %d ", item, mProfileBox->count() ); 383 //qDebug("KSyncPrefsDialog::profileChanged before %d, count %d ", item, mProfileBox->count() );
384 KSyncProfile* prof; 384 KSyncProfile* prof;
385 saveProfile(); 385 saveProfile();
386 currentSelection = item; 386 currentSelection = item;
387 prof = mSyncProfiles.at(item) ; 387 prof = mSyncProfiles.at(item) ;
388 388
389 mRemotePw->setText(prof->getRemotePw()); 389 mRemotePw->setText(prof->getRemotePw());
390 mRemoteIP->setText(prof->getRemoteIP()); 390 mRemoteIP->setText(prof->getRemoteIP());
391 mRemotePort->setText(prof->getRemotePort()); 391 mRemotePort->setText(prof->getRemotePort());
392 392
393 mRemotePwAB->setText(prof->getRemotePwAB()); 393 mRemotePwAB->setText(prof->getRemotePwAB());
394 mRemoteIPAB->setText(prof->getRemoteIPAB()); 394 mRemoteIPAB->setText(prof->getRemoteIPAB());
395 mRemotePortAB->setText(prof->getRemotePortAB()); 395 mRemotePortAB->setText(prof->getRemotePortAB());
396 396
397 mRemotePwPWM->setText(prof->getRemotePwPWM()); 397 mRemotePwPWM->setText(prof->getRemotePwPWM());
398 mRemoteIPPWM->setText(prof->getRemoteIPPWM()); 398 mRemoteIPPWM->setText(prof->getRemoteIPPWM());
399 mRemotePortPWM->setText(prof->getRemotePortPWM()); 399 mRemotePortPWM->setText(prof->getRemotePortPWM());
400 400
401 mRemotePrecommand->setText(prof->getPreSyncCommand()); 401 mRemotePrecommand->setText(prof->getPreSyncCommand());
402 mRemotePostcommand->setText(prof->getPostSyncCommand()); 402 mRemotePostcommand->setText(prof->getPostSyncCommand());
403 mLocalTempFile->setText(prof->getLocalTempFile()); 403 mLocalTempFile->setText(prof->getLocalTempFile());
404 mRemoteFile->setText(prof->getRemoteFileName()) ; 404 mRemoteFile->setText(prof->getRemoteFileName()) ;
405 405
406 mRemotePrecommandAB->setText(prof->getPreSyncCommandAB()); 406 mRemotePrecommandAB->setText(prof->getPreSyncCommandAB());
407 mRemotePostcommandAB->setText(prof->getPostSyncCommandAB()); 407 mRemotePostcommandAB->setText(prof->getPostSyncCommandAB());
408 mLocalTempFileAB->setText(prof->getLocalTempFileAB()); 408 mLocalTempFileAB->setText(prof->getLocalTempFileAB());
409 mRemoteFileAB->setText(prof->getRemoteFileNameAB()) ; 409 mRemoteFileAB->setText(prof->getRemoteFileNameAB()) ;
410 410
411 mRemotePrecommandPWM->setText(prof->getPreSyncCommandPWM()); 411 mRemotePrecommandPWM->setText(prof->getPreSyncCommandPWM());
412 mRemotePostcommandPWM->setText(prof->getPostSyncCommandPWM()); 412 mRemotePostcommandPWM->setText(prof->getPostSyncCommandPWM());
413 mLocalTempFilePWM->setText(prof->getLocalTempFilePWM()); 413 mLocalTempFilePWM->setText(prof->getLocalTempFilePWM());
414 mRemoteFilePWM->setText(prof->getRemoteFileNamePWM()) ; 414 mRemoteFilePWM->setText(prof->getRemoteFileNamePWM()) ;
415 415
416 mWriteContactToSIM->setChecked( prof->getWriteContactToSIM()); 416 if ( mWriteContactToSIM )
417 mWriteContactToSIM->setChecked( prof->getWriteContactToSIM());
417 mPhoneDevice->setText(prof->getPhoneDevice()); 418 mPhoneDevice->setText(prof->getPhoneDevice());
418 mPhoneConnection->setText(prof->getPhoneConnection()); 419 mPhoneConnection->setText(prof->getPhoneConnection());
419 mPhoneModel->setText(prof->getPhoneModel()); 420 mPhoneModel->setText(prof->getPhoneModel());
420 421
421 mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync()); 422 mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync());
422 mAskForPreferences->setChecked( prof->getAskForPreferences()); 423 mAskForPreferences->setChecked( prof->getAskForPreferences());
423 mWriteBackExisting->setChecked( prof->getWriteBackExisting() ); 424 mWriteBackExisting->setChecked( prof->getWriteBackExisting() );
424 mWriteBackFile->setChecked( prof->getWriteBackFile()); 425 mWriteBackFile->setChecked( prof->getWriteBackFile());
425 mIncludeInRing->setChecked( prof->getIncludeInRingSync() ); 426 mIncludeInRing->setChecked( prof->getIncludeInRingSync() );
426 mIncludeInRingAB->setChecked( prof->getIncludeInRingSyncAB() ); 427 mIncludeInRingAB->setChecked( prof->getIncludeInRingSyncAB() );
427 mIncludeInRingPWM->setChecked( prof->getIncludeInRingSyncPWM() ); 428 mIncludeInRingPWM->setChecked( prof->getIncludeInRingSyncPWM() );
428 mWriteBackFuture->setChecked( prof->getWriteBackFuture()); 429 mWriteBackFuture->setChecked( prof->getWriteBackFuture());
429 mWriteBackFutureWeeks->setValue( prof->getWriteBackFutureWeeks() ); 430 mWriteBackFutureWeeks->setValue( prof->getWriteBackFutureWeeks() );
430 431
431 switch ( prof->getSyncPrefs() ) { 432 switch ( prof->getSyncPrefs() ) {
432 case 0: 433 case 0:
433 loc->setChecked( true); 434 loc->setChecked( true);
434 break; 435 break;
435 case 1: 436 case 1:
436 rem->setChecked( true ); 437 rem->setChecked( true );
437 break; 438 break;
438 case 2: 439 case 2:
439 newest->setChecked( true); 440 newest->setChecked( true);
440 break; 441 break;
441 case 3: 442 case 3:
442 ask->setChecked( true); 443 ask->setChecked( true);
443 break; 444 break;
444 case 4: 445 case 4:
445 f_loc->setChecked( true); 446 f_loc->setChecked( true);
446 break; 447 break;
447 case 5: 448 case 5:
448 f_rem->setChecked( true); 449 f_rem->setChecked( true);
449 break; 450 break;
450 case 6: 451 case 6:
451 //both->setChecked( true); 452 //both->setChecked( true);
452 break; 453 break;
453 default: 454 default:
454 break; 455 break;
455 } 456 }
456 mIsLocal->setChecked(prof->getIsLocalFileSync()) ; 457 mIsLocal->setChecked(prof->getIsLocalFileSync()) ;
457 mIsPhone->setChecked(prof->getIsPhoneSync()) ; 458 mIsPhone->setChecked(prof->getIsPhoneSync()) ;
458 mIsPi->setChecked(prof->getIsPiSync()) ; 459 mIsPi->setChecked(prof->getIsPiSync()) ;
459 mIsNotLocal->setChecked(!prof->getIsLocalFileSync() && !prof->getIsPhoneSync() &&!prof->getIsPiSync() ); 460 mIsNotLocal->setChecked(!prof->getIsLocalFileSync() && !prof->getIsPhoneSync() &&!prof->getIsPiSync() );
460 proGr->setEnabled( item > 2 ); 461 proGr->setEnabled( item > 2 );
461 if ( item < 3 ) { 462 if ( item < 3 ) {
462 localFileWidget->hide(); 463 localFileWidget->hide();
463 remoteFileWidget->hide(); 464 remoteFileWidget->hide();
464 phoneWidget->hide(); 465 phoneWidget->hide();
465 piWidget->hide(); 466 piWidget->hide();
466 467
467 } else 468 } else
468 kindChanged( prof->getIsLocalFileSync() ); 469 kindChanged( prof->getIsLocalFileSync() );
469} 470}
470 471
471void KSyncPrefsDialog::fillSSH() 472void KSyncPrefsDialog::fillSSH()
472{ 473{
473 mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" ); 474 mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" );
474 mLocalTempFile->setText("/tmp/mycalendar.ics" ); 475 mLocalTempFile->setText("/tmp/mycalendar.ics" );
475 mRemotePostcommand->setText("scp /tmp/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics" ); 476 mRemotePostcommand->setText("scp /tmp/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics" );
476 mRemotePrecommandAB->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/kabc/std.vcf /tmp/std.vcf" ); 477 mRemotePrecommandAB->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/kabc/std.vcf /tmp/std.vcf" );
477 mLocalTempFileAB->setText("/tmp/std.vcf" ); 478 mLocalTempFileAB->setText("/tmp/std.vcf" );
478 mRemotePostcommandAB->setText("scp /tmp/std.vcf zaurus@192.168.0.65:/home/zaurus/kdepim/apps/kabc/std.vcf" ); 479 mRemotePostcommandAB->setText("scp /tmp/std.vcf zaurus@192.168.0.65:/home/zaurus/kdepim/apps/kabc/std.vcf" );
479 mRemotePrecommandPWM->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/pwmanager/passwords.pwm /tmp/passwords.pwm" ); 480 mRemotePrecommandPWM->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/pwmanager/passwords.pwm /tmp/passwords.pwm" );
480 mLocalTempFilePWM->setText("/tmp/passwords.pwm" ); 481 mLocalTempFilePWM->setText("/tmp/passwords.pwm" );
481 mRemotePostcommandPWM->setText("scp /tmp/passwords.pwm zaurus@192.168.0.65:/home/zaurus/kdepim/apps/pwmanager/pwmanager.pwm" ); 482 mRemotePostcommandPWM->setText("scp /tmp/passwords.pwm zaurus@192.168.0.65:/home/zaurus/kdepim/apps/pwmanager/pwmanager.pwm" );
482} 483}
483void KSyncPrefsDialog::fillFTP() 484void KSyncPrefsDialog::fillFTP()
484{ 485{
485 mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics" ); 486 mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics" );
486 mLocalTempFile->setText("/tmp/mycalendar.ics" ); 487 mLocalTempFile->setText("/tmp/mycalendar.ics" );
487 mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" ); 488 mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" );
488 mRemotePrecommandAB->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/kabc/std.vcf" ); 489 mRemotePrecommandAB->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/kabc/std.vcf" );
489 mLocalTempFileAB->setText("/tmp/std.vcf" ); 490 mLocalTempFileAB->setText("/tmp/std.vcf" );
490 mRemotePostcommandAB->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/kabc/std.vcf /tmp/std.vcf" ); 491 mRemotePostcommandAB->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/kabc/std.vcf /tmp/std.vcf" );
491 492
492 mRemotePrecommandPWM->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/pwmanager/passwords.pwm" ); 493 mRemotePrecommandPWM->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/pwmanager/passwords.pwm" );
493 mLocalTempFilePWM->setText("/tmp/passwords.pwm" ); 494 mLocalTempFilePWM->setText("/tmp/passwords.pwm" );
494 mRemotePostcommandPWM->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/pwmanager/passwords.pwm /tmp/passwords.pwm" ); 495 mRemotePostcommandPWM->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/pwmanager/passwords.pwm /tmp/passwords.pwm" );
495 496
496} 497}
497void KSyncPrefsDialog::kindChanged( bool b ) 498void KSyncPrefsDialog::kindChanged( bool b )
498{ 499{
499 500
500 if ( mIsLocal->isChecked () ) 501 if ( mIsLocal->isChecked () )
501 localFileWidget->show(); 502 localFileWidget->show();
502 else 503 else
503 localFileWidget->hide(); 504 localFileWidget->hide();
504 505
505 if ( mIsNotLocal->isChecked () ) 506 if ( mIsNotLocal->isChecked () )
506 remoteFileWidget->show(); 507 remoteFileWidget->show();
507 else 508 else
508 remoteFileWidget->hide(); 509 remoteFileWidget->hide();
509 510
510 if ( mIsPhone->isChecked () ) { 511 if ( mIsPhone->isChecked () ) {
511 phoneWidget->show(); 512 phoneWidget->show();
512 } 513 }
513 else { 514 else {
514 phoneWidget->hide(); 515 phoneWidget->hide();
515 } 516 }
516 if ( mIsPi->isChecked () ) { 517 if ( mIsPi->isChecked () ) {
517 piWidget->show(); 518 piWidget->show();
518 } 519 }
519 else { 520 else {
520 piWidget->hide(); 521 piWidget->hide();
521 } 522 }
522 523
523} 524}
524void KSyncPrefsDialog::deleteProfile() 525void KSyncPrefsDialog::deleteProfile()
525{ 526{
526 //qDebug("KSyncPrefsDialog::deleteProfile() "); 527 //qDebug("KSyncPrefsDialog::deleteProfile() ");
527 if ( currentSelection >= 0 ) { 528 if ( currentSelection >= 0 ) {
528 if ( currentSelection < 3 ) { 529 if ( currentSelection < 3 ) {
529 KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error")); 530 KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error"));
530 return; 531 return;
531 } 532 }
532 KSyncProfile* temp = mSyncProfiles.at(currentSelection); 533 KSyncProfile* temp = mSyncProfiles.at(currentSelection);
533 mSyncProfiles.remove( temp ); 534 mSyncProfiles.remove( temp );
534 mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection )); 535 mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection ));
535 insertProfiles(); 536 insertProfiles();
536 } 537 }
537} 538}
538 539
539void KSyncPrefsDialog::saveProfile() 540void KSyncPrefsDialog::saveProfile()
540{ 541{
541 KSyncProfile* prof; 542 KSyncProfile* prof;
542 if ( currentSelection >= 0 ) { 543 if ( currentSelection >= 0 ) {
543 prof = mSyncProfiles.at(currentSelection) ; 544 prof = mSyncProfiles.at(currentSelection) ;
544 545
545 prof->setRemotePw( mRemotePw->text()); 546 prof->setRemotePw( mRemotePw->text());
546 prof->setRemoteIP( mRemoteIP->text()); 547 prof->setRemoteIP( mRemoteIP->text());
547 prof->setRemotePort( mRemotePort->text()); 548 prof->setRemotePort( mRemotePort->text());
548 549
549 prof->setRemotePwAB( mRemotePwAB->text()); 550 prof->setRemotePwAB( mRemotePwAB->text());
550 prof->setRemoteIPAB( mRemoteIPAB->text()); 551 prof->setRemoteIPAB( mRemoteIPAB->text());
551 prof->setRemotePortAB( mRemotePortAB->text()); 552 prof->setRemotePortAB( mRemotePortAB->text());
552 553
553 prof->setRemotePwPWM( mRemotePwPWM->text()); 554 prof->setRemotePwPWM( mRemotePwPWM->text());
554 prof->setRemoteIPPWM( mRemoteIPPWM->text()); 555 prof->setRemoteIPPWM( mRemoteIPPWM->text());
555 prof->setRemotePortPWM( mRemotePortPWM->text()); 556 prof->setRemotePortPWM( mRemotePortPWM->text());
556 557
557 prof->setPreSyncCommand( mRemotePrecommand->text()); 558 prof->setPreSyncCommand( mRemotePrecommand->text());
558 prof->setPostSyncCommand( mRemotePostcommand->text() ); 559 prof->setPostSyncCommand( mRemotePostcommand->text() );
559 prof->setLocalTempFile( mLocalTempFile->text()); 560 prof->setLocalTempFile( mLocalTempFile->text());
560 prof->setRemoteFileName( mRemoteFile->text() ); 561 prof->setRemoteFileName( mRemoteFile->text() );
561 prof->setPreSyncCommandAB( mRemotePrecommandAB->text()); 562 prof->setPreSyncCommandAB( mRemotePrecommandAB->text());
562 prof->setPostSyncCommandAB( mRemotePostcommandAB->text() ); 563 prof->setPostSyncCommandAB( mRemotePostcommandAB->text() );
563 prof->setLocalTempFileAB( mLocalTempFileAB->text()); 564 prof->setLocalTempFileAB( mLocalTempFileAB->text());
564 prof->setRemoteFileNameAB( mRemoteFileAB->text() ); 565 prof->setRemoteFileNameAB( mRemoteFileAB->text() );
565 prof->setPreSyncCommandPWM( mRemotePrecommandPWM->text()); 566 prof->setPreSyncCommandPWM( mRemotePrecommandPWM->text());
566 prof->setPostSyncCommandPWM( mRemotePostcommandPWM->text() ); 567 prof->setPostSyncCommandPWM( mRemotePostcommandPWM->text() );
567 prof->setLocalTempFilePWM( mLocalTempFilePWM->text()); 568 prof->setLocalTempFilePWM( mLocalTempFilePWM->text());
568 prof->setRemoteFileNamePWM( mRemoteFilePWM->text() ); 569 prof->setRemoteFileNamePWM( mRemoteFilePWM->text() );
569 prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() ); 570 prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() );
570 prof->setAskForPreferences( mAskForPreferences->isChecked()); 571 prof->setAskForPreferences( mAskForPreferences->isChecked());
571 prof->setWriteBackExisting(mWriteBackExisting->isChecked() ); 572 prof->setWriteBackExisting(mWriteBackExisting->isChecked() );
572 prof->setWriteBackFile( mWriteBackFile->isChecked()); 573 prof->setWriteBackFile( mWriteBackFile->isChecked());
573 prof->setIncludeInRingSync( mIncludeInRing->isChecked() ); 574 prof->setIncludeInRingSync( mIncludeInRing->isChecked() );
574 prof->setIncludeInRingSyncAB( mIncludeInRingAB->isChecked() ); 575 prof->setIncludeInRingSyncAB( mIncludeInRingAB->isChecked() );
575 prof->setIncludeInRingSyncPWM( mIncludeInRingPWM->isChecked() ); 576 prof->setIncludeInRingSyncPWM( mIncludeInRingPWM->isChecked() );
576 int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ; 577 int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ;
577 prof->setSyncPrefs( syncprefs); 578 prof->setSyncPrefs( syncprefs);
578 prof->setIsLocalFileSync( mIsLocal->isChecked() ); 579 prof->setIsLocalFileSync( mIsLocal->isChecked() );
579 prof->setIsPhoneSync( mIsPhone->isChecked() ); 580 prof->setIsPhoneSync( mIsPhone->isChecked() );
580 prof->setIsPiSync( mIsPi->isChecked() ); 581 prof->setIsPiSync( mIsPi->isChecked() );
581 prof->setWriteBackFuture(mWriteBackFuture->isChecked()); 582 prof->setWriteBackFuture(mWriteBackFuture->isChecked());
582 prof->setWriteBackFutureWeeks(mWriteBackFutureWeeks->value()); 583 prof->setWriteBackFutureWeeks(mWriteBackFutureWeeks->value());
583 584 if ( mWriteContactToSIM )
584 prof->setWriteContactToSIM(mWriteContactToSIM->isChecked()); 585 prof->setWriteContactToSIM(mWriteContactToSIM->isChecked());
585 prof->setPhoneDevice( mPhoneDevice->text() ); 586 prof->setPhoneDevice( mPhoneDevice->text() );
586 prof->setPhoneConnection( mPhoneConnection->text() ); 587 prof->setPhoneConnection( mPhoneConnection->text() );
587 prof->setPhoneModel( mPhoneModel->text() ); 588 prof->setPhoneModel( mPhoneModel->text() );
588 589
589 } 590 }
590 591
591} 592}
592 593
593void KSyncPrefsDialog::insertProfiles() 594void KSyncPrefsDialog::insertProfiles()
594{ 595{
595 int curItem = mProfileBox->currentItem(); 596 int curItem = mProfileBox->currentItem();
596 mProfileBox->blockSignals( true ); 597 mProfileBox->blockSignals( true );
597 mProfileBox->clear(); 598 mProfileBox->clear();
598 mProfileBox->insertStringList (mSyncProfileNames ); 599 mProfileBox->insertStringList (mSyncProfileNames );
599 int item = mSyncProfileNames.count() -1; 600 int item = mSyncProfileNames.count() -1;
600 if ( curItem >= 0 && mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() ) 601 if ( curItem >= 0 && mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() )
601 mProfileBox->setCurrentItem( curItem ); 602 mProfileBox->setCurrentItem( curItem );
602 else if ( item >= 0 ) { 603 else if ( item >= 0 ) {
603 mProfileBox->setCurrentItem( item ); 604 mProfileBox->setCurrentItem( item );
604 } 605 }
605 currentSelection = -1; 606 currentSelection = -1;
606 if ( mSyncProfileNames.count() > 0 ) { 607 if ( mSyncProfileNames.count() > 0 ) {
607 //qDebug(" profileChanged( mProfileBox->currentItem() "); 608 //qDebug(" profileChanged( mProfileBox->currentItem() ");
608 profileChanged( mProfileBox->currentItem() ); 609 profileChanged( mProfileBox->currentItem() );
609 currentSelection = mProfileBox->currentItem(); 610 currentSelection = mProfileBox->currentItem();
610 } 611 }
611 mProfileBox->blockSignals( false ); 612 mProfileBox->blockSignals( false );
612} 613}
613 614
614void KSyncPrefsDialog::addProfile ( KSyncProfile* temp ) 615void KSyncPrefsDialog::addProfile ( KSyncProfile* temp )
615{ 616{
616 saveProfile(); 617 saveProfile();
617 mSyncProfiles.append( temp ); 618 mSyncProfiles.append( temp );
618 mSyncProfileNames << temp->getName(); 619 mSyncProfileNames << temp->getName();
619 insertProfiles(); 620 insertProfiles();
620 int last = mProfileBox->count() -1; 621 int last = mProfileBox->count() -1;
621 mProfileBox->blockSignals( true ); 622 mProfileBox->blockSignals( true );
622 mProfileBox->setCurrentItem( last ); 623 mProfileBox->setCurrentItem( last );
623 mProfileBox->blockSignals( false ); 624 mProfileBox->blockSignals( false );
624 profileChanged(last); 625 profileChanged(last);
625} 626}
626void KSyncPrefsDialog::newProfile() 627void KSyncPrefsDialog::newProfile()
627{ 628{
628 addProfile ( new KSyncProfile () ); 629 addProfile ( new KSyncProfile () );
629} 630}
630 631
631void KSyncPrefsDialog::cloneProfile() 632void KSyncPrefsDialog::cloneProfile()
632{ 633{
633 if ( currentSelection >= 0 ) 634 if ( currentSelection >= 0 )
634 addProfile (mSyncProfiles.at(currentSelection)->clone()) ; 635 addProfile (mSyncProfiles.at(currentSelection)->clone()) ;
635 else 636 else
636 newProfile(); 637 newProfile();
637} 638}
638 639
639void KSyncPrefsDialog::setLocalMachineName ( const QString& name ) 640void KSyncPrefsDialog::setLocalMachineName ( const QString& name )
640{ 641{
641 mMyMachineName->setText( name ); 642 mMyMachineName->setText( name );
642 643
643} 644}
644QString KSyncPrefsDialog::getLocalMachineName ( ) 645QString KSyncPrefsDialog::getLocalMachineName ( )
645{ 646{
646 return mMyMachineName->text(); 647 return mMyMachineName->text();
647} 648}
648 649
649QStringList KSyncPrefsDialog::getSyncProfileNames() 650QStringList KSyncPrefsDialog::getSyncProfileNames()
650{ 651{
651 return mSyncProfileNames; 652 return mSyncProfileNames;
652} 653}
653void KSyncPrefsDialog::usrReadConfig() 654void KSyncPrefsDialog::usrReadConfig()
654{ 655{
655 //KConfig *config = KOGlobals::config(); 656 //KConfig *config = KOGlobals::config();
656 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 657 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
657 config.setGroup("General"); 658 config.setGroup("General");
658 mSyncProfileNames =config.readListEntry("SyncProfileNames"); 659 mSyncProfileNames =config.readListEntry("SyncProfileNames");
659 mMyMachineName->setText(config.readEntry("LocalMachineName","undefined")); 660 mMyMachineName->setText(config.readEntry("LocalMachineName","undefined"));
660 int i; 661 int i;
661 KSyncProfile* temp ; 662 KSyncProfile* temp ;
662 mSyncProfiles.clear(); 663 mSyncProfiles.clear();
663 for ( i = 0; i < mSyncProfileNames.count();++i ) { 664 for ( i = 0; i < mSyncProfileNames.count();++i ) {
664 temp = new KSyncProfile (); 665 temp = new KSyncProfile ();
665 temp->setName( mSyncProfileNames[i] ); 666 temp->setName( mSyncProfileNames[i] );
666 temp->readConfig( &config ); 667 temp->readConfig( &config );
667 mSyncProfiles.append( temp ); 668 mSyncProfiles.append( temp );
668 } 669 }
669 insertProfiles(); 670 insertProfiles();
670 //mMyMachineName->setText(KOPrefs::instance()->mLocalMachineName ); 671 //mMyMachineName->setText(KOPrefs::instance()->mLocalMachineName );
671} 672}
672 673
673 674
674void KSyncPrefsDialog::usrWriteConfig() 675void KSyncPrefsDialog::usrWriteConfig()
675{ 676{
676 saveProfile(); 677 saveProfile();
677 if ( currentSelection >= 0 ) 678 if ( currentSelection >= 0 )
678 profileChanged(currentSelection); 679 profileChanged(currentSelection);
679 //KConfig *config = KOGlobals::config(); 680 //KConfig *config = KOGlobals::config();
680 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 681 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
681 KSyncProfile* prof = mSyncProfiles.first(); 682 KSyncProfile* prof = mSyncProfiles.first();
682 QStringList externalSyncProfileNames; 683 QStringList externalSyncProfileNames;
683 externalSyncProfileNames.append("Sharp_DTM");; 684 externalSyncProfileNames.append("Sharp_DTM");;
684 while ( prof ) { 685 while ( prof ) {
685 prof->writeConfig(&config); 686 prof->writeConfig(&config);
686 if ( prof->getIsPhoneSync( ) ) 687 if ( prof->getIsPhoneSync( ) )
687 externalSyncProfileNames.append(prof->getName( ) ); 688 externalSyncProfileNames.append(prof->getName( ) );
688 prof = mSyncProfiles.next(); 689 prof = mSyncProfiles.next();
689 } 690 }
690 //KOPrefs::instance()->mSyncProfileNames = mSyncProfileNames; 691 //KOPrefs::instance()->mSyncProfileNames = mSyncProfileNames;
691 //KOPrefs::instance()->mLocalMachineName = mMyMachineName->text(); 692 //KOPrefs::instance()->mLocalMachineName = mMyMachineName->text();
692 config.setGroup("General"); 693 config.setGroup("General");
693 config.writeEntry("SyncProfileNames",mSyncProfileNames); 694 config.writeEntry("SyncProfileNames",mSyncProfileNames);
694 config.writeEntry("ExternSyncProfiles",externalSyncProfileNames); 695 config.writeEntry("ExternSyncProfiles",externalSyncProfileNames);
695 config.writeEntry("LocalMachineName",mMyMachineName->text()); 696 config.writeEntry("LocalMachineName",mMyMachineName->text());
696 config.sync(); 697 config.sync();
697} 698}
698 699
699void KSyncPrefsDialog::helpDevice() 700void KSyncPrefsDialog::helpDevice()
700{ 701{
701 QString hint = i18n("Insert device where\nphone is connected. E.g.:\n"); 702 QString hint = i18n("Insert device where\nphone is connected. E.g.:\n");
702#ifdef _WIN32_ 703#ifdef _WIN32_
703 hint += "Leave empty for Irda.\n" 704 hint += "Leave empty for Irda.\n"
704 "com1:\n(first serial port)\n" 705 "com1:\n(first serial port)\n"
705 "usb not supported\n" 706 "usb not supported\n"
706 "???\n(bluetooth device address)\n"; 707 "???\n(bluetooth device address)\n";
707 708
708#else 709#else
709 hint += "/dev/ircomm\n(Irda)\n" 710 hint += "/dev/ircomm\n(Irda)\n"
710 "/dev/ttyS0\n(first serial port)\n" 711 "/dev/ttyS0\n(first serial port)\n"
711 "/dev/ttyUSB0\n(first device usb port)\n" 712 "/dev/ttyUSB0\n(first device usb port)\n"
712 "???\n(bluetooth device address)\n"; 713 "???\n(bluetooth device address)\n";
713#endif 714#endif
714 KMessageBox::information(this,hint,i18n("KDE-Pim sync config")); 715 KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));
715} 716}
716void KSyncPrefsDialog::helpModel() 717void KSyncPrefsDialog::helpModel()
717{ 718{
718 QString hint = i18n("Leave empty or\ninsert name of phone model:\n"); 719 QString hint = i18n("Recommended: Leave empty!\n(Such that model can\nbe auto detected)\nOr insert name of model:\n");
719 hint += "E.g. for Nokia 6310i:\n6310i\nAlso possible:\nobex\nfor Obex connection"; 720 hint += "E.g. for Nokia 6310i:\n6310i\nAlso possible:\nobex\nfor Obex connection";
720 KMessageBox::information(this,hint,i18n("KDE-Pim sync config")); 721 KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));
721 722
722} 723}
723void KSyncPrefsDialog::helpConnection() 724void KSyncPrefsDialog::helpConnection()
724{ 725{
725 QString hint = i18n("Insert kind of connection,e.g.:\n"); 726 QString hint = i18n("Insert kind of connection,e.g.:\n");
726 hint += "irda | Nokia FBUS over infrared\n" 727 hint += "irda | Nokia FBUS over infrared\n"
727 "irdaat | AT commands infrared\n(for Siemens/Sony-Erricsson)\n" 728 "irdaat | AT commands infrared\n(for Siemens/Sony-Erricsson)\n"
728 "irdaobex | set also model as obex\n" 729 "irdaobex | set also model as obex\n"
729 "fbus | Nokia FBUS2 serial\n"; 730 "fbus | Nokia FBUS2 serial\n";
730 KMessageBox::information(this,hint,i18n("KDE-Pim sync config")); 731 KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));
731} 732}