cheese r797 - in branches/cheese-dbus: . client src
- From: kaserf svn gnome org
- To: svn-commits-list gnome org
- Subject: cheese r797 - in branches/cheese-dbus: . client src
- Date: Sat, 12 Jul 2008 14:26:40 +0000 (UTC)
Author: kaserf
Date: Sat Jul 12 14:26:40 2008
New Revision: 797
URL: http://svn.gnome.org/viewvc/cheese?rev=797&view=rev
Log:
Improved the client, it's finished for now (just an example). Click on the button, take a picture with cheese and see what happens!
Added:
branches/cheese-dbus/client/waiting_dummy.jpeg (contents, props changed)
Modified:
branches/cheese-dbus/ChangeLog
branches/cheese-dbus/client/dbus_client.c
branches/cheese-dbus/src/cheese-dbus.c
Modified: branches/cheese-dbus/client/dbus_client.c
==============================================================================
--- branches/cheese-dbus/client/dbus_client.c (original)
+++ branches/cheese-dbus/client/dbus_client.c Sat Jul 12 14:26:40 2008
@@ -5,33 +5,65 @@
#include <glib-object.h>
#include <unistd.h>
#include <stdlib.h>
+#include <gtk/gtk.h>
+#include <glib/gstdio.h>
+#include <stdio.h>
+#include <errno.h>
+
+GdkPixbuf *pixbuf;
+GError *error = NULL;
+GtkWidget *window;
+GtkWidget *frame;
+GtkWidget *image;
+GtkWidget *button;
-static GMainLoop *loop = NULL;
+static void
+set_active (GtkContainer *container, gboolean state)
+{
+ GList *list;
+ GList *tmp;
+
+ list = gtk_container_get_children (container);
-void
-photo_saved_cb (DBusGProxy *proxy, char *path, gpointer user_data);
+ tmp = list;
+ while (tmp != NULL)
+ {
+ gtk_widget_set_sensitive (GTK_WIDGET (tmp->data), state);
+
+ tmp = tmp->next;
+ }
-static void run_mainloop (void)
-{
- GMainContext *ctx;
+ g_list_free (list);
+}
- ctx = g_main_loop_get_context (loop);
+void
+photo_saved_cb (DBusGProxy *proxy, char *path, gpointer user_data)
+{
+ pixbuf = gdk_pixbuf_new_from_file (path, &error);
+ gtk_container_remove (GTK_CONTAINER (frame), image);
+ image = gtk_image_new_from_pixbuf (pixbuf);
+ gtk_container_add (GTK_CONTAINER (frame), image);
+ gtk_widget_show_all (GTK_WIDGET (window));
+ g_message ("new photo: %s", path);
+
+ //set_active (GTK_CONTAINER (window), TRUE);
+ gtk_widget_set_sensitive (button, TRUE);
+ //gtk_window_present (GTK_WINDOW (window));
+ gtk_widget_grab_focus (window);
+}
- while (g_main_context_pending (ctx))
- g_main_context_iteration (ctx, FALSE);
+void
+destroy (GtkWidget *widget, gpointer data)
+{
+ gtk_main_quit ();
}
-int
-main(int argc, char **argv)
+void
+call_cheese (void)
{
- /* Somewhere in the code, we want to execute EchoString remote method */
DBusGProxy *proxy;
DBusGConnection *connection;
- GError *error = NULL;
- g_type_init ();
- loop = g_main_loop_new (NULL, FALSE);
-
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (connection == NULL)
@@ -39,7 +71,7 @@
g_warning("Unable to connect to dbus: %sn", error->message);
g_error_free (error);
/* Basically here, there is a problem, since there is no dbus :) */
- return -1;
+ return;
}
g_message ("connection established");
@@ -76,7 +108,7 @@
g_warning ("Woops remote method failed: %s", error->message);
//g_warning ("error in echo string");
g_error_free (error);
- return -1;
+ return;
}
g_message ("after triggered activation");
@@ -86,26 +118,114 @@
//dbus_g_object_register_marshaller(marshal_VOID__STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_add_signal (proxy, "photoSaved", G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (proxy, "photoSaved", G_CALLBACK(photo_saved_cb), connection, NULL);
+}
+
+static void
+button_pressed (GtkWidget *button, gpointer user_data)
+{
+ //set_active (user_data, FALSE);
+ gtk_widget_set_sensitive (button, FALSE);
+ call_cheese ();
+}
- //while(TRUE){
- // sleep (1);
- //}
-
- run_mainloop ();
- dbus_g_connection_flush (connection);
- g_main_loop_run (loop);
+int
+main(int argc, char **argv)
+{
+ GtkWidget *vbox;
+ GtkWidget *align;
+ char *filename;
+
+ g_type_init ();
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_screen (GTK_WINDOW (window), gdk_screen_get_default());
+ gtk_window_set_title (GTK_WINDOW (window), "Cheese-Dbus-Test");
+ gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+ gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
+
+ g_message ("blub");
+
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
+
+ vbox = gtk_vbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+ /* The alignment keeps the frame from growing when users resize
+ * the window
+ */
+ align = gtk_alignment_new (0.5, 0.5, 0, 0);
+ gtk_container_add (GTK_CONTAINER (align), frame);
+ gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0);
+
+ pixbuf = NULL;
+ filename = "waiting_dummy.jpeg";
+ if (filename)
+ {
+ pixbuf = gdk_pixbuf_new_from_file (filename, &error);
+ //g_object_set_property(G_OBJECT (pixbuf), "width", 800);
+ //pixbuf->width = 800;
+ //g_free (filename);
+ }
+
+ if (error)
+ {
+ /* This code shows off error handling. You can just use
+ * gtk_image_new_from_file() instead if you don't want to report
+ * errors to the user. If the file doesn't load when using
+ * gtk_image_new_from_file(), a "missing image" icon will
+ * be displayed instead.
+ */
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Unable to open image file: %s",
+ error->message);
+ g_error_free (error);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+
+ gtk_widget_show (dialog);
+ }
+
+ image = gtk_image_new_from_pixbuf (pixbuf);
+
+ gtk_container_add (GTK_CONTAINER (frame), image);
+ /* Sensitivity control */
+ button = gtk_button_new_with_mnemonic ("_Take a Picture");
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+ g_signal_connect (button, "pressed",
+ G_CALLBACK (button_pressed),
+ vbox);
+
+ if (!GTK_WIDGET_VISIBLE (window))
+ {
+ gtk_widget_show_all (GTK_WIDGET (window));
+ }
+ else
+ {
+ gtk_widget_destroy (GTK_WIDGET (window));
+ window = NULL;
+ }
+
+ gtk_main ();
/* Cleanup */
- g_object_unref (proxy);
+ //g_object_unref (proxy);
/* The DBusGConnection should never be unreffed, it lives once and is shared amongst the process */
return 1;
}
-
-void
-photo_saved_cb (DBusGProxy *proxy, char *path, gpointer user_data)
-{
- g_message (path);
- exit (0);
-}
Added: branches/cheese-dbus/client/waiting_dummy.jpeg
==============================================================================
Binary file. No diff available.
Modified: branches/cheese-dbus/src/cheese-dbus.c
==============================================================================
--- branches/cheese-dbus/src/cheese-dbus.c (original)
+++ branches/cheese-dbus/src/cheese-dbus.c Sat Jul 12 14:26:40 2008
@@ -57,6 +57,9 @@
{
g_message ("emit signal: %s", path);
g_signal_emit (server, cheese_dbus_signals[PHOTO_SAVED], 0, path);
+
+ //quit cheese after emitting the signal
+ exit (0);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]