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

« back to all changes in this revision

Viewing changes to src/xt_options.c

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2004-08-29 10:53:42 UTC
  • Revision ID: james.westby@ubuntu.com-20040829105342-qgmnry37eadfkoxx
Tags: upstream-1.1.3
ImportĀ upstreamĀ versionĀ 1.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * xt_options.c
 
3
 *
 
4
 * Copyright (C) 1997,98 Rasca, Berlin
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 *
 
20
 *
 
21
 * This file contains the Xt GUI's options dialog
 
22
 *
 
23
 */
 
24
 
 
25
#include "../config.h"  /* autoconf output */
 
26
 
 
27
#include <stdio.h>
 
28
#include <stdlib.h>
 
29
#include <limits.h>
 
30
#include <X11/Intrinsic.h>
 
31
#include <X11/StringDefs.h>
 
32
#include <X11/Shell.h>
 
33
#include "Xw/Label.h"
 
34
#include "Xw/Box.h"
 
35
#include "Xw/Field.h"
 
36
#include "Xw/Button.h"
 
37
#include "Xw/Toggle.h"
 
38
#include "xt_options.h"
 
39
#include "job.h"
 
40
#include "xutil.h"
 
41
#include "app_data.h"
 
42
 
 
43
#define DLG_CANCEL      0
 
44
#define DLG_OK          1
 
45
#define DLG_SAVE        2
 
46
 
 
47
static Widget wShell, wFps, wFile, wMaxFrames, wMaxTime, wQuality;
 
48
static Widget wCompress, wCodec, wShm, wMouse, wMouseType;
 
49
extern Widget next, prev;
 
50
static Job *sJob;
 
51
 
 
52
void ChangeLabel (int pic_no);
 
53
static void CbOk (Widget w, XtPointer client_data, XtPointer call_data);
 
54
static void CbSave (Widget w, XtPointer client_data, XtPointer call_data);
 
55
static void CbCancel (Widget w, XtPointer client_data, XtPointer call_data);
 
56
static void CbActivate (Widget w, XtPointer client_data, XtPointer call_data);
 
57
 
 
58
 
 
59
/*
 
60
 * read the new values and close the window
 
61
 */
 
62
static void
 
63
CbOk (Widget w, XtPointer client_data, XtPointer call_data)
 
64
{
 
65
#include "codecs.h"
 
66
 
 
67
        char *str;
 
68
        int val_int;
 
69
        float val_float;
 
70
        Job *job = (Job *) sJob;
 
71
 
 
72
        str = XwFieldGetString (wQuality);
 
73
        if ( str ) {
 
74
                if ( *str ) {
 
75
                        val_int = job_quality ();
 
76
                        sscanf (str, "%d", &val_int);
 
77
                        job_set_quality (val_int);
 
78
                }
 
79
                free (str);
 
80
        }
 
81
 
 
82
        str = XwFieldGetString (wCompress);
 
83
        if ( str ) {
 
84
                if ( *str ) {
 
85
                        val_int = job_compression ();
 
86
                        sscanf (str, "%d", &val_int);
 
87
                        job_set_compression (val_int);
 
88
                }
 
89
                free (str);
 
90
        }
 
91
 
 
92
        str = XwFieldGetString (wFps);
 
93
        if (str) {
 
94
                if (*str) {
 
95
                        val_float = job_fps ();
 
96
                        sscanf (str, "%f", &val_float);
 
97
                        job_set_fps (val_float);
 
98
                }
 
99
                free (str);
 
100
        }
 
101
 
 
102
        str = XwFieldGetString (wFile);
 
103
        if (str) {
 
104
                if (*str) {
 
105
                        job_set_file (str);
 
106
                }
 
107
                free (str);
 
108
        }
 
109
 
 
110
        str = XwFieldGetString (wMaxFrames);
 
111
        if (str) {
 
112
                if (*str)
 
113
                        sscanf (str, "%d", &job->max_frames);
 
114
                free (str);
 
115
        }
 
116
 
 
117
        str = XwFieldGetString (wMaxTime);
 
118
        if (str) {
 
119
                if (*str)
 
120
                        sscanf (str, "%f", &job->max_time);
 
121
                free (str);
 
122
        }
 
123
 
 
124
        str = XwFieldGetString (wCodec);
 
125
        if (str) {
 
126
                if (*str) {
 
127
                        int i, a = -1;
 
128
                        Boolean found = FALSE;
 
129
 
 
130
                        for  (i = 0; i < NUMCODECS; i ++) {
 
131
                                if (strcmp(tCodecNames[i], str) == 0) a = i;
 
132
                        }
 
133
                        if (a < CODEC_MPEG1) {
 
134
                                a = CODEC_MPEG1;
 
135
                                fprintf(stderr, "Unsupported Codec selected, resetting to MPEG1!\n");
 
136
                        }
 
137
                        job->targetCodec = a;
 
138
                }
 
139
                free (str);
 
140
        }
 
141
 
 
142
#ifdef HAVE_SHMAT
 
143
        XtVaGetValues (wShm, XtNstate, &val_int, NULL);
 
144
        if (val_int) {
 
145
                job->flags |= FLG_USE_SHM;
 
146
                job_set_capture ();
 
147
        } else {
 
148
                job->flags &= ~FLG_USE_SHM;
 
149
                job_set_capture ();
 
150
        }
 
151
#endif
 
152
        XtVaGetValues (wMouse, XtNstate, &val_int, NULL);
 
153
        if (val_int) {
 
154
                XtVaGetValues (wMouseType, XtNstate, &val_int, NULL);
 
155
                if (val_int) {
 
156
                        job->mouseWanted = 2;
 
157
                } else {
 
158
                        job->mouseWanted = 1;
 
159
                }
 
160
        } else {
 
161
                job->mouseWanted = 0;
 
162
        }
 
163
 
 
164
        XtDestroyWidget (wShell);
 
165
        ChangeLabel (job->pic_no);
 
166
 
 
167
        // unset autocontinue unless we capture to movie and file is mutable
 
168
        if ( job->flags & FLG_AUTO_CONTINUE && ( (! is_filename_mutable(job->file)) ||
 
169
                (! job->flags & FLG_MULTI_IMAGE) ) ) {
 
170
            job->flags &= ~FLG_AUTO_CONTINUE;
 
171
            fprintf(stderr, "Output not a video file or no counter in filename\nDisabling autocontinue!\n");
 
172
        }
 
173
        
 
174
    /* previous and next buttons have different meanings for on-the-fly encoding
 
175
     * and individual frame capture */
 
176
    if (( job->flags & FLG_MULTI_IMAGE ) == 0 ) {
 
177
        if (job->pic_no > job->step ) XtSetSensitive(prev, True);
 
178
        else XtSetSensitive(prev, False);
 
179
    } else {
 
180
        if ( is_filename_mutable(job->file) ) {
 
181
            XtSetSensitive(next, True);    
 
182
            XtSetSensitive(prev, True);    
 
183
        } else {
 
184
            XtSetSensitive(next, False);    
 
185
            if (job->movie_no > 0 ) XtSetSensitive(prev, True);    
 
186
            else XtSetSensitive(prev, False);    
 
187
        }
 
188
    }
 
189
        
 
190
}
 
191
 
 
192
/*
 
193
 * save the values
 
194
 */
 
195
static void
 
196
CbSave (Widget w, XtPointer client_data, XtPointer call_data)
 
197
{
 
198
 
 
199
#include "codecs.h"
 
200
 
 
201
        char *str;
 
202
        int val_int;
 
203
        float val_float;
 
204
        char *home;
 
205
        char file[PATH_MAX+1];
 
206
        FILE *fp;
 
207
        Job *job = (Job *) sJob ;
 
208
 
 
209
        str = XwFieldGetString (wQuality);
 
210
        if ( str ) {
 
211
                if ( *str ) {
 
212
                        val_int = job_quality ();
 
213
                        sscanf (str, "%d", &val_int);
 
214
                        job_set_quality (val_int);
 
215
                }
 
216
                free (str);
 
217
        }
 
218
 
 
219
        str = XwFieldGetString (wCompress);
 
220
        if ( str ) {
 
221
                if ( *str ) {
 
222
                        val_int = job_compression ();
 
223
                        sscanf (str, "%d", &val_int);
 
224
                        job_set_compression (val_int);
 
225
                }
 
226
                free (str);
 
227
        }
 
228
 
 
229
        str = XwFieldGetString (wFps);
 
230
        if (str) {
 
231
                if (*str) {
 
232
                        val_float = job_fps ();
 
233
                        sscanf (str, "%f", &val_float);
 
234
                        job_set_fps (val_float);
 
235
                }
 
236
                free (str);
 
237
        }
 
238
 
 
239
        str = XwFieldGetString (wFile);
 
240
        if (str) {
 
241
                if (*str) {
 
242
                        job_set_file (str);
 
243
                }
 
244
                free (str);
 
245
        }
 
246
 
 
247
        str = XwFieldGetString (wMaxFrames);
 
248
        if (str) {
 
249
                if (*str)
 
250
                        sscanf (str, "%d", &job->max_frames);
 
251
                free (str);
 
252
        }
 
253
 
 
254
        str = XwFieldGetString (wMaxTime);
 
255
        if (str) {
 
256
                if (*str)
 
257
                        sscanf (str, "%f", &job->max_time);
 
258
                free (str);
 
259
        }
 
260
 
 
261
        str = XwFieldGetString (wCodec);
 
262
        if (str) {
 
263
                if (*str) {
 
264
                        int i, a = -1;
 
265
                        Boolean found = FALSE;
 
266
 
 
267
                        for  (i = 0; i < NUMCODECS; i ++) {
 
268
                                if (strcmp(tCodecNames[i], str) == 0) a = i;
 
269
                        }
 
270
                        if (a < CODEC_MPEG1) {
 
271
                                a = CODEC_MPEG1;
 
272
                                fprintf(stderr, "Unsupported Codec selected, resetting to MPEG1!\n");
 
273
                        }
 
274
                        job->targetCodec = a;
 
275
                }
 
276
                free (str);
 
277
        }
 
278
 
 
279
#ifdef HAVE_SHMAT
 
280
        XtVaGetValues (wShm, XtNstate, &val_int, NULL);
 
281
        if (val_int) {
 
282
                job->flags |= FLG_USE_SHM;
 
283
                job_set_capture ();
 
284
        } else {
 
285
                job->flags &= ~FLG_USE_SHM;
 
286
                job_set_capture ();
 
287
        }
 
288
#endif
 
289
        XtVaGetValues (wMouse, XtNstate, &val_int, NULL);
 
290
        if (val_int) {
 
291
                XtVaGetValues (wMouseType, XtNstate, &val_int, NULL);
 
292
                if (val_int) {
 
293
                        job->mouseWanted = 2;
 
294
                } else {
 
295
                        job->mouseWanted = 1;
 
296
                }
 
297
        } else {
 
298
                job->mouseWanted = 0;
 
299
        }
 
300
 
 
301
        if ( ! XVC_WriteOptionsFile(job) ) {
 
302
            fprintf(stderr, "Unable to write personal options file!\n");
 
303
        }
 
304
}
 
305
 
 
306
/*
 
307
 */
 
308
static void
 
309
CbCancel (Widget w, XtPointer client_data, XtPointer call_data)
 
310
{
 
311
        XtDestroyWidget (wShell);
 
312
}
 
313
 
 
314
/*
 
315
 */
 
316
static void
 
317
CbActivate (Widget w, XtPointer client_data, XtPointer call_data)
 
318
{
 
319
        static Time t = CurrentTime;
 
320
        Widget next = (Widget) client_data;
 
321
 
 
322
#ifdef DEBUG
 
323
        printf ("%s: CbActivate()\n", __FILE__);
 
324
#endif
 
325
        if (XtCallAcceptFocus (next, &t))
 
326
                XtSetKeyboardFocus (XtParent(w), next);
 
327
}
 
328
 
 
329
 
 
330
/*
 
331
 * create the options dialog window
 
332
 */
 
333
void
 
334
CbOptions (Widget w, XtPointer client_data, XtPointer call_data)
 
335
{
 
336
#include "codecs.h"
 
337
 
 
338
        Job *job = (Job *) client_data;
 
339
        Widget frame, box, info;
 
340
        Widget fps_lbl, file_lbl, max_frames_lbl, max_time_lbl, quality_lbl;
 
341
        Widget compress_lbl, codec_lbl, mouse_lbl, ok, cancel, save;
 
342
        Position x, y;
 
343
        char str[PATH_MAX+1];
 
344
 
 
345
        sJob = job;
 
346
#ifdef DEBUG
 
347
        printf ("CbOptions() fps=%f\n", job->fps);
 
348
#endif
 
349
        wShell = XtVaCreatePopupShell ("options", transientShellWidgetClass,
 
350
                                GetToplevel(w), XtNinput, TRUE, NULL);
 
351
        frame = XtVaCreateManagedWidget ("frame", xwBoxWidgetClass, wShell, NULL);
 
352
 
 
353
        info = XtVaCreateManagedWidget ("info", xwLabelWidgetClass, frame,
 
354
                                        XtNshadowType, XtShadowNone, NULL);
 
355
 
 
356
        sprintf (str, "%f", job->fps);
 
357
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
358
                        XtNorientation, XtorientHorizontal, NULL);
 
