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
Branches
Tags
No related merge requests found
...@@ -27,10 +27,9 @@ public: ...@@ -27,10 +27,9 @@ public:
RingtonePrivate(); RingtonePrivate();
QString m_Path; QString m_Path;
QString m_Name; QString m_Name;
bool m_IsPlaying;
}; };
RingtonePrivate::RingtonePrivate() : m_IsPlaying(false) RingtonePrivate::RingtonePrivate()
{ {
} }
...@@ -55,7 +54,6 @@ QString Ringtone::name() const ...@@ -55,7 +54,6 @@ QString Ringtone::name() const
return d_ptr->m_Name; return d_ptr->m_Name;
} }
void Ringtone::setPath(const QString& path) void Ringtone::setPath(const QString& path)
{ {
d_ptr->m_Path = QDir::toNativeSeparators(path); d_ptr->m_Path = QDir::toNativeSeparators(path);
...@@ -65,13 +63,3 @@ void Ringtone::setName(const QString& name) ...@@ -65,13 +63,3 @@ void Ringtone::setName(const QString& name)
{ {
d_ptr->m_Name = 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: ...@@ -32,12 +32,10 @@ public:
//Getter //Getter
QString path () const; QString path () const;
QString name () const; QString name () const;
bool isPlaying() const;
//Setter //Setter
void setPath (const QString& path ); void setPath (const QString& path );
void setName (const QString& name ); void setName (const QString& name );
void setIsPlaying(const bool value);
private: private:
RingtonePrivate* d_ptr; RingtonePrivate* d_ptr;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "dbus/configurationmanager.h" #include "dbus/configurationmanager.h"
#include "dbus/callmanager.h" #include "dbus/callmanager.h"
#include "account.h" #include "account.h"
#include "accountmodel.h"
#include "ringtone.h" #include "ringtone.h"
#include <localringtonecollection.h> #include <localringtonecollection.h>
...@@ -46,6 +47,7 @@ public: ...@@ -46,6 +47,7 @@ public:
QHash<Account*,QItemSelectionModel*> m_hSelectionModels ; QHash<Account*,QItemSelectionModel*> m_hSelectionModels ;
LocalRingtoneCollection* m_pCollection ; LocalRingtoneCollection* m_pCollection ;
QHash<const Ringtone*,Account*> m_hPendingSelection; QHash<const Ringtone*,Account*> m_hPendingSelection;
bool m_isPlaying ;
//Helpers //Helpers
int currentIndex(Account* a) const; int currentIndex(Account* a) const;
...@@ -62,6 +64,7 @@ RingtoneModelPrivate::RingtoneModelPrivate(RingtoneModel* parent) ...@@ -62,6 +64,7 @@ RingtoneModelPrivate::RingtoneModelPrivate(RingtoneModel* parent)
: q_ptr(parent) : q_ptr(parent)
, m_pTimer(nullptr) , m_pTimer(nullptr)
, m_pCurrent(nullptr) , m_pCurrent(nullptr)
, m_isPlaying(false)
{ {
} }
...@@ -72,6 +75,16 @@ RingtoneModel::RingtoneModel(QObject* parent) ...@@ -72,6 +75,16 @@ RingtoneModel::RingtoneModel(QObject* parent)
, d_ptr(new RingtoneModelPrivate(this)) , d_ptr(new RingtoneModelPrivate(this))
{ {
d_ptr->m_pCollection = addCollection<LocalRingtoneCollection>(); 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() RingtoneModel& RingtoneModel::instance()
...@@ -96,12 +109,16 @@ QHash<int,QByteArray> RingtoneModel::roleNames() const ...@@ -96,12 +109,16 @@ QHash<int,QByteArray> RingtoneModel::roleNames() const
static bool initRoles = false; static bool initRoles = false;
if (!initRoles) { if (!initRoles) {
initRoles = true; initRoles = true;
roles[Role::IsPlaying ] = "IsPlaying";
roles[Role::FullPath ] = "FullPath"; roles[Role::FullPath ] = "FullPath";
} }
return roles; return roles;
} }
bool RingtoneModel::isPlaying()
{
return d_ptr->m_isPlaying;
}
QVariant RingtoneModel::data( const QModelIndex& index, int role ) const QVariant RingtoneModel::data( const QModelIndex& index, int role ) const
{ {
if (!index.isValid()) if (!index.isValid())
...@@ -112,8 +129,6 @@ QVariant RingtoneModel::data( const QModelIndex& index, int role ) const ...@@ -112,8 +129,6 @@ QVariant RingtoneModel::data( const QModelIndex& index, int role ) const
switch (role) { switch (role) {
case Qt::DisplayRole: case Qt::DisplayRole:
return info->name(); return info->name();
case Role::IsPlaying:
return info->isPlaying();
case Role::FullPath: case Role::FullPath:
return info->path(); return info->path();
}; };
...@@ -215,7 +230,7 @@ void RingtoneModel::play(const QModelIndex& idx) ...@@ -215,7 +230,7 @@ void RingtoneModel::play(const QModelIndex& idx)
d_ptr->m_pTimer->stop(); d_ptr->m_pTimer->stop();
} }
d_ptr->m_pTimer->start(); d_ptr->m_pTimer->start();
info->setIsPlaying(true); d_ptr->m_isPlaying = true;
emit dataChanged(index(idx.row(),0),index(idx.row(),1)); emit dataChanged(index(idx.row(),0),index(idx.row(),1));
d_ptr->m_pCurrent = info; d_ptr->m_pCurrent = info;
} }
...@@ -226,7 +241,7 @@ void RingtoneModelPrivate::slotStopTimer() ...@@ -226,7 +241,7 @@ void RingtoneModelPrivate::slotStopTimer()
if (m_pCurrent) { if (m_pCurrent) {
CallManagerInterface& callManager = CallManager::instance(); CallManagerInterface& callManager = CallManager::instance();
callManager.stopRecordedFilePlayback(m_pCurrent->path()); callManager.stopRecordedFilePlayback(m_pCurrent->path());
m_pCurrent->setIsPlaying(false); m_isPlaying = false;
const QModelIndex& idx = q_ptr->index(m_lRingtone.indexOf(m_pCurrent),0); const QModelIndex& idx = q_ptr->index(m_lRingtone.indexOf(m_pCurrent),0);
emit q_ptr->dataChanged(idx,q_ptr->index(idx.row(),1)); emit q_ptr->dataChanged(idx,q_ptr->index(idx.row(),1));
m_pCurrent = nullptr; m_pCurrent = nullptr;
......
...@@ -37,8 +37,7 @@ class LIB_EXPORT RingtoneModel : public QAbstractTableModel, public CollectionMa ...@@ -37,8 +37,7 @@ class LIB_EXPORT RingtoneModel : public QAbstractTableModel, public CollectionMa
public: public:
enum Role { enum Role {
IsPlaying = 100, FullPath = 100,
FullPath = 101,
}; };
virtual ~RingtoneModel(); virtual ~RingtoneModel();
...@@ -54,6 +53,7 @@ public: ...@@ -54,6 +53,7 @@ public:
//Getters //Getters
Ringtone* currentRingTone(Account* a) const; Ringtone* currentRingTone(Account* a) const;
QItemSelectionModel* selectionModel(Account* a) const; QItemSelectionModel* selectionModel(Account* a) const;
bool isPlaying();
//Mutator //Mutator
void play(const QModelIndex& index); 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