comparison src/streambrowser/bookmarks.c @ 2913:113454baecf8

lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
author Calin Crisan ccrisan@gmail.com
date Fri, 15 Aug 2008 16:00:43 +0200
parents c27da2c06805
children 3134a0987162
comparison
equal deleted inserted replaced
2891:c27da2c06805 2913:113454baecf8
23 23
24 #include "streambrowser.h" 24 #include "streambrowser.h"
25 #include "bookmarks.h" 25 #include "bookmarks.h"
26 26
27 27
28 static bookmark_t *bookmarks; 28 static bookmark_t **bookmarks;
29 static int bookmarks_count; 29 static int *bookmarks_count;
30 30
31 gboolean bookmarks_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo) 31 gboolean bookmarks_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo)
32 { 32 {
33 // todo: implement and make use of this
34
35 return FALSE;
33 } 36 }
34 37
35 gboolean bookmarks_category_fetch(streamdir_t *streamdir, category_t *category) 38 gboolean bookmarks_category_fetch(streamdir_t *streamdir, category_t *category)
36 { 39 {
37 debug("bookmarks: filling category '%s'\n", category->name); 40 debug("bookmarks: filling category '%s'\n", category->name);
40 while (streaminfo_get_count(category) > 0) 43 while (streaminfo_get_count(category) > 0)
41 streaminfo_remove(category, streaminfo_get_by_index(category, 0)); 44 streaminfo_remove(category, streaminfo_get_by_index(category, 0));
42 45
43 int i; 46 int i;
44 /* find bookmarks that match this category */ 47 /* find bookmarks that match this category */
45 for (i = 0; i < bookmarks_count; i++) 48 for (i = 0; i < *bookmarks_count; i++)
46 if (strcmp(bookmarks[i].streamdir_name, streamdir->name) == 0 && 49 if (strcmp((*bookmarks)[i].streamdir_name, category->name) == 0) {
47 strcmp(bookmarks[i].category_name, category->name) == 0) {
48
49 debug("bookmarks: adding stream info for '%s/%d'\n", streamdir->name, category->name); 50 debug("bookmarks: adding stream info for '%s/%d'\n", streamdir->name, category->name);
50 51
51 streaminfo_t *streaminfo = streaminfo_new(bookmarks[i].name, bookmarks[i].playlist_url, bookmarks[i].url, ""); 52 streaminfo_t *streaminfo = streaminfo_new((*bookmarks)[i].name, (*bookmarks)[i].playlist_url, (*bookmarks)[i].url, "");
52 streaminfo_add(category, streaminfo); 53 streaminfo_add(category, streaminfo);
53 54
54 debug("bookmarks: stream info added\n"); 55 debug("bookmarks: stream info added\n");
55 } 56 }
56 57
57 return TRUE; 58 return TRUE;
58 } 59 }
59 60
60 streamdir_t* bookmarks_streamdir_fetch(bookmark_t *bms, int count) 61 streamdir_t* bookmarks_streamdir_fetch(bookmark_t **p_bookmarks, int *p_bookmarks_count)
61 { 62 {
62 bookmarks = bms; 63 bookmarks = p_bookmarks;
63 bookmarks_count = count; 64 bookmarks_count = p_bookmarks_count;
64 65
65 streamdir_t *streamdir = streamdir_new(BOOKMARKS_NAME); 66 streamdir_t *streamdir = streamdir_new(BOOKMARKS_NAME);
66 67
67 debug("bookmarks: creating streaming directory for bookmarks\n"); 68 debug("bookmarks: creating streaming directory for bookmarks\n");
68 69
75 debug("bookmarks: streaming directory successfuly created\n"); 76 debug("bookmarks: streaming directory successfuly created\n");
76 77
77 return streamdir; 78 return streamdir;
78 } 79 }
79 80
81 void bookmark_add(bookmark_t *bookmark)
82 {
83 debug("bookmarks: adding bookmark with streamdir = '%s', name = '%s', playlist_url = '%s', url = '%s'\n",
84 bookmark->streamdir_name, bookmark->name, bookmark->playlist_url, bookmark->url);
85
86 int i;
87 for (i = 0; i < *bookmarks_count; i++)
88 if (strcmp((*bookmarks)[i].name, bookmark->name) == 0) {
89 debug("bookmarks: bookmark with name = '%s' already exists, skipping\n", bookmark->name);
90 return;
91 }
92
93 *bookmarks = realloc(*bookmarks, sizeof(bookmark_t) * ((*bookmarks_count) + 1));
94
95 strncpy((*bookmarks)[*bookmarks_count].streamdir_name, bookmark->streamdir_name, DEF_STRING_LEN);
96 strncpy((*bookmarks)[*bookmarks_count].name, bookmark->name, DEF_STRING_LEN);
97 strncpy((*bookmarks)[*bookmarks_count].playlist_url, bookmark->playlist_url, DEF_STRING_LEN);
98 strncpy((*bookmarks)[*bookmarks_count].url, bookmark->url, DEF_STRING_LEN);
99
100 (*bookmarks_count)++;
101
102 debug("bookmarks: bookmark added, there are now %d bookmarks\n", *bookmarks_count);
103
104 /* issue a configuration save for immediately saving the new added bookmark */
105 config_save();
106 }
107
108 void bookmark_remove(gchar *name)
109 {
110 debug("bookmarks: searching for bookmark with name = '%s'\n", name);
111
112 int pos = -1, i;
113
114 for (i = 0; i < *bookmarks_count; i++)
115 if (strcmp((*bookmarks)[i].name, name) == 0) {
116 pos = i;
117 break;
118 }
119
120 if (pos != -1) {
121 debug("bookmarks: removing bookmark with streamdir = '%s', name = '%s', playlist_url = '%s', url = '%s'\n",
122 (*bookmarks)[i].streamdir_name, (*bookmarks)[i].name, (*bookmarks)[i].playlist_url, (*bookmarks)[i].url);
123
124 for (i = pos; i < (*bookmarks_count) - 1; i++) {
125 /* bookmarks[i] = bookmarks[i + 1] */
126
127 strncpy((*bookmarks)[i].streamdir_name, (*bookmarks)[i + 1].streamdir_name, DEF_STRING_LEN);
128 strncpy((*bookmarks)[i].name, (*bookmarks)[i + 1].name, DEF_STRING_LEN);
129 strncpy((*bookmarks)[i].playlist_url, (*bookmarks)[i + 1].playlist_url, DEF_STRING_LEN);
130 strncpy((*bookmarks)[i].url, (*bookmarks)[i + 1].url, DEF_STRING_LEN);
131 }
132
133 (*bookmarks_count)--;
134 if (*bookmarks_count > 0)
135 *bookmarks = realloc(*bookmarks, sizeof(bookmark_t) * (*bookmarks_count));
136 else
137 *bookmarks = NULL;
138
139 debug("bookmarks: bookmark removed, there are now %d bookmarks\n", *bookmarks_count);
140 }
141 else
142 failure("bookmarks: cannot find a bookmark with name = '%s'\n", name);
143
144 /* issue a configuration save for immediately saving the remaining bookmarks */
145 config_save();
146 }
147