X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Fconvert.cpp;h=d7345196e3163d26ed772376f4ac3cde85d8fa2c;hp=ae0e4db81b30d0fa71659dc79c18d052855d715f;hb=3ef806261b5482a584e05dc8311c8d7633f146b4;hpb=6e5b70888b9a1bc4bb1c1d443402f9e7987e31d1 diff --git a/source/convert.cpp b/source/convert.cpp index ae0e4db..d734519 100644 --- a/source/convert.cpp +++ b/source/convert.cpp @@ -18,6 +18,7 @@ #include "convert.h" #include "vcard/vcard.h" +#include "vcard/vcard34conv.h" ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat, wxString InputFilename, wxString OutputFilename){ @@ -92,9 +93,7 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat, wxFile InputFile; if (!InputFile.Open(InputFilename, wxFile::read, wxS_DEFAULT)){ - - int InputFileErrNo = InputFile.GetLastError(); - + return CONVERTRESULT_INPUTFILEERROR; } @@ -118,6 +117,9 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat, // Check that the file has the correct file format. + vCard vCard4Format; + wxString FinalData; + if (InputFormat == "vCard4"){ // Read from the file. @@ -125,11 +127,11 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat, wxString InputFileData; InputFile.ReadAll(&InputFileData, wxConvAuto()); - vCard InputvCard; + vCard vCard4Format; - InputvCard.LoadString(InputFileData); + vCard4Format.LoadString(InputFileData); - if (InputvCard.Get("VERSION") != "4.0"){ + if (vCard4Format.Get("VERSION") != "4.0"){ return CONVERTRESULT_INPUTFILEINVALIDFORMAT; } @@ -147,9 +149,54 @@ ConvertResult ConvertContact(wxString InputFormat, wxString OutputFormat, if (InputvCard.Get("VERSION") != "3.0"){ return CONVERTRESULT_INPUTFILEINVALIDFORMAT; } + + vCard34Conv vCard34ConvObj; + + vCard vCard4Format; + + vCard34ConvObj.ConvertToV4(&InputFileData, &vCard4Format); + + FinalData = vCard4Format.WriteString(); + + } + + // Convert the vCard into the required format and + // get the string value. + + if (OutputFormat == "vCard4"){ + + // Do nothing as the vCard is already in the vCard 4.0 + // format. + + } else if (OutputFormat == "vCard3"){ + + // Convert the vCard to vCard 3.0. + + vCard34Conv vCard34ConvObj; + + vCard vCard3Format; + + vCard34ConvObj.ConvertToV3(InputFilename, &FinalData); + + } + + // Check if we are outputting to console or to file. + + if (OutputPipe == false){ + + // We are outputting to a file. + + OutputFile.Write(FinalData, wxConvUTF8); + + } else { + + // Write out the data to the console. + + FinalData.Trim(); + std::cout << FinalData.ToStdString() << std::endl; } return CONVERTRESULT_OK; -} \ No newline at end of file +}