359
        wFps = XtVaCreateManagedWidget ("fps_val", xwFieldWidgetClass, box,
 
360
                                        XtNstring, str, XtNonlyNumber, True, NULL);
 
361
        fps_lbl =XtVaCreateManagedWidget ("fps", xwLabelWidgetClass, box, NULL);
 
362
 
 
363
        sprintf (str, "%s", job->file);
 
364
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
365
                        XtNorientation, XtorientHorizontal, NULL);
 
366
        wFile = XtVaCreateManagedWidget ("file_val", xwFieldWidgetClass, box,
 
367
                                        XtNstring, str, XtNprev, wFps, NULL);
 
368
        file_lbl =XtVaCreateManagedWidget ("file", xwLabelWidgetClass, box, NULL);
 
369
 
 
370
        sprintf (str, "%d", job->max_frames);
 
371
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
372
                        XtNorientation, XtorientHorizontal, NULL);
 
373
        wMaxFrames = XtVaCreateManagedWidget ("max_frames_val", xwFieldWidgetClass,
 
374
                                        box, XtNstring, str, XtNonlyNumber, True,
 
375
                                        XtNprev, wFile, NULL);
 
376
        max_frames_lbl = XtVaCreateManagedWidget ("max_frames", xwLabelWidgetClass,
 
377
                                        box, NULL);
 
378
 
 
379
        sprintf (str, "%f", job->max_time);
 
380
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
381
                        XtNorientation, XtorientHorizontal, NULL);
 
382
        wMaxTime = XtVaCreateManagedWidget ("max_time_val", xwFieldWidgetClass,
 
383
                                        box, XtNstring, str, XtNonlyNumber, True,
 
384
                                        XtNprev, wMaxFrames, NULL);
 
385
        max_time_lbl =XtVaCreateManagedWidget ("max_time", xwLabelWidgetClass,
 
386
                                        box, NULL);
 
387
 
 
388
        sprintf (str, "%d", job->quality);
 
389
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
390
                        XtNorientation, XtorientHorizontal, NULL);
 
391
        wQuality = XtVaCreateManagedWidget ("quality_val", xwFieldWidgetClass,
 
392
                                        box, XtNstring, str, XtNonlyNumber, True,
 
393
                                        XtNlength, 3, XtNprev, wMaxTime, NULL);
 
394
        quality_lbl = XtVaCreateManagedWidget ("quality", xwLabelWidgetClass, box,
 
395
                                        NULL);
 
396
 
 
397
 
 
398
        sprintf (str, "%d", job->compress);
 
399
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
400
                        XtNorientation, XtorientHorizontal, NULL);
 
401
        wCompress = XtVaCreateManagedWidget ("compress_val", xwFieldWidgetClass,
 
402
                                        box, XtNstring, str, XtNlength, 1,
 
403
                                        XtNonlyNumber, True, XtNprev, wQuality, NULL);
 
404
        compress_lbl = XtVaCreateManagedWidget ("compress", xwLabelWidgetClass,
 
405
                                        box, NULL);
 
406
 
 
407
        sprintf (str, "%s", tCodecNames[(job->targetCodec)]);
 
408
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
409
                        XtNorientation, XtorientHorizontal, NULL);
 
410
        wCodec = XtVaCreateManagedWidget ("codec_val", xwFieldWidgetClass,
 
411
                                        box, XtNstring, str, XtNprev, wCompress, NULL);
 
412
        codec_lbl = XtVaCreateManagedWidget ("codec (e.g. MPEG4)", xwLabelWidgetClass,
 
413
                                        box, NULL);
 
414
 
 
415
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
416
                        XtNorientation, XtorientHorizontal, NULL);
 
417
        wShm = XtVaCreateManagedWidget ("shm", xwToggleWidgetClass, box,
 
418
                                        XtNstate, (Boolean)(job->flags & FLG_USE_SHM ? 1:0),
 
419
                                        XtNprev, wCodec, NULL);
 
420
 
 
421
        wMouse = XtVaCreateManagedWidget ("mouse", xwToggleWidgetClass, box,
 
422
                                        XtNstate, (Boolean)((job->mouseWanted > 0) ? 1:0),
 
423
                                        XtNprev, wShm, NULL);
 
424
 
 
425
        wMouseType = XtVaCreateManagedWidget ("black", xwToggleWidgetClass, box,
 
426
                                        XtNstate, (Boolean)((job->mouseWanted > 1) ? 1:0),
 
427
                                        XtNprev, wMouse, NULL);
 
428
 
 
429
 
 
430
        /*
 
431
         */
 
432
        box = XtVaCreateManagedWidget ("box", xwBoxWidgetClass, frame,
 
433
                        XtNorientation, XtorientHorizontal, NULL);
 
434
        ok = XtVaCreateManagedWidget ("ok", xwButtonWidgetClass, box,
 
435
                                XtNprev, wShm, NULL);
 
436
        cancel = XtVaCreateManagedWidget ("cancel", xwButtonWidgetClass, box,
 
437
                                XtNprev, ok, NULL);
 
438
        save = XtVaCreateManagedWidget ("save", xwButtonWidgetClass, box,
 
439
                                XtNprev, cancel, XtNnext, wFps, NULL);
 
440
 
 
441
        XtVaSetValues (cancel, XtNnext, save, NULL);
 
442
        XtVaSetValues (ok, XtNnext, cancel, NULL);
 
443
        XtVaSetValues (wShm, XtNnext, ok, NULL);
 
444
        XtVaSetValues (wCompress, XtNnext, wShm, NULL);
 
445
        XtVaSetValues (wQuality, XtNnext, wCompress, NULL);
 
446
        XtVaSetValues (wMaxTime, XtNnext, wQuality, NULL);
 
447
        XtVaSetValues (wMaxFrames, XtNnext, wMaxTime, NULL);
 
448
        XtVaSetValues (wFile, XtNnext, wMaxFrames, NULL);
 
449
        XtVaSetValues (wFps, XtNnext, wFile, XtNprev, save, NULL);
 
450
 
 
451
        XtAddCallback (wFps, XtNactivateCallback, CbActivate, wFile);
 
452
        XtAddCallback (wFile, XtNactivateCallback, CbActivate, wMaxFrames);
 
453
        XtAddCallback (wMaxFrames, XtNactivateCallback, CbActivate, wMaxTime);
 
454
        XtAddCallback (wMaxTime, XtNactivateCallback, CbActivate, wQuality);
 
455
        XtAddCallback (wQuality, XtNactivateCallback, CbActivate, wCompress);
 
456
        XtAddCallback (wCompress, XtNactivateCallback, CbActivate, wShm);
 
457
 
 
458
        XtAddCallback (ok, XtNcallback, CbOk, job);
 
459
        XtAddCallback (cancel, XtNcallback, CbCancel, NULL);
 
460
        XtAddCallback (save, XtNcallback, CbSave, job);
 
461
 
 
462
        XtTranslateCoords (w, 0, 0, &x, &y);
 
463
        XtVaSetValues (wShell, XtNx, x, XtNy, y, NULL);
 
464
 
 
465
        XtPopup (wShell, XtGrabNonexclusive);
 
466
}
 
467
 
 
468
/*
 
469
 */
 
470
void
 
471
OptionDoneAction (Widget w, XEvent *ev, String *parms, Cardinal *num_parms)
 
472
{
 
473
        if (*num_parms) {
 
474
                if (*parms[0] == '1') {
 
475
                        CbOk (w, (XtPointer)DLG_OK, NULL);
 
476
                } else if (*parms[0] == '2') {
 
477
                        CbSave (w, (XtPointer)DLG_SAVE, NULL);
 
478
                } else {
 
479
                        CbCancel (w, NULL, NULL);
 
480
                }
 
481
        }
 
482
}
 
483
 
 
484
/*
 
485
 */
 
486
void
 
487
OptionOpenAction (Widget w, XEvent *ev, String *parms, Cardinal *num_parms)
 
488
{
 
489
        Job *job = job_ptr();
 
490
        CbOptions (w, (XtPointer) job, (XtPointer) NULL);
 
491
}