1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Jonathan Gordon
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "oldmenuapi.h"
24 static struct plugin_api
* rb
;
27 static int dirs_count
;
29 #define RFA_FILE ROCKBOX_DIR "/folder_advance_list.dat"
30 #define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt"
31 #define MAX_REMOVED_DIRS 10
35 int num_replaced_dirs
= 0;
36 char removed_dirs
[MAX_REMOVED_DIRS
][MAX_PATH
];
39 char folder
[][MAX_PATH
];
41 struct file_format
*list
= NULL
;
42 #if CONFIG_KEYPAD == PLAYER_PAD
44 #elif (CONFIG_KEYPAD == RECORDER_PAD) \
45 || (CONFIG_KEYPAD == ONDIO_PAD)
47 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) \
48 || (CONFIG_KEYPAD == IRIVER_H300_PAD)
50 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
51 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
52 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
54 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
56 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
58 #elif CONFIG_KEYPAD == GIGABEAT_PAD
60 #elif CONFIG_KEYPAD == SANSA_E200_PAD
62 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
66 void update_screen(bool clear
)
71 rb
->snprintf(buf
,sizeof(buf
),"Folders: %d",dirs_count
);
75 rb
->screens
[i
]->clear_display();
76 rb
->screens
[i
]->putsxy(0,0,buf
);
77 rb
->screens
[i
]->update();
81 void traversedir(char* location
, char* name
)
85 char fullpath
[MAX_PATH
], path
[MAX_PATH
];
89 rb
->snprintf(fullpath
, sizeof(fullpath
), "%s/%s", location
, name
);
90 dir
= rb
->opendir(fullpath
);
92 entry
= rb
->readdir(dir
);
97 if (entry
->d_name
[0] == '.')
99 if ( !rb
->strcmp(entry
->d_name
,".")
100 || !rb
->strcmp(entry
->d_name
,"..")
101 || !rb
->strcmp(entry
->d_name
,".rockbox"))
107 /* check if path is removed directory, if so dont enter it */
108 rb
->snprintf(path
, MAX_PATH
, "%s/%s", fullpath
, entry
->d_name
);
109 while(path
[0] == '/')
110 rb
->strncpy(path
, path
+ 1, rb
->strlen(path
));
111 for(i
= 0; i
< num_replaced_dirs
; i
++)
113 if(!rb
->strcmp(path
, removed_dirs
[i
]))
122 if (entry
->attribute
& ATTR_DIRECTORY
) {
125 rb
->snprintf(path
,MAX_PATH
,"%s/%s",fullpath
,entry
->d_name
);
126 start
= &path
[rb
->strlen(path
)];
127 rb
->memset(start
,0,&path
[MAX_PATH
-1]-start
);
128 rb
->write(fd
,path
,MAX_PATH
);
129 traversedir(fullpath
, entry
->d_name
);
132 if (*rb
->current_tick
- lasttick
> (HZ
/2)) {
133 update_screen(false);
134 lasttick
= *rb
->current_tick
;
135 if (rb
->action_userabort(TIMEOUT_NOBLOCK
))
142 entry
= rb
->readdir(dir
);
148 bool custom_dir(void)
151 char *starts
, line
[MAX_PATH
], formatted_line
[MAX_PATH
];
156 /* populate removed dirs array */
157 if((fd2
= rb
->open(RFADIR_FILE
,O_RDONLY
)) > 0)
159 while ((rb
->read_line(fd2
, line
, MAX_PATH
- 1)) > 0)
161 if ((line
[0] == '-') && (line
[1] == '/') &&
162 (num_replaced_dirs
< MAX_REMOVED_DIRS
))
164 num_replaced_dirs
++;
165 rb
->strncpy(removed_dirs
[num_replaced_dirs
- 1], line
+ 2,
172 if((fd2
= rb
->open(RFADIR_FILE
,O_RDONLY
)) > 0)
174 while ((rb
->read_line(fd2
, line
, MAX_PATH
- 1)) > 0)
176 /* blank lines and removed dirs ignored */
177 if (rb
->strlen(line
) && ((line
[0] != '-') || (line
[1] != '/')))
179 /* remove preceeding '/'s from the line */
180 while(line
[0] == '/')
181 rb
->strncpy(line
, line
+ 1, rb
->strlen(line
));
183 rb
->snprintf(formatted_line
, MAX_PATH
, "/%s", line
);
185 dir_check
= rb
->opendir(formatted_line
);
189 rb
->closedir(dir_check
);
190 starts
= &formatted_line
[rb
->strlen(formatted_line
)];
191 rb
->memset(starts
, 0, &formatted_line
[MAX_PATH
-1]-starts
);
192 bool write_line
= true;
194 for(i
= 0; i
< num_replaced_dirs
; i
++)
196 if(!rb
->strcmp(line
, removed_dirs
[i
]))
206 rb
->write(fd
, formatted_line
, MAX_PATH
);
209 traversedir("", line
);
214 rb
->snprintf(buf
,sizeof(buf
),"Not found:");
217 rb
->screens
[i
]->puts(0,0,buf
);
218 rb
->screens
[i
]->puts(0, errors
, line
);
220 update_screen(false);
226 /* Press button to continue */
227 rb
->get_action(CONTEXT_STD
, TIMEOUT_BLOCK
);
238 fd
= rb
->open(RFA_FILE
,O_CREAT
|O_WRONLY
);
239 rb
->write(fd
,&dirs_count
,sizeof(int));
242 rb
->splash(HZ
, "Couldnt open %s", RFA_FILE
);
245 #ifndef HAVE_LCD_CHARCELLS
248 lasttick
= *rb
->current_tick
;
253 rb
->lseek(fd
,0,SEEK_SET
);
254 rb
->write(fd
,&dirs_count
,sizeof(int));
257 char *list_get_name_cb(int selected_item
,void* data
,char* buf
)
260 rb
->strcpy(buf
,list
->folder
[selected_item
]);
266 struct gui_synclist lists
;
270 fd
= rb
->open(RFA_FILE
,O_RDONLY
);
273 buffer
= rb
->plugin_get_audio_buffer((size_t *)&buffer_size
);
276 rb
->read(fd
,buffer
,buffer_size
);
278 list
= (struct file_format
*)buffer
;
279 dirs_count
= list
->count
;
281 rb
->gui_synclist_init(&lists
,list_get_name_cb
,0, false, 1, NULL
);
282 rb
->gui_synclist_set_icon_callback(&lists
,NULL
);
283 rb
->gui_synclist_set_nb_items(&lists
,list
->count
);
284 rb
->gui_synclist_limit_scroll(&lists
,true);
285 rb
->gui_synclist_select_item(&lists
, 0);
289 rb
->gui_synclist_draw(&lists
);
290 button
= rb
->get_action(CONTEXT_LIST
,TIMEOUT_BLOCK
);
291 if (rb
->gui_synclist_do_button(&lists
,&button
,LIST_WRAP_UNLESS_HELD
))
293 selection
= rb
->gui_synclist_get_sel_pos(&lists
);
297 list
->folder
[selection
][0] = ' ';
298 list
->folder
[selection
][1] = '\0';
300 case ACTION_STD_CONTEXT
:
303 static const struct menu_item items
[] = {
304 { "Remove Folder", NULL
},
305 { "Remove Folder Tree", NULL
},
307 m
= menu_init(rb
, items
, sizeof(items
) / sizeof(*items
),
308 NULL
, NULL
, NULL
, NULL
);
310 switch (menu_show(m
))
313 list
->folder
[selection
][0] = ' ';
314 list
->folder
[selection
][1] = '\0';
319 rb
->strcpy(temp
,list
->folder
[selection
]);
320 len
= rb
->strlen(temp
);
321 for (i
=0;i
<list
->count
;i
++)
323 if (!rb
->strncmp(list
->folder
[i
],temp
,len
))
325 list
->folder
[i
][0] = ' ';
326 list
->folder
[i
][1] = '\0';
335 case ACTION_STD_CANCEL
:
338 static const struct menu_item items
[] = {
339 { "Save and Exit", NULL
},
340 { "Ignore Changes and Exit", NULL
},
342 m
= menu_init(rb
, items
, sizeof(items
) / sizeof(*items
),
343 NULL
, NULL
, NULL
, NULL
);
345 switch (menu_show(m
))
349 rb
->splash(HZ
*2, "Saving " RFA_FILE
);
350 fd
= rb
->open(RFA_FILE
, O_CREAT
|O_WRONLY
);
353 rb
->splash(HZ
, "Could Not Open " RFA_FILE
);
357 rb
->write(fd
,&dirs_count
,sizeof(int));
358 for (i
=0;i
<list
->count
;i
++)
360 if (list
->folder
[i
][0] != ' ')
363 rb
->write(fd
,list
->folder
[i
],MAX_PATH
);
366 rb
->lseek(fd
,0,SEEK_SET
);
367 rb
->write(fd
,&dirs_count
,sizeof(int));
381 static const struct menu_item items
[] = {
382 { "Generate Folder List", NULL
},
383 { "Edit Folder List", NULL
},
386 m
= menu_init(rb
, items
, sizeof(items
) / sizeof(*items
),
387 NULL
, NULL
, NULL
, NULL
);
389 switch (menu_show(m
))
391 case 0: /* generate */
392 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
396 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
397 rb
->cpu_boost(false);
399 #ifdef HAVE_REMOTE_LCD
400 rb
->remote_backlight_on();
405 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
409 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
410 rb
->cpu_boost(false);
412 #ifdef HAVE_REMOTE_LCD
413 rb
->remote_backlight_on();
425 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)