LCOV - code coverage report
Current view: top level - libreoffice/framework/source/fwe/helper - titlehelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 260 290 89.7 %
Date: 2012-12-17 Functions: 27 29 93.1 %
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             : 
      39             : namespace framework{
      40             : 
      41             : //-----------------------------------------------
      42        1990 : TitleHelper::TitleHelper(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
      43             :     : ::cppu::BaseMutex ()
      44             :     , m_xContext        (rxContext)
      45             :     , m_xOwner          ()
      46             :     , m_xUntitledNumbers()
      47             :     , m_xSubTitle       ()
      48             :     , m_bExternalTitle  (sal_False)
      49             :     , m_sTitle          ()
      50             :     , m_nLeasedNumber   (css::frame::UntitledNumbersConst::INVALID_NUMBER)
      51        1990 :     , m_aListener       (m_aMutex)
      52             : {
      53        1990 : }
      54             : 
      55             : //-----------------------------------------------
      56        1104 : TitleHelper::~TitleHelper()
      57             : {
      58        1104 : }
      59             : 
      60             : //-----------------------------------------------
      61        1990 : void TitleHelper::setOwner(const css::uno::Reference< css::uno::XInterface >& xOwner)
      62             : {
      63             :     // SYNCHRONIZED ->
      64        1990 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
      65             : 
      66        1990 :         m_xOwner = xOwner;
      67             : 
      68        1990 :     aLock.clear ();
      69             :     // <- SYNCHRONIZED
      70             : 
      71        1990 :     css::uno::Reference< css::frame::XModel > xModel(xOwner, css::uno::UNO_QUERY);
      72        1990 :     if (xModel.is ())
      73             :     {
      74         958 :         impl_startListeningForModel (xModel);
      75             :         return;
      76             :     }
      77             : 
      78        1032 :     css::uno::Reference< css::frame::XController > xController(xOwner, css::uno::UNO_QUERY);
      79        1032 :     if (xController.is ())
      80             :     {
      81         516 :         impl_startListeningForController (xController);
      82             :         return;
      83             :     }
      84             : 
      85         516 :     css::uno::Reference< css::frame::XFrame > xFrame(xOwner, css::uno::UNO_QUERY);
      86         516 :     if (xFrame.is ())
      87             :     {
      88         516 :         impl_startListeningForFrame (xFrame);
      89             :         return;
      90         516 :     }
      91             : }
      92             : 
      93             : //-----------------------------------------------
      94        3519 : ::rtl::OUString SAL_CALL TitleHelper::getTitle()
      95             :     throw (css::uno::RuntimeException)
      96             : {
      97             :     // SYNCHRONIZED ->
      98        3519 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
      99             : 
     100             :         // An external title will win always and disable all internal logic about
     101             :         // creating/using a title value.
     102             :         // Even an empty string will be accepted as valid title !
     103        3519 :         if (m_bExternalTitle)
     104           0 :             return m_sTitle;
     105             : 
     106             :         // Title seams to be up-to-date. Return it directly.
     107        3519 :         if (!m_sTitle.isEmpty())
     108        1431 :             return m_sTitle;
     109             : 
     110             :         // Title seams to be unused till now ... do bootstraping
     111        2088 :         impl_updateTitle (true);
     112             : 
     113        2088 :         return m_sTitle;
     114             : 
     115             :     // <- SYNCHRONIZED
     116             : }
     117             : 
     118             : //-----------------------------------------------
     119        1474 : void TitleHelper::connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
     120             : {
     121             :     // SYNCHRONIZED ->
     122        1474 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     123             : 
     124        1474 :         m_xUntitledNumbers = xNumbers;
     125             : 
     126             :     // <- SYNCHRONIZED
     127        1474 : }
     128             : 
     129             : //-----------------------------------------------
     130           0 : void SAL_CALL TitleHelper::setTitle(const ::rtl::OUString& sTitle)
     131             :     throw (css::uno::RuntimeException)
     132             : {
     133             :     // SYNCHRONIZED ->
     134           0 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     135             : 
     136           0 :         m_bExternalTitle = sal_True;
     137           0 :         m_sTitle         = sTitle;
     138             : 
     139           0 :     aLock.clear ();
     140             :     // <- SYNCHRONIZED
     141             : 
     142           0 :     impl_sendTitleChangedEvent ();
     143           0 : }
     144             : 
     145             : //-----------------------------------------------
     146        1548 : void SAL_CALL TitleHelper::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
     147             :     throw (css::uno::RuntimeException)
     148             : {
     149             :     // container is threadsafe by himself
     150        1548 :     m_aListener.addInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
     151        1548 : }
     152             : 
     153             : //-----------------------------------------------
     154           0 : void SAL_CALL TitleHelper::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
     155             :     throw (css::uno::RuntimeException)
     156             : {
     157             :     // container is threadsafe by himself
     158           0 :     m_aListener.removeInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
     159           0 : }
     160             : 
     161             : //-----------------------------------------------
     162         259 : void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEvent)
     163             :     throw (css::uno::RuntimeException)
     164             : {
     165             :     // SYNCHRONIZED ->
     166         259 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     167             : 
     168         259 :         css::uno::Reference< css::frame::XTitle > xSubTitle(m_xSubTitle.get (), css::uno::UNO_QUERY);
     169             : 
     170         259 :     aLock.clear ();
     171             :     // <- SYNCHRONIZED
     172             : 
     173         259 :     if (aEvent.Source != xSubTitle)
     174         259 :         return;
     175             : 
     176         259 :     impl_updateTitle ();
     177             : }
     178             : 
     179             : //-----------------------------------------------
     180        7628 : void SAL_CALL TitleHelper::notifyEvent(const css::document::EventObject& aEvent)
     181             :     throw (css::uno::RuntimeException)
     182             : {
     183       22174 :     if ( ! aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("OnSaveAsDone"))
     184        7628 :       && ! aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("OnModeChanged"))
     185        6918 :       && ! aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("OnTitleChanged")))
     186             :         return;
     187             : 
     188             :     // SYNCHRONIZED ->
     189        2671 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     190             : 
     191        2671 :         css::uno::Reference< css::frame::XModel > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     192             : 
     193        2671 :     aLock.clear ();
     194             :     // <- SYNCHRONIZED
     195             : 
     196        9974 :     if (aEvent.Source != xOwner
     197             :         || ((aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(
     198        2671 :                  RTL_CONSTASCII_STRINGPARAM("OnModeChanged"))
     199             :              || aEvent.EventName.equalsIgnoreAsciiCaseAsciiL(
     200        1961 :                  RTL_CONSTASCII_STRINGPARAM("OnTitleChanged")))
     201        2671 :             && !xOwner.is()))
     202             :     {
     203             :         return;
     204             :     }
     205             : 
     206        2671 :     impl_updateTitle ();
     207             : }
     208             : 
     209             : //-----------------------------------------------
     210        2366 : void SAL_CALL TitleHelper::frameAction(const css::frame::FrameActionEvent& aEvent)
     211             :     throw(css::uno::RuntimeException)
     212             : {
     213             :     // SYNCHRONIZED ->
     214        2366 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     215             : 
     216        2366 :         css::uno::Reference< css::frame::XFrame > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
     217             : 
     218        2366 :     aLock.clear ();
     219             :     // <- SYNCHRONIZED
     220             : 
     221        2366 :     if (aEvent.Source != xOwner)
     222        2366 :         return;
     223             : 
     224             :     // we are interested on events only, which must trigger a title bar update
     225             :     // because component was changed.
     226        2366 :     if (
     227             :         (aEvent.Action == css::frame::FrameAction_COMPONENT_ATTACHED  ) ||
     228             :         (aEvent.Action == css::frame::FrameAction_COMPONENT_REATTACHED) ||
     229             :         (aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING )
     230             :        )
     231             :     {
     232         614 :         impl_updateListeningForFrame (xOwner);
     233         614 :         impl_updateTitle ();
     234        2366 :     }
     235             : }
     236             : 
     237             : //-----------------------------------------------
     238         542 : void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
     239             :     throw (css::uno::RuntimeException)
     240             : {
     241             :     // SYNCHRONIZED ->
     242         542 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     243         542 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     244         542 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     245         542 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     246         542 :     aLock.clear ();
     247             :     // <- SYNCHRONIZED
     248             : 
     249         542 :     if ( ! xOwner.is ())
     250             :         return;
     251             : 
     252         542 :     if (xOwner != aEvent.Source)
     253             :         return;
     254             : 
     255         542 :     if (
     256         542 :         (xNumbers.is ()                                                   ) &&
     257             :         (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     258             :        )
     259         213 :        xNumbers->releaseNumber (nLeasedNumber);
     260             : 
     261             :     // SYNCHRONIZED ->
     262         542 :     aLock.reset ();
     263             : 
     264         542 :          m_sTitle        = ::rtl::OUString ();
     265         542 :          m_nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     266             : 
     267         542 :     aLock.clear ();
     268             :     // <- SYNCHRONIZED
     269             : 
     270         542 :     impl_sendTitleChangedEvent ();
     271             : }
     272             : 
     273             : //-----------------------------------------------
     274        3213 : void TitleHelper::impl_sendTitleChangedEvent ()
     275             : {
     276             :     // SYNCHRONIZED ->
     277        3213 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     278             : 
     279        3213 :         css::frame::TitleChangedEvent aEvent(m_xOwner.get (), m_sTitle);
     280             : 
     281        3213 :     aLock.clear ();
     282             :     // <- SYNCHRONIZED
     283             : 
     284        3213 :     ::cppu::OInterfaceContainerHelper* pContainer = m_aListener.getContainer( ::getCppuType( ( const css::uno::Reference< css::frame::XTitleChangeListener >*) NULL ) );
     285        3213 :     if ( ! pContainer)
     286        3213 :         return;
     287             : 
     288         357 :     ::cppu::OInterfaceIteratorHelper pIt( *pContainer );
     289        1071 :     while ( pIt.hasMoreElements() )
     290             :     {
     291             :         try
     292             :         {
     293         357 :             ((css::frame::XTitleChangeListener*)pIt.next())->titleChanged( aEvent );
     294             :         }
     295           0 :         catch(const css::uno::Exception&)
     296             :         {
     297           0 :             pIt.remove();
     298             :         }
     299         357 :     }
     300             : }
     301             : 
     302             : //-----------------------------------------------
     303        5632 : void TitleHelper::impl_updateTitle (bool init)
     304             : {
     305             :     // SYNCHRONIZED ->
     306        5632 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     307             : 
     308        5632 :         css::uno::Reference< css::frame::XModel >      xModel     (m_xOwner.get(), css::uno::UNO_QUERY);
     309        5632 :         css::uno::Reference< css::frame::XController > xController(m_xOwner.get(), css::uno::UNO_QUERY);
     310        5632 :         css::uno::Reference< css::frame::XFrame >      xFrame     (m_xOwner.get(), css::uno::UNO_QUERY);
     311             : 
     312        5632 :     aLock.clear ();
     313             :     // <- SYNCHRONIZED
     314             : 
     315        5632 :     if (xModel.is ())
     316             :     {
     317        3629 :         impl_updateTitleForModel (xModel, init);
     318             :     }
     319        2003 :     else if (xController.is ())
     320             :     {
     321         775 :         impl_updateTitleForController (xController, init);
     322             :     }
     323        1228 :     else if (xFrame.is ())
     324             :     {
     325        1228 :         impl_updateTitleForFrame (xFrame, init);
     326        5632 :     }
     327        5632 : }
     328             : 
     329             : //-----------------------------------------------
     330        3629 : void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel, bool init)
     331             : {
     332             :     // SYNCHRONIZED ->
     333        3629 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     334             : 
     335             :         // external title wont be updated internaly !
     336             :         // It has to be set from outside new.
     337        3629 :         if (m_bExternalTitle)
     338             :             return;
     339             : 
     340        3629 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     341        3629 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     342        3629 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     343             : 
     344        3629 :     aLock.clear ();
     345             :     // <- SYNCHRONIZED
     346             : 
     347       10887 :     if (
     348        3629 :         ( ! xOwner.is    ()) ||
     349        3629 :         ( ! xNumbers.is  ()) ||
     350        3629 :         ( ! xModel.is    ())
     351             :        )
     352             :         return;
     353             : 
     354        3629 :     ::rtl::OUString sTitle;
     355        3629 :     ::rtl::OUString sURL  ;
     356             : 
     357        3629 :     css::uno::Reference< css::frame::XStorable > xURLProvider(xModel , css::uno::UNO_QUERY);
     358        3629 :     if (xURLProvider.is())
     359        3629 :         sURL = xURLProvider->getLocation ();
     360             : 
     361        3629 :     if (!sURL.isEmpty())
     362             :     {
     363        1310 :         sTitle = impl_convertURL2Title(sURL);
     364        1310 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     365           0 :             xNumbers->releaseNumber (nLeasedNumber);
     366        1310 :         nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
     367             :     }
     368             :     else
     369             :     {
     370        2319 :         if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     371         303 :             nLeasedNumber = xNumbers->leaseNumber (xOwner);
     372             : 
     373        2319 :         ::rtl::OUStringBuffer sNewTitle(256);
     374        2319 :         sNewTitle.append (xNumbers->getUntitledPrefix ());
     375        2319 :         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
     376        2319 :             sNewTitle.append ((::sal_Int32)nLeasedNumber);
     377             :         else
     378           0 :             sNewTitle.appendAscii ("?");
     379             : 
     380        2319 :         sTitle = sNewTitle.makeStringAndClear ();
     381             :     }
     382             : 
     383             :     // SYNCHRONIZED ->
     384        3629 :     aLock.reset ();
     385             : 
     386             :     // WORKAROUND: the notification is currently sent always,
     387             :     //             can be changed after shared mode is supported per UNO API
     388        3629 :     sal_Bool bChanged        = !init; // && m_sTitle != sTitle
     389             : 
     390        3629 :              m_sTitle        = sTitle;
     391        3629 :              m_nLeasedNumber = nLeasedNumber;
     392             : 
     393        3629 :     aLock.clear ();
     394             :     // <- SYNCHRONIZED
     395             : 
     396        3629 :     if (bChanged)
     397        2671 :         impl_sendTitleChangedEvent ();
     398             : }
     399             : 
     400             : //-----------------------------------------------
     401         775 : void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController, bool init)
     402             : {
     403             :     // SYNCHRONIZED ->
     404         775 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     405             : 
     406             :         // external title wont be updated internaly !
     407             :         // It has to be set from outside new.
     408         775 :         if (m_bExternalTitle)
     409             :             return;
     410             : 
     411         775 :         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
     412         775 :         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
     413         775 :         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
     414             : 
     415         775 :     aLock.clear ();
     416             :     // <- SYNCHRONIZED
     417             : 
     418        2325 :     if (
     419         775 :         ( ! xOwner.is      ()) ||
     420         775 :         ( ! xNumbers.is    ()) ||
     421         775 :         ( ! xController.is ())
     422             :        )
     423             :         return;
     424             : 
     425         775 :     ::rtl::OUStringBuffer sTitle(256);
     426             : 
     427         775 :     if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
     428         516 :         nLeasedNumber = xNumbers->leaseNumber (xOwner);
     429             : 
     430         775 :     css::uno::Reference< css::frame::XTitle > xModelTitle(xController->getModel (), css::uno::UNO_QUERY);
     431         775 :     if (!xModelTitle.is ())
     432          98 :         xModelTitle.set(xController, css::uno::UNO_QUERY);
     433         775 :     if (xModelTitle.is ())
     434             :     {
     435         775 :         sTitle.append      (xModelTitle->getTitle ());
     436         775 :         if ( nLeasedNumber > 1 )
     437             :         {
     438           0 :             sTitle.appendAscii (" : ");
     439           0 :             sTitle.append      ((::sal_Int32)nLeasedNumber);
     440             :         }
     441             :     }
     442             :     else
     443             :     {
     444           0 :         sTitle.append (xNumbers->getUntitledPrefix ());
     445           0 :         if ( nLeasedNumber > 1 )
     446             :         {
     447           0 :             sTitle.append ((::sal_Int32)nLeasedNumber  );
     448             :         }
     449             :     }
     450             : 
     451             :     // SYNCHRONIZED ->
     452         775 :     aLock.reset ();
     453             : 
     454         775 :         ::rtl::OUString sNewTitle       = sTitle.makeStringAndClear ();
     455         775 :         sal_Bool        bChanged        = !init && m_sTitle != sNewTitle;
     456         775 :                         m_sTitle        = sNewTitle;
     457         775 :                         m_nLeasedNumber = nLeasedNumber;
     458             : 
     459         775 :     aLock.clear ();
     460             :     // <- SYNCHRONIZED
     461             : 
     462         775 :     if (bChanged)
     463           0 :         impl_sendTitleChangedEvent ();
     464             : }
     465             : 
     466             : //-----------------------------------------------
     467        1228 : void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame, bool init)
     468             : {
     469        1228 :     if ( ! xFrame.is ())
     470             :         return;
     471             : 
     472             :     // SYNCHRONIZED ->
     473        1228 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     474             : 
     475             :         // external title wont be updated internaly !
     476             :         // It has to be set from outside new.
     477        1228 :         if (m_bExternalTitle)
     478             :             return;
     479             : 
     480        1228 :     aLock.clear ();
     481             :     // <- SYNCHRONIZED
     482             : 
     483        1228 :     css::uno::Reference< css::uno::XInterface > xComponent;
     484        1228 :     xComponent = xFrame->getController ();
     485        1228 :     if ( ! xComponent.is ())
     486          98 :         xComponent = xFrame->getComponentWindow ();
     487             : 
     488        1228 :     ::rtl::OUStringBuffer sTitle (256);
     489             : 
     490        1228 :     impl_appendComponentTitle   (sTitle, xComponent);
     491        1228 :     impl_appendProductName      (sTitle);
     492        1228 :     impl_appendModuleName       (sTitle);
     493        1228 :     impl_appendProductExtension (sTitle);
     494        1228 :     impl_appendDebugVersion     (sTitle);
     495             : 
     496             :     // SYNCHRONIZED ->
     497        1228 :     aLock.reset ();
     498             : 
     499        1228 :         ::rtl::OUString sNewTitle = sTitle.makeStringAndClear ();
     500        1228 :         sal_Bool        bChanged  = !init && m_sTitle != sNewTitle;
     501        1228 :                         m_sTitle  = sNewTitle;
     502             : 
     503        1228 :     aLock.clear ();
     504             :     // <- SYNCHRONIZED
     505             : 
     506        1228 :     if (bChanged)
     507           0 :         impl_sendTitleChangedEvent ();
     508             : }
     509             : 
     510             : //*****************************************************************************************************************
     511        1228 : void TitleHelper::impl_appendComponentTitle (      ::rtl::OUStringBuffer&                       sTitle    ,
     512             :                                              const css::uno::Reference< css::uno::XInterface >& xComponent)
     513             : {
     514        1228 :     css::uno::Reference< css::frame::XTitle > xTitle(xComponent, css::uno::UNO_QUERY);
     515             : 
     516             :     // Note: Title has to be used (even if it's empty) if the right interface is supported.
     517        1228 :     if (xTitle.is ())
     518        1130 :         sTitle.append (xTitle->getTitle ());
     519        1228 : }
     520             : 
     521             : //*****************************************************************************************************************
     522        1228 : void TitleHelper::impl_appendProductName (::rtl::OUStringBuffer& sTitle)
     523             : {
     524        1228 :     rtl::OUString name(utl::ConfigManager::getProductName());
     525        1228 :     if (!name.isEmpty())
     526             :     {
     527        1228 :         if (sTitle.getLength() != 0)
     528        1130 :             sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM(" - "));
     529        1228 :         sTitle.append(name);
     530        1228 :     }
     531        1228 : }
     532             : 
     533             : //*****************************************************************************************************************
     534        1228 : void TitleHelper::impl_appendProductExtension (::rtl::OUStringBuffer& sTitle)
     535             : {
     536        1228 :     rtl::OUString ext(utl::ConfigManager::getProductExtension());
     537        1228 :     if (!ext.isEmpty())
     538             :     {
     539        1220 :         sTitle.append(' ');
     540        1220 :         sTitle.append(ext);
     541        1228 :     }
     542        1228 : }
     543             : 
     544             : //*****************************************************************************************************************
     545        1228 : void TitleHelper::impl_appendModuleName (::rtl::OUStringBuffer& sTitle)
     546             : {
     547             :     // SYNCHRONIZED ->
     548        1228 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     549             : 
     550        1228 :         css::uno::Reference< css::uno::XInterface >        xOwner   = m_xOwner.get();
     551        1228 :         css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
     552             : 
     553        1228 :     aLock.clear ();
     554             :     // <- SYNCHRONIZED
     555             : 
     556             :     try
     557             :     {
     558             :         css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
     559        1228 :             css::frame::ModuleManager::create(xContext);
     560             : 
     561        1228 :         const ::rtl::OUString                 sID     = xModuleManager->identify(xOwner);
     562        1130 :               ::comphelper::SequenceAsHashMap lProps  = xModuleManager->getByName (sID);
     563        1114 :         const ::rtl::OUString                 sUIName = lProps.getUnpackedValueOrDefault (OFFICEFACTORY_PROPNAME_UINAME, ::rtl::OUString());
     564             : 
     565             :         // An UIname property is an optional value !
     566             :         // So please add it to the title in case it does realy exists only.
     567        1114 :         if (!sUIName.isEmpty())
     568             :         {
     569        1114 :             sTitle.appendAscii (" "    );
     570        1114 :             sTitle.append      (sUIName);
     571        1114 :         }
     572             :     }
     573         114 :     catch(const css::uno::Exception&)
     574        1228 :     {}
     575        1228 : }
     576             : 
     577             : //*****************************************************************************************************************
     578             : #ifdef DBG_UTIL
     579             : void TitleHelper::impl_appendDebugVersion (::rtl::OUStringBuffer& sTitle)
     580             : {
     581             :     ::rtl::OUString sDefault(RTL_CONSTASCII_USTRINGPARAM("development"));
     582             :     ::rtl::OUString sVersion = ::utl::Bootstrap::getProductSource(sDefault);
     583             :     sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM(" ["));
     584             :     sTitle.append(sVersion);
     585             :     sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM("]"));
     586             : }
     587             : #else
     588        1228 : void TitleHelper::impl_appendDebugVersion (::rtl::OUStringBuffer&)
     589             : {
     590        1228 : }
     591             : #endif
     592             : 
     593             : //-----------------------------------------------
     594         958 : void TitleHelper::impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel)
     595             : {
     596         958 :     css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xModel, css::uno::UNO_QUERY);
     597         958 :     if ( ! xBroadcaster.is ())
     598         958 :         return;
     599             : 
     600         958 :     xBroadcaster->addEventListener (static_cast< css::document::XEventListener* >(this));
     601             : }
     602             : 
     603             : //-----------------------------------------------
     604         516 : void TitleHelper::impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController)
     605             : {
     606         516 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xController->getModel (), css::uno::UNO_QUERY);
     607         516 :     impl_setSubTitle (xSubTitle);
     608         516 : }
     609             : 
     610             : //-----------------------------------------------
     611         516 : void TitleHelper::impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     612             : {
     613         516 :     xFrame->addFrameActionListener(this  );
     614         516 :     impl_updateListeningForFrame  (xFrame);
     615         516 : }
     616             : 
     617             : //-----------------------------------------------
     618        1130 : void TitleHelper::impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
     619             : {
     620        1130 :     css::uno::Reference< css::frame::XTitle > xSubTitle(xFrame->getController (), css::uno::UNO_QUERY);
     621        1130 :     impl_setSubTitle (xSubTitle);
     622        1130 : }
     623             : 
     624             : //-----------------------------------------------
     625        1646 : void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle)
     626             : {
     627             :     // SYNCHRONIZED ->
     628        1646 :     ::osl::ResettableMutexGuard aLock(m_aMutex);
     629             : 
     630             :         // ignore duplicate calls. Makes outside using of this helper more easy :-)
     631        1646 :         css::uno::Reference< css::frame::XTitle > xOldSubTitle(m_xSubTitle.get(), css::uno::UNO_QUERY);
     632        1646 :         if (xOldSubTitle == xSubTitle)
     633        1646 :             return;
     634             : 
     635        1032 :         m_xSubTitle = xSubTitle;
     636             : 
     637        1032 :     aLock.clear ();
     638             :     // <- SYNCHRONIZED
     639             : 
     640        1032 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xOldBroadcaster(xOldSubTitle                                          , css::uno::UNO_QUERY      );
     641        1032 :     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xNewBroadcaster(xSubTitle                                             , css::uno::UNO_QUERY      );
     642        1032 :     css::uno::Reference< css::frame::XTitleChangeListener >    xThis          (static_cast< css::frame::XTitleChangeListener* >(this), css::uno::UNO_QUERY_THROW);
     643             : 
     644        1032 :     if (xOldBroadcaster.is())
     645           0 :         xOldBroadcaster->removeTitleChangeListener (xThis);
     646             : 
     647        1032 :     if (xNewBroadcaster.is())
     648        1032 :         xNewBroadcaster->addTitleChangeListener (xThis);
     649             : }
     650             : 
     651             : //-----------------------------------------------
     652        1310 : ::rtl::OUString TitleHelper::impl_convertURL2Title(const ::rtl::OUString& sURL)
     653             : {
     654        1310 :     INetURLObject   aURL (sURL);
     655        1310 :     ::rtl::OUString sTitle;
     656             : 
     657        1310 :     if (aURL.GetProtocol() == INET_PROT_FILE)
     658             :     {
     659        1310 :         if (aURL.HasMark())
     660           0 :             aURL = INetURLObject(aURL.GetURLNoMark());
     661             : 
     662        1310 :         sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET);
     663             :     }
     664             :     else
     665             :     {
     666           0 :         if (aURL.hasExtension(INetURLObject::LAST_SEGMENT))
     667           0 :             sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET);
     668             : 
     669           0 :         if ( sTitle.isEmpty() )
     670           0 :             sTitle = aURL.GetHostPort(INetURLObject::DECODE_WITH_CHARSET);
     671             : 
     672           0 :         if ( sTitle.isEmpty() )
     673           0 :             sTitle = aURL.GetURLNoPass(INetURLObject::DECODE_WITH_CHARSET);
     674             :     }
     675             : 
     676        1310 :     return sTitle;
     677             : }
     678             : 
     679             : } // namespace framework
     680             : 
     681             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10