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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
// library.cpp
// Created 8/23/2009 by RJ Ryan (rryan@mit.edu)
#include <QItemSelectionModel>
#include <QMessageBox>
#include <QTranslator>
#include <QDir>
#include "database/mixxxdb.h"
#include "mixer/playermanager.h"
#include "library/library.h"
#include "library/library_preferences.h"
#include "library/libraryfeature.h"
#include "library/librarytablemodel.h"
#include "library/sidebarmodel.h"
#include "library/trackcollection.h"
#include "library/trackmodel.h"
#include "library/browse/browsefeature.h"
#include "library/crate/cratefeature.h"
#include "library/rhythmbox/rhythmboxfeature.h"
#include "library/banshee/bansheefeature.h"
#include "library/recording/recordingfeature.h"
#include "library/itunes/itunesfeature.h"
#include "library/mixxxlibraryfeature.h"
#include "library/autodj/autodjfeature.h"
#include "library/playlistfeature.h"
#include "library/traktor/traktorfeature.h"
#include "library/librarycontrol.h"
#include "library/setlogfeature.h"
#include "util/db/dbconnectionpooled.h"
#include "util/sandbox.h"
#include "util/logger.h"
#include "util/assert.h"
#include "widget/wtracktableview.h"
#include "widget/wlibrary.h"
#include "widget/wlibrarysidebar.h"
#include "controllers/keyboard/keyboardeventfilter.h"
namespace {
const mixxx::Logger kLogger("Library");
} // anonymous namespace
//static
const QString Library::kConfigGroup("[Library]");
//static
const ConfigKey Library::kConfigKeyRepairDatabaseOnNextRestart(kConfigGroup, "RepairDatabaseOnNextRestart");
// This is the name which we use to register the WTrackTableView with the
// WLibrary
const QString Library::m_sTrackViewName = QString("WTrackTableView");
// The default row height of the library.
const int Library::kDefaultRowHeightPx = 20;
Library::Library(
QObject* parent,
UserSettingsPointer pConfig,
mixxx::DbConnectionPoolPtr pDbConnectionPool,
PlayerManager* pPlayerManager,
RecordingManager* pRecordingManager)
: m_pConfig(pConfig),
m_pDbConnectionPool(pDbConnectionPool),
m_pSidebarModel(new SidebarModel(parent)),
m_pTrackCollection(new TrackCollection(pConfig)),
m_pLibraryControl(new LibraryControl(this)),
m_pMixxxLibraryFeature(nullptr),
m_pPlaylistFeature(nullptr),
m_pCrateFeature(nullptr),
m_pAnalysisFeature(nullptr),
m_scanner(pDbConnectionPool, m_pTrackCollection, pConfig) {
QSqlDatabase dbConnection = mixxx::DbConnectionPooled(m_pDbConnectionPool);
// TODO(XXX): Add a checkbox in the library preferences for checking
// and repairing the database on the next restart of the application.
if (pConfig->getValue(kConfigKeyRepairDatabaseOnNextRestart, false)) {
kLogger.info() << "Checking and repairing database (if necessary)";
m_pTrackCollection->repairDatabase(dbConnection);
// Reset config value
pConfig->setValue(kConfigKeyRepairDatabaseOnNextRestart, false);
}
kLogger.info() << "Connecting database";
m_pTrackCollection->connectDatabase(dbConnection);
qRegisterMetaType<Library::RemovalType>("Library::RemovalType");
m_pKeyNotation.reset(new ControlObject(ConfigKey(kConfigGroup, "key_notation")));
connect(&m_scanner, SIGNAL(scanStarted()),
this, SIGNAL(scanStarted()));
connect(&m_scanner, SIGNAL(scanFinished()),
this, SIGNAL(scanFinished()));
// Refresh the library models when the library (re)scan is finished.
connect(&m_scanner, SIGNAL(scanFinished()),
this, SLOT(slotRefreshLibraryModels()));
// TODO(rryan) -- turn this construction / adding of features into a static
// method or something -- CreateDefaultLibrary
m_pMixxxLibraryFeature = new MixxxLibraryFeature(this, m_pTrackCollection,m_pConfig);
addFeature(m_pMixxxLibraryFeature);
addFeature(new AutoDJFeature(this, pConfig, pPlayerManager, m_pTrackCollection));
m_pPlaylistFeature = new PlaylistFeature(this, m_pTrackCollection, m_pConfig);
addFeature(m_pPlaylistFeature);
m_pCrateFeature = new CrateFeature(this, m_pTrackCollection, m_pConfig);
addFeature(m_pCrateFeature);
BrowseFeature* browseFeature = new BrowseFeature(
this, pConfig, m_pTrackCollection, pRecordingManager);
connect(browseFeature, SIGNAL(scanLibrary()),
&m_scanner, SLOT(scan()));
connect(&m_scanner, SIGNAL(scanStarted()),
browseFeature, SLOT(slotLibraryScanStarted()));
connect(&m_scanner, SIGNAL(scanFinished()),
browseFeature, SLOT(slotLibraryScanFinished()));
addFeature(browseFeature);
addFeature(new RecordingFeature(this, pConfig, m_pTrackCollection, pRecordingManager));
addFeature(new SetlogFeature(this, pConfig, m_pTrackCollection));
m_pAnalysisFeature = new AnalysisFeature(this, pConfig);
connect(m_pPlaylistFeature, SIGNAL(analyzeTracks(QList<TrackId>)),
m_pAnalysisFeature, SLOT(analyzeTracks(QList<TrackId>)));
connect(m_pCrateFeature, SIGNAL(analyzeTracks(QList<TrackId>)),
m_pAnalysisFeature, SLOT(analyzeTracks(QList<TrackId>)));
addFeature(m_pAnalysisFeature);
// Suspend a batch analysis while an ad-hoc analysis of
// loaded tracks is in progress and resume it afterwards.
connect(pPlayerManager, SIGNAL(trackAnalyzerProgress(TrackId, AnalyzerProgress)),
m_pAnalysisFeature, SLOT(suspendAnalysis()));
connect(pPlayerManager, SIGNAL(trackAnalyzerIdle()),
m_pAnalysisFeature, SLOT(resumeAnalysis()));
//iTunes and Rhythmbox should be last until we no longer have an obnoxious
//messagebox popup when you select them. (This forces you to reach for your
//mouse or keyboard if you're using MIDI control and you scroll through them...)
if (RhythmboxFeature::isSupported() &&
pConfig->getValue(ConfigKey(kConfigGroup,"ShowRhythmboxLibrary"), true)) {
addFeature(new RhythmboxFeature(this, m_pTrackCollection));
}
if (pConfig->getValue(ConfigKey(kConfigGroup,"ShowBansheeLibrary"), true)) {
BansheeFeature::prepareDbPath(pConfig);
if (BansheeFeature::isSupported()) {
addFeature(new BansheeFeature(this, m_pTrackCollection, pConfig));
}
}
if (ITunesFeature::isSupported() &&
pConfig->getValue(ConfigKey(kConfigGroup,"ShowITunesLibrary"), true)) {
addFeature(new ITunesFeature(this, m_pTrackCollection));
}
if (TraktorFeature::isSupported() &&
pConfig->getValue(ConfigKey(kConfigGroup,"ShowTraktorLibrary"), true)) {
addFeature(new TraktorFeature(this, m_pTrackCollection));
}
// On startup we need to check if all of the user's library folders are
// accessible to us. If the user is using a database from <1.12.0 with
// sandboxing then we will need them to give us permission.
QStringList directories = m_pTrackCollection->getDirectoryDAO().getDirs();
qDebug() << "Checking for access to user's library directories:";
foreach (QString directoryPath, directories) {
QFileInfo directory(directoryPath);
bool hasAccess = Sandbox::askForAccess(directory.canonicalFilePath());
qDebug() << "Checking for access to" << directoryPath << ":" << hasAccess;
}
m_iTrackTableRowHeight = m_pConfig->getValue(
ConfigKey(kConfigGroup, "RowHeight"), kDefaultRowHeightPx);
QString fontStr = m_pConfig->getValueString(ConfigKey(kConfigGroup, "Font"));
if (!fontStr.isEmpty()) {
m_trackTableFont.fromString(fontStr);
} else {
m_trackTableFont = QApplication::font();
}
m_editMetadataSelectedClick = m_pConfig->getValue(
ConfigKey(kConfigGroup, "EditMetadataSelectedClick"),
PREF_LIBRARY_EDIT_METADATA_DEFAULT);
}
Library::~Library() {
// Delete the sidebar model first since it depends on the LibraryFeatures.
delete m_pSidebarModel;
QMutableListIterator<LibraryFeature*> features_it(m_features);
while(features_it.hasNext()) {
LibraryFeature* feature = features_it.next();
features_it.remove();
delete feature;
}
delete m_pLibraryControl;
kLogger.info() << "Disconnecting database";
m_pTrackCollection->disconnectDatabase();
//IMPORTANT: m_pTrackCollection gets destroyed via the QObject hierarchy somehow.
// Qt does it for us due to the way RJ wrote all this stuff.
//Update: - OR NOT! As of Dec 8, 2009, this pointer must be destroyed manually otherwise
// we never see the TrackCollection's destructor being called... - Albert
// Has to be deleted at last because the features holds references of it.
delete m_pTrackCollection;
}
void Library::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
m_pLibraryControl->bindSidebarWidget(pSidebarWidget);
// Setup the sources view
pSidebarWidget->setModel(m_pSidebarModel);
connect(m_pSidebarModel, SIGNAL(selectIndex(const QModelIndex&)),
pSidebarWidget, SLOT(selectIndex(const QModelIndex&)));
connect(pSidebarWidget, SIGNAL(pressed(const QModelIndex&)),
m_pSidebarModel, SLOT(pressed(const QModelIndex&)));
connect(pSidebarWidget, SIGNAL(clicked(const
|