lib: added implicit ctor converter from DatabaseDatabase to DBListType
[barry/progweb.git] / desktop / src / osconv40.cc
blob2c8c0d8c90b35f558300221a216e0b0daf96c9f6
1 ///
2 /// \file osconv40.cc
3 /// Converter class for opensync 0.40 plugins
4 ///
6 /*
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 "osconv40.h"
23 #include "osconfig.h"
24 #include <sstream>
26 using namespace std;
28 // Supported plugin names
29 #define PLUGIN_BARRY "barry-sync"
30 #define PLUGIN_EVOLUTION "evo2-sync"
31 #define PLUGIN_GOOGLE "google-data"
32 #define PLUGIN_KDEPIM "kdepim-sync"
33 #define PLUGIN_FILE "file-sync"
34 #define PLUGIN_SUNBIRD "sunbird-sync"
35 #define PLUGIN_LDAP "ldap-sync"
37 namespace OpenSync {
39 //////////////////////////////////////////////////////////////////////////////
40 // Converter40
42 Converter40::Converter40(OpenSync::OpenSync40 &api)
43 : m_api(api)
47 bool Converter40::IsPluginSupported(const std::string &plugin_name,
48 std::string *appname) const
50 if( plugin_name == PLUGIN_BARRY ) {
51 if( appname )
52 *appname = Config::Barry::AppName();
53 return true;
55 else if( plugin_name == PLUGIN_EVOLUTION ) {
56 if( appname )
57 *appname = Config::Evolution::AppName();
58 return true;
60 else if( plugin_name == PLUGIN_GOOGLE ) {
61 if( appname )
62 *appname = Config::Google::AppName();
63 return true;
66 return false;
69 Converter::plugin_ptr Converter40::CreateAndLoadPlugin(const Member &member)
71 Converter::plugin_ptr ptr;
73 // compare plugin name in member with all known plugins that
74 // we support... and default to Unsupported if not
75 if( member.plugin_name == PLUGIN_BARRY ) {
76 ptr.reset( new Config::Barry(this, member) );
78 else if( member.plugin_name == PLUGIN_EVOLUTION ) {
79 ptr.reset( new Config::Evolution(this, member) );
81 else if( member.plugin_name == PLUGIN_GOOGLE ) {
82 ptr.reset( new Config::Google(this, member) );
84 // default: Unsupported
85 else {
86 ptr.reset( new Config::Unsupported(this, member) );
89 return ptr;
92 std::string Converter40::GetPluginName(const Config::Barry &) const
94 return PLUGIN_BARRY;
97 std::string Converter40::GetPluginName(const Config::Evolution &) const
99 return PLUGIN_EVOLUTION;
102 std::string Converter40::GetPluginName(const Config::Google &) const
104 return PLUGIN_GOOGLE;
107 std::string Converter40::GetPluginName(const Config::KDEPim &) const
109 return PLUGIN_KDEPIM;
112 std::string Converter40::GetPluginName(const Config::Unsupported &) const
114 return "unsupported-sync";
117 bool Converter40::IsConfigured(const Config::Barry &config) const
119 return config.GetPin().Valid();
122 bool Converter40::IsConfigured(const Config::Evolution &config) const
124 // the 40 plugin supports all 4, so check all 4
125 return config.GetAddressPath().size() &&
126 config.GetCalendarPath().size() &&
127 config.GetTasksPath().size() &&
128 config.GetMemosPath().size();
131 bool Converter40::IsConfigured(const Config::Google &config) const
133 // password might (maaayybe) be empty, so skip it
134 return config.GetUsername().size();
136 bool Converter40::IsConfigured(const Config::KDEPim &config) const
138 // FIXME - not sure about this plugin yet
139 return false;
142 bool Converter40::IsConfigured(const Config::Unsupported &) const
144 return false;
147 // FIXME - these should/could? access the capabilities feature of
148 // opensync 0.4x, but I think that requires a discovery, and
149 // this information is required at the configuration stage
150 // for the GUI
151 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Barry &) const
153 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
156 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Evolution &) const
158 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
161 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Google &) const
163 return PST_CONTACTS | PST_EVENTS;
166 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::KDEPim &) const
168 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
171 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Unsupported &) const
173 return PST_NONE;
177 void Converter40::Load(Config::Barry &config, const Member &member)
179 // start with a default setting
180 config.DebugMode(false);
181 config.SetPassword("");
182 config.SetPin(Barry::Pin());
184 // read in config for barry-sync
185 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
186 member.id);
187 string value = cfg.GetAdvanced("Debug");
188 if( value == "1" )
189 config.DebugMode(true);
191 value = cfg.GetAdvanced("PinCode");
193 istringstream iss(value);
194 uint32_t pin = 0;
195 iss >> hex >> pin;
196 config.SetPin(Barry::Pin(pin));
199 value = cfg.GetPassword();
200 config.SetPassword(value);
203 void Converter40::Load(Config::Evolution &config, const Member &member)
205 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
206 member.id);
208 config.SetAddressPath(cfg.GetResource("contact")->GetUrl());
209 config.SetCalendarPath(cfg.GetResource("event")->GetUrl());
210 config.SetTasksPath(cfg.GetResource("todo")->GetUrl());
211 config.SetMemosPath(cfg.GetResource("note")->GetUrl());
214 void Converter40::Load(Config::Google &config, const Member &member)
216 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
217 member.id);
219 config.SetUsername(cfg.GetUsername());
220 config.SetPassword(cfg.GetPassword());
221 config.EnableContacts(cfg.GetResource("contact")->IsEnabled());
222 config.EnableCalendar(cfg.GetResource("event")->IsEnabled());
225 void Converter40::Load(Config::KDEPim &config, const Member &member)
227 // FIXME
230 void Converter40::Load(Config::Unsupported &config, const Member &member)
232 string cfg = m_api.GetConfiguration(member.group_name, member.id);
233 config.SetRawConfig(cfg);
236 void Converter40::Save(const Config::Barry &config, const std::string &group_name)
238 if( config.GetMemberId() == -1 )
239 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
241 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
242 config.GetMemberId());
243 cfg.SetAdvanced("Debug", "Debug mode", OS40PluginConfig::BOOL_TYPE,
244 config.IsDebugMode() ? "1" : "0");
245 cfg.SetAdvanced("PinCode", "PIN number", OS40PluginConfig::STRING_TYPE,
246 config.GetPin().Str());
248 cfg.SetPassword(config.GetPassword());
250 cfg.GetResource("contact")->
251 SetName("Contacts").
252 Enable(true).
253 SetObjFormat("vcard30").
254 AddResource();
255 cfg.GetResource("event")->
256 SetName("Event").
257 Enable(true).
258 SetObjFormat("vevent20").
259 AddResource();
260 cfg.GetResource("todo")->
261 SetName("Todo").
262 Enable(true).
263 SetObjFormat("vtodo20").
264 AddResource();
265 cfg.GetResource("note")->
266 SetName("Memo").
267 Enable(true).
268 SetObjFormat("vjournal").
269 AddResource();
271 cfg.Save();
274 void Converter40::Save(const Config::Evolution &config, const std::string &group_name)
276 if( config.GetMemberId() == -1 )
277 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
279 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
280 config.GetMemberId());
281 cfg.GetResource("contact")->
282 Enable(true).
283 SetObjFormat("vcard21", "VCARD_EXTENSION=Evolution").
284 SetObjFormat("vcard30", "VCARD_EXTENSION=Evolution").
285 SetUrl(config.GetAddressPath()).
286 AddResource();
287 cfg.GetResource("event")->
288 Enable(true).
289 SetObjFormat("vevent20").
290 SetUrl(config.GetCalendarPath()).
291 AddResource();
292 cfg.GetResource("todo")->
293 Enable(true).
294 SetObjFormat("vtodo20").
295 SetUrl(config.GetTasksPath()).
296 AddResource();
297 cfg.GetResource("note")->
298 Enable(true).
299 SetObjFormat("vjournal").
300 SetUrl(config.GetMemosPath()).
301 AddResource();
303 cfg.Save();
306 void Converter40::Save(const Config::Google &config, const std::string &group_name)
308 if( config.GetMemberId() == -1 )
309 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
311 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
312 config.GetMemberId());
313 cfg.SetUsername(config.GetUsername());
314 cfg.SetPassword(config.GetPassword());
315 cfg.GetResource("contact")->
316 Enable(config.IsContactsEnabled()).
317 SetObjFormat("xmlformat-contact-doc").
318 AddResource();
319 cfg.GetResource("event")->
320 Enable(config.IsCalendarEnabled()).
321 SetObjFormat("xmlformat-event-doc").
322 AddResource();
324 cfg.Save();
327 void Converter40::Save(const Config::KDEPim &config, const std::string &group_name)
329 // FIXME
332 void Converter40::Save(const Config::Unsupported &config, const std::string &group_name)
334 if( config.GetMemberId() == -1 )
335 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
337 m_api.SetConfiguration(group_name, config.GetMemberId(),
338 config.GetRawConfig());
341 } // namespace OpenSync