LCOV - code coverage report
Current view: top level - uui/source - iahndl-locking.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 116 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11