1 // main.cpp - Main subroutine (application start).
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/>
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"
33 #include "frmActivityMgr.h"
34 #include "frmSearch.h"
35 #include "common/timers.h"
36 #include "common/defaults.h"
37 #include "common/dirs.h"
39 class XestiaABApp: public wxApp
41 virtual bool OnInit();
44 IMPLEMENT_APP(XestiaABApp);
46 bool XestiaABApp::OnInit()
52 locale.Init(wxLANGUAGE_DEFAULT, wxLOCALE_LOAD_DEFAULT);
54 /*#if defined(__WIN32__)
56 // Check that the minimum version of Xestia Common Components is installed on the system.
58 #include <xestiaccdll.h>
60 if (!CheckXCCVersion(1, 0, 0)){
61 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);
67 static const wxCmdLineEntryDesc g_cmdLineDesc [] =
69 { wxCMD_LINE_SWITCH, wxT_2("h"), wxT_2("help"), wxTRANSLATE("Displays help on command line parameters"),
70 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
71 { wxCMD_LINE_OPTION, wxT_2("e"), wxT_2("edit"), wxTRANSLATE("Edit a vCard 4.0 formatted contact"),
72 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
73 { wxCMD_LINE_SWITCH, wxT_2("s"), wxT_2("search"), wxTRANSLATE("Display the search window instead of starting normally"),
74 wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
75 { wxCMD_LINE_SWITCH, wxT_2("v"), wxT_2("version"), wxTRANSLATE("Displays version number"),
76 wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
80 wxString wxSContactFilename;
81 wxCmdLineParser XABArgs (g_cmdLineDesc, argc, argv);
84 if (XABArgs.Found(wxT("h"))){
86 // Print out the list of help commands.
92 if (XABArgs.Found(wxT("v"))){
94 // Print out the version number.
96 wxPuts(XSDAB_VERSION);
101 wxInitAllImageHandlers();
103 if (XABArgs.Found(wxT("s"))){
105 // Open up the search window.
107 frmSearch *frmSearchPtr = new frmSearch( NULL );
108 frmSearchPtr->Show(true);
109 frmSearchPtr->SetSearchMode(true);
114 if (XABArgs.Found(wxT("e"), &wxSContactFilename)){
116 // Check if the filename exists.
118 wxFileName contactfile(wxSContactFilename);
120 if (!contactfile.FileExists()){
122 wxMessageBox(_("The file with the filename given does not exist."), _("Error loading contact"), wxICON_ERROR);
127 // Check if file is in the user's Xestia Address Book data storage
128 // path. If it is, refuse to open it.
130 wxString UserDir = GetUserDir();
131 long UserDirLength = UserDir.Len();
133 if (UserDir == contactfile.GetFullPath().Mid(0, UserDirLength)){
135 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);
140 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
141 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
142 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
144 contacticon.CopyFromBitmap(contacticonbmp);
146 // Get the filename of the selected contact.
148 frmContactEditor *ContactEditor = new frmContactEditor( NULL );
149 ContactEditor->SetupHeaders();
150 ContactEditor->SetMode(TRUE);
151 ContactEditor->LoadContact(wxSContactFilename);
152 ContactEditor->SetIcon(contacticon);
153 ContactEditor->Show(true);
155 SetTopWindow(ContactEditor);
161 // Setup default settings and accounts if they don't exist.
164 SetupDefaultSettings();
165 SetupDefaultAddressBook();
167 wxMemoryInputStream istream(bigimgs_appicon48_png, sizeof(bigimgs_appicon_png));
168 wxImage bigimgs_appicon48i(istream, wxBITMAP_TYPE_PNG);
169 wxBitmap appiconbmp(bigimgs_appicon48i, -1);
172 appicon.CopyFromBitmap(appiconbmp);
173 frmMain *frame = new frmMain( NULL );
175 frmActivityMgr *frameActMgr = new frmActivityMgr ( frame );
176 frame->SetupPointers(frameActMgr);
178 frame->SetIcon(appicon);