Changeset 26

Show
Ignore:
Timestamp:
04/11/06 11:40:45 (3 years ago)
Author:
jordi
Message:

When an error loading the document happens, the view shows to the user an error message.

Also, updated POTFILES.in with the correct document sources and the MainPter? sources.

Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IMainView.h

    r24 r26  
    4141            virtual void sensitiveZoomWidth (gboolean sensitive) = 0; 
    4242            virtual void show (void) = 0; 
     43            virtual void showErrorMessage (const gchar *title,  
     44                                           const gchar *body) = 0; 
    4345            virtual void showPage (DocumentPage *page) = 0; 
    4446            virtual void setTitle (const gchar *title) = 0; 
  • trunk/src/MainPter.cxx

    r25 r26  
    147147    if ( NULL != fileName ) 
    148148    { 
    149         GError *error; 
     149        GError *error = NULL; 
    150150        if ( m_Document->loadFile (fileName, NULL, &error) ) 
    151151        { 
     
    154154            setInitialState (); 
    155155            g_free (fileName); 
     156        } 
     157        else 
     158        { 
     159            // We got an error, but also can be that the file is encrypted. 
     160            if ( DocumentErrorEncrypted == error->code ) 
     161            { 
     162                // TODO 
     163            } 
     164            else 
     165            { 
     166                // It was an error. Show the error message. 
     167                getView ().showErrorMessage (_("Error Loading File"),  
     168                                             error->message);                 
     169 
     170            } 
     171            g_free (error); 
    156172        } 
    157173    } 
  • trunk/tests/DumbDocument.cxx

    r24 r26  
    2929{ 
    3030    m_Loaded = FALSE; 
     31    m_OpenError = DocumentErrorNone; 
    3132} 
    3233 
     
    4546                        GError **error) 
    4647{ 
    47     setFileName (filename); 
    48     m_Loaded = TRUE; 
     48    if ( DocumentErrorNone == m_OpenError ) 
     49    { 
     50        setFileName (filename); 
     51        m_Loaded = TRUE; 
     52    } 
     53    else 
     54    { 
     55        g_set_error (error, EPDFVIEW_DOCUMENT_ERROR, m_OpenError,  
     56                     "%s", IDocument::getErrorMessage (m_OpenError)); 
     57    } 
    4958    return m_Loaded; 
    5059} 
     
    6271    return new DocumentPage (); 
    6372} 
     73 
     74//////////////////////////////////////////////////////////////// 
     75// Tests Methods 
     76//////////////////////////////////////////////////////////////// 
     77void 
     78DumbDocument::setOpenError (DocumentError error) 
     79{ 
     80    m_OpenError = error; 
     81} 
  • trunk/tests/DumbDocument.h

    r24 r26  
    3434            DocumentPage *renderPage (void); 
    3535 
     36            // Test functions. 
     37            void setOpenError (DocumentError error); 
     38 
    3639        private: 
    3740            gboolean m_Loaded; 
     41            DocumentError m_OpenError; 
    3842    }; 
    3943} 
  • trunk/tests/DumbMainView.cxx

    r25 r26  
    4040    m_SensitiveZoomWidth = TRUE; 
    4141    m_Shown = FALSE; 
     42    m_ShownError = FALSE; 
    4243    m_Title = g_strdup (""); 
    4344} 
     
    116117 
    117118void 
     119DumbMainView::showErrorMessage (const gchar *title, const gchar *body) 
     120{ 
     121    m_ShownError = TRUE; 
     122} 
     123 
     124void 
    118125DumbMainView::showPage (DocumentPage *page) 
    119126{ 
     
    136143DumbMainView::hasImagePageView () 
    137144{ 
    138     return NULL != m_DocumentPage; 
     145    gboolean shown = (NULL != m_DocumentPage); 
     146    // The next time, it will be FALSE unless it's shown again. 
     147    m_DocumentPage = NULL; 
     148 
     149    return shown; 
    139150} 
    140151 
     
    215226    } 
    216227} 
     228 
     229gboolean 
     230DumbMainView::shownError () 
     231{ 
     232    gboolean shown = m_ShownError; 
     233    // It's like the user clicked the "OK" button. No shown anymore, until 
     234    // the next error. 
     235    m_ShownError = FALSE; 
     236 
     237    return shown; 
     238} 
  • trunk/tests/DumbMainView.h

    r24 r26  
    3939            void sensitiveZoomWidth (gboolean sensitive); 
    4040            void show (void); 
     41            void showErrorMessage (const gchar *title, const gchar *body); 
    4142            void showPage (DocumentPage *page); 
    4243            void setTitle (const gchar *title); 
     
    5657            gboolean isSensitiveZoomWidth (void); 
    5758            void setOpenFileName (const gchar *fileName); 
     59            gboolean shownError (void); 
    5860 
    5961        protected: 
     
    7072            gboolean m_SensitiveZoomWidth; 
    7173            gboolean m_Shown; 
     74            gboolean m_ShownError; 
    7275            gchar *m_Title; 
    7376    }; 
  • trunk/tests/MainPterTest.cxx

    r25 r26  
    141141    CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); 
    142142    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     143    CPPUNIT_ASSERT (!m_View->shownError ()); 
    143144} 
     145 
     146/// 
     147/// @brief Test a failed load. 
     148/// 
     149/// A failed load (anything but a DocumentErrorNone and DocumentErrorEncrypted) 
     150/// is very similar to the load cancelled, but an error message is shown  
     151/// to the user. 
     152/// 
     153void 
     154MainPterTest::loadFailed () 
     155{     
     156    m_View->setOpenFileName ("/tmp/test.pdf"); 
     157    m_Document->setOpenError (DocumentErrorDamaged); 
     158    m_MainPter->openFileActivated (); 
     159    CPPUNIT_ASSERT_EQUAL (0,  
     160            g_ascii_strcasecmp ("PDF Viewer", m_View->getTitle ())); 
     161    CPPUNIT_ASSERT (!m_View->isSensitiveGoToFirstPage ()); 
     162    CPPUNIT_ASSERT (!m_View->isSensitiveGoToLastPage ()); 
     163    CPPUNIT_ASSERT (!m_View->isSensitiveGoToNextPage ()); 
     164    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPage ()); 
     165    CPPUNIT_ASSERT (!m_View->isSensitiveGoToPreviousPage ()); 
     166    CPPUNIT_ASSERT (!m_View->isSensitiveZoomIn ()); 
     167    CPPUNIT_ASSERT (!m_View->isSensitiveZoomOut ()); 
     168    CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); 
     169    CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); 
     170    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
     171    CPPUNIT_ASSERT (m_View->shownError ()); 
     172 
     173} 
  • trunk/tests/MainPterTest.h

    r25 r26  
    2929        CPPUNIT_TEST (loadDocument); 
    3030        CPPUNIT_TEST (loadCancelled); 
     31        CPPUNIT_TEST (loadFailed); 
    3132        CPPUNIT_TEST_SUITE_END(); 
    3233 
     
    3839            void loadDocument (void); 
    3940            void loadCancelled (void); 
     41            void loadFailed (void); 
    4042 
    4143        private: