Merge lp:~larsu/notify-osd/spam-a-bit-less into lp:notify-osd

Proposed by Lars Karlitski
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 494
Merged at revision: 497
Proposed branch: lp:~larsu/notify-osd/spam-a-bit-less
Merge into: lp:notify-osd
Diff against target: 314 lines (+71/-156)
3 files modified
src/bubble.c (+69/-150)
src/bubble.h (+1/-5)
src/stack.c (+1/-1)
To merge this branch: bzr merge lp:~larsu/notify-osd/spam-a-bit-less
Reviewer Review Type Date Requested Status
Sebastien Bacher Approve
Review via email: mp+274382@code.launchpad.net

Commit message

Refactor bubble_set_icon()

This function did the same as bubble_set_icon_for_path(), because paths are allowed in addition to icon names for both the app-icon parameter and the image-path hint.

Remove one of those functions and inline load_icon(), which gives us more control over when icon-not-found warnings are shown. Don't show one when using the fallback of prefixing the icon name with "notification-".

Remove TEMPORARY_ICON_PREFIX_WORKAROUND. It's been there since 2009 and
was never set to anything but 1.

Description of the change

Refactor bubble_set_icon() a bit to remove warnings about not found icons when using the "notification-" fallback.

To post a comment you must log in.
Revision history for this message
Sebastien Bacher (seb128) wrote :

looks fine and start of a new cycle is a good time to land such changes ;-)

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

with that branch the sound icons displayed when doing mouseover rolling over indicator-sound are wrong ...

review: Needs Fixing
lp:~larsu/notify-osd/spam-a-bit-less updated
494. By Lars Karlitski

bubble_set_icon: try fallback icon name first

Fallback icon name is the one prefixed with "notification-". The
previous commit accidentally changed the order of lookups.

Remove TEMPORARY_ICON_PREFIX_WORKAROUND. It's been there since 2009 and
was never set to anything but 1.

Revision history for this message
Lars Karlitski (larsu) wrote :

Indeed. Fixed in r494.

Revision history for this message
Sebastien Bacher (seb128) wrote :

thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/bubble.c'
--- src/bubble.c 2015-10-12 13:56:53 +0000
+++ src/bubble.c 2015-11-11 17:01:30 +0000
@@ -94,7 +94,7 @@
9494
95 // used to prevent unneeded updates of the tile-cache, for append-,95 // used to prevent unneeded updates of the tile-cache, for append-,
96 // update or replace-cases, needs to move into class Notification96 // update or replace-cases, needs to move into class Notification
97 GString* old_icon_filename;97 gchar * old_icon_filename;
98};98};
9999
100G_DEFINE_TYPE_WITH_PRIVATE (Bubble, bubble, G_TYPE_OBJECT);100G_DEFINE_TYPE_WITH_PRIVATE (Bubble, bubble, G_TYPE_OBJECT);
@@ -124,12 +124,6 @@
124 gdouble value;124 gdouble value;
125};125};
126126
127#define TEMPORARY_ICON_PREFIX_WORKAROUND 1
128#ifdef TEMPORARY_ICON_PREFIX_WORKAROUND
129#warning "--== Using the icon-name-substitution! This is a temp. workaround not going to be maintained for long! ==--"
130#define NOTIFY_OSD_ICON_PREFIX "notification"
131#endif
132
133// FIXME: this is in class Defaults already, but not yet hooked up so for the127// FIXME: this is in class Defaults already, but not yet hooked up so for the
134// moment we use the macros here, these values reflect the visual-guideline128// moment we use the macros here, these values reflect the visual-guideline
135// for jaunty notifications129// for jaunty notifications
@@ -1832,71 +1826,6 @@
1832}1826}
18331827
1834static1828static
1835GdkPixbuf*
1836load_icon (Bubble* self,
1837 const gchar* filename,
1838 gint icon_size)
1839{
1840 GdkPixbuf* buffer = NULL;
1841 GdkPixbuf* pixbuf = NULL;
1842 GtkIconTheme* theme = NULL;
1843 GError* error = NULL;
1844 gint scale;
1845
1846 /* sanity check */
1847 g_return_val_if_fail (filename, NULL);
1848
1849 /* Images referenced must always be local files. */
1850 if (!strncmp (filename, "file://", 7))
1851 filename += 7;
1852
1853 scale = gtk_widget_get_scale_factor (self->priv->widget);
1854
1855 if (filename[0] == '/')
1856 {
1857 /* load image into pixbuf */
1858 pixbuf = gdk_pixbuf_new_from_file_at_scale (filename,
1859 scale * icon_size,
1860 scale * icon_size,
1861 TRUE,
1862 NULL);
1863 } else {
1864 /* TODO: rewrite, check for SVG support, raise apport
1865 ** notification for low-res icons */
1866 theme = gtk_icon_theme_get_default ();
1867 buffer = gtk_icon_theme_load_icon_for_scale (theme,
1868 filename,
1869 icon_size,
1870 scale,
1871 GTK_ICON_LOOKUP_FORCE_SVG |
1872 GTK_ICON_LOOKUP_GENERIC_FALLBACK |
1873 GTK_ICON_LOOKUP_FORCE_SIZE,
1874 &error);
1875 if (error)
1876 {
1877 g_print ("loading icon '%s' caused error: '%s'",
1878 filename,
1879 error->message);
1880 g_error_free (error);
1881 error = NULL;
1882 pixbuf = NULL;
1883 }
1884 else
1885 {
1886 /* copy and unref buffer so on an icon-theme change old
1887 ** icons are not kept in memory due to dangling
1888 ** references, this also makes sure we do not need to
1889 ** connect to GtkWidget::style-set signal for the
1890 ** GdkPixbuf we get from gtk_icon_theme_load_icon() */
1891 pixbuf = gdk_pixbuf_copy (buffer);
1892 g_object_unref (buffer);
1893 }
1894 }
1895
1896 return pixbuf;
1897}
1898
1899static
1900gboolean1829gboolean
1901pointer_update (Bubble* bubble)1830pointer_update (Bubble* bubble)
1902{1831{
@@ -2109,11 +2038,7 @@
2109 priv->tile_indicator = NULL;2038 priv->tile_indicator = NULL;
2110 }2039 }
21112040
2112 if (priv->old_icon_filename)2041 g_clear_pointer (&priv->old_icon_filename, g_free);
2113 {
2114 g_string_free ((gpointer) priv->old_icon_filename, TRUE);
2115 priv->old_icon_filename = NULL;
2116 }
21172042
2118 // chain up to the parent class2043 // chain up to the parent class
2119 G_OBJECT_CLASS (bubble_parent_class)->dispose (gobject);2044 G_OBJECT_CLASS (bubble_parent_class)->dispose (gobject);
@@ -2321,7 +2246,6 @@
2321 this->priv->tile_body = NULL;2246 this->priv->tile_body = NULL;
2322 this->priv->tile_indicator = NULL;2247 this->priv->tile_indicator = NULL;
2323 this->priv->prevent_fade = FALSE;2248 this->priv->prevent_fade = FALSE;
2324 this->priv->old_icon_filename = g_string_new ("");
23252249
2326 update_input_shape (window);2250 update_input_shape (window);
23272251
@@ -2432,89 +2356,84 @@
2432}2356}
24332357
2434void2358void
2435bubble_set_icon_from_path (Bubble* self,
2436 const gchar* filepath)
2437{
2438 Defaults* d;
2439 BubblePrivate* priv;
2440
2441 if (!self || !IS_BUBBLE (self) || !g_strcmp0 (filepath, ""))
2442 return;
2443
2444 priv = self->priv;
2445
2446 // check if an app tries to set the same file as icon again, this check
2447 // avoids superfluous regeneration of the tile/blur-cache for the icon,
2448 // thus it improves performance in update- and append-cases
2449 if (!g_strcmp0 (priv->old_icon_filename->str, filepath))
2450 return;
2451
2452 // store the new icon-basename
2453 g_string_assign (priv->old_icon_filename, filepath);
2454
2455 if (priv->icon_pixbuf)
2456 {
2457 g_object_unref (priv->icon_pixbuf);
2458 priv->icon_pixbuf = NULL;
2459 }
2460
2461 d = self->defaults;
2462 priv->icon_pixbuf = load_icon (self,
2463 filepath,
2464 EM2PIXELS (defaults_get_icon_size (d), d));
2465
2466 _refresh_icon (self);
2467}
2468
2469void
2470bubble_set_icon (Bubble* self,2359bubble_set_icon (Bubble* self,
2471 const gchar* filename)2360 const gchar* name)
2472{2361{
2473 Defaults* d;2362 BubblePrivate *priv;
2474 BubblePrivate* priv;2363 gint scale;
2475#ifdef TEMPORARY_ICON_PREFIX_WORKAROUND2364 gint icon_size;
2476 gchar* notify_osd_iconname;
2477#endif
24782365
2479 if (!self || !IS_BUBBLE (self) || !g_strcmp0 (filename, ""))2366 g_return_if_fail (self != NULL);
2480 return;2367 g_return_if_fail (name != NULL);
24812368
2482 priv = self->priv;2369 priv = self->priv;
24832370 scale = gtk_widget_get_scale_factor (priv->widget);
2484 //basename = g_path_get_basename (filename);2371 icon_size = EM2PIXELS (defaults_get_icon_size (self->defaults), self->defaults);
24852372
2486 // check if an app tries to set the same file as icon again, this check2373 // check if an app tries to set the same file as icon again, this check
2487 // avoids superfluous regeneration of the tile/blur-cache for the icon,2374 // avoids superfluous regeneration of the tile/blur-cache for the icon,
2488 // thus it improves performance in update- and append-cases2375 // thus it improves performance in update- and append-cases
2489 if (!g_strcmp0 (priv->old_icon_filename->str, filename))2376 if (!g_strcmp0 (priv->old_icon_filename, name))
2490 return;2377 return;
24912378
2379 g_clear_object (&priv->icon_pixbuf);
2380 g_clear_pointer (&priv->old_icon_filename, g_free);
2381
2382 if (g_str_has_prefix (name, "file://"))
2383 {
2384 gchar *filename;
2385 GError *error = NULL;
2386
2387 filename = g_filename_from_uri (name, NULL, &error);
2388 if (filename == NULL)
2389 {
2390 g_printerr ("%s is not a valid file uri: %s", name, error->message);
2391 g_error_free (error);
2392 return;
2393 }
2394
2395 priv->icon_pixbuf = gdk_pixbuf_new_from_file_at_scale (filename, scale * icon_size, scale * icon_size, TRUE, NULL);
2396
2397 g_free (filename);
2398 }
2399 else
2400 {
2401 GError *error = NULL;
2402 GdkPixbuf *buffer;
2403 GtkIconTheme *theme;
2404 GtkIconLookupFlags flags;
2405 gchar *fallback_name;
2406
2407 theme = gtk_icon_theme_get_default ();
2408 flags = GTK_ICON_LOOKUP_FORCE_SVG | GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SIZE;
2409
2410 fallback_name = g_strconcat ("notification-", name, NULL);
2411 buffer = gtk_icon_theme_load_icon_for_scale (theme, fallback_name, icon_size, scale, flags, &error);
2412 g_free (fallback_name);
2413
2414 if (buffer == NULL && g_error_matches (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND)) {
2415 g_clear_error (&error);
2416 buffer = gtk_icon_theme_load_icon_for_scale (theme, name, icon_size, scale, flags, &error);
2417 }
2418
2419 if (buffer == NULL)
2420 {
2421 g_print ("Unable to load icon '%s': %s", name, error->message);
2422 g_error_free (error);
2423 return;
2424 }
2425
2426 /* copy and unref buffer so on an icon-theme change old
2427 ** icons are not kept in memory due to dangling
2428 ** references, this also makes sure we do not need to
2429 ** connect to GtkWidget::style-set signal for the
2430 ** GdkPixbuf we get from gtk_icon_theme_load_icon() */
2431 priv->icon_pixbuf = gdk_pixbuf_copy (buffer);
2432 g_object_unref (buffer);
2433 }
2434
2492 // store the new icon-basename2435 // store the new icon-basename
2493 g_string_assign (priv->old_icon_filename, filename);2436 priv->old_icon_filename = g_strdup (name);
2494
2495 if (priv->icon_pixbuf)
2496 {
2497 g_object_unref (priv->icon_pixbuf);
2498 priv->icon_pixbuf = NULL;
2499 }
2500
2501 d = self->defaults;
2502
2503#ifdef TEMPORARY_ICON_PREFIX_WORKAROUND
2504 notify_osd_iconname = g_strdup_printf (NOTIFY_OSD_ICON_PREFIX "-%s",
2505 filename);
2506 priv->icon_pixbuf = load_icon (self,
2507 notify_osd_iconname,
2508 EM2PIXELS (defaults_get_icon_size (d),
2509 d));
2510 g_free (notify_osd_iconname);
2511#endif
2512
2513 // fallback to non-notify-osd name
2514 if (!priv->icon_pixbuf)
2515 priv->icon_pixbuf = load_icon (self,
2516 filename,
2517 EM2PIXELS (defaults_get_icon_size (d), d));
25182437
2519 _refresh_icon (self);2438 _refresh_icon (self);
2520}2439}
@@ -2591,7 +2510,7 @@
2591 priv = self->priv;2510 priv = self->priv;
25922511
2593 // "reset" the stored the icon-filename, fixes LP: #4510862512 // "reset" the stored the icon-filename, fixes LP: #451086
2594 g_string_assign (priv->old_icon_filename, "\0");2513 g_clear_pointer (&priv->old_icon_filename, g_free);
25952514
2596 if (priv->icon_pixbuf)2515 if (priv->icon_pixbuf)
2597 {2516 {
25982517
=== modified file 'src/bubble.h'
--- src/bubble.h 2010-10-21 16:52:42 +0000
+++ src/bubble.h 2015-11-11 17:01:30 +0000
@@ -109,12 +109,8 @@
109bubble_get_message_body (Bubble* self);109bubble_get_message_body (Bubble* self);
110110
111void111void
112bubble_set_icon_from_path (Bubble* self,
113 const gchar* filepath);
114
115void
116bubble_set_icon (Bubble* self,112bubble_set_icon (Bubble* self,
117 const gchar* filename);113 const gchar* name);
118114
119void115void
120bubble_set_icon_from_pixbuf (Bubble* self,116bubble_set_icon_from_pixbuf (Bubble* self,
121117
=== modified file 'src/stack.c'
--- src/stack.c 2013-11-07 15:37:20 +0000
+++ src/stack.c 2015-11-11 17:01:30 +0000
@@ -730,7 +730,7 @@
730 {730 {
731 g_debug("Using image_path hint\n");731 g_debug("Using image_path hint\n");
732 if ((data && G_VALUE_HOLDS_STRING (data)))732 if ((data && G_VALUE_HOLDS_STRING (data)))
733 bubble_set_icon_from_path (bubble, g_value_get_string(data));733 bubble_set_icon (bubble, g_value_get_string(data));
734 else734 else
735 g_warning ("image_path hint is not a string\n");735 g_warning ("image_path hint is not a string\n");
736 }736 }

Subscribers

People subscribed via source and target branches