18
18
#include "videocodecmodel.h"
20
20
#include "account.h"
21
#include "video_interface_singleton.h"
21
#include "videocodec.h"
22
#include "dbus/videomanager.h"
24
#include <QtCore/QCoreApplication>
23
26
///Get data from the model
24
QVariant VideoCodecModel::data( const QModelIndex& index, int role) const
27
QVariant VideoCodecModel::data( const QModelIndex& idx, int role) const
26
if(index.column() == 0 && role == Qt::DisplayRole)
27
return QVariant(m_lCodecs[index.row()]->getName());
28
else if(index.column() == 0 && role == Qt::CheckStateRole) {
29
return QVariant(m_lCodecs[index.row()]->getEnabled()?Qt::Checked:Qt::Unchecked);
29
if(idx.column() == 0 && role == Qt::DisplayRole)
30
return QVariant(m_lCodecs[idx.row()]->name());
31
else if(idx.column() == 0 && role == Qt::CheckStateRole) {
32
return QVariant(m_lCodecs[idx.row()]->enabled()?Qt::Checked:Qt::Unchecked);
31
else if (index.column() == 0 && role == VideoCodecModel::BITRATE_ROLE)
32
return QVariant(m_lCodecs[index.row()]->getBitrate());
34
else if (idx.column() == 0 && role == VideoCodecModel::BITRATE_ROLE)
35
return QVariant(m_lCodecs[idx.row()]->bitrate());
36
39
///The number of codec
37
int VideoCodecModel::rowCount( const QModelIndex& parent ) const
40
int VideoCodecModel::rowCount( const QModelIndex& par ) const
40
43
return m_lCodecs.size();
44
Qt::ItemFlags VideoCodecModel::flags( const QModelIndex& index ) const
47
Qt::ItemFlags VideoCodecModel::flags( const QModelIndex& idx ) const
46
if (index.column() == 0)
47
return QAbstractItemModel::flags(index) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
48
return QAbstractItemModel::flags(index);
49
if (idx.column() == 0)
50
return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
51
return QAbstractItemModel::flags(idx);
51
54
///Set the codec data (codecs can't be added or removed that way)
52
bool VideoCodecModel::setData(const QModelIndex& index, const QVariant &value, int role)
55
bool VideoCodecModel::setData(const QModelIndex& idx, const QVariant &value, int role)
55
if (index.column() == 0 && role == Qt::CheckStateRole) {
56
bool changed = m_lCodecs[index.row()]->getEnabled() != (value == Qt::Checked);
57
m_lCodecs[index.row()]->setEnabled(value == Qt::Checked);
58
if (idx.column() == 0 && role == Qt::CheckStateRole) {
59
bool changed = m_lCodecs[idx.row()]->enabled() != (value == Qt::Checked);
60
m_lCodecs[idx.row()]->setEnabled(value == Qt::Checked);
59
emit dataChanged(index, index);
62
emit dataChanged(idx, idx);
62
else if (index.column() == 0 && role == VideoCodecModel::BITRATE_ROLE) {
63
bool changed = m_lCodecs[index.row()]->getBitrate() != value.toUInt();
64
m_lCodecs[index.row()]->setBitrate(value.toInt());
65
else if (idx.column() == 0 && role == VideoCodecModel::BITRATE_ROLE) {
66
bool changed = m_lCodecs[idx.row()]->bitrate() != value.toUInt();
67
m_lCodecs[idx.row()]->setBitrate(value.toInt());
66
emit dataChanged(index, index);
69
emit dataChanged(idx, idx);
73
VideoCodecModel::VideoCodecModel(Account* account) : QAbstractListModel(),m_pAccount(account)
76
VideoCodecModel::VideoCodecModel(Account* account) : QAbstractListModel(QCoreApplication::instance()),m_pAccount(account)
79
82
void VideoCodecModel::reload()
82
VideoInterface& interface = VideoInterfaceSingleton::getInstance();
83
const VectorMapStringString codecs = interface.getCodecs(m_pAccount->getAccountId());
85
VideoInterface& interface = DBus::VideoManager::instance();
86
const VectorMapStringString codecs = interface.getCodecs(m_pAccount->id());
84
87
foreach(const MapStringString& h,codecs) {
85
VideoCodec* c = new VideoCodec(h["name"],h["bitrate"].toInt(),h["enabled"]=="true");
88
VideoCodec* c = new VideoCodec(h[VideoCodec::CodecFields::NAME],
89
h[VideoCodec::CodecFields::BITRATE].toInt(),
90
h[VideoCodec::CodecFields::ENABLED]=="true");
91
c->setParamaters(h[VideoCodec::CodecFields::PARAMETERS]);
88
94
emit dataChanged(index(0,0), index(m_lCodecs.size()-1,0));
91
97
///Save the current model over dbus
92
98
void VideoCodecModel::save()
94
VideoInterface& interface = VideoInterfaceSingleton::getInstance();
100
VideoInterface& interface = DBus::VideoManager::instance();
95
101
VectorMapStringString toSave;
96
102
foreach(VideoCodec* vc,m_lCodecs) {
97
MapStringString details;
98
details[ "name" ] = vc->getName ();
99
details[ "bitrate" ] = QString::number(vc->getBitrate());
100
details[ "enabled" ] = vc->getEnabled()?"true":"false";
103
toSave << vc->toMap();
103
interface.setCodecs(m_pAccount->getAccountId(),toSave);
105
interface.setCodecs(m_pAccount->id(),toSave);
106
108
///Increase codec priority
107
109
bool VideoCodecModel::moveUp(QModelIndex idx)
109
111
if(idx.row() > 0 && idx.row() <= rowCount()) {
110
VideoCodec* data = m_lCodecs[idx.row()];
112
VideoCodec* data2 = m_lCodecs[idx.row()];
111
113
m_lCodecs.removeAt(idx.row());
112
m_lCodecs.insert(idx.row() - 1, data);
114
m_lCodecs.insert(idx.row() - 1, data2);
113
115
emit dataChanged(index(idx.row() - 1, 0, QModelIndex()), index(idx.row(), 0, QModelIndex()));
120
122
bool VideoCodecModel::moveDown(QModelIndex idx)
122
124
if(idx.row() >= 0 && idx.row() < rowCount()) {
123
VideoCodec* data = m_lCodecs[idx.row()];
125
VideoCodec* data2 = m_lCodecs[idx.row()];
124
126
m_lCodecs.removeAt(idx.row());
125
m_lCodecs.insert(idx.row() + 1, data);
127
m_lCodecs.insert(idx.row() + 1, data2);
126
128
emit dataChanged(index(idx.row(), 0, QModelIndex()), index(idx.row() + 1, 0, QModelIndex()));
133
QHash<QString,VideoCodec*> VideoCodec::m_slCodecs;
134
bool VideoCodec::m_sInit = false;
136
///Private constructor
137
VideoCodec::VideoCodec(QString codecName, uint bitRate, bool enabled) :
138
m_Name(codecName),m_Bitrate(bitRate),m_Enabled(enabled)
143
///Get the current codec name
144
QString VideoCodec::getName() const
149
///Get the current codec id
150
uint VideoCodec::getBitrate() const
155
///Get the current codec id
156
bool VideoCodec::getEnabled() const
161
///Set the codec bitrate
162
void VideoCodec::setBitrate(const uint bitrate)
167
///Set if the codec is enabled
168
void VideoCodec::setEnabled(const bool enabled)