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

Generated by: LCOV version 1.10