// frmContactEditor-LoadSound.cpp - frmContactEditor load sound 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" #include "../common/base64.h" void frmContactEditor::LoadSound(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *SoundCount){ 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 = 7; int intPref = 0; int intType = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 6; // 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. SoundsList.insert(std::make_pair(intValueSeek, "")); SoundsListType.insert(std::make_pair(intValueSeek, wxT(""))); SoundsListAltID.insert(std::make_pair(intValueSeek, wxT(""))); SoundsListPID.insert(std::make_pair(intValueSeek, wxT(""))); SoundsListPref.insert(std::make_pair(intValueSeek, 0)); SoundsListAudioEncType.insert(std::make_pair(intValueSeek, wxT(""))); SoundsListAudioType.insert(std::make_pair(intValueSeek, wxT(""))); SoundsListTokens.insert(std::make_pair(intValueSeek, wxT(""))); SoundsListMediatype.insert(std::make_pair(intValueSeek, wxT(""))); intPrevValue = 6; 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); } ProcessCaptureStrings(&PropertyValue); if (PropertyName == wxT("ALTID")){ if (intType == 0){ SoundsListAltID.erase(intValueSeek); SoundsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ SoundsListAltID.erase(intValueSeek); SoundsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ SoundsListAltID.erase(intValueSeek); SoundsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ SoundsListPID.erase(intValueSeek); SoundsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ SoundsListPID.erase(intValueSeek); SoundsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ SoundsListPID.erase(intValueSeek); SoundsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intType == 0){ SoundsListPref.erase(intValueSeek); SoundsListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ SoundsListPref.erase(intValueSeek); SoundsListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ SoundsListPref.erase(intValueSeek); SoundsListPref.insert(std::make_pair(intValueSeek, intPref)); } } else if (PropertyName == wxT("MEDIATYPE")){ if (intType == 0){ SoundsListMediatype.erase(intValueSeek); SoundsListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ SoundsListMediatype.erase(intValueSeek); SoundsListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ SoundsListMediatype.erase(intValueSeek); SoundsListMediatype.insert(std::make_pair(intValueSeek, 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); } } } } intPropertyLen = wxSPropertySeg2.Len(); SplitPoints.clear(); SplitLength.clear(); intSplitsFound = 0; intSplitSize = 0; intPrevValue = 0; ProcessCaptureStrings(&wxSPropertySeg2); for (int i = 0; i <= intPropertyLen; i++){ intSplitSize++; if (wxSPropertySeg2.Mid(i, 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 wxSSoundURI; wxString wxSSoundMIME; wxString wxSSoundEncoding; wxString wxSSoundData; 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){ wxSSoundURI = wSTDataType.GetNextToken(); wxSSoundMIME = wSTDataType.GetNextToken(); break; } wxStringTokenizer wSTDataInfo(wxSPropertySeg2.Mid((striter->second + 1)), wxT(",")); while (wSTDataInfo.HasMoreTokens() == TRUE){ wxSSoundEncoding = wSTDataInfo.GetNextToken(); wxSSoundData = wSTDataInfo.GetNextToken(); base64enc = wxSSoundData.mb_str(); break; } } // Add the data to the General/Home/Work address variables. wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(_("Sound")); ListCtrlIndex = lboSounds->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboSounds->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref)); } SoundsList.erase(intValueSeek); SoundsListType.erase(intValueSeek); SoundsListTokens.erase(intValueSeek); SoundsListAudioType.erase(intValueSeek); SoundsListAudioEncType.erase(intValueSeek); SoundsList.insert(std::make_pair(intValueSeek, base64enc)); SoundsListAudioType.insert(std::make_pair(intValueSeek, wxSSoundMIME)); SoundsListAudioEncType.insert(std::make_pair(intValueSeek, wxSSoundEncoding)); if (intType == 0){ SoundsListType.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ SoundsListType.insert(std::make_pair(intValueSeek, wxT("home"))); lboLogos->SetItem(ListCtrlIndex, 1, _("Home")); } else if (intType == 2){ SoundsListType.insert(std::make_pair(intValueSeek, wxT("work"))); lboLogos->SetItem(ListCtrlIndex, 1, _("Work")); } SoundsListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); SoundCount++; intValueSeek++; }