summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-07-05 17:56:38 +1000
committerMike Kaganski <mike.kaganski@collabora.com>2019-07-09 07:59:20 +0200
commit45bb41b169844ed913b42833a1c130c2d92678ec (patch)
tree2e1cafb5b50109651b4a7035ea18f1880db4a8b0 /sfx2
parent1e4d55f2663f95375f0f864bed232e5600c3d7ca (diff)
Show who has locked the document when reopening a read-only document
Pass the locking data from SfxMedium::LockOrigFileOnDemand, to allow clients to show it themselves when required. Change-Id: I6afe46a1896e1b60771c080efa2f58794dbed8a6 Reviewed-on: https://gerrit.libreoffice.org/75113 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/75137 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/75285 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/docfile.cxx73
-rw-r--r--sfx2/source/view/viewfrm.cxx41
2 files changed, 80 insertions, 34 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index ed96ed98395b..012481c849fd 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -1063,7 +1063,9 @@ namespace
// sets SID_DOC_READONLY if the document cannot be opened for editing
// if user cancel the loading the ERROR_ABORT is set
-SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool bNoUI, bool bTryIgnoreLockFile )
+SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand(bool bLoading, bool bNoUI,
+ bool bTryIgnoreLockFile,
+ LockFileEntry* pLockData)
{
#if !HAVE_FEATURE_MULTIUSER_ENVIRONMENT
(void) bLoading;
@@ -1114,37 +1116,47 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b
catch ( ucb::InteractiveLockingLockedException& )
{
// received when the resource is already locked
- // get the lock owner, using a special ucb.webdav property
- // the owner property retrieved here is what the other principal send the server
- // when activating the lock.
- // See http://tools.ietf.org/html/rfc4918#section-14.17 for details
- LockFileEntry aLockData;
- aLockData[LockFileComponent::OOOUSERNAME] = "Unknown user";
- // This solution works right when the LO user name and the WebDAV user
- // name are the same.
- // A better thing to do would be to obtain the 'real' WebDAV user name,
- // but that's not possible from a WebDAV UCP provider client.
- LockFileEntry aOwnData = svt::LockFileCommon::GenerateOwnEntry();
- // use the current LO user name as the system name
- aLockData[LockFileComponent::SYSUSERNAME] = aOwnData[LockFileComponent::SYSUSERNAME];
-
- uno::Sequence< css::ucb::Lock > aLocks;
- // getting the property, send a PROPFIND to the server over the net
- if( aContentToLock.getPropertyValue( "DAV:lockdiscovery" ) >>= aLocks )
+ if (!bNoUI || pLockData)
{
- // got at least a lock, show the owner of the first lock returned
- css::ucb::Lock aLock = aLocks[0];
- OUString aOwner;
- if(aLock.Owner >>= aOwner)
+ // get the lock owner, using a special ucb.webdav property
+ // the owner property retrieved here is what the other principal send the server
+ // when activating the lock.
+ // See http://tools.ietf.org/html/rfc4918#section-14.17 for details
+ LockFileEntry aLockData;
+ aLockData[LockFileComponent::OOOUSERNAME] = "Unknown user";
+ // This solution works right when the LO user name and the WebDAV user
+ // name are the same.
+ // A better thing to do would be to obtain the 'real' WebDAV user name,
+ // but that's not possible from a WebDAV UCP provider client.
+ LockFileEntry aOwnData = svt::LockFileCommon::GenerateOwnEntry();
+ // use the current LO user name as the system name
+ aLockData[LockFileComponent::SYSUSERNAME]
+ = aOwnData[LockFileComponent::SYSUSERNAME];
+
+ uno::Sequence<css::ucb::Lock> aLocks;
+ // getting the property, send a PROPFIND to the server over the net
+ if (aContentToLock.getPropertyValue("DAV:lockdiscovery") >>= aLocks)
{
- // we need to display the WebDAV user name owning the lock, not the local one
- aLockData[LockFileComponent::OOOUSERNAME] = aOwner;
+ // got at least a lock, show the owner of the first lock returned
+ css::ucb::Lock aLock = aLocks[0];
+ OUString aOwner;
+ if (aLock.Owner >>= aOwner)
+ {
+ // we need to display the WebDAV user name owning the lock, not the local one
+ aLockData[LockFileComponent::OOOUSERNAME] = aOwner;
+ }
}
- }
- if ( !bResult && !bNoUI )
- {
- bUIStatus = ShowLockedDocumentDialog("", aLockData, bLoading, false , true );
+ if (!bNoUI)
+ {
+ bUIStatus = ShowLockedDocumentDialog("", aLockData, bLoading, false,
+ true);
+ }
+
+ if (pLockData)
+ {
+ std::copy(aLockData.begin(), aLockData.end(), pLockData->begin());
+ }
}
}
catch( ucb::InteractiveNetworkWriteException& )
@@ -1397,6 +1409,11 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b
}
else if (bLoading && !bHandleSysLocked)
eResult = LockFileResult::FailedLockFile;
+
+ if (!bResult && pLockData)
+ {
+ std::copy(aData.begin(), aData.end(), pLockData->begin());
+ }
}
}
}
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 770b69d83815..0d9b905e2382 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -188,11 +188,36 @@ void SfxEditDocumentDialog::dispose()
class SfxQueryOpenAsTemplate : public QueryBox
{
public:
- SfxQueryOpenAsTemplate(vcl::Window* pParent, MessBoxStyle nStyle, bool bAllowIgnoreLock);
+ SfxQueryOpenAsTemplate(vcl::Window* pParent, MessBoxStyle nStyle, bool bAllowIgnoreLock, LockFileEntry& rLockData);
+private:
+ static OUString QueryString(bool bAllowIgnoreLock, LockFileEntry& rLockData)
+ {
+ OUString sLockUserData;
+ if (!rLockData[LockFileComponent::OOOUSERNAME].isEmpty())
+ sLockUserData = rLockData[LockFileComponent::OOOUSERNAME];
+ else
+ sLockUserData = rLockData[LockFileComponent::SYSUSERNAME];
+
+ if (!sLockUserData.isEmpty() && !rLockData[LockFileComponent::EDITTIME].isEmpty())
+ sLockUserData += " ( " + rLockData[LockFileComponent::EDITTIME] + " )";
+
+ if (!sLockUserData.isEmpty())
+ sLockUserData = "\n\n" + sLockUserData + "\n";
+
+ const bool bUseLockStr = bAllowIgnoreLock || !sLockUserData.isEmpty();
+
+ OUString sMsg(
+ SfxResId(bUseLockStr ? STR_QUERY_OPENASTEMPLATE_LOCKED : STR_QUERY_OPENASTEMPLATE));
+
+ if (bAllowIgnoreLock)
+ sMsg += "\n\n" + SfxResId(STR_QUERY_OPENASTEMPLATE_ALLOW_IGNORE);
+
+ return sMsg.replaceFirst("%LOCKINFO", sLockUserData);
+ }
};
-SfxQueryOpenAsTemplate::SfxQueryOpenAsTemplate(vcl::Window* pParent, MessBoxStyle nStyle, bool bAllowIgnoreLock)
- : QueryBox(pParent, nStyle, SfxResId(bAllowIgnoreLock ? STR_QUERY_OPENASTEMPLATE_ALLOW_IGNORE : STR_QUERY_OPENASTEMPLATE))
+SfxQueryOpenAsTemplate::SfxQueryOpenAsTemplate(vcl::Window* pParent, MessBoxStyle nStyle, bool bAllowIgnoreLock, LockFileEntry& rLockData)
+ : QueryBox(pParent, nStyle, QueryString(bAllowIgnoreLock, rLockData))
{
AddButton(SfxResId(STR_QUERY_OPENASTEMPLATE_OPENCOPY_BTN), RET_YES,
ButtonDialogFlags::Default | ButtonDialogFlags::OK | ButtonDialogFlags::Focus);
@@ -445,6 +470,7 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
bool bRetryIgnoringLock = false;
bool bOpenTemplate = false;
do {
+ LockFileEntry aLockData;
if ( !pVersionItem )
{
if (bRetryIgnoringLock)
@@ -466,8 +492,10 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
pMed->CompleteReOpen();
if ( nOpenMode & StreamMode::WRITE )
{
- auto eResult = pMed->LockOrigFileOnDemand( true, true, bRetryIgnoringLock );
- bRetryIgnoringLock = eResult == SfxMedium::LockFileResult::FailedLockFile;
+ auto eResult = pMed->LockOrigFileOnDemand(
+ true, true, bRetryIgnoringLock, &aLockData);
+ bRetryIgnoringLock
+ = eResult == SfxMedium::LockFileResult::FailedLockFile;
}
// LockOrigFileOnDemand might set the readonly flag itself, it should be set back
@@ -482,7 +510,8 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
if (nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI())
{
// css::sdbcx::User offering to open it as a template
- ScopedVclPtrInstance<SfxQueryOpenAsTemplate> aBox(&GetWindow(), MessBoxStyle::NONE, bRetryIgnoringLock);
+ ScopedVclPtrInstance<SfxQueryOpenAsTemplate> aBox(&GetWindow(),
+ MessBoxStyle::NONE, bRetryIgnoringLock, aLockData);
short nUserAnswer = aBox->Execute();
bOpenTemplate = RET_YES == nUserAnswer;