Changeset 27 for trunk/src/MainPter.cxx

Show
Ignore:
Timestamp:
04/11/06 12:15:53 (3 years ago)
Author:
jordi
Message:

The user can now open an encrypted pdf file, as the presenter will ask for the password three time before to show an error, or until the user gives the cancels out.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/MainPter.cxx

    r26 r27  
    153153            // state. 
    154154            setInitialState (); 
    155             g_free (fileName); 
    156155        } 
    157156        else 
    158         { 
     157        {             
    159158            // We got an error, but also can be that the file is encrypted. 
    160159            if ( DocumentErrorEncrypted == error->code ) 
    161160            { 
    162                 // TODO 
     161                // Now we got an encrypted file. 
     162                // Prompt for the password up to three time, until the password 
     163                // is correct or the user cancels the password dialog. 
     164                int passwordTries = 0; 
     165                gchar *password = NULL; 
     166                gboolean loaded = FALSE; 
     167                do  
     168                { 
     169                    g_free (password); 
     170                    password = getView ().promptPasswordDialog (); 
     171                    loaded = m_Document->loadFile (fileName, password, NULL); 
     172                } while ( 3 > ++passwordTries &&  
     173                          NULL != password &&  
     174                          !loaded); 
     175 
     176                // We are go, just check if we could load it or show the 
     177                // error. 
     178                if ( loaded ) 
     179                { 
     180                    // Phew, finally loaded. Set the initial state. 
     181                    setInitialState (); 
     182                } 
     183                else if ( NULL != password ) 
     184                { 
     185                    // We didn't get the correct password, but the user 
     186                    // tried, because the password is not NULL. 
     187                    getView ().showErrorMessage (_("Error Loading File"), 
     188                            _("The password you have supplier is not a" 
     189                              "valid password for this file.")); 
     190                    g_free (password); 
     191                } 
    163192            } 
    164193            else 
     
    171200            g_free (error); 
    172201        } 
     202        g_free (fileName); 
    173203    } 
    174204}