Skip to content

Commit

Permalink
[utils.cpp] Avoid creating QSettings too early (#65)
Browse files Browse the repository at this point in the history
If the QSettings are initialised statically they may fail to pick up the
organization and application names set in main. The result is that the
settings are written to and read from both
~~"~/.config/Unknown\Organization.conf" and~~
"~/.config/sailfishos-applications/flowplayer.conf".

This can prevent the configured Music directories being read from
successfully.

P.S.: We can still move to a singleton object later if needed.
  • Loading branch information
llewelld authored Feb 24, 2024
1 parent a5c5c22 commit eccc980
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ QString albumArtUrl, albumArtArtist, albumArtAlbum;
QString currentArtist, currentSong;
QString searchServer;

QSettings settings;

//extern bool isDBOpened;

Utils::Utils(QQuickItem *parent)
Expand Down Expand Up @@ -442,136 +440,159 @@ void Utils::removePreview()

void Utils::setSettings(QString set, QString val)
{
QSettings settings;
settings.setValue(set, val);
settings.sync();
}

QString Utils::readSettings(QString set, QString val)
{
QSettings settings;
return settings.value(set, val).toString();
}

QString Utils::showReflection()
{
QSettings settings;
return settings.value("ShowReflection", "true").toString();
}

QString Utils::viewmode() const
{
QSettings settings;
return settings.value("ViewMode", "grid").toString();
}

QString Utils::paging() const
{
QSettings settings;
return settings.value("Paging", "multiple").toString();
}

QString Utils::scrobble() const
{
QSettings settings;
return settings.value("Scrobble", "false").toString();
}

QString Utils::order() const
{
QSettings settings;
return settings.value("SortOrder", "album").toString();
}

QString Utils::lang() const
{
QSettings settings;
return settings.value("LastFMlang", "en").toString();
}

QString Utils::updatestart() const
{
QSettings settings;
return settings.value("UpdateOnStartup", "no").toString();
}

QString Utils::autosearch() const
{
QSettings settings;
return settings.value("AutoSearchLyrics", "yes").toString();
}

QString Utils::cleanqueue() const
{
QSettings settings;
return settings.value("CleanQueue", "yes").toString();
}

QString Utils::workoffline() const
{
QSettings settings;
return settings.value("WorkOffline", "no").toString();
}


void Utils::setViewMode(QString val)
{
QSettings settings;
settings.setValue("ViewMode", val);
settings.sync();
emit viewmodeChanged();
}

void Utils::setPaging(QString val)
{
QSettings settings;
settings.setValue("Paging", val);
settings.sync();
emit pagingChanged();
}

void Utils::setScrobble(QString val)
{
QSettings settings;
settings.setValue("Scrobble", val);
settings.sync();
emit scrobbleChanged();
}

void Utils::setOrder(QString val)
{
QSettings settings;
settings.setValue("SortOrder", val);
settings.sync();
emit orderChanged();
}

void Utils::setLang(QString val)
{
QSettings settings;
settings.setValue("LastFMlang", val);
settings.sync();
emit langChanged();
}

void Utils::setUpdateStart(QString val)
{
QSettings settings;
settings.setValue("UpdateOnStartup", val);
settings.sync();
emit updateChanged();
}

void Utils::setAutoSearch(QString val)
{
QSettings settings;
settings.setValue("AutoSearchLyrics", val);
settings.sync();
emit autosearchChanged();
}

void Utils::setCleanQueue(QString val)
{
QSettings settings;
settings.setValue("CleanQueue", val);
settings.sync();
emit queueChanged();
}

void Utils::setWorkOffline(QString val)
{
QSettings settings;
settings.setValue("WorkOffline", val);
settings.sync();
emit workofflineChanged();
}

QString Utils::orientation() const
{
QSettings settings;
return settings.value("Orientation", "auto").toString();
}

void Utils::setOrientation(QString val)
{
QSettings settings;
settings.setValue("Orientation", val);
settings.sync();
emit orientationChanged();
Expand All @@ -586,6 +607,7 @@ QString Utils::plainLyrics(QString text)

QString Utils::version()
{
QSettings settings;
return settings.value("Firmware", "PR10").toString();
}

Expand Down Expand Up @@ -622,6 +644,7 @@ void Utils::removeAlbumArt()

void Utils::getFolders()
{
QSettings settings;
QStringList folders = settings.value("Folders","").toString().split("<separator>");
folders.removeAll("");

Expand Down Expand Up @@ -684,6 +707,7 @@ void Utils::getFolderItems(QString path)

void Utils::addFolderToList(QString path)
{
QSettings settings;
QStringList folders = settings.value("Folders","").toString().split("<separator>");
folders.removeAll("");
folders.append(path);
Expand All @@ -695,6 +719,7 @@ void Utils::addFolderToList(QString path)

void Utils::removeFolder(QString path)
{
QSettings settings;
QStringList folders = settings.value("Folders","").toString().split("<separator>");
folders.removeAll("");
folders.removeAll(path);
Expand Down

0 comments on commit eccc980

Please sign in to comment.