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){
29 // Export a vCard 3.0 contact file.
33 // Output each contact into the directory.
35 // Load the contact file and covert it to vCard 3.0.
38 wxString FinalFilename;
41 for (int i = 0; i < FileList->GetCount(); i++){
43 // Get the final part of the path (filename).
45 vCard34Conv vCardConvObj;
46 vCardConvObj.ConvertToV3(FileList->Item(i), &ContactData);
48 #if defined(__HAIKU__)
51 #elif defined(__WIN32__)
53 wxStringTokenizer FileToken(FileList->Item(i), wxT("\\"));
55 while (FileToken.HasMoreTokens()){
56 Filename = FileToken.GetNextToken();
59 FinalFilename.Append(OutputLocation);
60 FinalFilename.Append(wxT("\\"));
61 FinalFilename.Append(Filename);
65 wxStringTokenizer FileToken(FileList->Item(i), wxT("//"));
67 while(FileToken.HasMoreTokens()){
68 Filename = FileToken.GetNextToken();
71 FinalFilename.Append(OutputLocation);
72 FinalFilename.Append(wxT("/"));
73 FinalFilename.Append(Filename);
77 // Write the converted card to the file.
81 #if wxABI_VERSION < 20900
82 OutputFile.Open(FinalFilename, wxT("w"));
84 OutputFile.Open(FinalFilename, wxT("w"));
87 OutputFile.Write(ContactData, wxConvAuto());
94 FinalFilename.Clear();
101 // Output all contacts into one file.
105 // Open the output file.
107 #if wxABI_VERSION < 20900
108 OutputFile.Open(OutputLocation.c_str(), wxT("w"));
110 OutputFile.Open(OutputLocation, wxT("w"));
113 wxString InputFileData;
115 for (int i = 0; i < FileList->GetCount(); i++){
117 // Open up the input file.
119 vCard34Conv vCardConvObj;
120 vCardConvObj.ConvertToV3(FileList->Item(i), &InputFileData);
122 OutputFile.Write(InputFileData, wxConvAuto());
124 InputFileData.Clear();