diff --git a/src/ringtone.cpp b/src/ringtone.cpp index a661c36d550497d09c6eaf9cb59362edd38f2bf1..a0ebc1955e6bfa3ce616367fc3c4834027ae667b 100644 --- a/src/ringtone.cpp +++ b/src/ringtone.cpp @@ -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; -} diff --git a/src/ringtone.h b/src/ringtone.h index 1a809d37e961c3daf077e137e2f89046f7cc2cb1..8c3c80739cd721215474a1b0621ead5135c64ba3 100644 --- a/src/ringtone.h +++ b/src/ringtone.h @@ -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; diff --git a/src/ringtonemodel.cpp b/src/ringtonemodel.cpp index bed7157dce59e7e95765482ea4e810f34d41a3ee..6abaf7b5fbe567112bc35fb8e452769f0d414725 100644 --- a/src/ringtonemodel.cpp +++ b/src/ringtonemodel.cpp @@ -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 ¤t, 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; diff --git a/src/ringtonemodel.h b/src/ringtonemodel.h index bd01fb00c3d7d8e5452ec69737e752f804898307..e00e23215bffb530ff51be4d3ad3ea75bcd0a414 100644 --- a/src/ringtonemodel.h +++ b/src/ringtonemodel.h @@ -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);