Added the ability to edit the PID number using the number pad.
[profile/ivi/hfdialer.git] / src / dialercontext.cpp
1 /*
2  * hfdialer - Hands Free Voice Call Manager
3  * Copyright (c) 2012, Intel Corporation.
4  *
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
8  *
9  */
10
11 #include "common.h"
12 #include "dialercontext.h"
13
14 #define AUTOSELECT OfonoModem::AutomaticSelect
15
16 #ifndef CONFIG_KEY_TARGET_MODE
17 #define CONFIG_KEY_TARGET_MODE "/apps/dialer/mode"
18 #endif
19
20 #include <QDebug>
21
22 DialerContext *DialerContext::gContext = 0;
23
24 class DialerContextPrivate
25 {
26 public:
27     DialerContextPrivate()
28         : modemManager(0),
29           volumeManager(0),
30           voicemailManager(0),
31           callManager(0),
32           modesKey(CONFIG_KEY_TARGET_MODE)
33     { TRACE }
34
35     ~DialerContextPrivate() {
36         delete volumeManager;
37         volumeManager = 0;
38         delete voicemailManager;
39         voicemailManager = 0;
40         delete callManager;
41         callManager = 0;
42         delete modemManager;
43         modemManager = 0;
44     }
45
46     OfonoModemManager   *modemManager;
47     OfonoCallVolume     *volumeManager;
48     OfonoMessageWaiting *voicemailManager;
49     CallManager         *callManager;
50 //    ResourceProxy       *policyManager;
51     QStringList          modes;
52     MGConfItem           modesKey;
53 };
54
55
56 DialerContext::DialerContext(QObject *parent)
57     : QObject(parent),
58       d(new DialerContextPrivate)
59 {
60     if (gContext)
61         qFatal(__func__, ": There can be only one!");
62
63     // Read and configure default runtime modes
64     setModes(d->modesKey.value().toStringList());
65
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();
73
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&)));
79
80     // CallManager signals to monitor
81     connect(d->callManager, SIGNAL(validityChanged(bool)),
82                             SLOT(onCallManagerValidityChanged(bool)));
83     connect(d->callManager, SIGNAL(callsChanged()), SLOT(onCallsChanged()));
84
85     // OfonoCallVolume signals to monitor
86     connect(d->volumeManager, SIGNAL(validityChanged(bool)),
87                               SLOT(onCallVolumeValidityChanged(bool)));
88
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)));
96
97     // GConf Key change signals to monitor
98     connect(&d->modesKey, SIGNAL(valueChanged()), SLOT(onModesChanged()));
99
100     // ResourceProxy is a singleton, probably don't need to store this...
101     //d->policyManager = ResourceProxy::instance();
102
103     if (d->callManager)
104         qDebug() << __func__ << ": Using modem - "
105                  << d->callManager->modem()->path();
106
107     gContext = this;
108 }
109
110 /*
111  * Public methods
112  */
113 DialerContext::~DialerContext()
114 {
115     delete d;
116     d = 0;
117     gContext=0;
118 }
119
120 DialerContext *DialerContext::instance()
121 {
122     if (!gContext)
123         gContext = new DialerContext();
124     return gContext;
125 }
126
127 OfonoModemManager* DialerContext::modemManager() const
128 {
129     return d->modemManager;
130 }
131
132 OfonoCallVolume* DialerContext::volumeManager() const
133 {
134     return d->volumeManager;
135 }
136
137 OfonoMessageWaiting* DialerContext::voicemailManager() const
138 {
139     return d->voicemailManager;
140 }
141
142 CallManager* DialerContext::callManager() const
143 {
144     return d->callManager;
145 }
146
147 /*
148 ResourceProxy* DialerContext::policyManager() const
149 {
150     return d->policyManager;
151 }
152 */
153
154 QStringList DialerContext::modes() const
155 {
156     return d->modes;
157 }
158
159 void DialerContext::setModes(const QStringList &modelist)
160 {
161     d->modes = modelist;
162     d->modes.removeDuplicates();
163     emit modesChanged();
164 }
165
166 /*
167 OfonoModem* DialerContext::modem() const
168 {
169     if (d->callManager)
170         return d->callManager->modem();
171     return NULL;
172 }
173 */
174
175 /*
176  * Private methods/slots
177  */
178
179 void DialerContext::onModemAdded(const QString &path)
180 {
181     TRACE
182     // TODO: Handle modem additions, maybe...
183     qWarning() << __func__ << ": Unhandled ModemAdded - " << path;
184 }
185
186 void DialerContext::onModemRemoved(const QString &path)
187 {
188     TRACE
189     // TODO: Handle modem removals, currently active for sure, others, maybe...
190     qWarning() << __func__ << ": Unhandled ModemAdded - " << path;
191 }
192
193 void DialerContext::onCallVolumeValidityChanged(bool valid)
194 {
195     TRACE
196     // TODO: Reset the volumeManager service reference
197     qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
198 }
199
200 void DialerContext::onVoicemailValidityChanged(bool valid)
201 {
202     TRACE
203     // TODO: Reset the voicemailManager service reference
204     qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
205 }
206
207 void DialerContext::onVoicemailWaitingChanged(bool waiting)
208 {
209     TRACE
210     // TODO: Send notifications (or bubble this up for UI to handle?)
211     qDebug() << __func__ << ": Messages? " << ((waiting)?"true":"false");
212 }
213
214 void DialerContext::onVoicemailCountChanged(int count)
215 {
216     TRACE
217     // TODO: Send notifications (or bubble this up for UI to handle?)
218     qDebug() << __func__ << ": Message count == " << count;
219 }
220
221 void DialerContext::onCallManagerValidityChanged(bool valid)
222 {
223     TRACE
224     // TODO: Reset the callManager service reference
225     qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
226 }
227
228 void DialerContext::onCallsChanged()
229 {
230     TRACE
231     // TODO: Send notifications (or bubble this up for UI to handle?)
232     qDebug() << __func__ << ": Calls count == "
233              << d->callManager->getCalls().count();
234 }
235
236 void DialerContext::onModesChanged()
237 {
238     TRACE
239     setModes(d->modesKey.value().toStringList());
240     // Send notification of change
241     emit modesChanged();
242     qDebug() << __func__ << ": New modes == " << d->modes.join(", ");
243 }