GUI: move the code managing the dark mode css into guiutils

This commit is contained in:
Jean-Francois Dockes 2021-03-21 10:03:27 +01:00
parent 572e37c36f
commit ecf775e306
6 changed files with 27 additions and 27 deletions

View File

@ -26,6 +26,7 @@
#include "pathut.h"
#include "base64.h"
#include "advshist.h"
#include "readfile.h"
#include <QSettings>
#include <QStringList>
@ -421,10 +422,32 @@ void rwSettings(bool writing)
prefs.asearchSubdirHist.push_back(u8s2qs(dbd.c_str()));
}
}
if (!writing) {
prefs.setupDarkCSS();
}
if (!writing)
havereadsettings = true;
}
void PrefsPack::setupDarkCSS()
{
if (!darkMode) {
darkreslistheadertext.clear();
return;
}
if (nullptr == theconfig) {
return;
}
string fn = path_cat(
path_cat(theconfig->getDatadir(), "examples"), "recoll-dark.css");
string data;
string reason;
if (!file_to_string(fn, data, &reason)) {
std::cerr << "Recoll: Could not read: " << fn << "\n";
}
darkreslistheadertext = u8s2qs(data);
}
string PrefsPack::stemlang()
{
string stemLang(qs2utf8s(prefs.queryStemLang));

View File

@ -173,6 +173,8 @@ public:
std::string stemlang();
void setupDarkCSS();
// MIME types for which we prefer to use stored text from preview
// rather than extracting the possibly nicer HTML because the
// extractor is very slow. This is compiled in and there is no UI

View File

@ -331,11 +331,7 @@ void RclMain::showExtIdxDialog()
void RclMain::showAboutDialog()
{
QString darkcss;
if (prefs.darkMode) {
darkcss = readDarkCSS();
}
QString vstring = QString("<html><head>") + darkcss + "</head><body>" +
QString vstring = QString("<html><head>") + prefs.darkreslistheadertext + "</head><body>" +
u8s2qs(Rcl::version_string()) +
"<br><a href='https://www.recoll.org'>www.recoll.org</a>" +
"<br><a href='https://www.xapian.org'>www.xapian.org</a>";

View File

@ -530,22 +530,6 @@ void RclMain::setSynEnabled(bool on)
uiprefs->synFileCB->setChecked(prefs.synFileEnable);
}
QString RclMain::readDarkCSS()
{
if (nullptr == theconfig) {
return QString();
}
string fn = path_cat(
path_cat(theconfig->getDatadir(), "examples"), "recoll-dark.css");
string data;
string reason;
if (!file_to_string(fn, data, &reason)) {
QMessageBox::warning(0, "Recoll", tr("Could not read: ") + u8s2qs(fn));
return QString();
}
return u8s2qs(data);
}
void RclMain::resultCount(int n)
{
actionSortByDateAsc->setEnabled(n>0);

View File

@ -89,7 +89,6 @@ public:
return m_indexerState;
}
void enableTrayIcon(bool onoff);
QString readDarkCSS();
void setupToolbars();
void setupStatusBar();
void buildMenus();

View File

@ -400,11 +400,7 @@ void UIPrefsDialog::accept()
prefs.reslistfontfamily = reslistFontFamily;
prefs.reslistfontsize = reslistFontSize;
prefs.darkMode = darkMode;
if (darkMode) {
prefs.darkreslistheadertext = m_mainWindow->readDarkCSS();
} else {
prefs.darkreslistheadertext.clear();
}
prefs.setupDarkCSS();
prefs.qssFile = qssFile;
QTimer::singleShot(0, m_mainWindow, SLOT(applyStyleSheet()));
prefs.snipCssFile = snipCssFile;