2 * hfdialer - Hands Free Voice Call Manager
3 * Copyright (c) 2012, Intel Corporation.
5 * This program is licensed under the terms and conditions of the
6 * Apache License, version 2.0. The full text of the Apache License is at
7 * http://www.apache.org/licenses/LICENSE-2.0
11 #include "modemproxy.h"
15 ModemProxy::ModemProxy(const QString &objectPath)
16 : org::ofono::Modem(OFONO_SERVICE,
18 QDBusConnection::systemBus()),
23 qDebug() << "Failed to connect to Ofono: \n\t" << lastError().message();
26 QDBusPendingReply<QVariantMap> reply;
27 QDBusPendingCallWatcher * watcher;
29 reply = GetProperties();
30 watcher = new QDBusPendingCallWatcher(reply);
32 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
33 this, SLOT(modemDBusGetPropDone(QDBusPendingCallWatcher*)));
36 SIGNAL(PropertyChanged(const QString&,const QDBusVariant&)),
37 SLOT(propertyChanged(const QString&,const QDBusVariant&)));
41 ModemProxy::~ModemProxy()
46 QStringList ModemProxy::interfaces() const { return m_interfaces; }
47 QString ModemProxy::path() const { return m_path; }
48 QString ModemProxy::manufacturer() const { return m_manufacturer; }
49 QString ModemProxy::model() const { return m_model; }
50 QString ModemProxy::revision() const { return m_revision; }
51 QString ModemProxy::serial() const { return m_serial; }
52 bool ModemProxy::powered() const { return m_powered; }
53 bool ModemProxy::online() const { return m_online; }
55 void ModemProxy::setPowered(bool is_powered)
58 if (m_powered == is_powered)
61 QVariant powered(is_powered);
63 QDBusPendingReply<QVariantMap> reply;
64 reply = SetProperty("Powered", QDBusVariant(powered));
67 qCritical() << "SetProperty \"Powered\" failed!";
70 void ModemProxy::setOnline(bool is_online)
73 if (m_online == is_online)
76 QDBusPendingReply<QVariantMap> reply;
77 reply = SetProperty("Online", QDBusVariant(m_online?"true":"false"));
79 qCritical() << "SetProperty \"Powered\" failed!";
84 void ModemProxy::modemDBusGetPropDone(QDBusPendingCallWatcher *call)
87 QDBusPendingReply<QVariantMap> reply = *call;
89 if (reply.isError()) {
90 // TODO: Handle this properly, by setting states, or disabling features...
91 qDebug() << "org.ofono.ModemProxy.getProperties() failed: " <<
92 reply.error().message();
94 QVariantMap properties = reply.value();
95 m_interfaces = qdbus_cast<QStringList >(properties["Interfaces"]);
96 m_manufacturer = qdbus_cast<QString>(properties["Manufacturer"]);
97 m_model = qdbus_cast<QString>(properties["Model"]);
98 m_powered = qdbus_cast<bool>(properties["Powered"]);
99 m_revision = qdbus_cast<QString>(properties["Revision"]);
100 m_serial = qdbus_cast<QString>(properties["Serial"]);
101 m_online = qdbus_cast<bool>(properties["Online"]);
103 // First sucessfull GetProperties == connected
111 void ModemProxy::propertyChanged(const QString &in0, const QDBusVariant &in1)
114 qDebug() << "org.ofono.ModemProxy.propertyChanged()"
115 << in0 << ": " << in1.variant();
116 if (in0 == "Interfaces") {
117 m_interfaces = qdbus_cast<QStringList>(in1.variant());
118 emit interfacesChanged(m_interfaces);
120 else if (in0 == "Powered") {
121 m_powered = qdbus_cast<bool>(in1.variant());
122 emit poweredChanged(m_powered);
123 } else if (in0 == "Online") {
124 m_online = qdbus_cast<bool>(in1.variant());
125 emit onlineChanged(m_online);
127 qDebug() << QString("Unhandled property \"%1\" changed...").arg(in0);
132 * VoicemailProxy (aka MessageWaiting) implementation
135 VoicemailProxy::VoicemailProxy(const QString &objectPath)
136 : org::ofono::MessageWaiting(OFONO_SERVICE,
138 QDBusConnection::systemBus()),
143 qDebug() << "Failed to connect to Ofono: \n\t" << lastError().message();
146 QDBusPendingReply<QVariantMap> reply;
147 QDBusPendingCallWatcher * watcher;
149 reply = GetProperties();
150 watcher = new QDBusPendingCallWatcher(reply);
152 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
153 this, SLOT(voicemailDBusGetPropDone(QDBusPendingCallWatcher*)));
154 connect(this, SIGNAL(PropertyChanged(const QString&, const QDBusVariant&)),
155 SLOT(voicemailPropertyChanged(const QString&, const QDBusVariant&)));
159 VoicemailProxy::~VoicemailProxy()
164 bool VoicemailProxy::isConnected() const { return m_connected; }
165 QString VoicemailProxy::path() const { return m_path; }
166 QString VoicemailProxy::mailbox() const { return m_mailbox; }
167 int VoicemailProxy::count() const { return m_count; }
168 bool VoicemailProxy::waiting() const { return m_waiting; }
170 void VoicemailProxy::setMailbox(QString lineid)
173 if (lineid.isEmpty() || (m_mailbox == lineid))
176 QDBusPendingReply<> reply;
177 reply = SetProperty("VoicemailMailboxNumber", QDBusVariant(lineid));
178 reply.waitForFinished();
181 qCritical() << "SetProperty \"VoicemailMailboxNumber\" failed: " <<
182 reply.error().message();
187 void VoicemailProxy::voicemailDBusGetPropDone(QDBusPendingCallWatcher *call)
190 QDBusPendingReply<QVariantMap> reply = *call;
192 if (reply.isError()) {
193 // TODO: Handle this properly, by setting states, or disabling features...
194 qDebug() << "org.ofono.MessageWaiting.getProperties() failed: " <<
195 reply.error().message();
197 QVariantMap properties = reply.value();
198 bool waiting = qdbus_cast<bool>(properties["VoicemailWaiting"]);
199 int count = qdbus_cast<int>(properties["VoicemailMessageCount"]);
200 QString mailbox = qdbus_cast<QString>(properties["VoicemailMailboxNumber"]);
202 if (count != m_count) {
204 emit messagesWaitingChanged();
206 if (waiting != m_waiting) {
208 emit messagesWaitingChanged();
210 if (!mailbox.isEmpty() && (mailbox != m_mailbox)) {
212 emit mailboxChanged();
215 // First sucessfull GetProperties == connected
223 void VoicemailProxy::voicemailPropertyChanged(const QString &in0, const QDBusVariant &in1)
226 qDebug() << QString("Property \"%1\" changed...").arg(in0);
230 if (in0 == "VoicemailWaiting") {
231 waiting = qdbus_cast<bool>(in1.variant());
232 } else if (in0 == "VoicemailMessageCount") {
233 count = qdbus_cast<int>(in1.variant());
234 } else if (in0 == "VoicemailMailboxNumber") {
235 mailbox = qdbus_cast<QString>(in1.variant());
237 qDebug() << QString("Unexpected property changed...");
239 if ((count != m_count) || (waiting != m_waiting)) {
242 emit messagesWaitingChanged();
244 if (!mailbox.isEmpty() && (mailbox != m_mailbox)) {
246 emit mailboxChanged();
251 * CallVolume Manager implementation
254 VolumeManager::VolumeManager(const QString &objectPath)
255 : org::ofono::CallVolume(OFONO_SERVICE,
257 QDBusConnection::systemBus())
261 qDebug() << "Failed to connect to Ofono: \n\t" << lastError().message();
264 QDBusPendingReply<QVariantMap> reply;
265 QDBusPendingCallWatcher * watcher;
267 reply = GetProperties();
268 watcher = new QDBusPendingCallWatcher(reply);
270 connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
271 this, SLOT(volumeDBusGetPropDone(QDBusPendingCallWatcher*)));
275 VolumeManager::~VolumeManager()
280 QString VolumeManager::path() const { return m_path; }
281 int VolumeManager::speakerVolume() const { return m_speakerVolume; }
282 int VolumeManager::micVolume() const { return m_micVolume; }
283 bool VolumeManager::muted() const { return m_muted; }
284 bool VolumeManager::isConnected() const { return m_connected; }
286 void VolumeManager::setSpeakerVolume(int volume)
289 if (m_speakerVolume == volume)
292 if ((volume < 0) || (volume > 100)) {
293 qWarning() << "SpeakerVolume value out of range (0<>100)";
297 QDBusPendingReply<> reply;
298 reply = SetProperty("SpeakerVolume", QDBusVariant(volume));
299 reply.waitForFinished();
302 qCritical() << "SetProperty \"SpeakerVolume\" failed: " <<
303 reply.error().message();
305 m_speakerVolume = volume;
308 void VolumeManager::setMicVolume(int volume)
311 if (m_micVolume == volume)
314 if ((volume < 0) || (volume > 100)) {
315 qWarning() << "MicrophoneVolume value out of range (0<>100)";
319 QDBusPendingReply<> reply;
320 reply = SetProperty("MicrophoneVolume", QDBusVariant(volume));
321 reply.waitForFinished();
324 qCritical() << "SetProperty \"MicrophoneVolume\" failed: " <<
325 reply.error().message();
327 m_micVolume = volume;
330 void VolumeManager::setMuted(bool is_muted)
333 if (m_muted == is_muted)
336 QDBusPendingReply<> reply;
337 reply = SetProperty("Muted", QDBusVariant(is_muted));
338 reply.waitForFinished();
341 qCritical() << "SetProperty \"Muted\" failed: " <<
342 reply.error().message();
347 void VolumeManager::volumeDBusGetPropDone(QDBusPendingCallWatcher *call)
350 QDBusPendingReply<QVariantMap> reply = *call;
352 if (reply.isError()) {
353 // TODO: Handle this properly, by setting states, or disabling features...
354 qDebug() << "org.ofono.CallVolume.getProperties() failed: " <<
355 reply.error().message();
357 QVariantMap properties = reply.value();
358 m_speakerVolume = qdbus_cast<int>(properties["SpeakerVolume"]);
359 m_micVolume = qdbus_cast<int>(properties["MicrophoneVolume"]);
360 m_muted = qdbus_cast<bool>(properties["Muted"]);
362 // First sucessfull GetProperties == connected
370 /* Local Variables: */
372 /* c-basic-offset:4 */
373 /* indent-tabs-mode: nil */