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
|
#include <QSqlTableModel>
#include "widget/wwidget.h"
#include "widget/wskincolor.h"
#include "widget/wanalysislibrarytableview.h"
#include "library/trackcollection.h"
#include "library/dlganalysis.h"
#include "util/assert.h"
DlgAnalysis::DlgAnalysis(QWidget* parent,
UserSettingsPointer pConfig,
TrackCollection* pTrackCollection)
: QWidget(parent),
m_pConfig(pConfig),
m_pTrackCollection(pTrackCollection),
m_bAnalysisActive(false),
m_tracksInQueue(0),
m_currentTrack(0) {
setupUi(this);
m_songsButtonGroup.addButton(radioButtonRecentlyAdded);
m_songsButtonGroup.addButton(radioButtonAllSongs);
m_pAnalysisLibraryTableView = new WAnalysisLibraryTableView(this, pConfig, pTrackCollection);
connect(m_pAnalysisLibraryTableView, SIGNAL(loadTrack(TrackPointer)),
this, SIGNAL(loadTrack(TrackPointer)));
connect(m_pAnalysisLibraryTableView, SIGNAL(loadTrackToPlayer(TrackPointer, QString)),
this, SIGNAL(loadTrackToPlayer(TrackPointer, QString)));
connect(m_pAnalysisLibraryTableView, SIGNAL(trackSelected(TrackPointer)),
this, SIGNAL(trackSelected(TrackPointer)));
QBoxLayout* box = dynamic_cast<QBoxLayout*>(layout());
DEBUG_ASSERT_AND_HANDLE(box) { // Assumes the form layout is a QVBox/QHBoxLayout!
} else {
box->removeWidget(m_pTrackTablePlaceholder);
m_pTrackTablePlaceholder->hide();
box->insertWidget(1, m_pAnalysisLibraryTableView);
}
m_pAnalysisLibraryTableModel = new AnalysisLibraryTableModel(this, pTrackCollection);
m_pAnalysisLibraryTableView->loadTrackModel(m_pAnalysisLibraryTableModel);
connect(radioButtonRecentlyAdded, SIGNAL(clicked()),
this, SLOT(showRecentSongs()));
connect(radioButtonAllSongs, SIGNAL(clicked()),
this, SLOT(showAllSongs()));
// TODO(rryan): This triggers a library search before the UI has even
// started up. Accounts for 0.2% of skin creation time. Get rid of this!
radioButtonRecentlyAdded->click();
labelProgress->setText("");
pushButtonAnalyze->setEnabled(false);
connect(pushButtonAnalyze, SIGNAL(clicked()),
this, SLOT(analyze()));
connect(pushButtonSelectAll, SIGNAL(clicked()),
this, SLOT(selectAll()));
connect(m_pAnalysisLibraryTableView->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection&)),
this,
SLOT(tableSelectionChanged(const QItemSelection &, const QItemSelection&)));
}
DlgAnalysis::~DlgAnalysis() {
}
void DlgAnalysis::onShow() {
// Refresh table
// There might be new tracks dropped to other views
m_pAnalysisLibraryTableModel->select();
}
bool DlgAnalysis::hasFocus() const {
return QWidget::hasFocus();
}
void DlgAnalysis::onSearch(const QString& text) {
m_pAnalysisLibraryTableModel->search(text);
}
void DlgAnalysis::loadSelectedTrack() {
m_pAnalysisLibraryTableView->loadSelectedTrack();
}
void DlgAnalysis::loadSelectedTrackToGroup(QString group, bool play) {
m_pAnalysisLibraryTableView->loadSelectedTrackToGroup(group, play);
}
void DlgAnalysis::slotSendToAutoDJ() {
// append to auto DJ
m_pAnalysisLibraryTableView->slotSendToAutoDJ();
}
void DlgAnalysis::slotSendToAutoDJTop() {
m_pAnalysisLibraryTableView->slotSendToAutoDJTop();
}
void DlgAnalysis::moveSelection(int delta) {
m_pAnalysisLibraryTableView->moveSelection(delta);
}
void DlgAnalysis::tableSelectionChanged(const QItemSelection& selected,
const QItemSelection& deselected) {
Q_UNUSED(selected);
Q_UNUSED(deselected);
bool tracksSelected = m_pAnalysisLibraryTableView->selectionModel()->hasSelection();
pushButtonAnalyze->setEnabled(tracksSelected || m_bAnalysisActive);
}
void DlgAnalysis::selectAll() {
m_pAnalysisLibraryTableView->selectAll();
}
void DlgAnalysis::analyze() {
//qDebug() << this << "analyze()";
if (m_bAnalysisActive) {
emit(stopAnalysis());
} else {
QList<TrackId> trackIds;
QModelIndexList selectedIndexes = m_pAnalysisLibraryTableView->selectionModel()->selectedRows();
foreach(QModelIndex selectedIndex, selectedIndexes) {
TrackId trackId(selectedIndex.sibling(
selectedIndex.row(),
m_pAnalysisLibraryTableModel->fieldIndex(LIBRARYTABLE_ID)).data());
if (trackId.isValid()) {
trackIds.append(trackId);
}
}
m_currentTrack = 1;
emit(analyzeTracks(trackIds));
}
}
void DlgAnalysis::analysisActive(bool bActive) {
qDebug() << this << "analysisActive" << bActive;
m_bAnalysisActive = bActive;
if (bActive) {
pushButtonAnalyze->setEnabled(true);
pushButtonAnalyze->setText(tr("Stop Analysis"));
labelProgress->setEnabled(true);
} else {
pushButtonAnalyze->setText(tr("Analyze"));
labelProgress->setText("");
labelProgress->setEnabled(false);
}
}
// slot
void DlgAnalysis::trackAnalysisFinished(int size) {
qDebug() << "Analysis finished" << size << "tracks left";
if (size > 0) {
m_currentTrack = m_tracksInQueue - size + 1;
}
}
// slot
void DlgAnalysis::trackAnalysisProgress(int progress) {
if (m_bAnalysisActive) {
QString text = tr("Analyzing %1/%2 %3%").arg(
QString::number(m_currentTrack),
QString::number(m_tracksInQueue),
QString::number(progress));
labelProgress->setText(text);
}
}
int DlgAnalysis::getNumTracks() {
return m_tracksInQueue;
}
void DlgAnalysis::trackAnalysisStarted(int size) {
m_tracksInQueue = size;
}
void DlgAnalysis::showRecentSongs() {
m_pAnalysisLibraryTableModel->showRecentSongs();
}
void DlgAnalysis::showAllSongs() {
m_pAnalysisLibraryTableModel->showAllSongs();
}
void DlgAnalysis::installEventFilter(QObject* pFilter) {
QWidget::installEventFilter(pFilter);
m_pAnalysisLibraryTableView->installEventFilter(pFilter);
}
|