Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added comment to describe the ExportRun function.
[xestiaab/.git] / source / export / export-vcard4.cpp
1 // export-vcard4.cpp - Export vCard4 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 void ExportVCard4(bool DirMode, wxString OutputLocation, wxArrayString *FileList, int *ExportCount){
26         // Export a vCard 4.0 contact file.
27         
28         if (DirMode == TRUE){
29         
30                 // Output each contact into the directory.
31         
32                 // Simply just copy the files unchanged.
33                 
34                 wxString Filename;
35                 wxString FinalFilename;
36                 
37                 for (int i = 0; i < FileList->GetCount(); i++){
38                 
39                         // Get the final part of the path (filename).
40                         
41 #if defined(__HAIKU__)
42     
44 #elif defined(__WIN32__)
46                         wxStringTokenizer FileToken(FileList->Item(i), wxT("//"));
48                         while (FileToken.HasMoreTokens()){
49                                 Filename = FileToken.GetNextToken();
50                         }
52                         // Copy the file to the requested directory.
54                         FinalFilename.Append(OutputLocation);
55                         FinalFilename.Append(wxT("/"));
56                         FinalFilename.Append(Filename);
58 #else
59                         
60                         wxStringTokenizer FileToken(FileList->Item(i), wxT("//"));
62                         while(FileToken.HasMoreTokens()){
63                                 Filename = FileToken.GetNextToken();
64                         }
65                 
66                         // Copy the file to the requested directory.
67                 
68                         FinalFilename.Append(OutputLocation);
69                         FinalFilename.Append(wxT("/"));
70                         FinalFilename.Append(Filename);
72 #endif
73                 
74                         bool CopyResult = wxCopyFile(FileList->Item(i), FinalFilename);
75                         
76                         (*ExportCount)++;
77                         
78                         Filename.Clear();
79                         FinalFilename.Clear();
80                 
81                 }
82         
83         } else {
84         
85                 // Output all contacts into one file.
86                 
87                 wxFFile OutputFile;
88                 wxFFile InputFile;
89                 
90                 // Open the output file.
91                 
92 #if wxABI_VERSION < 20900
93                 OutputFile.Open(OutputLocation.c_str(), wxT("w"));
94 #else
95                 OutputFile.Open(OutputLocation, wxT("w"));
96 #endif
97                 
98                 wxString InputFileData;
99                 
100                 for (int i = 0; i < FileList->GetCount(); i++){
101                 
102                         // Open up the input file.
103                 
104                         InputFile.Open(FileList->Item(i), wxT("r"));
105                         
106                         InputFile.ReadAll(&InputFileData, wxConvAuto());
108                         OutputFile.Write(InputFileData, wxConvAuto());
109                         
110                         InputFile.Close();
111                         InputFileData.Clear();
112                         
113                         (*ExportCount)++;
114                 
115                 }
116         
117                 OutputFile.Close();
118         
119         }
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