Skip to content

Commit

Permalink
Merge pull request #4726 from ronso0/history-cleanup-options
Browse files Browse the repository at this point in the history
add History cleanup options
  • Loading branch information
daschuer committed May 9, 2022
2 parents 34c6a95 + 2ec1ceb commit 30cc5f1
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 143 deletions.
3 changes: 2 additions & 1 deletion src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "engine/enginemaster.h"
#include "library/coverartcache.h"
#include "library/library.h"
#include "library/library_prefs.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "mixer/playerinfo.h"
Expand Down Expand Up @@ -375,7 +376,7 @@ void CoreServices::initialize(QApplication* pApp) {

// Scan the library for new files and directories
bool rescan = pConfig->getValue<bool>(
ConfigKey("[Library]", "RescanOnStartup"));
library::prefs::kRescanOnStartupConfigKey);
// rescan the library if we get a new plugin
QList<QString> prev_plugins_list =
pConfig->getValueString(
Expand Down
4 changes: 2 additions & 2 deletions src/library/dao/playlistdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void PlaylistDAO::deletePlaylist(const int playlistId) {
}
}

int PlaylistDAO::deleteAllPlaylistsWithFewerTracks(
int PlaylistDAO::deleteAllUnlockedPlaylistsWithFewerTracks(
PlaylistDAO::HiddenType type, int minNumberOfTracks) {
VERIFY_OR_DEBUG_ASSERT(minNumberOfTracks > 0) {
return 0; // nothing to do, probably unintended invocation
Expand All @@ -238,7 +238,7 @@ int PlaylistDAO::deleteAllPlaylistsWithFewerTracks(
"SELECT id FROM Playlists "
"WHERE (SELECT count(playlist_id) FROM PlaylistTracks WHERE "
"Playlists.ID = PlaylistTracks.playlist_id) < :length AND "
"Playlists.hidden = :hidden"));
"Playlists.hidden = :hidden AND Playlists.locked = 0"));
query.bindValue(":hidden", static_cast<int>(type));
query.bindValue(":length", minNumberOfTracks);
if (!query.exec()) {
Expand Down
3 changes: 2 additions & 1 deletion src/library/dao/playlistdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class PlaylistDAO : public QObject, public virtual DAO {
/// Delete Playlists with fewer entries then "length"
/// Needs to be called inside a transaction.
/// @return number of deleted playlists, -1 on error
int deleteAllPlaylistsWithFewerTracks(PlaylistDAO::HiddenType type, int minNumberOfTracks);
int deleteAllUnlockedPlaylistsWithFewerTracks(PlaylistDAO::HiddenType type,
int minNumberOfTracks);
// Rename a playlist
void renamePlaylist(const int playlistId, const QString& newName);
// Lock or unlock a playlist
Expand Down
25 changes: 25 additions & 0 deletions src/library/library_prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,36 @@ const ConfigKey mixxx::library::prefs::kLegacyDirectoryConfigKey =
const QString mixxx::library::prefs::kConfigGroup =
QStringLiteral("[Library]");

const ConfigKey mixxx::library::prefs::kRescanOnStartupConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("RescanOnStartup")};

const ConfigKey mixxx::library::prefs::kKeyNotationConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("key_notation")};

const ConfigKey mixxx::library::prefs::kTrackDoubleClickActionConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("TrackLoadAction")};

const ConfigKey mixxx::library::prefs::kEditMetadataSelectedClickConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("EditMetadataSelectedClick")};

const ConfigKey mixxx::library::prefs::kHistoryMinTracksToKeepConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("history_min_tracks_to_keep")};

const ConfigKey mixxx::library::prefs::kHistoryTrackDuplicateDistanceConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("history_track_duplicate_distance")};

const ConfigKey mixxx::library::prefs::kSearchDebouncingTimeoutMillisConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
Expand All @@ -39,3 +59,8 @@ const ConfigKey mixxx::library::prefs::kSyncSeratoMetadataConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("SeratoMetadataExport")};

const ConfigKey mixxx::library::prefs::kUseRelativePathOnExportConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("UseRelativePathOnExport")};
14 changes: 14 additions & 0 deletions src/library/library_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ extern const ConfigKey kLegacyDirectoryConfigKey;

extern const QString kConfigGroup;

extern const ConfigKey kRescanOnStartupConfigKey;

extern const ConfigKey kKeyNotationConfigKey;

extern const ConfigKey kTrackDoubleClickActionConfigKey;

extern const ConfigKey kSearchDebouncingTimeoutMillisConfigKey;

extern const ConfigKey kEditMetadataSelectedClickConfigKey;

extern const ConfigKey kHistoryMinTracksToKeepConfigKey;

