TWindow *new_playlist_menu() { TWindow *ret; ret = ttk_new_window(_("Playlists")); ttk_add_widget(ret, populate_playlists()); ttk_show_window(ret); }
TWindow * mystify_new_window() { TWindow *win; TWidget *wid; win = ttk_new_window(); win->title="Mystify"; wid = ttk_new_widget(0,0); wid->w = ttk_screen->w; wid->h = ttk_screen->h - ttk_screen->wy; wid->draw = mystify_draw; wid->down = mystify_down; wid->button = mystify_button; wid->scroll = mystify_scroll; wid->timer = mystify_timer; wid->focusable = 1; mystify_init(); ttk_widget_set_timer(wid, sleep_time); ttk_add_widget(win, wid); ttk_window_hide_header(win); ttk_show_window(win); }
TWindow *new_stringview_window(char *buf, char *title) { TWindow *ret = ttk_new_window(); ttk_add_widget (ret, ttk_new_textarea_widget (ret->w, ret->h, buf, ttk_textfont, ttk_text_height (ttk_textfont) + 2)); ttk_window_title (ret, title); return ret; }
TWindow * new_podwrite_window_with_text(char * dt) { TWindow * ret; TWidget * wid; /* set podwrite's state */ podwrite_mode = 0; podwrite_linecount = 0; podwrite_screenlines = 0; podwrite_scroll = 0; podwrite_cursor_out_of_bounds = 0; podwrite_filename = 0; /* create the window, widget, and buffer */ podwrite_win = ret = ttk_new_window(_("PodWrite")); podwrite_wid = wid = ti_new_text_widget(0, 0, ret->w, ret->h, 1, dt, podwrite_callback, podwrite_widget_draw, podwrite_widget_input, 0); podwrite_buf = (TiBuffer *)wid->data; wid->scroll = podwrite_widget_scroll; wid->button = podwrite_widget_button; /* move cursor to beginning */ ti_buffer_cset(podwrite_buf, 0); /* set up window */ ttk_add_widget(ret, wid); // ret = pz_finish_window(ret); ttk_show_window(ret); ti_widget_start(wid); /* return */ return ret; }
TWindow *pz_new_textview_window(char *filename) { TWindow *ret; char *buf = NULL; char tmp[4096]; FILE *fp; long len, cs; if ((fp = fopen(filename, "r")) == NULL) { pz_perror(filename); return TTK_MENU_DONOTHING; } fseek(fp, 0L, SEEK_END); len = ftell(fp); rewind(fp); if (len == 0) { cs = 0; while (fgets(tmp, 4096, fp) != NULL) { len = buf ? strlen(buf) : 0; if (len + (long)strlen(tmp) > cs) { cs += 8192; if ((buf = realloc(buf, cs)) == NULL) { pz_error(_("Memory allocation failed")); fclose(fp); return TTK_MENU_DONOTHING; } } strncpy(buf + len, tmp, cs - len); } if (buf == NULL) { pz_message(_("Empty file")); fclose(fp); return TTK_MENU_DONOTHING; } } else { cs = len; if ((buf = malloc(len + 1)) == NULL) { pz_error(_("Memory allocation failed")); fclose(fp); return TTK_MENU_DONOTHING; } while (cs > 0) cs -= fread(buf + (len - cs), 1, cs, fp); *(buf + len) = '\0'; } fclose(fp); ret = ttk_new_window(); ret->data = 0x12345678; ttk_add_widget(ret, ttk_new_textarea_widget(ret->w, ret->h, buf, ttk_textfont, ttk_text_height(ttk_textfont)+2)); ttk_window_title(ret, strrchr(filename, '/')? strrchr(filename, '/') + 1:filename); free(buf); /* strdup'd in textarea */ return ret; }
static TWindow *remove_tracks (ttk_menu_item *item) { TWindow *ret = ttk_new_window(); ret->data = 0x12345678; ttk_window_set_title (ret, _("Really Delete These Tracks?")); remove_tracks_menu[0].flags = 0; remove_tracks_menu[1].flags = TTK_MENU_ICON_EXE; remove_tracks_menu[0].data = remove_tracks_menu[1].data = item->data; ttk_add_widget (ret, ttk_new_menu_widget (remove_tracks_menu, ttk_textfont, item->menuwidth, item->menuheight)); ttk_set_popup (ret); return ret; }
static TWindow *browser_delete (ttk_menu_item *item) { TWindow *ret = ttk_new_window(); ret->data = 0x12345678; ttk_window_set_title (ret, _("Really Delete?")); delete_menu[0].flags = 0; delete_menu[1].flags = TTK_MENU_ICON_EXE; delete_menu[0].data = delete_menu[1].data = item->data; ttk_add_widget (ret, ttk_new_menu_widget (delete_menu, ttk_textfont, item->menuwidth, item->menuheight)); ttk_set_popup (ret); return ret; }
TWindow * podwrite_mh_save(ttk_menu_item * item) { TWindow * ret; TWidget * wid; ret = ttk_new_window(_("Save to...")); wid = ti_new_standard_text_widget(10, 40, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, (podwrite_filename?podwrite_filename:"/mnt/Notes/"), podwrite_save_callback); ttk_add_widget(ret, wid); // ret = pz_finish_window(ret); ttk_show_window(ret); ti_widget_start(wid); return ret; }
static TWindow *browser_execute(ttk_menu_item *item) { TWindow *ret = ttk_new_window(); ret->data = 0x12345678; ttk_window_set_title(ret, _("Execute")); execute_menu[0].data = execute_menu[1].data = execute_menu[2].data = item->data; ttk_add_widget(ret, ttk_new_menu_widget(execute_menu, ttk_menufont, item->menuwidth, item->menuheight)); ttk_set_popup(ret); return ret; }
static TWindow *new_settings_slider_window (char *title, int setting, int slider_min, int slider_max) { int tval = pz_get_int_setting (pz_global_config, setting); TWindow *win = ttk_new_window(); TWidget *slider = ttk_new_slider_widget (0, 0, ttk_screen->w * 3 / 5, slider_min, slider_max, &tval, 0); ttk_slider_set_callback (slider, slider_set_setting, setting); ttk_window_set_title (win, title); ttk_add_widget (win, slider); win->data = 0x12345678; ttk_set_popup (win); return win; }
static int piezomaker_save() { { TWindow *ret; TWidget *wid; ret = ttk_new_window(_("Save to...")); wid = ti_new_standard_text_widget(10, 40, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, "/untitled.pzm", piezomaker_save_callback); ttk_add_widget(ret, wid); ttk_show_window(ret); ti_widget_start(wid); } return 0; }
TWindow * new_mkdir_window(ttk_menu_item * item) { TWindow * ret; TWidget * wid; TWidget * wid2; ret = ttk_new_window(_("Make Directory")); wid = ti_new_standard_text_widget(10, 10+ttk_text_height(ttk_textfont)*2, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, "", tix_mkdir_callback); ttk_add_widget(ret, wid); wid2 = ttk_new_widget(10, 10); wid2->w = ret->w-20; wid2->h = ttk_text_height(ttk_menufont); wid2->draw = tix_mkdir_draw; ttk_add_widget(ret, wid2); ttk_show_window(ret); ti_widget_start(wid); return 0; }
TWindow * new_podwrite_menu_window() { TWindow * w=ttk_new_window(_("PodWrite")); podwrite_menu = ttk_new_menu_widget(0, ttk_menufont, ttk_screen->w, ttk_screen->h-ttk_screen->wy); if (!podwrite_menu) return 0; ttk_menu_append(podwrite_menu, podwrite_new_menu_item(N_("Return to PodWrite"), podwrite_mh_return, 0)); ttk_menu_append(podwrite_menu, podwrite_new_menu_item(N_("Move Cursor"), podwrite_mh_cursor, 0)); ttk_menu_append(podwrite_menu, podwrite_new_menu_item(N_("Scroll"), podwrite_mh_scroll, 0)); ttk_menu_append(podwrite_menu, podwrite_new_menu_item(N_("Clear All Text"), podwrite_mh_clear, 0)); ttk_menu_append(podwrite_menu, podwrite_new_menu_item(N_("Save..."), podwrite_mh_save, 0)); //ttk_menu_append(podwrite_menu, podwrite_new_menu_item(N_("Change Input Method"), podwrite_mh_input, TTK_MENU_ICON_SUB)); ttk_menu_append(podwrite_menu, podwrite_new_menu_item(N_("Quit PodWrite"), podwrite_mh_quit, 0)); ttk_add_widget(w,podwrite_menu); //w = pz_new_menu_window(podwrite_menu); // if (w) w->title = _("PodWrite"); return w; }
TWindow * new_rename_window(ttk_menu_item * item) { TWindow * ret; TWidget * wid; TWidget * wid2; tix_rename_oldname = strdup(item->data); ret = ttk_new_window(_("Rename")); wid = ti_new_standard_text_widget(10, 10+ttk_text_height(ttk_textfont)*2, ret->w-20, 10+ttk_text_height(ttk_textfont), 0, tix_rename_oldname, tix_rename_callback); ttk_add_widget(ret, wid); wid2 = ttk_new_widget(10, 10); wid2->w = ret->w-20; wid2->h = ttk_text_height(ttk_menufont); wid2->draw = tix_rename_draw; ttk_add_widget(ret, wid2); ti_widget_start(wid); ttk_show_window(ret); return 0; }
TWindow *new_textview_window(char *filename) { struct stat st; if (stat (filename, &st) < 0) return 0; char *buf = malloc (st.st_size); if (!buf) return 0; int fd = open (filename, O_RDONLY); if (fd < 0) return 0; read (fd, buf, st.st_size); close (fd); TWindow *ret = ttk_new_window(); ttk_add_widget (ret, ttk_new_textarea_widget (ret->w, ret->h, buf, ttk_textfont, ttk_text_height (ttk_textfont) + 2)); ttk_window_title (ret, strrchr (filename, '/')? strrchr (filename, '/') + 1 : filename); free (buf); // strdup'd in textarea return ret; }
TWindow *new_font_window (ttk_menu_item *item) { TWindow *ret = ttk_new_window(); TWidget *this = ttk_new_menu_widget (0, ttk_menufont, ret->w, ret->h); ttk_fontinfo *cur = ttk_fonts; while (cur) { ttk_menu_item *item = calloc (1, sizeof(ttk_menu_item)); item->name = cur->name; item->makesub = select_font; item->flags = 0; item->data = cur; ttk_menu_append (this, item); cur = cur->next; } ttk_add_widget (ret, this); ttk_window_title (ret, _("Select Font")); return ret; }
TWindow * iconui_new_menu_window(TWidget * menu_wid) { TWindow * ret; int iconsize = 1;//ipod_get_setting((75)); int iconcache = 1;//ipod_get_setting((76)); iconsize=1; iconcache=1; int i = 0; while (1) { ttk_menu_item * mi = ttk_menu_get_item(menu_wid, i); if (!mi) break; if (mi->makesub == ttk_mh_sub) mi->makesub = iconui_mh_sub; if (iconcache) ttk_free_surface(iconui_get_icon((char *)mi->name)); i++; } switch (iconsize) { case 1: /* small list */ menu_wid->draw = iconui_menu_draw; menu_wid->frame = iconui_menu_frame; menu_wid->down = iconui_menu_down; menu_wid->button = iconui_menu_button; menu_wid->scroll = iconui_menu_scroll; menu_wid->destroy = iconui_menu_free; //menu_wid->focusable=1; ((menu_data *)menu_wid->data)->epoch--; break; case 2: /* large list */ menu_wid->draw = bigiconui_menu_draw; menu_wid->frame = bigiconui_menu_frame; menu_wid->down = bigiconui_menu_down; menu_wid->button = bigiconui_menu_button; menu_wid->scroll = bigiconui_menu_scroll; menu_wid->destroy = bigiconui_menu_free; ((menu_data *)menu_wid->data)->epoch--; break; case 3: /* small array */ menu_wid->draw = icon2ui_menu_draw; menu_wid->frame = icon2ui_menu_frame; menu_wid->down = icon2ui_menu_down; menu_wid->button = icon2ui_menu_button; menu_wid->scroll = icon2ui_menu_scroll; menu_wid->destroy = icon2ui_menu_free; ((menu_data *)menu_wid->data)->font = iconui_font; ((menu_data *)menu_wid->data)->epoch--; break; case 4: /* large array */ menu_wid->draw = bigicon2ui_menu_draw; menu_wid->frame = bigicon2ui_menu_frame; menu_wid->down = bigicon2ui_menu_down; menu_wid->button = bigicon2ui_menu_button; menu_wid->scroll = bigicon2ui_menu_scroll; menu_wid->destroy = bigicon2ui_menu_free; ((menu_data *)menu_wid->data)->font = iconui_font; ((menu_data *)menu_wid->data)->epoch--; break; case 5: /* small dock */ menu_wid->draw = smdockiconui_menu_draw; menu_wid->frame = smdockiconui_menu_frame; menu_wid->down = smdockiconui_menu_down; menu_wid->button = smdockiconui_menu_button; menu_wid->scroll = smdockiconui_menu_scroll; menu_wid->destroy = smdockiconui_menu_free; ((menu_data *)menu_wid->data)->font = iconui_font; ((menu_data *)menu_wid->data)->epoch--; break; case 6: /* mag dock */ menu_wid->draw = mdockiconui_menu_draw; menu_wid->frame = mdockiconui_menu_frame; menu_wid->down = mdockiconui_menu_down; menu_wid->button = mdockiconui_menu_button; menu_wid->scroll = mdockiconui_menu_scroll; menu_wid->destroy = mdockiconui_menu_free; ((menu_data *)menu_wid->data)->font = iconui_font; ((menu_data *)menu_wid->data)->epoch--; break; case 7: /* large dock */ menu_wid->draw = dockiconui_menu_draw; menu_wid->frame = dockiconui_menu_frame; menu_wid->down = dockiconui_menu_down; menu_wid->button = dockiconui_menu_button; menu_wid->scroll = dockiconui_menu_scroll; menu_wid->destroy = dockiconui_menu_free; ((menu_data *)menu_wid->data)->font = iconui_font; ((menu_data *)menu_wid->data)->epoch--; break; } ret = ttk_new_window(); ttk_add_widget(ret, menu_wid); ttk_window_title(ret, "ZacZilla"); return ret; }
void pz_modules_init(char *path) { #ifdef IPOD #define MODULEDIR "/opt/Base:/opt/Emulators:/opt/Media:/opt/Tools:/opt/Zillae" #else #define MODULEDIR "modules" #endif /* Used for the progress bar */ TWindow * sliderwin; TWidget * slider; int sliderVal=0; int verbosity = pz_get_int_setting( pz_global_config, VERBOSITY ); #define MAXSLIDERVAL (100) #define SETUPSECTIONS (6) PzModule *last, *cur; int i; int modCount=0; if (module_head) { pz_error (_("modules_init called more than once")); return; } /* set up the screen to show a pretty progress bar */ sliderwin = ttk_new_window(); ttk_window_hide_header(sliderwin); sliderwin->x = sliderwin->y = 0; slider = ttk_new_slider_widget(2, ttk_screen->h/3, ttk_screen->w - 8, 0, MAXSLIDERVAL, &sliderVal, 0); slider->x = (sliderwin->w - slider->w)/2; ttk_add_widget(sliderwin, slider); sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 1; updateprogress(sliderwin, slider, sliderVal, _("Scanning For Modules"), NULL); if (!path) path = MODULEDIR; path = strtok(strdupa(path), ":"); while (path) { find_modules (path); path = strtok(NULL, ":"); } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 2; updateprogress(sliderwin, slider, sliderVal, _("Reading Modules"), NULL); for (i = 0; i < __pz_builtin_number_of_init_functions; i++) { int found = 0; const char *name = __pz_builtin_names[i]; cur = module_head; while (cur) { char *p = strrchr (cur->podpath, '/'); if (!p) p = cur->podpath; else p++; if (!strncmp (p, name, strlen (name)) && !isalpha (p[strlen (name)])) { found = 1; break; } cur = cur->next; } if (!found) { if (module_head) { cur = module_head; while (cur->next) cur = cur->next; cur->next = calloc (1, sizeof(PzModule)); cur = cur->next; } else { cur = module_head = calloc (1, sizeof(PzModule)); } cur->podpath = 0; cur->name = strdup (__pz_builtin_names[i]); cur->init = __pz_builtin_init_functions[i]; cur->to_load = -1; cur->ordered = 0; cur->next = 0; } } if (!module_head) { pz_message_title (_("Warning"), _("No modules. podzilla will probably be very boring.")); return; } /* Used to initialize the window + progressbar used in loading the modules*/ cur = module_head; while (cur) { modCount++; cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 3; updateprogress(sliderwin, slider, sliderVal, _("Mounting Modules"), NULL); // Mount 'em cur = module_head; last = 0; while (cur) { if (cur->podpath && cur->extracted) { cur->mountpt = strdup (cur->podpath); last = cur; cur = cur->next; } else if (cur->podpath && mount_pod (cur) == -1) { if (last) last->next = cur->next; else module_head = cur->next; free (cur->podpath); free (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 4; updateprogress(sliderwin, slider, sliderVal, _("Scanning Module Info"), NULL); // Load the module.inf's cur = module_head; while (cur) { load_modinf (cur); cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 5; updateprogress(sliderwin, slider, sliderVal, _("Module Dependencies"), NULL); // Figure out the dependencies cur = module_head; last = 0; while (cur) { if (fix_dependencies (cur, 1, SOFTDEP) == -1 || fix_dependencies(cur, 1, HARDDEP) == -1) { if (last) last->next = cur->next; else module_head = cur->next; free_module (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } // Check which ones are linked in cur = module_head; last = 0; while (cur) { for (i = 0; i < __pz_builtin_number_of_init_functions; i++) { if (!strcmp (__pz_builtin_names[i], cur->name)) { cur->init = __pz_builtin_init_functions[i]; cur->to_load = -1; cur->ordered = 0; } } cur = cur->next; } // XXX. For now, we use a slow method for deps, and it'll crash // for circular deps. davidc__ is working on a // better solution. cur = module_head; while (cur) { add_deps (cur); cur = cur->next; } sliderVal = (MAXSLIDERVAL/SETUPSECTIONS) * 6; updateprogress(sliderwin, slider, sliderVal, _("Loading Modules"), NULL); struct dep *c = load_order; while (c) { if (c->mod->to_load > 0) { do_load (c->mod); } if( verbosity < VERBOSITY_ERRORS && c->mod->longname ) { updateprogress(sliderwin, slider, sliderVal, _("Loading Modules"), c->mod->longname ); } c = c->next; } c = load_order; sliderVal = 0; updateprogress(sliderwin, slider, sliderVal, _("Initializing Modules"), NULL); /* trigger the sliders to switch to init mode, restting the slider */ sliderVal = 0; /* initialize the modules */ while (c) { sliderVal += MAXSLIDERVAL / modCount; current_module = c->mod; updateprogress(sliderwin, slider, sliderVal, _("Initializing Modules"), (verbosity < 2)? c->mod->longname : NULL ); do_init (c->mod); c = c->next; } sliderVal = MAXSLIDERVAL; updateprogress(sliderwin, slider, sliderVal, _("Finishing Up..."), NULL); // Any modules with unrecoverable errors on loading set mod->to_free. // Oblige them. cur = module_head; last = 0; while (cur) { if (cur->to_free) { if (last) last->next = cur->next; else module_head = cur->next; free_module (cur); cur = last? last->next : module_head; } else { last = cur; cur = cur->next; } } ttk_free_window (sliderwin); }