LCOV - code coverage report
Current view: top level - framework/source/fwe/helper - titlehelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 281 298 94.3 %
Date: 2014-11-03 Functions: 28 28 100.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 <framework/titlehelper.hxx>
      21             : #include <services.h>
      22             : #include <properties.h>
      23             : 
      24             : #include <com/sun/star/frame/UntitledNumbersConst.hpp>
      25             : #include <com/sun/star/frame/XStorable.hpp>
      26             : #include <com/sun/star/frame/ModuleManager.hpp>
      27             : #include <com/sun/star/container/XNameAccess.hpp>
      28             : #include <com/sun/star/document/XEventBroadcaster.hpp>
      29             : #include <com/sun/star/beans/XMaterialHolder.hpp>
      30             : 
      31             : #include <unotools/configmgr.hxx>
      32             : #include <unotools/bootstrap.hxx>
      33             : #include <comphelper/sequenceashashmap.hxx>
      34             : #include <rtl/ustrbuf.hxx>
      35             : #include <osl/mutex.hxx>
      36             : #include <tools/urlobj.hxx>
      37             : 
      38             : namespace framework{
      39             : 
      40       17852 : TitleHelper::TitleHelper(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
      41             :     : ::cppu::BaseMutex ()
      42             :     , m_xContext        (rxContext)
      43             :     , m_xOwner          ()
      44             :     , m_xUntitledNumbers()
      45             :     , m_xSubTitle       ()
      46             :     , m_bExternalTitle  (false)
      47             :     , m_sTitle          ()
      48             :     , m_nLeasedNumber   (css::frame::UntitledNumbersConst::INVALID_NUMBER)
      49       17852 :     , m_aListener       (m_aMutex)
      50             : {
      51       17852 : }
      52             : 
      53       34214 : TitleHelper::~TitleHelper()
      54             : {
      55       34214 : }
      56             : 
      57       17852 : void TitleHelper::setOwner(const css::uno::Reference< css::uno::XInterface >& xOwner)
      58             : {
      59             :     // SYNCHRONIZED ->
      60       17852 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
      61             : 
      62       17852 :         m_xOwner = xOwner;
      63             : 
      64       17852 :     aLock.clear ();
      65             :     // <- SYNCHRONIZED
      66             : 
      67       17852 :     css::uno::Reference< css::frame::XModel > xModel(xOwner, css::uno::UNO_QUERY);
      68       17852 :     if (xModel.is ())
      69             :     {
      70        6726 :         impl_startListeningForModel (xModel);
      71        6726 :         return;
      72             :     }
      73             : 
      74       11126 :     css::uno::Reference< css::frame::XController > xController(xOwner, css::uno::UNO_QUERY);
      75       11126 :     if (xController.is ())
      76             :     {
      77        5554 :         impl_startListeningForController (xController);
      78        5554 :         return;
      79             :     }
      80             : 
      81        5572 :     css::uno::Reference< css::frame::XFrame > xFrame(xOwner, css::uno::UNO_QUERY);
      82        5572 :     if (xFrame.is ())
      83             :     {
      84        5572 :         impl_startListeningForFrame (xFrame);
      85        5572 :         return;
      86           0 :     }
      87             : }
      88             : 
      89       61122 : OUString SAL_CALL TitleHelper::getTitle()
      90             :     throw (css::uno::RuntimeException, std::exception)
      91             : {
      92             :     // SYNCHRONIZED ->
      93       61122 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
      94             : 
      95             :         // An external title will win always and disable all internal logic about
      96             :         // creating/using a title value.
      97             :         // Even an empty string will be accepted as valid title !
      98       61122 :         if (m_bExternalTitle)
      99          16 :             return m_sTitle;
     100             : 
     101             :         // Title seems to be up-to-date. Return it directly.
     102       61106 :         if (!m_sTitle.isEmpty())
     103       37704 :             return m_sTitle;
     104             : 
     105             :         // Title seems to be unused till now ... do bootstraping
     106       23402 :         impl_updateTitle (true);
     107             : 
     108       23402 :         return m_sTitle;
     109             : 
     110             :     // <- SYNCHRONIZED
     111             : }
     112             : 
     113       12280 : void TitleHelper::connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
     114             : {
     115             :     // SYNCHRONIZED ->
     116       12280 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     117             : 
     118       12280 :         m_xUntitledNumbers = xNumbers;
     119             : 
     120             :     // <- SYNCHRONIZED
     121       12280 : }
     122             : 
     123           4 : void SAL_CALL TitleHelper::setTitle(const OUString& sTitle)
     124             :     throw (css::uno::RuntimeException, std::exception)
     125             : {
     126             :     // SYNCHRONIZED ->
     127           4 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     128             : 
     129           4 :         m_bExternalTitle = true;
     130           4 :         m_sTitle         = sTitle;
     131             : 
     132           4 :     aLock.clear ();
     133             :     // <- SYNCHRONIZED
     134             : 
     135           4 :     impl_sendTitleChangedEvent ();
     136           4 : }
     137             : 
     138       16648 : void SAL_CALL TitleHelper::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
     139             :     throw (css::uno::RuntimeException, std::exception)
     140             : {
     141             :     // container is threadsafe by himself
     142       16648 :     m_aListener.addInterface( cppu::UnoType<css::frame::XTitleChangeListener>::get(), xListener );
     143       16648 : }
     144             : 
     145          18 : void SAL_CALL TitleHelper::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
     146             :     throw (css::uno::RuntimeException, std::exception)
     147             : {
     148             :     // container is threadsafe by himself
     149          18 :     m_aListener.removeInterface( cppu::UnoType<css::frame::XTitleChangeListener>::get(), xListener );
     150          18 : }
     151             : 
     152       14663 : void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEvent)
     153             :     throw (css::uno::RuntimeException, std::exception)
     154             : {
     155             :     // SYNCHRONIZED ->
     156       14663 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     157             : 
     158       29309 :         css::uno::Reference< css::frame::XTitle > xSubTitle(m_xSubTitle.get (), css::uno::UNO_QUERY);
     159             : 
     160       14663 :     aLock.clear ();
     161             :     // <- SYNCHRONIZED
     162             : 
     163       14663 :     if (aEvent.Source != xSubTitle)
     164       14646 :         return;
     165             : 
     166       29326 :     impl_updateTitle ();
     167             : }
     168             : 
     169       70354 : void SAL_CALL TitleHelper::notifyEvent(const css::document::EventObject& aEvent)
     170             :     throw (css::uno::RuntimeException, std::exception)
     171             : {
     172      140708 :     if ( ! aEvent.EventName.equalsIgnoreAsciiCase("OnSaveAsDone")
     173       70336 :       && ! aEvent.EventName.equalsIgnoreAsciiCase("OnModeChanged")
     174      138918 :       && ! aEvent.EventName.equalsIgnoreAsciiCase("OnTitleChanged"))
     175      105358 :         return;
     176             : 
     177             :     // SYNCHRONIZED ->
     178       17675 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     179             : 
     180       35350 :         css::uno::Reference< css::frame::XModel > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     181             : 
     182       17675 :     aLock.clear ();
     183             :     // <- SYNCHRONIZED
     184             : 
     185       35350 :     if (aEvent.Source != xOwner
     186       17675 :         || ((aEvent.EventName.equalsIgnoreAsciiCase("OnModeChanged")
     187       15903 :              || aEvent.EventName.equalsIgnoreAsciiCase("OnTitleChanged"))
     188       17657 :             && !xOwner.is()))
     189             :     {
     190           0 :         return;
     191             :     }
     192             : 
     193       35350 :     impl_updateTitle ();
     194             : }
     195             : 
     196       31278 : void SAL_CALL TitleHelper::frameAction(const css::frame::FrameActionEvent& aEvent)
     197             :     throw(css::uno::RuntimeException, std::exception)
     198             : {
     199             :     // SYNCHRONIZED ->
     200       31278 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     201             : 
     202       62556 :         css::uno::Reference< css::frame::XFrame > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     203             : 
     204       31278 :     aLock.clear ();
     205             :     // <- SYNCHRONIZED
     206             : 
     207       31278 :     if (aEvent.Source != xOwner)
     208       31278 :         return;
     209             : 
     210             :     // we are interested on events only, which must trigger a title bar update
     211             :     // because component was changed.
     212       31278 :     if (
     213       56992 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_ATTACHED  ) ||
     214       51410 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_REATTACHED) ||
     215       25696 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING )
     216             :        )
     217             :     {
     218       11158 :         impl_updateListeningForFrame (xOwner);
     219       11158 :         impl_updateTitle ();
     220       31278 :     }
     221             : }
     222             : 
     223       12289 : void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
     224             :     throw (css::uno::RuntimeException, std::exception)
     225             : {
     226             :     // SYNCHRONIZED ->
     227       12289 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     228       24578 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     229       24578 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     230       12289 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     231       12289 :     aLock.clear ();
     232             :     // <- SYNCHRONIZED
     233             : 
     234       12289 :     if ( ! xOwner.is ())
     235           0 :         return;
     236             : 
     237       12289 :     if (xOwner != aEvent.Source)
     238           0 :         return;
     239             : 
     240       12289 :     if (
     241       12289 :         (xNumbers.is ()                                                   ) &&
     242             :         (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     243             :        )
     244        2081 :        xNumbers->releaseNumber (nLeasedNumber);
     245             : 
     246             :     // SYNCHRONIZED ->
     247       12289 :     aLock.reset ();
     248             : 
     249       12289 :          m_sTitle        = OUString ();
     250       12289 :          m_nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     251             : 
     252       12289 :     aLock.clear ();
     253             :     // <- SYNCHRONIZED
     254             : 
     255       24578 :     impl_sendTitleChangedEvent ();
     256             : }
     257             : 
     258       30085 : void TitleHelper::impl_sendTitleChangedEvent ()
     259             : {
     260             :     // SYNCHRONIZED ->
     261       30085 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     262             : 
     263       50334 :         css::frame::TitleChangedEvent aEvent(m_xOwner.get (), m_sTitle);
     264             : 
     265       30085 :     aLock.clear ();
     266             :     // <- SYNCHRONIZED
     267             : 
     268       30085 :     ::cppu::OInterfaceContainerHelper* pContainer = m_aListener.getContainer( cppu::UnoType<css::frame::XTitleChangeListener>::get());
     269       30085 :     if ( ! pContainer)
     270       39921 :         return;
     271             : 
     272       40498 :     ::cppu::OInterfaceIteratorHelper pIt( *pContainer );
     273       60793 :     while ( pIt.hasMoreElements() )
     274             :     {
     275             :         try
     276             :         {
     277       20295 :             static_cast<css::frame::XTitleChangeListener*>(pIt.next())->titleChanged( aEvent );
     278             :         }
     279          17 :         catch(const css::uno::Exception&)
     280             :         {
     281          17 :             pIt.remove();
     282             :         }
     283       20249 :     }
     284             : }
     285             : 
     286       66898 : void TitleHelper::impl_updateTitle (bool init)
     287             : {
     288             :     // SYNCHRONIZED ->
     289       66898 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     290             : 
     291      133796 :         css::uno::Reference< css::frame::XModel >      xModel     (m_xOwner.get(), css::uno::UNO_QUERY);
     292      133796 :         css::uno::Reference< css::frame::XController > xController(m_xOwner.get(), css::uno::UNO_QUERY);
     293      133779 :         css::uno::Reference< css::frame::XFrame >      xFrame     (m_xOwner.get(), css::uno::UNO_QUERY);
     294             : 
     295       66898 :     aLock.clear ();
     296             :     // <- SYNCHRONIZED
     297             : 
     298       66898 :     if (xModel.is ())
     299             :     {
     300       24405 :         impl_updateTitleForModel (xModel, init);
     301             :     }
     302       42493 :     else if (xController.is ())
     303             :     {
     304       20167 :         impl_updateTitleForController (xController, init);
     305             :     }
     306       22326 :     else if (xFrame.is ())
     307             :     {
     308       22311 :         impl_updateTitleForFrame (xFrame, init);
     309       66898 :     }
     310       66881 : }
     311             : 
     312       24405 : void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel, bool init)
     313             : {
     314             :     // SYNCHRONIZED ->
     315       24405 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     316             : 
     317             :         // external title wont be updated internally !
     318             :         // It has to be set from outside new.
     319       24405 :         if (m_bExternalTitle)
     320          11 :             return;
     321             : 
     322       48788 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     323       48788 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     324       24394 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     325             : 
     326       24394 :     aLock.clear ();
     327             :     // <- SYNCHRONIZED
     328             : 
     329       24394 :     if (
     330       48788 :         ( ! xOwner.is    ()) ||
     331       48788 :         ( ! xNumbers.is  ()) ||
     332       24394 :         ( ! xModel.is    ())
     333             :        )
     334           0 :         return;
     335             : 
     336       48788 :     OUString sTitle;
     337       48788 :     OUString sURL;
     338             : 
     339       48788 :     css::uno::Reference< css::frame::XStorable > xURLProvider(xModel , css::uno::UNO_QUERY);
     340       24394 :     if (xURLProvider.is())
     341       24394 :         sURL = xURLProvider->getLocation ();
     342             : 
     343       24394 :     if (!sURL.isEmpty())
     344             :     {
     345       13334 :         sTitle = impl_convertURL2Title(sURL);
     346       13334 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     347          14 :             xNumbers->releaseNumber (nLeasedNumber);
     348       13334 :         nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     349             :     }
     350             :     else
     351             :     {
     352       11060 :         if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     353        2098 :             nLeasedNumber = xNumbers->leaseNumber (xOwner);
     354             : 
     355       11060 :         OUStringBuffer sNewTitle(256);
     356       11060 :         sNewTitle.append (xNumbers->getUntitledPrefix ());
     357       11060 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     358       11060 :             sNewTitle.append ((::sal_Int32)nLeasedNumber);
     359             :         else
     360           0 :             sNewTitle.appendAscii("?");
     361             : 
     362       11060 :         sTitle = sNewTitle.makeStringAndClear ();
     363             :     }
     364             : 
     365             :     // SYNCHRONIZED ->
     366       24394 :     aLock.reset ();
     367             : 
     368             :     // WORKAROUND: the notification is currently sent always,
     369             :     //             can be changed after shared mode is supported per UNO API
     370       24394 :     bool     bChanged        = !init; // && m_sTitle != sTitle
     371             : 
     372       24394 :              m_sTitle        = sTitle;
     373       24394 :              m_nLeasedNumber = nLeasedNumber;
     374             : 
     375       24394 :     aLock.clear ();
     376             :     // <- SYNCHRONIZED
     377             : 
     378       24394 :     if (bChanged)
     379       42058 :         impl_sendTitleChangedEvent ();
     380             : }
     381             : 
     382       20167 : void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController, bool init)
     383             : {
     384             :     // SYNCHRONIZED ->
     385       20167 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     386             : 
     387             :         // external title wont be updated internally !
     388             :         // It has to be set from outside new.
     389       20167 :         if (m_bExternalTitle)
     390           0 :             return;
     391             : 
     392       40318 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     393       40318 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     394       20167 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     395             : 
     396       20167 :     aLock.clear ();
     397             :     // <- SYNCHRONIZED
     398             : 
     399       20167 :     if (
     400       40334 :         ( ! xOwner.is      ()) ||
     401       40318 :         ( ! xNumbers.is    ()) ||
     402       20151 :         ( ! xController.is ())
     403             :        )
     404          16 :         return;
     405             : 
     406       40302 :     OUStringBuffer sTitle(256);
     407             : 
     408       20151 :     if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     409        5540 :         nLeasedNumber = xNumbers->leaseNumber (xOwner);
     410             : 
     411       40302 :     css::uno::Reference< css::frame::XTitle > xModelTitle(xController->getModel (), css::uno::UNO_QUERY);
     412       20151 :     if (!xModelTitle.is ())
     413        5563 :         xModelTitle.set(xController, css::uno::UNO_QUERY);
     414       20151 :     if (xModelTitle.is ())
     415             :     {
     416       20151 :         sTitle.append      (xModelTitle->getTitle ());
     417       20151 :         if ( nLeasedNumber > 1 )
     418             :         {
     419          64 :             sTitle.appendAscii (" : ");
     420          64 :             sTitle.append      ((::sal_Int32)nLeasedNumber);
     421             :         }
     422             :     }
     423             :     else
     424             :     {
     425           0 :         sTitle.append (xNumbers->getUntitledPrefix ());
     426           0 :         if ( nLeasedNumber > 1 )
     427             :         {
     428           0 :             sTitle.append ((::sal_Int32)nLeasedNumber  );
     429             :         }
     430             :     }
     431             : 
     432             :     // SYNCHRONIZED ->
     433       20151 :     aLock.reset ();
     434             : 
     435       40302 :         OUString sNewTitle       = sTitle.makeStringAndClear ();
     436       20151 :         bool     bChanged        = !init && m_sTitle != sNewTitle;
     437       20151 :                  m_sTitle        = sNewTitle;
     438       20151 :                  m_nLeasedNumber = nLeasedNumber;
     439             : 
     440       20151 :     aLock.clear ();
     441             :     // <- SYNCHRONIZED
     442             : 
     443       20151 :     if (bChanged)
     444       20201 :         impl_sendTitleChangedEvent ();
     445             : }
     446             : 
     447       22311 : void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame, bool init)
     448             : {
     449       22311 :     if ( ! xFrame.is ())
     450           2 :         return;
     451             : 
     452             :     // SYNCHRONIZED ->
     453       22311 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     454             : 
     455             :         // external title wont be updated internally !
     456             :         // It has to be set from outside new.
     457       22311 :         if (m_bExternalTitle)
     458           2 :             return;
     459             : 
     460       22309 :     aLock.clear ();
     461             :     // <- SYNCHRONIZED
     462             : 
     463       44618 :     css::uno::Reference< css::uno::XInterface > xComponent;
     464       22309 :     xComponent = xFrame->getController ();
     465       22309 :     if ( ! xComponent.is ())
     466        5575 :         xComponent = xFrame->getComponentWindow ();
     467             : 
     468       44584 :     OUStringBuffer sTitle (256);
     469             : 
     470       22292 :     impl_appendComponentTitle   (sTitle, xComponent);
     471             : #ifndef MACOSX
     472             :     // fdo#70376: We want the window title to contain just the
     473             :     // document name (from the above "component title").
     474       22292 :     impl_appendProductName      (sTitle);
     475       22292 :     impl_appendModuleName       (sTitle);
     476       22292 :     impl_appendDebugVersion     (sTitle);
     477             : #endif
     478             :     // SYNCHRONIZED ->
     479       22292 :     aLock.reset ();
     480             : 
     481       44584 :         OUString sNewTitle = sTitle.makeStringAndClear ();
     482       22292 :         bool     bChanged  = !init && m_sTitle != sNewTitle;
     483       22292 :                  m_sTitle  = sNewTitle;
     484             : 
     485       22292 :     aLock.clear ();
     486             :     // <- SYNCHRONIZED
     487             : 
     488       22292 :     if (bChanged)
     489       22387 :         impl_sendTitleChangedEvent ();
     490             : }
     491             : 
     492       22292 : void TitleHelper::impl_appendComponentTitle (      OUStringBuffer&                       sTitle    ,
     493             :                                              const css::uno::Reference< css::uno::XInterface >& xComponent)
     494             : {
     495       22292 :     css::uno::Reference< css::frame::XTitle > xTitle(xComponent, css::uno::UNO_QUERY);
     496             : 
     497             :     // Note: Title has to be used (even if it's empty) if the right interface is supported.
     498       22292 :     if (xTitle.is ())
     499       16620 :         sTitle.append (xTitle->getTitle ());
     500       22292 : }
     501             : 
     502       22292 : void TitleHelper::impl_appendProductName (OUStringBuffer& sTitle)
     503             : {
     504       22292 :     OUString name(utl::ConfigManager::getProductName());
     505       22292 :     if (!name.isEmpty())
     506             :     {
     507       22292 :         if (!sTitle.isEmpty())
     508       16618 :             sTitle.append(" - ");
     509       22292 :         sTitle.append(name);
     510       22292 :     }
     511       22292 : }
     512             : 
     513       22292 : void TitleHelper::impl_appendModuleName (OUStringBuffer& sTitle)
     514             : {
     515             :     // SYNCHRONIZED ->
     516       22292 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     517             : 
     518       44584 :         css::uno::Reference< css::uno::XInterface >        xOwner   = m_xOwner.get();
     519       44584 :         css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
     520             : 
     521       22292 :     aLock.clear ();
     522             :     // <- SYNCHRONIZED
     523             : 
     524             :     try
     525             :     {
     526             :         css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
     527       22292 :             css::frame::ModuleManager::create(xContext);
     528             : 
     529       38986 :         const OUString                 sID     = xModuleManager->identify(xOwner);
     530       33388 :               ::comphelper::SequenceAsHashMap lProps  = xModuleManager->getByName (sID);
     531       33388 :         const OUString                 sUIName = lProps.getUnpackedValueOrDefault (OFFICEFACTORY_PROPNAME_UINAME, OUString());
     532             : 
     533             :         // An UIname property is an optional value !
     534             :         // So please add it to the title in case it does really exists only.
     535       16694 :         if (!sUIName.isEmpty())
     536             :         {
     537       16690 :             sTitle.appendAscii (" "    );
     538       16690 :             sTitle.append      (sUIName);
     539       22292 :         }
     540             :     }
     541        5598 :     catch(const css::uno::Exception&)
     542       22292 :     {}
     543       22292 : }
     544             : 
     545             : #ifdef DBG_UTIL
     546             : void TitleHelper::impl_appendDebugVersion (OUStringBuffer& sTitle)
     547             : {
     548             :     OUString version(utl::ConfigManager::getProductVersion());
     549             :     sTitle.append(' ');
     550             :     sTitle.append(version);
     551             :     OUString sDefault("development");
     552             :     OUString sVersion = ::utl::Bootstrap::getBuildIdData(sDefault);
     553             :     sTitle.append(" [");
     554             :     sTitle.append(sVersion);
     555             :     sTitle.append("]");
     556             : }
     557             : #else
     558       22292 : void TitleHelper::impl_appendDebugVersion (OUStringBuffer&)
     559             : {
     560       22292 : }
     561             : #endif
     562             : 
     563        6726 : void TitleHelper::impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel)
     564             : {
     565        6726 :     css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xModel, css::uno::UNO_QUERY);
     566        6726 :     if ( ! xBroadcaster.is ())
     567        6726 :         return;
     568             : 
     569        6726 :     xBroadcaster->addEventListener (static_cast< css::document::XEventListener* >(this));
     570             : }
     571             : 
     572        5554 : void TitleHelper::impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController)
     573             : {
     574        5554 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xController->getModel (), css::uno::UNO_QUERY);
     575        5554 :     impl_setSubTitle (xSubTitle);
     576        5554 : }
     577             : 
     578        5572 : void TitleHelper::impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     579             : {
     580        5572 :     xFrame->addFrameActionListener(this  );
     581        5572 :     impl_updateListeningForFrame  (xFrame);
     582        5572 : }
     583             : 
     584       16730 : void TitleHelper::impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     585             : {
     586       16730 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xFrame->getController (), css::uno::UNO_QUERY);
     587       16730 :     impl_setSubTitle (xSubTitle);
     588       16730 : }
     589             : 
     590       22284 : void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle)
     591             : {
     592             :     // SYNCHRONIZED ->
     593       22284 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     594             : 
     595             :         // ignore duplicate calls. Makes outside using of this helper more easy :-)
     596       33368 :         css::uno::Reference< css::frame::XTitle > xOldSubTitle(m_xSubTitle.get(), css::uno::UNO_QUERY);
     597       22284 :         if (xOldSubTitle == xSubTitle)
     598       33484 :             return;
     599             : 
     600       11084 :         m_xSubTitle = xSubTitle;
     601             : 
     602       11084 :     aLock.clear ();
     603             :     // <- SYNCHRONIZED
     604             : 
     605       22168 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xOldBroadcaster(xOldSubTitle                                          , css::uno::UNO_QUERY      );
     606       22168 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xNewBroadcaster(xSubTitle                                             , css::uno::UNO_QUERY      );
     607       22168 :     css::uno::Reference< css::frame::XTitleChangeListener >    xThis          (static_cast< css::frame::XTitleChangeListener* >(this), css::uno::UNO_QUERY_THROW);
     608             : 
     609       11084 :     if (xOldBroadcaster.is())
     610          18 :         xOldBroadcaster->removeTitleChangeListener (xThis);
     611             : 
     612       11084 :     if (xNewBroadcaster.is())
     613       22166 :         xNewBroadcaster->addTitleChangeListener (xThis);
     614             : }
     615             : 
     616       13334 : OUString TitleHelper::impl_convertURL2Title(const OUString& sURL)
     617             : {
     618       13334 :     INetURLObject   aURL (sURL);
     619       13334 :     OUString sTitle;
     620             : 
     621       13334 :     if (aURL.GetProtocol() == INET_PROT_FILE)
     622             :     {
     623       13334 :         if (aURL.HasMark())
     624           0 :             aURL = INetURLObject(aURL.GetURLNoMark());
     625             : 
     626       13334 :         sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET);
     627             :     }
     628             :     else
     629             :     {
     630           0 :         if (aURL.hasExtension(INetURLObject::LAST_SEGMENT))
     631           0 :             sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET);
     632             : 
     633           0 :         if ( sTitle.isEmpty() )
     634           0 :             sTitle = aURL.GetHostPort(INetURLObject::DECODE_WITH_CHARSET);
     635             : 
     636           0 :         if ( sTitle.isEmpty() )
     637           0 :             sTitle = aURL.GetURLNoPass(INetURLObject::DECODE_WITH_CHARSET);
     638             :     }
     639             : 
     640       13334 :     return sTitle;
     641             : }
     642             : 
     643             : } // namespace framework
     644             : 
     645             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10