qt: medialib: define a super-type for list items
[vlc.git] / modules / gui / qt / medialibrary / mlqmltypes.hpp
blobcc4f75e4e00d08c5ef5f78be8f4760611ea5d523
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 *****************************************************************************/
19 #ifndef MLQMLTYPES_HPP
20 #define MLQMLTYPES_HPP
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
26 #include <QObject>
27 #include <vlc_common.h>
28 #include <vlc_media_library.h>
30 class MLItemId
32 Q_GADGET
33 public:
34 MLItemId() : id(0), type( VLC_ML_PARENT_UNKNOWN ) {}
35 MLItemId( int64_t i, vlc_ml_parent_type t ) : id( i ), type( t ) {}
36 bool operator==( const MLItemId& other )
38 return id == other.id && type == other.type;
40 bool operator!=( const MLItemId& other )
42 return !(*this == other);
44 int64_t id;
45 vlc_ml_parent_type type;
47 Q_INVOKABLE inline QString toString() const {
49 #define ML_PARENT_TYPE_CASE(type) case type: return QString("%1 - %2").arg(#type).arg(id)
50 switch (type) {
51 ML_PARENT_TYPE_CASE(VLC_ML_PARENT_ALBUM);
52 ML_PARENT_TYPE_CASE(VLC_ML_PARENT_ARTIST);
53 ML_PARENT_TYPE_CASE(VLC_ML_PARENT_SHOW);
54 ML_PARENT_TYPE_CASE(VLC_ML_PARENT_GENRE);
55 ML_PARENT_TYPE_CASE(VLC_ML_PARENT_PLAYLIST);
56 default:
57 return QString("UNKNONW - %2").arg(id);
59 #undef ML_PARENT_TYPE_CASE
63 Q_DECLARE_METATYPE(MLItemId)
65 class MLItem
67 public:
68 MLItem(MLItemId id) : m_id(id) {}
69 virtual ~MLItem() = default;
71 MLItemId getId() const { return m_id; };
73 private:
74 MLItemId m_id;
77 #endif // MLQMLTYPES_HPP