aboutsummaryrefslogtreecommitdiffstats
path: root/mail/test-thread.c
blob: eddf9dd7c8f5dc42fb84131ddb9379904da605c7 (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
/* Tests the multithreaded UI code */

#include "config.h"
#include <unistd.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <libgnomeui/libgnomeui.h>
#include <stdio.h>
#include "mail-threads.h"

static gchar *desc_1 (gpointer in, gboolean gerund);
static void op_1( gpointer in, gpointer op, CamelException *ex );
static gchar *desc_2 (gpointer in, gboolean gerund);
static void op_2( gpointer in, gpointer op, CamelException *ex );
static gchar *desc_3 (gpointer in, gboolean gerund);
static void op_3( gpointer in, gpointer op, CamelException *ex );
static gchar *desc_4 (gpointer in, gboolean gerund);
static void op_4( gpointer in, gpointer op, CamelException *ex );
static gchar *desc_5 (gpointer in, gboolean gerund);
static void op_5( gpointer in, gpointer op, CamelException *ex );
static gchar *desc_6 (gpointer in, gboolean gerund);
static gchar *desc_7 (gpointer in, gboolean gerund);
static gchar *desc_8 (gpointer in, gboolean gerund);
static void done( gpointer in, gpointer op, CamelException *ex );
static void exception( gpointer in, gpointer op, CamelException *ex );
static gboolean queue_ops( void );

const mail_operation_spec spec1 = { desc_1, 0, NULL, op_1, done };
const mail_operation_spec spec2 = { desc_2, 0, NULL, op_2, done };
const mail_operation_spec spec3 = { desc_3, 0, NULL, op_3, done };
const mail_operation_spec spec4 = { desc_4, 0, NULL, op_4, NULL };
const mail_operation_spec spec5 = { desc_5, 0, NULL, op_5, done };
const mail_operation_spec spec6 = { desc_6, 0, exception, op_4, NULL };
const mail_operation_spec spec7 = { desc_7, 0, NULL, exception, NULL };
const mail_operation_spec spec8 = { desc_8, 0, NULL, op_4, exception };

static gboolean queue_ops( void )
{
    int i;

    g_message( "Top of queue_ops" );

    mail_operation_queue( &spec1, "op1 finished", FALSE );
    mail_operation_queue( &spec2, "op2 finished", FALSE );
    mail_operation_queue( &spec3, "op3 finished", FALSE );

    for( i = 0; i < 3; i++ ) {
        mail_operation_queue( &spec4, GINT_TO_POINTER( i ), FALSE );
    }

    g_message( "Waiting for finish..." );
    mail_operation_wait_for_finish();

    g_message( "Ops done -- queue some more!" );

    mail_operation_queue( &spec1, "done a second time", FALSE );

    g_message( "Waiting for finish again..." );
    mail_operation_wait_for_finish();

    g_message( "Ops done -- more, more!" );

    mail_operation_queue( &spec5, "passwords stolen", FALSE );

    for( i = 0; i < 3; i++ ) {
        mail_operation_queue( &spec4, GINT_TO_POINTER( i ), FALSE );
    }

    mail_operation_queue( &spec6, NULL, FALSE );
    mail_operation_queue( &spec7, NULL, FALSE );
    mail_operation_queue( &spec8, NULL, FALSE );

    g_message( "Waiting for finish for the last time..." );
    mail_operations_terminate();
    g_message( "Ops done again. Exiting 0" );
    gtk_exit( 0 );
    return FALSE;
}

static void exception( gpointer in, gpointer op, CamelException *ex )
{
    camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, "I don't feel like it.");
}

static void op_1( gpointer in, gpointer op, CamelException *ex )
{
    gfloat pct;

    mail_op_show_progressbar();
    mail_op_set_message( "Watch the progress bar!" );

    for( pct = 0.0; pct < 1.0; pct += 0.2 ) {
        sleep( 1 );
        mail_op_set_percentage( pct );
    }
}

static void op_2( gpointer in, gpointer op, CamelException *ex )
{
    int i;

    mail_op_hide_progressbar();
    for( i = 5; i > 0; i-- ) {
        mail_op_set_message( "%d", i );
        sleep( 1 );
    }

    mail_op_set_message( "BOOOM!" );
    sleep( 1 );
}

static void op_3( gpointer in, gpointer op, CamelException *ex )
{
    gfloat pct;

    mail_op_show_progressbar();
    mail_op_set_message( "Frobulating the foosamatic" );

    for( pct = 0.0; pct < 0.3; pct += 0.1 ) {
        mail_op_set_percentage( pct );
        sleep( 1 );
    }

    mail_op_error( "Oh no! The foosamatic was booby-trapped!" );
    sleep( 1 );
}

static void op_4( gpointer in, gpointer op, CamelException *ex )
{
    mail_op_hide_progressbar();
    mail_op_set_message( "Filler # %d", GPOINTER_TO_INT( in ) );
    sleep( 1 );
}

static void op_5( gpointer in, gpointer op, CamelException *ex )
{
    gchar *pass;
    gboolean ret;

    mail_op_show_progressbar();
    mail_op_set_percentage( 0.5 );

    ret = mail_op_get_password( "What is your super-secret password?", TRUE, &pass );

    if( ret == FALSE )
        mail_op_set_message( "Oh no, you cancelled! : %s", pass );
    else
        mail_op_set_message( "\"%s\", you said?", pass );

    sleep( 1 );
}

static void done( gpointer in, gpointer op, CamelException *ex )
{
    g_message( "Operation done: %s", (gchar *) in );
}

static gchar *desc_1 (gpointer in, gboolean gerund)
{
    if (gerund)
        return g_strdup ("Showing the Crawling Progress Bar of Doom");
    else
        return g_strdup ("Progress Bar");
}

static gchar *desc_2 (gpointer in, gboolean gerund)
{
    if (gerund)
        return g_strdup ("Exploring the Mysterious Message Setter");
    else
        return g_strdup ("Explore");
}

static gchar *desc_3 (gpointer in, gboolean gerund)
{
    if (gerund)
        return g_strdup ("Dare the Error Dialog of No Return");
    else
        return g_strdup ("Dare");
}

static gchar *desc_4 (gpointer in, gboolean gerund)
{
    if (gerund)
        return g_strdup_printf ("Filling Queue Space -- %d", GPOINTER_TO_INT (in));
    else
        return g_strdup_printf ("Filler -- %d", GPOINTER_TO_INT (in));
}

static gchar *desc_5 (gpointer in, gboolean gerund)
{
    if (gerund)
        return g_strdup ("Stealing your Password");
    else
        return g_strdup ("The Dastardly Password Stealer");
}

static gchar *desc_6 (gpointer in, gboolean gerund)
{
    if (gerund)
        return g_strdup ("Setting exception on setup");
    else
        return g_strdup ("Exception on setup");
}

static gchar *desc_7 (gpointer in, gboolean gerund)
{
    if (gerund)
        return g_strdup ("Setting exception in process");
    else
        return g_strdup ("Exception coming soon");
}

static gchar *desc_8 (gpointer in, gboolean gerund)
{
    if (gerund)
        return g_strdup ("Setting exception in cleanup");
    else
        return g_strdup ("Exception in cleanup");
}


int main( int argc, char **argv )
{
    g_thread_init( NULL );
    gnome_init( "test-thread", "0.0", argc, argv );
    gtk_idle_add( (GtkFunction) queue_ops, NULL );
    gtk_main();
    return 0;
}