|
1 /* |
|
2 * Copyright (c) 2003-2009 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: DRM Encryption tool. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "drmencryptor.h" |
|
19 //#include "ui_dialog.h" |
|
20 #include <QMessageBox> |
|
21 #include <QDoubleValidator> |
|
22 #include <QMenu> |
|
23 #include <QHBoxLayout> |
|
24 #include <QString> |
|
25 #include <QLabel> |
|
26 #include <QPlainTextEdit> |
|
27 #include <QVBoxLayout> |
|
28 #include <QWidget> |
|
29 #include <QPalette> |
|
30 |
|
31 #ifdef RD_MULTIPLE_DRIVE |
|
32 #include <driveinfo.h> |
|
33 #endif |
|
34 |
|
35 #include <e32std.h> |
|
36 #include <e32base.h> |
|
37 #include <e32cmn.h> |
|
38 |
|
39 #include <Oma1DcfCreator.h> |
|
40 #include <s32file.h> |
|
41 #include <DRMMessageParser.h> |
|
42 #include <DcfRep.h> |
|
43 #include <DcfEntry.h> |
|
44 #include <DRMRights.h> |
|
45 //#include <drmbrowserlauncher.h> |
|
46 |
|
47 #include "drmserviceapi.h" |
|
48 #include "DRMTypes.h" |
|
49 |
|
50 const TInt KBufferSize = 20000; |
|
51 |
|
52 DRMEncryptor::DRMEncryptor() |
|
53 { |
|
54 QWidget *widget = new QWidget(); |
|
55 setCentralWidget(widget); |
|
56 |
|
57 setBackgroundRole( QPalette::Window ); |
|
58 |
|
59 QVBoxLayout *layout = new QVBoxLayout; |
|
60 layout->setAlignment(Qt::AlignCenter); |
|
61 |
|
62 QLabel *mainWindowLabel = new QLabel("DRM Encryptor"); |
|
63 layout->addWidget(mainWindowLabel); |
|
64 |
|
65 //layout->addStretch(); |
|
66 |
|
67 //ui->setupUi(this); |
|
68 //iOptionsMenu = menuBar()->addMenu(tr("&Options")); |
|
69 |
|
70 // Create menu options |
|
71 iSetDRMClockAct = new QAction(tr("&Set DRM Clock"), this); |
|
72 iSetDRMClockAct->setStatusTip(tr("Set DRM secure clock time.")); |
|
73 |
|
74 iGetDRMClockAct = new QAction(tr("&Get DRM Clock Time"), this); |
|
75 iGetDRMClockAct->setStatusTip(tr("Get DRM secure clock time.")); |
|
76 |
|
77 iEncryptAct = new QAction(tr("&Encrypt"), this); |
|
78 iEncryptAct->setStatusTip(tr("Encrypt")); |
|
79 |
|
80 iLaunchBrowserAct = new QAction(tr("&Launch Browser"), this); |
|
81 iLaunchBrowserAct->setStatusTip(tr("Launch Browser")); |
|
82 |
|
83 iDeleteWMDRMDBAct = new QAction(tr("&Delete WMDRM DB"), this); |
|
84 iDeleteWMDRMDBAct->setStatusTip(tr("Delete WMDRM Database rights.")); |
|
85 |
|
86 iDeleteOMADRMDBAct = new QAction(tr("&Delete OMADRM DB"), this); |
|
87 iDeleteOMADRMDBAct->setStatusTip(tr("Delete OMADRM Database rights.")); |
|
88 |
|
89 menuBar()->addAction(iSetDRMClockAct); |
|
90 menuBar()->addAction(iGetDRMClockAct); |
|
91 menuBar()->addAction(iEncryptAct); |
|
92 menuBar()->addAction(iDeleteWMDRMDBAct); |
|
93 menuBar()->addAction(iDeleteOMADRMDBAct); |
|
94 menuBar()->addAction(iLaunchBrowserAct); |
|
95 |
|
96 connect(iSetDRMClockAct, SIGNAL(triggered()), this, SLOT(setDRMClock())); |
|
97 connect(iGetDRMClockAct, SIGNAL(triggered()), this, SLOT(getDRMClock())); |
|
98 connect(iEncryptAct, SIGNAL(triggered()), this, SLOT(startEncrypt())); |
|
99 connect(iDeleteWMDRMDBAct, SIGNAL(triggered()), this, SLOT(deleteWmDrmDB())); |
|
100 connect(iDeleteOMADRMDBAct, SIGNAL(triggered()), this, SLOT(deleteOmaDrmDB())); |
|
101 connect(iLaunchBrowserAct, SIGNAL(triggered()), this, SLOT(launchBrowser())); |
|
102 |
|
103 //setDRMClockButton = new QPushButton("Set DRM Clock", this); |
|
104 //connect(setDRMClockButton, SIGNAL(clicked()), this, SLOT(setDRMClock())); |
|
105 //setDRMClockButton->show(); |
|
106 |
|
107 /* ui->pushButton->setEnabled(false); |
|
108 |
|
109 ui->lineEdit->setValidator(new QDoubleValidator(this)); |
|
110 ui->lineEdit_2->setValidator(new QDoubleValidator(this)); |
|
111 */ |
|
112 //connect(ui->mainMenu,SIGNAL(onChanged()),this,SLOT(onLaske())); |
|
113 //connect(ui->lineEdit,SIGNAL(textChanged(const QString &)),this,SLOT(onTextChanged(const QString &))); |
|
114 //connect(ui->mainMenu,SIGNAL(textChanged(const QString &)),this,SLOT(onTextChanged(const QString &))); |
|
115 |
|
116 widget->setLayout(layout); |
|
117 } |
|
118 |
|
119 DRMEncryptor::~DRMEncryptor() |
|
120 { |
|
121 //delete ui; |
|
122 } |
|
123 |
|
124 void DRMEncryptor::setDRMClock() |
|
125 { |
|
126 DateTimeDialog *dateTimeDialog = new DateTimeDialog(); |
|
127 dateTimeDialog->show(); |
|
128 } |
|
129 |
|
130 void DRMEncryptor::getDRMClock() |
|
131 { |
|
132 TTime time; |
|
133 TInt timeZone; |
|
134 TDateTime date; |
|
135 DRMClock::ESecurityLevel level; |
|
136 TInt error( KErrNone ); |
|
137 TBuf< 80 > buf; |
|
138 |
|
139 DRM::CDrmServiceApi* service = NULL; |
|
140 |
|
141 TRAPD(err, service = DRM::CDrmServiceApi::NewL()); |
|
142 if(err!=KErrNone) |
|
143 { |
|
144 QMessageBox::information(this, tr("DRM Clock"),tr("Error creating CDrmServiceApi.")); |
|
145 buf.AppendNum(error); |
|
146 QString string((QChar*)buf.Ptr(),buf.Length()); |
|
147 QMessageBox::information(this, tr("DRM Clock"),string); |
|
148 delete service; // service |
|
149 return; |
|
150 } |
|
151 |
|
152 error = service->GetSecureTime( time, timeZone, level ); |
|
153 if(!error==KErrNone) |
|
154 { |
|
155 QMessageBox::information(this, tr("DRM Clock"),tr("Error getting secure time.")); |
|
156 |
|
157 buf.AppendNum(error); |
|
158 QString string((QChar*)buf.Ptr(),buf.Length()); |
|
159 QMessageBox::information(this, tr("DRM Clock"),string); |
|
160 delete service; |
|
161 return; |
|
162 } |
|
163 |
|
164 date = time.DateTime(); |
|
165 |
|
166 if(level == DRMClock::KSecure) |
|
167 { |
|
168 _LIT(KFormatTxt,"DRMClock Time:\n%d/%d/%d\n%d:%d:%d\nNitz available"); |
|
169 buf.Format( KFormatTxt, |
|
170 date.Day()+1, |
|
171 TInt(date.Month()+1), |
|
172 date.Year(), |
|
173 date.Hour(), |
|
174 date.Minute(), |
|
175 date.Second()); |
|
176 } |
|
177 else |
|
178 { |
|
179 _LIT(KFormatTxt,"DRMClock Time:\n%d/%d/%d\n%d:%d:%d\nNitz unavailable"); |
|
180 buf.Format( KFormatTxt, |
|
181 date.Day()+1, |
|
182 TInt(date.Month()+1), |
|
183 date.Year(), |
|
184 date.Hour(), |
|
185 date.Minute(), |
|
186 date.Second()); |
|
187 } |
|
188 |
|
189 QGridLayout *layout = new QGridLayout; |
|
190 layout->setAlignment(Qt::AlignCenter); |
|
191 setLayout(layout); |
|
192 |
|
193 |
|
194 QString datetimeString((QChar*)buf.Ptr(),buf.Length()); |
|
195 |
|
196 QMessageBox *drmClockTime = new QMessageBox(this); |
|
197 drmClockTime->setWindowTitle(tr("DRM Clock")); |
|
198 drmClockTime->setText(datetimeString); |
|
199 |
|
200 layout->addWidget(drmClockTime); |
|
201 drmClockTime->show(); |
|
202 |
|
203 } |
|
204 |
|
205 LOCAL_C void ReadFileL(HBufC8*& aContent, const TDesC& aName, RFs& aFs) |
|
206 { |
|
207 TInt size = 0; |
|
208 RFile file; |
|
209 User::LeaveIfError(file.Open(aFs, aName, EFileRead)); |
|
210 User::LeaveIfError(file.Size(size)); |
|
211 aContent = HBufC8::NewLC(size); |
|
212 TPtr8 ptr(aContent->Des()); |
|
213 User::LeaveIfError(file.Read(ptr, size)); |
|
214 CleanupStack::Pop(); //aContent |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------- |
|
218 // UpdateDCFRepositoryL() |
|
219 // Update saved file to DCFRepository |
|
220 // --------------------------------------------------------- |
|
221 // |
|
222 LOCAL_C void UpdateDCFRepositoryL( const TDesC& aFileName) |
|
223 { |
|
224 CDcfEntry* dcf( NULL ); |
|
225 CDcfRep* dcfRep( NULL ); |
|
226 |
|
227 dcf = CDcfEntry::NewL(); |
|
228 CleanupStack::PushL( dcf ); |
|
229 |
|
230 dcfRep = CDcfRep::NewL(); |
|
231 CleanupStack::PushL( dcfRep ); |
|
232 |
|
233 dcf->SetLocationL( aFileName, 0 ); |
|
234 dcfRep->UpdateL( dcf ); |
|
235 |
|
236 CleanupStack::PopAndDestroy(2); // dcf, dcfRep |
|
237 } |
|
238 |
|
239 void ProcessRightsL(const TDesC& aFile) |
|
240 { |
|
241 CDRMMessageParser* c = NULL; |
|
242 HBufC8* d = NULL; |
|
243 RFs fs; |
|
244 RPointerArray<CDRMRights> rights; |
|
245 |
|
246 User::LeaveIfError(fs.Connect()); |
|
247 c = CDRMMessageParser::NewL(); |
|
248 ReadFileL(d, aFile, fs); |
|
249 c->ProcessRightsObject(*d, rights); |
|
250 rights.ResetAndDestroy(); |
|
251 delete d; |
|
252 delete c; |
|
253 fs.Close(); |
|
254 } |
|
255 |
|
256 void DRMEncryptor::ProcessMessageL(const TDesC& aFile, const TDesC& aOutput) |
|
257 { |
|
258 CDRMMessageParser* c = NULL; |
|
259 HBufC8* d = NULL; |
|
260 RFs fs; |
|
261 TPtr8 inRead(NULL, 0); |
|
262 TInt error = 1; |
|
263 __UHEAP_MARK; |
|
264 |
|
265 User::LeaveIfError(fs.Connect()); |
|
266 CleanupClosePushL(fs); |
|
267 c = CDRMMessageParser::NewL(); |
|
268 CleanupStack::PushL(c); |
|
269 |
|
270 d = HBufC8::NewLC( KBufferSize ); |
|
271 |
|
272 RFile input; |
|
273 User::LeaveIfError(input.Open( fs, aFile, EFileRead )); |
|
274 CleanupClosePushL( input ); |
|
275 |
|
276 RFileWriteStream output; |
|
277 output.Replace( fs, aOutput, EFileWrite ); |
|
278 CleanupClosePushL( output ); |
|
279 |
|
280 c->InitializeMessageParserL( output ); |
|
281 |
|
282 while( error ) |
|
283 { |
|
284 inRead.Set( const_cast<TUint8*>(d->Ptr()),0,KBufferSize); |
|
285 error = input.Read( inRead ); |
|
286 |
|
287 if( error ) |
|
288 { |
|
289 c->FinalizeMessageParserL(); |
|
290 |
|
291 User::Leave( error ); |
|
292 } |
|
293 else |
|
294 { |
|
295 error = inRead.Length(); |
|
296 } |
|
297 |
|
298 if( error ) |
|
299 { |
|
300 c->ProcessMessageDataL(inRead); |
|
301 } |
|
302 } |
|
303 |
|
304 c->FinalizeMessageParserL(); |
|
305 |
|
306 |
|
307 CleanupStack::PopAndDestroy( 5 ); // fs, c, d, input, output |
|
308 UpdateDCFRepositoryL( aOutput ); |
|
309 __UHEAP_MARKEND; |
|
310 } |
|
311 |
|
312 void EncryptFileL(const TDesC& aFile, TDesC& aOutput, TInt aMultiplier) |
|
313 { |
|
314 COma1DcfCreator* c = NULL; |
|
315 CDRMRights* rights = NULL; |
|
316 TBuf8<64> mime; |
|
317 RFs fs; |
|
318 TFileName aDcfFile; |
|
319 TInt aOriginalFileNameLength(aOutput.Length() - 4); |
|
320 |
|
321 User::LeaveIfError(fs.Connect()); |
|
322 if (aFile.Right(3).CompareF(_L("amr")) == 0) //AMR |
|
323 { |
|
324 mime.Copy(_L8("audio/amr")); |
|
325 } |
|
326 else if (aFile.Right(3).CompareF(_L("awb")) == 0) //AMR-AWB |
|
327 { |
|
328 mime.Copy(_L8("audio/amr-wb")); |
|
329 } |
|
330 else if (aFile.Right(3).CompareF(_L("mp3")) == 0) //MP3 |
|
331 { |
|
332 mime.Copy(_L8("audio/mpeg")); |
|
333 } |
|
334 else if (aFile.Right(3).CompareF(_L("mp4")) == 0) //MP4 |
|
335 { |
|
336 mime.Copy(_L8("audio/mp4")); |
|
337 } |
|
338 else if (aFile.Right(3).CompareF(_L("m4a")) == 0) //M4A |
|
339 { |
|
340 mime.Copy(_L8("audio/mp4")); |
|
341 } |
|
342 else if (aFile.Right(3).CompareF(_L("3gp")) == 0) //3GPP |
|
343 { |
|
344 mime.Copy(_L8("audio/3gpp")); |
|
345 } |
|
346 else if (aFile.Right(3).CompareF(_L("3g2")) == 0) //3GPP2 |
|
347 { |
|
348 mime.Copy(_L8("audio/3gpp2")); |
|
349 } |
|
350 else if (aFile.Right(3).CompareF(_L("aac")) == 0) //AAC |
|
351 { |
|
352 mime.Copy(_L8("audio/aac")); |
|
353 } |
|
354 else if (aFile.Right(3).CompareF(_L("mid")) == 0) //MIDI |
|
355 { |
|
356 mime.Copy(_L8("audio/midi")); |
|
357 } |
|
358 else if (aFile.Right(5).CompareF(_L(".spmid")) == 0) //SP-MIDI |
|
359 { |
|
360 mime.Copy(_L8("audio/sp-midi")); |
|
361 } |
|
362 else if (aFile.Right(3).CompareF(_L("rmf")) == 0) //RMF |
|
363 { |
|
364 mime.Copy(_L8("audio/rmf")); |
|
365 } |
|
366 else if (aFile.Right(4).CompareF(_L("mxmf")) == 0) //Mobile-XMF |
|
367 { |
|
368 mime.Copy(_L8("audio/mobile-xmf")); |
|
369 } |
|
370 else if (aFile.Right(3).CompareF(_L("wav")) == 0) //WAV |
|
371 { |
|
372 mime.Copy(_L8("audio/x-wav")); |
|
373 } |
|
374 else if (aFile.Right(3).CompareF(_L("gif")) == 0) // GIF |
|
375 { |
|
376 mime.Copy(_L8("image/gif")); |
|
377 } |
|
378 else if (aFile.Right(3).CompareF(_L("jpg")) == 0) // JPEG |
|
379 { |
|
380 mime.Copy(_L8("image/jpeg")); |
|
381 } |
|
382 else if (aFile.Right(3).CompareF(_L("txt")) == 0) // text |
|
383 { |
|
384 mime.Copy(_L8("text/plain")); |
|
385 } |
|
386 else if (aFile.Right(3).CompareF(_L("pip")) == 0) // PIP |
|
387 { |
|
388 mime.Copy(_L8("application/x-pip")); |
|
389 } |
|
390 |
|
391 aDcfFile.Append(aOutput); |
|
392 |
|
393 for(TInt i = 0; i < aMultiplier ; ++i) |
|
394 { |
|
395 aDcfFile.Delete(aOriginalFileNameLength, aDcfFile.Length()); |
|
396 aDcfFile.Append(_L("-")); |
|
397 aDcfFile.AppendNum(i); |
|
398 aDcfFile.Append(_L(".dcf")); |
|
399 c = COma1DcfCreator::NewL(); |
|
400 CleanupStack::PushL(c); |
|
401 fs.Delete(aOutput); |
|
402 c->EncryptFileL(aFile, aDcfFile, mime, rights); |
|
403 UpdateDCFRepositoryL( aDcfFile ); |
|
404 delete rights; |
|
405 CleanupStack::PopAndDestroy(); // c |
|
406 } |
|
407 fs.Close(); |
|
408 |
|
409 } |
|
410 |
|
411 void DRMEncryptor::startEncrypt() |
|
412 { |
|
413 TUint result = 0; |
|
414 TUint aEncryptedCount = 0; |
|
415 TUint aRightsCount = 0; |
|
416 TUint aMessagesProcessed = 0; |
|
417 TBuf<128> buffer; |
|
418 |
|
419 result = EncryptL(aEncryptedCount, aRightsCount, aMessagesProcessed); |
|
420 |
|
421 buffer.Append(_L("Encryption done\n")); |
|
422 if(result < 1) |
|
423 { |
|
424 buffer.Append(_L("No files found")); |
|
425 } |
|
426 if(aMessagesProcessed != 0) |
|
427 { |
|
428 buffer.AppendNum(aMessagesProcessed); |
|
429 buffer.Append(_L(" messages processed\n")); |
|
430 } |
|
431 if(aRightsCount != 0) |
|
432 { |
|
433 buffer.AppendNum(aRightsCount); |
|
434 buffer.Append(_L(" rights objects processed\n")); |
|
435 } |
|
436 if(aMessagesProcessed != 0) |
|
437 { |
|
438 buffer.AppendNum(aEncryptedCount); |
|
439 buffer.Append(_L(" files encrypted\n")); |
|
440 } |
|
441 |
|
442 QGridLayout *layout = new QGridLayout; |
|
443 layout->setAlignment(Qt::AlignCenter); |
|
444 setLayout(layout); |
|
445 |
|
446 QString encryptString((QChar*)buffer.Ptr(),buffer.Length()); |
|
447 QMessageBox *encrpytMessage = new QMessageBox(this); |
|
448 encrpytMessage->setWindowTitle(tr("Encrypt")); |
|
449 encrpytMessage->setText(encryptString); |
|
450 |
|
451 layout->addWidget(encrpytMessage); |
|
452 encrpytMessage->show(); |
|
453 |
|
454 } |
|
455 |
|
456 TUint DRMEncryptor::EncryptL(TUint& aEncryptedCount, TUint& aRightsCount, TUint& aMessagesProcessed) |
|
457 { |
|
458 TInt i; |
|
459 CDir* files; |
|
460 TFileName input; |
|
461 TFileName output; |
|
462 TUint inputNameSize = 0; |
|
463 TUint outputNameSize = 0; |
|
464 RFs fs; |
|
465 User::LeaveIfError(fs.Connect()); |
|
466 TInt aMultiplier(1); |
|
467 |
|
468 |
|
469 #ifdef __WINS__ |
|
470 input.Append(_L("c:\\data\\DRM\\")); |
|
471 output.Append(_L("c:\\data\\Others\\")); |
|
472 #else |
|
473 #ifndef RD_MULTIPLE_DRIVE |
|
474 |
|
475 input.Append(_L("e:\\DRM\\")); |
|
476 output.Append(_L("e:\\Others\\")); |
|
477 |
|
478 #else //RD_MULTIPLE_DRIVE |
|
479 |
|
480 TInt driveNumber( -1 ); |
|
481 TChar driveLetter; |
|
482 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultMassStorage, driveNumber ); |
|
483 fs.DriveToChar( driveNumber, driveLetter ); |
|
484 |
|
485 _LIT( KdrmDir, "%c:\\DRM\\" ); |
|
486 input.Format( KdrmDir, (TUint)driveLetter ); |
|
487 |
|
488 _LIT( KothersDir, "%c:\\Others\\" ); |
|
489 output.Format( KothersDir, (TUint)driveLetter ); |
|
490 |
|
491 #endif |
|
492 #endif |
|
493 |
|
494 inputNameSize = input.Length(); |
|
495 outputNameSize = output.Length(); |
|
496 |
|
497 |
|
498 fs.MkDir(input); |
|
499 fs.MkDir(output); |
|
500 |
|
501 fs.GetDir(input, KEntryAttNormal, ESortNone, files); |
|
502 for (i = 0; i < files->Count(); i++) |
|
503 { |
|
504 input.Append((*files)[i].iName); |
|
505 |
|
506 output.Append((*files)[i].iName); |
|
507 |
|
508 if (input.Right(2).CompareF(_L("dm")) == 0) |
|
509 { |
|
510 |
|
511 for(TInt ii = 0; ii < aMultiplier ; ++ii) |
|
512 { |
|
513 output.Delete(outputNameSize +(*files)[i].iName.Length() , output.Length()-1); |
|
514 output.Append(_L("-")); |
|
515 output.AppendNum(ii); |
|
516 output.Append(_L(".dcf")); |
|
517 ProcessMessageL(input, output); |
|
518 ++aMessagesProcessed; |
|
519 } |
|
520 } |
|
521 else if (input.Right(3).CompareF(_L("oro")) == 0 || |
|
522 input.Right(3).CompareF(_L("drc")) == 0 || |
|
523 input.Right(2).CompareF(_L("ro")) == 0 || |
|
524 input.Right(2).CompareF(_L("dr")) == 0 ) |
|
525 { |
|
526 for (TInt iii = 0; iii < aMultiplier; ++iii) |
|
527 { |
|
528 ProcessRightsL(input); |
|
529 ++aRightsCount; |
|
530 } |
|
531 } |
|
532 else if (input.Right(3).CompareF(_L("dcf")) != 0) |
|
533 { |
|
534 output.Append(_L(".dcf")); |
|
535 EncryptFileL(input, output, aMultiplier); |
|
536 ++aEncryptedCount; |
|
537 } |
|
538 |
|
539 //restore paths |
|
540 input.Delete(inputNameSize, input.Length()-1); |
|
541 output.Delete(outputNameSize, output.Length()-1); |
|
542 } |
|
543 |
|
544 fs.Close(); |
|
545 |
|
546 TRequestStatus status; |
|
547 CDcfRep* rep = CDcfRep::NewL(); |
|
548 CleanupStack::PushL(rep); |
|
549 rep->RefreshDcf(status); |
|
550 User::WaitForRequest( status ); |
|
551 CleanupStack::PopAndDestroy( rep ); |
|
552 |
|
553 delete files; |
|
554 |
|
555 return (aEncryptedCount*aMultiplier + aRightsCount + aMessagesProcessed); |
|
556 |
|
557 } |
|
558 |
|
559 ContentAccess::CManager* GetCafDataL( TAgent& aAgent ) |
|
560 { |
|
561 TPtr8 ptr(NULL, 0, 0); |
|
562 RArray<TAgent> agents; |
|
563 TRequestStatus status; |
|
564 TInt i; |
|
565 |
|
566 CleanupClosePushL( agents ); |
|
567 CManager* manager = CManager::NewLC(); |
|
568 |
|
569 manager->ListAgentsL( agents ); |
|
570 |
|
571 for (i = 0; i < agents.Count(); i++) |
|
572 { |
|
573 if (agents[i].Name().Compare(KWmDrmAgentName) == 0) |
|
574 { |
|
575 aAgent = agents[i]; |
|
576 break; |
|
577 } |
|
578 } |
|
579 CleanupStack::Pop( manager ); |
|
580 CleanupStack::PopAndDestroy(); // agents |
|
581 return manager; |
|
582 } |
|
583 |
|
584 void DRMEncryptor::DeleteWmDrmRdbL() |
|
585 { |
|
586 // get the data part |
|
587 ContentAccess::CManager* manager = NULL; |
|
588 ContentAccess::TAgent agent; |
|
589 TPtr8 ptr(NULL, 0, 0); |
|
590 TPtrC8 ptr2; |
|
591 |
|
592 // Find the caf agent and create manager |
|
593 manager = GetCafDataL( agent ); |
|
594 CleanupStack::PushL( manager ); |
|
595 |
|
596 User::LeaveIfError( |
|
597 manager->AgentSpecificCommand( agent, |
|
598 (TInt)DRM::EWmDrmDeleteRights, |
|
599 ptr2, |
|
600 ptr) ); |
|
601 CleanupStack::PopAndDestroy( manager ); |
|
602 } |
|
603 |
|
604 void DRMEncryptor::deleteWmDrmDB() |
|
605 { |
|
606 TRAPD(err, DeleteWmDrmRdbL()); |
|
607 if(!err) |
|
608 { |
|
609 QMessageBox::information(this, tr("WMDRM DB"),tr("DRM rights deleted.")); |
|
610 } |
|
611 else |
|
612 { |
|
613 QMessageBox::information(this, tr("WMDRM DB"),tr("Error deleting WMDRM rights.")); |
|
614 } |
|
615 } |
|
616 |
|
617 void DRMEncryptor::deleteOmaDrmDB() |
|
618 { |
|
619 RDRMRightsClient client; |
|
620 User::LeaveIfError(client.Connect()); |
|
621 client.DeleteAll(); |
|
622 client.Close(); |
|
623 } |
|
624 |
|
625 |
|
626 |
|
627 void DRMEncryptor::launchBrowser() |
|
628 { |
|
629 /*_LIT( KTestDrmFile, "c:\\data\\others\\sd_water003.dcf" ); |
|
630 TInt urlLength = 256; |
|
631 TFileName fileName(KTestDrmFile); |
|
632 RFile file; |
|
633 RFs fs; |
|
634 |
|
635 User::LeaveIfError(fs.Connect()); |
|
636 TInt result = 0; |
|
637 |
|
638 result = file.Open(fs, fileName, EFileRead | EFileShareReadersOrWriters); |
|
639 |
|
640 CData* content = CData::NewLC( file, KDefaultContentObject, EPeek ); |
|
641 |
|
642 HBufC* rightsIssuerBuf = HBufC::NewLC( urlLength ); // Content issuer max URL length |
|
643 TPtr rightsIssuer(const_cast<TUint16*>(rightsIssuerBuf->Ptr()), 0, urlLength); |
|
644 |
|
645 // Get value of rights-issuer header field |
|
646 TInt error = content->GetStringAttribute( ERightsIssuerUrl, rightsIssuer ); |
|
647 rightsIssuer.TrimAll(); |
|
648 |
|
649 rightsIssuer.Insert(0, _L("http://")); |
|
650 |
|
651 HBufC* finalUrl = rightsIssuer.AllocLC(); |
|
652 |
|
653 DRM::CDrmBrowserLauncher::LaunchUrlL(*finalUrl); |
|
654 |
|
655 CleanupStack::PopAndDestroy(3); // finalUrl, rightsIssuerBuf, content;*/ |
|
656 } |
|
657 |
|
658 /* |
|
659 void DRMEncryptorsetDRMClock() |
|
660 { |
|
661 |
|
662 double value1 = ui->lineEdit->text().toDouble(&bOK1); |
|
663 double value2 = ui->lineEdit_2->text().toDouble(&bOK2); |
|
664 |
|
665 ui->lineEdit_3->setText(""); |
|
666 |
|
667 if(bOK1 && bOK2) |
|
668 { |
|
669 if(value2 != 0) |
|
670 { |
|
671 double result = value1 / value2; |
|
672 ui->lineEdit_3->setText(QString::number(result)); |
|
673 } |
|
674 else |
|
675 { |
|
676 box.setText("Et voi jakaa nollalla"); |
|
677 box.exec(); |
|
678 } |
|
679 } |
|
680 else |
|
681 { |
|
682 box.setText("Virheellinen syöte"); |
|
683 box.exec(); |
|
684 } |
|
685 } |
|
686 |
|
687 void DRMEncryptoronDateTimeChanged(const QDateTime & datetime ) |
|
688 { |
|
689 |
|
690 } |
|
691 */ |
|
692 |
|
693 void DRMEncryptor::onTextChanged(const QString &) |
|
694 { |
|
695 //ui->pushButton->setEnabled(ui->lineEdit->text() != "" && ui->lineEdit_2->text() != ""); |
|
696 } |
|
697 |
|
698 DateTimeDialog::DateTimeDialog() |
|
699 { |
|
700 //iLayout = new QHBoxLayout; |
|
701 QGridLayout *layout = new QGridLayout; |
|
702 layout->setAlignment(Qt::AlignCenter); |
|
703 setLayout(layout); |
|
704 |
|
705 iDateEdit = new QDateTimeEdit(QDate::currentDate()); |
|
706 iDateEdit->setAlignment(Qt::AlignHCenter); |
|
707 iDateEdit->setDisplayFormat("yyyy.mm.dd hh.mm.ss"); |
|
708 iDateEdit->setWindowTitle("Set DRM Clock yyyy.MM.dd hh.mm.ss"); |
|
709 QPushButton *okButton = new QPushButton("OK", this); |
|
710 QPushButton *cancelButton = new QPushButton("Cancel", this); |
|
711 |
|
712 layout->addWidget(iDateEdit); |
|
713 layout->addWidget(okButton); |
|
714 layout->addWidget(cancelButton); |
|
715 |
|
716 connect(okButton, SIGNAL(clicked()), this, SLOT(setDRMClock())); |
|
717 connect(cancelButton, SIGNAL(clicked()), this, SLOT(close())); |
|
718 |
|
719 //this->setLayout(iLayout); |
|
720 okButton->show(); |
|
721 cancelButton->show(); |
|
722 this->show(); |
|
723 } |
|
724 |
|
725 DateTimeDialog::~DateTimeDialog() |
|
726 { |
|
727 |
|
728 } |
|
729 |
|
730 void DateTimeDialog::setDRMClock() |
|
731 { |
|
732 DRM::CDrmServiceApi* service = NULL; |
|
733 TBuf<5> buf; |
|
734 TRAPD(err, service = DRM::CDrmServiceApi::NewL()); |
|
735 if(err!=KErrNone) |
|
736 { |
|
737 QMessageBox::information(this, tr("DRM Clock"),tr("Error creating CDrmServiceApi.")); |
|
738 buf.AppendNum(err); |
|
739 QString string((QChar*)buf.Ptr(),buf.Length()); |
|
740 QMessageBox::information(this, tr("DRM Clock"),string); |
|
741 delete service; // service |
|
742 return; |
|
743 } |
|
744 |
|
745 QString datetimeString = iDateEdit->dateTime().toString("yyyy.mm.dd hh.mm.ss"); |
|
746 |
|
747 // datetime in format YYYYMMDD:HHMMSS for TTime |
|
748 datetimeString.remove(QChar('.')); |
|
749 datetimeString.replace(" ", ":"); |
|
750 datetimeString.append(".000000"); |
|
751 |
|
752 TPtrC datetimePtr(reinterpret_cast<const TText*>(datetimeString.constData())); |
|
753 HBufC *datetimeBuf = NULL; |
|
754 TBuf<5> errorBuf; |
|
755 TRAPD(errorCode, datetimeBuf = datetimePtr.AllocL()); |
|
756 if(errorCode!=KErrNone) |
|
757 { |
|
758 QMessageBox::information(this, tr("DRM Clock"),tr("Error in datetimePtr.AllocL.")); |
|
759 errorBuf.AppendNum(errorCode); |
|
760 QString string((QChar*)buf.Ptr(),buf.Length()); |
|
761 QMessageBox::information(this, tr("DRM Clock"),string); |
|
762 delete service; |
|
763 delete datetimeBuf; |
|
764 return; |
|
765 } |
|
766 |
|
767 |
|
768 TTime inputTime(*datetimeBuf); |
|
769 TInt timezone = 0; |
|
770 delete datetimeBuf; |
|
771 |
|
772 // Get secure time from service api to get timezone |
|
773 DRMClock::ESecurityLevel level; |
|
774 TInt error( KErrNone ); |
|
775 |
|
776 TTime currentTime; |
|
777 error = service->GetSecureTime(currentTime, timezone, level); |
|
778 |
|
779 if(error != KErrNone) |
|
780 { |
|
781 return; |
|
782 } |
|
783 |
|
784 error = service->UpdateSecureTime(inputTime, timezone); |
|
785 |
|
786 if(error != KErrNone) |
|
787 { |
|
788 return; |
|
789 } |
|
790 |
|
791 delete service; |
|
792 |
|
793 QMessageBox::information(this, tr("DRM Clock"),tr("DRM Clock Set")); |
|
794 } |
|
795 |