diff options
author | Bjoern Michaelsen <b_michaelsen@openoffice.org> | 2010-12-08 14:12:49 +0100 |
---|---|---|
committer | Bjoern Michaelsen <b_michaelsen@openoffice.org> | 2010-12-08 14:12:49 +0100 |
commit | 44aec49b2cdaffa72e7ece2b71c25a95ff935601 (patch) | |
tree | c4f388965120292c41798a12ea72a9f51f52b20e /sfx2 | |
parent | ee730ab172f887f537ff3026dd4a5c0e611bf016 (diff) | |
parent | 5e5f32868925e3fc20bad2b7cc1c23b77b524d5e (diff) |
gnumake2: resync to DEV300_m95
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/sfx2/docfile.hxx | 2 | ||||
-rw-r--r-- | sfx2/inc/sfx2/passwd.hxx | 22 | ||||
-rw-r--r-- | sfx2/inc/sfx2/sfxsids.hrc | 4 | ||||
-rw-r--r-- | sfx2/inc/sfx2/sfxuno.hxx | 3 | ||||
-rw-r--r-- | sfx2/sdi/sfx.sdi | 2 | ||||
-rw-r--r-- | sfx2/source/appl/appopen.cxx | 49 | ||||
-rw-r--r-- | sfx2/source/appl/appuno.cxx | 20 | ||||
-rw-r--r-- | sfx2/source/dialog/filedlghelper.cxx | 31 | ||||
-rw-r--r-- | sfx2/source/dialog/passwd.cxx | 179 | ||||
-rw-r--r-- | sfx2/source/dialog/passwd.hrc | 5 | ||||
-rw-r--r-- | sfx2/source/dialog/passwd.src | 30 | ||||
-rw-r--r-- | sfx2/source/dialog/versdlg.cxx | 8 | ||||
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 14 | ||||
-rw-r--r-- | sfx2/source/doc/guisaveas.cxx | 10 | ||||
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 3 | ||||
-rw-r--r-- | sfx2/source/doc/objstor.cxx | 46 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 70 |
17 files changed, 335 insertions, 163 deletions
diff --git a/sfx2/inc/sfx2/docfile.hxx b/sfx2/inc/sfx2/docfile.hxx index 0cb57e7a414d..35656202650f 100644 --- a/sfx2/inc/sfx2/docfile.hxx +++ b/sfx2/inc/sfx2/docfile.hxx @@ -112,7 +112,7 @@ class SFX2_DLLPUBLIC SfxMedium : public SvRefBase SAL_DLLPRIVATE void CloseStreams_Impl(); DECL_DLLPRIVATE_STATIC_LINK( SfxMedium, UCBHdl_Impl, sal_uInt32 * ); - SAL_DLLPRIVATE void SetPasswordToStorage_Impl(); + SAL_DLLPRIVATE void SetEncryptionDataToStorage_Impl(); #endif public: diff --git a/sfx2/inc/sfx2/passwd.hxx b/sfx2/inc/sfx2/passwd.hxx index d53dfbe461d8..6ca9d5212a57 100644 --- a/sfx2/inc/sfx2/passwd.hxx +++ b/sfx2/inc/sfx2/passwd.hxx @@ -37,29 +37,35 @@ // defines --------------------------------------------------------------- -#define SHOWEXTRAS_NONE ((USHORT)0x0000) -#define SHOWEXTRAS_USER ((USHORT)0x0001) -#define SHOWEXTRAS_CONFIRM ((USHORT)0x0002) -#define SHOWEXTRAS_ALL ((USHORT)(SHOWEXTRAS_USER | SHOWEXTRAS_CONFIRM)) +#define SHOWEXTRAS_NONE ((USHORT)0x0000) +#define SHOWEXTRAS_USER ((USHORT)0x0001) +#define SHOWEXTRAS_CONFIRM ((USHORT)0x0002) +#define SHOWEXTRAS_PASSWORD2 ((USHORT)0x0004) +#define SHOWEXTRAS_CONFIRM2 ((USHORT)0x0008) +#define SHOWEXTRAS_ALL ((USHORT)(SHOWEXTRAS_USER | SHOWEXTRAS_CONFIRM)) // class SfxPasswordDialog ----------------------------------------------- class SFX2_DLLPUBLIC SfxPasswordDialog : public ModalDialog { private: + FixedLine maPasswordBox; FixedText maUserFT; Edit maUserED; FixedText maPasswordFT; Edit maPasswordED; FixedText maConfirmFT; Edit maConfirmED; - FixedLine maPasswordBox; + FixedLine maPassword2Box; + FixedText maPassword2FT; + Edit maPassword2ED; + FixedText maConfirm2FT; + Edit maConfirm2ED; OKButton maOKBtn; CancelButton maCancelBtn; HelpButton maHelpBtn; - String maConfirmStr; USHORT mnMinLen; USHORT mnExtras; @@ -74,6 +80,10 @@ public: String GetPassword() const { return maPasswordED.GetText(); } String GetConfirm() const { return maConfirmED.GetText(); } + String GetPassword2() const { return maPassword2ED.GetText(); } + String GetConfirm2() const { return maConfirm2ED.GetText(); } + void SetGroup2Text( const String& i_rText ) { maPassword2Box.SetText( i_rText ); } + void SetMinLen( USHORT Len ); void SetMaxLen( USHORT Len ); void SetEditHelpId( const rtl::OString& rId ) { maPasswordED.SetHelpId( rId ); } diff --git a/sfx2/inc/sfx2/sfxsids.hrc b/sfx2/inc/sfx2/sfxsids.hrc index b5dd2623ae35..561a41b04387 100644 --- a/sfx2/inc/sfx2/sfxsids.hrc +++ b/sfx2/inc/sfx2/sfxsids.hrc @@ -313,7 +313,9 @@ #define SID_RECOMMENDREADONLY (SID_SFX_START + 1719) #define SID_SUGGESTEDSAVEASDIR (SID_SFX_START + 1720) #define SID_SUGGESTEDSAVEASNAME (SID_SFX_START + 1721) -#define SID_SFX_free_START (SID_SFX_START + 1722) +#define SID_ENCRYPTIONDATA (SID_SFX_START + 1722) +#define SID_PASSWORDINTERACTION (SID_SFX_START + 1723) +#define SID_SFX_free_START (SID_SFX_START + 1724) #define SID_SFX_free_END (SID_SFX_START + 3999) #define SID_OPEN_NEW_VIEW (SID_SFX_START + 520) diff --git a/sfx2/inc/sfx2/sfxuno.hxx b/sfx2/inc/sfx2/sfxuno.hxx index f9702063713a..691716b70571 100644 --- a/sfx2/inc/sfx2/sfxuno.hxx +++ b/sfx2/inc/sfx2/sfxuno.hxx @@ -37,6 +37,7 @@ #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/lang/XTypeProvider.hpp> #include <com/sun/star/task/ErrorCodeIOException.hpp> +#include <com/sun/star/beans/NamedValue.hpp> //________________________________________________________________________________________________________________________ @@ -104,7 +105,7 @@ SFX2_DLLPUBLIC void TransformItems( sal_uInt16 UNOSEQUENCE< UNOPROPERTYVALUE >& seqArgs , const SfxSlot* pSlot = 0 ); -sal_Bool GetPasswd_Impl( const SfxItemSet* pSet, ::rtl::OUString& rPasswd ); +bool GetEncryptionData_Impl( const SfxItemSet* pSet, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ); #define FrameSearchFlags sal_Int32 diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index 40d35ab4d702..aadd57185880 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -5317,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,SfxBoolItem PasswordInteraction SID_PASSWORDINTERACTION,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) [ /* flags: */ AutoUpdate = FALSE, diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx index fa2a60a45dcc..0f4c1f651082 100644 --- a/sfx2/source/appl/appopen.cxx +++ b/sfx2/source/appl/appopen.cxx @@ -239,8 +239,7 @@ void SetTemplate_Impl( const String &rFileName, pDoc->ResetFromTemplate( rLongName, rFileName ); } -//-------------------------------------------------------------------- - +//==================================================================== class SfxDocPasswordVerifier : public ::comphelper::IDocPasswordVerifier { public: @@ -248,21 +247,33 @@ public: mxStorage( rxStorage ) {} virtual ::comphelper::DocPasswordVerifierResult - verifyPassword( const ::rtl::OUString& rPassword ); + verifyPassword( const ::rtl::OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData ); + virtual ::comphelper::DocPasswordVerifierResult + verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ); + private: Reference< embed::XStorage > mxStorage; }; -::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyPassword( const ::rtl::OUString& rPassword ) +//-------------------------------------------------------------------- +::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyPassword( const ::rtl::OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData ) +{ + o_rEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( rPassword ); + return verifyEncryptionData( o_rEncryptionData ); +} + + +//-------------------------------------------------------------------- +::comphelper::DocPasswordVerifierResult SfxDocPasswordVerifier::verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ) { ::comphelper::DocPasswordVerifierResult eResult = ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD; try { - // check the password - // if the password correct is the stream will be opened successfuly + // check the encryption data + // if the data correct is the stream will be opened successfuly // and immediatelly closed - ::comphelper::OStorageHelper::SetCommonStoragePassword( mxStorage, rPassword ); + ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( mxStorage, rEncryptionData ); mxStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ), @@ -283,6 +294,8 @@ private: return eResult; } +//==================================================================== + //-------------------------------------------------------------------- sal_uInt32 CheckPasswd_Impl @@ -341,14 +354,28 @@ sal_uInt32 CheckPasswd_Impl if( xInteractionHandler.is() ) { // use the comphelper password helper to request a password + ::rtl::OUString aPassword; + SFX_ITEMSET_ARG( pSet, pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False); + if ( pPasswordItem ) + aPassword = pPasswordItem->GetValue(); + + uno::Sequence< beans::NamedValue > aEncryptionData; + SFX_ITEMSET_ARG( pSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, sal_False); + if ( pEncryptionDataItem ) + pEncryptionDataItem->GetValue() >>= aEncryptionData; + ::rtl::OUString aDocumentName = INetURLObject( pFile->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET ); + SfxDocPasswordVerifier aVerifier( xStorage ); - ::rtl::OUString aPassword = ::comphelper::DocPasswordHelper::requestAndVerifyDocPassword( - aVerifier, ::rtl::OUString(), xInteractionHandler, aDocumentName, comphelper::DocPasswordRequestType_STANDARD ); + aEncryptionData = ::comphelper::DocPasswordHelper::requestAndVerifyDocPassword( + aVerifier, aEncryptionData, aPassword, xInteractionHandler, aDocumentName, comphelper::DocPasswordRequestType_STANDARD ); + + pSet->ClearItem( SID_PASSWORD ); + pSet->ClearItem( SID_ENCRYPTIONDATA ); - if ( aPassword.getLength() > 0 ) + if ( aEncryptionData.getLength() > 0 ) { - pSet->Put( SfxStringItem( SID_PASSWORD, aPassword ) ); + pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ) ); try { diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index a0d576ca40da..60b684d7385f 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -188,6 +188,8 @@ static char const sBlackList[] = "BlackList"; static char const sModifyPasswordInfo[] = "ModifyPasswordInfo"; static char const sSuggestedSaveAsDir[] = "SuggestedSaveAsDir"; static char const sSuggestedSaveAsName[] = "SuggestedSaveAsName"; +static char const sEncryptionData[] = "EncryptionData"; + void TransformParameters( sal_uInt16 nSlotId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rArgs, SfxAllItemSet& rSet, const SfxSlot* pSlot ) { @@ -847,6 +849,10 @@ void TransformParameters( sal_uInt16 nSlotId, const ::com::sun::star::uno::Seque { rSet.Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, rProp.Value ) ); } + else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sEncryptionData)) ) + { + rSet.Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, rProp.Value ) ); + } else if ( aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(sSuggestedSaveAsDir)) ) { ::rtl::OUString sVal; @@ -1077,9 +1083,12 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, ::com::sun::sta nAdditional++; if ( rSet.GetItemState( SID_MODIFYPASSWORDINFO ) == SFX_ITEM_SET ) nAdditional++; - if ( rSet.GetItemState( SID_SUGGESTEDSAVEASDIR ) == SFX_ITEM_SET ) + if ( rSet.GetItemState( SID_SUGGESTEDSAVEASDIR ) == SFX_ITEM_SET ) + nAdditional++; + if ( rSet.GetItemState( SID_ENCRYPTIONDATA ) == SFX_ITEM_SET ) + nAdditional++; nAdditional++; - if ( rSet.GetItemState( SID_SUGGESTEDSAVEASNAME ) == SFX_ITEM_SET ) + if ( rSet.GetItemState( SID_SUGGESTEDSAVEASNAME ) == SFX_ITEM_SET ) nAdditional++; // consider additional arguments @@ -1216,6 +1225,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, ::com::sun::sta continue; if ( nId == SID_NOAUTOSAVE ) continue; + if ( nId == SID_ENCRYPTIONDATA ) + continue; // used only internally if ( nId == SID_SAVETO ) @@ -1589,6 +1600,11 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, ::com::sun::sta pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sModifyPasswordInfo)); pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() ); } + if ( rSet.GetItemState( SID_ENCRYPTIONDATA, sal_False, &pItem ) == SFX_ITEM_SET ) + { + pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sEncryptionData)); + pValue[nActProp++].Value = ( ((SfxUnoAnyItem*)pItem)->GetValue() ); + } if ( rSet.GetItemState( SID_SUGGESTEDSAVEASDIR, sal_False, &pItem ) == SFX_ITEM_SET ) { pValue[nActProp].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sSuggestedSaveAsDir)); diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 5a3a6621fec8..c3624f50191a 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -1522,8 +1522,8 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, // check password checkbox if the document had password before if( mbHasPassword ) { - SFX_ITEMSET_ARG( rpSet, pPassItem, SfxStringItem, SID_PASSWORD, FALSE ); - mbPwdCheckBoxState = ( pPassItem != NULL ); + SFX_ITEMSET_ARG( rpSet, pPassItem, SfxBoolItem, SID_PASSWORDINTERACTION, FALSE ); + mbPwdCheckBoxState = ( pPassItem != NULL && pPassItem->GetValue() ); // in case the document has password to modify, the dialog should be shown SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, FALSE ); @@ -1537,7 +1537,9 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, mbSelectionEnabled = sal_False; // the password will be set in case user decide so + rpSet->ClearItem( SID_PASSWORDINTERACTION ); rpSet->ClearItem( SID_PASSWORD ); + rpSet->ClearItem( SID_ENCRYPTIONDATA ); rpSet->ClearItem( SID_RECOMMENDREADONLY ); rpSet->ClearItem( SID_MODIFYPASSWORDINFO ); @@ -1652,7 +1654,30 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, if ( pPasswordRequest->isPassword() ) { if ( pPasswordRequest->getPassword().getLength() ) - rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + { + // 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 ) ); diff --git a/sfx2/source/dialog/passwd.cxx b/sfx2/source/dialog/passwd.cxx index 3a4e2e7637b2..455479b9d125 100644 --- a/sfx2/source/dialog/passwd.cxx +++ b/sfx2/source/dialog/passwd.cxx @@ -41,14 +41,15 @@ #include "passwd.hrc" #include "vcl/sound.hxx" +#include "vcl/arrange.hxx" // ----------------------------------------------------------------------- -IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG ) +IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, pEdit ) { - if( mbAsciiOnly ) + if( mbAsciiOnly && (pEdit == &maPasswordED || pEdit == &maPassword2ED) ) { - rtl::OUString aTest( maPasswordED.GetText() ); + rtl::OUString aTest( pEdit->GetText() ); const sal_Unicode* pTest = aTest.getStr(); sal_Int32 nLen = aTest.getLength(); rtl::OUStringBuffer aFilter( nLen ); @@ -64,12 +65,15 @@ IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG ) if( bReset ) { Sound::Beep( SOUND_ERROR ); - maPasswordED.SetSelection( Selection( 0, nLen ) ); - maPasswordED.ReplaceSelected( aFilter.makeStringAndClear() ); + pEdit->SetSelection( Selection( 0, nLen ) ); + pEdit->ReplaceSelected( aFilter.makeStringAndClear() ); } } - maOKBtn.Enable( maPasswordED.GetText().Len() >= mnMinLen ); + bool bEnable = maPasswordED.GetText().Len() >= mnMinLen; + if( maPassword2ED.IsVisible() ) + bEnable = (bEnable && (maPassword2ED.GetText().Len() >= mnMinLen)); + maOKBtn.Enable( bEnable ); return 0; } IMPL_LINK_INLINE_END( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG ) @@ -78,8 +82,11 @@ IMPL_LINK_INLINE_END( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG ) IMPL_LINK( SfxPasswordDialog, OKHdl, OKButton *, EMPTYARG ) { - if ( ( ( mnExtras & SHOWEXTRAS_CONFIRM ) == SHOWEXTRAS_CONFIRM ) && - ( GetConfirm() != GetPassword() ) ) + bool bConfirmFailed = ( ( mnExtras & SHOWEXTRAS_CONFIRM ) == SHOWEXTRAS_CONFIRM ) && + ( GetConfirm() != GetPassword() ); + if( ( mnExtras & SHOWEXTRAS_CONFIRM2 ) == SHOWEXTRAS_CONFIRM2 && ( GetConfirm2() != GetPassword2() ) ) + bConfirmFailed = true; + if ( bConfirmFailed ) { ErrorBox aBox( this, SfxResId( MSG_ERROR_WRONG_CONFIRM ) ); aBox.Execute(); @@ -97,27 +104,83 @@ SfxPasswordDialog::SfxPasswordDialog( Window* pParent, const String* pGroupText ModalDialog( pParent, SfxResId ( DLG_PASSWD ) ), + maPasswordBox ( this, SfxResId( GB_PASSWD_PASSWORD ) ), maUserFT ( this, SfxResId( FT_PASSWD_USER ) ), maUserED ( this, SfxResId( ED_PASSWD_USER ) ), maPasswordFT ( this, SfxResId( FT_PASSWD_PASSWORD ) ), maPasswordED ( this, SfxResId( ED_PASSWD_PASSWORD ) ), maConfirmFT ( this, SfxResId( FT_PASSWD_CONFIRM ) ), maConfirmED ( this, SfxResId( ED_PASSWD_CONFIRM ) ), - maPasswordBox ( this, SfxResId( GB_PASSWD_PASSWORD ) ), + maPassword2Box ( this, 0 ), + maPassword2FT ( this, SfxResId( FT_PASSWD_PASSWORD2 ) ), + maPassword2ED ( this, SfxResId( ED_PASSWD_PASSWORD2 ) ), + maConfirm2FT ( this, SfxResId( FT_PASSWD_CONFIRM2 ) ), + maConfirm2ED ( this, SfxResId( ED_PASSWD_CONFIRM2 ) ), maOKBtn ( this, SfxResId( BTN_PASSWD_OK ) ), maCancelBtn ( this, SfxResId( BTN_PASSWD_CANCEL ) ), maHelpBtn ( this, SfxResId( BTN_PASSWD_HELP ) ), - maConfirmStr ( SfxResId( STR_PASSWD_CONFIRM ) ), - mnMinLen ( 5 ), + mnMinLen ( 1 ), mnExtras ( 0 ), mbAsciiOnly ( false ) { FreeResource(); + // setup layout + boost::shared_ptr<vcl::RowOrColumn> xLayout = + boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() ); + xLayout->setOuterBorder( 0 ); + + // get edit size, should be used as minimum + Size aEditSize( maUserED.GetSizePixel() ); + + // add labelcolumn for the labeled edit fields + boost::shared_ptr<vcl::LabelColumn> xEdits( new vcl::LabelColumn( xLayout.get() ) ); + size_t nChildIndex = xLayout->addChild( xEdits ); + xLayout->setBorders( nChildIndex, -2, -2, -2, 0 ); + + // add group box + xEdits->addWindow( &maPasswordBox ); + + // add user line + xEdits->addRow( &maUserFT, &maUserED, -2, aEditSize ); + + // add password line + xEdits->addRow( &maPasswordFT, &maPasswordED, -2, aEditSize ); + + // add confirm line + xEdits->addRow( &maConfirmFT, &maConfirmED, -2, aEditSize ); + + // add second group box + xEdits->addWindow( &maPassword2Box ); + + // add second password line + xEdits->addRow( &maPassword2FT, &maPassword2ED, -2, aEditSize ); + + // add second confirm line + xEdits->addRow( &maConfirm2FT, &maConfirm2ED, -2, aEditSize ); + + // add a FixedLine + FixedLine* pLine = new FixedLine( this, 0 ); + pLine->Show(); + addWindow( pLine, true ); + xLayout->addWindow( pLine ); + + // add button column + Size aBtnSize( maCancelBtn.GetSizePixel() ); + boost::shared_ptr<vcl::RowOrColumn> xButtons( new vcl::RowOrColumn( xLayout.get(), false ) ); + nChildIndex = xLayout->addChild( xButtons ); + xLayout->setBorders( nChildIndex, -2, 0, -2, -2 ); + + size_t nBtnIndex = xButtons->addWindow( &maHelpBtn, 0, aBtnSize ); + xButtons->addChild( new vcl::Spacer( xButtons.get() ) ); + nBtnIndex = xButtons->addWindow( &maOKBtn, 0, aBtnSize ); + nBtnIndex = xButtons->addWindow( &maCancelBtn, 0, aBtnSize ); + Link aLink = LINK( this, SfxPasswordDialog, EditModifyHdl ); maPasswordED.SetModifyHdl( aLink ); + maPassword2ED.SetModifyHdl( aLink ); aLink = LINK( this, SfxPasswordDialog, OKHdl ); maOKBtn.SetClickHdl( aLink ); @@ -146,66 +209,46 @@ void SfxPasswordDialog::SetMaxLen( USHORT nLen ) short SfxPasswordDialog::Execute() { - if ( mnExtras < SHOWEXTRAS_ALL ) + maUserFT.Hide(); + maUserED.Hide(); + maConfirmFT.Hide(); + maConfirmED.Hide(); + maPasswordFT.Hide(); + maPassword2Box.Hide(); + maPassword2FT.Hide(); + maPassword2ED.Hide(); + maPassword2FT.Hide(); + maConfirm2FT.Hide(); + maConfirm2ED.Hide(); + + if( mnExtras != SHOWEXTRAS_NONE ) + maPasswordFT.Show(); + if( (mnExtras & SHOWEXTRAS_USER ) ) { - Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT ); - Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT ); - long nMinHeight = maHelpBtn.GetPosPixel().Y() + - maHelpBtn.GetSizePixel().Height() + a6Size.Height(); - USHORT nRowHided = 1; - - if ( SHOWEXTRAS_NONE == mnExtras ) - { - maUserFT.Hide(); - maUserED.Hide(); - maConfirmFT.Hide(); - maConfirmED.Hide(); - maPasswordFT.Hide(); - - Point aPos = maUserFT.GetPosPixel(); - long nEnd = maUserED.GetPosPixel().X() + maUserED.GetSizePixel().Width(); - maPasswordED.SetPosPixel( aPos ); - Size aSize = maPasswordED.GetSizePixel(); - aSize.Width() = nEnd - aPos.X(); - maPasswordED.SetSizePixel( aSize ); - - nRowHided = 2; - } - else if ( SHOWEXTRAS_USER == mnExtras ) - { - maConfirmFT.Hide(); - maConfirmED.Hide(); - } - else if ( SHOWEXTRAS_CONFIRM == mnExtras ) - { - maUserFT.Hide(); - maUserED.Hide(); - - Point aPwdPos1 = maPasswordFT.GetPosPixel(); - Point aPwdPos2 = maPasswordED.GetPosPixel(); - - Point aPos = maUserFT.GetPosPixel(); - maPasswordFT.SetPosPixel( aPos ); - aPos = maUserED.GetPosPixel(); - maPasswordED.SetPosPixel( aPos ); - - maConfirmFT.SetPosPixel( aPwdPos1 ); - maConfirmED.SetPosPixel( aPwdPos2 ); - } - - Size aBoxSize = maPasswordBox.GetSizePixel(); - aBoxSize.Height() -= ( nRowHided * maUserED.GetSizePixel().Height() ); - aBoxSize.Height() -= ( nRowHided * a3Size.Height() ); - maPasswordBox.SetSizePixel( aBoxSize ); - - long nDlgHeight = maPasswordBox.GetPosPixel().Y() + aBoxSize.Height() + a6Size.Height(); - if ( nDlgHeight < nMinHeight ) - nDlgHeight = nMinHeight; - Size aDlgSize = GetOutputSizePixel(); - aDlgSize.Height() = nDlgHeight; - SetOutputSizePixel( aDlgSize ); + maUserFT.Show(); + maUserED.Show(); + } + if( (mnExtras & SHOWEXTRAS_CONFIRM ) ) + { + maConfirmFT.Show(); + maConfirmED.Show(); + } + if( (mnExtras & SHOWEXTRAS_PASSWORD2) ) + { + maPassword2Box.Show(); + maPassword2FT.Show(); + maPassword2ED.Show(); + } + if( (mnExtras & SHOWEXTRAS_CONFIRM2 ) ) + { + maConfirm2FT.Show(); + maConfirm2ED.Show(); } + boost::shared_ptr<vcl::RowOrColumn> xLayout = + boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() ); + SetSizePixel( xLayout->getOptimalSize( WINDOWSIZE_PREFERRED ) ); + return ModalDialog::Execute(); } diff --git a/sfx2/source/dialog/passwd.hrc b/sfx2/source/dialog/passwd.hrc index 5be0446fd752..5c9b07c7a130 100644 --- a/sfx2/source/dialog/passwd.hrc +++ b/sfx2/source/dialog/passwd.hrc @@ -41,7 +41,10 @@ #define BTN_PASSWD_CANCEL 21 #define BTN_PASSWD_HELP 22 -#define STR_PASSWD_CONFIRM 30 +#define FT_PASSWD_PASSWORD2 25 +#define ED_PASSWD_PASSWORD2 26 +#define FT_PASSWD_CONFIRM2 27 +#define ED_PASSWD_CONFIRM2 28 #endif diff --git a/sfx2/source/dialog/passwd.src b/sfx2/source/dialog/passwd.src index 79cbb382ad36..426fb9986d5a 100644 --- a/sfx2/source/dialog/passwd.src +++ b/sfx2/source/dialog/passwd.src @@ -86,6 +86,32 @@ ModalDialog DLG_PASSWD Size = MAP_APPFONT( 132, 8 ); Text [ en-US ] = "Password" ; }; + FixedText FT_PASSWD_PASSWORD2 + { + Pos = MAP_APPFONT( 12, 30 ); + Size = MAP_APPFONT( 42, 10 ); + Text [ en-US ] = "P~assword"; + }; + Edit ED_PASSWD_PASSWORD2 + { + Border = TRUE; + PassWord = TRUE; + Pos = MAP_APPFONT( 57, 29 ); + Size = MAP_APPFONT( 75, 12 ); + }; + FixedText FT_PASSWD_CONFIRM2 + { + Pos = MAP_APPFONT( 12, 45 ); + Size = MAP_APPFONT( 42, 10 ); + Text [ en-US ] = "Confir~m"; + }; + Edit ED_PASSWD_CONFIRM2 + { + Border = TRUE; + PassWord = TRUE; + Pos = MAP_APPFONT( 57, 44 ); + Size = MAP_APPFONT( 75, 12 ); + }; OKButton BTN_PASSWD_OK { Disable = TRUE; @@ -103,10 +129,6 @@ ModalDialog DLG_PASSWD Pos = MAP_APPFONT( 144, 43 ); Size = MAP_APPFONT( 50, 14 ); }; - String STR_PASSWD_CONFIRM - { - Text [ en-US ] = "Confirm password" ; - }; }; // ********************************************************************** EOF diff --git a/sfx2/source/dialog/versdlg.cxx b/sfx2/source/dialog/versdlg.cxx index 15e9ed7a127a..f2a0cf2790f3 100644 --- a/sfx2/source/dialog/versdlg.cxx +++ b/sfx2/source/dialog/versdlg.cxx @@ -329,13 +329,13 @@ void SfxVersionDialog::Open_Impl() SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE("private:user") ); SfxStringItem aFile( SID_FILE_NAME, pObjShell->GetMedium()->GetName() ); - ::rtl::OUString aPassString; - if ( GetPasswd_Impl( pObjShell->GetMedium()->GetItemSet(), aPassString ) ) + uno::Sequence< beans::NamedValue > aEncryptionData; + if ( GetEncryptionData_Impl( pObjShell->GetMedium()->GetItemSet(), aEncryptionData ) ) { // there is a password, it should be used during the opening - SfxStringItem aPassItem( SID_PASSWORD, aPassString ); + SfxUnoAnyItem aEncryptionDataItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ); pViewFrame->GetDispatcher()->Execute( - SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, &aPassItem, 0L ); + SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, &aFile, &aItem, &aTarget, &aReferer, &aEncryptionDataItem, 0L ); } else pViewFrame->GetDispatcher()->Execute( diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 17f0adf46ea6..434553bdb226 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -882,17 +882,21 @@ uno::Reference < embed::XStorage > SfxMedium::GetOutputStorage() } //------------------------------------------------------------------ -void SfxMedium::SetPasswordToStorage_Impl() +void SfxMedium::SetEncryptionDataToStorage_Impl() { // in case media-descriptor contains password it should be used on opening if ( pImp->xStorage.is() && pSet ) { - ::rtl::OUString aPasswd; - if ( GetPasswd_Impl( pSet, aPasswd ) ) + uno::Sequence< beans::NamedValue > aEncryptionData; + if ( GetEncryptionData_Impl( pSet, aEncryptionData ) ) { + // replace the password with encryption data + pSet->ClearItem( SID_PASSWORD ); + pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ) ); + try { - ::comphelper::OStorageHelper::SetCommonStoragePassword( pImp->xStorage, aPasswd ); + ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( pImp->xStorage, aEncryptionData ); } catch( uno::Exception& ) { @@ -1327,7 +1331,7 @@ uno::Reference < embed::XStorage > SfxMedium::GetStorage( sal_Bool bCreateTempIf // TODO/LATER: Get versionlist on demand if ( pImp->xStorage.is() ) { - SetPasswordToStorage_Impl(); + SetEncryptionDataToStorage_Impl(); GetVersionList(); } diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index e8c81f4b7080..9eb82e7cfd44 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -978,12 +978,11 @@ sal_Bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode, NULL ); const SfxPoolItem* pItem = NULL; - if ( bPreselectPassword && aDialogParams.GetItemState( SID_PASSWORD, sal_True, &pItem ) != SFX_ITEM_SET ) + if ( bPreselectPassword && aDialogParams.GetItemState( SID_ENCRYPTIONDATA, sal_True, &pItem ) != SFX_ITEM_SET ) { - // the file dialog preselects the password checkbox if the provided mediadescriptor has password entry - // after dialog execution the password entry will be either removed or replaced with the password - // entered by the user - aDialogParams.Put( SfxStringItem( SID_PASSWORD, String() ) ); + // the file dialog preselects the password checkbox if the provided mediadescriptor has encryption data entry + // after dialog execution the password interaction flag will be either removed or not + aDialogParams.Put( SfxBoolItem( SID_PASSWORDINTERACTION, sal_True ) ); } // aStringTypeFN is a pure output parameter, pDialogParams is an in/out parameter @@ -1590,6 +1589,7 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >& DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), nStoreMode & EXPORT_REQUESTED ); + OSL_ENSURE( aModelData.GetMediaDescr().find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ) ) == aModelData.GetMediaDescr().end(), "The Password property of MediaDescriptor should not be used here!" ); if ( aOptions.IsDocInfoSave() && ( !aModelData.GetStorable()->hasLocation() || INetURLObject( aModelData.GetStorable()->getLocation() ) != aURL ) ) diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 4b907154202b..c9b5e6f37293 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -599,8 +599,9 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) // ======================================================================================================== sal_Bool bPreselectPassword = sal_False; + SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pOldEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, FALSE ); SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pOldPasswordItem, SfxStringItem, SID_PASSWORD, FALSE ); - if ( pOldPasswordItem ) + if ( pOldEncryptionDataItem || pOldPasswordItem ) bPreselectPassword = sal_True; uno::Sequence< beans::PropertyValue > aDispatchArgs; diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 79cd06c98d80..0575660877a3 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -202,16 +202,30 @@ sal_Bool SfxObjectShell::QuerySlotExecutable( USHORT /*nSlotId*/ ) //------------------------------------------------------------------------- -sal_Bool GetPasswd_Impl( const SfxItemSet* pSet, ::rtl::OUString& rPasswd ) +bool GetEncryptionData_Impl( const SfxItemSet* pSet, uno::Sequence< beans::NamedValue >& o_rEncryptionData ) { - const SfxPoolItem* pItem = NULL; - if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_PASSWORD, sal_True, &pItem ) ) + bool bResult = false; + if ( pSet ) { - DBG_ASSERT( pItem->IsA( TYPE(SfxStringItem) ), "wrong item type" ); - rPasswd = ( (const SfxStringItem*)pItem )->GetValue(); - return sal_True; + SFX_ITEMSET_ARG( pSet, pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, sal_False); + if ( pEncryptionDataItem ) + { + pEncryptionDataItem->GetValue() >>= o_rEncryptionData; + bResult = true; + } + else + { + SFX_ITEMSET_ARG( pSet, pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False); + if ( pPasswordItem ) + { + ::rtl::OUString aPassword = pPasswordItem->GetValue(); + o_rEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPassword ); + bResult = true; + } + } } - return sal_False; + + return bResult; } //------------------------------------------------------------------------- @@ -996,15 +1010,15 @@ sal_Bool SfxObjectShell::DoSave() pImp->bIsSaving = sal_True; - ::rtl::OUString aPasswd; + uno::Sequence< beans::NamedValue > aEncryptionData; if ( IsPackageStorageFormat_Impl( *GetMedium() ) ) { - if ( GetPasswd_Impl( GetMedium()->GetItemSet(), aPasswd ) ) + if ( GetEncryptionData_Impl( GetMedium()->GetItemSet(), aEncryptionData ) ) { try { //TODO/MBA: GetOutputStorage?! Special mode, because it's "Save"?! - ::comphelper::OStorageHelper::SetCommonStoragePassword( GetMedium()->GetStorage(), aPasswd ); + ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( GetMedium()->GetStorage(), aEncryptionData ); bOk = sal_True; } catch( uno::Exception& ) @@ -1386,13 +1400,13 @@ sal_Bool SfxObjectShell::SaveTo_Impl } // transfer password from the parameters to the storage - ::rtl::OUString aPasswd; + uno::Sequence< beans::NamedValue > aEncryptionData; sal_Bool bPasswdProvided = sal_False; - if ( GetPasswd_Impl( rMedium.GetItemSet(), aPasswd ) ) + if ( GetEncryptionData_Impl( rMedium.GetItemSet(), aEncryptionData ) ) { bPasswdProvided = sal_True; try { - ::comphelper::OStorageHelper::SetCommonStoragePassword( xMedStorage, aPasswd ); + ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( xMedStorage, aEncryptionData ); bOk = sal_True; } catch( uno::Exception& ) @@ -3154,13 +3168,13 @@ sal_Bool SfxObjectShell::LoadOwnFormat( SfxMedium& rMedium ) SFX_ITEMSET_ARG( rMedium.GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False ); if ( pPasswdItem || ERRCODE_IO_ABORT != CheckPasswd_Impl( this, SFX_APP()->GetPool(), pMedium ) ) { - ::rtl::OUString aPasswd; - if ( GetPasswd_Impl(pMedium->GetItemSet(), aPasswd) ) + uno::Sequence< beans::NamedValue > aEncryptionData; + if ( GetEncryptionData_Impl(pMedium->GetItemSet(), aEncryptionData) ) { try { // the following code must throw an exception in case of failure - ::comphelper::OStorageHelper::SetCommonStoragePassword( xStorage, aPasswd ); + ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( xStorage, aEncryptionData ); } catch( uno::Exception& ) { diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index afbe9b773961..21c06cb29615 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -980,6 +980,8 @@ sal_Bool SAL_CALL SfxBaseModel::attachResource( const ::rtl::OUString& aArgs.remove( "InputStream" ); aArgs.remove( "URL" ); aArgs.remove( "Frame" ); + aArgs.remove( "Password" ); + aArgs.remove( "EncryptionData" ); // TODO/LATER: all the parameters that are accepted by ItemSet of the DocShell must be removed here @@ -1633,6 +1635,11 @@ void SAL_CALL SfxBaseModel::storeAsURL( const ::rtl::OUString& uno::Sequence< beans::PropertyValue > aSequence ; TransformItems( SID_OPENDOC, *m_pData->m_pObjectShell->GetMedium()->GetItemSet(), aSequence ); attachResource( rURL, aSequence ); + +#if OSL_DEBUG_LEVEL > 0 + SFX_ITEMSET_ARG( m_pData->m_pObjectShell->GetMedium()->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False); + OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" ); +#endif } } @@ -1889,6 +1896,11 @@ void SAL_CALL SfxBaseModel::load( const uno::Sequence< beans::PropertyValue >& SFX_ITEMSET_ARG( pMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False); if ( pHidItem ) bHidden = pHidItem->GetValue(); + +#if OSL_DEBUG_LEVEL > 0 + SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswdItem, SfxStringItem, SID_PASSWORD, sal_False); + OSL_ENSURE( !pPasswdItem, "There should be no Password property in the document MediaDescriptor!" ); +#endif // !TODO: will be done by Framework! pMedium->SetUpdatePickList( !bHidden ); } @@ -2668,49 +2680,41 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL aArgHash.erase( aFilterString ); aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) ); - // if the password is changed SaveAs should be done - // no password for encrypted document is also a change here - sal_Bool bPassChanged = sal_False; - - ::comphelper::SequenceAsHashMap::iterator aNewPassIter - = aArgHash.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ) ); - SFX_ITEMSET_ARG( pMedium->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False ); - if ( pPasswordItem && aNewPassIter != aArgHash.end() ) + try { - ::rtl::OUString aNewPass; - aNewPassIter->second >>= aNewPass; - bPassChanged = !aNewPass.equals( pPasswordItem->GetValue() ); + storeSelf( aArgHash.getAsConstPropertyValueList() ); + bSaved = sal_True; } - else if ( pPasswordItem || aNewPassIter != aArgHash.end() ) - bPassChanged = sal_True; - - if ( !bPassChanged ) + catch( const lang::IllegalArgumentException& ) { - try - { - storeSelf( aArgHash.getAsConstPropertyValueList() ); - bSaved = sal_True; - } - catch( const lang::IllegalArgumentException& ) + // some additional arguments do not allow to use saving, SaveAs should be done + // but only for normal documents, the shared documents would be overwritten in this case + // that would mean an information loss + // TODO/LATER: need a new interaction for this case + if ( m_pData->m_pObjectShell->IsDocShared() ) { - // some additional arguments do not allow to use saving, SaveAs should be done - // but only for normal documents, the shared documents would be overwritten in this case - // that would mean an information loss - // TODO/LATER: need a new interaction for this case - if ( m_pData->m_pObjectShell->IsDocShared() ) + m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) ); + m_pData->m_pObjectShell->StoreLog(); + + uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() ); + if ( !aNewEncryptionData.getLength() ) { - m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) ); - m_pData->m_pObjectShell->StoreLog(); + ::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() ); + aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword ); + } + + uno::Sequence< beans::NamedValue > aOldEncryptionData; + GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ); + if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() ) throw; + else + { + // if the password is changed a special error should be used in case of shared document + throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ); } } } - else if ( m_pData->m_pObjectShell->IsDocShared() ) - { - // if the password is changed a special error should be used in case of shared document - throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ); - } } } } |