diff --git a/src/gui/official/PhoneLineManagerImpl.cpp b/src/gui/official/PhoneLineManagerImpl.cpp index 952a365db1ef58dbbef18a7f9009acc18d917bd9..9eb287e2e76b2e36824a576c88f6e664ae9f92f6 100644 --- a/src/gui/official/PhoneLineManagerImpl.cpp +++ b/src/gui/official/PhoneLineManagerImpl.cpp @@ -18,6 +18,9 @@ PhoneLineManagerImpl::PhoneLineManagerImpl() { EventFactory::instance().registerEvent< HangupEvent >("002"); EventFactory::instance().registerEvent< IncommingEvent >("001"); + QObject::connect(this, SIGNAL(connected()), + this, SLOT(startSession())); + } PhoneLineManagerImpl::~PhoneLineManagerImpl() @@ -42,6 +45,14 @@ PhoneLineManagerImpl::initialize() } } +void +PhoneLineManagerImpl::start() +{ + isInitialized(); + + mSession->connect(); +} + void PhoneLineManagerImpl::isInitialized() { QMutexLocker guard(&mIsInitializedMutex); @@ -50,6 +61,12 @@ void PhoneLineManagerImpl::isInitialized() } } +void +PhoneLineManagerImpl::connect() +{ + mSession->connect(); +} + void PhoneLineManagerImpl::startSession() { diff --git a/src/gui/official/PhoneLineManagerImpl.hpp b/src/gui/official/PhoneLineManagerImpl.hpp index fccbef46603b877ba1213394655ccf5e66ed8427..ee2bed5fd457f47a9d776131dba8868873da894b 100644 --- a/src/gui/official/PhoneLineManagerImpl.hpp +++ b/src/gui/official/PhoneLineManagerImpl.hpp @@ -44,6 +44,8 @@ public: signals: void unselected(unsigned int); void selected(unsigned int); + void connected(); + void disconnected(); public slots: /** @@ -56,11 +58,18 @@ public slots: void initialize(); /** - * This will send all the command needed when a - * connection has just been established. + * This function will make the process to start. + * It will connect to the server, and start the + * event handling. */ - void startSession(); - + void start(); + + /** + * This will ask the session to connect + * to the sflphone server. + */ + void connect(); + void sendKey(Qt::Key c); /** @@ -135,6 +144,13 @@ public slots: */ PhoneLine *selectNextAvailableLine(); + private slots: + /** + * This will send all the command needed when a + * connection has just been established. + */ + void startSession(); + private: void isInitialized(); diff --git a/src/gui/official/RequesterImpl.cpp b/src/gui/official/RequesterImpl.cpp index 84ec7f08e489c4596b9f886b4d33ba82e9711f1a..d67cfc3bae06247230a534a5c3ff9c9aeb24d0b0 100644 --- a/src/gui/official/RequesterImpl.cpp +++ b/src/gui/official/RequesterImpl.cpp @@ -86,6 +86,18 @@ RequesterImpl::registerSession(const std::string &id, mSessions.insert(std::make_pair(id, s)); } +void +RequesterImpl::connect(const std::string &id) +{ + std::map< std::string, SessionIO * >::iterator pos = mSessions.find(id); + if(pos == mSessions.end()) { + throw std::logic_error("Trying to connect an unknown session."); + } + + pos->second->connect(); +} + + int RequesterImpl::getCodeCategory(const std::string &code) { diff --git a/src/gui/official/RequesterImpl.hpp b/src/gui/official/RequesterImpl.hpp index 232e516fef96d0c03cbb7fa61362f312287af050..2876c0174109f2ad61220e0726c45548772a6a57 100644 --- a/src/gui/official/RequesterImpl.hpp +++ b/src/gui/official/RequesterImpl.hpp @@ -79,6 +79,11 @@ class RequesterImpl */ void registerSession(const std::string &id, SessionIO *io); + /** + * Will ask the session IO with id to connect. + */ + void connect(const std::string &id); + /** * This function is used to notify that the SessionIO * input of a session is down. It means that we no longer diff --git a/src/gui/official/SFLPhoneApp.cpp b/src/gui/official/SFLPhoneApp.cpp index ca32a05c791c56376649fa71796259853c339cef..4e036a751a6e7c4ae5d3a2cc0b1f3c552253b0b5 100644 --- a/src/gui/official/SFLPhoneApp.cpp +++ b/src/gui/official/SFLPhoneApp.cpp @@ -29,6 +29,7 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv) Requester::instance().registerObject< CallRelatedRequest >(std::string("hold")); Requester::instance().registerObject< CallRelatedRequest >(std::string("unhold")); Requester::instance().registerObject< CallRelatedRequest >(std::string("hangup")); + PhoneLineManager::instance().start(); } void @@ -62,4 +63,9 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w) &PhoneLineManager::instance(), SLOT(clear())); QObject::connect(w, SIGNAL(keyPressed(Qt::Key)), &PhoneLineManager::instance(), SLOT(sendKey(Qt::Key))); + QObject::connect(&PhoneLineManager::instance(), SIGNAL(disconnected()), + w, SLOT(askReconnect())); + QObject::connect(w, SIGNAL(reconnectAsked()), + &PhoneLineManager::instance(), SLOT(connect())); } + diff --git a/src/gui/official/SFLPhoneWindow.cpp b/src/gui/official/SFLPhoneWindow.cpp index 13cb8e160a2ac2280de74739716a564d6e320dbe..72496d606bb6e5858049febf8e84b489bb348c58 100644 --- a/src/gui/official/SFLPhoneWindow.cpp +++ b/src/gui/official/SFLPhoneWindow.cpp @@ -1,6 +1,7 @@ #include "SFLPhoneWindow.hpp" #include <QLabel> +#include <QMessageBox> #include <QPixmap> #include <QKeyEvent> #include <iostream> @@ -96,3 +97,21 @@ SFLPhoneWindow::keyPressEvent(QKeyEvent *e) { // Misc. key emit keyPressed(Qt::Key(e->key())); } + +void +SFLPhoneWindow::askReconnect() +{ + int ret = QMessageBox::critical(NULL, + tr("SFLPhone disconnected"), + tr("The link between SFLPhone and SFLPhoned is broken.\n" + "Do you want to try to reconnect? If not, the application\n" + "will close."), + QMessageBox::Retry | QMessageBox::Default, + QMessageBox::Cancel | QMessageBox::Escape); + if (ret == QMessageBox::Retry) { + emit reconnectAsked(); + } + else { + close(); + } +} diff --git a/src/gui/official/SFLPhoneWindow.hpp b/src/gui/official/SFLPhoneWindow.hpp index 4a19597011fc62aa9c8579d99ec9dd9f964c29dd..72da6fd360ef0cbe3f7cc2fa46fe0b48cc9d18da 100644 --- a/src/gui/official/SFLPhoneWindow.hpp +++ b/src/gui/official/SFLPhoneWindow.hpp @@ -21,6 +21,14 @@ private: signals: void keyPressed(Qt::Key); + void reconnectAsked(); + + public slots: + /** + * This function will prompt a message box, to ask + * if the user want to reconnect to sflphoned. + */ + void askReconnect(); protected: void keyPressEvent(QKeyEvent *e); diff --git a/src/gui/official/Session.cpp b/src/gui/official/Session.cpp index 78911f02d5b252e0450fb29bbfc22950f8606876..29f3d7fcfbc423fbcc723db8e5cc8cc13adee72f 100644 --- a/src/gui/official/Session.cpp +++ b/src/gui/official/Session.cpp @@ -49,6 +49,13 @@ Session::playTone() const return Requester::instance().send(mId, "playtone", std::list< std::string >()); } +void +Session::connect() const +{ + return Requester::instance().connect(mId); +} + + std::string Session::getEvents() const { diff --git a/src/gui/official/Session.hpp b/src/gui/official/Session.hpp index fbb3244cadc0d74f55c09ac6c8e6679e88412e4f..5f2c20f16cca117e995e4d78c5cea6b74cb12cc6 100644 --- a/src/gui/official/Session.hpp +++ b/src/gui/official/Session.hpp @@ -49,6 +49,11 @@ class Session */ std::string getEvents() const; + /** + * This function will ask to the SessionIO + * linked to this session to connect. + */ + void connect() const; Call createCall() const; diff --git a/src/gui/official/SessionIO.hpp b/src/gui/official/SessionIO.hpp index 17862bd270130c1eeecc5d4d2bcbcc4c1a8cc4aa..a5af83f73406952b9ce3dbb1d4bcaea21c6df95c 100644 --- a/src/gui/official/SessionIO.hpp +++ b/src/gui/official/SessionIO.hpp @@ -35,6 +35,9 @@ class SessionIO : public QObject public: virtual ~SessionIO(){} +public slots: + virtual void connect() {} + /** * You can use this function for sending request. * The sending is non-blocking. This function will diff --git a/src/gui/official/TCPSessionIO.cpp b/src/gui/official/TCPSessionIO.cpp index f20d0e1b1b00aca974a65a4087c0288dfae61e3d..22d9a4c497e8dbb6057e4e3f5fe4ac7fd267f04f 100644 --- a/src/gui/official/TCPSessionIO.cpp +++ b/src/gui/official/TCPSessionIO.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <QMessageBox> - #include "globals.h" #include "Requester.hpp" #include "TCPSessionIO.hpp" @@ -35,28 +33,22 @@ TCPSessionIO::TCPSessionIO(const QString &hostname, quint16 port) this, SLOT(sendWaitingRequests())); QObject::connect(mSocket, SIGNAL(connected()), this, SIGNAL(connected())); - QObject::connect(mSocket, SIGNAL(disconnected()), - this, SLOT(askReconnect())); QObject::connect(mSocket, SIGNAL(error(QAbstractSocket::SocketError)), - this, SLOT(askReconnect())); + this, SLOT(error())); + QObject::connect(mSocket, SIGNAL(error(QAbstractSocket::SocketError)), + this, SIGNAL(disconnected())); } TCPSessionIO::~TCPSessionIO() {} void -TCPSessionIO::askReconnect() +TCPSessionIO::error() { - _debug("TCPSessionIO: Link broken.\n"); - int ret = QMessageBox::critical(NULL, - tr("SFLPhone disconnected"), - tr("The link between SFLPhone and SFLPhoned is broken.\n" - "Do you want to try to reconnect?"), - QMessageBox::Retry | QMessageBox::Default, - QMessageBox::Cancel | QMessageBox::Escape); - if (ret == QMessageBox::Retry) { - connect(); - } + _debug("TCPSessionIO: %s. %d\n", + mSocket->errorString().toStdString().c_str(), + mSocket->state()); + mSocket->close(); } void diff --git a/src/gui/official/TCPSessionIO.hpp b/src/gui/official/TCPSessionIO.hpp index 3254558c5d8245f46598affcf34527ed494504b8..0b7c1e8818e5bd47fa2202290891ba5e25745473 100644 --- a/src/gui/official/TCPSessionIO.hpp +++ b/src/gui/official/TCPSessionIO.hpp @@ -42,6 +42,7 @@ public: signals: void connected(); + void disconnected(); public slots: /** @@ -57,10 +58,6 @@ public slots: virtual void send(const QString &request); virtual void send(const std::string &request); - /** - */ - void askReconnect(); - /** * This function is called when we have * incomming data on the socket. @@ -75,6 +72,13 @@ public slots: virtual void receive(std::string &answer); virtual void connect(); + private slots: + /** + * This function is called when we have an error + * on the socket. + */ + void error(); + private: QTcpSocket *mSocket; QString mHostname; diff --git a/src/gui/official/TCPSessionIOCreator.cpp b/src/gui/official/TCPSessionIOCreator.cpp index 13ea7fef09a98193d0e88af491a113fedf236fba..b2f9dab8a3c2439a711dd84b73c568072c9f67e0 100644 --- a/src/gui/official/TCPSessionIOCreator.cpp +++ b/src/gui/official/TCPSessionIOCreator.cpp @@ -12,7 +12,8 @@ TCPSessionIOCreator::create() { TCPSessionIO *t = new TCPSessionIO(mHostname, mPort); QObject::connect(t, SIGNAL(connected()), - &PhoneLineManager::instance(), SLOT(startSession())); - t->connect(); + &PhoneLineManager::instance(), SIGNAL(connected())); + QObject::connect(t, SIGNAL(disconnected()), + &PhoneLineManager::instance(), SIGNAL(disconnected())); return t; }