LCOV - code coverage report
Current view: top level - vcl/source/app - IconThemeSelector.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 52 55 94.5 %
Date: 2014-04-11 Functions: 14 14 100.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             : #include <vcl/IconThemeSelector.hxx>
      11             : 
      12             : #include <vcl/IconThemeScanner.hxx>
      13             : #include <vcl/IconThemeInfo.hxx>
      14             : 
      15             : #include <algorithm>
      16             : 
      17             : namespace vcl {
      18             : 
      19             : /*static*/ const OUString
      20         172 : IconThemeSelector::HIGH_CONTRAST_ICON_THEME_ID("hicontrast");
      21             : 
      22             : /*static*/ const OUString
      23         172 : IconThemeSelector::FALLBACK_ICON_THEME_ID("tango");
      24             : 
      25             : namespace {
      26             : 
      27             :     class SameTheme :
      28             :         public std::unary_function<const vcl::IconThemeInfo &, bool>
      29             :     {
      30             :     private:
      31             :         const OUString& m_rThemeId;
      32             :     public:
      33      119211 :         SameTheme(const OUString &rThemeId) : m_rThemeId(rThemeId) {}
      34      476858 :         bool operator()(const vcl::IconThemeInfo &rInfo)
      35             :         {
      36      476858 :             return m_rThemeId == rInfo.GetThemeId();
      37             :         }
      38             :     };
      39             : 
      40      119211 : bool icon_theme_is_in_installed_themes(const OUString& theme,
      41             :         const std::vector<IconThemeInfo>& installedThemes)
      42             : {
      43             :     return std::find_if(installedThemes.begin(), installedThemes.end(),
      44             :                SameTheme(theme)
      45      119211 :            ) != installedThemes.end();
      46             : }
      47             : 
      48             : } // end anonymous namespace
      49             : 
      50         302 : IconThemeSelector::IconThemeSelector()
      51         302 : : mUseHighContrastTheme(false)
      52             : {
      53         302 : }
      54             : 
      55             : /*static*/ OUString
      56         250 : IconThemeSelector::GetIconThemeForDesktopEnvironment(const OUString& desktopEnvironment)
      57             : {
      58         250 :     OUString r;
      59         500 :     if ( desktopEnvironment.equalsIgnoreAsciiCase("tde") ||
      60         250 :          desktopEnvironment.equalsIgnoreAsciiCase("kde") ) {
      61           0 :         r = "crystal";
      62             :     }
      63         250 :     else if ( desktopEnvironment.equalsIgnoreAsciiCase("kde4") ) {
      64           1 :         r = "oxygen";
      65             :     }
      66             :     else {
      67         249 :         r = FALLBACK_ICON_THEME_ID;
      68             :     }
      69         250 :     return r;
      70             : }
      71             : 
      72             : OUString
      73         251 : IconThemeSelector::SelectIconThemeForDesktopEnvironment(
      74             :         const std::vector<IconThemeInfo>& installedThemes,
      75             :         const OUString& desktopEnvironment) const
      76             : {
      77         251 :     if (!mPreferredIconTheme.isEmpty()) {
      78           1 :         if (icon_theme_is_in_installed_themes(mPreferredIconTheme, installedThemes)) {
      79           1 :             return mPreferredIconTheme;
      80             :         }
      81             :     }
      82             : 
      83         250 :     OUString themeForDesktop = GetIconThemeForDesktopEnvironment(desktopEnvironment);
      84         250 :     if (icon_theme_is_in_installed_themes(themeForDesktop, installedThemes)) {
      85         250 :         return themeForDesktop;
      86             :     }
      87             : 
      88           0 :     return ReturnFallback(installedThemes);
      89             : }
      90             : 
      91             : OUString
      92      118960 : IconThemeSelector::SelectIconTheme(
      93             :         const std::vector<IconThemeInfo>& installedThemes,
      94             :         const OUString& theme) const
      95             : {
      96      118960 :     if (mUseHighContrastTheme) {
      97           1 :         if (icon_theme_is_in_installed_themes(HIGH_CONTRAST_ICON_THEME_ID, installedThemes)) {
      98           1 :             return HIGH_CONTRAST_ICON_THEME_ID;
      99             :         }
     100             :     }
     101             : 
     102      118959 :     if (icon_theme_is_in_installed_themes(theme, installedThemes)) {
     103      118940 :         return theme;
     104             :     }
     105             : 
     106          19 :     return ReturnFallback(installedThemes);
     107             : }
     108             : 
     109             : void
     110           5 : IconThemeSelector::SetUseHighContrastTheme(bool v)
     111             : {
     112           5 :     mUseHighContrastTheme = v;
     113           5 : }
     114             : 
     115             : void
     116           3 : IconThemeSelector::SetPreferredIconTheme(const OUString& theme)
     117             : {
     118           3 :     mPreferredIconTheme = theme;
     119           3 : }
     120             : 
     121             : bool
     122       29624 : IconThemeSelector::operator==(const vcl::IconThemeSelector& other) const
     123             : {
     124       29624 :     if (this == &other) {
     125           0 :         return true;
     126             :     }
     127       29624 :     if (mPreferredIconTheme != other.mPreferredIconTheme) {
     128           1 :         return false;
     129             :     }
     130       29623 :     if (mUseHighContrastTheme != other.mUseHighContrastTheme) {
     131           1 :         return false;
     132             :     }
     133       29622 :     return true;
     134             : }
     135             : 
     136             : bool
     137       29622 : IconThemeSelector::operator!=(const vcl::IconThemeSelector& other) const
     138             : {
     139       29622 :     return !((*this) == other);
     140             : }
     141             : 
     142             : /*static*/ OUString
     143          19 : IconThemeSelector::ReturnFallback(const std::vector<IconThemeInfo>& installedThemes)
     144             : {
     145          19 :     if (!installedThemes.empty()) {
     146          18 :         return installedThemes.front().GetThemeId();
     147             :     }
     148             :     else {
     149           1 :         return FALLBACK_ICON_THEME_ID;
     150             :     }
     151             : }
     152             : 
     153         516 : } /* namespace vcl */
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10