Skip to content
Snippets Groups Projects
Commit a3c37ad1 authored by jpbl's avatar jpbl
Browse files

*** empty log message ***

parent 085bd7ce
No related branches found
No related tags found
No related merge requests found
Showing
with 350 additions and 75 deletions
...@@ -28,17 +28,6 @@ Account::Account(const std::string &sessionId, ...@@ -28,17 +28,6 @@ Account::Account(const std::string &sessionId,
, mId(name) , mId(name)
{} {}
Call
Account::call(const std::string &to)
{
std::string callId = Requester::instance().generateCallId();
std::list< std::string > args;
args.push_back(mId);
args.push_back(to);
Requester::instance().send(mSessionId, "register", args);
return Call(mSessionId, callId);
}
std::string std::string
Account::registerAccount() Account::registerAccount()
{ {
......
...@@ -33,7 +33,6 @@ class Account { ...@@ -33,7 +33,6 @@ class Account {
/** /**
* This will generate a call ready to be used. * This will generate a call ready to be used.
*/ */
Call call(const std::string &to);
std::string registerAccount(); std::string registerAccount();
std::string unregisterAccount(); std::string unregisterAccount();
......
...@@ -38,6 +38,14 @@ Call::Call(const Session &session, ...@@ -38,6 +38,14 @@ Call::Call(const Session &session,
, mId(callId) , mId(callId)
{} {}
std::string
Call::call(const std::string &to)
{
std::list< std::string> args;
args.push_back(mId);
args.push_back(to);
return Requester::instance().send(mSessionId, "call", args);
}
std::string std::string
Call::answer() Call::answer()
......
...@@ -33,6 +33,8 @@ class Call ...@@ -33,6 +33,8 @@ class Call
Call(const Session &session, Call(const Session &session,
const std::string &callId); const std::string &callId);
std::string call(const std::string &to);
/** /**
* This function will answer the call. * This function will answer the call.
*/ */
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <QLabel> #include <QLabel>
#include <QPixmap> #include <QPixmap>
#include <QImage>
/** /**
* This class Emulate a PushButton but takes two * This class Emulate a PushButton but takes two
...@@ -41,13 +42,14 @@ public: ...@@ -41,13 +42,14 @@ public:
Qt::WFlags flags = 0); Qt::WFlags flags = 0);
~JPushButton(); ~JPushButton();
public slots:
/** /**
* This function will switch the button * This function will switch the button
*/ */
void press(); void press();
void release(); void release();
private: protected:
QPixmap mImages[2]; QPixmap mImages[2];
protected: protected:
...@@ -56,7 +58,7 @@ protected: ...@@ -56,7 +58,7 @@ protected:
void mouseMoveEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *);
signals: signals:
void clicked(void); void clicked();
}; };
......
#include <iostream>
#include "globals.h" #include "globals.h"
#include "PhoneLine.hpp" #include "PhoneLine.hpp"
#include "Call.hpp" #include "Call.hpp"
PhoneLine::PhoneLine() PhoneLine::PhoneLine(const Call &call,
: mCall(NULL) unsigned int line)
: mCall(call)
, mLine(line)
, mSelected(false)
, mInUse(false)
{} {}
unsigned int
PhoneLine::line()
{
return mLine;
}
void void
PhoneLine::lock() PhoneLine::lock()
{ {
...@@ -21,11 +33,60 @@ PhoneLine::unlock() ...@@ -21,11 +33,60 @@ PhoneLine::unlock()
void void
PhoneLine::select() PhoneLine::select()
{ {
_debug("I am selected.\n"); if(!mSelected) {
_debug("PhoneLine %d: I am selected.\n", mLine + 1);
mSelected = true;
emit selected();
}
} }
void void
PhoneLine::unselect() PhoneLine::unselect()
{ {
_debug("I am unselected.\n"); if(mSelected) {
_debug("PhoneLine %d: I am unselected.\n", mLine + 1);
mSelected = false;
if(!mInUse) {
mBuffer.clear();
emit backgrounded();
}
else {
emit unselected();
}
}
}
void
PhoneLine::sendKey(Qt::Key c)
{
_debug("PhoneLine %d: Received the character:%s.\n", mLine + 1, QString(c).toStdString().c_str());
switch(c) {
case Qt::Key_Enter:
case Qt::Key_Return:
if(!mInUse) {
return call();
}
break;
default:
if(!mInUse) {
mBuffer += QString(c).toStdString();
}
}
}
void
PhoneLine::call()
{
call(mBuffer);
}
void
PhoneLine::call(const std::string &to)
{
_debug("PhoneLine %d: Calling %s.\n", mLine, to.c_str());
if(!mInUse) {
mInUse = true;
mCall.call(to);
}
} }
#include <QChar>
#include <QObject> #include <QObject>
#include <QMutex> #include <QMutex>
#include <string> #include <string>
class Call; #include "Call.hpp"
class PhoneLine : public QObject class PhoneLine : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
PhoneLine(); PhoneLine(const Call &call, unsigned int line);
~PhoneLine(){} ~PhoneLine(){}
void call(const std::string &to); void call(const std::string &to);
void call();
unsigned int line();
/** /**
* This will lock the current phone line. * This will lock the current phone line.
...@@ -31,6 +35,19 @@ public: ...@@ -31,6 +35,19 @@ public:
*/ */
void unlock(); void unlock();
/**
* This function will return true if there's no
* activity on this line. It means that even
* if we typed something on this line, but haven't
* started any communication, this will be available.
*/
bool isAvailable()
{return !mInUse;}
void sendKey(Qt::Key c);
public slots:
/** /**
* The user selected this line. * The user selected this line.
*/ */
...@@ -41,11 +58,19 @@ public: ...@@ -41,11 +58,19 @@ public:
*/ */
void unselect(); void unselect();
signals: signals:
void selected(); void selected();
void unselected(); void unselected();
void backgrounded();
private: private:
Call *mCall; Call mCall;
QMutex mPhoneLineMutex; QMutex mPhoneLineMutex;
unsigned int mLine;
bool mSelected;
bool mInUse;
//This is the buffer when the line is not in use;
std::string mBuffer;
}; };
...@@ -9,18 +9,53 @@ PhoneLineButton::PhoneLineButton(const QPixmap &released, ...@@ -9,18 +9,53 @@ PhoneLineButton::PhoneLineButton(const QPixmap &released,
Qt::WFlags flags) Qt::WFlags flags)
: JPushButton(released, pressed, parent, flags) : JPushButton(released, pressed, parent, flags)
, mLine(line) , mLine(line)
{} , mTimer(this)
, mFace(0)
{
connect(&mTimer, SIGNAL(timeout()),
this, SLOT(swap()));
}
void
PhoneLineButton::suspend()
{
mTimer.start(500);
}
void
PhoneLineButton::swap()
{
mFace = (mFace + 1) / 2;
resize(mImages[mFace].size());
setPixmap(mImages[mFace]);
}
void
PhoneLineButton::press()
{
mTimer.stop();
JPushButton::press();
}
void
PhoneLineButton::release()
{
mTimer.stop();
JPushButton::release();
}
void void
PhoneLineButton::mouseReleaseEvent (QMouseEvent *e) PhoneLineButton::mouseReleaseEvent (QMouseEvent *e)
{ {
switch (e->button()) { switch (e->button()) {
case Qt::LeftButton: case Qt::LeftButton:
release();
// Emulate the left mouse click // Emulate the left mouse click
if (this->rect().contains(e->pos())) { if (this->rect().contains(e->pos())) {
emit clicked(mLine); emit clicked(mLine);
} }
else {
release();
}
break; break;
default: default:
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <QLabel> #include <QLabel>
#include <QObject> #include <QObject>
#include <QPixmap> #include <QPixmap>
#include <QTimer>
#include "JPushButton.hpp" #include "JPushButton.hpp"
...@@ -25,14 +26,22 @@ public: ...@@ -25,14 +26,22 @@ public:
virtual ~PhoneLineButton(){} virtual ~PhoneLineButton(){}
protected:
void mouseReleaseEvent(QMouseEvent *);
signals: signals:
void clicked(unsigned int); void clicked(unsigned int);
public slots:
void suspend();
void press();
void release();
protected:
void mouseReleaseEvent(QMouseEvent *);
void swap();
private: private:
unsigned int mLine; unsigned int mLine;
QTimer mTimer;
unsigned int mFace;
}; };
......
#include <QMutexLocker>
#include <iostream> #include <iostream>
#include <stdexcept>
#include "globals.h" #include "globals.h"
...@@ -11,15 +13,67 @@ PhoneLineManager::PhoneLineManager(unsigned int nbLines) ...@@ -11,15 +13,67 @@ PhoneLineManager::PhoneLineManager(unsigned int nbLines)
, mCurrentLine(NULL) , mCurrentLine(NULL)
{ {
for(unsigned int i = 0; i < nbLines; i++) { for(unsigned int i = 0; i < nbLines; i++) {
mPhoneLines.push_back(new PhoneLine()); mPhoneLines.push_back(new PhoneLine(mSession.createCall(),
i));
} }
} }
void PhoneLineManager::clicked() void
PhoneLineManager::selectAvailableLine()
{
PhoneLine *selectedLine = NULL;
mPhoneLinesMutex.lock();
unsigned int i = 0;
while(i < mPhoneLines.size() && !selectedLine) {
PhoneLineLocker guard(mPhoneLines[i]);
if(mPhoneLines[i]->isAvailable()) {
selectedLine = mPhoneLines[i];
}
else {
i++;
}
}
mPhoneLinesMutex.unlock();
if(selectedLine) {
selectLine(i);
}
}
PhoneLine *
PhoneLineManager::getPhoneLine(unsigned int line)
{
QMutexLocker guard(&mPhoneLinesMutex);
if(mPhoneLines.size() <= line) {
throw std::runtime_error("Trying to get an invalid Line");
}
return mPhoneLines[line];
}
void
PhoneLineManager::sendKey(Qt::Key c)
{ {
std::cout << "Clicked" << std::endl; PhoneLine *selectedLine = NULL;
mCurrentLineMutex.lock();
selectedLine = mCurrentLine;
mCurrentLineMutex.unlock();
if(!selectedLine) {
selectAvailableLine();
mCurrentLineMutex.lock();
selectedLine = mCurrentLine;
mCurrentLineMutex.unlock();
}
if(selectedLine) {
PhoneLineLocker guard(selectedLine);
selectedLine->sendKey(c);
}
} }
/** /**
* Warning: This function might 'cause a problem if * Warning: This function might 'cause a problem if
* we select 2 line in a very short time. * we select 2 line in a very short time.
...@@ -52,6 +106,9 @@ PhoneLineManager::selectLine(unsigned int line) ...@@ -52,6 +106,9 @@ PhoneLineManager::selectLine(unsigned int line)
PhoneLineLocker guard(selectedLine); PhoneLineLocker guard(selectedLine);
selectedLine->select(); selectedLine->select();
if(selectedLine->isAvailable()) {
mSession.sendTone();
}
} }
} }
else { else {
...@@ -60,6 +117,6 @@ PhoneLineManager::selectLine(unsigned int line) ...@@ -60,6 +117,6 @@ PhoneLineManager::selectLine(unsigned int line)
} }
void void
PhoneLineManager::call(const QString &to) PhoneLineManager::call(const QString &)
{ {
} }
#ifndef __PHONELINEMANAGER_HPP__ #ifndef __PHONELINEMANAGER_HPP__
#define __PHONELINEMANAGER_HPP__ #define __PHONELINEMANAGER_HPP__
#include <Qt>
#include <QObject> #include <QObject>
#include <QMutex> #include <QMutex>
#include <utility> #include <utility>
...@@ -41,12 +42,14 @@ public: ...@@ -41,12 +42,14 @@ public:
*/ */
void hangup(unsigned int line); void hangup(unsigned int line);
/** PhoneLine *getPhoneLine(unsigned int line);
* This function hangup the
*/ signals:
void unselected(unsigned int);
void selected(unsigned int);
public slots: public slots:
void clicked(); void sendKey(Qt::Key c);
/** /**
* This function will switch the lines. If the line * This function will switch the lines. If the line
...@@ -54,11 +57,7 @@ public slots: ...@@ -54,11 +57,7 @@ public slots:
*/ */
void selectLine(unsigned int line); void selectLine(unsigned int line);
private: void selectAvailableLine();
/**
* Returns the PhoneLine in position line.
*/
PhoneLine *getPhoneLine(unsigned int line);
private: private:
Session mSession; Session mSession;
......
...@@ -75,7 +75,7 @@ Request::toString() ...@@ -75,7 +75,7 @@ Request::toString()
} }
CallRequest::CallRequest(const std::string &sequenceId, CallRelatedRequest::CallRelatedRequest(const std::string &sequenceId,
const std::string &command, const std::string &command,
const std::list< std::string > &args) const std::list< std::string > &args)
: Request(sequenceId, command, args) : Request(sequenceId, command, args)
...@@ -83,7 +83,7 @@ CallRequest::CallRequest(const std::string &sequenceId, ...@@ -83,7 +83,7 @@ CallRequest::CallRequest(const std::string &sequenceId,
{} {}
void void
CallRequest::onError(const std::string &code, const std::string &message) CallRelatedRequest::onError(const std::string &code, const std::string &message)
{ {
onError(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()), onError(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()),
mCallId), mCallId),
...@@ -92,11 +92,11 @@ CallRequest::onError(const std::string &code, const std::string &message) ...@@ -92,11 +92,11 @@ CallRequest::onError(const std::string &code, const std::string &message)
} }
void void
CallRequest::onError(Call, const std::string &, const std::string &) CallRelatedRequest::onError(Call, const std::string &, const std::string &)
{} {}
void void
CallRequest::onEntry(const std::string &code, const std::string &message) CallRelatedRequest::onEntry(const std::string &code, const std::string &message)
{ {
onEntry(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()), onEntry(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()),
mCallId), mCallId),
...@@ -105,11 +105,11 @@ CallRequest::onEntry(const std::string &code, const std::string &message) ...@@ -105,11 +105,11 @@ CallRequest::onEntry(const std::string &code, const std::string &message)
} }
void void
CallRequest::onEntry(Call, const std::string &, const std::string &) CallRelatedRequest::onEntry(Call, const std::string &, const std::string &)
{} {}
void void
CallRequest::onSuccess(const std::string &code, const std::string &message) CallRelatedRequest::onSuccess(const std::string &code, const std::string &message)
{ {
onSuccess(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()), onSuccess(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()),
mCallId), mCallId),
...@@ -118,7 +118,7 @@ CallRequest::onSuccess(const std::string &code, const std::string &message) ...@@ -118,7 +118,7 @@ CallRequest::onSuccess(const std::string &code, const std::string &message)
} }
void void
CallRequest::onSuccess(Call, const std::string &, const std::string &) CallRelatedRequest::onSuccess(Call, const std::string &, const std::string &)
{} {}
AccountRequest::AccountRequest(const std::string &sequenceId, AccountRequest::AccountRequest(const std::string &sequenceId,
......
...@@ -88,10 +88,10 @@ class Request ...@@ -88,10 +88,10 @@ class Request
const std::list< std::string > mArgs; const std::list< std::string > mArgs;
}; };
class CallRequest : public Request class CallRelatedRequest : public Request
{ {
public: public:
CallRequest(const std::string &sequenceId, CallRelatedRequest(const std::string &sequenceId,
const std::string &command, const std::string &command,
const std::list< std::string > &args); const std::list< std::string > &args);
......
...@@ -30,9 +30,7 @@ RequesterImpl::RequesterImpl() ...@@ -30,9 +30,7 @@ RequesterImpl::RequesterImpl()
: mCallIdCount(0) : mCallIdCount(0)
, mSessionIdCount(0) , mSessionIdCount(0)
, mSequenceIdCount(0) , mSequenceIdCount(0)
{ {}
registerObject< Request >(std::string("register"));
}
SessionIO * SessionIO *
RequesterImpl::getSessionIO(const std::string &sessionId) RequesterImpl::getSessionIO(const std::string &sessionId)
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
#include "SFLPhoneApp.hpp" #include "SFLPhoneApp.hpp"
#include "SFLPhoneWindow.hpp" #include "SFLPhoneWindow.hpp"
#include "PhoneLine.hpp"
#include "PhoneLineButton.hpp" #include "PhoneLineButton.hpp"
#include "Requester.hpp"
...@@ -11,17 +13,32 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv) ...@@ -11,17 +13,32 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
, mPhoneLineManager(NB_PHONELINES) , mPhoneLineManager(NB_PHONELINES)
, mSession() , mSession()
, mAccount(mSession.getDefaultAccount()) , mAccount(mSession.getDefaultAccount())
{} {
Requester::instance().registerObject< Request >(std::string("sendtone"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("call"));
}
void void
SFLPhoneApp::initConnections(SFLPhoneWindow *w) SFLPhoneApp::initConnections(SFLPhoneWindow *w)
{ {
// We connect the phone line buttons to the PhoneLineManager
unsigned int i = 0; unsigned int i = 0;
for(std::list< PhoneLineButton * >::iterator pos = w->mPhoneLineButtons.begin(); for(std::list< PhoneLineButton * >::iterator pos = w->mPhoneLineButtons.begin();
pos != w->mPhoneLineButtons.end(); pos != w->mPhoneLineButtons.end();
pos++) { pos++) {
PhoneLine *line = mPhoneLineManager.getPhoneLine(i);
QObject::connect(*pos, SIGNAL(clicked(unsigned int)), QObject::connect(*pos, SIGNAL(clicked(unsigned int)),
&mPhoneLineManager, SLOT(selectLine(unsigned int))); &mPhoneLineManager, SLOT(selectLine(unsigned int)));
QObject::connect(line, SIGNAL(selected()),
*pos, SLOT(press()));
QObject::connect(line, SIGNAL(unselected()),
*pos, SLOT(release()));
QObject::connect(line, SIGNAL(backgrounded()),
*pos, SLOT(suspend()));
i++; i++;
} }
QObject::connect(w, SIGNAL(keyPressed(Qt::Key)),
&mPhoneLineManager, SLOT(sendKey(Qt::Key)));
} }
...@@ -2,17 +2,19 @@ ...@@ -2,17 +2,19 @@
#include <QLabel> #include <QLabel>
#include <QPixmap> #include <QPixmap>
#include <QKeyEvent>
#include <iostream> #include <iostream>
#include "globals.h" #include "globals.h"
#include "PhoneLineButton.hpp" #include "PhoneLineButton.hpp"
#include "JPushButton.hpp"
SFLPhoneWindow::SFLPhoneWindow() SFLPhoneWindow::SFLPhoneWindow()
: QMainWindow(NULL, 0) : QMainWindow()
{ {
// Initialize the background image // Initialize the background image
QLabel *l = new QLabel(this); QLabel *l = new QLabel(this);
QPixmap main(":/images/main-img.png"); QPixmap main(":/sflphone/images/main.png");
l->setPixmap(main); l->setPixmap(main);
resize(main.size()); resize(main.size());
l->resize(main.size()); l->resize(main.size());
...@@ -24,14 +26,12 @@ SFLPhoneWindow::SFLPhoneWindow() ...@@ -24,14 +26,12 @@ SFLPhoneWindow::SFLPhoneWindow()
// os->move(22,44); // os->move(22,44);
initWindowButtons();
initLineButtons(); initLineButtons();
} }
SFLPhoneWindow::~SFLPhoneWindow() SFLPhoneWindow::~SFLPhoneWindow()
{ {}
int i = 0;
i++;
}
void void
SFLPhoneWindow::initLineButtons() SFLPhoneWindow::initLineButtons()
...@@ -40,12 +40,12 @@ SFLPhoneWindow::initLineButtons() ...@@ -40,12 +40,12 @@ SFLPhoneWindow::initLineButtons()
int ypos = 151; int ypos = 151;
int offset = 31; int offset = 31;
for(int i = 0; i < NB_PHONELINES; i++) { for(int i = 0; i < NB_PHONELINES; i++) {
PhoneLineButton *line = new PhoneLineButton(QPixmap(QString(":/images/line") + PhoneLineButton *line = new PhoneLineButton(QPixmap(QString(":/sflphone/images/l") +
QString::number(i + 1) + QString::number(i + 1) +
"off-img.png"), "_off.png"),
QPixmap(QString(":/images/line") + QPixmap(QString(":/sflphone/images/l") +
QString::number(i + 1) + QString::number(i + 1) +
"on-img.png"), "_on.png"),
i, i,
this); this);
line->move(xpos, ypos); line->move(xpos, ypos);
...@@ -54,3 +54,27 @@ SFLPhoneWindow::initLineButtons() ...@@ -54,3 +54,27 @@ SFLPhoneWindow::initLineButtons()
} }
} }
void SFLPhoneWindow::initWindowButtons()
{
mCloseButton = new JPushButton(QPixmap(":/sflphone/images/close_off.png"),
QPixmap(":/sflphone/images/close_on.png"),
this);
QObject::connect(mCloseButton, SIGNAL(clicked()),
this, SLOT(close()));
mCloseButton->move(374,5);
mMinimizeButton = new JPushButton(QPixmap(":/sflphone/images/minimize_off.png"),
QPixmap(":/sflphone/images/minimize_on.png"),
this);
QObject::connect(mMinimizeButton, SIGNAL(clicked()),
this, SLOT(lower()));
mMinimizeButton->move(354,5);
// JPushButton *b = new JPushButton(QPixmap(":/sflphone/images/closeoff.png"),
// QPixmap(":/sflphone/images/closeon.png").
}
void
SFLPhoneWindow::keyPressEvent(QKeyEvent *e) {
// Misc. key
emit keyPressed(Qt::Key(e->key()));
}
#include <QObject>
#include <QMainWindow> #include <QMainWindow>
#include <list> #include <list>
class PhoneLineButton; class PhoneLineButton;
class JPushButton;
class SFLPhoneWindow : public QMainWindow class SFLPhoneWindow : public QMainWindow
{ {
Q_OBJECT;
friend class SFLPhoneApp; friend class SFLPhoneApp;
public: public:
...@@ -14,7 +17,17 @@ public: ...@@ -14,7 +17,17 @@ public:
private: private:
void initLineButtons(); void initLineButtons();
void initWindowButtons();
signals:
void keyPressed(Qt::Key);
protected:
void keyPressEvent(QKeyEvent *e);
private: private:
std::list< PhoneLineButton * > mPhoneLineButtons; std::list< PhoneLineButton * > mPhoneLineButtons;
JPushButton *mCloseButton;
JPushButton *mMinimizeButton;
}; };
class AnswerManagerImpl
{
public:
void setPhoneLineManager(PhoneLineManager *manager);
private:
PhoneLineManager *mManager;
};
void
CallRelatedRequest::onError(Call call, const std::string &code, const std::string &message)
{
PhoneLineManager::instance().error();
}
void
CallRelatedRequest::onEntry(Call, const std::string &, const std::string &)
{}
void
CallRelatedRequest::onSuccess(Call, const std::string &, const std::string &)
{}
#ifndef SFLPHONEGUI_SFLREQUEST_HPP
#define SFLPHONEGUI_SFLREQUEST_HPP
#include "Request.hpp"
class CallRequest : public CallRelatedRequest
{
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment