1 /* This file is part of Clementine.
2    Copyright 2010, David Sansome <me@davidsansome.com>
3 
4    Clementine is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8 
9    Clementine is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef DEVICEVIEW_H
19 #define DEVICEVIEW_H
20 
21 #include <memory>
22 
23 #include "core/song.h"
24 #include "library/libraryview.h"
25 #include "widgets/autoexpandingtreeview.h"
26 
27 class QAction;
28 class QMenu;
29 class QSortFilterProxyModel;
30 
31 class Application;
32 class DeviceManager;
33 class DeviceProperties;
34 class LibraryModel;
35 class MergedProxyModel;
36 
37 class DeviceItemDelegate : public LibraryItemDelegate {
38  public:
39   DeviceItemDelegate(QObject* parent);
40 
41   static const int kIconPadding;
42 
43   void paint(QPainter* painter, const QStyleOptionViewItem& option,
44              const QModelIndex& index) const;
45 };
46 
47 class DeviceView : public AutoExpandingTreeView {
48   Q_OBJECT
49 
50  public:
51   DeviceView(QWidget* parent = nullptr);
52   ~DeviceView();
53 
54   void SetApplication(Application* app);
55 
56  protected:
57   void contextMenuEvent(QContextMenuEvent*);
58   void mouseDoubleClickEvent(QMouseEvent* event);
59 
60  private slots:
61   // Device menu actions
62   void Connect();
63   void Unmount();
64   void Forget();
65   void Properties();
66 
67   // Library menu actions
68   void Load();
69   void AddToPlaylist();
70   void OpenInNewPlaylist();
71   void Organise();
72   void Delete();
73 
74   void DeviceConnected(QModelIndex idx);
75   void DeviceDisconnected(QModelIndex idx);
76 
77   void DeleteFinished(const SongList& songs_with_errors);
78 
79   // AutoExpandingTreeView
80   bool CanRecursivelyExpand(const QModelIndex& index) const;
81 
82  private:
83   QModelIndex MapToDevice(const QModelIndex& merged_model_index) const;
84   QModelIndex MapToLibrary(const QModelIndex& merged_model_index) const;
85   QModelIndex FindParentDevice(const QModelIndex& merged_model_index) const;
86   SongList GetSelectedSongs() const;
87 
88  private:
89   Application* app_;
90   MergedProxyModel* merged_model_;
91   QSortFilterProxyModel* sort_model_;
92 
93   std::unique_ptr<DeviceProperties> properties_dialog_;
94   std::unique_ptr<OrganiseDialog> organise_dialog_;
95 
96   QMenu* device_menu_;
97   QAction* eject_action_;
98   QAction* forget_action_;
99   QAction* properties_action_;
100 
101   QMenu* library_menu_;
102   QAction* load_action_;
103   QAction* add_to_playlist_action_;
104   QAction* open_in_new_playlist_;
105   QAction* organise_action_;
106   QAction* delete_action_;
107 
108   QModelIndex menu_index_;
109 };
110 
111 #endif  // DEVICEVIEW_H
112