1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include <memory> 25 26 #include "com/sun/star/document/ChangedByOthersRequest.hpp" 27 #include "com/sun/star/document/LockedDocumentRequest.hpp" 28 #include "com/sun/star/document/LockedOnSavingRequest.hpp" 29 #include "com/sun/star/document/LockFileIgnoreRequest.hpp" 30 #include "com/sun/star/document/OwnLockOnDocumentRequest.hpp" 31 #include "com/sun/star/task/XInteractionApprove.hpp" 32 #include "com/sun/star/task/XInteractionDisapprove.hpp" 33 #include "com/sun/star/task/XInteractionAbort.hpp" 34 #include "com/sun/star/task/XInteractionRequest.hpp" 35 36 #include "vos/mutex.hxx" 37 #include "vcl/svapp.hxx" 38 #include "vcl/msgbox.hxx" 39 40 #include "ids.hrc" 41 #include "getcontinuations.hxx" 42 #include "openlocked.hxx" 43 #include "trylater.hxx" 44 #include "alreadyopen.hxx" 45 #include "filechanged.hxx" 46 #include "lockfailed.hxx" 47 48 #include "iahndl.hxx" 49 50 #define UUI_DOC_LOAD_LOCK 0 51 #define UUI_DOC_OWN_LOAD_LOCK 1 52 #define UUI_DOC_SAVE_LOCK 2 53 #define UUI_DOC_OWN_SAVE_LOCK 3 54 55 using namespace com::sun::star; 56 57 namespace { 58 59 void 60 handleLockedDocumentRequest_( 61 Window * pParent, 62 const ::rtl::OUString& aDocumentURL, 63 const ::rtl::OUString& aInfo, 64 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & 65 rContinuations, 66 sal_uInt16 nMode ) 67 SAL_THROW((uno::RuntimeException)) 68 { 69 uno::Reference< task::XInteractionApprove > xApprove; 70 uno::Reference< task::XInteractionDisapprove > xDisapprove; 71 uno::Reference< task::XInteractionAbort > xAbort; 72 getContinuations(rContinuations, &xApprove, &xDisapprove, &xAbort); 73 74 if ( !xApprove.is() || !xDisapprove.is() || !xAbort.is() ) 75 return; 76 77 try 78 { 79 vos::OGuard aGuard(Application::GetSolarMutex()); 80 std::auto_ptr< ResMgr > xManager( 81 ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui))); 82 if (!xManager.get()) 83 return; 84 85 ::rtl::OUString aMessage; 86 std::vector< rtl::OUString > aArguments; 87 aArguments.push_back( aDocumentURL ); 88 89 sal_Int32 nResult = RET_CANCEL; 90 if ( nMode == UUI_DOC_LOAD_LOCK ) 91 { 92 aArguments.push_back( aInfo.getLength() 93 ? aInfo 94 : ::rtl::OUString( String( 95 ResId( STR_UNKNOWNUSER, 96 *xManager.get() ) ) ) ); 97 aMessage = String( ResId( STR_OPENLOCKED_MSG, *xManager.get() ) ); 98 aMessage = UUIInteractionHelper::replaceMessageWithArguments( 99 aMessage, aArguments ); 100 101 std::auto_ptr< OpenLockedQueryBox > xDialog(new OpenLockedQueryBox( 102 pParent, xManager.get(), aMessage ) ); 103 nResult = xDialog->Execute(); 104 } 105 else if ( nMode == UUI_DOC_SAVE_LOCK ) 106 { 107 aArguments.push_back( aInfo.getLength() 108 ? aInfo 109 : ::rtl::OUString( String( 110 ResId( STR_UNKNOWNUSER, 111 *xManager.get() ) ) ) ); 112 aMessage = String( ResId( STR_TRYLATER_MSG, *xManager.get() ) ); 113 aMessage = UUIInteractionHelper::replaceMessageWithArguments( 114 aMessage, aArguments ); 115 116 std::auto_ptr< TryLaterQueryBox > xDialog( 117 new TryLaterQueryBox( pParent, xManager.get(), aMessage ) ); 118 nResult = xDialog->Execute(); 119 } 120 else if ( nMode == UUI_DOC_OWN_LOAD_LOCK || 121 nMode == UUI_DOC_OWN_SAVE_LOCK ) 122 { 123 aArguments.push_back( aInfo ); 124 aMessage = String( ResId( nMode == UUI_DOC_OWN_SAVE_LOCK 125 ? STR_ALREADYOPEN_SAVE_MSG 126 : STR_ALREADYOPEN_MSG, 127 *xManager.get() ) ); 128 aMessage = UUIInteractionHelper::replaceMessageWithArguments( 129 aMessage, aArguments ); 130 131 std::auto_ptr< AlreadyOpenQueryBox > xDialog( 132 new AlreadyOpenQueryBox( pParent, 133 xManager.get(), 134 aMessage, 135 nMode == UUI_DOC_OWN_SAVE_LOCK ) ); 136 nResult = xDialog->Execute(); 137 } 138 139 if ( nResult == RET_YES ) 140 xApprove->select(); 141 else if ( nResult == RET_NO ) 142 xDisapprove->select(); 143 else 144 xAbort->select(); 145 } 146 catch (std::bad_alloc const &) 147 { 148 throw uno::RuntimeException( 149 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")), 150 uno::Reference< uno::XInterface >()); 151 } 152 } 153 154 void 155 handleChangedByOthersRequest_( 156 Window * pParent, 157 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & 158 rContinuations ) 159 SAL_THROW((uno::RuntimeException)) 160 { 161 uno::Reference< task::XInteractionApprove > xApprove; 162 uno::Reference< task::XInteractionAbort > xAbort; 163 getContinuations(rContinuations, &xApprove, &xAbort); 164 165 if ( !xApprove.is() || !xAbort.is() ) 166 return; 167 168 try 169 { 170 vos::OGuard aGuard(Application::GetSolarMutex()); 171 std::auto_ptr< ResMgr > xManager( 172 ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui))); 173 if (!xManager.get()) 174 return; 175 176 std::auto_ptr< FileChangedQueryBox > xDialog( 177 new FileChangedQueryBox( pParent, xManager.get() ) ); 178 sal_Int32 nResult = xDialog->Execute(); 179 180 if ( nResult == RET_YES ) 181 xApprove->select(); 182 else 183 xAbort->select(); 184 } 185 catch (std::bad_alloc const &) 186 { 187 throw uno::RuntimeException( 188 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")), 189 uno::Reference< uno::XInterface >()); 190 } 191 } 192 193 void 194 handleLockFileIgnoreRequest_( 195 Window * pParent, 196 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & 197 rContinuations ) 198 SAL_THROW((uno::RuntimeException)) 199 { 200 uno::Reference< task::XInteractionApprove > xApprove; 201 uno::Reference< task::XInteractionAbort > xAbort; 202 getContinuations(rContinuations, &xApprove, &xAbort); 203 204 if ( !xApprove.is() || !xAbort.is() ) 205 return; 206 207 try 208 { 209 vos::OGuard aGuard(Application::GetSolarMutex()); 210 std::auto_ptr< ResMgr > xManager( 211 ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui))); 212 if (!xManager.get()) 213 return; 214 215 std::auto_ptr< LockFailedQueryBox > xDialog( 216 new LockFailedQueryBox( pParent, xManager.get() ) ); 217 sal_Int32 nResult = xDialog->Execute(); 218 219 if ( nResult == RET_OK ) 220 xApprove->select(); 221 else 222 xAbort->select(); 223 } 224 catch (std::bad_alloc const &) 225 { 226 throw uno::RuntimeException( 227 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")), 228 uno::Reference< uno::XInterface >()); 229 } 230 } 231 232 } // namespace 233 234 bool 235 UUIInteractionHelper::handleLockedDocumentRequest( 236 uno::Reference< task::XInteractionRequest > const & rRequest) 237 SAL_THROW((::com::sun::star::uno::RuntimeException)) 238 { 239 uno::Any aAnyRequest(rRequest->getRequest()); 240 241 document::LockedDocumentRequest aLockedDocumentRequest; 242 if (aAnyRequest >>= aLockedDocumentRequest ) 243 { 244 handleLockedDocumentRequest_( getParentProperty(), 245 aLockedDocumentRequest.DocumentURL, 246 aLockedDocumentRequest.UserInfo, 247 rRequest->getContinuations(), 248 UUI_DOC_LOAD_LOCK ); 249 return true; 250 } 251 252 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest; 253 if (aAnyRequest >>= aOwnLockOnDocumentRequest ) 254 { 255 handleLockedDocumentRequest_( getParentProperty(), 256 aOwnLockOnDocumentRequest.DocumentURL, 257 aOwnLockOnDocumentRequest.TimeInfo, 258 rRequest->getContinuations(), 259 aOwnLockOnDocumentRequest.IsStoring 260 ? UUI_DOC_OWN_SAVE_LOCK 261 : UUI_DOC_OWN_LOAD_LOCK ); 262 return true; 263 } 264 265 document::LockedOnSavingRequest aLockedOnSavingRequest; 266 if (aAnyRequest >>= aLockedOnSavingRequest ) 267 { 268 handleLockedDocumentRequest_( getParentProperty(), 269 aLockedOnSavingRequest.DocumentURL, 270 aLockedOnSavingRequest.UserInfo, 271 rRequest->getContinuations(), 272 UUI_DOC_SAVE_LOCK ); 273 return true; 274 } 275 return false; 276 } 277 278 bool 279 UUIInteractionHelper::handleChangedByOthersRequest( 280 uno::Reference< task::XInteractionRequest > const & rRequest) 281 SAL_THROW((uno::RuntimeException)) 282 { 283 uno::Any aAnyRequest(rRequest->getRequest()); 284 285 document::ChangedByOthersRequest aChangedByOthersRequest; 286 if (aAnyRequest >>= aChangedByOthersRequest ) 287 { 288 handleChangedByOthersRequest_( getParentProperty(), 289 rRequest->getContinuations() ); 290 return true; 291 } 292 return false; 293 } 294 295 bool 296 UUIInteractionHelper::handleLockFileIgnoreRequest( 297 uno::Reference< task::XInteractionRequest > const & rRequest) 298 SAL_THROW((uno::RuntimeException)) 299 { 300 uno::Any aAnyRequest(rRequest->getRequest()); 301 302 document::LockFileIgnoreRequest aLockFileIgnoreRequest; 303 if (aAnyRequest >>= aLockFileIgnoreRequest ) 304 { 305 handleLockFileIgnoreRequest_( getParentProperty(), 306 rRequest->getContinuations() ); 307 return true; 308 } 309 return false; 310 } 311 312 313