~ubuntu-branches/ubuntu/precise/rhythmbox/precise-201203091205

« back to all changes in this revision

Viewing changes to remote/bonobo/test-corba.c

Tags: upstream-0.9.5
ImportĀ upstreamĀ versionĀ 0.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  arch-tag: Simple program to test bonobo notification from rhythmbox
3
 
 */
4
 
 
5
 
#include <stdlib.h>
6
 
#include <libbonobo.h>
7
 
#include "Rhythmbox.h"
8
 
 
9
 
#define RB_IID "OAFIID:GNOME_Rhythmbox"
10
 
 
11
 
 
12
 
static void
13
 
on_bonobo_event (BonoboListener *listener, const char *event_name,
14
 
                 const CORBA_any *any, CORBA_Environment *ev,
15
 
                 gpointer user_data)
16
 
{
17
 
        g_print ("event received: %s\n", event_name);
18
 
}
19
 
 
20
 
static void
21
 
on_song_change (BonoboListener *listener, const char *event_name,
22
 
                const CORBA_any *any, CORBA_Environment *ev,
23
 
                gpointer user_data)
24
 
{
25
 
        GNOME_Rhythmbox_SongInfo *song_info;
26
 
 
27
 
        if (!CORBA_TypeCode_equivalent (any->_type, 
28
 
                                        TC_GNOME_Rhythmbox_SongInfo, 
29
 
                                        NULL)) { 
30
 
                g_warning ("Unexpected type\n");
31
 
        }
32
 
        song_info = (GNOME_Rhythmbox_SongInfo *)any->_value;
33
 
        if (song_info == NULL) {
34
 
                g_warning ("Unexpected error\n");
35
 
        }
36
 
        g_print ("Now Playing:\n");
37
 
        g_print ("Title: %s\n", song_info->title);
38
 
        g_print ("Artist: %s\n", song_info->artist);
39
 
        g_print ("Album: %s\n", song_info->album);
40
 
        g_print ("Bitrate: %u bps\n", song_info->bitrate);
41
 
        g_print ("Length: %u\n", song_info->duration);
42
 
}
43
 
 
44
 
int 
45
 
main (int argc, char *argv [])
46
 
{
47
 
        GNOME_Rhythmbox rb;
48
 
        CORBA_Environment  ev;
49
 
        Bonobo_PropertyBag pb;
50
 
 
51
 
        /*
52
 
         * Initialize bonobo.
53
 
         */
54
 
        if (!bonobo_init (&argc, argv))
55
 
                g_error ("Could not initialize Bonobo");
56
 
        
57
 
        CORBA_exception_init (&ev);
58
 
        rb = bonobo_activation_activate_from_id (RB_IID, 0, NULL, &ev);
59
 
 
60
 
 
61
 
        if (rb == CORBA_OBJECT_NIL) {
62
 
                g_warning ("Could not create an instance of Rhythmbox");
63
 
                return bonobo_debug_shutdown ();
64
 
        }
65
 
        CORBA_exception_init (&ev);
66
 
 
67
 
        pb = GNOME_Rhythmbox_getPlayerProperties (rb, &ev);
68
 
        if (BONOBO_EX (&ev)) {
69
 
                char *err = bonobo_exception_get_text (&ev);
70
 
                g_warning ("An exception occured '%s'", err);
71
 
                g_free (err);
72
 
                exit (1);
73
 
        }
74
 
 
75
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
76
 
                                                 "Bonobo/Property:change:repeat",
77
 
                                                 &ev, NULL);
78
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
79
 
                                                 "Bonobo/Property:change:shuffle",
80
 
                                                 &ev, NULL);
81
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
82
 
                                                 "Bonobo/Property:change:playing",
83
 
                                                 &ev, NULL);
84
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
85
 
                                                 "Bonobo/Property:change:visibility",
86
 
                                                 &ev, NULL);
87
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
88
 
                                                 "Bonobo/Property:change:play-order",
89
 
                                                 &ev, NULL);
90
 
        bonobo_event_source_client_add_listener (pb, on_bonobo_event,
91
 
                                                 "Bonobo/Property:change:volume",
92
 
                                                 &ev, NULL);
93
 
        bonobo_event_source_client_add_listener (pb, on_song_change,
94
 
                                                 "Bonobo/Property:change:song",
95
 
                                                 &ev, NULL);
96
 
 
97
 
        if (BONOBO_EX (&ev)) {
98
 
                char *err = bonobo_exception_get_text (&ev);
99
 
                g_warning ("An exception occured '%s'", err);
100
 
                g_free (err);
101
 
                exit (1);
102
 
        }
103
 
 
104
 
 
105
 
        bonobo_main ();
106
 
        
107
 
        CORBA_exception_free (&ev);
108
 
 
109
 
        bonobo_object_release_unref (rb, NULL);
110
 
 
111
 
        return bonobo_debug_shutdown ();
112
 
}