~ubuntu-branches/debian/sid/tickr/sid

« back to all changes in this revision

Viewing changes to src/tickr/tickr_resource.c

  • Committer: Package Import Robot
  • Author(s): Emmanuel Thomas-Maurin
  • Date: 2012-06-04 14:23:24 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120604142324-j6ycu0cw6vvoahhy
Tags: 0.6.1-1
* Add: 'quick setup' thing (in tickr_quicksetup.c) which is launched
  at program startup if config file doesn't exist.

* Little improvements in layout of 'feed picker win' and 'preferences
  win'.

* Fix a segfault that happens when trying to export params and no
  config file exists yet.

* Make several windows that should not be resized by user, unresizable.

* Fix Launchpad bug #1007346: When 'window always-on-top' is disabled,
  'visible on all user desktops' stops working.

* If mouse wheel scrolling applies to speed (or feed), then Ctrl +
  mouse wheel scrolling applies to feed (or speed.)

* No real code changes in libetm, only in comments, so no need for a
  new version number.

* Update tickr_helptext.c and tickr.1 (man page.)

* Add new cli option 'no-ui' (similar to 'instance-id') used by new
  IF_UI_ALLOWED macro and remove all #if USE_GUI occurences.

* In tickr_list.c, free listfname before using it. Fixed by swapping 2
  lines:
    warning(FALSE, 4, "Can't save URL list ", listfname, ...);
    l_str_free(listfname);

* Use/add #define
    FONT_MAXLEN         68
    ARBITRARY_TASKBAR_HEIGHT    25
  to replace a few 'magic' numeric values.

* Rename: rss_title/description(_delimiter) ->
    item_title/description(_delimiter)
  then add new param: feed_title(_delimiter). Now we have:
  feed title / item title / item description.

* Use table in resource properties window.

* Fix a bug in f_list_load_from_file() in tickr_list.c which
  uncorrectly retrieves any feed title string containing TITLE_TAG_CHAR
  when TITLE_TAG_CHAR has not been removed from string first, for
  instance: 'NYT > World' -> ' World'.

* New param: disable left-click.

* Add 'check for updates' feature.

* Launch 'import OPML file' if feed list doesn't exist.

* Remove code changing get_params()->disable_popups value in
    START/END_PAUSE_TICKER_WHILE_OPENING
  macros which prevents this setting to be saved and add
    START/END_PAUSE_TICKER_ENABLE_POPUPS_WHILE_OPENING
  new macros. Which ones to use depends on context.

* Move:
    #ifdef G_OS_WIN32
    extern FILE *stdout_fp, *stderr_fp;
    #endif
  from *.c into tickr.h.

* Default always-on-top setting changed to 'n' (so that tickr is not
  intrusive by default.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "tickr.h"
20
20
#include "tickr_html_entities.h"
21
21
 
22
 
#ifdef G_OS_WIN32
23
 
extern FILE     *stdout_fp, *stderr_fp;
24
 
#endif
25
 
 
26
22
/*
27
 
 * build selection f_list from full feed f_list
 
23
 * Build selection f_list from full feed f_list.
28
24
 *
29
 
 * always use get/set_feed_list() and get/set_feed_selection() to access
30
 
 * FList *feed_list and FList *feed_selection defined in tickr_main.c
 
25
 * Always use get/set_feed_list() and get/set_feed_selection() to access
 
26
 * FList *feed_list and FList *feed_selection defined in tickr_main.c.
31
27
 */
32
28
int build_feed_selection_from_feed_list()
33
29
{
55
51
 * feed_index_in_selection starts at 0
56
52
 * (these funcs do nothing in single selection mode)
57
53
 */
58
 
/* always reload -> ok like that ? */
 
54
/* Always reload -> OK like that ? */
59
55
void current_feed()
60
56
{
61
57
        FList   *selection = get_feed_selection();
70
66
        }
71
67
}
72
68
 
73
 
/* always reload -> ok like that ? */
 
69
/* Always reload -> OK like that ? */
74
70
void first_feed()
75
71
{
76
72
        if (get_ticker_env()->selection_mode == MULTIPLE) {
79
75
        }
80
76
}
81
77
 
82
 
/* always reload -> ok like that ? */
 
78
/* Always reload -> OK like that ? */
83
79
void last_feed()
84
80
{
85
81
        if (get_ticker_env()->selection_mode == MULTIPLE) {
123
119
}
124
120
 
125
121
/*
126
 
 * - single mode: (re)load resrc->id = text file if it exists or rss feed if valid
127
 
 * - multiple mode: load sequentially all selected feeds in feed list
 
122
 * - Single mode: (re)load resrc->id = text file if it exists or rss feed if valid.
 
123
 * - Multiple mode: load sequentially all selected feeds in feed list.
128
124
 *
129
 
 * in case of url: load_resource() -> get_feed() -> parse_rss20/rss10/atom_xml_file()
 
125
 * In case of url: load_resource() -> get_feed() -> parse_rss20/rss10/atom_xml_file().
130
126
 */
131
127
int load_resource(Resource *resrc, FList *feed_selection)
132
128
{
169
165
                exit_status = RESOURCE_UNSPECIFIED;
170
166
        } else {
171
167
                /*
172
 
                 * is there an existing file?
 
168
                 * Is there an existing file ?
173
169
                 */
174
170
#ifndef G_OS_WIN32
175
171
                if ((resrc->fp = g_fopen(resrc->id, "rb")) == NULL) {
179
175
                        g_free(win32_filename);
180
176
#endif
181
177
                        /*
182
 
                         * if not, have we a valid rss url instead?
 
178
                         * If not, have we a valid rss url instead ?
183
179
                         */
184
180
                        if ((rss_status = get_feed(resrc, get_params())) != OK) {
185
181
                                if (rss_status != FEED_UNPARSABLE && rss_status != FEED_EMPTY &&\
219
215
}
220
216
 
221
217
/*
222
 
 * strip html tags
223
 
 * then check for lines longer than LINE_MAXLEN and insert newline's if any
224
 
 * then resrc->fp refers to a "formatted" file
 
218
 * Strip html tags,
 
219
 * then 'translate' html entities,
 
220
 * then check for lines longer than LINE_MAXLEN and insert newline's if any,
 
221
 * then resrc->fp refers to a "formatted" file.
225
222
 */
226
223
int format_resource(Resource *resrc)
227
224
{
231
228
        int             is_inside_tag = FALSE, c, i;
232
229
        gchar           *p;
233
230
 
234
 
        /* strip html tags */
 
231
        /* Strip html tags */
235
232
        tmp_fp = open_new_datafile_with_name(TMP1, "wb+");
236
233
        i = 0;
237
234
        while ((c = fgetc(resrc->fp)) != (int)EOF) {
243
240
                                is_inside_tag = FALSE;
244
241
                } else
245
242
                        is_inside_tag = FALSE;
246
 
                /* a little bit confusing here... */
 
243
                /* A little bit confusing here... */
247
244
                if (!is_inside_tag && !(get_params()->strip_html_tags == 'y' && c == '>'))
248
245
                        fputc((int)c, tmp_fp);
249
246
                else if (i++ < 1)
253
250
        resrc->fp = tmp_fp;
254
251
        fseek(resrc->fp, 0, SEEK_SET);
255
252
 
256
 
        /* 'translate' html entities */
 
253
        /* 'Translate' html entities */
257
254
        tmp_fp = open_new_datafile_with_name(TMP2, "wb+");
258
255
        while ((c = fgetc(resrc->fp)) != (int)EOF) {
259
256
                if (c == '&') {
280
277
        resrc->fp = tmp_fp;
281
278
        fseek(resrc->fp, 0, SEEK_SET);
282
279
 
283
 
        /* check for lines longer than LINE_MAXLEN and insert newline's if any */
 
280
        /* Check for lines longer than LINE_MAXLEN and insert newline's if any */
284
281
        tmp_fp = open_new_datafile_with_name(XML_DUMP, "wb+");
285
282
        str1 = malloc2(str1_size * sizeof(char));
286
283
        str2 = l_str_new(NULL);
296
293
                if (*p == '\n')
297
294
                        i = 0;
298
295
                /*
299
 
                 * if the word we are parsing isn't longer than WORD_MAXLEN
300
 
                 * chars, we replace the 1st ' ' found after it with a '\n'
301
 
                 * otherwise the word is cut off
 
296
                 * If the word we are parsing isn't longer than WORD_MAXLEN
 
297
                 * chars, we replace the 1st ' ' found after it with '\n',
 
298
                 * otherwise the word is cut off.
302
299
                 */
303
300
                if (i >= LINE_MAXLEN - WORD_MAXLEN)
304
301
                        if (i >= LINE_MAXLEN || g_unichar_isspace(*p)) {
317
314
}
318
315
 
319
316
/*
320
 
 * *** file names, paths and dirs stuff ***
 
317
 * *** File names, paths and dirs stuff ***
321
318
 */
322
319
void set_tickr_icon_to_dialog(GtkWindow *dialog)
323
320
{
324
321
        gtk_window_set_icon_from_file(dialog, get_imagefile_full_name_from_name(TICKR_ICON), NULL);
325
322
}
326
323
 
327
 
/* open/create file in data dir from name
328
 
 * data dir = config files, not images files
 
324
/* Open/create file in data dir from name.
 
325
 * Data dir = config files, not images files.
329
326
 */
330
327
FILE *open_new_datafile_with_name(const char *name, const char *mode_str)
331
328
{
351
348
        return fp;
352
349
}
353
350
 
354
 
/* get full path and name for file in data dir from name
355
 
 * data dir = config files, not images files
 
351
/* Get full path and name for file in data dir from name.
 
352
 * Data dir = config files, not images files.
356
353
 */
357
354
char *get_datafile_full_name_from_name(const char *name)
358
355
{
373
370
        return file_name;
374
371
}
375
372
 
376
 
/* now, image files */
 
373
/* Now, image files */
377
374
char *get_imagefile_full_name_from_name(const char *name)
378
375
{
379
376
        static char     file_name[FILE_NAME_MAXLEN + 1];
394
391
        return file_name;
395
392
}
396
393
 
397
 
/* data dir = config files, not images files */
 
394
/* Data dir = config files, not images files */
398
395
char *get_datadir_full_path()
399
396
{
400
397
        static char     full_path[TMPSTR_SIZE + 1];
414
411
#ifndef G_OS_WIN32
415
412
        return str_n_cpy(str, getpwuid(getuid())->pw_dir, TMPSTR_SIZE);
416
413
#endif
417
 
        /* for win32 version, no home dir - see win32 specific funcs in libetm */
 
414
        /* For win32 version, no home dir - See win32 specific funcs in libetm. */
418
415
        return str;
419
416
}