2 * Funambol is a mobile platform developed by Funambol, Inc.
3 * Copyright (C) 2003 - 2007 Funambol, Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by
7 * the Free Software Foundation with the addition of the following permission
8 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
9 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
10 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program; if not, see http://www.gnu.org/licenses or write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
23 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License
30 * version 3, these Appropriate Legal Notices must retain the display of the
31 * "Powered by Funambol" logo. If the display of the logo is not reasonably
32 * feasible for technical reasons, the Appropriate Legal Notices must display
33 * the words "Powered by Funambol".
36 #include "base/util/utils.h"
37 #include "vocl/WinNote.h"
38 #include "vocl/VConverter.h"
39 #include "base/stringUtils.h"
40 #include "base/globalsdef.h"
48 * Following are the possible values for WinNote property "X-FUNAMBOL-COLOR".
49 * @see enum WinNoteColor
51 static WCHAR* colorName[] =
67 // Constructor: fills propertyMap parsing the passed data
68 WinNote::WinNote(const wstring dataString) {
80 // Format and return a vNote string from the propertyMap.
81 wstring& WinNote::toString() {
86 // Conversion: WinNote -> vObject.
87 // -------------------------------
89 VObject* vo = new VObject();
93 vp = new VProperty(TEXT("BEGIN"), TEXT("VNOTE"));
97 vp = new VProperty(TEXT("VERSION"), VNOTE_VERSION);
103 if (getProperty(L"Folder", element)) {
104 vp = new VProperty(L"X-FUNAMBOL-FOLDER");
105 vp->addValue(element.c_str());
107 delete vp; vp = NULL;
110 if (getProperty(L"Subject", element)) {
111 vp = new VProperty(TEXT("SUMMARY"), element.c_str());
113 delete vp; vp = NULL;
115 if (getProperty(L"Body", element)) {
116 vp = new VProperty(TEXT("BODY"), element.c_str());
118 delete vp; vp = NULL;
120 if (getProperty(L"Categories", element)) {
121 vp = new VProperty(TEXT("CATEGORIES"), element.c_str());
123 delete vp; vp = NULL;
128 // ---- Other Funambol defined properties ----
129 // Support for other fields that don't have a
130 // specific correspondence in vCalendar.
131 if (getProperty(L"Color", element)) {
132 long color = _wtoi(element.c_str());
133 vp = new VProperty(TEXT("X-FUNAMBOL-COLOR"));
135 if (color < 0 || color >= NUM_NOTE_COLOR) {
136 color = 1; // Default = yellow.
138 vp->addValue(colorName[color]);
141 delete vp; vp = NULL;
146 vp = new VProperty(TEXT("X-FUNAMBOL-POSITION"));
147 if (getProperty(L"Top", element)) {
149 vp->addValue(element.c_str());
151 if (getProperty(L"Left", element)) {
153 vp->addValue(element.c_str());
155 if (getProperty(L"Height", element)) {
157 vp->addValue(element.c_str());
159 if (getProperty(L"Width", element)) {
161 vp->addValue(element.c_str());
166 delete vp; vp = NULL;
169 vp = new VProperty(TEXT("END"), TEXT("VNOTE"));
171 delete vp; vp = NULL;
178 WCHAR* tmp = vo->toString();
190 // Parse a vNote string and fills the propertyMap.
192 int WinNote::parse(const wstring dataString) {
194 WCHAR* element = NULL;
197 // Parse the vNote and fill the VObject.
198 // -----------------------------------------
200 VObject* vo = VConverter::parse(dataString.c_str());
202 //sprintf(lastErrorMsg, ERR_ITEM_VOBJ_PARSE);
203 setError(1, ERR_ITEM_VOBJ_PARSE);
204 LOG.error(getLastErrorMsg());
207 // Check if VObject type and version are the correct ones.
208 if (!checkVNoteTypeAndVersion(vo)) {
215 // Conversion: vObject -> WinNote.
216 // -------------------------------
217 // Note: properties found are added to the propertyMap, so that the
218 // map will contain only parsed properties after this process.
220 if (element = getVObjectPropertyValue(vo, L"SUMMARY")) {
221 setProperty(L"Subject", element);
223 if (element = getVObjectPropertyValue(vo, L"BODY")) {
224 setProperty(L"Body", element);
226 if (element = getVObjectPropertyValue(vo, L"CATEGORIES")) {
227 setProperty(L"Categories", element);
229 if (element = getVObjectPropertyValue(vo, L"X-FUNAMBOL-FOLDER")) {
230 setProperty(L"Folder", element);
235 // ---- Other Funambol defined properties ----
236 // Support for other fields that don't have a
237 // specific correspondence in vNote.
238 if (element = getVObjectPropertyValue(vo, L"X-FUNAMBOL-COLOR")) {
241 for (i=0; i<NUM_NOTE_COLOR; i++) {
242 if (!wcscmp(colorName[i], element)) { break; }
244 if (i == NUM_NOTE_COLOR) {
245 i = 1; // Default = yellow
247 wsprintf(tmp, TEXT("%i"), i);
248 setProperty(L"Color", tmp);
251 if (element = getVObjectPropertyValue(vo, L"X-FUNAMBOL-POSITION")) {
252 VProperty* vp = vo->getProperty(TEXT("X-FUNAMBOL-POSITION"));
253 element = vp->getPropComponent(1);
254 if (element && wcslen(element)>0) { setProperty(L"Top", element); }
255 element = vp->getPropComponent(2);
256 if (element && wcslen(element)>0) { setProperty(L"Left", element); }
257 element = vp->getPropComponent(3);
258 if (element && wcslen(element)>0) { setProperty(L"Height", element); }
259 element = vp->getPropComponent(4);
260 if (element && wcslen(element)>0) { setProperty(L"Width", element); }
267 // Utility to check the productID and version of VObject passed.
268 bool WinNote::checkVNoteTypeAndVersion(VObject* vo) {
270 WCHAR* prodID = vo->getProdID();
271 WCHAR* version = vo->getVersion();
274 LOG.error(ERR_ITEM_VOBJ_TYPE_NOTFOUND, L"VNOTE");
277 if (wcscmp(prodID, L"VNOTE")) {
278 LOG.error(ERR_ITEM_VOBJ_WRONG_TYPE, prodID, L"VNOTE");
283 // Just log a warning...
284 LOG.info(INFO_ITEM_VOBJ_VERSION_NOTFOUND, VNOTE_VERSION);
286 else if (wcscmp(version, VNOTE_VERSION)) {
287 // Just log a warning...
288 LOG.info(INFO_ITEM_VOBJ_WRONG_VERSION, version, VNOTE_VERSION);