File indexing completed on 2024-05-12 05:39:51

0001 /***************************************************************************
0002  *  Copyright (C) 2014 by Renaud Guezennec                                 *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #ifndef MUSICMODEL_H
0021 #define MUSICMODEL_H
0022 
0023 #include <QAbstractListModel>
0024 #include <QUrl>
0025 #include <core_global.h>
0026 
0027 /**
0028  * @brief The MusicModel class is the model which stores the playlist. Each audioWidget has one instance of this class.
0029  */
0030 class  CORE_EXPORT MusicModel : public QAbstractListModel
0031 {
0032     Q_OBJECT
0033 public:
0034     enum CustomRole
0035     {
0036         TITLE= Qt::UserRole + 1,
0037         URL,
0038     };
0039     Q_ENUM(CustomRole)
0040     explicit MusicModel(QObject* parent= nullptr);
0041     QUrl getMediaByModelIndex(const QModelIndex&) const;
0042 
0043     virtual int rowCount(const QModelIndex& parent= QModelIndex()) const override;
0044     virtual QVariant data(const QModelIndex& index, int role= Qt::DisplayRole) const override;
0045     virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0046     Qt::ItemFlags flags(const QModelIndex& index) const override;
0047 
0048     void addSong(const QList<QUrl>& urls);
0049     void insertSong(int i, QUrl str);
0050     void removeAll();
0051     void removeSong(const QModelIndexList& list);
0052     void setCurrentSong(const QModelIndex& p);
0053     QStringList mimeTypes() const override;
0054 
0055     int indexOfCurrent() const;
0056 
0057     const QList<QUrl>& urls() const;
0058 
0059 protected:
0060     Qt::DropActions supportedDropActions() const override;
0061     bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
0062                       const QModelIndex& index) override;
0063 
0064 private:
0065     QStringList m_header;
0066     QList<QUrl> m_data;
0067     QUrl m_currentSong;
0068 };
0069 
0070 #endif // MUSICMODEL_H