qt: medialib: define a super-type for list items
[vlc.git] / modules / gui / qt / medialibrary / mlalbum.cpp
blob6a80648b33235ed3c42f6d2f7154d883f273a193
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 , MLItem ( MLItemId( _data->i_id, VLC_ML_PARENT_ALBUM ) )
24 , m_ml ( _ml )
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)
41 m_duration = QString("%1:%2")
42 .arg(min, 2, 10, QChar('0'))
43 .arg(sec, 2, 10, QChar('0'));
44 m_durationShort = m_duration;
46 else
48 m_duration = QString("%1:%2:%3")
49 .arg(hour, 2, 10, QChar('0'))
50 .arg(min, 2, 10, QChar('0'))
51 .arg(sec, 2, 10, QChar('0'));
52 m_durationShort = QString("%1h%2")
53 .arg(hour)
54 .arg(min, 2, 10, QChar('0'));
58 //private ctor for cloning
59 MLAlbum::MLAlbum(const MLAlbum& _album, QObject *_parent)
60 : QObject( _parent )
61 , MLItem ( _album.getId() )
62 , m_ml ( _album.m_ml )
63 , m_title ( _album.m_title )
64 , m_releaseYear ( _album.m_releaseYear )
65 , m_shortSummary( _album.m_shortSummary )
66 , m_cover ( _album.m_cover )
67 , m_mainArtist ( _album.m_mainArtist )
68 , m_nbTracks ( _album.m_nbTracks )
69 , m_duration ( _album.m_duration )
73 QString MLAlbum::getTitle() const
75 return m_title;
78 unsigned int MLAlbum::getReleaseYear() const
80 return m_releaseYear;
83 QString MLAlbum::getShortSummary() const
85 return m_shortSummary;
88 QString MLAlbum::getCover() const
90 return m_cover;
94 QString MLAlbum::getArtist() const
96 return m_mainArtist;
99 unsigned int MLAlbum::getNbTracks() const
101 return m_nbTracks;
104 QString MLAlbum::getDuration() const
106 return m_duration;
109 QString MLAlbum::getDurationShort() const
111 return m_durationShort;
114 MLAlbum *MLAlbum::clone(QObject *parent) const
116 return new MLAlbum(*this, parent);
119 QString MLAlbum::getPresName() const
121 return m_title;
124 QString MLAlbum::getPresImage() const
126 return m_cover;
129 QString MLAlbum::getPresInfo() const
131 return m_shortSummary;