Line 0
Link Here
|
|
|
1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
2 |
* |
3 |
* Copyright (C) 2009 Canonical Ltd |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
7 |
* the Free Software Foundation; either version 2 of the License, or |
8 |
* (at your option) any later version. |
9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
* GNU General Public License for more details. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
* |
19 |
*/ |
20 |
|
21 |
#include <libnotify/notify.h> |
22 |
#include <glib/gi18n.h> |
23 |
|
24 |
gboolean |
25 |
gsd_media_keys_notification_check_service (void) |
26 |
{ |
27 |
GList * caps = NULL; |
28 |
gchar *name = NULL, *vendor = NULL, *version = NULL, *specver = NULL; |
29 |
gboolean compat = FALSE; |
30 |
|
31 |
if (! notify_is_initted()) |
32 |
notify_init ("gnome-settings-daemon"); |
33 |
|
34 |
if (! notify_get_server_info (&name, &vendor, &version, &specver)) |
35 |
{ |
36 |
g_debug ("unable to reach notification service"); |
37 |
return FALSE; |
38 |
} |
39 |
|
40 |
caps = notify_get_server_caps(); |
41 |
if (g_list_find_custom (caps, |
42 |
"private-synchronous", |
43 |
(GCompareFunc) g_strcmp0) != NULL) |
44 |
compat = TRUE; |
45 |
|
46 |
g_list_foreach(caps, (GFunc)g_free, NULL); |
47 |
g_list_free(caps); |
48 |
|
49 |
if (! compat) |
50 |
g_debug ("the service does not support the 'synchronous' capability"); |
51 |
|
52 |
g_free (name); g_free (vendor); g_free (version); g_free (specver); |
53 |
|
54 |
return compat; |
55 |
} |
56 |
|
57 |
static const char *icon_name[] = { |
58 |
"notification-audio-volume-muted", |
59 |
/* "notification-audio-volume-off", */ |
60 |
"notification-audio-volume-low", |
61 |
"notification-audio-volume-medium", |
62 |
"notification-audio-volume-high", |
63 |
NULL |
64 |
}; |
65 |
|
66 |
|
67 |
gboolean |
68 |
gsd_media_keys_notification_volume (int value, gboolean muted) |
69 |
{ |
70 |
static NotifyNotification *n = NULL; |
71 |
int s; |
72 |
|
73 |
if (! gsd_media_keys_notification_check_service ()) |
74 |
return FALSE; |
75 |
|
76 |
if (n == NULL) |
77 |
n = notify_notification_new (_("Volume"), |
78 |
"", |
79 |
NULL, |
80 |
NULL); |
81 |
if (value < 0) |
82 |
{ |
83 |
value = 0; /* notify-osd doesn't like -1 */ |
84 |
s = 0; /* off, ie with the undershoot effect */ |
85 |
} else { |
86 |
s = 3 * value / 100 + 1; |
87 |
if (s < 1) |
88 |
s = 1; |
89 |
if (s > 3) |
90 |
s = 3; |
91 |
} |
92 |
|
93 |
if (muted) |
94 |
s = 0; |
95 |
|
96 |
notify_notification_update (n, |
97 |
_("Volume"), |
98 |
"", |
99 |
icon_name[s]); |
100 |
|
101 |
notify_notification_set_hint_int32(n, "value", value); |
102 |
notify_notification_set_hint_string(n, "synchronous", "volume"); |
103 |
|
104 |
notify_notification_show (n, NULL); |
105 |
|
106 |
return TRUE; |
107 |
} |
108 |
|
109 |
gboolean |
110 |
gsd_media_keys_notification_eject (void) |
111 |
{ |
112 |
static NotifyNotification *n = NULL; |
113 |
|
114 |
if (! gsd_media_keys_notification_check_service ()) |
115 |
return FALSE; |
116 |
|
117 |
if (n == NULL) |
118 |
{ |
119 |
n = notify_notification_new ("Eject", |
120 |
"", |
121 |
"notification-device-eject", |
122 |
NULL); |
123 |
notify_notification_set_hint_string(n, "synchronous", "eject"); |
124 |
notify_notification_set_hint_string (n, |
125 |
"icon-only", |
126 |
"allowed"); |
127 |
} |
128 |
|
129 |
notify_notification_show (n, NULL); |
130 |
|
131 |
return TRUE; |
132 |
} |