qt: notify dataChanged when a thumbnail is updated from the medialibrary
[vlc.git] / modules / gui / qt / medialibrary / mlalbum.cpp
blob2c4a1e9bb8ee2be1012425e38552843ccdead09b
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 <cassert>
19 #include "mlalbum.hpp"
21 MLAlbum::MLAlbum(vlc_medialibrary_t* _ml, const vlc_ml_album_t *_data, QObject *_parent)
22 : QObject( _parent )
23 , m_ml ( _ml )
24 , m_id ( _data->i_id, VLC_ML_PARENT_ALBUM )
25 , m_title ( QString::fromUtf8( _data->psz_title ) )
26 , m_releaseYear ( _data->i_year )
27 , m_shortSummary( QString::fromUtf8( _data->psz_summary ) )
28 , m_cover ( QString::fromUtf8( _data->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl ) )
29 , m_mainArtist ( QString::fromUtf8( _data->psz_artist ) )
30 , m_nbTracks ( _data->i_nb_tracks )
32 assert( _data );
33 assert( _ml );
35 int t_sec = _data->i_duration / 1000;
36 int sec = t_sec % 60;
37 int min = (t_sec / 60) % 60;
38 int hour = t_sec / 3600;
39 if (hour == 0)
40 m_duration = QString("%1:%2")
41 .arg(min, 2, 10, QChar('0'))
42 .arg(sec, 2, 10, QChar('0'));
43 else
44 m_duration = QString("%1:%2:%3")
45 .arg(hour, 2, 10, QChar('0'))
46 .arg(min, 2, 10, QChar('0'))
47 .arg(sec, 2, 10, QChar('0'));
50 //private ctor for cloning
51 MLAlbum::MLAlbum(const MLAlbum& _album, QObject *_parent)
52 : QObject( _parent )
53 , m_ml ( _album.m_ml )
54 , m_id ( _album.m_id )
55 , m_title ( _album.m_title )
56 , m_releaseYear ( _album.m_releaseYear )
57 , m_shortSummary( _album.m_shortSummary )
58 , m_cover ( _album.m_cover )
59 , m_mainArtist ( _album.m_mainArtist )
60 , m_nbTracks ( _album.m_nbTracks )
61 , m_duration ( _album.m_duration )
65 MLParentId MLAlbum::getId() const
67 return m_id;
70 QString MLAlbum::getTitle() const
72 return m_title;
75 unsigned int MLAlbum::getReleaseYear() const
77 return m_releaseYear;
80 QString MLAlbum::getShortSummary() const
82 return m_shortSummary;
85 QString MLAlbum::getCover() const
87 return m_cover;
91 QString MLAlbum::getArtist() const
93 return m_mainArtist;
96 unsigned int MLAlbum::getNbTracks() const
98 return m_nbTracks;
101 QString MLAlbum::getDuration() const
103 return m_duration;
106 MLAlbum *MLAlbum::clone(QObject *parent) const
108 return new MLAlbum(*this, parent);
111 QString MLAlbum::getPresName() const
113 return m_title;
116 QString MLAlbum::getPresImage() const
118 return m_cover;
121 QString MLAlbum::getPresInfo() const
123 return m_shortSummary;