diff options
Diffstat (limited to 'sfx2')
-rwxr-xr-x[-rw-r--r--] | sfx2/inc/brokenpackageint.hxx | 18 | ||||
-rw-r--r-- | sfx2/inc/sfx2/docfile.hxx | 2 | ||||
-rw-r--r-- | sfx2/inc/sfx2/docfilt.hxx | 23 | ||||
-rw-r--r-- | sfx2/inc/sfx2/objsh.hxx | 6 | ||||
-rw-r--r-- | sfx2/inc/sfx2/sfxsids.hrc | 4 | ||||
-rw-r--r-- | sfx2/sdi/sfx.sdi | 57 | ||||
-rwxr-xr-x[-rw-r--r--] | sfx2/source/appl/appuno.cxx | 40 | ||||
-rw-r--r-- | sfx2/source/dialog/filedlghelper.cxx | 66 | ||||
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 55 | ||||
-rw-r--r-- | sfx2/source/doc/docfilt.cxx | 14 | ||||
-rw-r--r-- | sfx2/source/doc/guisaveas.cxx | 81 | ||||
-rw-r--r-- | sfx2/source/doc/objcont.cxx | 30 | ||||
-rwxr-xr-x | sfx2/source/doc/objmisc.cxx | 29 | ||||
-rw-r--r-- | sfx2/source/doc/objstor.cxx | 51 | ||||
-rw-r--r-- | sfx2/source/doc/objxtor.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 14 | ||||
-rw-r--r-- | sfx2/source/inc/objshimp.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 247 |
18 files changed, 519 insertions, 222 deletions
diff --git a/sfx2/inc/brokenpackageint.hxx b/sfx2/inc/brokenpackageint.hxx index e39c92c599ae..16f332480cf6 100644..100755 --- a/sfx2/inc/brokenpackageint.hxx +++ b/sfx2/inc/brokenpackageint.hxx @@ -36,7 +36,9 @@ using namespace ::framework; typedef ContinuationBase< ::com::sun::star::task::XInteractionApprove > SfxContinuationApprove; typedef ContinuationBase< ::com::sun::star::task::XInteractionDisapprove > SfxContinuationDisapprove; -class SFX2_DLLPUBLIC RequestPackageReparation : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest > +class SFX2_DLLPUBLIC RequestPackageReparation : + public ::com::sun::star::task::XInteractionRequest, + public ::cppu::OWeakObject { ::com::sun::star::uno::Any m_aRequest; @@ -50,6 +52,11 @@ class SFX2_DLLPUBLIC RequestPackageReparation : public ::cppu::WeakImplHelper1< public: RequestPackageReparation( ::rtl::OUString aName ); + // XInterface / OWeakObject + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL acquire( ) throw (); + virtual void SAL_CALL release( ) throw (); + sal_Bool isApproved() { return m_pApprove->isSelected(); } virtual ::com::sun::star::uno::Any SAL_CALL getRequest() @@ -61,7 +68,9 @@ public: throw( ::com::sun::star::uno::RuntimeException ); }; -class SFX2_DLLPUBLIC NotifyBrokenPackage : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest > +class SFX2_DLLPUBLIC NotifyBrokenPackage : + public ::com::sun::star::task::XInteractionRequest, + public ::cppu::OWeakObject { ::com::sun::star::uno::Any m_aRequest; @@ -74,6 +83,11 @@ class SFX2_DLLPUBLIC NotifyBrokenPackage : public ::cppu::WeakImplHelper1< ::com public: NotifyBrokenPackage( ::rtl::OUString aName ); + // XInterface / OWeakObject + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL acquire( ) throw (); + virtual void SAL_CALL release( ) throw (); + sal_Bool isAborted() { return m_pAbort->isSelected(); } virtual ::com::sun::star::uno::Any SAL_CALL getRequest() diff --git a/sfx2/inc/sfx2/docfile.hxx b/sfx2/inc/sfx2/docfile.hxx index 074f74cb0e72..e4d3ff023b3b 100644 --- a/sfx2/inc/sfx2/docfile.hxx +++ b/sfx2/inc/sfx2/docfile.hxx @@ -154,6 +154,7 @@ public: const SfxFilter * GetFilter() const { return pFilter; } const SfxFilter * GetOrigFilter( sal_Bool bNotCurrent = sal_False ) const; const String& GetOrigURL() const; + SfxItemSet * GetItemSet() const; void SetItemSet(SfxItemSet *pSet); void Close(); @@ -327,6 +328,7 @@ public: static sal_Bool CallApproveHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler, ::com::sun::star::uno::Any aRequest, sal_Bool bAllowAbort ); static sal_Bool SetWritableForUserOnly( const ::rtl::OUString& aURL ); + static sal_uInt32 CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter ); }; SV_DECL_IMPL_REF( SfxMedium ) diff --git a/sfx2/inc/sfx2/docfilt.hxx b/sfx2/inc/sfx2/docfilt.hxx index b4118272bb88..f024fdb07c06 100644 --- a/sfx2/inc/sfx2/docfilt.hxx +++ b/sfx2/inc/sfx2/docfilt.hxx @@ -37,6 +37,7 @@ #include <com/sun/star/uno/RuntimeException.hpp> #include <tools/wldcrd.hxx> +// TODO/LATER: The flags should be part of the UNO specification #define SFX_FILTER_IMPORT 0x00000001L #define SFX_FILTER_EXPORT 0x00000002L #define SFX_FILTER_TEMPLATE 0x00000004L @@ -45,13 +46,13 @@ #define SFX_FILTER_OWN 0x00000020L #define SFX_FILTER_ALIEN 0x00000040L #define SFX_FILTER_USESOPTIONS 0x00000080L -#define SFX_FILTER_NOTINFILEDLG 0x00001000L -#define SFX_FILTER_NOTINCHOOSER 0x00002000L #define SFX_FILTER_DEFAULT 0x00000100L #define SFX_FILTER_EXECUTABLE 0x00000200L #define SFX_FILTER_SUPPORTSSELECTION 0x00000400L #define SFX_FILTER_MAPTOAPPPLUG 0x00000800L +#define SFX_FILTER_NOTINFILEDLG 0x00001000L +#define SFX_FILTER_NOTINCHOOSER 0x00002000L #define SFX_FILTER_ASYNC 0x00004000L // Legt Objekt nur an, kein Laden #define SFX_FILTER_CREATOR 0x00008000L @@ -64,6 +65,10 @@ #define SFX_FILTER_SILENTEXPORT 0x00200000L #define SFX_FILTER_BROWSERPREFERED 0x00400000L + +#define SFX_FILTER_ENCRYPTION 0x01000000L +#define SFX_FILTER_PASSWORDTOMODIFY 0x02000000L + #define SFX_FILTER_PREFERED 0x10000000L #define SFX_FILTER_VERSION_NONE 0 @@ -72,20 +77,6 @@ #include <sfx2/sfxdefs.hxx> //======================================================================== - -namespace sfx2 { - -/** Returns true if the passed string is the name of a Microsoft Office file - format filter supporting export of password protected documents. - - This function is just a hack for #i105076# is fixed and needs to be removed - then. - */ -SFX2_DLLPUBLIC bool CheckMSPasswordCapabilityForExport( const String& rFilterName ); - -} // namespace sfx2 - -//======================================================================== class SfxFilterContainer; class SotStorage; class SFX2_DLLPUBLIC SfxFilter diff --git a/sfx2/inc/sfx2/objsh.hxx b/sfx2/inc/sfx2/objsh.hxx index d514235cbfa2..d8a8ea2f678a 100644 --- a/sfx2/inc/sfx2/objsh.hxx +++ b/sfx2/inc/sfx2/objsh.hxx @@ -286,6 +286,7 @@ public: sal_Bool HasName() const { return bHasName; } virtual String GetAPIName() const; void SetHasName( sal_Bool bSet = sal_True ) { bHasName = bSet; } + void SetReadOnly(); sal_Bool IsReadOnly() const; sal_Bool IsReadOnlyMedium() const; void SetReadOnlyUI( sal_Bool bReadOnly = sal_True ); @@ -438,6 +439,9 @@ public: void SetSaveVersionOnClose( sal_Bool bSet ); void ResetFromTemplate( const String& rTemplateName, const String& rFileName ); + sal_uInt32 GetModifyPasswordHash() const; + sal_Bool SetModifyPasswordHash( sal_uInt32 nHash ); + static sal_uInt32 HandleFilter( SfxMedium* pMedium, SfxObjectShell* pDoc ); virtual void ViewAssigned(); @@ -713,6 +717,8 @@ public: SAL_DLLPRIVATE sal_uInt16 ImplCheckSignaturesInformation( const ::com::sun::star::uno::Sequence< ::com::sun::star::security::DocumentSignatureInformation >& aInfos ); SAL_DLLPRIVATE void CheckEncryption_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ); + SAL_DLLPRIVATE void SetModifyPasswordEntered(); + SAL_DLLPRIVATE sal_Bool IsModifyPasswordEntered(); SAL_DLLPRIVATE void InitBasicManager_Impl(); SAL_DLLPRIVATE SfxObjectShell_Impl* Get_Impl() { return pImp; } diff --git a/sfx2/inc/sfx2/sfxsids.hrc b/sfx2/inc/sfx2/sfxsids.hrc index bc4c11b53184..5492c76a7e7e 100644 --- a/sfx2/inc/sfx2/sfxsids.hrc +++ b/sfx2/inc/sfx2/sfxsids.hrc @@ -306,7 +306,9 @@ #define SID_ACTIVATE_STYLE_APPLY (SID_SFX_START + 1715) #define SID_FONT_NAME (SID_SFX_START + 1716) #define SID_DEFAULTFILENAME (SID_SFX_START + 1717) -#define SID_SFX_free_START (SID_SFX_START + 1718) +#define SID_MODIFYPASSWORDHASH (SID_SFX_START + 1718) +#define SID_RECOMMENDREADONLY (SID_SFX_START + 1719) +#define SID_SFX_free_START (SID_SFX_START + 1720) #define SID_SFX_free_END (SID_SFX_START + 3999) #define SID_OPEN_NEW_VIEW (SID_SFX_START + 520) diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index 10a920852848..1fc2cc16962d 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -3594,6 +3594,61 @@ SfxVoidItem MacroOrganizer SID_MACROORGANIZER ] //-------------------------------------------------------------------------- +SfxUInt16Item PasswordToModifyHash SID_MODIFYPASSWORDHASH + +[ + /* flags: */ + AutoUpdate = FALSE, + Cachable = Cachable, + FastCall = FALSE, + HasCoreId = FALSE, + HasDialog = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = TRUE, + RecordAbsolute = FALSE, + RecordPerSet; + Synchron; + + Readonly = TRUE, + + /* config: */ + AccelConfig = FALSE, + MenuConfig = FALSE, + StatusBarConfig = FALSE, + ToolBoxConfig = FALSE, + GroupId = ; +] + +//-------------------------------------------------------------------------- +SfxBoolItem ReccomendReadonly SID_RECOMMENDREADONLY + +[ + /* flags: */ + AutoUpdate = FALSE, + Cachable = Cachable, + FastCall = FALSE, + HasCoreId = FALSE, + HasDialog = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = TRUE, + RecordAbsolute = FALSE, + RecordPerSet; + Synchron; + + Readonly = TRUE, + + /* config: */ + AccelConfig = FALSE, + MenuConfig = FALSE, + StatusBarConfig = FALSE, + ToolBoxConfig = FALSE, + GroupId = ; +] + + +//-------------------------------------------------------------------------- SfxVoidItem RunMacro SID_RUNMACRO () [ @@ -5262,7 +5317,7 @@ SfxBoolItem SaveAll SID_SAVEDOCS //-------------------------------------------------------------------------- SfxBoolItem SaveAs SID_SAVEASDOC -(SfxStringItem URL SID_FILE_NAME,SfxStringItem FilterName SID_FILTER_NAME,SfxStringItem Password SID_PASSWORD,SfxStringItem FilterOptions SID_FILE_FILTEROPTIONS,SfxStringItem VersionComment SID_DOCINFO_COMMENTS,SfxStringItem VersionAuthor SID_DOCINFO_AUTHOR,SfxBoolItem Overwrite SID_OVERWRITE,SfxBoolItem Unpacked SID_UNPACK,SfxBoolItem SaveTo SID_SAVETO) +(SfxStringItem URL SID_FILE_NAME,SfxStringItem FilterName SID_FILTER_NAME,SfxStringItem Password SID_PASSWORD,SfxStringItem FilterOptions SID_FILE_FILTEROPTIONS,SfxStringItem VersionComment SID_DOCINFO_COMMENTS,SfxStringItem VersionAuthor SID_DOCINFO_AUTHOR,SfxBoolItem Overwrite SID_OVERWRITE,SfxBoolItem Unpacked SID_UNPACK,SfxBoolItem SaveTo SID_SAVETO,SfxInt32Item ModifyPasswordHash SID_MODIFYPASSWORDHASH) [ /* flags: */ AutoUpdate = FALSE, diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index fd33e21ea645..66452f10bbfb 100644..100755 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -2411,6 +2411,26 @@ RequestPackageReparation::RequestPackageReparation( ::rtl::OUString aName ) m_lContinuations[1] = ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >( m_pDisapprove ); } +/*uno::*/Any SAL_CALL RequestPackageReparation::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException) +{ + return ::cppu::queryInterface ( rType, + // OWeakObject interfaces + dynamic_cast< XInterface* > ( (XInteractionRequest *) this ), + static_cast< XWeak* > ( this ), + // my own interfaces + static_cast< XInteractionRequest* > ( this ) ); +} + +void SAL_CALL RequestPackageReparation::acquire( ) throw () +{ + OWeakObject::acquire(); +} + +void SAL_CALL RequestPackageReparation::release( ) throw () +{ + OWeakObject::release(); +} + ::com::sun::star::uno::Any SAL_CALL RequestPackageReparation::getRequest() throw( ::com::sun::star::uno::RuntimeException ) { @@ -2442,6 +2462,26 @@ NotifyBrokenPackage::NotifyBrokenPackage( ::rtl::OUString aName ) m_lContinuations[0] = ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation >( m_pAbort ); } +/*uno::*/Any SAL_CALL NotifyBrokenPackage::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException) +{ + return ::cppu::queryInterface ( rType, + // OWeakObject interfaces + dynamic_cast< XInterface* > ( (XInteractionRequest *) this ), + static_cast< XWeak* > ( this ), + // my own interfaces + static_cast< XInteractionRequest* > ( this ) ); +} + +void SAL_CALL NotifyBrokenPackage::acquire( ) throw () +{ + OWeakObject::acquire(); +} + +void SAL_CALL NotifyBrokenPackage::release( ) throw () +{ + OWeakObject::release(); +} + ::com::sun::star::uno::Any SAL_CALL NotifyBrokenPackage::getRequest() throw( ::com::sun::star::uno::RuntimeException ) { diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 5270eb5d4207..759c47598f9f 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -464,31 +464,6 @@ sal_Bool FileDialogHelper_Impl::isInOpenMode() const // ------------------------------------------------------------------------ -namespace { - -bool lclCheckODFPasswordCapability( const SfxFilter* pFilter ) -{ - return pFilter && pFilter->IsOwnFormat() && pFilter->UsesStorage() && (pFilter->GetVersion() >= SOFFICE_FILEFORMAT_60); -} - -bool lclCheckMSPasswordCapability( const SfxFilter* pFilter ) -{ - // TODO #i105076# this should be in the filter configuration!!! - return pFilter && CheckMSPasswordCapabilityForExport( pFilter->GetFilterName() ); -} - -bool lclCheckPasswordCapability( const SfxFilter* pFilter ) -{ - return - lclCheckODFPasswordCapability( pFilter ) || - // TODO #i105076# this should be in the filter configuration!!! - lclCheckMSPasswordCapability( pFilter ); -} - -} - -// ------------------------------------------------------------------------ - void FileDialogHelper_Impl::updateFilterOptionsBox() { if ( !m_bHaveFilterOptions ) @@ -546,7 +521,7 @@ void FileDialogHelper_Impl::updateSelectionBox() return; // Does the selection box exist? - bool bSelectionBoxFound = false; + sal_Bool bSelectionBoxFound = sal_False; uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY ); if ( xCtrlInfo.is() ) { @@ -555,7 +530,7 @@ void FileDialogHelper_Impl::updateSelectionBox() for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl ) if ( aCtrlList[ nCtrl ].equalsAscii("SelectionBox") ) { - bSelectionBoxFound = true; + bSelectionBoxFound = sal_False; break; } } @@ -579,9 +554,10 @@ void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit ) sal_Bool bWasEnabled = mbIsPwdEnabled; + const SfxFilter* pCurrentFilter = getCurentSfxFilter(); mbIsPwdEnabled = updateExtendedControl( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, - lclCheckPasswordCapability( getCurentSfxFilter() ) + pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION ) ); if( bInit ) @@ -1550,6 +1526,10 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, { SFX_ITEMSET_ARG( rpSet, pPassItem, SfxStringItem, SID_PASSWORD, FALSE ); mbPwdCheckBoxState = ( pPassItem != NULL ); + + // in case the document has password to modify, the dialog should be shown + SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUInt32Item, SID_MODIFYPASSWORDHASH, FALSE ); + mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue() ); } SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, FALSE ); @@ -1560,6 +1540,9 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, // the password will be set in case user decide so rpSet->ClearItem( SID_PASSWORD ); + rpSet->ClearItem( SID_RECOMMENDREADONLY ); + rpSet->ClearItem( SID_MODIFYPASSWORDHASH ); + } if ( mbHasPassword && !mbPwdCheckBoxState ) @@ -1636,13 +1619,15 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, // set the filter getRealFilter( rFilter ); + const SfxFilter* pCurrentFilter = getCurentSfxFilter(); + // fill the rpURLList - implGetAndCacheFiles(mxFileDlg, rpURLList, getCurentSfxFilter()); + implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter ); if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL ) return ERRCODE_ABORT; // check, wether or not we have to display a password box - if ( mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() ) + if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() ) { try { @@ -1656,18 +1641,29 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, if( xInteractionHandler.is() ) { // TODO: need a save way to distinguish MS filters from other filters - bool bMSType = CheckMSPasswordCapabilityForExport( rFilter ); + // for now MS-filters are the only alien filters that support encryption + sal_Bool bMSType = !pCurrentFilter->IsOwnFormat(); ::comphelper::DocPasswordRequestType eType = bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD; - ::comphelper::DocPasswordRequest* pPasswordRequest = new ::comphelper::DocPasswordRequest( - eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)) ); + ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)), ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) ) ); - uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest ); + uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() ); xInteractionHandler->handle( rRequest ); if ( pPasswordRequest->isPassword() ) - rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + { + if ( pPasswordRequest->getPassword().getLength() ) + rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + + if ( pPasswordRequest->getRecommendReadOnly() ) + rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) ); + + // the empty password has 0 as Hash + sal_uInt16 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) ); + if ( nHash ) + rpSet->Put( SfxInt32Item( SID_MODIFYPASSWORDHASH, (sal_Int32)nHash ) ); + } else return ERRCODE_ABORT; } diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 298da13be147..1dea202e0d0e 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -115,6 +115,7 @@ using namespace ::com::sun::star::io; #include <comphelper/storagehelper.hxx> #include <comphelper/mediadescriptor.hxx> #include <comphelper/configurationhelper.hxx> +#include <comphelper/docpasswordhelper.hxx> #include <tools/urlobj.hxx> #include <tools/inetmime.hxx> #include <unotools/ucblockbytes.hxx> @@ -2558,18 +2559,72 @@ void SfxMedium::SetFilter( const SfxFilter* pFilterP, sal_Bool /*bResetOrig*/ ) pFilter = pFilterP; pImp->nFileVersion = 0; } + //---------------------------------------------------------------- const SfxFilter* SfxMedium::GetOrigFilter( sal_Bool bNotCurrent ) const { return ( pImp->pOrigFilter || bNotCurrent ) ? pImp->pOrigFilter : pFilter; } + //---------------------------------------------------------------- void SfxMedium::SetOrigFilter_Impl( const SfxFilter* pOrigFilter ) { pImp->pOrigFilter = pOrigFilter; } + +//------------------------------------------------------------------ + +sal_uInt32 SfxMedium::CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter ) +{ + sal_uInt32 nHash = 0; + + if ( aPasswd.getLength() ) + { + if ( bWriter ) + { + nHash = ::comphelper::DocPasswordHelper::GetWordHashAsUINT32( aPasswd ); + } + else + { + rtl_TextEncoding nEncoding = RTL_TEXTENCODING_UTF8; + + // if the MS-filter should be used + // use the inconsistent algorithm to find the encoding specified by MS + nEncoding = osl_getThreadTextEncoding(); + switch( nEncoding ) + { + case RTL_TEXTENCODING_ISO_8859_15: + case RTL_TEXTENCODING_MS_874: + case RTL_TEXTENCODING_MS_1250: + case RTL_TEXTENCODING_MS_1251: + case RTL_TEXTENCODING_MS_1252: + case RTL_TEXTENCODING_MS_1253: + case RTL_TEXTENCODING_MS_1254: + case RTL_TEXTENCODING_MS_1255: + case RTL_TEXTENCODING_MS_1256: + case RTL_TEXTENCODING_MS_1257: + case RTL_TEXTENCODING_MS_1258: + case RTL_TEXTENCODING_SHIFT_JIS: + case RTL_TEXTENCODING_GB_2312: + case RTL_TEXTENCODING_BIG5: + // in case the system uses an encoding from the list above, it should be used + break; + + default: + // in case other encoding is used, use one of the encodings from the list + nEncoding = RTL_TEXTENCODING_MS_1250; + break; + } + + nHash = ::comphelper::DocPasswordHelper::GetXLHashAsUINT16( aPasswd, nEncoding ); + } + } + + return nHash; +} + //------------------------------------------------------------------ void SfxMedium::Close() diff --git a/sfx2/source/doc/docfilt.cxx b/sfx2/source/doc/docfilt.cxx index e955c43af705..1219d30d7b27 100644 --- a/sfx2/source/doc/docfilt.cxx +++ b/sfx2/source/doc/docfilt.cxx @@ -49,20 +49,6 @@ using namespace ::com::sun::star; -namespace sfx2 { - -// TODO #i105076# this should be in the filter configuration!!! -bool CheckMSPasswordCapabilityForExport( const String& rFilterName ) -{ - return - rFilterName.EqualsAscii( "MS Word 97" ) || - rFilterName.EqualsAscii( "MS Word 97 Vorlage" ) || - rFilterName.EqualsAscii( "MS Excel 97" ) || - rFilterName.EqualsAscii( "MS Excel 97 Vorlage/Template" ); -} - -} // namespace sfx2 - // STATIC DATA ----------------------------------------------------------- DBG_NAME(SfxFilter) diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index 24f2f359607f..3c4df7276d6b 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -62,6 +62,9 @@ #include <unotools/pathoptions.hxx> #include <unotools/pathoptions.hxx> #include <svl/itemset.hxx> +#include <svl/eitem.hxx> +#include <svl/stritem.hxx> +#include <svl/intitem.hxx> #include <unotools/useroptions.hxx> #include <unotools/saveopt.hxx> #include <tools/debug.hxx> @@ -80,6 +83,7 @@ #include <sfx2/app.hxx> #include <sfx2/objsh.hxx> #include <sfx2/dinfdlg.hxx> +#include <sfx2/request.hxx> #include <sfxtypes.hxx> #include "alienwarn.hxx" @@ -108,6 +112,7 @@ const ::rtl::OUString aFilterFlagsString = ::rtl::OUString::createFromAscii( " using namespace ::com::sun::star; +namespace { //------------------------------------------------------------------------- static sal_uInt16 getSlotIDFromMode( sal_Int8 nStoreMode ) { @@ -168,6 +173,69 @@ static sal_Int32 getDontFlags( sal_Int8 nStoreMode ) } //========================================================================= +// class DocumentSettingsGuard +//========================================================================= + +class DocumentSettingsGuard +{ + uno::Reference< beans::XPropertySet > m_xDocumentSettings; + sal_Bool m_bPreserveReadOnly; + sal_Bool m_bReadOnlySupported; + + sal_Bool m_bRestoreSettings; +public: + DocumentSettingsGuard( const uno::Reference< frame::XModel >& xModel, sal_Bool bReadOnly, sal_Bool bRestore ) + : m_bPreserveReadOnly( sal_False ) + , m_bReadOnlySupported( sal_False ) + , m_bRestoreSettings( bRestore ) + { + try + { + uno::Reference< lang::XMultiServiceFactory > xDocSettingsSupplier( xModel, uno::UNO_QUERY_THROW ); + m_xDocumentSettings.set( + xDocSettingsSupplier->createInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ), + uno::UNO_QUERY_THROW ); + + ::rtl::OUString aLoadReadonlyString( RTL_CONSTASCII_USTRINGPARAM( "LoadReadonly" ) ); + + try + { + m_xDocumentSettings->getPropertyValue( aLoadReadonlyString ) >>= m_bPreserveReadOnly; + m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( bReadOnly ) ); + m_bReadOnlySupported = sal_True; + } + catch( uno::Exception& ) + {} + } + catch( uno::Exception& ) + {} + + if ( ( bReadOnly && !m_bReadOnlySupported ) ) + throw uno::RuntimeException(); // the user could provide the data, so it must be stored + } + + ~DocumentSettingsGuard() + { + if ( m_bRestoreSettings ) + { + ::rtl::OUString aLoadReadonlyString( RTL_CONSTASCII_USTRINGPARAM( "LoadReadonly" ) ); + + try + { + if ( m_bReadOnlySupported ) + m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( m_bPreserveReadOnly ) ); + } + catch( uno::Exception& ) + { + OSL_ASSERT( "Unexpected exception!" ); + } + } + } +}; +} // anonymous namespace + +//========================================================================= // class ModelData_Impl //========================================================================= class ModelData_Impl @@ -184,6 +252,8 @@ class ModelData_Impl ::comphelper::SequenceAsHashMap m_aMediaDescrHM; + sal_Bool m_bRecommendReadOnly; + public: ModelData_Impl( SfxStoringHelper& aOwner, const uno::Reference< frame::XModel >& xModel, @@ -200,6 +270,8 @@ public: ::comphelper::SequenceAsHashMap& GetMediaDescr() { return m_aMediaDescrHM; } + sal_Bool IsRecommendReadOnly() { return m_bRecommendReadOnly; } + const ::comphelper::SequenceAsHashMap& GetDocProps(); ::rtl::OUString GetModuleName(); @@ -252,6 +324,7 @@ ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner, , m_pDocumentPropsHM( NULL ) , m_pModulePropsHM( NULL ) , m_aMediaDescrHM( aMediaDescr ) +, m_bRecommendReadOnly( sal_False ) { CheckInteractionHandler(); } @@ -923,6 +996,12 @@ sal_Bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode, ::rtl::OUString aFilterName = aStringTypeFN; + // the following two arguments can not be converted in MediaDescriptor, + // so they should be removed from the ItemSet after retrieving + SFX_ITEMSET_ARG( pDialogParams, pRecommendReadOnly, SfxBoolItem, SID_RECOMMENDREADONLY, sal_False ); + m_bRecommendReadOnly = ( pRecommendReadOnly && pRecommendReadOnly->GetValue() ); + pDialogParams->ClearItem( SID_RECOMMENDREADONLY ); + uno::Sequence< beans::PropertyValue > aPropsFromDialog; TransformItems( nSlotID, *pDialogParams, aPropsFromDialog, NULL ); GetMediaDescr() << aPropsFromDialog; @@ -1509,6 +1588,8 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& // store the document and handle it's docinfo SvtSaveOptions aOptions; + DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), nStoreMode & EXPORT_REQUESTED ); + if ( aOptions.IsDocInfoSave() && ( !aModelData.GetStorable()->hasLocation() || INetURLObject( aModelData.GetStorable()->getLocation() ) != aURL ) ) diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx index e73594af1e10..dc834debd533 100644 --- a/sfx2/source/doc/objcont.cxx +++ b/sfx2/source/doc/objcont.cxx @@ -1242,3 +1242,33 @@ void SfxObjectShell::SetSaveVersionOnClose( sal_Bool bNew ) pImp->bSaveVersionOnClose = bNew; } +sal_uInt32 SfxObjectShell::GetModifyPasswordHash() const +{ + return pImp->m_nModifyPasswordHash; +} + +sal_Bool SfxObjectShell::SetModifyPasswordHash( sal_uInt32 nHash ) +{ +// Commented out before the solution for Saving process is found +// if ( ( !IsReadOnly() && !IsReadOnlyUI() ) +// || !(pImp->nFlagsInProgress & SFX_LOADED_MAINDOCUMENT ) ) +// { +// // the hash can be changed only in editable documents, +// // or during loading of document + pImp->m_nModifyPasswordHash = nHash; + return sal_True; +// } +// +// return sal_False; +} + +void SfxObjectShell::SetModifyPasswordEntered() +{ + pImp->m_bModifyPasswordEntered = sal_True; +} + +sal_Bool SfxObjectShell::IsModifyPasswordEntered() +{ + return pImp->m_bModifyPasswordEntered; +} + diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 628c3b020c08..76aed9d11ed1 100755 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -470,6 +470,32 @@ void SfxObjectShell::SetReadOnlyUI( sal_Bool bReadOnly ) //------------------------------------------------------------------------- +void SfxObjectShell::SetReadOnly() +{ + // Let the document be completely readonly, means that the + // medium open mode is adjusted accordingly, and the write lock + // on the file is removed. + + if ( pMedium && !IsReadOnlyMedium() ) + { + sal_Bool bWasROUI = IsReadOnly(); + + pMedium->UnlockFile( sal_False ); + + // the storage-based mediums are already based on the temporary file + // so UnlockFile has already closed the locking stream + if ( !pMedium->HasStorage_Impl() && IsLoadingFinished() ) + pMedium->CloseInStream(); + + pMedium->SetOpenMode( SFX_STREAM_READONLY, pMedium->IsDirect(), sal_True ); + pMedium->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); + + if ( !bWasROUI ) + Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); + } +} +//------------------------------------------------------------------------- + sal_Bool SfxObjectShell::IsReadOnly() const { return pImp->bReadOnlyUI || IsReadOnlyMedium(); @@ -1363,6 +1389,9 @@ void SfxObjectShell::FinishedLoading( sal_uInt16 nFlags ) if( !IsAbortingImport() ) PositionView_Impl(); + if ( GetModifyPasswordHash() ) + SetReadOnly(); + // Salvage if ( pSalvageItem ) bSetModifiedTRUE = sal_True; diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 6e1d89f2a8cd..49188defc4f1 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -1332,7 +1332,6 @@ sal_Bool SfxObjectShell::SaveTo_Impl { if ( pFilt->GetServiceName() != rMedium.GetFilter()->GetServiceName() ) { -//REMOVE rMedium.GetStorage()->SetClass( SvFactory::GetServerName( nFormat ), nFormat, pFilt->GetTypeName() ); datatransfer::DataFlavor aDataFlavor; SotExchange::GetFormatDataFlavor( nFormat, aDataFlavor ); @@ -2049,9 +2048,6 @@ sal_Bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed ) } else { -//REMOVE if( pFilter->UsesStorage() ) -//REMOVE pMedium->GetStorage(); -//REMOVE else if( pMedium->GetOpenMode() & STREAM_WRITE ) if( pMedium->GetOpenMode() & STREAM_WRITE ) pMedium->GetInStream(); xStorage = GetStorage(); @@ -2589,9 +2585,6 @@ sal_Bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) SetError(pMediumTmp->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); -//REMOVE if ( !IsHandsOff() ) -//REMOVE pMediumTmp->Close(); - sal_Bool bOpen( sal_False ); bOpen = DoSaveCompleted( pMediumTmp ); DBG_ASSERT(bOpen,"Fehlerbehandlung fuer DoSaveCompleted nicht implementiert"); @@ -2602,13 +2595,7 @@ sal_Bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) SetError( pMediumTmp->GetError(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // reconnect to object storage -//REMOVE if ( IsHandsOff() ) -//REMOVE { -//REMOVE if ( !DoSaveCompleted( pRetrMedium ) ) -//REMOVE DBG_ERROR("Case not handled - no way to get a storage!"); -//REMOVE } -//REMOVE else - DoSaveCompleted( 0 ); + DoSaveCompleted( 0 ); if( pRetrMedium->GetItemSet() ) { @@ -2867,8 +2854,6 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl else pNewFile->SetFilter( GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_IMPORT | SFX_FILTER_EXPORT ) ); -//REMOVE // saving is alway done using a temporary file -//REMOVE pNewFile->CreateTempFileNoCopy(); if ( pNewFile->GetErrorCode() != ERRCODE_NONE ) { // creating temporary file failed ( f.e. floppy disk not inserted! ) @@ -2905,18 +2890,8 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // notify the document that saving was done successfully -//REMOVE if ( bCopyTo ) -//REMOVE { -//REMOVE if ( IsHandsOff() ) -//REMOVE bOk = DoSaveCompleted( pMedium ); -//REMOVE } -//REMOVE else if ( !bCopyTo ) { - // Muss !!! -//REMOVE if ( bToOwnFormat ) -//REMOVE SetFileName( pNewFile->GetPhysicalName() ); - bOk = DoSaveCompleted( pNewFile ); } else @@ -2948,31 +2923,12 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl // by the storage DELETEZ( pNewFile ); } - - // TODO/LATER: there is no need in the following code in case HandsOff is not used, - // hope we will not have to introduce it back -//REMOVE String aPasswd; -//REMOVE if ( IsOwnStorageFormat_Impl( *GetMedium() ) && GetPasswd_Impl( GetMedium()->GetItemSet(), aPasswd ) ) -//REMOVE { -//REMOVE try -//REMOVE { -//REMOVE // the following code must throw an exception in case of failure -//REMOVE ::comphelper::OStorageHelper::SetCommonStoragePassword( GetMedium->GetStorage(), aPasswd ); -//REMOVE } -//REMOVE catch( uno::Exception& ) -//REMOVE { -//REMOVE // TODO: handle the error -//REMOVE } -//REMOVE } } else { SetError( pNewFile->GetErrorCode(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); -//REMOVE // reconnect to the old storage -//REMOVE if ( IsHandsOff() ) -//REMOVE DoSaveCompleted( pMedium ); -//REMOVE else + // reconnect to the old storage DoSaveCompleted( 0 ); DELETEZ( pNewFile ); @@ -3153,9 +3109,6 @@ sal_Bool SfxObjectShell::LoadOwnFormat( SfxMedium& rMedium ) uno::Reference< embed::XStorage > xStorage = rMedium.GetStorage(); if ( xStorage.is() ) { -//REMOVE if ( rMedium.GetFileVersion() ) -//REMOVE xStor->SetVersion( rMedium.GetFileVersion() ); - // Password SFX_ITEMSET_ARG( rMedium.GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False ); if ( pPasswdItem || ERRCODE_IO_ABORT != CheckPasswd_Impl( this, SFX_APP()->GetPool(), pMedium ) ) diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 6502eeaeb78c..45fc31774f5f 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -247,6 +247,8 @@ SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell ) ,m_bCreateTempStor( sal_False ) ,m_bIsInit( sal_False ) ,m_bIncomplEncrWarnShown( sal_False ) + ,m_nModifyPasswordHash( 0 ) + ,m_bModifyPasswordEntered( sal_False ) { SfxObjectShell* pDoc = &_rDocShell; SfxObjectShellArr_Impl &rArr = SFX_APP()->GetObjectShells_Impl(); diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index e1b37c119f1a..d3707636d5ea 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -74,6 +74,7 @@ #include <svl/itemset.hxx> #include <svl/stritem.hxx> #include <svl/eitem.hxx> +#include <svl/intitem.hxx> #include <basic/sbx.hxx> #include <basic/sbuno.hxx> #include <tools/urlobj.hxx> @@ -2731,6 +2732,12 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL uno::Reference< uno::XInterface >() ); } + SFX_ITEMSET_ARG( aParams, pModifyPasswordHashItem, SfxInt32Item, SID_MODIFYPASSWORDHASH, sal_False ); + sal_uInt32 nModifyPasswordHash = pModifyPasswordHashItem ? pModifyPasswordHashItem->GetValue() : 0; + aParams->ClearItem( SID_MODIFYPASSWORDHASH ); + sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash(); + m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash ); + // since saving a document modifies its DocumentInfo, the current // DocumentInfo must be saved on "SaveTo", so it can be restored // after saving @@ -2809,10 +2816,14 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL if ( !bSaveTo ) { m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl(); + m_pData->m_pObjectShell->SetModifyPasswordEntered(); + SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) ); } else { + m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash ); + SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) ); } } @@ -2822,6 +2833,9 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) ); m_pData->m_pObjectShell->StoreLog(); + m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash ); + + SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED), m_pData->m_pObjectShell ) ); diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx index a882cfedd821..e170a7c27240 100644 --- a/sfx2/source/inc/objshimp.hxx +++ b/sfx2/source/inc/objshimp.hxx @@ -149,6 +149,8 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess sal_Bool m_bIncomplEncrWarnShown; + sal_uInt32 m_nModifyPasswordHash; + sal_Bool m_bModifyPasswordEntered; SfxObjectShell_Impl( SfxObjectShell& _rDocShell ); virtual ~SfxObjectShell_Impl(); diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 66af0d7ac8ba..ca95475cabe6 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -82,6 +82,7 @@ #include <comphelper/componentcontext.hxx> #include <comphelper/namedvaluecollection.hxx> #include <comphelper/configurationhelper.hxx> +#include <comphelper/docpasswordrequest.hxx> #include <com/sun/star/uno/Reference.h> #include <com/sun/star/ucb/XContent.hpp> @@ -169,6 +170,44 @@ TYPEINIT1(SfxViewFrameItem, SfxPoolItem); //========================================================================= //------------------------------------------------------------------------- +static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const ::rtl::OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash ) +{ + sal_Bool bResult = !nPasswordHash; + + OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" ); + + if ( pFilter && xHandler.is() ) + { + sal_Bool bCancel = sal_False; + sal_Bool bFirstTime = sal_True; + + while ( !bResult && !bCancel ) + { + sal_Bool bMSType = !pFilter->IsOwnFormat(); + + ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( + new ::comphelper::DocPasswordRequest( + bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD, + bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER, + aPath, + sal_True ) ); + + uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() ); + xHandler->handle( rRequest ); + + if ( pPasswordRequest->isPassword() ) + bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pFilter->GetServiceName() ) ) == nPasswordHash ); + else + bCancel = sal_True; + + bFirstTime = sal_False; + } + } + + return bResult; +} + +//------------------------------------------------------------------------- void SfxViewFrame::SetDowning_Impl() { pImp->bIsDowning = sal_True; @@ -307,10 +346,11 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )) break; + SfxMedium* pMed = pSh->GetMedium(); + SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, sal_False ); if ( pItem && pItem->GetValue() ) { - SfxMedium* pMed = pSh->GetMedium(); SfxApplication* pApp = SFX_APP(); SfxAllItemSet aSet( pApp->GetPool() ); aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) ); @@ -353,6 +393,22 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) } else { + if ( pSh->IsReadOnlyMedium() + && pSh->GetModifyPasswordHash() + && !pSh->IsModifyPasswordEntered() ) + { + ::rtl::OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET ); + if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash() ) ) + { + // this is a read-only document, if it has "Password to modify" + // the user should enter password before he can edit the document + rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) ); + return; + } + + pSh->SetModifyPasswordEntered(); + } + nOpenMode = SFX_STREAM_READWRITE; pSh->SetReadOnlyUI( sal_False ); @@ -372,130 +428,113 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq ) } // doing - if( pSh ) + + String aTemp; + utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp ); + INetURLObject aPhysObj( aTemp ); + SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), + pVersionItem, SfxInt16Item, SID_VERSION, sal_False ); + + INetURLObject aMedObj( pMed->GetName() ); + + // the logic below is following, if the document seems not to need to be reloaded and the physical name is different + // to the logical one, then on file system it can be checked that the copy is still newer than the original and no document reload is required + if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INET_PROT_FILE && + aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) && + !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) )) + || pMed->IsRemote() ) ) + || pVersionItem ) { - SfxMedium* pMed = pSh->GetMedium(); - String aTemp; - utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp ); - INetURLObject aPhysObj( aTemp ); - SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), - pVersionItem, SfxInt16Item, SID_VERSION, sal_False ); - - INetURLObject aMedObj( pMed->GetName() ); - - // the logic below is following, if the document seems not to need to be reloaded and the physical name is different - // to the logical one, then on file system it can be checked that the copy is still newer than the original and no document reload is required - if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INET_PROT_FILE && - aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) && - !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) )) - || pMed->IsRemote() ) ) - || pVersionItem ) + sal_Bool bOK = sal_False; + if ( !pVersionItem ) { - sal_Bool bOK = sal_False; - if ( !pVersionItem ) + sal_Bool bHasStorage = pMed->HasStorage_Impl(); + // switching edit mode could be possible without reload + if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() ) { - sal_Bool bHasStorage = pMed->HasStorage_Impl(); - // switching edit mode could be possible without reload - if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() ) - { - // TODO/LATER: faster creation of copy - if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) ) - return; - } + // TODO/LATER: faster creation of copy + if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) ) + return; + } - pMed->CloseAndRelease(); - pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) ); - pMed->SetOpenMode( nOpenMode, pMed->IsDirect() ); + pMed->CloseAndRelease(); + pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) ); + pMed->SetOpenMode( nOpenMode, pMed->IsDirect() ); - pMed->CompleteReOpen(); - if ( nOpenMode & STREAM_WRITE ) - pMed->LockOrigFileOnDemand( sal_False, sal_True ); + pMed->CompleteReOpen(); + if ( nOpenMode & STREAM_WRITE ) + pMed->LockOrigFileOnDemand( sal_False, sal_True ); - // LockOrigFileOnDemand might set the readonly flag itself, it should be set back - pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) ); + // LockOrigFileOnDemand might set the readonly flag itself, it should be set back + pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) ); - if ( !pMed->GetErrorCode() ) - bOK = sal_True; - } + if ( !pMed->GetErrorCode() ) + bOK = sal_True; + } - if( !bOK ) + if( !bOK ) + { + ErrCode nErr = pMed->GetErrorCode(); + if ( pVersionItem ) + nErr = ERRCODE_IO_ACCESSDENIED; + else { - ErrCode nErr = pMed->GetErrorCode(); - if ( pVersionItem ) - nErr = ERRCODE_IO_ACCESSDENIED; - else - { - pMed->ResetError(); - pMed->SetOpenMode( SFX_STREAM_READONLY, pMed->IsDirect() ); - pMed->ReOpen(); - pSh->DoSaveCompleted( pMed ); - } + pMed->ResetError(); + pMed->SetOpenMode( SFX_STREAM_READONLY, pMed->IsDirect() ); + pMed->ReOpen(); + pSh->DoSaveCompleted( pMed ); + } - // r/o-Doc kann nicht in Editmode geschaltet werden? - rReq.Done( sal_False ); + // r/o-Doc kann nicht in Editmode geschaltet werden? + rReq.Done( sal_False ); - if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() ) + if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() ) + { + // dem ::com::sun::star::sdbcx::User anbieten, als Vorlage zu oeffnen + QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) ); + if ( RET_YES == aBox.Execute() ) { - // dem ::com::sun::star::sdbcx::User anbieten, als Vorlage zu oeffnen - QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) ); - if ( RET_YES == aBox.Execute() ) + SfxApplication* pApp = SFX_APP(); + SfxAllItemSet aSet( pApp->GetPool() ); + aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) ); + SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False ); + if ( pReferer ) + aSet.Put( *pReferer ); + aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); + if ( pVersionItem ) + aSet.Put( *pVersionItem ); + + if( pMed->GetFilter() ) { - SfxApplication* pApp = SFX_APP(); - SfxAllItemSet aSet( pApp->GetPool() ); - aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) ); - SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False ); - if ( pReferer ) - aSet.Put( *pReferer ); - aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); - if ( pVersionItem ) - aSet.Put( *pVersionItem ); - - if( pMed->GetFilter() ) - { - aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) ); - SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, - SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False ); - if ( pOptions ) - aSet.Put( *pOptions ); - } - - GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); - return; + aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) ); + SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, + SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False ); + if ( pOptions ) + aSet.Put( *pOptions ); } - else - nErr = 0; - } - ErrorHandler::HandleError( nErr ); - rReq.SetReturnValue( - SfxBoolItem( rReq.GetSlot(), sal_False ) ); - return; - } - else - { - pSh->DoSaveCompleted( pMed ); - pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); - rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_True ) ); - rReq.Done( sal_True ); - // if( nOpenMode == SFX_STREAM_READONLY ) - // pMed->Close(); - return; + GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet ); + return; + } + else + nErr = 0; } - } - /* - if ( !bReload ) - { - // Es soll nicht reloaded werden - SfxErrorContext aEc( ERRCODE_SFX_NODOCRELOAD ); - ErrorHandler::HandleError( ERRCODE_SFX_NODOCRELOAD ); + ErrorHandler::HandleError( nErr ); rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) ); return; } - */ - // Ansonsten ( lokal und arbeiten auf Kopie ) muss gereloaded - // werden. + else + { + pSh->DoSaveCompleted( pMed ); + pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) ); + rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_True ) ); + rReq.Done( sal_True ); + // if( nOpenMode == SFX_STREAM_READONLY ) + // pMed->Close(); + return; + } } rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, sal_True) ); |