~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/render.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
2
 * @file render.c  generic XSLT rendering handling
3
3
 * 
4
 
 * Copyright (C) 2006-2009 Lars Lindner <lars.lindner@gmail.com>
 
4
 * Copyright (C) 2006-2011 Lars Lindner <lars.lindner@gmail.com>
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
58
58
   and performs CSS adaptions to the current GTK theme. */
59
59
 
60
60
static renderParamPtr   langParams = NULL;      /* the current locale settings (for localization stylesheet) */
61
 
static gchar            *defaultParams = NULL;  /* some default parameters (for rendering stylesheets) */
62
61
 
63
62
static GHashTable       *stylesheets = NULL;    /* XSLT stylesheet cache */
64
63
 
65
64
static void
66
65
render_init (void)
67
66
{
68
 
        gchar   **shortlang = NULL;     /* e.g. "de" */
69
 
        gchar   **lang = NULL;          /* e.g. "de_AT" */
 
67
        gchar           **shortlang = NULL;     /* e.g. "de" */
 
68
        gchar           **lang = NULL;          /* e.g. "de_AT" */
 
69
        gchar           *filename;
70
70
 
71
71
        if (langParams)
72
72
                render_parameter_free (langParams);
73
 
        if (defaultParams)
74
 
                g_free (defaultParams);
75
 
 
76
 
        /* prepare localization parameters */
 
73
 
 
74
        /* Install default stylesheet if it does not yet exist */
 
75
        filename = common_create_cache_filename ("", "liferea", "css");
 
76
        if (!g_file_test (filename, G_FILE_TEST_EXISTS))
 
77
                common_copy_file (PACKAGE_DATA_DIR "/" PACKAGE "/css/user.css", filename);
 
78
        g_free(filename);
 
79
 
 
80
        /* Prepare localization parameters */
77
81
        debug1 (DEBUG_HTML, "XSLT localisation: setlocale(LC_MESSAGES, NULL) reports '%s'", setlocale(LC_MESSAGES, NULL));
78
82
        lang = g_strsplit (setlocale (LC_MESSAGES, NULL), "@", 0);
79
83
        shortlang = g_strsplit (setlocale (LC_MESSAGES, NULL), "_", 0);
86
90
        g_strfreev (shortlang);
87
91
        g_strfreev (lang);
88
92
 
89
 
        /* prepare rendering default parameters */
90
 
        defaultParams = g_strdup_printf("search_link_enable='%s'", conf_get_bool_value (SOCIAL_LINK_SEARCH_HIDE)?"false":"true");
91
 
 
92
93
        if (!stylesheets)
93
94
                stylesheets = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
94
95
}
148
149
 
149
150
/** cached CSS definitions */
150
151
static GString  *css = NULL;
151
 
static time_t lastCssModification = 0;
152
152
 
153
153
/** widget background theme colors as 8bit HTML RGB code */
154
154
typedef struct themeColor {
225
225
        return css;
226
226
}
227
227
 
228
 
static void
229
 
render_remove_css_comments (void)
230
 
