aboutsummaryrefslogtreecommitdiffstats
path: root/executive-summary/test-service/main.c
blob: 2f2fcb32b0bd552de77630b84181eca16483b71f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gnome.h>
#include <bonobo.h>
#include <executive-summary-component.h>
#include <liboaf/liboaf.h>

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;

int
clicked_cb (ExecutiveSummaryComponent *component) 
{
  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<br><center>%d</center><br>seconds have passed.", i);
  executive_summary_component_update (component, html);
  i++;

  g_free (html);
  return TRUE;
}

void
view_destroyed (GtkWidget *widget,
        gpointer data)
{
  g_print ("Destroying view: %d\n", running_views);

  gtk_main_quit ();
}

static BonoboObject*
create_view (ExecutiveSummaryComponent *component,
         char **title,
         char **icon,
         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<br><center>0</center><br>seconds have passed.");
}

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);
}
  
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);
}

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);
  }
}

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;
}