1 /* 2 * Strawberry Music Player 3 * This file was part of Clementine. 4 * Copyright 2010, David Sansome <me@davidsansome.com> 5 * Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net> 6 * 7 * Strawberry 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 * Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 #ifndef DEVICEVIEW_H 23 #define DEVICEVIEW_H 24 25 #include "config.h" 26 27 #include <memory> 28 29 #include <QObject> 30 #include <QStyleOption> 31 #include <QStyleOptionViewItem> 32 #include <QAbstractItemModel> 33 #include <QString> 34 35 #include "core/song.h" 36 #include "collection/collectionitemdelegate.h" 37 #include "widgets/autoexpandingtreeview.h" 38 39 class QSortFilterProxyModel; 40 class QPainter; 41 class QWidget; 42 class QMenu; 43 class QAction; 44 class QMouseEvent; 45 class QContextMenuEvent; 46 47 class Application; 48 class DeviceProperties; 49 class MergedProxyModel; 50 class OrganizeDialog; 51 52 class DeviceItemDelegate : public CollectionItemDelegate { 53 Q_OBJECT 54 55 public: 56 explicit DeviceItemDelegate(QObject *parent); 57 58 static const int kIconPadding; 59 60 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override; 61 62 }; 63 64 class DeviceView : public AutoExpandingTreeView { 65 Q_OBJECT 66 67 public: 68 explicit DeviceView(QWidget *parent = nullptr); 69 ~DeviceView() override; 70 71 void SetApplication(Application *app); 72 73 // AutoExpandingTreeView 74 bool CanRecursivelyExpand(const QModelIndex &idx) const override; 75 76 protected: 77 void contextMenuEvent(QContextMenuEvent*) override; 78 void mouseDoubleClickEvent(QMouseEvent *e) override; 79 80 private slots: 81 // Device menu actions 82 void Connect(); 83 void Unmount(); 84 void Forget(); 85 void Properties(); 86 87 // Collection menu actions 88 void Load(); 89 void AddToPlaylist(); 90 void OpenInNewPlaylist(); 91 void Organize(); 92 void Delete(); 93 94 void DeviceConnected(const QModelIndex &idx); 95 void DeviceDisconnected(const QModelIndex &idx); 96 97 void DeleteFinished(const SongList &songs_with_errors); 98 99 private: 100 QModelIndex MapToDevice(const QModelIndex &merged_model_index) const; 101 QModelIndex MapToCollection(const QModelIndex &merged_model_index) const; 102 QModelIndex FindParentDevice(const QModelIndex &merged_model_index) const; 103 SongList GetSelectedSongs() const; 104 105 private: 106 Application *app_; 107 MergedProxyModel *merged_model_; 108 QSortFilterProxyModel *sort_model_; 109 110 std::unique_ptr<DeviceProperties> properties_dialog_; 111 std::unique_ptr<OrganizeDialog> organize_dialog_; 112 113 QMenu *device_menu_; 114 QAction *eject_action_; 115 QAction *forget_action_; 116 QAction *properties_action_; 117 118 QMenu *collection_menu_; 119 QAction *load_action_; 120 QAction *add_to_playlist_action_; 121 QAction *open_in_new_playlist_; 122 QAction *organize_action_; 123 QAction *delete_action_; 124 125 QModelIndex menu_index_; 126 }; 127 128 #endif // DEVICEVIEW_H 129