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

« back to all changes in this revision

Viewing changes to kde/src/lib/audiosettingsmodel.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
/****************************************************************************
 
2
 *   Copyright (C) 2013-2014 by Savoir-Faire Linux                          *
 
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
 
4
 *                                                                          *
 
5
 *   This library is free software; you can redistribute it and/or          *
 
6
 *   modify it under the terms of the GNU Lesser General Public             *
 
7
 *   License as published by the Free Software Foundation; either           *
 
8
 *   version 2.1 of the License, or (at your option) any later version.     *
 
9
 *                                                                          *
 
10
 *   This library is distributed in the hope that it will be useful,        *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
 
13
 *   Lesser General Public License for more details.                        *
 
14
 *                                                                          *
 
15
 *   You should have received a copy of the GNU General Public License      *
 
16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 
17
 ***************************************************************************/
 
18
#include "audiosettingsmodel.h"
 
19
#include "dbus/configurationmanager.h"
 
20
#include "dbus/callmanager.h"
 
21
 
 
22
AudioSettingsModel* AudioSettingsModel::m_spInstance = nullptr;
 
23
 
 
24
///Constructor
 
25
AudioSettingsModel::AudioSettingsModel() : QObject(),m_EnableRoomTone(false),
 
26
 m_pAlsaPluginModel  (nullptr), m_pInputDeviceModel   (nullptr),
 
27
 m_pAudioManagerModel(nullptr), m_pRingtoneDeviceModel(nullptr),
 
28
 m_pOutputDeviceModel(nullptr)
 
29
{
 
30
   m_pRingtoneDeviceModel = new RingtoneDeviceModel (this);
 
31
}
 
32
 
 
33
///Destructor
 
34
AudioSettingsModel::~AudioSettingsModel()
 
35
{
 
36
   delete m_pAlsaPluginModel    ;
 
37
   delete m_pInputDeviceModel   ;
 
38
   delete m_pOutputDeviceModel  ;
 
39
   delete m_pAudioManagerModel  ;
 
40
   delete m_pRingtoneDeviceModel;
 
41
}
 
42
 
 
43
///Singleton
 
44
AudioSettingsModel* AudioSettingsModel::instance()
 
45
{
 
46
   if (!m_spInstance)
 
47
      m_spInstance = new AudioSettingsModel();
 
48
   return m_spInstance;
 
49
}
 
50
 
 
51
///Return plugin model (alsa only for the time being)
 
52
AlsaPluginModel* AudioSettingsModel::alsaPluginModel()
 
53
{
 
54
   if (!m_pAlsaPluginModel)
 
55
      m_pAlsaPluginModel = new AlsaPluginModel(this);
 
56
   return m_pAlsaPluginModel;
 
57
}
 
58
 
 
59
///Return the input device model
 
60
InputDeviceModel* AudioSettingsModel::inputDeviceModel()
 
61
{
 
62
   if (!m_pInputDeviceModel)
 
63
      m_pInputDeviceModel = new InputDeviceModel(this);
 
64
   return m_pInputDeviceModel;
 
65
}
 
66
 
 
67
///Return the output device model
 
68
OutputDeviceModel* AudioSettingsModel::outputDeviceModel()
 
69
{
 
70
   if (!m_pOutputDeviceModel)
 
71
      m_pOutputDeviceModel   = new OutputDeviceModel(this);
 
72
   return m_pOutputDeviceModel;
 
73
}
 
74
 
 
75
///Return audio manager
 
76
AudioManagerModel* AudioSettingsModel::audioManagerModel()
 
77
{
 
78
   if (!m_pAudioManagerModel)
 
79
      m_pAudioManagerModel = new AudioManagerModel(this);
 
80
   return m_pAudioManagerModel;
 
81
}
 
82
 
 
83
///Return the ringtone device model
 
84
RingtoneDeviceModel* AudioSettingsModel::ringtoneDeviceModel()
 
85
{
 
86
   if (!m_pRingtoneDeviceModel)
 
87
      m_pRingtoneDeviceModel = new RingtoneDeviceModel (this);
 
88
   return m_pRingtoneDeviceModel;
 
89
}
 
90
 
 
91
///Is the room tone (globally) enabled
 
92
bool AudioSettingsModel::isRoomToneEnabled()
 
