4 #include <wx/tokenzr.h>
5 #include <wx/datetime.h>
8 #include "frmContactEditor.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.
21 wxString wxSContactString;
24 XABViewMode XVMData = MainPtr->GetViewMode();
26 wxSContactFilename = Filename;
28 // Check if we are using wxWidgets version 2.8 or less and
29 // execute the required command accordingly.
31 #if wxABI_VERSION < 20900
32 ContactFile.Open(Filename.c_str(), wxT("r"));
34 ContactFile.Open(Filename, wxT("r"));
37 if (ContactFile.IsOpened() == FALSE){
43 ContactFile.ReadAll(&wxSContactString, wxConvAuto());
47 std::map<int, wxString> ContactFileLines;
48 std::map<int, wxString>::iterator striter;
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));
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;
80 wxString wxSPropertySeg1;
81 wxString wxSPropertySeg2;
82 wxString wxSPropertyNextLine;
83 size_t ContactLineLen = 0;
84 int QuoteBreakPoint = 0;
87 int NicknameCount = 0;
101 int CategoryCount = 0;
107 int CalReqAdrCount = 0;
108 int FreeBusyCount = 0;
112 //int intValueSeek = 1;
114 for (std::map<int,wxString>::iterator iter = ContactFileLines.begin();
115 iter != ContactFileLines.end(); ++iter){
117 // Find the colon which splits the start bit from the data part.
119 ContactLine = iter->second;
121 while (ExtraLineSeek == TRUE){
123 // Check if there is extra data on the next line
124 // (indicated by space or tab at the start) and add data.
128 if (iter == ContactFileLines.end()){
135 wxSPropertyNextLine = iter->second;
138 if (wxSPropertyNextLine.Mid(0, 1) == wxT(" ") || wxSPropertyNextLine.Mid(0, 1) == wxT("\t")){
140 wxSPropertyNextLine.Remove(0, 1);
141 //wxSPropertyNextLine.Trim(FALSE);
142 //ContactLine.Trim();
143 ContactLine.Append(wxSPropertyNextLine);
148 ExtraLineSeek = FALSE;
154 ContactLineLen = ContactLine.Len();
156 // Make sure we are not in quotation mode.
157 // Make sure colon does not have \ or \\ before it.
159 for (int i = 0; i <= ContactLineLen; i++){
161 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
163 PropertyFind = FALSE;
165 } else if (PropertyFind == TRUE){
167 wxSProperty.Append(ContactLine.Mid(i, 1));
171 if (ContactLine.Mid(i, 1) == wxT("\"")){
173 if (QuoteMode == TRUE){
185 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
194 // Split that line at the point into two variables (ignore the colon).
196 wxSPropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
197 wxSPropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
199 // Add the data into the contact editor depending on what it is.
201 if (wxSProperty == wxT("KIND") && KindProcessed == FALSE){
203 // See frmContactEditor-LoadGroup.cpp
205 LoadKind(wxSPropertySeg2);
207 } else if (wxSProperty == wxT("MEMBER")){
209 // See frmContactEditor-LoadGroup.cpp
211 LoadMember(wxSPropertySeg2, &GroupCount);
213 } else if (wxSProperty == wxT("FN")){
215 // See frmContactEditor-LoadName.cpp
217 LoadFN(wxSPropertySeg1, wxSPropertySeg2, &FNCount, &FNProcessed, &ContactData);
219 } else if (wxSProperty == wxT("N") && NameProcessed == FALSE){
221 // See frmContactEditor-LoadName.cpp
223 LoadN(wxSPropertySeg1, wxSPropertySeg2, &NameProcessed, &ContactData);
225 } else if (wxSProperty == wxT("NICKNAME")){
227 // See frmContactEditor-LoadNickname.cpp
229 LoadNickname(wxSPropertySeg1, wxSPropertySeg2, &NicknameCount, &ContactData);
231 } else if (wxSProperty == wxT("GENDER") && GenderProcessed == FALSE){
233 // See frmContactEditor-LoadGender.cpp
235 LoadGender(wxSPropertySeg1, wxSPropertySeg2, &GenderProcessed, &ContactData);
237 } else if (wxSProperty == wxT("BDAY") && BirthdayProcessed == FALSE){
239 // See frmContactEditor-LoadBADays.cpp
241 LoadBDay(wxSPropertySeg1, wxSPropertySeg2, &BirthdayProcessed);
243 } else if (wxSProperty == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
245 // See frmContactEditor-LoadBADays.cpp
247 LoadAnniversary(wxSPropertySeg1, wxSPropertySeg2, &AnniversaryProcessed);
249 } else if (wxSProperty == wxT("TZ")){
251 // See frmContactEditor-LoadTimeZone.cpp
253 LoadTimeZone(wxSPropertySeg1, wxSPropertySeg2, &TZCount);
255 } else if (wxSProperty == wxT("ADR")){
257 // See frmContactEditor-LoadAddress.cpp
259 LoadADR(wxSPropertySeg1, wxSPropertySeg2, &ADRCount);
261 } else if (wxSProperty == wxT("EMAIL")){
263 // See frmContactEditor-LoadEmail.cpp
265 LoadEmail(wxSPropertySeg1, wxSPropertySeg2, &EmailCount);
267 } else if (wxSProperty == wxT("IMPP")){
269 // See frmContactEditor-LoadIM.cpp
271 LoadIM(wxSPropertySeg1, wxSPropertySeg2, &IMPPCount);
273 } else if (wxSProperty == wxT("TEL")){
275 // See frmContactEditor-LoadTelephone.cpp
277 LoadTelephone(wxSPropertySeg1, wxSPropertySeg2, &TelCount);
279 } else if (wxSProperty == wxT("LANG")){
281 // See frmContactEditor-LoadLanguage.cpp
283 LoadLanguage(wxSPropertySeg1, wxSPropertySeg2, &LangCount);
285 } else if (wxSProperty == wxT("GEO")){
287 // See frmContactEditor-LoadGeo.cpp
289 LoadGeo(wxSPropertySeg1, wxSPropertySeg2, &GeoCount);
291 } else if (wxSProperty == wxT("RELATED")){
293 // See fromContactEditor-LoadRelated.cpp
295 LoadRelated(wxSPropertySeg1, wxSPropertySeg2, &RelatedCount);
297 } else if (wxSProperty == wxT("URL")){
299 // See frmContactEditor-LoadURL.cpp
301 LoadURL(wxSPropertySeg1, wxSPropertySeg2, &URLCount);
303 } else if (wxSProperty == wxT("TITLE")) {
305 // See frmContactEditor-LoadTitle.cpp
307 LoadTitle(wxSPropertySeg1, wxSPropertySeg2, &TitleCount);
309 } else if (wxSProperty == wxT("ROLE")) {
311 // See frmContactEditor-LoadRole.cpp
313 LoadRole(wxSPropertySeg1, wxSPropertySeg2, &RoleCount);
315 } else if (wxSProperty == wxT("ORG")) {
317 // See frmContactEditor-LoadOrg.cpp
319 LoadOrg(wxSPropertySeg1, wxSPropertySeg2, &OrgCount);
321 } else if (wxSProperty == wxT("NOTE")) {
323 // See frmContactEditor-LoadNote.cpp
325 LoadNote(wxSPropertySeg1, wxSPropertySeg2, &NoteCount);
327 } else if (wxSProperty == wxT("CATEGORIES")) {
329 // See frmContactEditor-LoadCategory.cpp
331 LoadCategory(wxSPropertySeg1, wxSPropertySeg2, &CategoryCount);
333 } else if (wxSProperty == wxT("PHOTO")) {
335 // See frmContactEditor-LoadPhoto.cpp
337 LoadPhoto(wxSPropertySeg1, wxSPropertySeg2, &PhotoCount);
339 } else if (wxSProperty == wxT("LOGO")) {
341 // See frmContactEditor-LoadLogo.cpp
343 LoadLogo(wxSPropertySeg1, wxSPropertySeg2, &LogoCount);
345 } else if (wxSProperty == wxT("SOUND")) {
347 // See frmContactEditor-LoadSound.cpp
349 LoadSound(wxSPropertySeg1, wxSPropertySeg2, &SoundCount);
351 } else if (wxSProperty == wxT("CALURI")){
353 // See frmContactEditor-LoadCalendar.cpp
355 LoadCalURI(wxSPropertySeg1, wxSPropertySeg2, &CalAdrCount);
357 } else if (wxSProperty == wxT("CALADRURI")){
359 // See frmContactEditor-LoadCalendar.cpp
361 LoadCalAdrURI(wxSPropertySeg1, wxSPropertySeg2, &CalReqAdrCount);
363 } else if (wxSProperty == wxT("FBURL")){
365 // See frmContactEditor-LoadCalendar.cpp
367 LoadCalFreeBusy(wxSPropertySeg1, wxSPropertySeg2, &FreeBusyCount);
369 } else if (wxSProperty == wxT("KEY")){
371 // See frmContactEditor-LoadKey.cpp
373 LoadKey(wxSPropertySeg1, wxSPropertySeg2, &KeyCount);
375 } else if (wxSProperty == wxT("UID") && UIDProcessed == FALSE){
377 UIDToken = wxSPropertySeg2;
380 } else if (wxSProperty.Mid(0, 3) == wxT("VND")){
382 // Split the Vendor three ways.
384 wxStringTokenizer wSTVendorDetails(wxSPropertySeg1, wxT("-"));
387 wxString wxSVNDPropName;
390 while (wSTVendorDetails.HasMoreTokens() == TRUE){
392 wSTVendorDetails.GetNextToken();
393 wxSVNDID = wSTVendorDetails.GetNextToken();
394 wxSVNDPropName = wSTVendorDetails.GetNextToken();
399 if (!wxSVNDID.IsEmpty() && !wxSVNDPropName.IsEmpty()){
401 // Setup the values for later processing.
403 VendorList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
404 VendorListPEN.insert(std::make_pair(intValueSeek, wxSVNDID));
405 VendorListElement.insert(std::make_pair(intValueSeek, wxSVNDPropName));
407 // Add the data to the vendor variables.
411 coldata.SetId(intValueSeek);
412 coldata.SetData(intValueSeek);
413 coldata.SetText(wxSVNDID + wxT("-") + wxSVNDPropName);
415 ListCtrlIndex = lboVendorNamespace->InsertItem(coldata);
417 VendorList.erase(intValueSeek);
418 VendorListPEN.erase(intValueSeek);
419 VendorListElement.erase(intValueSeek);
421 VendorList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
422 VendorListPEN.insert(std::make_pair(intValueSeek, wxSVNDID));
423 VendorListElement.insert(std::make_pair(intValueSeek, wxSVNDPropName));
430 } else if (wxSProperty.Mid(0, 2) == wxT("X-")){
434 XTokenList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
435 XTokenListTokens.insert(std::make_pair(intValueSeek, wxSPropertySeg1.Mid(2)));
441 coldata.SetId(intValueSeek);
442 coldata.SetData(intValueSeek);
443 coldata.SetText(wxSPropertySeg1.Mid(2));
445 ListCtrlIndex = lboXToken->InsertItem(coldata);
453 // Reset the variables.
457 ExtraLineSeek = TRUE;
465 FMTimer.SetFilename(Filename);
466 FMTimer.Start(10000, FALSE);
473 void frmContactEditor::SplitValues(wxString *PropertyLine,
474 std::map<int,int> *SplitPoints,
475 std::map<int,int> *SplitLength,
478 size_t intPropertyLen = PropertyLine->Len();
479 int intSplitsFound = 0;
480 int intSplitSize = 0;
481 int intSplitSeek = 0;
483 for (int i = intSize; i <= intPropertyLen; i++){
487 if (PropertyLine->Mid(i, 1) == wxT(";") &&
488 PropertyLine->Mid((i - 1), 1) != wxT("\\")){
490 if (intSplitsFound == 0){
492 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
496 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
500 SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
510 if (intSplitsFound == 0){
512 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
513 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
517 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
518 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));