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
12 #include "dialercontext.h"
14 #define AUTOSELECT OfonoModem::AutomaticSelect
16 #ifndef CONFIG_KEY_TARGET_MODE
17 #define CONFIG_KEY_TARGET_MODE "/apps/dialer/mode"
22 DialerContext *DialerContext::gContext = 0;
24 class DialerContextPrivate
27 DialerContextPrivate()
32 modesKey(CONFIG_KEY_TARGET_MODE)
35 ~DialerContextPrivate() {
38 delete voicemailManager;
46 OfonoModemManager *modemManager;
47 OfonoCallVolume *volumeManager;
48 OfonoMessageWaiting *voicemailManager;
49 CallManager *callManager;
50 // ResourceProxy *policyManager;
56 DialerContext::DialerContext(QObject *parent)
58 d(new DialerContextPrivate)
61 qFatal(__func__, ": There can be only one!");
63 // Read and configure default runtime modes
64 setModes(d->modesKey.value().toStringList());
66 // Create misc services
67 // TODO: We may not actually need this, since OfonoModem class
68 // allows for "auto selection" and switching of modems
69 d->modemManager = new OfonoModemManager(parent);
70 d->volumeManager = new OfonoCallVolume(AUTOSELECT,"");
71 d->voicemailManager = new OfonoMessageWaiting(AUTOSELECT,"");
72 d->callManager = new CallManager();
74 // OfonoModemManager signals to monitor
75 connect(d->modemManager, SIGNAL(modemAdded(const QString&)),
76 SLOT(onModemAdded(const QString&)));
77 connect(d->modemManager, SIGNAL(modemRemoved(const QString&)),
78 SLOT(onModemRemoved(const QString&)));
80 // CallManager signals to monitor
81 connect(d->callManager, SIGNAL(validityChanged(bool)),
82 SLOT(onCallManagerValidityChanged(bool)));
83 connect(d->callManager, SIGNAL(callsChanged()), SLOT(onCallsChanged()));
85 // OfonoCallVolume signals to monitor
86 connect(d->volumeManager, SIGNAL(validityChanged(bool)),
87 SLOT(onCallVolumeValidityChanged(bool)));
89 // OfonoMessageWaiting signals to monitor
90 connect(d->voicemailManager, SIGNAL(validityChanged(bool)),
91 SLOT(onVoicemailValidityChanged(bool)));
92 connect(d->voicemailManager, SIGNAL(voicemailWaitingChanged(bool)),
93 SLOT(onVoicemailWaitingChanged(bool)));
94 connect(d->voicemailManager, SIGNAL(voicemailMessageCountChanged(int)),
95 SLOT(onVoicemailCountChanged(int)));
97 // GConf Key change signals to monitor
98 connect(&d->modesKey, SIGNAL(valueChanged()), SLOT(onModesChanged()));
100 // ResourceProxy is a singleton, probably don't need to store this...
101 //d->policyManager = ResourceProxy::instance();
104 qDebug() << __func__ << ": Using modem - "
105 << d->callManager->modem()->path();
113 DialerContext::~DialerContext()
120 DialerContext *DialerContext::instance()
123 gContext = new DialerContext();
127 OfonoModemManager* DialerContext::modemManager() const
129 return d->modemManager;
132 OfonoCallVolume* DialerContext::volumeManager() const
134 return d->volumeManager;
137 OfonoMessageWaiting* DialerContext::voicemailManager() const
139 return d->voicemailManager;
142 CallManager* DialerContext::callManager() const
144 return d->callManager;
148 ResourceProxy* DialerContext::policyManager() const
150 return d->policyManager;
154 QStringList DialerContext::modes() const
159 void DialerContext::setModes(const QStringList &modelist)
162 d->modes.removeDuplicates();
167 OfonoModem* DialerContext::modem() const
170 return d->callManager->modem();
176 * Private methods/slots
179 void DialerContext::onModemAdded(const QString &path)
182 // TODO: Handle modem additions, maybe...
183 qWarning() << __func__ << ": Unhandled ModemAdded - " << path;
186 void DialerContext::onModemRemoved(const QString &path)
189 // TODO: Handle modem removals, currently active for sure, others, maybe...
190 qWarning() << __func__ << ": Unhandled ModemAdded - " << path;
193 void DialerContext::onCallVolumeValidityChanged(bool valid)
196 // TODO: Reset the volumeManager service reference
197 qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
200 void DialerContext::onVoicemailValidityChanged(bool valid)
203 // TODO: Reset the voicemailManager service reference
204 qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
207 void DialerContext::onVoicemailWaitingChanged(bool waiting)
210 // TODO: Send notifications (or bubble this up for UI to handle?)
211 qDebug() << __func__ << ": Messages? " << ((waiting)?"true":"false");
214 void DialerContext::onVoicemailCountChanged(int count)
217 // TODO: Send notifications (or bubble this up for UI to handle?)
218 qDebug() << __func__ << ": Message count == " << count;
221 void DialerContext::onCallManagerValidityChanged(bool valid)
224 // TODO: Reset the callManager service reference
225 qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
228 void DialerContext::onCallsChanged()
231 // TODO: Send notifications (or bubble this up for UI to handle?)
232 qDebug() << __func__ << ": Calls count == "
233 << d->callManager->getCalls().count();
236 void DialerContext::onModesChanged()
239 setModes(d->modesKey.value().toStringList());
240 // Send notification of change
242 qDebug() << __func__ << ": New modes == " << d->modes.join(", ");