1 // export.cpp - Export 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/>
19 #include <wx/filedlg.h>
20 #include <wx/arrstr.h>
23 #include "../frmMain.h"
24 #include "export-vcard3.h"
25 #include "export-vcard4.h"
27 void ExportRun(frmMain *frmMainPtrInc, wxArrayString *FileListInc){
29 // Run the export function. Bring up the export file save
30 // dialog and run the required export functions as needed.
32 frmMainPtrInc->PauseAllTimers();
37 long ContactsExported = 0;
38 long ContactsCollected = 0;
41 wxString FinalFilename;
43 FileTypes.Append(wxT("vCard 4.0 (directory, one contact per file) (*.vcf)"));
44 FileTypes.Append(wxT("|*.vcf|"));
45 FileTypes.Append(wxT("vCard 4.0 (file, all contacts in one file) (*.vcf)"));
46 FileTypes.Append(wxT("|*.vcf|"));
47 FileTypes.Append(wxT("vCard 3.0 (directory, one contact per file) (*.vcf)"));
48 FileTypes.Append(wxT("|*.vcf|"));
49 FileTypes.Append(wxT("vCard 3.0 (file, all contacts in one file) (*.vcf)"));
50 FileTypes.Append(wxT("|*.vcf"));
52 // Open up the dialog to export file data.
54 wxFileDialog ExportDlg(frmMainPtrInc, wxT("Export Contacts"), wxT(""), wxT(""),
55 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
57 if (ExportDlg.ShowModal() == wxID_CANCEL){
59 frmMainPtrInc->ResumeAllTimers();
64 // Find which data type is being used.
66 ExportType = ExportDlg.GetFilterIndex();
68 if (ExportType == 0 || ExportType == 2){
72 // Process the filename based on data type.
74 if (DirMode == FALSE){
76 // All contacts exported into one file. Setup the filename.
78 FinalFilename = ExportDlg.GetPath();
82 // One contact per filename. Setup the directory name.
84 FinalFilename = ExportDlg.GetDirectory();
88 if (ExportType == 0 || ExportType == 1){
90 ExportVCard4(DirMode, FinalFilename, FileListInc, &ExportCount);
96 if (ExportType == 2 || ExportType == 3){
98 ExportVCard3(DirMode, FinalFilename, FileListInc, &ExportCount);
102 // Notify the user of how many contacts
105 wxMessageBox(wxString::Format(_("%i contacts exported."), ExportCount), _("Contacts exported"));
107 frmMainPtrInc->ResumeAllTimers();