strawberry-audio-player-win.../src/device/deviceview.h

129 lines
3.2 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018, 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 DEVICEVIEW_H
#define DEVICEVIEW_H
#include "config.h"
#include <memory>
#include <QObject>
#include <QStyleOption>
#include <QStyleOptionViewItem>
#include <QAbstractItemModel>
2020-02-09 02:29:35 +01:00
#include <QString>
2018-02-27 18:06:05 +01:00
#include "core/song.h"
#include "collection/collectionitemdelegate.h"
2018-02-27 18:06:05 +01:00
#include "widgets/autoexpandingtreeview.h"
2020-02-09 02:29:35 +01:00
class QSortFilterProxyModel;
class QPainter;
class QWidget;
class QMenu;
class QAction;
class QMouseEvent;
class QContextMenuEvent;
2018-02-27 18:06:05 +01:00
class Application;
class DeviceProperties;
class MergedProxyModel;
class OrganiseDialog;
2018-02-27 18:06:05 +01:00
class DeviceItemDelegate : public CollectionItemDelegate {
2018-09-14 23:05:58 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
2020-04-07 16:49:15 +02:00
explicit DeviceItemDelegate(QObject *parent);
2018-02-27 18:06:05 +01:00
static const int kIconPadding;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
2018-09-14 23:05:58 +02:00
2018-02-27 18:06:05 +01:00
};
class DeviceView : public AutoExpandingTreeView {
Q_OBJECT
public:
2020-04-07 16:49:15 +02:00
explicit DeviceView(QWidget *parent = nullptr);
2018-02-27 18:06:05 +01:00
~DeviceView();
void SetApplication(Application *app);
protected:
void contextMenuEvent(QContextMenuEvent*);
void mouseDoubleClickEvent(QMouseEvent *event);
private slots:
// Device menu actions
void Connect();
void Unmount();
void Forget();
void Properties();
// Collection menu actions
void Load();
void AddToPlaylist();
void OpenInNewPlaylist();
void Organise();
void Delete();
void DeviceConnected(QModelIndex idx);
void DeviceDisconnected(QModelIndex idx);
2018-02-27 18:06:05 +01:00
void DeleteFinished(const SongList &songs_with_errors);
// AutoExpandingTreeView
bool CanRecursivelyExpand(const QModelIndex &idx) const;
2018-02-27 18:06:05 +01:00
private:
QModelIndex MapToDevice(const QModelIndex &merged_model_index) const;
QModelIndex MapToCollection(const QModelIndex &merged_model_index) const;
QModelIndex FindParentDevice(const QModelIndex &merged_model_index) const;
SongList GetSelectedSongs() const;
private:
Application *app_;
MergedProxyModel *merged_model_;
QSortFilterProxyModel *sort_model_;
std::unique_ptr<DeviceProperties> properties_dialog_;
std::unique_ptr<OrganiseDialog> organise_dialog_;
QMenu *device_menu_;
QAction *eject_action_;
QAction *forget_action_;
QAction *properties_action_;
QMenu *collection_menu_;
QAction *load_action_;
QAction *add_to_playlist_action_;
QAction *open_in_new_playlist_;
QAction *organise_action_;
QAction *delete_action_;
QModelIndex menu_index_;
};
#endif // DEVICEVIEW_H