~ubuntu-branches/ubuntu/vivid/imagination/vivid

« back to all changes in this revision

Viewing changes to src/support.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2011-05-19 13:22:01 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110519132201-4az49l8yvxrag1x0
Tags: 3.0-1
* New upstream release (Closes: #627240).
 - Fixes inverted tooltips in the toolbar (Closes: #599442).
 - Adds updated Brazilian Portuguese (pt_BR) translation.
   Thanks to Sérgio Cipolla (Closes: #599448).
* imagination.install: Don't install la files (Closes: #621684).
* Drop debian/README.source. Not needed with source
  version 3.0 (quilt).
* Bump Standards-Version to 3.9.2, no changes needed.
* debian/rules: Convert to minimal dh 7 style rules file.
* Drop debian/patches/20_lang-zh_TW.patch: zh_TW translation
  have been added upstream. 
* Update debian/patches/15_PLUGINS_INSTALLED.patch and
  debian/patches/10_link_math_lib.patch for new release.
* debian/{control, rules}: Maintain the different Ubuntu and
  Debian recommends in the same source package using dpkg-vendor
  and a ${dist:Recommends} substvar. Thanks to Alessio Treglia.
  (Closes: #627246)
* debian/copyright: Minor tweaks to bring up to rev 174
  of Dep 5.
* debian/control: Update suggests for libavutil-extra-50.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "support.h"
21
21
#include <glib/gstdio.h>
22
22
 
23
 
#define PLUGINS_INSTALLED 1
24
 
 
25
23
static gboolean img_plugin_is_loaded(img_window_struct *, GModule *);
26
24
 
27
25
GtkWidget *img_load_icon(gchar *filename, GtkIconSize size)
54
52
        return g_strdup_printf("%02d:%02d:%02d", h, m, s);
55
53
}
56
54
 
 
55
static void
 
56
sens_cell_func( GtkCellLayout   *layout,
 
57
                                GtkCellRenderer *cell,
 
58
                                GtkTreeModel    *model,
 
59
                                GtkTreeIter     *iter,
 
60
                                gpointer         data )
 
61
{
 
62
        gboolean sensitive = ! gtk_tree_model_iter_has_child( model, iter );
 
63
        g_object_set( cell, "sensitive", sensitive, NULL );
 
64
}
 
65
 
57
66
GtkWidget *_gtk_combo_box_new_text(gboolean pointer)
58
67
{
59
68
        GtkWidget *combo_box;
64
73
 
65
74
        if (pointer)
66
75
        {
67
 
                tree = gtk_tree_store_new (4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_INT);
 
76
                tree = gtk_tree_store_new( 6, GDK_TYPE_PIXBUF,
 
77
                                                                          G_TYPE_STRING,
 
78
                                                                          G_TYPE_POINTER,
 
79
                                                                          G_TYPE_INT,
 
80
                                                                          GDK_TYPE_PIXBUF_ANIMATION,
 
81
                                                                          G_TYPE_BOOLEAN );
68
82
                model = GTK_TREE_MODEL( tree );
69
83
 
70
84
                combo_box = gtk_combo_box_new_with_model (model);
71
85
                g_object_unref (G_OBJECT( model ));
72
 
                cell = gtk_cell_renderer_pixbuf_new ();
73
 
                gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, FALSE);
74
 
                gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, "pixbuf", 0, NULL);
 
86
                cell = img_cell_renderer_anim_new ();
 
87
                gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combo_box ), cell, FALSE );
 
88
                gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT (combo_box), cell,
 
89
                                                                                "anim", 4,
 
90
                                                                                NULL );
 
91
                gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( combo_box ), cell,
 
92
                                                                                        sens_cell_func, NULL, NULL );
 
93
                
 
94
                cell = gtk_cell_renderer_text_new ();
 
95
                gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
 
96
                gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
 
97
                                                                                "text", 1,
 
98
                                                                                NULL);
 
