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

« back to all changes in this revision

Viewing changes to src/tickr/tickr_list.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_list.h"
21
21
 
22
 
#ifdef G_OS_WIN32
23
 
extern FILE     *stdout_fp, *stderr_fp;
24
 
#endif
25
 
 
26
 
#if USE_GUI
27
 
/* TODO: more testing of these funcs */
28
22
FList *f_list_new(const char *url, const char *title, gboolean selected)
29
23
{
30
24
        FList   *node = malloc2(sizeof(FList));
37
31
        str_n_cpy(node->title, title, FLIST_TITLE_MAXLEN);
38
32
 
39
33
        /*
40
 
         * if we want to use the following code (which save memory use),
 
34
         * If we want to use the following code (which save memory use),
41
35
         * we must implement funcs that reallocate memory when modifying
42
 
         * data and we must never modify it directly
 
36
         * data and we must never modify it directly.
43
37
         */
44
38
        /*url_len = MIN(strlen(url), FLIST_URL_MAXLEN);
45
39
        node->url = malloc2(url_len + 1);
59
53
}
60
54
 
61
55
/*
62
 
 * free allocated memory
 
56
 * Free allocated memory.
63
57
 */
64
58
void f_list_free(FList *node)
65
59
{
72
66
}
73
67
 
74
68
/*
75
 
 * free allocated memory
 
69
 * Free allocated memory.
76
70
 */
77
71
void f_list_free_all(FList *some_node)
78
72
{
103
97
}
104
98
 
105
99
/*
106
 
 * return NULL if no previous node
 
100
 * Return NULL if no previous node.
107
101
 */
108
102
FList *f_list_prev(FList *node)
109
103
{
116
110
}
117
111
 
118
112
/*
119
 
 * return NULL if no next node
 
113
 * Return NULL if no next node.
120
114
 */
121
115
FList *f_list_next(FList *node)
122
116
{
129
123
}
130
124
 
131
125
/*
132
 
 * return NULL if out of range
 
126
 * Return NULL if out of range.
133
127
 */
134
128
FList *f_list_nth(FList *some_node, int n)
135
129
{
154
148
}
155
149
 
156
150
/*
157
 
 * return index if found (starting at 0) / -1 otherwise
 
151
 * Return index if found (starting at 0) / -1 otherwise.
158
152
 */
159
153
int f_list_index(FList *some_node)
160
154
{
187
181
}
188
182
 
189
183
/*
190
 
 * create and add node at start of list
191
 
 * some_node may be any node in the list or NULL -> when creating list
 
184
 * Create and add node at start of list.
 
185
 * 'some_node' may be any node in the list or NULL -> when creating list.
192
186
 */
193
187
FList *f_list_add_at_start(FList *some_node, const char *url, const char *title, gboolean selected)
194
188
{
204
198
}
205
199
 
206
200
/*
207
 
 * create and add node at end of list
208
 
 * some_node may be any node in the list or NULL -> when creating list
 
201
 * Create and add node at end of list.
 
202
 * 'some_node' may be any node in the list or NULL -> when creating list.
209
203
 */
210
204
FList *f_list_add_at_end(FList *some_node, const char *url, const char *title, gboolean selected)
211
205
{
221
215
}
222
216
 
223
217
/*
224
 
 * create and insert node before some_node
 
218
 * Create and insert node before 'some_node'.
225
219
 */
226
220
FList *f_list_insert_before(FList *some_node, const char *url, const char *title, gboolean selected)
227
221
{
240
234
}
241
235
 
242
236
/*
243
 
 * create and insert node after some_node
 
237
 * Create and insert node after 'some_node'.
244
238
 */
245
239
FList *f_list_insert_after(FList *some_node, const char *url, const char *title, gboolean selected)
246
240
{
260
254
}
261
255
 
262
256
/*
263
 
 * remove then return first node or NULL if empty
 
257
 * Remove then return first node or NULL if empty.
264
258
 */
265
259
FList *f_list_remove(FList *node)
266
260
{
301
295
}
302
296
 
303
297
/*
304
 
 * sort by node->url then remove duplicated and empty entries
305
 
 * then return first node
 
298
 * Sort by node->url, then remove duplicated and empty entries,
 
299
 * then return first node.
306
300
 */
307
301
FList *f_list_sort(FList *some_node)
308
302
{
320
314
                        break;
321
315
        }
322
316
        list_len = i;
323
 
        /* selection sort */
 
317
        /* Selection sort */
324
318
        for (i = 0; i < list_len; i++) {
325
319
                min = i;
326
320
                for (j = i + 1; j < list_len; j++)
330
324
                node_i[i] = node_i[min];
331
325
                node_i[min] = tmp;
332
326
        }
333
 
        /* remove duplicated entries */
 
327
        /* Remove duplicated entries */
334
328
        for (i = 0; i < list_len; i++)
335
329
                for (j = i + 1; j < list_len; j++)
336
330
                        if (strcmp(node_i[i]->url, node_i[j]->url) == 0) {
337
 
                                if (node_i[j]->title[0] == '\0')        /* if no title in the second entry */
 
331
                                if (node_i[j]->title[0] == '\0')        /* If no title in the second entry */
338
332
                                        node_i[j]->url[0] = '\0';       /* (ie the last added), we keep the */
339
 
                                else                                    /* first one */
 
333
                                else                                    /* first one. */
340
334
                                        node_i[i]->url[0] = '\0';
341
335
                                if (node_i[i]->selected || node_i[j]->selected) {
342
336
                                        node_i[i]->selected = TRUE;
343
337
                                        node_i[j]->selected = TRUE;
344
338
                                }
345
339
                        }
346
 
        /* remove empty entries */
 
340
        /* Remove empty entries */
347
341
        for (i = 0; i < list_len; i++)
348
342
                if (node_i[i]->url[0] != '\0')
349
343
                        node2 = f_list_add_at_end(node2, node_i[i]->url, node_i[i]->title, node_i[i]->selected);
353
347
}
354
348
 
