Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 346423
Collapse All | Expand All

(-)src/interfaces/gtk/ec_gtk.c (-45 / +147 lines)
Lines 20-25 Link Here
20
    $Id: ec_gtk.c,v 1.39 2004/12/21 11:24:02 alor Exp $
20
    $Id: ec_gtk.c,v 1.39 2004/12/21 11:24:02 alor Exp $
21
*/
21
*/
22
22
23
#include <string.h>
24
23
#include <ec.h>
25
#include <ec.h>
24
26
25
#include <ec_gtk.h>
27
#include <ec_gtk.h>
Lines 45-51 Link Here
45
static GtkTextBuffer *msgbuffer = NULL;
47
static GtkTextBuffer *msgbuffer = NULL;
46
static GtkTextMark   *endmark = NULL;
48
static GtkTextMark   *endmark = NULL;
47
static GtkAccelGroup *accel_group = NULL;
49
static GtkAccelGroup *accel_group = NULL;
50
48
static gboolean       progress_cancelled = FALSE;
51
static gboolean       progress_cancelled = FALSE;
52
static GtkWidget     *progress_dialog = NULL;
53
static GtkWidget     *progress_bar = NULL;
49
54
50
/* proto */
55
/* proto */
51
56
Lines 64-70 Link Here
64
static void gtkui_error(const char *msg);
69
static void gtkui_error(const char *msg);
65
static void gtkui_fatal_error(const char *msg);
70
static void gtkui_fatal_error(const char *msg);
66
static gboolean gtkui_flush_msg(gpointer data);
71
static gboolean gtkui_flush_msg(gpointer data);
67
static int gtkui_progress(char *title, int value, int max);
72
static void gtkui_progress(char *title, int value, int max);
68
73
69
static void gtkui_setup(void);
74
static void gtkui_setup(void);
70
75
Lines 102-107 Link Here
102
static void gtkui_page_defocus_tabs(void);
107
static void gtkui_page_defocus_tabs(void);
103
#endif
108
#endif
104
109
110
/* wrapper functions which inject the real function call into the main
111
   idle loop, ensuring only the main thread performs GTK operations
112
*/
113
114
static gboolean gtkui_cleanup_shim(gpointer data) {
115
   gtkui_cleanup();
116
   return FALSE;
117
}
118
119
static void gtkui_cleanup_wrap(void) {
120
   g_idle_add(gtkui_cleanup_shim, NULL);
121
}
122
123
static gboolean gtkui_msg_shim(gpointer data) {
124
   gtkui_msg(data);
125
   free(data);
126
   return FALSE;
127
}
128
129
static void gtkui_msg_wrap(const char *msg) {
130
131
   char *copy = strdup(msg);
132
   if (msg) {
133
      g_idle_add(gtkui_msg_shim, copy);
134
   } else {
135
      FATAL_ERROR("out of memory");
136
   }
137
}
138
139
static gboolean gtkui_error_shim(gpointer data) {
140
   gtkui_error(data);
141
   free(data);
142
   return FALSE;
143
}
144
145
static void gtkui_error_wrap(const char *msg) {
146
147
   char *copy = strdup(msg);
148
   if (msg) {
149
      g_idle_add(gtkui_error_shim, copy);
150
   } else {
151
      FATAL_ERROR("out of memory");
152
   }
153
}
154
155
static gboolean gtkui_fatal_error_shim(gpointer data) {
156
   gtkui_fatal_error(data);
157
   free(data);
158
   return FALSE;
159
}
160
161
static void gtkui_fatal_error_wrap(const char *msg) {
162
163
   char *copy = strdup(msg);
164
   if (msg) {
165
      g_idle_add(gtkui_fatal_error_shim, copy);
166
   } else {
167
      FATAL_ERROR("out of memory");
168
   }
169
}
170
171
struct gtkui_input_data {
172
   const char *title;
173
   char *input;
174
   size_t n;
175
   void (*callback)(void);
176
};
177
178
static gboolean gtkui_input_shim(gpointer data) {
179
180
   struct gtkui_input_data *gid = data;
181
   gtkui_input(gid->title, gid->input, gid->n, gid->callback);
182
   free(gid);
183
   return FALSE;
184
}
185
186
static void gtkui_input_wrap(const char *title, char *input, size_t n, void (*callback)(void)) {
187
188
   struct gtkui_input_data *gid = malloc(sizeof *gid);
189
   if (gid) {
190
      gid->title = title;
191
      gid->input = input;
192
      gid->n = n;
193
      gid->callback = callback;
194
      g_idle_add(gtkui_input_shim, gid);
195
   } else {
196
      FATAL_ERROR("out of memory");
197
   }
198
}
199
200
struct gtkui_progress_data {
201
   char *title;
202
   int value;
203
   int max;
204
};
205
206
static gboolean gtkui_progress_shim(gpointer data) {
207
208
   struct gtkui_progress_data *gpd = data;
209
   gtkui_progress(gpd->title, gpd->value, gpd->max);
210
   free(gpd);
211
   return FALSE;
212
}
213
214
static int gtkui_progress_wrap(char *title, int value, int max) {
215
216
   struct gtkui_progress_data *gpd;
217
218
   if (progress_cancelled == TRUE) {
219
      progress_cancelled = FALSE;
220
      return UI_PROGRESS_INTERRUPTED;
221
   }
222
223
   gpd = malloc(sizeof *gpd);
224
   if (gpd) {
225
      gpd->title = title;
226
      gpd->value = value;
227
      gpd->max = max;
228
      g_idle_add(gtkui_progress_shim, gpd);
229
   } else {
230
      FATAL_ERROR("out of memory");
231
   }
232
233
   return value == max
234
      ? UI_PROGRESS_FINISHED
235
      : UI_PROGRESS_UPDATED;
236
}
237
105
/***#****************************************/
238
/***#****************************************/
106
239
107
void set_gtk_interface(void)
240
void set_gtk_interface(void)
Lines 114-125 Link Here
114
   /* register the functions */