99
                gtk_cell_layout_set_cell_data_func( GTK_CELL_LAYOUT( combo_box ), cell,
 
100
                                                                                        sens_cell_func, NULL, NULL );
 
101
                g_object_set(cell, "ypad", (guint)0, NULL);
75
102
        }
76
103
        else
77
104
        {
80
107
                
81
108
                combo_box = gtk_combo_box_new_with_model (model);
82
109
                g_object_unref (G_OBJECT( model ));
 
110
 
 
111
                cell = gtk_cell_renderer_text_new ();
 
112
                gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
 
113
                gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell,
 
114
                                                                                "text", 0,
 
115
                                                                                NULL);
 
116
                g_object_set(cell, "ypad", (guint)0, NULL);
83
117
        }
84
118
 
85
 
        cell = gtk_cell_renderer_text_new ();
86
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE);
87
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, "text", pointer ? 1 : 0, NULL);
88
 
        g_object_set(cell, "ypad", (guint)0, NULL);
89
119
        return combo_box;
90
120
}
91
121
 
96
126
 
97
127
        if (img_struct->slides_nr == 0)
98
128
        {
99
 
                message = g_strdup_printf(_("Welcome to Imagination - %d transitions loaded."),img_struct->nr_transitions_loaded);
100
 
                gtk_statusbar_push(GTK_STATUSBAR(img_struct->statusbar),img_struct->context_id,message);
101
 
                g_free(message);
102
 
                gtk_label_set_text(GTK_LABEL(img_struct->total_slide_number_label),NULL);
 
129
                message = g_strdup_printf(
 
130
                                ngettext( "Welcome to Imagination - %d transition loaded.",
 
131
                                                  "Welcome to Imagination - %d transitions loaded.",
 
132
                                                  img_struct->nr_transitions_loaded ),
 
133
                                img_struct->nr_transitions_loaded );
 
134
                gtk_statusbar_push( GTK_STATUSBAR( img_struct->statusbar ),
 
135
                                                        img_struct->context_id, message );
 
136
                g_free( message );
 
137
                gtk_label_set_text( GTK_LABEL( img_struct->total_slide_number_label ), NULL );
103
138
        }
104
139
        else if (selected)
105
140
        {
106
 
                message = g_strdup_printf(_("%d slides selected"),selected);
107
 
                gtk_statusbar_push(GTK_STATUSBAR(img_struct->statusbar),img_struct->context_id,message);
108
 
                g_free(message);
 
141
                message = g_strdup_printf( ngettext( "%d slide selected",
 
142
                                                                                         "%d slides selected",
 
143
                                                                                         selected ), selected);
 
144
                gtk_statusbar_push( GTK_STATUSBAR( img_struct->statusbar ),
 
145
                                                        img_struct->context_id, message );
 
146
                g_free( message );
109
147
        }
110
148
        else
111
149
        {
112
150
                total_slides = g_strdup_printf("%d",img_struct->slides_nr);
113
151
                gtk_label_set_text(GTK_LABEL(img_struct->total_slide_number_label),total_slides);
114
 
                message = g_strdup_printf(ngettext("%d slide imported %s" ,"%d slides imported %s",img_struct->slides_nr),img_struct->slides_nr,_(" - Use the CTRL key to select/unselect or SHIFT for multiple select"));
115
 
                gtk_statusbar_push(GTK_STATUSBAR(img_struct->statusbar),img_struct->context_id,message);
 
152
                message = g_strdup_printf( ngettext( "%d slide loaded %s",
 
153
                                                                                         "%d slides loaded %s",
 
154
                                                                                         img_struct->slides_nr ),
 
155
                                                                   img_struct->slides_nr,
 
156
                                                                   _(" - Use the CTRL key to select/unselect "
 
157
                                                                         "or SHIFT for multiple select") );
 
158
                gtk_statusbar_push( GTK_STATUSBAR( img_struct->statusbar ),
 
159
                                                        img_struct->context_id, message );
116
160
                g_free(total_slides);
117
161
                g_free(message);
118
162
        }
120
164
 
121
165
void img_load_available_transitions(img_window_struct *img)
122
166
{
123
 
        GDir          *dir;
124
 
        const gchar   *transition_name;
125
 
        gchar         *fname = NULL, *name, *filename;
126
 
        gchar        **trans, **bak;
127
 
        GModule       *module;
128
 
        GdkPixbuf     *pixbuf;
129
167
        GtkTreeIter    piter, citer;
130
168
        GtkTreeStore  *model;
131
169
        gpointer       address;
132
 
        gchar         *search_paths[3], **path;
133
 
        void (*plugin_set_name)(gchar **, gchar ***);
 
170
        gchar         *search_paths[3],
 
171
                                 **path;
134
172
 
135
 
        model = GTK_TREE_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(img->transition_type)));
 
173
        model = GTK_TREE_STORE( gtk_combo_box_get_model(
 
174
                                                                GTK_COMBO_BOX( img->transition_type ) ) );
136
175
        
137
176
        /* Fill the combo box with no transition */
138
 
        gtk_tree_store_append(model, &piter, NULL);
139
 
        gtk_tree_store_set(model, &piter, 0, NULL, 1, _("None"), 2, NULL, 3, -1, -1);
140
 
        gtk_combo_box_set_active(GTK_COMBO_BOX(img->transition_type), 0);
 
177
        gtk_tree_store_append( model, &piter, NULL );
 
178
        gtk_tree_store_set( model, &piter, 0, NULL,
 
179
                                                                           1, _("None"),
 
180
                                                                           2, NULL,
 
181
                                                                           3, -1,
 
182
                                                                           4, NULL,
 
183
                                                                           -1);
 
184
        gtk_combo_box_set_active( GTK_COMBO_BOX( img->transition_type ), 0 );
141
185
 
142
186
        /* Create NULL terminated array of paths that we'll be looking at */
143
187
#if PLUGINS_INSTALLED
144
 
        search_paths[0] = g_strconcat(PACKAGE_LIB_DIR,"/imagination",NULL);
 
188
        search_paths[0] = g_build_path(G_DIR_SEPARATOR_S, PACKAGE_LIB_DIR, "imagination", NULL );
145
189
#else
146
190
        search_paths[0] = g_strdup("./transitions");
147
191
#endif
148
 
        search_paths[1] = g_strconcat( g_get_home_dir(), "/.imagination/plugins", NULL );
 
192
        search_paths[1] = g_build_path(G_DIR_SEPARATOR_S, g_get_home_dir(), ".imagination",
 
193
                                                                        "plugins", NULL );
149
194
        search_paths[2] = NULL;
150
195
 
151
196
        /* Search all paths listed in array */
152
197
        for( path = search_paths; *path; path++ )
