[GnomeMeeting-devel-list] Re: Gnomemeeting remote control through DBUS



Le dim, 15/08/2004 à 01:33 +0200, PUYDT Julien a écrit :
> * gm_remote.c and a little Makefile to help compile it;

Here they come.

Snark
#include <gtk/gtk.h>
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus-glib.h>

#define OBJECT "/org/gnomemeeting/Endpoint"
#define INTERFACE "org.gnomemeeting.CallService"
#define SERVICE "org.gnomemeeting.CallService"


struct needed_data {
  DBusConnection *connection;
  GtkWidget *window;
  GtkWidget *entry;
};


static void
connect_button_cb (GtkButton *button, gpointer user_data)
{
  struct needed_data *my_data = (struct needed_data *)user_data;
  DBusMessage *message = NULL;

  message = dbus_message_new_method_call (SERVICE, OBJECT, 
					  INTERFACE, "Call");
  (void)dbus_message_append_args (message,
				  DBUS_TYPE_STRING,
				  gtk_entry_get_text (GTK_ENTRY (my_data->entry)),
				  DBUS_TYPE_INVALID);
  dbus_message_set_no_reply (message, TRUE);
  (void)dbus_connection_send (my_data->connection, message,NULL);
  dbus_connection_flush (my_data->connection);
  dbus_message_unref (message);
}


static void
disconnect_button_cb (GtkButton *button, gpointer user_data)
{
  struct needed_data *my_data = (struct needed_data *)user_data;
  DBusMessage *message = NULL;

  message = dbus_message_new_method_call (SERVICE, OBJECT, 
					  INTERFACE, "EndCall");
  dbus_message_set_no_reply (message, TRUE);
  (void)dbus_connection_send (my_data->connection, message, NULL);
  dbus_connection_flush (my_data->connection);
  dbus_message_unref (message);
}


static void
update_status_button_cb (GtkButton *button, gpointer user_data)
{
  struct needed_data *my_data = (struct needed_data *)user_data;
  DBusMessage *message = NULL;
  DBusMessage *reply = NULL;
  DBusPendingCall *call = NULL;
  gchar *title = NULL;

  message = dbus_message_new_method_call (SERVICE, OBJECT, 
					  INTERFACE, "GetState");
  dbus_message_set_no_reply (message, FALSE);
  (void)dbus_connection_send_with_reply (my_data->connection, message,
					 &call, -1);
  dbus_connection_flush (my_data->connection);

  dbus_pending_call_block (call);
  reply = dbus_pending_call_get_reply (call);
  if (dbus_message_get_args (reply, NULL,
                             DBUS_TYPE_STRING, &title,
                             DBUS_TYPE_INVALID)) {
    gtk_window_set_title (GTK_WINDOW (my_data->window), title);
    g_free (title);
  }
  
  dbus_message_unref (message);
  dbus_message_unref (reply);
  dbus_pending_call_unref (call);
}


static void
quit_button_cb (GtkButton *button, gpointer user_data)
{
  gtk_main_quit ();
}


int main (int argc,
	  char *argv[])
{
  struct needed_data *my_data = NULL;
  GtkWidget *window = NULL;
  GtkWidget *vbox = NULL;
  GtkWidget *connect_button = NULL;
  GtkWidget *disconnect_button = NULL;
  GtkWidget *update_status_button = NULL;
  GtkWidget *quit_button = NULL;
  GtkWidget *hbox = NULL;
  GtkWidget *entry = NULL;

  gtk_set_locale ();

  gtk_init (&argc, &argv);

  my_data = g_new0 (struct needed_data, 1);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (window, "delete-event",
                    G_CALLBACK (gtk_false), NULL);
  g_signal_connect (window, "destroy",
		    G_CALLBACK (gtk_main_quit), NULL);
  gtk_window_set_title (GTK_WINDOW (window), "Unknown");

  vbox = gtk_vbox_new (TRUE, 2);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  entry = gtk_entry_new ();
  gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (entry), TRUE, TRUE, 2);

  hbox = gtk_hbox_new (TRUE, 2);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 2);

  connect_button = gtk_button_new_with_label ("Connect");
  g_signal_connect (G_OBJECT (connect_button), "clicked",
		    G_CALLBACK (connect_button_cb), my_data);
  gtk_box_pack_start (GTK_BOX (hbox), connect_button, TRUE, TRUE, 2);

  disconnect_button = gtk_button_new_with_label ("Disconnect");
  g_signal_connect (G_OBJECT (disconnect_button), "clicked",
		    G_CALLBACK (disconnect_button_cb), my_data);
  gtk_box_pack_start (GTK_BOX (hbox), disconnect_button, TRUE, TRUE, 2);

  update_status_button = gtk_button_new_with_label ("Update");
  g_signal_connect (G_OBJECT (update_status_button), "clicked",
		    G_CALLBACK (update_status_button_cb), my_data);
  gtk_box_pack_start (GTK_BOX (hbox), update_status_button, TRUE, TRUE, 2);

  quit_button = gtk_button_new_with_label ("Quit");
  g_signal_connect (G_OBJECT (quit_button), "clicked",
		    G_CALLBACK (quit_button_cb), my_data);
  gtk_box_pack_start (GTK_BOX (hbox), quit_button, TRUE, TRUE, 2);

  gtk_widget_show_all (window);

  my_data->window = window;
  my_data->entry = entry;
  my_data->connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);

  gtk_main ();

  return 0;
}
TARGETS = gm_remote

CC=gcc
CFLAGS = `pkg-config --cflags dbus-glib-1 glib-2.0 gtk+-2.0`
LDFLAGS = `pkg-config --libs dbus-glib-1 glib-2.0 gtk+-2.0`

all: $(TARGETS)

%: %.o

clean:
	rm -f *~ $(TARGETS)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]