File: devicesmodel.h

package info (click to toggle)
cantata 3.4.0.ds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,428 kB
  • sloc: cpp: 109,584; perl: 1,366; xml: 722; python: 139; lex: 110; sh: 105; yacc: 78; makefile: 8
file content (136 lines) | stat: -rw-r--r-- 4,882 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Cantata
 *
 * Copyright (c) 2011-2022 Craig Drummond <craig.p.drummond@gmail.com>
 *
 * ----
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
#ifndef DEVICES_MODEL_H
#define DEVICES_MODEL_H

#include "config.h"
#include "devices/cdalbum.h"
#include "devices/remotefsdevice.h"
#include "mpd-interface/song.h"
#include "musiclibrarymodel.h"
#include "musiclibraryproxymodel.h"
#include <QSet>

class QMimeData;
class Device;
class MirrorMenu;

class DevicesModel : public MusicLibraryModel {
	Q_OBJECT

public:
	static DevicesModel* self();

	static void enableDebug();
	static bool debugEnabled();
	static QString fixDevicePath(const QString& path);

	DevicesModel(QObject* parent = nullptr);
	~DevicesModel() override;
	QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
	QModelIndex parent(const QModelIndex& index) const override;
	QVariant headerData(int, Qt::Orientation, int = Qt::DisplayRole) const override { return QVariant(); }
	int columnCount(const QModelIndex& = QModelIndex()) const override { return 1; }
	int rowCount(const QModelIndex& parent = QModelIndex()) const override;
	void getDetails(QSet<QString>& artists, QSet<QString>& albumArtists, QSet<QString>& composers, QSet<QString>& albums, QSet<QString>& genres);
	QList<Song> songs(const QModelIndexList& indexes, bool playableOnly = false, bool fullPath = false) const;
	QStringList filenames(const QModelIndexList& indexes, bool playableOnly = false, bool fullPath = false) const;
	int row(void* i) const override { return collections.indexOf(static_cast<MusicLibraryItemRoot*>(i)); }
	bool setData(const QModelIndex& index, const QVariant& value, int role) override;
	QVariant data(const QModelIndex&, int) const override;
	Qt::ItemFlags flags(const QModelIndex& index) const override;
	QStringList playableUrls(const QModelIndexList& indexes) const;
	void clear(bool clearConfig = true);
	MirrorMenu* menu() { return itemMenu; }
	Device* device(const QString& udi);
	bool isEnabled() const { return enabled; }
	void setEnabled(bool e);
	void stop();
	QMimeData* mimeData(const QModelIndexList& indexes) const override;
#ifdef ENABLE_REMOTE_DEVICES
	void unmountRemote();
#endif

	Action* configureAct() const { return configureAction; }
	Action* refreshAct() const { return refreshAction; }
	Action* connectAct() const { return connectAction; }
	Action* disconnectAct() const { return disconnectAction; }
#if defined CDDB_FOUND || defined MusicBrainz5_FOUND
	Action* editAct() const { return editAction; }
	void playCd(const QString& dev);
#endif

private:
	int indexOf(const QString& id);

public Q_SLOTS:
	void setCover(const Song& song, const QImage& img, const QString& file);
	void setCover(const Song& song, const QImage& img);
	void deviceAdded(const QString& udi);
	void deviceRemoved(const QString& udi);
	void accessibilityChanged(bool accessible, const QString& udi);
	void deviceUpdating(const QString& udi, bool state);
	void emitAddToDevice();
	void addRemoteDevice(const DeviceOptions& opts, RemoteFsDevice::Details details);
	void removeRemoteDevice(const QString& udi, bool removeFromConfig = true);
	void remoteDeviceUdiChanged();
	void mountsChanged();

private:
	void addLocalDevice(const QString& udi);
#ifdef ENABLE_REMOTE_DEVICES
	void loadRemote();
#endif

Q_SIGNALS:
	void addToDevice(const QString& udi);
	void error(const QString& text);
	void updated(const QModelIndex& idx);
	void matches(const QString& udi, const QList<CdAlbum>& albums);
	void invalid(const QList<Song>& songs);
	void updatedDetails(const QList<Song>& songs);
	void add(const QStringList& files, int action, quint8 priority, bool decreasePriority);// add songs to MPD playqueue

private Q_SLOTS:
	void play(const QList<Song>& songs);
	void loadLocal();
	void updateItemMenu();

private:
	QList<MusicLibraryItemRoot*> collections;
	QSet<QString> volumes;
	MirrorMenu* itemMenu;
	bool enabled;
	bool inhibitMenuUpdate;
	Action* configureAction;
	Action* refreshAction;
	Action* connectAction;
	Action* disconnectAction;
#if defined CDDB_FOUND || defined MusicBrainz5_FOUND
	QString autoplayCd;
	Action* editAction;
#endif
	friend class Device;
};

#endif