summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Kuptz <jeromekuptz@gmail.com>2003-07-20 21:29:16 +0000
committerJerome Kuptz <jeromekuptz@gmail.com>2003-07-20 21:29:16 +0000
commitc7d42bbbd7641c8e9e06b28000c4c02c2ee36d21 (patch)
tree6a8ad9d5ef9642c5a5b7371ef8f2fc772df1c8d7
parentcb2caf7e0d66956151b0e484f261f2ea932305ab (diff)
downloadrockbox-c7d42bbbd7641c8e9e06b28000c4c02c2ee36d21.tar.gz
rockbox-c7d42bbbd7641c8e9e06b28000c4c02c2ee36d21.zip
update to the api to allow fetching of currently playing id3 struct. Adding the favorites plugin.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3854 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugin.c2
-rw-r--r--apps/plugin.h6
-rw-r--r--apps/plugins/favorites.c51
3 files changed, 57 insertions, 2 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index ad3cbdca43..08358aa576 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -31,6 +31,7 @@
31#include "plugin.h" 31#include "plugin.h"
32#include "lang.h" 32#include "lang.h"
33#include "keyboard.h" 33#include "keyboard.h"
34#include "mpeg.h"
34 35
35#ifdef HAVE_LCD_BITMAP 36#ifdef HAVE_LCD_BITMAP
36#include "widgets.h" 37#include "widgets.h"
@@ -134,6 +135,7 @@ static struct plugin_api rockbox_api = {
134 splash, 135 splash,
135 qsort, 136 qsort,
136 kbd_input, 137 kbd_input,
138 mpeg_current_track,
137}; 139};
138 140
139int plugin_load(char* plugin, void* parameter) 141int plugin_load(char* plugin, void* parameter)
diff --git a/apps/plugin.h b/apps/plugin.h
index dab3320b2a..6926797cba 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -39,9 +39,10 @@
39#include "font.h" 39#include "font.h"
40#include "system.h" 40#include "system.h"
41#include "lcd.h" 41#include "lcd.h"
42 42#include "id3.h"
43#include "mpeg.h"
43/* increase this every time the api struct changes */ 44/* increase this every time the api struct changes */
44#define PLUGIN_API_VERSION 4 45#define PLUGIN_API_VERSION 5
45 46
46/* plugin return codes */ 47/* plugin return codes */
47enum plugin_status { 48enum plugin_status {
@@ -162,6 +163,7 @@ struct plugin_api {
162 void (*qsort)(void *base, size_t nmemb, size_t size, 163 void (*qsort)(void *base, size_t nmemb, size_t size,
163 int(*compar)(const void *, const void *)); 164 int(*compar)(const void *, const void *));
164 int (*kbd_input)(char* buffer, int buflen); 165 int (*kbd_input)(char* buffer, int buflen);
166 struct mp3entry* (*mpeg_current_track)();
165}; 167};
166 168
167/* defined by the plugin loader (plugin.c) */ 169/* defined by the plugin loader (plugin.c) */
diff --git a/apps/plugins/favorites.c b/apps/plugins/favorites.c
new file mode 100644
index 0000000000..59001647ac
--- /dev/null
+++ b/apps/plugins/favorites.c
@@ -0,0 +1,51 @@
1#include "plugin.h"
2#define FAVORITES_FILE "/favorites.m3u"
3
4static struct plugin_api* rb;
5
6enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
7{
8 struct mp3entry* id3;
9 char track_path[MAX_PATH+1];
10 int fd, seek, result, len;
11
12 /* this macro should be called as the first thing you do in the plugin.
13 it test that the api version and model the plugin was compiled for
14 matches the machine it is running on */
15 TEST_PLUGIN_API(api);
16
17 /* if you don't use the parameter, you can do like
18 this to avoid the compiler warning about it */
19 (void)parameter;
20
21 rb = api;
22
23 id3 = rb->mpeg_current_track();
24 if (!id3)
25 return PLUGIN_ERROR;
26
27 fd = rb->open(FAVORITES_FILE, O_WRONLY);
28
29 // creat the file if it does not return on open.
30 if (fd < 0)
31 fd = rb->creat(FAVORITES_FILE, 0);
32
33 if (fd > 0) {
34 rb->strcpy(track_path, id3->path);
35 len = rb->strlen(track_path);
36
37 // seek to the end of file
38 seek = rb->lseek(fd, 0, SEEK_END);
39 // append the current mp3 path
40 track_path[len] = '\n';
41 result = rb->write(fd, track_path, len + 1);
42 track_path[len] = '\0';
43 rb->close(fd);
44 }
45
46 rb->splash(HZ*2, 0, true, "Saved Favorite");
47
48 return PLUGIN_OK;
49}
50
51