LCOV - code coverage report
Current view: top level - framework/source/fwe/helper - titlehelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 286 298 96.0 %
Date: 2015-06-13 12:38:46 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/XDocumentEventBroadcaster.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       10550 : 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       10550 :     , m_aListener       (m_aMutex)
      50             : {
      51       10550 : }
      52             : 
      53       19180 : TitleHelper::~TitleHelper()
      54             : {
      55       19180 : }
      56             : 
      57       10550 : void TitleHelper::setOwner(const css::uno::Reference< css::uno::XInterface >& xOwner)
      58             : {
      59             :     // SYNCHRONIZED ->
      60       10550 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
      61             : 
      62       10550 :         m_xOwner = xOwner;
      63             : 
      64       10550 :     aLock.clear ();
      65             :     // <- SYNCHRONIZED
      66             : 
      67       10550 :     css::uno::Reference< css::frame::XModel > xModel(xOwner, css::uno::UNO_QUERY);
      68       10550 :     if (xModel.is ())
      69             :     {
      70        3990 :         impl_startListeningForModel (xModel);
      71        3990 :         return;
      72             :     }
      73             : 
      74        6560 :     css::uno::Reference< css::frame::XController > xController(xOwner, css::uno::UNO_QUERY);
      75        6560 :     if (xController.is ())
      76             :     {
      77        3278 :         impl_startListeningForController (xController);
      78        3278 :         return;
      79             :     }
      80             : 
      81        3282 :     css::uno::Reference< css::frame::XFrame > xFrame(xOwner, css::uno::UNO_QUERY);
      82        3282 :     if (xFrame.is ())
      83             :     {
      84        3282 :         impl_startListeningForFrame (xFrame);
      85        3282 :         return;
      86           0 :     }
      87             : }
      88             : 
      89       37073 : OUString SAL_CALL TitleHelper::getTitle()
      90             :     throw (css::uno::RuntimeException, std::exception)
      91             : {
      92             :     // SYNCHRONIZED ->
      93       37073 :     ::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       37073 :         if (m_bExternalTitle)
      99           8 :             return m_sTitle;
     100             : 
     101             :         // Title seems to be up-to-date. Return it directly.
     102       37065 :         if (!m_sTitle.isEmpty())
     103       23251 :             return m_sTitle;
     104             : 
     105             :         // Title seems to be unused till now ... do bootstraping
     106       13814 :         impl_updateTitle (true);
     107             : 
     108       13814 :         return m_sTitle;
     109             : 
     110             :     // <- SYNCHRONIZED
     111             : }
     112             : 
     113        7268 : void TitleHelper::connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
     114             : {
     115             :     // SYNCHRONIZED ->
     116        7268 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     117             : 
     118        7268 :         m_xUntitledNumbers = xNumbers;
     119             : 
     120             :     // <- SYNCHRONIZED
     121        7268 : }
     122             : 
     123           2 : void SAL_CALL TitleHelper::setTitle(const OUString& sTitle)
     124             :     throw (css::uno::RuntimeException, std::exception)
     125             : {
     126             :     // SYNCHRONIZED ->
     127           2 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     128             : 
     129           2 :         m_bExternalTitle = true;
     130           2 :         m_sTitle         = sTitle;
     131             : 
     132           2 :     aLock.clear ();
     133             :     // <- SYNCHRONIZED
     134             : 
     135           2 :     impl_sendTitleChangedEvent ();
     136           2 : }
     137             : 
     138        9824 : 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        9824 :     m_aListener.addInterface( cppu::UnoType<css::frame::XTitleChangeListener>::get(), xListener );
     143        9824 : }
     144             : 
     145          16 : 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          16 :     m_aListener.removeInterface( cppu::UnoType<css::frame::XTitleChangeListener>::get(), xListener );
     150          16 : }
     151             : 
     152        8448 : void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEvent)
     153             :     throw (css::uno::RuntimeException, std::exception)
     154             : {
     155             :     // SYNCHRONIZED ->
     156        8448 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     157             : 
     158       16887 :         css::uno::Reference< css::frame::XTitle > xSubTitle(m_xSubTitle.get (), css::uno::UNO_QUERY);
     159             : 
     160        8448 :     aLock.clear ();
     161             :     // <- SYNCHRONIZED
     162             : 
     163        8448 :     if (aEvent.Source != xSubTitle)
     164        8439 :         return;
     165             : 
     166       16896 :     impl_updateTitle ();
     167             : }
     168             : 
     169       39622 : void SAL_CALL TitleHelper::documentEventOccured(const css::document::DocumentEvent& aEvent)
     170             :     throw (css::uno::RuntimeException, std::exception)
     171             : {
     172       79244 :     if ( ! aEvent.EventName.equalsIgnoreAsciiCase("OnSaveAsDone")
     173       39606 :       && ! aEvent.EventName.equalsIgnoreAsciiCase("OnModeChanged")
     174       78171 :       && ! aEvent.EventName.equalsIgnoreAsciiCase("OnTitleChanged"))
     175       58488 :         return;
     176             : 
     177             :     // SYNCHRONIZED ->
     178       10378 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     179             : 
     180       20756 :         css::uno::Reference< css::frame::XModel > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     181             : 
     182       10378 :     aLock.clear ();
     183             :     // <- SYNCHRONIZED
     184             : 
     185       20756 :     if (aEvent.Source != xOwner
     186       10378 :         || ((aEvent.EventName.equalsIgnoreAsciiCase("OnModeChanged")
     187        9321 :              || aEvent.EventName.equalsIgnoreAsciiCase("OnTitleChanged"))
     188       10362 :             && !xOwner.is()))
     189             :     {
     190           0 :         return;
     191             :     }
     192             : 
     193       20756 :     impl_updateTitle ();
     194             : }
     195             : 
     196       18257 : void SAL_CALL TitleHelper::frameAction(const css::frame::FrameActionEvent& aEvent)
     197             :     throw(css::uno::RuntimeException, std::exception)
     198             : {
     199             :     // SYNCHRONIZED ->
     200       18257 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     201             : 
     202       36514 :         css::uno::Reference< css::frame::XFrame > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     203             : 
     204       18257 :     aLock.clear ();
     205             :     // <- SYNCHRONIZED
     206             : 
     207       18257 :     if (aEvent.Source != xOwner)
     208       18257 :         return;
     209             : 
     210             :     // we are interested on events only, which must trigger a title bar update
     211             :     // because component was changed.
     212       18257 :     if (
     213       33237 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_ATTACHED  ) ||
     214       29944 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_REATTACHED) ||
     215       14964 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING )
     216             :        )
     217             :     {
     218        6577 :         impl_updateListeningForFrame (xOwner);
     219        6577 :         impl_updateTitle ();
     220       18257 :     }
     221             : }
     222             : 
     223        7244 : void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
     224             :     throw (css::uno::RuntimeException, std::exception)
     225             : {
     226             :     // SYNCHRONIZED ->
     227        7244 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     228       14488 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     229       14488 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     230        7244 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     231        7244 :     aLock.clear ();
     232             :     // <- SYNCHRONIZED
     233             : 
     234        7244 :     if ( ! xOwner.is ())
     235           0 :         return;
     236             : 
     237        7244 :     if (xOwner != aEvent.Source)
     238           0 :         return;
     239             : 
     240        7244 :     if (
     241        7244 :         (xNumbers.is ()                                                   ) &&
     242             :         (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     243             :        )
     244        1093 :        xNumbers->releaseNumber (nLeasedNumber);
     245             : 
     246             :     // SYNCHRONIZED ->
     247        7244 :     aLock.reset ();
     248             : 
     249        7244 :          m_sTitle        = OUString ();
     250        7244 :          m_nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     251             : 
     252        7244 :     aLock.clear ();
     253             :     // <- SYNCHRONIZED
     254             : 
     255       14488 :     impl_sendTitleChangedEvent ();
     256             : }
     257             : 
     258       17750 : void TitleHelper::impl_sendTitleChangedEvent ()
     259             : {
     260             :     // SYNCHRONIZED ->
     261       17750 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     262             : 
     263       29498 :         css::frame::TitleChangedEvent aEvent(m_xOwner.get (), m_sTitle);
     264             : 
     265       17750 :     aLock.clear ();
     266             :     // <- SYNCHRONIZED
     267             : 
     268       17750 :     ::cppu::OInterfaceContainerHelper* pContainer = m_aListener.getContainer( cppu::UnoType<css::frame::XTitleChangeListener>::get());
     269       17750 :     if ( ! pContainer)
     270       23752 :         return;
     271             : 
     272       23496 :     ::cppu::OInterfaceIteratorHelper pIt( *pContainer );
     273       35284 :     while ( pIt.hasMoreElements() )
     274             :     {
     275             :         try
     276             :         {
     277       11788 :             static_cast<css::frame::XTitleChangeListener*>(pIt.next())->titleChanged( aEvent );
     278             :         }
     279           9 :         catch(const css::uno::Exception&)
     280             :         {
     281           9 :             pIt.remove();
     282             :         }
     283       11748 :     }
     284             : }
     285             : 
     286       39217 : void TitleHelper::impl_updateTitle (bool init)
     287             : {
     288             :     // SYNCHRONIZED ->
     289       39217 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     290             : 
     291       78434 :         css::uno::Reference< css::frame::XModel >      xModel     (m_xOwner.get(), css::uno::UNO_QUERY);
     292       78434 :         css::uno::Reference< css::frame::XController > xController(m_xOwner.get(), css::uno::UNO_QUERY);
     293       78425 :         css::uno::Reference< css::frame::XFrame >      xFrame     (m_xOwner.get(), css::uno::UNO_QUERY);
     294             : 
     295       39217 :     aLock.clear ();
     296             :     // <- SYNCHRONIZED
     297             : 
     298       39217 :     if (xModel.is ())
     299             :     {
     300       14370 :         impl_updateTitleForModel (xModel, init);
     301             :     }
     302       24847 :     else if (xController.is ())
     303             :     {
     304       11669 :         impl_updateTitleForController (xController, init);
     305             :     }
     306       13178 :     else if (xFrame.is ())
     307             :     {
     308       13166 :         impl_updateTitleForFrame (xFrame, init);
     309       39217 :     }
     310       39208 : }
     311             : 
     312       14370 : void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel, bool init)
     313             : {
     314             :     // SYNCHRONIZED ->
     315       14370 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     316             : 
     317             :         // external title wont be updated internally !
     318             :         // It has to be set from outside new.
     319       14370 :         if (m_bExternalTitle)
     320           5 :             return;
     321             : 
     322       28730 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     323       28730 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     324       14365 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     325             : 
     326       14365 :     aLock.clear ();
     327             :     // <- SYNCHRONIZED
     328             : 
     329       14365 :     if (
     330       28730 :         ( ! xOwner.is    ()) ||
     331       28730 :         ( ! xNumbers.is  ()) ||
     332       14365 :         ( ! xModel.is    ())
     333             :        )
     334           0 :         return;
     335             : 
     336       28730 :     OUString sTitle;
     337       28730 :     OUString sURL;
     338             : 
     339       28730 :     css::uno::Reference< css::frame::XStorable > xURLProvider(xModel , css::uno::UNO_QUERY);
     340       14365 :     if (xURLProvider.is())
     341       14365 :         sURL = xURLProvider->getLocation ();
     342             : 
     343       14365 :     if (!sURL.isEmpty())
     344             :     {
     345        8612 :         sTitle = impl_convertURL2Title(sURL);
     346        8612 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     347          10 :             xNumbers->releaseNumber (nLeasedNumber);
     348        8612 :         nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     349             :     }
     350             :     else
     351             :     {
     352        5753 :         if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     353        1106 :             nLeasedNumber = xNumbers->leaseNumber (xOwner);
     354             : 
     355        5753 :         OUStringBuffer sNewTitle(256);
     356        5753 :         sNewTitle.append (xNumbers->getUntitledPrefix ());
     357        5753 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     358        5753 :             sNewTitle.append ((::sal_Int32)nLeasedNumber);
     359             :         else
     360           0 :             sNewTitle.appendAscii("?");
     361             : 
     362        5753 :         sTitle = sNewTitle.makeStringAndClear ();
     363             :     }
     364             : 
     365             :     // SYNCHRONIZED ->
     366       14365 :     aLock.reset ();
     367             : 
     368             :     // WORKAROUND: the notification is currently sent always,
     369             :     //             can be changed after shared mode is supported per UNO API
     370       14365 :     bool     bChanged        = !init; // && m_sTitle != sTitle
     371             : 
     372       14365 :              m_sTitle        = sTitle;
     373       14365 :              m_nLeasedNumber = nLeasedNumber;
     374             : 
     375       14365 :     aLock.clear ();
     376             :     // <- SYNCHRONIZED
     377             : 
     378       14365 :     if (bChanged)
     379       24738 :         impl_sendTitleChangedEvent ();
     380             : }
     381             : 
     382       11669 : void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController, bool init)
     383             : {
     384             :     // SYNCHRONIZED ->
     385       11669 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     386             : 
     387             :         // external title wont be updated internally !
     388             :         // It has to be set from outside new.
     389       11669 :         if (m_bExternalTitle)
     390           0 :             return;
     391             : 
     392       23331 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     393       23331 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     394       11669 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     395             : 
     396       11669 :     aLock.clear ();
     397             :     // <- SYNCHRONIZED
     398             : 
     399       11669 :     if (
     400       23338 :         ( ! xOwner.is      ()) ||
     401       23331 :         ( ! xNumbers.is    ()) ||
     402       11662 :         ( ! xController.is ())
     403             :        )
     404           7 :         return;
     405             : 
     406       23324 :     OUStringBuffer sTitle(256);
     407             : 
     408       11662 :     if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     409        3272 :         nLeasedNumber = xNumbers->leaseNumber (xOwner);
     410             : 
     411       23324 :     css::uno::Reference< css::frame::XTitle > xModelTitle(xController->getModel (), css::uno::UNO_QUERY);
     412       11662 :     if (!xModelTitle.is ())
     413        3288 :         xModelTitle.set(xController, css::uno::UNO_QUERY);
     414       11662 :     if (xModelTitle.is ())
     415             :     {
     416       11662 :         sTitle.append      (xModelTitle->getTitle ());
     417       11662 :         if ( nLeasedNumber > 1 )
     418             :         {
     419          56 :             sTitle.appendAscii (" : ");
     420          56 :             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       11662 :     aLock.reset ();
     434             : 
     435       23324 :         OUString sNewTitle       = sTitle.makeStringAndClear ();
     436       11662 :         bool     bChanged        = !init && m_sTitle != sNewTitle;
     437       11662 :                  m_sTitle        = sNewTitle;
     438       11662 :                  m_nLeasedNumber = nLeasedNumber;
     439             : 
     440       11662 :     aLock.clear ();
     441             :     // <- SYNCHRONIZED
     442             : 
     443       11662 :     if (bChanged)
     444       11720 :         impl_sendTitleChangedEvent ();
     445             : }
     446             : 
     447       13166 : void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame, bool init)
     448             : {
     449       13166 :     if ( ! xFrame.is ())
     450           1 :         return;
     451             : 
     452             :     // SYNCHRONIZED ->
     453       13166 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     454             : 
     455             :         // external title wont be updated internally !
     456             :         // It has to be set from outside new.
     457       13166 :         if (m_bExternalTitle)
     458           1 :             return;
     459             : 
     460       13165 :     aLock.clear ();
     461             :     // <- SYNCHRONIZED
     462             : 
     463       26330 :     css::uno::Reference< css::uno::XInterface > xComponent;
     464       13165 :     xComponent = xFrame->getController ();
     465       13165 :     if ( ! xComponent.is ())
     466        3278 :         xComponent = xFrame->getComponentWindow ();
     467             : 
     468       26312 :     OUStringBuffer sTitle (256);
     469             : 
     470       13156 :     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       13156 :     impl_appendProductName      (sTitle);
     475       13156 :     impl_appendModuleName       (sTitle);
     476       13156 :     impl_appendDebugVersion     (sTitle);
     477             : #endif
     478             :     // SYNCHRONIZED ->
     479       13156 :     aLock.reset ();
     480             : 
     481       26312 :         OUString sNewTitle = sTitle.makeStringAndClear ();
     482       13156 :         bool     bChanged  = !init && m_sTitle != sNewTitle;
     483       13156 :                  m_sTitle  = sNewTitle;
     484             : 
     485       13156 :     aLock.clear ();
     486             :     // <- SYNCHRONIZED
     487             : 
     488       13156 :     if (bChanged)
     489       13238 :         impl_sendTitleChangedEvent ();
     490             : }
     491             : 
     492       13156 : void TitleHelper::impl_appendComponentTitle (      OUStringBuffer&                       sTitle    ,
     493             :                                              const css::uno::Reference< css::uno::XInterface >& xComponent)
     494             : {
     495       13156 :     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       13156 :     if (xTitle.is ())
     499        9830 :         sTitle.append (xTitle->getTitle ());
     500       13156 : }
     501             : 
     502       13156 : void TitleHelper::impl_appendProductName (OUStringBuffer& sTitle)
     503             : {
     504       13156 :     OUString name(utl::ConfigManager::getProductName());
     505       13156 :     if (!name.isEmpty())
     506             :     {
     507       13156 :         if (!sTitle.isEmpty())
     508        9829 :             sTitle.append(" - ");
     509       13156 :         sTitle.append(name);
     510       13156 :     }
     511       13156 : }
     512             : 
     513       13156 : void TitleHelper::impl_appendModuleName (OUStringBuffer& sTitle)
     514             : {
     515             :     // SYNCHRONIZED ->
     516       13156 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     517             : 
     518       26312 :         css::uno::Reference< css::uno::XInterface >        xOwner   = m_xOwner.get();
     519       26312 :         css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
     520             : 
     521       13156 :     aLock.clear ();
     522             :     // <- SYNCHRONIZED
     523             : 
     524             :     try
     525             :     {
     526             :         css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
     527       13156 :             css::frame::ModuleManager::create(xContext);
     528             : 
     529       23023 :         const OUString                 sID     = xModuleManager->identify(xOwner);
     530       19734 :               ::comphelper::SequenceAsHashMap lProps  = xModuleManager->getByName (sID);
     531       19734 :         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        9867 :         if (!sUIName.isEmpty())
     536             :         {
     537        9865 :             sTitle.appendAscii (" "    );
     538        9865 :             sTitle.append      (sUIName);
     539       13156 :         }
     540             :     }
     541        3289 :     catch(const css::uno::Exception&)
     542       13156 :     {}
     543       13156 : }
     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       13156 : void TitleHelper::impl_appendDebugVersion (OUStringBuffer&)
     559             : {
     560       13156 : }
     561             : #endif
     562             : 
     563        3990 : void TitleHelper::impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel)
     564             : {
     565        3990 :     css::uno::Reference< css::document::XDocumentEventBroadcaster > xBroadcaster(xModel, css::uno::UNO_QUERY);
     566        3990 :     if ( ! xBroadcaster.is ())
     567        3990 :         return;
     568             : 
     569        3990 :     xBroadcaster->addDocumentEventListener (static_cast< css::document::XDocumentEventListener* >(this));
     570             : }
     571             : 
     572        3278 : void TitleHelper::impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController)
     573             : {
     574        3278 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xController->getModel (), css::uno::UNO_QUERY);
     575        3278 :     impl_setSubTitle (xSubTitle);
     576        3278 : }
     577             : 
     578        3282 : void TitleHelper::impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     579             : {
     580        3282 :     xFrame->addFrameActionListener(this  );
     581        3282 :     impl_updateListeningForFrame  (xFrame);
     582        3282 : }
     583             : 
     584        9859 : void TitleHelper::impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     585             : {
     586        9859 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xFrame->getController (), css::uno::UNO_QUERY);
     587        9859 :     impl_setSubTitle (xSubTitle);
     588        9859 : }
     589             : 
     590       13137 : void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle)
     591             : {
     592             :     // SYNCHRONIZED ->
     593       13137 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     594             : 
     595             :         // ignore duplicate calls. Makes outside using of this helper more easy :-)
     596       19683 :         css::uno::Reference< css::frame::XTitle > xOldSubTitle(m_xSubTitle.get(), css::uno::UNO_QUERY);
     597       13137 :         if (xOldSubTitle == xSubTitle)
     598       19728 :             return;
     599             : 
     600        6546 :         m_xSubTitle = xSubTitle;
     601             : 
     602        6546 :     aLock.clear ();
     603             :     // <- SYNCHRONIZED
     604             : 
     605       13092 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xOldBroadcaster(xOldSubTitle                                          , css::uno::UNO_QUERY      );
     606       13092 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xNewBroadcaster(xSubTitle                                             , css::uno::UNO_QUERY      );
     607       13092 :     css::uno::Reference< css::frame::XTitleChangeListener >    xThis          (static_cast< css::frame::XTitleChangeListener* >(this), css::uno::UNO_QUERY_THROW);
     608             : 
     609        6546 :     if (xOldBroadcaster.is())
     610          16 :         xOldBroadcaster->removeTitleChangeListener (xThis);
     611             : 
     612        6546 :     if (xNewBroadcaster.is())
     613       13091 :         xNewBroadcaster->addTitleChangeListener (xThis);
     614             : }
     615             : 
     616        8612 : OUString TitleHelper::impl_convertURL2Title(const OUString& sURL)
     617             : {
     618        8612 :     INetURLObject   aURL (sURL);
     619        8612 :     OUString sTitle;
     620             : 
     621        8612 :     if (aURL.GetProtocol() == INetProtocol::File)
     622             :     {
     623        8605 :         if (aURL.HasMark())
     624           0 :             aURL = INetURLObject(aURL.GetURLNoMark());
     625             : 
     626        8605 :         sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET);
     627             :     }
     628             :     else
     629             :     {
     630           7 :         if (aURL.hasExtension(INetURLObject::LAST_SEGMENT))
     631           0 :             sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET);
     632             : 
     633           7 :         if ( sTitle.isEmpty() )
     634           7 :             sTitle = aURL.GetHostPort(INetURLObject::DECODE_WITH_CHARSET);
     635             : 
     636           7 :         if ( sTitle.isEmpty() )
     637           7 :             sTitle = aURL.GetURLNoPass(INetURLObject::DECODE_WITH_CHARSET);
     638             :     }
     639             : 
     640        8612 :     return sTitle;
     641             : }
     642             : 
     643             : } // namespace framework
     644             : 
     645             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11