153
198
        {
 
199
                GDir *dir;
 
200
 
154
201
                dir = g_dir_open( *path, 0, NULL );
155
202
                if( dir == NULL )
156
203
                {
160
207
                
161
208
                while( TRUE )
162
209
                {
 
210
                        const gchar  *transition_name;
 
211
                        gchar        *fname = NULL;
 
212
                        GModule      *module;
 
213
                        void (*plugin_set_name)(gchar **, gchar ***);
 
214
 
163
215
                        transition_name = g_dir_read_name( dir );
164
216
                        if ( transition_name == NULL )
165
217
                                break;
168
220
                        module = g_module_open( fname, G_MODULE_BIND_LOCAL );
169
221
                        if( module && img_plugin_is_loaded(img, module) == FALSE )
170
222
                        {
 
223
                                gchar  *name,
 
224
                                          **trans,
 
225
                                          **bak;
 
226
 
171
227
                                /* Obtain the name from the plugin function */
172
228
                                g_module_symbol( module, "img_get_plugin_info",
173
229
                                                                 (void *)&plugin_set_name);
181
237
                                /* Add transitions */
182
238
                                for( bak = trans; *trans; trans += 3 )
183
239
                                {
 
240
                                        gchar              *pix_name,
 
241
                                                                           *anim_name,
 
242
                                                                           *tmp;
 
243
                                        GdkPixbuf          *pixbuf;
 
244
                                        GdkPixbufAnimation *anim;
 
245
                                        gint                id = GPOINTER_TO_INT( trans[2] );
 
246
 
184
247
#if PLUGINS_INSTALLED
185
 
                                        filename =
186
 
                                                g_strdup_printf( "%s/imagination/pixmaps/imagination-%d.png",
187
 
                                                                                 DATADIR, GPOINTER_TO_INT( trans[2] ) );
 
248
                                        tmp = g_build_filename( DATADIR, "imagination",
 
249
                                                                                        "pixmaps", NULL );
188
250
#else /* PLUGINS_INSTALLED */
189
 
                                        filename =
190
 
                                                g_strdup_printf( "./pixmaps/imagination-%d.png",
191
 
                                                                                 GPOINTER_TO_INT( trans[2] ) );
 
251
                                        tmp = g_strdup( "./pixmaps" );
192
252
#endif /* ! PLUGINS_INSTALLED */
193
253
 
194
 
                                        pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
 
254
                                        pix_name = g_strdup_printf( "%s%simagination-%d.png",
 
255
                                                                                                tmp, G_DIR_SEPARATOR_S, id );
 
256
                                        anim_name = g_strdup_printf( "%s%simagination-%d.gif",
 
257
                                                                                                 tmp, G_DIR_SEPARATOR_S, id );
 
258
                                        g_free( tmp );
 
259
 
 
260
                                        pixbuf = gdk_pixbuf_new_from_file( pix_name, NULL );
195
261
 
196
262
                                        /* Local plugins will fail to load images from system
197
263
                                         * folder, so we'll try to load the from home folder. */
198
264
                                        if( ! pixbuf )
199
265
                                        {
200
 
                                                g_free( filename );
201
 
                                                filename =
202
 
                                                        g_strdup_printf( "%s/.imagination/pixmaps/imagination-%d.png",
203
 
                                                                                         g_get_home_dir(),
204
 
                                                                                         GPOINTER_TO_INT( trans[2] ) );
205
 
                                                pixbuf = gdk_pixbuf_new_from_file( filename, NULL );
 
266
                                                g_free( pixbuf );
 
267
                                                g_free( anim );
 
268
 
 
269
                                                tmp = g_build_filename( g_get_home_dir(),
 
270
                                                                                                ".imagination",
 
271
                                                                                                "pixmaps",
 
272
                                                                                                NULL );
 
273
 
 
274
                                                pix_name =
 
275
                                                        g_strdup_printf( "%s%simagination-%d.png",
 
276
                                                                                         tmp, G_DIR_SEPARATOR_S, id );
 
277
                                                anim_name =
 
278
                                                        g_strdup_printf( "%s%simagination-%d.gif",
 
279
                                                                                         tmp, G_DIR_SEPARATOR_S, id );
 
280
                                                g_free( tmp );
 
281
 
 
282
                                                pixbuf = gdk_pixbuf_new_from_file( pix_name, NULL );
206
283
                                        }
207
 
                                        g_free( filename );
 
284
                                        anim = gdk_pixbuf_animation_new_from_file( anim_name,
 
285
                                                                                                                           NULL );
 
286
                                        g_free( pix_name );
 
287
                                        g_free( anim_name );
208
288
                                        g_module_symbol( module, trans[1], &address );
209
289
                                        gtk_tree_store_append( model, &citer, &piter );
210
290
                                        gtk_tree_store_set( model, &citer, 0, pixbuf,
211
291
                                                                                                           1, trans[0],
212
292
                                                                                                           2, address,
213
 
                                                                                                           3, GPOINTER_TO_INT( trans[2] ),
 
293
                                                                                                           3, id,
 
294
                                                                                                           4, anim,
214
295
                                                                                                           -1 );
215
296
                                        img->nr_transitions_loaded++;
 
297
                                        g_object_unref( G_OBJECT( pixbuf ) );
 
298
                                        g_object_unref( G_OBJECT( anim ) );
216
299
                                }
217
300
                                g_free( bak );
218
301
                        }
233
316
        GtkWidget *file_selector;
234
317
        gchar *dest_dir;
235
318
        gint response;
 
319
    GtkFileFilter *video_filter, *all_files_filter;
 
320
    gchar *file_extention, *dot_position, *proposed_filename, *file_basename, *stripped_filename;
236
321
 
237
322
        file_selector = gtk_file_chooser_dialog_new (_("Please choose the slideshow project filename"),
238
323
                                                        GTK_WINDOW (img->imagination_window),
243
328
                                                        GTK_RESPONSE_ACCEPT,
244
329
                                                        NULL);
245
330
 
 
331
    /* only video files filter */
 
332
    video_filter = gtk_file_filter_new ();
 
333
    switch (img->video_format)
 
334
    {
 
335
        default:
 
336
        case 'V':
 
337
        gtk_file_filter_set_name (video_filter, _("VOB (DVD video)") );
 
338
        gtk_file_filter_add_pattern (video_filter, "*.vob");
 
339
        file_extention = ".vob";
 
340
        break;
 
341
 
 
342
        case 'M':
 
343
        gtk_file_filter_set_name (video_filter, _("MP4 (MPEG-4)") );
 
344
        gtk_file_filter_add_pattern (video_filter, "*.mp4");
 
345
        file_extention = ".mp4";
 
346
        break;
 
347
 
 
348
        case 'O':
 
349
        gtk_file_filter_set_name (video_filter, _("OGV (Theora/Vorbis)") );
 
350
        gtk_file_filter_add_pattern (video_filter, "*.ogv");
 
351
        file_extention = ".ogv";
 
352
        break;
 
353
 
 
354
        case 'F':
 
355
        gtk_file_filter_set_name (video_filter, _("FLV (Flash video)") );
 
356
        gtk_file_filter_add_pattern (video_filter, "*.flv");
 
357
        file_extention = ".flv";
 
358
        break;
 
359
 
 
360
        case '3':
 
361
        gtk_file_filter_set_name (video_filter, _("3GP (Mobile Phones)") );
 
362
        gtk_file_filter_add_pattern (video_filter, "*.3gp");
 
363
        file_extention = ".3gp";
 
364
        break;
 
365
    }
 
366
    gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_selector), video_filter);
 
367
 
 
368
    /* All files filter */
 
369
    all_files_filter = gtk_file_filter_new ();
 
370
    gtk_file_filter_set_name(all_files_filter, _("All files"));
 
371
    gtk_file_filter_add_pattern(all_files_filter, "*");
 
372
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(file_selector), all_files_filter);
 
