Skip to content
Snippets Groups Projects
Commit bf8750e2 authored by Emmanuel Lepage Vallée's avatar Emmanuel Lepage Vallée Committed by gerrit2
Browse files

ringtone: Implement missing bits

When porting all objects to the Collection system, the RingtoneModel
gained the ability to keep a global list of RingTones, add folders
and so on. However, this was never finished due to time constraints.

This commit complete the basic features. It is now good enough to be
used by the clients.

Tuleap: #204
Change-Id: I36a14b811b36646aa62f87aeccdbab130f416f43
parent 4e2280a2
No related branches found
No related tags found
No related merge requests found
......@@ -265,11 +265,13 @@ void Serializable::RingtoneNode::read(const QJsonObject &json)
{
ringtone = new Ringtone();
ringtone->setPath(json["path"].toString());
ringtone->setName(json["name"].toString());
}
void Serializable::RingtoneNode::write(QJsonObject& json)
{
json["path"] = ringtone->path().path();
json["name"] = ringtone->name();
}
#include <localringtonecollection.moc>
......@@ -44,6 +44,8 @@ public:
Ringtone* m_pCurrent ;
QHash<Account*,int> m_hCurrent ;
QHash<Account*,QItemSelectionModel*> m_hSelectionModels ;
LocalRingtoneCollection* m_pCollection ;
QHash<const Ringtone*,Account*> m_hPendingSelection;
//Helpers
int currentIndex(Account* a) const;
......@@ -71,7 +73,7 @@ RingtoneModel::RingtoneModel(QObject* parent)
{
// ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance();
addCollection<LocalRingtoneCollection>();
d_ptr->m_pCollection = addCollection<LocalRingtoneCollection>();
}
RingtoneModel& RingtoneModel::instance()
......@@ -139,7 +141,7 @@ int RingtoneModel::columnCount( const QModelIndex& parent ) const
{
if (parent.isValid())
return 0;
return 2; //Name, then an empty one for widgets
return 1;
}
Qt::ItemFlags RingtoneModel::flags( const QModelIndex& index ) const
......@@ -245,6 +247,17 @@ bool RingtoneModel::addItemCallback(const Ringtone* item)
beginInsertRows(QModelIndex(),d_ptr->m_lRingtone.size(),d_ptr->m_lRingtone.size());
d_ptr->m_lRingtone << const_cast<Ringtone*>(item);
endInsertRows();
if (Account* a = d_ptr->m_hPendingSelection[item]) {
if (auto sm = d_ptr->m_hSelectionModels[a])
sm->setCurrentIndex(index(rowCount()-1,0), QItemSelectionModel::ClearAndSelect);
else
a->setRingtonePath(item->path().path());
d_ptr->m_hPendingSelection[item] = nullptr;
}
return true;
}
......@@ -254,4 +267,21 @@ bool RingtoneModel::removeItemCallback(const Ringtone* item)
return true;
}
bool RingtoneModel::add(const QUrl& path, Account* autoSelect)
{
auto r = new Ringtone(this);
r->setPath(path);
r->setName(QFile(path.path()).fileName());
if (autoSelect)
d_ptr->m_hPendingSelection[r] = autoSelect;
d_ptr->m_pCollection->add(r);
//TODO check the file type
//TODO avoid duplicates
return true;
}
#include <ringtonemodel.moc>
......@@ -57,6 +57,7 @@ public:
//Mutator
void play(const QModelIndex& index);
bool add(const QUrl& path, Account* autoSelect = nullptr);
static RingtoneModel& instance();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment