LCOV - code coverage report
Current view: top level - framework/source/fwe/helper - titlehelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 281 298 94.3 %
Date: 2014-04-11 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        6714 : 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        6714 :     , m_aListener       (m_aMutex)
      50             : {
      51        6714 : }
      52             : 
      53       12874 : TitleHelper::~TitleHelper()
      54             : {
      55       12874 : }
      56             : 
      57        6714 : void TitleHelper::setOwner(const css::uno::Reference< css::uno::XInterface >& xOwner)
      58             : {
      59             :     // SYNCHRONIZED ->
      60        6714 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
      61             : 
      62        6714 :         m_xOwner = xOwner;
      63             : 
      64        6714 :     aLock.clear ();
      65             :     // <- SYNCHRONIZED
      66             : 
      67        6714 :     css::uno::Reference< css::frame::XModel > xModel(xOwner, css::uno::UNO_QUERY);
      68        6714 :     if (xModel.is ())
      69             :     {
      70        2574 :         impl_startListeningForModel (xModel);
      71        2574 :         return;
      72             :     }
      73             : 
      74        4140 :     css::uno::Reference< css::frame::XController > xController(xOwner, css::uno::UNO_QUERY);
      75        4140 :     if (xController.is ())
      76             :     {
      77        2063 :         impl_startListeningForController (xController);
      78        2063 :         return;
      79             :     }
      80             : 
      81        2077 :     css::uno::Reference< css::frame::XFrame > xFrame(xOwner, css::uno::UNO_QUERY);
      82        2077 :     if (xFrame.is ())
      83             :     {
      84        2077 :         impl_startListeningForFrame (xFrame);
      85        2077 :         return;
      86           0 :     }
      87             : }
      88             : 
      89       22922 : OUString SAL_CALL TitleHelper::getTitle()
      90             :     throw (css::uno::RuntimeException, std::exception)
      91             : {
      92             :     // SYNCHRONIZED ->
      93       22922 :     ::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       22922 :         if (m_bExternalTitle)
      99           8 :             return m_sTitle;
     100             : 
     101             :         // Title seems to be up-to-date. Return it directly.
     102       22914 :         if (!m_sTitle.isEmpty())
     103       14142 :             return m_sTitle;
     104             : 
     105             :         // Title seems to be unused till now ... do bootstraping
     106        8772 :         impl_updateTitle (true);
     107             : 
     108        8772 :         return m_sTitle;
     109             : 
     110             :     // <- SYNCHRONIZED
     111             : }
     112             : 
     113        4637 : void TitleHelper::connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
     114             : {
     115             :     // SYNCHRONIZED ->
     116        4637 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     117             : 
     118        4637 :         m_xUntitledNumbers = xNumbers;
     119             : 
     120             :     // <- SYNCHRONIZED
     121        4637 : }
     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        6197 : 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        6197 :     m_aListener.addInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
     143        6197 : }
     144             : 
     145           9 : 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           9 :     m_aListener.removeInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
     150           9 : }
     151             : 
     152        5729 : void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEvent)
     153             :     throw (css::uno::RuntimeException, std::exception)
     154             : {
     155             :     // SYNCHRONIZED ->
     156        5729 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     157             : 
     158       11449 :         css::uno::Reference< css::frame::XTitle > xSubTitle(m_xSubTitle.get (), css::uno::UNO_QUERY);
     159             : 
     160        5729 :     aLock.clear ();
     161             :     // <- SYNCHRONIZED
     162             : 
     163        5729 :     if (aEvent.Source != xSubTitle)
     164        5720 :         return;
     165             : 
     166       11458 :     impl_updateTitle ();
     167             : }
     168             : 
     169       26218 : void SAL_CALL TitleHelper::notifyEvent(const css::document::EventObject& aEvent)
     170             :     throw (css::uno::RuntimeException, std::exception)
     171             : {
     172       52436 :     if ( ! aEvent.EventName.equalsIgnoreAsciiCase("OnSaveAsDone")
     173       26212 :       && ! aEvent.EventName.equalsIgnoreAsciiCase("OnModeChanged")
     174       51629 :       && ! aEvent.EventName.equalsIgnoreAsciiCase("OnTitleChanged"))
     175       37994 :         return;
     176             : 
     177             :     // SYNCHRONIZED ->
     178        7221 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     179             : 
     180       14442 :         css::uno::Reference< css::frame::XModel > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     181             : 
     182        7221 :     aLock.clear ();
     183             :     // <- SYNCHRONIZED
     184             : 
     185       14442 :     if (aEvent.Source != xOwner
     186        7221 :         || ((aEvent.EventName.equalsIgnoreAsciiCase("OnModeChanged")
     187        6420 :              || aEvent.EventName.equalsIgnoreAsciiCase("OnTitleChanged"))
     188        7215 :             && !xOwner.is()))
     189             :     {
     190           0 :         return;
     191             :     }
     192             : 
     193       14442 :     impl_updateTitle ();
     194             : }
     195             : 
     196       11620 : void SAL_CALL TitleHelper::frameAction(const css::frame::FrameActionEvent& aEvent)
     197             :     throw(css::uno::RuntimeException, std::exception)
     198             : {
     199             :     // SYNCHRONIZED ->
     200       11620 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     201             : 
     202       23240 :         css::uno::Reference< css::frame::XFrame > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     203             : 
     204       11620 :     aLock.clear ();
     205             :     // <- SYNCHRONIZED
     206             : 
     207       11620 :     if (aEvent.Source != xOwner)
     208       11620 :         return;
     209             : 
     210             :     // we are interested on events only, which must trigger a title bar update
     211             :     // because component was changed.
     212       11620 :     if (
     213       21167 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_ATTACHED  ) ||
     214       19085 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_REATTACHED) ||
     215        9538 :         (aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING )
     216             :        )
     217             :     {
     218        4151 :         impl_updateListeningForFrame (xOwner);
     219        4151 :         impl_updateTitle ();
     220       11620 :     }
     221             : }
     222             : 
     223        4603 : void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
     224             :     throw (css::uno::RuntimeException, std::exception)
     225             : {
     226             :     // SYNCHRONIZED ->
     227        4603 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     228        9206 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     229        9206 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     230        4603 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     231        4603 :     aLock.clear ();
     232             :     // <- SYNCHRONIZED
     233             : 
     234        4603 :     if ( ! xOwner.is ())
     235           0 :         return;
     236             : 
     237        4603 :     if (xOwner != aEvent.Source)
     238           0 :         return;
     239             : 
     240        4603 :     if (
     241        4603 :         (xNumbers.is ()                                                   ) &&
     242             :         (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     243             :        )
     244         936 :        xNumbers->releaseNumber (nLeasedNumber);
     245             : 
     246             :     // SYNCHRONIZED ->
     247        4603 :     aLock.reset ();
     248             : 
     249        4603 :          m_sTitle        = OUString ();
     250        4603 :          m_nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     251             : 
     252        4603 :     aLock.clear ();
     253             :     // <- SYNCHRONIZED
     254             : 
     255        9206 :     impl_sendTitleChangedEvent ();
     256             : }
     257             : 
     258       11873 : void TitleHelper::impl_sendTitleChangedEvent ()
     259             : {
     260             :     // SYNCHRONIZED ->
     261       11873 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     262             : 
     263       19673 :         css::frame::TitleChangedEvent aEvent(m_xOwner.get (), m_sTitle);
     264             : 
     265       11873 :     aLock.clear ();
     266             :     // <- SYNCHRONIZED
     267             : 
     268       11873 :     ::cppu::OInterfaceContainerHelper* pContainer = m_aListener.getContainer( ::getCppuType( ( const css::uno::Reference< css::frame::XTitleChangeListener >*) NULL ) );
     269       11873 :     if ( ! pContainer)
     270       15946 :         return;
     271             : 
     272       15600 :     ::cppu::OInterfaceIteratorHelper pIt( *pContainer );
     273       23423 :     while ( pIt.hasMoreElements() )
     274             :     {
     275             :         try
     276             :         {
     277        7823 :             ((css::frame::XTitleChangeListener*)pIt.next())->titleChanged( aEvent );
     278             :         }
     279           9 :         catch(const css::uno::Exception&)
     280             :         {
     281           9 :             pIt.remove();
     282             :         }
     283        7800 :     }
     284             : }
     285             : 
     286       25873 : void TitleHelper::impl_updateTitle (bool init)
     287             : {
     288             :     // SYNCHRONIZED ->
     289       25873 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     290             : 
     291       51746 :         css::uno::Reference< css::frame::XModel >      xModel     (m_xOwner.get(), css::uno::UNO_QUERY);
     292       51746 :         css::uno::Reference< css::frame::XController > xController(m_xOwner.get(), css::uno::UNO_QUERY);
     293       51737 :         css::uno::Reference< css::frame::XFrame >      xFrame     (m_xOwner.get(), css::uno::UNO_QUERY);
     294             : 
     295       25873 :     aLock.clear ();
     296             :     // <- SYNCHRONIZED
     297             : 
     298       25873 :     if (xModel.is ())
     299             :     {
     300        9799 :         impl_updateTitleForModel (xModel, init);
     301             :     }
     302       16074 :     else if (xController.is ())
     303             :     {
     304        7776 :         impl_updateTitleForController (xController, init);
     305             :     }
     306        8298 :     else if (xFrame.is ())
     307             :     {
     308        8297 :         impl_updateTitleForFrame (xFrame, init);
     309       25873 :     }
     310       25864 : }
     311             : 
     312        9799 : void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel, bool init)
     313             : {
     314             :     // SYNCHRONIZED ->
     315        9799 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     316             : 
     317             :         // external title wont be updated internally !
     318             :         // It has to be set from outside new.
     319        9799 :         if (m_bExternalTitle)
     320           6 :             return;
     321             : 
     322       19586 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     323       19586 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     324        9793 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     325             : 
     326        9793 :     aLock.clear ();
     327             :     // <- SYNCHRONIZED
     328             : 
     329        9793 :     if (
     330       19586 :         ( ! xOwner.is    ()) ||
     331       19586 :         ( ! xNumbers.is  ()) ||
     332        9793 :         ( ! xModel.is    ())
     333             :        )
     334           0 :         return;
     335             : 
     336       19586 :     OUString sTitle;
     337       19586 :     OUString sURL;
     338             : 
     339       19586 :     css::uno::Reference< css::frame::XStorable > xURLProvider(xModel , css::uno::UNO_QUERY);
     340        9793 :     if (xURLProvider.is())
     341        9793 :         sURL = xURLProvider->getLocation ();
     342             : 
     343        9793 :     if (!sURL.isEmpty())
     344             :     {
     345        4596 :         sTitle = impl_convertURL2Title(sURL);
     346        4596 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     347           6 :             xNumbers->releaseNumber (nLeasedNumber);
     348        4596 :         nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     349             :     }
     350             :     else
     351             :     {
     352        5197 :         if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     353         966 :             nLeasedNumber = xNumbers->leaseNumber (xOwner);
     354             : 
     355        5197 :         OUStringBuffer sNewTitle(256);
     356        5197 :         sNewTitle.append (xNumbers->getUntitledPrefix ());
     357        5197 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     358        5197 :             sNewTitle.append ((::sal_Int32)nLeasedNumber);
     359             :         else
     360           0 :             sNewTitle.appendAscii("?");
     361             : 
     362        5197 :         sTitle = sNewTitle.makeStringAndClear ();
     363             :     }
     364             : 
     365             :     // SYNCHRONIZED ->
     366        9793 :     aLock.reset ();
     367             : 
     368             :     // WORKAROUND: the notification is currently sent always,
     369             :     //             can be changed after shared mode is supported per UNO API
     370        9793 :     bool     bChanged        = !init; // && m_sTitle != sTitle
     371             : 
     372        9793 :              m_sTitle        = sTitle;
     373        9793 :              m_nLeasedNumber = nLeasedNumber;
     374             : 
     375        9793 :     aLock.clear ();
     376             :     // <- SYNCHRONIZED
     377             : 
     378        9793 :     if (bChanged)
     379       17008 :         impl_sendTitleChangedEvent ();
     380             : }
     381             : 
     382        7776 : void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController, bool init)
     383             : {
     384             :     // SYNCHRONIZED ->
     385        7776 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     386             : 
     387             :         // external title wont be updated internally !
     388             :         // It has to be set from outside new.
     389        7776 :         if (m_bExternalTitle)
     390           0 :             return;
     391             : 
     392       15549 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     393       15549 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     394        7776 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     395             : 
     396        7776 :     aLock.clear ();
     397             :     // <- SYNCHRONIZED
     398             : 
     399        7776 :     if (
     400       15552 :         ( ! xOwner.is      ()) ||
     401       15549 :         ( ! xNumbers.is    ()) ||
     402        7773 :         ( ! xController.is ())
     403             :        )
     404           3 :         return;
     405             : 
     406       15546 :     OUStringBuffer sTitle(256);
     407             : 
     408        7773 :     if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     409        2061 :         nLeasedNumber = xNumbers->leaseNumber (xOwner);
     410             : 
     411       15546 :     css::uno::Reference< css::frame::XTitle > xModelTitle(xController->getModel (), css::uno::UNO_QUERY);
     412        7773 :     if (!xModelTitle.is ())
     413        2042 :         xModelTitle.set(xController, css::uno::UNO_QUERY);
     414        7773 :     if (xModelTitle.is ())
     415             :     {
     416        7773 :         sTitle.append      (xModelTitle->getTitle ());
     417        7773 :         if ( nLeasedNumber > 1 )
     418             :         {
     419          32 :             sTitle.appendAscii (" : ");
     420          32 :             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        7773 :     aLock.reset ();
     434             : 
     435       15546 :         OUString sNewTitle       = sTitle.makeStringAndClear ();
     436        7773 :         bool     bChanged        = !init && m_sTitle != sNewTitle;
     437        7773 :                  m_sTitle        = sNewTitle;
     438        7773 :                  m_nLeasedNumber = nLeasedNumber;
     439             : 
     440        7773 :     aLock.clear ();
     441             :     // <- SYNCHRONIZED
     442             : 
     443        7773 :     if (bChanged)
     444        7790 :         impl_sendTitleChangedEvent ();
     445             : }
     446             : 
     447        8297 : void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame, bool init)
     448             : {
     449        8297 :     if ( ! xFrame.is ())
     450           1 :         return;
     451             : 
     452             :     // SYNCHRONIZED ->
     453        8297 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     454             : 
     455             :         // external title wont be updated internally !
     456             :         // It has to be set from outside new.
     457        8297 :         if (m_bExternalTitle)
     458           1 :             return;
     459             : 
     460        8296 :     aLock.clear ();
     461             :     // <- SYNCHRONIZED
     462             : 
     463       16592 :     css::uno::Reference< css::uno::XInterface > xComponent;
     464        8296 :     xComponent = xFrame->getController ();
     465        8296 :     if ( ! xComponent.is ())
     466        2069 :         xComponent = xFrame->getComponentWindow ();
     467             : 
     468       16574 :     OUStringBuffer sTitle (256);
     469             : 
     470        8287 :     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        8287 :     impl_appendProductName      (sTitle);
     475        8287 :     impl_appendModuleName       (sTitle);
     476        8287 :     impl_appendDebugVersion     (sTitle);
     477             : #endif
     478             :     // SYNCHRONIZED ->
     479        8287 :     aLock.reset ();
     480             : 
     481       16574 :         OUString sNewTitle = sTitle.makeStringAndClear ();
     482        8287 :         bool     bChanged  = !init && m_sTitle != sNewTitle;
     483        8287 :                  m_sTitle  = sNewTitle;
     484             : 
     485        8287 :     aLock.clear ();
     486             :     // <- SYNCHRONIZED
     487             : 
     488        8287 :     if (bChanged)
     489        8332 :         impl_sendTitleChangedEvent ();
     490             : }
     491             : 
     492        8287 : void TitleHelper::impl_appendComponentTitle (      OUStringBuffer&                       sTitle    ,
     493             :                                              const css::uno::Reference< css::uno::XInterface >& xComponent)
     494             : {
     495        8287 :     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        8287 :     if (xTitle.is ())
     499        6170 :         sTitle.append (xTitle->getTitle ());
     500        8287 : }
     501             : 
     502        8287 : void TitleHelper::impl_appendProductName (OUStringBuffer& sTitle)
     503             : {
     504        8287 :     OUString name(utl::ConfigManager::getProductName());
     505        8287 :     if (!name.isEmpty())
     506             :     {
     507        8287 :         if (!sTitle.isEmpty())
     508        6169 :             sTitle.append(" - ");
     509        8287 :         sTitle.append(name);
     510        8287 :     }
     511        8287 : }
     512             : 
     513        8287 : void TitleHelper::impl_appendModuleName (OUStringBuffer& sTitle)
     514             : {
     515             :     // SYNCHRONIZED ->
     516        8287 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     517             : 
     518       16574 :         css::uno::Reference< css::uno::XInterface >        xOwner   = m_xOwner.get();
     519       16574 :         css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
     520             : 
     521        8287 :     aLock.clear ();
     522             :     // <- SYNCHRONIZED
     523             : 
     524             :     try
     525             :     {
     526             :         css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
     527        8287 :             css::frame::ModuleManager::create(xContext);
     528             : 
     529       14494 :         const OUString                 sID     = xModuleManager->identify(xOwner);
     530       12414 :               ::comphelper::SequenceAsHashMap lProps  = xModuleManager->getByName (sID);
     531       12414 :         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        6207 :         if (!sUIName.isEmpty())
     536             :         {
     537        6205 :             sTitle.appendAscii (" "    );
     538        6205 :             sTitle.append      (sUIName);
     539        8287 :         }
     540             :     }
     541        2080 :     catch(const css::uno::Exception&)
     542        8287 :     {}
     543        8287 : }
     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        8287 : void TitleHelper::impl_appendDebugVersion (OUStringBuffer&)
     559             : {
     560        8287 : }
     561             : #endif
     562             : 
     563        2574 : void TitleHelper::impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel)
     564             : {
     565        2574 :     css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xModel, css::uno::UNO_QUERY);
     566        2574 :     if ( ! xBroadcaster.is ())
     567        2574 :         return;
     568             : 
     569        2574 :     xBroadcaster->addEventListener (static_cast< css::document::XEventListener* >(this));
     570             : }
     571             : 
     572        2063 : void TitleHelper::impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController)
     573             : {
     574        2063 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xController->getModel (), css::uno::UNO_QUERY);
     575        2063 :     impl_setSubTitle (xSubTitle);
     576        2063 : }
     577             : 
     578        2077 : void TitleHelper::impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     579             : {
     580        2077 :     xFrame->addFrameActionListener(this  );
     581        2077 :     impl_updateListeningForFrame  (xFrame);
     582        2077 : }
     583             : 
     584        6228 : void TitleHelper::impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     585             : {
     586        6228 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xFrame->getController (), css::uno::UNO_QUERY);
     587        6228 :     impl_setSubTitle (xSubTitle);
     588        6228 : }
     589             : 
     590        8291 : void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle)
     591             : {
     592             :     // SYNCHRONIZED ->
     593        8291 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     594             : 
     595             :         // ignore duplicate calls. Makes outside using of this helper more easy :-)
     596       12415 :         css::uno::Reference< css::frame::XTitle > xOldSubTitle(m_xSubTitle.get(), css::uno::UNO_QUERY);
     597        8291 :         if (xOldSubTitle == xSubTitle)
     598       12458 :             return;
     599             : 
     600        4124 :         m_xSubTitle = xSubTitle;
     601             : 
     602        4124 :     aLock.clear ();
     603             :     // <- SYNCHRONIZED
     604             : 
     605        8248 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xOldBroadcaster(xOldSubTitle                                          , css::uno::UNO_QUERY      );
     606        8248 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xNewBroadcaster(xSubTitle                                             , css::uno::UNO_QUERY      );
     607        8248 :     css::uno::Reference< css::frame::XTitleChangeListener >    xThis          (static_cast< css::frame::XTitleChangeListener* >(this), css::uno::UNO_QUERY_THROW);
     608             : 
     609        4124 :     if (xOldBroadcaster.is())
     610           9 :         xOldBroadcaster->removeTitleChangeListener (xThis);
     611             : 
     612        4124 :     if (xNewBroadcaster.is())
     613        8247 :         xNewBroadcaster->addTitleChangeListener (xThis);
     614             : }
     615             : 
     616        4596 : OUString TitleHelper::impl_convertURL2Title(const OUString& sURL)
     617             : {
     618        4596 :     INetURLObject   aURL (sURL);
     619        4596 :     OUString sTitle;
     620             : 
     621        4596 :     if (aURL.GetProtocol() == INET_PROT_FILE)
     622             :     {
     623        4596 :         if (aURL.HasMark())
     624           0 :             aURL = INetURLObject(aURL.GetURLNoMark());
     625             : 
     626        4596 :         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        4596 :     return sTitle;
     641             : }
     642             : 
     643             : } // namespace framework
     644             : 
     645             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10