desktop: added timezone list to CalendarEditDlg
[barry.git] / desktop / src / CUI_Barry.cc
blob4d89b980e5862381cee6cc431ccd5018737ce2fd
1 ///
2 /// \file CUI_Barry.cc
3 /// ConfigUI derived class to configure the Barry "App"
4 ///
6 /*
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"
24 #include <iostream>
25 #include <sstream>
27 using namespace std;
29 namespace AppConfig {
31 Barry::Barry()
35 std::string Barry::AppName() const
37 return OpenSync::Config::Barry::AppName();
40 bool Barry::Configure(wxWindow *parent, plugin_ptr old_plugin)
42 return false;
45 ConfigUI::plugin_ptr Barry::GetPlugin()
47 return m_container;
50 bool Barry::RunApp(wxWindow *parent)
52 return false;
55 void Barry::PreSyncAppInit()
57 // nothing to do
60 bool Barry::ZapData(wxWindow *parent,
61 plugin_ptr plugin,
62 OpenSync::API *engine)
64 try {
66 m_parent = parent;
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);
75 // build device name
76 string device_name;
77 const ::Barry::Probe::Results &results = wxGetApp().GetResults();
78 int index = ::Barry::Probe::Find(results, barry.GetPin());
79 if( index != -1 )
80 device_name = results[index].GetDisplayName();
81 else
82 device_name = barry.GetPin().Str(); // default to PIN if not in list
84 // build intro message
85 ostringstream oss;
86 oss << "Please select the databases you wish to erase\n"
87 "on device: " << device_name << "\n"
88 "\n"
89 "Note: all synced databases must be erased\n"
90 "to avoid a slow-sync.";
91 wxString msg(oss.str().c_str(), wxConvUTF8);
93 // build list of databases (base on information from engine, if
94 // the pointer is valid)
95 wxArrayString dbs;
96 wxArrayInt selections;
97 if( !engine || (barry.GetSupportedSyncTypes(*engine) & PST_CONTACTS) ) {
98 dbs.Add( wxString(::Barry::Contact::GetDBName(), wxConvUTF8) );
99 selections.Add(dbs.GetCount() - 1);
101 if( !engine || (barry.GetSupportedSyncTypes(*engine) & PST_EVENTS) ) {
102 dbs.Add( wxString(::Barry::Calendar::GetDBName(), wxConvUTF8) );
103 selections.Add(dbs.GetCount() - 1);
105 if( !engine || (barry.GetSupportedSyncTypes(*engine) & PST_NOTES) ) {
106 dbs.Add( wxString(::Barry::Memo::GetDBName(), wxConvUTF8) );
107 selections.Add(dbs.GetCount() - 1);
109 if( !engine || (barry.GetSupportedSyncTypes(*engine) & PST_TODOS) ) {
110 dbs.Add( wxString(::Barry::Task::GetDBName(), wxConvUTF8) );
111 selections.Add(dbs.GetCount() - 1);
114 // present the list to the user
115 int count = wxGetMultipleChoices(selections, msg,
116 _T("Select Databases to Erase"), dbs, m_parent);
117 if( count <= 0 )
118 return false; // nothing to do
120 // display selections to the user for one final confirmation
121 oss.str("");
122 oss << "You have selected the following databases to be completely "
123 "erased from device " << device_name << ":\n\n";
124 for( size_t i = 0; i < selections.GetCount(); i++ ) {
125 oss << string(dbs[selections[i]].utf8_str()) << "\n";
127 oss << "\nProceed with erase?";
128 wxString confirm(oss.str().c_str(), wxConvUTF8);
129 int choice = wxMessageBox(confirm, _T("Erase Confirmation"),
130 wxYES_NO | wxICON_QUESTION, m_parent);
131 if( choice != wxYES )
132 return false; // nothing to do
134 // connect to the device and delete all selected databases
135 wxBusyCursor wait;
136 ::Barry::Controller con(results[index]);
137 ::Barry::Mode::Desktop desktop(con);
138 desktop.Open();
139 const ::Barry::DatabaseDatabase &dbdb = desktop.GetDBDB();
141 for( size_t i = 0; i < selections.GetCount(); i++ ) {
143 string dbname(dbs[selections[i]].utf8_str());
145 unsigned int dbid;
146 if( !dbdb.GetDBNumber(dbname, dbid) ) {
147 barryverbose("No database named '" << dbname << "' in device!");
148 continue;
151 barryverbose("Clearing db: " << dbname);
152 desktop.ClearDatabase(dbid);
155 return true;
157 } catch( ::Barry::Error &e ) {
158 ostringstream oss;
159 oss << "Barry exception: " << e.what() << "\n\n"
160 "You may need to do a USB reset and rescan from the "
161 "main menu.";
162 wxString msg(oss.str().c_str(), wxConvUTF8);
163 wxMessageBox(msg, _T("Barry Exception"),
164 wxOK | wxICON_ERROR, m_parent);
165 return false;