diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-05-16 12:56:42 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-05-16 12:56:42 +0000 |
commit | 34acad9f903982c85193068a75b7c3577528d712 (patch) | |
tree | 131267aaf2832f4f2f437e855a40202c2d76b07a /uisimulator/tree.c | |
parent | 8218285c0b848cf2173a59129062e033d0c8e46a (diff) | |
download | rockbox-34acad9f903982c85193068a75b7c3577528d712.tar.gz rockbox-34acad9f903982c85193068a75b7c3577528d712.zip |
Moved tree.? to apps module
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@590 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/tree.c')
-rw-r--r-- | uisimulator/tree.c | 298 |
1 files changed, 0 insertions, 298 deletions
diff --git a/uisimulator/tree.c b/uisimulator/tree.c deleted file mode 100644 index c74aa07fea..0000000000 --- a/uisimulator/tree.c +++ /dev/null | |||
@@ -1,298 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Daniel Stenberg | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <string.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <stdbool.h> | ||
23 | |||
24 | #include "dir.h" | ||
25 | #include "file.h" | ||
26 | #include "lcd.h" | ||
27 | #include "button.h" | ||
28 | #include "kernel.h" | ||
29 | #include "tree.h" | ||
30 | #include "icons.h" | ||
31 | #include "play.h" | ||
32 | |||
33 | |||
34 | #define TREE_MAX_FILENAMELEN 128 | ||
35 | #define MAX_DIR_LEVELS 10 | ||
36 | |||
37 | struct entry { | ||
38 | bool file; /* true if file, false if dir */ | ||
39 | char name[TREE_MAX_FILENAMELEN]; | ||
40 | int namelen; | ||
41 | }; | ||
42 | |||
43 | void browse_root(void) | ||
44 | { | ||
45 | dirbrowse("/"); | ||
46 | } | ||
47 | |||
48 | |||
49 | #ifdef HAVE_LCD_BITMAP | ||
50 | |||
51 | #define TREE_MAX_ON_SCREEN 7 | ||
52 | #define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */ | ||
53 | |||
54 | #define MARGIN_Y 8 /* Y pixel margin */ | ||
55 | #define MARGIN_X 12 /* X pixel margin */ | ||
56 | #define LINE_Y 0 /* Y position the entry-list starts at */ | ||
57 | #define LINE_X 2 /* X position the entry-list starts at */ | ||
58 | #define LINE_HEIGTH 8 /* pixels for each text line */ | ||
59 | |||
60 | extern unsigned char bitmap_icons_6x8[LastIcon][6]; | ||
61 | extern icons_6x8; | ||
62 | |||
63 | #else /* HAVE_LCD_BITMAP */ | ||
64 | |||
65 | #define TREE_MAX_ON_SCREEN 2 | ||
66 | #define TREE_MAX_LEN_DISPLAY 11 /* max length that fits on screen */ | ||
67 | #define LINE_Y 0 /* Y position the entry-list starts at */ | ||
68 | #define LINE_X 1 /* X position the entry-list starts at */ | ||
69 | |||
70 | #endif /* HAVE_LCD_BITMAP */ | ||
71 | |||
72 | int static showdir(char *path, struct entry *buffer, int start, | ||
73 | int scrollpos, int* at_end) | ||
74 | { | ||
75 | int i; | ||
76 | int j=0; | ||
77 | int icon_type = 0; | ||
78 | DIR *dir = opendir(path); | ||
79 | struct dirent *entry; | ||
80 | |||
81 | if(!dir) | ||
82 | return -1; /* not a directory */ | ||
83 | |||
84 | i=start; | ||
85 | *at_end=0; /* Have we displayed the last directory entry? */ | ||
86 | while((entry = readdir(dir))) { | ||
87 | int len; | ||
88 | |||
89 | if(entry->d_name[0] == '.') | ||
90 | /* skip names starting with a dot */ | ||
91 | continue; | ||
92 | |||
93 | if(j++ < scrollpos) | ||
94 | continue ; | ||
95 | |||
96 | len = strlen(entry->d_name); | ||
97 | if(len < TREE_MAX_FILENAMELEN) | ||
98 | /* strncpy() is evil, we memcpy() instead, +1 includes the | ||
99 | trailing zero */ | ||
100 | memcpy(buffer[i].name, entry->d_name, len+1); | ||
101 | else | ||
102 | memcpy(buffer[i].name, "too long", 9); | ||
103 | |||
104 | buffer[i].file = !(entry->attribute&ATTR_DIRECTORY); | ||
105 | |||
106 | #ifdef HAVE_LCD_BITMAP | ||
107 | if ( buffer[i].file ) | ||
108 | icon_type=File; | ||
109 | else | ||
110 | icon_type=Folder; | ||
111 | lcd_bitmap(bitmap_icons_6x8[icon_type], 6, MARGIN_Y+i*LINE_HEIGTH, 6, | ||
112 | 8, true); | ||
113 | #endif | ||
114 | |||
115 | if(len < TREE_MAX_LEN_DISPLAY) | ||
116 | lcd_puts(LINE_X, LINE_Y+i, buffer[i].name); | ||
117 | else { | ||
118 | char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY]; | ||
119 | buffer[i].name[TREE_MAX_LEN_DISPLAY]=0; | ||
120 | lcd_puts(LINE_X, LINE_Y+i, buffer[i].name); | ||
121 | buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage; | ||
122 | } | ||
123 | |||
124 | if(++i >= TREE_MAX_ON_SCREEN) | ||
125 | break; | ||
126 | } | ||
127 | |||
128 | if (entry==0) { | ||
129 | *at_end=1; | ||
130 | } else { | ||
131 | *at_end=(readdir(dir)==0); | ||
132 | } | ||
133 | j = i ; | ||
134 | while (j++ < TREE_MAX_ON_SCREEN) { | ||
135 | lcd_puts(LINE_X, LINE_Y+j," "); | ||
136 | } | ||
137 | closedir(dir); | ||
138 | |||
139 | return i; | ||
140 | } | ||
141 | |||
142 | bool dirbrowse(char *root) | ||
143 | { | ||
144 | struct entry buffer[TREE_MAX_ON_SCREEN]; | ||
145 | int numentries; | ||
146 | char buf[255]; | ||
147 | char currdir[255]; | ||
148 | int dircursor=0; | ||
149 | int i; | ||
150 | int start=0; | ||
151 | int at_end=0; | ||
152 | int dirpos[MAX_DIR_LEVELS]; | ||
153 | int dirlevel=0; | ||
154 | |||
155 | lcd_clear_display(); | ||
156 | |||
157 | #ifdef HAVE_LCD_BITMAP | ||
158 | lcd_putsxy(0,0, "[Browse]",0); | ||
159 | lcd_setmargins(0,MARGIN_Y); | ||
160 | lcd_setfont(0); | ||
161 | #endif | ||
162 | memcpy(currdir,root,sizeof(currdir)); | ||
163 | |||
164 | numentries = showdir(root, buffer, 0, start, &at_end); | ||
165 | |||
166 | if (numentries == -1) | ||
167 | return -1; /* root is not a directory */ | ||
168 | |||
169 | lcd_puts(0, dircursor, "-"); | ||
170 | lcd_update(); | ||
171 | |||
172 | while(1) { | ||
173 | int key = button_get(); | ||
174 | |||
175 | if(!key) { | ||
176 | sleep(1); | ||
177 | continue; | ||
178 | } | ||
179 | switch(key) { | ||
180 | case BUTTON_OFF: | ||
181 | return false; | ||
182 | break; | ||
183 | |||
184 | case BUTTON_LEFT: | ||
185 | i=strlen(currdir); | ||
186 | if (i==1) { | ||
187 | return false; | ||
188 | } | ||
189 | else { | ||
190 | while (currdir[i-1]!='/') | ||
191 | i--; | ||
192 | strcpy(buf,&currdir[i]); | ||
193 | if (i==1) | ||
194 | currdir[i]=0; | ||
195 | else | ||
196 | currdir[i-1]=0; | ||
197 | |||
198 | lcd_clear_display(); | ||
199 | #ifdef HAVE_LCD_BITMAP | ||
200 | lcd_putsxy(0,0, "[Browse]",0); | ||
201 | #endif | ||
202 | dirlevel--; | ||
203 | if ( dirlevel < MAX_DIR_LEVELS ) | ||
204 | start = dirpos[dirlevel]; | ||
205 | else | ||
206 | start = 0; | ||
207 | numentries = showdir(currdir, buffer, 0, start, &at_end); | ||
208 | dircursor=0; | ||
209 | while ( (dircursor < TREE_MAX_ON_SCREEN) && | ||
210 | (strcmp(buffer[dircursor].name,buf)!=0)) | ||
211 | dircursor++; | ||
212 | if (dircursor==TREE_MAX_ON_SCREEN) | ||
213 | dircursor=0; | ||
214 | lcd_puts(0, LINE_Y+dircursor, "-"); | ||
215 | lcd_update(); | ||
216 | } | ||
217 | |||
218 | break; | ||
219 | |||
220 | case BUTTON_RIGHT: | ||
221 | case BUTTON_PLAY: | ||
222 | if ((currdir[0]=='/') && (currdir[1]==0)) { | ||
223 | sprintf(buf,"%s%s",currdir,buffer[dircursor].name); | ||
224 | } else { | ||
225 | sprintf(buf,"%s/%s",currdir,buffer[dircursor].name); | ||
226 | } | ||
227 | |||
228 | if (!buffer[dircursor].file) { | ||
229 | memcpy(currdir,buf,sizeof(currdir)); | ||
230 | if ( dirlevel < MAX_DIR_LEVELS ) | ||
231 | dirpos[dirlevel] = start+dircursor; | ||
232 | dirlevel++; | ||
233 | dircursor=0; | ||
234 | start=0; | ||
235 | } else { | ||
236 | playtune(currdir, buffer[dircursor].name); | ||
237 | #ifdef HAVE_LCD_BITMAP | ||
238 | lcd_setmargins(0, MARGIN_Y); | ||
239 | lcd_setfont(0); | ||
240 | #endif | ||
241 | } | ||
242 | |||
243 | lcd_clear_display(); | ||
244 | numentries = showdir(currdir, buffer, 0, start, &at_end); | ||
245 | #ifdef HAVE_LCD_BITMAP | ||
246 | lcd_putsxy(0,0, "[Browse]",0); | ||
247 | #endif | ||
248 | lcd_puts(0, LINE_Y+dircursor, "-"); | ||
249 | lcd_update(); | ||
250 | break; | ||
251 | |||
252 | case BUTTON_UP: | ||
253 | if(dircursor) { | ||
254 | lcd_puts(0, LINE_Y+dircursor, " "); | ||
255 | dircursor--; | ||
256 | lcd_puts(0, LINE_Y+dircursor, "-"); | ||
257 | lcd_update(); | ||
258 | } | ||
259 | else { | ||
260 | if (start) { | ||
261 | lcd_clear_display(); | ||
262 | start--; | ||
263 | numentries = showdir(currdir, buffer, 0, | ||
264 | start, &at_end); | ||
265 | #ifdef HAVE_LCD_BITMAP | ||
266 | lcd_putsxy(0,0, "[Browse]",0); | ||
267 | #endif | ||
268 | lcd_puts(0, LINE_Y+dircursor, "-"); | ||
269 | lcd_update(); | ||
270 | } | ||
271 | } | ||
272 | break; | ||
273 | case BUTTON_DOWN: | ||
274 | if(dircursor+1 < numentries) { | ||
275 | lcd_puts(0, LINE_Y+dircursor, " "); | ||
276 | dircursor++; | ||
277 | lcd_puts(0, LINE_Y+dircursor, "-"); | ||
278 | lcd_update(); | ||
279 | } else | ||
280 | { | ||
281 | if (!at_end) { | ||
282 | lcd_clear_display(); | ||
283 | start++; | ||
284 | numentries = showdir(currdir, buffer, 0, | ||
285 | start, &at_end); | ||
286 | #ifdef HAVE_LCD_BITMAP | ||
287 | lcd_putsxy(0,0, "[Browse]",0); | ||
288 | #endif | ||
289 | lcd_puts(0, LINE_Y+dircursor, "-"); | ||
290 | lcd_update(); | ||
291 | } | ||
292 | } | ||
293 | break; | ||
294 | } | ||
295 | } | ||
296 | |||
297 | return false; | ||
298 | } | ||