summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Voytenko <mav@openoffice.org>2010-03-30 16:47:18 +0200
committerMikhail Voytenko <mav@openoffice.org>2010-03-30 16:47:18 +0200
commitd160fd054bc4e8c02152d7ce55f7eddbd611e01f (patch)
tree07076067430da0bc93f45df9d57bbe1f2755c456
parenta6c29b00be50f9b48c56903d5764518b7b3aced9 (diff)
tl78: #i110383# support password to modify
-rw-r--r--sfx2/inc/sfx2/sfxsids.hrc5
-rw-r--r--sfx2/sdi/sfx.sdi30
-rw-r--r--sfx2/source/dialog/filedlghelper.cxx51
-rw-r--r--sfx2/source/doc/guisaveas.cxx109
-rw-r--r--sfx2/source/doc/objstor.cxx51
5 files changed, 188 insertions, 58 deletions
diff --git a/sfx2/inc/sfx2/sfxsids.hrc b/sfx2/inc/sfx2/sfxsids.hrc
index a7c73d3e14d8..64bb5692cf09 100644
--- a/sfx2/inc/sfx2/sfxsids.hrc
+++ b/sfx2/inc/sfx2/sfxsids.hrc
@@ -505,8 +505,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_MODIFYPASSWORDHASH (SID_SFX_START + 1718)
-#define SID_SFX_free_START (SID_SFX_START + 1719)
+#define SID_PASSWORDTOMODIFYHASH (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 1b59c639a17d..9df71c085b25 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -3990,7 +3990,7 @@ SfxVoidItem MacroOrganizer SID_MACROORGANIZER
]
//--------------------------------------------------------------------------
-SfxInt32Item ModifyPasswordHash SID_MODIFYPASSWORDHASH
+SfxUInt16Item PasswordToModifyHash SID_PASSWORDTOMODIFYHASH
[
/* flags: */
@@ -4017,6 +4017,34 @@ SfxInt32Item ModifyPasswordHash SID_MODIFYPASSWORDHASH
]
//--------------------------------------------------------------------------
+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
()
[
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index 5e4e7d88258c..adca8cdb7922 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -80,6 +80,7 @@
#include <svtools/helpid.hrc>
#include <svl/pickerhelper.hxx>
#include <comphelper/docpasswordrequest.hxx>
+#include <comphelper/docpasswordhelper.hxx>
#include <ucbhelper/content.hxx>
#include <ucbhelper/commandenvironment.hxx>
#include <comphelper/storagehelper.hxx>
@@ -1543,7 +1544,7 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
mbPwdCheckBoxState = ( pPassItem != NULL );
// in case the document has password to modify, the dialog should be shown
- SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxStringItem, SID_PASSWORDTOMODIFY, FALSE );
+ SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUInt16Item, SID_PASSWORDTOMODIFYHASH, FALSE );
mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue() );
}
@@ -1556,7 +1557,7 @@ 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_PASSWORDTOMODIFY );
+ rpSet->ClearItem( SID_PASSWORDTOMODIFYHASH );
}
@@ -1634,8 +1635,10 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
// set the filter
getRealFilter( rFilter );
+ SfxFilter* pCurrentFilter = getCurentSfxFilter();
+
// fill the rpURLList
- implGetAndCacheFiles(mxFileDlg, rpURLList, getCurentSfxFilter());
+ implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter );
if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL )
return ERRCODE_ABORT;
@@ -1654,12 +1657,13 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
if( xInteractionHandler.is() )
{
// TODO: need a save way to distinguish MS filters from other filters
- sal_Bool bMSType = CheckMSPasswordCapabilityForExport( rFilter );
+ // for now MS-filters are the only alien filters that support encryption
+ sal_Bool bMSType = !pCurrentFilter->isOwn();
::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)), lclCheckPasswordToModifyCapability( getCurentSfxFilter() ) ) );
+ ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)), lclCheckPasswordToModifyCapability( pCurrentFilter ) ) );
uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest );
xInteractionHandler->handle( rRequest );
@@ -1672,7 +1676,42 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
if ( pPasswordRequest->getPasswordToModify().getLength() )
- rpSet->Put( SfxStringItem( SID_PASSWORDTOMODIFY, pPasswordRequest->getPasswordToModify() ) );
+ {
+ rtl_TextEncoding nEncoding = RTL_TEXTENCOFING_UTF8;
+ if ( bMSType )
+ {
+ // if the MS-filter should be used
+ // use the inconsistent algorithm to find the encoding specified by MS
+ nEncoding = rtl_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;
+ }
+ }
+
+ sal_uInt16 nHash = ::comphelper::DocPasswordHelper::GetXLHashAsUINT16( pPasswordRequest->getPasswordToModify(), nEncoding );
+ rpSet->Put( SfxUInt16Item( SID_PASSWORDTOMODIFYHASH, nHash ) );
+ }
}
else
return ERRCODE_ABORT;
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index cbd269b41516..4993e96b40bb 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,88 @@ static sal_Int32 getDontFlags( sal_Int8 nStoreMode )
}
//=========================================================================
+// class DocumentSettingsGuard
+//=========================================================================
+
+class DocumentSettingsGuard
+{
+ uno::Reference< beans::XPropertySet > m_xDocumentSettings;
+ sal_Bool m_bPreserveReadOnly;
+ sal_uInt16 m_nPreserveHash;
+
+ sal_Bool m_bReadOnlySupported;
+ sal_Bool m_bModifyPasswordHashSupported;
+
+ sal_Bool m_bRestoreSettings;
+public:
+ DocumentSettingsGuard( const uno::Reference< frame::XModel >& xModel, sal_Bool bReadOnly, sal_uInt16 nHash, sal_Bool bRestore )
+ : m_bPreserveReadOnly( sal_False )
+ , m_nPreserveHash( 0 )
+ , m_bReadOnlySupported( sal_False )
+ , m_bModifyPasswordHashSupported( 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" ) );
+ ::rtl::OUString aModifyPasswordHashString( RTL_CONSTASCII_USTRINGPARAM( "ModifyPasswordHash" ) );
+
+ try
+ {
+ m_xDocumentSettings->getPropertyValue( aLoadReadonlyString ) >>= m_bPreserveReadOnly;
+ m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( bReadOnly ) );
+ m_bReadOnlySupported = sal_True;
+ }
+ catch( uno::Exception& )
+ {}
+
+ try
+ {
+ m_xDocumentSettings->getPropertyValue( aModifyPasswordHashString ) >>= m_nPreserveHash;
+ m_xDocumentSettings->setPropertyValue( aModifyPasswordHashString, uno::makeAny( nHash ) );
+ m_bModifyPasswordHashSupported = sal_True;
+ }
+ catch( uno::Exception& )
+ {}
+ }
+ catch( uno::Exception& )
+ {}
+
+ if ( ( bReadOnly && !m_bReadOnlySupported ) || ( nHash && !m_bModifyPasswordHashSupported ) )
+ 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" ) );
+ ::rtl::OUString aModifyPasswordHashString( RTL_CONSTASCII_USTRINGPARAM( "ModifyPasswordHash" ) );
+
+ try
+ {
+ if ( m_bReadOnlySupported )
+ m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( m_bPreserveReadOnly ) );
+
+ if ( m_bModifyPasswordHashSupported )
+ m_xDocumentSettings->setPropertyValue( aModifyPasswordHashString, uno::makeAny( m_nPreserveHash ) );
+ }
+ catch( uno::Exception& )
+ {
+ OSL_ASSERT( "Unexpected exception!" );
+ }
+ }
+ }
+};
+} // anonymous namespace
+
+//=========================================================================
// class ModelData_Impl
//=========================================================================
class ModelData_Impl
@@ -184,6 +271,9 @@ class ModelData_Impl
::comphelper::SequenceAsHashMap m_aMediaDescrHM;
+ sal_Bool m_bRecommendReadOnly;
+ sal_uInt16 m_nPasswordToModifyHash;
+
public:
ModelData_Impl( SfxStoringHelper& aOwner,
const uno::Reference< frame::XModel >& xModel,
@@ -200,6 +290,9 @@ public:
::comphelper::SequenceAsHashMap& GetMediaDescr() { return m_aMediaDescrHM; }
+ sal_Bool IsRecommendReadOnly() { return m_bRecommendReadOnly; }
+ sal_uInt16 GetPasswordToModifyHash() { return m_nPasswordToModifyHash; }
+
const ::comphelper::SequenceAsHashMap& GetDocProps();
::rtl::OUString GetModuleName();
@@ -252,6 +345,9 @@ ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner,
, m_pDocumentPropsHM( NULL )
, m_pModulePropsHM( NULL )
, m_aMediaDescrHM( aMediaDescr )
+, m_bRecommendReadOnly( sal_False )
+, m_nPasswordToModifyHash( 0 )
+
{
CheckInteractionHandler();
}
@@ -916,6 +1012,17 @@ 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 );
+
+ SFX_ITEMSET_ARG( pDialogParams, pPassToModifyItem, SfxUInt16Item, SID_PASSWORDTOMODIFYHASH, sal_False );
+ if ( pPassToModifyItem )
+ m_nPasswordToModifyHash = pPassToModifyItem->GetValue();
+ pDialogParams->ClearItem( SID_PASSWORDTOMODIFYHASH );
+
uno::Sequence< beans::PropertyValue > aPropsFromDialog;
TransformItems( nSlotID, *pDialogParams, aPropsFromDialog, NULL );
GetMediaDescr() << aPropsFromDialog;
@@ -1500,6 +1607,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(), aModelData.GetPasswordToModifyHash(), nStoreMode & EXPORT_REQUESTED );
+
if ( aOptions.IsDocInfoSave()
&& ( !aModelData.GetStorable()->hasLocation()
|| INetURLObject( aModelData.GetStorable()->getLocation() ) != aURL ) )
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 593de3d181f1..b710a4b0fbfe 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -1376,7 +1376,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 );
@@ -2093,9 +2092,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();
@@ -2632,9 +2628,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");
@@ -2645,13 +2638,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() )
{
@@ -2910,8 +2897,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! )
@@ -2948,18 +2933,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
@@ -2991,31 +2966,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 );
@@ -3196,9 +3152,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 ) )