From 20394851919f80269d11aa460e60f2bd1e46b7dc Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Wed, 25 Oct 2000 23:03:33 +0000 Subject: Summary is back in :D Fixed a silly size issue for composer file selectors. svn path=/trunk/; revision=6187 --- executive-summary/test-service/main.c | 242 ++++++++++++++++++++-------------- 1 file changed, 145 insertions(+), 97 deletions(-) (limited to 'executive-summary/test-service/main.c') diff --git a/executive-summary/test-service/main.c b/executive-summary/test-service/main.c index 2f2fcb32b0..8612c2d394 100644 --- a/executive-summary/test-service/main.c +++ b/executive-summary/test-service/main.c @@ -1,146 +1,194 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* main.c + * Test Service that counts the number of seconds since it was started. + * + * Authors: Iain Holmes + * + * Copyright (C) 2000 Helix Code, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + #ifdef HAVE_CONFIG_H #include #endif #include #include -#include + +#include +#include + #include static int running_views = 0; +struct userdata { + int i; +}; + #define TEST_SERVICE_ID "OAFIID:evolution-summary-component-factory:test-service:0ea887d5-622b-4b8c-b525-18aa1cbe18a6" static BonoboGenericFactory *factory = NULL; +/* The "do something interesting" function */ int -clicked_cb (ExecutiveSummaryComponent *component) +add_one (ExecutiveSummaryComponentView *view) { - static int i = 1; - char *html; - -#if 0 - executive_summary_component_set_title (component, "Iain's title"); - executive_summary_component_flash (component); -#endif - - html = g_strdup_printf ("Since you started this service
%d

seconds have passed.", i); - executive_summary_component_update (component, html); - i++; - - g_free (html); - return TRUE; + char *html; + struct userdata *ud; + + /* Get the user data from the view */ + ud = gtk_object_get_data (GTK_OBJECT (view), "timer-data"); + if (ud == NULL) { + g_warning ("No user data"); + return FALSE; + } + + /* Generate the new html */ + html = g_strdup_printf ("Since you started this service
" + "
%d

seconds have passed.", ud->i); + + /* Change the html on the view + which will tell the Executive Summary that something needs updating */ + executive_summary_component_view_set_html (view, html); + + /* executive_summary_component_view_set_html () makes a copy of the HTML + passed into it, so we don't need to keep it around */ + g_free (html); + + /* Do something "fun" */ + ud->i++; + + return TRUE; } void -view_destroyed (GtkWidget *widget, +view_destroyed (GtkObject *object, gpointer data) { - g_print ("Destroying view: %d\n", running_views); - - gtk_main_quit (); + ExecutiveSummaryComponentView *view; + struct userdata *ud; + int id; + + /* Free the user data for this view*/ + ud = gtk_object_get_data (object, "timer-data"); + gtk_object_set_data (object, "timer-data", NULL); + g_free (ud); + + /* Remove one running view */ + running_views--; + + /* If there are no running views left, quit */ + if (running_views <= 0) + gtk_main_quit (); } -static BonoboObject* +/* Create the view: + HTML only */ +static void create_view (ExecutiveSummaryComponent *component, - char **title, - char **icon, + ExecutiveSummaryComponentView *view, void *closure) { - BonoboControl *control; - GtkWidget *button; - - *title = g_strdup ("This is the test bonobo service"); - *icon = g_strdup ("gnome-clock.png"); - - button = gtk_button_new_with_label ("A test service with a whole button"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (clicked_cb), NULL); - - control = bonobo_control_new (button); - gtk_signal_connect (GTK_OBJECT (control), "destroy", - GTK_SIGNAL_FUNC (view_destroyed), NULL); - - gtk_widget_show_all (button); - - g_assert (control != NULL); - - return BONOBO_OBJECT (control); -} - -static char * -create_html (ExecutiveSummaryComponent *component, - char **title, - char **icon, - void *closure) -{ - *title = g_strdup ("The Magic Counter"); - *icon = g_strdup ("gnome-clock.png"); - - gtk_timeout_add (1000, clicked_cb, component); - return g_strdup ("Since you started this service
0

seconds have passed."); + char *html = "Since you started this service
0

seconds have passed."; + struct userdata *ud; + + /* Create the userdata structure */ + ud = g_new (struct userdata, 1); + + ud->i = 1; + executive_summary_component_view_construct (view, component, NULL, + html, "The Magic Counter", + "gnome-clock.png"); + /* Set the user data on the object */ + gtk_object_set_data (GTK_OBJECT (view), "timer-data", ud); + + /* Connect the the destroyed signal to find out + when the view is destroyed */ + gtk_signal_connect (GTK_OBJECT (view), "destroy", + GTK_SIGNAL_FUNC (view_destroyed), NULL); + + /* Increase the number of running views */ + running_views++; + + /* Do something "interesting" once a second */ + gtk_timeout_add (1000, add_one, view); } static void configure (ExecutiveSummaryComponent *component, void *closure) { - GtkWidget *window, *label; - - g_print ("configuring\n"); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - label = gtk_label_new ("This is a configuration dialog.\nNo it really is"); - - gtk_container_add (GTK_CONTAINER (window), label); - gtk_widget_show_all (window); + GtkWidget *window, *label; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + label = gtk_label_new ("This is a configuration dialog.\nNo it really is"); + + gtk_container_add (GTK_CONTAINER (window), label); + gtk_widget_show_all (window); } - + static BonoboObject * factory_fn (BonoboGenericFactory *_factory, void *closure) { - ExecutiveSummaryComponent *component; - - running_views++; - component = executive_summary_component_new (create_view, - create_html, - configure, - NULL); - gtk_signal_connect (GTK_OBJECT (component), "object_gone", - GTK_SIGNAL_FUNC (view_destroyed), NULL); - return BONOBO_OBJECT (component); + ExecutiveSummaryComponent *component; + + /* Create an executive summary component for this factory */ + component = executive_summary_component_new (create_view, + configure, + NULL); + return BONOBO_OBJECT (component); } void test_service_factory_init (void) { - if (factory != NULL) - return; - - factory = bonobo_generic_factory_new (TEST_SERVICE_ID, factory_fn, NULL); - if (factory == NULL) { - g_warning ("Cannot initialize test service"); - exit (0); - } + if (factory != NULL) + return; + + /* Register the factory creation function and the IID */ + factory = bonobo_generic_factory_new (TEST_SERVICE_ID, factory_fn, NULL); + if (factory == NULL) { + g_warning ("Cannot initialize test service"); + exit (0); + } } int main (int argc, char **argv) { - CORBA_ORB orb; - - gnome_init_with_popt_table ("Test service", VERSION, - argc, argv, oaf_popt_options, 0, NULL); - orb = oaf_init (argc, argv); - - if (bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) { - g_error ("Could not initialize Bonobo"); - } - - test_service_factory_init (); - - bonobo_main (); - - return 0; + CORBA_ORB orb; + + /* Init GNOME, oaf and bonobo */ + gnome_init_with_popt_table ("Test service", VERSION, + argc, argv, oaf_popt_options, 0, NULL); + orb = oaf_init (argc, argv); + + if (bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE) { + g_error ("Could not initialize Bonobo"); + } + + /* Register the factory */ + test_service_factory_init (); + + /* Enter main */ + bonobo_main (); + + return 0; } -- cgit v1.2.3