2 /// \file CUI_Evolution.cc
3 /// ConfigUI derived class to configure the Evolution App
7 Copyright (C) 2009-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "CUI_Evolution.h"
23 #include "EvoSources.h"
24 #include "EvoCfgDlg.h"
25 #include "EvoDefaultDlg.h"
26 #include "os22.h" // only for the dynamic_cast
27 #include "windowids.h"
29 #include <wx/process.h>
34 class ExecCallback
: public wxProcess
41 ExecCallback(wxDialog
*dlg
)
48 virtual void OnTerminate(int pid
, int status
)
54 // close the dialog and let it delete us
55 m_waitdlg
->EndModal(wxID_OK
);
58 // our parent doesn't exist, delete ourselves
64 class WaitDialog
: public wxDialog
68 WaitDialog(wxWindow
*parent
, const wxString
&msg
,
69 const wxString
&title
)
70 : wxDialog(parent
, wxID_ANY
, title
)
72 wxBoxSizer
*top
= new wxBoxSizer(wxVERTICAL
);
73 top
->Add( new wxStaticText(this, wxID_ANY
, msg
),
74 0, wxALL
| wxALIGN_LEFT
, 10);
75 top
->Add( new wxButton(this, wxID_CANCEL
,
77 0, wxALL
| wxALIGN_RIGHT
, 5);
79 top
->SetSizeHints(this);
82 SetEscapeId(wxID_CANCEL
);
85 void OnButton(wxCommandEvent
&event
)
87 EndModal(wxID_CANCEL
);
91 BEGIN_EVENT_TABLE(WaitDialog
, wxDialog
)
92 EVT_BUTTON (wxID_CANCEL
, WaitDialog::OnButton
)
96 //////////////////////////////////////////////////////////////////////////////
97 // Static utility functions
99 long Evolution::ForceShutdown()
101 ExecHelper
shutdown(NULL
);
102 shutdown
.Run(NULL
, "Evolution shutdown", _T("evolution --force-shutdown"));
103 shutdown
.WaitForChild();
104 return shutdown
.GetChildExitCode();
107 //////////////////////////////////////////////////////////////////////////////
108 // Evolution config UI class
110 Evolution::Evolution()
116 bool Evolution::InitialRun()
119 "Unable to automatically detect Evolution's configuration.\n"
120 "You need to run Evolution, and manually click each of the\n"
123 " Mail, Contacts, Calendars, Memos, and Tasks\n"
125 "Then quit Evolution to continue configuration.\n"
127 "Would you like to start Evolution now?\n");
129 int choice
= wxMessageBox(msg
, _T("Evolution Config"),
130 wxYES_NO
| wxICON_QUESTION
, m_parent
);
137 // start Evolution, and wait for it to exit, showing a waiting
138 // message to the user
139 WaitDialog
waitdlg(m_parent
, _T("Waiting for Evolution to exit..."),
140 _T("Evolution Running"));
142 ExecCallback
*callback
= new ExecCallback(&waitdlg
);
144 const wxChar
*start_argv
[] = {
148 long ret
= wxExecute((wxChar
**)start_argv
, wxEXEC_ASYNC
, callback
);
151 wxMessageBox(_T("Failed to run evolution. Please make sure it is installed and in your PATH."), _T("Evolution Config"), wxOK
| wxICON_ERROR
, m_parent
);
155 if( waitdlg
.ShowModal() == wxID_CANCEL
) {
156 // user aborted, so ExecCallback will be left
157 // waiting, and waitdlg will go out of scope, so
158 // reset the callback's pointer
159 callback
->m_waitdlg
= 0;
160 return false; // user aborted
163 // if we don't get wxID_CANCEL, then the callback
164 // closed us, and we can delete it
165 if( callback
->m_status
) {
167 wxMessageBox(_T("Failed to run evolution. Please make sure it is installed and in your PATH."), _T("Evolution Config"), wxOK
| wxICON_ERROR
, m_parent
);
180 std::string
Evolution::AppName() const
182 return OpenSync::Config::Evolution::AppName();
185 bool Evolution::Configure(wxWindow
*parent
, plugin_ptr old_plugin
)
189 // create our plugin config
190 m_evolution
= dynamic_cast<OpenSync::Config::Evolution
*> (old_plugin
.get());
192 m_evolution
= m_evolution
->Clone();
195 m_evolution
= new OpenSync::Config::Evolution
;
197 m_container
.reset( m_evolution
);
203 // if no sources are found at all, and if Evolution is in the path
204 // do InitialRun and then auto detect again
205 if( srcs
.IsEmpty() ) {
206 if( !InitialRun() ) {
207 // impossible to do initial run, so fail here
215 // we now have an auto detect (EvoSources) to work with
216 // if minimum three paths are available, and if no list has
217 // more than 1 item, then just default to those settings
218 // and notify the user... in the notification, allow
219 // the user to "Manual Cfg..." button
221 if( srcs
.IsDefaultable() ) {
222 EvoDefaultDlg
dlg(m_parent
);
223 if( dlg
.ShowModal() == Dialog_EvoDefault_ManualConfigButton
) {
228 // otherwise, if default settings are not possible, then
229 // load the path config dialog without notification
230 if( !srcs
.IsDefaultable() || manual
) {
231 EvoCfgDlg
cfgdlg(m_parent
, *m_evolution
, srcs
);
232 if( cfgdlg
.ShowModal() == wxID_OK
) {
233 cfgdlg
.SetPaths(*m_evolution
);
242 // it's defaultable! use default paths
243 m_evolution
->SetAddressPath(srcs
.GetAddressBook().size() ?
244 srcs
.GetAddressBook()[0].m_SourcePath
: "");
245 m_evolution
->SetCalendarPath(srcs
.GetEvents().size() ?
246 srcs
.GetEvents()[0].m_SourcePath
: "");
247 m_evolution
->SetTasksPath(srcs
.GetTasks().size() ?
248 srcs
.GetTasks()[0].m_SourcePath
: "");
249 m_evolution
->SetMemosPath(srcs
.GetMemos().size() ?
250 srcs
.GetMemos()[0].m_SourcePath
: "");
257 ConfigUI::plugin_ptr
Evolution::GetPlugin()
263 bool Evolution::RunApp(wxWindow
*parent
)
265 return Run(parent
, AppName(), _T("evolution"));
268 void Evolution::PreSyncAppInit()
273 bool Evolution::ZapData(wxWindow
*parent
,
275 OpenSync::API
*engine
)
279 // extract OpenSync::Config::Evolution from plugin
280 // this *can* throw an exception if the wrong plugin is
281 // passed in, but we want this... such an exception would
282 // represent a bug in the app, not a runtime error
283 // OpenSync::Config::Evolution &evo =
284 // dynamic_cast<OpenSync::Config::Evolution&>(*plugin);
286 if( IsAppRunning() ) {
287 wxMessageBox(_T("Evolution already running."),
288 _T("No Biscuit"), wxOK
| wxICON_INFORMATION
,
293 // tell the user what to do
295 if( dynamic_cast<OpenSync::OpenSync22
*>(engine
) ) {
297 "Starting Evolution. Delete all contacts and calendar "
298 "entries manually.");
302 "Starting Evolution. Delete all contacts and calendar "
303 "entries manually (as well as memos and tasks if you are "
307 int choice
= wxMessageBox(msg
, _T("Starting Evolution"),
308 wxOK
| wxCANCEL
| wxICON_QUESTION
, m_parent
);
314 // wait for app to finish... this is kinda lame, but
315 // we don't want other Zaps to happen before this is finished
316 while( IsAppRunning() )
322 } // namespace AppConfig