diff --git a/src/gui/official/PhoneLineManagerImpl.cpp b/src/gui/official/PhoneLineManagerImpl.cpp index 1ec717439bad622e68df340fca28246288f7f48e..bdc8dd57ce73c61289b39fef8c04a90f8fdee414 100644 --- a/src/gui/official/PhoneLineManagerImpl.cpp +++ b/src/gui/official/PhoneLineManagerImpl.cpp @@ -16,6 +16,8 @@ PhoneLineManagerImpl::PhoneLineManagerImpl() , mAccount(NULL) , mCurrentLine(NULL) , mIsInitialized(false) + , mVolume(-1) + , mMicVolume(-1) { EventFactory::instance().registerDefaultEvent< DefaultEvent >(); // TODO: 000 @@ -24,6 +26,8 @@ PhoneLineManagerImpl::PhoneLineManagerImpl() 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"); @@ -531,3 +535,35 @@ PhoneLineManagerImpl::addCall(Call call, call.notAvailable(); } } + +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); + } +} diff --git a/src/gui/official/PhoneLineManagerImpl.hpp b/src/gui/official/PhoneLineManagerImpl.hpp index 3633ce80c956decfc2c2d5e9bda5b4b1ca97bc21..724c4d8d0a1aa4918a860cebe67bf6275e9b498c 100644 --- a/src/gui/official/PhoneLineManagerImpl.hpp +++ b/src/gui/official/PhoneLineManagerImpl.hpp @@ -55,6 +55,9 @@ signals: void actionSet(QString); void lineStatusSet(QString); + void volumeUpdated(int); + void micVolumeUpdated(int); + public slots: /** * You need to call this function once. It must be @@ -216,6 +219,28 @@ public slots: */ void handleEvents(); + /** + * This function will simply signal the volume change. + */ + void updateVolume(int volume); + + /** + * This function will send a request to sflphoned + * to change the volume to the given percentage. + */ + void setVolume(int volume); + + /** + * This function will simply signal the mic volume change. + */ + void updateMicVolume(int volume); + + /** + * This function will send a request to sflphoned + * to change the mic volume to the given percentage. + */ + void setMicVolume(int volume); + void errorOnCallStatus() {emit gotErrorOnCallStatus();} @@ -248,6 +273,9 @@ private: bool mIsInitialized; QMutex mIsInitializedMutex; + + int mVolume; + int mMicVolume; }; diff --git a/src/gui/official/RequesterImpl.cpp b/src/gui/official/RequesterImpl.cpp index d418243a5a275fd1476ec005773728160718281c..5bffc0282cc47c066a600507264b4e2d90e2c8d6 100644 --- a/src/gui/official/RequesterImpl.cpp +++ b/src/gui/official/RequesterImpl.cpp @@ -50,6 +50,7 @@ RequesterImpl::send(const QString &sessionId, const QString &command, const std::list< QString > &args) { + DebugOutput::instance() << QObject::tr("Requester: Trying to create command \"%1\"\n").arg(command); // We retreive the internal of a session. SessionIO *session = getSessionIO(sessionId); diff --git a/src/gui/official/SFLEvents.cpp b/src/gui/official/SFLEvents.cpp index 3d994c8a8ab6f0d0b65cf4591d6ea95937f75d69..6e191bb174fd1bf4cc5d21ab95b07d3e3058b950 100644 --- a/src/gui/official/SFLEvents.cpp +++ b/src/gui/official/SFLEvents.cpp @@ -64,3 +64,32 @@ IncommingEvent::execute() .arg(toString()); } } + +VolumeEvent::VolumeEvent(const QString &code, + const std::list< QString > &args) + : Event(code, args) +{ + std::list< QString > l = getUnusedArgs(); + if(l.size() >= 1) { + mVolume = l.begin()->toUInt(); + l.pop_front(); + setUnusedArgs(l); + } +} + +void +VolumeEvent::execute() +{ + PhoneLineManager::instance().updateVolume(mVolume); +} + +MicVolumeEvent::MicVolumeEvent(const QString &code, + const std::list< QString > &args) + : VolumeEvent(code, args) +{} + +void +MicVolumeEvent::execute() +{ + PhoneLineManager::instance().updateMicVolume(mVolume); +} diff --git a/src/gui/official/SFLEvents.hpp b/src/gui/official/SFLEvents.hpp index 0440810b6f2d86aec87f7bccf04443df8602d36e..b8ac753c4356f2473c80eecd9d601979643a4fba 100644 --- a/src/gui/official/SFLEvents.hpp +++ b/src/gui/official/SFLEvents.hpp @@ -55,4 +55,26 @@ private: }; +class VolumeEvent : public Event +{ +public: + VolumeEvent(const QString &code, + const std::list< QString > &args); + + virtual void execute(); + +protected: + unsigned int mVolume; +}; + +class MicVolumeEvent : public VolumeEvent +{ +public: + MicVolumeEvent(const QString &code, + const std::list< QString > &args); + + virtual void execute(); + +}; + #endif diff --git a/src/gui/official/SFLPhoneApp.cpp b/src/gui/official/SFLPhoneApp.cpp index bd860ade3a79e8e4f566089ca26a2ac10166caa3..b64cc049de55d5f1f7bd632f4dd3433b0cac1ad2 100644 --- a/src/gui/official/SFLPhoneApp.cpp +++ b/src/gui/official/SFLPhoneApp.cpp @@ -9,6 +9,7 @@ #include "SFLPhoneWindow.hpp" #include "SFLRequest.hpp" #include "TCPSessionIOCreator.hpp" +#include "VolumeControl.hpp" @@ -32,6 +33,8 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv) Requester::instance().registerObject< TemporaryRequest >(QString("hold")); Requester::instance().registerObject< TemporaryRequest >(QString("unhold")); Requester::instance().registerObject< TemporaryRequest >(QString("senddtmf")); + Requester::instance().registerObject< Request >(QString("volume")); + Requester::instance().registerObject< Request >(QString("micvolume")); } void @@ -79,6 +82,16 @@ SFLPhoneApp::initConnections(SFLPhoneWindow *w) w->mLcd, SLOT(setBufferStatus(QString))); + //Volume connections + QObject::connect(w->mVolume, SIGNAL(valueUpdated(int)), + &PhoneLineManager::instance(), SLOT(setVolume(int))); + QObject::connect(w->mMicVolume, SIGNAL(valueUpdated(int)), + &PhoneLineManager::instance(), SLOT(setMicVolume(int))); + QObject::connect(&PhoneLineManager::instance(), SIGNAL(volumeUpdated(int)), + w->mVolume, SLOT(setValue(int))); + QObject::connect(&PhoneLineManager::instance(), SIGNAL(micVolumeUpdated(int)), + w->mMicVolume, SLOT(setValue(int))); + QObject::connect(&PhoneLineManager::instance(), SIGNAL(disconnected()), diff --git a/src/gui/official/SFLPhoneWindow.cpp b/src/gui/official/SFLPhoneWindow.cpp index d55a4093255c64e10f0701cd7fd16a2f2eca6203..a4dac71899f8f34d7f6f18d2b98a039b909e8c5d 100644 --- a/src/gui/official/SFLPhoneWindow.cpp +++ b/src/gui/official/SFLPhoneWindow.cpp @@ -33,12 +33,21 @@ #define MUTE_RELEASED_IMAGE "images/mute_off.png" #define MUTE_PRESSED_IMAGE "images/mute_on.png" #define VOLUME_IMAGE "images/volume.png" +#define CLOSE_RELEASED_IMAGE "images/close_off.png" +#define CLOSE_PRESSED_IMAGE "images/close_on.png" +#define MINIMIZE_RELEASED_IMAGE "images/minimize_off.png" +#define MINIMIZE_PRESSED_IMAGE "images/minimize_on.png" + + SFLPhoneWindow::SFLPhoneWindow() #ifdef QT3_SUPPORT : QMainWindow(NULL, Qt::FramelessWindowHint) #else - : QMainWindow(NULL, NULL, Qt::WDestructiveClose) + : QMainWindow(NULL, NULL, + Qt::WDestructiveClose | + Qt::WStyle_Customize | + Qt::WStyle_NoBorder) #endif { // Initialize the background image @@ -114,11 +123,15 @@ SFLPhoneWindow::initGUIButtons() mMain); mVolume->setOrientation(VolumeControl::Vertical); mVolume->move(365,91); - + QObject::connect(mVolume, SIGNAL(valueUpdated(int)), + this, SIGNAL(volumeUpdated(int))); + mMicVolume = new VolumeControl(QString(VOLUME_IMAGE), mMain); mMicVolume->setOrientation(VolumeControl::Vertical); mMicVolume->move(347,91); + QObject::connect(mVolume, SIGNAL(valueUpdated(int)), + this, SIGNAL(micVolumeUpdated(int))); } @@ -141,14 +154,14 @@ SFLPhoneWindow::initLineButtons() void SFLPhoneWindow::initWindowButtons() { - mCloseButton = new JPushButton(":/sflphone/images/close_off.png", - ":/sflphone/images/close_on.png", + mCloseButton = new JPushButton(CLOSE_RELEASED_IMAGE, + CLOSE_PRESSED_IMAGE, mMain); QObject::connect(mCloseButton, SIGNAL(clicked()), this, SLOT(close())); mCloseButton->move(374,5); - mMinimizeButton = new JPushButton(":/sflphone/images/minimize_off.png", - ":/sflphone/images/minimize_on.png", + mMinimizeButton = new JPushButton(MINIMIZE_RELEASED_IMAGE, + MINIMIZE_PRESSED_IMAGE, mMain); QObject::connect(mMinimizeButton, SIGNAL(clicked()), this, SLOT(lower())); diff --git a/src/gui/official/SFLPhoneWindow.hpp b/src/gui/official/SFLPhoneWindow.hpp index 09f61c1897383be66ad1c4b52f69418afba9ec10..a6a3d00f9c7b454998e73073899216940fd06b39 100644 --- a/src/gui/official/SFLPhoneWindow.hpp +++ b/src/gui/official/SFLPhoneWindow.hpp @@ -29,6 +29,8 @@ signals: void keyPressed(Qt::Key); void reconnectAsked(); void resendStatusAsked(); + void volumeUpdated(int); + void micVolumeUpdated(int); public slots: void mousePressEvent(QMouseEvent *event); diff --git a/src/gui/official/Session.cpp b/src/gui/official/Session.cpp index eb3751bab11e16ba9363e5708572a1bea64f420d..f91c9bc5f7d86371dc9879c3b8b159e3f8fbbf9b 100644 --- a/src/gui/official/Session.cpp +++ b/src/gui/official/Session.cpp @@ -74,6 +74,22 @@ Session::unmute() const return Requester::instance().send(mId, "unmute", std::list< QString >()); } +QString +Session::volume(unsigned int volume) const +{ + std::list< QString > args; + args.push_back(QString("%1").arg(volume)); + return Requester::instance().send(mId, "volume", args); +} + +QString +Session::micVolume(unsigned int volume) const +{ + std::list< QString > args; + args.push_back(QString("%1").arg(volume)); + return Requester::instance().send(mId, "micvolume", args); +} + QString Session::getCallStatus() const { diff --git a/src/gui/official/Session.hpp b/src/gui/official/Session.hpp index 0069457aa1b8861836b359d0d203f310e9e7cca1..6af32f0e938f31582f01764f0691b1d09817ad19 100644 --- a/src/gui/official/Session.hpp +++ b/src/gui/official/Session.hpp @@ -59,6 +59,18 @@ class Session */ QString mute() const; + /** + * This function will set the volume to + * the given percentage + */ + QString volume(unsigned int volume) const; + + /** + * This function will set the mic volume to + * the given percentage + */ + QString micVolume(unsigned int volume) const; + /** * This function will unmute the microphone. */ diff --git a/src/gui/official/TCPSessionIO.cpp b/src/gui/official/TCPSessionIO.cpp index acede4af412926b28980aa572662381030625c0a..b375e9852b1c81b7ffa7bb44ce16313c0871afa4 100644 --- a/src/gui/official/TCPSessionIO.cpp +++ b/src/gui/official/TCPSessionIO.cpp @@ -104,7 +104,7 @@ TCPSessionIO::receive(QString &answer) if(mSocket->isReadable()) { QTextStream stream(mSocket); answer = stream.readLine(); - DebugOutput::instance() << QObject::tr("TCPSessionIO: Received answer from sflphone: %1") + DebugOutput::instance() << QObject::tr("TCPSessionIO: Received answer from sflphone: %1\n") .arg(answer); } } diff --git a/src/gui/official/TransparentWidget.cpp b/src/gui/official/TransparentWidget.cpp index 4c4a6eaa7a81f7eb94edb59568fe3f3c2a07fac8..6807b34dbb1392918256e40e6a78e354d8dd7998 100644 --- a/src/gui/official/TransparentWidget.cpp +++ b/src/gui/official/TransparentWidget.cpp @@ -65,7 +65,7 @@ TransparentWidget::~TransparentWidget() QPixmap TransparentWidget::transparize(const QString &image) { - QPixmap p(image); + QPixmap p(QPixmap::fromMimeSource(image)); /* if (!p.mask()) { if (p.hasAlphaChannel()) { diff --git a/src/gui/official/VolumeControl.cpp b/src/gui/official/VolumeControl.cpp index fc791b76fd15d2e8f5493cf322591b05577228d5..82e58a04b8c35c3fb097c2b4e0d5e10cd3930a11 100644 --- a/src/gui/official/VolumeControl.cpp +++ b/src/gui/official/VolumeControl.cpp @@ -20,8 +20,11 @@ #include <qevent.h> #include <iostream> -#include "VolumeControl.hpp" + #include "TransparentWidget.hpp" +#include "VolumeControl.hpp" + +#define SLIDER_IMAGE "images/slider.png" VolumeControl::VolumeControl (const QString &pixname, QWidget *parent, @@ -44,7 +47,7 @@ VolumeControl::~VolumeControl() void VolumeControl::resize() { - QPixmap q(QString(":/sflphone/images/slider")); + QPixmap q(TransparentWidget::transparize(SLIDER_IMAGE)); setPixmap(q); QWidget::resize(q.size()); mMaxPosition = q.height() - mSlider->height(); @@ -108,15 +111,16 @@ VolumeControl::mouseMoveEvent (QMouseEvent *e) { else { mSlider->move(e->y() - mPos.x(), mSlider->y()); } - } void VolumeControl::updateValue() { int value = (int)((float)offset() / mMaxPosition * (mMax - mMin)); - mValue = value; - emit valueUpdated(mValue); + if(mValue != value) { + mValue = value; + emit valueUpdated(mValue); + } } @@ -125,9 +129,9 @@ VolumeControl::updateSlider(int value) { if(mOrientation == VolumeControl::Vertical) { std::cout << "Move again to : " << - value / (mMax - mMin) * mMaxPosition << + (float)value / (mMax - mMin) * mMaxPosition << std::endl << std::endl; - mSlider->move(mSlider->x(), value / (mMax - mMin) * mMaxPosition); + mSlider->move(mSlider->x(), (float)value / (mMax - mMin) * mMaxPosition); } else { mSlider->move(value / (mMax - mMin) * mMaxPosition, mSlider->y());