~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to kde/src/lib/videocodecmodel.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
 
 *   Copyright (C) 2012-2013 by Savoir-Faire Linux                          *
 
2
 *   Copyright (C) 2012-2014 by Savoir-Faire Linux                          *
3
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
4
4
 *                                                                          *
5
5
 *   This library is free software; you can redistribute it and/or          *
18
18
#include "videocodecmodel.h"
19
19
#include "call.h"
20
20
#include "account.h"
21
 
#include "video_interface_singleton.h"
 
21
#include "videocodec.h"
 
22
#include "dbus/videomanager.h"
 
23
 
 
24
#include <QtCore/QCoreApplication>
22
25
 
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
25
28
{
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);
30
33
   }
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());
33
36
   return QVariant();
34
37
}
35
38
 
36
39
///The number of codec
37
 
int VideoCodecModel::rowCount( const QModelIndex& parent ) const
 
40
int VideoCodecModel::rowCount( const QModelIndex& par ) const
38
41
{
39
 
   Q_UNUSED(parent)
 
42
   Q_UNUSED(par)
40
43
   return m_lCodecs.size();
41
44
}
42
45
 
43
46
///Items flag
44
 
Qt::ItemFlags VideoCodecModel::flags( const QModelIndex& index ) const
 
47
Qt::ItemFlags VideoCodecModel::flags( const QModelIndex& idx ) const
45
48
{
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);
49
52
}
50
53
 
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)
53
56
{
54
57
 
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);
58
61
      if (changed)
59
 
         emit dataChanged(index, index);
 
62
         emit dataChanged(idx, idx);
60
63
      return true;
61
64
   }
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());
65
68
      if (changed)
66
 
         emit dataChanged(index, index);
 
69
         emit dataChanged(idx, idx);
67
70
      return true;
68
71
   }
69
72
   return false;
70
73
}
71
74
 
72
75
///Constructor
73
 
VideoCodecModel::VideoCodecModel(Account* account) : QAbstractListModel(),m_pAccount(account)
 
76
VideoCodecModel::VideoCodecModel(Account* account) : QAbstractListModel(QCoreApplication::instance()),m_pAccount(account)
74
77
{
75
78
   reload();
76
79
}
79
82
void VideoCodecModel::reload()
80
83
{
81
84
   m_lCodecs.clear();
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]);
86
92
      m_lCodecs << c;
87
93
   }
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()
93
99
{
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";
101
 
      toSave << details;
 
103
      toSave << vc->toMap();
102
104
   }
103
 
   interface.setCodecs(m_pAccount->getAccountId(),toSave);
 
105
   interface.setCodecs(m_pAccount->id(),toSave);
104
106
}
105
107
 
106
108
///Increase codec priority
107
109
bool VideoCodecModel::moveUp(QModelIndex idx)
108
110
{
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()));
114
116
      return true;
115
117
   }
120
122
bool VideoCodecModel::moveDown(QModelIndex idx)
121
123
{
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()));
127
129
      return true;
128
130
   }
129
131
   return false;
130
132
}
131
 
 
132
 
 
133
 
QHash<QString,VideoCodec*> VideoCodec::m_slCodecs;
134
 
bool VideoCodec::m_sInit = false;
135
 
 
136
 
///Private constructor
137
 
VideoCodec::VideoCodec(QString codecName, uint bitRate, bool enabled) :
138
 
m_Name(codecName),m_Bitrate(bitRate),m_Enabled(enabled)
139
 
{
140
 
 
141
 
}
142
 
 
143
 
///Get the current codec name
144
 
QString VideoCodec::getName() const
145
 
{
146
 
   return m_Name;
147
 
}
148
 
 
149
 
///Get the current codec id
150
 
uint VideoCodec::getBitrate() const
151
 
{
152
 
   return m_Bitrate;
153
 
}
154
 
 
155
 
///Get the current codec id
156
 
bool VideoCodec::getEnabled() const
157
 
{
158
 
   return m_Enabled;
159
 
}
160
 
 
161
 
///Set the codec bitrate
162
 
void VideoCodec::setBitrate(const uint bitrate)
163
 
{
164
 
   m_Bitrate = bitrate;
165
 
}
166
 
 
167
 
///Set if the codec is enabled
168
 
void VideoCodec::setEnabled(const bool enabled)
169
 
{
170
 
   m_Enabled = enabled;
171
 
}