const int kHistoryMinTracksToKeepDefault = 1;

extern const ConfigKey kHistoryTrackDuplicateDistanceConfigKey;

const int kHistoryTrackDuplicateDistanceDefault = 6;

const bool kEditMetadataSelectedClickDefault = false;

extern const ConfigKey kSyncTrackMetadataConfigKey;
Expand All @@ -26,6 +38,8 @@ extern const ConfigKey kSyncSeratoMetadataConfigKey;

extern const ConfigKey kSyncSeratoMetadataConfigKey;

extern const ConfigKey kUseRelativePathOnExportConfigKey;

} // namespace prefs

} // namespace library
Expand Down
5 changes: 4 additions & 1 deletion src/library/trackset/baseplaylistfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/export/trackexportwizard.h"
#include "library/library.h"
#include "library/library_prefs.h"
#include "library/parser.h"
#include "library/parsercsv.h"
#include "library/parserm3u.h"
Expand All @@ -31,6 +32,8 @@ const ConfigKey kConfigKeyLastImportExportPlaylistDirectory(

} // anonymous namespace

using namespace mixxx::library::prefs;

BasePlaylistFeature::BasePlaylistFeature(
Library* pLibrary,
UserSettingsPointer pConfig,
Expand Down Expand Up @@ -568,7 +571,7 @@ void BasePlaylistFeature::slotExportPlaylist() {

// check config if relative paths are desired
bool useRelativePath = m_pConfig->getValue<bool>(
ConfigKey("[Library]", "UseRelativePathOnExport"));
kUseRelativePathOnExportConfigKey);

if (fileLocation.endsWith(".csv", Qt::CaseInsensitive)) {
ParserCsv::writeCSVFile(fileLocation, pPlaylistTableModel.data(), useRelativePath);
Expand Down
5 changes: 4 additions & 1 deletion src/library/trackset/crate/cratefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "library/export/trackexportwizard.h"
#include "library/library.h"
#include "library/library_prefs.h"
#include "library/parser.h"
#include "library/parsercsv.h"
#include "library/parserm3u.h"
Expand Down Expand Up @@ -42,6 +43,8 @@ const ConfigKey kConfigKeyLastImportExportCrateDirectoryKey(

} // anonymous namespace

using namespace mixxx::library::prefs;

CrateFeature::CrateFeature(Library* pLibrary,
UserSettingsPointer pConfig)
: BaseTrackSetFeature(pLibrary, pConfig, "CRATEHOME", QStringLiteral("crates")),
Expand Down Expand Up @@ -739,7 +742,7 @@ void CrateFeature::slotExportPlaylist() {
// check config if relative paths are desired
bool useRelativePath =
m_pConfig->getValue<bool>(
ConfigKey("[Library]", "UseRelativePathOnExport"));
kUseRelativePathOnExportConfigKey);

// Create list of files of the crate
// Create a new table model since the main one might have an active search.
Expand Down
37 changes: 28 additions & 9 deletions src/library/trackset/setlogfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "control/controlobject.h"
#include "library/library.h"
#include "library/library_prefs.h"
#include "library/playlisttablemodel.h"
#include "library/queryutil.h"
#include "library/trackcollection.h"
Expand All @@ -23,6 +24,8 @@ namespace {
constexpr int kNumToplevelHistoryEntries = 5;
}

using namespace mixxx::library::prefs;

SetlogFeature::SetlogFeature(
Library* pLibrary,
UserSettingsPointer pConfig)
Expand All @@ -36,13 +39,11 @@ SetlogFeature::SetlogFeature(
/*keep deleted tracks*/ true),
QStringLiteral("SETLOGHOME"),
QStringLiteral("history")),
m_playlistId(kInvalidPlaylistId) {
// clear old empty entries
ScopedTransaction transaction(pLibrary->trackCollectionManager()
->internalCollection()
->database());
m_playlistDao.deleteAllPlaylistsWithFewerTracks(PlaylistDAO::HiddenType::PLHT_SET_LOG, 1);
transaction.commit();
m_playlistId(kInvalidPlaylistId),
m_pLibrary(pLibrary),
m_pConfig(pConfig) {
// remove unneeded entries
deleteAllUnlockedPlaylistsWithFewerTracks();

//construct child model
m_pSidebarModel->setRootItem(TreeItem::newRoot(this));
Expand Down Expand Up @@ -72,6 +73,8 @@ SetlogFeature::~SetlogFeature() {
m_playlistDao.tracksInPlaylist(m_playlistId) == 0) {
m_playlistDao.deletePlaylist(m_playlistId);
}
// Also clean history up when shutting down in case the track threshold changed
deleteAllUnlockedPlaylistsWithFewerTracks();
}

QVariant SetlogFeature::title() {
Expand All @@ -88,6 +91,18 @@ void SetlogFeature::bindLibraryWidget(
m_libraryWidget = QPointer(libraryWidget);
}

void SetlogFeature::deleteAllUnlockedPlaylistsWithFewerTracks() {
ScopedTransaction transaction(m_pLibrary->trackCollectionManager()
->internalCollection()
->database());
int minTrackCount = m_pConfig->getValue(
kHistoryMinTracksToKeepConfigKey,
kHistoryMinTracksToKeepDefault);
m_playlistDao.deleteAllUnlockedPlaylistsWithFewerTracks(PlaylistDAO::HiddenType::PLHT_SET_LOG,
minTrackCount);
transaction.commit();
}

void SetlogFeature::onRightClick(const QPoint& globalPos) {
Q_UNUSED(globalPos);
m_lastRightClickedIndex = QModelIndex();
Expand Down Expand Up @@ -279,6 +294,8 @@ void SetlogFeature::slotGetNewPlaylist() {
qDebug() << "Setlog playlist Creation Failed";
qDebug() << "An unknown error occurred while creating playlist: "
<< set_log_name;
} else {
m_recentTracks.clear();
}

reloadChildModel(m_playlistId); // For moving selection
Expand Down Expand Up @@ -366,8 +383,10 @@ void SetlogFeature::slotPlayingTrackChanged(TrackPointer currentPlayingTrack) {
m_recentTracks.push_front(currentPlayingTrackId);

// Keep a window of 6 tracks (inspired by 2 decks, 4 samplers)
constexpr int kRecentTrackWindow = 6;
while (m_recentTracks.size() > kRecentTrackWindow) {
const unsigned int recentTrackWindow = m_pConfig->getValue(
kHistoryTrackDuplicateDistanceConfigKey,
kHistoryTrackDuplicateDistanceDefault);
while (m_recentTracks.size() > recentTrackWindow) {
m_recentTracks.pop_back();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/library/trackset/setlogfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "library/trackset/baseplaylistfeature.h"
#include "preferences/usersettings.h"

class Library;

class SetlogFeature : public BasePlaylistFeature {
Q_OBJECT

Expand Down Expand Up @@ -40,6 +42,7 @@ class SetlogFeature : public BasePlaylistFeature {
void slotPlaylistTableRenamed(int playlistId, const QString& newName) override;

private:
void deleteAllUnlockedPlaylistsWithFewerTracks();
void reloadChildModel(int playlistId);
QString getRootViewHtml() const override;

Expand All @@ -48,4 +51,6 @@ class SetlogFeature : public BasePlaylistFeature {
QAction* m_pStartNewPlaylist;
int m_playlistId;
QPointer<WLibrary> m_libraryWidget;
Library* m_pLibrary;
UserSettingsPointer m_pConfig;
};
45 changes: 33 additions & 12 deletions src/preferences/dialog/dlgpreflibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ void DlgPrefLibrary::initializeDirList() {

void DlgPrefLibrary::slotResetToDefaults() {
checkBox_library_scan->setChecked(false);
spinbox_history_track_duplicate_distance->setValue(
kHistoryTrackDuplicateDistanceDefault);
spinbox_history_min_tracks_to_keep->setValue(1);
checkBox_SyncTrackMetadata->setChecked(false);
checkBox_SeratoMetadataExport->setChecked(false);
checkBox_use_relative_path->setChecked(false);
Expand All @@ -199,8 +202,8 @@ void DlgPrefLibrary::slotResetToDefaults() {
checkBox_show_itunes->setChecked(true);
checkBox_show_traktor->setChecked(true);
checkBox_show_rekordbox->setChecked(true);
radioButton_dbclick_bottom->setChecked(false);
checkBoxEditMetadataSelectedClicked->setChecked(kEditMetadataSelectedClickDefault);
radioButton_dbclick_bottom->setChecked(false);
radioButton_dbclick_top->setChecked(false);
radioButton_dbclick_deck->setChecked(true);
spinBoxRowHeight->setValue(Library::kDefaultRowHeightPx);
Expand All @@ -212,13 +215,22 @@ void DlgPrefLibrary::slotResetToDefaults() {
void DlgPrefLibrary::slotUpdate() {
initializeDirList();
checkBox_library_scan->setChecked(m_pConfig->getValue(
ConfigKey("[Library]","RescanOnStartup"), false));
kRescanOnStartupConfigKey, false));

spinbox_history_track_duplicate_distance->setValue(m_pConfig->getValue(
kHistoryTrackDuplicateDistanceConfigKey,
kHistoryTrackDuplicateDistanceDefault));
spinbox_history_min_tracks_to_keep->setValue(m_pConfig->getValue(
kHistoryMinTracksToKeepConfigKey,
kHistoryMinTracksToKeepDefault));

checkBox_SyncTrackMetadata->setChecked(
m_pConfig->getValue(kSyncTrackMetadataConfigKey, false));
checkBox_SeratoMetadataExport->setChecked(
m_pConfig->getValue(kSyncSeratoMetadataConfigKey, false));
checkBox_use_relative_path->setChecked(m_pConfig->getValue(
ConfigKey("[Library]","UseRelativePathOnExport"), false));
kUseRelativePathOnExportConfigKey, false));

checkBox_show_rhythmbox->setChecked(m_pConfig->getValue(
ConfigKey("[Library]","ShowRhythmboxLibrary"), true));
checkBox_show_banshee->setChecked(m_pConfig->getValue(
Expand All @@ -233,7 +245,7 @@ void DlgPrefLibrary::slotUpdate() {
ConfigKey("[Library]", "ShowSeratoLibrary"), true));

switch (m_pConfig->getValue<int>(
ConfigKey("[Library]", "TrackLoadAction"),
kTrackDoubleClickActionConfigKey,
static_cast<int>(TrackDoubleClickAction::LoadToDeck))) {
case static_cast<int>(TrackDoubleClickAction::AddToAutoDJBottom):
radioButton_dbclick_bottom->setChecked(true);
Expand All @@ -245,8 +257,8 @@ void DlgPrefLibrary::slotUpdate() {
radioButton_dbclick_ignore->setChecked(true);
break;
default:
radioButton_dbclick_deck->setChecked(true);
break;
radioButton_dbclick_deck->setChecked(true);
break;
}

bool editMetadataSelectedClick = m_pConfig->getValue(
Expand Down Expand Up @@ -383,16 +395,24 @@ void DlgPrefLibrary::slotSeratoMetadataExportClicked(bool checked) {
}

void DlgPrefLibrary::slotApply() {
m_pConfig->set(ConfigKey("[Library]","RescanOnStartup"),
ConfigValue((int)checkBox_library_scan->isChecked()));
m_pConfig->set(kRescanOnStartupConfigKey,
ConfigValue((int)checkBox_library_scan->isChecked()));

m_pConfig->set(kHistoryTrackDuplicateDistanceConfigKey,
ConfigValue(spinbox_history_track_duplicate_distance->value()));
m_pConfig->set(kHistoryMinTracksToKeepConfigKey,
ConfigValue(spinbox_history_min_tracks_to_keep->value()));

m_pConfig->set(
kSyncTrackMetadataConfigKey,
ConfigValue{checkBox_SyncTrackMetadata->isChecked()});
m_pConfig->set(
kSyncSeratoMetadataConfigKey,
ConfigValue{checkBox_SeratoMetadataExport->isChecked()});
m_pConfig->set(ConfigKey("[Library]","UseRelativePathOnExport"),
ConfigValue((int)checkBox_use_relative_path->isChecked()));

m_pConfig->set(kUseRelativePathOnExportConfigKey,
ConfigValue((int)checkBox_use_relative_path->isChecked()));

m_pConfig->set(ConfigKey("[Library]","ShowRhythmboxLibrary"),
ConfigValue((int)checkBox_show_rhythmbox->isChecked()));
m_pConfig->set(ConfigKey("[Library]","ShowBansheeLibrary"),
Expand All @@ -405,6 +425,7 @@ void DlgPrefLibrary::slotApply() {
ConfigValue((int)checkBox_show_rekordbox->isChecked()));
m_pConfig->set(ConfigKey("[Library]", "ShowSeratoLibrary"),
ConfigValue((int)checkBox_show_serato->isChecked()));

int dbclick_status;
if (radioButton_dbclick_bottom->isChecked()) {
dbclick_status = static_cast<int>(TrackDoubleClickAction::AddToAutoDJBottom);
Expand All @@ -415,8 +436,8 @@ void DlgPrefLibrary::slotApply() {
} else { // radioButton_dbclick_ignore
dbclick_status = static_cast<int>(TrackDoubleClickAction::Ignore);
}
m_pConfig->set(ConfigKey("[Library]","TrackLoadAction"),
ConfigValue(dbclick_status));
m_pConfig->set(kTrackDoubleClickActionConfigKey,
ConfigValue(dbclick_status));

m_pConfig->set(kEditMetadataSelectedClickConfigKey,
ConfigValue(checkBoxEditMetadataSelectedClicked->checkState()));
Expand Down

0 comments on commit 30cc5f1

Please sign in to comment.