Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated TODO list.
[xestiaab/.git] / source / main.cpp
1 #include <stdlib.h>
3 #include <wx/wx.h>
4 #include <wx/icon.h>
5 #include <wx/mstream.h>
6 #include <wx/cmdline.h>
7 #include <wx/wxprec.h>
8 #include <wx/filename.h>
9 #include <curl/curl.h>
11 #include "contacteditor/frmContactEditor.h"
12 #include "frmMain.h"
13 #include "bitmaps.h"
14 #include "version.h"
15 #include "frmActivityMgr.h"
16 #include "frmSearch.h"
17 #include "common/timers.h"
18 #include "common/defaults.h"
19 #include "common/dirs.h"
21 class XestiaABApp: public wxApp
22 {
23     virtual bool OnInit();
24 };
26 IMPLEMENT_APP(XestiaABApp);
28 bool XestiaABApp::OnInit()
29 {
31         // Setup the locale.
33         wxLocale locale;
34         locale.Init(wxLANGUAGE_DEFAULT, wxLOCALE_LOAD_DEFAULT);
36 /*#if defined(__WIN32__)
38         // Check that the minimum version of Xestia Common Components is installed on the system.
40 #include <xestiaccdll.h>
42         if (!CheckXCCVersion(1, 0, 0)){
43                 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);
44                 this->Exit();
45         }
47 #endif*/
49         static const wxCmdLineEntryDesc g_cmdLineDesc [] =
50         {
51                 { wxCMD_LINE_SWITCH, wxT_2("h"), wxT_2("help"), wxTRANSLATE("Displays help on command line parameters"),
52                         wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
53                 { wxCMD_LINE_OPTION, wxT_2("e"), wxT_2("edit"), wxTRANSLATE("Edit a vCard 4.0 formatted contact"),
54                         wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
55                 { wxCMD_LINE_SWITCH, wxT_2("s"), wxT_2("search"), wxTRANSLATE("Display the search window instead of starting normally"),
56                         wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
57                 { wxCMD_LINE_SWITCH, wxT_2("v"), wxT_2("version"), wxTRANSLATE("Displays version number"),
58                         wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
59                 { wxCMD_LINE_NONE }
60         };
62         wxString wxSContactFilename;
63         wxCmdLineParser XABArgs (g_cmdLineDesc, argc, argv);
64         XABArgs.Parse();
65     
66         if (XABArgs.Found(wxT("h"))){
67     
68                 // Print out the list of help commands.
69     
70                 return false;
71     
72         }
73     
74         if (XABArgs.Found(wxT("v"))){
75     
76                 // Print out the version number.    
78                 wxPuts(XSDAB_VERSION);
79                 exit(0);
80     
81         }
82     
83         wxInitAllImageHandlers();
84     
85         if (XABArgs.Found(wxT("s"))){
86     
87                 // Open up the search window.
88         
89                 frmSearch *frmSearchPtr = new frmSearch( NULL );
90                 frmSearchPtr->Show(true);
91                 frmSearchPtr->SetSearchMode(true);
92                 return true;
93     
94         }
95     
96         if (XABArgs.Found(wxT("e"), &wxSContactFilename)){
98                 // Check if the filename exists.
100                 wxFileName contactfile(wxSContactFilename);
101         
102                 if (!contactfile.FileExists()){
103         
104                         wxMessageBox(_("The file with the filename given does not exist."), _("Error loading contact"), wxICON_ERROR);
105                         return false;
106         
107                 }
108         
109                 // Check if file is in the user's Xestia Address Book data storage
110                 // path. If it is, refuse to open it.
111         
112                 wxString UserDir = GetUserDir();
113                 long UserDirLength = UserDir.Len();
114         
115                 if (UserDir == contactfile.GetFullPath().Mid(0, UserDirLength)){
116         
117                         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);
118                         return false;
119         
120                 }
121         
122                 wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
123                 wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
124                 wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
125                 wxIcon contacticon;
126                 contacticon.CopyFromBitmap(contacticonbmp); 
128                 // Get the filename of the selected contact.
130                 frmContactEditor *ContactEditor = new frmContactEditor( NULL );
131                 ContactEditor->SetupHeaders();
132                 ContactEditor->SetMode(TRUE);
133                 ContactEditor->LoadContact(wxSContactFilename);
134                 ContactEditor->SetIcon(contacticon);
135                 ContactEditor->Show(true);
136         
137                 SetTopWindow(ContactEditor);
138         
139                 return true;
140     
141         }
142     
143         // Setup default settings and accounts if they don't exist.
144     
145         SetupDirectories();
146         SetupDefaultSettings();
147         SetupDefaultAddressBook();
149         wxMemoryInputStream istream(bigimgs_appicon48_png, sizeof(bigimgs_appicon_png));
150         wxImage bigimgs_appicon48i(istream, wxBITMAP_TYPE_PNG);
151         wxBitmap appiconbmp(bigimgs_appicon48i, -1);    
152         wxIcon appicon;
153     
154         appicon.CopyFromBitmap(appiconbmp);
155         frmMain *frame = new frmMain( NULL );
156         frame->Show(true);
157         frmActivityMgr *frameActMgr = new frmActivityMgr ( frame );
158         frame->SetupPointers(frameActMgr);
159         frame->SetupForm();
160         frame->SetIcon(appicon);
161    
162         SetTopWindow(frame);
163    
164         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