{
231
 
        gssize i, len = css->len;
232
 
        gchar *str = css->str;
233
 
        GString *newcss;
234
 
 
235
 
        newcss = g_string_new(NULL);
236
 
        i = 0;
237
 
        while (i < len) {
238
 
                if (i+1 < len && str[i] == '/' && str[i+1] == '*') {
239
 
                        i += 4;
240
 
                        while (i-1 < len && (str[i-2] != '*' || str[i-1] != '/'))
241
 
                                i++;
242
 
                        continue;
243
 
                }
244
 
                if (i+1 < len && str[i] == '/' && str[i+1] == '/') {
245
 
                        i += 2;
246
 
                        while (i < len && str[i] != '\n')
247
 
                                i++;
248
 
                        continue;
249
 
                }
250
 
                newcss = g_string_append_c(newcss, str[i]);
251
 
                i++;
252
 
        }
253
 
        g_string_free(css, TRUE);
254
 
        css = newcss;
255
 
}
256
 
 
257
228
const gchar *
258
229
render_get_css (gboolean externalCss)
259
230
{
260
 
        gchar *styleSheetFile;
261
 
        time_t newLastModification;
262
 
 
263
 
        styleSheetFile      = g_build_filename (common_get_cache_path (), "liferea.css", NULL);
264
 
        newLastModification = common_get_mod_time ((char *)styleSheetFile);
265
 
 
266
 
        if (!css || lastCssModification != newLastModification) {
267
 
                gchar   *defaultStyleSheetFile, *adblockStyleSheetFile;
268
 
                gchar   *font = NULL;
269
 
                gchar   *fontsize = NULL;
 
231
        if (!css) {
 
232
                gchar   *defaultStyleSheetFile;
 
233
                gchar   *userStyleSheetFile;
 
234
                gchar   *adblockStyleSheetFile;
270
235
                gchar   *tmp;
271
236
 
272
 
                // Update last modification timestamp
273
 
                lastCssModification = newLastModification;
274
 
 
275
 
                if (themeColors == NULL) {
 
237
                if (!themeColors)
276
238
                        render_get_theme_colors();
277
 
                }
278
239
 
279
240
                css = g_string_new(NULL);
280
241
 
281
 
                /* font configuration support */
282
 
                font = conf_get_str_value (USER_FONT);
283
 
                if(0 == strlen(font)) {
284
 
                        g_free(font);
285
 
                        font = conf_get_str_value (DEFAULT_FONT);
286
 
                }
287
 
 
288
 
                if(font) {
289
 
                        fontsize = font;
290
 
                        /* the GTK2/GNOME font name format is <font name>,<font size in point>
291
 
                         Or it can also be "Font Name size*/
292
 
                        strsep(&fontsize, ",");
293
 
                        if(fontsize == NULL) {
294
 
                                if(NULL != (fontsize = strrchr(font, ' '))) {
295
 
                                        *fontsize = '\0';
296
 
                                        fontsize++;
297
 
                                }
298
 
                        }
299
 
                        g_string_append(css, "body, table, div {");
300
 
                        g_string_append_printf(css, "font-family: %s;\n", font);
301
 
 
302
 
                        if(fontsize)
303
 
                                g_string_append_printf(css, "font-size: %spt;\n", fontsize);
304
 
 
305
 
                        g_free(font);
306
 
                        g_string_append(css, "}\n");
307
 
                }
308
 
 
309
242
                defaultStyleSheetFile = g_build_filename (PACKAGE_DATA_DIR, PACKAGE, "css", "liferea.css", NULL);
310
243
 
311
244
                if (g_file_get_contents(defaultStyleSheetFile, &tmp, NULL, NULL)) {
312
245
                        tmp = render_set_theme_colors(tmp);
313
246
                        g_string_append(css, tmp);
314
247
                        g_free(tmp);
315
 
                }
316
 
 
317
 
                if (g_file_get_contents(styleSheetFile, &tmp, NULL, NULL)) {
318
 
                        tmp = render_set_theme_colors(tmp);
319
 
                        g_string_append(css, tmp);
320
 
                        g_free(tmp);
 
248
                } else {
 
249
                        g_error ("Loading %s failed.", defaultStyleSheetFile);
321
250
                }
322
251
 
323
252
                g_free(defaultStyleSheetFile);
324
253
 
 
254
                userStyleSheetFile = g_build_filename (common_get_cache_path (), "liferea.css", NULL);
 
255
 
 
256
                if (g_file_get_contents(userStyleSheetFile, &tmp, NULL, NULL)) {
 
257
                        tmp = render_set_theme_colors(tmp);
 
258
                        g_string_append(css, tmp);
 
259
                        g_free(tmp);
 
260
                }
 
261
 
 
262
                g_free(userStyleSheetFile);
 
263
 
325
264
                adblockStyleSheetFile = g_build_filename(PACKAGE_DATA_DIR, PACKAGE, "css", "adblock.css", NULL);
326
265
 
327
266
                if (g_file_get_contents(adblockStyleSheetFile, &tmp, NULL, NULL)) {
331
270
 
332
271
                g_free(adblockStyleSheetFile);
333
272
 
334
 
                /* remove comments from the CSS to circumvent libgtkhtml2 freezing bug */
335
 
                render_remove_css_comments();
336
 
 
337
273
                if (externalCss) {
338
274
                        /* dump CSS to cache file and create a <style> tag to use the it */
339
275
                        gchar *filename = common_create_cache_filename("cache", "style", "css");
354
290
                }
355
291
        }
356
292
 
357
 
        g_free(styleSheetFile);
358
 
 
359
293
        return css->str;
360
294
}
361
295
 
373
307
 
374
308
        if (!paramSet)
375
309
                paramSet = render_parameter_new ();
376
 
        render_parameter_add (paramSet, "%s", defaultParams);
 
310
        render_parameter_add (paramSet, "pixmapsDir='file://" PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "pixmaps" G_DIR_SEPARATOR_S "'");
377
311
 
378
 
        resDoc = xsltApplyStylesheet(xslt, doc, (const gchar **)paramSet->params);
 
312
        resDoc = xsltApplyStylesheet (xslt, doc, (const gchar **)paramSet->params);
379
313
        if (!resDoc) {
380
314
                g_warning ("fatal: applying rendering stylesheet (%s) failed!", xsltName);
381
315
                return NULL;
415
349
        return output;
416
350
}
417
351
 
418
 
gchar *
419
 
render_file (const gchar *filename, const gchar *xsltName, renderParamPtr paramSet)
420
 
{
421
 
        xmlDocPtr       srcDoc;
422
 
        gchar           *output;
423
 
 
424
 
        srcDoc = xmlParseFile(filename);
425
 
        if (!srcDoc) {
426
 
                g_warning ("fatal: loading source XML (%s) failed", filename);
427
 
                return NULL;
428
 
        }
429
 
 
430
 
        output = render_xml (srcDoc, xsltName, paramSet);
431
 
        xmlFreeDoc (srcDoc);
432
 
 
433
 
        return output;
434
 
}
435
 
 
436
352
/* parameter handling */
437
353
 
438
354
renderParamPtr