Commit 236c229d authored by jpbl's avatar jpbl
Browse files

Line managing works

parent cecca79b
......@@ -22,6 +22,7 @@
#include <list>
#include "Call.hpp"
#include "Session.hpp"
#include "Requester.hpp"
......
......@@ -41,14 +41,12 @@ public:
Qt::WFlags flags = 0);
~JPushButton();
private:
/**
* This function will switch the button
*/
void press();
void release();
private:
QPixmap mImages[2];
......
......@@ -33,6 +33,7 @@ template< typename Base >
class ObjectCreatorBase
{
public:
virtual ~ObjectCreatorBase(){}
virtual Base *create(const std::string &command,
const std::string &sequenceId,
const std::list< std::string > &args) = 0;
......
#include "globals.h"
#include "PhoneLine.hpp"
#include "Call.hpp"
PhoneLine::PhoneLine()
: mCall(NULL)
......@@ -17,3 +17,15 @@ PhoneLine::unlock()
{
mPhoneLineMutex.unlock();
}
void
PhoneLine::select()
{
_debug("I am selected.\n");
}
void
PhoneLine::unselect()
{
_debug("I am unselected.\n");
}
......@@ -2,7 +2,7 @@
#include <QMutex>
#include <string>
#include "Call.h"
class Call;
class PhoneLine : public QObject
{
......@@ -10,7 +10,7 @@ class PhoneLine : public QObject
public:
PhoneLine();
~PhoneLine();
~PhoneLine(){}
void call(const std::string &to);
......@@ -31,6 +31,16 @@ public:
*/
void unlock();
/**
* The user selected this line.
*/
void select();
/**
* This phoneline is no longer selected.
*/
void unselect();
signals:
void selected();
void unselected();
......@@ -38,4 +48,4 @@ signals:
private:
Call *mCall;
QMutex mPhoneLineMutex;
}
};
#include "PhoneLineButton.hpp"
#include <QMouseEvent>
PhoneLineButton::PhoneLineButton(const QPixmap &released,
const QPixmap &pressed,
unsigned int line,
QWidget *parent,
Qt::WFlags flags)
: JPushButton(released, pressed, parent, flags)
, mLine(line)
{}
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);
}
break;
default:
e->ignore();
break;
}
}
#ifndef __PHONELINEBUTTON_HPP__
#define __PHONELINEBUTTON_HPP__
#include <QLabel>
#include <QObject>
#include <QPixmap>
#include "JPushButton.hpp"
/**
* This class Emulate a PushButton but takes two
* images to display its state.
*/
class PhoneLineButton : public JPushButton
{
Q_OBJECT
public:
PhoneLineButton(const QPixmap &released,
const QPixmap &pressed,
unsigned int line,
QWidget *parent,
Qt::WFlags flags = 0);
virtual ~PhoneLineButton(){}
protected:
void mouseReleaseEvent(QMouseEvent *);
signals:
void clicked(unsigned int);
private:
unsigned int mLine;
};
#endif // defined(__J_PUSH_BUTTON_H__)
#include "PhoneLineLocker.hpp"
#include "PhoneLine.hpp"
PhoneLineLocker::PhoneLineLocker(PhoneLine *line)
: mPhoneLine(line)
......
#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
......@@ -21,7 +22,10 @@ public:
/**
* Unlock the currently locked PhoneLine.
*/
~PhoneLine();
}
~PhoneLineLocker();
private:
PhoneLine *mPhoneLine;
};
#endif
#include <iostream>
#include "globals.h"
#include "PhoneLine.hpp"
#include "PhoneLineLocker.hpp"
#include "PhoneLineManager.hpp"
PhoneLineManager::PhoneLineManager()
PhoneLineManager::PhoneLineManager(unsigned int nbLines)
: mAccount(mSession.getDefaultAccount())
, mCurrentLine(NULL)
{}
{
for(unsigned int i = 0; i < nbLines; i++) {
mPhoneLines.push_back(new PhoneLine());
}
}
void PhoneLineManager::clicked()
{
......@@ -30,6 +38,7 @@ PhoneLineManager::selectLine(unsigned int line)
}
if(selectedLine != NULL) {
_debug("Line %d selected.\n", line);
mCurrentLineMutex.lock();
PhoneLine *oldLine = mCurrentLine;
mCurrentLine = selectedLine;
......@@ -45,12 +54,12 @@ PhoneLineManager::selectLine(unsigned int line)
selectedLine->select();
}
}
else {
_debug("Tried to selected line %d, which appears to be invalid.\n", line);
}
}
void
PhoneLineManager::call(const QString &to)
{
{
QMutexLock currentLineGuard(&mCurrentLineMutex);
if
}
#ifndef __PHONELINEMANAGER_HPP__
#define __PHONELINEMANAGER_HPP__
#include <QObject>
#include <QMutex>
#include <utility>
#include <vector>
class PhoneLine;
#include "Account.hpp"
#include "Session.hpp"
/**
* This is the class that ma
* This is the class that manages phone lines
*/
class PhoneLineManager : public QObject
{
Q_OBJECT
public:
PhoneLineManager(unsigned int nbLines);
/**
* This function will make a call on the
* current line. If there's no selected
......@@ -19,11 +28,6 @@ public:
*/
void call(const QString &to);
/**
* This function will switch the lines. If the line
* is invalid, it just do nothing.
*/
void selectLine(unsigned int line);
/**
* This function hangup the selected line.
......@@ -41,14 +45,20 @@ public:
* This function hangup the
*/
slots:
public slots:
void clicked();
/**
* 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);
PhoneLine *getPhoneLine(unsigned int line);
private:
Session mSession;
......@@ -62,3 +72,4 @@ private:
};
#endif
......@@ -20,7 +20,7 @@
#include <sstream>
#include "global.h"
#include "globals.h"
#include "Request.hpp"
#include "Requester.hpp"
......
......@@ -35,6 +35,8 @@ class Request
const std::string &command,
const std::list< std::string > &args);
virtual ~Request(){}
/**
* This function will be called when the request
* receive its answer, if the request didn't successfully
......
......@@ -21,7 +21,7 @@
#include <stdexcept>
#include <sstream>
#include "global.h"
#include "globals.h"
#include "RequesterImpl.hpp"
#include "SessionIO.hpp"
#include "AnswerReceiver.hpp"
......
#include "globals.h"
#include "SFLPhoneApp.hpp"
#include "SFLPhoneWindow.hpp"
#include "PhoneLineButton.hpp"
SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
: QApplication(argc, argv)
, mPhoneLineManager(NB_PHONELINES)
, mSession()
, mAccount(mSession.getDefaultAccount())
{}
void
SFLPhoneApp::initConnections(SFLPhoneWindow *w)
{
unsigned int i = 0;
for(std::list< PhoneLineButton * >::iterator pos = w->mPhoneLineButtons.begin();
pos != w->mPhoneLineButtons.end();
pos++) {
QObject::connect(*pos, SIGNAL(clicked(unsigned int)),
&mPhoneLineManager, SLOT(selectLine(unsigned int)));
i++;
}
}
#ifndef __SFLPHONEAPP_HPP__
#define __SFLPHONEAPP_HPP__
#include <QApplication>
#include "PhoneLineManager.hpp"
#include "Session.hpp"
#include "Account.hpp"
class SFLPhoneWindow;
class SFLPhoneApp : public QApplication
{
public:
SFLPhoneApp(int argc, char **argv);
/**
* This function will make the widgets
* connections.
*/
void initConnections(SFLPhoneWindow *w);
private:
PhoneLineManager mPhoneLineManager;
Session mSession;
Account mAccount;
};
#endif
......@@ -4,15 +4,11 @@
#include <QPixmap>
#include <iostream>
#include "JPushButton.hpp"
#define NBLINES 6
#include "globals.h"
#include "PhoneLineButton.hpp"
SFLPhoneWindow::SFLPhoneWindow()
: QMainWindow(NULL, 0)
, mSession()
, mAccount(mSession.getAccount("monaccount")
{
// Initialize the background image
QLabel *l = new QLabel(this);
......@@ -21,7 +17,7 @@ SFLPhoneWindow::SFLPhoneWindow()
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());
......@@ -43,20 +39,18 @@ SFLPhoneWindow::initLineButtons()
int xpos = 21;
int ypos = 151;
int offset = 31;
for(int i = 0; i < NBLINES; i++) {
std::cout << i << std::endl;
JPushButton *line = new JPushButton(QPixmap(QString(":/images/line") +
QString::number(i + 1) +
"off-img.png"),
QPixmap(QString(":/images/line") +
QString::number(i + 1) +
"on-img.png"),
this);
connect(line, clicked()
&mPhoneLineManager, clicked());
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"),
i,
this);
line->move(xpos, ypos);
xpos += offset;
mLineButtons.push_back(line);
mPhoneLineButtons.push_back(line);
}
}
......@@ -2,10 +2,12 @@
#include <QMainWindow>
#include <list>
class JPushButton;
class PhoneLineButton;
class SFLPhoneWindow : public QMainWindow
{
friend class SFLPhoneApp;
public:
SFLPhoneWindow();
~SFLPhoneWindow();
......@@ -14,7 +16,5 @@ private:
void initLineButtons();
private:
std::list< PhoneLineButton * > mLineButtons;
PhoneLineManager mPhoneLineManager;
std::list< PhoneLineButton * > mPhoneLineButtons;
};
......@@ -19,6 +19,7 @@
*/
#include <iostream>
#include <string>
#include "Session.hpp"
#include "Requester.hpp"
......@@ -37,13 +38,19 @@ Session::Session()
}
std::string
Session::id()
Session::id() const
{
return mId;
}
Account
Session::getAccount(const std::string &name)
Session::getAccount(const std::string &name) const
{
return Account(mId, name);
}
Account
Session::getDefaultAccount() const
{
return Account(mId, std::string("mydefaultaccount"));
}
......@@ -34,9 +34,11 @@ class Session
/**
* retreive the account identified by name.
*/
Account getAccount(const std::string &name);
Account getAccount(const std::string &name) const;
Account getDefaultAccount() const;
std::string id();
std::string id() const;
private:
std::string mId;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment