~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/gnome_warning.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-25 15:47:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080225154712-qvr11ekcea4c9ry8
Tags: 1.1.6-0.1ubuntu1
* Merge from debian-multimedia (LP: #120003), Ubuntu Changes:
 - For ffmpeg-related build-deps, remove cvs from package names.
 - Standards-Version 3.7.3
 - Maintainer Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file gnome_warning.c
 
3
 *
 
4
 * this file contains the warnings dialog for the options dialog of
 
5
 * the GTK2 control
 
6
 *
 
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
 
9
 *      the cases.
 
10
 */
 
11
/*
 
12
 * Copyright (C) 2003-07 Karl H. Beckers, Frankfurt
 
13
 *
 
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.
 
18
 *
 
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.
 
23
 *
 
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.
 
27
 *
 
28
 */
 
29
 
 
30
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
31
#ifdef HAVE_CONFIG_H
 
32
# include <config.h>
 
33
#endif
 
34
 
 
35
#define DEBUGFILE "gnome_warning.c"
 
36
#endif     // DOXYGEN_SHOULD_SKIP_THIS
 
37
 
 
38
#include <stdlib.h>
 
39
#include <sys/types.h>
 
40
#include <sys/stat.h>
 
41
#include <unistd.h>
 
42
#include <string.h>
 
43
#include <stdio.h>
 
44
#include <gtk/gtk.h>
 
45
#include <glade/glade.h>
 
46
 
 
47
#include "control.h"
 
48
#include "gnome_options.h"
 
49
#include "gnome_ui.h"
 
50
#include "xv_error_item.h"
 
51
#include "app_data.h"
 
52
 
 
53
/*
 
54
 * global variables
 
55
 */
 
56
/** \brief make the warning window globally available */
 
57
GtkWidget *xvc_warn_main_window;
 
58
 
 
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
 
63
 
 
64
// static gint xvc_warn_label_width = 0;
 
65
/**
 
66
 * \brief tells from where the warning originates
 
67
 *
 
68
 * <ul><li>0 = preferences dialog</li>
 
69
 * <li>1 = capture type toggle</li>
 
70
 * <li>2 = initial validation in main.c</li></ul>
 
71
 */
 
72
static int called_from_where = 0;
 
73
 
 
74
/**
 
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.
 
79
 *
 
80
 * @see auto_resize_warning_dialog
 
81
 */
 
82
static guint scheduled_warning_resize_id = 0;
 
83
 
 
84
/** \brief the list of errors that caused this warning to be displayed */
 
85
static XVC_ErrorListItem *warning_elist = NULL;
 
86
 
 
87
/*
 
88
 * helper functions
 
89
 */
 
90
/**
 
91
 * \brief displays the xvidcap user manual. This is used when a user
 
92
 *      clicks the Help button on the warning dialog.
 
93
 */
 
94
static void
 
95
doHelp ()
 
96
{
 
97
    system ("yelp ghelp:xvidcap?xvidcap-warning &");
 
98
}
 
99
 
 
100
/**
 
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.
 
104
 */
 
105
void
 
106
auto_resize_warning_dialog ()
 
107
{
 
108
#undef DEBUGFUNCTION
 
109
#define DEBUGFUNCTION "auto_resize_warning_dialog()"
 
110
    GtkRequisition vp_size;
 
111
    int set_size = 0, orig_vp_size = 0;
 
112
    gint win_width = 0;
 
113
    gint win_height = 0;
 
114
    GtkWidget *vbox = NULL, *viewport = NULL, *eitem = NULL;
 
115
    GList *elist = NULL;
 
116
    int ind = 0, height = 0;
 
117
    GladeXML *xml = NULL;
 
118
 
 
119
#ifdef DEBUG
 
120
    printf ("%s %s: Entering\n", DEBUGFILE, DEBUGFUNCTION);
 
121
#endif     // DEBUG
 
122
 
 
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");
 
126
    g_assert (vbox);
 
127
 
 
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) {
 
132
 
 
133
        for (ind = 0; ind < g_list_length (elist); ind++) {
 
134
            eitem = g_list_nth_data (elist, ind);
 
135
            g_assert (eitem);
 
136
            height += (eitem->allocation.height + 1);
 
137
        }
 
138
 
 
139
        set_size = (height > 400 ? 400 : height);
 
140
 
 
141
        viewport = glade_xml_get_widget (xml, "xvc_warn_errors_viewport");
 
142
        g_assert (viewport);
 
143
 
 
144
        gtk_widget_size_request (viewport, &vp_size);
 
145
        orig_vp_size = vp_size.height;
 
146
 
 
147
        gtk_widget_set_size_request (viewport, -1, set_size);
 
148
        gtk_widget_size_request (viewport, &vp_size);
 
149
 
 
150
        gtk_window_get_size (GTK_WINDOW (xvc_warn_main_window), &win_width,
 
151
                             &win_height);
 
152
        gtk_window_resize (GTK_WINDOW (xvc_warn_main_window), win_width,
 
153
                           win_height - (orig_vp_size - vp_size.height) + 1);
 
154
 
 
155
        g_source_remove (scheduled_warning_resize_id);
 
156
    }
 
157
#ifdef DEBUG
 
158
    printf ("%s %s: Leaving\n", DEBUGFILE, DEBUGFUNCTION);
 
159
#endif     // DEBUG
 
160
}
 
