X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=confmanager.cpp;fp=confmanager.cpp;h=4acbe45b189f83653fab1ae91bcdedf45611eb8b;hb=6f0e06a23515e795b75e08161487d60c9fc4f933;hp=0000000000000000000000000000000000000000;hpb=8cdf509abbdb8654def1e0df79e1f607e9a41807;p=confmgr diff --git a/confmanager.cpp b/confmanager.cpp new file mode 100644 index 0000000..4acbe45 --- /dev/null +++ b/confmanager.cpp @@ -0,0 +1,200 @@ +#include "confmanager.h" +#include +#include + +confManager::confManager(QObject *parent) : + QObject(parent) +{ + mProfileSet = false; + mInStep = 0; +} + +void confManager::setProfile(Profile &p) +{ + mInStep = 0; + mProfileInUse = p; + mProfileSet = true; +} + +void confManager::continueSendDTMF() +{ + // We have now waited for the required period of seconds + // Lets send the DTMF now + Steps step = mProfileInUse.mSteps.at(mInStep); + + // Increment the steps as we want to point to the next one + mInStep++; + + QList argsToSend; + argsToSend.append(step.value()); + + bool status = mDBusUtility.sendMethodCall(CSD_SERVICE, CSD_CALL_PATH, CSD_CALL_INTERFACE, + QString("SendDTMF"),argsToSend); + + if(!status) + { + qDebug() << "Unable to send DTMF code."; + QString error = "DBus Error: " + mDBusUtility.getErrorMessage(); + mDBusUtility.displayNotification(error); + } + + // Check if we are over with the sequence or we need to continue + if(mInStep > mProfileInUse.mNoOfSteps) + { + StopCallMonitors(); + return; + } + + step = mProfileInUse.mSteps.at(mInStep); + QTimer *timer = new QTimer(this); + timer->setSingleShot(true); + connect(timer, SIGNAL(timeout()), this, SLOT(sendDTMF(const QDBusMessage &))); + timer->start(step.delay()); +} + +void confManager::sendDTMF(const QDBusMessage &dBusMessage) +{ + QList listArguments = dBusMessage.arguments(); + bool audioConnected = listArguments.first().toBool(); + + if(mInStep > mProfileInUse.mNoOfSteps) + { + StopCallMonitors(); + return; + } + + Steps step = mProfileInUse.mSteps.at(mInStep); + + if (audioConnected) + { + qDebug() << "Audio Connected..."; + //Wait for specified delay in the step + QTimer *timer = new QTimer(this); + timer->setSingleShot(true); + connect(timer, SIGNAL(timeout()), this, SLOT(continueSendDTMF())); + timer->start(step.delay()); + } +} + +void confManager::StartCallMonitors() +{ + QDBusConnection connection = mDBusUtility.getConnection(); + /* Declare the slot to be executed when a call is picked up by other party (Audio connection established). + We need this to confirm whether a call went though successfully. + */ + bool status = connection.connect(QString(""), CSD_CALL_INSTANCE_PATH, CSD_CALL_INSTANCE_INTERFACE, + QString("AudioConnect"),this, SLOT(sendDTMF(const QDBusMessage&))); + + if(!status) + { + qDebug() << "Failed to connect to Dbus signal AudioConnect in interface "<< CSD_CALL_INSTANCE_INTERFACE; + QString error = "DBus Error: " + mDBusUtility.getErrorMessage(); + mDBusUtility.displayNotification(error); + } + + qDebug() << "Successfully connected to Dbus signal AudioConnect in interface "<< CSD_CALL_INSTANCE_INTERFACE; + + /* 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. + */ + status = connection.connect(QString(""), CSD_CALL_INSTANCE_PATH, CSD_CALL_INSTANCE_INTERFACE, + QString("Terminated"),this, SLOT(StopCallMonitors())); + + if(!status) + { + qDebug() << "Failed to connect to Dbus signal Terminated in interface "<< CSD_CALL_INSTANCE_INTERFACE; + QString error = "DBus Error: " + mDBusUtility.getErrorMessage(); + mDBusUtility.displayNotification(error); + } + + qDebug() << "Successfully connected to Dbus signal Terminated in interface "<< CSD_CALL_INSTANCE_INTERFACE; + + /* Declare the slot to be executed when a call is received + (before we can place the call to calling card number). + It is extremely rare that somebody should get a call within these few seconds. + In any case, we need this to avoid sending DTMF code on the received call. + + Btw - I don't care for the incoming number here. If anyone is calling the user before we can send DTMF code, + then we stop sending the DTMF code even if user does not respond to the call. + */ + + status = connection.connect(QString(""), CSD_CALL_PATH, CSD_CALL_INTERFACE, + QString("Coming"),this, SLOT(StopCallMonitors())); + + if(!status) + { + qDebug() << "Failed to connect to Dbus signal Coming in interface" << CSD_CALL_INTERFACE; + QString error = "DBus Error: " + mDBusUtility.getErrorMessage(); + mDBusUtility.displayNotification(error); + } + qDebug() << "Successfully connected to Dbus signal Coming in interface" << CSD_CALL_INTERFACE; +} + +void confManager::StopCallMonitors() +{ + mInStep = 0; + mProfileSet = false; + + QDBusConnection connection = mDBusUtility.getConnection(); + + // Disconnect the slot for audio connection status + bool status = connection.disconnect(QString(""), CSD_CALL_INSTANCE_PATH, CSD_CALL_INSTANCE_INTERFACE, + QString("AudioConnect"),this, SLOT(sendDTMF(const QDBusMessage&))); + + if(!status) + { + qDebug() << "Failed to disconnect from Dbus signal AudioConnect in interface" << CSD_CALL_INSTANCE_INTERFACE; + QString error = "DBus Error: " + mDBusUtility.getErrorMessage(); + mDBusUtility.displayNotification(error); + } + qDebug() << "Successfully disconnected from Dbus signal AudioConnect in interface "<< CSD_CALL_INSTANCE_INTERFACE; + + // Disconnect the slot for monitoring terminated calls + status = connection.disconnect(QString(""), CSD_CALL_INSTANCE_PATH, CSD_CALL_INSTANCE_INTERFACE, + QString("Terminated"),this, SLOT(StopCallMonitors())); + + if(!status) + { + qDebug() << "Failed to disconnect from Dbus signal Terminated in interface" << CSD_CALL_INSTANCE_INTERFACE; + QString error = "DBus Error: " + mDBusUtility.getErrorMessage(); + mDBusUtility.displayNotification(error); + } + qDebug() << "Successfully disconnected from Dbus signal Terminated in interface "<< CSD_CALL_INSTANCE_INTERFACE; + + // Disconnect the slot for monitoring incoming calls + status = connection.disconnect(QString(""), CSD_CALL_PATH, CSD_CALL_INTERFACE, + QString("Coming"),this, SLOT(StopCallMonitors())); + + if(!status) + { + qDebug() << "Failed to disconnect from Dbus signal Coming in interface" << CSD_CALL_INTERFACE; + QString error = "DBus Error: " + mDBusUtility.getErrorMessage(); + mDBusUtility.displayNotification(error); + } + qDebug() << "Successfully disconnected from Dbus signal Coming in interface" << CSD_CALL_INTERFACE; +} + +void confManager::startConference() +{ + if(!mProfileSet) + { + qDebug() << "Please set the profile to use with Conference Manager first!"; + return; + } + //Assume that the first number is always a phone number... + Steps step = mProfileInUse.mSteps.at(mInStep); + mInStep++; + QList sendArgs; + sendArgs.append(step.value()); + sendArgs.append(0); + bool status = mDBusUtility.sendMethodCall(CSD_SERVICE, CSD_CALL_PATH, CSD_CALL_INTERFACE, + QString("CreateWith"), sendArgs); + if(!status) + { + QString error = "Error while dialing: " + mDBusUtility.getErrorMessage(); + qDebug() << error; + mDBusUtility.displayNotification(error); + return; + } + StartCallMonitors(); +}