summaryrefslogtreecommitdiff
path: root/sfx2/source/doc
diff options
context:
space:
mode:
Diffstat (limited to 'sfx2/source/doc')
-rw-r--r--sfx2/source/doc/docfile.cxx272
-rw-r--r--sfx2/source/doc/guisaveas.cxx10
2 files changed, 145 insertions, 137 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 7735d5acbc..2ca8a68257 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -283,7 +283,6 @@ public:
sal_Bool m_bSalvageMode: 1;
sal_Bool m_bVersionsAlreadyLoaded: 1;
sal_Bool m_bLocked: 1;
- sal_Bool m_bHandleSysLocked: 1;
sal_Bool m_bGotDateTime: 1;
uno::Reference < embed::XStorage > xStorage;
@@ -378,7 +377,6 @@ SfxMedium_Impl::SfxMedium_Impl( SfxMedium* pAntiImplP )
m_bSalvageMode( sal_False ),
m_bVersionsAlreadyLoaded( sal_False ),
m_bLocked( sal_False ),
- m_bHandleSysLocked( sal_False ),
m_bGotDateTime( sal_False ),
pAntiImpl( pAntiImplP ),
nFileVersion( 0 ),
@@ -1147,159 +1145,181 @@ sal_Bool SfxMedium::LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI )
sal_Bool bResult = pImp->m_bLocked;
- if ( ::utl::LocalFileHelper::IsLocalFile( aLogicName ) )
+ if ( !bResult )
{
- // the special file locking should be used only for file URLs
-
- // in case of storing the document should request the output before locking
- if ( bLoading )
- {
- // let the stream be opened to check the system file locking
- GetMedium_Impl();
- }
-
- // no locking is necessary on loading if the document is explicitly opened as copy
+ // no read-write access is necessary on loading if the document is explicitly opened as copy
SFX_ITEMSET_ARG( GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False);
bResult = ( bLoading && pTemplateItem && pTemplateItem->GetValue() );
+ }
- if ( !bResult && ( !IsReadOnly() || pImp->m_bHandleSysLocked ) )
+ if ( !bResult && !IsReadOnly() )
+ {
+ // check whether the file is readonly in fs
+ // do it only for loading, some contents still might have problems with this property, let them not affect the saving
+ sal_Bool bContentReadonly = sal_False;
+ if ( bLoading )
{
- sal_Int8 bUIStatus = LOCK_UI_NOLOCK;
-
- // check whether system file locking has been used, the default value is false
- sal_Bool bUseSystemLock = sal_False;
try
{
-
- uno::Reference< uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
- ::comphelper::getProcessServiceFactory(),
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
- ::comphelper::ConfigurationHelper::E_STANDARD );
- if ( !xCommonConfig.is() )
- throw uno::RuntimeException();
-
- ::comphelper::ConfigurationHelper::readRelativeKey(
- xCommonConfig,
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ),
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseSystemLock;
+ // MediaDescriptor does this check also, the duplication should be avoided in future
+ pImp->aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bContentReadonly;
}
- catch( const uno::Exception& )
+ catch( uno::Exception )
+ {}
+ }
+
+ if ( !bContentReadonly )
+ {
+ if ( ::utl::LocalFileHelper::IsLocalFile( aLogicName ) )
{
- }
+ // the special file locking should be used only for file URLs
- // TODO/LATER: This implementation does not allow to detect the system lock on saving here, actually this is no big problem
- if ( bLoading && bUseSystemLock && !pImp->xStream.is() && !pOutStream )
- pImp->m_bHandleSysLocked = sal_True; // if system lock is used the writeable stream should be available
+ // in case of storing the document should request the output before locking
+ if ( bLoading )
+ {
+ // let the stream be opened to check the system file locking
+ GetMedium_Impl();
+ }
- do
- {
+ sal_Int8 bUIStatus = LOCK_UI_NOLOCK;
+
+ // check whether system file locking has been used, the default value is false
+ sal_Bool bUseSystemLock = sal_False;
try
- {
- ::svt::DocumentLockFile aLockFile( aLogicName );
- if ( !pImp->m_bHandleSysLocked )
- {
- try
- {
- bResult = aLockFile.CreateOwnLockFile();
- }
- catch ( ucb::InteractiveIOException& e )
+ {
+ uno::Reference< uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
+ ::comphelper::getProcessServiceFactory(),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
+ ::comphelper::ConfigurationHelper::E_STANDARD );
+ if ( !xCommonConfig.is() )
+ throw uno::RuntimeException();
+
+ ::comphelper::ConfigurationHelper::readRelativeKey(
+ xCommonConfig,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseSystemLock;
+ }
+ catch( const uno::Exception& )
+ {
+ }
+
+ // TODO/LATER: This implementation does not allow to detect the system lock on saving here, actually this is no big problem
+ // if system lock is used the writeable stream should be available
+ sal_Bool bHandleSysLocked = ( bLoading && bUseSystemLock && !pImp->xStream.is() && !pOutStream );
+
+ do
+ {
+ try
+ {
+ ::svt::DocumentLockFile aLockFile( aLogicName );
+ if ( !bHandleSysLocked )
{
- if ( e.Code == IOErrorCode_INVALID_PARAMETER )
+ try
+ {
+ bResult = aLockFile.CreateOwnLockFile();
+ }
+ catch ( ucb::InteractiveIOException& e )
{
- // it looks like the lock file name is not accepted by the content
- if ( !bUseSystemLock )
+ if ( e.Code == IOErrorCode_INVALID_PARAMETER )
{
- // system file locking is not active, ask user whether he wants to open the document without any locking
- uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler();
-
- if ( xHandler.is() )
+ // it looks like the lock file name is not accepted by the content
+ if ( !bUseSystemLock )
{
- ::rtl::Reference< ::ucbhelper::InteractionRequest > xIgnoreRequestImpl
- = new ::ucbhelper::InteractionRequest( uno::makeAny( document::LockFileIgnoreRequest() ) );
-
- uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 );
- aContinuations[0] = new ::ucbhelper::InteractionAbort( xIgnoreRequestImpl.get() );
- aContinuations[1] = new ::ucbhelper::InteractionApprove( xIgnoreRequestImpl.get() );
- xIgnoreRequestImpl->setContinuations( aContinuations );
-
- xHandler->handle( xIgnoreRequestImpl.get() );
-
- ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xIgnoreRequestImpl->getSelection();
- bResult = ( uno::Reference< task::XInteractionApprove >( xSelected.get(), uno::UNO_QUERY ).is() );
+ // system file locking is not active, ask user whether he wants to open the document without any locking
+ uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler();
+
+ if ( xHandler.is() )
+ {
+ ::rtl::Reference< ::ucbhelper::InteractionRequest > xIgnoreRequestImpl
+ = new ::ucbhelper::InteractionRequest( uno::makeAny( document::LockFileIgnoreRequest() ) );
+
+ uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 );
+ aContinuations[0] = new ::ucbhelper::InteractionAbort( xIgnoreRequestImpl.get() );
+ aContinuations[1] = new ::ucbhelper::InteractionApprove( xIgnoreRequestImpl.get() );
+ xIgnoreRequestImpl->setContinuations( aContinuations );
+
+ xHandler->handle( xIgnoreRequestImpl.get() );
+
+ ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xIgnoreRequestImpl->getSelection();
+ bResult = ( uno::Reference< task::XInteractionApprove >( xSelected.get(), uno::UNO_QUERY ).is() );
+ }
}
+ else
+ bResult = sal_True;
}
else
- bResult = sal_True;
+ throw;
}
- else
- throw;
}
- }
-
- if ( !bResult )
- {
- uno::Sequence< ::rtl::OUString > aData;
- try
+
+ if ( !bResult )
{
- // impossibility to get data is no real problem
- aData = aLockFile.GetLockData();
- }
- catch( uno::Exception ) {}
+ uno::Sequence< ::rtl::OUString > aData;
+ try
+ {
+ // impossibility to get data is no real problem
+ aData = aLockFile.GetLockData();
+ }
+ catch( uno::Exception ) {}
- sal_Bool bOwnLock = sal_False;
+ sal_Bool bOwnLock = sal_False;
- if ( !pImp->m_bHandleSysLocked )
- {
- uno::Sequence< ::rtl::OUString > aOwnData = aLockFile.GenerateOwnEntry();
- bOwnLock = ( aData.getLength() > LOCKFILE_USERURL_ID
- && aOwnData.getLength() > LOCKFILE_USERURL_ID
- && aOwnData[LOCKFILE_SYSUSERNAME_ID].equals( aData[LOCKFILE_SYSUSERNAME_ID] ) );
-
- if ( bOwnLock
- && aOwnData[LOCKFILE_LOCALHOST_ID].equals( aData[LOCKFILE_LOCALHOST_ID] )
- && aOwnData[LOCKFILE_USERURL_ID].equals( aData[LOCKFILE_USERURL_ID] ) )
+ if ( !bHandleSysLocked )
{
- // this is own lock from the same installation, it could remain because of crash
- bResult = sal_True;
+ uno::Sequence< ::rtl::OUString > aOwnData = aLockFile.GenerateOwnEntry();
+ bOwnLock = ( aData.getLength() > LOCKFILE_USERURL_ID
+ && aOwnData.getLength() > LOCKFILE_USERURL_ID
+ && aOwnData[LOCKFILE_SYSUSERNAME_ID].equals( aData[LOCKFILE_SYSUSERNAME_ID] ) );
+
+ if ( bOwnLock
+ && aOwnData[LOCKFILE_LOCALHOST_ID].equals( aData[LOCKFILE_LOCALHOST_ID] )
+ && aOwnData[LOCKFILE_USERURL_ID].equals( aData[LOCKFILE_USERURL_ID] ) )
+ {
+ // this is own lock from the same installation, it could remain because of crash
+ bResult = sal_True;
+ }
}
- }
- if ( !bResult && !bNoUI )
- {
- bUIStatus = ShowLockedDocumentDialog( aData, bLoading, bOwnLock );
- if ( bUIStatus == LOCK_UI_SUCCEEDED )
+ if ( !bResult && !bNoUI )
{
- // take the ownership over the lock file
- bResult = aLockFile.OverwriteOwnLockFile();
+ bUIStatus = ShowLockedDocumentDialog( aData, bLoading, bOwnLock );
+ if ( bUIStatus == LOCK_UI_SUCCEEDED )
+ {
+ // take the ownership over the lock file
+ bResult = aLockFile.OverwriteOwnLockFile();
+ }
}
- }
- pImp->m_bHandleSysLocked = sal_False;
+ bHandleSysLocked = sal_False;
+ }
}
- }
- catch( uno::Exception& )
- {
- }
- } while( !bResult && bUIStatus == LOCK_UI_TRY );
+ catch( uno::Exception& )
+ {
+ }
+ } while( !bResult && bUIStatus == LOCK_UI_TRY );
- pImp->m_bLocked = bResult;
+ pImp->m_bLocked = bResult;
+ }
+ else
+ {
+ // this is no file URL, check whether the file is readonly
+ bResult = !bContentReadonly;
+ }
}
+ }
- if ( !bResult && GetError() == ERRCODE_NONE )
- {
- // the error should be set in case it is storing process
- // or the document has been opened for editing explicitly
+ if ( !bResult && GetError() == ERRCODE_NONE )
+ {
+ // the error should be set in case it is storing process
+ // or the document has been opened for editing explicitly
- SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
- if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) )
- SetError( ERRCODE_IO_ACCESSDENIED );
- else
- GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
- }
+ SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, FALSE );
+ if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) )
+ SetError( ERRCODE_IO_ACCESSDENIED );
+ else
+ GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
}
- else
- bResult = sal_True;
return bResult;
}
@@ -2515,7 +2535,6 @@ void SfxMedium::GetMedium_Impl()
{
TransformItems( SID_OPENDOC, *GetItemSet(), xProps );
comphelper::MediaDescriptor aMedium( xProps );
- sal_Bool bRequestedReadOnly = aMedium.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_READONLY(), sal_False );
if ( bFromTempFile )
{
@@ -2531,19 +2550,8 @@ void SfxMedium::GetMedium_Impl()
else
aMedium.addInputStream();
- // the warning is shown if the user wants to edit the document, but it is not possible
- pImp->m_bHandleSysLocked = ( !bRequestedReadOnly && aMedium.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_READONLY(), sal_False ) );
-
- sal_Bool bReadOnly = sal_False;
- aMedium[comphelper::MediaDescriptor::PROP_READONLY()] >>= bReadOnly;
- if ( bReadOnly )
- {
- SFX_ITEMSET_ARG( GetItemSet(), pROItem, SfxBoolItem, SID_DOC_READONLY, sal_False);
- BOOL bForceWritable = ( pROItem && !pROItem->GetValue() );
- GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
- if( bForceWritable )
- SetError( ERRCODE_IO_ACCESSDENIED );
- }
+ // the ReadOnly property set in aMedium is ignored
+ // the check is done in LockOrigFileOnDemand() for file and non-file URLs
//TODO/MBA: what happens if property is not there?!
GetContent();
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index 12f0c4ef96..4b6812bb8b 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -921,7 +921,7 @@ sal_Bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode,
// get the path from the dialog
INetURLObject aURL( pFileDlg->GetPath() );
// the path should be provided outside since it might be used for further calls to the dialog
- aSuggestedName = aURL.GetName();
+ aSuggestedName = aURL.GetName( INetURLObject::DECODE_WITH_CHARSET );
// old filter options should be cleared in case different filter is used
@@ -1081,8 +1081,8 @@ sal_Bool ModelData_Impl::ShowDocumentInfoDialog()
else
{
// pb: set graphic path if context == SD_EXPORT or SI_EXPORT else work path
- aReccomendedDir = ( aCtxt != sfx2::FileDialogHelper::UNKNOWN_CONTEXT )
- ? SvtPathOptions().GetGraphicPath() : SvtPathOptions().GetWorkPath();
+ ::rtl::OUString aConfigSuggestion( ( aCtxt != sfx2::FileDialogHelper::UNKNOWN_CONTEXT ) ? SvtPathOptions().GetGraphicPath() : SvtPathOptions().GetWorkPath() );
+ aReccomendedDir = INetURLObject( aConfigSuggestion ).GetMainURL( INetURLObject::NO_DECODE );
}
return aReccomendedDir;
@@ -1098,7 +1098,7 @@ sal_Bool ModelData_Impl::ShowDocumentInfoDialog()
aReccomendedName = aSuggestedName;
else
{
- aReccomendedName = INetURLObject( GetStorable()->getLocation() ).GetName();
+ aReccomendedName = INetURLObject( GetStorable()->getLocation() ).GetName( INetURLObject::DECODE_WITH_CHARSET );
if ( !aReccomendedName.getLength() )
{
try {
@@ -1128,7 +1128,7 @@ sal_Bool ModelData_Impl::ShowDocumentInfoDialog()
aObj.SetExtension( aExtensions[0] );
}
- aReccomendedName = aObj.GetName();
+ aReccomendedName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
}
}
}