161
 
 
162
/**
 
163
 * \brief creates a warning dialog widget displaying the errors contained
 
164
 *      in the list passed.
 
165
 *
 
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
 
171
 */
 
172
GtkWidget *
 
173
xvc_create_warning_with_errors (XVC_ErrorListItem * elist, int from_where)
 
174
{
 
175
#undef DEBUGFUNCTION
 
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 ();
 
181
 
 
182
#ifdef DEBUG
 
183
    printf ("%s %s: Entering\n", DEBUGFILE, DEBUGFUNCTION);
 
184
#endif     // DEBUG
 
185
 
 
186
    // save list for cleanup
 
187
    warning_elist = elist;
 
188
    // save the origin
 
189
    called_from_where = from_where;
 
190
 
 
191
    // load the interface
 
192
    xml = glade_xml_new (XVC_GLADE_FILE, "xvc_warn_main_window", NULL);
 
193
    g_assert (xml);
 
194
 
 
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);
 
200
 
 
201
    // set the error list
 
202
    if (elist != NULL) {
 
203
        XVC_ErrorListItem *err = NULL;
 
204
 
 
205
        vbox = glade_xml_get_widget (xml, "xvc_warn_errors_vbox");
 
206
        g_assert (vbox);
 
207
 
 
208
        err = elist;
 
209
        for (; err != NULL; err = err->next) {
 
210
            GtkWidget *eitem;
 
211
 
 
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);
 
219
            }
 
220
        }
 
221
    } else {
 
222
        fprintf (stderr,
 
223
                 "%s %s: displaying a warning with a NULL error list\n",
 
224
                 DEBUGFILE, DEBUGFUNCTION);
 
225
    }
 
226
 
 
227
    // depending on where we're called from make different buttons
 
228
    // visible/sensitive
 
229
    switch (called_from_where) {
 
230
    case 0:
 
231
        w = NULL;
 
232
        w = glade_xml_get_widget (xml, "xvc_warn_pref_button");
 
233
        g_assert (w);
 
234
        gtk_widget_hide (w);
 
235
 
 
236
        w = NULL;
 
237
        w = glade_xml_get_widget (xml, "xvc_warn_cancel_button");
 
238
        g_assert (w);
 
239
        gtk_widget_show (w);
 
240
        break;
 
241
    case 1:
 
242
    case 2:
 
243
        w = NULL;
 
244
        w = glade_xml_get_widget (xml, "xvc_warn_pref_button");
 
245
        g_assert (w);
 
246
        gtk_widget_show (w);
 
247
 
 
248
        w = NULL;
 
249
        w = glade_xml_get_widget (xml, "xvc_warn_cancel_button");
 
250
        g_assert (w);
 
251
        gtk_widget_hide (w);
 
252
        break;
 
253
    default:
 
254
        break;
 
255
    }
 
256
#ifdef DEBUG
 
257
    printf ("%s %s: called from where %i\n", DEBUGFILE, DEBUGFUNCTION,
 
258
            called_from_where);
 
259
#endif     // DEBUG
 
260
 
 
261
    // auto-resize the dialog ... this is one ugly hack but the only way
 
262
    // to do it
 
263
    scheduled_warning_resize_id = g_timeout_add ((guint32) 5, (GtkFunction)
 
264
                                                 auto_resize_warning_dialog,
 
265
                                                 NULL);
 
266
 
 
267
#ifdef DEBUG
 
268
    printf ("%s %s: Leaving\n", DEBUGFILE, DEBUGFUNCTION);
 
269
#endif     // DEBUG
 
270
 
 
271
    return xvc_warn_main_window;
 
272
}
 
273
 
 
274
/*
 
275
 * callbacks
 
276
 */
 
277
 
 
278
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
279
 
 
280
/*
 
281
 * // // recalculate line breaks when size changes typedef struct
 
282
 * _LabelWrapWidth LabelWrapWidth; struct _LabelWrapWidth { gint width;
 
283
 * PangoFontDescription *font_desc; };
 
284
 *
 
285
 * static void set_label_wrap_width (GtkLabel *label, gint set_width) { //
 
286
 * PangoLayout *layout; GtkStyle *style = GTK_WIDGET (label)->style;
 
287
 * g_assert(style);
 
288
 *
 
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 ); }
 
293
 *
 
294
 * // printf("gtk2_warning: setting wrap_width to %i\n", ( set_width *
 
295
 * 1000 ) ); wrap_width->width = ( set_width * 1000 ); }
 
296
 *
 
297
 *
 
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;
 
301
 *
 
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);
 
304
 *
 
305
 * // printf("gtk2_warning: got wrap_width: %i\n", wrap_width); //
 
306
 * GtkStyle *style = GTK_WIDGET (label)->style; // g_assert(style);
 
307
 *
 
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);
 
311
 *
 
312
 * if ( xvc_warn_label_width != new_width ) { xvc_warn_label_width =
 
313
 * new_width;
 
314
 *
 
315
 * set_label_wrap_width( GTK_LABEL(label), new_width );
 
316
 * gtk_label_set_text(GTK_LABEL(label), XVC_WARN_LABEL_TEXT); } }
 
317
 */
 
318
 
 
319
gboolean
 
320
on_xvc_warn_main_window_delete_event (GtkWidget * widget, GdkEvent * event,
 
321
                                      gpointer user_data)
 
322
{
 
323
    if (called_from_where == 2)
 
324
        return TRUE;
 
325
    else
 
326
        return FALSE;
 
327
}
 
328
 
 
329
void
 
330
on_xvc_warn_main_window_close (GtkDialog * dialog, gpointer user_data)
 
331
{
 
332
    // empty as yet ...
 
333
}
 
334
 
 
335
void
 
336
on_xvc_warn_main_window_destroy (GtkButton * button, gpointer user_data)
 
337
{
 
338
    // empty as yet ...
 
339
}
 
340
 
 
341
void
 
342
on_xvc_warn_main_window_response (GtkDialog * dialog, gint response_id,
 
343
                                  gpointer user_data)
 
344
{
 
345
#undef DEBUGFUNCTION
 
346
#define DEBUGFUNCTION "on_xvc_warn_main_window_response()"
 
347
    GladeXML *xml = NULL;
 
348
    GtkWidget *mitem = NULL;
 
349
 
 
350
#ifdef DEBUG
 
351
    printf ("%s %s: Entering with response_id %i, called from %i\n",
 
352
            DEBUGFILE, DEBUGFUNCTION, response_id, called_from_where);
 
353
#endif     // DEBUG
 
354
 
 
355
    switch (response_id) {
 
356
    case GTK_RESPONSE_OK:
 
357
 
 
358
        if (warning_elist != NULL) {
 
359
            XVC_ErrorListItem *err;
 
360
 
 
361
            err = warning_elist;
 
362
            for (; err != NULL; err = err->next) {
 
363
                (*err->err->action) (err);
 
364
            }
 
365
        }
 
366
 
 
367
        warning_elist = xvc_errorlist_delete (warning_elist);
 
368
 
 
369
        switch (called_from_where) {
 
370
        case 0:
 
371
            gtk_widget_destroy (xvc_warn_main_window);
 
372
            xvc_pref_do_OK ();
 
373
            break;
 
374
#ifdef USE_FFMPEG
 
375
        case 1:
 
376
            gtk_widget_destroy (xvc_warn_main_window);
 
377
            xvc_toggle_cap_type ();
 
378
            break;
 
379
#endif     // USE_FFMPEG
 
380
        case 2:
 
381
            gtk_widget_destroy (xvc_warn_main_window);
 
382
            xvc_check_start_options ();
 
383
        }
 
384
        break;
 
385
    case GTK_RESPONSE_CANCEL:
 
386
        switch (called_from_where) {
 
387
        case 0:
 
388
            xvc_pref_reset_OK_attempts ();
 
389
            gtk_widget_destroy (xvc_warn_main_window);
 
390
            break;
 
391
#ifdef USE_FFMPEG
 
392
        case 1:
 
393
            xvc_undo_toggle_cap_type ();
 
394
            gtk_widget_destroy (xvc_warn_main_window);
 
395
            break;
 
396
#endif     // USE_FFMPEG
 
397
        }
 
398
        break;
 
399
    case GTK_RESPONSE_HELP:
 
400
        doHelp ();
 
401
        break;
 
402
    case GTK_RESPONSE_REJECT:
 
403
        xml = glade_get_widget_tree (xvc_ctrl_m1);
 
404
        g_assert (xml);
 
405
        mitem = glade_xml_get_widget (xml, "xvc_ctrl_m1_mitem_preferences");
 
406
        g_assert (mitem);
 
407
        gtk_menu_item_activate (GTK_MENU_ITEM (mitem));
 
408
 
 
409
        xml = NULL;
 
410
        xml = glade_get_widget_tree (xvc_pref_main_window);
 
411
        g_assert (xml);
 
412
        mitem = glade_xml_get_widget (xml, "xvc_pref_cancel_button");
 
413
        g_assert (mitem);
 
414
        gtk_widget_set_sensitive (GTK_WIDGET (mitem), FALSE);
 
415
 
 
416
        warning_elist = xvc_errorlist_delete (warning_elist);
 
417
        xvc_pref_reset_OK_attempts ();
 
418
 
 
419
        gtk_widget_destroy (xvc_warn_main_window);
 
420
        break;
 
421
    default:
 
422
        break;
 
423
    }
 
424
 
 
425
#ifdef DEBUG
 
426
    printf ("%s %s: Leaving\n", DEBUGFILE, DEBUGFUNCTION);
 
427
#endif     // DEBUG
 
428
}
 
429
 
 
430
#endif     // DOXYGEN_SHOULD_SKIP_THIS