Commit dbe90085 authored by Jerome Guidon's avatar Jerome Guidon Committed by Nate Graham
Browse files

Add setting to disable scan on startup

Add additional checkbox setting to disable autoscan on startup. This is annoying
for some users and with certain music library setups.

When using this setting, the config window informs you of the need to manually
scan every time new music is added. A new "Scan for new music" menu item is
added to facilitate this.
parent 9c8ab409
Pipeline #181283 passed with stage
in 5 minutes
......@@ -7,6 +7,7 @@
#include "databasetestdata.h"
#include "file/localfilelisting.h"
#include "elisa_settings.h"
#include "config-upnp-qt.h"
......@@ -46,6 +47,7 @@ private Q_SLOTS:
qRegisterMetaType<QVector<qlonglong>>("QVector<qlonglong>");
qRegisterMetaType<QHash<qlonglong,int>>("QHash<qlonglong,int>");
qRegisterMetaType<QList<QUrl>>("QList<QUrl>");
Elisa::ElisaConfiguration::instance(QStringLiteral("scanAtStartupFeature"));
}
void initialTestWithNoTrack()
......@@ -76,6 +78,43 @@ private Q_SLOTS:
QCOMPARE(removedTracksListSpy.count(), 0);
}
void initialTestWithEnabledScanOnStartupSetting()
{
LocalFileListing myListing;
Elisa::ElisaConfiguration::self()->setDefaults();
QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList);
QSignalSpy askRestoredTracksSpy(&myListing, &LocalFileListing::askRestoredTracks);
QCOMPARE(tracksListSpy.count(), 0);
QCOMPARE(askRestoredTracksSpy.count(), 0);
myListing.init();
QCOMPARE(tracksListSpy.count(), 0);
QCOMPARE(askRestoredTracksSpy.count(), 1);
}
void initialTestWithDisabledScanOnStartupSetting()
{
LocalFileListing myListing;
Elisa::ElisaConfiguration::self()->setDefaults();
Elisa::ElisaConfiguration::self()->setScanAtStartup(false);
QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList);
QSignalSpy askRestoredTracksSpy(&myListing, &LocalFileListing::askRestoredTracks);
QCOMPARE(tracksListSpy.count(), 0);
QCOMPARE(askRestoredTracksSpy.count(), 0);
myListing.init();
QCOMPARE(tracksListSpy.count(), 0);
QCOMPARE(askRestoredTracksSpy.count(), 0);
}
void initialTestWithTracks()
{
LocalFileListing myListing;
......@@ -411,6 +450,8 @@ private Q_SLOTS:
{
LocalFileListing myListing;
Elisa::ElisaConfiguration::self()->setDefaults();
QSignalSpy tracksListSpy(&myListing, &LocalFileListing::tracksList);
QSignalSpy removedTracksListSpy(&myListing, &LocalFileListing::removedTracksList);
QSignalSpy modifiedTracksListSpy(&myListing, &LocalFileListing::modifyTracksList);
......
......@@ -11,6 +11,7 @@
#include "abstractfile/indexercommon.h"
#include "filescanner.h"
#include "elisa_settings.h"
#include <QThread>
#include <QHash>
......@@ -72,10 +73,12 @@ AbstractFileListing::~AbstractFileListing()
void AbstractFileListing::init()
{
qCDebug(orgKdeElisaIndexer()) << "AbstractFileListing::init";
d->mIsActive = true;
Q_EMIT askRestoredTracks();
const bool autoScan = Elisa::ElisaConfiguration::self()->scanAtStartup();
if (autoScan) {
Q_EMIT askRestoredTracks();
}
}
void AbstractFileListing::stop()
......
......@@ -31,6 +31,11 @@
false
</default>
</entry>
<entry key="ScanAtStartup" type="Bool" >
<default>
true
</default>
</entry>
<entry key="UseFavoriteStyleRatings" type="Bool" >
<default>
false
......
......@@ -77,6 +77,7 @@ void ElisaConfigurationDialog::save()
Elisa::ElisaConfiguration::setShowSystemTrayIcon(mShowSystemTrayIcon);
Elisa::ElisaConfiguration::setForceUsageOfFastFileSearch(!mForceUsageOfSlowFileSystemIndexing);
Elisa::ElisaConfiguration::setPlayAtStartup(mPlayAtStartup);
Elisa::ElisaConfiguration::setScanAtStartup(mScanAtStartup);
Elisa::ElisaConfiguration::setColorScheme(mColorScheme);
Elisa::ElisaConfiguration::setUseFavoriteStyleRatings(mUseFavoriteStyleRatings);
......@@ -205,6 +206,17 @@ void ElisaConfigurationDialog::setPlayAtStartup(bool playAtStartup)
setDirty();
}
void ElisaConfigurationDialog::setScanAtStartup(bool scanAtStartup)
{
if (mScanAtStartup == scanAtStartup) {
return;
}
mScanAtStartup = scanAtStartup;
Q_EMIT scanAtStartupChanged();
setDirty();
}
void ElisaConfigurationDialog::setColorScheme(const QString &scheme)
{
if (mColorScheme == scheme) {
......@@ -250,6 +262,9 @@ void ElisaConfigurationDialog::configChanged()
mPlayAtStartup = Elisa::ElisaConfiguration::playAtStartup();
Q_EMIT playAtStartupChanged();
mScanAtStartup = Elisa::ElisaConfiguration::scanAtStartup();
Q_EMIT scanAtStartupChanged();
mColorScheme = Elisa::ElisaConfiguration::colorScheme();
Q_EMIT colorSchemeChanged();
......
......@@ -63,6 +63,11 @@ class ELISALIB_EXPORT ElisaConfigurationDialog : public QObject
WRITE setPlayAtStartup
NOTIFY playAtStartupChanged)
Q_PROPERTY(bool scanAtStartup
READ scanAtStartup
WRITE setScanAtStartup
NOTIFY scanAtStartupChanged)
Q_PROPERTY(QString colorScheme
READ colorScheme
WRITE setColorScheme
......@@ -122,6 +127,11 @@ public:
return mPlayAtStartup;
}
[[nodiscard]] bool scanAtStartup() const
{
return mScanAtStartup;
}
[[nodiscard]] QString colorScheme() const
{
return mColorScheme;
......@@ -155,6 +165,8 @@ Q_SIGNALS:
void playAtStartupChanged();
void scanAtStartupChanged();
void colorSchemeChanged();
void useFavoriteStyleRatingsChanged();
......@@ -181,6 +193,8 @@ public Q_SLOTS:
void setPlayAtStartup(bool playAtStartup);
void setScanAtStartup(bool scanAtStartup);
void setColorScheme(const QString &scheme);
void setUseFavoriteStyleRatings(bool useFavoriteStyleRatings);
......@@ -209,6 +223,8 @@ private:
bool mPlayAtStartup = false;
bool mScanAtStartup = true;
bool mUseFavoriteStyleRatings = false;
QString mColorScheme;
......
......@@ -106,8 +106,10 @@ MusicListenersManager::MusicListenersManager(QObject *parent)
connect(&d->mDatabaseInterface, &DatabaseInterface::requestsInitDone,
this, &MusicListenersManager::databaseReady);
connect(this, &MusicListenersManager::clearDatabase,
&d->mDatabaseInterface, &DatabaseInterface::clearData);
connect(&d->mDatabaseInterface, &DatabaseInterface::cleanedDatabase,
this, &MusicListenersManager::cleanedDatabase);
......@@ -117,6 +119,9 @@ MusicListenersManager::MusicListenersManager(QObject *parent)
connect(&d->mConfigFileWatcher, &QFileSystemWatcher::fileChanged,
this, &MusicListenersManager::configChanged);
connect(this, &MusicListenersManager::refreshDatabase,
&d->mDatabaseInterface, &DatabaseInterface::askRestoredTracks);
d->mListenerThread.start();
d->mDatabaseThread.start();
......@@ -298,9 +303,16 @@ void MusicListenersManager::connectModel(ModelDataLoader *dataLoader)
dataLoader->moveToThread(&d->mDatabaseThread);
}
void MusicListenersManager::resetMusicData()
void MusicListenersManager::scanCollection(CollectionScan scantype)
{
Q_EMIT clearDatabase();
switch (scantype)
{
case CollectionScan::Hard:
Q_EMIT clearDatabase();
break;
case CollectionScan::Soft:
Q_EMIT refreshDatabase();
}
}
void MusicListenersManager::configChanged()
......
......@@ -72,6 +72,12 @@ class ELISALIB_EXPORT MusicListenersManager : public QObject
public:
enum CollectionScan {
Soft,
Hard,
};
Q_ENUM(CollectionScan)
explicit MusicListenersManager(QObject *parent = nullptr);
~MusicListenersManager() override;
......@@ -130,6 +136,8 @@ Q_SIGNALS:
void androidIndexerAvailableChanged();
void refreshDatabase();
public Q_SLOTS:
void databaseReady();
......@@ -144,7 +152,7 @@ public Q_SLOTS:
void connectModel(ModelDataLoader *dataLoader);
void resetMusicData();
void scanCollection(CollectionScan scantype);
void updateSingleFileMetaData(const QUrl &url, DataTypes::ColumnsRoles role, const QVariant &data);
......
......@@ -565,6 +565,7 @@ Module {
Property { name: "initialViewIndex"; type: "int" }
Property { name: "isDirty"; type: "bool"; isReadonly: true }
Property { name: "playAtStartup"; type: "bool" }
Property { name: "scanAtStartup"; type: "bool" }
Property { name: "colorScheme"; type: "string" }
Property { name: "useFavoriteStyleRatings"; type: "bool" }
Signal {
......@@ -605,6 +606,10 @@ Module {
name: "setPlayAtStartup"
Parameter { name: "playAtStartup"; type: "bool" }
}
Method {
name: "setScanAtStartup"
Parameter { name: "scanAtStartup"; type: "bool" }
}
Method {
name: "setColorScheme"
Parameter { name: "scheme"; type: "string" }
......@@ -1338,7 +1343,7 @@ Module {
name: "connectModel"
Parameter { name: "dataLoader"; type: "ModelDataLoader"; isPointer: true }
}
Method { name: "resetMusicData" }
Method { name: "scanCollection" }
Method {
name: "updateSingleFileMetaData"
Parameter { name: "url"; type: "QUrl" }
......
......@@ -22,14 +22,17 @@ Menu {
property var configureAction: ElisaApplication.action("options_configure")
Action {
text: i18nc("Refresh Music Collection application menu entry", "Refresh Music Collection")
text: i18nc("Scan for New Music application menu entry", "Scan for New Music")
icon.name: "view-refresh"
onTriggered: {
applicationMenu.close()
ElisaApplication.musicManager.resetMusicData()
ElisaApplication.musicManager.scanCollection(MusicListenersManager.Soft)
}
}
MenuSeparator {
}
Menu {
title: i18n("Color Scheme")
Repeater {
......@@ -48,9 +51,6 @@ Menu {
}
}
MenuSeparator {
}
Action {
text: configureAction.text
shortcut: ElisaApplication.actionShortcut(configureAction)
......@@ -71,6 +71,18 @@ Menu {
}
}
MenuSeparator {
}
Action {
text: i18nc("Reset Database and Re-Scan Everything application menu entry", "Reset Database and Re-Scan Everything")
icon.name: "edit-clear-all"
onTriggered: {
applicationMenu.close()
ElisaApplication.musicManager.scanCollection(MusicListenersManager.Hard)
}
}
MenuSeparator {
visible: reportBugAction.text !== ""
}
......
......@@ -30,9 +30,9 @@ MenuBar {
}
MenuItem {
text: i18nc("Refresh Music Collection application menu entry", "Refresh Music Collection")
text: i18nc("Reset Database and Re-Scan Everything application menu entry", "Reset Database and Re-Scan Everything")
iconName: "view-refresh"
onTriggered: ElisaApplication.musicManager.resetMusicData()
onTriggered: ElisaApplication.musicManager.scanCollection(MusicListenersManager.Hard)
}
MenuSeparator {
......
......@@ -21,10 +21,16 @@ Menu {
property var configureAction: ElisaApplication.action("options_configure")
property var togglePlaylistAction: ElisaApplication.action("toggle_playlist")
MenuItem {
text: i18nc("Refresh Music Collection application menu entry", "Refresh Music Collection")
MenuItem {
text: i18nc("Scan for New Music application menu entry", "Scan for New Music")
iconName: "view-refresh"
onTriggered: ElisaApplication.musicManager.resetMusicData()
onTriggered: ElisaApplication.musicManager.scanCollection(MusicListenersManager.Soft)
}
MenuItem {
text: i18nc("Reset Database and Re-Scan Everything application menu entry", "Reset Database and Re-Scan Everything")
iconName: "edit-clear-all"
onTriggered: ElisaApplication.musicManager.scanCollection(MusicListenersManager.Hard)
}
MenuSeparator {
......
......@@ -73,6 +73,32 @@ ColumnLayout {
Accessible.onPressAction: onToggled
}
QQC2.CheckBox {
Layout.fillWidth: true
text: i18n("Scan for New Music on startup")
checked: ElisaConfigurationDialog.scanAtStartup
onToggled: {
startupScanWarningMessage.visible = !checked
ElisaConfigurationDialog.scanAtStartup = checked
}
Accessible.onToggleAction: onToggled
Accessible.onPressAction: onToggled
}
Kirigami.InlineMessage {
id: startupScanWarningMessage
Layout.fillWidth: true
// Not visible by default, the message only becomes visible when "Scan for New Music on startup" checkbox is unchecked. See onToggled implementation of the checkbox.
visible: false
type: Kirigami.MessageType.Warning
text: xi18nc("@info", "When using this setting, you will need to manually refresh the music collection whenever new files are added to configured music folders. You can do this with the <interface>Scan for new music</interface> item in Elisa's hamburger menu.")
}
Item {
Kirigami.FormData.isSection: true
}
......@@ -133,13 +159,23 @@ ColumnLayout {
}
}
// refresh music collection (mobile only, since on desktop it is in the application menu)
// scan for new music (mobile only, since on desktop it is in the application menu)
QQC2.Button {
visible: Kirigami.Settings.isMobile
text: i18n("Refresh Music Collection")
text: i18n("Scan for New Music")
icon.name: "view-refresh"
onClicked: {
ElisaApplication.musicManager.resetMusicData();
ElisaApplication.musicManager.scanCollection(MusicListenersManager.Soft)
mainWindow.pageStack.layers.pop();
}
}
QQC2.Button {
visible: Kirigami.Settings.isMobile
text: i18n("Reset Database and Re-Scan Everything")
icon.name: "edit-clear-all"
onClicked: {
ElisaApplication.musicManager.scanCollection(MusicListenersManager.Hard);
mainWindow.pageStack.layers.pop();
}
}
......@@ -263,7 +299,6 @@ ColumnLayout {
]
}
// Music locations list
// ====================
ColumnLayout {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment