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

Generated by: LCOV version 1.10