[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [sflphone-kde/contact_refactor] src: [ #45246 ] Split the video model into multiple smaller models
From: Emmanuel Lepage Vallee <emmanuel.lepage () savoirfairelinux ! com>
Date: 2014-04-16 20:55:09
Message-ID: E1WaWrN-00060y-BO () scm ! kde ! org
[Download RAW message or body]
Git commit 034bec33376bad5c49449a3d18382be24d1cbfed by Emmanuel Lepage Vallee.
Committed on 16/04/2014 at 20:54.
Pushed by lepagevalleeemmanuel into branch 'contact_refactor'.
[ #45246 ] Split the video model into multiple smaller models
M +28 -42 src/conf/dlgvideo.cpp
M +2 -0 src/lib/CMakeLists.txt
M +1 -0 src/lib/videodevice.h
A +491 -0 src/lib/videodevicemodel.cpp [License: LGPL (v2.1+)]
A +191 -0 src/lib/videodevicemodel.h [License: LGPL (v2.1+)]
M +28 -19 src/lib/videomodel.cpp
M +2 -2 src/lib/videomodel.h
M +29 -1 src/widgets/videodock.cpp
http://commits.kde.org/sflphone-kde/034bec33376bad5c49449a3d18382be24d1cbfed
diff --git a/src/conf/dlgvideo.cpp b/src/conf/dlgvideo.cpp
index 32ca20c..2bf6bf4 100644
--- a/src/conf/dlgvideo.cpp
+++ b/src/conf/dlgvideo.cpp
@@ -26,6 +26,7 @@
#include "../lib/videodevice.h"
#include "../lib/videocodecmodel.h"
#include "../lib/videomodel.h"
+#include "../lib/videodevicemodel.h"
///Constructor
DlgVideo::DlgVideo(KConfigDialog* parent)
@@ -37,10 +38,27 @@ DlgVideo::DlgVideo(KConfigDialog* parent)
const QList<VideoDevice*> devices = VideoModel::instance()->devices();
- connect(m_pDeviceCB ,SIGNAL(currentIndexChanged(QString)), this , \
SLOT(loadDevice(QString)) );
- connect(m_pChannelCB ,SIGNAL(currentIndexChanged(QString)), this , \
SLOT(loadResolution(QString)));
- connect(m_pResolutionCB,SIGNAL(currentIndexChanged(QString)), this , \
SLOT(loadRate(QString)) );
- connect(m_pRateCB ,SIGNAL(currentIndexChanged(QString)), this , \
SLOT(changeRate(QString)) ); + m_pDeviceCB -> \
setModel(VideoDeviceModel::instance()); + m_pChannelCB -> \
setModel(VideoDeviceModel::instance()->channelModel()); + m_pResolutionCB -> \
setModel(VideoDeviceModel::instance()->resolutionModel()); + m_pRateCB -> \
setModel(VideoDeviceModel::instance()->rateModel()); +
+ connect(m_pDeviceCB ,SIGNAL(currentIndexChanged(int)), \
VideoDeviceModel::instance() , SLOT(setActive(int))); + \
connect(m_pChannelCB ,SIGNAL(currentIndexChanged(int)), \
VideoDeviceModel::instance()->channelModel() , SLOT(setActive(int))); + \
connect(m_pResolutionCB,SIGNAL(currentIndexChanged(int)), \
VideoDeviceModel::instance()->resolutionModel(), SLOT(setActive(int))); + \
connect(m_pRateCB ,SIGNAL(currentIndexChanged(int)), \
VideoDeviceModel::instance()->rateModel() , SLOT(setActive(int))); +
+// connect(VideoDeviceModel::instance() \
,SIGNAL(currentIndexChanged(int)), m_pDeviceCB , SLOT(setCurrentIndex(int))); + \
connect(VideoDeviceModel::instance()->channelModel() \
,SIGNAL(currentIndexChanged(int)), m_pChannelCB , SLOT(setCurrentIndex(int))); + \
connect(VideoDeviceModel::instance()->resolutionModel(),SIGNAL(currentIndexChanged(int)), \
m_pResolutionCB, SLOT(setCurrentIndex(int))); + \
connect(VideoDeviceModel::instance()->rateModel() \
,SIGNAL(currentIndexChanged(int)), m_pRateCB , SLOT(setCurrentIndex(int))); +
+ qDebug() << "SETTING" << VideoDeviceModel::instance()-> currentIndex() << \
m_pDeviceCB->count(); + m_pDeviceCB -> setCurrentIndex( \
VideoDeviceModel::instance() -> currentIndex() ); + m_pChannelCB \
-> setCurrentIndex( VideoDeviceModel::instance()->channelModel() -> currentIndex() \
); + m_pResolutionCB-> setCurrentIndex( \
VideoDeviceModel::instance()->resolutionModel()-> currentIndex() ); + m_pRateCB \
-> setCurrentIndex( VideoDeviceModel::instance()->rateModel() -> currentIndex() \
); +
connect(m_pPreviewPB ,SIGNAL(clicked()) , this , \
SLOT(startStopPreview()) ); connect( this ,SIGNAL(updateButtons()) \
, parent , SLOT(updateButtons()) ); \
connect(VideoModel::instance(),SIGNAL(previewStateChanged(bool)),this,SLOT(startStopPreview(bool)) \
); @@ -51,7 +69,7 @@ DlgVideo::DlgVideo(KConfigDialog* parent)
m_pConfGB->setEnabled(devices.size());
- if (devices.size() && devices[0])
+ if ((devices.size() && devices[0]) || (devices[0] && (!m_pDeviceCB->count())))
loadDevice(devices[0]->id());
if (VideoModel::instance()->isPreviewing()) {
@@ -76,56 +94,31 @@ bool DlgVideo::hasChanged()
///Load the device list
void DlgVideo::loadDevice(const QString& device)
{
+ Q_UNUSED(device)
if (!m_IsLoading) {
m_IsChanged = true;
emit updateButtons();
}
- m_pDevice = VideoModel::instance()->device(device);
- if (m_pDevice) {
- const QString curChan = m_pDevice->channel();
- m_pChannelCB->clear();
- foreach(const VideoChannel& channel,m_pDevice->channelList()) {
- m_pChannelCB->addItem(channel);
- if (channel == curChan)
- m_pChannelCB->setCurrentIndex(m_pChannelCB->count()-1);
- }
- VideoModel::instance()->setActiveDevice(m_pDevice);
- }
}
///Load resolution
void DlgVideo::loadResolution(const QString& channel)
{
+ Q_UNUSED(channel)
if (!m_IsLoading) {
m_IsChanged = true;
emit updateButtons();
}
- Resolution current = m_pDevice->resolution();
- m_pResolutionCB->clear();
- foreach(const Resolution& res,m_pDevice->resolutionList(channel)) {
- m_pResolutionCB->addItem(res.toString());
- if (current == res) {
- m_pResolutionCB->setCurrentIndex(m_pResolutionCB->count()-1);
- }
- }
- m_pDevice->setChannel(channel);
}
///Load the rate
void DlgVideo::loadRate(const QString& resolution)
{
+ Q_UNUSED(resolution)
if (!m_IsLoading) {
m_IsChanged = true;
emit updateButtons();
}
- m_pRateCB->clear();
- const QString rate = m_pDevice->rate();
- foreach(const QString& \
r,m_pDevice->rateList(m_pChannelCB->currentText(),resolution)) {
- m_pRateCB->addItem(r);
- if (r == rate)
- m_pRateCB->setCurrentIndex(m_pRateCB->count()-1);
- }
- m_pDevice->setResolution(resolution);
}
///Changes the rate
@@ -162,19 +155,12 @@ void DlgVideo::startStopPreview(bool state)
void DlgVideo::updateWidgets ()
{
- const QList<VideoDevice*> devices = VideoModel::instance()->devices();
- m_pDeviceCB->clear();
- foreach(VideoDevice* dev,devices) {
- if (dev) {
- m_pDeviceCB->addItem(dev->id());
- }
- }
- m_pDeviceCB->setCurrentIndex(devices.indexOf(VideoModel::instance()->activeDevice()));
+ //The models should take care of that
}
void DlgVideo::updateSettings()
{
const QList<VideoDevice*> devices = VideoModel::instance()->devices();
- VideoModel::instance()->setActiveDevice(devices[m_pDeviceCB->currentIndex()]);
+ VideoDeviceModel::instance()->setActive(devices[m_pDeviceCB->currentIndex()]);
m_IsChanged = false;
}
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index afe737b..c37b0cc 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -76,6 +76,7 @@ set( qtsflphone_LIB_SRCS
lastusednumbermodel.cpp
contactmodel.cpp
itembackendmodel.cpp
+ videodevicemodel.cpp
#Data backends
transitionalcontactbackend.cpp
@@ -138,6 +139,7 @@ set( qtsflphone_LIB_HDRS
abstractitembackend.h
itembackendmodel.h
videodevice.h
+ videodevicemodel.h
#commonbackendmanagerinterface.h
)
diff --git a/src/lib/videodevice.h b/src/lib/videodevice.h
index d2ff191..d898922 100644
--- a/src/lib/videodevice.h
+++ b/src/lib/videodevice.h
@@ -53,6 +53,7 @@ class VideoModel;
class LIB_EXPORT VideoDevice : public QObject {
Q_OBJECT
friend class VideoModel;
+ friend class VideoDeviceModel;
public:
//Getter
const QStringList rateList(VideoChannel channel, Resolution \
resolution);
diff --git a/src/lib/videodevicemodel.cpp b/src/lib/videodevicemodel.cpp
new file mode 100644
index 0000000..bb0bd31
--- /dev/null
+++ b/src/lib/videodevicemodel.cpp
@@ -0,0 +1,491 @@
+/****************************************************************************
+ * Copyright (C) 2012-2014 by Savoir-Faire Linux *
+ * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
+ * *
+ * This library is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * This library 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 *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+#include "videodevicemodel.h"
+#include "videodevice.h"
+#include "call.h"
+#include "account.h"
+#include "videocodec.h"
+#include "dbus/videomanager.h"
+
+#include <QtCore/QCoreApplication>
+
+VideoDeviceModel* VideoDeviceModel::m_spInstance = nullptr;
+
+VideoDeviceModel* VideoDeviceModel::instance()
+{
+ if (!m_spInstance)
+ m_spInstance = new VideoDeviceModel();
+ return m_spInstance;
+}
+
+///Get data from the model
+QVariant VideoDeviceModel::data( const QModelIndex& idx, int role) const
+{
+ if(idx.column() == 0 && role == Qt::DisplayRole)
+ return QVariant(m_lDevices[idx.row()]->id());
+ return QVariant();
+}
+
+///The number of codec
+int VideoDeviceModel::rowCount( const QModelIndex& par ) const
+{
+ Q_UNUSED(par)
+ return m_lDevices.size();
+}
+
+///Items flag
+Qt::ItemFlags VideoDeviceModel::flags( const QModelIndex& idx ) const
+{
+ if (idx.column() == 0)
+ return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | \
Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return QAbstractItemModel::flags(idx);
+}
+
+///Set the codec data (codecs can't be added or removed that way)
+bool VideoDeviceModel::setData(const QModelIndex& idx, const QVariant &value, int \
role) +{
+ Q_UNUSED(idx)
+ Q_UNUSED(value)
+ Q_UNUSED(role)
+ return false;
+}
+
+///Constructor
+VideoDeviceModel::VideoDeviceModel() : \
QAbstractListModel(QCoreApplication::instance()), \
+m_pResolutionModel(nullptr),m_pChannelModel(nullptr),m_pRateModel(nullptr) +{
+ connect(this ,SIGNAL(changed()) , channelModel () , \
SLOT(reload())); + connect(channelModel() ,SIGNAL(changed()) , resolutionModel() \
, SLOT(reload())); + connect(resolutionModel(),SIGNAL(changed()) , rateModel \
() , SLOT(reload())); + m_spInstance = this;
+ reload();
+ channelModel ()->reload();
+ rateModel ()->reload();
+ resolutionModel()->reload();
+}
+
+///Destructor
+VideoDeviceModel::~VideoDeviceModel()
+{
+ while (m_lDevices.size()) {
+ VideoDevice* c = m_lDevices[0];
+ m_lDevices.removeAt(0);
+ delete c;
+ }
+}
+
+///Save the current model over dbus
+void VideoDeviceModel::setActive(const QModelIndex& idx)
+{
+ if (idx.isValid()) {
+ qDebug() << "DEV CHANGE" << m_lDevices[idx.row()]->id();
+ VideoInterface& interface = DBus::VideoManager::instance();
+ interface.setActiveDevice(m_lDevices[idx.row()]->id());
+ emit changed();
+ emit currentIndexChanged(idx.row());
+ }
+}
+
+///Convenience
+void VideoDeviceModel::setActive(const int idx)
+{
+ setActive(index(idx,0,QModelIndex()));
+}
+
+
+void VideoDeviceModel::setActive(const VideoDevice* device)
+{
+ VideoInterface& interface = DBus::VideoManager::instance();
+ interface.setActiveDevice(device->id());
+ emit changed();
+ const int idx = m_lDevices.indexOf((VideoDevice*)device);
+ emit currentIndexChanged(idx);
+}
+
+void VideoDeviceModel::reload()
+{
+ QHash<QString,VideoDevice*> devicesHash;
+ VideoInterface& interface = DBus::VideoManager::instance();
+ const QStringList deviceList = interface.getDeviceList();
+ if (deviceList.size() == m_hDevices.size()) {
+ m_lDevices = m_hDevices.values();
+ }
+
+ foreach(const QString& deviceName,deviceList) {
+ if (!m_hDevices[deviceName]) {
+ devicesHash[deviceName] = new VideoDevice(deviceName);
+ }
+ else {
+ devicesHash[deviceName] = m_hDevices[deviceName];
+ }
+ }
+ foreach(VideoDevice* dev,m_hDevices) {
+ if (dev && devicesHash.key(dev).isEmpty()) {
+ delete dev;
+ }
+ }
+ m_hDevices.clear();
+ m_hDevices = devicesHash;
+ m_lDevices = m_hDevices.values();
+
+ qDebug() << "\n\n\nLAYOUT" << m_lDevices.size();
+ emit layoutChanged();
+ channelModel ()->reload();
+ setActive(activeDevice());
+}
+
+
+VideoDevice* VideoDeviceModel::activeDevice() const
+{
+ VideoInterface& interface = DBus::VideoManager::instance();
+ const QString deId = interface.getActiveDevice();
+ if (!m_lDevices.size())
+ const_cast<VideoDeviceModel*>(this)->reload();
+ return m_hDevices[deId];
+}
+
+
+int VideoDeviceModel::currentIndex() const
+{
+ qDebug() << "\n\n\n\nCURRENT" << activeDevice() \
<<m_lDevices.indexOf(activeDevice()) <<rowCount(); + return \
m_lDevices.indexOf(activeDevice()); +}
+
+
+
+
+
+//Resolution
+
+VideoDeviceResolutionModel* VideoDeviceModel::resolutionModel() const
+{
+ if (!m_pResolutionModel)
+ const_cast<VideoDeviceModel*>(this)->m_pResolutionModel = new \
VideoDeviceResolutionModel(); + return m_pResolutionModel;
+}
+
+///Get data from the model
+QVariant VideoDeviceResolutionModel::data( const QModelIndex& idx, int role) const
+{
+ if(idx.column() == 0 && role == Qt::DisplayRole)
+ return QVariant(m_lResolutions[idx.row()]->toString());
+ return QVariant();
+}
+
+///The number of codec
+int VideoDeviceResolutionModel::rowCount( const QModelIndex& par ) const
+{
+ Q_UNUSED(par)
+ return m_lResolutions.size();
+}
+
+///Items flag
+Qt::ItemFlags VideoDeviceResolutionModel::flags( const QModelIndex& idx ) const
+{
+ if (idx.column() == 0)
+ return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | \
Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return QAbstractItemModel::flags(idx);
+}
+
+///Set the codec data (codecs can't be added or removed that way)
+bool VideoDeviceResolutionModel::setData(const QModelIndex& idx, const QVariant \
&value, int role) +{
+ Q_UNUSED(idx)
+ Q_UNUSED(value)
+ Q_UNUSED(role)
+ return false;
+}
+
+///Constructor
+VideoDeviceResolutionModel::VideoDeviceResolutionModel() : \
QAbstractListModel(QCoreApplication::instance()) +{
+}
+
+///Destructor
+VideoDeviceResolutionModel::~VideoDeviceResolutionModel()
+{
+
+}
+
+
+Resolution VideoDeviceResolutionModel::activeResolution() const
+{
+ VideoInterface& interface = DBus::VideoManager::instance();
+ const QString res = interface.getActiveDeviceSize();
+ if (!m_hResolutions[res])
+ const_cast<VideoDeviceResolutionModel*>(this)->reload();
+ if (m_hResolutions[res])
+ return *m_hResolutions[res];
+ return Resolution("0x0");
+}
+
+///Save the current model over dbus
+void VideoDeviceResolutionModel::setActive(const QModelIndex& idx)
+{
+ if (idx.isValid()) {
+ qDebug() << "RES CHANGE" << m_lResolutions[idx.row()]->toString();
+ VideoInterface& interface = DBus::VideoManager::instance();
+ interface.setActiveDeviceSize(m_lResolutions[idx.row()]->toString());
+ emit changed();
+ qDebug() << "CURRENT" << idx.row();
+ emit currentIndexChanged(idx.row());
+ }
+ else
+ qDebug() << "INVALID INDEX2" << idx.row();
+}
+
+///Convenience
+void VideoDeviceResolutionModel::setActive(const int idx)
+{
+ setActive(index(idx,0,QModelIndex()));
+}
+
+void VideoDeviceResolutionModel::reload()
+{
+ QHash<QString,Resolution*> devicesHash;
+ VideoInterface& interface = DBus::VideoManager::instance();
+ const QStringList deviceList = \
interface.getDeviceSizeList(VideoDeviceModel::instance()->activeDevice()->id(), + \
VideoDeviceModel::instance()->rateModel()->activeRate()); + if (deviceList.size() \
== m_hResolutions.size()) { + m_lResolutions = m_hResolutions.values();
+ }
+
+ foreach(const QString& deviceName,deviceList) {
+ if (!m_hResolutions.contains(deviceName)) {
+ devicesHash[deviceName] = new Resolution(deviceName);
+ }
+ else {
+ devicesHash[deviceName] = m_hResolutions[deviceName];
+ }
+ }
+ m_hResolutions.clear();
+ m_hResolutions = devicesHash;
+ m_lResolutions = m_hResolutions.values();
+ qDebug() << "\n\n\nRELOADING RES" << m_hResolutions.size();
+ emit layoutChanged();
+
+ VideoDeviceModel::instance()->rateModel()->reload();
+ setActive(m_lResolutions.indexOf(m_hResolutions[activeResolution().toString()]));
+}
+
+
+int VideoDeviceResolutionModel::currentIndex() const
+{
+ const Resolution& res = activeResolution();
+ return m_lResolutions.indexOf((Resolution*)&res);
+}
+
+
+
+
+
+//Camera
+
+
+VideoDeviceChannelModel* VideoDeviceModel::channelModel() const
+{
+ if (!m_pChannelModel)
+ const_cast<VideoDeviceModel*>(this)->m_pChannelModel = new \
VideoDeviceChannelModel(); + return m_pChannelModel;
+}
+
+
+QString VideoDeviceChannelModel::activeChannel() const
+{
+ VideoInterface& interface = DBus::VideoManager::instance();
+ return interface.getActiveDeviceChannel();
+}
+
+///Get data from the model
+QVariant VideoDeviceChannelModel::data( const QModelIndex& idx, int role) const
+{
+ if(idx.column() == 0 && role == Qt::DisplayRole)
+ return QVariant(m_lChannels[idx.row()]);
+ return QVariant();
+}
+
+///The number of codec
+int VideoDeviceChannelModel::rowCount( const QModelIndex& par ) const
+{
+ Q_UNUSED(par)
+ return m_lChannels.size();
+}
+
+///Items flag
+Qt::ItemFlags VideoDeviceChannelModel::flags( const QModelIndex& idx ) const
+{
+ if (idx.column() == 0)
+ return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | \
Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return QAbstractItemModel::flags(idx);
+}
+
+///Set the codec data (codecs can't be added or removed that way)
+bool VideoDeviceChannelModel::setData(const QModelIndex& idx, const QVariant &value, \
int role) +{
+ Q_UNUSED(idx)
+ Q_UNUSED(value)
+ Q_UNUSED(role)
+ return false;
+}
+
+///Constructor
+VideoDeviceChannelModel::VideoDeviceChannelModel() : \
QAbstractListModel(QCoreApplication::instance()) +{
+}
+
+///Destructor
+VideoDeviceChannelModel::~VideoDeviceChannelModel()
+{
+}
+
+///Save the current model over dbus
+void VideoDeviceChannelModel::setActive(const QModelIndex& idx)
+{
+ if (idx.isValid()) {
+ qDebug() << "CHAN CHANGE" << m_lChannels[idx.row()];
+ VideoInterface& interface = DBus::VideoManager::instance();
+ interface.setActiveDeviceChannel(m_lChannels[idx.row()]);
+ emit changed();
+ emit currentIndexChanged(idx.row());
+ }
+}
+
+///Convenience
+void VideoDeviceChannelModel::setActive(const int idx)
+{
+ setActive(index(idx,0,QModelIndex()));
+}
+
+void VideoDeviceChannelModel::reload()
+{
+ QHash<QString,QString> devicesHash;
+ VideoInterface& interface = DBus::VideoManager::instance();
+ const QStringList deviceList = \
interface.getDeviceChannelList(VideoDeviceModel::instance()->activeDevice()->id()); +
+ m_lChannels = deviceList;
+ emit layoutChanged();
+
+ VideoDeviceModel::instance()->resolutionModel()->reload();
+
+ setActive(m_lChannels.indexOf(activeChannel()));
+}
+
+int VideoDeviceChannelModel::currentIndex() const
+{
+ return m_lChannels.indexOf(activeChannel());
+}
+
+
+
+
+//Rate
+
+
+VideoDeviceRateModel* VideoDeviceModel::rateModel() const
+{
+ if (!m_pRateModel)
+ const_cast<VideoDeviceModel*>(this)->m_pRateModel = new \
VideoDeviceRateModel(); + return m_pRateModel;
+}
+
+QString VideoDeviceRateModel::activeRate() const
+{
+ VideoInterface& interface = DBus::VideoManager::instance();
+ return interface.getActiveDeviceRate();
+}
+
+///Get data from the model
+QVariant VideoDeviceRateModel::data( const QModelIndex& idx, int role) const
+{
+ if(idx.isValid() && idx.column() == 0 && role == Qt::DisplayRole && idx.row() < \
m_lRates.size()) + return QVariant(m_lRates[idx.row()]);
+ return QVariant();
+}
+
+///The number of codec
+int VideoDeviceRateModel::rowCount( const QModelIndex& par ) const
+{
+ Q_UNUSED(par)
+ return m_lRates.size();
+}
+
+///Items flag
+Qt::ItemFlags VideoDeviceRateModel::flags( const QModelIndex& idx ) const
+{
+ if (idx.column() == 0)
+ return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | \
Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return QAbstractItemModel::flags(idx);
+}
+
+///Set the codec data (codecs can't be added or removed that way)
+bool VideoDeviceRateModel::setData(const QModelIndex& idx, const QVariant &value, \
int role) +{
+ Q_UNUSED(idx)
+ Q_UNUSED(value)
+ Q_UNUSED(role)
+ return false;
+}
+
+///Constructor
+VideoDeviceRateModel::VideoDeviceRateModel() : \
QAbstractListModel(QCoreApplication::instance()) +{
+}
+
+///Destructor
+VideoDeviceRateModel::~VideoDeviceRateModel()
+{
+}
+
+///Save the current model over dbus
+void VideoDeviceRateModel::setActive(const QModelIndex& idx)
+{
+ if (idx.isValid()) {
+ qDebug() << "RATE CHANGE" << m_lRates[idx.row()];
+ VideoInterface& interface = DBus::VideoManager::instance();
+ interface.setActiveDeviceRate(m_lRates[idx.row()]);
+ emit changed();
+ emit currentIndexChanged(idx.row());
+ }
+ else
+ qDebug() << "\n\n\n\nINVALID INDEX" << idx.row() << rowCount();
+}
+
+///Convenience
+void VideoDeviceRateModel::setActive(const int idx)
+{
+ setActive(index(idx,0,QModelIndex()));
+}
+
+void VideoDeviceRateModel::reload()
+{
+ QHash<QString,VideoDevice*> devicesHash;
+ VideoInterface& interface = DBus::VideoManager::instance();
+ const QStringList deviceList = \
interface.getDeviceRateList(VideoDeviceModel::instance()->activeDevice()->id \
(), + \
VideoDeviceModel::instance()->channelModel()->activeChannel (), + \
VideoDeviceModel::instance()->resolutionModel()->activeResolution().toString() + \
); + m_lRates = deviceList;
+ emit layoutChanged();
+ qDebug() << "COMPUTE" << activeRate() << m_lRates << deviceList.size() << \
m_lRates.indexOf(activeRate()); + setActive(m_lRates.indexOf(activeRate()));
+}
+
+int VideoDeviceRateModel::currentIndex() const
+{
+ return m_lRates.indexOf(activeRate());
+}
diff --git a/src/lib/videodevicemodel.h b/src/lib/videodevicemodel.h
new file mode 100644
index 0000000..b422570
--- /dev/null
+++ b/src/lib/videodevicemodel.h
@@ -0,0 +1,191 @@
+/****************************************************************************
+ * Copyright (C) 2014 by Savoir-Faire Linux *
+ * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
+ * *
+ * This library is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2.1 of the License, or (at your option) any later version. *
+ * *
+ * This library 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 *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+#ifndef VIDEODEVICEMODEL_H
+#define VIDEODEVICEMODEL_H
+
+#include "typedefs.h"
+#include <QtCore/QAbstractListModel>
+#include "videodevice.h"
+
+//Qt
+
+//SFLPhone
+class VideoDevice;
+
+///Abstract model for managing account video codec list
+class LIB_EXPORT VideoDeviceResolutionModel : public QAbstractListModel {
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
+ Q_OBJECT
+ #pragma GCC diagnostic pop
+
+public:
+ //Private constructor, can only be called by 'Account'
+ explicit VideoDeviceResolutionModel();
+ ~VideoDeviceResolutionModel();
+
+ //Model functions
+ QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole \
) const; + int rowCount ( const QModelIndex& parent = QModelIndex() \
) const; + Qt::ItemFlags flags ( const QModelIndex& index \
) const; + virtual bool setData ( const QModelIndex& index, const QVariant \
&value, int role) ; +
+ Resolution activeResolution() const;
+ int currentIndex() const;
+
+private:
+ //Attrbutes
+ QHash<QString,Resolution*> m_hResolutions ;
+ QList<Resolution*> m_lResolutions;
+ static VideoDeviceResolutionModel* m_spInstance;
+
+public Q_SLOTS:
+ void setActive(const QModelIndex& idx);
+ void setActive(const int idx);
+ void reload();
+
+Q_SIGNALS:
+ void changed();
+ void currentIndexChanged(int);
+};
+Q_DECLARE_METATYPE(VideoDeviceResolutionModel*)
+
+///Abstract model for managing account video codec list
+class LIB_EXPORT VideoDeviceChannelModel : public QAbstractListModel {
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
+ Q_OBJECT
+ #pragma GCC diagnostic pop
+
+public:
+ //Private constructor, can only be called by 'Account'
+ explicit VideoDeviceChannelModel();
+ ~VideoDeviceChannelModel();
+
+ //Model functions
+ QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole \
) const; + int rowCount ( const QModelIndex& parent = QModelIndex() \
) const; + Qt::ItemFlags flags ( const QModelIndex& index \
) const; + virtual bool setData ( const QModelIndex& index, const QVariant \
&value, int role) ; +
+ static VideoDeviceChannelModel* instance();
+
+ QString activeChannel() const;
+ int currentIndex() const;
+
+private:
+ //Attrbutes
+ QList<QString> m_lChannels;
+
+
+public Q_SLOTS:
+ void setActive(const QModelIndex& idx);
+ void setActive(const int idx);
+ void reload();
+
+Q_SIGNALS:
+ void changed();
+ void currentIndexChanged(int);
+};
+Q_DECLARE_METATYPE(VideoDeviceChannelModel*)
+
+///Abstract model for managing account video codec list
+class LIB_EXPORT VideoDeviceRateModel : public QAbstractListModel {
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
+ Q_OBJECT
+ #pragma GCC diagnostic pop
+
+public:
+ //Private constructor, can only be called by 'Account'
+ explicit VideoDeviceRateModel();
+ ~VideoDeviceRateModel();
+
+ //Model functions
+ QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole \
) const; + int rowCount ( const QModelIndex& parent = QModelIndex() \
) const; + Qt::ItemFlags flags ( const QModelIndex& index \
) const; + virtual bool setData ( const QModelIndex& index, const QVariant \
&value, int role) ; +
+ QString activeRate() const;
+ int currentIndex() const;
+
+private:
+ //Attrbutes
+ QList<QString> m_lRates;
+
+public Q_SLOTS:
+ void setActive(const QModelIndex& idx);
+ void setActive(const int idx);
+ void reload();
+
+Q_SIGNALS:
+ void changed();
+ void currentIndexChanged(int);
+};
+Q_DECLARE_METATYPE(VideoDeviceRateModel*)
+
+///Abstract model for managing account video codec list
+class LIB_EXPORT VideoDeviceModel : public QAbstractListModel {
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
+ Q_OBJECT
+ #pragma GCC diagnostic pop
+
+public:
+ //Private constructor, can only be called by 'Account'
+ explicit VideoDeviceModel();
+ ~VideoDeviceModel();
+
+ //Model functions
+ QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole \
) const; + int rowCount ( const QModelIndex& parent = QModelIndex() \
) const; + Qt::ItemFlags flags ( const QModelIndex& index \
) const; + virtual bool setData ( const QModelIndex& index, const QVariant \
&value, int role) ; +
+ static VideoDeviceModel* instance();
+
+ VideoDeviceRateModel* rateModel () const;
+ VideoDeviceChannelModel* channelModel () const;
+ VideoDeviceResolutionModel* resolutionModel () const;
+
+ VideoDevice* activeDevice() const;
+ int currentIndex() const;
+
+private:
+ //Attrbutes
+ QHash<QString,VideoDevice*> m_hDevices ;
+ QList<VideoDevice*> m_lDevices ;
+ static VideoDeviceModel* m_spInstance ;
+ VideoDeviceResolutionModel* m_pResolutionModel;
+ VideoDeviceChannelModel* m_pChannelModel ;
+ VideoDeviceRateModel* m_pRateModel ;
+
+public Q_SLOTS:
+ void setActive(const QModelIndex& idx);
+ void setActive(const int idx);
+ void setActive(const VideoDevice* device);
+ void reload();
+
+Q_SIGNALS:
+ void changed();
+ void currentIndexChanged(int);
+
+};
+Q_DECLARE_METATYPE(VideoDeviceModel*)
+#endif
diff --git a/src/lib/videomodel.cpp b/src/lib/videomodel.cpp
index 90d64c0..8a8ef32 100644
--- a/src/lib/videomodel.cpp
+++ b/src/lib/videomodel.cpp
@@ -173,14 +173,14 @@ void VideoModel::stoppedDecoding(const QString& id, const \
QString& shmPath) // }
-void VideoModel::setActiveDevice(const VideoDevice* device)
-{
- VideoInterface& interface = DBus::VideoManager::instance();
- if (isPreviewing()) {
- switchDevice(device);
- }
- interface.setActiveDevice(device->id());
-}
+// void VideoModel::setActiveDevice(const VideoDevice* device)
+// {
+// VideoInterface& interface = DBus::VideoManager::instance();
+// if (isPreviewing()) {
+// switchDevice(device);
+// }
+// interface.setActiveDevice(device->id());
+// }
void VideoModel::switchDevice(const VideoDevice* device) const
{
@@ -194,17 +194,26 @@ QList<VideoDevice*> VideoModel::devices()
VideoInterface& interface = DBus::VideoManager::instance();
const QStringList deviceList = interface.getDeviceList();
if (deviceList.size() == m_hDevices.size()) {
+// qDebug() << "\n\nRETUNING CACHE" << m_hDevices.values();
+// foreach(const QString& deviceName,deviceList) {
+// qDebug() << "Meh" << m_hDevices[deviceName];
+// }
return m_hDevices.values();
}
foreach(const QString& deviceName,deviceList) {
- if (!m_hDevices[deviceName])
+ if (!m_hDevices[deviceName]) {
devicesHash[deviceName] = new VideoDevice(deviceName);
- else
+// qDebug() << "\n\nNEW" << devicesHash[deviceName];
+ }
+ else {
+// qDebug() << "\n\nPUSH" << m_hDevices[deviceName];
devicesHash[deviceName] = m_hDevices[deviceName];
+ }
}
foreach(VideoDevice* dev,m_hDevices) {
if (dev && devicesHash.key(dev).isEmpty()) {
+// qDebug() << "\n\nDELETE";
delete dev;
}
}
@@ -213,15 +222,15 @@ QList<VideoDevice*> VideoModel::devices()
return m_hDevices.values();
}
-VideoDevice* VideoModel::activeDevice() const
-{
- VideoInterface& interface = DBus::VideoManager::instance();
- const QString deId = interface.getActiveDevice();
- if (!deId.isEmpty() && !m_hDevices.size()) {
- const_cast<VideoModel*>(this)->devices();
- }
- return m_hDevices[deId];
-}
+// VideoDevice* VideoModel::activeDevice() const
+// {
+// VideoInterface& interface = DBus::VideoManager::instance();
+// const QString deId = interface.getActiveDevice();
+// if (!deId.isEmpty() && !m_hDevices.size()) {
+// const_cast<VideoModel*>(this)->devices();
+// }
+// return m_hDevices[deId];
+// }
VideoDevice* VideoModel::device(const QString &id)
{
diff --git a/src/lib/videomodel.h b/src/lib/videomodel.h
index 6117df9..f89787b 100644
--- a/src/lib/videomodel.h
+++ b/src/lib/videomodel.h
@@ -46,13 +46,13 @@ public:
VideoRenderer* getRenderer(const Call* call) const;
VideoRenderer* previewRenderer();
QList<VideoDevice*> devices();
- VideoDevice* activeDevice() const;
+// VideoDevice* activeDevice() const;
VideoDevice* device(const QString &id);
QMutex* startStopMutex() const;
//Setters
void setBufferSize(uint size);
- void setActiveDevice(const VideoDevice* device);
+// void setActiveDevice(const VideoDevice* device);
void switchDevice(const VideoDevice* device) const;
protected:
diff --git a/src/widgets/videodock.cpp b/src/widgets/videodock.cpp
index 160d4ac..15271e6 100644
--- a/src/widgets/videodock.cpp
+++ b/src/widgets/videodock.cpp
@@ -21,14 +21,17 @@
#include <QtGui/QGridLayout>
#include <QtGui/QWidgetItem>
#include <QtGui/QGraphicsView>
+#include <QtGui/QLabel>
#include <KLocale>
+#include <KComboBox>
#include "videowidget3.h"
#include "videoscene.h"
#include "videotoolbar.h"
#include "actioncollection.h"
#include "extendedaction.h"
+#include "lib/videodevicemodel.h"
class VideoWidgetItem : public QWidgetItem {
public:
@@ -52,9 +55,10 @@ VideoDock::VideoDock(QWidget* parent) : QDockWidget(parent)
QWidget* wdg = new QWidget(this);
m_pVideoWidet = new VideoWidget3(wdg);
+ m_pVideoWidet->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
auto l = new QGridLayout(wdg);
// l->addItem(new VideoWidgetItem(m_pVideoWidet),1,0);
- l->addWidget(m_pVideoWidet,1,0);
+ l->addWidget(m_pVideoWidet,1,0,1,3);
// l->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, \
QSizePolicy::Expanding),0,0); // l->addItem(new QSpacerItem(0, 0, \
QSizePolicy::Expanding, QSizePolicy::Expanding),2,0); setWidget(wdg);
@@ -63,6 +67,30 @@ VideoDock::VideoDock(QWidget* parent) : QDockWidget(parent)
VideoToolbar* tb = new VideoToolbar(this);
l->addWidget(tb,2,0);
+ QToolButton* btn = new QToolButton(this);
+ btn->setIcon(KIcon("arrow-down-double"));
+ btn->setCheckable(true);
+ l->addWidget(btn,2,2);
+
+ QWidget* moreOptions = new QWidget(this);
+ moreOptions->setVisible(false);
+ moreOptions->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
+ l->addWidget(moreOptions,3,0,1,3);
+
+ QGridLayout* moreOpts = new QGridLayout(moreOptions);
+ QLabel* devL = new QLabel(i18n("Device:"));
+ QLabel* resL = new QLabel(i18n("Resolution:"));
+ moreOpts->addWidget(devL,1,0,1,1);
+ moreOpts->addWidget(resL,1,1,1,1);
+
+ KComboBox* device = new KComboBox(this);
+ KComboBox* res = new KComboBox(this);
+ device->setModel(VideoDeviceModel::instance());
+ moreOpts->addWidget(device,1,0,2,1);
+ moreOpts->addWidget(res ,1,1,2,1);
+ connect(btn,SIGNAL(toggled(bool)),moreOptions,SLOT(setVisible(bool)));
+ connect(device,SIGNAL(currentIndexChanged(int)),VideoDeviceModel::instance(),SLOT(setActive(int)));
+
connect(ActionCollection::instance()->videoRotateLeftAction() \
,SIGNAL(triggered(bool)),m_pVideoWidet,SLOT(slotRotateLeft())); \
connect(ActionCollection::instance()->videoRotateRightAction(),SIGNAL(triggered(bool)),m_pVideoWidet,SLOT(slotRotateRight()));
connect(ActionCollection::instance()->videoPreviewAction() \
,SIGNAL(triggered(bool)),m_pVideoWidet,SLOT(slotShowPreview(bool)));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic