GNOME · GNOME Hispano · Planeta GNOME Hispano · Planet GNOME · Freedesktop · LINUPS · GSyC · LibreSoft

Thu, 07 Apr 2005

Hello Remote World!
13:47

Some days ago, ross posted in his blog a very interesting example of how to do a RPC with DBus/GObject by using the DBus glib bindings. I've taken this example as base for playing with widgets embedded. Basically I've created a label to be embedded in a container. The container also will be able to change the text of the label by doing a method invocation.

The xml file that describes the object is as simple as:

<?xml version="1.0" encoding="UTF-8" ?>
<node name="/org/freedesktop/DBus/Tests/Label">

 <interface name="org.freedesktop.DBus.Tests.Label">
  <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="label"/>

   <method name="GetXid">
    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="label_get_xid"/>
    <arg type="u" name="xid" direction="out"/>
   </method>

   <method name="SetText">
    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="label_set_text"/>
    <arg type="s" name="text" direction="in"/>
   </method>

 </interface>
</node>

The method SetText only changes the current text of the label and the implementation is:

gboolean
label_set_text (Label *label, char *text, GError **error)
{
        gtk_label_set_text (GTK_LABEL (label->label), text);
	gtk_widget_show (label->label);

	return TRUE;
}

The method GetXid is used by the container to obtain the window ID of the label, which is needed to be able to embed it. The code is also very simple:

gboolean
label_get_xid (Label *label, guint32 *xid, GError **error)
{
        *xid = label->xid;

	return TRUE;
}

The container is a window with an entry and a frame. The frame is the real container of the label, and the entry is used to input the text for changing the label. First of all the container invokes the GetXid method in order to obtain the window ID of the label:

if (!org_freedesktop_DBus_Tests_Label_get_xid (proxy, &xid, &error)) {
	die ("Call to get_xid failed", error);
}

When the activate signal of the entry is emitted the callback invokes the SetText method of the label:

static void
on_entry_activate (GtkWidget *entry, gpointer gdata)
{
        DBusGProxy *proxy;
        gchar      *text;
        GError     *error = NULL;

        proxy = (DBusGProxy *) gdata;

        text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));

        if (!org_freedesktop_DBus_Tests_Label_set_text (proxy, text, &error)) {
                g_free (text);
                die ("Call to set_text failed", error);
        }

	g_free (text);
}
Hello Remote World
Hello Remote World

I think it's a first approach for using DBus instead of bonobo

Category: gnome

Sections
   Main (blog)
   Photo Gallery
   Contact
   PGP Key

Calendar
< April 2005 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930

Archives
   May 2008
   Mar 2008
   Dec 2007
   Nov 2007
   Oct 2007
   Sep 2007
   May 2007
   Apr 2007
   Feb 2007
   Jan 2007
   Dec 2006
   Oct 2006
   Sep 2006
   Jun 2006
   Apr 2006
   Mar 2006
   Feb 2006
   Jan 2006
   Dec 2005
   Nov 2005
   Oct 2005
   Sep 2005
   Jul 2005
   Jun 2005
   May 2005
   Apr 2005
   Mar 2005
   Feb 2005
   Jan 2005
   Dec 2004
   Nov 2004
   Oct 2004
   Sep 2004
   Aug 2004
   Jul 2004
   Jun 2004
   May 2004

Friends
   Alvaro del Castillo (acs)
   Alvaro Lopez Ortega (alo)
   Alvaro Peña (apg)
   Arturo Gonzalez (arturogf)
   Ayose Cazorla (setepo)
   Carlos Garnacho
   Carlos Miguelañez (Tuxer)
   Carlos Perelló
   Cesar Alvarez (webbo)
   Eduardo García (kiwnix)
   Esteban Sanchez (steve-o)
   Fernando Herrera (fer)
   German Poo (gpoo)
   Gillermo (daimon)
   Javier Gonzalez (^IcE-bOy^)
   JoAkKiNeN
   Jordi Mallach
   JuanJo Amor
   Juan Pablo Zafra
   Lorenzo Gil Sanchez (lgs)
   Pablo Arroyo (zioma)
   Rodrigo Moya
   Sergio (muttley)
   zordor


rss
Powered by Pyblosxom
Powered by Pyblosxom
Rock is Roll