| | 26 | /// This is the error domain that will be used to report Document's errors. |
| | 27 | GQuark Document::errorQuark = 0; |
| | 28 | |
| | 29 | /// |
| | 30 | /// @brief Gets the Document's error quark. |
| | 31 | /// |
| | 32 | /// The first time it's called will create the new quark value for the |
| | 33 | /// document class. Successive calls will just return the previously created |
| | 34 | /// quark value. |
| | 35 | /// |
| | 36 | /// @return The Document's quark. |
| | 37 | /// |
| | 38 | GQuark |
| | 39 | Document::getErrorQuark () |
| | 40 | { |
| | 41 | if ( 0 == Document::errorQuark ) |
| | 42 | Document::errorQuark = g_quark_from_static_string ("epdfview-document"); |
| | 43 | |
| | 44 | return Document::errorQuark; |
| | 45 | } |
| | 46 | |
| | 47 | /// |
| | 48 | /// @brief Gives the error's description. |
| | 49 | /// |
| | 50 | /// This function looks the error at @a errorCode and gives an human |
| | 51 | /// readable error string. |
| | 52 | /// |
| | 53 | /// The error message must be freed using g_free(). |
| | 54 | /// |
| | 55 | /// @param errorCode The error code to get the string from. |
| | 56 | /// |
| | 57 | /// @return An human readable error message. |
| | 58 | /// |
| | 59 | gchar * |
| | 60 | Document::getErrorMessage (DocumentError errorCode) |
| | 61 | { |
| | 62 | gchar *errorMessage = NULL; |
| | 63 | switch (errorCode) |
| | 64 | { |
| | 65 | case DocumentErrorNone: |
| | 66 | errorMessage = g_strdup (_("No error")); |
| | 67 | break; |
| | 68 | case DocumentErrorOpenFile: |
| | 69 | errorMessage = g_strdup (_("File not found.")); |
| | 70 | break; |
| | 71 | case DocumentErrorBadCatalog: |
| | 72 | errorMessage = g_strdup (_("Couldn't read the page catalog.")); |
| | 73 | break; |
| | 74 | case DocumentErrorDamaged: |
| | 75 | errorMessage = g_strdup (_("The PDF file is damaged and can't be repaired.")); |
| | 76 | break; |
| | 77 | case DocumentErrorEncrypted: |
| | 78 | errorMessage = g_strdup (_("The file is encrypted and the password was incorrect or not supplied.")); |
| | 79 | break; |
| | 80 | case DocumentErrorHighlightFile: |
| | 81 | errorMessage = g_strdup (_("Nonexistent or invlid highlight file.")); |
| | 82 | break; |
| | 83 | case DocumentErrorBadPrinter: |
| | 84 | errorMessage = g_strdup (_("Invalid printer.")); |
| | 85 | break; |
| | 86 | case DocumentErrorPrinting: |
| | 87 | errorMessage = g_strdup (_("Error during printing.")); |
| | 88 | break; |
| | 89 | case DocumentErrorPermission: |
| | 90 | errorMessage = g_strdup (_("The PDF file doesn't allow that operation.")); |
| | 91 | break; |
| | 92 | case DocumentErrorBadPageNumber: |
| | 93 | errorMessage = g_strdup (_("Invalid page number.")); |
| | 94 | break; |
| | 95 | case DocumentErrorFileIO: |
| | 96 | errorMessage = g_strdup (_("File I/O error.")); |
| | 97 | break; |
| | 98 | default: |
| | 99 | errorMessage = g_strdup_printf (_("Unknown error (%d)"), errorCode); |
| | 100 | } |
| | 101 | |
| | 102 | g_assert (NULL != errorMessage && "The error message is NULL"); |
| | 103 | return errorMessage; |
| | 104 | } |
| | 105 | |
| 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 | | } |
| | 169 | gchar *errorMessage = Document::getErrorMessage (errorCode); |
| | 170 | g_set_error (error, |
| | 171 | EPDFVIEW_DOCUMENT_ERROR, errorCode, |
| | 172 | _("Failed to load document '%s'.\n%s\n"), |
| | 173 | filename, errorMessage); |
| | 174 | g_free (errorMessage); |