diff --git a/src/gui/official/Call.hpp b/src/gui/official/Call.hpp index d59eccf33..2b8f096b9 100644 --- a/src/gui/official/Call.hpp +++ b/src/gui/official/Call.hpp @@ -33,6 +33,9 @@ class Call Call(const Session &session, const std::string &callId); + std::string id() + {return mId;} + std::string call(const std::string &to); /** diff --git a/src/gui/official/Event.cpp b/src/gui/official/Event.cpp new file mode 100644 index 000000000..83a989087 --- /dev/null +++ b/src/gui/official/Event.cpp @@ -0,0 +1,43 @@ +#include "globals.h" +#include "Event.hpp" +#include "PhoneLineManager.hpp" + +Event::Event(const std::string &code, + const std::list< std::string > &args) + : mCode(code) + , mArgs(args) +{} + +std::string +Event::toString() +{ + std::string output(mCode); + for(std::list< std::string >::iterator pos = mArgs.begin(); + pos != mArgs.end(); + pos++) { + output += *pos; + } + + return output; +} + +HangupEvent::HangupEvent(const std::string &code, + const std::list< std::string > &args) + : Event(code, args) +{ + if(args.size() != 0) { + mCallId = *args.begin(); + } +} + +void +HangupEvent::execute() +{ + if(mCallId.size() > 0) { + _debug("Hangup Event received for call ID: %s.\n", mCallId.c_str()); + PhoneLineManager::instance().hangup(mCallId); + } + else { + _debug("Event invalid: %s\n", toString().c_str()); + } +} diff --git a/src/gui/official/Event.hpp b/src/gui/official/Event.hpp new file mode 100644 index 000000000..e868c8524 --- /dev/null +++ b/src/gui/official/Event.hpp @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2004-2005 Savoir-Faire Linux inc. + * Author: Jean-Philippe Barrette-LaPierre + * + * + * 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 +#include + +class Event +{ +public: + Event(const std::string &code, + const std::list< std::string > &args); + virtual ~Event(){} + + virtual void execute(){}; + + virtual std::string toString(); + +private: + std::string mCode; + std::list< std::string > mArgs; +}; + + +class HangupEvent : public Event +{ +public: + HangupEvent(const std::string &code, + const std::list< std::string > &args); + + virtual void execute(); + +private: + std::string mCallId; +}; + + +#endif diff --git a/src/gui/official/PhoneLine.cpp b/src/gui/official/PhoneLine.cpp index 9ae54c812..497316fa9 100644 --- a/src/gui/official/PhoneLine.cpp +++ b/src/gui/official/PhoneLine.cpp @@ -140,3 +140,15 @@ PhoneLine::hangup() unselect(); } + + +std::string +PhoneLine::getCallId() +{ + std::string id; + if(mCall) { + id = mCall->id(); + } + + return id; +} diff --git a/src/gui/official/PhoneLine.hpp b/src/gui/official/PhoneLine.hpp index 3ae8bb905..f52fe2504 100644 --- a/src/gui/official/PhoneLine.hpp +++ b/src/gui/official/PhoneLine.hpp @@ -20,6 +20,8 @@ public: void hangup(); void hold(); + std::string getCallId(); + unsigned int line(); /** diff --git a/src/gui/official/PhoneLineManager.cpp b/src/gui/official/PhoneLineManager.cpp deleted file mode 100644 index ecff954d8..000000000 --- a/src/gui/official/PhoneLineManager.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include -#include - -#include "globals.h" - -#include "PhoneLine.hpp" -#include "PhoneLineLocker.hpp" -#include "PhoneLineManager.hpp" - -PhoneLineManager::PhoneLineManager(unsigned int nbLines) - : mAccount(mSession.getDefaultAccount()) - , mCurrentLine(NULL) -{ - for(unsigned int i = 0; i < nbLines; i++) { - mPhoneLines.push_back(new PhoneLine(mSession.createCall(), - i)); - } -} - -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) -{ - 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. - */ -void -PhoneLineManager::selectLine(unsigned int line) -{ - PhoneLine *selectedLine = NULL; - // getting the wanted line; - { - mPhoneLinesMutex.lock(); - if(mPhoneLines.size() > line) { - selectedLine = mPhoneLines[line]; - } - mPhoneLinesMutex.unlock(); - } - - if(selectedLine != NULL) { - _debug("Line %d selected.\n", line); - mCurrentLineMutex.lock(); - PhoneLine *oldLine = mCurrentLine; - mCurrentLine = selectedLine; - mCurrentLineMutex.unlock(); - - if(oldLine != selectedLine) { - if(oldLine != NULL) { - PhoneLineLocker guard(oldLine); - oldLine->unselect(); - } - - PhoneLineLocker guard(selectedLine); - selectedLine->select(); - if(selectedLine->isAvailable()) { - mSession.sendTone(); - } - } - } - else { - _debug("Tried to selected line %d, which appears to be invalid.\n", line); - } -} - -void -PhoneLineManager::call(const QString &) -{ -} diff --git a/src/gui/official/PhoneLineManagerImpl.cpp b/src/gui/official/PhoneLineManagerImpl.cpp index 3045b7a75..3c8bcf77e 100644 --- a/src/gui/official/PhoneLineManagerImpl.cpp +++ b/src/gui/official/PhoneLineManagerImpl.cpp @@ -81,6 +81,27 @@ PhoneLineManagerImpl::getPhoneLine(unsigned int line) return mPhoneLines[line]; } +PhoneLine * +PhoneLineManagerImpl::getPhoneLine(const std::string &callId) +{ + PhoneLine *selectedLine = NULL; + + QMutexLocker guard(&mPhoneLinesMutex); + 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) { @@ -187,6 +208,26 @@ PhoneLineManagerImpl::hangup() } } +void +PhoneLineManagerImpl::hangup(const std::string &callId) +{ + PhoneLine *selectedLine = getPhoneLine(callId); + if(selectedLine) { + PhoneLineLocker guard(selectedLine); + selectedLine->hangup(); + } +} + +void +PhoneLineManagerImpl::hangup(unsigned int line) +{ + PhoneLine *selectedLine = getPhoneLine(line); + if(selectedLine) { + PhoneLineLocker guard(selectedLine); + selectedLine->hangup(); + } +} + void PhoneLineManagerImpl::clear() { diff --git a/src/gui/official/PhoneLineManagerImpl.hpp b/src/gui/official/PhoneLineManagerImpl.hpp index 8cb0cbdf9..495cd7a3c 100644 --- a/src/gui/official/PhoneLineManagerImpl.hpp +++ b/src/gui/official/PhoneLineManagerImpl.hpp @@ -23,10 +23,20 @@ class PhoneLineManagerImpl : public QObject public: PhoneLineManagerImpl(); - - + /** + * Will return the PhoneLine linked to the line + * number. + */ PhoneLine *getPhoneLine(unsigned int line); + + /** + * Will return the PhoneLine with the call ID. + * If there's no PhoneLine of call ID, it will + * return NULL. + */ + PhoneLine *getPhoneLine(const std::string &callId); + PhoneLine *getCurrentLine(); void setNbLines(unsigned int line); @@ -51,6 +61,20 @@ public slots: */ void hangup(); + /** + * This function will hanp up the line number given + * argument. Be aware that the first line is 1, not + * zero. + */ + void hangup(unsigned int line); + + /** + * This function will hanp up the line with the + * following call ID. If there's no line with + * the call ID, it will do nothing. + */ + void hangup(const std::string &callId); + /** * This function will make a call on the * current line. If there's no selected diff --git a/src/gui/official/images/clear_off.png b/src/gui/official/images/clear_off.png new file mode 100644 index 000000000..be1436097 Binary files /dev/null and b/src/gui/official/images/clear_off.png differ diff --git a/src/gui/official/images/clear_on.png b/src/gui/official/images/clear_on.png new file mode 100644 index 000000000..9605e89ae Binary files /dev/null and b/src/gui/official/images/clear_on.png differ