System call sys_getchar () was improved; stdin is correspond with 0. fd and stdout...
[ZeXOS.git] / apps / wm / filemanager.c
blob562f638b51f9c52a0a6560d56f4bb3f92619a7b7
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
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 void chdir (char *dir)
71 asm volatile (
72 "movl $24, %%eax;"
73 "movl %0, %%ebx;"
74 "int $0x80;"
75 :: "b" (dir) : "%eax", "memory");
78 unsigned filemanager_exit ()
80 winfm_act = 0;
82 return 1;
85 void ifilemanager ()
87 getdir ();
89 winfm = window_create ("Filemanager");
91 if (!winfm)
92 return;
94 winfm_act = 1;
96 //winfm->hnd_exit = (unsigned *) &filemanager_exit;
99 unsigned filemanager_draw ()
101 if (!winfm_act || !winfm)
102 return 0;
104 /* when error or directory is clear */
105 if (!dirent) {
106 if (cursor->state == XCURSOR_STATE_RBUTTON) {
107 chdir ("..");
109 getdir ();
112 return 0;
116 unsigned id = 0;
118 while (1) {
119 xtext_puts (winfm->x+1+(id*42), winfm->y+44, 0, dirent[id].name);
121 if ((winfm->x+33+(id*42)) > winfm->x+winfm->size_x)
122 winfm->size_x += 42;
124 unsigned i = 0;
125 unsigned j = 0;
126 unsigned k = 0;
127 unsigned pix = 0;
129 unsigned short *bitmap = 0;
131 if (dirent[id].attrib & VFS_FILEATTR_DIR)
132 bitmap = bitmap_folder;
134 if (dirent[id].attrib & VFS_FILEATTR_FILE)
135 bitmap = bitmap_file;
137 if (!bitmap)
138 continue;
140 for (i = 0; i < 32*32; i ++) {
141 if (k >= 32) {
142 j ++;
143 k = 0;
146 pix = (1024-i)+34;
148 if (bitmap[pix] != 0)
149 xpixel (winfm->x+1+k+(id*42), winfm->y+12+j, (unsigned short) bitmap[pix]);
151 k ++;
154 if (cursor->state == XCURSOR_STATE_LBUTTON)
155 if (cursor->x > (signed) (winfm->x+1+(id*42)) && cursor->x < (signed) (winfm->x+33+(id*42)) &&
156 cursor->y > (signed) winfm->y+12 && cursor->y <= (signed) winfm->y+54) {
157 if (dirent[id].attrib & VFS_FILEATTR_DIR) {
158 if (dirent[id].name[0] == '.') {
159 if (dirent[id].name[1] == '.') {
160 chdir ("..");
162 free (dirent);
164 dirent = 0;
166 getdir ();
168 return 1;
171 chdir (dirent[id].name);
173 free (dirent);
175 dirent = 0;
177 getdir ();
180 if (dirent[id].attrib & VFS_FILEATTR_FILE) {
181 tview_open (dirent[id].name);
184 return 1;
187 if (cursor->state == XCURSOR_STATE_RBUTTON) {
188 if (cursor->x > (signed) winfm->x && cursor->x < (signed) winfm->x+(signed) winfm->size_x &&
189 cursor->y > (signed) winfm->y+11 && cursor->y <= (signed) winfm->y+(signed) winfm->size_y) {
191 dirent = 0;
193 free (dirent);
195 chdir ("..");
197 getdir ();
199 return 1;
203 if (!dirent[id].next)
204 break;
206 id ++;
209 return 1;
212 unsigned init_filemanager ()
214 /* FOLDER bitmap */
215 bitmap_folder = (unsigned short *) malloc (2100);
217 if (!bitmap_folder)
218 return 0;
220 memset (bitmap_folder, 0, 2048+70);
222 // html web page
223 int fd = open ("folder", O_RDONLY);
225 if (!fd) {
226 puts ("error -> file 'folder' not found\n");
227 return 0;
230 /*if (!read (fd, (unsigned char *) bitmap_folder, 2048+70)) {
231 puts ("error -> something was wrong !\n");
232 return 0;
235 /* FILE bitmap */
236 bitmap_file = (unsigned short *) malloc (2100);
238 if (!bitmap_file)
239 return 0;
241 memset (bitmap_file, 0, 2048+70);
243 // html web page
244 fd = open ("file", O_RDONLY);
246 if (!fd) {
247 puts ("error -> file 'file' not found\n");
248 return 0;
251 /*if (!read (fd, (unsigned char *) bitmap_file, 2048+70)) {
252 puts ("error -> something was wrong !\n");
253 return 0;
256 winfm = 0;
258 winfm_act = 0;
260 return 1;