Changeset 258

Show
Ignore:
Timestamp:
10/20/06 08:56:29 (2 years ago)
Author:
jordi
Message:

When the stdin (i.e., '-') is specified as a filename, ePDFView saves the contents of the standard input to a temporary file and tries to load that file instead. This should fix bug #59.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/PDFDocument.cxx

    r257 r258  
    2020#include <time.h> 
    2121#include <poppler.h> 
     22#include <unistd.h> 
    2223#include "epdfview.h" 
    2324 
     
    197198/// 
    198199gboolean 
    199 PDFDocument::loadFile (const gchar *filename, const gchar *password,  
     200PDFDocument::loadFile (const gchar *filename, const gchar *password, 
    200201                    GError **error) 
    201202{ 
     
    211212    // Try to open the PDF document. 
    212213    GError *loadError = NULL; 
     214    // In case the user specified to read the PDF file from the stdin 
     215    // (i.e., -), then we save the contents of the stdin to a temporary 
     216    // file and use the URI to this temporary file to load. 
     217    if ( g_ascii_strcasecmp ("-", filename) == 0 ) 
     218    { 
     219        gchar *tmpFileName; 
     220        gint fd = g_file_open_tmp ("epdfviewXXXXXX", &tmpFileName, error); 
     221        if ( -1 == fd ) 
     222        { 
     223            return FALSE; 
     224        } 
     225        while ( !feof (stdin) ) 
     226        { 
     227            gchar inputLine[512]; 
     228            size_t readBytes = fread (inputLine, sizeof (char), 
     229                                      sizeof (inputLine) / sizeof (char), 
     230                                      stdin); 
     231            write (fd, inputLine, readBytes); 
     232        } 
     233        close (fd); 
     234 
     235        g_free (filename_uri); 
     236        filename_uri = g_filename_to_uri (tmpFileName, NULL, error); 
     237        g_free (tmpFileName); 
     238        if ( NULL == filename_uri ) 
     239        { 
     240            return FALSE; 
     241        } 
     242    } 
    213243    PopplerDocument *newDocument = 
    214244        poppler_document_new_from_file (filename_uri, password, &loadError); 
     
    320350    { 
    321351        struct tm *tmpTime = localtime ((const time_t *)&creationDate); 
    322     if ( NULL != tmpTime ) 
    323     { 
     352        if ( NULL != tmpTime ) 
     353        { 
    324354            gchar *date = g_strnfill (DATE_LENGTH + 1, 0); 
    325355            strftime (date, DATE_LENGTH, "%Y-%m-%d %H:%M:%S", tmpTime); 
    326356            setCreationDate (date); 
    327     } 
     357        } 
    328358    } 
    329359    else 
     
    338368    { 
    339369        struct tm *tmpTime = localtime ((const time_t *)&modDate); 
    340     if ( NULL != tmpTime ) 
    341     { 
    342         gchar *date = g_strnfill (DATE_LENGTH + 1, 0); 
     370        if ( NULL != tmpTime ) 
     371        { 
     372            gchar *date = g_strnfill (DATE_LENGTH + 1, 0); 
    343373            strftime (date, DATE_LENGTH, "%Y-%m-%d %H:%M:%S", tmpTime); 
    344374            setModifiedDate (date); 
    345     } 
     375        } 
    346376    } 
    347377    else