1 #pragma once
2 
3 #include <QAbstractItemModel>
4 #include <QFont>
5 #include <QList>
6 #include <QObject>
7 #include <QPointer>
8 
9 #include "analyzer/analyzerprogress.h"
10 #include "preferences/usersettings.h"
11 #include "track/track_decl.h"
12 #include "track/trackid.h"
13 #include "util/db/dbconnectionpool.h"
14 #include "util/parented_ptr.h"
15 
16 class AnalysisFeature;
17 class ControlObject;
18 class CrateFeature;
19 class ExternalTrackCollection;
20 class LibraryControl;
21 class LibraryFeature;
22 class LibraryTableModel;
23 class KeyboardEventFilter;
24 class MixxxLibraryFeature;
25 class PlayerManager;
26 class PlaylistFeature;
27 class RecordingManager;
28 class SidebarModel;
29 class TrackCollection;
30 class TrackCollectionManager;
31 class TrackModel;
32 class WSearchLineEdit;
33 class WLibrarySidebar;
34 class WLibrary;
35 
36 // A Library class is a container for all the model-side aspects of the library.
37 // A library widget can be attached to the Library object by calling bindLibraryWidget.
38 class Library: public QObject {
39     Q_OBJECT
40 
41   public:
42     static const QString kConfigGroup;
43 
44     Library(QObject* parent,
45             UserSettingsPointer pConfig,
46             mixxx::DbConnectionPoolPtr pDbConnectionPool,
47             TrackCollectionManager* pTrackCollectionManager,
48             PlayerManager* pPlayerManager,
49             RecordingManager* pRecordingManager);
50     ~Library() override;
51 
52     void stopPendingTasks();
53 
dbConnectionPool()54     const mixxx::DbConnectionPoolPtr& dbConnectionPool() const {
55         return m_pDbConnectionPool;
56     }
57 
58     TrackCollectionManager* trackCollections() const;
59 
60     // Deprecated: Obtain directly from TrackCollectionManager
61     TrackCollection& trackCollection();
62 
63     void bindSearchboxWidget(WSearchLineEdit* pSearchboxWidget);
64     void bindSidebarWidget(WLibrarySidebar* sidebarWidget);
65     void bindLibraryWidget(WLibrary* libraryWidget,
66                     KeyboardEventFilter* pKeyboard);
67 
68     void addFeature(LibraryFeature* feature);
69     QStringList getDirs();
70 
getTrackTableRowHeight()71     int getTrackTableRowHeight() const {
72         return m_iTrackTableRowHeight;
73     }
74 
getTrackTableFont()75     const QFont& getTrackTableFont() const {
76         return m_trackTableFont;
77     }
78 
79     //static Library* buildDefaultLibrary();
80 
81     enum class RemovalType {
82         KeepTracks,
83         HideTracks,
84         PurgeTracks
85     };
86 
87     static const int kDefaultRowHeightPx;
88 
89     void setFont(const QFont& font);
90     void setRowHeight(int rowHeight);
91     void setEditMedatataSelectedClick(bool enable);
92 
93   public slots:
94     void slotShowTrackModel(QAbstractItemModel* model);
95     void slotSwitchToView(const QString& view);
96     void slotLoadTrack(TrackPointer pTrack);
97     void slotLoadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play);
98     void slotLoadLocationToPlayer(const QString& location, const QString& group);
99     void slotRefreshLibraryModels();
100     void slotCreatePlaylist();
101     void slotCreateCrate();
102     void slotRequestAddDir(const QString& directory);
103     void slotRequestRemoveDir(const QString& directory, Library::RemovalType removalType);
104     void slotRequestRelocateDir(const QString& previousDirectory, const QString& newDirectory);
105     void onSkinLoadFinished();
106 
107   signals:
108     void showTrackModel(QAbstractItemModel* model);
109     void switchToView(const QString& view);
110     void loadTrack(TrackPointer pTrack);
111     void loadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play = false);
112     void restoreSearch(const QString&);
113     void search(const QString& text);
114     void disableSearch();
115     // emit this signal to enable/disable the cover art widget
116     void enableCoverArtDisplay(bool);
117     void trackSelected(TrackPointer pTrack);
118 
119     void setTrackTableFont(const QFont& font);
120     void setTrackTableRowHeight(int rowHeight);
121     void setSelectedClick(bool enable);
122 
123   private slots:
124       void onPlayerManagerTrackAnalyzerProgress(TrackId trackId, AnalyzerProgress analyzerProgress);
125       void onPlayerManagerTrackAnalyzerIdle();
126 
127   private:
128     const UserSettingsPointer m_pConfig;
129 
130     // The Mixxx database connection pool
131     const mixxx::DbConnectionPoolPtr m_pDbConnectionPool;
132 
133     const QPointer<TrackCollectionManager> m_pTrackCollectionManager;
134 
135     parented_ptr<SidebarModel> m_pSidebarModel;
136     parented_ptr<LibraryControl> m_pLibraryControl;
137 
138     QList<LibraryFeature*> m_features;
139     const static QString m_sTrackViewName;
140     const static QString m_sAutoDJViewName;
141     MixxxLibraryFeature* m_pMixxxLibraryFeature;
142     PlaylistFeature* m_pPlaylistFeature;
143     CrateFeature* m_pCrateFeature;
144     AnalysisFeature* m_pAnalysisFeature;
145     QFont m_trackTableFont;
146     int m_iTrackTableRowHeight;
147     bool m_editMetadataSelectedClick;
148     QScopedPointer<ControlObject> m_pKeyNotation;
149 };
150