35
35
#endif
36
36
37
37
namespace {
38
- QString vanillaThemePath ()
38
+ QString whiteTheme ()
39
39
{
40
- return QStringLiteral (" :/client/ownCloud/theme " );
40
+ return QStringLiteral (" white " );
41
41
}
42
42
43
- QString brandThemePath ()
43
+ QString blackTheme ()
44
44
{
45
- return QStringLiteral (" :/client/ " APPLICATION_SHORTNAME " /theme " );
45
+ return QStringLiteral (" black " );
46
46
}
47
47
48
48
QString darkTheme ()
@@ -55,16 +55,6 @@ QString coloredTheme()
55
55
return QStringLiteral (" colored" );
56
56
}
57
57
58
- QString whiteTheme ()
59
- {
60
- return QStringLiteral (" white" );
61
- }
62
-
63
- QString blackTheme ()
64
- {
65
- return QStringLiteral (" black" );
66
- }
67
-
68
58
constexpr bool isVanilla ()
69
59
{
70
60
return std::string_view (APPLICATION_SHORTNAME) == " ownCloud" ;
@@ -118,7 +108,7 @@ QString Theme::configFileName() const
118
108
119
109
QIcon Theme::applicationIcon () const
120
110
{
121
- return themeUniversalIcon (applicationIconName () + QStringLiteral (" -icon" ));
111
+ return Resources:: themeUniversalIcon (applicationIconName () + QStringLiteral (" -icon" ));
122
112
}
123
113
124
114
QString Theme::applicationIconName () const
@@ -131,20 +121,25 @@ QIcon Theme::aboutIcon() const
131
121
return applicationIcon ();
132
122
}
133
123
134
- bool Theme::allowDarkTheme ( ) const
124
+ QIcon Theme::themeTrayIcon ( const SyncResult &result, bool sysTrayMenuVisible, Resources::IconType iconType ) const
135
125
{
136
- return _hasBrandedColored == _hasBrandedDark;
137
- }
126
+ auto systrayIconFlavor = [&]() {
127
+ QString flavor;
128
+ if (_mono) {
129
+ flavor = Utility::hasDarkSystray () ? whiteTheme () : blackTheme ();
138
130
139
-
140
- QIcon Theme::themeUniversalIcon (const QString &name, Theme::IconType iconType) const
141
- {
142
- return loadIcon (QStringLiteral (" universal" ), name, iconType);
143
- }
144
-
145
- QIcon Theme::themeTrayIcon (const QString &name, bool sysTrayMenuVisible, IconType iconType) const
146
- {
147
- auto icon = loadIcon (systrayIconFlavor (_mono, sysTrayMenuVisible), name, iconType);
131
+ #ifdef Q_OS_MAC
132
+ if (sysTrayMenuVisible) {
133
+ flavor = QLatin1String (" white" );
134
+ }
135
+ #endif
136
+ } else {
137
+ // we have a dark sys tray and the theme has support for that
138
+ flavor = (Utility::hasDarkSystray () && Resources::hasDarkTheme ()) ? darkTheme () : coloredTheme ();
139
+ }
140
+ return flavor;
141
+ };
142
+ auto icon = Resources::loadIcon (systrayIconFlavor (), QStringLiteral (" state-%1" ).arg (syncStateIconName (result)), iconType);
148
143
#ifdef Q_OS_MAC
149
144
// This defines the icon as a template and enables automatic macOS color handling
150
145
// See https://bugreports.qt.io/browse/QTBUG-42109
@@ -153,89 +148,6 @@ QIcon Theme::themeTrayIcon(const QString &name, bool sysTrayMenuVisible, IconTyp
153
148
return icon;
154
149
}
155
150
156
- QIcon Theme::themeIcon (const QString &name, Theme::IconType iconType) const
157
- {
158
- return loadIcon ((Resources::isUsingDarkTheme () && allowDarkTheme ()) ? darkTheme () : coloredTheme (), name, iconType);
159
- }
160
- /*
161
- * helper to load a icon from either the icon theme the desktop provides or from
162
- * the apps Qt resources.
163
- */
164
- QIcon Theme::loadIcon (const QString &flavor, const QString &name, IconType iconType) const
165
- {
166
- // prevent recusion
167
- const bool useCoreIcon = (iconType == IconType::VanillaIcon) || isVanilla ();
168
- const QString path = useCoreIcon ? vanillaThemePath () : brandThemePath ();
169
- const QString key = name + QLatin1Char (' ,' ) + flavor;
170
- QIcon &cached = _iconCache[key]; // Take reference, this will also "set" the cache entry
171
- if (cached.isNull ()) {
172
- if (isVanilla () && QIcon::hasThemeIcon (name)) {
173
- // use from theme
174
- return cached = QIcon::fromTheme (name);
175
- }
176
- const QString svg = QStringLiteral (" %1/%2/%3.svg" ).arg (path, flavor, name);
177
- if (QFile::exists (svg)) {
178
- return cached = QIcon (svg);
179
- }
180
-
181
- const QString png = QStringLiteral (" %1/%2/%3.png" ).arg (path, flavor, name);
182
- if (QFile::exists (png)) {
183
- return cached = QIcon (png);
184
- }
185
-
186
- const QList<int > sizes {16 , 22 , 32 , 48 , 64 , 128 , 256 , 512 , 1024 };
187
- QString previousIcon;
188
- for (int size : sizes) {
189
- QString pixmapName = QStringLiteral (" %1/%2/%3-%4.png" ).arg (path, flavor, name, QString::number (size));
190
- if (QFile::exists (pixmapName)) {
191
- previousIcon = pixmapName;
192
- cached.addFile (pixmapName, { size, size });
193
- } else if (size >= 128 ) {
194
- if (!previousIcon.isEmpty ()) {
195
- qWarning () << " Upscaling:" << previousIcon << " to" << size;
196
- cached.addPixmap (QPixmap (previousIcon).scaled ({ size, size }, Qt::KeepAspectRatio, Qt::SmoothTransformation));
197
- }
198
- }
199
- }
200
- }
201
- if (cached.isNull ()) {
202
- if (!useCoreIcon && iconType == IconType::BrandedIconWithFallbackToVanillaIcon) {
203
- return loadIcon (flavor, name, IconType::VanillaIcon);
204
- }
205
- qWarning () << " Failed to locate the icon" << name;
206
- }
207
- return cached;
208
- }
209
-
210
- bool Theme::hasTheme (IconType type, const QString &theme) const
211
- {
212
- const auto key = qMakePair (type != IconType::VanillaIcon, theme);
213
- auto it = _themeCache.constFind (key);
214
- if (it == _themeCache.cend ()) {
215
- return _themeCache[key] = QFileInfo (QStringLiteral (" %1/%2/" ).arg (type == IconType::VanillaIcon ? vanillaThemePath () : brandThemePath (), theme)).isDir ();
216
- }
217
- return it.value ();
218
- }
219
-
220
- QString Theme::systrayIconFlavor (bool mono, bool sysTrayMenuVisible) const
221
- {
222
- Q_UNUSED (sysTrayMenuVisible)
223
- QString flavor;
224
- if (mono) {
225
- flavor = Utility::hasDarkSystray () ? whiteTheme () : blackTheme ();
226
-
227
- #ifdef Q_OS_MAC
228
- if (sysTrayMenuVisible) {
229
- flavor = QLatin1String (" white" );
230
- }
231
- #endif
232
- } else {
233
- // we have a dark sys tray and the theme has support for that
234
- flavor = (Utility::hasDarkSystray () && allowDarkTheme ()) ? darkTheme () : coloredTheme ();
235
- }
236
- return flavor;
237
- }
238
-
239
151
Theme::Theme ()
240
152
: QObject(nullptr )
241
153
{
@@ -305,13 +217,6 @@ bool Theme::systrayUseMonoIcons() const
305
217
return _mono;
306
218
}
307
219
308
- bool Theme::monoIconsAvailable () const
309
- {
310
- // mono icons are only supported in vanilla and if a customer provides them
311
- // no fallback to vanilla
312
- return hasTheme (IconType::BrandedIcon, systrayIconFlavor (true ));
313
- }
314
-
315
220
QUrl Theme::updateCheckUrl () const
316
221
{
317
222
return QUrl (QStringLiteral (APPLICATION_UPDATE_URL));
@@ -445,25 +350,6 @@ QString Theme::syncStateIconName(const SyncResult &result) const
445
350
Q_UNREACHABLE ();
446
351
}
447
352
448
- QIcon Theme::syncStateIcon (SyncResult::Status status, bool sysTray, bool sysTrayMenuVisible) const
449
- {
450
- return syncStateIcon (SyncResult{status}, sysTray, sysTrayMenuVisible);
451
- }
452
-
453
- QIcon Theme::syncStateIcon (const SyncResult &result, bool sysTray, bool sysTrayMenuVisible) const
454
- {
455
- return syncStateIcon (QStringLiteral (" state-%1" ).arg (syncStateIconName (result)), sysTray, sysTrayMenuVisible);
456
- }
457
-
458
- QIcon Theme::syncStateIcon (const QString &iconName, bool sysTray, bool sysTrayMenuVisible) const
459
- {
460
- if (sysTray) {
461
- return themeTrayIcon (iconName, sysTrayMenuVisible);
462
- } else {
463
- return themeIcon (iconName);
464
- }
465
- }
466
-
467
353
QColor Theme::wizardHeaderTitleColor () const
468
354
{
469
355
return qApp->palette ().text ().color ();
0 commit comments