|
1 /* |
|
2 * Copyright (c) 2003 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 the License "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: |
|
15 * Entry point and main function for Bookmark Dump utility application. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <bacline.h> |
|
24 #include <FavouritesDb.h> |
|
25 #include <FavouritesLimits.h> |
|
26 #include <FavouritesItemList.h> |
|
27 #include "UnicodeFile.h" |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 /// Formatting buffer size. Longest data is URL (plus format stuff). |
|
32 LOCAL_D const TInt KFormatBufLen = KFavouritesMaxUrl + 20; |
|
33 |
|
34 // ================= LOCAL FUNCTIONS ======================= |
|
35 |
|
36 /** |
|
37 * Main function. Process command line arguments and import bookmark data. |
|
38 */ |
|
39 LOCAL_D void MainL() |
|
40 { |
|
41 TBuf<KFormatBufLen> buf; |
|
42 TInt num; |
|
43 CCommandLineArguments* args = CCommandLineArguments::NewLC(); |
|
44 if( args->Count() != 2 ) |
|
45 { |
|
46 // Expecting command line 'Appname outfile'. |
|
47 User::Leave( KErrArgument ); |
|
48 } |
|
49 RFs fs; |
|
50 User::LeaveIfError( fs.Connect() ); |
|
51 CleanupClosePushL<RFs>( fs ); |
|
52 RUnicodeFile file; |
|
53 User::LeaveIfError( file.ReplaceL |
|
54 ( fs, args->Arg( 1 ), EFileWrite | EFileShareExclusive ) ); |
|
55 CleanupClosePushL<RUnicodeFile>( file ); |
|
56 RFavouritesSession sess; |
|
57 User::LeaveIfError( sess.Connect() ); |
|
58 CleanupClosePushL<RFavouritesSession>( sess ); |
|
59 RFavouritesDb db; |
|
60 User::LeaveIfError( db.Open( sess, KBrowserBookmarks ) ); |
|
61 CleanupClosePushL<RFavouritesDb>( db ); |
|
62 User::LeaveIfError( db.Begin( /*aWrite=*/EFalse ) ); |
|
63 db.CleanupRollbackPushL(); |
|
64 |
|
65 CFavouritesItemList* items = new (ELeave) CFavouritesItemList(); |
|
66 CleanupStack::PushL( items ); |
|
67 const CFavouritesItem* item; |
|
68 User::LeaveIfError( db.GetAll( *items ) ); |
|
69 buf.Format( _L("%d entries\r\n"), items->Count() ); |
|
70 User::LeaveIfError( file.Write( buf ) ); |
|
71 for ( TInt i = 0; i < items->Count(); i++ ) |
|
72 { |
|
73 User::LeaveIfError( file.Write( _L("\r\n") ) ); |
|
74 item = items->At( i ); |
|
75 // Uid. |
|
76 num = item->Uid(); |
|
77 buf.Format( _L("Uid=(%d)"), num ); |
|
78 User::LeaveIfError( file.Write( buf ) ); |
|
79 // Fixed Uid info. |
|
80 if ( num == KFavouritesRootUid ) |
|
81 { |
|
82 User::LeaveIfError( file.Write( _L(" (root folder)\r\n") ) ); |
|
83 } |
|
84 else if ( num == KFavouritesHomepageUid ) |
|
85 { |
|
86 User::LeaveIfError( file.Write( _L(" (homepage)\r\n") ) ); |
|
87 } |
|
88 else if ( num == KFavouritesLastVisitedUid ) |
|
89 { |
|
90 User::LeaveIfError( file.Write( _L(" (last visited)\r\n") ) ); |
|
91 } |
|
92 else |
|
93 { |
|
94 User::LeaveIfError( file.Write( _L("\r\n") ) ); |
|
95 } |
|
96 // Type. |
|
97 if ( item->Type() == CFavouritesItem::EFolder ) |
|
98 { |
|
99 User::LeaveIfError( file.Write( _L("Type=Folder\r\n") ) ); |
|
100 } |
|
101 else if ( item->Type() == CFavouritesItem::EItem ) |
|
102 { |
|
103 User::LeaveIfError( file.Write( _L("Type=Item\r\n") ) ); |
|
104 } |
|
105 else |
|
106 { |
|
107 User::LeaveIfError( file.Write( _L("Type=HUH???\r\n") ) ); |
|
108 } |
|
109 TPtrC ptr; |
|
110 // Name |
|
111 ptr.Set( item->Name() ); |
|
112 buf.Format( _L("Name=<%S>\r\n"), &ptr ); |
|
113 User::LeaveIfError( file.Write( buf ) ); |
|
114 // Parent. |
|
115 buf.Format( _L("ParentFolder=(%d)\r\n"), item->ParentFolder() ); |
|
116 User::LeaveIfError( file.Write( buf ) ); |
|
117 // Url. |
|
118 ptr.Set( item->Url() ); |
|
119 buf.Format( _L("Url=<%S>\r\n"), &ptr ); |
|
120 User::LeaveIfError( file.Write( buf ) ); |
|
121 // Access Point. |
|
122 if ( item->WapAp().IsNull() ) |
|
123 { |
|
124 User::LeaveIfError( file.Write( _L("WapAp=Null\r\n") ) ); |
|
125 } |
|
126 else if ( item->WapAp().IsDefault() ) |
|
127 { |
|
128 User::LeaveIfError( file.Write( _L("WapAp=Default\r\n") ) ); |
|
129 } |
|
130 else |
|
131 { |
|
132 buf.Format( _L("WapAp=(%d)\r\n"), item->WapAp().ApId() ); |
|
133 User::LeaveIfError( file.Write( buf ) ); |
|
134 } |
|
135 // UserName. |
|
136 ptr.Set( item->UserName() ); |
|
137 buf.Format( _L("UserName=<%S>\r\n"), &ptr ); |
|
138 User::LeaveIfError( file.Write( buf ) ); |
|
139 // Password. |
|
140 ptr.Set( item->Password() ); |
|
141 buf.Format( _L("Password=<%S>\r\n"), &ptr ); |
|
142 User::LeaveIfError( file.Write( buf ) ); |
|
143 // Read-only. |
|
144 buf.Format( _L("ReadOnly=(%d)\r\n"), item->IsReadOnly() ); |
|
145 User::LeaveIfError( file.Write( buf ) ); |
|
146 // Factory item. |
|
147 buf.Format( _L("FactoryItem=(%d)\r\n"), item->IsFactoryItem() ); |
|
148 User::LeaveIfError( file.Write( buf ) ); |
|
149 // ContextId. |
|
150 buf.Format( _L("ContextId=(0x%x)\r\n"), item->ContextId() ); |
|
151 User::LeaveIfError( file.Write( buf ) ); |
|
152 // Modified. |
|
153 item->Modified().FormatL |
|
154 ( buf, _L("Modified=<%F%Y/%M/%D %H:%T:%S>\r\n") ); |
|
155 User::LeaveIfError( file.Write( buf ) ); |
|
156 // Preferred uid. |
|
157 if ( item->Type() == CFavouritesItem::EFolder ) |
|
158 { |
|
159 User::LeaveIfError( db.PreferredUid( item->Uid(), num ) ); |
|
160 buf.Format( _L("PreferredUid=(%d)\r\n"), num ); |
|
161 User::LeaveIfError( file.Write( buf ) ); |
|
162 } |
|
163 } |
|
164 CleanupStack::PopAndDestroy(); // items |
|
165 |
|
166 User::LeaveIfError( db.Commit() ); |
|
167 CleanupStack::Pop(); // Pop the rollback |
|
168 |
|
169 CleanupStack::PopAndDestroy( 5 ); // sess, db, file, fs, args |
|
170 } |
|
171 |
|
172 /** |
|
173 * Entry point to the application. |
|
174 * @return Error code. |
|
175 */ |
|
176 GLDEF_C TInt E32Main() |
|
177 { |
|
178 TInt err = KErrNone; |
|
179 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
180 if ( trapCleanup ) |
|
181 { |
|
182 TRAP( err, MainL() ); |
|
183 delete trapCleanup; |
|
184 } |
|
185 else |
|
186 { |
|
187 err = KErrNoMemory; |
|
188 } |
|
189 return err; |
|
190 } |