247
   /* register the functions */
115
   ops.init = &gtkui_init;
248
   ops.init = &gtkui_init;
116
   ops.start = &gtkui_start;
249
   ops.start = &gtkui_start;
117
   ops.cleanup = &gtkui_cleanup;
250
   ops.cleanup = &gtkui_cleanup_wrap;
118
   ops.msg = &gtkui_msg;
251
   ops.msg = &gtkui_msg_wrap;
119
   ops.error = &gtkui_error;
252
   ops.error = &gtkui_error_wrap;
120
   ops.fatal_error = &gtkui_fatal_error;
253
   ops.fatal_error = &gtkui_fatal_error_wrap;
121
   ops.input = &gtkui_input;
254
   ops.input = &gtkui_input_wrap;
122
   ops.progress = &gtkui_progress;
255
   ops.progress = &gtkui_progress_wrap;
123
   ops.type = UI_GTK;
256
   ops.type = UI_GTK;
124
   
257
   
125
   ui_register(&ops);
258
   ui_register(&ops);
Lines 134-140 Link Here
134
   DEBUG_MSG("gtk_init");
267
   DEBUG_MSG("gtk_init");
135
268
136
   g_thread_init(NULL);
269
   g_thread_init(NULL);
137
   gdk_threads_init();
138
270
139
   if(!gtk_init_check(0, NULL)) {
271
   if(!gtk_init_check(0, NULL)) {
140
   	FATAL_ERROR("GTK+ failed to initialize. Is X running?");
272
   	FATAL_ERROR("GTK+ failed to initialize. Is X running?");
Lines 148-156 Link Here
148
   /* gui init loop, calling gtk_main_quit will cause
280
   /* gui init loop, calling gtk_main_quit will cause
149
    * this to exit so we can proceed to the main loop
281
    * this to exit so we can proceed to the main loop
150
    * later. */
282
    * later. */
151
   gdk_threads_enter();
152
   gtk_main();
283
   gtk_main();
153
   gdk_threads_leave();
154
284
155
   /* remove the keyboard shortcuts for the setup menus */
285
   /* remove the keyboard shortcuts for the setup menus */
156
   gtk_window_remove_accel_group(GTK_WINDOW (window), accel_group);
286
   gtk_window_remove_accel_group(GTK_WINDOW (window), accel_group);
Lines 311-339 Link Here
311
/* 
441
/* 
312
 * show or update the progress bar
442
 * show or update the progress bar
313
 */
443
 */
314
static int gtkui_progress(char *title, int value, int max)
444
static void gtkui_progress(char *title, int value, int max)
315
{
445
{
316
   static GtkWidget *progress_dialog = NULL;
317
   static GtkWidget *progress_bar = NULL;
318
   static GtkWidget *hbox, *button;
446
   static GtkWidget *hbox, *button;
319
447
320
#ifndef OS_MINGW
321
   /* FIXME: try to understand why it does not work under mingw.
322
    * (look even in ec_scan.c
323
    */
324
   gdk_threads_enter();
325
#endif
326
   
327
   if (progress_cancelled == TRUE) {
328
      progress_dialog = NULL;
329
      progress_bar = NULL;
330
      progress_cancelled = FALSE;
331
#ifndef OS_MINGW
332
      gdk_threads_leave();
333
#endif
334
      return UI_PROGRESS_INTERRUPTED;
335
   }
336
337
   /* the first time, create the object */
448
   /* the first time, create the object */
338
   if (progress_bar == NULL) {
449
   if (progress_bar == NULL) {
339
      progress_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
450
      progress_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
Lines 363-376 Link Here
363
   gtk_progress_bar_set_text(GTK_PROGRESS_BAR (progress_bar), title);
474
   gtk_progress_bar_set_text(GTK_PROGRESS_BAR (progress_bar), title);
364
   gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (progress_bar), (gdouble)((gdouble)value / (gdouble)max));
475
   gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (progress_bar), (gdouble)((gdouble)value / (gdouble)max));
365
476
366
#ifndef OS_MINGW
367
   gdk_threads_leave();
368
#else
369
   /* a nasty little loop that lets gtk update the progress bar immediately */
477
   /* a nasty little loop that lets gtk update the progress bar immediately */
370
   while (gtk_events_pending ())
478
   while (gtk_events_pending ())
371
      gtk_main_iteration ();
479
      gtk_main_iteration ();
372
#endif
480
373
   
374
   /* 
481
   /* 
375
    * when 100%, destroy it
482
    * when 100%, destroy it
376
    */
483
    */
Lines 378-398 Link Here
378
      gtk_widget_destroy(progress_dialog);
485
      gtk_widget_destroy(progress_dialog);
379
      progress_dialog = NULL;
486
      progress_dialog = NULL;
380
      progress_bar = NULL;
487
      progress_bar = NULL;
381
#ifndef OS_MINGW
382
      gdk_threads_leave();
383
#endif
384
      return UI_PROGRESS_FINISHED;
385
   }
488
   }
386
387
   return UI_PROGRESS_UPDATED;
388
}
489
}
389
490
390
static gboolean gtkui_progress_cancel(GtkWidget *window, gpointer data) {
491
static gboolean gtkui_progress_cancel(GtkWidget *window, gpointer data) {
391
   progress_cancelled = TRUE;
492
   progress_cancelled = TRUE;
392
493
393
   /* the progress dialog must be manually destroyed if the cancel button is used */
494
   /* the progress dialog must be manually destroyed if the cancel button is used */
394
   if(data != NULL && GTK_IS_WIDGET(data))
495
   if(data != NULL && GTK_IS_WIDGET(data)) {
395
       gtk_widget_destroy(data);
496
      gtk_widget_destroy(data);
497
      progress_dialog = NULL;
498
      progress_bar = NULL;
499
   }
396
500
397
   return(FALSE);
501
   return(FALSE);
398
}
502
}
Lines 437-445 Link Here
437
      gtkui_sniff_live();
