2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLAYLISTLISTMODEL_H
|
|
|
|
#define PLAYLISTLISTMODEL_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QObject>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QStandardItemModel>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QMap>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QString>
|
|
|
|
|
2020-02-08 15:03:11 +01:00
|
|
|
class QMimeData;
|
2018-05-01 00:41:33 +02:00
|
|
|
class QModelIndex;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
class PlaylistListModel : public QStandardItemModel {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit PlaylistListModel(QObject *parent = nullptr);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
enum Types {
|
|
|
|
Type_Folder,
|
|
|
|
Type_Playlist
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Roles {
|
|
|
|
Role_Type = Qt::UserRole,
|
|
|
|
Role_PlaylistId
|
|
|
|
};
|
|
|
|
|
2020-06-15 21:55:05 +02:00
|
|
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// These icons will be used for newly created playlists and folders.
|
|
|
|
// The caller will need to set these icons on existing items if there are any.
|
|
|
|
void SetIcons(const QIcon &playlist_icon, const QIcon &folder_icon);
|
|
|
|
const QIcon &playlist_icon() const { return playlist_icon_; }
|
|
|
|
const QIcon &folder_icon() const { return folder_icon_; }
|
|
|
|
|
|
|
|
// Walks from the given item to the root, returning the / separated path of
|
|
|
|
// all the parent folders. The path includes this item if it is a folder.
|
2021-07-11 09:49:38 +02:00
|
|
|
static QString ItemPath(const QStandardItem *item);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Finds the playlist with the given ID, returns 0 if it doesn't exist.
|
2021-01-26 16:48:04 +01:00
|
|
|
QStandardItem *PlaylistById(const int id) const;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Finds the folder with the given path, creating it (and its parents) if they
|
|
|
|
// do not exist. Returns invisibleRootItem() if path is empty.
|
|
|
|
QStandardItem *FolderByPath(const QString &path);
|
|
|
|
|
|
|
|
// Returns a new folder item with the given name. The item isn't added to
|
|
|
|
// the model yet.
|
|
|
|
QStandardItem *NewFolder(const QString &name) const;
|
|
|
|
|
|
|
|
// Returns a new playlist item with the given name and ID. The item isn't
|
|
|
|
// added to the model yet.
|
2021-01-26 16:48:04 +01:00
|
|
|
QStandardItem *NewPlaylist(const QString &name, const int id) const;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// QStandardItemModel
|
2021-01-26 16:48:04 +01:00
|
|
|
bool setData(const QModelIndex &idx, const QVariant &value, int role) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
signals:
|
|
|
|
void PlaylistPathChanged(int id, QString new_path);
|
|
|
|
void PlaylistRenamed(int id, QString new_name);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void RowsChanged(const QModelIndex &begin, const QModelIndex &end);
|
2021-01-26 16:48:04 +01:00
|
|
|
void RowsAboutToBeRemoved(const QModelIndex &parent, const int start, const int end);
|
|
|
|
void RowsInserted(const QModelIndex &parent, const int start, const int end);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void AddRowMappings(const QModelIndex &begin, const QModelIndex &end);
|
|
|
|
void AddRowItem(QStandardItem *item, const QString &parent_path);
|
|
|
|
void UpdatePathsRecursive(const QModelIndex &parent);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool dropping_rows_;
|
|
|
|
|
|
|
|
QIcon playlist_icon_;
|
|
|
|
QIcon folder_icon_;
|
|
|
|
|
|
|
|
QMap<int, QStandardItem*> playlists_by_id_;
|
|
|
|
QMap<QString, QStandardItem*> folders_by_path_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYLISTLISTMODEL_H
|