Initial Import
[profile/ivi/hfdialer.git] / src / callitem.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 "callitem.h"
13 #include "dialerapplication.h"
14 #include "pacontrol.h"
15 #include <QGraphicsItem>
16 #include <QGraphicsWidget>
17 #include <QDebug>
18
19 #define DEFAULT_RINGTONE "ring-1.wav"
20
21 CallItem::CallItem(const QString path, QObject *parent)
22     : QObject(parent),
23       m_path(path),
24       m_rtKey(new MGConfItem("/apps/dialer/defaultRingtone")),
25       m_isconnected(FALSE)
26 {
27     TRACE;
28     QString l_ringtoneFile = QString("/usr/share/hfdialer/sounds/%1").arg(DEFAULT_RINGTONE);
29     QString l_rtKeyValue = m_rtKey->value(QVariant(l_ringtoneFile)).toString();
30
31     if (!QFileInfo(l_rtKeyValue).exists()) {
32         qWarning() << QString("CallItem: %1 ringtone not found: %2")
33             .arg(m_path)
34             .arg(l_rtKeyValue);
35     }
36
37     if (isValid()) {
38         init();
39     }
40 }
41
42 CallItem::~CallItem()
43 {
44     TRACE;
45     PAControl::instance()->unrouteAudio();
46    
47     if (m_rtKey) {
48         delete m_rtKey;
49     }
50     m_rtKey = 0;
51
52     // delete the callproxy object
53     if (callProxy())
54         delete callProxy();
55 }
56
57 void CallItem::init()
58 {
59     TRACE;
60     if (!m_path.isEmpty()) {
61         m_call = new CallProxy(m_path);
62         if (m_call->isValid()) {
63             // dynamic_cast<CallItemModel*>(model())->setCall(call);
64             connect(m_call,SIGNAL(stateChanged()),this,SLOT(callStateChanged()));
65             connect(m_call,SIGNAL(dataChanged()),this,SLOT(callDataChanged()));
66             connect(m_call,SIGNAL(multipartyChanged()),this,SLOT(callMultipartyChanged()));
67         } else {
68             qCritical("Invalid CallProxy instance!");
69         }
70     } else {
71         qCritical("Empty call path.  Can not create CallProxy!");
72     }
73 }
74
75 bool CallItem::isValid()
76 {
77     TRACE;
78     return (!path().isEmpty());
79 }
80
81 bool CallItem::isValid() const
82 {
83     TRACE;
84     return (!path().isEmpty());
85 }
86
87 QString CallItem::path() const
88 {
89     TRACE;
90     return m_path;
91 }
92
93 bool CallItem::setPath(QString path)
94 {
95     TRACE;
96     if (!m_path.isEmpty()) {
97         qCritical("Path already set and can not be changed once it is set");
98         return false;
99     } else if (path.isEmpty()) {
100         qCritical("It makes no sense to set Path to an empty string!?!?");
101         return false;
102     }
103
104     m_path = path;
105
106     init();
107
108     return true;
109 }
110
111 void CallItem::setDirection(CallDirection direction)
112 {
113     TRACE; 
114 }
115
116 QString CallItem::lineID() const
117 {
118     TRACE;
119     return m_call->lineID();
120 }
121
122 QString CallItem::name() const
123 {
124     TRACE;
125     return m_call->name();
126 }
127
128 CallState CallItem::state() const
129 {
130     TRACE;
131     CallState cs = STATE_NONE;
132     QString state = m_call->state();
133
134     if (state == "active")
135         cs = STATE_ACTIVE;
136            
137     else if (state == "held")
138         cs = STATE_HELD;
139     else if (state == "dialing")
140         cs = STATE_DIALING;
141     else if (state == "alerting")
142         cs = STATE_ALERTING;
143     else if (state == "incoming")
144         cs = STATE_INCOMING;
145     else if (state == "waiting")
146         cs = STATE_WAITING;
147     else if (state == "disconnected")
148         cs = STATE_DISCONNECTED;
149
150     return cs;
151 }
152
153 CallDirection CallItem::direction() const
154 {
155     TRACE;
156     return DIRECTION_NONE;
157 }
158
159 CallDisconnectReason CallItem::reason() const
160 {
161     TRACE;
162     return DISCONNECT_NONE; 
163 }
164
165 int CallItem::duration() const
166 {
167     TRACE;
168     return m_call->duration();
169 }
170
171 QDateTime CallItem::startTime() const
172 {
173     TRACE;
174     return m_call->startTime();
175 }
176
177 CallProxy* CallItem::callProxy() const
178 {
179     TRACE;
180     return m_call;
181 }
182
183 void CallItem::click()
184 {
185     TRACE;
186
187     emit clicked();
188 }
189
190 void CallItem::silenceRingtone()
191 {
192     TRACE;
193 }
194
195 void CallItem::callStateChanged()
196 {
197     TRACE;
198     emit stateChanged();
199 }
200
201 void CallItem::callDataChanged()
202 {
203     TRACE;
204 }
205
206 void CallItem::callDisconnected(const QString &reason)
207 {
208     TRACE;
209     Q_UNUSED(reason);
210 }
211
212
213 bool CallItem::multiparty()
214 {
215     TRACE; 
216     return false;   
217 }
218
219 void CallItem::callMultipartyChanged()
220 {
221     TRACE;
222     emit multipartyChanged();
223 }
224
225 /* Local Variables:      */
226 /* mode:c++              */
227 /* c-basic-offset:4      */
228 /* indent-tabs-mode: nil */
229 /* End:                  */