8#include "modemdevice.h"
9#include "modemdevice_p.h"
12#include "dbus/fakedbus.h"
19#include "modem3gppussd.h"
21#include "modemlocation.h"
22#if MM_CHECK_VERSION(1, 2, 0)
24#include "modemsignal.h"
26#if MM_CHECK_VERSION(1, 6, 0)
27#include "modemvoice.h"
29#include "modemfirmware.h"
30#include "modemsimple.h"
33#include <QDBusConnection>
34#include <QDomDocument>
36ModemManager::ModemDevicePrivate::ModemDevicePrivate(
const QString &path, ModemManager::ModemDevice *q)
43ModemManager::ModemDevicePrivate::~ModemDevicePrivate()
47void ModemManager::ModemDevicePrivate::init()
49 Q_Q(ModemManager::ModemDevice);
54 QStringLiteral(
"InterfacesAdded"),
56 SLOT(onInterfacesAdded(
QDBusObjectPath, ModemManager::MMVariantMapMap)));
60 QStringLiteral(
"InterfacesRemoved"),
67 QStringLiteral(
"InterfacesAdded"),
69 SLOT(onInterfacesAdded(
QDBusObjectPath, ModemManager::MMVariantMapMap)));
73 QStringLiteral(
"InterfacesRemoved"),
81void ModemManager::ModemDevicePrivate::initInterfaces()
83 interfaceList.clear();
85 const QString xmlData = introspect();
87 qCDebug(MMQT) << uni <<
"has no interfaces!";
95 for (
int i = 0; i < ifaceNodeList.
count(); i++) {
102 interfaceList.insert(ModemManager::ModemDevice::ModemInterface, ModemManager::Modem::Ptr());
103 if (interfaceList.contains(ModemManager::ModemDevice::ModemInterface)) {
104 ModemManager::Modem::Ptr modemInterface = interface(ModemManager::ModemDevice::ModemInterface).objectCast<
ModemManager::Modem>();
105 if (!modemInterface->simPath().isEmpty()) {
112 }
else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_SIMPLE)) {
113 interfaceList.insert(ModemManager::ModemDevice::SimpleInterface, ModemManager::ModemSimple::Ptr());
114 }
else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP)) {
115 interfaceList.insert(ModemManager::ModemDevice::GsmInterface, ModemManager::Modem3gpp::Ptr());
116 }
else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP_USSD)) {
117 interfaceList.insert(ModemManager::ModemDevice::GsmUssdInterface, ModemManager::Modem3gppUssd::Ptr());
118 }
else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEMCDMA)) {
119 interfaceList.insert(ModemManager::ModemDevice::CdmaInterface, ModemManager::ModemCdma::Ptr());
120 }
else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MESSAGING)) {
121 interfaceList.insert(ModemManager::ModemDevice::MessagingInterface, ModemManager::ModemMessaging::Ptr());
122 }
else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_LOCATION)) {
123 interfaceList.insert(ModemManager::ModemDevice::LocationInterface, ModemManager::ModemLocation::Ptr());
124 }
else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_TIME)) {
125 interfaceList.insert(ModemManager::ModemDevice::TimeInterface, ModemManager::ModemTime::Ptr());
127#if MM_CHECK_VERSION(1, 2, 0)
128 else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_OMA)) {
129 interfaceList.insert(ModemManager::ModemDevice::OmaInterface, ModemManager::ModemOma::Ptr());
130 }
else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_SIGNAL)) {
131 interfaceList.insert(ModemManager::ModemDevice::SignalInterface, ModemManager::ModemSignal::Ptr());
134 else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_FIRMWARE)) {
135 interfaceList.insert(ModemManager::ModemDevice::FirmwareInterface, ModemManager::ModemFirmware::Ptr());
137#if MM_CHECK_VERSION(1, 6, 0)
138 else if (name ==
QLatin1String(MMQT_DBUS_INTERFACE_MODEM_VOICE)) {
139 interfaceList.insert(ModemManager::ModemDevice::VoiceInterface, ModemManager::ModemVoice::Ptr());
145 qCDebug(MMQT) << uni <<
"has interfaces:" << interfaceList.keys();
148QString ModemManager::ModemDevicePrivate::introspect()
const
159 return reply.
value();
165ModemManager::ModemDevice::ModemDevice(
const QString &path,
QObject *parent)
167 , d_ptr(new ModemDevicePrivate(
path, this))
171ModemManager::ModemDevice::ModemDevice(ModemDevicePrivate &dd,
QObject *parent)
177ModemManager::ModemDevice::~ModemDevice()
182ModemManager::Interface::List ModemManager::ModemDevicePrivate::interfaces()
184 ModemManager::Interface::List
list;
186 QMap<ModemManager::ModemDevice::InterfaceType, ModemManager::Interface::Ptr>::const_iterator i;
187 for (i = interfaceList.constBegin(); i != interfaceList.constEnd(); ++i) {
188 ModemManager::Interface::Ptr modemInterface = interface(i.key());
189 if (modemInterface) {
192 qCWarning(MMQT) <<
"warning: null network Interface for" << i.key();
199ModemManager::Interface::Ptr ModemManager::ModemDevicePrivate::interface(ModemManager::ModemDevice::InterfaceType type)
201 ModemManager::Interface::Ptr modemInterface;
203 if (interfaceList.contains(type)) {
204 if (interfaceList.value(type)) {
205 modemInterface = interfaceList.value(type);
207 modemInterface = createInterface(type);
208 interfaceList[
type] = modemInterface;
212 return modemInterface;
215ModemManager::Interface::Ptr ModemManager::ModemDevicePrivate::createInterface(ModemManager::ModemDevice::InterfaceType type)
217 ModemManager::Interface::Ptr createdInterface;
219 case ModemManager::ModemDevice::ModemInterface:
220 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::Modem(uni), &
QObject::deleteLater);
222 case ModemManager::ModemDevice::SimpleInterface:
223 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemSimple(uni), &
QObject::deleteLater);
225 case ModemManager::ModemDevice::GsmInterface:
226 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::Modem3gpp(uni), &
QObject::deleteLater);
228 case ModemManager::ModemDevice::GsmUssdInterface:
229 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::Modem3gppUssd(uni), &
QObject::deleteLater);
231 case ModemManager::ModemDevice::CdmaInterface:
232 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemCdma(uni), &
QObject::deleteLater);
234 case ModemManager::ModemDevice::MessagingInterface:
235 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemMessaging(uni), &
QObject::deleteLater);
237 case ModemManager::ModemDevice::LocationInterface:
238 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemLocation(uni), &
QObject::deleteLater);
240 case ModemManager::ModemDevice::TimeInterface:
241 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemTime(uni), &
QObject::deleteLater);
243#if MM_CHECK_VERSION(1, 2, 0)
244 case ModemManager::ModemDevice::OmaInterface:
245 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemOma(uni), &
QObject::deleteLater);
247 case ModemManager::ModemDevice::SignalInterface:
248 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemSignal(uni), &
QObject::deleteLater);
251 case ModemManager::ModemDevice::FirmwareInterface:
252 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemFirmware(uni), &
QObject::deleteLater);
254#if MM_CHECK_VERSION(1, 6, 0)
255 case ModemManager::ModemDevice::VoiceInterface:
256 createdInterface = ModemManager::Interface::Ptr(
new ModemManager::ModemVoice(uni), &
QObject::deleteLater);
260 return createdInterface;
263ModemManager::Bearer::Ptr ModemManager::ModemDevicePrivate::findBearer(
const QString &uni)
265 ModemManager::Bearer::Ptr result;
266 Q_FOREACH (
const ModemManager::Bearer::Ptr &bearer, bearers()) {
267 if (bearer->uni() == uni) {
276ModemManager::Bearer::List ModemManager::ModemDevicePrivate::bearers()
278 Q_Q(ModemManager::ModemDevice);
280 return q->modemInterface()->listBearers();
283ModemManager::Sim::Ptr ModemManager::ModemDevicePrivate::sim()
288QString ModemManager::ModemDevice::uni()
const
290 Q_D(
const ModemDevice);
294bool ModemManager::ModemDevice::hasInterface(ModemManager::ModemDevice::InterfaceType type)
const
296 Q_D(
const ModemDevice);
297 return d->interfaceList.contains(type);
300ModemManager::Interface::Ptr ModemManager::ModemDevice::interface(ModemManager::ModemDevice::InterfaceType type)
const
302 Q_D(
const ModemDevice);
304 return const_cast<ModemDevicePrivate *
>(d)->interface(type);
307ModemManager::Interface::List ModemManager::ModemDevice::interfaces()
const
309 Q_D(
const ModemDevice);
311 return const_cast<ModemDevicePrivate *
>(d)->interfaces();
314ModemManager::ModemMessaging::Ptr ModemManager::ModemDevice::messagingInterface()
318 return d->interface(ModemManager::ModemDevice::MessagingInterface).objectCast<ModemManager::ModemMessaging>();
321ModemManager::Modem::Ptr ModemManager::ModemDevice::modemInterface()
325 return d->interface(ModemManager::ModemDevice::ModemInterface).objectCast<ModemManager::Modem>();
328ModemManager::Bearer::Ptr ModemManager::ModemDevice::findBearer(
const QString &uni)
332 return d->findBearer(uni);
335ModemManager::Bearer::List ModemManager::ModemDevice::bearers()
const
337 Q_D(
const ModemDevice);
339 return const_cast<ModemDevicePrivate *
>(d)->bearers();
342ModemManager::Sim::Ptr ModemManager::ModemDevice::sim()
const
344 Q_D(
const ModemDevice);
346 return const_cast<ModemDevicePrivate *
>(d)->sim();
349bool ModemManager::ModemDevice::isGsmModem()
const
351 return hasInterface(ModemManager::ModemDevice::GsmInterface);
354bool ModemManager::ModemDevice::isCdmaModem()
const
356 return hasInterface(ModemManager::ModemDevice::CdmaInterface);
359void ModemManager::ModemDevicePrivate::onInterfacesAdded(
const QDBusObjectPath &object_path,
const MMVariantMapMap &interfaces_and_properties)
362 if (object_path.
path() != uni) {
366 Q_FOREACH (
const QString &iface, interfaces_and_properties.keys()) {
368 if (iface.
startsWith(QLatin1String(MMQT_DBUS_SERVICE))) {
369 if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM)) {
370 interfaceList.insert(ModemManager::ModemDevice::ModemInterface, ModemManager::Modem::Ptr());
371 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::ModemInterface);
372 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_SIMPLE)) {
373 interfaceList.insert(ModemManager::ModemDevice::SimpleInterface, ModemManager::ModemSimple::Ptr());
374 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::SimpleInterface);
375 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP)) {
376 interfaceList.insert(ModemManager::ModemDevice::GsmInterface, ModemManager::Modem3gpp::Ptr());
377 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::GsmInterface);
378 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP_USSD)) {
379 interfaceList.insert(ModemManager::ModemDevice::GsmUssdInterface, ModemManager::Modem3gppUssd::Ptr());
380 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::GsmUssdInterface);
381 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEMCDMA)) {
382 interfaceList.insert(ModemManager::ModemDevice::CdmaInterface, ModemManager::ModemCdma::Ptr());
383 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::CdmaInterface);
384 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MESSAGING)) {
385 interfaceList.insert(ModemManager::ModemDevice::MessagingInterface, ModemManager::ModemMessaging::Ptr());
386 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::MessagingInterface);
387 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_LOCATION)) {
388 interfaceList.insert(ModemManager::ModemDevice::LocationInterface, ModemManager::ModemLocation::Ptr());
389 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::LocationInterface);
390 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_TIME)) {
391 interfaceList.insert(ModemManager::ModemDevice::TimeInterface, ModemManager::ModemTime::Ptr());
392 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::TimeInterface);
394#if MM_CHECK_VERSION(1, 2, 0)
395 else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_OMA)) {
396 interfaceList.insert(ModemManager::ModemDevice::OmaInterface, ModemManager::ModemOma::Ptr());
397 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::OmaInterface);
398 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_SIGNAL)) {
399 interfaceList.insert(ModemManager::ModemDevice::SignalInterface, ModemManager::ModemSignal::Ptr());
400 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::SignalInterface);
403 else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_FIRMWARE)) {
404 interfaceList.insert(ModemManager::ModemDevice::FirmwareInterface, ModemManager::ModemFirmware::Ptr());
405 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::FirmwareInterface);
407#if MM_CHECK_VERSION(1, 6, 0)
408 else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_VOICE)) {
409 interfaceList.insert(ModemManager::ModemDevice::VoiceInterface, ModemManager::ModemVoice::Ptr());
410 Q_EMIT q->interfaceAdded(ModemManager::ModemDevice::VoiceInterface);
417void ModemManager::ModemDevicePrivate::onInterfacesRemoved(
const QDBusObjectPath &object_path,
const QStringList &interfaces)
420 if (object_path.
path() != uni) {
424 if (interfaces.
contains(QLatin1String(MMQT_DBUS_INTERFACE_MODEM)) || interfaces.
isEmpty()) {
426 Q_EMIT q->simRemoved(simCard->uni());
427 simCard = ModemManager::Sim::Ptr();
431 Q_FOREACH (
const QString &iface, interfaces) {
432 if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM)) {
433 interfaceList.remove(ModemManager::ModemDevice::ModemInterface);
434 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::ModemInterface);
435 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_SIMPLE)) {
436 interfaceList.remove(ModemManager::ModemDevice::SimpleInterface);
437 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::SimpleInterface);
438 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP)) {
439 interfaceList.remove(ModemManager::ModemDevice::GsmInterface);
440 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::GsmInterface);
441 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEM3GPP_USSD)) {
442 interfaceList.remove(ModemManager::ModemDevice::GsmUssdInterface);
443 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::GsmUssdInterface);
444 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MODEMCDMA)) {
445 interfaceList.remove(ModemManager::ModemDevice::CdmaInterface);
446 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::CdmaInterface);
447 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_MESSAGING)) {
448 interfaceList.remove(ModemManager::ModemDevice::MessagingInterface);
449 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::MessagingInterface);
450 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_LOCATION)) {
451 interfaceList.remove(ModemManager::ModemDevice::LocationInterface);
452 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::LocationInterface);
453 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_TIME)) {
454 interfaceList.remove(ModemManager::ModemDevice::TimeInterface);
455 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::TimeInterface);
457#if MM_CHECK_VERSION(1, 2, 0)
458 else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_OMA)) {
459 interfaceList.remove(ModemManager::ModemDevice::OmaInterface);
460 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::OmaInterface);
461 }
else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_SIGNAL)) {
462 interfaceList.remove(ModemManager::ModemDevice::SignalInterface);
463 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::SignalInterface);
466 else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_FIRMWARE)) {
467 interfaceList.remove(ModemManager::ModemDevice::FirmwareInterface);
468 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::FirmwareInterface);
470#if MM_CHECK_VERSION(1, 6, 0)
471 else if (iface == QLatin1String(MMQT_DBUS_INTERFACE_MODEM_VOICE)) {
472 interfaceList.remove(ModemManager::ModemDevice::VoiceInterface);
473 Q_EMIT q->interfaceRemoved(ModemManager::ModemDevice::VoiceInterface);
479void ModemManager::ModemDevicePrivate::onSimPathChanged(
const QString &oldPath,
const QString &newPath)
483 if (!oldPath.
isEmpty() && simCard->uni() == oldPath) {
484 Q_EMIT q->simRemoved(oldPath);
485 simCard = ModemManager::Sim::Ptr();
490 Q_EMIT q->simAdded(newPath);
494#include "moc_modemdevice.cpp"
495#include "moc_modemdevice_p.cpp"
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
QString path(const QString &relativePath)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QString name(StandardAction id)
QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode, int timeout) const const
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
QString path() const const
bool isValid() const const
typename Select< 0 >::Type value() const const
QDomNodeList elementsByTagName(const QString &tagname) const const
ParseResult setContent(QAnyStringView text, ParseOptions options)
QString attribute(const QString &name, const QString &defValue) const const
bool isNull() const const
QDomElement toElement() const const
QDomNode item(int index) const const
void append(QList< T > &&value)
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const