Search your playlist – Plasma-Mediacenter

Till last week or 2 I was surfing through calligra code base. Shantanu asked me share my love for Plasma-mediacenter and hence it bubbled up with this post. I wanted this post as a Christmas gift to PMC(Plasma-mediacenter) users. But then due to my laziness and some foo factors it delayed.

PMC has support for playlist. Lets see how I added the search option for playlist. I wrote a model to filter the search in the playlist, named FilterPlaylistModel. FilterPlaylistModel inherits the QSortFilterProxyModel. And the key method of FilterPlaylistModel is filterAcceptRow. filterAcceptRow method will help us to filter out the rows which didn’t matched with string in the search box. Playlist.qml uses playlistModel which is already in use. I wanted to add my FilterPlaylistModel to Playlist.qml. This was accomplished by adding a Q_PROPERTY in FilterPlaylistModel. Created a sourcePlaylistModel of type QObject. Added the read, write and notify options. I registered the FilterPlaylistModel in mainwindow.cpp. Now here is the tricky part, which took me some time to understand. Updated the model of Playlist.qml to:

model: MediaCenterComponents.FilterPlaylistModel {
 sourcePlaylistModel : playlistModel
filterString: filterText.text 
}

This will allow ListView to use model playlistModel and for playlist filtering FilterPlaylistModel. And then set the text. Thanks, to shantanu for clearing my queries on time 🙂 So PMC users have their cake ready. Test it and shoot bugs. We are here to fix it. Below is the screenshot.

Search in playlist

Leave a comment

Your comment