Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
1ef92c485598ea6be4e1978765fb67de7bf4f907
[xestiaab/.git] / source / contacteditor / frmContactEditor-Load.cpp
1 #include <map>
3 #include <wx/ffile.h>
4 #include <wx/tokenzr.h>
5 #include <wx/datetime.h>
6 #include <wx/dir.h>
8 #include "frmContactEditor.h"
10 #include "../enums.h"
11 #include "../version.h"
12 #include "../vcard/vcard.h"
13 #include "../common/textprocessing.h"
14 #include "../common/dirs.h"
16 bool frmContactEditor::LoadContact(wxString Filename){
18         // Load the contact into the contact editor.
19         
20         wxFFile ContactFile;
21         wxString wxSContactString;
22         wxString ContactLine;
23         vCard ContactData;
24         XABViewMode XVMData = MainPtr->GetViewMode();
25         
26         wxSContactFilename = Filename;
27         
28         // Check if we are using wxWidgets version 2.8 or less and
29         // execute the required command accordingly.
30         
31 #if wxABI_VERSION < 20900
32         ContactFile.Open(Filename.c_str(), wxT("r"));
33 #else
34         ContactFile.Open(Filename, wxT("r"));
35 #endif  
36         
37         if (ContactFile.IsOpened() == FALSE){
38         
39                 return FALSE;
40         
41         }
42         
43         ContactFile.ReadAll(&wxSContactString, wxConvAuto());
44         
45         // Split the lines.
46         
47         std::map<int, wxString> ContactFileLines;
48         std::map<int, wxString>::iterator striter;
49         
50         wxStringTokenizer wSTContactFileLines(wxSContactString, wxT("\r\n"));
52         int ContactLineSeek = 0;
54         while (wSTContactFileLines.HasMoreTokens() == TRUE){
56                 ContactLine = wSTContactFileLines.GetNextToken();
57                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
58                 ContactLineSeek++;              
59         
60         }
62         // Get the line.
64         bool QuoteMode = FALSE;
65         bool PropertyFind = TRUE;
66         bool HasExtraNicknames = FALSE;
67         bool IgnoreGender = FALSE;
68         bool ExtraLineSeek = TRUE;
69         bool BirthdayProcessed = FALSE;
70         bool AnniversaryProcessed = FALSE;
71         bool FNProcessed = FALSE;
72         bool GenderProcessed = FALSE;
73         bool NameProcessed = FALSE;
74         bool UIDProcessed = FALSE;
75         bool KindProcessed = FALSE;
76         bool ETagFound = FALSE;
77         bool ETagOrigFound = FALSE;
78         int intExtraNickname = 0;
79         wxString wxSProperty;
80         wxString wxSPropertySeg1;
81         wxString wxSPropertySeg2;
82         wxString wxSPropertyNextLine;
83         size_t ContactLineLen = 0;
84         int QuoteBreakPoint = 0;
85         int FNCount = 0;
86         int NameCount = 0;
87         int NicknameCount = 0;
88         int ADRCount = 0;
89         int EmailCount = 0;
90         int IMPPCount = 0;
91         int TelCount = 0;
92         int LangCount = 0;
93         int TZCount = 0;
94         int GeoCount = 0;
95         int URLCount = 0;
96         int RelatedCount = 0;
97         int TitleCount = 0;
98         int RoleCount = 0;
99         int OrgCount = 0;
100         int NoteCount = 0;
101         int CategoryCount = 0;
102         int GroupCount = 0;
103         int PhotoCount = 0;
104         int LogoCount = 0;
105         int SoundCount = 0;
106         int CalAdrCount = 0;
107         int CalReqAdrCount = 0;
108         int FreeBusyCount = 0;
109         int KeyCount = 0;
110         int VendorCount = 0;
111         int XTokenCount = 0;
112         //int intValueSeek = 1;
114         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
115          iter != ContactFileLines.end(); ++iter){
116         
117                 // Find the colon which splits the start bit from the data part.
118                 
119                 ContactLine = iter->second;
120                 
121                 while (ExtraLineSeek == TRUE){
122                 
123                         // Check if there is extra data on the next line 
124                         // (indicated by space or tab at the start) and add data.
125                 
126                         iter++;
127                         
128                         if (iter == ContactFileLines.end()){
129                         
130                                 iter--;
131                                 break;
132                         
133                         }                       
134                 
135                         wxSPropertyNextLine = iter->second;
136                         
137                 
138                         if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
139                 
140                                 wxSPropertyNextLine.Remove(0, 1);
141                                 //wxSPropertyNextLine.Trim(FALSE);
142                                 //ContactLine.Trim();
143                                 ContactLine.Append(wxSPropertyNextLine);
144                 
145                         } else {
146                         
147                                 iter--;
148                                 ExtraLineSeek = FALSE;
149                         
150                         }
151                 
152                 }
154                 ContactLineLen = ContactLine.Len();
155                 
156                 // Make sure we are not in quotation mode.
157                 // Make sure colon does not have \ or \\ before it.
158                 
159                 for (int i = 0; i <= ContactLineLen; i++){
160                 
161                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
162                         
163                                 PropertyFind = FALSE;
164                         
165                         } else if (PropertyFind == TRUE){
166                         
167                                 wxSProperty.Append(ContactLine.Mid(i, 1));
168                         
169                         }               
170                 
171                         if (ContactLine.Mid(i, 1) == wxT("\"")){
172                         
173                                 if (QuoteMode == TRUE){
174                                 
175                                         QuoteMode = FALSE;
176                                 
177                                 } else {
178                         
179                                         QuoteMode = TRUE;
180                                         
181                                 }
182                         
183                         }
184                         
185                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
186                         
187                                 QuoteBreakPoint = i;
188                                 break;
189                         
190                         }
191                 
192                 }
193                 
194                 // Split that line at the point into two variables (ignore the colon).
195                 
196                 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
197                 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
198                 
199                 // Add the data into the contact editor depending on what it is.                                
200                 
201                 if (wxSProperty == wxT("KIND") && KindProcessed == FALSE){
202                 
203                         // See frmContactEditor-LoadGroup.cpp
204                 
205                         LoadKind(wxSPropertySeg2);
206                 
207                 } else if (wxSProperty == wxT("MEMBER")){
209                         // See frmContactEditor-LoadGroup.cpp
211                         LoadMember(wxSPropertySeg2, &GroupCount);               
212                 
213                 } else if (wxSProperty == wxT("FN")){
214                 
215                         // See frmContactEditor-LoadName.cpp
216                 
217                         LoadFN(wxSPropertySeg1, wxSPropertySeg2, &FNCount, &FNProcessed, &ContactData);
218                 
219                 } else if (wxSProperty == wxT("N") && NameProcessed == FALSE){
220                 
221                         // See frmContactEditor-LoadName.cpp
222                 
223                         LoadN(wxSPropertySeg1, wxSPropertySeg2, &NameProcessed, &ContactData);
224                 
225                 } else if (wxSProperty == wxT("NICKNAME")){
226                         
227                         // See frmContactEditor-LoadNickname.cpp
228                         
229                         LoadNickname(wxSPropertySeg1, wxSPropertySeg2, &NicknameCount, &ContactData);
230                         
231                 } else if (wxSProperty == wxT("GENDER") && GenderProcessed == FALSE){
232                 
233                         // See frmContactEditor-LoadGender.cpp
234                 
235                         LoadGender(wxSPropertySeg1, wxSPropertySeg2, &GenderProcessed, &ContactData);
236                 
237                 } else if (wxSProperty == wxT("BDAY") && BirthdayProcessed == FALSE){
239                         // See frmContactEditor-LoadBADays.cpp
241                         LoadBDay(wxSPropertySeg1, wxSPropertySeg2, &BirthdayProcessed);
242                 
243                 } else if (wxSProperty == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
244                         
245                         // See frmContactEditor-LoadBADays.cpp
246                         
247                         LoadAnniversary(wxSPropertySeg1, wxSPropertySeg2, &AnniversaryProcessed);
248                 
249                 } else if (wxSProperty == wxT("TZ")){
250                 
251                         // See frmContactEditor-LoadTimeZone.cpp
252                 
253                         LoadTimeZone(wxSPropertySeg1, wxSPropertySeg2, &TZCount);       
254                 
255                 } else if (wxSProperty == wxT("ADR")){
256                         
257                         // See frmContactEditor-LoadAddress.cpp
258                 
259                         LoadADR(wxSPropertySeg1, wxSPropertySeg2, &ADRCount);
260                 
261                 } else if (wxSProperty == wxT("EMAIL")){
262                 
263                         // See frmContactEditor-LoadEmail.cpp
264                         
265                         LoadEmail(wxSPropertySeg1, wxSPropertySeg2, &EmailCount);       
266                 
267                 } else if (wxSProperty == wxT("IMPP")){
268                 
269                         // See frmContactEditor-LoadIM.cpp
270                 
271                         LoadIM(wxSPropertySeg1, wxSPropertySeg2, &IMPPCount);
272                 
273                 } else if (wxSProperty == wxT("TEL")){
274                 
275                         // See frmContactEditor-LoadTelephone.cpp
276                 
277                         LoadTelephone(wxSPropertySeg1, wxSPropertySeg2, &TelCount);
278                 
279                 } else if (wxSProperty == wxT("LANG")){
280                 
281                         // See frmContactEditor-LoadLanguage.cpp
282                         
283                         LoadLanguage(wxSPropertySeg1, wxSPropertySeg2, &LangCount);
284                 
285                 } else if (wxSProperty == wxT("GEO")){
286                 
287                         // See frmContactEditor-LoadGeo.cpp
288                         
289                         LoadGeo(wxSPropertySeg1, wxSPropertySeg2, &GeoCount);   
290                 
291                 } else if (wxSProperty == wxT("RELATED")){
292                         
293                         // See fromContactEditor-LoadRelated.cpp
294                         
295                         LoadRelated(wxSPropertySeg1, wxSPropertySeg2, &RelatedCount);           
296                 
297                 } else if (wxSProperty == wxT("URL")){
299                         // See frmContactEditor-LoadURL.cpp
300                 
301                         LoadURL(wxSPropertySeg1, wxSPropertySeg2, &URLCount);
302                 
303                 } else if (wxSProperty == wxT("TITLE")) {
304                 
305                         // See frmContactEditor-LoadTitle.cpp
306                         
307                         LoadTitle(wxSPropertySeg1, wxSPropertySeg2, &TitleCount);
308                         
309                 } else if (wxSProperty == wxT("ROLE")) {
311                         // See frmContactEditor-LoadRole.cpp
312                 
313                         LoadRole(wxSPropertySeg1, wxSPropertySeg2, &RoleCount);
314                         
315                 } else if (wxSProperty == wxT("ORG")) {
316                 
317                         // See frmContactEditor-LoadOrg.cpp
318                         
319                         LoadOrg(wxSPropertySeg1, wxSPropertySeg2, &OrgCount);
320                         
321                 } else if (wxSProperty == wxT("NOTE")) {
323                         // See frmContactEditor-LoadNote.cpp
325                         LoadNote(wxSPropertySeg1, wxSPropertySeg2, &NoteCount); 
326                         
327                 } else if (wxSProperty == wxT("CATEGORIES")) {
328                 
329                         // See frmContactEditor-LoadCategory.cpp
330                 
331                         LoadCategory(wxSPropertySeg1, wxSPropertySeg2, &CategoryCount); 
332                         
333                 } else if (wxSProperty == wxT("PHOTO")) {
334                 
335                         // See frmContactEditor-LoadPhoto.cpp
336                         
337                         LoadPhoto(wxSPropertySeg1, wxSPropertySeg2, &PhotoCount);
339                 } else if (wxSProperty == wxT("LOGO")) {
340                 
341                         // See frmContactEditor-LoadLogo.cpp
342                 
343                         LoadLogo(wxSPropertySeg1, wxSPropertySeg2, &LogoCount);
344                         
345                 } else if (wxSProperty == wxT("SOUND")) {
346                 
347                         // See frmContactEditor-LoadSound.cpp
348                         
349                         LoadSound(wxSPropertySeg1, wxSPropertySeg2, &SoundCount);
350                         
351                 } else if (wxSProperty == wxT("CALURI")){
353                         // See frmContactEditor-LoadCalendar.cpp
354                         
355                         LoadCalURI(wxSPropertySeg1, wxSPropertySeg2, &CalAdrCount);
356                 
357                 } else if (wxSProperty == wxT("CALADRURI")){
359                         // See frmContactEditor-LoadCalendar.cpp
360                         
361                         LoadCalAdrURI(wxSPropertySeg1, wxSPropertySeg2, &CalReqAdrCount);
362                 
363                 } else if (wxSProperty == wxT("FBURL")){
365                         // See frmContactEditor-LoadCalendar.cpp
367                         LoadCalFreeBusy(wxSPropertySeg1, wxSPropertySeg2, &FreeBusyCount);
369                 } else if (wxSProperty == wxT("KEY")){
370                 
371                         // See frmContactEditor-LoadKey.cpp
372                         
373                         LoadKey(wxSPropertySeg1, wxSPropertySeg2, &KeyCount);
374                 
375                 } else if (wxSProperty == wxT("UID") && UIDProcessed == FALSE){
376                 
377                         UIDToken = wxSPropertySeg2;
378                         UIDProcessed = TRUE;
379                 
380                 } else if (wxSProperty.Mid(0, 3) == wxT("VND")){
381                 
382                         // Split the Vendor three ways.
383                         
384                         wxStringTokenizer wSTVendorDetails(wxSPropertySeg1, wxT("-"));
385                         
386                         wxString wxSVNDID;
387                         wxString wxSVNDPropName;
388                         long ListCtrlIndex;                     
390                         while (wSTVendorDetails.HasMoreTokens() == TRUE){
391                         
392                                 wSTVendorDetails.GetNextToken();
393                                 wxSVNDID = wSTVendorDetails.GetNextToken();
394                                 wxSVNDPropName = wSTVendorDetails.GetNextToken();
395                                 break;
396                         
397                         }
398                         
399                         if (!wxSVNDID.IsEmpty() && !wxSVNDPropName.IsEmpty()){
400                         
401                                 // Setup the values for later processing.
402                         
403                                 VendorList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
404                                 VendorListPEN.insert(std::make_pair(intValueSeek, wxSVNDID));
405                                 VendorListElement.insert(std::make_pair(intValueSeek, wxSVNDPropName));
406                         
407                                 // Add the data to the vendor variables.
408                         
409                                 wxListItem coldata;
410                 
411                                 coldata.SetId(intValueSeek);
412                                 coldata.SetData(intValueSeek);
413                                 coldata.SetText(wxSVNDID + wxT("-") + wxSVNDPropName);
415                                 ListCtrlIndex = lboVendorNamespace->InsertItem(coldata);
416                                 
417                                 VendorList.erase(intValueSeek);
418                                 VendorListPEN.erase(intValueSeek);
419                                 VendorListElement.erase(intValueSeek);
420                         
421                                 VendorList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
422                                 VendorListPEN.insert(std::make_pair(intValueSeek, wxSVNDID));
423                                 VendorListElement.insert(std::make_pair(intValueSeek, wxSVNDPropName));                         
424                         
425                                 VendorCount++;
426                                 intValueSeek++;
427                         
428                         }       
429                 
430                 } else if (wxSProperty.Mid(0, 2) == wxT("X-")){
431                 
432                         long ListCtrlIndex;
433                         
434                         XTokenList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
435                         XTokenListTokens.insert(std::make_pair(intValueSeek, wxSPropertySeg1.Mid(2)));
436                         
437                         // Add to the form.
438                         
439                         wxListItem coldata;
440                 
441                         coldata.SetId(intValueSeek);
442                         coldata.SetData(intValueSeek);
443                         coldata.SetText(wxSPropertySeg1.Mid(2));
445                         ListCtrlIndex = lboXToken->InsertItem(coldata);
446                         
447                         XTokenCount++;
448                         intValueSeek++;
449                         
450                 
451                 }
452                 
453                 // Reset the variables.
454                 
455                 QuoteMode = FALSE;
456                 PropertyFind = TRUE;
457                 ExtraLineSeek = TRUE;
458                 ContactLineLen = 0;
459                 QuoteBreakPoint = 0;
460                 ContactLine.Clear();
461                 wxSProperty.Clear();    
462         
463         }
464         
465         FMTimer.SetFilename(Filename);
466         FMTimer.Start(10000, FALSE);
467         
468         EditMode = TRUE;
469         
470         return TRUE;
473 void frmContactEditor::SplitValues(wxString *PropertyLine, 
474         std::map<int,int> *SplitPoints, 
475         std::map<int,int> *SplitLength, 
476         int intSize){
477         
478         size_t intPropertyLen = PropertyLine->Len();
479         int intSplitsFound = 0;
480         int intSplitSize = 0;
481         int intSplitSeek = 0;
482         
483         for (int i = intSize; i <= intPropertyLen; i++){
485                 intSplitSize++;
486         
487                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
488                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
489            
490                     if (intSplitsFound == 0){
491             
492                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
493           
494                     } else {
495            
496                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
497             
498                     }
499             
500                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
501             
502                     intSplitsFound++;
503                     intSplitSeek = i;
504                     intSplitSize = 0;
505             
506                 }
508         }
510         if (intSplitsFound == 0){
512                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
513                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
515         } else {
517                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
518                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
520         }
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy