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