93
{
 
94
   return m_EnableRoomTone;
 
95
}
 
96
 
 
97
///Reload everything
 
98
void AudioSettingsModel::reload()
 
99
{
 
100
   m_pAlsaPluginModel->reload();
 
101
   m_pInputDeviceModel->reload();
 
102
   m_pOutputDeviceModel->reload();
 
103
//    m_pAudioManagerModel->reload();
 
104
   m_pRingtoneDeviceModel->reload();
 
105
}
 
106
 
 
107
///Play room tone
 
108
AudioSettingsModel::ToneType AudioSettingsModel::playRoomTone() const
 
109
{
 
110
   CallManagerInterface& callManager = DBus::CallManager::instance();
 
111
   callManager.startTone(true,static_cast<int>(AudioSettingsModel::ToneType::WITHOUT_MESSAGE));
 
112
   //TODO support voicemail
 
113
   return AudioSettingsModel::ToneType::WITHOUT_MESSAGE;
 
114
}
 
115
 
 
116
///Stop room tone if it is playing
 
117
void AudioSettingsModel::stopRoomTone() const
 
118
{
 
119
   CallManagerInterface& callManager = DBus::CallManager::instance();
 
120
   callManager.startTone(false,0);
 
121
}
 
122
 
 
123
///Set if the roomtone is (globally) enabled
 
124
void AudioSettingsModel::setEnableRoomTone(bool enable)
 
125
{
 
126
   m_EnableRoomTone = enable;
 
127
}
 
128
 
 
129
///Enable noise suppress code, may make things worst
 
130
void AudioSettingsModel::setNoiseSuppressState(bool enabled)
 
131
{
 
132
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
133
   configurationManager.setNoiseSuppressState(enabled);
 
134
}
 
135
 
 
136
///Enable noise suppress code, may make things worst
 
137
bool AudioSettingsModel::isNoiseSuppressEnabled() const
 
138
{
 
139
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
140
   return configurationManager.getNoiseSuppressState();
 
141
}
 
142
 
 
143
///Mute playback
 
144
void AudioSettingsModel::mutePlayback(bool m)
 
145
{
 
146
   DBus::ConfigurationManager::instance().mutePlayback(m);
 
147
   emit playbackMuted(m);
 
148
}
 
149
 
 
150
///Mute capture
 
151
void AudioSettingsModel::muteCapture(bool m)
 
152
{
 
153
   DBus::ConfigurationManager::instance().muteCapture(m);
 
154
   emit captureMuted(m);
 
155
}
 
156
 
 
157
///is mute playback
 
158
bool AudioSettingsModel::isPlaybackMuted() const
 
159
{
 
160
   return DBus::ConfigurationManager::instance().isPlaybackMuted();
 
161
}
 
162
 
 
163
///is mute capture
 
164
bool AudioSettingsModel::isCaptureMuted() const
 
165
{
 
166
   return DBus::ConfigurationManager::instance().isCaptureMuted();
 
167
}
 
168
 
 
169
int AudioSettingsModel::playbackVolume() const
 
170
{
 
171
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
172
   return configurationManager.getVolume(DeviceKey::PLAYBACK)*100;
 
173
}
 
174
 
 
175
int AudioSettingsModel::captureVolume() const
 
176
{
 
177
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
178
   return configurationManager.getVolume(DeviceKey::CAPTURE)*100;
 
179
}
 
180
 
 
181
void AudioSettingsModel::setPlaybackVolume(int volume)
 
182
{
 
183
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
184
   configurationManager.setVolume(DeviceKey::PLAYBACK,volume/100.0f);
 
185
   emit playbackVolumeChanged(volume);
 
186
}
 
187
 
 
188
void AudioSettingsModel::setCaptureVolume(int volume)
 
189
{
 
190
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
191
   configurationManager.setVolume(DeviceKey::CAPTURE,volume/100.0f);
 
192
   emit captureVolumeChanged(volume);
 
193
}
 
194
 
 
195
void AudioSettingsModel::setDTMFMuted(bool muted)
 
196
{
 
197
   //TODO
 
198
   DBus::ConfigurationManager::instance().muteDtmf(muted);
 
199
   emit DTMFMutedChanged(muted);
 
200
}
 
201
 
 
202
bool AudioSettingsModel::areDTMFMuted() const
 
203
{
 
204
   return DBus::ConfigurationManager::instance().isDtmfMuted();
 
205
}
 
206
 
 
207
/****************************************************************
 
208
 *                                                              *
 
209
 *                        AlsaPluginModel                       *
 
210
 *                                                              *
 
211
 ***************************************************************/
 
212
///Constructor
 
213
AlsaPluginModel::AlsaPluginModel(QObject* parent) : QAbstractListModel(parent)
 
214
{
 
215
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
216
   m_lDeviceList = configurationManager.getAudioPluginList();
 
217
}
 
218
 
 
219
///Destructor
 
220
AlsaPluginModel::~AlsaPluginModel()
 
221
{
 
222
   
 
223
}
 
224
 
 
225
///Re-implement QAbstractListModel data
 
226
QVariant AlsaPluginModel::data( const QModelIndex& index, int role) const
 
227
{
 
228
   if (!index.isValid())
 
229
      return QVariant();
 
230
   switch(role) {
 
231
      case Qt::DisplayRole:
 
232
         return m_lDeviceList[index.row()];
 
233
   };
 
234
   return QVariant();
 
235
}
 
236
 
 
237
///Re-implement QAbstractListModel rowCount
 
238
int AlsaPluginModel::rowCount( const QModelIndex& parent ) const
 
239
{
 
240
   if (parent.isValid())
 
241
      return 0;
 
242
   return m_lDeviceList.size();
 
243
}
 
244
 
 
245
///Re-implement QAbstractListModel flags
 
246
Qt::ItemFlags AlsaPluginModel::flags( const QModelIndex& index ) const
 
247
{
 
248
   Q_UNUSED(index)
 
249
   return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 
250
}
 
251
 
 
252
///Setting data is disabled
 
253
bool AlsaPluginModel::setData( const QModelIndex& index, const QVariant &value, int role)
 
254
{
 
255
   Q_UNUSED(index)
 
256
   Q_UNUSED(value)
 
257
   Q_UNUSED(role)
 
258
   return false;
 
259
}
 
260
 
 
261
///Return the current index
 
262
QModelIndex AlsaPluginModel::currentPlugin() const
 
263
{
 
264
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
265
   const int idx = m_lDeviceList.indexOf(configurationManager.getCurrentAudioOutputPlugin());
 
266
   qDebug() << "Invalid current audio plugin";
 
267
   if (idx == -1)
 
268
      return QModelIndex();
 
269
   else
 
270
      return index(idx,0,QModelIndex());
 
271
}
 
272
 
 
273
///Set the current index
 
274
void AlsaPluginModel::setCurrentPlugin(const QModelIndex& idx)
 
275
{
 
276
   if (!idx.isValid())
 
277
      return;
 
278
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
279
   configurationManager.setAudioPlugin(m_lDeviceList[idx.row()]);
 
280
}
 
281
 
 
282
///Set the current index (qcombobox compatibility shim)
 
283
void AlsaPluginModel::setCurrentPlugin(int idx)
 
284
{
 
285
   setCurrentPlugin(index(idx,0));
 
286
}
 
287
 
 
288
///Reload to current daemon state
 
289
void AlsaPluginModel::reload()
 
290
{
 
291
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
292
   m_lDeviceList = configurationManager.getAudioPluginList();
 
293
   emit layoutChanged();
 
294
   emit dataChanged(index(0,0),index(m_lDeviceList.size()-1,0));
 
295
}
 
296
 
 
297
 
 
298
/****************************************************************
 
299
 *                                                              *
 
300
 *                       InputDeviceModel                       *
 
301
 *                                                              *
 
302
 ***************************************************************/
 
303
 
 
304
///Constructor
 
305
InputDeviceModel::InputDeviceModel(QObject* parent) : QAbstractListModel(parent)
 
306
{
 
307
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
308
   m_lDeviceList = configurationManager.getAudioInputDeviceList  ();
 
309
}
 
310
 
 
311
///Destructor
 
312
InputDeviceModel::~InputDeviceModel()
 
313
{
 
314
   
 
315
}
 
316
 
 
317
///Re-implement QAbstractListModel data
 
318
QVariant InputDeviceModel::data( const QModelIndex& index, int role) const
 
319
{
 
320
   if (!index.isValid())
 
321
      return QVariant();
 
322
   switch(role) {
 
323
      case Qt::DisplayRole:
 
324
         return m_lDeviceList[index.row()];
 
325
   };
 
326
   return QVariant();
 
327
}
 
328
 
 
329
///Re-implement QAbstractListModel rowCount
 
330
int InputDeviceModel::rowCount( const QModelIndex& parent ) const
 
331
{
 
332
   if (parent.isValid())
 
333
      return 0;
 
334
   return m_lDeviceList.size();
 
335
}
 
336
 
 
337
///Re-implement QAbstractListModel flags
 
338
Qt::ItemFlags InputDeviceModel::flags( const QModelIndex& index ) const
 
339
{
 
340
   Q_UNUSED(index)
 
341
   return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 
342
}
 
343
 
 
344
///This model does not support setting data
 
345
bool InputDeviceModel::setData( const QModelIndex& index, const QVariant &value, int role)
 
346
{
 
347
   Q_UNUSED(index)
 
348
   Q_UNUSED(value)
 
349
   Q_UNUSED(role)
 
350
   return false;
 
351
}
 
352
 
 
353
///Return the current input device index
 
354
QModelIndex InputDeviceModel::currentDevice() const
 
355
{
 
356
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
357
   const QStringList currentDevices = configurationManager.getCurrentAudioDevicesIndex();
 
358
   const int idx = currentDevices[AudioSettingsModel::DeviceIndex::INPUT].toInt();
 
359
   if (idx >= m_lDeviceList.size())
 
360
      return QModelIndex();
 
361
   return index(idx,0);
 
362
}
 
363
 
 
364
///Set the current input device
 
365
void InputDeviceModel::setCurrentDevice(const QModelIndex& index)
 
366
{
 
367
   if (index.isValid()) {
 
368
      ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
369
      configurationManager.setAudioInputDevice(index.row());
 
370
   }
 
371
}
 
372
 
 
373
///QCombobox signals -> QModelIndex shim
 
374
void InputDeviceModel::setCurrentDevice(int idx)
 
375
{
 
376
   setCurrentDevice(index(idx,0));
 
377
}
 
378
 
 
379
///Reload input device list
 
380
void InputDeviceModel::reload()
 
381
{
 
382
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
383
   m_lDeviceList = configurationManager.getAudioInputDeviceList  ();
 
384
   emit layoutChanged();
 
385
   emit dataChanged(index(0,0),index(m_lDeviceList.size()-1,0));
 
386
}
 
387
 
 
388
 
 
389
/****************************************************************
 
390
 *                                                              *
 
391
 *                       OutputDeviceModel                      *
 
392
 *                                                              *
 
393
 ***************************************************************/
 
394
 
 
395
///Constructor
 
396
OutputDeviceModel::OutputDeviceModel(QObject* parent) : QAbstractListModel(parent)
 
397
{
 
398
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
399
   m_lDeviceList = configurationManager.getAudioOutputDeviceList();
 
400
}
 
401
 
 
402
///Destructor
 
403
OutputDeviceModel::~OutputDeviceModel()
 
404
{
 
405
   
 
406
}
 
407
 
 
408
///Re-implement QAbstractListModel data
 
409
QVariant OutputDeviceModel::data( const QModelIndex& index, int role) const
 
410
{
 
411
   if (!index.isValid())
 
412
      return QVariant();
 
413
   switch(role) {
 
414
      case Qt::DisplayRole:
 
415
         return m_lDeviceList[index.row()];
 
416
   };
 
417
   return QVariant();
 
418
}
 
419
 
 
420
///Re-implement QAbstractListModel rowCount
 
421
int OutputDeviceModel::rowCount( const QModelIndex& parent ) const
 
422
{
 
423
   if (parent.isValid())
 
424
      return 0;
 
425
   return m_lDeviceList.size();
 
426
}
 
427
 
 
428
///Re-implement QAbstractListModel flags
 
429
Qt::ItemFlags OutputDeviceModel::flags( const QModelIndex& index ) const
 
430
{
 
431
   Q_UNUSED(index)
 
432
   return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 
433
}
 
434
 
 
435
///This model is read only
 
436
bool OutputDeviceModel::setData( const QModelIndex& index, const QVariant &value, int role)
 
437
{
 
438
   Q_UNUSED(index)
 
439
   Q_UNUSED(value)
 
440
   Q_UNUSED(role)
 
441
   return false;
 
442
}
 
443
 
 
444
///Return the current output device
 
445
QModelIndex OutputDeviceModel::currentDevice() const
 
446
{
 
447
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
448
   const QStringList currentDevices = configurationManager.getCurrentAudioDevicesIndex();
 
449
   const int         idx            = currentDevices[AudioSettingsModel::DeviceIndex::OUTPUT].toInt();
 
450
 
 
451
   if (idx >= m_lDeviceList.size())
 
452
      return QModelIndex();
 
453
   return index(idx,0);
 
454
}
 
455
 
 
456
///Set the current output device
 
457
void OutputDeviceModel::setCurrentDevice(const QModelIndex& index)
 
458
{
 
459
   if (index.isValid()) {
 
460
      ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
461
      configurationManager.setAudioOutputDevice(index.row());
 
462
   }
 
463
}
 
464
 
 
465
///QCombobox index -> QModelIndex shim
 
466
void OutputDeviceModel::setCurrentDevice(int idx)
 
467
{
 
468
   setCurrentDevice(index(idx,0));
 
469
}
 
470
 
 
471
///reload output devices list
 
472
void OutputDeviceModel::reload()
 
473
{
 
474
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
475
   m_lDeviceList = configurationManager.getAudioOutputDeviceList();
 
476
   emit layoutChanged();
 
477
   emit dataChanged(index(0,0),index(m_lDeviceList.size()-1,0));
 
478
}
 
479
 
 
480
/****************************************************************
 
481
 *                                                              *
 
482
 *                        AudioManagerModel                      *
 
483
 *                                                              *
 
484
 ***************************************************************/
 
485
 
 
486
///Constructor
 
487
AudioManagerModel::AudioManagerModel(QObject* parent) : QAbstractListModel(parent)
 
488
{
 
489
   m_lDeviceList << "ALSA" << "Pulse Audio";
 
490
}
 
491
 
 
492
///Destructor
 
493
AudioManagerModel::~AudioManagerModel()
 
494
{
 
495
   m_lDeviceList.clear();
 
496
}
 
497
 
 
498
///Re-implement QAbstractListModel data
 
499
QVariant AudioManagerModel::data( const QModelIndex& index, int role) const
 
500
{
 
501
   if (!index.isValid())
 
502
      return QVariant();
 
503
   switch(role) {
 
504
      case Qt::DisplayRole:
 
505
         return m_lDeviceList[index.row()];
 
506
   };
 
507
   return QVariant();
 
508
}
 
509
 
 
510
///Re-implement QAbstractListModel rowCount
 
511
int AudioManagerModel::rowCount( const QModelIndex& parent ) const
 
512
{
 
513
   if (parent.isValid())
 
514
      return 0;
 
515
   return m_lDeviceList.size();
 
516
}
 
517
 
 
518
///Re-implement QAbstractListModel flags
 
519
Qt::ItemFlags AudioManagerModel::flags( const QModelIndex& index ) const
 
520
{
 
521
   Q_UNUSED(index)
 
522
   return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 
523
}
 
524
 
 
525
///This model is read only
 
526
bool AudioManagerModel::setData( const QModelIndex& index, const QVariant &value, int role)
 
527
{
 
528
   Q_UNUSED(index)
 
529
   Q_UNUSED(value)
 
530
   Q_UNUSED(role)
 
531
   return false;
 
532
}
 
533
 
 
534
/**
 
535
 * Return the current audio manager
 
536
 * @warning Changes to the current index model will invalid Input/Output/Ringtone devices models
 
537
 */
 
538
QModelIndex AudioManagerModel::currentManager() const
 
539
{
 
540
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
541
   const QString manager = configurationManager.getAudioManager();
 
542
      if (manager == ManagerName::PULSEAUDIO)
 
543
         return index((int)Manager::PULSE,0);
 
544
      else if (manager == ManagerName::ALSA)
 
545
         return index((int)Manager::ALSA,0);
 
546
      return QModelIndex();
 
547
}
 
548
 
 
549
///Set current audio manager
 
550
void AudioManagerModel::setCurrentManager(const QModelIndex& idx)
 
551
{
 
552
   if (!idx.isValid())
 
553
      return;
 
554
 
 
555
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
556
   switch (static_cast<Manager>(idx.row())) {
 
557
      case Manager::PULSE:
 
558
         configurationManager.setAudioManager(ManagerName::PULSEAUDIO);
 
559
         AudioSettingsModel::instance()->reload();
 
560
         break;
 
561
      case Manager::ALSA:
 
562
         configurationManager.setAudioManager(ManagerName::ALSA);
 
563
         AudioSettingsModel::instance()->reload();
 
564
         break;
 
565
   };
 
566
}
 
567
 
 
568
///QCombobox -> QModelIndex shim
 
569
void AudioManagerModel::setCurrentManager(int idx)
 
570
{
 
571
   setCurrentManager(index(idx,0));
 
572
}
 
573
 
 
574
/****************************************************************
 
575
 *                                                              *
 
576
 *                       RingtoneDeviceModel                    *
 
577
 *                                                              *
 
578
 ***************************************************************/
 
579
 
 
580
///Constructor
 
581
RingtoneDeviceModel::RingtoneDeviceModel(QObject* parent) : QAbstractListModel(parent)
 
582
{
 
583
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
584
   m_lDeviceList = configurationManager.getAudioOutputDeviceList();
 
585
}
 
586
 
 
587
///Destructor
 
588
RingtoneDeviceModel::~RingtoneDeviceModel()
 
589
{
 
590
   
 
591
}
 
592
 
 
593
///Re-implement QAbstractListModel data
 
594
QVariant RingtoneDeviceModel::data( const QModelIndex& index, int role) const
 
595
{
 
596
   if (!index.isValid())
 
597
      return QVariant();
 
598
   switch(role) {
 
599
      case Qt::DisplayRole:
 
600
         return m_lDeviceList[index.row()];
 
601
   };
 
602
   return QVariant();
 
603
}
 
604
 
 
605
///Re-implement QAbstractListModel rowCount
 
606
int RingtoneDeviceModel::rowCount( const QModelIndex& parent ) const
 
607
{
 
608
   if (parent.isValid())
 
609
      return 0;
 
610
   return m_lDeviceList.size();
 
611
}
 
612
 
 
613
///Re-implement QAbstractListModel flags
 
614
Qt::ItemFlags RingtoneDeviceModel::flags( const QModelIndex& index ) const
 
615
{
 
616
   Q_UNUSED(index)
 
617
   return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 
618
}
 
619
 
 
620
///RingtoneDeviceModel is read only
 
621
bool RingtoneDeviceModel::setData( const QModelIndex& index, const QVariant &value, int role)
 
622
{
 
623
   Q_UNUSED(index)
 
624
   Q_UNUSED(value)
 
625
   Q_UNUSED(role)
 
626
   return false;
 
627
}
 
628
 
 
629
///Return the current ringtone device
 
630
QModelIndex RingtoneDeviceModel::currentDevice() const
 
631
{
 
632
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
633
   const QStringList currentDevices = configurationManager.getCurrentAudioDevicesIndex();
 
634
   const int         idx            = currentDevices[AudioSettingsModel::DeviceIndex::RINGTONE].toInt();
 
635
   if (idx >= m_lDeviceList.size())
 
636
      return QModelIndex();
 
637
   return index(idx,0);
 
638
}
 
639
 
 
640
///Set the current ringtone device
 
641
void RingtoneDeviceModel::setCurrentDevice(const QModelIndex& index)
 
642
{
 
643
   if (index.isValid()) {
 
644
      ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
645
      configurationManager.setAudioRingtoneDevice(index.row());
 
646
   }
 
647
}
 
648
 
 
649
///QCombobox -> QModelIndex shim
 
650
void RingtoneDeviceModel::setCurrentDevice(int idx)
 
651
{
 
652
   setCurrentDevice(index(idx,0));
 
653
}
 
654
 
 
655
///Reload ringtone device list
 
656
void RingtoneDeviceModel::reload()
 
657
{
 
658
   ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
 
659
   m_lDeviceList = configurationManager.getAudioOutputDeviceList();
 
660
   emit layoutChanged();
 
661
   emit dataChanged(index(0,0),index(m_lDeviceList.size()-1,0));
 
662
}