373
    
 
374
    /* Propose a file name */
 
375
    if (img->project_filename)
 
376
    {
 
377
        file_basename = g_path_get_basename(img->project_filename);
 
378
        dot_position = g_strrstr(file_basename, ".");
 
379
        if (NULL != dot_position)
 
380
        {
 
381
            stripped_filename = g_strndup(file_basename, dot_position - file_basename);
 
382
            g_free(file_basename);
 
383
        }
 
384
        else
 
385
        {
 
386
            stripped_filename = file_basename;
 
387
        }
 
388
        proposed_filename = g_strjoin(NULL, stripped_filename, file_extention, NULL);
 
389
        g_free(stripped_filename);
 
390
    }
 
391
    else
 
392
    {
 
393
        proposed_filename = g_strjoin(NULL, "unknown", file_extention, NULL);
 
394
    }
 
395
    gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (file_selector), proposed_filename);
 
396
    g_free(proposed_filename);
 
397
 
 
398
    /* set current dir to the project current dir */
 
399
    if (img->project_current_dir)
 
400
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_selector),img->project_current_dir);
 
401
 
246
402
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (file_selector),TRUE);
247
403
        response = gtk_dialog_run (GTK_DIALOG(file_selector));
248
404
        if (response == GTK_RESPONSE_ACCEPT)
