LCOV - code coverage report
Current view: top level - uui/source - fltdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 44 0.0 %
Date: 2012-08-25 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 68 0.0 %

           Branch data     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 "fltdlg.hxx"
      21                 :            : 
      22                 :            : #include "ids.hrc"
      23                 :            : 
      24                 :            : #include "fltdlg.hrc"
      25                 :            : 
      26                 :            : #include <com/sun/star/util/XStringWidth.hpp>
      27                 :            : #include <cppuhelper/implbase1.hxx>
      28                 :            : #include <unotools/localfilehelper.hxx>
      29                 :            : #include <tools/urlobj.hxx>
      30                 :            : 
      31                 :            : #include <vcl/button.hxx>
      32                 :            : #include <osl/mutex.hxx>
      33                 :            : #include <vcl/svapp.hxx>
      34                 :            : 
      35                 :            : namespace uui
      36                 :            : {
      37                 :            : 
      38                 :            : /*-************************************************************************************************************//**
      39                 :            :     @short      initialize filter dialog with start values
      40                 :            :     @descr      We set some neccessary informations on these instance for later working and create internal structures.
      41                 :            :                 After construction user should call "SetFilters()" and "SetURL()" to fill listbox with selectable filter
      42                 :            :                 names and set file name of file, which should be used for selected filter.
      43                 :            : 
      44                 :            :     @seealso    method SetFilters()
      45                 :            :     @seealso    method SetURL()
      46                 :            : 
      47                 :            :     @param      "pParentWindow"  , parent window for dialog
      48                 :            :     @param      "pResMgr"        , resource manager
      49                 :            :     @return     -
      50                 :            : 
      51                 :            :     @onerror    -
      52                 :            :     @threadsafe no
      53                 :            : *//*-*************************************************************************************************************/
      54                 :          0 : FilterDialog::FilterDialog( Window* pParentWindow ,
      55                 :            :                             ResMgr* pResMgr       )
      56                 :            :     :   ModalDialog  ( pParentWindow, ResId( DLG_FILTER_SELECT, *pResMgr ) )
      57                 :            :     ,   m_ftURL      ( this, ResId( FT_URL, *pResMgr            )                   )
      58                 :            :     ,   m_lbFilters  ( this, ResId( LB_FILTERS, *pResMgr        )                   )
      59                 :            :     ,   m_btnOK      ( this, ResId( BTN_OK, *pResMgr            )                   )
      60                 :            :     ,   m_btnCancel  ( this, ResId( BTN_CANCEL, *pResMgr        )                   )
      61 [ #  # ][ #  # ]:          0 :     ,   m_btnHelp    ( this, ResId( BTN_HELP, *pResMgr          )                   )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      62                 :            : {
      63         [ #  # ]:          0 :     FreeResource();
      64                 :          0 : }
      65                 :            : 
      66                 :            : /*-************************************************************************************************************//**
      67                 :            :     @short      set file name on dialog control
      68                 :            :     @descr      We convert given URL (it must be an URL!) into valid file name and show it on our dialog.
      69                 :            : 
      70                 :            :     @seealso    -
      71                 :            : 
      72                 :            :     @param      "sURL", URL for showing
      73                 :            :     @return     -
      74                 :            : 
      75                 :            :     @onerror    -
      76                 :            :     @threadsafe no
      77                 :            : *//*-*************************************************************************************************************/
      78                 :          0 : void FilterDialog::SetURL( const String& sURL )
      79                 :            : {
      80                 :            :     // convert it and use given pure string as fallback if conversion failed
      81         [ #  # ]:          0 :     m_ftURL.SetText( impl_buildUIFileName(sURL) );
      82                 :          0 : }
      83                 :            : 
      84                 :            : /*-************************************************************************************************************//**
      85                 :            :     @short      change list of filter names
      86                 :            :     @descr      We save given pointer internal and use it to fill our listbox with given names.
      87                 :            :                 Saved list pointer is used on method "AskForFilter()" too, to find user selected item
      88                 :            :                 and return pointer into these list as result of operation.
      89                 :            :                 So it's possible to call dialog again and again for different or same filter list
      90                 :            :                 and ask user for his decision by best performance!
      91                 :            : 
      92                 :            :     @attention  Don't free memory of given list after this call till object will die ... or
      93                 :            :                 you call "ChangeFilters( NULL )"! Then we forget it too.
      94                 :            : 
      95                 :            :     @seealso    method AskForFilter()
      96                 :            : 
      97                 :            :     @param      "pFilterNames", pointer to list of filter names, which should be used for later operations.
      98                 :            :     @return     -
      99                 :            : 
     100                 :            :     @onerror    We clear list box and forget our currently set filter informations completly!
     101                 :            :     @threadsafe no
     102                 :            : *//*-*************************************************************************************************************/
     103                 :          0 : void FilterDialog::ChangeFilters( const FilterNameList* pFilterNames )
     104                 :            : {
     105                 :          0 :     m_pFilterNames = pFilterNames;
     106                 :          0 :     m_lbFilters.Clear();
     107         [ #  # ]:          0 :     if( m_pFilterNames != NULL )
     108                 :            :     {
     109 [ #  # ][ #  # ]:          0 :         for( FilterNameListPtr pItem  = m_pFilterNames->begin();
     110                 :          0 :                                pItem != m_pFilterNames->end()  ;
     111                 :            :                                ++pItem                         )
     112                 :            :         {
     113         [ #  # ]:          0 :             m_lbFilters.InsertEntry( pItem->sUI );
     114                 :            :         }
     115                 :            :     }
     116                 :          0 : }
     117                 :            : 
     118                 :            : /*-************************************************************************************************************//**
     119                 :            :     @short      ask user for his decision
     120                 :            :     @descr      We show the dialog and if user finish it with "OK" - we try to find selected item in internal saved
     121                 :            :                 name list (which you must set in "ChangeFilters()"!). If we return sal_True as result, you can use out
     122                 :            :                 parameter "pSelectedItem" as pointer into your FilterNameList to get selected item realy ...
     123                 :            :                 but if we return sal_False ... user hsa cancel the dialog ... you shouldnt do that. pSelectedItem isnt
     124                 :            :                 set to any valid value then. We don't change them ...
     125                 :            : 
     126                 :            :     @seealso    method ChangeFilters()
     127                 :            : 
     128                 :            :     @param      "pSelectedItem", returns result of selection as pointer into set list of filter names
     129                 :            :                                  (valid for function return sal_True only!)
     130                 :            :     @return     true  => pSelectedItem parameter points into name list and represent use decision
     131                 :            :                 false => use has cancelled dialog (pSelectedItem isnt valid then!)
     132                 :            : 
     133                 :            :     @onerror    We return false ... but don't change pSelectedItem!
     134                 :            :     @threadsafe no
     135                 :            : *//*-*************************************************************************************************************/
     136                 :          0 : bool FilterDialog::AskForFilter( FilterNameListPtr& pSelectedItem )
     137                 :            : {
     138                 :          0 :     bool bSelected = sal_False;
     139                 :            : 
     140         [ #  # ]:          0 :     if( m_pFilterNames != NULL )
     141                 :            :     {
     142         [ #  # ]:          0 :         if( ModalDialog::Execute() == RET_OK )
     143                 :            :         {
     144         [ #  # ]:          0 :             String sEntry = m_lbFilters.GetSelectEntry();
     145         [ #  # ]:          0 :             if( sEntry.Len() > 0 )
     146                 :            :             {
     147         [ #  # ]:          0 :                 int nPos = m_lbFilters.GetSelectEntryPos();
     148         [ #  # ]:          0 :                 if( nPos < (int)(m_pFilterNames->size()) )
     149                 :            :                 {
     150                 :          0 :                     pSelectedItem  = m_pFilterNames->begin();
     151                 :          0 :                     pSelectedItem += nPos;
     152         [ #  # ]:          0 :                     bSelected      = ( pSelectedItem != m_pFilterNames->end() );
     153                 :            :                 }
     154         [ #  # ]:          0 :             }
     155                 :            :         }
     156                 :            :     }
     157                 :            : 
     158                 :          0 :     return bSelected;
     159                 :            : }
     160                 :            : 
     161                 :            : /*-************************************************************************************************************//**
     162                 :            :     @short      helper class to calculate length of given string
     163                 :            :     @descr      Instances of it can be used as callback for INetURLObject::getAbbreviated() method to build
     164                 :            :                 short URLs to show it on GUI. We use in ctor set OutputDevice to call special VCL method ...
     165                 :            : 
     166                 :            :     @seealso    method OutputDevice::GetTextWidth()
     167                 :            :     @seealso    method InetURLObject::getAbbreviated()
     168                 :            : 
     169                 :            :     @param      -
     170                 :            :     @return     -
     171                 :            : 
     172                 :            :     @onerror    -
     173                 :            :     @threadsafe no
     174                 :            : *//*-*************************************************************************************************************/
     175         [ #  # ]:          0 : class StringCalculator : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
     176                 :            : {
     177                 :            :     public:
     178                 :          0 :         StringCalculator( const OutputDevice* pDevice )
     179                 :          0 :             : m_pDevice( pDevice )
     180                 :            :         {
     181                 :          0 :         }
     182                 :            : 
     183                 :          0 :         sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& sString ) throw( ::com::sun::star::uno::RuntimeException )
     184                 :            :         {
     185         [ #  # ]:          0 :             return (sal_Int32)(m_pDevice->GetTextWidth(String(sString)));
     186                 :            :         }
     187                 :            : 
     188                 :            :     private:
     189                 :            :         const OutputDevice* m_pDevice;
     190                 :            : };
     191                 :            : 
     192                 :            : /*-************************************************************************************************************//**
     193                 :            :     @short      try to build short name of given URL to show it n GUI
     194                 :            :     @descr      We detect type of given URL automaticly and build this short name depend on this type ...
     195                 :            :                 If we couldnt make it right we return full given string without any changes ...
     196                 :            : 
     197                 :            :     @seealso    class LocalFileHelper
     198                 :            :     @seealso    method InetURLObject::getAbbreviated()
     199                 :            : 
     200                 :            :     @param      "sName", file name
     201                 :            :     @return     A short file name ...
     202                 :            : 
     203                 :            :     @onerror    We return given name without any changes.
     204                 :            :     @threadsafe no
     205                 :            : *//*-*************************************************************************************************************/
     206                 :          0 : String FilterDialog::impl_buildUIFileName( const String& sName )
     207                 :            : {
     208                 :          0 :     String sShortName( sName );
     209                 :            : 
     210 [ #  # ][ #  # ]:          0 :     if( ::utl::LocalFileHelper::ConvertURLToSystemPath( sName, sShortName ) == sal_True )
     211                 :            :     {
     212                 :            :         // its a system file ... build short name by using osl functionality
     213                 :            :     }
     214                 :            :     else
     215                 :            :     {
     216                 :            :         // otherwise its really a url ... build short name by using INetURLObject
     217 [ #  # ][ #  # ]:          0 :         ::com::sun::star::uno::Reference< ::com::sun::star::util::XStringWidth > xStringCalculator( new StringCalculator(&m_ftURL) );
                 [ #  # ]
     218         [ #  # ]:          0 :         if( xStringCalculator.is() == sal_True )
     219                 :            :         {
     220 [ #  # ][ #  # ]:          0 :             INetURLObject aBuilder   ( sName );
     221         [ #  # ]:          0 :             Size          aSize      = m_ftURL.GetOutputSize();
     222 [ #  # ][ #  # ]:          0 :                           sShortName = aBuilder.getAbbreviated( xStringCalculator, aSize.Width(), INetURLObject::DECODE_UNAMBIGUOUS );
                 [ #  # ]
     223                 :          0 :         }
     224                 :            :     }
     225                 :            : 
     226                 :          0 :     return sShortName;
     227                 :            : }
     228                 :            : 
     229                 :            : }   // namespace uui
     230                 :            : 
     231                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10