void moth_gui::handle_find() { std::string info("\"Find:\""); moth_dialog dialog; search_string.clear(); moth_dialog_response resp = dialog.input(info, search_string); if (resp == MOTH_DIALOG_OK) { unsigned int i; char found = 0; rm_newline(search_string); if (search_string.empty()) return; search_results.clear(); for(i = book->get_page(); i < book->get_pages(); i++) { book->search(search_string, i, search_results); if (!search_results.empty()) { found = 1; start_show_search_res(); if (i == 0) i = 1; goto_page(i); break; } } if (!found) { info = "\"Text not found.\""; dialog.info(info); stop_show_search_res(); } } }
void moth_gui::book_select(std::string &file) { moth_dialog file_dialog; std::string type("\"Ebooks | *.pdf *.mobi\""); moth_dialog_response resp = file_dialog.choose_file(type, file); if(resp != MOTH_DIALOG_OK || file.empty()) throw moth_bad_cancel(); rm_newline(file); }
void moth_gui::handle_save_copy() { std::string file; moth_dialog dialog; moth_dialog_response resp = dialog.save_file(file); if (resp == MOTH_DIALOG_OK) { rm_newline(file); std::string url = "file://" + file; if (book->save_copy(url) != SUCCESS) { std::string err("\"Could not save file\""); dialog.error(err); } } }
void moth_gui::handle_goto_page() { std::string nr; std::string info("\"Go To Page Number:\""); moth_dialog dialog; moth_dialog_response resp = dialog.input(info, nr); if (resp == MOTH_DIALOG_OK) { stop_show_search_res(); rm_newline(nr); if (nr.compare("last") == 0) goto_page(book->get_pages() - 1); else goto_page(atoi(nr.c_str())); } }
void check_config(void) { char buf[BUFSIZ]; char aclfile[MAXPATHLEN]; char *tools_dir=NULL; char *tree_owner=NULL; char *map_file=NULL; char *cmd; char *p; char *q=(char *)""; FILE *fp; int cmdfound; char *uniq_str_arg; struct stat st; struct passwd *pw; char * bufptr; BOOLEAN matched; int i; char * dummy; if (debug) diag("checking config"); if ( !batch ) { tree_base = *arglist++; tree_owner = *arglist++; } /* if */ cmd = *arglist; if (debug) diag("command: %s", cmd ); if ( strcmp ( cmd, "odexm_begin") == 0 ) { start_batch = 1; return; } /* if */ if ( strcmp ( cmd, "odexm_end") == 0 ) { end_batch = 1; return; } /* if */ if ( first ) { first = FALSE; if ((fp = fopen( conf_file, "r")) == NULL) efatal("fopen %s", conf_file); matched = FALSE; while ( fgets( buf, sizeof(buf), fp ) != NULL) { rm_newline ( buf ); bufptr = (char *) buf; uniq_str_arg = strdup ( nxtarg ( &bufptr, " \t" ) ); if ( strcmp ( uniq_str_arg, uniq_str ) != 0 ) continue; /* if */ matched = TRUE; if ( batch ) tree_base = strdup ( nxtarg ( &bufptr, " \t" ) ); else /* Skip over argument */ dummy = nxtarg ( &bufptr, " \t" ); /* if */ tools_dir = strdup ( nxtarg ( &bufptr, " \t" ) ); if ( batch ) tree_owner = strdup ( nxtarg ( &bufptr, " \t" ) ); else /* Skip over argument */ dummy = nxtarg ( &bufptr, " \t" ); /* if */ map_file = strdup ( nxtarg ( &bufptr, " \t" ) ); break; } /* while */ fclose ( fp ); if ( ! matched ) { sprintf (buf, "No match for unique string %s\nin configuration file %s.\n", uniq_str, conf_file ); fatal (buf); } if (debug) diag("map file %s", map_file ); if (lstat(map_file, &st) < 0 || (st.st_mode&S_IFMT) != S_IFREG) { sprintf(buf, "Invalid odexm map file: %s\n", map_file); fatal(buf); } if (debug) diag("map file mode ok"); if ((pw = getpwnam(tree_owner)) == NULL) fatal("Owner of directory not found"); if (pw -> pw_uid == 0) fatal("Cannot run as root"); if (setgid(pw->pw_gid) < 0) efatal("setgid"); if (setuid(pw->pw_uid) < 0) efatal("setuid"); if (chdir(tree_base) < 0) efatal("chdir"); if (debug) diag("setuid/chdir ok"); (void) concat ( exec_path, sizeof (exec_path), tools_dir, ":/bin:/usr/bin:/usr/ucb", NULL ); if ((fp = fopen(map_file, "r")) == NULL) efatal("map file fopen"); i = 0; while ((p = fgets(buf, sizeof(buf), fp)) != NULL) { if ((q = strrchr (p, '\n')) != NULL) *q = '\0'; q = nxtarg(&p, " \t"); strcpy ( map_data [i].cmd, q ); q = nxtarg(&p, " \t"); strcpy ( map_data [i].bin, q ); q = nxtarg(&p, " \t"); strcpy ( map_data [i].acl, q ); i++; } map_entries = i; (void) fclose(fp); } /* if */ if ( tempslot != 0 && !made_temp_dir ) { made_temp_dir = TRUE; concat ( tempdir, sizeof(tempdir), tree_base, "/#odexmXXXXXX", NULL); if ( opentemp(tempdir, tempdir ) < 0) { efatal("opentemp %s failed", tree_base); } } /* if */ cmdfound = FALSE; if ( strcmp ( cmd, "odexm_cp" ) != 0 ) { for ( i = 0; i < map_entries; i++ ) { if (strcmp( map_data [i].cmd, cmd) == 0) { cmdfound = TRUE; (void) strcpy(aclfile, q); strcpy ( cmdbuf, map_data [i].bin ); } /* if */ } /* for */ if (!cmdfound) { sprintf (buf, "No match for command %s in map file %s.\n", cmd, map_file ); fatal("%s", buf); } if (debug) diag("command %s acl %s temp %s", cmdbuf, aclfile, tempdir); /* if */ } /* if */ if ( !batch ) authenticate_client (); /* if */ }