Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced string processing in FBURL with ProcessStringValue.
[xestiaab/.git] / source / main.cpp
1 // main.cpp - Main subroutine (application start).
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 <stdlib.h>
21 #include <wx/wx.h>
22 #include <wx/icon.h>
23 #include <wx/mstream.h>
24 #include <wx/cmdline.h>
25 #include <wx/wxprec.h>
26 #include <wx/filename.h>
27 #include <curl/curl.h>
29 #include "contacteditor/frmContactEditor.h"
30 #include "frmMain.h"
31 #include "bitmaps.h"
32 #include "version.h"
33 #include "convert.h"
34 #include "actmgr/frmActivityMgr.h"
35 #include "search/frmSearch.h"
36 #include "common/timers.h"
37 #include "common/defaults.h"
38 #include "common/dirs.h"
40 class XestiaABApp: public wxApp
41 {
42     virtual bool OnInit();
43 };
45 IMPLEMENT_APP(XestiaABApp);
47 bool XestiaABApp::OnInit()
48 {
50         // Setup the locale.
52         wxLocale locale;
53         locale.Init(wxLANGUAGE_DEFAULT, wxLOCALE_LOAD_DEFAULT);
55 /*#if defined(__WIN32__)
57         // Check that the minimum version of Xestia Common Components is installed on the system.
59 #include <xestiaccdll.h>
61         if (!CheckXCCVersion(1, 0, 0)){
62                 MessageBox(0, L"The version of Xestia Common Components installed is an older version not supported by this version of Xestia Address Book.\n\nPlease visit http://xestia.co.uk/commoncomponents and follow the page instructions to download the version required.", L"Older version of Xestia Common Components installed", MB_OK|MB_ICONSTOP);
63                 this->Exit();
64         }
66 #endif*/
68         static const wxCmdLineEntryDesc g_cmdLineDesc [] =
69         {
70                 { wxCMD_LINE_SWITCH, wxT_2("h"), wxT_2("help"), wxTRANSLATE("Displays help on command line parameters"),
71                         wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
72                 { wxCMD_LINE_OPTION, wxT_2("e"), wxT_2("edit"), wxTRANSLATE("Edit a vCard 4.0 formatted contact"),
73                         wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
74                 { wxCMD_LINE_SWITCH, wxT_2("c"), wxT_2("convert"), wxTRANSLATE("Convert a contact file into another format."),
75                         wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
76                 { wxCMD_LINE_OPTION, wxT_2("ifmt"), NULL, wxTRANSLATE("Input format to convert from. (used with -c)"),
77                         wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
78                 { wxCMD_LINE_OPTION, wxT_2("ofmt"), NULL, wxTRANSLATE("Output format to convert to. (used with -c)"),
79                         wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
80                 { wxCMD_LINE_OPTION, wxT_2("ifile"), NULL, wxTRANSLATE("Input filename to read from. (used with -c)"),
81                         wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
82                 { wxCMD_LINE_OPTION, wxT_2("ofile"), NULL, wxTRANSLATE("Output filename to write to (don't use to pipe to console). (used with -c)"),
83                         wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
84                 { wxCMD_LINE_SWITCH, wxT_2("s"), wxT_2("search"), wxTRANSLATE("Display the search window instead of starting normally"),
85                         wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
86                 { wxCMD_LINE_SWITCH, wxT_2("v"), wxT_2("version"), wxTRANSLATE("Displays version number"),
87                         wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
88                 { wxCMD_LINE_NONE }
89         };
91         wxString wxSContactFilename;
92         wxString wxSContactOutputFilename;
93         wxString wxSContactFormat;
94         wxString wxSContactOutputFormat;
95         wxCmdLineParser XABArgs (g_cmdLineDesc, argc, argv);
96         XABArgs.Parse();
97     
98         if (XABArgs.Found(wxT("h"))){
99     
100                 // Print out the list of help commands.
101     
102                 return false;
103     
104         }
105     
106         if (XABArgs.Found(wxT("v"))){
107     
108                 // Print out the version number.    
110                 wxPuts(XSDAB_VERSION);
111                 return false;
112     
113         }
114     
115         wxInitAllImageHandlers();
117         if (XABArgs.Found(wxT("c"))){
118         
119                 // Preform a conversion.
121                 wxString InputFormat;
122                 wxString ExportFormat;
123                 wxString InputFilename;
124                 wxString OutputFilename;
125                 
126                 // Get the input format. Return error if blank
127                 // or invalid.
129                 if (XABArgs.Found(wxT("ifmt"))){                
130                         XABArgs.Found(wxT("ifmt"), &InputFormat);
131                 }       
132                         
133                 // Get the export format. Return error if blank
134                 // or invalid.
136                 if (XABArgs.Found(wxT("ofmt"))){
137                         XABArgs.Found(wxT("ofmt"), &ExportFormat);
138                 }
139                 
140                 // Get the input filename.
142                 if (XABArgs.Found(wxT("ifile"))){
143                         XABArgs.Found(wxT("ifile"), &InputFilename);
144                 }
145                 
146                 // Get the output filename (if any).
147                 
148                 if (XABArgs.Found(wxT("ofile"))){
149                         XABArgs.Found(wxT("ofile"), &OutputFilename);
150                 }
151                 
152                 if (argc >= 7){
153                         wxPuts("Too many arguments given.");
154                         exit(EXIT_FAILURE);
155                 }
156                 
157                 // Run the conversion process.
158                 
159                 ConvertResult ConvertRunStatus = ConvertContact(InputFormat, ExportFormat, InputFilename, OutputFilename);
160         
161                 switch (ConvertRunStatus){
162                         case CONVERTRESULT_UNITTESTFAIL:
163                                 wxPuts("An internal unit testing failure has occured.");
164                                 exit(EXIT_SUCCESS);
165                                 break;
166                         case CONVERTRESULT_OK:
167                                 break;
168                         case CONVERTRESULT_FORMATSSAME:
169                                 wxPuts("Both input and output formats are the same.");
170                                 exit(EXIT_FAILURE);
171                                 break;
172                         case CONVERTRESULT_INVALIDINPUTFORMAT:
173                                 wxPuts("Invalid input format given.");
174                                 exit(EXIT_FAILURE);
175                                 break;
176                         case CONVERTRESULT_INVALIDOUTPUTFORMAT:
177                                 wxPuts("Invalid output format given.");
178                                 exit(EXIT_FAILURE);
179                                 break;
180                         case CONVERTRESULT_INPUTFILEMISSING:
181                                 wxPuts("Input file with the filename given does not exist.");
182                                 exit(EXIT_FAILURE);
183                                 break;
184                         case CONVERTRESULT_INPUTFILEEMPTY:
185                                 wxPuts("No input filename given.");
186                                 exit(EXIT_FAILURE);
187                                 break;
188                         case CONVERTRESULT_INPUTFILEINVALIDFORMAT:
189                                 wxPuts("Input file is in an invalid format.");
190                                 exit(EXIT_FAILURE);
191                                 break; 
192                         case CONVERTRESULT_INPUTFILEERROR:
193                                 wxPuts("An error occured whilst trying to open the input file location.");
194                                 exit(EXIT_FAILURE);
195                                 break;
196                         case CONVERTRESULT_OUTPUTFILEERROR:
197                                 wxPuts("An error occured whilst trying to open the output file location.");
198                                 exit(EXIT_FAILURE);
199                                 break;
200                 }
201         
202                 return true;
203         
204         }
206         if (XABArgs.Found(wxT("s"))){
207     
208                 // Open up the search window.
209         
210                 frmSearch *frmSearchPtr = new frmSearch( NULL );
211                 frmSearchPtr->Show(true);
212                 frmSearchPtr->SetSearchMode(true);
213                 return true;
214     
215         }
216     
217         if (XABArgs.Found(wxT("e"), &wxSContactFilename)){
219                 // Check if the filename exists.
221                 wxFileName contactfile(wxSContactFilename);
222         
223                 if (!contactfile.FileExists()){
224         
225                         wxMessageBox(_("The file with the filename given does not exist."), _("Error loading contact"), wxICON_ERROR);
226                         return false;
227         
228                 }
229         
230                 // Check if file is in the user's Xestia Address Book data storage
231                 // path. If it is, refuse to open it.
232         
233                 wxString UserDir = GetUserDir();
234                 long UserDirLength = UserDir.Len();
235         
236                 if (UserDir == contactfile.GetFullPath().Mid(0, UserDirLength)){
237         
238                         wxMessageBox(_("The file with the filename given is in the directories that Xestia Address Book stores it's data and cannot be opened directly."), _("Error loading contact"), wxICON_ERROR);
239                         return false;
240         
241                 }
242         
243                 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
244                 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
245                 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
246                 wxIcon contacticon;
247                 contacticon.CopyFromBitmap(contacticonbmp); 
249                 // Get the filename of the selected contact.
251                 frmContactEditor *ContactEditor = new frmContactEditor( NULL );
252                 ContactEditor->SetupHeaders();
253                 ContactEditor->SetMode(TRUE);
254                 ContactEditor->LoadContact(wxSContactFilename);
255                 ContactEditor->SetIcon(contacticon);
256                 ContactEditor->Show(true);
257         
258                 SetTopWindow(ContactEditor);
259         
260                 return true;
261     
262         }
263         
264         /*if (!XABArgs.Found(wxT(""))){
265         
266                 return false;
267         
268         }*/
269     
270         // Setup default settings and accounts if they don't exist.
271     
272         SetupDirectories();
273         SetupDefaultSettings();
274         SetupDefaultAddressBook();
276         wxMemoryInputStream istream(bigimgs_appicon48_png, sizeof(bigimgs_appicon_png));
277         wxImage bigimgs_appicon48i(istream, wxBITMAP_TYPE_PNG);
278         wxBitmap appiconbmp(bigimgs_appicon48i, -1);    
279         wxIcon appicon;
280     
281         appicon.CopyFromBitmap(appiconbmp);
282         frmMain *frame = new frmMain( NULL );
283         frame->Show(true);
284         frmActivityMgr *frameActMgr = new frmActivityMgr ( frame );
285         frame->SetupPointers(frameActMgr);
286         frame->SetupForm();
287         frame->SetIcon(appicon);
288    
289         SetTopWindow(frame);
290    
291         return true;
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