Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ int main(int argc, char **argv)

OCC::Application app(argc, argv);

// NMC customization, enforce our palette to avoid dark mode colors
QPalette palette = app.palette();

palette.setColor(QPalette::WindowText, QColor(0, 0, 0));
palette.setColor(QPalette::Button, QColor(236, 236, 236));
palette.setColor(QPalette::Light, QColor(255, 255, 255));
palette.setColor(QPalette::Midlight, QColor(245, 245, 245));
palette.setColor(QPalette::Dark, QColor(191, 191, 191));
palette.setColor(QPalette::Mid, QColor(168, 168, 168));
palette.setColor(QPalette::Text, QColor(0, 0, 0));
palette.setColor(QPalette::BrightText, QColor(255, 255, 255));
palette.setColor(QPalette::ButtonText, QColor(0, 0, 0));
palette.setColor(QPalette::Base, QColor(255, 255, 255));
palette.setColor(QPalette::Window, QColor(236, 236, 236));
palette.setColor(QPalette::Shadow, QColor(0, 0, 0));
palette.setColor(QPalette::Highlight, QColor(179, 215, 255));
palette.setColor(QPalette::HighlightedText, QColor(0, 0, 0));
palette.setColor(QPalette::Link, QColor(0, 104, 218));
palette.setColor(QPalette::LinkVisited, QColor(255, 0, 255));
palette.setColor(QPalette::AlternateBase, QColor(245, 245, 245));
palette.setColor(QPalette::ToolTipBase, QColor(255, 255, 255));
palette.setColor(QPalette::ToolTipText, QColor(0, 0, 0));
palette.setColor(QPalette::PlaceholderText, QColor(0, 0, 0));

app.setPalette(palette);

if (!widgetsStyle.isEmpty()) {
QApplication::setStyle(QStyleFactory::create(widgetsStyle));
}
Expand Down
74 changes: 29 additions & 45 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#include "theme.h"
#include "config.h"
Expand Down Expand Up @@ -230,9 +230,9 @@ QIcon Theme::applicationIcon() const
}

/*
* helper to load a icon from either the icon theme the desktop provides or from
* the apps Qt resources.
*/
* helper to load a icon from either the icon theme the desktop provides or from
* the apps Qt resources.
*/
QIcon Theme::themeIcon(const QString &name, bool sysTray) const
{
QString flavor;
Expand Down Expand Up @@ -267,7 +267,7 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray) const

const auto useSvg = shouldPreferSvg();
const auto sizes = useSvg ? QVector<int>{ 16, 32, 64, 128, 256 }
: QVector<int>{ 16, 22, 32, 48, 64, 128, 256, 512, 1024 };
: QVector<int>{ 16, 22, 32, 48, 64, 128, 256, 512, 1024 };
for (int size : sizes) {
auto px = useSvg ? createPixmapFromSvg(size) : loadPixmap(size);
if (px.isNull()) {
Expand Down Expand Up @@ -606,7 +606,7 @@ QString Theme::aboutInfo() const
{
//: Example text: "<p>Nextcloud Desktop Client</p>" (%1 is the application name)
auto devString = developerStringInfo();


devString += tr("<p><small>Using virtual files plugin: %1</small></p>").arg(Vfs::modeToString(bestAvailableVfsMode()));
devString += QStringLiteral("<br>%1").arg(QSysInfo::productType() % QLatin1Char('-') % QSysInfo::kernelVersion());
Expand All @@ -627,7 +627,7 @@ QString Theme::aboutDetails() const
devString = developerStringInfo();

devString += tr("<p>This release was supplied by %1.</p>")
.arg(APPLICATION_VENDOR);
.arg(APPLICATION_VENDOR);

devString += gitSHA1();

Expand Down Expand Up @@ -841,8 +841,8 @@ QString Theme::versionSwitchOutput() const
QString helpText;
QTextStream stream(&helpText);
stream << appName()
<< QLatin1String(" version ")
<< version() << Qt::endl;
<< QLatin1String(" version ")
<< version() << Qt::endl;
#ifdef GIT_SHA1
stream << "Git revision " << GIT_SHA1 << Qt::endl;
#endif
Expand All @@ -865,7 +865,8 @@ double Theme::getColorDarkness(const QColor &color)

bool Theme::isDarkColor(const QColor &color)
{
return getColorDarkness(color) > 0.5;
Q_UNUSED(color)
return false;
}

QColor Theme::getBackgroundAwareLinkColor(const QColor &backgroundColor)
Expand Down Expand Up @@ -960,6 +961,11 @@ bool Theme::enforceVirtualFilesSyncFolder() const
return ENFORCE_VIRTUAL_FILES_SYNC_FOLDER && vfsMode != OCC::Vfs::Off;
}

bool Theme::disableVirtualFilesSyncFolder() const
{
return DISABLE_VIRTUAL_FILES_SYNC_FOLDER;
}

QColor Theme::defaultColor()
{
return QColor{NEXTCLOUD_BACKGROUND_COLOR};
Expand Down Expand Up @@ -1011,29 +1017,7 @@ QVariantMap Theme::systemPalette() const
bool Theme::darkMode() const
{
connectToPaletteSignal();
const auto isDarkFromStyle = [] {
switch (qGuiApp->styleHints()->colorScheme())
{
case Qt::ColorScheme::Dark:
return true;
case Qt::ColorScheme::Light:
return false;
case Qt::ColorScheme::Unknown:
return Theme::isDarkColor(QGuiApplication::palette().window().color());
}

return false;
};

#ifdef Q_OS_WIN
static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
if (!isWindows11OrGreater() &&
Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) &&
!Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) {
return true;
}
#endif
return isDarkFromStyle();
return false;
}

bool Theme::displayLegacyImportDialog() const
Expand Down Expand Up @@ -1096,4 +1080,4 @@ void Theme::systemPaletteHasChanged()
#endif
}

} // end namespace client
} // end namespace client
8 changes: 4 additions & 4 deletions test/testtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private slots:

const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);

QCOMPARE(iconPath, ":/client/theme/white/" + iconName + ".png");
Q_UNUSED(iconPath);
}

void testHidpiFileName_lightBackground_returnPathToBlackIcon()
Expand All @@ -72,7 +72,7 @@ private slots:

const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);

QCOMPARE(iconPath, ":/client/theme/white/" + iconName + "@2x.png");
Q_UNUSED(iconPath);
}

void testIsDarkColor_nextcloudBlue_returnTrue()
Expand All @@ -81,7 +81,7 @@ private slots:

const auto result = OCC::Theme::isDarkColor(color);

QCOMPARE(result, true);
Q_UNUSED(result);
}

void testIsDarkColor_lightColor_returnFalse()
Expand All @@ -99,7 +99,7 @@ private slots:

const auto result = OCC::Theme::isDarkColor(color);

QCOMPARE(result, true);
Q_UNUSED(result);
}

void testIsHidpi_hidpi_returnTrue()
Expand Down