Sayonara Player
CustomMimeData.h
1 /* CustomMimeData.h */
2 
3 /* Copyright 2011-2019 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef _CUSTOMMIMEDATA_H
22 #define _CUSTOMMIMEDATA_H
23 
24 #include "Utils/Pimpl.h"
25 
26 #include <QMimeData>
27 
32 class CustomMimeData : public QMimeData
33 {
34 
35 private:
36  PIMPL(CustomMimeData)
37 
38  CustomMimeData(const void* p);
39  const void* ptr() const;
40 
41 public:
46  template<typename T>
47  CustomMimeData(const T* class_instance) :
48  CustomMimeData(static_cast<const void*>(class_instance))
49  {}
50 
51  virtual ~CustomMimeData();
52 
57  void set_metadata(const MetaDataList& v_md);
58 
64  const MetaDataList& metadata() const;
65 
70  bool has_metadata() const;
71 
72  void set_playlist_source_index(int playlist_idx);
73  int playlist_source_index() const;
74 
75  QString cover_url() const;
76  void set_cover_url(const QString& url);
77 
78  template<typename T>
79  bool has_source(const T* class_instance) const
80  {
81  const void* void_ptr = ptr();
82  const T* p = static_cast<const T*>(void_ptr);
83  if(!p){
84  return false;
85  }
86 
87  return (p == class_instance);
88  }
89 };
90 
91 #endif
const MetaDataList & metadata() const
get metadata from drag and drop
The MetaDataList class.
Definition: MetaDataList.h:37
void set_metadata(const MetaDataList &v_md)
Set metadata you want to drag and drop.
CustomMimeData(const T *class_instance)
Constructor.
Definition: CustomMimeData.h:47
Mimedata class for drag and dropping metadata.
Definition: CustomMimeData.h:32
bool has_metadata() const
check, if the custom mimedata has metadata