*** empty log message ***

This commit is contained in:
jpbl
2005-09-26 20:22:14 +00:00
parent 085bd7ce5d
commit a3c37ad164
25 changed files with 427 additions and 91 deletions

View File

@ -28,17 +28,6 @@ Account::Account(const std::string &sessionId,
, 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
Account::registerAccount()
{

View File

@ -33,7 +33,6 @@ class Account {
/**
* This will generate a call ready to be used.
*/
Call call(const std::string &to);
std::string registerAccount();
std::string unregisterAccount();

View File

@ -38,6 +38,14 @@ Call::Call(const Session &session,
, 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
Call::answer()

View File

@ -33,6 +33,8 @@ class Call
Call(const Session &session,
const std::string &callId);
std::string call(const std::string &to);
/**
* This function will answer the call.
*/

View File

@ -44,14 +44,14 @@ void
JPushButton::release()
{
resize(mImages[0].size());
setPixmap (mImages[0]);
setPixmap(mImages[0]);
}
void
JPushButton::press()
{
resize(mImages[1].size());
setPixmap (mImages[1]);
setPixmap(mImages[1]);
}
// Mouse button released

View File

@ -26,6 +26,7 @@
#include <QLabel>
#include <QPixmap>
#include <QImage>
/**
* This class Emulate a PushButton but takes two
@ -40,14 +41,15 @@ public:
QWidget *parent,
Qt::WFlags flags = 0);
~JPushButton();
public slots:
/**
* This function will switch the button
*/
void press();
void release();
private:
protected:
QPixmap mImages[2];
protected:
@ -56,7 +58,7 @@ protected:
void mouseMoveEvent(QMouseEvent *);
signals:
void clicked(void);
void clicked();
};

View File

@ -1,11 +1,23 @@
#include <iostream>
#include "globals.h"
#include "PhoneLine.hpp"
#include "Call.hpp"
PhoneLine::PhoneLine()
: mCall(NULL)
PhoneLine::PhoneLine(const Call &call,
unsigned int line)
: mCall(call)
, mLine(line)
, mSelected(false)
, mInUse(false)
{}
unsigned int
PhoneLine::line()
{
return mLine;
}
void
PhoneLine::lock()
{
@ -21,11 +33,60 @@ PhoneLine::unlock()
void
PhoneLine::select()
{
_debug("I am selected.\n");
if(!mSelected) {
_debug("PhoneLine %d: I am selected.\n", mLine + 1);
mSelected = true;
emit selected();
}
}
void
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);
}
}

View File

@ -1,18 +1,22 @@
#include <QChar>
#include <QObject>
#include <QMutex>
#include <string>
class Call;
#include "Call.hpp"
class PhoneLine : public QObject
{
Q_OBJECT
public:
PhoneLine();
PhoneLine(const Call &call, unsigned int line);
~PhoneLine(){}
void call(const std::string &to);
void call();
unsigned int line();
/**
* This will lock the current phone line.
@ -31,6 +35,19 @@ public:
*/
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.
*/
@ -41,11 +58,19 @@ public:
*/
void unselect();
signals:
void selected();
void unselected();
void backgrounded();
private:
Call *mCall;
Call mCall;
QMutex mPhoneLineMutex;
unsigned int mLine;
bool mSelected;
bool mInUse;
//This is the buffer when the line is not in use;
std::string mBuffer;
};

View File

@ -9,18 +9,53 @@ PhoneLineButton::PhoneLineButton(const QPixmap &released,
Qt::WFlags flags)
: JPushButton(released, pressed, parent, flags)
, 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
PhoneLineButton::mouseReleaseEvent (QMouseEvent *e)
{
switch (e->button()) {
case Qt::LeftButton:
release();
// Emulate the left mouse click
if (this->rect().contains(e->pos())) {
emit clicked(mLine);
}
else {
release();
}
break;
default:

View File

@ -5,6 +5,7 @@
#include <QLabel>
#include <QObject>
#include <QPixmap>
#include <QTimer>
#include "JPushButton.hpp"
@ -25,15 +26,23 @@ public:
virtual ~PhoneLineButton(){}
protected:
void mouseReleaseEvent(QMouseEvent *);
signals:
void clicked(unsigned int);
public slots:
void suspend();
void press();
void release();
protected:
void mouseReleaseEvent(QMouseEvent *);
void swap();
private:
unsigned int mLine;
QTimer mTimer;
unsigned int mFace;
};
#endif // defined(__J_PUSH_BUTTON_H__)

View File

@ -1,4 +1,6 @@
#include <QMutexLocker>
#include <iostream>
#include <stdexcept>
#include "globals.h"
@ -11,15 +13,67 @@ PhoneLineManager::PhoneLineManager(unsigned int nbLines)
, mCurrentLine(NULL)
{
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()
{
std::cout << "Clicked" << std::endl;
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)
{
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
* we select 2 line in a very short time.
@ -52,6 +106,9 @@ PhoneLineManager::selectLine(unsigned int line)
PhoneLineLocker guard(selectedLine);
selectedLine->select();
if(selectedLine->isAvailable()) {
mSession.sendTone();
}
}
}
else {
@ -60,6 +117,6 @@ PhoneLineManager::selectLine(unsigned int line)
}
void
PhoneLineManager::call(const QString &to)
PhoneLineManager::call(const QString &)
{
}

View File

@ -1,6 +1,7 @@
#ifndef __PHONELINEMANAGER_HPP__
#define __PHONELINEMANAGER_HPP__
#include <Qt>
#include <QObject>
#include <QMutex>
#include <utility>
@ -41,24 +42,22 @@ public:
*/
void hangup(unsigned int line);
/**
* This function hangup the
*/
PhoneLine *getPhoneLine(unsigned int line);
signals:
void unselected(unsigned int);
void selected(unsigned int);
public slots:
void clicked();
void sendKey(Qt::Key c);
/**
* This function will switch the lines. If the line
* is invalid, it just do nothing.
*/
void selectLine(unsigned int line);
private:
/**
* Returns the PhoneLine in position line.
*/
PhoneLine *getPhoneLine(unsigned int line);
void selectAvailableLine();
private:
Session mSession;

View File

@ -75,7 +75,7 @@ Request::toString()
}
CallRequest::CallRequest(const std::string &sequenceId,
CallRelatedRequest::CallRelatedRequest(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args)
: Request(sequenceId, command, args)
@ -83,7 +83,7 @@ CallRequest::CallRequest(const std::string &sequenceId,
{}
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()),
mCallId),
@ -92,11 +92,11 @@ CallRequest::onError(const std::string &code, const std::string &message)
}
void
CallRequest::onError(Call, const std::string &, const std::string &)
CallRelatedRequest::onError(Call, const std::string &, const std::string &)
{}
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()),
mCallId),
@ -105,11 +105,11 @@ CallRequest::onEntry(const std::string &code, const std::string &message)
}
void
CallRequest::onEntry(Call, const std::string &, const std::string &)
CallRelatedRequest::onEntry(Call, const std::string &, const std::string &)
{}
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()),
mCallId),
@ -118,7 +118,7 @@ CallRequest::onSuccess(const std::string &code, const std::string &message)
}
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,

View File

@ -88,12 +88,12 @@ class Request
const std::list< std::string > mArgs;
};
class CallRequest : public Request
class CallRelatedRequest : public Request
{
public:
CallRequest(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args);
CallRelatedRequest(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args);
/**

View File

@ -30,9 +30,7 @@ RequesterImpl::RequesterImpl()
: mCallIdCount(0)
, mSessionIdCount(0)
, mSequenceIdCount(0)
{
registerObject< Request >(std::string("register"));
}
{}
SessionIO *
RequesterImpl::getSessionIO(const std::string &sessionId)

View File

@ -2,7 +2,9 @@
#include "SFLPhoneApp.hpp"
#include "SFLPhoneWindow.hpp"
#include "PhoneLine.hpp"
#include "PhoneLineButton.hpp"
#include "Requester.hpp"
@ -11,17 +13,32 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
, mPhoneLineManager(NB_PHONELINES)
, mSession()
, mAccount(mSession.getDefaultAccount())
{}
{
Requester::instance().registerObject< Request >(std::string("sendtone"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("call"));
}
void
SFLPhoneApp::initConnections(SFLPhoneWindow *w)
{
// We connect the phone line buttons to the PhoneLineManager
unsigned int i = 0;
for(std::list< PhoneLineButton * >::iterator pos = w->mPhoneLineButtons.begin();
pos != w->mPhoneLineButtons.end();
pos++) {
PhoneLine *line = mPhoneLineManager.getPhoneLine(i);
QObject::connect(*pos, SIGNAL(clicked(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++;
}
QObject::connect(w, SIGNAL(keyPressed(Qt::Key)),
&mPhoneLineManager, SLOT(sendKey(Qt::Key)));
}

View File

@ -2,36 +2,36 @@
#include <QLabel>
#include <QPixmap>
#include <QKeyEvent>
#include <iostream>
#include "globals.h"
#include "PhoneLineButton.hpp"
#include "JPushButton.hpp"
SFLPhoneWindow::SFLPhoneWindow()
: QMainWindow(NULL, 0)
: QMainWindow()
{
// Initialize the background image
QLabel *l = new QLabel(this);
QPixmap main(":/images/main-img.png");
QPixmap main(":/sflphone/images/main.png");
l->setPixmap(main);
resize(main.size());
l->resize(main.size());
// QLabel *os = new QLabel(this);
// QLabel *os = new QLabel(this);
// QPixmap overscreen(":/images/overscreen.png");
// os->setPixmap(overscreen);
// os->resize(overscreen.size());
// os->move(22,44);
initWindowButtons();
initLineButtons();
}
SFLPhoneWindow::~SFLPhoneWindow()
{
int i = 0;
i++;
}
{}
void
SFLPhoneWindow::initLineButtons()
@ -40,12 +40,12 @@ SFLPhoneWindow::initLineButtons()
int ypos = 151;
int offset = 31;
for(int i = 0; i < NB_PHONELINES; i++) {
PhoneLineButton *line = new PhoneLineButton(QPixmap(QString(":/images/line") +
QString::number(i + 1) +
"off-img.png"),
QPixmap(QString(":/images/line") +
QString::number(i + 1) +
"on-img.png"),
PhoneLineButton *line = new PhoneLineButton(QPixmap(QString(":/sflphone/images/l") +
QString::number(i + 1) +
"_off.png"),
QPixmap(QString(":/sflphone/images/l") +
QString::number(i + 1) +
"_on.png"),
i,
this);
line->move(xpos, ypos);
@ -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()));
}

View File

@ -1,20 +1,33 @@
#include <QObject>
#include <QMainWindow>
#include <list>
class PhoneLineButton;
class JPushButton;
class SFLPhoneWindow : public QMainWindow
{
friend class SFLPhoneApp;
Q_OBJECT;
friend class SFLPhoneApp;
public:
SFLPhoneWindow();
~SFLPhoneWindow();
private:
void initLineButtons();
void initWindowButtons();
signals:
void keyPressed(Qt::Key);
protected:
void keyPressEvent(QKeyEvent *e);
private:
std::list< PhoneLineButton * > mPhoneLineButtons;
JPushButton *mCloseButton;
JPushButton *mMinimizeButton;
};

View File

@ -0,0 +1,23 @@
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 &)
{}

View File

@ -0,0 +1,14 @@
#ifndef SFLPHONEGUI_SFLREQUEST_HPP
#define SFLPHONEGUI_SFLREQUEST_HPP
#include "Request.hpp"
class CallRequest : public CallRelatedRequest
{
};
#endif

View File

@ -43,6 +43,12 @@ Session::id() const
return mId;
}
std::string
Session::sendTone() const
{
return Requester::instance().send(mId, "sendtone", std::list< std::string >());
}
Account
Session::getAccount(const std::string &name) const
{
@ -54,3 +60,9 @@ Session::getDefaultAccount() const
{
return Account(mId, std::string("mydefaultaccount"));
}
Call
Session::createCall() const
{
return Call(mId, Requester::instance().generateCallId());
}

View File

@ -37,8 +37,11 @@ class Session
Account getAccount(const std::string &name) const;
Account getDefaultAccount() const;
Call createCall() const;
std::string id() const;
std::string sendTone() const;
private:
std::string mId;

View File

@ -6,6 +6,7 @@ TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .
#CONFIG += debug
# Input
HEADERS += Account.hpp \

View File

@ -1,19 +1,25 @@
<RCC>
<qresource prefix="/images" >
<file alias="main-img.png">images/main.png</file>
<file alias="overscreen.png">images/overscreen.png</file>
<file alias="line1on-img.png">images/l1_on.png</file>
<file alias="line1off-img.png">images/l1_off.png</file>
<file alias="line2on-img.png">images/l2_on.png</file>
<file alias="line2off-img.png">images/l2_off.png</file>
<file alias="line3on-img.png">images/l3_on.png</file>
<file alias="line3off-img.png">images/l3_off.png</file>
<file alias="line4on-img.png">images/l4_on.png</file>
<file alias="line4off-img.png">images/l4_off.png</file>
<file alias="line5on-img.png">images/l5_on.png</file>
<file alias="line5off-img.png">images/l5_off.png</file>
<file alias="line6on-img.png">images/l6_on.png</file>
<file alias="line6off-img.png">images/l6_off.png</file>
<file alias="icon.png">images/logo_ico.png</file>
<qresource prefix="/sflphone" >
<file>images/audio.png</file>
<file>images/close_off.png</file>
<file>images/close_on.png</file>
<file>images/directory_on.png</file>
<file>images/l1_off.png</file>
<file>images/l1_on.png</file>
<file>images/l2_off.png</file>
<file>images/l2_on.png</file>
<file>images/l3_off.png</file>
<file>images/l3_on.png</file>
<file>images/l4_off.png</file>
<file>images/l4_on.png</file>
<file>images/l5_off.png</file>
<file>images/l5_on.png</file>
<file>images/l6_off.png</file>
<file>images/l6_on.png</file>
<file>images/logo_ico.png</file>
<file>images/main.png</file>
<file>images/minimize_off.png</file>
<file>images/minimize_on.png</file>
<file>images/overscreen.png</file>
</qresource>
</RCC>

39
src/gui/official/skin.ini Normal file
View File

@ -0,0 +1,39 @@
# Main window
l1=21,151
l2=52,151
l3=83,151
l4=114,151
l5=145,151
l6=176,151
hangup=225,156
ok=225,182
mute=225,94
conference=225,69
hold=225,68
transfer=225,42
voicemail=310,43
setup=310,68
dtmf=20,181
directory=140,181
screen=22,44
minimize=353,5
close=374,5
vol_mic=347,155-100
vol_spkr=365,155-100
#
# DTMF Keypad
dtmf_1=12,22
dtmf_2=58,22
dtmf_3=104,22
dtmf_4=12,67
dtmf_5=58,67
dtmf_6=104,67
dtmf_7=12,112
dtmf_8=58,112
dtmf_9=104,112
dtmf_star=12,157
dtmf_0=58,157
dtmf_pound=104,157
dtmf_close=141,5
#
# EOF