LCOV - code coverage report
Current view: top level - vcl/source/app - IconThemeSelector.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 52 55 94.5 %
Date: 2014-11-03 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         411 : IconThemeSelector::HIGH_CONTRAST_ICON_THEME_ID("hicontrast");
      21             : 
      22             : /*static*/ const OUString
      23         411 : 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      344688 :         SameTheme(const OUString &rThemeId) : m_rThemeId(rThemeId) {}
      34     1723530 :         bool operator()(const vcl::IconThemeInfo &rInfo)
      35             :         {
      36     1723530 :             return m_rThemeId == rInfo.GetThemeId();
      37             :         }
      38             :     };
      39             : 
      40      344688 : 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      344688 :            ) != installedThemes.end();
      46             : }
      47             : 
      48             : } // end anonymous namespace
      49             : 
      50         701 : IconThemeSelector::IconThemeSelector()
      51         701 : : mUseHighContrastTheme(false)
      52             : {
      53         701 : }
      54             : 
      55             : /*static*/ OUString
      56         548 : IconThemeSelector::GetIconThemeForDesktopEnvironment(const OUString& desktopEnvironment)
      57             : {
      58         548 :     OUString r;
      59        1096 :     if ( desktopEnvironment.equalsIgnoreAsciiCase("tde") ||
      60         548 :          desktopEnvironment.equalsIgnoreAsciiCase("kde") ) {
      61           0 :         r = "crystal";
      62             :     }
      63         548 :     else if ( desktopEnvironment.equalsIgnoreAsciiCase("kde4") ) {
      64           2 :         r = "oxygen";
      65             :     }
      66             :     else {
      67         546 :         r = FALLBACK_ICON_THEME_ID;
      68             :     }
      69         548 :     return r;
      70             : }
      71             : 
      72             : OUString
      73         550 : IconThemeSelector::SelectIconThemeForDesktopEnvironment(
      74             :         const std::vector<IconThemeInfo>& installedThemes,
      75             :         const OUString& desktopEnvironment) const
      76             : {
      77         550 :     if (!mPreferredIconTheme.isEmpty()) {
      78           2 :         if (icon_theme_is_in_installed_themes(mPreferredIconTheme, installedThemes)) {
      79           2 :             return mPreferredIconTheme;
      80             :         }
      81             :     }
      82             : 
      83         548 :     OUString themeForDesktop = GetIconThemeForDesktopEnvironment(desktopEnvironment);
      84         548 :     if (icon_theme_is_in_installed_themes(themeForDesktop, installedThemes)) {
      85         548 :         return themeForDesktop;
      86             :     }
      87             : 
      88           0 :     return ReturnFallback(installedThemes);
      89             : }
      90             : 
      91             : OUString
      92      344138 : IconThemeSelector::SelectIconTheme(
      93             :         const std::vector<IconThemeInfo>& installedThemes,
      94             :         const OUString& theme) const
      95             : {
      96      344138 :     if (mUseHighContrastTheme) {
      97           2 :         if (icon_theme_is_in_installed_themes(HIGH_CONTRAST_ICON_THEME_ID, installedThemes)) {
      98           2 :             return HIGH_CONTRAST_ICON_THEME_ID;
      99             :         }
     100             :     }
     101             : 
     102      344136 :     if (icon_theme_is_in_installed_themes(theme, installedThemes)) {
     103      344058 :         return theme;
     104             :     }
     105             : 
     106          78 :     return ReturnFallback(installedThemes);
     107             : }
     108             : 
     109             : void
     110          10 : IconThemeSelector::SetUseHighContrastTheme(bool v)
     111             : {
     112          10 :     mUseHighContrastTheme = v;
     113          10 : }
     114             : 
     115             : void
     116           6 : IconThemeSelector::SetPreferredIconTheme(const OUString& theme)
     117             : {
     118           6 :     mPreferredIconTheme = theme;
     119           6 : }
     120             : 
     121             : bool
     122       81103 : IconThemeSelector::operator==(const vcl::IconThemeSelector& other) const
     123             : {
     124       81103 :     if (this == &other) {
     125           0 :         return true;
     126             :     }
     127       81103 :     if (mPreferredIconTheme != other.mPreferredIconTheme) {
     128           2 :         return false;
     129             :     }
     130       81101 :     if (mUseHighContrastTheme != other.mUseHighContrastTheme) {
     131           2 :         return false;
     132             :     }
     133       81099 :     return true;
     134             : }
     135             : 
     136             : bool
     137       81099 : IconThemeSelector::operator!=(const vcl::IconThemeSelector& other) const
     138             : {
     139       81099 :     return !((*this) == other);
     140             : }
     141             : 
     142             : /*static*/ OUString
     143          78 : IconThemeSelector::ReturnFallback(const std::vector<IconThemeInfo>& installedThemes)
     144             : {
     145          78 :     if (!installedThemes.empty()) {
     146          76 :         return installedThemes.front().GetThemeId();
     147             :     }
     148             :     else {
     149           2 :         return FALLBACK_ICON_THEME_ID;
     150             :     }
     151             : }
     152             : 
     153        1233 : } /* namespace vcl */
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10