282
438
                slide->font_color[1] = 0; /* G */
283
439
                slide->font_color[2] = 0; /* B */
284
440
                slide->font_color[3] = 1; /* A */
 
441
                /* default: no font color background */
 
442
        slide->font_bgcolor[0] = 1; /* R */
 
443
        slide->font_bgcolor[1] = 1; /* G */
 
444
        slide->font_bgcolor[2] = 1; /* B */
 
445
        slide->font_bgcolor[3] = 1; /* A */
 
446
        
 
447
        /* Load error handling */
 
448
        slide->load_ok = TRUE;
 
449
        slide->original_filename = NULL;
285
450
        }
286
451
 
287
452
        return( slide );
426
591
                                                 gint               placing,
427
592
                                                 const gchar       *font_desc,
428
593
                                                 gdouble           *font_color,
 
594
                         gdouble           *font_bgcolor,
429
595
                                                 img_window_struct *img )
430
596
{
431
597
        /* Set the slide text info parameters */
487
653
                slide->font_color[2] = font_color[2];
488
654
                slide->font_color[3] = font_color[3];
489
655
        }
 
656
 
 
657
    if( font_bgcolor )
 
658
    {
 
659
        slide->font_bgcolor[0] = font_bgcolor[0];
 
660
        slide->font_bgcolor[1] = font_bgcolor[1];
 
661
        slide->font_bgcolor[2] = font_bgcolor[2];
 
662
        slide->font_bgcolor[3] = font_bgcolor[3];
 
663
    }
490
664
}                                                               
491
665
 
492
666
void
498
672
                g_unlink( entry->r_filename );
499
673
        g_free(entry->o_filename);
500
674
        g_free(entry->r_filename);
 
675
    g_free(entry->original_filename);
501
676
        g_free(entry->resolution);
502
677
        g_free(entry->type);
503
678
        
961
1136
        return( TRUE );
962
1137
}
963
1138
 
 
1139
/* Prints a message in the message tab */
 
1140
void
 
1141
img_message (img_window_struct *img,
 
1142
             gboolean alert_user,
 
1143
             gchar *message, ...)
 
1144
{
 
1145
        GtkTextIter message_end;
 
1146
        va_list args;
 
1147
        char *parsed_message;
 
1148
        int parsed_message_size = 0;
 
1149
 
 
1150
        va_start (args, message);
 
1151
        parsed_message_size = vsnprintf(NULL, 0, message, args);
 
1152
        va_end(args);
 
1153
        /* if we have a glibc 2.0, just print the first 500 char */
 
1154
        if (-1 == parsed_message_size)
 
1155
            parsed_message_size = 500;
 
1156
        parsed_message = malloc(parsed_message_size + 1);
 
1157
 
 
1158
//        vprintf(message, args);
 
1159
        va_start(args, message);
 
1160
        vsnprintf(parsed_message, parsed_message_size + 1, message, args);
 
1161
        va_end(args);
 
1162
 
 
1163
        gtk_text_buffer_get_end_iter(img->message_buffer, &message_end);
 
1164
        gtk_text_buffer_insert(img->message_buffer, &message_end,
 
1165
                               parsed_message, -1);
 
1166
 
 
1167
        free(parsed_message);
 
1168
 
 
1169
        if (alert_user)
 
1170
        {
 
1171
            PangoAttrList *   pango_list = pango_attr_list_new();
 
1172
            PangoAttribute *  pango_attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
 
1173
            pango_attr_list_insert(pango_list, pango_attr);
 
1174
            gtk_label_set_attributes(GTK_LABEL(img->message_label), pango_list);
 
1175
            pango_attr_list_unref (pango_list);
 
1176
        }
 
1177
 
 
1178
}