Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqnxmediautil.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Research In Motion
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#include "qqnxmediautil_p.h"
4
5#include <QDebug>
6#include <QDir>
7#include <QFile>
8#include <QJsonDocument>
9#include <QJsonObject>
10#include <QJsonValue>
11#include <QMutex>
12#include <QMutex>
13#include <QString>
14#include <QXmlStreamReader>
15
16#include <mm/renderer.h>
17#include <mm/renderer/types.h>
18
20
21struct MmError {
23 const char *name;
24};
25
26#define MM_ERROR_ENTRY(error) { error, #error }
27static const MmError mmErrors[] = {
28 MM_ERROR_ENTRY(MMR_ERROR_NONE),
29 MM_ERROR_ENTRY(MMR_ERROR_UNKNOWN ),
30 MM_ERROR_ENTRY(MMR_ERROR_INVALID_PARAMETER ),
31 MM_ERROR_ENTRY(MMR_ERROR_INVALID_STATE),
32 MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_VALUE),
33 MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_MEDIA_TYPE),
34 MM_ERROR_ENTRY(MMR_ERROR_MEDIA_PROTECTED),
35 MM_ERROR_ENTRY(MMR_ERROR_UNSUPPORTED_OPERATION),
36 MM_ERROR_ENTRY(MMR_ERROR_READ),
37 MM_ERROR_ENTRY(MMR_ERROR_WRITE),
38 MM_ERROR_ENTRY(MMR_ERROR_MEDIA_UNAVAILABLE),
39 MM_ERROR_ENTRY(MMR_ERROR_MEDIA_CORRUPTED),
40 MM_ERROR_ENTRY(MMR_ERROR_OUTPUT_UNAVAILABLE),
41 MM_ERROR_ENTRY(MMR_ERROR_NO_MEMORY),
42 MM_ERROR_ENTRY(MMR_ERROR_RESOURCE_UNAVAILABLE),
43 MM_ERROR_ENTRY(MMR_ERROR_MEDIA_DRM_NO_RIGHTS),
44 MM_ERROR_ENTRY(MMR_ERROR_DRM_CORRUPTED_DATA_STORE),
45 MM_ERROR_ENTRY(MMR_ERROR_DRM_OUTPUT_PROTECTION),
46 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_HDMI),
47 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_DISPLAYPORT),
48 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_DVI),
49 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_ANALOG_VIDEO),
50 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_ANALOG_AUDIO),
51 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_TOSLINK),
52 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_SPDIF),
53 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_BLUETOOTH),
54 MM_ERROR_ENTRY(MMR_ERROR_DRM_OPL_WIRELESSHD),
55};
56static const unsigned int numMmErrors = sizeof(mmErrors) / sizeof(MmError);
57
58template <typename T, size_t N>
59constexpr size_t countof(T (&)[N])
60{
61 return N;
62}
63
65{
66 QByteArray qtKeyValueMaps = qgetenv("QT_KEY_VALUE_MAPS");
67 if (qtKeyValueMaps.isNull())
68 return QString::fromUtf8("/etc/qt/keyvaluemaps");
69 else
70 return QString::fromUtf8(qtKeyValueMaps);
71}
72
73QJsonObject loadMapObject(const QString &keyValueMapPath)
74{
75 QFile mapFile(keyValueMapsLocation() + keyValueMapPath);
76 if (mapFile.open(QIODevice::ReadOnly)) {
77 QByteArray mapFileContents = mapFile.readAll();
78 QJsonDocument mapDocument = QJsonDocument::fromJson(mapFileContents);
79 if (mapDocument.isObject()) {
80 QJsonObject mapObject = mapDocument.object();
81 return mapObject;
82 }
83 }
84 return QJsonObject();
85}
86
87QString mmErrorMessage(const QString &msg, mmr_context_t *context, int *errorCode)
88{
89 const mmr_error_info_t * const mmError = mmr_error_info(context);
90
91 if (errorCode)
92 *errorCode = mmError->error_code;
93
94 if (mmError->error_code < numMmErrors) {
95 return QString::fromLatin1("%1: %2 (code %3)").arg(msg).arg(QString::fromUtf8(mmErrors[mmError->error_code].name))
96 .arg(mmError->error_code);
97 } else {
98 return QString::fromLatin1("%1: Unknown error code %2").arg(msg).arg(mmError->error_code);
99 }
100}
101
103{
104 QDir sandboxDir = QDir::home(); // always returns 'data' directory
105 sandboxDir.cdUp(); // change to app sandbox directory
106
107 QFile file(sandboxDir.filePath(QString::fromUtf8("app/native/bar-descriptor.xml")));
109 qWarning() << "checkForDrmPermission: Unable to open bar-descriptor.xml";
110 return false;
111 }
112
113 QXmlStreamReader reader(&file);
114 while (!reader.atEnd()) {
115 reader.readNextStartElement();
116 if (reader.name() == QLatin1String("action")
117 || reader.name() == QLatin1String("permission")) {
118 if (reader.readElementText().trimmed() == QLatin1String("access_protected_media"))
119 return true;
120 }
121 }
122
123 return false;
124}
125
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qdir.h:20
static QDir home()
Returns the user's home directory.
Definition qdir.h:222
\inmodule QtCore
Definition qfile.h:93
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition qfile.cpp:904
\inmodule QtCore\reentrant
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
Combined button and popup list for selecting options.
static void * context
#define qWarning
Definition qlogging.h:166
typedefQT_BEGIN_NAMESPACE struct mmr_context mmr_context_t
static const unsigned int numMmErrors
QString keyValueMapsLocation()
QJsonObject loadMapObject(const QString &keyValueMapPath)
QString mmErrorMessage(const QString &msg, mmr_context_t *context, int *errorCode)
static const MmError mmErrors[]
bool checkForDrmPermission()
#define MM_ERROR_ENTRY(error)
constexpr size_t countof(T(&)[N])
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QFile file
[0]
const char * name