I have made the following changes intended for : CE:MW:Shared / nemo-qml-plugin-grilo
Please review and accept or decline. BOSS has already run some checks on this request. See the "Messages from BOSS" section below. https://build.pub.meego.com//request/show/7669 Thank You, msameer [This message was auto-generated] --- Request # 7669: Messages from BOSS: State: review at 2013-01-14T13:44:07 by bossbot Reviews: accepted by bossbot : Prechecks succeeded. new for CE-maintainers : Please replace this text with a review and approve/reject the review (not the SR). BOSS will take care of the rest Changes: submit: home:msameer:grilo / nemo-qml-plugin-grilo -> CE:MW:Shared / nemo-qml-plugin-grilo changes files: -------------- --- nemo-qml-plugin-grilo.changes +++ nemo-qml-plugin-grilo.changes @@ -0,0 +1,5 @@ +* Mon Jan 14 2013 Mohammed Hassan <[email protected]> - 0.0.20130114 +- Added GriloDataSource::finished() signal +- Added GriloModel::count property +- Added GriloModel::get() invokable method + old: ---- qtgrilo-0.0.20121207.tar.gz new: ---- qtgrilo-0.0.20130114.tar.gz spec files: ----------- --- nemo-qml-plugin-grilo.spec +++ nemo-qml-plugin-grilo.spec @@ -1,6 +1,6 @@ Name: nemo-qml-plugin-grilo Summary: Framework for discovering and browsing media -Version: 0.0.20121207 +Version: 0.0.20130114 Release: 1 Group: Development/Libraries License: LGPLv2.1 other changes: -------------- ++++++ qtgrilo-0.0.20121207.tar.gz -> qtgrilo-0.0.20130114.tar.gz --- declarative/grilodatasource.cpp +++ declarative/grilodatasource.cpp @@ -42,8 +42,8 @@ } GriloDataSource::~GriloDataSource() { - m_models.clear(); cancelRefresh(); + m_models.clear(); } const QList<GriloMedia *> *GriloDataSource::media() const { @@ -69,19 +69,58 @@ model->beginInsertRows(QModelIndex(), 0, m_media.size() - 1); model->endInsertRows(); + + emit model->countChanged(); } -void GriloDataSource::addMedia(GriloMedia *media) { +void GriloDataSource::addMedia(GrlMedia *media) { + GriloMedia *wrappedMedia = new GriloMedia(media); int size = m_media.size(); foreach (GriloModel *model, m_models) { model->beginInsertRows(QModelIndex(), size, size); } - m_media << media; + m_media << wrappedMedia; + + QString id = wrappedMedia->id(); + if (!id.isEmpty()) { + m_hash.insert(id, wrappedMedia); + } foreach (GriloModel *model, m_models) { model->endInsertRows(); + emit model->countChanged(); + } +} + +void GriloDataSource::removeMedia(GrlMedia *media) { + QString id = GriloMedia(media).id(); + + if (id.isEmpty() || !m_hash.contains(id)) { + // We really cannot do much. + return; + } + + GriloMedia *wrapper = m_hash[id]; + int index = m_media.indexOf(wrapper); + + // remove from models: + foreach (GriloModel *model, m_models) { + model->beginRemoveRows(QModelIndex(), index, index); + } + + // remove from hash + m_hash.take(id); + + // remove from list + m_media.takeAt(index); + + // destroy + wrapper->deleteLater(); + + foreach (GriloModel *model, m_models) { + model->endRemoveRows(); } } @@ -94,9 +133,11 @@ qDeleteAll(m_media); m_media.clear(); + m_hash.clear(); foreach (GriloModel *model, m_models) { model->endRemoveRows(); + emit model->countChanged(); } } @@ -239,10 +280,11 @@ } if (media) { - that->addMedia(new GriloMedia(media)); + that->addMedia(media); } if (remaining == 0) { + emit that->finished(); that->m_opId = 0; } } --- declarative/grilodatasource.h +++ declarative/grilodatasource.h @@ -2,7 +2,7 @@ /*! * - * Copyright (C) 2012 Jolla Ltd. + * Copyright (C) 2012-2013 Jolla Ltd. * * Contact: Mohammed Hassan <[email protected]> * @@ -135,6 +135,7 @@ void skipChanged(); void metadataKeysChanged(); void typeFilterChanged(); + void finished(); protected: enum OperationType { @@ -146,7 +147,9 @@ GrlMedia *media, guint remaining, gpointer user_data, const GError *error); - void addMedia(GriloMedia *media); + void addMedia(GrlMedia *media); + void removeMedia(GrlMedia *media); + void clearMedia(); GrlOperationOptions *operationOptions(GrlSource *src, const OperationType& type); @@ -166,6 +169,7 @@ private: QList<GriloMedia *> m_media; QList<GriloModel *> m_models; + QHash<QString, GriloMedia *> m_hash; }; #endif /* GRILO_DATA_SOURCE_H */ --- declarative/grilomodel.cpp +++ declarative/grilomodel.cpp @@ -1,6 +1,6 @@ /*! * - * Copyright (C) 2012 Jolla Ltd. + * Copyright (C) 2012-2013 Jolla Ltd. * * Contact: Mohammed Hassan <[email protected]> * @@ -50,11 +50,9 @@ return QVariant(); } - const GriloMedia *media = m_source->media()->at(index.row()); - switch (role) { case MediaRole: - return QVariant::fromValue((QObject *)media); + return QVariant::fromValue(get(index.row())); } return QVariant(); @@ -89,3 +87,15 @@ m_source->prefill(this); } } + +QObject *GriloModel::get(int index) const { + if (index < 0 || index >= rowCount()) { + return 0; + } + + return m_source->media()->at(index); +} + +int GriloModel::count() const { + return rowCount(); +} --- declarative/grilomodel.h +++ declarative/grilomodel.h @@ -2,7 +2,7 @@ /*! * - * Copyright (C) 2012 Jolla Ltd. + * Copyright (C) 2012-2013 Jolla Ltd. * * Contact: Mohammed Hassan <[email protected]> * @@ -33,6 +33,7 @@ Q_OBJECT Q_PROPERTY(GriloDataSource* source READ source WRITE setSource NOTIFY sourceChanged); + Q_PROPERTY(int count READ count NOTIFY countChanged); friend class GriloDataSource; @@ -50,8 +51,13 @@ GriloDataSource *source() const; void setSource(GriloDataSource *source); + Q_INVOKABLE QObject *get(int index) const; + + int count() const; + signals: void sourceChanged(); + void countChanged(); private: GriloDataSource *m_source; --- declarative/griloquery.cpp +++ declarative/griloquery.cpp @@ -130,7 +130,7 @@ if (!m_available && m_opId) { // A source has disappeared while an operation is already running. - // Most grilo will crash soon but we will just reset the opId + // Not sure how will grilo behave but we will just reset the opId m_opId = 0; } }
