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

removed the qt gui from sflphone

parent 4ca86775
Branches
Tags
No related merge requests found
Showing
with 0 additions and 2110 deletions
#include <qobject.h>
#include "globals.h"
#include "Call.hpp"
#include "DebugOutput.hpp"
#include "Event.hpp"
Event::Event(const QString &code,
const std::list< QString > &args)
: mCode(code)
, mUnusedArgs(args)
, mArgs(args)
{}
void
Event::execute()
{
DebugOutput::instance() << QObject::tr("Event: Received: %1\n").arg(toString());
}
QString
Event::toString()
{
QString output(mCode);
for(std::list< QString >::iterator pos = mArgs.begin();
pos != mArgs.end();
pos++) {
output += " ";
output += *pos;
}
return output;
}
CallRelatedEvent::CallRelatedEvent(const QString &code,
const std::list< QString > &args)
: Event(code, args)
{
std::list< QString > l(getUnusedArgs());
if(l.size() != 0) {
mCallId = *l.begin();
l.pop_front();
setUnusedArgs(l);
}
}
QString
CallRelatedEvent::getCallId()
{
return mCallId;
}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __EVENT_HPP__
#define __EVENT_HPP__
#include <list>
#include <qstring.h>
class Event
{
public:
Event(const QString &code,
const std::list< QString > &args);
virtual ~Event(){}
virtual void execute();
virtual QString toString();
std::list< QString > getUnusedArgs()
{return mUnusedArgs;}
void setUnusedArgs(const std::list< QString > &args)
{mUnusedArgs = args;}
private:
QString mCode;
std::list< QString > mUnusedArgs;
std::list< QString > mArgs;
};
class CallRelatedEvent : public Event
{
public:
CallRelatedEvent(const QString &code,
const std::list< QString > &args);
QString getCallId();
private:
QString mCallId;
};
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __EVENTFACTORY_HPP__
#define __EVENTFACTORY_HPP__
#include <list>
#include <map>
#include <qstring.h>
#include "Event.hpp"
/**
* This is the base class that we will use to
* create an object from the "create" function.
*/
template< typename Base >
class EventCreatorBase
{
public:
virtual ~EventCreatorBase(){}
virtual Base *create(const QString &code,
const std::list< QString > &args) = 0;
virtual EventCreatorBase *clone() = 0;
};
/**
* This is the actual class that will create
* the request. It will return a Request
*/
template< typename Base, typename Actual >
class EventCreator : public EventCreatorBase< Base >
{
public:
virtual Actual *create(const QString &code,
const std::list< QString > &args);
virtual EventCreatorBase< Base > *clone();
};
/**
* This class is used to create object related to
* a string. However, thoses objects will be created
* with the default constructor.
*/
template< typename Base >
class EventFactoryImpl
{
public:
EventFactoryImpl();
/**
* Ask for a new object linked to the string.
*/
Base *create(const QString &code,
const std::list< QString > &args);
/**
* Register the string to return a Actual type.
*/
template< typename Actual >
void registerEvent(const QString &code);
template< typename Actual >
void registerDefaultEvent();
private:
std::map< QString, EventCreatorBase< Base > * > mEventCreators;
EventCreatorBase< Base > *mDefaultCreator;
};
#include "EventFactory.inl"
#include "utilspp/Singleton.hpp"
typedef utilspp::SingletonHolder< EventFactoryImpl< Event > > EventFactory;
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __EVENTFACTORY_INL__
#define __EVENTFACTORY_INL__
#include <qobject.h>
#include <stdexcept>
#include "DebugOutput.hpp"
template< typename Base, typename Actual >
Actual *
EventCreator< Base, Actual >::create(const QString &code,
const std::list< QString > &args)
{
return new Actual(code, args);
}
template< typename Base, typename Actual >
EventCreatorBase< Base > *
EventCreator< Base, Actual >::clone()
{
return new EventCreator< Base, Actual >();
}
template< typename Base >
EventFactoryImpl< Base >::EventFactoryImpl()
: mDefaultCreator(NULL)
{}
template< typename Base >
Base *
EventFactoryImpl< Base >::create(const QString &code,
const std::list< QString > &args)
{
typename std::map< QString, EventCreatorBase< Base > * >::iterator pos = mEventCreators.find(code);
if(pos == mEventCreators.end()) {
if(mDefaultCreator) {
return mDefaultCreator->create(code, args);
}
else{
DebugOutput::instance() << QObject::tr("The code %1 has no creator registered.\n"
"and there's no default creator").arg(code);
}
}
return pos->second->create(code, args);
}
template< typename Base >
template< typename Actual >
void
EventFactoryImpl< Base >::registerEvent(const QString &code)
{
if(mEventCreators.find(code) != mEventCreators.end()) {
delete mEventCreators[code];
}
mEventCreators[code] = new EventCreator< Base, Actual >();
}
template< typename Base >
template< typename Actual >
void
EventFactoryImpl< Base >::registerDefaultEvent()
{
if(mDefaultCreator) {
delete mDefaultCreator;
}
mDefaultCreator = new EventCreator< Base, Actual >();
}
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __FACTORY_HPP__
#define __FACTORY_HPP__
template< typename T >
struct Creator
{
virtual ~Creator(){}
virtual T *create() = 0;
};
template< typename T >
class Factory
{
public:
Factory();
~Factory();
/**
* This function will set the creator. The
* Factory owns the creator instance.
*/
void setCreator(Creator< T > *creator);
/**
* It ask the creator to create a SessionIO.
* If there's no creator set, it will throw
* a std::logic_error.
*/
T *create();
private:
Creator< T > *mCreator;
};
#include "Factory.inl"
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdexcept>
template< typename T >
Factory< T >::Factory()
: mCreator(0)
{}
template< typename T >
Factory< T >::~Factory()
{
delete mCreator;
}
template< typename T >
void
Factory< T >::setCreator(Creator< T > *creator)
{
mCreator = creator;
}
template< typename T >
T *
Factory< T >::create()
{
if(!mCreator) {
throw std::logic_error("Trying to create without a creator.");
}
else {
return mCreator->create();
}
}
/*
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jerome Oufella (jerome.oufella@savoirfairelinux.com)
*
* Portions (c) Jean-Philippe Barrette-LaPierre
* (jean-philippe.barrette-lapierre@savoirfairelinux.com)
* Portions (c) Valentin Heinitz
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2,
* or (at your option) any later version.
*
* This is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with dpkg; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <qbitmap.h>
#include <qevent.h>
#include <qimage.h>
#include <qevent.h>
#include "globals.h"
#include "JPushButton.hpp"
#include "TransparentWidget.hpp"
JPushButton::JPushButton(const QString &released,
const QString &pressed,
QWidget* parent)
: QLabel(parent)
, mIsPressed(false)
, mIsToggling(false)
{
mImages[0] = transparize(released);
mImages[1] = transparize(pressed);
release();
}
JPushButton::~JPushButton()
{}
void
JPushButton::setToggle(bool toggle)
{
mIsToggling = toggle;
}
QPixmap
JPushButton::transparize(const QString &image)
{
return TransparentWidget::transparize(image);
}
void
JPushButton::release()
{
setPixmap(mImages[0]);
if(mImages[0].hasAlpha()) {
setMask(*mImages[0].mask());
}
resize(mImages[0].size());
}
void
JPushButton::press()
{
setPixmap(mImages[1]);
if(mImages[1].hasAlpha()) {
setMask(*mImages[1].mask());
}
resize(mImages[1].size());
}
// Mouse button released
void
JPushButton::mousePressEvent(QMouseEvent *e)
{
switch (e->button()) {
case Qt::LeftButton:
press();
break;
default:
e->ignore();
break;
}
}
// Mouse button released
void
JPushButton::mouseReleaseEvent (QMouseEvent *e) {
switch (e->button()) {
case Qt::LeftButton:
if(mIsToggling) {
mIsPressed = !mIsPressed;
if(mIsPressed) {
press();
}
else {
release();
}
emit clicked(mIsPressed);
}
else {
release();
emit clicked();
}
// Emulate the left mouse click
//if (this->rect().contains(e->pos())) {
// emit clicked();
//}
break;
default:
e->ignore();
break;
}
}
void
JPushButton::mouseMoveEvent(QMouseEvent *e)
{
e->accept();
}
/*
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jerome Oufella (jerome.oufella@savoirfairelinux.com)
*
* Portions (c) Jean-Philippe Barrette-LaPierre
* (jean-philippe.barrette-lapierre@savoirfairelinux.com)
* Portions (c) Valentin Heinitz
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2,
* or (at your option) any later version.
*
* This is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with dpkg; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __J_PUSH_BUTTON_H__
#define __J_PUSH_BUTTON_H__
#include <qlabel.h>
#include <qpixmap.h>
#include <qimage.h>
/**
* This class Emulate a PushButton but takes two
* images to display its state.
*/
class JPushButton : public QLabel
{
Q_OBJECT
public:
JPushButton(const QString &released,
const QString &pressed,
QWidget *parent);
~JPushButton();
bool isPressed()
{return mIsPressed;}
static QPixmap transparize(const QString &image);
public slots:
/**
* This function will switch the button
*/
virtual void press();
virtual void release();
virtual void setToggle(bool toggled);
protected:
QPixmap mImages[2];
bool mIsPressed;
protected:
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
signals:
void clicked(bool);
void clicked();
private:
bool mIsToggling;
};
#endif // defined(__J_PUSH_BUTTON_H__)
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_OBJECTFACTORY_H
#define SFLPHONEGUI_OBJECTFACTORY_H
#include <list>
#include <map>
#include <qstring.h>
/**
* This is the base class that we will use to
* create an object from the "create" function.
*/
template< typename Base >
class ObjectCreatorBase
{
public:
virtual ~ObjectCreatorBase(){}
virtual Base *create(const QString &command,
const QString &sequenceId,
const std::list< QString > &args) = 0;
virtual ObjectCreatorBase *clone() = 0;
};
/**
* This is the actual class that will create
* the request. It will return a Request
*/
template< typename Base, typename Actual >
class ObjectCreator : public ObjectCreatorBase< Base >
{
public:
virtual Actual *create(const QString &command,
const QString &sequenceId,
const std::list< QString > &args);
virtual ObjectCreatorBase< Base > *clone();
};
/**
* This class is used to create object related to
* a string. However, thoses objects will be created
* with the default constructor.
*/
template< typename Base >
class ObjectFactory
{
public:
/**
* Ask for a new object linked to the string.
*/
Base *create(const QString &requestname,
const QString &sequenceId,
const std::list< QString > &args);
/**
* Register the string to return a Actual type.
*/
template< typename Actual >
void registerObject(const QString &name);
private:
std::map< QString, ObjectCreatorBase< Base > * > mObjectCreators;
};
#include "ObjectFactory.inl"
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_OBJECTFACTORY_INL
#define SFLPHONEGUI_OBJECTFACTORY_INL
#include <stdexcept>
template< typename Base, typename Actual >
Actual *
ObjectCreator< Base, Actual >::create(const QString &command,
const QString &sequenceId,
const std::list< QString > &args)
{
return new Actual(sequenceId, command, args);
}
template< typename Base, typename Actual >
ObjectCreatorBase< Base > *
ObjectCreator< Base, Actual >::clone()
{
return new ObjectCreator< Base, Actual >();
}
template< typename Base >
Base *
ObjectFactory< Base >::create(const QString &command,
const QString &sequenceId,
const std::list< QString > &args)
{
typename std::map< QString, ObjectCreatorBase< Base > * >::iterator pos = mObjectCreators.find(command);
if(pos == mObjectCreators.end()) {
throw std::logic_error("We need to have a better handling");
//throw std::runtime_error("The command \"" + command.toStdString() + "\" has no creator registered.");
}
return pos->second->create(command, sequenceId, args);
}
template< typename Base >
template< typename Actual >
void
ObjectFactory< Base >::registerObject(const QString &name)
{
if(mObjectCreators.find(name) != mObjectCreators.end()) {
delete mObjectCreators[name];
}
mObjectCreators[name] = new ObjectCreator< Base, Actual >();
}
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_OBJECTPOOL_H
#define SFLPHONEGUI_OBJECTPOOL_H
#include <list>
#include <qstring.h>
#include <QMutex>
#include <QWaitCondition>
template< typename T >
class ObjectPool
{
public:
/**
* This function will push a line in the pool.
*/
void push(const T &line);
/**
* This function will wait for an available line.
*/
bool pop(T &value, unsigned long time = ULONG_MAX);
private:
std::list< T > mPool;
QMutex mMutex;
QWaitCondition mDataAvailable;
};
#include "ObjectPool.inl"
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_OBJECTPOOL_INL
#define SFLPHONEGUI_OBJECTPOOL_INL
template< typename T >
void
ObjectPool< T >::push(const T &value)
{
QMutexLocker guard(&mMutex);
mPool.push_back(value);
mDataAvailable.wakeOne();
}
template< typename T >
bool
ObjectPool< T >::pop(T &value, unsigned long time)
{
QMutexLocker guard(&mMutex);
mDataAvailable.wait(guard.mutex(), time);
if(mPool.begin() == mPool.end()) {
return false;
}
else {
typename std::list< T >::iterator pos = mPool.begin();
mPool.pop_front();
value = (*pos);
return true;
}
}
#endif
#include <iostream>
#include "globals.h"
#include "Call.hpp"
#include "DebugOutput.hpp"
#include "PhoneLine.hpp"
PhoneLine::PhoneLine(const Session &session,
const Account &account,
unsigned int line)
: mSession(session)
, mAccount(account)
, mCall(NULL)
, mLine(line)
, mSelected(false)
, mLineStatus("test")
, mActionTimer(new QTimer(this))
, mIsOnError(false)
{
QObject::connect(mActionTimer, SIGNAL(timeout()),
this, SLOT(resetAction()));
}
PhoneLine::~PhoneLine()
{
delete mCall;
mCall = NULL;
}
QString
PhoneLine::getLineStatus()
{
return mLineStatus;
}
void
PhoneLine::resetAction()
{
setAction("");
}
void
PhoneLine::setLineStatus(const QString &status)
{
mActionTimer->stop();
mAction = "";
mLineStatus = status;
emit lineStatusChanged(mLineStatus);
}
void
PhoneLine::setAction(const QString &status)
{
mActionTimer->stop();
mAction = status;
emit actionChanged(mAction);
}
void
PhoneLine::setTempAction(const QString &status)
{
mActionTimer->stop();
mActionTimer->start(3000);
mAction = status;
emit actionChanged(mAction);
}
unsigned int
PhoneLine::line()
{
return mLine;
}
void
PhoneLine::lock()
{
mPhoneLineMutex.lock();
}
void
PhoneLine::unlock()
{
mPhoneLineMutex.unlock();
}
void
PhoneLine::select(bool hardselect)
{
if(!mSelected) {
DebugOutput::instance() << tr("PhoneLine %1: I am selected.\n").arg(mLine);
mSelected = true;
if(!hardselect) {
if(mCall) {
if(mIsOnError) {
close();
}
else if(mCall->isIncomming()) {
answer();
}
else {
unhold();
}
}
else {
setLineStatus(QObject::tr("Ready."));
setAction("");
}
}
emit selected();
}
}
void
PhoneLine::disconnect()
{
mSelected = false;
DebugOutput::instance() << QObject::tr("PhoneLine %1: I am disconnected.\n").arg(mLine);
close();
emit unselected();
}
void
PhoneLine::close()
{
DebugOutput::instance() << tr("PhoneLine %1: I am closed.\n").arg(mLine);
if(mCall) {
delete mCall;
mCall = NULL;
}
mIsOnError = false;
}
void
PhoneLine::error()
{
mIsOnError = true;
}
void
PhoneLine::unselect(bool hardselect)
{
if(mSelected) {
DebugOutput::instance() << tr("PhoneLine %1: I am unselected.\n").arg(mLine);
setAction("");
mSelected = false;
if(mIsOnError) {
close();
}
if(mCall) {
if(!hardselect) {
mCall->hold();
}
emit backgrounded();
}
else {
emit unselected();
}
}
}
void
PhoneLine::incomming(const Call &call)
{
if(mCall) {
DebugOutput::instance() << tr("PhoneLine %1: Trying to set a phone line to an active call.\n").arg(mLine);
}
else {
mCall = new Call(call);
emit backgrounded();
}
}
void
PhoneLine::clear()
{
mBuffer = "";
emit bufferStatusChanged(mBuffer);
}
void
PhoneLine::sendKey(Qt::Key c)
{
DebugOutput::instance() << tr("PhoneLine %1: Received the character:%2.\n")
.arg(mLine)
.arg(c);
switch(c) {
case Qt::Key_Enter:
case Qt::Key_Return:
if(!mCall) {
return call();
}
break;
default:
if (QChar(c).isDigit() || c == Qt::Key_Asterisk || c == Qt::Key_NumberSign) {
if(!mCall) {
mSession.playDtmf(c);
mBuffer += c;
emit bufferStatusChanged(mBuffer);
}
else {
mCall->sendDtmf(c);
}
}
}
}
void
PhoneLine::call()
{
if(mBuffer.length()) {
call(mBuffer);
}
}
void
PhoneLine::call(const QString &to)
{
DebugOutput::instance() << tr("PhoneLine %1: Calling %2.\n").arg(mLine).arg(to);
if(!mCall) {
setLineStatus(tr("Calling %1...").arg(to));
mCall = new Call(mAccount.createCall(to));
clear();
}
}
void
PhoneLine::hold()
{
if(mCall) {
setAction(tr("Holding..."));
DebugOutput::instance() << tr("PhoneLine %1: Trying to Hold.\n").arg(mLine);
mCall->hold();
}
unselect();
}
void
PhoneLine::unhold()
{
if(mCall) {
setAction("Unholding...");
DebugOutput::instance() << tr("PhoneLine %1: Trying to Unhold.\n").arg(mLine);
mCall->unhold();
}
}
void
PhoneLine::answer()
{
if(mCall) {
setAction("Answering...");
DebugOutput::instance() << tr("PhoneLine %1: Trying to answer.\n").arg(mLine);
mCall->answer();
}
}
void
PhoneLine::hangup(bool sendrequest)
{
if(sendrequest) {
setAction(tr("Hanguping..."));
}
else {
setAction(tr("Hanguped."));
}
if(mCall) {
if(sendrequest) {
mCall->hangup();
}
delete mCall;
mCall = NULL;
}
else {
clear();
}
//This is a hack for unselect;
mSelected = true;
unselect();
}
QString
PhoneLine::getCallId()
{
QString id;
if(mCall) {
id = mCall->id();
}
return id;
}
#include <qobject.h>
#include <qmutex.h>
#include <qstring.h>
#include <qtimer.h>
#include "Account.hpp"
#include "Session.hpp"
class Call;
class PhoneLine : public QObject
{
Q_OBJECT
public:
PhoneLine(const Session &session,
const Account &account,
unsigned int line);
~PhoneLine();
void call(const QString &to);
void call();
void answer();
void hangup(bool sendrequest = true);
void hold();
void unhold();
QString getCallId();
unsigned int line();
/**
* This will lock the current phone line.
*
* Note: this will only lock the phone line
* for those that uses this lock, unlock
* mechanism. PhoneLineManager always uses
* this mechanism. So, if you work only with
* PhoneLineManager, it will be thread safe.
*/
void lock();
/**
* This will unlock the current phone line.
* See the Note of the lock function.
*/
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 !mCall;}
void sendKey(Qt::Key c);
QString getLineStatus();
QString getBuffer()
{return mBuffer;}
public slots:
void setLineStatus(const QString &);
void setAction(const QString &);
void setTempAction(const QString &);
void resetAction();
void incomming(const Call &call);
/**
* Clears the buffer of the line.
*/
void clear();
/**
* The user selected this line.
*/
void select(bool hardselect = false);
/**
* This phoneline is no longer selected.
*/
void unselect(bool hardselect = false);
/**
* This will do a hard unselect. it means it
* will remove the call if there's one.
*/
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 &){}
signals:
void selected();
void unselected();
void backgrounded();
void lineStatusChanged(QString);
void actionChanged(QString);
void bufferStatusChanged(QString);
private:
Session mSession;
Account mAccount;
Call *mCall;
QMutex mPhoneLineMutex;
unsigned int mLine;
bool mSelected;
bool mInUse;
//This is the buffer when the line is not in use;
QString mBuffer;
QString mLineStatus;
QString mAction;
QTimer *mActionTimer;
bool mIsOnError;
};
#include "globals.h"
#include "PhoneLineButton.hpp"
#include <qevent.h>
#include <qtimer.h>
PhoneLineButton::PhoneLineButton(const QString &released,
const QString &pressed,
unsigned int line,
QWidget *parent)
: JPushButton(released, pressed, parent)
, mLine(line)
, mFace(0)
{
mTimer = new QTimer(this);
connect(mTimer, SIGNAL(timeout()),
this, SLOT(swap()));
}
void
PhoneLineButton::suspend()
{
if(isPressed()) {
mFace = 1;
}
else {
mFace = 0;
}
swap();
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:
// Emulate the left mouse click
if (this->rect().contains(e->pos())) {
emit clicked(mLine);
}
else {
release();
}
break;
default:
e->ignore();
break;
}
}
#ifndef __PHONELINEBUTTON_HPP__
#define __PHONELINEBUTTON_HPP__
#include <qlabel.h>
#include <qobject.h>
#include <qpixmap.h>
#include "JPushButton.hpp"
class QTimer;
/**
* This class Emulate a PushButton but takes two
* images to display its state.
*/
class PhoneLineButton : public JPushButton
{
Q_OBJECT
public:
PhoneLineButton(const QString &released,
const QString &pressed,
unsigned int line,
QWidget *parent);
virtual ~PhoneLineButton(){}
signals:
void clicked(unsigned int);
public slots:
virtual void suspend();
virtual void press();
virtual void release();
private slots:
void swap();
protected:
void mouseReleaseEvent(QMouseEvent *);
private:
unsigned int mLine;
QTimer *mTimer;
unsigned int mFace;
};
#endif // defined(__J_PUSH_BUTTON_H__)
#include "PhoneLineLocker.hpp"
#include "PhoneLine.hpp"
PhoneLineLocker::PhoneLineLocker(PhoneLine *line, bool lock)
: mPhoneLine(line)
{
if(mPhoneLine && lock) {
mPhoneLine->lock();
}
}
PhoneLineLocker::~PhoneLineLocker()
{
if(mPhoneLine) {
mPhoneLine->unlock();
}
}
#ifndef SFLPHONEGUI_PHONELINELOCKER_HPP
#define SFLPHONEGUI_PHONELINELOCKER_HPP
class PhoneLine;
/**
* This class is used as a Lock. It means
* that it will lock a phone line on its
* constructor, and unlock it in its
* destructor. This is generaly used to
* be exception safe.
*/
class PhoneLineLocker
{
public:
/**
* Retreive the "line" PhoneLine and
* locks it.
*/
PhoneLineLocker(PhoneLine *line, bool lock = true);
/**
* Unlock the currently locked PhoneLine.
*/
~PhoneLineLocker();
private:
PhoneLine *mPhoneLine;
};
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author : Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __PHONELINEMANAGER_HPP__
#define __PHONELINEMANAGER_HPP__
#include "utilspp/Singleton.hpp"
#include "PhoneLineManagerImpl.hpp"
typedef utilspp::SingletonHolder< PhoneLineManagerImpl > PhoneLineManager;
#endif
#include <iostream>
#include <stdexcept>
#include "globals.h"
#include "CallStatusFactory.hpp"
#include "SFLEvents.hpp"
#include "SFLCallStatus.hpp"
#include "PhoneLine.hpp"
#include "PhoneLineLocker.hpp"
#include "PhoneLineManager.hpp"
PhoneLineManagerImpl::PhoneLineManagerImpl()
: mSession(NULL)
, mAccount(NULL)
, mCurrentLine(NULL)
, mIsInitialized(false)
, mVolume(-1)
, mMicVolume(-1)
{
EventFactory::instance().registerDefaultEvent< DefaultEvent >();
// TODO: 000
EventFactory::instance().registerEvent< CallRelatedEvent >("000");
EventFactory::instance().registerEvent< IncommingEvent >("001");
EventFactory::instance().registerEvent< HangupEvent >("002");
// TODO: 020
EventFactory::instance().registerEvent< CallRelatedEvent >("020");
EventFactory::instance().registerEvent< VolumeEvent >("021");
EventFactory::instance().registerEvent< MicVolumeEvent >("022");
EventFactory::instance().registerEvent< TryingStatus >("110");
EventFactory::instance().registerEvent< RingingStatus >("111");
EventFactory::instance().registerEvent< HoldStatus >("112");
EventFactory::instance().registerEvent< EstablishedStatus >("113");
EventFactory::instance().registerEvent< BusyStatus >("114");
EventFactory::instance().registerEvent< CongestionStatus >("115");
EventFactory::instance().registerEvent< WrongNumberStatus >("116");
QObject::connect(this, SIGNAL(disconnected()),
this, SLOT(closeSession()));
QObject::connect(this, SIGNAL(readyToHandleEvents()),
this, SLOT(handleEvents()));
QObject::connect(this, SIGNAL(connected()),
this, SIGNAL(readyToSendStatus()));
QObject::connect(this, SIGNAL(readyToSendStatus()),
this, SLOT(startSession()));
}
PhoneLineManagerImpl::~PhoneLineManagerImpl()
{
delete mSession;
delete mAccount;
for(std::vector< PhoneLine * >::iterator pos = mPhoneLines.begin();
pos != mPhoneLines.end();
pos++) {
delete *pos;
}
}
void
PhoneLineManagerImpl::initialize()
{
if(!mIsInitialized) {
mIsInitialized = true;
mSession = new Session();
mAccount = new Account(mSession->getDefaultAccount());
}
}
void
PhoneLineManagerImpl::start()
{
isInitialized();
emit globalStatusSet(QString(tr("Trying to connect to sflphone server..")));
mSession->connect();
}
void PhoneLineManagerImpl::isInitialized()
{
if(!mIsInitialized) {
throw std::logic_error("Trying to use PhoneLineManager without prior initialize.");
}
}
void
PhoneLineManagerImpl::connect()
{
isInitialized();
emit globalStatusSet(QString(tr("Trying to connect to sflphone server..")));
mSession->connect();
}
void
PhoneLineManagerImpl::startSession()
{
isInitialized();
closeSession();
emit globalStatusSet(QString(tr("Trying to get line status...")));
mSession->getCallStatus();
}
void
PhoneLineManagerImpl::handleEvents()
{
isInitialized();
emit globalStatusSet(QString(tr("SFLPhone is ready to serve you, master.")));
mSession->getEvents();
mSession->list("audiodevice");
}
void
PhoneLineManagerImpl::closeSession()
{
isInitialized();
mCurrentLine = NULL;
unsigned int i = 0;
while(i < mPhoneLines.size()) {
mPhoneLines[i]->disconnect();
i++;
}
emit lineStatusSet("");
emit bufferStatusSet("");
emit actionSet("");
emit globalStatusSet("Disconnected.");
}
PhoneLine *
PhoneLineManagerImpl::getCurrentLine()
{
isInitialized();
return mCurrentLine;
}
void
PhoneLineManagerImpl::setNbLines(unsigned int nb)
{
isInitialized();
mPhoneLines.clear();
for(unsigned int i = 0; i < nb; i++) {
PhoneLine *p = new PhoneLine(*mSession, *mAccount, i + 1);
QObject::connect(p, SIGNAL(lineStatusChanged(QString)),
this, SIGNAL(unselectedLineStatusSet(QString)));
mPhoneLines.push_back(p);
}
}
PhoneLine *
PhoneLineManagerImpl::getNextAvailableLine()
{
isInitialized();
PhoneLine *selectedLine = NULL;
PhoneLine *current = mCurrentLine;
unsigned int i = 0;
while(i < mPhoneLines.size() && !selectedLine) {
if(mPhoneLines[i]->isAvailable() &&
mPhoneLines[i] != current) {
selectedLine = mPhoneLines[i];
}
else {
i++;
}
}
return selectedLine;
}
PhoneLine *
PhoneLineManagerImpl::getLine(const Call &call)
{
isInitialized();
PhoneLine *selectedLine = NULL;
unsigned int i = 0;
while(i < mPhoneLines.size() && !selectedLine) {
if(mPhoneLines[i]->getCallId() == call.id()) {
selectedLine = mPhoneLines[i];
}
else {
i++;
}
}
return selectedLine;
}
PhoneLine *
PhoneLineManagerImpl::getLine(unsigned int line)
{
isInitialized();
PhoneLine *selectedLine = NULL;
if(line < mPhoneLines.size()) {
selectedLine = mPhoneLines[line];
}
return selectedLine;
}
void
PhoneLineManagerImpl::select(PhoneLine *line, bool hardselect)
{
if(line && (mCurrentLine != line)) {
unselect();
QObject::disconnect(line, SIGNAL(lineStatusChanged(QString)),
this, SIGNAL(unselectedLineStatusSet(QString)));
QObject::connect(line, SIGNAL(lineStatusChanged(QString)),
this, SIGNAL(lineStatusSet(QString)));
QObject::connect(line, SIGNAL(actionChanged(QString)),
this, SIGNAL(actionSet(QString)));
QObject::connect(line, SIGNAL(bufferStatusChanged(QString)),
this, SIGNAL(bufferStatusSet(QString)));
mCurrentLine = line;
mCurrentLine->select(hardselect);
if(mCurrentLine->isAvailable() && !hardselect) {
mSession->playTone();
}
emit lineStatusSet(mCurrentLine->getLineStatus());
emit bufferStatusSet(mCurrentLine->getBuffer());
}
}
void
PhoneLineManagerImpl::unselect()
{
if(mCurrentLine) {
QObject::disconnect(mCurrentLine, SIGNAL(lineStatusChanged(QString)),
this, SIGNAL(lineStatusSet(QString)));
QObject::disconnect(mCurrentLine, SIGNAL(actionChanged(QString)),
this, SIGNAL(actionSet(QString)));
QObject::disconnect(mCurrentLine, SIGNAL(bufferStatusChanged(QString)),
this, SIGNAL(bufferStatusSet(QString)));
QObject::connect(mCurrentLine, SIGNAL(lineStatusChanged(QString)),
this, SIGNAL(unselectedLineStatusSet(QString)));
if(mCurrentLine->isAvailable()) {
mSession->stopTone();
}
mCurrentLine->unselect();
mCurrentLine = NULL;
}
}
PhoneLine *
PhoneLineManagerImpl::selectNextAvailableLine()
{
isInitialized();
PhoneLine *selectedLine = getNextAvailableLine();
// If we found one available line.
if(selectedLine) {
unselect();
select(selectedLine);
}
return selectedLine;
}
PhoneLine *
PhoneLineManagerImpl::getPhoneLine(unsigned int line)
{
isInitialized();
if(mPhoneLines.size() <= line) {
throw std::runtime_error("Trying to get an invalid Line");
}
return mPhoneLines[line];
}
PhoneLine *
PhoneLineManagerImpl::getPhoneLine(const QString &callId)
{
isInitialized();
PhoneLine *selectedLine = NULL;
unsigned int i = 0;
while(i < mPhoneLines.size() &&
!selectedLine) {
if(mPhoneLines[i]->getCallId() == callId) {
selectedLine = mPhoneLines[i];
}
else {
i++;
}
}
return selectedLine;
}
void
PhoneLineManagerImpl::sendKey(Qt::Key c)
{
isInitialized();
PhoneLine *selectedLine = getCurrentLine();
// Only digits that select a line if there's
// no current line.
if (!selectedLine && QChar(c).isDigit()) {
selectedLine = selectNextAvailableLine();
}
if(selectedLine) {
selectedLine->sendKey(c);
}
}
void
PhoneLineManagerImpl::selectLine(const QString &callId, bool hardselect)
{
isInitialized();
PhoneLine *selectedLine = NULL;
unsigned int line = 0;
while(!selectedLine && line < mPhoneLines.size()) {
if(mPhoneLines[line]->getCallId() == callId) {
selectedLine = mPhoneLines[line];
}
else {
line++;
}
}
if(selectedLine) {
selectLine(line, hardselect);
}
else {
DebugOutput::instance() << QObject::tr("PhoneLineManager: Tried to selected line with call ID (%1), "
"which appears to be invalid.\n").arg(callId);
}
}
/**
* Warning: This function might 'cause a problem if
* we select 2 line in a very short time.
*/
void
PhoneLineManagerImpl::selectLine(unsigned int line, bool hardselect)
{
isInitialized();
PhoneLine *selectedLine = NULL;
// getting the wanted line;
{
if(mPhoneLines.size() > line) {
selectedLine = mPhoneLines[line];
}
}
if(selectedLine != NULL) {
PhoneLine *oldLine = mCurrentLine;
if(oldLine != selectedLine) {
select(selectedLine, hardselect);
}
}
else {
DebugOutput::instance() << QObject::tr("PhoneLineManager: Tried to selected line %1, "
"which appears to be invalid.\n").arg(line);
}
}
void
PhoneLineManagerImpl::call(const QString &to)
{
PhoneLine *current = getCurrentLine();
if(current) {
current->call(to);
}
}
void
PhoneLineManagerImpl::call()
{
PhoneLine *current = getCurrentLine();
if(current) {
current->call();
}
}
void
PhoneLineManagerImpl::hold()
{
PhoneLine *selectedLine = mCurrentLine;
mCurrentLine = NULL;
if(selectedLine) {
if(selectedLine->isAvailable()) {
mSession->stopTone();
}
selectedLine->hold();
}
}
void
PhoneLineManagerImpl::hangup(bool sendrequest)
{
PhoneLine *selectedLine = mCurrentLine;
mCurrentLine = NULL;
if(selectedLine) {
if(selectedLine->isAvailable()) {
mSession->stopTone();
}
selectedLine->hangup(sendrequest);
lineStatusSet("");
}
}
void
PhoneLineManagerImpl::mute(bool muting)
{
if(muting) {
mute();
}
else {
unmute();
}
}
void
PhoneLineManagerImpl::mute()
{
isInitialized();
mSession->mute();
}
void
PhoneLineManagerImpl::setup()
{
isInitialized();
mSession->configGetAll();
}
void
PhoneLineManagerImpl::unmute()
{
isInitialized();
mSession->unmute();
}
void
PhoneLineManagerImpl::hangup(const QString &callId, bool sendrequest)
{
PhoneLine *selectedLine = getPhoneLine(callId);
hangup(selectedLine, sendrequest);
}
void
PhoneLineManagerImpl::hangup(unsigned int line, bool sendrequest)
{
PhoneLine *selectedLine = getPhoneLine(line);
hangup(selectedLine, sendrequest);
}
void
PhoneLineManagerImpl::hangup(PhoneLine *line, bool sendrequest)
{
if(line) {
line->hangup(sendrequest);
if(mCurrentLine == line) {
unselect();
}
}
}
void
PhoneLineManagerImpl::clear()
{
PhoneLine *selectedLine = mCurrentLine;
if(selectedLine) {
selectedLine->clear();
}
}
void
PhoneLineManagerImpl::incomming(const QString &accountId,
const QString &callId,
const QString &peer)
{
Call call(mSession->id(), accountId, callId, true);
PhoneLine *line = addCall(call, peer, QObject::tr("Incomming"));
if(line) {
line->setLineStatus(QObject::tr("Ringing (%1)...").arg(peer));
}
}
PhoneLine *
PhoneLineManagerImpl::addCall(const QString &accountId,
const QString &callId,
const QString &peer,
const QString &state)
{
return addCall(Call(mSession->id(), accountId, callId), peer, state);
}
PhoneLine *
PhoneLineManagerImpl::addCall(Call call,
const QString &peer,
const QString &state)
{
PhoneLine *selectedLine = getNextAvailableLine();
if(selectedLine) {
selectedLine->incomming(call);
selectedLine->setPeer(peer);
selectedLine->setLineStatus(state);
}
else {
DebugOutput::instance() << QObject::tr("PhoneLineManager: There's no available lines"
"here for the incomming call ID: %1.\n")
.arg(call.id());
call.notAvailable();
}
return selectedLine;
}
void
PhoneLineManagerImpl::updateVolume(int volume)
{
mVolume = volume;
emit volumeUpdated((unsigned int)volume);
}
void
PhoneLineManagerImpl::updateMicVolume(int volume)
{
mMicVolume = volume;
emit micVolumeUpdated((unsigned int)volume);
}
void
PhoneLineManagerImpl::setVolume(int volume)
{
if(mVolume != volume) {
mSession->volume(volume);
updateVolume(volume);
}
}
void
PhoneLineManagerImpl::setMicVolume(int volume)
{
if(mMicVolume != volume) {
mSession->micVolume(volume);
updateMicVolume(volume);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment