lib: added warning checks for unsupported recursion fields in vevent.cc
[barry/progweb.git] / desktop / src / osconv40.cc
blobe886a1049cb8648663938f6980e5d13e181a0320
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_EVOLUTION3 "evo3-sync"
32 #define PLUGIN_GOOGLE "google-data"
33 #define PLUGIN_KDEPIM "kdepim-sync"
34 #define PLUGIN_FILE "file-sync"
35 #define PLUGIN_SUNBIRD "sunbird-sync"
36 #define PLUGIN_LDAP "ldap-sync"
38 namespace OpenSync {
40 //////////////////////////////////////////////////////////////////////////////
41 // Converter40
43 Converter40::Converter40(OpenSync::OpenSync40 &api)
44 : m_api(api)
48 bool Converter40::IsPluginSupported(const std::string &plugin_name,
49 std::string *appname) const
51 if( plugin_name == PLUGIN_BARRY ) {
52 if( appname )
53 *appname = Config::Barry::AppName();
54 return true;
56 else if( plugin_name == PLUGIN_EVOLUTION ) {
57 if( appname )
58 *appname = Config::Evolution::AppName();
59 return true;
61 else if( plugin_name == PLUGIN_EVOLUTION3 ) {
62 if( appname )
63 *appname = Config::Evolution3::AppName();
64 return true;
66 else if( plugin_name == PLUGIN_GOOGLE ) {
67 if( appname )
68 *appname = Config::Google::AppName();
69 return true;
72 return false;
75 Converter::plugin_ptr Converter40::CreateAndLoadPlugin(const Member &member)
77 Converter::plugin_ptr ptr;
79 // compare plugin name in member with all known plugins that
80 // we support... and default to Unsupported if not
81 if( member.plugin_name == PLUGIN_BARRY ) {
82 ptr.reset( new Config::Barry(this, member) );
84 else if( member.plugin_name == PLUGIN_EVOLUTION ) {
85 ptr.reset( new Config::Evolution(this, member) );
87 else if( member.plugin_name == PLUGIN_EVOLUTION3 ) {
88 ptr.reset( new Config::Evolution3(this, member) );
90 else if( member.plugin_name == PLUGIN_GOOGLE ) {
91 ptr.reset( new Config::Google(this, member) );
93 // default: Unsupported
94 else {
95 ptr.reset( new Config::Unsupported(this, member) );
98 return ptr;
101 std::string Converter40::GetPluginName(const Config::Barry &) const
103 return PLUGIN_BARRY;
106 std::string Converter40::GetPluginName(const Config::Evolution &) const
108 return PLUGIN_EVOLUTION;
111 std::string Converter40::GetPluginName(const Config::Evolution3 &) const
113 return PLUGIN_EVOLUTION3;
116 std::string Converter40::GetPluginName(const Config::Google &) const
118 return PLUGIN_GOOGLE;
121 std::string Converter40::GetPluginName(const Config::KDEPim &) const
123 return PLUGIN_KDEPIM;
126 std::string Converter40::GetPluginName(const Config::Unsupported &) const
128 return "unsupported-sync";
131 bool Converter40::IsConfigured(const Config::Barry &config) const
133 return config.GetPin().Valid();
136 bool Converter40::IsConfigured(const Config::Evolution &config) const
138 // as long as one is configured, we're good
139 return config.GetAddressPath().size() ||
140 config.GetCalendarPath().size() ||
141 config.GetTasksPath().size() ||
142 config.GetMemosPath().size();
145 bool Converter40::IsConfigured(const Config::Evolution3 &config) const
147 return IsConfigured(static_cast<const Config::Evolution&> (config));
150 bool Converter40::IsConfigured(const Config::Google &config) const
152 // password might (maaayybe) be empty, so skip it
153 return config.GetUsername().size();
155 bool Converter40::IsConfigured(const Config::KDEPim &config) const
157 // FIXME - not sure about this plugin yet
158 return false;
161 bool Converter40::IsConfigured(const Config::Unsupported &) const
163 return false;
166 // FIXME - these should/could? access the capabilities feature of
167 // opensync 0.4x, but I think that requires a discovery, and
168 // this information is required at the configuration stage
169 // for the GUI
170 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Barry &) const
172 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
175 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Evolution &) const
177 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
180 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Evolution3 &) const
182 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
185 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Google &) const
187 return PST_CONTACTS | PST_EVENTS;
190 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::KDEPim &) const
192 return PST_CONTACTS | PST_EVENTS | PST_NOTES | PST_TODOS;
195 Config::pst_type Converter40::GetSupportedSyncTypes(const Config::Unsupported &) const
197 return PST_NONE;
201 void Converter40::Load(Config::Barry &config, const Member &member)
203 // start with a default setting
204 config.DebugMode(false);
205 config.SetPassword("");
206 config.SetPin(Barry::Pin());
208 // read in config for barry-sync
209 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
210 member.id);
211 string value = cfg.GetAdvanced("Debug");
212 if( value == "1" )
213 config.DebugMode(true);
215 value = cfg.GetAdvanced("PinCode");
217 istringstream iss(value);
218 uint32_t pin = 0;
219 iss >> hex >> pin;
220 config.SetPin(Barry::Pin(pin));
223 value = cfg.GetPassword();
224 config.SetPassword(value);
227 void Converter40::Load(Config::Evolution &config, const Member &member)
229 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
230 member.id);
232 config.SetAddressPath(cfg.GetResource("contact")->GetUrl());
233 config.SetCalendarPath(cfg.GetResource("event")->GetUrl());
234 config.SetTasksPath(cfg.GetResource("todo")->GetUrl());
235 config.SetMemosPath(cfg.GetResource("note")->GetUrl());
238 void Converter40::Load(Config::Evolution3 &config, const Member &member)
240 Load(static_cast<Config::Evolution&> (config), member);
243 void Converter40::Load(Config::Google &config, const Member &member)
245 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
246 member.id);
248 config.SetUsername(cfg.GetUsername());
249 config.SetPassword(cfg.GetPassword());
250 config.EnableContacts(cfg.GetResource("contact")->IsEnabled());
251 config.EnableCalendar(cfg.GetResource("event")->IsEnabled());
254 void Converter40::Load(Config::KDEPim &config, const Member &member)
256 // FIXME
259 void Converter40::Load(Config::Unsupported &config, const Member &member)
261 string cfg = m_api.GetConfiguration(member.group_name, member.id);
262 config.SetRawConfig(cfg);
265 void Converter40::Save(const Config::Barry &config, const std::string &group_name)
267 if( config.GetMemberId() == -1 )
268 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
270 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
271 config.GetMemberId());
272 cfg.SetAdvanced("Debug", "Debug mode", OS40PluginConfig::BOOL_TYPE,
273 config.IsDebugMode() ? "1" : "0");
274 cfg.SetAdvanced("PinCode", "PIN number", OS40PluginConfig::STRING_TYPE,
275 config.GetPin().Str());
277 cfg.SetPassword(config.GetPassword());
279 cfg.GetResource("contact")->
280 SetName("Contacts").
281 Enable(true).
282 SetObjFormat("vcard30").
283 AddResource();
284 cfg.GetResource("event")->
285 SetName("Event").
286 Enable(true).
287 SetObjFormat("vevent20").
288 AddResource();
289 cfg.GetResource("todo")->
290 SetName("Todo").
291 Enable(true).
292 SetObjFormat("vtodo20").
293 AddResource();
294 cfg.GetResource("note")->
295 SetName("Memo").
296 Enable(true).
297 SetObjFormat("vjournal").
298 AddResource();
300 cfg.Save();
303 void Converter40::Save(const Config::Evolution &config, const std::string &group_name)
305 if( config.GetMemberId() == -1 )
306 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
308 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
309 config.GetMemberId());
310 cfg.GetResource("contact")->
311 Enable(config.GetAddressPath().size()).
312 SetObjFormat("vcard21", "VCARD_EXTENSION=Evolution").
313 SetObjFormat("vcard30", "VCARD_EXTENSION=Evolution").
314 SetUrl(config.GetAddressPath()).
315 AddResource();
316 cfg.GetResource("event")->
317 Enable(config.GetCalendarPath().size()).
318 SetObjFormat("vevent20").
319 SetUrl(config.GetCalendarPath()).
320 AddResource();
321 cfg.GetResource("todo")->
322 Enable(config.GetTasksPath().size()).
323 SetObjFormat("vtodo20").
324 SetUrl(config.GetTasksPath()).
325 AddResource();
326 cfg.GetResource("note")->
327 Enable(config.GetMemosPath().size()).
328 SetObjFormat("vjournal").
329 SetUrl(config.GetMemosPath()).
330 AddResource();
332 cfg.Save();
335 void Converter40::Save(const Config::Evolution3 &config, const std::string &group_name)
337 Save(static_cast<const Config::Evolution&> (config), group_name);
340 void Converter40::Save(const Config::Google &config, const std::string &group_name)
342 if( config.GetMemberId() == -1 )
343 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
345 OS40PluginConfig cfg = m_api.GetConfigurationObj(group_name,
346 config.GetMemberId());
347 cfg.SetUsername(config.GetUsername());
348 cfg.SetPassword(config.GetPassword());
349 cfg.GetResource("contact")->
350 Enable(config.IsContactsEnabled()).
351 SetObjFormat("xmlformat-contact-doc").
352 AddResource();
353 cfg.GetResource("event")->
354 Enable(config.IsCalendarEnabled()).
355 SetObjFormat("xmlformat-event-doc").
356 AddResource();
358 cfg.Save();
361 void Converter40::Save(const Config::KDEPim &config, const std::string &group_name)
363 // FIXME
366 void Converter40::Save(const Config::Unsupported &config, const std::string &group_name)
368 if( config.GetMemberId() == -1 )
369 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
371 m_api.SetConfiguration(group_name, config.GetMemberId(),
372 config.GetRawConfig());
375 } // namespace OpenSync