541
      gtkui_sniff_live();
438
   
542
   
439
   /* the main gui loop, once this exits the gui will be destroyed */
543
   /* the main gui loop, once this exits the gui will be destroyed */
440
   gdk_threads_enter();
441
   gtk_main();
544
   gtk_main();
442
   gdk_threads_leave();
443
545
444
   gtk_timeout_remove(idle_flush);
546
   gtk_timeout_remove(idle_flush);
445
}
547
}
(-)src/interfaces/gtk/ec_gtk_view_connections.c (-5 / +1 lines)
Lines 900-911 Link Here
900
   ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf);
900
   ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf);
901
   dispbuf[ret] = 0;
901
   dispbuf[ret] = 0;
902
        
902
        
903
   gdk_threads_enter();
904
   if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1))
903
   if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1))
905
      gtkui_data_print(1, dispbuf, 0);
904
      gtkui_data_print(1, dispbuf, 0);
906
   else
905
   else
907
      gtkui_data_print(2, dispbuf, 0);
906
      gtkui_data_print(2, dispbuf, 0);
908
   gdk_threads_leave();
909
}
907
}
910
908
911
/*
909
/*
Lines 1066-1078 Link Here
1066
   /* format the data */
1064
   /* format the data */
1067
   ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf);
1065
   ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf);
1068
   dispbuf[ret] = 0;
1066
   dispbuf[ret] = 0;
1069
        
1067
1070
   gdk_threads_enter();
1071
   if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1))
1068
   if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1))
1072
      gtkui_data_print(3, dispbuf, 1);
1069
      gtkui_data_print(3, dispbuf, 1);
1073
   else
1070
   else
1074
      gtkui_data_print(3, dispbuf, 2);
1071
      gtkui_data_print(3, dispbuf, 2);
1075
   gdk_threads_leave();
1076
}
1072
}
1077
1073
1078
/*
1074
/*

Return to bug 346423