New release - version 0.6.1; zasm compiler added - ZeX/OS assembly compiler; lot...
[ZeXOS.git] / apps / wm / filemanager.c
blobae077a5a9e06d04cad6d9964bcdd3dd93b74555d
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <libx/base.h>
25 #include <libx/object.h>
26 #include <libx/image.h>
27 #include <libx/cursor.h>
28 #include <libx/text.h>
29 #include "window.h"
30 #include "cursor.h"
32 #define VFS_FILEATTR_FILE 0x1
33 #define VFS_FILEATTR_DIR 0x2
34 #define VFS_FILEATTR_HIDDEN 0x4
35 #define VFS_FILEATTR_SYSTEM 0x8
36 #define VFS_FILEATTR_BIN 0x10
37 #define VFS_FILEATTR_READ 0x20
38 #define VFS_FILEATTR_WRITE 0x40
39 #define VFS_FILEATTR_MOUNTED 0x80
41 typedef struct {
42 char *name;
43 unsigned attrib;
44 unsigned char next;
45 } dirent_t;
47 extern wmcursor *cursor;
49 unsigned winfm_act = 0;
51 wmwindow *winfm;
53 dirent_t *dirent;
55 unsigned short *bitmap_folder;
56 unsigned short *bitmap_file;
58 void getdir ()
60 asm volatile (
61 "movl $25, %%eax;"
62 "int $0x80;"
63 "movl %%eax, %0;"
64 : "=g" (dirent) :: "%eax");
67 void chdir (char *dir)
69 asm volatile (
70 "movl $24, %%eax;"
71 "movl %0, %%ebx;"
72 "int $0x80;"
73 :: "b" (dir) : "%eax", "memory");
76 unsigned filemanager_exit ()
78 winfm_act = 0;
80 return 1;
83 void ifilemanager ()
85 getdir ();
87 winfm = window_create ("Filemanager");
89 if (!winfm)
90 return;
92 winfm_act = 1;
94 //winfm->hnd_exit = (unsigned *) &filemanager_exit;
97 unsigned filemanager_draw ()
99 if (!winfm_act || !winfm)
100 return 0;
102 /* when error or directory is clear */
103 if (!dirent) {
104 if (cursor->state == XCURSOR_STATE_RBUTTON) {
105 chdir ("..");
107 getdir ();
110 return 0;
114 unsigned id = 0;
116 while (1) {
117 xtext_puts (winfm->x+1+(id*42), winfm->y+44, 0, dirent[id].name);
119 if ((winfm->x+33+(id*42)) > winfm->x+winfm->size_x)
120 winfm->size_x += 42;
122 unsigned i = 0;
123 unsigned j = 0;
124 unsigned k = 0;
125 unsigned pix = 0;
127 unsigned short *bitmap = 0;
129 if (dirent[id].attrib & VFS_FILEATTR_DIR)
130 bitmap = bitmap_folder;
132 if (dirent[id].attrib & VFS_FILEATTR_FILE)
133 bitmap = bitmap_file;
135 if (!bitmap)
136 continue;
138 for (i = 0; i < 32*32; i ++) {
139 if (k >= 32) {
140 j ++;
141 k = 0;
144 pix = (1024-i)+34;
146 if (bitmap[pix] != 0)
147 xpixel (winfm->x+1+k+(id*42), winfm->y+12+j, (unsigned short) bitmap[pix]);
149 k ++;
152 if (cursor->state == XCURSOR_STATE_LBUTTON)
153 if (cursor->x > (signed) (winfm->x+1+(id*42)) && cursor->x < (signed) (winfm->x+33+(id*42)) &&
154 cursor->y > (signed) winfm->y+12 && cursor->y <= (signed) winfm->y+54) {
155 if (dirent[id].attrib & VFS_FILEATTR_DIR) {
156 if (dirent[id].name[0] == '.') {
157 if (dirent[id].name[1] == '.') {
158 chdir ("..");
160 free (dirent);
162 dirent = 0;
164 getdir ();
166 return 1;
169 chdir (dirent[id].name);
171 free (dirent);
173 dirent = 0;
175 getdir ();
178 if (dirent[id].attrib & VFS_FILEATTR_FILE) {
179 tview_open (dirent[id].name);
182 return 1;
185 if (cursor->state == XCURSOR_STATE_RBUTTON) {
186 if (cursor->x > (signed) winfm->x && cursor->x < (signed) winfm->x+(signed) winfm->size_x &&
187 cursor->y > (signed) winfm->y+11 && cursor->y <= (signed) winfm->y+(signed) winfm->size_y) {
189 dirent = 0;
191 free (dirent);
193 chdir ("..");
195 getdir ();
197 return 1;
201 if (!dirent[id].next)
202 break;
204 id ++;
207 return 1;
210 unsigned init_filemanager ()
212 /* FOLDER bitmap */
213 bitmap_folder = (unsigned short *) malloc (2100);
215 if (!bitmap_folder)
216 return 0;
218 memset (bitmap_folder, 0, 2048+70);
220 // html web page
221 int fd = open ("folder", O_RDONLY);
223 if (!fd) {
224 puts ("error -> file 'folder' not found\n");
225 return 0;
228 /*if (!read (fd, (unsigned char *) bitmap_folder, 2048+70)) {
229 puts ("error -> something was wrong !\n");
230 return 0;
233 /* FILE bitmap */
234 bitmap_file = (unsigned short *) malloc (2100);
236 if (!bitmap_file)
237 return 0;
239 memset (bitmap_file, 0, 2048+70);
241 // html web page
242 fd = open ("file", O_RDONLY);
244 if (!fd) {
245 puts ("error -> file 'file' not found\n");
246 return 0;
249 /*if (!read (fd, (unsigned char *) bitmap_file, 2048+70)) {
250 puts ("error -> something was wrong !\n");
251 return 0;
254 winfm = 0;
256 winfm_act = 0;
258 return 1;