Added an .xpm file. Still am not able to see the icon in the menu.
[confmgr] / confmanager.cpp
1 #include "confmanager.h"
2 #include <QDebug>
3 #include <QTimer>
4
5 confManager::confManager(QObject *parent) :
6     QObject(parent)
7 {
8     mProfileSet = false;
9     mInStep = 0;
10 }
11
12 void confManager::setProfile(Profile &p)
13 {
14     mInStep = 0;
15     mProfileInUse = p;
16     mProfileSet = true;
17 }
18
19 void confManager::continueSendDTMF()
20 {
21     qDebug() << "In ContinueSendDTF for mInStep " << mInStep;
22     // We have now waited for the required period of seconds
23     // Lets send the DTMF now
24     Steps step = mProfileInUse.mSteps.at(mInStep);
25
26     // Increment the steps as we want to point to the next one
27     mInStep++;
28
29     QList<QVariant> argsToSend;
30     qDebug() << "DTMF = " << step.value();
31     argsToSend.append(step.value());
32 //    argsToSend.append(0);
33
34     bool status = mDBusUtility.sendMethodCall(CSD_SERVICE, CSD_CALL_PATH, CSD_CALL_INTERFACE,
35                                          QString("SendDTMF"),argsToSend);
36
37     if(!status)
38     {
39         qDebug() << "Unable to send DTMF code.";
40         QString error = "DBus Error (continueSendDTMF): " + mDBusUtility.getErrorMessage();
41         mDBusUtility.displayNotification(error);
42     }
43
44     mDBusUtility.displayNotification(step.value());
45
46     // Check if we are over with the sequence or we need to continue
47     if(mInStep >= mProfileInUse.mNoOfSteps)
48     {
49         StopCallMonitors();
50         return;
51     }
52
53     step = mProfileInUse.mSteps.at(mInStep);
54     QTimer *timer = new QTimer(this);
55     timer->setSingleShot(true);
56     connect(timer, SIGNAL(timeout()), this, SLOT(continueSendDTMF()));
57     qDebug() << "Setting delay for " << step.delay() << "seconds...";
58     timer->start(step.delay()*1000);
59 }
60
61 void confManager::sendDTMF(const QDBusMessage &dBusMessage)
62 {
63     QList<QVariant> listArguments = dBusMessage.arguments();
64     bool audioConnect =  listArguments.first().toBool();
65
66     if(mInStep >= mProfileInUse.mNoOfSteps)
67     {
68         StopCallMonitors();
69         return;
70     }
71
72     Steps step = mProfileInUse.mSteps.at(mInStep);
73
74     if (audioConnect)
75     {
76         qDebug() << "Call Active...";
77         //Wait for specified delay in the step
78         QTimer *timer = new QTimer(this);
79         timer->setSingleShot(true);
80         connect(timer, SIGNAL(timeout()), this, SLOT(continueSendDTMF()));
81         qDebug() << "Setting delay for " << step.delay() << "seconds...";
82         timer->start(step.delay()*1000);
83     }
84 }
85
86 void confManager::StartCallMonitors()
87 {
88     QDBusConnection connection = mDBusUtility.getConnection();
89     /* Declare the slot to be executed when a call is picked up by other party (Audio connection established).
90        We need this to confirm whether a call went though successfully.
91     */
92     bool status = connection.connect(CSD_CALL_SERVICE, CSD_CALL_INSTANCE_PATH, CSD_CALL_INSTANCE_INTERFACE,
93                            QString("AudioConnect"),this, SLOT(sendDTMF(const QDBusMessage&)));
94
95     if(!status)
96     {
97         qDebug() << "Failed to connect to Dbus signal AudioConnect in interface "<< CSD_CALL_INSTANCE_INTERFACE;
98         QString error = "DBus Error (StartCallMonitors): " + mDBusUtility.getErrorMessage();
99         mDBusUtility.displayNotification(error);
100         qDebug() << "Error is: " << error;
101     }
102
103     qDebug() << "Successfully connected to Dbus signal AudioConnect in interface "<< CSD_CALL_INSTANCE_INTERFACE;
104
105     /* Declare the slot to be executed when the call is terminated (due to connection errors etc).
106        We need this to avoid sending DTMF code on wrong calls.
107     */
108     status = connection.connect(CSD_CALL_SERVICE, CSD_CALL_INSTANCE_PATH, CSD_CALL_INSTANCE_INTERFACE,
109                                QString("Terminated"),this, SLOT(StopCallMonitors()));
110
111     if(!status)
112     {
113         qDebug() << "Failed to connect to Dbus signal Terminated in interface "<< CSD_CALL_INSTANCE_INTERFACE;
114         QString error = "DBus Error (StartCallMonitors): " + mDBusUtility.getErrorMessage();
115         mDBusUtility.displayNotification(error);
116         qDebug() << "Error is: " << error;
117     }
118
119     qDebug() << "Successfully connected to Dbus signal Terminated in interface "<< CSD_CALL_INSTANCE_INTERFACE;
120
121     /* Declare the slot to be executed when a call is received
122       (before we can place the call to calling card number).
123        It is extremely rare that somebody should get a call within these few seconds.
124        In any case, we need this to avoid sending DTMF code on the received call.
125
126        Btw - I don't care for the incoming number here. If anyone is calling the user before we can send DTMF code,
127        then we stop sending the DTMF code even if user does not respond to the call.
128     */
129
130     status = connection.connect(CSD_CALL_SERVICE, CSD_CALL_PATH, CSD_CALL_INTERFACE,
131                                QString("Coming"),this, SLOT(StopCallMonitors()));
132
133     if(!status)
134     {
135         qDebug() << "Failed to connect to Dbus signal Coming in interface" << CSD_CALL_INTERFACE;
136         QString error = "DBus Error (StartCallMonitors): " + mDBusUtility.getErrorMessage();
137         mDBusUtility.displayNotification(error);
138         qDebug() << "Error is: " << error;
139     }
140     qDebug() << "Successfully connected to Dbus signal Coming in interface" << CSD_CALL_INTERFACE;
141 }
142
143 void confManager::StopCallMonitors()
144 {
145 //    mInStep = 0;
146     mProfileSet = false;
147
148     QDBusConnection connection = mDBusUtility.getConnection();
149
150     // Disconnect the slot for audio connection status
151     bool status = connection.disconnect(CSD_CALL_BUS_NAME, CSD_CALL_INSTANCE_PATH, CSD_CALL_INSTANCE_INTERFACE,
152                                    QString("AudioConnect"),this, SLOT(sendDTMF(const QDBusMessage&)));
153
154     if(!status)
155     {
156         qDebug() << "Failed to disconnect from Dbus signal AudioConnect in interface" << CSD_CALL_INSTANCE_INTERFACE;
157         QString error = "DBus Error (StopCallMonitors): " + mDBusUtility.getErrorMessage();
158         mDBusUtility.displayNotification(error);
159         qDebug() << "Error is: " << error;
160     }
161     qDebug() << "Successfully disconnected from Dbus signal AudioConnect in interface "<< CSD_CALL_INSTANCE_INTERFACE;
162
163     // Disconnect the slot for monitoring terminated calls
164     status = connection.disconnect(CSD_CALL_BUS_NAME, CSD_CALL_INSTANCE_PATH, CSD_CALL_INSTANCE_INTERFACE,
165                                    QString("Terminated"),this, SLOT(StopCallMonitors()));
166
167     if(!status)
168     {
169         qDebug() << "Failed to disconnect from Dbus signal Terminated in interface" << CSD_CALL_INSTANCE_INTERFACE;
170         QString error = "DBus Error (StopCallMonitors): " + mDBusUtility.getErrorMessage();
171         mDBusUtility.displayNotification(error);
172         qDebug() << "Error is: " << error;
173     }
174     qDebug() << "Successfully disconnected from Dbus signal Terminated in interface "<< CSD_CALL_INSTANCE_INTERFACE;
175
176     // Disconnect the slot for monitoring incoming calls
177     status = connection.disconnect(CSD_CALL_BUS_NAME, CSD_CALL_PATH, CSD_CALL_INTERFACE,
178                                    QString("Coming"),this, SLOT(StopCallMonitors()));
179
180     if(!status)
181     {
182         qDebug() << "Failed to disconnect from Dbus signal Coming in interface" << CSD_CALL_INTERFACE;
183         QString error = "DBus Error (StopCallMonitors): " + mDBusUtility.getErrorMessage();
184         mDBusUtility.displayNotification(error);
185         qDebug() << "Error is: " << error;
186     }
187     qDebug() << "Successfully disconnected from Dbus signal Coming in interface" << CSD_CALL_INTERFACE;
188 }
189
190 void confManager::startConference()
191 {
192     mInStep = 0;
193     if(!mProfileSet)
194     {
195         qDebug() << "Please set the profile to use with Conference Manager first!";
196         return;
197     }
198     //Assume that the first number is always a phone number...
199     Steps step = mProfileInUse.mSteps.at(mInStep);
200     mInStep++;
201     QList<QVariant> sendArgs;
202     sendArgs.append(step.value());
203     sendArgs.append(0);
204     bool status = mDBusUtility.sendMethodCall(CSD_SERVICE, CSD_CALL_PATH, CSD_CALL_INTERFACE,
205                                               QString("CreateWith"), sendArgs);
206     if(!status)
207     {
208         QString error = "Error while dialing: " + mDBusUtility.getErrorMessage();
209         qDebug() << error;
210         mDBusUtility.displayNotification(error);
211         return;
212     }
213     StartCallMonitors();
214 }