Merge lp:~midori/midori/abstractBubbles into lp:midori

Proposed by Cris Dywan
Status: Work in progress
Proposed branch: lp:~midori/midori/abstractBubbles
Merge into: lp:midori
Diff against target: 246 lines (+142/-28)
5 files modified
CMakeLists.txt (+1/-0)
midori/midori-app.c (+1/-28)
midori/midori-browser.c (+14/-0)
midori/midori-notification.vala (+125/-0)
po/POTFILES.in (+1/-0)
To merge this branch: bzr merge lp:~midori/midori/abstractBubbles
Reviewer Review Type Date Requested Status
Midori Devs Pending
Review via email: mp+216800@code.launchpad.net

Commit message

Add Notification class abstracting libnotify

To post a comment you must log in.
lp:~midori/midori/abstractBubbles updated
6676. By Cris Dywan

Make Midori.Notification build with GTK+2

6677. By Cris Dywan

Dynamic sizing and placement based on monitor dimensions

6678. By Cris Dywan

Use boxes, labels and an icon for layout

6679. By Cris Dywan

Destroy the bubble after 60 seconds

6680. By Cris Dywan

Use real transfer strings for dummy notification

6681. By Cris Dywan

Leave space between bubble and screen edge

6682. By Cris Dywan

Wrapping, ellipsis and padding

6683. By Cris Dywan

Make the bubble semi-transparent

6684. By Paweł Forysiuk

Make label wrap on gtk3

6685. By Paweł Forysiuk

Don't expand child widgets by default on gtk3

6686. By Paweł Forysiuk

Fix drawing widgets with gtk3, remove some unneded cairo code

6687. By Paweł Forysiuk

Tweak the notifications size a bit

6688. By Paweł Forysiuk

Make positioning of the bubble a little less magical

6689. By Cris Dywan

Set window size rather than widget size

6690. By Cris Dywan

Drop #if hack and broken timeout

Unmerged revisions

6690. By Cris Dywan

Drop #if hack and broken timeout

6689. By Cris Dywan

Set window size rather than widget size

6688. By Paweł Forysiuk

Make positioning of the bubble a little less magical

6687. By Paweł Forysiuk

Tweak the notifications size a bit

6686. By Paweł Forysiuk

Fix drawing widgets with gtk3, remove some unneded cairo code

6685. By Paweł Forysiuk

Don't expand child widgets by default on gtk3

6684. By Paweł Forysiuk

Make label wrap on gtk3

6683. By Cris Dywan

Make the bubble semi-transparent

6682. By Cris Dywan

Wrapping, ellipsis and padding

6681. By Cris Dywan

Leave space between bubble and screen edge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-07-11 01:36:48 +0000
3+++ CMakeLists.txt 2014-08-26 21:42:13 +0000
4@@ -149,6 +149,7 @@
5 pkg_check_modules(NOTIFY REQUIRED libnotify)
6 add_definitions("-DLIBNOTIFY_VERSION=\"${NOTIFY_VERSION}\"")
7 add_definitions("-DHAVE_LIBNOTIFY")
8+ set(VALAFLAGS ${VALAFLAGS} -D HAVE_LIBNOTIFY)
9 set(OPTS_INCLUDE_DIRS "${OPTS_INCLUDE_DIRS};${NOTIFY_INCLUDE_DIRS}")
10 set(OPTS_LIBRARIES "${OPTS_LIBRARIES};${NOTIFY_LIBRARIES}")
11 set(PKGS ${PKGS} libnotify)
12
13=== modified file 'midori/midori-app.c'
14--- midori/midori-app.c 2014-04-14 06:53:01 +0000
15+++ midori/midori-app.c 2014-08-26 21:42:13 +0000
16@@ -34,13 +34,6 @@
17 #include <locale.h>
18 #endif
19
20-#ifdef HAVE_LIBNOTIFY
21- #include <libnotify/notify.h>
22- #ifndef NOTIFY_CHECK_VERSION
23- #define NOTIFY_CHECK_VERSION(x,y,z) 0
24- #endif
25-#endif
26-
27 #ifdef HAVE_SIGNAL_H
28 #include <signal.h>
29 #endif
30@@ -690,10 +683,6 @@
31 app->speeddial = NULL;
32 app->extensions = katze_array_new (KATZE_TYPE_ARRAY);
33 app->browsers = katze_array_new (MIDORI_TYPE_BROWSER);
34-
35- #ifdef HAVE_LIBNOTIFY
36- notify_init (PACKAGE_NAME);
37- #endif
38 }
39
40 static void
41@@ -711,11 +700,6 @@
42 katze_object_assign (app->extensions, NULL);
43 katze_object_assign (app->browsers, NULL);
44
45- #ifdef HAVE_LIBNOTIFY
46- if (notify_is_initted ())
47- notify_uninit ();
48- #endif
49-
50 G_OBJECT_CLASS (midori_app_parent_class)->finalize (object);
51 }
52
53@@ -1129,18 +1113,7 @@
54 g_return_if_fail (MIDORI_IS_APP (app));
55 g_return_if_fail (title);
56
57- #ifdef HAVE_LIBNOTIFY
58- if (notify_is_initted ())
59- {
60- #if NOTIFY_CHECK_VERSION (0, 7, 0)
61- NotifyNotification* note = notify_notification_new (title, message, "midori");
62- #else
63- NotifyNotification* note = notify_notification_new (title, message, "midori", NULL);
64- #endif
65- notify_notification_show (note, NULL);
66- g_object_unref (note);
67- }
68- #endif
69+ midori_notification_show_one (title, message);
70 }
71
72 /**
73
74=== modified file 'midori/midori-browser.c'
75--- midori/midori-browser.c 2014-07-30 17:47:30 +0000
76+++ midori/midori-browser.c 2014-08-26 21:42:13 +0000
77@@ -4850,6 +4850,18 @@
78 }
79
80 static void
81+_action_notify (GtkAction* action,
82+ MidoriBrowser* browser)
83+{
84+ /* Dummy notification using real transfer strings for testing */
85+ gchar* msg = g_strdup_printf (
86+ _("'<b>%s</b>' and %d other files have been downloaded."),
87+ "Kittens being eaten by a stuffed shark.mp4", 7);
88+ g_signal_emit (browser, signals[SEND_NOTIFICATION], 0,
89+ _("Transfer completed"), msg);
90+}
91+
92+static void
93 _action_help_link_activate (GtkAction* action,
94 MidoriBrowser* browser)
95 {
96@@ -5352,6 +5364,8 @@
97 { "About", GTK_STOCK_ABOUT,
98 NULL, "",
99 NULL, G_CALLBACK (_action_about_activate) },
100+ { "Notify", NULL, NULL, NULL,
101+ NULL, G_CALLBACK (_action_notify) },
102 { "Dummy", NULL, N_("_Tools") },
103 };
104 static const guint entries_n = G_N_ELEMENTS (entries);
105
106=== added file 'midori/midori-notification.vala'
107--- midori/midori-notification.vala 1970-01-01 00:00:00 +0000
108+++ midori/midori-notification.vala 2014-08-26 21:42:13 +0000
109@@ -0,0 +1,125 @@
110+/*
111+ Copyright (C) 2014 Christian Dywan <christian@twotoats.de>
112+
113+ This library is free software; you can redistribute it and/or
114+ modify it under the terms of the GNU Lesser General Public
115+ License as published by the Free Software Foundation; either
116+ version 2.1 of the License, or (at your option) any later version.
117+
118+ See the file COPYING for the full license text.
119+*/
120+
121+namespace Midori {
122+ public class Notification {
123+ public string title { get; set; }
124+ public string message { get; set; }
125+
126+#if HAVE_LIBNOTIFY
127+ public Notification (string title, string message) {
128+ if (!Notify.is_initted ())
129+ warn_if_fail (Notify.init (PACKAGE_NAME));
130+ this.title = title;
131+ this.message = message;
132+ }
133+
134+ public bool show () throws Error {
135+ var bubble = (Notify.Notification)GLib.Object.new (
136+ typeof (Notify.Notification),
137+ "summary", title,
138+ "body", message,
139+ "icon-name", PACKAGE_NAME);
140+ return bubble.show ();
141+ }
142+#else
143+ public Notification (string title, string message) {
144+ this.title = title;
145+ this.message = message;
146+ }
147+
148+ public bool show () throws Error {
149+ var bubble = new Gtk.Window (Gtk.WindowType.POPUP);
150+ bubble.decorated = false;
151+ bubble.app_paintable = true;
152+ bubble.skip_taskbar_hint = true;
153+ bubble.title = title;
154+
155+ var screen = Gdk.Screen.get_default ();
156+ Gdk.Rectangle monitor;
157+ screen.get_monitor_geometry (0, out monitor);
158+ int width = monitor.width / 4, height = monitor.height / 6;
159+ bubble.resize (width, height);
160+ int x, y, padding = 32;
161+ x = monitor.width - (width + padding);
162+ y = monitor.height - (height + padding);
163+ bubble.move (x, y);
164+
165+#if HAVE_GTK3
166+ bubble.set_visual (screen.get_rgba_visual());
167+ bubble.draw.connect (window_exposed);
168+#else
169+ bubble.set_colormap (screen.get_rgba_colormap ());
170+ bubble.expose_event.connect (window_exposed);
171+#endif
172+ var hbox = new Gtk.HBox (false, 8);
173+ var icon = new Gtk.Image.from_icon_name (PACKAGE_NAME, Gtk.IconSize.DIALOG);
174+ hbox.pack_start (icon, false, false, 4);
175+ hbox.set_border_width (4);
176+#if HAVE_GTK3
177+ /* Don't set expand on gtk3, it would make child widgets inherit it */
178+ var vbox = new Gtk.VBox (false, 8);
179+#else
180+ var vbox = new Gtk.VBox (true, 8);
181+#endif
182+ var header = new Gtk.Label ("<b>%s</b>".printf(title));
183+ header.ellipsize = Pango.EllipsizeMode.END;
184+ header.use_markup = true;
185+ vbox.pack_start (header, false, false, 4);
186+ var body = new Gtk.Label (message);
187+ /* Wrapping means we can't ellipsize */
188+ body.set_line_wrap (true);
189+ body.set_size_request (width - width / 5, height / 2);
190+#if HAVE_GTK3
191+ /* gtk3 ignores size_request on labels, add some arbitrary max width */
192+ body.set_max_width_chars (40);
193+#endif
194+ body.use_markup = true;
195+ vbox.pack_start (body, false, false, 4);
196+ vbox.set_border_width (4);
197+ hbox.pack_start (vbox, false, false, 4);
198+ bubble.add (hbox);
199+ bubble.show_all ();
200+ return true;
201+ }
202+
203+#if HAVE_GTK3
204+ bool window_exposed (Gtk.Widget bubble, Cairo.Context ctx) {
205+#else
206+ bool window_exposed (Gtk.Widget bubble, Gdk.EventExpose event) {
207+ var ctx = Gdk.cairo_create (bubble.window);
208+#endif
209+ ctx.set_source_rgba (0.9, 0.9, 0.9, 0.7);
210+ ctx.set_operator (Cairo.Operator.SOURCE);
211+ ctx.paint ();
212+ ctx.set_operator (Cairo.Operator.OVER);
213+
214+ var cont = bubble as Gtk.Bin;
215+#if HAVE_GTK3
216+ cont.propagate_draw (cont.get_child (), ctx);
217+#else
218+ cont.propagate_expose (cont.get_child (), event);
219+#endif
220+ return true;
221+ }
222+#endif
223+
224+ public static void show_one (string title, string message) {
225+ var bubble = new Notification (title, message);
226+ try {
227+ bubble.show ();
228+ } catch (Error error) {
229+ warning (error.message);
230+ }
231+ }
232+ }
233+}
234+
235
236=== modified file 'po/POTFILES.in'
237--- po/POTFILES.in 2014-04-28 16:32:22 +0000
238+++ po/POTFILES.in 2014-08-26 21:42:13 +0000
239@@ -82,6 +82,7 @@
240 midori/midori-bookmarks-db.c
241 midori/midori-session.c
242 extensions/nsplugin-manager.vala
243+midori/midori-notification.vala
244 midori/midori-frontend.c
245 extensions/cookie-permissions/cookie-permission-manager-preferences-window.c
246 extensions/cookie-permissions/cookie-permission-manager-preferences-window.h

Subscribers

People subscribed via source and target branches

to all changes: