summaryrefslogtreecommitdiff
path: root/sfx2/source/dialog
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-07-29 00:31:08 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-07-29 00:31:08 +0200
commit57962429d8bb46b11a7b91d8a8f7363a32e40961 (patch)
tree81d3062ad6f3d39594171f0807f669745601c0f3 /sfx2/source/dialog
parentf96d1a7597f5e3ae229a3a9ac431195fce466d6a (diff)
fix for fdo37628: change password button is always disabled
Note: changing the password to modify doc is not working, and we'll leave that as a known bug for now.
Diffstat (limited to 'sfx2/source/dialog')
-rw-r--r--sfx2/source/dialog/dinfdlg.cxx30
-rw-r--r--sfx2/source/dialog/filedlghelper.cxx133
2 files changed, 84 insertions, 79 deletions
diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx
index 106633b0a9d5..a69a84490df4 100644
--- a/sfx2/source/dialog/dinfdlg.cxx
+++ b/sfx2/source/dialog/dinfdlg.cxx
@@ -69,6 +69,7 @@
#include <sfx2/viewfrm.hxx>
#include <sfx2/request.hxx>
#include <sfx2/passwd.hxx>
+#include <sfx2/filedlghelper.hxx>
#include "helper.hxx"
#include <sfx2/objsh.hxx>
#include <sfx2/docfile.hxx>
@@ -924,15 +925,12 @@ IMPL_LINK( SfxDocumentPage, ChangePassHdl, PushButton*, EMPTYARG )
SfxItemSet* pMedSet = pShell->GetMedium()->GetItemSet();
if (!pMedSet)
break;
+ const SfxFilter* pFilter = pShell->GetMedium()->GetFilter();
+ if (!pFilter)
+ break;
- ::std::auto_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(this));
- pDlg->SetMinLen(1);
- pDlg->ShowExtras(SHOWEXTRAS_CONFIRM);
- if (pDlg->Execute() != RET_OK)
- break;
-
- String aNewPass = pDlg->GetPassword();
- pMedSet->Put( SfxStringItem(SID_PASSWORD, aNewPass) );
+ rtl::OUString aDocName;
+ sfx2::RequestPassword(pFilter, aDocName, pMedSet);
pShell->SetModified(true);
}
while (false);
@@ -986,15 +984,15 @@ void SfxDocumentPage::ImplCheckPasswordState()
if (!pMedSet)
break;
- const SfxPoolItem* pItem;
- if (!pMedSet->GetItemState(SID_PASSWORD, true, &pItem))
- break;
-
- const SfxStringItem* pStrItem = dynamic_cast<const SfxStringItem*>(pItem);
- if (!pStrItem)
- break;
+ SFX_ITEMSET_ARG( pMedSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, sal_False);
+ uno::Sequence< beans::NamedValue > aEncryptionData;
+ if (pEncryptionDataItem)
+ pEncryptionDataItem->GetValue() >>= aEncryptionData;
+ else
+ break;
- String aPass = pStrItem->GetValue();
+ if (!aEncryptionData.getLength())
+ break;
aChangePassBtn.Enable();
return;
}
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index 24fc8396ab6f..35b2f6223c17 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -1557,69 +1557,10 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
if ( ( aValue >>= bPassWord ) && bPassWord )
{
// ask for a password
- uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.uui.UUIInteractionHandler"))), UNO_QUERY );
-
- if( xInteractionHandler.is() )
- {
- // TODO: need a save way to distinguish MS filters from other filters
- // 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;
-
- ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)), ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) );
-
- uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
- xInteractionHandler->handle( rRequest );
- if ( pPasswordRequest->isPassword() )
- {
- if ( pPasswordRequest->getPassword().getLength() )
- {
- // TODO/LATER: The filters should show the password dialog themself in future
- if ( bMSType )
- {
- // all the current MS-filters use MSCodec_Std97 implementation
- uno::Sequence< sal_Int8 > aUniqueID = ::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
- uno::Sequence< sal_Int8 > aEncryptionKey = ::comphelper::DocPasswordHelper::GenerateStd97Key( pPasswordRequest->getPassword(), aUniqueID );
-
- if ( aEncryptionKey.getLength() )
- {
- ::comphelper::SequenceAsHashMap aHashData;
- aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97EncryptionKey" ) ) ] <<= aEncryptionKey;
- aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97UniqueID" ) ) ] <<= aUniqueID;
-
- rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aHashData.getAsConstNamedValueList() ) ) );
- }
- else
- return ERRCODE_IO_NOTSUPPORTED;
- }
- else
- {
- rpSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreatePackageEncryptionData( pPasswordRequest->getPassword() ) ) ) );
- }
- }
-
- if ( pPasswordRequest->getRecommendReadOnly() )
- rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
-
- if ( bMSType )
- {
- // the empty password has 0 as Hash
- sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) );
- if ( nHash )
- rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( nHash ) ) );
- }
- else
- {
- uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = ::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( pPasswordRequest->getPasswordToModify() );
- if ( aModifyPasswordInfo.getLength() )
- rpSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( aModifyPasswordInfo ) ) );
- }
- }
- else
- return ERRCODE_ABORT;
- }
+ rtl::OUString aDocName(*(rpURLList->GetObject(0)));
+ ErrCode errCode = RequestPassword(pCurrentFilter, aDocName, rpSet);
+ if (errCode != ERRCODE_NONE)
+ return errCode;
}
}
catch( const IllegalArgumentException& ){}
@@ -2764,6 +2705,72 @@ ErrCode FileOpenDialog_Impl( sal_Int64 nFlags,
return nRet;
}
+ErrCode RequestPassword(const SfxFilter* pCurrentFilter, rtl::OUString& aURL, SfxItemSet* pSet)
+{
+ uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.uui.UUIInteractionHandler"))), UNO_QUERY );
+ if( xInteractionHandler.is() )
+ {
+ // TODO: need a save way to distinguish MS filters from other filters
+ // 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;
+
+ ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, aURL, ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) );
+
+ uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
+ xInteractionHandler->handle( rRequest );
+ if ( pPasswordRequest->isPassword() )
+ {
+ if ( pPasswordRequest->getPassword().getLength() )
+ {
+ // TODO/LATER: The filters should show the password dialog themself in future
+ if ( bMSType )
+ {
+ // all the current MS-filters use MSCodec_Std97 implementation
+ uno::Sequence< sal_Int8 > aUniqueID = ::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
+ uno::Sequence< sal_Int8 > aEncryptionKey = ::comphelper::DocPasswordHelper::GenerateStd97Key( pPasswordRequest->getPassword(), aUniqueID );
+
+ if ( aEncryptionKey.getLength() )
+ {
+ ::comphelper::SequenceAsHashMap aHashData;
+ aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97EncryptionKey" ) ) ] <<= aEncryptionKey;
+ aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97UniqueID" ) ) ] <<= aUniqueID;
+
+ pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aHashData.getAsConstNamedValueList() ) ) );
+ }
+ else
+ return ERRCODE_IO_NOTSUPPORTED;
+ }
+ else
+ {
+ pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreatePackageEncryptionData( pPasswordRequest->getPassword() ) ) ) );
+ }
+ }
+
+ if ( pPasswordRequest->getRecommendReadOnly() )
+ pSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
+
+ if ( bMSType )
+ {
+ // the empty password has 0 as Hash
+ sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) );
+ if ( nHash )
+ pSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( nHash ) ) );
+ }
+ else
+ {
+ uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = ::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( pPasswordRequest->getPasswordToModify() );
+ if ( aModifyPasswordInfo.getLength() )
+ pSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( aModifyPasswordInfo ) ) );
+ }
+ }
+ else
+ return ERRCODE_ABORT;
+ }
+ return ERRCODE_NONE;
+}
// ------------------------------------------------------------------------
String EncodeSpaces_Impl( const String& rSource )