Bumped copyright dates for 2013
[barry.git] / desktop / src / osconv40.cc
blob506246df02a8060f4b583562cd0712e15b7ce825
1 ///
2 /// \file osconv40.cc
3 /// Converter class for opensync 0.40 plugins
4 ///
6 /*
7 Copyright (C) 2009-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 "osconv40.h"
23 #include "osconfig.h"
24 #include <sstream>
25 #include "i18n.h"
27 using namespace std;
29 // Supported plugin names
30 #define PLUGIN_BARRY "barry-sync"
31 #define PLUGIN_EVOLUTION "evo2-sync"
32 #define PLUGIN_EVOLUTION3 "evo3-sync"
33 #define PLUGIN_GOOGLE "google-data"
34 #define PLUGIN_KDEPIM "kdepim-sync"
35 #define PLUGIN_FILE "file-sync"
36 #define PLUGIN_SUNBIRD "sunbird-sync"
37 #define PLUGIN_LDAP "ldap-sync"
39 namespace OpenSync {
41 //////////////////////////////////////////////////////////////////////////////
42 // Converter40
44 Converter40::Converter40(OpenSync::OpenSync40 &api)
45 : m_api(api)
49 bool Converter40::IsPluginSupported(const std::string &plugin_name,
50 std::string *appname) const
52 if( plugin_name == PLUGIN_BARRY ) {
53 if( appname )
54 *appname = Config::Barry::AppName();
55 return true;
57 else if( plugin_name == PLUGIN_EVOLUTION ) {
58 if( appname )
59 *appname = Config::Evolution::AppName();
60 return true;
62 else if( plugin_name == PLUGIN_EVOLUTION3 ) {
63 if( appname )
64 *appname = Config::Evolution3::AppName();
65 return true;
67 else if( plugin_name == PLUGIN_GOOGLE ) {
68 if( appname )
69 *appname = Config::Google::AppName();
70 return true;
73 return false;
76 Converter::plugin_ptr Converter40::CreateAndLoadPlugin(const Member &member)
78 Converter::plugin_ptr ptr;
80 // compare plugin name in member with all known plugins that
81 // we support... and default to Unsupported if not
82 if( member.plugin_name == PLUGIN_BARRY ) {
83 ptr.reset( new Config::Barry(this, member) );
85 else if( member.plugin_name == PLUGIN_EVOLUTION ) {
86 ptr.reset( new Config::Evolution(this, member) );
88 else if( member.plugin_name == PLUGIN_EVOLUTION3 ) {
89 ptr.reset( new Config::Evolution3(this, member) );
91 else if( member.plugin_name == PLUGIN_GOOGLE ) {
92 ptr.reset( new Config::Google(this, member) );
94 // default: Unsupported
95 else {
96 ptr.reset( new Config::Unsupported(this, member) );
99 return ptr;
102 std::string Converter40::GetPluginName(const Config::Barry &) const
104 return PLUGIN_BARRY;
107 std::string Converter40::GetPluginName(const Config::Evolution &) const
109 return PLUGIN_EVOLUTION;
112 std::string Converter40::GetPluginName(const Config::Evolution3 &) const
114 return PLUGIN_EVOLUTION3;
117 std::string Converter40::GetPluginName(const Config::Google &) const
119 return PLUGIN_GOOGLE;
122 std::string Converter40::GetPluginName(const Config::KDEPim &) const
124 return PLUGIN_KDEPIM;
127 std::string Converter40::GetPluginName(const Config::Unsupported &) const
129 return "unsupported-sync";
132 bool Converter40::IsConfigured(const Config::Barry &config) const
134 return config.GetPin().Valid();
137 bool Converter40::IsConfigured(const Config::Evolution &config) const
139 // as long as one is configured, we're good
140 return config.GetAddressPath().size() ||
141 config.GetCalendarPath().size() ||
142 config.GetTasksPath().size() ||
143 config.GetMemosPath().size();
146 bool Converter40::IsConfigured(const Config::Evolution3 &config) const
148 return IsConfigured(static_cast<const Config::Evolution&> (config));
151 bool Converter40::IsConfigured(const Config::Google &config) const
153 // password might (maaayybe) be empty, so skip it
154 return config.GetUsername().size();
156 bool Converter40::IsConfigured(const Config::KDEPim &config) const
158 // FIXME - not sure about this plugin yet
159 return false;
162 bool Converter40::IsConfigured(const Config::Unsupported &) const
164 return false;
167 // FIXME - these should/could? access the capabilities feature of
168 // opensync 0.4x, but I think that requires a discovery, and
169 // this information is required at the configuration stage
170 // for the GUI
171 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Barry &) const
173 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
176 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Evolution &) const
178 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
181 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Evolution3 &) const
183 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
186 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Google &) const
188 return PST_CONTACTS | PST_EVENTS;
191 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::KDEPim &) const
193 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
196 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Unsupported &) const
198 return PST_NONE;
202 void Converter40::Load(Config::Barry &config, const Member &member)
204 // start with a default setting
205 config.DebugMode(false);
206 config.SetPassword("");
207 config.SetPin(Barry::Pin());
209 // read in config for barry-sync
210 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
211 member.id);
212 string value = cfg.GetAdvanced("Debug");
213 if( value == "1" )
214 config.DebugMode(true);
216 value = cfg.GetAdvanced("PinCode");
218 istringstream iss(value);
219 uint32_t pin = 0;
220 iss >> hex >> pin;
221 config.SetPin(Barry::Pin(pin));
224 value = cfg.GetPassword();
225 config.SetPassword(value);
228 void Converter40::Load(Config::Evolution &config, const Member &member)
230 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
231 member.id);
233 config.SetAddressPath(cfg.GetResource("contact")->GetUrl());
234 config.SetCalendarPath(cfg.GetResource("event")->GetUrl());
235 config.SetTasksPath(cfg.GetResource("todo")->GetUrl());
236 config.SetMemosPath(cfg.GetResource("note")->GetUrl());
239 void Converter40::Load(Config::Evolution3 &config, const Member &member)
241 Load(static_cast<Config::Evolution&> (config), member);
244 void Converter40::Load(Config::Google &config, const Member &member)
246 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
247 member.id);
249 config.SetUsername(cfg.GetUsername());
250 config.SetPassword(cfg.GetPassword());
251 config.EnableContacts(cfg.GetResource("contact")->IsEnabled());
252 config.EnableCalendar(cfg.GetResource("event")->IsEnabled());
255 void Converter40::Load(Config::KDEPim &config, const Member &member)
257 // FIXME
260 void Converter40::Load(Config::Unsupported &config, const Member &member)
262 string cfg = m_api.GetConfiguration(member.group_name, member.id);
263 config.SetRawConfig(cfg);
266 void Converter40::Save(const Config::Barry &config, const std::string &group_name)
268 if( config.GetMemberId() == -1 )
269 throw Config::SaveError(_C("Cannot save a plugin with a member_id of -1"));
271 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
272 config.GetMemberId());
273 cfg.SetAdvanced("Debug", "Debug mode", OS40PluginConfig::BOOL_TYPE,
274 config.IsDebugMode() ? "1" : "0");
275 cfg.SetAdvanced("PinCode", "PIN number", OS40PluginConfig::STRING_TYPE,
276 config.GetPin().Str());
278 cfg.SetPassword(config.GetPassword());
280 cfg.GetResource("contact")->
281 SetName("Contacts").
282 Enable(true).
283 SetObjFormat("vcard30").
284 AddResource();
285 cfg.GetResource("event")->
286 SetName("Event").
287 Enable(true).
288 SetObjFormat("vevent20").
289 AddResource();
290 cfg.GetResource("todo")->
291 SetName("Todo").
292 Enable(true).
293 SetObjFormat("vtodo20").
294 AddResource();
295 cfg.GetResource("note")->
296 SetName("Memo").
297 Enable(true).
298 SetObjFormat("vjournal").
299 AddResource();
301 cfg.Save();
304 void Converter40::Save(const Config::Evolution &config, const std::string &group_name)
306 if( config.GetMemberId() == -1 )
307 throw Config::SaveError(_C("Cannot save a plugin with a member_id of -1"));
309 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
310 config.GetMemberId());
311 cfg.GetResource("contact")->
312 Enable(config.GetAddressPath().size()).
313 SetObjFormat("vcard21", "VCARD_EXTENSION=Evolution").
314 SetObjFormat("vcard30", "VCARD_EXTENSION=Evolution").
315 SetUrl(config.GetAddressPath()).
316 AddResource();
317 cfg.GetResource("event")->
318 Enable(config.GetCalendarPath().size()).
319 SetObjFormat("vevent20").
320 SetUrl(config.GetCalendarPath()).
321 AddResource();
322 cfg.GetResource("todo")->
323 Enable(config.GetTasksPath().size()).
324 SetObjFormat("vtodo20").
325 SetUrl(config.GetTasksPath()).
326 AddResource();
327 cfg.GetResource("note")->
328 Enable(config.GetMemosPath().size()).
329 SetObjFormat("vjournal").
330 SetUrl(config.GetMemosPath()).
331 AddResource();
333 cfg.Save();
336 void Converter40::Save(const Config::Evolution3 &config, const std::string &group_name)
338 Save(static_cast<const Config::Evolution&> (config), group_name);
341 void Converter40::Save(const Config::Google &config, const std::string &group_name)
343 if( config.GetMemberId() == -1 )
344 throw Config::SaveError(_C("Cannot save a plugin with a member_id of -1"));
346 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
347 config.GetMemberId());
348 cfg.SetUsername(config.GetUsername());
349 cfg.SetPassword(config.GetPassword());
350 cfg.GetResource("contact")->
351 Enable(config.IsContactsEnabled()).
352 SetObjFormat("xmlformat-contact-doc").
353 AddResource();
354 cfg.GetResource("event")->
355 Enable(config.IsCalendarEnabled()).
356 SetObjFormat("xmlformat-event-doc").
357 AddResource();
359 cfg.Save();
362 void Converter40::Save(const Config::KDEPim &config, const std::string &group_name)
364 // FIXME
367 void Converter40::Save(const Config::Unsupported &config, const std::string &group_name)
369 if( config.GetMemberId() == -1 )
370 throw Config::SaveError(_C("Cannot save a plugin with a member_id of -1"));
372 m_api.SetConfiguration(group_name, config.GetMemberId(),
373 config.GetRawConfig());
376 } // namespace OpenSync