1 // export-vcard3.cpp - Export vCard3 subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
20 #include <wx/arrstr.h>
21 #include <wx/filefn.h>
22 #include <wx/tokenzr.h>
24 #include "../vcard/vcard.h"
25 #include "../vcard/vcard34conv.h"
27 void ExportVCard3(bool DirMode, wxString OutputLocation, wxArrayString *FileList, int *ExportCount){
31 // Output each contact into the directory.
33 // Load the contact file and covert it to vCard 3.0.
36 wxString FinalFilename;
39 for (int i = 0; i < FileList->GetCount(); i++){
41 // Get the final part of the path (filename).
43 vCard34Conv vCardConvObj;
44 vCardConvObj.ConvertToV3(FileList->Item(i), &ContactData);
46 #if defined(__HAIKU__)
49 #elif defined(__WIN32__)
51 wxStringTokenizer FileToken(FileList->Item(i), wxT("\\"));
53 while (FileToken.HasMoreTokens()){
54 Filename = FileToken.GetNextToken();
57 FinalFilename.Append(OutputLocation);
58 FinalFilename.Append(wxT("\\"));
59 FinalFilename.Append(Filename);
63 wxStringTokenizer FileToken(FileList->Item(i), wxT("//"));
65 while(FileToken.HasMoreTokens()){
66 Filename = FileToken.GetNextToken();
69 FinalFilename.Append(OutputLocation);
70 FinalFilename.Append(wxT("/"));
71 FinalFilename.Append(Filename);
75 // Write the converted card to the file.
79 #if wxABI_VERSION < 20900
80 OutputFile.Open(FinalFilename, wxT("w"));
82 OutputFile.Open(FinalFilename, wxT("w"));
85 OutputFile.Write(ContactData, wxConvAuto());
92 FinalFilename.Clear();
99 // Output all contacts into one file.
103 // Open the output file.
105 #if wxABI_VERSION < 20900
106 OutputFile.Open(OutputLocation.c_str(), wxT("w"));
108 OutputFile.Open(OutputLocation, wxT("w"));
111 wxString InputFileData;
113 for (int i = 0; i < FileList->GetCount(); i++){
115 // Open up the input file.
117 vCard34Conv vCardConvObj;
118 vCardConvObj.ConvertToV3(FileList->Item(i), &InputFileData);
120 OutputFile.Write(InputFileData, wxConvAuto());
122 InputFileData.Clear();