Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and licence header to the C++ source and header files in the export...
[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         if (DirMode == TRUE){
30         
31                 // Output each contact into the directory.
32         
33                 // Load the contact file and covert it to vCard 3.0.
34                 
35                 wxString Filename;
36                 wxString FinalFilename;
37                 wxString ContactData;
38                 
39                 for (int i = 0; i < FileList->GetCount(); i++){
40                 
41                         // Get the final part of the path (filename).
42                         
43                         vCard34Conv vCardConvObj;               
44                         vCardConvObj.ConvertToV3(FileList->Item(i), &ContactData);
46 #if defined(__HAIKU__)
47     
49 #elif defined(__WIN32__)
51                         wxStringTokenizer FileToken(FileList->Item(i), wxT("\\"));
53                         while (FileToken.HasMoreTokens()){
54                                 Filename = FileToken.GetNextToken();
55                         }
57                         FinalFilename.Append(OutputLocation);
58                         FinalFilename.Append(wxT("\\"));
59                         FinalFilename.Append(Filename);
61 #else
62                         
63                         wxStringTokenizer FileToken(FileList->Item(i), wxT("//"));
65                         while(FileToken.HasMoreTokens()){
66                                 Filename = FileToken.GetNextToken();
67                         }
68                 
69                         FinalFilename.Append(OutputLocation);
70                         FinalFilename.Append(wxT("/"));
71                         FinalFilename.Append(Filename);
73 #endif
75                         // Write the converted card to the file.
76                         
77                         wxFFile OutputFile;
78                         
79 #if wxABI_VERSION < 20900
80                         OutputFile.Open(FinalFilename, wxT("w"));
81 #else
82                         OutputFile.Open(FinalFilename, wxT("w"));
83 #endif
84                         
85                         OutputFile.Write(ContactData, wxConvAuto());
86                         
87                         OutputFile.Close();
88                         
89                         (*ExportCount)++;
90                         
91                         Filename.Clear();
92                         FinalFilename.Clear();
93                         ContactData.Clear();
94                 
95                 }
96         
97         } else {
98         
99                 // Output all contacts into one file.
100                 
101                 wxFFile OutputFile;
102                 
103                 // Open the output file.
104                 
105 #if wxABI_VERSION < 20900
106                 OutputFile.Open(OutputLocation.c_str(), wxT("w"));
107 #else
108                 OutputFile.Open(OutputLocation, wxT("w"));
109 #endif
110                 
111                 wxString InputFileData;
112                 
113                 for (int i = 0; i < FileList->GetCount(); i++){
114                 
115                         // Open up the input file.
117                         vCard34Conv vCardConvObj;               
118                         vCardConvObj.ConvertToV3(FileList->Item(i), &InputFileData);
120                         OutputFile.Write(InputFileData, wxConvAuto());
121                         
122                         InputFileData.Clear();
123                         
124                         (*ExportCount)++;
125                 
126                 }
127         
128                 OutputFile.Close();
129         
130         }
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