24 #include <apacmdln.h> |
24 #include <apacmdln.h> |
25 #include <apparc.h> |
25 #include <apparc.h> |
26 #include <apmstd.h> |
26 #include <apmstd.h> |
27 #include <w32std.h> |
27 #include <w32std.h> |
28 #include <apgtask.h> |
28 #include <apgtask.h> |
|
29 #include <caf/content.h> |
29 |
30 |
30 #include "xqaiwdecl.h" |
31 #include "xqaiwdecl.h" |
31 #include "xqservicelog.h" |
32 #include "xqservicelog.h" |
32 #include <xqserviceglobal.h> // Error codes |
33 #include <xqserviceglobal.h> // Error codes |
33 #include <xqserviceipcconst.h> |
34 #include <xqserviceipcconst.h> |
|
35 #include <xqapplicationmanager.h> |
34 #include "xqaiwutils.h" |
36 #include "xqaiwutils.h" |
35 |
37 |
36 |
38 |
37 class XQAiwUtilsPrivate : public QObject |
39 class XQAiwUtilsPrivate : public QObject |
38 { |
40 { |
40 |
42 |
41 XQAiwUtilsPrivate(); |
43 XQAiwUtilsPrivate(); |
42 virtual ~XQAiwUtilsPrivate(); |
44 virtual ~XQAiwUtilsPrivate(); |
43 |
45 |
44 void launchApplicationL(int applicationId, const QString &cmdArguments); |
46 void launchApplicationL(int applicationId, const QString &cmdArguments); |
45 int findApplicationFromApa(const QFile &file, int &applicationId); |
47 int findApplicationFromApa(const QString &file, int &applicationId, QString &mimeType); |
46 int findApplicationFromApa(const XQSharableFile &file, int &applicationId); |
48 int findApplicationFromApa(const XQSharableFile &file, int &applicationId, QString &mimeType); |
47 bool applicationExists(int applicationId); |
49 bool applicationExists(int applicationId); |
48 int toIntFromHex(const QString &str, bool *ok); |
50 int toIntFromHex(const QString &str, bool *ok); |
|
51 void GetDrmAttributesL(ContentAccess::CContent *c, const QList<int> & attributes, QVariantList &result); |
49 |
52 |
50 public: |
53 public: |
51 RApaLsSession apaSession; |
54 RApaLsSession apaSession; |
52 |
55 |
53 }; |
56 }; |
127 int XQAiwUtils::findApplication(const QFile &file, int &applicationId) |
130 int XQAiwUtils::findApplication(const QFile &file, int &applicationId) |
128 { |
131 { |
129 XQSERVICE_DEBUG_PRINT("XQAiwUtils::findApplication %s", qPrintable(file.fileName())); |
132 XQSERVICE_DEBUG_PRINT("XQAiwUtils::findApplication %s", qPrintable(file.fileName())); |
130 TInt error = KErrNone; |
133 TInt error = KErrNone; |
131 int appId = 0; |
134 int appId = 0; |
132 error = d->findApplicationFromApa(file, appId); |
135 QString mimeType; |
|
136 error = d->findApplicationFromApa(file.fileName(), appId, mimeType); |
133 if (!error) |
137 if (!error) |
134 { |
138 { |
135 applicationId = appId; |
139 applicationId = appId; |
136 } |
140 } |
137 return error; |
141 return error; |
141 int XQAiwUtils::findApplication(const XQSharableFile &file, int &applicationId) |
145 int XQAiwUtils::findApplication(const XQSharableFile &file, int &applicationId) |
142 { |
146 { |
143 XQSERVICE_DEBUG_PRINT("XQAiwUtils::findApplication (handle)"); |
147 XQSERVICE_DEBUG_PRINT("XQAiwUtils::findApplication (handle)"); |
144 TInt error = KErrNone; |
148 TInt error = KErrNone; |
145 int appId = 0; |
149 int appId = 0; |
146 error = d->findApplicationFromApa(file, appId); |
150 QString mimeType; |
|
151 error = d->findApplicationFromApa(file, appId, mimeType); |
147 if (!error) |
152 if (!error) |
148 { |
153 { |
149 applicationId = appId; |
154 applicationId = appId; |
150 } |
155 } |
151 return error; |
156 return error; |
265 ret += ")"; |
271 ret += ")"; |
266 |
272 |
267 return ret; |
273 return ret; |
268 } |
274 } |
269 |
275 |
|
276 bool XQAiwUtils::getDrmAttributes(const QString &file, const QList<int> & attributes, QVariantList &result) |
|
277 { |
|
278 |
|
279 QString fileName = file; |
|
280 fileName.replace("/", "\\"); // Normalize |
|
281 |
|
282 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::getDrmAttributes %s", qPrintable(fileName)); |
|
283 |
|
284 TPtrC fileNameSymbian( reinterpret_cast<const TUint16*>(fileName.utf16())); |
|
285 |
|
286 TInt err=KErrNone; |
|
287 ContentAccess::CContent* c = 0; |
|
288 |
|
289 TRAP(err,c = ContentAccess::CContent::NewL(fileNameSymbian)); |
|
290 if (err != KErrNone) |
|
291 { |
|
292 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::getDrmAttributes leave %d", err); |
|
293 return false; |
|
294 } |
|
295 CleanupStack::PushL(c); |
|
296 |
|
297 d->GetDrmAttributesL(c, attributes, result); |
|
298 |
|
299 CleanupStack::PopAndDestroy(); // c |
|
300 |
|
301 return true; |
|
302 } |
|
303 |
|
304 |
|
305 bool XQAiwUtils::getDrmAttributes(const XQSharableFile &file, const QList<int> & attributes, QVariantList &result) |
|
306 { |
|
307 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::getDrmAttributes (handle) %s", qPrintable(file.fileName())); |
|
308 |
|
309 RFile fileHandle; |
|
310 if (!file.getHandle(fileHandle)) |
|
311 { |
|
312 XQSERVICE_DEBUG_PRINT("\tInvalid handle"); |
|
313 return false; |
|
314 } |
|
315 TInt err=KErrNone; |
|
316 ContentAccess::CContent* c = 0; |
|
317 TRAP(err,c = ContentAccess::CContent::NewL(fileHandle)); |
|
318 if (err != KErrNone) |
|
319 { |
|
320 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::getDrmAttributes leave %d", err); |
|
321 return false; |
|
322 } |
|
323 CleanupStack::PushL(c); |
|
324 |
|
325 d->GetDrmAttributesL(c, attributes, result); |
|
326 |
|
327 CleanupStack::PopAndDestroy(); // c |
|
328 |
|
329 return true; |
|
330 } |
|
331 |
|
332 int XQAiwUtils::toIntFromHex(const QString &str, bool *ok) |
|
333 { |
|
334 return d->toIntFromHex(str,ok); |
|
335 |
|
336 } |
|
337 |
|
338 |
|
339 // --- XQAiwUtilsPrivate-- |
|
340 |
|
341 XQAiwUtilsPrivate::XQAiwUtilsPrivate() |
|
342 { |
|
343 apaSession.Connect(); |
|
344 } |
|
345 |
|
346 XQAiwUtilsPrivate::~XQAiwUtilsPrivate() |
|
347 { |
|
348 apaSession.Close(); |
|
349 } |
270 |
350 |
271 void XQAiwUtilsPrivate::launchApplicationL(int applicationId, const QString &cmdArguments) |
351 void XQAiwUtilsPrivate::launchApplicationL(int applicationId, const QString &cmdArguments) |
272 { |
352 { |
273 XQSERVICE_DEBUG_PRINT("XQAiwUtils::launchApplication"); |
353 XQSERVICE_DEBUG_PRINT("XQAiwUtils::launchApplication"); |
274 XQSERVICE_DEBUG_PRINT("applicationId=%x, cmdArguments %s", applicationId, qPrintable(cmdArguments)); |
354 XQSERVICE_DEBUG_PRINT("applicationId=%x, cmdArguments %s", applicationId, qPrintable(cmdArguments)); |
309 |
389 |
310 XQSERVICE_DEBUG_PRINT("application started"); |
390 XQSERVICE_DEBUG_PRINT("application started"); |
311 |
391 |
312 } |
392 } |
313 |
393 |
314 // ----- XQAiwUtilsPrivate --- |
394 |
315 |
395 int XQAiwUtilsPrivate::findApplicationFromApa(const QString &file, int &applicationId, QString &mimeType) |
316 XQAiwUtilsPrivate::XQAiwUtilsPrivate() |
396 { |
317 { |
397 QString fileName = file; |
318 apaSession.Connect(); |
398 |
319 } |
399 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::::findApplicationFromApa file=%s", qPrintable(fileName)); |
320 |
400 |
321 XQAiwUtilsPrivate::~XQAiwUtilsPrivate() |
401 fileName.replace("/", "\\"); // Normalize |
322 { |
|
323 apaSession.Close(); |
|
324 } |
|
325 |
|
326 |
|
327 int XQAiwUtilsPrivate::findApplicationFromApa(const QFile &file, int &applicationId) |
|
328 { |
|
329 QString fileName = file.fileName(); |
|
330 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::::findApplicationFromApa %s", qPrintable(fileName)); |
|
331 |
402 |
332 TPtrC name( reinterpret_cast<const TUint16*>(fileName.utf16()) ); |
403 TPtrC name( reinterpret_cast<const TUint16*>(fileName.utf16()) ); |
333 |
404 |
334 // Get the UID and MIME type for the given file name. |
405 // Get the UID and MIME type for the given file name. |
335 TUid uid; |
406 TUid uid; |
342 XQSERVICE_DEBUG_PRINT("\tHandler not found"); |
413 XQSERVICE_DEBUG_PRINT("\tHandler not found"); |
343 return KErrNotFound; |
414 return KErrNotFound; |
344 } |
415 } |
345 |
416 |
346 applicationId = uid.iUid; // return value |
417 applicationId = uid.iUid; // return value |
347 |
418 QString mime = QString::fromUtf16(dataType.Des().Ptr(), dataType.Des().Length()); |
348 XQSERVICE_DEBUG_PRINT("\tapplicationId=%x", applicationId); |
419 mimeType = mime; |
|
420 |
|
421 XQSERVICE_DEBUG_PRINT("\tapplicationId=%x,mime-type=%s", applicationId, qPrintable(mime)); |
|
422 |
349 return KErrNone; |
423 return KErrNone; |
350 |
424 |
351 } |
425 } |
352 |
426 |
353 int XQAiwUtilsPrivate::findApplicationFromApa(const XQSharableFile &file, int &applicationId) |
427 int XQAiwUtilsPrivate::findApplicationFromApa(const XQSharableFile &file, int &applicationId, QString &mimeType) |
354 { |
428 { |
355 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::findApplicationFromApa (handle)"); |
429 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::findApplicationFromApa by handle, file=%s", qPrintable(file.fileName())); |
356 RFile fileHandle; |
430 RFile fileHandle; |
357 if (!file.getHandle(fileHandle)) |
431 if (!file.getHandle(fileHandle)) |
358 { |
432 { |
359 XQSERVICE_DEBUG_PRINT("\tInvalid handle"); |
433 XQSERVICE_DEBUG_PRINT("\tInvalid handle"); |
360 return KErrArgument; |
434 return KErrArgument; |
371 XQSERVICE_DEBUG_PRINT("\tHandler not found"); |
445 XQSERVICE_DEBUG_PRINT("\tHandler not found"); |
372 return KErrNotFound; |
446 return KErrNotFound; |
373 } |
447 } |
374 |
448 |
375 applicationId = uid.iUid; // return value |
449 applicationId = uid.iUid; // return value |
376 |
450 QString mime = QString::fromUtf16(dataType.Des().Ptr(), dataType.Des().Length()); |
377 XQSERVICE_DEBUG_PRINT("\tapplicationId=%x", applicationId); |
451 mimeType = mime; |
|
452 |
|
453 XQSERVICE_DEBUG_PRINT("\tapplicationId=%x,mime-type=%s", applicationId, qPrintable(mime)); |
378 return KErrNone; |
454 return KErrNone; |
379 |
455 |
380 } |
456 } |
381 |
457 |
382 |
458 |
398 { |
474 { |
399 int result=0; |
475 int result=0; |
400 int power = 0; |
476 int power = 0; |
401 int base=16; |
477 int base=16; |
402 QString s = str.toUpper(); |
478 QString s = str.toUpper(); |
|
479 s.replace("0X", ""); // Remove possible 0x |
|
480 |
|
481 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::toIntFromHex=%s", qPrintable(s)); |
|
482 |
403 for (int i=s.length()-1; i >= 0; i--) |
483 for (int i=s.length()-1; i >= 0; i--) |
404 { |
484 { |
405 int val = (int)s[i].toLatin1(); |
485 int val = (int)s[i].toLatin1(); |
406 int num; |
486 int num; |
407 if ((val >= (int)'A') && (val <= (int)'F')) |
487 if ((val >= (int)'A') && (val <= (int)'F')) |
425 *ok = true; |
505 *ok = true; |
426 |
506 |
427 return result; |
507 return result; |
428 } |
508 } |
429 |
509 |
|
510 |
|
511 |
|
512 void XQAiwUtilsPrivate::GetDrmAttributesL(ContentAccess::CContent *c, const QList<int> & attributes, QVariantList &result) |
|
513 { |
|
514 |
|
515 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::GetDrmAttributesL"); |
|
516 |
|
517 HBufC* buffer = 0; |
|
518 |
|
519 foreach (int attrName, attributes) |
|
520 { |
|
521 QVariant v; // By default invalid |
|
522 bool isStringAttribute = attrName >= XQApplicationManager::DrmStringAttributeBase; |
|
523 if (isStringAttribute && !buffer) |
|
524 { |
|
525 // Assume 512 characters is enough |
|
526 buffer = HBufC::NewLC(512); |
|
527 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::buffer allocated"); |
|
528 } |
|
529 |
|
530 if (!isStringAttribute) |
|
531 { |
|
532 TInt value = 0; |
|
533 TInt err = c->GetAttribute(attrName, value); |
|
534 if(err == KErrNone) |
|
535 { |
|
536 // Ok, set the value |
|
537 v.setValue(value); |
|
538 } |
|
539 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::GetDrmAttributesL (int):%d,%d=%d", err, attrName, value); |
|
540 } |
|
541 else |
|
542 { |
|
543 // String attribute |
|
544 attrName -= XQApplicationManager::DrmStringAttributeBase; // CAF uses same values for int and string attributes |
|
545 TPtr value( buffer->Des() ); |
|
546 value.Zero(); |
|
547 TInt err = c->GetStringAttribute(attrName, value); |
|
548 QString strValue; |
|
549 if(err == KErrNone) |
|
550 { |
|
551 // Ok, set the value |
|
552 strValue = QString::fromUtf16(value.Ptr(), value.Length()); |
|
553 v.setValue(strValue); |
|
554 } |
|
555 XQSERVICE_DEBUG_PRINT("XQAiwUtilsPrivate::GetDrmAttributesL (string):%d,%d=%s", err, attrName, qPrintable(strValue)); |
|
556 |
|
557 } |
|
558 // On error value remains invalid and client can check that |
|
559 // v.isValid() |
|
560 result.append(v); |
|
561 } |
|
562 |
|
563 if (buffer) |
|
564 { |
|
565 CleanupStack::PopAndDestroy(); // buffer |
|
566 } |
|
567 |
|
568 } |