~ubuntu-branches/ubuntu/utopic/rhythmbox/utopic-proposed

« back to all changes in this revision

Viewing changes to corba/test-corba.c

Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
 
/*
3
 
 *  arch-tag: Simple program to test bonobo notification from rhythmbox
4
 
 */
5
 
 
6
 
#include <stdlib.h>
7
 
#include <string.h>
8
 
#include <libbonobo.h>
9
 
#include "Rhythmbox.h"
10
 
 
11
 
#define RB_IID "OAFIID:GNOME_Rhythmbox"
12
 
 
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"
28
 
 
29
 
static void
30
 
on_bonobo_event (BonoboListener *listener, const char *event_name,
31
 
                 const CORBA_any *any, CORBA_Environment *ev,
32
 
                 gpointer user_data)
33
 
{
34
 
        g_print ("event received: %s\n", event_name);
35
 
}
36
 
 
37
 
static void
38
 
on_song_change (BonoboListener *listener, const char *event_name,
39
 
                const CORBA_any *any, CORBA_Environment *ev,
40
 
                gpointer user_data)
41
 
{
42
 
        GNOME_Rhythmbox_SongInfo *song_info;
43
 
 
44
 
        if (!CORBA_TypeCode_equivalent (any->_type, 
45
 
                                        TC_GNOME_Rhythmbox_SongInfo, 
46
 
                                        NULL)) { 
47
 
                g_warning ("Unexpected type\n");
48
 
        }
49
 
        song_info = (GNOME_Rhythmbox_SongInfo *)any->_value;
50
 
        if (song_info == NULL) {
51
 
                g_warning ("Unexpected error\n");
52
 
        }
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);
60
 
}
61
 
 
62
 
static void 
63
 
changeRating (GNOME_Rhythmbox rb, int ratingChange)
64
 
{
65
 
        CORBA_Environment  ev;
66
 
        Bonobo_PropertyBag pb;
67
 
        GNOME_Rhythmbox_SongInfo *song_info;
68
 
        CORBA_any *any;
69
 
 
70
 
        CORBA_exception_init (&ev);
71
 
        pb = GNOME_Rhythmbox_getPlayerProperties (rb, &ev);
72
 
 
73
 
        any = Bonobo_PropertyBag_getValue (pb, "song", &ev);
74
 
 
75
 
        if (!CORBA_TypeCode_equivalent (any->_type, 
76
 
                                        TC_GNOME_Rhythmbox_SongInfo, 
77
 
                                        NULL)) { 
78
 
                g_warning ("Unexpected type\n");
79
 
        }
80
 
        song_info = (GNOME_Rhythmbox_SongInfo *)any->_value;
81
 
        if (song_info == NULL) {
82
 
                g_warning ("Unexpected error\n");
83
 
        }
84
 
 
85
 
        GNOME_Rhythmbox_setRating (rb, song_info->rating + ratingChange, &ev);
86
 
 
87
 
        CORBA_exception_free (&ev);
88
 
}
89
 
 
90
 
int 
91
 
main (int argc, char *argv [])
92
 
{
93
 
        GNOME_Rhythmbox rb;
94
 
        CORBA_Environment  ev;
95
 
        Bonobo_PropertyBag pb;
96
 
 
97
 
        /*
98
 
         * Initialize bonobo.
99
 
         */
100
 
        if (!bonobo_init (&argc, argv))
101
 
                g_error ("Could not initialize Bonobo");
102
 
        
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 ();
108
 
        }
109
 
 
110
 
        if (argc > 1) {
111
 
                int arg;
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);
142
 
                        }
143
 
                        CORBA_exception_free (&ev);
144
 
                }
145
 
                return bonobo_debug_shutdown ();
146
 
        } 
147
 
 
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);
153
 
                g_free (err);
154
 
                exit (1);
155
 
        }
156
 
 
157
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
158
 
                                                 "Bonobo/Property:change:repeat",
159
 
                                                 &ev, NULL);
160
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
161
 
                                                 "Bonobo/Property:change:shuffle",
162
 
                                                 &ev, NULL);
163
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
164
 
                                                 "Bonobo/Property:change:playing",
165
 
                                                 &ev, NULL);
166
 
        bonobo_event_source_client_add_listener (pb, on_song_change,
167
 
                                                 "Bonobo/Property:change:song",
168
 
                                                 &ev, NULL);
169
 
 
170
 
        if (BONOBO_EX (&ev)) {
171
 
                char *err = bonobo_exception_get_text (&ev);
172
 
                g_warning ("An exception occured '%s'", err);
173
 
                g_free (err);
174
 
                exit (1);
175
 
        }
176
 
 
177
 
 
178
 
        bonobo_main ();
179
 
        
180
 
        CORBA_exception_free (&ev);
181
 
 
182
 
        bonobo_object_release_unref (rb, NULL);
183
 
 
184
 
        return bonobo_debug_shutdown ();
185
 
}