3 /// ConfigUI derived class to configure the Barry "App"
7 Copyright (C) 2010-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_Barry.h"
23 #include "barrydesktop.h"
35 std::string
Barry::AppName() const
37 return OpenSync::Config::Barry::AppName();
40 bool Barry::Configure(wxWindow
*parent
, plugin_ptr old_plugin
)
45 ConfigUI::plugin_ptr
Barry::GetPlugin()
50 bool Barry::RunApp(wxWindow
*parent
)
55 void Barry::PreSyncAppInit()
60 bool Barry::ZapData(wxWindow
*parent
,
62 OpenSync::API
*engine
)
68 // extract OpenSync::Config::Barry from plugin
69 // this *can* throw an exception if the wrong plugin is
70 // passed in, but we want this... such an exception would
71 // represent a bug in the app, not a runtime error
72 OpenSync::Config::Barry
&barry
=
73 dynamic_cast<OpenSync::Config::Barry
&>(*plugin
);
76 string device_name
= barry
.GetPin().Str();
77 const ::Barry::Probe::Results
&results
= wxGetApp().GetResults();
78 int index
= ::Barry::Probe::Find(results
, barry
.GetPin());
79 if( index
!= -1 && results
[index
].m_cfgDeviceName
.size() )
80 device_name
+= " (" + results
[index
].m_cfgDeviceName
+ ")";
82 // build intro message
84 oss
<< "Please select the databases you wish to erase\n"
85 "on device: " << device_name
<< "\n"
87 "Note: all synced databases must be erased\n"
88 "to avoid a slow-sync.";
89 wxString
msg(oss
.str().c_str(), wxConvUTF8
);
91 // build list of databases (base on information from engine, if
92 // the pointer is valid)
94 wxArrayInt selections
;
95 if( !engine
|| (barry
.GetSupportedSyncTypes(*engine
) & PST_CONTACTS
) ) {
96 dbs
.Add( wxString(::Barry::Contact::GetDBName(), wxConvUTF8
) );
97 selections
.Add(dbs
.GetCount() - 1);
99 if( !engine
|| (barry
.GetSupportedSyncTypes(*engine
) & PST_EVENTS
) ) {
100 dbs
.Add( wxString(::Barry::Calendar::GetDBName(), wxConvUTF8
) );
101 selections
.Add(dbs
.GetCount() - 1);
103 if( !engine
|| (barry
.GetSupportedSyncTypes(*engine
) & PST_NOTES
) ) {
104 dbs
.Add( wxString(::Barry::Memo::GetDBName(), wxConvUTF8
) );
105 selections
.Add(dbs
.GetCount() - 1);
107 if( !engine
|| (barry
.GetSupportedSyncTypes(*engine
) & PST_TODOS
) ) {
108 dbs
.Add( wxString(::Barry::Task::GetDBName(), wxConvUTF8
) );
109 selections
.Add(dbs
.GetCount() - 1);
112 // present the list to the user
113 int count
= wxGetMultipleChoices(selections
, msg
,
114 _T("Select Databases to Erase"), dbs
, m_parent
);
116 return false; // nothing to do
118 // display selections to the user for one final confirmation
120 oss
<< "You have selected the following databases to be completely "
121 "erased from device " << device_name
<< ":\n\n";
122 for( size_t i
= 0; i
< selections
.GetCount(); i
++ ) {
123 oss
<< string(dbs
[selections
[i
]].utf8_str()) << "\n";
125 oss
<< "\nProceed with erase?";
126 wxString
confirm(oss
.str().c_str(), wxConvUTF8
);
127 int choice
= wxMessageBox(confirm
, _T("Erase Confirmation"),
128 wxYES_NO
| wxICON_QUESTION
, m_parent
);
129 if( choice
!= wxYES
)
130 return false; // nothing to do
132 // connect to the device and delete all selected databases
134 ::Barry::Controller
con(results
[index
]);
135 ::Barry::Mode::Desktop
desktop(con
);
137 const ::Barry::DatabaseDatabase
&dbdb
= desktop
.GetDBDB();
139 for( size_t i
= 0; i
< selections
.GetCount(); i
++ ) {
141 string
dbname(dbs
[selections
[i
]].utf8_str());
144 if( !dbdb
.GetDBNumber(dbname
, dbid
) ) {
145 barryverbose("No database named '" << dbname
<< "' in device!");
149 barryverbose("Clearing db: " << dbname
);
150 desktop
.ClearDatabase(dbid
);
155 } catch( ::Barry::Error
&e
) {
157 oss
<< "Barry exception: " << e
.what() << "\n\n"
158 "You may need to do a USB reset and rescan from the "
160 wxString
msg(oss
.str().c_str(), wxConvUTF8
);
161 wxMessageBox(msg
, _T("Barry Exception"),
162 wxOK
| wxICON_ERROR
, m_parent
);