Added a little extra logic, also some cross-platform help, to the custom

stylesheet loader.
lv2
Elliott Liggett 2021-07-30 17:30:34 -07:00
rodzic 2ac1b8c0ac
commit 4e63a72106
1 zmienionych plików z 33 dodań i 21 usunięć

Wyświetl plik

@ -2222,40 +2222,52 @@ void wfmain::setAppTheme(bool isCustom)
if(isCustom) if(isCustom)
{ {
#ifndef Q_OS_LINUX #ifndef Q_OS_LINUX
QFile f(":"+prefs.stylesheetPath); // built-in resource QFile fresource(":"+prefs.stylesheetPath); // built-in resource
#else if (!fresource.exists())
// two paths are possible - fu = /usr; fl = /usr/local
QFile fu("/usr/share/wfview/stylesheets/" + prefs.stylesheetPath);
QFile fl("/usr/local/share/wfview/stylesheets/" + prefs.stylesheetPath);
#endif
// check if the filepath is in /usr and if so -- set the style and return
if (!fu.exists())
{ {
printf("Unable to set stylesheet, file not found or permission issue [%s]\n", QString( QString("/usr/share/wfview/stylesheets/") + prefs.stylesheetPath).toStdString().c_str() ); // This would be quite unusual...
qApp->setStyleSheet("");
return;
} }
else else
{ {
fu.open(QFile::ReadOnly | QFile::Text); fresource.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&fu); QTextStream ts(&fresource);
qApp->setStyleSheet(ts.readAll()); qApp->setStyleSheet(ts.readAll());
return; return;
} }
#else
// two paths are possible - fusr = /usr; flocal = /usr/local
QFile fusr("/usr/share/wfview/stylesheets/" + prefs.stylesheetPath);
QFile flocal("/usr/local/share/wfview/stylesheets/" + prefs.stylesheetPath);
// check if the filepath is in /usr and if so -- set the style and return
if (fusr.exists())
{
fusr.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&fusr);
qApp->setStyleSheet(ts.readAll());
return;
}
// if above fails, check if filepath is in /usr/local and if so -- set the style from there and return // if above fails, check if filepath is in /usr/local and if so -- set the style from there and return
if (!fl.exists()) if (flocal.exists())
{ {
printf("Unable to set stylesheet, file not found or permisson issue [%s]\n", QString( QString("/usr/local/share/wfview/stylesheets/") + prefs.stylesheetPath).toStdString().c_str() ); flocal.open(QFile::ReadOnly | QFile::Text);
} QTextStream ts(&flocal);
else
{
fl.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&fl);
qApp->setStyleSheet(ts.readAll()); qApp->setStyleSheet(ts.readAll());
return; return;
} }
// Still here? Then we could not find a file:
printf("Unable to set stylesheet, file not found or permisson issue. Tried loading [%s] and ", QString( QString("/usr/local/share/wfview/stylesheets/") + prefs.stylesheetPath).toStdString().c_str() );
printf(" [%s]\n", QString( QString("/usr/share/wfview/stylesheets/") + prefs.stylesheetPath).toStdString().c_str() );
printf("Unsetting stylesheet.");
qApp->setStyleSheet("");
#endif
} else { } else {
// if both fail, we revert to no style sheet set // Not custom, proceed without:
qApp->setStyleSheet(""); qApp->setStyleSheet("");
} }
} }