/*
-@version: 0.5
+@version: 0.6
@author: Sudheer K. <scifi1947 at gmail.com>
@license: GNU General Public License
*/
#include <QDBusMessage>
#include <QStringListIterator>
-
-//static QString strLastDialedNumber = QString();
-//static org::maemo::vicar::Profile currentProfile;
-
class CallRouterPrivate
{
public:
GConfUtility * gconfUtility;
TelepathyUtility *tpUtility;
QString strLastDialedNumber;
+ QString strLastDTMFCode;
org::maemo::vicar::Profile *currentProfile;
CallRouter * const parent;
};
qDebug() <<"Vicar-Daemon: DBus Error: "<< d->dbusUtility->getErrorMessage();
}
+
+ /* Declare the slot to be executed when the DTMF code is sent.
+ */
+
+ success = connection.connect(QString(""),
+ CSD_CALL_INSTANCE_PATH,
+ CSD_CALL_INSTANCE_INTERFACE,
+ QString("StoppedDTMF"),this,
+ SLOT(displayDTMFConfirmation()));
+
+ if (success){
+ qDebug() << "Vicar-Daemon: Successfully connected to Dbus signal StoppedDTMF in interface "<< CSD_CALL_INSTANCE_INTERFACE;
+ }
+ else{
+ qDebug() << "Vicar-Daemon: Failed to connect to Dbus signal StoppedDTMF in interface "<< CSD_CALL_INSTANCE_INTERFACE;
+ qDebug() <<"Vicar-Daemon: DBus Error: "<< d->dbusUtility->getErrorMessage();
+ }
+
+
/* Declare the slot to be executed when the call is terminated (due to connection errors etc).
We need this to avoid sending DTMF code on wrong calls.
*/
void CallRouter::stopCallStatusMonitors(){
+ d->strLastDTMFCode.clear();
d->strLastDialedNumber.clear();
delete d->currentProfile;
d->currentProfile = 0;
qDebug() <<"Vicar-Daemon: DBus Error: "<< d->dbusUtility->getErrorMessage();
}
+ // Disconnect the slot for monitoring DTMF completion
+ status = connection.disconnect(QString(""),
+ CSD_CALL_INSTANCE_PATH,
+ CSD_CALL_INSTANCE_INTERFACE,
+ QString("StoppedDTMF"),this,
+ SLOT(displayDTMFConfirmation()));
+
+ if (status){
+ qDebug() << "Vicar-Daemon: Successfully disconnected from Dbus signal StoppedDTMF in interface "<< CSD_CALL_INSTANCE_INTERFACE;
+ }
+ else{
+ qDebug() << "Vicar-Daemon: Failed to disconnect from Dbus signal StoppedDTMF in interface "<< CSD_CALL_INSTANCE_INTERFACE;
+ qDebug() <<"Vicar-Daemon: DBus Error: "<< d->dbusUtility->getErrorMessage();
+ }
+
+
// Disconnect the slot for monitoring terminated calls
status = connection.disconnect(QString(""),
CSD_CALL_INSTANCE_PATH,
qDebug() << "Vicar-Daemon: Audio connection established. Sending DTMF code "<< strDTMFCode;
+
QList<QVariant> argsToSend;
argsToSend.append(strDTMFCode);
-
bool status = d->dbusUtility->sendMethodCall(CSD_SERVICE,
CSD_CALL_PATH,
CSD_CALL_INTERFACE,
QString("SendDTMF"),argsToSend);
if (status){
- QString strMessage = strDTMFCode.append(" sent as DTMF code");
- qDebug() << strMessage;
- d->dbusUtility->displayNotification(strMessage);
+ qDebug() << "Vicar-Daemon: Sending " << strDTMFCode << " as DTMF code.";
+ d->strLastDTMFCode = strDTMFCode;
}
else{
qDebug() << "Vicar-Daemon: Unable to send DTMF code.";
}
-
-
- /*
- Connecting and Disconnecting from/to DBus signal for each international call
- may not be the most efficient way of handling this. But we need to make sure
- that the DTMF codes are sent only for the calls placed by this app (i.e calls to Calling card number).
- */
-
- qDebug() << "Vicar-Daemon: Now disconnecting from call status monitors..";
- stopCallStatusMonitors();
-
- d->strLastDialedNumber.clear();
- delete d->currentProfile;
- d->currentProfile = 0;
}
else{
qDebug() << "Vicar-Daemon: Audio not yet connected.";
}
}
+void CallRouter::displayDTMFConfirmation(){
+ //This slot is called when the all the DTMF tones are sent (i.e StoppedDTMF signal is emitted)
+ //Just display confirmation message and cleanup
+
+
+ if (!d->strLastDTMFCode.isEmpty()){
+ QString strMessage = d->strLastDTMFCode.append(" sent as DTMF code");
+ d->dbusUtility->displayNotification(strMessage);
+ qDebug() << "Vicar-Daemon: "<< d->strLastDTMFCode << " sent as DTMF code.";
+ }
+
+ /*
+ Connecting and Disconnecting from/to DBus signal for each international call
+ may not be the most efficient way of handling this. But we need to make sure
+ that the DTMF codes are sent only for the calls placed by this app (i.e calls to Calling card number).
+ */
+
+ qDebug() << "Vicar-Daemon: Now disconnecting from call status monitors..";
+ stopCallStatusMonitors();
+}
+
QString CallRouter::convertToDTMFCode(QString strNumber){
QString strDTMFCode;
if (!strNumber.isEmpty()){
- int intDTMFDelay = 1;
+ //int intDTMFDelay = 1;
//Add the prefix p so that there is some delay after the call is picked up by the automated system to send DTMF tones.
- strDTMFCode = QString("").fill('p',intDTMFDelay);
+ //strDTMFCode = QString("").fill('p',intDTMFDelay);
+ strDTMFCode = "";
//Now check whether we need a prefix
QString strDTMFPrefix = d->currentProfile->dtmfPrefix;
if (isValidPhoneNumber(strDestinationNumber)){
- strErrorMessage = this->callViaCallingCard(strDestinationNumber);
+ //Remove spaces in the phone number before using
+ QString numberWithoutSpaces = QString(strDestinationNumber).remove(" ");
+
+ strErrorMessage = this->callViaCallingCard(numberWithoutSpaces);
}
else{
strErrorMessage = QString("Vicar-Daemon: %1 is not a valid number").arg(strDestinationNumber);
+ if (strDestinationNumber != "publish" && strDestinationNumber != "subscribe"){
+ d->dbusUtility->displayNotification(QString("Vicar: %1 is not a valid number").arg(strDestinationNumber));
+ }
}
qDebug() << strErrorMessage;
//Check whether a string is valid phone number
bool CallRouter::isValidPhoneNumber(QString strPhoneNumber){
-
-/* Remove all dialble characters. The resulting string should be a valid number */
- QRegExp regexp = QRegExp("[p+*#]");
+/* Remove all dialble characters and space. The resulting string should be a valid number */
+ QRegExp regexp = QRegExp("[p+*# ]");
strPhoneNumber = strPhoneNumber.replace(regexp,"");