aboutsummaryrefslogtreecommitdiffstats
path: root/executive-summary/test-service/main.c
diff options
context:
space:
mode:
authorIain Holmes <iain@src.gnome.org>2000-11-22 08:34:39 +0800
committerIain Holmes <iain@src.gnome.org>2000-11-22 08:34:39 +0800
commitf69d5ec14310f4903a8b88224f7c82cfa1de014a (patch)
treedc66bdbfc7f7859e5d4ab33dc71354da56725fcb /executive-summary/test-service/main.c
parent615a467b605dfbbdbab66d6edd64f8c298993397 (diff)
downloadgsoc2013-evolution-f69d5ec14310f4903a8b88224f7c82cfa1de014a.tar
gsoc2013-evolution-f69d5ec14310f4903a8b88224f7c82cfa1de014a.tar.gz
gsoc2013-evolution-f69d5ec14310f4903a8b88224f7c82cfa1de014a.tar.bz2
gsoc2013-evolution-f69d5ec14310f4903a8b88224f7c82cfa1de014a.tar.lz
gsoc2013-evolution-f69d5ec14310f4903a8b88224f7c82cfa1de014a.tar.xz
gsoc2013-evolution-f69d5ec14310f4903a8b88224f7c82cfa1de014a.tar.zst
gsoc2013-evolution-f69d5ec14310f4903a8b88224f7c82cfa1de014a.zip
Big patch. Evolution-services rewrite, services updated for new system,
Big patch. Evolution-services rewrite, services updated for new system, Fixes to Executive Summary and other things. See some changelogs svn path=/trunk/; revision=6644
Diffstat (limited to 'executive-summary/test-service/main.c')
-rw-r--r--executive-summary/test-service/main.c271
1 files changed, 180 insertions, 91 deletions
diff --git a/executive-summary/test-service/main.c b/executive-summary/test-service/main.c
index 75bbc3199b..6a646adecd 100644
--- a/executive-summary/test-service/main.c
+++ b/executive-summary/test-service/main.c
@@ -30,131 +30,220 @@
#include <bonobo.h>
#include <evolution-services/executive-summary-component.h>
-#include <evolution-services/executive-summary-component-view.h>
+#include <evolution-services/executive-summary-html-view.h>
#include <liboaf/liboaf.h>
-static int running_views = 0;
+enum {
+ PROPERTY_TITLE,
+ PROPERTY_ICON
+};
-struct userdata {
- int i;
+struct _UserData {
+ char *title;
+ char *icon;
};
+typedef struct _UserData UserData;
+
+static int running_views = 0;
#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
-add_one (ExecutiveSummaryComponentView *view)
+/* PersistStream callbacks */
+static void
+load_from_stream (BonoboPersistStream *ps,
+ Bonobo_Stream stream,
+ Bonobo_Persist_ContentType type,
+ gpointer data,
+ CORBA_Environment *ev)
{
- char *html;
- struct userdata *ud;
+ char *str;
- /* 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;
+ if (*type && g_strcasecmp (type, "application/x-test-service") != 0) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_WrongDataType, NULL);
+ return;
}
-
- /* Generate the new html */
- html = g_strdup_printf ("Since you started this service<br>"
- "<center>%d</center><br>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;
+
+ bonobo_stream_client_read_string (stream, &str, ev);
+ if (ev->_major != CORBA_NO_EXCEPTION || str == NULL) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_WrongDataType, NULL);
+ return;
+ }
+
+ g_print ("Restoring with :%s\n", str);
+ g_free (str);
}
-void
-view_destroyed (GtkObject *object,
- gpointer data)
+static void
+save_to_stream (BonoboPersistStream *ps,
+ const Bonobo_Stream stream,
+ Bonobo_Persist_ContentType type,
+ gpointer data,
+ CORBA_Environment *ev)
{
- 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);
+
+ if (*type && g_strcasecmp (type, "application/x-test-service") != 0) {
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
+ ex_Bonobo_Persist_WrongDataType, NULL);
+ return;
+ }
+
+ bonobo_stream_client_printf (stream, TRUE, ev, "Yo yo yo");
+ if (ev->_major != CORBA_NO_EXCEPTION)
+ return;
+}
+
+static Bonobo_Persist_ContentTypeList *
+content_types (BonoboPersistStream *ps,
+ void *closure,
+ CORBA_Environment *ev)
+{
+ return bonobo_persist_generate_content_types (1, "application/x-test-service");
+}
+
+/* PropertyControl callback */
+
+/* Propertybag set/get functions */
+static void
+set_property (BonoboPropertyBag *bag,
+ const BonoboArg *arg,
+ guint arg_id,
+ gpointer user_data)
+{
+ switch (arg_id) {
+ case PROPERTY_TITLE:
+ g_print ("Setting title.\n");
+ break;
+
+ case PROPERTY_ICON:
+ g_print ("Setting icon.\n");
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void
+get_property (BonoboPropertyBag *bag,
+ BonoboArg *arg,
+ guint arg_id,
+ gpointer user_data)
+{
+ UserData *ud = (UserData *) user_data;
+
+ switch (arg_id) {
+ case PROPERTY_TITLE:
+ BONOBO_ARG_SET_STRING (arg, ud->title);
+ break;
+
+ case PROPERTY_ICON:
+ BONOBO_ARG_SET_STRING (arg, ud->icon);
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void
+component_destroyed (GtkObject *object,
+ gpointer data)
+{
+ UserData *ud = (UserData *) ud;
+ /* Free the UserData structure */
+ g_free (ud->title);
+ g_free (ud->icon);
g_free (ud);
-
- /* Remove one running view */
+
running_views--;
-
- /* If there are no running views left, quit */
+
+ g_print ("Destroy!\n");
if (running_views <= 0)
gtk_main_quit ();
}
-/* Create the view:
- HTML only */
-static void
-create_view (ExecutiveSummaryComponent *component,
- ExecutiveSummaryComponentView *view,
+static BonoboObject *
+create_view (ExecutiveSummaryComponentFactory *_factory,
void *closure)
{
- char *html = "Since you started this service<br><center>0</center><br>seconds have passed.";
- struct userdata *ud;
-
- g_print ("In: %s\n", __FUNCTION__);
- /* 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");
- g_print ("Out: %s\n", __FUNCTION__);
- /* Set the user data on the object */
- gtk_object_set_data (GTK_OBJECT (view), "timer-data", ud);
+ BonoboObject *component, *view, *bag, *stream;
+ UserData *ud;
+
+ /* Create the component object */
+ component = executive_summary_component_new ();
+
+ /* Create the UserData structure and fill it */
+ ud = g_new (UserData, 1);
+ ud->title = g_strdup ("Hello World!");
+ ud->icon = g_strdup ("apple-red.png");
+
+ gtk_signal_connect (GTK_OBJECT (component), "destroy",
+ GTK_SIGNAL_FUNC (component_destroyed), ud);
+
+ /* Now create the aggregate objects. For a "service"
+ either a Summary::HTMLView or Bonobo::Control are required.
+ Other supported agreggate objects are
+ PersistStream: For saving and restoring the component.
+ PropertyBag: To set the icon and title and other properties
+ PropertyControl: To produce a control to configure the service.
- /* 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);
+ To aggregate the objects
+ i) Create the objects using their creation functions
+ ii) Use bonobo_object_add_interface ().
+ */
- /* Increase the number of running views */
- running_views++;
+ /* The Summary::HTMLView interface */
+ view = executive_summary_html_view_new ();
+ /* Set the default HTML */
+ executive_summary_html_view_set_html (EXECUTIVE_SUMMARY_HTML_VIEW (view),
+ "<B>Hello World</b>");
- /* Do something "interesting" once a second */
- gtk_timeout_add (1000, add_one, view);
-}
+ bonobo_object_add_interface (component, view);
-static void
-configure (ExecutiveSummaryComponent *component,
- void *closure)
-{
- 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);
+ /* Add the Bonobo::PropertyBag interface */
+ bag = bonobo_property_bag_new (get_property, set_property, ud);
+ /* Add the properties. There should be 2:
+ window_title: For the window title.
+ window_icon: For the window icon.
+ */
+ bonobo_property_bag_add (BONOBO_PROPERTY_BAG (bag),
+ "window_title", PROPERTY_TITLE,
+ BONOBO_ARG_STRING,
+ NULL,
+ "The title of this components window", 0);
+ bonobo_property_bag_add (BONOBO_PROPERTY_BAG (bag),
+ "window_icon", PROPERTY_ICON,
+ BONOBO_ARG_STRING,
+ NULL,
+ "The icon for this component's window", 0);
+
+ /* Now add the interface */
+ bonobo_object_add_interface (component, bag);
+
+
+ /* Add the Bonobo::PersistStream interface */
+ stream = bonobo_persist_stream_new (load_from_stream, save_to_stream,
+ NULL, content_types, NULL);
+ bonobo_object_add_interface (component, stream);
+
+ /* Return the ExecutiveSummaryComponent object */
+ return component;
}
static BonoboObject *
-factory_fn (BonoboGenericFactory *_factory,
+factory_fn (BonoboGenericFactory *generic_factory,
void *closure)
{
- ExecutiveSummaryComponent *component;
+ BonoboObject *_factory;
- /* Create an executive summary component for this factory */
- component = executive_summary_component_new (create_view,
- configure,
- NULL);
- return BONOBO_OBJECT (component);
+ /* Create an executive summary component factory */
+ _factory = executive_summary_component_factory_new (create_view, NULL);
+ return _factory;
}
void