X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Fcontacteditor%2FContactDataObject.cpp;h=e6c82a1382c0c5b76bcdece7458488cc11fa13fa;hp=0770747b1cecb900d9a5d7ec0d71887291f7a36a;hb=b9886d22768b3d67c03c3ae1c5152be92fdf1c89;hpb=c1f0c1c8b56a8304a894dea7f361bda8cbc8d11a diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 0770747..e6c82a1 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -96,6 +96,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ int RoleCount = 0; int OrganisationCount = 0; int NoteCount = 0; + int CategoryCount = 0; wxString ContactLine; wxString PropertyLine; wxString PropertySeg1; @@ -314,6 +315,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ ProcessNote(PropertySeg1, PropertySeg2, &NoteCount); NoteCount++; + } else if (Property == wxT("CATEGORIES")) { + + // See frmContactEditor-LoadCategory.cpp + + ProcessCategory(PropertySeg1, PropertySeg2, &CategoryCount); + CategoryCount++; + } } @@ -3587,7 +3595,6 @@ void ContactDataObject::ProcessNote(wxString PropertySeg1, wxString PropertySeg2 std::map *NoteListType = NULL; std::map *NoteListTokens = NULL; std::map *NoteListLanguage = NULL; - std::map *NoteListSortAs = NULL; std::map *NoteListPref = NULL; // Setup blank lines for later on. @@ -3666,11 +3673,6 @@ void ContactDataObject::ProcessNote(wxString PropertySeg1, wxString PropertySeg2 NoteListPID->erase(*NoteCount); NoteListPID->insert(std::make_pair(*NoteCount, PropertyValue)); - } else if (PropertyName == wxT("SORT-AS")){ - - NoteListSortAs->erase(*NoteCount); - NoteListSortAs->insert(std::make_pair(*NoteCount, PropertyValue)); - } else if (PropertyName == wxT("PREF")){ int PriorityNumber = 0; @@ -3734,6 +3736,306 @@ void ContactDataObject::ProcessNote(wxString PropertySeg1, wxString PropertySeg2 } +void ContactDataObject::ProcessCategory(wxString PropertySeg1, wxString PropertySeg2, int *CategoryCount){ + + std::map SplitPoints; + std::map SplitLength; + std::map::iterator SLiter; + wxString PropertyData; + wxString PropertyName; + wxString PropertyValue; + wxString PropertyTokens; + bool FirstToken = TRUE; + int intPrevValue = 12; + int intPref = 0; + int intType = 0; + long ListCtrlIndex; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 11; + + PropertyType PropType = PROPERTY_NONE; + + // Look for type before continuing. + + CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType); + + // Setup blank lines for later on. + + switch(PropType){ + case PROPERTY_NONE: + break; + case PROPERTY_HOME: + CategoriesListType.insert(std::make_pair(*CategoryCount, "home")); + break; + case PROPERTY_WORK: + CategoriesListType.insert(std::make_pair(*CategoryCount, "work")); + break; + } + + intPrevValue = 11; + + for (std::map::iterator intiter = SplitPoints.begin(); + intiter != SplitPoints.end(); ++intiter){ + + SLiter = SplitLength.find(intiter->first); + + PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second)); + + wxStringTokenizer PropertyElement (PropertyData, wxT("=")); + PropertyName = PropertyElement.GetNextToken(); + PropertyValue = PropertyElement.GetNextToken(); + + intPrevValue = intiter->second; + + // Process properties. + + size_t intPropertyValueLen = PropertyValue.Len(); + + if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){ + + PropertyValue.Trim(); + PropertyValue.RemoveLast(); + + } + + if (PropertyValue.Mid(0, 1) == wxT("\"")){ + + PropertyValue.Remove(0, 1); + + } + + CaptureString(&PropertyValue, FALSE); + + if (PropertyName == wxT("ALTID")){ + + CategoriesListAltID.erase(*CategoryCount); + CategoriesListAltID.insert(std::make_pair(*CategoryCount, PropertyValue)); + + } else if (PropertyName == wxT("PID")){ + + CategoriesListPID.erase(*CategoryCount); + CategoriesListPID.insert(std::make_pair(*CategoryCount, PropertyValue)); + + } else if (PropertyName == wxT("PREF")){ + + int PriorityNumber = 0; + bool ValidNumber = TRUE; + + try{ + PriorityNumber = std::stoi(PropertyValue.ToStdString()); + } + + catch(std::invalid_argument &e){ + ValidNumber = FALSE; + } + + if (ValidNumber == TRUE){ + + CategoriesListPref.erase(*CategoryCount); + CategoriesListPref.insert(std::make_pair(*CategoryCount, PriorityNumber)); + + } + + } else if (PropertyName == wxT("LANGUAGE")){ + + CategoriesListLanguage.erase(*CategoryCount); + CategoriesListLanguage.insert(std::make_pair(*CategoryCount, PropertyValue)); + + } else { + + // Something else we don't know about so append + // to the tokens variable. + + if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){ + + if (FirstToken == TRUE){ + + PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue); + FirstToken = FALSE; + + } else { + + PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); + + } + + } + + } + + } + + // Deal with multiple categories. + + int intOrigCatCount = *CategoryCount; + bool FirstCategoryProcessed = TRUE; + bool AfterFirstToken = FALSE; + int intSplitSize = 0; + int intSplitsFound = 0; + int intSplitSeek = 0; + int intPropertyLen = PropertySeg2.Len(); + + SplitPoints.clear(); + SplitLength.clear(); + intPrevValue = 0; + + for (int i = 0; i <= intPropertyLen; i++){ + + if (intSplitSize == 0 && PropertySeg2.Mid(i, 1) == wxT(" ")){ + + continue; + + } + + intSplitSize++; + + if (PropertySeg2.Mid(i, 1) == wxT(",") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){ + + if (AfterFirstToken == TRUE){ + + SplitPoints.insert(std::make_pair(intSplitsFound, (i - intSplitSize + 1))); + SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 2))); + + } else { + + SplitPoints.insert(std::make_pair(intSplitsFound, 0)); + SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 2))); + AfterFirstToken = TRUE; + + } + + intSplitsFound++; + intSplitSeek = i; + intSplitSize = 0; + + } + + } + + if (SplitPoints.size() > 0){ + + SplitPoints.insert(std::make_pair(intSplitsFound, (intSplitSeek + 1))); + SplitLength.insert(std::make_pair(intSplitsFound, intSplitSize)); + + } + + if (SplitPoints.size() == 0){ + + CategoriesList.insert(std::make_pair(*CategoryCount, PropertySeg2)); + + if (!PropertyTokens.IsEmpty()){ + + CategoriesListTokens.insert(std::make_pair(*CategoryCount, PropertyTokens)); + + } + + } + + for (std::map::iterator intiter = SplitPoints.begin(); + intiter != SplitPoints.end(); ++intiter){ + + SLiter = SplitLength.find(intiter->first); + + intPrevValue = intiter->second; + + PropertyData = PropertySeg2.Mid(intPrevValue, (SLiter->second + 1)); + + // Add the data to the General/Home/Work address variables. + + // Trim any whitespace from the start and end. + + PropertyData = PropertyData.Trim(FALSE); + PropertyData = PropertyData.Trim(TRUE); + + CaptureString(&PropertyData, FALSE); + + if (FirstCategoryProcessed == TRUE){ + + FirstCategoryProcessed = FALSE; + + CategoriesList.insert(std::make_pair(*CategoryCount, PropertyData)); + + if (!PropertyTokens.IsEmpty()){ + + CategoriesListTokens.insert(std::make_pair(*CategoryCount, PropertyTokens)); + + } + + continue; + + } else { + + (*CategoryCount)++; + + CategoriesList.insert(std::make_pair(*CategoryCount, PropertyData)); + + if (!PropertyTokens.IsEmpty()){ + + CategoriesListTokens.insert(std::make_pair(*CategoryCount, PropertyTokens)); + + } + + } + + // Copy the properties to each of the categories (if it exists). + + if (!PropertyTokens.IsEmpty()){ + + CategoriesListTokens.insert(std::make_pair(*CategoryCount, CategoriesListTokens.find(intOrigCatCount)->second)); + + } + + // Check if ALTID was used. + + if (CategoriesListAltID.find(intOrigCatCount) != CategoriesListAltID.end()){ + + CategoriesListAltID.insert(std::make_pair(*CategoryCount, CategoriesListAltID.find(intOrigCatCount)->second)); + + } + + // Check if PID was used. + + if (CategoriesListPID.find(intOrigCatCount) != CategoriesListPID.end()){ + + CategoriesListPID.insert(std::make_pair(*CategoryCount, CategoriesListPID.find(intOrigCatCount)->second)); + + } + + // Check if PREF was used. + + if (CategoriesListPref.find(intOrigCatCount) != CategoriesListPref.end()){ + + CategoriesListPref.insert(std::make_pair(*CategoryCount, CategoriesListPref.find(intOrigCatCount)->second)); + + } + + // Check if LANGUAGE was used. + + if (CategoriesListLanguage.find(intOrigCatCount) != CategoriesListLanguage.end()){ + + CategoriesListLanguage.insert(std::make_pair(*CategoryCount, CategoriesListLanguage.find(intOrigCatCount)->second)); + + } + + // Check if TYPE was used. + + switch(PropType){ + case PROPERTY_NONE: + break; + case PROPERTY_HOME: + CategoriesListType.insert(std::make_pair(*CategoryCount, "home")); + break; + case PROPERTY_WORK: + CategoriesListType.insert(std::make_pair(*CategoryCount, "work")); + break; + } + + } + +} + void SplitValues(wxString *PropertyLine, std::map *SplitPoints, std::map *SplitLength,