43 #include "program-handler.h"
45 #define FILENAMELEN 24
46 #define MAX_NUMFILES 40
50 static char (filenames[FILENAMELEN + 1])[MAX_NUMFILES];
51 static struct dsc *dscs[MAX_NUMFILES];
52 static unsigned char numfiles, morestart, filenameptr;
56 static struct ctk_label description =
59 static char autoexit = 1;
60 static struct ctk_button autoexitbutton =
62 static char autoexiton[] =
"is On ";
63 static char autoexitoff[] =
"is Off";
64 static struct ctk_label autoexitlabel =
65 {
CTK_LABEL(WIDTH/2 - 9 + 12, 20, 6, 1, autoexiton)};
67 static struct ctk_button morebutton =
70 static struct ctk_button backbutton =
73 static struct ctk_button reloadbutton =
76 PROCESS(directory_process,
"Directory browser");
78 AUTOSTART_PROCESSES(&directory_process);
80 static unsigned char width, height;
84 static char loading = 0;
85 static struct cfs_dir dir;
88 show_statustext(
char *text)
98 show_statustext(
"Cannot open directory");
101 loading = LOADING_DIR;
108 makewindow(
unsigned char i)
120 for(; dscs[i] !=
NULL; ++i) {
122 if(x + strlen(dscs[i]->icon->title) >= width) {
125 if(y >= height - 2 - 4) {
134 x += (
unsigned char)strlen(dscs[i]->icon->title) + 2;
159 if(loading == LOADING_DIR) {
163 for(i = 0; dscs[i] !=
NULL; ++i) {
173 static struct cfs_dirent dirent;
174 static char message[40];
176 if(loading == LOADING_DIR) {
179 loading = LOADING_DSC;
181 }
else if(strcasecmp(&dirent.name[strlen(dirent.name) - 4],
".dsc") == 0) {
182 strncpy(filenames[numfiles], dirent.name, FILENAMELEN);
184 if(numfiles == MAX_NUMFILES) {
186 loading = LOADING_DSC;
190 strcpy(message,
"Found \"");
191 strcpy(message + 7, dirent.name);
192 strcpy(message + 7 + strlen(dirent.name),
"\"...");
193 show_statustext(message);
201 static char message[40];
204 if(loading == LOADING_DSC) {
206 name = filenames[filenameptr];
208 if(dscs[filenameptr] ==
NULL || filenameptr + 1 >= numfiles) {
211 show_statustext(
"Directory loaded");
216 strcpy(message,
"Loading \"");
217 strcpy(message + 9, name);
218 strcpy(message + 9 + strlen(name),
"\"...");
219 show_statustext(message);
229 width = ctk_draw_width() - 2;
230 height = ctk_draw_height() - 2 - CTK_CONF_MENUS;
236 show_statustext(
"Loading directory...");
243 if(ev == PROCESS_EVENT_CONTINUE) {
250 if(data == (process_data_t)&reloadbutton) {
251 for(i = 0; dscs[i] !=
NULL; ++i) {
259 }
else if(data == (process_data_t)&morebutton) {
260 makewindow(morestart);
262 }
else if(data == (process_data_t)&backbutton) {
265 }
else if(data == (process_data_t)&autoexitbutton) {
266 autoexit = 1 - autoexit;
274 for(i = 0; dscs[i] !=
NULL; ++i) {
275 if(data == (process_data_t)(dscs[i]->icon)) {
286 if(data == (process_data_t)&reloadbutton) {
287 show_statustext(
"Reload directory");
288 }
else if(data == (process_data_t)&morebutton) {
289 show_statustext(
"Show more files");
290 }
else if(data == (process_data_t)&backbutton) {
291 show_statustext(
"Show first files");
292 }
else if(data == (process_data_t)&autoexitbutton) {
293 show_statustext(
"Exit when loading program");
295 for(i = 0; dscs[i] !=
NULL; ++i) {
296 if(data == (process_data_t)(dscs[i]->icon)) {
297 show_statustext(dscs[i]->description);
303 data == (process_data_t)&window) {
305 }
else if(ev == PROCESS_EVENT_EXIT) {
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
process_event_t ctk_signal_window_close
Emitted when a window is closed.
void ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
Open a window, or bring window to front if already open.
#define CTK_WIDGET_FOCUS(win, widg)
Set focus to a widget.
void ctk_window_close(struct ctk_window *w)
Close a window if it is open.
process_event_t ctk_signal_widget_select
Emitted when a widget is selected.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define LOADER_LOAD_DSC(name)
Load a DSC (program description).
#define ctk_label_set_text(l, t)
Set the text of a label.
#define NULL
The null pointer.
void ctk_window_redraw(struct ctk_window *w)
Redraw a window.
#define CTK_WIDGET_SET_WIDTH(widget, width)
Sets the width of a widget.
int cfs_readdir(struct cfs_dir *dir, struct cfs_dirent *record)
Read a directory entry.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
The DSC program description structure.
void ctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title)
Create a new window.
#define CTK_WIDGET_SET_XPOS(w, xpos)
Sets the x position of a widget, relative to the window in which the widget is contained.
#define LOADER_UNLOAD()
Unload a program from memory.
void cfs_closedir(struct cfs_dir *dir)
Close a directory opened with cfs_opendir().
void ctk_window_clear(struct ctk_window *w)
Remove all widgets from a window.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
process_event_t ctk_signal_widget_activate
Emitted when a widget is activated (pressed).
int cfs_opendir(struct cfs_dir *dir, const char *name)
Open a directory for reading directory entries.
CTK screen drawing module interface, ctk-draw.
#define CTK_BUTTON(x, y, w, text)
Instantiating macro for the ctk_button widget.
Representation of a CTK window.
#define CTK_WIDGET_SET_YPOS(w, ypos)
Sets the y position of a widget, relative to the window in which the widget is contained.
#define CTK_WIDGET_REDRAW(widg)
Add a widget to the redraw queue.
#define LOADER_UNLOAD_DSC(dsc)
Unload a DSC (program description).
void program_handler_load(char *name, char *arg)
Loads a program and displays a dialog telling the user about it.
void process_exit(struct process *p)
Cause a process to exit.