qt: playlist: use item title if available
[vlc.git] / modules / gui / qt / playlist / playlist_item.cpp
blob18ba080d3c7c46f927193e31ee089b6df4a4534b
1 /*****************************************************************************
2 * Copyright (C) 2019 VLC authors and VideoLAN
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * ( at your option ) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17 *****************************************************************************/
18 #include "playlist_item.hpp"
20 //namespace vlc {
21 //namespace playlist {
23 PlaylistItem::PlaylistItem(vlc_playlist_item_t* item)
25 d = new Data();
26 if (item)
28 d->item.reset(item);
29 sync();
33 bool PlaylistItem::isSelected() const
35 return d->selected;
38 void PlaylistItem::setSelected(bool selected)
40 d->selected = selected;
43 QString PlaylistItem::getTitle() const
45 return d->title;
48 QString PlaylistItem::getArtist() const
50 return d->artist;
53 QString PlaylistItem::getAlbum() const
55 return d->album;
58 QUrl PlaylistItem::getArtwork() const
60 return d->artwork;
63 vlc_tick_t PlaylistItem::getDuration() const
65 return d->duration;
68 QUrl PlaylistItem::getUrl() const
70 return d->url;
73 void PlaylistItem::sync() {
74 input_item_t *media = vlc_playlist_item_GetMedia(d->item.get());
75 vlc_mutex_lock(&media->lock);
76 d->duration = media->i_duration;
77 d->url = media->psz_uri;
79 if (media->p_meta) {
80 d->title = vlc_meta_Get(media->p_meta, vlc_meta_Title);
81 d->artist = vlc_meta_Get(media->p_meta, vlc_meta_Artist);
82 d->album = vlc_meta_Get(media->p_meta, vlc_meta_Album);
83 d->artwork = vlc_meta_Get(media->p_meta, vlc_meta_ArtworkURL);
86 if (d->title.isNull())
87 /* If there is no title, use the item name */
88 d->title = media->psz_name;
90 vlc_mutex_unlock(&media->lock);
93 PlaylistItem::operator bool() const
95 return d && d->item.get();
99 //}