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

Generated by: LCOV version 1.10