3 /// Converter class for opensync 0.40 plugins
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.
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"
39 //////////////////////////////////////////////////////////////////////////////
42 Converter40::Converter40(OpenSync::OpenSync40
&api
)
47 bool Converter40::IsPluginSupported(const std::string
&plugin_name
,
48 std::string
*appname
) const
50 if( plugin_name
== PLUGIN_BARRY
) {
52 *appname
= Config::Barry::AppName();
55 else if( plugin_name
== PLUGIN_EVOLUTION
) {
57 *appname
= Config::Evolution::AppName();
60 else if( plugin_name
== PLUGIN_GOOGLE
) {
62 *appname
= Config::Google::AppName();
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
86 ptr
.reset( new Config::Unsupported(this, member
) );
92 std::string
Converter40::GetPluginName(const Config::Barry
&) const
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
142 bool Converter40::IsConfigured(const Config::Unsupported
&) const
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
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
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
,
187 string value
= cfg
.GetAdvanced("Debug");
189 config
.DebugMode(true);
191 value
= cfg
.GetAdvanced("PinCode");
193 istringstream
iss(value
);
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
,
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
,
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
)
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")->
253 SetObjFormat("vcard30").
255 cfg
.GetResource("event")->
258 SetObjFormat("vevent20").
260 cfg
.GetResource("todo")->
263 SetObjFormat("vtodo20").
265 cfg
.GetResource("note")->
268 SetObjFormat("vjournal").
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")->
283 SetObjFormat("vcard21", "VCARD_EXTENSION=Evolution").
284 SetObjFormat("vcard30", "VCARD_EXTENSION=Evolution").
285 SetUrl(config
.GetAddressPath()).
287 cfg
.GetResource("event")->
289 SetObjFormat("vevent20").
290 SetUrl(config
.GetCalendarPath()).
292 cfg
.GetResource("todo")->
294 SetObjFormat("vtodo20").
295 SetUrl(config
.GetTasksPath()).
297 cfg
.GetResource("note")->
299 SetObjFormat("vjournal").
300 SetUrl(config
.GetMemosPath()).
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").
319 cfg
.GetResource("event")->
320 Enable(config
.IsCalendarEnabled()).
321 SetObjFormat("xmlformat-event-doc").
327 void Converter40::Save(const Config::KDEPim
&config
, const std::string
&group_name
)
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