1 /* Copyright 2011 by Kohei Takahashi
2 * modification, are permitted provided that the following conditions are met:
3 *
4 * 1. Redistributions of source code must retain the above copyright notice,
5 * this list of conditions and the following disclaimer.
6 * 2. Redistributions in binary form must reproduce the above copyright notice,
7 * this list of conditions and the following disclaimer in the documentation
8 * and/or other materials provided with the distribution.
9 *
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
14 * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
15 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
21 * OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23
24 #include <gtk/gtk.h>
25 #ifdef _WIN32
26 # include <gdk/gdkwin32.h>
27 #endif
28
29 #include <libnotify/notify.h>
30
31 #include "gol.h"
32 #include "plugins/from_url.h"
33
34 #include "display_libnotify.xpm"
35
36 G_MODULE_EXPORT gboolean
display_init()37 display_init() {
38 return notify_init("Growl for Linux");
39 }
40
41 G_MODULE_EXPORT void
display_term()42 display_term() {
43 notify_uninit();
44 }
45
46 static gchar*
get_icon_path_if_local(const NOTIFICATION_INFO * ni)47 get_icon_path_if_local(const NOTIFICATION_INFO* ni) {
48 if (!ni->local || !ni->icon) return NULL;
49
50 gchar* const icon_path = g_filename_from_uri(ni->icon, NULL, NULL);
51 return icon_path ? icon_path : g_strdup(ni->icon);
52 }
53
54 G_MODULE_EXPORT gboolean
display_show(gpointer data)55 display_show(gpointer data) {
56 const NOTIFICATION_INFO* const ni = (const NOTIFICATION_INFO*) data;
57
58 gchar* const icon_path = get_icon_path_if_local(ni);
59 gchar* const text = g_markup_escape_text(ni->text, -1);
60 #ifdef NOTIFY_CHECK_VERSION
61 # if NOTIFY_CHECK_VERSION (0, 7, 0)
62 NotifyNotification* const nt = notify_notification_new(ni->title, text, icon_path);
63 # else
64 NotifyNotification* const nt = notify_notification_new(ni->title, text, icon_path, NULL);
65 # endif
66 #else
67 NotifyNotification* const nt = notify_notification_new(ni->title, text, icon_path, NULL);
68 #endif
69 g_free(icon_path);
70 g_free(text);
71
72 GdkPixbuf* const pixbuf = !ni->local ? pixbuf_from_url(ni->icon, NULL) : NULL;
73 if (pixbuf) {
74 notify_notification_set_icon_from_pixbuf(nt, pixbuf);
75 g_object_unref(pixbuf);
76 }
77
78 if (ni->sticky)
79 notify_notification_set_urgency(nt, NOTIFY_URGENCY_CRITICAL);
80
81 GError* error = NULL;
82 if (!notify_notification_show(nt, &error))
83 {
84 g_warning("%s: %s", G_STRFUNC, error->message);
85 g_error_free(error);
86 }
87
88 return FALSE;
89 }
90
91 G_MODULE_EXPORT const gchar*
display_name()92 display_name() {
93 return "libnotify";
94 }
95
96 G_MODULE_EXPORT const gchar*
display_description()97 display_description() {
98 return
99 "<span size=\"large\"><b>libnotify</b></span>\n"
100 "<span>This is gateway and delegating notification to libnotify.</span>\n"
101 "<span>For more detail, see <a href=\"https://launchpad.net/notify-osd\">here</a>"
102 " and reference manual is <a href=\"http://developer.gnome.org/libnotify/\">here</a>.</span>\n";
103 }
104
105 G_MODULE_EXPORT char**
display_thumbnail()106 display_thumbnail() {
107 return display_libnotify;
108 }
109
110 // vim:set et sw=2 ts=2 ai:
111