blob: 6e4af6cab5233cb98e1d5a1bc8e0a9915d1b5589 (
plain)
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
|
#include "library/missingtablemodel.h"
#include "library/dao/trackschema.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "moc_missingtablemodel.cpp"
namespace {
const QString kMissingFilter = "mixxx_deleted=0 AND fs_deleted=1";
} // anonymous namespace
MissingTableModel::MissingTableModel(QObject* parent,
TrackCollectionManager* pTrackCollectionManager)
: BaseSqlTableModel(parent, pTrackCollectionManager,
"mixxx.db.model.missing") {
setTableModel();
}
void MissingTableModel::setTableModel(int id) {
Q_UNUSED(id);
QSqlQuery query(m_database);
//query.prepare("DROP VIEW " + playlistTableName);
//query.exec();
QString tableName("missing_songs");
QStringList columns;
columns << "library." + LIBRARYTABLE_ID;
query.prepare("CREATE TEMPORARY VIEW IF NOT EXISTS " + tableName + " AS "
"SELECT "
+ columns.join(",") +
" FROM library "
"INNER JOIN track_locations "
"ON library.location=track_locations.id "
"WHERE " + kMissingFilter);
if (!query.exec()) {
qDebug() << query.executedQuery() << query.lastError();
}
//Print out any SQL error, if there was one.
if (query.lastError().isValid()) {
qDebug() << __FILE__ << __LINE__ << query.lastError();
}
QStringList tableColumns;
tableColumns << LIBRARYTABLE_ID;
setTable(tableName, LIBRARYTABLE_ID, tableColumns,
m_pTrackCollectionManager->internalCollection()->getTrackSource());
setDefaultSort(fieldIndex("artist"), Qt::AscendingOrder);
setSearch("");
}
MissingTableModel::~MissingTableModel() {
}
void MissingTableModel::purgeTracks(const QModelIndexList& indices) {
m_pTrackCollectionManager->purgeTracks(getTrackRefs(indices));
// TODO(rryan) : do not select, instead route event to BTC and notify from
// there.
select(); //Repopulate the data model.
}
bool MissingTableModel::isColumnInternal(int column) {
if (column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_ID) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PLAYED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_BPM_LOCK) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_KEY_ID)||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_MIXXXDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_TRACKLOCATIONSTABLE_FSDELETED) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_SOURCE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_TYPE) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_LOCATION) ||
column == fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART_HASH)) {
return true;
}
return false;
}
// Override flags from BaseSqlModel since we don't want edit this model
Qt::ItemFlags MissingTableModel::flags(const QModelIndex &index) const {
return readOnlyFlags(index);
}
TrackModel::CapabilitiesFlags MissingTableModel::getCapabilities() const {
return TRACKMODELCAPS_NONE | TRACKMODELCAPS_PURGE;
}
|