2
* \file gnome_warning.c
4
* this file contains the warnings dialog for the options dialog of
7
* \todo investigate what's to be done with the warning text and line breaks
8
* \todo make the warning text generally applicable or distinguish between
12
* Copyright (C) 2003-07 Karl H. Beckers, Frankfurt
14
* This program is free software; you can redistribute it and/or modify
15
* it under the terms of the GNU General Public License as published by
16
* the Free Software Foundation; either version 2 of the License, or
17
* (at your option) any later version.
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU General Public License for more details.
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to the Free Software
26
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30
#ifndef DOXYGEN_SHOULD_SKIP_THIS
35
#define DEBUGFILE "gnome_warning.c"
36
#endif // DOXYGEN_SHOULD_SKIP_THIS
39
#include <sys/types.h>
45
#include <glade/glade.h>
48
#include "gnome_options.h"
50
#include "xv_error_item.h"
56
/** \brief make the warning window globally available */
57
GtkWidget *xvc_warn_main_window;
59
#ifndef DOXYGEN_SHOULD_SKIP_THIS
60
extern GtkWidget *xvc_ctrl_m1;
61
extern GtkWidget *xvc_pref_main_window;
62
#endif // DOXYGEN_SHOULD_SKIP_THIS
64
// static gint xvc_warn_label_width = 0;
66
* \brief tells from where the warning originates
68
* <ul><li>0 = preferences dialog</li>
69
* <li>1 = capture type toggle</li>
70
* <li>2 = initial validation in main.c</li></ul>
72
static int called_from_where = 0;
75
* \brief the initial resize of the warning needs to be done a little time
76
* after the display of the dialog, so the actual size of the components
77
* can be determined. Therefor this is done through a timed function
78
* and the id of that is stored here.
80
* @see auto_resize_warning_dialog
82
static guint scheduled_warning_resize_id = 0;
84
/** \brief the list of errors that caused this warning to be displayed */
85
static XVC_ErrorListItem *warning_elist = NULL;
91
* \brief displays the xvidcap user manual. This is used when a user
92
* clicks the Help button on the warning dialog.
97
system ("yelp ghelp:xvidcap?xvidcap-warning &");
101
* \brief the initial resize of the warning needs to be done a little time
102
* after the display of the dialog, so the actual size of the components
103
* can be determined. Therefor this is done through a timed function.
106
auto_resize_warning_dialog ()
109
#define DEBUGFUNCTION "auto_resize_warning_dialog()"
110
GtkRequisition vp_size;
111
int set_size = 0, orig_vp_size = 0;
114
GtkWidget *vbox = NULL, *viewport = NULL, *eitem = NULL;
116
int ind = 0, height = 0;
117
GladeXML *xml = NULL;
120
printf ("%s %s: Entering\n", DEBUGFILE, DEBUGFUNCTION);
123
g_assert (xvc_warn_main_window);
124
xml = glade_get_widget_tree (GTK_WIDGET (xvc_warn_main_window));
125
vbox = glade_xml_get_widget (xml, "xvc_warn_errors_vbox");
128
elist = gtk_container_get_children (GTK_CONTAINER (vbox));
129
eitem = g_list_nth_data (elist, 0);
130
// the hack keeps getting uglier ...
131
if (eitem->allocation.height > 1) {
133
for (ind = 0; ind < g_list_length (elist); ind++) {
134
eitem = g_list_nth_data (elist, ind);
136
height += (eitem->allocation.height + 1);
139
set_size = (height > 400 ? 400 : height);
141
viewport = glade_xml_get_widget (xml, "xvc_warn_errors_viewport");
144
gtk_widget_size_request (viewport, &vp_size);
145
orig_vp_size = vp_size.height;
147
gtk_widget_set_size_request (viewport, -1, set_size);
148
gtk_widget_size_request (viewport, &vp_size);
150
gtk_window_get_size (GTK_WINDOW (xvc_warn_main_window), &win_width,
152
gtk_window_resize (GTK_WINDOW (xvc_warn_main_window), win_width,
153
win_height - (orig_vp_size - vp_size.height) + 1);
155
g_source_remove (scheduled_warning_resize_id);
158
printf ("%s %s: Leaving\n", DEBUGFILE, DEBUGFUNCTION);
163
* \brief creates a warning dialog widget displaying the errors contained
164
* in the list passed.
166
* @param elist the list of errors to display
167
* @param from_where flag to tell the warning where it originated from. The
168
* values recognized are defined with called_from_where.
169
* @return the warning dialog widget
170
* @see called_from_where
173
xvc_create_warning_with_errors (XVC_ErrorListItem * elist, int from_where)
176
#define DEBUGFUNCTION "xvc_create_warning_with_errors()"
177
GtkWidget *vbox = NULL, *w = NULL;
178
GladeXML *xml = NULL;
179
int count_fatal_messages = 0;
180
XVC_AppData *app = xvc_appdata_ptr ();
183
printf ("%s %s: Entering\n", DEBUGFILE, DEBUGFUNCTION);
186
// save list for cleanup
187
warning_elist = elist;
189
called_from_where = from_where;
191
// load the interface
192
xml = glade_xml_new (XVC_GLADE_FILE, "xvc_warn_main_window", NULL);
195
// connect the signals in the interface
196
glade_xml_signal_autoconnect (xml);
197
// store the toplevel widget for further reference
198
xvc_warn_main_window = glade_xml_get_widget (xml, "xvc_warn_main_window");
199
g_assert (xvc_warn_main_window);
201
// set the error list
203
XVC_ErrorListItem *err = NULL;
205
vbox = glade_xml_get_widget (xml, "xvc_warn_errors_vbox");
209
for (; err != NULL; err = err->next) {
212
if (err->err->type != XVC_ERR_INFO
213
|| (app->flags & FLG_RUN_VERBOSE)) {
214
if (err->err->type == XVC_ERR_FATAL)
215
count_fatal_messages++;
216
eitem = xv_error_item_new_with_error (err->err);
217
gtk_box_pack_start (GTK_BOX (vbox), eitem, FALSE, FALSE, 0);
218
gtk_widget_show (eitem);
223
"%s %s: displaying a warning with a NULL error list\n",
224
DEBUGFILE, DEBUGFUNCTION);
227
// depending on where we're called from make different buttons
229
switch (called_from_where) {
232
w = glade_xml_get_widget (xml, "xvc_warn_pref_button");
237
w = glade_xml_get_widget (xml, "xvc_warn_cancel_button");
244
w = glade_xml_get_widget (xml, "xvc_warn_pref_button");
249
w = glade_xml_get_widget (xml, "xvc_warn_cancel_button");
257
printf ("%s %s: called from where %i\n", DEBUGFILE, DEBUGFUNCTION,
261
// auto-resize the dialog ... this is one ugly hack but the only way
263
scheduled_warning_resize_id = g_timeout_add ((guint32) 5, (GtkFunction)
264
auto_resize_warning_dialog,
268
printf ("%s %s: Leaving\n", DEBUGFILE, DEBUGFUNCTION);
271
return xvc_warn_main_window;
278
#ifndef DOXYGEN_SHOULD_SKIP_THIS
281
* // // recalculate line breaks when size changes typedef struct
282
* _LabelWrapWidth LabelWrapWidth; struct _LabelWrapWidth { gint width;
283
* PangoFontDescription *font_desc; };
285
* static void set_label_wrap_width (GtkLabel *label, gint set_width) { //
286
* PangoLayout *layout; GtkStyle *style = GTK_WIDGET (label)->style;
289
* LabelWrapWidth *wrap_width = g_object_get_data (G_OBJECT (style),
290
* "gtk-label-wrap-width"); if (!wrap_width) { wrap_width = g_new0
291
* (LabelWrapWidth, 1); g_object_set_data_full (G_OBJECT (style),
292
* "gtk-label-wrap-width", wrap_width, label_wrap_width_free ); }
294
* // printf("gtk2_warning: setting wrap_width to %i\n", ( set_width *
295
* 1000 ) ); wrap_width->width = ( set_width * 1000 ); }
298
* void on_xvc_warn_main_window_size_allocate(GtkWidget *w, gpointer
299
* user_data) { gint new_width = w->allocation.width; GladeXML *xml =
300
* NULL; GtkWidget *label = NULL;
302
* xml = glade_get_widget_tree(xvc_warn_main_window); g_assert(xml); label
303
* = glade_xml_get_widget(xml, "xvc_warn_label"); g_assert(label);
305
* // printf("gtk2_warning: got wrap_width: %i\n", wrap_width); //
306
* GtkStyle *style = GTK_WIDGET (label)->style; // g_assert(style);
308
* // LabelWrapWidth *wrap = g_object_get_data (G_OBJECT (style),
309
* "gtk-label-wrap-width"); // printf("gtk2_warning: old_width %i -
310
* new_width %i\n", (int) label2_width, (int) new_width);
312
* if ( xvc_warn_label_width != new_width ) { xvc_warn_label_width =
315
* set_label_wrap_width( GTK_LABEL(label), new_width );
316
* gtk_label_set_text(GTK_LABEL(label), XVC_WARN_LABEL_TEXT); } }
320
on_xvc_warn_main_window_delete_event (GtkWidget * widget, GdkEvent * event,
323
if (called_from_where == 2)
330
on_xvc_warn_main_window_close (GtkDialog * dialog, gpointer user_data)
336
on_xvc_warn_main_window_destroy (GtkButton * button, gpointer user_data)
342
on_xvc_warn_main_window_response (GtkDialog * dialog, gint response_id,
346
#define DEBUGFUNCTION "on_xvc_warn_main_window_response()"
347
GladeXML *xml = NULL;
348
GtkWidget *mitem = NULL;
351
printf ("%s %s: Entering with response_id %i, called from %i\n",
352
DEBUGFILE, DEBUGFUNCTION, response_id, called_from_where);
355
switch (response_id) {
356
case GTK_RESPONSE_OK:
358
if (warning_elist != NULL) {
359
XVC_ErrorListItem *err;
362
for (; err != NULL; err = err->next) {
363
(*err->err->action) (err);
367
warning_elist = xvc_errorlist_delete (warning_elist);
369
switch (called_from_where) {
371
gtk_widget_destroy (xvc_warn_main_window);
376
gtk_widget_destroy (xvc_warn_main_window);
377
xvc_toggle_cap_type ();
381
gtk_widget_destroy (xvc_warn_main_window);
382
xvc_check_start_options ();
385
case GTK_RESPONSE_CANCEL:
386
switch (called_from_where) {
388
xvc_pref_reset_OK_attempts ();
389
gtk_widget_destroy (xvc_warn_main_window);
393
xvc_undo_toggle_cap_type ();
394
gtk_widget_destroy (xvc_warn_main_window);
399
case GTK_RESPONSE_HELP:
402
case GTK_RESPONSE_REJECT:
403
xml = glade_get_widget_tree (xvc_ctrl_m1);
405
mitem = glade_xml_get_widget (xml, "xvc_ctrl_m1_mitem_preferences");
407
gtk_menu_item_activate (GTK_MENU_ITEM (mitem));
410
xml = glade_get_widget_tree (xvc_pref_main_window);
412
mitem = glade_xml_get_widget (xml, "xvc_pref_cancel_button");
414
gtk_widget_set_sensitive (GTK_WIDGET (mitem), FALSE);
416
warning_elist = xvc_errorlist_delete (warning_elist);
417
xvc_pref_reset_OK_attempts ();
419
gtk_widget_destroy (xvc_warn_main_window);
426
printf ("%s %s: Leaving\n", DEBUGFILE, DEBUGFUNCTION);
430
#endif // DOXYGEN_SHOULD_SKIP_THIS