opacity for MessageDialog { id: mesgDialog state: 'hidden' } will make dial page...
[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     QStringList          modes;
51     MGConfItem           modesKey;
52 };
53
54
55 DialerContext::DialerContext(QObject *parent)
56     : QObject(parent),
57       d(new DialerContextPrivate)
58 {
59     if (gContext)
60         qFatal(__func__, ": There can be only one!");
61
62     // Read and configure default runtime modes
63     setModes(d->modesKey.value().toStringList());
64
65     // Create misc services
66     // TODO: We may not actually need this, since OfonoModem class
67     //       allows for "auto selection" and switching of modems
68     d->modemManager = new OfonoModemManager(parent);
69     d->volumeManager = new OfonoCallVolume(AUTOSELECT,"");
70     d->voicemailManager = new OfonoMessageWaiting(AUTOSELECT,"");
71     d->callManager = new CallManager();
72
73     // OfonoModemManager signals to monitor
74     connect(d->modemManager, SIGNAL(modemAdded(const QString&)),
75             SLOT(onModemAdded(const QString&)));
76     connect(d->modemManager, SIGNAL(modemRemoved(const QString&)),
77             SLOT(onModemRemoved(const QString&)));
78
79     // CallManager signals to monitor
80     connect(d->callManager, SIGNAL(validityChanged(bool)),
81             SLOT(onCallManagerValidityChanged(bool)));
82     connect(d->callManager, SIGNAL(callsChanged()), SLOT(onCallsChanged()));
83
84     // OfonoCallVolume signals to monitor
85     connect(d->volumeManager, SIGNAL(validityChanged(bool)),
86             SLOT(onCallVolumeValidityChanged(bool)));
87
88     // OfonoMessageWaiting signals to monitor
89     connect(d->voicemailManager, SIGNAL(validityChanged(bool)),
90             SLOT(onVoicemailValidityChanged(bool)));
91     connect(d->voicemailManager, SIGNAL(voicemailWaitingChanged(bool)),
92             SLOT(onVoicemailWaitingChanged(bool)));
93     connect(d->voicemailManager, SIGNAL(voicemailMessageCountChanged(int)),
94             SLOT(onVoicemailCountChanged(int)));
95
96     // GConf Key change signals to monitor
97     connect(&d->modesKey, SIGNAL(valueChanged()), SLOT(onModesChanged()));
98
99     if (d->callManager)
100         qDebug() << __func__ << ": Using modem - "
101                  << d->callManager->modem()->path();
102
103     gContext = this;
104 }
105
106 /*
107  * Public methods
108  */
109 DialerContext::~DialerContext()
110 {
111     delete d;
112     d = 0;
113     gContext=0;
114 }
115
116 DialerContext *DialerContext::instance()
117 {
118     if (!gContext)
119         gContext = new DialerContext();
120     return gContext;
121 }
122
123 OfonoModemManager* DialerContext::modemManager() const
124 {
125     return d->modemManager;
126 }
127
128 OfonoCallVolume* DialerContext::volumeManager() const
129 {
130     return d->volumeManager;
131 }
132
133 OfonoMessageWaiting* DialerContext::voicemailManager() const
134 {
135     return d->voicemailManager;
136 }
137
138 CallManager* DialerContext::callManager() const
139 {
140     return d->callManager;
141 }
142
143 QStringList DialerContext::modes() const
144 {
145     return d->modes;
146 }
147
148 void DialerContext::setModes(const QStringList &modelist)
149 {
150     d->modes = modelist;
151     d->modes.removeDuplicates();
152     emit modesChanged();
153 }
154
155 /*
156  * Private methods/slots
157  */
158
159 void DialerContext::onModemAdded(const QString &path)
160 {
161     TRACE;
162     // TODO: Handle modem additions, maybe...
163     qWarning() << __func__ << ": Unhandled ModemAdded - " << path;
164 }
165
166 void DialerContext::onModemRemoved(const QString &path)
167 {
168     TRACE;
169     // TODO: Handle modem removals, currently active for sure, others, maybe...
170     qWarning() << __func__ << ": Unhandled ModemAdded - " << path;
171 }
172
173 void DialerContext::onCallVolumeValidityChanged(bool valid)
174 {
175     TRACE;
176     // TODO: Reset the volumeManager service reference
177     qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
178 }
179
180 void DialerContext::onVoicemailValidityChanged(bool valid)
181 {
182     TRACE;
183     // TODO: Reset the voicemailManager service reference
184     qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
185 }
186
187 void DialerContext::onVoicemailWaitingChanged(bool waiting)
188 {
189     TRACE;
190     // TODO: Send notifications (or bubble this up for UI to handle?)
191     qDebug() << __func__ << ": Messages? " << ((waiting)?"true":"false");
192 }
193
194 void DialerContext::onVoicemailCountChanged(int count)
195 {
196     TRACE;
197     // TODO: Send notifications (or bubble this up for UI to handle?)
198     qDebug() << __func__ << ": Message count == " << count;
199 }
200
201 void DialerContext::onCallManagerValidityChanged(bool valid)
202 {
203     TRACE;
204     // TODO: Reset the callManager service reference
205     qWarning() << __func__ << ": valid? " << ((valid)?"true":"false");
206 }
207
208 void DialerContext::onCallsChanged()
209 {
210     TRACE;
211     // TODO: Send notifications (or bubble this up for UI to handle?)
212     qDebug() << __func__ << ": Calls count == "
213              << d->callManager->getCalls().count();
214 }
215
216 void DialerContext::onModesChanged()
217 {
218     TRACE;
219     setModes(d->modesKey.value().toStringList());
220     // Send notification of change
221     emit modesChanged();
222     qDebug() << __func__ << ": New modes == " << d->modes.join(", ");
223 }
224
225 /* Local Variables:      */
226 /* mode:c++              */
227 /* c-basic-offset:4      */
228 /* indent-tabs-mode: nil */
229 /* End:                  */