|
1 /* |
|
2 * Copyright (c) 2006 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: Contains CNcdNodeActivate class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <bamdesca.h> |
|
20 |
|
21 #include "ncdnodeactivateimpl.h" |
|
22 #include "ncdnodemetadataproxy.h" |
|
23 #include "ncdnodeinstallproxy.h" |
|
24 #include "ncdnodeidentifier.h" |
|
25 #include "catalogsinterfaceidentifier.h" |
|
26 #include "ncddeviceinteractionfactory.h" |
|
27 #include "ncddeviceservice.h" |
|
28 #include "catalogsutils.h" |
|
29 #include "catalogsdebug.h" |
|
30 #include "ncdinstalledtheme.h" |
|
31 #include "ncdinstalledfile.h" |
|
32 #include "ncdinstalledcontent.h" |
|
33 |
|
34 |
|
35 CNcdNodeActivate::CNcdNodeActivate( CNcdNodeMetadataProxy& aMetadata ) |
|
36 : CCatalogsInterfaceBase( &aMetadata ), |
|
37 iMetadata( aMetadata ) |
|
38 { |
|
39 } |
|
40 |
|
41 |
|
42 void CNcdNodeActivate::ConstructL() |
|
43 { |
|
44 // Register the interface |
|
45 MNcdNodeActivate* interface( this ); |
|
46 AddInterfaceL( |
|
47 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeActivate::KInterfaceUid ) ); |
|
48 } |
|
49 |
|
50 |
|
51 CNcdNodeActivate* CNcdNodeActivate::NewL( CNcdNodeMetadataProxy& aMetadata ) |
|
52 { |
|
53 CNcdNodeActivate* self = |
|
54 CNcdNodeActivate::NewLC( aMetadata ); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 CNcdNodeActivate* CNcdNodeActivate::NewLC( CNcdNodeMetadataProxy& aMetadata ) |
|
60 { |
|
61 CNcdNodeActivate* self = |
|
62 new( ELeave ) CNcdNodeActivate( aMetadata ); |
|
63 // Using PushL because the object does not have any references yet |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 CNcdNodeActivate::~CNcdNodeActivate() |
|
71 { |
|
72 DLTRACEIN(("this-ptr: %x", this)); |
|
73 // Remove interfaces implemented by this class from the interface list. |
|
74 // So, the interface list is up to date when this class object is deleted. |
|
75 RemoveInterface( MNcdNodeActivate::KInterfaceUid ); |
|
76 |
|
77 |
|
78 // Delete member variables here |
|
79 // Do not delete node and operation manager because |
|
80 // this object does not own them. |
|
81 DLTRACEOUT(("this-ptr: %x", this)); |
|
82 } |
|
83 |
|
84 |
|
85 CNcdNodeMetadataProxy& CNcdNodeActivate::Metadata() const |
|
86 { |
|
87 return iMetadata; |
|
88 } |
|
89 |
|
90 |
|
91 // MNcdNodeActivate functions |
|
92 |
|
93 void CNcdNodeActivate::ActivateL() |
|
94 { |
|
95 DLTRACEIN(("")); |
|
96 |
|
97 // Note that ownership is not transferred here. |
|
98 // So, do not add to the cleanup stack. |
|
99 // When the items have been installed, they may be activated. |
|
100 // Install proxy contains theme name and file information that |
|
101 // can be used to activate items. |
|
102 CNcdNodeInstallProxy* install( Metadata().Install() ); |
|
103 |
|
104 if ( install != NULL && install->IsInstalledL() ) |
|
105 { |
|
106 // Create the service that can handle activations |
|
107 MNcdDeviceService* service( |
|
108 NcdDeviceInteractionFactory::CreateDeviceServiceLC() ); |
|
109 |
|
110 if ( service == NULL ) |
|
111 { |
|
112 DLERROR(("Could not create service for active interface")); |
|
113 |
|
114 // For debugging purposes |
|
115 DASSERT( EFalse ); |
|
116 |
|
117 User::Leave( KErrNotFound ); |
|
118 } |
|
119 |
|
120 // Now we have the install interface to use and to check if some |
|
121 // of its material could be activated. Activation may be done |
|
122 // after the item has been installed. |
|
123 |
|
124 |
|
125 // NOTICE: If you add or remove functionality here, |
|
126 // then remember to update the CNcdNodeProxy::InternalizeActivateL() |
|
127 // function accordingly. So, the MNcdNodeActivate interface can be |
|
128 // provided from the API in correct situations. |
|
129 |
|
130 RCatalogsArray<MNcdInstalledContent> content( install->InstalledContentL() ); |
|
131 CleanupResetAndDestroyPushL( content ); |
|
132 |
|
133 TBool setSomething = EFalse; |
|
134 for ( TInt i = 0; i < content.Count(); ++i ) |
|
135 { |
|
136 MNcdInstalledTheme* theme = content[i]->QueryInterfaceLC<MNcdInstalledTheme>(); |
|
137 if ( theme ) |
|
138 { |
|
139 SetThemeL( *theme, *service ); |
|
140 setSomething = ETrue; |
|
141 CleanupStack::PopAndDestroy( theme ); |
|
142 break; |
|
143 } |
|
144 |
|
145 MNcdInstalledFile* file = content[i]->QueryInterfaceLC<MNcdInstalledFile>(); |
|
146 if ( file ) |
|
147 { |
|
148 SetContentFileL( *file, *install, *service ); |
|
149 setSomething = ETrue; |
|
150 CleanupStack::PopAndDestroy( file ); |
|
151 break; |
|
152 } |
|
153 } |
|
154 |
|
155 CleanupStack::PopAndDestroy( &content ); |
|
156 |
|
157 if ( !setSomething ) |
|
158 { |
|
159 User::Leave( KErrNotFound ); |
|
160 } |
|
161 |
|
162 |
|
163 CleanupStack::PopAndDestroy( service ); |
|
164 } |
|
165 |
|
166 DLTRACEOUT(("")); |
|
167 } |
|
168 |
|
169 |
|
170 // Other functions |
|
171 |
|
172 void CNcdNodeActivate::SetThemeL( MNcdInstalledTheme& aTheme, |
|
173 MNcdDeviceService& aService ) |
|
174 { |
|
175 DLTRACEIN(("")); |
|
176 aService.SetAsThemeL( aTheme.Theme() ); |
|
177 } |
|
178 |
|
179 |
|
180 void CNcdNodeActivate::SetContentFileL( MNcdInstalledFile& aFile, |
|
181 CNcdNodeInstallProxy& aInstall, |
|
182 MNcdDeviceService& aService ) |
|
183 { |
|
184 DLTRACEIN(("")); |
|
185 RBuf fileName; |
|
186 fileName.CreateL( KMaxFileName ); |
|
187 CleanupClosePushL( fileName ); |
|
188 |
|
189 // Get the file handle to the file that will be activated. |
|
190 RFile file = aFile.OpenFileL(); |
|
191 CleanupClosePushL( file ); |
|
192 |
|
193 // Get the filename from the handle. |
|
194 // The name will be used for the activation |
|
195 file.FullName( fileName ); |
|
196 CleanupStack::PopAndDestroy( &file ); |
|
197 |
|
198 if ( aInstall.IsPurpose( ENcdItemPurposeRingtone ) ) |
|
199 { |
|
200 aService.SetAsRingingToneL( fileName ); |
|
201 } |
|
202 else if( aInstall.IsPurpose( ENcdItemPurposeWallpaper ) ) |
|
203 { |
|
204 aService.SetAsWallpaperL( fileName ); |
|
205 } |
|
206 else |
|
207 { |
|
208 User::Leave( KErrNotSupported ); |
|
209 } |
|
210 CleanupStack::PopAndDestroy ( &fileName ); |
|
211 DLTRACEOUT(("All is well")); |
|
212 } |
|
213 |
|
214 |