Skip to content

Commit

Permalink
Provides a fix for the issue reported in bug 1199945. The progess of …
Browse files Browse the repository at this point in the history
…the analyser queue is now visible from anywhere, via a change in the title from 'Analyze' to 'Analyze (x / y)' where x is the number of tracks that have been analyzed so far and y is the total number of tracks originally in the queue. This is an alternative to the progess bar images created by jus, as it allows for more detail.
  • Loading branch information
radkoff committed Jun 9, 2014
1 parent 0eb6e90 commit 6f982a2
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/dlganalysis.cpp
Expand Up @@ -147,6 +147,10 @@ void DlgAnalysis::trackAnalysisProgress(int progress) {
}
}

int DlgAnalysis::getNumTracks() {
return m_tracksInQueue;
}

void DlgAnalysis::trackAnalysisStarted(int size) {
m_tracksInQueue = size;
}
Expand Down
1 change: 1 addition & 0 deletions src/dlganalysis.h
Expand Up @@ -27,6 +27,7 @@ class DlgAnalysis : public QWidget, public Ui::DlgAnalysis, public virtual Libra
inline const QString currentSearch() {
return m_pAnalysisLibraryTableModel->currentSearch();
}
int getNumTracks();

public slots:
void tableSelectionChanged(const QItemSelection& selected,
Expand Down
33 changes: 32 additions & 1 deletion src/library/analysisfeature.cpp
Expand Up @@ -13,6 +13,7 @@
#include "analyserqueue.h"
#include "soundsourceproxy.h"
#include "util/dnd.h"
#include "util/debug.h"

const QString AnalysisFeature::m_sAnalysisViewName = QString("Analysis");

Expand All @@ -25,6 +26,7 @@ AnalysisFeature::AnalysisFeature(QObject* parent,
m_pAnalyserQueue(NULL),
m_iOldBpmEnabled(0),
m_pAnalysisView(NULL) {
setTitleDefault();
}

AnalysisFeature::~AnalysisFeature() {
Expand All @@ -33,8 +35,27 @@ AnalysisFeature::~AnalysisFeature() {
cleanupAnalyser();
}

// Sets the title of this feature to the default name, given by m_sAnalysisTitleName
void AnalysisFeature::setTitleDefault() {
m_Title = tr(m_sAnalysisTitleName);
emit(featureIsLoading(this, false)); // Signals a change in title
}

// Sets the title of this feature to the default name followed by (x / y)
// where x is the current track being analyzed and y is the total number of tracks in the job
void AnalysisFeature::setTitleProgress(int trackNum, int totalNum) {
QString title = tr(m_sAnalysisTitleName);
title.append(" (");
title.append(QString::number(trackNum));
title.append(" / ");
title.append(QString::number(totalNum));
title.append(")");
m_Title = title;
emit(featureIsLoading(this, false)); // Signals a change in title
}

QVariant AnalysisFeature::title() {
return tr("Analyze");
return m_Title;
}

QIcon AnalysisFeature::getIcon() {
Expand Down Expand Up @@ -99,6 +120,8 @@ void AnalysisFeature::analyzeTracks(QList<int> trackIds) {

connect(m_pAnalyserQueue, SIGNAL(trackProgress(int)),
m_pAnalysisView, SLOT(trackAnalysisProgress(int)));
connect(m_pAnalyserQueue, SIGNAL(trackFinished(int)),
this, SLOT(slotProgressUpdate(int)));
connect(m_pAnalyserQueue, SIGNAL(trackFinished(int)),
m_pAnalysisView, SLOT(trackAnalysisFinished(int)));

Expand All @@ -114,9 +137,16 @@ void AnalysisFeature::analyzeTracks(QList<int> trackIds) {
m_pAnalyserQueue->queueAnalyseTrack(pTrack);
}
}
if(trackIds.size() > 0)
setTitleProgress(0, trackIds.size());
emit(trackAnalysisStarted(trackIds.size()));
}

void AnalysisFeature::slotProgressUpdate(int num_left) {
int num_tracks = m_pAnalysisView->getNumTracks();
setTitleProgress(num_tracks - num_left, num_tracks);
}

void AnalysisFeature::stopAnalysis() {
//qDebug() << this << "stopAnalysis()";
if (m_pAnalyserQueue != NULL) {
Expand All @@ -125,6 +155,7 @@ void AnalysisFeature::stopAnalysis() {
}

void AnalysisFeature::cleanupAnalyser() {
setTitleDefault();
emit(analysisActive(false));
if (m_pAnalyserQueue != NULL) {
m_pAnalyserQueue->stop();
Expand Down
7 changes: 7 additions & 0 deletions src/library/analysisfeature.h
Expand Up @@ -48,17 +48,24 @@ class AnalysisFeature : public LibraryFeature {
void analyzeTracks(QList<int> trackIds);

private slots:
void slotProgressUpdate(int num_left);
void stopAnalysis();
void cleanupAnalyser();

private:
void setTitleDefault(); // Set title to tr("Analyze")
void setTitleProgress(int trackNum, int totalNum); // Set title to "Analyze (x out of y)"

ConfigObject<ConfigValue>* m_pConfig;
TrackCollection* m_pTrackCollection;
AnalyserQueue* m_pAnalyserQueue;
// Used to temporarily enable BPM detection in the prefs before we analyse
int m_iOldBpmEnabled;
// The title returned by title()
QVariant m_Title;
TreeItemModel m_childModel;
const static QString m_sAnalysisViewName;
const char * m_sAnalysisTitleName = "Analyze";
DlgAnalysis* m_pAnalysisView;
};

Expand Down
2 changes: 1 addition & 1 deletion src/library/itunes/itunesfeature.cpp
Expand Up @@ -169,7 +169,7 @@ void ITunesFeature::activate(bool forceReload) {
m_future_watcher.setFuture(m_future);
m_title = tr("(loading) iTunes");
// calls a slot in the sidebar model such that 'iTunes (isLoading)' is displayed.
emit (featureIsLoading(this));
emit (featureIsLoading(this, true));
}

emit(showTrackModel(m_pITunesTrackModel));
Expand Down
3 changes: 2 additions & 1 deletion src/library/libraryfeature.h
Expand Up @@ -86,7 +86,8 @@ class LibraryFeature : public QObject {
void loadTrackToPlayer(TrackPointer pTrack, QString group, bool play = false);
void restoreSearch(const QString&);
// emit this signal before you parse a large music collection, e.g., iTunes, Traktor.
void featureIsLoading(LibraryFeature*);
// The second arg indicates if the feature should be "selected" when loading starts
void featureIsLoading(LibraryFeature*, bool selectFeature);
// emit this signal if the foreign music collection has been imported/parsed.
void featureLoadingFinished(LibraryFeature*s);
// emit this signal to select pFeature
Expand Down
2 changes: 1 addition & 1 deletion src/library/rhythmbox/rhythmboxfeature.cpp
Expand Up @@ -117,7 +117,7 @@ void RhythmboxFeature::activate() {
m_track_watcher.setFuture(m_track_future);
m_title = "(loading) Rhythmbox";
//calls a slot in the sidebar model such that 'Rhythmbox (isLoading)' is displayed.
emit (featureIsLoading(this));
emit (featureIsLoading(this, true));
}

emit(showTrackModel(m_pRhythmboxTrackModel));
Expand Down
14 changes: 7 additions & 7 deletions src/library/sidebarmodel.cpp
Expand Up @@ -18,8 +18,8 @@ SidebarModel::~SidebarModel() {

void SidebarModel::addLibraryFeature(LibraryFeature* feature) {
m_sFeatures.push_back(feature);
connect(feature, SIGNAL(featureIsLoading(LibraryFeature*)),
this, SLOT(slotFeatureIsLoading(LibraryFeature*)));
connect(feature, SIGNAL(featureIsLoading(LibraryFeature*, bool)),
this, SLOT(slotFeatureIsLoading(LibraryFeature*, bool)));
connect(feature, SIGNAL(featureLoadingFinished(LibraryFeature*)),
this, SLOT(slotFeatureLoadingFinished(LibraryFeature*)));
connect(feature, SIGNAL(featureSelect(LibraryFeature*, const QModelIndex&)),
Expand Down Expand Up @@ -375,13 +375,13 @@ void SidebarModel::slotModelReset() {

/*
* Call this slot whenever the title of the feature has changed.
* See RhythmboxFeature for an example.
* While the rhythmbox music collection is parsed
* the title becomes '(loading) Rhythmbox'
* See RhythmboxFeature for an example, in which the title becomes '(loading) Rhythmbox'
* If selectFeature is true, the feature is selected when the title change occurs.
*/
void SidebarModel::slotFeatureIsLoading(LibraryFeature * feature) {
void SidebarModel::slotFeatureIsLoading(LibraryFeature * feature, bool selectFeature) {
featureRenamed(feature);
slotFeatureSelect(feature);
if(selectFeature)
slotFeatureSelect(feature);
}

/* Tobias: This slot is somewhat redundant but I decided
Expand Down
2 changes: 1 addition & 1 deletion src/library/sidebarmodel.h
Expand Up @@ -56,7 +56,7 @@ class SidebarModel : public QAbstractItemModel {
void slotRowsInserted(const QModelIndex& parent, int start, int end);
void slotRowsRemoved(const QModelIndex& parent, int start, int end);
void slotModelReset();
void slotFeatureIsLoading(LibraryFeature*);
void slotFeatureIsLoading(LibraryFeature*, bool selectFeature);
void slotFeatureLoadingFinished(LibraryFeature*);

signals:
Expand Down
2 changes: 1 addition & 1 deletion src/library/traktor/traktorfeature.cpp
Expand Up @@ -146,7 +146,7 @@ void TraktorFeature::activate() {
m_future_watcher.setFuture(m_future);
m_title = tr("(loading) Traktor");
//calls a slot in the sidebar model such that 'iTunes (isLoading)' is displayed.
emit (featureIsLoading(this));
emit (featureIsLoading(this, true));
}

emit(showTrackModel(m_pTraktorTableModel));
Expand Down

0 comments on commit 6f982a2

Please sign in to comment.