aboutsummaryrefslogtreecommitdiffstats
path: root/shell/evolution-test-component.c
blob: e1d2354a7b1bce7a771a26b9e778cf60ba8627b2 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* evolution-test-component.c
 *
 * Copyright (C) 2001  Ximian, 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.
 *
 * Author: Ettore Perazzoli
 */

/* Simple test component for the Evolution shell.  */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "evolution-shell-component.h"
#include "evolution-activity-client.h"

#include <bonobo/bonobo-generic-factory.h>
#include <bonobo/bonobo-main.h>

#include <gdk-pixbuf/gdk-pixbuf.h>


#define COMPONENT_FACTORY_ID "OAFIID:GNOME_Evolution_TestComponent_ShellComponentFactory"
#define COMPONENT_ID         "OAFIID:GNOME_Evolution_TestComponent_ShellComponent"

static const EvolutionShellComponentFolderType folder_types[] = {
    { "test", "/usr/share/pixmaps/gnome-money.png", NULL, NULL },
    { NULL }
};


static EvolutionShellClient *parent_shell = NULL;
static EvolutionActivityClient *activity_client;

static int timeout_id = 0;
static int progress = -1;


/* Callbacks.  */

static void
activity_client_cancel_callback (EvolutionActivityClient *client,
                 void *data)
{
    g_print ("User requested that the operation be cancelled.\n");
}

static void
activity_client_show_details_callback (EvolutionActivityClient *client,
                       void *data)
{
    g_print ("User wants to see details.\n");
}


/* Timeout #3: We are done.  */
static int
timeout_callback_3 (void *data)
{
    gtk_object_unref (GTK_OBJECT (activity_client));

    g_print ("--> Done.\n");

    return FALSE;
}

/* Timeout #2: Update the progress until it reaches 100%.  */
static int
timeout_callback_2 (void *data)
{
    if (progress < 0)
        progress = 0;

    g_print ("--> Updating %d\n", progress);

    if (! evolution_activity_client_update (activity_client, "Operation Foo in progress",
                        (float) progress / 100.0)) {
        g_warning ("Error when updating operation");
        return FALSE;
    }

    progress ++;
    if (progress > 100) {
        gtk_timeout_add (200, timeout_callback_3, NULL);
        return FALSE;
    }

    return TRUE;
}

/* Timeout #1: Set busy.  */
static int
timeout_callback_1 (void *data)
{
    gboolean suggest_display;
    GdkPixbuf *animated_icon[2];

    animated_icon[0] = gdk_pixbuf_new_from_file (gnome_pixmap_file ("gnome-money.png"));
    animated_icon[1] = NULL;

    g_assert (animated_icon[0] != NULL);

    activity_client = evolution_activity_client_new (parent_shell, COMPONENT_ID,
                             animated_icon,
                             "Operation Foo started!",
                             TRUE,
                             &suggest_display);
    if (activity_client == CORBA_OBJECT_NIL) {
        g_warning ("Cannot create EvolutionActivityClient object");
        return FALSE;
    }

    gtk_signal_connect (GTK_OBJECT (activity_client), "cancel",
                GTK_SIGNAL_FUNC (activity_client_cancel_callback), NULL);
    gtk_signal_connect (GTK_OBJECT (activity_client), "show_details",
                GTK_SIGNAL_FUNC (activity_client_show_details_callback), NULL);

    g_print ("Component becoming busy -- %s\n", COMPONENT_ID);
    if (suggest_display)
        g_print (" --> Could display dialog box.\n");

    gtk_timeout_add (100, timeout_callback_2, NULL);

    return FALSE;
}


static EvolutionShellComponentResult
create_view_fn (EvolutionShellComponent *shell_component,
        const char *physical_uri,
        const char *folder_type,
        BonoboControl **control_return,
        void *closure)
{
    GtkWidget *vbox;
    GtkWidget *label_1, *label_2;
    GtkWidget *event_box_1, *event_box_2;

    label_1 = gtk_label_new ("This is just a test component, displaying the following URI:");
    label_2 = gtk_label_new (physical_uri);

    event_box_1 = gtk_event_box_new ();
    event_box_2 = gtk_event_box_new ();

    vbox = gtk_vbox_new (FALSE, 5);

    gtk_box_pack_start (GTK_BOX (vbox), event_box_1, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), label_1, FALSE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), label_2, FALSE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox), event_box_2, TRUE, TRUE, 0);

    gtk_widget_show (label_1);
    gtk_widget_show (label_2);
    gtk_widget_show (event_box_1);
    gtk_widget_show (event_box_2);

    gtk_widget_show (vbox);

    *control_return = bonobo_control_new (vbox);

    g_assert (timeout_id == 0);
    timeout_id = gtk_timeout_add (2000, timeout_callback_1, NULL);

    return EVOLUTION_SHELL_COMPONENT_OK;
}


/* Callbacks.  */

static void
owner_set_callback (EvolutionShellComponent *shell_component,
            EvolutionShellClient *shell_client,
            const char *evolution_homedir)
{
    g_assert (parent_shell == NULL);

    g_print ("We have an owner -- home directory is `%s'\n", evolution_homedir);

    parent_shell = shell_client;

    if (evolution_shell_client_get_activity_interface (parent_shell) == CORBA_OBJECT_NIL)
        g_warning ("Shell doesn't have a ::Activity interface -- weird!");
}

static int
owner_unset_idle_callback (void *data)
{
    gtk_main_quit ();
    return FALSE;
}

static void
owner_unset_callback (EvolutionShellComponent *shell_component,
              void *data)
{
    g_idle_add_full (G_PRIORITY_LOW, owner_unset_idle_callback, NULL, NULL);
}


static BonoboObject *
factory_fn (BonoboGenericFactory *factory,
        void *closure)
{
    EvolutionShellComponent *shell_component;

    shell_component = evolution_shell_component_new (folder_types,
                             NULL,
                             create_view_fn,
                             NULL, NULL, NULL, NULL, NULL, NULL);

    gtk_signal_connect (GTK_OBJECT (shell_component), "owner_set",
                GTK_SIGNAL_FUNC (owner_set_callback), NULL);
    gtk_signal_connect (GTK_OBJECT (shell_component), "owner_unset",
                GTK_SIGNAL_FUNC (owner_unset_callback), NULL);

    return BONOBO_OBJECT (shell_component);
}

static void
component_factory_init (void)
{
    BonoboGenericFactory *factory;

    factory = bonobo_generic_factory_new (COMPONENT_FACTORY_ID, factory_fn, NULL);

    if (factory == NULL)
        g_error ("Cannot initialize test component.");
}


int
main (int argc, char **argv)
{
    CORBA_ORB orb;

    bindtextdomain (PACKAGE, EVOLUTION_LOCALEDIR);
    textdomain (PACKAGE);

    gnome_init_with_popt_table ("evolution-test-component", 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 ("Cannot initialize the test component.");

    component_factory_init ();

    bonobo_main ();

    return 0;
}