Esempio n. 1
0
/*
** Conversion thread.  This is launched as a separate thread to do the
** conversions while the dialog box displays the progress.
*/
static void k2gui_cbox_start_conversion(void *data)

    {
    void **ptrs;
    int i;
    K2PDFOPT_CONVERSION *k2conv;
    K2PDFOPT_SETTINGS *k2settings;
    K2PDFOPT_FILELIST_PROCESS k2listproc;
    static char *funcname="k2gui_cbox_start_conversion";

    ptrs=(void **)data;
    k2conv=(K2PDFOPT_CONVERSION *)ptrs[0];
    k2settings=&k2conv->k2settings;
    /*
    ** Count files
    */
    k2gui_cbox_set_num_files(1);
    k2gui_cbox_set_files_completed(0,"Counting files...");
    overwrite_set(1);
    for (i=k2listproc.filecount=0;i<k2conv->k2files.n;i++)
        {
        k2listproc.bmp=NULL;
        k2listproc.outname=NULL;
        k2listproc.mode=K2PDFOPT_FILELIST_PROCESS_MODE_GET_FILECOUNT;
        k2pdfopt_proc_wildarg(k2settings,k2conv->k2files.file[i],&k2listproc);
        willus_mem_free((double **)&k2listproc.outname,funcname);
        }
    if (k2listproc.filecount==0)
        {
        k2gui_cbox_set_files_completed(0,"No files");
        k2gui_alertbox(0,"No files","No files can be opened for conversion.");
        k2gui_cbox_conversion_thread_cleanup();
        return;
        }
    k2gui_cbox_set_num_files(k2listproc.filecount);
    k2gui_cbox_set_files_completed(0,NULL);
    /*
    ** Process files
    */
    k2gui_cbox_set_error_count(0);
    k2gui_cbox_freelist();
    overwrite_set(0);
    for (i=k2listproc.filecount=0;i<k2conv->k2files.n;i++)
        {
        char *buf;
        K2PDFOPT_CONVERSION *k2c;
        STRBUF *cmdline,_cmdline;

        willus_mem_alloc_warn((void **)&buf,1024,funcname,10);
        k2gui_cbox_set_num_pages(1);
        sprintf(buf,"Starting conversion of %s...",k2gui_short_name(k2conv->k2files.file[i]));
        k2gui_cbox_set_pages_completed(0,buf);
        willus_mem_alloc_warn((void **)&k2c,sizeof(K2PDFOPT_CONVERSION),funcname,10);
        k2pdfopt_conversion_init(k2c);
        cmdline=&_cmdline;
        strbuf_init(cmdline);
        k2gui_settings_to_cmdline(cmdline,&k2conv->k2settings);
        parse_cmd_args(k2c,k2gui->env,cmdline,&k2gui->cmdxtra,1,1);
        k2listproc.outname=NULL;
        k2listproc.bmp=NULL;
        k2listproc.mode=K2PDFOPT_FILELIST_PROCESS_MODE_CONVERT_FILES;
        k2pdfopt_proc_wildarg(&k2c->k2settings,k2conv->k2files.file[i],&k2listproc);
#if (WILLUSDEBUGX & 0x2000)
printf("\n\nDone conversion...\n\n");
#endif
        str0_addstring(&k2gui_cbox->filelist,&k2gui_cbox->filelist_na,k2listproc.outname);
        willus_mem_free((double **)&k2listproc.outname,funcname);
        k2pdfopt_conversion_close(k2c);
        willus_mem_free((double **)&k2c,funcname);
        willus_mem_free((double **)&buf,funcname);
        }
    k2gui_cbox_set_files_completed(k2listproc.filecount,NULL);
    if (k2listproc.filecount==k2conv->k2files.n && k2gui_cbox->error_count==0)
        k2gui_cbox->successful=1;
    k2gui_cbox_conversion_thread_cleanup();
    }
static int overwrite_fail(char *outname,double overwrite_minsize_mb)

    {
    double size_mb;
    char basepath[512];
    char buf[512];
    char newname[512];

    if (wfile_status(outname)==0)
        return(0);
    if (overwrite_minsize_mb < 0.)
        return(0);
    if (k2files_overwrite==1)
        return(0);
    size_mb = wfile_size(outname)/1024./1024.;
    if (size_mb < overwrite_minsize_mb)
        return(0);
    if (k2files_overwrite==-1)
        return(1);
    wfile_basepath(basepath,outname);
    strcpy(newname,outname);
    k2printf("\n\a");
    while (1)
        {
        while (1)
            {
#ifdef HAVE_K2GUI
            if (k2gui_active())
                {
                int reply;
                reply=k2gui_yes_no_all("File overwrite query","File %s (%.1f MB) already exists!  "
                                       "Overwrite it?",newname,size_mb);
                if (reply==2)
                    {
                    overwrite_set(-1);
                    return(1);
                    }
                if (reply==3)
                    overwrite_set(1);
                return(0);
                }
            else
                {
#endif
            k2printf("File " TTEXT_MAGENTA "%s" TTEXT_NORMAL " (%.1f MB) already exists!\n"
                      "   Overwrite it (y[es]/n[o]/a[ll]/q[uit])? " TTEXT_INPUT,
                    newname,size_mb);
            k2gets(buf,16,"y");
            k2printf(TTEXT_NORMAL);
            clean_line(buf);
            buf[0]=tolower(buf[0]);
#ifdef HAVE_K2GUI
                }
#endif
            if (buf[0]!='y' && buf[0]!='n' && buf[0]!='a' && buf[0]!='q')
                {
                k2printf("\a\n  ** Must respond with 'y', 'n', 'a', or 'q' **\n\n");
                continue;
                }
            break;
            }
        if (buf[0]=='q')
            return(-1);
        if (buf[0]=='a' || buf[0]=='y')
            {
            if (buf[0]=='a')
                overwrite_set(1);
            return(0);
            }

        k2printf("Enter a new output base name (.pdf will be appended, q=quit).\n"
                "New name: " TTEXT_INPUT);
        k2gets(buf,255,"__out__.pdf");
        k2printf(TTEXT_NORMAL);
        clean_line(buf);
        if (!stricmp(buf,"q"))
            return(-1);
        if (buf[0]=='/' || buf[0]=='\\' || buf[1]==':')
            strcpy(newname,buf);
        else
            wfile_fullname(newname,basepath,buf);
        if (!strcmp(wfile_ext(newname),""))
            strcat(newname,".pdf");
        if (wfile_status(newname)==0)
            break;
        }
    strcpy(outname,newname);
    return(0);
    }
Esempio n. 3
0
/*
** Conversion thread.  This is launched as a separate thread to do the
** conversions while the dialog box displays the progress.
*/
static void k2gui_overlay_start_conversion(void *data)

    {
    void **ptrs;
    /* static char *funcname="k2gui_overlay_start_conversion"; */
    char *filename;
    char *pagelist;
    char buf[256];
    WILLUSBITMAP *bmp;

#if (WILLUSDEBUGX & 0x2000000)
k2dprintf("@k2gui_overlay_start_conversion thread.\n");
#endif
    ptrs=(void **)data;
    filename=(char *)ptrs[0];
    pagelist=(char *)ptrs[1];
    overwrite_set(1);
    k2gui_overlay_set_error_count(0);
    /* k2gui_overlay_freelist(); */
    overwrite_set(0);
    k2gui_overlay_set_num_pages(1);
    strncpy(k2gui_overlay->filename,k2gui_short_name(filename),255);
    k2gui_overlay->filename[255]='\0';
    sprintf(buf,"Creating overlay for %s...",k2gui_overlay->filename);
    k2gui_overlay_set_pages_completed(0,buf);
    bmp=&k2gui_overlay->bmp;
#if (WILLUSDEBUGX & 0x2000000)
k2dprintf("Getting overlay bitmap...\n");
#endif
    k2file_get_overlay_bitmap(bmp,&k2gui_overlay->dpi,filename,pagelist);
#if (WILLUSDEBUGX & 0x2000000)
k2dprintf("   Done overlay bitmap (ecount=%d)...\n",k2gui_overlay->error_count);
#endif
/*
printf(" = %d x %d\n",bmp->width,bmp->height);
*/
    /* If successful, size the window to the proportions of the loaded bitmap */
    if (k2gui_overlay->error_count==0 && bmp->width>0 && bmp->height>0)
        {
        WILLUSGUIRECT rect,r1,ru;
        int dw,dh,w,h,bh,bw,delw,delh,delw2,delh2;

        k2gui_overlay->converting=2;
        k2gui_overlay->successful=1;
        willusgui_window_get_rect(&k2gui_overlay->mainwin,&r1);
        willusgui_window_get_useable_rect(&k2gui_overlay->mainwin,&ru);
        delw=(r1.right-r1.left)-(ru.right-ru.left);
        delw2=delw + 10;
        delh=(r1.bottom-r1.top)-(ru.bottom-ru.top);
        delh2=delh + (int)k2gui_overlay->bf.size*2.0 + (int)k2gui_overlay->mf.size/4;
/*
printf("delw=%d, delw2=%d, delh=%d, delh2=%d\n",delw,delw2,delh,delh2);
*/
        willusgui_window_get_rect(NULL,&rect);
        dw=rect.right-rect.left+1;
        dh=rect.bottom-rect.top+1;
        h = dh*3/4;
        bh = h - delh2;
        bw = bh*bmp->width/bmp->height;
        w = bw+delw2;
        if (w > dw*3/4)
            {
            bw =  dw*3/4-delw2;
            bh =  bw*bmp->height/bmp->width;
            }
/*
printf("bw=%d, bh=%d\n",bw,bh);
*/
        w = bw+delw2;
        h = bh+delh2;
/*
printf("w=%d, h=%d\n",w,h);
*/
        rect.left=dw/2-w/2;
        rect.right=rect.left+w-1;
        rect.top=dh/2-h/2;
        rect.bottom=rect.top+h-1;
        willusgui_window_set_pos(&k2gui_overlay->mainwin,&rect);
        k2gui_overlay_update_window();
        }
    else
        bmp->width=-1;
#if (WILLUSDEBUGX & 0x2000000)
k2dprintf("   Done overlay_start_conversion..\n",k2gui_overlay->error_count);
#endif
    k2gui_overlay_conversion_thread_cleanup();
    }