Skip to content
Snippets Groups Projects
Commit 0e79b741 authored by Alexandre Lision's avatar Alexandre Lision
Browse files

ringtonemodel: improve switching

Tuleap: #339
Change-Id: I921c16f103dcb7e3293cca82e83ca7f0f4156200
parent 228e9ba3
No related branches found
No related tags found
No related merge requests found
......@@ -27,10 +27,9 @@ public:
RingtonePrivate();
QString m_Path;
QString m_Name;
bool m_IsPlaying;
};
RingtonePrivate::RingtonePrivate() : m_IsPlaying(false)
RingtonePrivate::RingtonePrivate()
{
}
......@@ -55,7 +54,6 @@ QString Ringtone::name() const
return d_ptr->m_Name;
}
void Ringtone::setPath(const QString& path)
{
d_ptr->m_Path = QDir::toNativeSeparators(path);
......@@ -65,13 +63,3 @@ void Ringtone::setName(const QString& name)
{
d_ptr->m_Name = name;
}
bool Ringtone::isPlaying() const
{
return d_ptr->m_IsPlaying;
}
void Ringtone::setIsPlaying(const bool value)
{
d_ptr->m_IsPlaying = value;
}
......@@ -32,12 +32,10 @@ public:
//Getter
QString path () const;
QString name () const;
bool isPlaying() const;
//Setter
void setPath (const QString& path );
void setName (const QString& name );
void setIsPlaying(const bool value);
private:
RingtonePrivate* d_ptr;
......
......@@ -28,6 +28,7 @@
#include "dbus/configurationmanager.h"
#include "dbus/callmanager.h"
#include "account.h"
#include "accountmodel.h"
#include "ringtone.h"
#include <localringtonecollection.h>
......@@ -46,6 +47,7 @@ public:
QHash<Account*,QItemSelectionModel*> m_hSelectionModels ;
LocalRingtoneCollection* m_pCollection ;
QHash<const Ringtone*,Account*> m_hPendingSelection;
bool m_isPlaying ;
//Helpers
int currentIndex(Account* a) const;
......@@ -62,6 +64,7 @@ RingtoneModelPrivate::RingtoneModelPrivate(RingtoneModel* parent)
: q_ptr(parent)
, m_pTimer(nullptr)
, m_pCurrent(nullptr)
, m_isPlaying(false)
{
}
......@@ -72,6 +75,16 @@ RingtoneModel::RingtoneModel(QObject* parent)
, d_ptr(new RingtoneModelPrivate(this))
{
d_ptr->m_pCollection = addCollection<LocalRingtoneCollection>();
QObject::connect(AccountModel::instance().selectionModel(),
&QItemSelectionModel::currentChanged,
[=](const QModelIndex &current, const QModelIndex &previous) {
Q_UNUSED(current)
if (d_ptr->m_isPlaying && previous.isValid()) {
auto acc = AccountModel::instance().getAccountByModelIndex(previous);
auto qIdx = d_ptr->m_hSelectionModels[acc]->currentIndex();
play(qIdx);
}
});
}
RingtoneModel& RingtoneModel::instance()
......@@ -96,12 +109,16 @@ QHash<int,QByteArray> RingtoneModel::roleNames() const
static bool initRoles = false;
if (!initRoles) {
initRoles = true;
roles[Role::IsPlaying ] = "IsPlaying";
roles[Role::FullPath ] = "FullPath";
}
return roles;
}
bool RingtoneModel::isPlaying()
{
return d_ptr->m_isPlaying;
}
QVariant RingtoneModel::data( const QModelIndex& index, int role ) const
{
if (!index.isValid())
......@@ -112,8 +129,6 @@ QVariant RingtoneModel::data( const QModelIndex& index, int role ) const
switch (role) {
case Qt::DisplayRole:
return info->name();
case Role::IsPlaying:
return info->isPlaying();
case Role::FullPath:
return info->path();
};
......@@ -215,7 +230,7 @@ void RingtoneModel::play(const QModelIndex& idx)
d_ptr->m_pTimer->stop();
}
d_ptr->m_pTimer->start();
info->setIsPlaying(true);
d_ptr->m_isPlaying = true;
emit dataChanged(index(idx.row(),0),index(idx.row(),1));
d_ptr->m_pCurrent = info;
}
......@@ -226,7 +241,7 @@ void RingtoneModelPrivate::slotStopTimer()
if (m_pCurrent) {
CallManagerInterface& callManager = CallManager::instance();
callManager.stopRecordedFilePlayback(m_pCurrent->path());
m_pCurrent->setIsPlaying(false);
m_isPlaying = false;
const QModelIndex& idx = q_ptr->index(m_lRingtone.indexOf(m_pCurrent),0);
emit q_ptr->dataChanged(idx,q_ptr->index(idx.row(),1));
m_pCurrent = nullptr;
......
......@@ -37,8 +37,7 @@ class LIB_EXPORT RingtoneModel : public QAbstractTableModel, public CollectionMa
public:
enum Role {
IsPlaying = 100,
FullPath = 101,
FullPath = 100,
};
virtual ~RingtoneModel();
......@@ -54,6 +53,7 @@ public:
//Getters
Ringtone* currentRingTone(Account* a) const;
QItemSelectionModel* selectionModel(Account* a) const;
bool isPlaying();
//Mutator
void play(const QModelIndex& index);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment