40
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Conversion utility
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <feedsserverfolderitem.h>
|
|
19 |
#include "conversionutil.h"
|
|
20 |
#include "omadsfolderobject.h"
|
|
21 |
#include "vbookmarkconverter.h"
|
|
22 |
#include "logger.h"
|
|
23 |
|
|
24 |
|
|
25 |
// -----------------------------------------------------------------------------
|
|
26 |
// NewL
|
|
27 |
// Creates the object
|
|
28 |
// -----------------------------------------------------------------------------
|
|
29 |
CBookmarkConversionUtil* CBookmarkConversionUtil::NewL()
|
|
30 |
{
|
|
31 |
CBookmarkConversionUtil* self = CBookmarkConversionUtil::NewLC();
|
|
32 |
CleanupStack::Pop(self);
|
|
33 |
return self;
|
|
34 |
}
|
|
35 |
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
// NewLC
|
|
38 |
// Creates the object and leaves it into the cleanup stack
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
CBookmarkConversionUtil* CBookmarkConversionUtil::NewLC()
|
|
41 |
{
|
|
42 |
CBookmarkConversionUtil* self = new ( ELeave ) CBookmarkConversionUtil();
|
|
43 |
CleanupStack::PushL( self );
|
|
44 |
self->ConstructL();
|
|
45 |
return self;
|
|
46 |
}
|
|
47 |
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
// ConstructL
|
|
50 |
// 2nd phase constructor
|
|
51 |
// -----------------------------------------------------------------------------
|
|
52 |
void CBookmarkConversionUtil::ConstructL()
|
|
53 |
{
|
|
54 |
// Create OMA DS folder object converter
|
|
55 |
iOmaConverter = COMADSFolderObject::NewL();
|
|
56 |
|
|
57 |
// Create vBookmark converter
|
|
58 |
iVBookmarkConverter = CVBookmarkConverter::NewL();
|
|
59 |
}
|
|
60 |
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
// ~CBookmarkConversionUtil
|
|
63 |
// Destroys all allocated resources
|
|
64 |
// -----------------------------------------------------------------------------
|
|
65 |
CBookmarkConversionUtil::~CBookmarkConversionUtil()
|
|
66 |
{
|
|
67 |
delete iOmaConverter;
|
|
68 |
iOmaConverter = NULL;
|
|
69 |
|
|
70 |
delete iVBookmarkConverter;
|
|
71 |
iVBookmarkConverter = NULL;
|
|
72 |
}
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
// -----------------------------------------------------------------------------
|
|
77 |
// FavouritesItemToBufferL
|
|
78 |
// Converts CFavouritesItem to it's binary sync representation
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
void CBookmarkConversionUtil::FavouritesItemToBufferL(
|
|
81 |
const CFavouritesItem& aItem, CBufFlat& aBuffer)
|
|
82 |
{
|
|
83 |
LOGGER_ENTERFN( "CBookmarkConversionUtil::FavouritesItemToBufferL" );
|
|
84 |
|
|
85 |
if( aItem.Type() == CFavouritesItem::EFolder )
|
|
86 |
{
|
|
87 |
// Set input data
|
|
88 |
iOmaConverter->ImportDbItem(aItem);
|
|
89 |
|
|
90 |
// Export to buffer
|
|
91 |
iOmaConverter->ExportFolderXmlL(aBuffer);
|
|
92 |
}
|
|
93 |
else if( aItem.Type() == CFavouritesItem::EItem )
|
|
94 |
{
|
|
95 |
// Set input data
|
|
96 |
iVBookmarkConverter->ImportDbItemL(aItem);
|
|
97 |
|
|
98 |
// Export to buffer
|
|
99 |
iVBookmarkConverter->ExportVBookmarkL(aBuffer);
|
|
100 |
}
|
|
101 |
else
|
|
102 |
{
|
|
103 |
User::Leave( KErrNotSupported );
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
// -----------------------------------------------------------------------------
|
|
108 |
// RssItemToBufferL
|
|
109 |
// Converts CFolderItem to it's binary sync representation
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
void CBookmarkConversionUtil::RssItemToBufferL(
|
|
112 |
const CFolderItem& aItem, CBufFlat& aBuffer)
|
|
113 |
{
|
|
114 |
LOGGER_ENTERFN( "CBookmarkConversionUtil::RssItemToBufferL" );
|
|
115 |
|
|
116 |
if( aItem.IsFolder() )
|
|
117 |
{
|
|
118 |
// Set input data
|
|
119 |
iOmaConverter->ImportDbItem(aItem);
|
|
120 |
|
|
121 |
// Export to buffer
|
|
122 |
iOmaConverter->ExportFolderXmlL(aBuffer);
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
// Set input data
|
|
127 |
iVBookmarkConverter->ImportDbItemL(aItem);
|
|
128 |
|
|
129 |
// Export to buffer
|
|
130 |
iVBookmarkConverter->ExportVBookmarkL(aBuffer);
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
// -----------------------------------------------------------------------------
|
|
135 |
// BufferToFavouritesItemL
|
|
136 |
// Converts Binary data to CFavouritesItem
|
|
137 |
// -----------------------------------------------------------------------------
|
|
138 |
TInt CBookmarkConversionUtil::BufferToFavouritesItemL(CFavouritesItem::TType aType,
|
|
139 |
CBufFlat& aBuffer, CFavouritesItem& aItem)
|
|
140 |
{
|
|
141 |
LOGGER_ENTERFN( "CBookmarkConversionUtil::BufferToFavouritesItemL" );
|
|
142 |
|
|
143 |
if ( aType == CFavouritesItem::EFolder )
|
|
144 |
{
|
|
145 |
// Import XML data
|
|
146 |
TInt error = iOmaConverter->ImportFolderXml( aBuffer.Ptr( 0 ) );
|
|
147 |
|
|
148 |
// Convert to CFavouritesItem
|
|
149 |
if ( error == KErrNone )
|
|
150 |
{
|
|
151 |
iOmaConverter->ExportDbItemL( aItem );
|
|
152 |
}
|
|
153 |
|
|
154 |
return error;
|
|
155 |
}
|
|
156 |
else if ( aType == CFavouritesItem::EItem )
|
|
157 |
{
|
|
158 |
// Import vBookmark data
|
|
159 |
TInt error = iVBookmarkConverter->ImportVBookmarkL( aBuffer.Ptr( 0 ) );
|
|
160 |
|
|
161 |
// Convert to CFavouritesItem
|
|
162 |
if ( error == KErrNone )
|
|
163 |
{
|
|
164 |
iVBookmarkConverter->ExportDbItemL( aItem );
|
|
165 |
}
|
|
166 |
|
|
167 |
return error;
|
|
168 |
}
|
|
169 |
else
|
|
170 |
{
|
|
171 |
return KErrNotSupported;
|
|
172 |
}
|
|
173 |
}
|