3 /// Converter class for opensync 0.40 plugins
7 Copyright (C) 2009-2010, 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_KDEPIM "kdepim-sync"
32 #define PLUGIN_FILE "file-sync"
33 #define PLUGIN_SUNBIRD "sunbird-sync"
34 #define PLUGIN_LDAP "ldap-sync"
38 //////////////////////////////////////////////////////////////////////////////
41 Converter40::Converter40(OpenSync::OpenSync40
&api
)
46 bool Converter40::IsPluginSupported(const std::string
&plugin_name
,
47 std::string
*appname
) const
49 if( plugin_name
== PLUGIN_BARRY
) {
51 *appname
= Config::Barry::AppName();
54 else if( plugin_name
== PLUGIN_EVOLUTION
) {
56 *appname
= Config::Evolution::AppName();
63 Converter::plugin_ptr
Converter40::CreateAndLoadPlugin(const Member
&member
)
65 Converter::plugin_ptr ptr
;
67 // compare plugin name in member with all known plugins that
68 // we support... and default to Unsupported if not
69 if( member
.plugin_name
== PLUGIN_BARRY
) {
70 ptr
.reset( new Config::Barry(this, member
) );
72 else if( member
.plugin_name
== PLUGIN_EVOLUTION
) {
73 ptr
.reset( new Config::Evolution(this, member
) );
75 // default: Unsupported
77 ptr
.reset( new Config::Unsupported(this, member
) );
83 std::string
Converter40::GetPluginName(const Config::Barry
&) const
88 std::string
Converter40::GetPluginName(const Config::Evolution
&) const
90 return PLUGIN_EVOLUTION
;
93 std::string
Converter40::GetPluginName(const Config::Unsupported
&) const
95 return "unsupported-sync";
98 bool Converter40::IsConfigured(const Config::Barry
&config
) const
100 return config
.GetPin().valid();
103 bool Converter40::IsConfigured(const Config::Evolution
&config
) const
105 // the 40 plugin supports all 4, so check all 4
106 return config
.GetAddressPath().size() &&
107 config
.GetCalendarPath().size() &&
108 config
.GetTasksPath().size() &&
109 config
.GetMemosPath().size();
112 bool Converter40::IsConfigured(const Config::Unsupported
&) const
118 void Converter40::Load(Config::Barry
&config
, const Member
&member
)
120 // start with a default setting
121 config
.DebugMode(false);
122 config
.SetPassword("");
123 config
.SetPin(Barry::Pin());
125 // read in config for barry-sync
126 OS40PluginConfig cfg
= m_api
.GetConfigurationObj(member
.group_name
,
128 string value
= cfg
.GetAdvanced("Debug");
130 config
.DebugMode(true);
132 value
= cfg
.GetAdvanced("PinCode");
134 istringstream
iss(value
);
137 config
.SetPin(Barry::Pin(pin
));
140 value
= cfg
.GetPassword();
141 config
.SetPassword(value
);
144 std::string
GrabPath(const std::string
&url
)
146 if( url
.substr(0, 7) == "file://" )
147 return url
.substr(7);
151 void Converter40::Load(Config::Evolution
&config
, const Member
&member
)
153 OS40PluginConfig cfg
= m_api
.GetConfigurationObj(member
.group_name
,
156 config
.SetAddressPath(GrabPath(cfg
.GetResource("contact")->GetUrl()));
157 config
.SetCalendarPath(GrabPath(cfg
.GetResource("event")->GetUrl()));
158 config
.SetTasksPath(GrabPath(cfg
.GetResource("todo")->GetUrl()));
159 config
.SetMemosPath(GrabPath(cfg
.GetResource("note")->GetUrl()));
162 void Converter40::Load(Config::Unsupported
&config
, const Member
&member
)
164 string cfg
= m_api
.GetConfiguration(member
.group_name
, member
.id
);
165 config
.SetRawConfig(cfg
);
168 void Converter40::Save(const Config::Barry
&config
, const std::string
&group_name
)
170 if( config
.GetMemberId() == -1 )
171 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
173 OS40PluginConfig cfg
= m_api
.GetConfigurationObj(group_name
,
174 config
.GetMemberId());
175 cfg
.SetAdvanced("Debug", "Debug mode", OS40PluginConfig::BOOL_TYPE
,
176 config
.IsDebugMode() ? "1" : "0");
177 cfg
.SetAdvanced("PinCode", "PIN number", OS40PluginConfig::STRING_TYPE
,
178 config
.GetPin().str());
180 cfg
.SetPassword(config
.GetPassword());
182 cfg
.GetResource("contact")->
185 SetObjFormat("vcard30").
187 cfg
.GetResource("event")->
190 SetObjFormat("vevent20").
192 cfg
.GetResource("todo")->
195 SetObjFormat("vtodo20").
197 cfg
.GetResource("note")->
200 SetObjFormat("vjournal").
206 void Converter40::Save(const Config::Evolution
&config
, const std::string
&group_name
)
208 if( config
.GetMemberId() == -1 )
209 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
211 OS40PluginConfig cfg
= m_api
.GetConfigurationObj(group_name
,
212 config
.GetMemberId());
213 cfg
.GetResource("contact")->
215 SetObjFormat("vcard21", "VCARD_EXTENSION=Evolution").
216 SetObjFormat("vcard30", "VCARD_EXTENSION=Evolution").
217 SetUrl("file://" + config
.GetAddressPath()).
219 cfg
.GetResource("event")->
221 SetObjFormat("vevent20").
222 SetUrl("file://" + config
.GetCalendarPath()).
224 cfg
.GetResource("todo")->
226 SetObjFormat("vtodo20").
227 SetUrl("file://" + config
.GetTasksPath()).
229 cfg
.GetResource("note")->
231 SetObjFormat("vjournal").
232 SetUrl("file://" + config
.GetMemosPath()).
238 void Converter40::Save(const Config::Unsupported
&config
, const std::string
&group_name
)
240 if( config
.GetMemberId() == -1 )
241 throw Config::SaveError("Cannot save a plugin with a member_id of -1");
243 m_api
.SetConfiguration(group_name
, config
.GetMemberId(),
244 config
.GetRawConfig());
247 } // namespace OpenSync