|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <eikenv.h> |
|
22 |
|
23 #include "ImageEditorPluginStorage.h" |
|
24 #include "PluginInfo.h" |
|
25 |
|
26 //============================================================================= |
|
27 CPluginStorage * CPluginStorage::NewL () |
|
28 { |
|
29 CPluginStorage * self = new (ELeave) CPluginStorage; |
|
30 CleanupStack::PushL (self); |
|
31 self->ConstructL (); |
|
32 CleanupStack::Pop (); // self |
|
33 return self; |
|
34 } |
|
35 |
|
36 //============================================================================= |
|
37 CPluginStorage::~CPluginStorage () |
|
38 { |
|
39 iPlugins.ResetAndDestroy(); |
|
40 } |
|
41 |
|
42 //============================================================================= |
|
43 TInt CPluginStorage::CountPlugins() const |
|
44 { |
|
45 return iPlugins.Count(); |
|
46 } |
|
47 |
|
48 //============================================================================= |
|
49 void CPluginStorage::ResetAndDestroy () |
|
50 { |
|
51 iPlugins.ResetAndDestroy(); |
|
52 } |
|
53 |
|
54 //============================================================================= |
|
55 TInt CPluginStorage::FindPluginDll(const TDesC& aPluginDll, TInt& aPos ) const |
|
56 { |
|
57 for (TInt i = 0, c = iPlugins.Count(); i < c; ++i) |
|
58 { |
|
59 aPos = i; |
|
60 TPtrC plugin = iPlugins[i]->PluginDll()->Des(); |
|
61 if ( plugin.CompareF(aPluginDll) == 0 ) |
|
62 { |
|
63 return 0; |
|
64 } |
|
65 } |
|
66 return KErrNotFound; |
|
67 } |
|
68 |
|
69 //============================================================================= |
|
70 CPluginInfo * CPluginStorage::GetPluginInfo (const TInt aID) |
|
71 { |
|
72 for (TInt i = 0, c = iPlugins.Count(); i < c; ++i) |
|
73 { |
|
74 if (iPlugins[i]->PluginRID() == aID) |
|
75 { |
|
76 return iPlugins[i]; |
|
77 } |
|
78 } |
|
79 return 0; |
|
80 } |
|
81 |
|
82 //============================================================================= |
|
83 CPluginStorage::CPluginStorage () |
|
84 { |
|
85 |
|
86 } |
|
87 |
|
88 //============================================================================= |
|
89 void CPluginStorage::ConstructL () |
|
90 { |
|
91 LOG(KImageEditorLogFile,"CPluginStorage: Storage created"); |
|
92 } |
|
93 |
|
94 //============================================================================= |
|
95 void CPluginStorage::AddPluginInfoL (const CPluginInfo * aPluginInfo) |
|
96 { |
|
97 // Add plug-in to storage |
|
98 TLinearOrder<CPluginInfo> order (CPluginInfo::ComparePluginOrder); |
|
99 iPlugins.InsertInOrderAllowRepeats (aPluginInfo, order); |
|
100 } |
|
101 |
|
102 //============================================================================= |
|
103 void CPluginStorage::InternalizeL ( RReadStream& aStream ) |
|
104 { |
|
105 LOG(KImageEditorLogFile,"CPluginStorage::InternalizeL"); |
|
106 |
|
107 TRAPD ( err, |
|
108 |
|
109 // Internalize the contents of iPlugins |
|
110 TInt count = aStream.ReadInt32L(); |
|
111 for ( TInt i=0; i<count; i++ ) |
|
112 { |
|
113 CPluginInfo* info = CPluginInfo::NewLC(); |
|
114 aStream >> *info; |
|
115 User::LeaveIfError( iPlugins.Append( info ) ); |
|
116 CleanupStack::Pop( info ); |
|
117 } |
|
118 ); |
|
119 |
|
120 if (err) |
|
121 { |
|
122 LOGFMT(KImageEditorLogFile, "CPluginLocator: Internalize failed: %d", err); |
|
123 iPlugins.ResetAndDestroy(); |
|
124 } |
|
125 } |
|
126 |
|
127 //============================================================================= |
|
128 void CPluginStorage::ExternalizeL ( RWriteStream& aStream ) const |
|
129 { |
|
130 LOG(KImageEditorLogFile,"CPluginStorage::ExternalizeL"); |
|
131 |
|
132 TRAPD ( err, |
|
133 |
|
134 // Externalize the contents of iPlugins |
|
135 aStream.WriteInt32L( iPlugins.Count() ); |
|
136 for ( TInt i=0; i< iPlugins.Count(); i++ ) |
|
137 { |
|
138 CPluginInfo* info = iPlugins[i]; |
|
139 aStream << *info; |
|
140 } |
|
141 ); |
|
142 |
|
143 if (err) |
|
144 { |
|
145 LOGFMT(KImageEditorLogFile, "CPluginLocator: Externalize failed: %d", err); |
|
146 } |
|
147 } |
|
148 |
|
149 // End of File |