Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated includes for frmActivityMgr.
[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 "actmgr/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
40 {
41     virtual bool OnInit();
42 };
44 IMPLEMENT_APP(XestiaABApp);
46 bool XestiaABApp::OnInit()
47 {
49         // Setup the locale.
51         wxLocale locale;
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);
62                 this->Exit();
63         }
65 #endif*/
67         static const wxCmdLineEntryDesc g_cmdLineDesc [] =
68         {
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 },
77                 { wxCMD_LINE_NONE }
78         };
80         wxString wxSContactFilename;
81         wxCmdLineParser XABArgs (g_cmdLineDesc, argc, argv);
82         XABArgs.Parse();
83     
84         if (XABArgs.Found(wxT("h"))){
85     
86                 // Print out the list of help commands.
87     
88                 return false;
89     
90         }
91     
92         if (XABArgs.Found(wxT("v"))){
93     
94                 // Print out the version number.    
96                 wxPuts(XSDAB_VERSION);
97                 exit(0);
98     
99         }
100     
101         wxInitAllImageHandlers();
102     
103         if (XABArgs.Found(wxT("s"))){
104     
105                 // Open up the search window.
106         
107                 frmSearch *frmSearchPtr = new frmSearch( NULL );
108                 frmSearchPtr->Show(true);
109                 frmSearchPtr->SetSearchMode(true);
110                 return true;
111     
112         }
113     
114         if (XABArgs.Found(wxT("e"), &wxSContactFilename)){
116                 // Check if the filename exists.
118                 wxFileName contactfile(wxSContactFilename);
119         
120                 if (!contactfile.FileExists()){
121         
122                         wxMessageBox(_("The file with the filename given does not exist."), _("Error loading contact"), wxICON_ERROR);
123                         return false;
124         
125                 }
126         
127                 // Check if file is in the user's Xestia Address Book data storage
128                 // path. If it is, refuse to open it.
129         
130                 wxString UserDir = GetUserDir();
131                 long UserDirLength = UserDir.Len();
132         
133                 if (UserDir == contactfile.GetFullPath().Mid(0, UserDirLength)){
134         
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);
136                         return false;
137         
138                 }
139         
140                 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
141                 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
142                 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
143                 wxIcon contacticon;
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);
154         
155                 SetTopWindow(ContactEditor);
156         
157                 return true;
158     
159         }
160     
161         // Setup default settings and accounts if they don't exist.
162     
163         SetupDirectories();
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);    
170         wxIcon appicon;
171     
172         appicon.CopyFromBitmap(appiconbmp);
173         frmMain *frame = new frmMain( NULL );
174         frame->Show(true);
175         frmActivityMgr *frameActMgr = new frmActivityMgr ( frame );
176         frame->SetupPointers(frameActMgr);
177         frame->SetupForm();
178         frame->SetIcon(appicon);
179    
180         SetTopWindow(frame);
181    
182         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