|
1 /* |
|
2 * Copyright (c) 2003-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: Disk service utility for Psln. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 // General. |
|
22 #include <coemain.h> |
|
23 #include <DRMHelper.h> |
|
24 #include <DRMRights.h> |
|
25 #include <AknsSrvClient.h> |
|
26 #include <pathinfo.h> |
|
27 #include <caf/manager.h> |
|
28 |
|
29 // Psln specific. |
|
30 #include "PslnDiskUtil.h" |
|
31 #include "PslnFeatures.h" |
|
32 #include "PslnConst.h" |
|
33 #include "PslnDebug.h" |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // PslnDiskUtil::MmcStatus |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 TInt PslnDiskUtil::MmcStatus() |
|
42 { |
|
43 PSLN_TRACE_DEBUG("PslnDiskUtil::MmcStatus"); |
|
44 if( !PslnFeatures::IsMMCSupported() ) |
|
45 { |
|
46 PSLN_TRACE_DEBUG("PslnDiskUtil::MmcStatus Not Supported"); |
|
47 return KErrNotSupported; |
|
48 } |
|
49 |
|
50 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
51 |
|
52 TInt error = KErrNone; |
|
53 TDriveInfo driveInfo; |
|
54 TInt res = 0; |
|
55 fs.CharToDrive( PathInfo::MemoryCardRootPath()[0], res ); |
|
56 error = fs.Drive( driveInfo, res ); |
|
57 if( error ) |
|
58 { |
|
59 PSLN_TRACE_DEBUG1("PslnDiskUtil::MmcStatus Error=%d", error ); |
|
60 return error; |
|
61 } |
|
62 |
|
63 // MMC is locked |
|
64 if( driveInfo.iMediaAtt & KMediaAttLocked ) |
|
65 { |
|
66 PSLN_TRACE_DEBUG("PslnDiskUtil::MmcStatus Locked"); |
|
67 return KErrLocked; |
|
68 } |
|
69 |
|
70 // MMC is not present or of unknown type |
|
71 if ( driveInfo.iType == EMediaNotPresent || |
|
72 driveInfo.iType == EMediaUnknown ) |
|
73 { |
|
74 PSLN_TRACE_DEBUG("PslnDiskUtil::MmcStatus Not present"); |
|
75 return KErrNotFound; |
|
76 } |
|
77 |
|
78 if( driveInfo.iMediaAtt & KMediaAttWriteProtected ) |
|
79 { |
|
80 PSLN_TRACE_DEBUG("PslnDiskUtil::MmcStatus Read Only"); |
|
81 return KPslnDiskUtilReadOnly; |
|
82 } |
|
83 PSLN_TRACE_DEBUG("PslnDiskUtil::MmcStatus Ok"); |
|
84 return KErrNone; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // PslnDiskUtil::QueryAndSetAutomatedL |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 TBool PslnDiskUtil::QueryAndSetAutomatedL( |
|
92 RAknsSrvSession& aSkinSrvSession, const TDesC& aFileName) |
|
93 { |
|
94 PSLN_TRACE_DEBUG("PslnDiskUtil::QueryAndSetAutomatedL"); |
|
95 |
|
96 TBool isProtected = EFalse; |
|
97 TInt value = KErrNone; |
|
98 |
|
99 TInt fileserverhandle; |
|
100 TInt filehandle; |
|
101 fileserverhandle = aSkinSrvSession.OpenBitmapFile( aFileName, filehandle ); |
|
102 RFile file; |
|
103 User::LeaveIfError( file.AdoptFromServer( fileserverhandle, filehandle ) ); |
|
104 CleanupClosePushL( file ); |
|
105 |
|
106 CContent* content = CContent::NewLC( file ); |
|
107 User::LeaveIfError( content->GetAttribute( EIsProtected, value ) ); |
|
108 if ( value ) |
|
109 { |
|
110 isProtected = ETrue; |
|
111 } |
|
112 CleanupStack::PopAndDestroy( content ); |
|
113 |
|
114 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL prot=%d", isProtected ); |
|
115 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL value=%d", value ); |
|
116 |
|
117 TBool set = ETrue; |
|
118 if ( isProtected ) |
|
119 { |
|
120 CDRMHelper* helper = CDRMHelper::NewLC(); |
|
121 CDRMHelperRightsConstraints* playconst = NULL; |
|
122 CDRMHelperRightsConstraints* dispconst = NULL; |
|
123 CDRMHelperRightsConstraints* execconst = NULL; |
|
124 CDRMHelperRightsConstraints* printconst = NULL; |
|
125 TBool expired = EFalse; |
|
126 TBool sendingallowed = EFalse; |
|
127 helper->GetRightsDetailsL( |
|
128 file, |
|
129 CDRMRights::EDisplay, |
|
130 expired, |
|
131 sendingallowed, |
|
132 playconst, |
|
133 dispconst, |
|
134 execconst, |
|
135 printconst ); |
|
136 delete playconst; |
|
137 delete execconst; |
|
138 delete printconst; |
|
139 CleanupStack::PushL( dispconst ); |
|
140 |
|
141 // Talkin' 'bout themes here |
|
142 helper->SetAutomatedType( CDRMHelper::EAutomatedTypeTheme ); |
|
143 |
|
144 if ( dispconst && dispconst->FullRights() ) |
|
145 { |
|
146 set = ETrue; |
|
147 // Set the Fullrights content as automated also |
|
148 // and ignore the result.... |
|
149 helper->SetAutomated( file ); |
|
150 } |
|
151 else |
|
152 { |
|
153 TInt res = KErrNone; |
|
154 res = helper->SetAutomated( file ); |
|
155 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL res=%d", res ); |
|
156 |
|
157 if ( res == KErrCancel ) |
|
158 { |
|
159 set = EFalse; |
|
160 } |
|
161 else |
|
162 { |
|
163 User::LeaveIfError( res ); |
|
164 TInt err = helper->ConsumeFile2( file, CDRMRights::EPlay, CDRMHelper::EStart ); |
|
165 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL 1 err=%d", err ); |
|
166 err = helper->ConsumeFile2( file, CDRMRights::EPlay, CDRMHelper::EFinish ); |
|
167 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL 2 err=%d", err ); |
|
168 err = helper->ConsumeFile2( file, CDRMRights::EDisplay, CDRMHelper::EStart ); |
|
169 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL 3 err=%d", err ); |
|
170 err = helper->ConsumeFile2( file, CDRMRights::EDisplay, CDRMHelper::EFinish ); |
|
171 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL 4 err=%d", err ); |
|
172 err = helper->ConsumeFile2( file, CDRMRights::EExecute, CDRMHelper::EStart ); |
|
173 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL 5 err=%d", err ); |
|
174 err = helper->ConsumeFile2( file, CDRMRights::EExecute, CDRMHelper::EFinish ); |
|
175 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL 6 err=%d", err ); |
|
176 set = ETrue; |
|
177 } |
|
178 } |
|
179 CleanupStack::PopAndDestroy( 2, helper ); |
|
180 } |
|
181 CleanupStack:: PopAndDestroy(); // file |
|
182 PSLN_TRACE_DEBUG1("PslnDiskUtil::QueryAndSetAutomatedL set=%d", (TInt) set ); |
|
183 return set; |
|
184 } |
|
185 |
|
186 // End of File |