// frmContactEditor-LoadKey.cpp - frmContactEditor load key subroutines.
//
// (c) 2012-2015 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
#include "frmContactEditor.h"
void frmContactEditor::LoadKey(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *KeyCount){
size_t intPropertyLen = wxSPropertySeg1.Len();
std::map SplitPoints;
std::map SplitLength;
std::map::iterator SLiter;
wxString PropertyData;
wxString PropertyName;
wxString PropertyValue;
wxString PropertyTokens;
bool FirstToken = TRUE;
int intSplitsFound = 0;
int intSplitSize = 0;
int intPrevValue = 5;
int intPref = 0;
int intType = 0;
long ListCtrlIndex;
SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
intPrevValue = 4;
// Look for type before continuing.
for (std::map::iterator intiter = SplitPoints.begin();
intiter != SplitPoints.end(); ++intiter){
SLiter = SplitLength.find(intiter->first);
PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
wxStringTokenizer PropertyElement (PropertyData, wxT("="));
PropertyName = PropertyElement.GetNextToken();
PropertyValue = PropertyElement.GetNextToken();
intPrevValue = intiter->second;
if (PropertyName == wxT("TYPE")){
if (PropertyValue == wxT("work")){
intType = 2;
} else if (PropertyValue == wxT("home")){
intType = 1;
} else {
intType = 0;
}
}
}
// Setup blank lines for later on.
KeyList.insert(std::make_pair(intValueSeek, wxT("")));
KeyListAltID.insert(std::make_pair(intValueSeek, wxT("")));
KeyListPID.insert(std::make_pair(intValueSeek, wxT("")));
KeyListPref.insert(std::make_pair(intValueSeek, 0));
KeyListKeyType.insert(std::make_pair(intValueSeek, FALSE));
KeyListDataType.insert(std::make_pair(intValueSeek, wxT("")));
KeyListDataEncType.insert(std::make_pair(intValueSeek, wxT("")));
KeyListTokens.insert(std::make_pair(intValueSeek, wxT("")));
intPrevValue = 4;
for (std::map::iterator intiter = SplitPoints.begin();
intiter != SplitPoints.end(); ++intiter){
SLiter = SplitLength.find(intiter->first);
PropertyData = wxSPropertySeg1.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);
}
if (PropertyName == wxT("ALTID")){
KeyListAltID.erase(intValueSeek); KeyListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
} else if (PropertyName == wxT("PID")){
KeyListPID.erase(intValueSeek); KeyListPID.insert(std::make_pair(intValueSeek, PropertyValue));
} else if (PropertyName == wxT("PREF")){
intPref = wxAtoi(PropertyValue);
KeyListPref.erase(intValueSeek); KeyListPref.insert(std::make_pair(intValueSeek, intPref));
} 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);
}
}
}
}
intPropertyLen = wxSPropertySeg2.Len();
SplitPoints.clear();
SplitLength.clear();
intSplitsFound = 0;
intSplitSize = 0;
intPrevValue = 0;
for (int i = 0; i <= intPropertyLen; i++){
intSplitSize++;
if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
intSplitsFound++;
SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
if (intSplitsFound == 6){
SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
break;
} else {
SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
}
intSplitSize = 0;
}
}
wxString wxSKeyURI;
wxString wxSKeyMIME;
wxString wxSKeyEncoding;
wxString wxSKeyData;
std::string base64enc;
if (intSplitsFound == 0){
} else {
std::map::iterator striter;
striter = SplitLength.find(1);
wxStringTokenizer wSTDataType(wxSPropertySeg2.Mid(0, striter->second), wxT(":"));
while (wSTDataType.HasMoreTokens() == TRUE){
wxSKeyURI = wSTDataType.GetNextToken();
wxSKeyMIME = wSTDataType.GetNextToken();
break;
}
if (wxSKeyURI == wxT("data")){
wxStringTokenizer wSTDataInfo(wxSPropertySeg2.Mid((striter->second + 2)), wxT(","));
while (wSTDataInfo.HasMoreTokens() == TRUE){
wxSKeyEncoding = wSTDataInfo.GetNextToken();
wxSKeyData = wSTDataInfo.GetNextToken();
break;
}
}
}
// Add the data to the General/Home/Work address variables.
wxListItem coldata;
coldata.SetId(intValueSeek);
coldata.SetData(intValueSeek);
if (wxSKeyURI == wxT("data")){
if (wxSKeyMIME == wxT("application/pgp-keys")){
coldata.SetText(_("PGP Key"));
} else {
coldata.SetText(_("Key"));
}
KeyListDataEncType.erase(intValueSeek);
KeyListKeyType.erase(intValueSeek);
KeyListDataEncType.insert(std::make_pair(intValueSeek, wxSKeyEncoding));
KeyListKeyType.insert(std::make_pair(intValueSeek, TRUE));
KeyList.erase(intValueSeek);
KeyList.insert(std::make_pair(intValueSeek, wxSKeyData));
} else {
coldata.SetText(wxSPropertySeg2);
KeyList.erase(intValueSeek);
KeyList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
}
ListCtrlIndex = lboKeys->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboKeys->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
KeyListType.erase(intValueSeek);
KeyListTokens.erase(intValueSeek);
KeyListDataType.erase(intValueSeek);
KeyListDataType.insert(std::make_pair(intValueSeek, wxSKeyMIME));
switch (intType){
case 0: KeyListType.insert(std::make_pair(intValueSeek, wxT("")));
case 1: KeyListType.insert(std::make_pair(intValueSeek, wxT("home")));
case 2: KeyListType.insert(std::make_pair(intValueSeek, wxT("work")));
}
KeyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
KeyCount++;
intValueSeek++;
}