LCOV - code coverage report
Current view: top level - svx/source/gallery2 - galini.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 37 0.0 %
Date: 2014-04-14 Functions: 0 1 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             : 
      10             : /*
      11             :  * The world's quickest and lamest .desktop / .ini file parser.
      12             :  * Ideally the .thm file would move to a .desktop file in
      13             :  * future.
      14             :  */
      15             : 
      16             : #include <sal/config.h>
      17             : 
      18             : #include <unotools/streamwrap.hxx>
      19             : #include <unotools/ucbstreamhelper.hxx>
      20             : #include <unotools/tempfile.hxx>
      21             : #include <svx/gallery1.hxx>
      22             : #include <i18nlangtag/languagetag.hxx>
      23             : #include <unotools/syslocale.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <vcl/settings.hxx>
      26             : 
      27           0 : OUString GalleryThemeEntry::ReadStrFromIni(const OUString &aKeyName )
      28             : {
      29             :     SvStream *pStrm = ::utl::UcbStreamHelper::CreateStream(
      30           0 :                                 GetStrURL().GetMainURL( INetURLObject::NO_DECODE ),
      31           0 :                                 STREAM_READ );
      32             : 
      33           0 :     const LanguageTag &rLangTag = Application::GetSettings().GetUILanguageTag();
      34             : 
      35           0 :     ::std::vector< OUString > aFallbacks = rLangTag.getFallbackStrings( true);
      36             : 
      37           0 :     OUString aResult;
      38           0 :     sal_Int32 nRank = 42;
      39             : 
      40           0 :     if( pStrm )
      41             :     {
      42           0 :         OString aLine;
      43           0 :         while( pStrm->ReadLine( aLine ) )
      44             :         {
      45           0 :             OUString aKey;
      46           0 :             OUString aLocale;
      47           0 :             OUString aValue;
      48             :             sal_Int32 n;
      49             : 
      50             :             // comments
      51           0 :             if( aLine.startsWith( "#" ) )
      52           0 :                 continue;
      53             : 
      54             :             // a[en_US] = Bob
      55           0 :             if( ( n = aLine.indexOf( '=' ) ) >= 1)
      56             :             {
      57           0 :                 aKey = OStringToOUString(
      58           0 :                     aLine.copy( 0, n ).trim(), RTL_TEXTENCODING_ASCII_US );
      59           0 :                 aValue = OStringToOUString(
      60           0 :                     aLine.copy( n + 1 ).trim(), RTL_TEXTENCODING_UTF8 );
      61             : 
      62           0 :                 if( ( n = aKey.indexOf( '[' ) ) >= 1 )
      63             :                 {
      64           0 :                     aLocale = aKey.copy( n + 1 ).trim();
      65           0 :                     aKey = aKey.copy( 0, n ).trim();
      66           0 :                     if( (n = aLocale.indexOf( ']' ) ) >= 1 )
      67           0 :                         aLocale = aLocale.copy( 0, n ).trim();
      68             :                 }
      69             :             }
      70             :             SAL_INFO("svx", "ini file has '" << aKey << "' [ '" << aLocale << "' ] = '" << aValue << "'");
      71             : 
      72             :             // grisly language matching, is this not available somewhere else?
      73           0 :             if( aKey == aKeyName )
      74             :             {
      75             :                 /* FIXME-BCP47: what is this supposed to do? */
      76           0 :                 n = 0;
      77           0 :                 OUString aLang = aLocale.replace('_','-');
      78           0 :                 for( std::vector< OUString >::const_iterator i = aFallbacks.begin();
      79           0 :                      i != aFallbacks.end(); ++i, ++n )
      80             :                 {
      81             :                     SAL_INFO( "svx", "compare '" << aLang << "' with '" << *i << "' rank " << nRank << " vs. " << n );
      82           0 :                     if( *i == aLang && n < nRank ) {
      83           0 :                         nRank = n; // try to get the most accurate match
      84           0 :                         aResult = aValue;
      85             :                     }
      86           0 :                 }
      87             :             }
      88           0 :         }
      89           0 :         delete pStrm;
      90             :     }
      91             : 
      92             :     SAL_INFO( "svx", "readStrFromIni returns '" << aResult << "'");
      93           0 :     return aResult;
      94             : }
      95             : 
      96             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10