355
349
/*
356
 
 * search by node->url and return index if found (starting at 0) / -1 otherwise
 
350
 * Search by node->url and return index if found (starting at 0) / -1 otherwise.
357
351
 */
358
352
int f_list_search(FList *some_node, const char *str)
359
353
{
372
366
}
373
367
 
374
368
/*
375
 
 * use provided file_name if not NULL / default file name (URL_LIST_FILE) otherwise
376
 
 * create new f_list
 
369
 * Use provided file_name if not NULL / default file name (URL_LIST_FILE) otherwise.
 
370
 * Create new f_list.
377
371
 *
378
 
 * entry format in url list file:
 
372
 * Entry format in url list file:
379
373
 *      ["*" (selected) or "-" (unselected) + url [+ ">" + title] + '\n']
380
374
 *
381
 
 * entry max length = FILE_NAME_MAXLEN
382
 
 * see also: (UN)SELECTED_URL_CHAR in tickr.h
 
375
 * Entry max length = FILE_NAME_MAXLEN.
 
376
 * See also: (UN)SELECTED_URL_CHAR and TITLE_TAG_CHAR in tickr.h.
383
377
 *
384
 
 * return OK (and first node of list) or LOAD_URL_LIST_ERROR
 
378
 * Return OK (and first node of list) or LOAD_URL_LIST_ERROR.
385
379
 */
386
380
int f_list_load_from_file(FList **new_node, const char *file_name)
387
381
{
390
384
        char            *tmp;
391
385
        FList           *node;
392
386
        size_t          tmp_size = FILE_NAME_MAXLEN + 1;
393
 
        gboolean        selected;
 
387
        gboolean        selected, title_found;
394
388
        int             title_shift, i;
395
389
 
396
390
        if (file_name == NULL) {
403
397
#endif
404
398
                listfname = listfname1;
405
399
                if ((fp = g_fopen(listfname, "rb")) == NULL) {
406
 
                        if (question_win("No URL list has been saved yet. Use sample one ?") == YES)
 
400
                        if (question_win("No URL list has been saved yet. Import one (OPML format required) ?") == YES)
 
401
                                import_opml_file();
 
402
                        else if (question_win("No URL list has been saved yet. Use sample one ?") == YES)
407
403
                                listfname = listfname2;
408
404
                        else
409
405
                                return LOAD_URL_LIST_ERROR;
421
417
                        if (tmp[0] == SELECTED_URL_CHAR || tmp[0] == UNSELECTED_URL_CHAR) {
422
418
                                selected = (tmp[0] == SELECTED_URL_CHAR) ? TRUE : FALSE;
423
419
                                title_shift = -1;
 
420
                                title_found = FALSE;
424
421
                                for (i = 0; i < FILE_NAME_MAXLEN; i++) {
425
 
                                        if (tmp[i] == TITLE_TAG_CHAR) {
 
422
                                        if (!title_found && tmp[i] == TITLE_TAG_CHAR) {
426
423
                                                title_shift = i + 1;
427
424
                                                tmp[i] = '\0';
 
425
                                                title_found = TRUE;
428
426
                                        } else if (tmp[i] == '\n') {
429
427
                                                tmp[i] = '\0';
430
428
                                                break;
450
448
}
451
449
 
452
450
/*
453
 
 * use provided file_name if not NULL / default file name (URL_LIST_FILE) otherwise
 
451
 * Use provided file_name if not NULL / default file name (URL_LIST_FILE) otherwise.
454
452
 *
455
 
 * entry format in url list file:
 
453
 * Entry format in url list file:
456
454
 *      ["*" (selected) or "-" (unselected) + url [+ ">" + title] + '\n']
457
455
 *
458
 
 * entry max length = FILE_NAME_MAXLEN
459
 
 * see also: (UN)SELECTED_URL_CHAR in tickr.h
 
456
 * Entry max length = FILE_NAME_MAXLEN.
 
457
 * See also: (UN)SELECTED_URL_CHAR and TITLE_TAG_CHAR in tickr.h.
460
458
 *
461
 
 * return OK (and first node of list) or SAVE_URL_LIST_ERROR
 
459
 * Return OK (and first node of list) or SAVE_URL_LIST_ERROR.
462
460
 */
463
461
int f_list_save_to_file(FList *node, const char *file_name)
464
462
{
483
481
                l_str_free(listfname);
484
482
                return OK;
485
483
        } else {
486
 
                l_str_free(listfname);
487
484
                warning(FALSE, 4, "Can't save URL list ", listfname, ": ", strerror(errno));
 
485
                l_str_free(listfname);
488
486
                return SAVE_URL_LIST_ERROR;
489
487
        }
490
488
}
491
 
#endif