1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
3
* arch-tag: Simple program to test bonobo notification from rhythmbox
11
#define RB_IID "OAFIID:GNOME_Rhythmbox"
13
#define COMMAND_PLAY "play"
14
#define COMMAND_PAUSE "pause"
15
#define COMMAND_SHUFFLE "shuffle"
16
#define COMMAND_REPEAT "repeat"
17
#define COMMAND_NEXT "next"
18
#define COMMAND_PREVIOUS "previous"
19
#define COMMAND_SEEK_FORWARD "seek_forward"
20
#define COMMAND_SEEK_BACKWARD "seek_backward"
21
#define COMMAND_VOLUME_UP "volume_up"
22
#define COMMAND_VOLUME_DOWN "volume_down"
23
#define COMMAND_RATE_UP "rate_up"
24
#define COMMAND_RATE_DOWN "rate_down"
25
#define COMMAND_MUTE "mute"
26
#define COMMAND_QUIT "quit"
27
#define COMMAND_POWER "power"
30
on_bonobo_event (BonoboListener *listener, const char *event_name,
31
const CORBA_any *any, CORBA_Environment *ev,
34
g_print ("event received: %s\n", event_name);
38
on_song_change (BonoboListener *listener, const char *event_name,
39
const CORBA_any *any, CORBA_Environment *ev,
42
GNOME_Rhythmbox_SongInfo *song_info;
44
if (!CORBA_TypeCode_equivalent (any->_type,
45
TC_GNOME_Rhythmbox_SongInfo,
47
g_warning ("Unexpected type\n");
49
song_info = (GNOME_Rhythmbox_SongInfo *)any->_value;
50
if (song_info == NULL) {
51
g_warning ("Unexpected error\n");
53
g_print ("Now Playing:\n");
54
g_print ("Title: %s\n", song_info->title);
55
g_print ("Artist: %s\n", song_info->artist);
56
g_print ("Album: %s\n", song_info->album);
57
g_print ("Bitrate: %u bps\n", song_info->bitrate);
58
g_print ("Length: %u\n", song_info->duration);
59
g_print ("Rating: %u\n", song_info->rating);
63
changeRating (GNOME_Rhythmbox rb, int ratingChange)
66
Bonobo_PropertyBag pb;
67
GNOME_Rhythmbox_SongInfo *song_info;
70
CORBA_exception_init (&ev);
71
pb = GNOME_Rhythmbox_getPlayerProperties (rb, &ev);
73
any = Bonobo_PropertyBag_getValue (pb, "song", &ev);
75
if (!CORBA_TypeCode_equivalent (any->_type,
76
TC_GNOME_Rhythmbox_SongInfo,
78
g_warning ("Unexpected type\n");
80
song_info = (GNOME_Rhythmbox_SongInfo *)any->_value;
81
if (song_info == NULL) {
82
g_warning ("Unexpected error\n");
85
GNOME_Rhythmbox_setRating (rb, song_info->rating + ratingChange, &ev);
87
CORBA_exception_free (&ev);
91
main (int argc, char *argv [])
95
Bonobo_PropertyBag pb;
100
if (!bonobo_init (&argc, argv))
101
g_error ("Could not initialize Bonobo");
103
CORBA_exception_init (&ev);
104
rb = bonobo_activation_activate_from_id (RB_IID, 0, NULL, &ev);
105
if (rb == CORBA_OBJECT_NIL) {
106
g_warning ("Could not create an instance of Rhythmbox");
107
return bonobo_debug_shutdown ();
112
for (arg = 0; arg < argc; arg++) {
113
CORBA_exception_init (&ev);
114
if (strcmp (argv[arg], COMMAND_PLAY) == 0) {
115
GNOME_Rhythmbox_playPause (rb, &ev);
116
} else if (strcmp (argv[arg], COMMAND_PAUSE) == 0) {
117
GNOME_Rhythmbox_playPause (rb, &ev);
118
} else if (strcmp (argv[arg], COMMAND_SHUFFLE) == 0) {
119
} else if (strcmp (argv[arg], COMMAND_REPEAT) == 0) {
120
} else if (strcmp (argv[arg], COMMAND_NEXT) == 0) {
121
GNOME_Rhythmbox_next (rb, &ev);
122
} else if (strcmp (argv[arg], COMMAND_PREVIOUS) == 0) {
123
GNOME_Rhythmbox_previous (rb, &ev);
124
} else if (strcmp (argv[arg], COMMAND_SEEK_FORWARD) == 0) {
125
GNOME_Rhythmbox_skip (rb, 5, &ev);
126
} else if (strcmp (argv[arg], COMMAND_SEEK_BACKWARD) == 0) {
127
GNOME_Rhythmbox_skip (rb, -5, &ev);
128
} else if (strcmp (argv[arg], COMMAND_VOLUME_UP) == 0) {
129
GNOME_Rhythmbox_volumeUp (rb, &ev);
130
} else if (strcmp (argv[arg], COMMAND_VOLUME_DOWN) == 0) {
131
GNOME_Rhythmbox_volumeDown (rb, &ev);
132
} else if (strcmp (argv[arg], COMMAND_RATE_UP) == 0) {
133
changeRating (rb, 1);
134
} else if (strcmp (argv[arg], COMMAND_RATE_DOWN) == 0) {
135
changeRating (rb, -1);
136
} else if (strcmp (argv[arg], COMMAND_MUTE) == 0) {
137
GNOME_Rhythmbox_toggleMute (rb, &ev);
138
} else if (strcmp (argv[arg], COMMAND_QUIT) == 0) {
139
GNOME_Rhythmbox_quit (rb, &ev);
140
} else if (strcmp (argv[arg], COMMAND_POWER) == 0) {
141
GNOME_Rhythmbox_toggleHide (rb, &ev);
143
CORBA_exception_free (&ev);
145
return bonobo_debug_shutdown ();
148
CORBA_exception_init (&ev);
149
pb = GNOME_Rhythmbox_getPlayerProperties (rb, &ev);
150
if (BONOBO_EX (&ev)) {
151
char *err = bonobo_exception_get_text (&ev);
152
g_warning ("An exception occured '%s'", err);
157
bonobo_event_source_client_add_listener (pb, on_bonobo_event,
158
"Bonobo/Property:change:repeat",
160
bonobo_event_source_client_add_listener (pb, on_bonobo_event,
161
"Bonobo/Property:change:shuffle",
163
bonobo_event_source_client_add_listener (pb, on_bonobo_event,
164
"Bonobo/Property:change:playing",
166
bonobo_event_source_client_add_listener (pb, on_song_change,
167
"Bonobo/Property:change:song",
170
if (BONOBO_EX (&ev)) {
171
char *err = bonobo_exception_get_text (&ev);
172
g_warning ("An exception occured '%s'", err);
180
CORBA_exception_free (&ev);
182
bonobo_object_release_unref (rb, NULL);
184
return bonobo_debug_shutdown ();