settings format conv -> win

This commit is contained in:
Jean-Francois Dockes 2020-03-04 15:07:56 +01:00
parent 0df3da180c
commit 45b785b728
5 changed files with 51 additions and 4 deletions

View File

@ -72,6 +72,19 @@ static bool havereadsettings;
void rwSettings(bool writing)
{
#ifdef _WIN32
{
static int once = 1;
// Once conversion registry -> file. Only happens once ever, and
// also we only call the function at program startup (the once
// above).
maybeCopyFromRegistry();
once = 0;
}
#endif _WIN32
// Keep this AFTER maybecopy...()
QSettings::setDefaultFormat(QSettings::IniFormat);
LOGDEB1("rwSettings: write " << writing << "\n");
if (writing && !havereadsettings)
return;
@ -434,6 +447,38 @@ string PrefsPack::stemlang()
return stemLang;
}
#ifdef _WIN32
// Once conversion of registry storage to file. If the file-specific
// key does not exist, copy from registry to file and create the
// file-specific key.
void maybeCopyFromRegistry()
{
const char* markerkey = "registryToFileDone";
std::map<QString, QVariant> settingsmap;
{
QSettings settings;
QStringList keys = settings.allKeys();
for (int ki = 0; ki < keys.count(); ki++) {
QString key = keys[ki];
settingsmap[keys[ki]] = settings.value(keys[ki]);
}
}
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings settings;
if (settings.value(markerkey) != QVariant()) {
// Already done;
return;
}
for (const auto& entry : settingsmap) {
LOGDEB("maybeCopyFromRegistry: KEY [" <<
qs2utf8s(entry.first) << "] VALUE [" <<
qs2utf8s(entry.second.toString()) << "]\n");
settings.setValue(entry.first, entry.second);
}
settings.setValue(markerkey, 1);
}
#endif
#ifdef SHOWEVENTS
const char *eventTypeToStr(int tp)
{

View File

@ -18,6 +18,7 @@
#include <cstdlib>
#include <list>
#include <iostream>
#include <qapplication.h>
#include <qtranslator.h>
@ -31,6 +32,7 @@
#include <QLibraryInfo>
#include <QFileDialog>
#include <QUrl>
#include <QSettings>
#include "rcldb.h"
#include "rclconfig.h"

View File

@ -44,7 +44,7 @@ void PlainToRichQtPreview::clear()
m_lastanchor = 0;
m_groupanchors.clear();
m_groupcuranchors.clear();
QSettings settings("Recoll.org", "recoll");
QSettings settings;
m_spacehack = settings.value("anchorSpcHack", 0).toBool();
}

View File

@ -377,7 +377,7 @@ void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum, QString term)
confirm.exec();
// Pita: need to keep the prefs struct in sync, else the value
// will be clobbered on program exit.
QSettings settings("Recoll.org", "recoll");
QSettings settings;
prefs.showTempFileWarning =
settings.value("Recoll/prefs/showTempFileWarning").toInt();
}

View File

@ -106,7 +106,7 @@ void UIPrefsDialog::setFromPrefs()
{
// Most values are stored in the prefs struct. Some rarely used
// ones go directly through the settings
QSettings settings("Recoll.org", "recoll");
QSettings settings;
// Entries per result page spinbox
pageLenSB->setValue(prefs.respagesize);
@ -277,7 +277,7 @@ void UIPrefsDialog::accept()
{
// Most values are stored in the prefs struct. Some rarely used
// ones go directly through the settings
QSettings settings("Recoll.org", "recoll");
QSettings settings;
prefs.noBeeps = noBeepsCB->isChecked();
prefs.ssearchNoComplete = ssNoCompleteCB->isChecked();
prefs.ssearchStartOnComplete = ssSearchOnCompleteCB->isChecked();