After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 780191 - Improved css provider file loading
Improved css provider file loading
Status: RESOLVED FIXED
Product: gnome-todo
Classification: Other
Component: General
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: GNOME To Do maintainer(s)
GNOME To Do maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2017-03-17 12:18 UTC by Iñigo Martínez
Modified: 2017-03-29 21:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Improved css file loading patch (1.83 KB, patch)
2017-03-17 12:18 UTC, Iñigo Martínez
none Details | Review
Load a css provider based on the current theme (2.13 KB, patch)
2017-03-17 15:47 UTC, Iñigo Martínez
committed Details | Review
Fixed css provider file loading for GTK 4.0 (1.47 KB, patch)
2017-03-20 12:47 UTC, Iñigo Martínez
none Details | Review
Fixed css provider file loading for GTK 4.0 (1.78 KB, patch)
2017-03-23 08:27 UTC, Iñigo Martínez
committed Details | Review

Description Iñigo Martínez 2017-03-17 12:18:04 UTC
Created attachment 348171 [details] [review]
Improved css file loading patch

Different steps are made in order to load a css provider. This patches removes several lines by using gtk_css_provider_load_from_resource.
Comment 1 Georges Basile Stavracas Neto 2017-03-17 12:22:31 UTC
Review of attachment 348171 [details] [review]:

Nice catch. Only one minor nitpick.

There's something I wanted to do for quite some time: could you make this code generic to load CSS for any theme? So instead of:

"/org/gnome/todo/theme/Adwaita.css"

We'd have:

"/org/gnome/todo/theme/%s.css"

And it'd check at runtime the name of the current theme, and if we ship CSS for the current theme. If we do, load that CSS; otherwise, load Adwaita.

What do you think?

::: src/gtd-application.c
@@ +230,3 @@
 
+     gtk_css_provider_load_from_resource (priv->provider,
+                                          "/org/gnome/todo/theme/Adwaita.css");

Can be in a single line.
Comment 2 Iñigo Martínez 2017-03-17 15:47:19 UTC
Created attachment 348188 [details] [review]
Load a css provider based on the current theme

Changed the patch to load a css provider based on the current theme. On any error when loading it, errors when parsing, the file does not exist, etc.. it loads Adwaita theme.

This patch also fixes the memory leak with css_file in case of any error when loading it (which should be very unlikely).
Comment 3 Georges Basile Stavracas Neto 2017-03-18 00:35:44 UTC
Review of attachment 348188 [details] [review]:

Looks good.
Comment 4 Georges Basile Stavracas Neto 2017-03-18 00:38:21 UTC
Comment on attachment 348188 [details] [review]
Load a css provider based on the current theme

Thanks
Comment 5 Iñigo Martínez 2017-03-18 09:44:18 UTC
I was thinking about the approach of checking if a resource exists by trying to open it with gtk_css_provider_load_from_file and then check the error parameter was the proper way of solve the problem, so I started looking at GTK code and I have discovered that error parameter does not exist anymore.

I am trying to figure out a different approach to solve the problem so this will be valid for GTK 4.0 too. I have sent a mail to the gtk-devel-list in order to get an advice from someone more experienced.
Comment 6 Iñigo Martínez 2017-03-20 12:47:23 UTC
Created attachment 348313 [details] [review]
Fixed css provider file loading for GTK 4.0

Changed the way an external css provider file is loaded. In the first place, the code checks if the file exists using GFile functions and loads it if it does, otherwise it loads the Adwaita resource.

The solution is not pefect though, as there is a race condition where the file may not exist after file exist check.
Comment 7 Georges Basile Stavracas Neto 2017-03-23 00:55:36 UTC
Review of attachment 348313 [details] [review]:

This patch introduces a warning:

'warning: unused variable ‘error’ [-Wunused-variable]'

Please remove that variable.
Comment 8 Iñigo Martínez 2017-03-23 08:27:53 UTC
Created attachment 348552 [details] [review]
Fixed css provider file loading for GTK 4.0

Updated css provider file loading patch by removing the unused error variable.
Comment 9 Georges Basile Stavracas Neto 2017-03-29 21:35:08 UTC
Thanks for the patches.