LCOV - code coverage report
Current view: top level - sw/source/core/doc - visiturl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 51 70.6 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 45 124 36.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <sfx2/docfile.hxx>
      30                 :            : #include <svl/inethist.hxx>
      31                 :            : #include <fmtinfmt.hxx>
      32                 :            : #include <txtinet.hxx>
      33                 :            : #include <doc.hxx>
      34                 :            : #include <visiturl.hxx>
      35                 :            : #include <hints.hxx>
      36                 :            : #include <ndtxt.hxx>
      37                 :            : #include <editsh.hxx>
      38                 :            : #include <docsh.hxx>
      39                 :            : 
      40                 :            : 
      41                 :         32 : SwURLStateChanged::SwURLStateChanged( const SwDoc* pD )
      42                 :         32 :     : pDoc( pD )
      43                 :            : {
      44 [ +  - ][ +  - ]:         32 :     StartListening( *INetURLHistory::GetOrCreate() );
      45                 :         32 : }
      46                 :            : 
      47                 :         32 : SwURLStateChanged::~SwURLStateChanged()
      48                 :            : {
      49 [ +  - ][ +  - ]:         32 :     EndListening( *INetURLHistory::GetOrCreate() );
      50         [ -  + ]:         64 : }
      51                 :            : 
      52                 :          6 : void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint )
      53                 :            : {
      54 [ +  - ][ +  - ]:          6 :     if( rHint.ISA( INetURLHistoryHint ) && pDoc->GetCurrentViewShell() )    //swmod 071108//swmod 071225
                 [ +  - ]
      55                 :            :     {
      56                 :            :         // This URL has been changed:
      57                 :          6 :         const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
      58 [ +  - ][ +  - ]:          6 :         String sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;
                 [ +  - ]
      59                 :            : 
      60         [ +  - ]:          6 :         SwEditShell* pESh = pDoc->GetEditShell();
      61                 :            : 
      62         [ +  - ]:         18 :         if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
           [ +  -  +  - ]
                 [ +  - ]
      63                 :            :             // If this is our Doc, we can also have local jumps!
      64 [ +  - ][ +  - ]:         12 :             pDoc->GetDocShell()->GetMedium()->GetName().equals(sURL) )
         [ +  - ][ #  # ]
      65 [ +  - ][ +  - ]:          6 :             (sBkmk = pIURL->GetMark()).Insert( INET_MARK_TOKEN, 0 );
                 [ +  - ]
      66                 :            : 
      67                 :          6 :         sal_Bool bAction = sal_False, bUnLockView = sal_False;
      68                 :            :         const SwFmtINetFmt* pItem;
      69                 :            :         const SwTxtINetFmt* pTxtAttr;
      70                 :            :         const SwTxtNode* pTxtNd;
      71         [ +  - ]:          6 :         sal_uInt32 n, nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
      72         [ +  + ]:         21 :         for( n = 0; n < nMaxItems; ++n )
      73 [ +  - ][ +  + ]:         33 :             if( 0 != (pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem2(
           [ +  -  +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ -  + ]
      74                 :         15 :                 RES_TXTATR_INETFMT, n ) ) &&
      75         [ +  - ]:          6 :                 ( pItem->GetValue() == sURL ||
      76         [ +  - ]:         12 :                     ( sBkmk.Len() && pItem->GetValue() == sBkmk )) &&
      77                 :            :                 0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
      78                 :            :                 0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) )
      79                 :            :             {
      80 [ #  # ][ #  # ]:          0 :                 if( !bAction && pESh )
      81                 :            :                 {
      82         [ #  # ]:          0 :                     pESh->StartAllAction();
      83                 :          0 :                     bAction = sal_True;
      84                 :          0 :                     bUnLockView = !pESh->IsViewLocked();
      85                 :          0 :                     pESh->LockView( sal_True );
      86                 :            :                 }
      87                 :          0 :                 const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisitedValid( false );
      88                 :          0 :                 const SwTxtAttr* pAttr = pTxtAttr;
      89                 :          0 :                 SwUpdateAttr aUpdateAttr( *pAttr->GetStart(),
      90         [ #  # ]:          0 :                                           *pAttr->GetEnd(),
      91         [ #  # ]:          0 :                                           RES_FMT_CHG );
      92 [ #  # ][ #  # ]:          0 :                 ((SwTxtNode*)pTxtNd)->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
      93                 :            :             }
      94                 :            : 
      95         [ -  + ]:          6 :         if( bAction )
      96         [ #  # ]:          0 :             pESh->EndAllAction();
      97         [ -  + ]:          6 :          if( bUnLockView )
      98 [ +  - ][ +  - ]:          6 :              pESh->LockView( sal_False );
      99                 :            :     }
     100                 :          6 : }
     101                 :            : 
     102                 :            : // Check if the URL has been visited before. Via the Doc, if only one Bookmark is set
     103                 :            : // We need to put the Doc's name before it!
     104                 :        114 : sal_Bool SwDoc::IsVisitedURL( const String& rURL ) const
     105                 :            : {
     106                 :        114 :     sal_Bool bRet = sal_False;
     107         [ +  + ]:        114 :     if( rURL.Len() )
     108                 :            :     {
     109                 :        106 :         INetURLHistory *pHist = INetURLHistory::GetOrCreate();
     110 [ #  # ][ #  # ]:        106 :         if( '#' == rURL.GetChar( 0 ) && pDocShell && pDocShell->GetMedium() )
         [ -  + ][ -  + ]
     111                 :            :         {
     112 [ #  # ][ #  # ]:          0 :             INetURLObject aIObj( pDocShell->GetMedium()->GetURLObject() );
     113 [ #  # ][ #  # ]:          0 :             aIObj.SetMark( rURL.Copy( 1 ) );
         [ #  # ][ #  # ]
     114 [ #  # ][ #  # ]:          0 :             bRet = pHist->QueryUrl( aIObj );
     115                 :            :         }
     116                 :            :         else
     117                 :        106 :             bRet = pHist->QueryUrl( rURL );
     118                 :            : 
     119                 :            :         // We also want to be informed about status updates in the History
     120         [ +  + ]:        106 :         if( !pURLStateChgd )
     121                 :            :         {
     122                 :         32 :             SwDoc* pD = (SwDoc*)this;
     123         [ +  - ]:         32 :             pD->pURLStateChgd = new SwURLStateChanged( this );
     124                 :            :         }
     125                 :            :     }
     126                 :        114 :     return bRet;
     127                 :            : }
     128                 :            : 
     129                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10