LCOV - code coverage report
Current view: top level - sc/source/ui/docshell - documentlinkmgr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 63 120 52.5 %
Date: 2014-11-03 Functions: 12 17 70.6 %
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 <documentlinkmgr.hxx>
      21             : #include <datastream.hxx>
      22             : #include <ddelink.hxx>
      23             : #include <sc.hrc>
      24             : #include <scresid.hxx>
      25             : 
      26             : #include <sfx2/linkmgr.hxx>
      27             : #include <vcl/layout.hxx>
      28             : 
      29             : #include <boost/noncopyable.hpp>
      30             : #include <boost/scoped_ptr.hpp>
      31             : 
      32             : namespace sc {
      33             : 
      34             : struct DocumentLinkManagerImpl : boost::noncopyable
      35             : {
      36             :     ScDocument& mrDoc;
      37             :     SfxObjectShell* mpShell;
      38             :     boost::scoped_ptr<DataStream> mpDataStream;
      39             :     boost::scoped_ptr<sfx2::LinkManager> mpLinkManager;
      40             : 
      41        1390 :     DocumentLinkManagerImpl( ScDocument& rDoc, SfxObjectShell* pShell ) :
      42        1390 :         mrDoc(rDoc), mpShell(pShell), mpDataStream(NULL), mpLinkManager(NULL) {}
      43             : 
      44        1388 :     ~DocumentLinkManagerImpl()
      45        1388 :     {
      46             :         // Shared base links
      47        1388 :         if (mpLinkManager)
      48             :         {
      49        1226 :             sfx2::SvLinkSources aTemp = mpLinkManager->GetServers();
      50        1226 :             for (sfx2::SvLinkSources::const_iterator it = aTemp.begin(); it != aTemp.end(); ++it)
      51           0 :                 (*it)->Closed();
      52             : 
      53        1226 :             if (!mpLinkManager->GetLinks().empty())
      54          22 :                 mpLinkManager->Remove(0, mpLinkManager->GetLinks().size());
      55             :         }
      56        1388 :     }
      57             : };
      58             : 
      59        1390 : DocumentLinkManager::DocumentLinkManager( ScDocument& rDoc, SfxObjectShell* pShell ) :
      60        1390 :     mpImpl(new DocumentLinkManagerImpl(rDoc, pShell)) {}
      61             : 
      62        1388 : DocumentLinkManager::~DocumentLinkManager()
      63             : {
      64        1388 :     delete mpImpl;
      65        1388 : }
      66             : 
      67           0 : void DocumentLinkManager::setDataStream( DataStream* p )
      68             : {
      69           0 :     mpImpl->mpDataStream.reset(p);
      70           0 : }
      71             : 
      72           0 : DataStream* DocumentLinkManager::getDataStream()
      73             : {
      74           0 :     return mpImpl->mpDataStream.get();
      75             : }
      76             : 
      77           0 : const DataStream* DocumentLinkManager::getDataStream() const
      78             : {
      79           0 :     return mpImpl->mpDataStream.get();
      80             : }
      81             : 
      82        3134 : sfx2::LinkManager* DocumentLinkManager::getLinkManager( bool bCreate )
      83             : {
      84        3134 :     if (!mpImpl->mpLinkManager && bCreate && mpImpl->mpShell)
      85        1226 :         mpImpl->mpLinkManager.reset(new sfx2::LinkManager(mpImpl->mpShell));
      86        3134 :     return mpImpl->mpLinkManager.get();
      87             : }
      88             : 
      89         570 : const sfx2::LinkManager* DocumentLinkManager::getExistingLinkManager() const
      90             : {
      91         570 :     return mpImpl->mpLinkManager.get();
      92             : }
      93             : 
      94        1325 : bool DocumentLinkManager::idleCheckLinks()
      95             : {
      96        1325 :     if (!mpImpl->mpLinkManager)
      97           0 :         return false;
      98             : 
      99        1325 :     bool bAnyLeft = false;
     100        1325 :     const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks();
     101        1343 :     for (size_t i = 0, n = rLinks.size(); i < n; ++i)
     102             :     {
     103          18 :         sfx2::SvBaseLink* pBase = *rLinks[i];
     104          18 :         ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
     105          18 :         if (!pDdeLink || !pDdeLink->NeedsUpdate())
     106          18 :             continue;
     107             : 
     108           0 :         pDdeLink->TryUpdate();
     109           0 :         if (pDdeLink->NeedsUpdate()) // Was not successful?
     110           0 :             bAnyLeft = true;
     111             :     }
     112             : 
     113        1325 :     return bAnyLeft;
     114             : }
     115             : 
     116         690 : bool DocumentLinkManager::hasDdeLinks() const
     117             : {
     118         690 :     if (!mpImpl->mpLinkManager)
     119         436 :         return false;
     120             : 
     121         254 :     const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks();
     122         254 :     for (size_t i = 0, n = rLinks.size(); i < n; ++i)
     123             :     {
     124           0 :         sfx2::SvBaseLink* pBase = *rLinks[i];
     125           0 :         if (dynamic_cast<ScDdeLink*>(pBase))
     126           0 :             return true;
     127             :     }
     128             : 
     129         254 :     return false;
     130             : }
     131             : 
     132           0 : bool DocumentLinkManager::updateDdeLinks( vcl::Window* pWin )
     133             : {
     134           0 :     if (!mpImpl->mpLinkManager)
     135           0 :         return false;
     136             : 
     137           0 :     sfx2::LinkManager* pMgr = mpImpl->mpLinkManager.get();
     138           0 :     const sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
     139             : 
     140             :     // If the update takes longer, reset all values so that nothing
     141             :     // old (wrong) is left behind
     142           0 :     bool bAny = false;
     143           0 :     for (size_t i = 0, n = rLinks.size(); i < n; ++i)
     144             :     {
     145           0 :         sfx2::SvBaseLink* pBase = *rLinks[i];
     146           0 :         ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
     147           0 :         if (!pDdeLink)
     148           0 :             continue;
     149             : 
     150           0 :         if (pDdeLink->Update())
     151           0 :             bAny = true;
     152             :         else
     153             :         {
     154             :             // Update failed.  Notify the user.
     155           0 :             OUString aFile = pDdeLink->GetTopic();
     156           0 :             OUString aElem = pDdeLink->GetItem();
     157           0 :             OUString aType = pDdeLink->GetAppl();
     158             : 
     159           0 :             OUStringBuffer aBuf;
     160           0 :             aBuf.append(OUString(ScResId(SCSTR_DDEDOC_NOT_LOADED)));
     161           0 :             aBuf.appendAscii("\n\n");
     162           0 :             aBuf.appendAscii("Source : ");
     163           0 :             aBuf.append(aFile);
     164           0 :             aBuf.appendAscii("\nElement : ");
     165           0 :             aBuf.append(aElem);
     166           0 :             aBuf.appendAscii("\nType : ");
     167           0 :             aBuf.append(aType);
     168           0 :             MessageDialog aBox(pWin, aBuf.makeStringAndClear());
     169           0 :             aBox.Execute();
     170             :         }
     171             :     }
     172             : 
     173           0 :     pMgr->CloseCachedComps();
     174             : 
     175           0 :     return bAny;
     176             : }
     177             : 
     178           4 : bool DocumentLinkManager::updateDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem )
     179             : {
     180           4 :     if (!mpImpl->mpLinkManager)
     181           0 :         return false;
     182             : 
     183           4 :     sfx2::LinkManager* pMgr = mpImpl->mpLinkManager.get();
     184           4 :     const sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
     185             : 
     186           4 :     bool bFound = false;
     187           8 :     for (size_t i = 0, n = rLinks.size(); i < n; ++i)
     188             :     {
     189           4 :         ::sfx2::SvBaseLink* pBase = *rLinks[i];
     190           4 :         ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
     191           4 :         if (!pDdeLink)
     192           0 :             continue;
     193             : 
     194          24 :         if ( OUString(pDdeLink->GetAppl()) == rAppl &&
     195          28 :              OUString(pDdeLink->GetTopic()) == rTopic &&
     196          12 :              OUString(pDdeLink->GetItem()) == rItem )
     197             :         {
     198           4 :             pDdeLink->TryUpdate();
     199           4 :             bFound = true; // Could be multiple (Mode), so continue searching
     200             :         }
     201             :     }
     202             : 
     203           4 :     return bFound;
     204             : }
     205             : 
     206          70 : size_t DocumentLinkManager::getDdeLinkCount() const
     207             : {
     208          70 :     if (!mpImpl->mpLinkManager)
     209           0 :         return 0;
     210             : 
     211          70 :     size_t nDdeCount = 0;
     212          70 :     const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks();
     213          92 :     for (size_t i = 0, n = rLinks.size(); i < n; ++i)
     214             :     {
     215          22 :         ::sfx2::SvBaseLink* pBase = *rLinks[i];
     216          22 :         ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
     217          22 :         if (!pDdeLink)
     218           0 :             continue;
     219             : 
     220          22 :         ++nDdeCount;
     221             :     }
     222             : 
     223          70 :     return nDdeCount;
     224             : }
     225             : 
     226           0 : void DocumentLinkManager::disconnectDdeLinks()
     227             : {
     228           0 :     if (!mpImpl->mpLinkManager)
     229           0 :         return;
     230             : 
     231           0 :     const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks();
     232           0 :     for (size_t i = 0, n = rLinks.size(); i < n; ++i)
     233             :     {
     234           0 :         ::sfx2::SvBaseLink* pBase = *rLinks[i];
     235           0 :         ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
     236           0 :         if (pDdeLink)
     237           0 :             pDdeLink->Disconnect();
     238             :     }
     239             : }
     240             : 
     241         228 : }
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10