Bumped copyright dates for 2013
[barry.git] / desktop / src / CUI_Barry.cc
blobee275b000024bce71597708abb9651b94b3471ff
1 ///
2 /// \file CUI_Barry.cc
3 /// ConfigUI derived class to configure the Barry "App"
4 ///
6 /*
7 Copyright (C) 2010-2013, 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>
26 #include "wxi18n.h"
28 using namespace std;
30 namespace AppConfig {
32 Barry::Barry()
36 std::string Barry::AppName() const
38 return OpenSync::Config::Barry::AppName();
41 bool Barry::Configure(wxWindow *parent, plugin_ptr old_plugin)
43 return false;
46 ConfigUI::plugin_ptr Barry::GetPlugin()
48 return m_container;
51 bool Barry::RunApp(wxWindow *parent)
53 return false;
56 void Barry::PreSyncAppInit()
58 // nothing to do
61 bool Barry::ZapData(wxWindow *parent,
62 plugin_ptr plugin,
63 OpenSync::API *engine)
65 try {
67 m_parent = parent;
69 // extract OpenSync::Config::Barry from plugin
70 // this *can* throw an exception if the wrong plugin is
71 // passed in, but we want this... such an exception would
72 // represent a bug in the app, not a runtime error
73 OpenSync::Config::Barry &barry =
74 dynamic_cast<OpenSync::Config::Barry&>(*plugin);
76 // build device name
77 string device_name;
78 const ::Barry::Probe::Results &results = wxGetApp().GetResults();
79 int index = ::Barry::Probe::Find(results, barry.GetPin());
80 if( index != -1 )
81 device_name = results[index].GetDisplayName();
82 else
83 device_name = barry.GetPin().Str(); // default to PIN if not in list
85 // build intro message
86 wxString msg = wxString::Format(
87 _W("Please select the databases you wish to erase\n"
88 "on device: %s\n"
89 "\n"
90 "Note: all synced databases must be erased\n"
91 "to avoid a slow-sync."),
92 wxString(device_name.c_str(), wxConvUTF8).c_str());
94 // build list of databases (base on information from engine, if
95 // the pointer is valid)
96 wxArrayString dbs;
97 wxArrayInt selections;
98 if( !engine || (barry.GetSupportedSyncTypes(*engine) & PST_CONTACTS) ) {
99 dbs.Add( wxString(::Barry::Contact::GetDBName(), wxConvUTF8) );
100 selections.Add(dbs.GetCount() - 1);
102 if( !engine || (barry.GetSupportedSyncTypes(*engine) & PST_EVENTS) ) {
103 dbs.Add( wxString(::Barry::Calendar::GetDBName(), wxConvUTF8) );
104 selections.Add(dbs.GetCount() - 1);
106 if( !engine || (barry.GetSupportedSyncTypes(*engine) & PST_NOTES) ) {
107 dbs.Add( wxString(::Barry::Memo::GetDBName(), wxConvUTF8) );
108 selections.Add(dbs.GetCount() - 1);
110 if( !engine || (barry.GetSupportedSyncTypes(*engine) & PST_TODOS) ) {
111 dbs.Add( wxString(::Barry::Task::GetDBName(), wxConvUTF8) );
112 selections.Add(dbs.GetCount() - 1);
115 // present the list to the user
116 int count = wxGetMultipleChoices(selections, msg,
117 _W("Select Databases to Erase"), dbs, m_parent);
118 if( count <= 0 )
119 return false; // nothing to do
121 // display selections to the user for one final confirmation
122 ostringstream oss;
123 oss << _C("You have selected the following databases to be completely "
124 "erased from device: ") << device_name << "\n\n";
125 for( size_t i = 0; i < selections.GetCount(); i++ ) {
126 oss << string(dbs[selections[i]].utf8_str()) << "\n";
128 oss << "\n" << _C("Proceed with erase?");
129 wxString confirm(oss.str().c_str(), wxConvUTF8);
130 int choice = wxMessageBox(confirm, _W("Erase Confirmation"),
131 wxYES_NO | wxICON_QUESTION, m_parent);
132 if( choice != wxYES )
133 return false; // nothing to do
135 // connect to the device and delete all selected databases
136 wxBusyCursor wait;
137 ::Barry::Controller con(results[index]);
138 ::Barry::Mode::Desktop desktop(con);
139 desktop.Open();
140 const ::Barry::DatabaseDatabase &dbdb = desktop.GetDBDB();
142 for( size_t i = 0; i < selections.GetCount(); i++ ) {
144 string dbname(dbs[selections[i]].utf8_str());
146 unsigned int dbid;
147 if( !dbdb.GetDBNumber(dbname, dbid) ) {
148 barryverbose(_C("No database named '") << dbname << _C("' in device!"));
149 continue;
152 barryverbose(_C("Clearing db: ") << dbname);
153 desktop.ClearDatabase(dbid);
156 return true;
158 } catch( ::Barry::Error &e ) {
159 ostringstream oss;
160 oss << _C("Barry exception: ") << e.what() << "\n\n"
161 << _C("You may need to do a USB reset and rescan from the "
162 "main menu.");
163 wxString msg(oss.str().c_str(), wxConvUTF8);
164 wxMessageBox(msg, _W("Barry Exception"),
165 wxOK | wxICON_ERROR, m_parent);
166 return false;