Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Export: Cleanup export.h and add export.h to export.cpp
[xestiaab/.git] / source / export / export-vcard3.cpp
1 // export-vcard3.cpp - Export vCard3 subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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/>
19 #include <wx/ffile.h>
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.
30         
31         if (DirMode == TRUE){
32         
33                 // Output each contact into the directory.
34         
35                 // Load the contact file and covert it to vCard 3.0.
36                 
37                 wxString Filename;
38                 wxString FinalFilename;
39                 wxString ContactData;
40                 
41                 for (int i = 0; i < FileList->GetCount(); i++){
42                 
43                         // Get the final part of the path (filename).
44                         
45                         vCard34Conv vCardConvObj;               
46                         vCardConvObj.ConvertToV3(FileList->Item(i), &ContactData);
48 #if defined(__HAIKU__)
49     
51 #elif defined(__WIN32__)
53                         wxStringTokenizer FileToken(FileList->Item(i), wxT("\\"));
55                         while (FileToken.HasMoreTokens()){
56                                 Filename = FileToken.GetNextToken();
57                         }
59                         FinalFilename.Append(OutputLocation);
60                         FinalFilename.Append(wxT("\\"));
61                         FinalFilename.Append(Filename);
63 #else
64                         
65                         wxStringTokenizer FileToken(FileList->Item(i), wxT("//"));
67                         while(FileToken.HasMoreTokens()){
68                                 Filename = FileToken.GetNextToken();
69                         }
70                 
71                         FinalFilename.Append(OutputLocation);
72                         FinalFilename.Append(wxT("/"));
73                         FinalFilename.Append(Filename);
75 #endif
77                         // Write the converted card to the file.
78                         
79                         wxFFile OutputFile;
80                         
81 #if wxABI_VERSION < 20900
82                         OutputFile.Open(FinalFilename, wxT("w"));
83 #else
84                         OutputFile.Open(FinalFilename, wxT("w"));
85 #endif
86                         
87                         OutputFile.Write(ContactData, wxConvAuto());
88                         
89                         OutputFile.Close();
90                         
91                         (*ExportCount)++;
92                         
93                         Filename.Clear();
94                         FinalFilename.Clear();
95                         ContactData.Clear();
96                 
97                 }
98         
99         } else {
100         
101                 // Output all contacts into one file.
102                 
103                 wxFFile OutputFile;
104                 
105                 // Open the output file.
106                 
107 #if wxABI_VERSION < 20900
108                 OutputFile.Open(OutputLocation.c_str(), wxT("w"));
109 #else
110                 OutputFile.Open(OutputLocation, wxT("w"));
111 #endif
112                 
113                 wxString InputFileData;
114                 
115                 for (int i = 0; i < FileList->GetCount(); i++){
116                 
117                         // Open up the input file.
119                         vCard34Conv vCardConvObj;               
120                         vCardConvObj.ConvertToV3(FileList->Item(i), &InputFileData);
122                         OutputFile.Write(InputFileData, wxConvAuto());
123                         
124                         InputFileData.Clear();
125                         
126                         (*ExportCount)++;
127                 
128                 }
129         
130                 OutputFile.Close();
131         
132         }
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy