1
/****************************************************************************
2
* Copyright (C) 2013-2014 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
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. *
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. *
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 "ringtonemodel.h"
21
#include <QtCore/QTimer>
24
#include "dbus/configurationmanager.h"
25
#include "dbus/callmanager.h"
28
RingToneModel::RingToneModel(Account* a) : QAbstractTableModel(a),m_pAccount(a),m_pTimer(nullptr),
31
ConfigurationManagerInterface& configurationManager = DBus::ConfigurationManager::instance();
32
QMap<QString,QString> m_hRingtonePath = configurationManager.getRingtoneList();
33
QMutableMapIterator<QString, QString> iter(m_hRingtonePath);
34
while (iter.hasNext()) {
36
QFileInfo fileinfo(iter.key());
37
RingToneInfo* info = new RingToneInfo();
38
info->name = iter.value();
39
info->path = fileinfo.absoluteFilePath();
44
RingToneModel::~RingToneModel()
46
while (m_lRingTone.size()) {
47
RingToneInfo* ringtone = m_lRingTone[0];
48
m_lRingTone.removeAt(0);
53
QVariant RingToneModel::data( const QModelIndex& index, int role ) const
57
RingToneInfo* info = m_lRingTone[index.row()];
58
switch (index.column()) {
64
return info->isPlaying;
79
int RingToneModel::rowCount( const QModelIndex& parent ) const
81
if (!parent.isValid())
82
return m_lRingTone.size();
86
int RingToneModel::columnCount( const QModelIndex& parent ) const
90
return 2; //Name, then an empty one for widgets
93
Qt::ItemFlags RingToneModel::flags( const QModelIndex& index ) const
95
if (index.isValid() && !index.parent().isValid())
96
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
97
return Qt::NoItemFlags;
100
///This is a read only model
101
bool RingToneModel::setData( const QModelIndex& index, const QVariant &value, int role)
109
QString RingToneModel::currentRingTone() const
111
return QFileInfo(m_pAccount->ringtonePath()).absoluteFilePath();
114
QModelIndex RingToneModel::currentIndex() const
116
const QString rt = currentRingTone();
117
for (int i=0;i<m_lRingTone.size();i++) {
118
RingToneInfo* info = m_lRingTone[i];
119
if (info->path == rt)
122
return QModelIndex();
125
void RingToneModel::play(const QModelIndex& idx)
128
RingToneInfo* info = m_lRingTone[idx.row()];
129
if (m_pCurrent && info == m_pCurrent) {
133
CallManagerInterface& callManager = DBus::CallManager::instance();
134
Q_NOREPLY callManager.startRecordedFilePlayback(info->path);
136
m_pTimer = new QTimer(this);
137
m_pTimer->setInterval(10000);
138
connect(m_pTimer,SIGNAL(timeout()),this,SLOT(slotStopTimer()));
140
else if (m_pTimer->isActive()) {
144
info->isPlaying = true;
145
emit dataChanged(index(idx.row(),0),index(idx.row(),1));
150
void RingToneModel::slotStopTimer()
153
CallManagerInterface& callManager = DBus::CallManager::instance();
154
callManager.stopRecordedFilePlayback(m_pCurrent->path);
155
m_pCurrent->isPlaying = false;
156
const QModelIndex& idx = index(m_lRingTone.indexOf(m_pCurrent),0);
157
emit dataChanged(idx,index(idx.row(),1));
158
m_pCurrent = nullptr;