summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2008-04-15 13:19:37 +0000
committerVladimir Glazounov <vg@openoffice.org>2008-04-15 13:19:37 +0000
commit912e8f9d1dc5a9c90ab60e38652150e296f02e29 (patch)
tree1a7a4755adf2f5b2b4ac9d4f16b36f0e86fbc86a /sfx2
parente437f3a6f835b267c2337ee37adf183feb384f32 (diff)
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
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/objmisc.cxx193
1 files changed, 164 insertions, 29 deletions
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 1a86385e4239..2f3422b617bc 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -7,7 +7,7 @@
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: objmisc.cxx,v $
- * $Revision: 1.100 $
+ * $Revision: 1.101 $
*
* This file is part of OpenOffice.org.
*
@@ -526,56 +526,191 @@ void SfxObjectShell::SetModalMode_Impl( sal_Bool bModal )
}
//--------------------------------------------------------------------
-
-sal_Bool SfxObjectShell::IsDocShared() const
+sal_Bool SfxObjectShell::SwitchToShared( sal_Bool bShared, sal_Bool bSave )
{
- 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 ( !bShared )
+ if ( IsDocShared() )
{
- try
+ if ( pMedium && pMedium->GetStorage().is() )
{
- ::svt::ShareControlFile aControlFile( GetSharedFileUrl() );
- aControlFile.RemoveFile();
+ // set medium to noname
+ 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
- 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
- }
+ return ( pImp->m_aSharedFileURL.getLength() > 0 );
+}
+
+//--------------------------------------------------------------------
- SetTitle( String() );
+::rtl::OUString SfxObjectShell::GetSharedFileURL() const
+{
+ return pImp->m_aSharedFileURL;
}
//--------------------------------------------------------------------
@@ -795,7 +930,7 @@ String SfxObjectShell::GetTitle
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 )
{
sal_uInt16 nRemote;
@@ -1876,7 +2011,7 @@ void SfxObjectShell::SetWaitCursor( BOOL bSet ) 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() );
if( !aName.Len() )
aName = aURL.GetURLNoPass();