LCOV - code coverage report
Current view: top level - uui/source - iahndl-locking.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 116 0.9 %
Date: 2014-11-03 Functions: 2 8 25.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             :             boost::scoped_ptr< OpenLockedQueryBox > xDialog(new OpenLockedQueryBox(
      97           0 :                             pParent, xManager.get(), aMessage ) );
      98           0 :             nResult = xDialog->Execute();
      99             :         }
     100           0 :         else if ( nMode == UUI_DOC_SAVE_LOCK )
     101             :         {
     102           0 :             aArguments.push_back( !aInfo.isEmpty()
     103             :                                   ? aInfo
     104             :                                   : ResId( STR_UNKNOWNUSER,
     105           0 :                                                *xManager.get() ).toString() );
     106           0 :             aMessage = ResId(STR_TRYLATER_MSG, *xManager.get()).toString();
     107           0 :             aMessage = UUIInteractionHelper::replaceMessageWithArguments(
     108           0 :                 aMessage, aArguments );
     109             : 
     110             :             boost::scoped_ptr< TryLaterQueryBox > xDialog(
     111           0 :                 new TryLaterQueryBox( pParent, xManager.get(), aMessage ) );
     112           0 :             nResult = xDialog->Execute();
     113             :         }
     114           0 :         else if ( nMode == UUI_DOC_OWN_LOAD_LOCK ||
     115             :                   nMode == UUI_DOC_OWN_SAVE_LOCK )
     116             :         {
     117           0 :             aArguments.push_back( aInfo );
     118           0 :             aMessage = ResId(nMode == UUI_DOC_OWN_SAVE_LOCK
     119             :                                           ? STR_ALREADYOPEN_SAVE_MSG
     120             :                                           : STR_ALREADYOPEN_MSG,
     121           0 :                                       *xManager.get() ).toString();
     122           0 :             aMessage = UUIInteractionHelper::replaceMessageWithArguments(
     123           0 :                 aMessage, aArguments );
     124             : 
     125             :             boost::scoped_ptr< AlreadyOpenQueryBox > xDialog(
     126             :                 new AlreadyOpenQueryBox( pParent,
     127             :                                          xManager.get(),
     128             :                                          aMessage,
     129           0 :                                          nMode == UUI_DOC_OWN_SAVE_LOCK ) );
     130           0 :             nResult = xDialog->Execute();
     131             :         }
     132             : 
     133           0 :         if ( nResult == RET_YES )
     134           0 :             xApprove->select();
     135           0 :         else if ( nResult == RET_NO )
     136           0 :             xDisapprove->select();
     137             :         else
     138           0 :             xAbort->select();
     139             :     }
     140           0 :     catch (std::bad_alloc const &)
     141             :     {
     142           0 :         throw uno::RuntimeException("out of memory");
     143           0 :     }
     144             : }
     145             : 
     146             : void
     147           0 : handleChangedByOthersRequest_(
     148             :     vcl::Window * pParent,
     149             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
     150             :         rContinuations )
     151             : {
     152           0 :     uno::Reference< task::XInteractionApprove > xApprove;
     153           0 :     uno::Reference< task::XInteractionAbort > xAbort;
     154           0 :     getContinuations(rContinuations, &xApprove, &xAbort);
     155             : 
     156           0 :     if ( !xApprove.is() || !xAbort.is() )
     157           0 :         return;
     158             : 
     159             :     try
     160             :     {
     161           0 :         SolarMutexGuard aGuard;
     162           0 :         boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
     163           0 :         if (!xManager.get())
     164           0 :             return;
     165             : 
     166             :         boost::scoped_ptr< FileChangedQueryBox > xDialog(
     167           0 :             new FileChangedQueryBox( pParent, xManager.get() ) );
     168           0 :         sal_Int32 nResult = xDialog->Execute();
     169             : 
     170           0 :         if ( nResult == RET_YES )
     171           0 :             xApprove->select();
     172             :         else
     173           0 :             xAbort->select();
     174             :     }
     175           0 :     catch (std::bad_alloc const &)
     176             :     {
     177           0 :         throw uno::RuntimeException("out of memory");
     178           0 :     }
     179             : }
     180             : 
     181             : void
     182           0 : handleLockFileIgnoreRequest_(
     183             :     vcl::Window * pParent,
     184             :     uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
     185             :         rContinuations )
     186             : {
     187           0 :     uno::Reference< task::XInteractionApprove > xApprove;
     188           0 :     uno::Reference< task::XInteractionAbort > xAbort;
     189           0 :     getContinuations(rContinuations, &xApprove, &xAbort);
     190             : 
     191           0 :     if ( !xApprove.is() || !xAbort.is() )
     192           0 :         return;
     193             : 
     194             :     try
     195             :     {
     196           0 :         SolarMutexGuard aGuard;
     197           0 :         boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
     198           0 :         if (!xManager.get())
     199           0 :             return;
     200             : 
     201             :         boost::scoped_ptr< LockFailedQueryBox > xDialog(
     202           0 :             new LockFailedQueryBox( pParent, xManager.get() ) );
     203           0 :         sal_Int32 nResult = xDialog->Execute();
     204             : 
     205           0 :         if ( nResult == RET_OK )
     206           0 :             xApprove->select();
     207             :         else
     208           0 :             xAbort->select();
     209             :     }
     210           0 :     catch (std::bad_alloc const &)
     211             :     {
     212           0 :         throw uno::RuntimeException("out of memory");
     213           0 :     }
     214             : }
     215             : 
     216             : } // namespace
     217             : 
     218             : bool
     219           0 : UUIInteractionHelper::handleLockedDocumentRequest(
     220             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     221             : {
     222           0 :     uno::Any aAnyRequest(rRequest->getRequest());
     223             : 
     224           0 :     document::LockedDocumentRequest aLockedDocumentRequest;
     225           0 :     if (aAnyRequest >>= aLockedDocumentRequest )
     226             :     {
     227             :         handleLockedDocumentRequest_( getParentProperty(),
     228             :                                       aLockedDocumentRequest.DocumentURL,
     229             :                                       aLockedDocumentRequest.UserInfo,
     230           0 :                                       rRequest->getContinuations(),
     231           0 :                                       UUI_DOC_LOAD_LOCK );
     232           0 :         return true;
     233             :     }
     234             : 
     235           0 :     document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest;
     236           0 :     if (aAnyRequest >>= aOwnLockOnDocumentRequest )
     237             :     {
     238             :         handleLockedDocumentRequest_( getParentProperty(),
     239             :                                       aOwnLockOnDocumentRequest.DocumentURL,
     240             :                                       aOwnLockOnDocumentRequest.TimeInfo,
     241           0 :                                       rRequest->getContinuations(),
     242             :                                       aOwnLockOnDocumentRequest.IsStoring
     243             :                                           ? UUI_DOC_OWN_SAVE_LOCK
     244           0 :                                           : UUI_DOC_OWN_LOAD_LOCK );
     245           0 :         return true;
     246             :     }
     247             : 
     248           0 :     document::LockedOnSavingRequest aLockedOnSavingRequest;
     249           0 :     if (aAnyRequest >>= aLockedOnSavingRequest )
     250             :     {
     251             :         handleLockedDocumentRequest_( getParentProperty(),
     252             :                                       aLockedOnSavingRequest.DocumentURL,
     253             :                                       aLockedOnSavingRequest.UserInfo,
     254           0 :                                       rRequest->getContinuations(),
     255           0 :                                       UUI_DOC_SAVE_LOCK );
     256           0 :         return true;
     257             :     }
     258           0 :     return false;
     259             : }
     260             : 
     261             : bool
     262           0 : UUIInteractionHelper::handleChangedByOthersRequest(
     263             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     264             : {
     265           0 :     uno::Any aAnyRequest(rRequest->getRequest());
     266             : 
     267           0 :     document::ChangedByOthersRequest aChangedByOthersRequest;
     268           0 :     if (aAnyRequest >>= aChangedByOthersRequest )
     269             :     {
     270             :         handleChangedByOthersRequest_( getParentProperty(),
     271           0 :                                        rRequest->getContinuations() );
     272           0 :         return true;
     273             :     }
     274           0 :     return false;
     275             : }
     276             : 
     277             : bool
     278           0 : UUIInteractionHelper::handleLockFileIgnoreRequest(
     279             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     280             : {
     281           0 :     uno::Any aAnyRequest(rRequest->getRequest());
     282             : 
     283           0 :     document::LockFileIgnoreRequest aLockFileIgnoreRequest;
     284           0 :     if (aAnyRequest >>= aLockFileIgnoreRequest )
     285             :     {
     286             :         handleLockFileIgnoreRequest_( getParentProperty(),
     287           0 :                                       rRequest->getContinuations() );
     288           0 :         return true;
     289             :     }
     290           0 :     return false;
     291         180 : }
     292             : 
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10