Mercurial > audlegacy-plugins
annotate 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 |
rev | line source |
---|---|
2891 | 1 /* |
2 * Audacious Streambrowser Plugin | |
3 * | |
4 * Copyright (c) 2008 Calin Crisan <ccrisan@gmail.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; under version 3 of the License. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
17 */ | |
18 | |
19 | |
20 #include <string.h> | |
21 #include <glib.h> | |
22 #include <audacious/plugin.h> | |
23 | |
24 #include "streambrowser.h" | |
25 #include "bookmarks.h" | |
26 | |
27 | |
2913
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
28 static bookmark_t **bookmarks; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
29 static int *bookmarks_count; |
2891 | 30 |
31 gboolean bookmarks_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo) | |
32 { | |
2913
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
33 // todo: implement and make use of this |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
34 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
35 return FALSE; |
2891 | 36 } |
37 | |
38 gboolean bookmarks_category_fetch(streamdir_t *streamdir, category_t *category) | |
39 { | |
40 debug("bookmarks: filling category '%s'\n", category->name); | |
41 | |
42 /* free/remove any existing streaminfos in this category */ | |
43 while (streaminfo_get_count(category) > 0) | |
44 streaminfo_remove(category, streaminfo_get_by_index(category, 0)); | |
45 | |
46 int i; | |
47 /* find bookmarks that match this category */ | |
2913
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
48 for (i = 0; i < *bookmarks_count; i++) |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
49 if (strcmp((*bookmarks)[i].streamdir_name, category->name) == 0) { |
2891 | 50 debug("bookmarks: adding stream info for '%s/%d'\n", streamdir->name, category->name); |
51 | |
2913
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
52 streaminfo_t *streaminfo = streaminfo_new((*bookmarks)[i].name, (*bookmarks)[i].playlist_url, (*bookmarks)[i].url, ""); |
2891 | 53 streaminfo_add(category, streaminfo); |
54 | |
55 debug("bookmarks: stream info added\n"); | |
56 } | |
57 | |
58 return TRUE; | |
59 } | |
60 | |
2913
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
61 streamdir_t* bookmarks_streamdir_fetch(bookmark_t **p_bookmarks, int *p_bookmarks_count) |
2891 | 62 { |
2913
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
63 bookmarks = p_bookmarks; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
64 bookmarks_count = p_bookmarks_count; |
2891 | 65 |
66 streamdir_t *streamdir = streamdir_new(BOOKMARKS_NAME); | |
67 | |
68 debug("bookmarks: creating streaming directory for bookmarks\n"); | |
69 | |
70 category_t *category = category_new("Shoutcast"); | |
71 category_add(streamdir, category); | |
72 | |
73 category = category_new("Xiph"); | |
74 category_add(streamdir, category); | |
75 | |
76 debug("bookmarks: streaming directory successfuly created\n"); | |
77 | |
78 return streamdir; | |
79 } | |
80 | |
2913
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
81 void bookmark_add(bookmark_t *bookmark) |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
82 { |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
83 debug("bookmarks: adding bookmark with streamdir = '%s', name = '%s', playlist_url = '%s', url = '%s'\n", |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
84 bookmark->streamdir_name, bookmark->name, bookmark->playlist_url, bookmark->url); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
85 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
86 int i; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
87 for (i = 0; i < *bookmarks_count; i++) |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
88 if (strcmp((*bookmarks)[i].name, bookmark->name) == 0) { |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
89 debug("bookmarks: bookmark with name = '%s' already exists, skipping\n", bookmark->name); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
90 return; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
91 } |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
92 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
93 *bookmarks = realloc(*bookmarks, sizeof(bookmark_t) * ((*bookmarks_count) + 1)); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
94 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
95 strncpy((*bookmarks)[*bookmarks_count].streamdir_name, bookmark->streamdir_name, DEF_STRING_LEN); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
96 strncpy((*bookmarks)[*bookmarks_count].name, bookmark->name, DEF_STRING_LEN); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
97 strncpy((*bookmarks)[*bookmarks_count].playlist_url, bookmark->playlist_url, DEF_STRING_LEN); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
98 strncpy((*bookmarks)[*bookmarks_count].url, bookmark->url, DEF_STRING_LEN); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
99 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
100 (*bookmarks_count)++; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
101 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
102 debug("bookmarks: bookmark added, there are now %d bookmarks\n", *bookmarks_count); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
103 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
104 /* issue a configuration save for immediately saving the new added bookmark */ |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
105 config_save(); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
106 } |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
107 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
108 void bookmark_remove(gchar *name) |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
109 { |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
110 debug("bookmarks: searching for bookmark with name = '%s'\n", name); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
111 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
112 int pos = -1, i; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
113 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
114 for (i = 0; i < *bookmarks_count; i++) |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
115 if (strcmp((*bookmarks)[i].name, name) == 0) { |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
116 pos = i; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
117 break; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
118 } |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
119 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
120 if (pos != -1) { |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
121 debug("bookmarks: removing bookmark with streamdir = '%s', name = '%s', playlist_url = '%s', url = '%s'\n", |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
122 (*bookmarks)[i].streamdir_name, (*bookmarks)[i].name, (*bookmarks)[i].playlist_url, (*bookmarks)[i].url); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
123 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
124 for (i = pos; i < (*bookmarks_count) - 1; i++) { |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
125 /* bookmarks[i] = bookmarks[i + 1] */ |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
126 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
127 strncpy((*bookmarks)[i].streamdir_name, (*bookmarks)[i + 1].streamdir_name, DEF_STRING_LEN); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
128 strncpy((*bookmarks)[i].name, (*bookmarks)[i + 1].name, DEF_STRING_LEN); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
129 strncpy((*bookmarks)[i].playlist_url, (*bookmarks)[i + 1].playlist_url, DEF_STRING_LEN); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
130 strncpy((*bookmarks)[i].url, (*bookmarks)[i + 1].url, DEF_STRING_LEN); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
131 } |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
132 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
133 (*bookmarks_count)--; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
134 if (*bookmarks_count > 0) |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
135 *bookmarks = realloc(*bookmarks, sizeof(bookmark_t) * (*bookmarks_count)); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
136 else |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
137 *bookmarks = NULL; |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
138 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
139 debug("bookmarks: bookmark removed, there are now %d bookmarks\n", *bookmarks_count); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
140 } |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
141 else |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
142 failure("bookmarks: cannot find a bookmark with name = '%s'\n", name); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
143 |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
144 /* issue a configuration save for immediately saving the remaining bookmarks */ |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
145 config_save(); |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
146 } |
113454baecf8
lots of changes: most important - bookmarks code almost finished, fixed bold-text gui bug, and others...
Calin Crisan ccrisan@gmail.com
parents:
2891
diff
changeset
|
147 |