desktop: fixed bug in GroupCfgDlg that gave mistaken "not configured" error
[barry/progweb.git] / desktop / src / osconv40.cc
blob80dee96e77e5fb7d1ae1d691c5bd7b07736df744
1 ///
2 /// \file osconv40.cc
3 /// Converter class for opensync 0.40 plugins
4 ///
6 /*
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.
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_KDEPIM "kdepim-sync"
32 #define PLUGIN_FILE "file-sync"
33 #define PLUGIN_SUNBIRD "sunbird-sync"
34 #define PLUGIN_LDAP "ldap-sync"
36 namespace OpenSync {
38 //////////////////////////////////////////////////////////////////////////////
39 // Converter40
41 Converter40::Converter40(OpenSync::OpenSync40 &api)
42 : m_api(api)
46 bool Converter40::IsPluginSupported(const std::string &plugin_name,
47 std::string *appname) const
49 if( plugin_name == PLUGIN_BARRY ) {
50 if( appname )
51 *appname = Config::Barry::AppName();
52 return true;
54 else if( plugin_name == PLUGIN_EVOLUTION ) {
55 if( appname )
56 *appname = Config::Evolution::AppName();
57 return true;
60 return false;
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
76 else {
77 ptr.reset( new Config::Unsupported(this, member) );
80 return ptr;
83 std::string Converter40::GetPluginName(const Config::Barry &) const
85 return PLUGIN_BARRY;
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
114 return false;
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,
127 member.id);
128 string value = cfg.GetAdvanced("Debug");
129 if( value == "1" )
130 config.DebugMode(true);
132 value = cfg.GetAdvanced("PinCode");
134 istringstream iss(value);
135 uint32_t pin = 0;
136 iss >> hex >> pin;
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);
148 return url;
151 void Converter40::Load(Config::Evolution &config, const Member &member)
153 OS40PluginConfig cfg = m_api.GetConfigurationObj(member.group_name,
154 member.id);
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")->
183 SetName("Contacts").
184 Enable(true).
185 SetObjFormat("vcard30").
186 AddResource();
187 cfg.GetResource("event")->
188 SetName("Event").
189 Enable(true).
190 SetObjFormat("vevent20").
191 AddResource();
192 cfg.GetResource("todo")->
193 SetName("Todo").
194 Enable(true).
195 SetObjFormat("vtodo20").
196 AddResource();
197 cfg.GetResource("note")->
198 SetName("Memo").
199 Enable(true).
200 SetObjFormat("vjournal").
201 AddResource();
203 cfg.Save();
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")->
214 Enable(true).
215 SetObjFormat("vcard21", "VCARD_EXTENSION=Evolution").
216 SetObjFormat("vcard30", "VCARD_EXTENSION=Evolution").
217 SetUrl("file://" + config.GetAddressPath()).
218 AddResource();
219 cfg.GetResource("event")->
220 Enable(true).
221 SetObjFormat("vevent20").
222 SetUrl("file://" + config.GetCalendarPath()).
223 AddResource();
224 cfg.GetResource("todo")->
225 Enable(true).
226 SetObjFormat("vtodo20").
227 SetUrl("file://" + config.GetTasksPath()).
228 AddResource();
229 cfg.GetResource("note")->
230 Enable(true).
231 SetObjFormat("vjournal").
232 SetUrl("file://" + config.GetMemosPath()).
233 AddResource();
235 cfg.Save();
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