| | 51 | } |
| | 52 | |
| | 53 | /// |
| | 54 | /// @brief Load a PDF file. |
| | 55 | /// |
| | 56 | /// Tries to open the PDF file @a filename. |
| | 57 | /// |
| | 58 | /// @param filename The name of the filename to open. |
| | 59 | /// @param error Locatrion to store the error ocurringm or NULL to ignore |
| | 60 | /// errors. |
| | 61 | /// |
| | 62 | /// @return True if the file could be opened, false otherwise. |
| | 63 | /// |
| | 64 | bool |
| | 65 | Document::loadFile (const gchar *filename, GError **error) |
| | 66 | { |
| | 67 | assert (NULL != filename && "Tried to load a NULL filename"); |
| | 68 | |
| | 69 | // The poppler library has a GLOBAL file for parameters. |
| | 70 | // If this file isn't loaded then weird error happens. |
| | 71 | if ( NULL == globalParams ) |
| | 72 | { |
| | 73 | globalParams = new GlobalParams ("/etc/xpdfrc"); |
| | 74 | } |
| | 75 | |
| | 76 | GooString *filename_g = new GooString (filename); |
| | 77 | GooString *password_g = NULL; |
| | 78 | // Try to open the PDF document. |
| | 79 | PDFDoc *newDocument = new PDFDoc (filename_g, password_g, password_g); |
| | 80 | delete password_g; |
| | 81 | // The filename_g can't be deleted as PDFDoc saves the reference. |
| | 82 | // deleting it will cause trouble when deleting the newDocument. |
| | 83 | |
| | 84 | // Check if the document couldn't be opened sucessfully and why. |
| | 85 | if ( !newDocument->isOk() ) |
| | 86 | { |
| | 87 | gint errorCode = newDocument->getErrorCode (); |
| | 88 | delete newDocument; |
| | 89 | |
| | 90 | if ( errEncrypted == errorCode ) |
| | 91 | { |
| | 92 | g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, |
| | 93 | _("Document is encrypted.")); |
| | 94 | } |
| | 95 | else |
| | 96 | { |
| | 97 | g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, |
| | 98 | _("Failed to load document '%s'. Error %d"), |
| | 99 | filename, errorCode); |
| | 100 | } |
| | 101 | |
| | 102 | return false; |
| | 103 | } |
| | 104 | |
| | 105 | delete this->m_Document; |
| | 106 | this->m_Document = newDocument; |
| | 107 | |
| | 108 | return true; |