Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added support to directly edit a contact using the -e command switch.
[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         return false;
69     
70     }
71     
72     if (XABArgs.Found(wxT("v"))){
73     
74         wxPuts(XSDAB_VERSION);
75         exit(0);
76     
77     }
78     
79     wxInitAllImageHandlers();
80     
81     if (XABArgs.Found(wxT("s"))){
82     
83         // Open up the search window.
84         
85         frmSearch *frmSearchPtr = new frmSearch( NULL );
86         frmSearchPtr->Show(true);
87         frmSearchPtr->SetSearchMode(true);
88         return true;
89     
90     }
91     
92     if (XABArgs.Found(wxT("e"), &wxSContactFilename)){
94         // Check if the filename exists.
96         wxFileName contactfile(wxSContactFilename);
97         
98         if (!contactfile.FileExists()){
99         
100                 wxMessageBox(_("The file with the filename given does not exist."), _("Error loading contact"), wxICON_ERROR);
101                 return false;
102         
103         }
104         
105         // Check if file is in the user's Xestia Address Book data storage
106         // path. If it is, refuse to open it.
107         
108         wxString UserDir = GetUserDir();
109         long UserDirLength = UserDir.Len();
110         
111         if (UserDir == contactfile.GetFullPath().Mid(0, UserDirLength)){
112         
113                 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);
114                 return false;
115         
116         }
117         
118         wxMemoryInputStream istream(bigimgs_contactpersonicon48_png, sizeof(bigimgs_contactpersonicon48_png));
119         wxImage bigimgs_contactpersonicon48i(istream, wxBITMAP_TYPE_PNG);
120         wxBitmap contacticonbmp(bigimgs_contactpersonicon48i, -1);
121         wxIcon contacticon;
122         contacticon.CopyFromBitmap(contacticonbmp); 
124         // Get the filename of the selected contact.
126         frmContactEditor *ContactEditor = new frmContactEditor( NULL );
127         ContactEditor->SetupHeaders();
128         ContactEditor->SetMode(TRUE);
129         ContactEditor->LoadContact(wxSContactFilename);
130         //ContactEditor->SetupContact(ActiveAccount);
131         ContactEditor->SetIcon(contacticon);
132         ContactEditor->Show(true);
133         
134         SetTopWindow(ContactEditor);
135         
136         return true;
137     
138     }
139     
140     // Setup default settings and accounts if they don't exist.
141     
142     SetupDirectories();
143     SetupDefaultSettings();
144     SetupDefaultAddressBook();
146     //wxImage::AddHandler(new wxPNGHandler); 
147     wxMemoryInputStream istream(bigimgs_appicon48_png, sizeof(bigimgs_appicon_png));
148     wxImage bigimgs_appicon48i(istream, wxBITMAP_TYPE_PNG);
149     wxBitmap appiconbmp(bigimgs_appicon48i, -1);    
150     wxIcon appicon;
151     
152     appicon.CopyFromBitmap(appiconbmp);
153     frmMain *frame = new frmMain( NULL );
154         frame->Show(true);
155     frmActivityMgr *frameActMgr = new frmActivityMgr ( frame );
156     frame->SetupPointers(frameActMgr);
157     frame->SetupForm();
158     frame->SetIcon(appicon);
159    
160     SetTopWindow(frame);
161    
162     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