Skip to content
Snippets Groups Projects
Commit 7aadfa9e authored by Edric Milaret's avatar Edric Milaret Committed by Alexandre Lision
Browse files

fix ringtone model path

Tuleap: #339
Change-Id: I71783ee048bde01b4696752fe651801fa33478b2
parent 0c8ce959
No related branches found
No related tags found
No related merge requests found
...@@ -120,15 +120,16 @@ bool LocalRingtoneCollection::load() ...@@ -120,15 +120,16 @@ bool LocalRingtoneCollection::load()
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
QDir ringtonesDir(QFileInfo(QCoreApplication::applicationFilePath()).path()+"/ringtones/"); QDir ringtonesDir(QFileInfo(QCoreApplication::applicationFilePath()).path()+"/ringtones/");
#elif defined(Q_OS_OSX) #elif defined(Q_OS_OSX)
QDir ringtonesDir(QFileInfo(QCoreApplication::applicationFilePath()).path()+"/ringtones/"); //FIXME QDir ringtonesDir(QCoreApplication::applicationDirPath());
ringtonesDir.cdUp();
ringtonesDir.cd("Resources/ringtones/");
#endif #endif
if(!ringtonesDir.exists()) if(!ringtonesDir.exists())
return true; return true;
const QStringList entries = ringtonesDir.entryList({"*.wav", "*.ul", "*.au", "*.flac"}, QDir::Files);
const QStringList entries = ringtonesDir.entryList({"*.wav", "*.ul", "*.au", ".mp3", ".flac"}, QDir::Files);
for (const QString& item : entries) { for (const QString& item : entries) {
QFileInfo fileinfo(ringtonesDir.absolutePath()+item); QFileInfo fileinfo(ringtonesDir.absolutePath()+"/"+item);
Ringtone* info = new Ringtone(); Ringtone* info = new Ringtone();
info->setPath(fileinfo.absoluteFilePath()); info->setPath(fileinfo.absoluteFilePath());
info->setName(item); info->setName(item);
...@@ -270,7 +271,7 @@ void Serializable::RingtoneNode::read(const QJsonObject &json) ...@@ -270,7 +271,7 @@ void Serializable::RingtoneNode::read(const QJsonObject &json)
void Serializable::RingtoneNode::write(QJsonObject& json) void Serializable::RingtoneNode::write(QJsonObject& json)
{ {
json["path"] = ringtone->path().path(); json["path"] = ringtone->path();
json["name"] = ringtone->name(); json["name"] = ringtone->name();
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
//Qt //Qt
#include <QtCore/QUrl> #include <QtCore/QUrl>
#include <QtCore/QDir>
class RingtonePrivate class RingtonePrivate
{ {
...@@ -44,7 +45,7 @@ Ringtone::~Ringtone() ...@@ -44,7 +45,7 @@ Ringtone::~Ringtone()
delete d_ptr; delete d_ptr;
} }
QUrl Ringtone::path() const QString Ringtone::path() const
{ {
return d_ptr->m_Path; return d_ptr->m_Path;
} }
...@@ -55,9 +56,9 @@ QString Ringtone::name() const ...@@ -55,9 +56,9 @@ QString Ringtone::name() const
} }
void Ringtone::setPath(const QUrl& url) void Ringtone::setPath(const QString& path)
{ {
d_ptr->m_Path = url.path(); d_ptr->m_Path = QDir::toNativeSeparators(path);
} }
void Ringtone::setName(const QString& name) void Ringtone::setName(const QString& name)
......
...@@ -30,12 +30,12 @@ public: ...@@ -30,12 +30,12 @@ public:
virtual ~Ringtone(); virtual ~Ringtone();
//Getter //Getter
QUrl path () const; QString path () const;
QString name () const; QString name () const;
bool isPlaying() const; bool isPlaying() const;
//Setter //Setter
void setPath (const QUrl& url ); void setPath (const QString& path );
void setName (const QString& name ); void setName (const QString& name );
void setIsPlaying(const bool value); void setIsPlaying(const bool value);
......
...@@ -71,8 +71,6 @@ RingtoneModel::RingtoneModel(QObject* parent) ...@@ -71,8 +71,6 @@ RingtoneModel::RingtoneModel(QObject* parent)
, CollectionManagerInterface<Ringtone>(this) , CollectionManagerInterface<Ringtone>(this)
, d_ptr(new RingtoneModelPrivate(this)) , d_ptr(new RingtoneModelPrivate(this))
{ {
// ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance();
d_ptr->m_pCollection = addCollection<LocalRingtoneCollection>(); d_ptr->m_pCollection = addCollection<LocalRingtoneCollection>();
} }
...@@ -175,10 +173,10 @@ int RingtoneModelPrivate::currentIndex(Account* a) const ...@@ -175,10 +173,10 @@ int RingtoneModelPrivate::currentIndex(Account* a) const
const QString rt = a->ringtonePath(); const QString rt = a->ringtonePath();
for (int i=0;i<m_lRingtone.size();i++) { for (int i=0;i<m_lRingtone.size();i++) {
Ringtone* info = m_lRingtone[i]; Ringtone* info = m_lRingtone[i];
if (info->path().path() == rt) if (info->path() == rt)
return i; return i;
} }
return -1; return 0;
} }
QItemSelectionModel* RingtoneModel::selectionModel(Account* a) const QItemSelectionModel* RingtoneModel::selectionModel(Account* a) const
...@@ -189,7 +187,7 @@ QItemSelectionModel* RingtoneModel::selectionModel(Account* a) const ...@@ -189,7 +187,7 @@ QItemSelectionModel* RingtoneModel::selectionModel(Account* a) const
connect(d_ptr->m_hSelectionModels[a],&QItemSelectionModel::currentChanged, [a,this](const QModelIndex& idx) { connect(d_ptr->m_hSelectionModels[a],&QItemSelectionModel::currentChanged, [a,this](const QModelIndex& idx) {
if (idx.isValid()) { if (idx.isValid()) {
a->setRingtonePath(d_ptr->m_lRingtone[idx.row()]->path().path()); a->setRingtonePath(d_ptr->m_lRingtone[idx.row()]->path());
} }
}); });
...@@ -207,7 +205,7 @@ void RingtoneModel::play(const QModelIndex& idx) ...@@ -207,7 +205,7 @@ void RingtoneModel::play(const QModelIndex& idx)
return; return;
} }
CallManagerInterface& callManager = CallManager::instance(); CallManagerInterface& callManager = CallManager::instance();
Q_NOREPLY callManager.startRecordedFilePlayback(info->path().path()); Q_NOREPLY callManager.startRecordedFilePlayback(info->path());
if (!d_ptr->m_pTimer) { if (!d_ptr->m_pTimer) {
d_ptr->m_pTimer = new QTimer(this); d_ptr->m_pTimer = new QTimer(this);
d_ptr->m_pTimer->setInterval(10000); d_ptr->m_pTimer->setInterval(10000);
...@@ -227,7 +225,7 @@ void RingtoneModelPrivate::slotStopTimer() ...@@ -227,7 +225,7 @@ void RingtoneModelPrivate::slotStopTimer()
{ {
if (m_pCurrent) { if (m_pCurrent) {
CallManagerInterface& callManager = CallManager::instance(); CallManagerInterface& callManager = CallManager::instance();
callManager.stopRecordedFilePlayback(m_pCurrent->path().path()); callManager.stopRecordedFilePlayback(m_pCurrent->path());
m_pCurrent->setIsPlaying(false); m_pCurrent->setIsPlaying(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));
...@@ -248,12 +246,12 @@ bool RingtoneModel::addItemCallback(const Ringtone* item) ...@@ -248,12 +246,12 @@ bool RingtoneModel::addItemCallback(const Ringtone* item)
d_ptr->m_lRingtone << const_cast<Ringtone*>(item); d_ptr->m_lRingtone << const_cast<Ringtone*>(item);
endInsertRows(); endInsertRows();
if (Account* a = d_ptr->m_hPendingSelection[item]) { if (auto a = d_ptr->m_hPendingSelection[item]) {
if (auto sm = d_ptr->m_hSelectionModels[a]) if (auto sm = d_ptr->m_hSelectionModels[a])
sm->setCurrentIndex(index(rowCount()-1,0), QItemSelectionModel::ClearAndSelect); sm->setCurrentIndex(index(rowCount()-1,0), QItemSelectionModel::ClearAndSelect);
else else
a->setRingtonePath(item->path().path()); a->setRingtonePath(item->path());
d_ptr->m_hPendingSelection[item] = nullptr; d_ptr->m_hPendingSelection[item] = nullptr;
} }
...@@ -270,8 +268,8 @@ bool RingtoneModel::removeItemCallback(const Ringtone* item) ...@@ -270,8 +268,8 @@ bool RingtoneModel::removeItemCallback(const Ringtone* item)
bool RingtoneModel::add(const QUrl& path, Account* autoSelect) bool RingtoneModel::add(const QUrl& path, Account* autoSelect)
{ {
auto r = new Ringtone(this); auto r = new Ringtone(this);
r->setPath(path); r->setPath(path.toLocalFile());
r->setName(QFile(path.path()).fileName()); r->setName(QFile(path.toLocalFile()).fileName());
if (autoSelect) if (autoSelect)
d_ptr->m_hPendingSelection[r] = autoSelect; d_ptr->m_hPendingSelection[r] = autoSelect;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment