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

Generated by: LCOV version 1.10