Merge lp:~3v1n0/notify-osd/fix-empty-newlines-appending into lp:notify-osd

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 507
Merged at revision: 505
Proposed branch: lp:~3v1n0/notify-osd/fix-empty-newlines-appending
Merge into: lp:notify-osd
Prerequisite: lp:~3v1n0/notify-osd/fix-notifications-replacing
Diff against target: 75 lines (+37/-1)
3 files modified
debian/changelog (+7/-0)
src/bubble.c (+30/-0)
src/stack.c (+0/-1)
To merge this branch: bzr merge lp:~3v1n0/notify-osd/fix-empty-newlines-appending
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+291964@code.launchpad.net

Commit message

Bubble: don't append new lines when receiving empty bodies

Delay the addition of new lines until there's some real content to append.

Description of the change

To be tested with something like

from gi.repository import Notify
from time import sleep

Notify.init("Test App")

for i in range(10):
    n = Notify.Notification.new("Title", "" if i % 3 else "test {}".format(i))
    n.set_hint_string("append", "true")
    n.show()
    sleep(1)

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

+1

review: Approve
508. By Marco Trevisan (Treviño)

Bubble: strip body text when adding it

509. By Marco Trevisan (Treviño)

Bubble: Indentation fixes

510. By Marco Trevisan (Treviño)

Merging changelog from landing silo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-12-01 08:28:52 +0000
3+++ debian/changelog 2016-04-15 11:52:53 +0000
4@@ -1,3 +1,10 @@
5+notify-osd (0.9.35+16.04.20160413-0ubuntu1) xenial; urgency=medium
6+
7+ * Stack: allow to replace a notification when the replace_id has been
8+ provided (LP: #1569682)
9+
10+ -- Marco Trevisan (Treviño) <mail@3v1n0.net> Wed, 13 Apr 2016 05:36:20 +0000
11+
12 notify-osd (0.9.35+16.04.20151201-0ubuntu1) xenial; urgency=medium
13
14 [ CI Train Bot ]
15
16=== modified file 'src/bubble.c'
17--- src/bubble.c 2015-11-27 18:34:49 +0000
18+++ src/bubble.c 2016-04-15 11:52:53 +0000
19@@ -2323,6 +2323,7 @@
20
21 // filter out any HTML/markup if possible
22 text = filter_text (body);
23+ g_strstrip (text);
24
25 if (priv->message_body)
26 if (g_strcmp0 (priv->message_body->str, text))
27@@ -3766,7 +3767,36 @@
28
29 if (text)
30 {
31+ g_strstrip (text);
32+
33+ if (text[0] == '\0')
34+ {
35+ if (priv->message_body->len > 0 &&
36+ priv->message_body->str[priv->message_body->len-1] != '\n')
37+ {
38+ // This is a special combination, that allows us to remember that a
39+ // new empty body line has been requested, but we won't show this till
40+ // something visible will be appended.
41+ g_string_append_c (priv->message_body, '\0');
42+ g_string_append_c (priv->message_body, '\n');
43+ }
44+
45+ g_free (text);
46+ return;
47+ }
48+
49+ if (priv->message_body->len > 1)
50+ {
51+ if (priv->message_body->str[priv->message_body->len-1] == '\n' &&
52+ priv->message_body->str[priv->message_body->len-2] == '\0')
53+ {
54+ // A new message has been appended, let's remove the \0 we put before.
55+ g_string_erase (priv->message_body, priv->message_body->len-2, 1);
56+ }
57+ }
58+
59 // append text to current message-body
60+ g_string_append_c (priv->message_body, '\n');
61 g_string_append (priv->message_body, text);
62 priv->message_body_needs_refresh = TRUE;
63
64
65=== modified file 'src/stack.c'
66--- src/stack.c 2016-04-15 11:52:52 +0000
67+++ src/stack.c 2016-04-15 11:52:53 +0000
68@@ -682,7 +682,6 @@
69 g_object_unref(bubble);
70 bubble = app_bubble;
71 if (body) {
72- bubble_append_message_body (bubble, "\n");
73 bubble_append_message_body (bubble, body);
74 }
75 }

Subscribers

People subscribed via source and target branches