Kaydet (Commit) 912e8f9d authored tarafından Vladimir Glazounov's avatar Vladimir Glazounov

INTEGRATION: CWS calcshare2 (1.99.4); FILE MERGED

2008/04/04 11:13:54 mav 1.99.4.5: #i87752# let SaveAs to the same document behave correctly
2008/03/29 11:11:51 mav 1.99.4.4: #i86672# let the reload handle shared documents correctly
2008/03/28 12:07:36 mav 1.99.4.3: #i87551# adopt SaveAs for sharing scenario
2008/03/16 13:38:38 mav 1.99.4.2: #i85794# remove unused variable
2008/03/14 20:16:16 mav 1.99.4.1: #i85794# new file locking prototype
üst e437f3a6
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* OpenOffice.org - a multi-platform office productivity suite * OpenOffice.org - a multi-platform office productivity suite
* *
* $RCSfile: objmisc.cxx,v $ * $RCSfile: objmisc.cxx,v $
* $Revision: 1.100 $ * $Revision: 1.101 $
* *
* This file is part of OpenOffice.org. * This file is part of OpenOffice.org.
* *
...@@ -526,56 +526,191 @@ void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal ) ...@@ -526,56 +526,191 @@ void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal )
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave )
sal_Bool SfxObjectShell::IsDocShared() const
{ {
return pImp->m_bIsDocShared; sal_Bool bResult = sal_True;
if ( bShared != IsDocShared() )
{
sal_Bool bOldValue = HasSharedXMLFlagSet();
SetSharedXMLFlag( bShared );
if ( bSave )
{
SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst( this );
if ( pViewFrame )
{
// TODO/LATER: currently the application guards against the reentrance problem
const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC );
SfxBoolItem* pResult = PTR_CAST( SfxBoolItem, pItem );
bResult = ( pResult && pResult->GetValue() );
}
}
if ( bResult )
{
// TODO/LATER: Is it possible that the following calls fail?
if ( bShared )
{
::rtl::OUString aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
try
{
::svt::ShareControlFile aControlFile( aOrigURL );
aControlFile.InsertOwnEntry();
}
catch( uno::Exception& )
{
// TODO/LATER: in future the switching should not happen and an error should be shown
}
pImp->m_aSharedFileURL = aOrigURL;
GetMedium()->SwitchDocumentToTempFile();
}
else
{
::rtl::OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
pImp->m_aSharedFileURL = ::rtl::OUString();
// now remove the temporary file the document was based on
::utl::UCBContentHelper::Kill( aTempFileURL );
try
{
::svt::ShareControlFile aControlFile( GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
aControlFile.RemoveFile();
}
catch( uno::Exception& )
{
}
}
}
else
{
// the saving has failed!
SetSharedXMLFlag( bOldValue );
}
}
else
bResult = sal_False; // the second switch to the same mode
if ( bResult )
SetTitle( String() );
return bResult;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void SfxObjectShell::SetDocShared( sal_Bool bShared ) void SfxObjectShell::DisconnectFromShared()
{ {
pImp->m_bIsDocShared = bShared; if ( IsDocShared() )
if ( !bShared )
{ {
try if ( pMedium && pMedium->GetStorage().is() )
{ {
::svt::ShareControlFile aControlFile( GetSharedFileUrl() ); // set medium to noname
aControlFile.RemoveFile(); pMedium->SetName( String(), sal_True );
pMedium->Init_Impl();
// drop resource
SetNoName();
InvalidateName();
// untitled document must be based on temporary storage
// the medium should not dispose the storage in this case
if ( pMedium->GetStorage() == GetStorage() )
ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium );
pMedium->Close();
FreeSharedFile();
SfxMedium* pTmpMedium = pMedium;
ForgetMedium();
if( !DoSaveCompleted( pTmpMedium ) )
SetError( ERRCODE_IO_GENERAL );
else
{
// the medium should not dispose the storage, DoSaveCompleted() has let it to do so
pMedium->CanDisposeStorage_Impl( sal_False );
}
pMedium->GetItemSet()->ClearItem( SID_DOC_READONLY );
pMedium->SetOpenMode( SFX_STREAM_READWRITE, sal_True, sal_True );
SetTitle( String() );
} }
catch( uno::Exception& ) }
}
//--------------------------------------------------------------------
void SfxObjectShell::FreeSharedFile()
{
if ( pMedium )
FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
}
//--------------------------------------------------------------------
void SfxObjectShell::FreeSharedFile( const ::rtl::OUString& aTempFileURL )
{
SetSharedXMLFlag( sal_False );
if ( IsDocShared() && aTempFileURL.getLength()
&& !SfxMedium::EqualURLs( aTempFileURL, GetSharedFileURL() ) )
{
if ( pImp->m_bAllowShareControlFileClean )
{ {
try
{
::svt::ShareControlFile aControlFile( GetSharedFileURL() );
aControlFile.RemoveEntry();
}
catch( uno::Exception& )
{
}
} }
// the cleaning is forbidden only once
pImp->m_bAllowShareControlFileClean = sal_True;
// now remove the temporary file the document is based currently on
::utl::UCBContentHelper::Kill( aTempFileURL );
pImp->m_aSharedFileURL = ::rtl::OUString();
} }
}
SetTitle( String() ); //--------------------------------------------------------------------
void SfxObjectShell::DoNotCleanShareControlFile()
{
pImp->m_bAllowShareControlFileClean = sal_False;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void SfxObjectShell::SetSharedXMLFlag( sal_Bool bFlag ) const
{
pImp->m_bSharedXMLFlag = bFlag;
}
::rtl::OUString SfxObjectShell::GetSharedFileUrl() const //--------------------------------------------------------------------
sal_Bool SfxObjectShell::HasSharedXMLFlagSet() const
{ {
return pImp->m_aSharedFileURL; return pImp->m_bSharedXMLFlag;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void SfxObjectShell::SetSharedFileUrl( const ::rtl::OUString& aURL ) sal_Bool SfxObjectShell::IsDocShared() const
{ {
// TODO/LATER: should be supported only for file: urls return ( pImp->m_aSharedFileURL.getLength() > 0 );
pImp->m_aSharedFileURL = aURL; }
try
{ //--------------------------------------------------------------------
::svt::ShareControlFile aControlFile( aURL );
aControlFile.InsertOwnEntry();
}
catch( uno::Exception& )
{
// TODO/LATER: in future the switching should not happen and an error should be shown
}
SetTitle( String() ); ::rtl::OUString SfxObjectShell::GetSharedFileURL() const
{
return pImp->m_aSharedFileURL;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
...@@ -795,7 +930,7 @@ String SfxObjectShell::GetTitle ...@@ -795,7 +930,7 @@ String SfxObjectShell::GetTitle
return X(aNoName); return X(aNoName);
} }
const INetURLObject aURL( IsDocShared() ? GetSharedFileUrl() : ::rtl::OUString( GetMedium()->GetName() ) ); const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY ) if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
{ {
sal_uInt16 nRemote; sal_uInt16 nRemote;
...@@ -1876,7 +2011,7 @@ void SfxObjectShell::SetWaitCursor( BOOL bSet ) const ...@@ -1876,7 +2011,7 @@ void SfxObjectShell::SetWaitCursor( BOOL bSet ) const
String SfxObjectShell::GetAPIName() const String SfxObjectShell::GetAPIName() const
{ {
INetURLObject aURL( IsDocShared() ? GetSharedFileUrl() : ::rtl::OUString( GetMedium()->GetName() ) ); INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : ::rtl::OUString( GetMedium()->GetName() ) );
String aName( aURL.GetBase() ); String aName( aURL.GetBase() );
if( !aName.Len() ) if( !aName.Len() )
aName = aURL.GetURLNoPass(); aName = aURL.GetURLNoPass();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment