Commit 8e25bc10 authored by jpbl's avatar jpbl

Added action line

parent 5237c352
......@@ -11,7 +11,12 @@ PhoneLine::PhoneLine(const Session &session,
, mLine(line)
, mSelected(false)
, mLineStatus("test")
{}
, mActionTimer(new QTimer(this))
, mIsOnError(false)
{
QObject::connect(mActionTimer, SIGNAL(timeout()),
this, SLOT(resetAction()));
}
PhoneLine::~PhoneLine()
{
......@@ -25,15 +30,35 @@ PhoneLine::getLineStatus()
return mLineStatus;
}
void
PhoneLine::resetAction()
{
setAction("");
}
void
PhoneLine::setLineStatus(const QString &status)
{
mActionTimer->stop();
mAction.clear();
mLineStatus = status;
if(mSelected) {
emit lineStatusChanged(mLineStatus);
}
}
void
PhoneLine::setAction(const QString &status)
{
mActionTimer->stop();
mActionTimer->start(3000);
mAction = status;
if(mSelected) {
emit actionChanged(mAction);
}
}
unsigned int
PhoneLine::line()
{
......@@ -61,7 +86,10 @@ PhoneLine::select(bool hardselect)
if(!hardselect) {
if(mCall) {
if(mCall->isIncomming()) {
if(mIsOnError) {
close();
}
else if(mCall->isIncomming()) {
answer();
}
else {
......@@ -75,6 +103,7 @@ PhoneLine::select(bool hardselect)
emit selected();
}
}
void
......@@ -82,12 +111,26 @@ PhoneLine::disconnect()
{
mSelected = false;
_debug("PhoneLine %d: I am disconnected.\n", mLine);
close();
emit unselected();
}
void
PhoneLine::close()
{
_debug("PhoneLine %d: I am closed.\n", mLine);
if(mCall) {
delete mCall;
mCall = NULL;
}
mIsOnError = false;
}
emit unselected();
void
PhoneLine::error()
{
mIsOnError = true;
}
void
......@@ -96,6 +139,9 @@ PhoneLine::unselect(bool hardselect)
if(mSelected) {
_debug("PhoneLine %d: I am unselected.\n", mLine);
mSelected = false;
if(mIsOnError) {
close();
}
if(mCall) {
if(!hardselect) {
mCall->hold();
......@@ -180,7 +226,7 @@ void
PhoneLine::hold()
{
if(mCall) {
setLineStatus("Holded.");
setAction("Holded.");
_debug("PhoneLine %d: Trying to Hold.\n", mLine);
mCall->hold();
}
......@@ -192,7 +238,7 @@ void
PhoneLine::unhold()
{
if(mCall) {
setLineStatus("Unholding...");
setAction("Unholding...");
_debug("PhoneLine %d: Trying to Unhold.\n", mLine);
mCall->unhold();
}
......@@ -202,7 +248,7 @@ void
PhoneLine::answer()
{
if(mCall) {
setLineStatus("Answering...");
setAction("Answering...");
_debug("PhoneLine %d: Trying to answer.\n", mLine);
mCall->answer();
}
......@@ -212,7 +258,7 @@ void
PhoneLine::hangup()
{
if(mCall) {
setLineStatus("Hanguping...");
setAction("Hanguping...");
_debug("PhoneLine %d: Trying to Hangup.\n", mLine);
mCall->hangup();
delete mCall;
......
......@@ -2,6 +2,7 @@
#include <QObject>
#include <QMutex>
#include <QString>
#include <QTimer>
#include "Session.hpp"
......@@ -58,9 +59,11 @@ public:
QString getLineStatus();
QString getBuffer()
{return mBuffer;}
void setLineStatus(const QString &);
public slots:
void setLineStatus(const QString &);
void setAction(const QString &);
void resetAction();
void incomming(const Call &call);
/**
......@@ -84,6 +87,19 @@ public slots:
*/
void disconnect();
/**
* This will close the current call. it means it
* will remove the call if there's one.
*/
void close();
/**
* This will close the current call. it means it
* will remove the call if there's one. The line
* will be in an error state.
*/
void error();
void setState(const QString &){}
void setPeer(const QString &){}
......@@ -93,6 +109,7 @@ signals:
void unselected();
void backgrounded();
void lineStatusChanged(const QString &);
void actionChanged(const QString &);
void bufferStatusChanged(const QString &);
private:
......@@ -107,4 +124,8 @@ private:
QString mBuffer;
QString mLineStatus;
QString mAction;
QTimer *mActionTimer;
bool mIsOnError;
};
......@@ -143,6 +143,8 @@ PhoneLineManagerImpl::setNbLines(unsigned int nb)
PhoneLine *p = new PhoneLine(*mSession, i + 1);
QObject::connect(p, SIGNAL(lineStatusChanged(const QString &)),
this, SIGNAL(lineStatusSet(const QString &)));
QObject::connect(p, SIGNAL(actionChanged(const QString &)),
this, SIGNAL(actionSet(const QString &)));
QObject::connect(p, SIGNAL(bufferStatusChanged(const QString &)),
this, SIGNAL(bufferStatusSet(const QString &)));
mPhoneLines.push_back(p);
......@@ -189,7 +191,7 @@ PhoneLineManagerImpl::getLine(const Call &call)
unsigned int i = 0;
while(i < mPhoneLines.size() && !selectedLine) {
mPhoneLines[i]->lock();
if(mPhoneLines[i]->getCallId() == call->id())
if(mPhoneLines[i]->getCallId() == call.id()) {
selectedLine = mPhoneLines[i];
}
else {
......
......@@ -52,6 +52,7 @@ signals:
void gotErrorOnCallStatus();
void globalStatusSet(const QString &);
void bufferStatusSet(const QString &);
void actionSet(const QString &);
void lineStatusSet(const QString &);
public slots:
......
......@@ -116,6 +116,7 @@ RequesterImpl::receiveAnswer(const QString &answer)
std::istringstream s(answer.toStdString());
s >> code >> seq;
getline(s, message);
message.erase(0, 1);
receiveAnswer(QString::fromStdString(code),
QString::fromStdString(seq),
QString::fromStdString(message));
......
......@@ -17,6 +17,7 @@ SFLLcd::SFLLcd(QWidget *parent, Qt::WFlags flags)
, mGlobalStatusPos(-1)
, mLineStatusPos(-1)
, mBufferStatusPos(-1)
, mActionPos(-1)
, mIsTimed(false)
, mFont(FONT_FAMILY, FONT_SIZE)
{
......@@ -46,6 +47,10 @@ SFLLcd::updateText()
if(mBufferStatusPos >= 0) {
mBufferStatusPos++;
}
if(mActionPos >= 0) {
mActionPos++;
}
}
void
......@@ -97,6 +102,18 @@ SFLLcd::setLineStatus(const QString &line)
mLineStatus = line;
}
void
SFLLcd::setAction(const QString &line)
{
if(textIsTooBig(line)) {
mActionPos = 0;
}
else {
mActionPos = -1;
}
mAction = line;
}
QString
SFLLcd::getTimeStatus()
{
......@@ -134,6 +151,8 @@ SFLLcd::paintEvent(QPaintEvent *)
p.drawText(QPoint(margin, 2*fm.height()),
extractVisibleText(mLineStatus, mLineStatusPos));
p.drawText(QPoint(margin, 3*fm.height()),
extractVisibleText(mAction, mActionPos));
p.drawText(QPoint(margin, 4*fm.height()),
extractVisibleText(mBufferStatus, mBufferStatusPos));
p.drawText(QPoint(margin, mScreen.size().height() - margin), getTimeStatus());
......
......@@ -42,6 +42,7 @@ public slots:
void setGlobalStatus(const QString &global);
void setLineStatus(const QString &line);
void setAction(const QString &line);
void setBufferStatus(const QString &line);
void startTiming();
......@@ -56,9 +57,11 @@ private:
QString mGlobalStatus;
QString mLineStatus;
QString mBufferStatus;
QString mAction;
int mGlobalStatusPos;
int mLineStatusPos;
int mBufferStatusPos;
int mActionPos;
bool mIsTimed;
QTime mTime;
......
......@@ -22,15 +22,14 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
Requester::instance().registerObject< Request >(QString("playdtmf"));
Requester::instance().registerObject< EventRequest >(QString("getevents"));
Requester::instance().registerObject< CallStatusRequest >(QString("getcallstatus"));
Requester::instance().registerObject< CallRelatedRequest >(QString("answer"));
Requester::instance().registerObject< CallRelatedRequest >(QString("notavailable"));
Requester::instance().registerObject< CallRelatedRequest >(QString("refuse"));
Requester::instance().registerObject< CallRelatedRequest >(QString("senddtmf"));
Requester::instance().registerObject< CallRelatedRequest >(QString("playdtmf"));
Requester::instance().registerObject< CallRelatedRequest >(QString("call"));
Requester::instance().registerObject< CallRelatedRequest >(QString("hold"));
Requester::instance().registerObject< CallRelatedRequest >(QString("unhold"));
Requester::instance().registerObject< CallRelatedRequest >(QString("hangup"));
Requester::instance().registerObject< PermanentRequest >(QString("answer"));
Requester::instance().registerObject< PermanentRequest >(QString("notavailable"));
Requester::instance().registerObject< PermanentRequest >(QString("refuse"));
Requester::instance().registerObject< TemporaryRequest >(QString("senddtmf"));
Requester::instance().registerObject< PermanentRequest >(QString("call"));
Requester::instance().registerObject< TemporaryRequest >(QString("hold"));
Requester::instance().registerObject< TemporaryRequest >(QString("unhold"));
Requester::instance().registerObject< PermanentRequest >(QString("hangup"));
}
void
......@@ -68,6 +67,8 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w)
// LCD Connections.
QObject::connect(&PhoneLineManager::instance(), SIGNAL(lineStatusSet(const QString &)),
w->mLcd, SLOT(setLineStatus(const QString &)));
QObject::connect(&PhoneLineManager::instance(), SIGNAL(actionSet(const QString &)),
w->mLcd, SLOT(setAction(const QString &)));
QObject::connect(&PhoneLineManager::instance(), SIGNAL(globalStatusSet(const QString &)),
w->mLcd, SLOT(setGlobalStatus(const QString &)));
QObject::connect(&PhoneLineManager::instance(), SIGNAL(bufferStatusSet(const QString &)),
......
......@@ -4,10 +4,12 @@
#include <QString>
#include "globals.h"
#include "PhoneLineManager.hpp"
#include "SFLRequest.hpp"
#include "CallStatus.hpp"
#include "CallStatusFactory.hpp"
#include "PhoneLine.hpp"
#include "PhoneLineLocker.hpp"
#include "PhoneLineManager.hpp"
#include "SFLRequest.hpp"
EventRequest::EventRequest(const QString &sequenceId,
const QString &command,
......@@ -81,3 +83,122 @@ CallStatusRequest::onSuccess(const QString &code, const QString &message)
}
PhoneLineManager::instance().handleEvents();
}
PermanentRequest::PermanentRequest(const QString &sequenceId,
const QString &command,
const std::list< QString > &args)
: CallRelatedRequest(sequenceId, command, args)
{}
void
PermanentRequest::onError(Call call,
const QString &,
const QString &message)
{
PhoneLine *line = PhoneLineManager::instance().getLine(call);
if(line) {
PhoneLineLocker guard(line, false);
line->setLineStatus(message);
line->error();
}
else {
_debug("We received an error on a call "
"that doesn't have a phone line (%s).\n",
call.id().toStdString().c_str());
}
}
void
PermanentRequest::onEntry(Call call,
const QString &,
const QString &message)
{
PhoneLine *line = PhoneLineManager::instance().getLine(call);
if(line) {
PhoneLineLocker guard(line, false);
line->setLineStatus(message);
}
else {
_debug("We received a status on a call related request "
"that doesn't have a phone line (%s).\n",
call.id().toStdString().c_str());
}
}
void
PermanentRequest::onSuccess(Call call,
const QString &,
const QString &message)
{
PhoneLine *line = PhoneLineManager::instance().getLine(call);
if(line) {
PhoneLineLocker guard(line, false);
line->setLineStatus(message);
}
else {
_debug("We received a success on a call related request "
"that doesn't have a phone line (%s).\n",
call.id().toStdString().c_str());
}
}
TemporaryRequest::TemporaryRequest(const QString &sequenceId,
const QString &command,
const std::list< QString > &args)
: CallRelatedRequest(sequenceId, command, args)
{}
void
TemporaryRequest::onError(Call call,
const QString &,
const QString &message)
{
PhoneLine *line = PhoneLineManager::instance().getLine(call);
if(line) {
PhoneLineLocker guard(line, false);
line->setAction(message);
}
else {
_debug("We received an error on a temporary call "
"related request that doesn't have a phone "
"line (%s).\n",
call.id().toStdString().c_str());
}
}
void
TemporaryRequest::onEntry(Call call,
const QString &,
const QString &message)
{
PhoneLine *line = PhoneLineManager::instance().getLine(call);
if(line) {
PhoneLineLocker guard(line, false);
line->setAction(message);
}
else {
_debug("We received a status on a temporary call "
"related request that doesn't have a phone "
"line (%s).\n",
call.id().toStdString().c_str());
}
}
void
TemporaryRequest::onSuccess(Call call,
const QString &,
const QString &message)
{
PhoneLine *line = PhoneLineManager::instance().getLine(call);
if(line) {
PhoneLineLocker guard(line, false);
line->setAction(message);
}
else {
_debug("We received a success on a temporary call "
"related request that doesn't have a phone "
"line (%s).\n",
call.id().toStdString().c_str());
}
}
......@@ -76,4 +76,76 @@ public:
};
class PermanentRequest : public CallRelatedRequest
{
public:
PermanentRequest(const QString &sequenceId,
const QString &command,
const std::list< QString > &args);
/**
* This function will be called when the request
* receive its answer, if the request didn't successfully
* ended.
*/
virtual void onError(Call call,
const QString &code,
const QString &message);
/**
* This function will be called when the request
* receive an answer, but there's other answers to come.
*/
virtual void onEntry(Call call,
const QString &code,
const QString &message);
/**
* This function will be called when the request
* receive its answer, if the request successfully
* ended.
*/
virtual void onSuccess(Call call,
const QString &code,
const QString &message);
};
class TemporaryRequest : public CallRelatedRequest
{
public:
TemporaryRequest(const QString &sequenceId,
const QString &command,
const std::list< QString > &args);
/**
* This function will be called when the request
* receive its answer, if the request didn't successfully
* ended.
*/
virtual void onError(Call call,
const QString &code,
const QString &message);
/**
* This function will be called when the request
* receive an answer, but there's other answers to come.
*/
virtual void onEntry(Call call,
const QString &code,
const QString &message);
/**
* This function will be called when the request
* receive its answer, if the request successfully
* ended.
*/
virtual void onSuccess(Call call,
const QString &code,
const QString &message);
};
#endif
......@@ -103,7 +103,7 @@ TCPSessionIO::receive(QString &answer)
if(mSocket->isReadable()) {
QTextStream stream(mSocket);
answer = stream.readLine();
_debug("TCPSessionIO: Received answer from sflphone: %s",
_debug("TCPSessionIO: Received answer from sflphone: %s\n",
answer.toStdString().c_str());
}
}
......
need to consolidated Request and Answers.
need to set temp status.
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment