1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*
Copyright 2011 Canonical Ltd.
Authors:
Conor Curran <conor.curran@canonical.com>
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3, as published
by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranties of
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sound-state-manager.h"
typedef struct _SoundStateManagerPrivate SoundStateManagerPrivate;
struct _SoundStateManagerPrivate
{
GDBusProxy* dbus_proxy;
GHashTable* volume_states;
GList* blocked_animation_list;
};
#define SOUND_STATE_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_TYPE_STATE_MANAGER, SoundStateManagerPrivate))
static GtkImage *speaker_image = NULL;
static gint current_state = 0;
static gint previous_state = 0;
static GtkIconSize design_team_size;
static gint blocked_id;
static gint animation_id;
static GList * blocked_animation_list = NULL;
static GList * blocked_iter = NULL;
static void prepare_blocked_animation();
static gboolean fade_back_to_mute_image();
static gboolean start_animation();
static void reset_mute_blocking_animation();
static void free_the_animation_list();
G_DEFINE_TYPE (SoundStateManager, sound_state_manager, G_TYPE_OBJECT);
static void
sound_state_manager_init (SoundStateManager *object)
{
/* TODO: Add initialization code here */
}
static void
sound_state_manager_finalize (GObject *object)
{
/* TODO: Add deinitalization code here */
G_OBJECT_CLASS (sound_state_manager_parent_class)->finalize (object);
}
static void
sound_state_manager_class_init (SoundStateManagerClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
GObjectClass* parent_class = G_OBJECT_CLASS (klass);
object_class->finalize = sound_state_manager_finalize;
}
/*
Prepare states Array.
*/
void
sound_state_manager_prepare_state_machine(SoundStateManager* self)
{
SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self);
priv->volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(MUTED), g_strdup("audio-volume-muted-panel"));
g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(ZERO_LEVEL), g_strdup("audio-volume-low-zero-panel"));
g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(LOW_LEVEL), g_strdup("audio-volume-low-panel"));
g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(MEDIUM_LEVEL), g_strdup("audio-volume-medium-panel"));
g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(HIGH_LEVEL), g_strdup("audio-volume-high-panel"));
g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(BLOCKED), g_strdup("audio-volume-muted-blocking-panel"));
g_hash_table_insert(priv->volume_states, GINT_TO_POINTER(UNAVAILABLE), g_strdup("audio-output-none-panel"));
}
/*
prepare_blocked_animation:
Prepares the array of images to be used in the blocked animation.
Only called at startup.
*/
static void
sound_state_manager_prepare_blocked_animation(SoundStateManager* self)
{
SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self);
gchar* blocked_name = g_hash_table_lookup(priv->volume_states,
GINT_TO_POINTER(BLOCKED));
gchar* muted_name = g_hash_table_lookup(priv->volume_states,
GINT_TO_POINTER(MUTED));
GtkImage* temp_image = indicator_image_helper(muted_name);
GdkPixbuf* mute_buf = gtk_image_get_pixbuf(temp_image);
temp_image = indicator_image_helper(blocked_name);
GdkPixbuf* blocked_buf = gtk_image_get_pixbuf(temp_image);
if (mute_buf == NULL || blocked_buf == NULL) {
//g_debug("Don bother with the animation, the theme aint got the goods !");
return;
}
int i;
// sample 51 snapshots - range : 0-256
for (i = 0; i < 51; i++) {
gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0,
gdk_pixbuf_get_width(mute_buf),
gdk_pixbuf_get_height(mute_buf),
0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 5));
priv->blocked_animation_list = g_list_append(priv->blocked_animation_list,
gdk_pixbuf_copy(blocked_buf));
}
g_object_ref_sink(mute_buf);
g_object_unref(mute_buf);
g_object_ref_sink(blocked_buf);
g_object_unref(blocked_buf);
}
void
sound_state_manager_tidy_up_hash()
{
g_hash_table_destroy(volume_states);
}
gchar*
sound_state_manager_get_current_icon_name (SoundStateManager* self)
{
SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self);
return g_hash_table_lookup (priv->volume_states,
GINT_TO_POINTER(priv->current_state));
}
static void g_signal_cb ( GDBusProxy* proxy,
gchar* sender_name,
gchar* signal_name,
GVariant* parameters,
gpointer user_data)
{
}
static void
sound_state_manager_style_changed_cb(GtkWidget *widget, gpointer user_data)
{
//g_debug("Just caught a style change event");
update_state(current_state);
reset_mute_blocking_animation();
update_state(current_state);
free_the_animation_list();
prepare_blocked_animation();
}
/**
* volume_widget_new:
* @returns: a new #VolumeWidget.
**/
SoundStateManager*
sound_state_manager_new (GDProxy* proxy)
{
SoundStateManager* manager = g_object_new (SOUND_TYPE_STATE_MANAGER, NULL);
SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(manager);
priv->dbus_proxy = proxy;
return manager;
}
|