bool ExtraLineSeek = TRUE;
bool QuoteMode = FALSE;
bool PropertyFind = TRUE;
+ bool KindProcessed = FALSE;
int ContactLineLen = 0;
int QuoteBreakPoint = 0;
+ int GroupCount = 0;
wxString ContactLine;
wxString PropertyLine;
wxString PropertySeg1;
PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
+ if (Property == wxT("KIND") && KindProcessed == FALSE){
+
+ // See frmContactEditor-LoadGroup.cpp
+
+ ProcessKind(PropertySeg2);
+
+ } else if (Property == wxT("MEMBER")){
+
+ // See frmContactEditor-LoadGroup.cpp
+
+ ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
+ GroupCount++;
+
+ }
-
}
return CONTACTLOAD_OK;
+}
+
+void ContactDataObject::ProcessKind(wxString KindType){
+
+ if (KindType == wxT("individual")){
+
+ ContactKind = CONTACTKIND_INDIVIDUAL;
+
+ } else if (KindType == wxT("group")){
+
+ ContactKind = CONTACTKIND_GROUP;
+
+ } else if (KindType == wxT("org")){
+
+ ContactKind = CONTACTKIND_ORGANISATION;
+
+ } else if (KindType == wxT("location")){
+
+ ContactKind = CONTACTKIND_LOCATION;
+
+ } else {
+
+ ContactKind = CONTACTKIND_NONE;
+ }
+
+}
+
+void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
+
+ std::map<int, int> SplitPoints;
+ std::map<int, int> SplitLength;
+
+ int intPrevValue = 8;
+ int intPref = 0;
+ int intType = 0;
+
+ SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+ intPrevValue = 7;
+
+ // Look for type before continuing.
+
+ wxString PropertyName;
+ wxString PropertyValue;
+ wxString PropertyData;
+ wxString PropertyTokens;
+ std::map<int,int>::iterator SLiter;
+ bool FirstToken = TRUE;
+
+ for (std::map<int, int>::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;
+
+ CaptureString(&PropertyValue, FALSE);
+
+ //ContactProcess::ContactProcessCaptureStrings(&PropertyValue);
+
+ if (PropertyName == wxT("ALTID")){
+
+ GroupsListAltID.erase(*GroupCount);
+ GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
+
+ } else if (PropertyName == wxT("PID")){
+
+ GroupsListPID.erase(*GroupCount);
+ GroupsListPID.insert(std::make_pair(*GroupCount, 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){
+
+ GroupsListPref.erase(*GroupCount);
+ GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
+
+ }
+
+ } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
+
+ if (FirstToken == TRUE){
+
+ PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+ FirstToken = FALSE;
+
+ } else {
+
+ PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
+
+ }
+
+ }
+
+ }
+
+ //SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+ GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
+
+
+}
+
+void SplitValues(wxString *PropertyLine,
+ std::map<int,int> *SplitPoints,
+ std::map<int,int> *SplitLength,
+ int intSize){
+
+ size_t intPropertyLen = PropertyLine->Len();
+ int intSplitsFound = 0;
+ int intSplitSize = 0;
+ int intSplitSeek = 0;
+
+ for (int i = intSize; i <= intPropertyLen; i++){
+
+ intSplitSize++;
+
+ if (PropertyLine->Mid(i, 1) == wxT(";") &&
+ PropertyLine->Mid((i - 1), 1) != wxT("\\")){
+
+ if (intSplitsFound == 0){
+
+ SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
+
+ } else {
+
+ SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
+
+ }
+
+ SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
+
+ intSplitsFound++;
+ intSplitSeek = i;
+ intSplitSize = 0;
+
+ }
+
+ }
+
+ if (intSplitsFound == 0){
+
+ SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
+ SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
+
+ } else {
+
+ SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
+ SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
+
+ }
+
}
\ No newline at end of file
#include <wx/tokenzr.h>
#include "../vcard/vcard.h"
+#include "../common/textprocessing.h"
enum ContactLoadStatus{
CONTACTLOAD_UNITTESTFAIL = -1,
CONTACTLOAD_FILEBASESPECFAIL
};
+enum ContactKindType{
+ CONTACTKIND_NONE,
+ CONTACTKIND_INDIVIDUAL,
+ CONTACTKIND_GROUP,
+ CONTACTKIND_ORGANISATION,
+ CONTACTKIND_LOCATION
+};
+
class ContactDataObject{
public:
+ ContactKindType ContactKind = CONTACTKIND_NONE;
+
/* Items on General Tab */
wxString NameTitle;
// Subroutines.
ContactLoadStatus LoadFile(wxString Filename);
+ void ProcessKind(wxString KindData);
+ void ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount);
};
+void SplitValues(wxString *PropertyLine,
+ std::map<int,int> *SplitPoints,
+ std::map<int,int> *SplitLength,
+ int intSize);
+
#endif
\ No newline at end of file
TEST(ContactLoad, ContactLoadTests){
-
ContactDataObject TestFile;
// Check that the file given is not missing.
// Check that the vCard 4.0 file loads OK.
ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf"));
+
+ // Check that the kind status has been set. (KIND).
+
+ ASSERT_NE(CONTACTKIND_NONE, TestFile.ContactKind);
+ ASSERT_EQ(CONTACTKIND_INDIVIDUAL, TestFile.ContactKind);
+
+ // Check that the groups have been read (MEMBER).
+
+ std::map<int,wxString>::iterator TestFileIter;
+ std::map<int,int>::iterator TestFileIntIter;
+
+ TestFileIter = TestFile.GroupsList.find(0);
+
+ ASSERT_NE(TestFile.GroupsList.end(), TestFileIter);
+ ASSERT_EQ("7a2af44d-6431-4797-a55f-d86d56304fda", TestFileIter->second);
+
+ // Check the ALTID parameter.
+
+ TestFileIter = TestFile.GroupsListAltID.find(0);
+ ASSERT_NE(TestFile.GroupsListAltID.end(), TestFileIter);
+ ASSERT_EQ("35", TestFileIter->second);
+
+ // Check the PID parameter.
+
+ TestFileIter = TestFile.GroupsListPID.find(0);
+ ASSERT_NE(TestFile.GroupsListPID.end(), TestFileIter);
+ ASSERT_EQ("40", TestFileIter->second);
+
+ // Check the PREF parameter.
+
+ TestFileIntIter = TestFile.GroupsListPref.find(0);
+ ASSERT_NE(TestFile.GroupsListPref.end(), TestFileIntIter);
+ ASSERT_EQ(45, TestFileIntIter->second);
}