static Ret ftk_file_browser_on_create_folder(void* ctx, void* obj) { int ret = 0; const char* name = NULL; FtkWidget* win = (FtkWidget*)ctx; FtkWidget* dialog = NULL; PrivInfo* priv = (PrivInfo*)ftk_widget_user_data(win); dialog = ftk_file_browser_input_dialog(win, _("Please input folder name:")); ret = ftk_dialog_run(dialog); if(ret == ID_OK) { name = ftk_entry_get_text(ftk_widget_lookup(dialog, ID_ENTRY)); if(name != NULL) { char folder_name[FTK_MAX_PATH+1] = {0}; ftk_strs_cat(folder_name, FTK_MAX_PATH, priv->path, "/", name, NULL); if(ftk_fs_create_dir(folder_name) == RET_OK) { ftk_file_browser_load(win); } else { ftk_tips(_("Create folder failed.")); } ftk_logd("%s: create %s\n", __func__, folder_name); } } ftk_widget_unref(dialog); ftk_logd("%s: ret=%d\n", __func__, ret); return RET_OK; }
static int FW_update(const char *file) { int ret; FtkWidget* wait_box = NULL; char buf[64] = { 0, }; char cmd[100] = {0,}; printf("file: %s\n", file); /* snprintf(buf, sizeof(buf), "opkg --noaction install %s", file); printf("buf: %s\n", buf); ret = system(buf); if (ret) { return -1; } */ wait_box = ftk_widget_lookup(app_wins[APP_WIN_0],WAIT_BOX_ID); ftk_widget_show(wait_box, 1); ftk_wait_box_start_waiting(wait_box); if (access("/opt/PBAPPS/ipks/pb62_1.ipk", F_OK) == 0) { printf("pb62 is exist\n"); sprintf(cmd, "%s", "rm /opt/PBAPPS/ipks/pb62_1.ipk"); //ftk_wait_box_start_waiting(wait_box); ret = system(cmd); if (ret) { return -1; } } /* snprintf(buf, sizeof(buf), "cp %s /opt/PBAPPS/ipks/", file); printf("buf: %s\n", buf); ret = system(buf); if (ret) { return -1; } */ memset(cmd,0,sizeof(cmd)); sprintf(cmd,"%s %s %s","cp",file,"/opt/PBAPPS/ipks/pb62_1.ipk"); printf("cmd is %s\n",cmd); ret = system(cmd); if (ret) { return -1; } ftk_tips("updating,please wait for some minutes"); memset(buf,0,sizeof(buf)); snprintf(buf, sizeof(buf), "opkg install /opt/PBAPPS/ipks/pb62_1.ipk"); printf("buf: %s\n", buf); ret = system(buf); if (ret) { return -1; } ftk_wait_box_stop_waiting(wait_box); //ftk_widget_remove_child(app_wins[APP_WIN_0], wait_box); ftk_widget_show(wait_box, 0); //ftk_widget_destroy(wait_box); //return 0; //system("echo ./ipks/pb62_1.ipk > /etc/.need_update"); return system("echo ./ipks/pb62_1.ipk > /etc/.need_update"); }
static int lua_ftk_tips(lua_State* L) { tolua_Error err = {0}; int retv; const char* text; int param_ok = tolua_isstring(L, 1, 0, &err); return_val_if_fail(param_ok, 0); text = tolua_tostring(L, 1, 0); retv = ftk_tips(text); tolua_pushnumber(L, (lua_Number)retv); return 1; }
static Ret ftk_file_browser_on_rename(void* ctx, void* obj) { int i = 0; int ret = 0; const char* name = NULL; FtkWidget* win = (FtkWidget*)ctx; FtkWidget* dialog = NULL; FtkListItemInfo* info = NULL; PrivInfo* priv = (PrivInfo*)ftk_widget_user_data(win); i = ftk_list_view_get_selected(priv->list_view); ftk_list_model_get_data(priv->model, i, (void**)&info); return_val_if_fail(info != NULL, RET_FAIL); if(strcmp(info->text, _("..")) == 0) { return RET_FAIL; } dialog = ftk_file_browser_input_dialog(win, _("Please input new name:")); ret = ftk_dialog_run(dialog); if(ret == ID_OK) { name = ftk_entry_get_text(ftk_widget_lookup(dialog, ID_ENTRY)); if(name != NULL) { char new_name[FTK_MAX_PATH+1] = {0}; char old_name[FTK_MAX_PATH+1] = {0}; ftk_strs_cat(old_name, FTK_MAX_PATH, priv->path, "/", info->text, NULL); ftk_strs_cat(new_name, FTK_MAX_PATH, priv->path, "/", name, NULL); if(ftk_fs_move(old_name, new_name) == RET_OK) { ftk_file_browser_load(win); } else { ftk_tips(_("Rename failed.")); } ftk_logd("%s: %s --> %s\n", __func__, old_name, new_name); } } ftk_widget_unref(dialog); ftk_logd("%s: ret=%d\n", __func__, ret); return RET_OK; }
static Ret ftk_file_browser_on_remove(void* ctx, void* obj) { int i = 0; int ret = 0; const char* buttons[3]; FtkWidget* win = (FtkWidget*)ctx; FtkListItemInfo* info = NULL; PrivInfo* priv = (PrivInfo*)ftk_widget_user_data(win); char message[FTK_MAX_PATH + 30] = {0}; buttons[0] = _("Yes"); buttons[1] = _("No"); buttons[2] = NULL; i = ftk_list_view_get_selected(priv->list_view); ftk_list_model_get_data(priv->model, i, (void**)&info); return_val_if_fail(info != NULL, RET_FAIL); if(strcmp(info->text, _("..")) == 0) { return RET_FAIL; } ftk_strs_cat(message, sizeof(message), _("Are you sure to remove:\n "), info->text, NULL); if((ret = ftk_question(_("Remove"), message, buttons)) == 1) { char path[FTK_MAX_PATH+1] = {0}; ftk_strs_cat(path, FTK_MAX_PATH, priv->path, "/", info->text, NULL); if(ftk_fs_delete(path) == RET_OK) { ftk_list_model_remove(priv->model, i); } else { ftk_strs_cat(message, sizeof(message), _("Remove failed:\n"), info->text, NULL); ftk_tips(message); } } return RET_OK; }
static Ret designer_on_help(void* ctx, void* item) { ftk_tips("Ctrl + UP|DOWN|LEFT|RIGHT: move widget.\n Alt + UP|DOWN|LEFT|RIGHT: resize widget\n <F5>: popup menu.\n"); return RET_OK; }