Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / wm / filemanager.c
blobec2ef3c65386182d6775dab2ab8cf00abe1240d9
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
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, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <fcntl.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <libx/base.h>
27 #include <libx/object.h>
28 #include <libx/image.h>
29 #include <libx/cursor.h>
30 #include <libx/text.h>
31 #include "window.h"
32 #include "cursor.h"
34 #define VFS_FILEATTR_FILE 0x1
35 #define VFS_FILEATTR_DIR 0x2
36 #define VFS_FILEATTR_HIDDEN 0x4
37 #define VFS_FILEATTR_SYSTEM 0x8
38 #define VFS_FILEATTR_BIN 0x10
39 #define VFS_FILEATTR_READ 0x20
40 #define VFS_FILEATTR_WRITE 0x40
41 #define VFS_FILEATTR_MOUNTED 0x80
43 typedef struct {
44 char *name;
45 unsigned attrib;
46 unsigned char next;
47 } dirent_t;
49 extern wmcursor *cursor;
51 unsigned winfm_act = 0;
53 wmwindow *winfm;
55 dirent_t *dirent;
57 unsigned short *bitmap_folder;
58 unsigned short *bitmap_file;
60 void getdir ()
62 asm volatile (
63 "movl $25, %%eax;"
64 "int $0x80;"
65 "movl %%eax, %0;"
66 : "=g" (dirent) :: "%eax");
69 unsigned filemanager_exit ()
71 winfm_act = 0;
73 return 1;
76 void ifilemanager ()
78 getdir ();
80 winfm = window_create ("Filemanager");
82 if (!winfm)
83 return;
85 winfm_act = 1;
87 //winfm->hnd_exit = (unsigned *) &filemanager_exit;
90 unsigned filemanager_draw ()
92 if (!winfm_act || !winfm)
93 return 0;
95 /* when error or directory is clear */
96 if (!dirent) {
97 if (cursor->state == XCURSOR_STATE_RBUTTON) {
98 chdir ("..");
100 getdir ();
103 return 0;
107 unsigned id = 0;
109 while (1) {
110 xtext_puts (winfm->x+1+(id*42), winfm->y+44, 0, dirent[id].name);
112 if ((winfm->x+33+(id*42)) > winfm->x+winfm->size_x)
113 winfm->size_x += 42;
115 unsigned i = 0;
116 unsigned j = 0;
117 unsigned k = 0;
118 unsigned pix = 0;
120 unsigned short *bitmap = 0;
122 if (dirent[id].attrib & VFS_FILEATTR_DIR)
123 bitmap = bitmap_folder;
125 if (dirent[id].attrib & VFS_FILEATTR_FILE)
126 bitmap = bitmap_file;
128 if (!bitmap)
129 continue;
131 for (i = 0; i < 32*32; i ++) {
132 if (k >= 32) {
133 j ++;
134 k = 0;
137 pix = (1024-i)+34;
139 if (bitmap[pix] != 0)
140 xpixel (winfm->x+1+k+(id*42), winfm->y+12+j, (unsigned short) bitmap[pix]);
142 k ++;
145 if (cursor->state == XCURSOR_STATE_LBUTTON)
146 if (cursor->x > (signed) (winfm->x+1+(id*42)) && cursor->x < (signed) (winfm->x+33+(id*42)) &&
147 cursor->y > (signed) winfm->y+12 && cursor->y <= (signed) winfm->y+54) {
148 if (dirent[id].attrib & VFS_FILEATTR_DIR) {
149 if (dirent[id].name[0] == '.') {
150 if (dirent[id].name[1] == '.') {
151 chdir ("..");
153 free (dirent);
155 dirent = 0;
157 getdir ();
159 return 1;
162 chdir (dirent[id].name);
164 free (dirent);
166 dirent = 0;
168 getdir ();
171 if (dirent[id].attrib & VFS_FILEATTR_FILE) {
172 tview_open (dirent[id].name);
175 return 1;
178 if (cursor->state == XCURSOR_STATE_RBUTTON) {
179 if (cursor->x > (signed) winfm->x && cursor->x < (signed) winfm->x+(signed) winfm->size_x &&
180 cursor->y > (signed) winfm->y+11 && cursor->y <= (signed) winfm->y+(signed) winfm->size_y) {
182 dirent = 0;
184 free (dirent);
186 chdir ("..");
188 getdir ();
190 return 1;
194 if (!dirent[id].next)
195 break;
197 id ++;
200 return 1;
203 unsigned init_filemanager ()
205 /* FOLDER bitmap */
206 bitmap_folder = (unsigned short *) malloc (2100);
208 if (!bitmap_folder)
209 return 0;
211 memset (bitmap_folder, 0, 2048+70);
213 // html web page
214 int fd = open ("folder", O_RDONLY);
216 if (!fd) {
217 puts ("error -> file 'folder' not found\n");
218 return 0;
221 /*if (!read (fd, (unsigned char *) bitmap_folder, 2048+70)) {
222 puts ("error -> something was wrong !\n");
223 return 0;
226 /* FILE bitmap */
227 bitmap_file = (unsigned short *) malloc (2100);
229 if (!bitmap_file)
230 return 0;
232 memset (bitmap_file, 0, 2048+70);
234 // html web page
235 fd = open ("file", O_RDONLY);
237 if (!fd) {
238 puts ("error -> file 'file' not found\n");
239 return 0;
242 /*if (!read (fd, (unsigned char *) bitmap_file, 2048+70)) {
243 puts ("error -> something was wrong !\n");
244 return 0;
247 winfm = 0;
249 winfm_act = 0;
251 return 1;