Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/app/IconThemeScanner.cxx
Line
Count
Source
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 <sal/config.h>
11
#include <sal/log.hxx>
12
#include <IconThemeScanner.hxx>
13
14
#include <salhelper/linkhelper.hxx>
15
#include <unotools/pathoptions.hxx>
16
#include <vcl/IconThemeInfo.hxx>
17
#include <o3tl/string_view.hxx>
18
19
namespace vcl
20
{
21
22
3
IconThemeScanner::IconThemeScanner() = default;
23
24
bool IconThemeScanner::addResource(const OUString& rURL)
25
0
{
26
0
    if (!IconThemeInfo::UrlCanBeParsed(rURL)) {
27
0
        return false;
28
0
    }
29
0
    SAL_INFO("vcl.app", "Found a file that seems to be an icon theme: '" << rURL << "'" );
30
0
    IconThemeInfo newTheme(rURL);
31
0
    mFoundIconThemes.push_back(newTheme);
32
0
    SAL_INFO("vcl.app", "Adding the file as '" << newTheme.GetDisplayName() <<
33
0
            "' with id '" << newTheme.GetThemeId() << "'.");
34
0
    return true;
35
0
}
36
37
bool IconThemeScanner::isValidResource(const OUString& filename)
38
0
{
39
    // check whether we can construct an IconThemeInfo from it
40
0
    if (!IconThemeInfo::UrlCanBeParsed(filename))
41
0
    {
42
0
        SAL_INFO("vcl.app", "File '" << filename << "' does not seem to be an icon theme.");
43
0
        return false;
44
0
    }
45
46
0
    osl::FileStatus fileStatus(osl_FileStatus_Mask_Type);
47
0
    if (!vcl::file::readFileStatus(fileStatus, filename))
48
0
        return false;
49
50
0
    if (!fileStatus.isRegular())
51
0
        return false;
52
53
0
    return true;
54
0
}
55
56
bool
57
IconThemeScanner::IconThemeIsInstalled(const OUString& themeId) const
58
0
{
59
0
    return IconThemeInfo::IconThemeIsInVector(mFoundIconThemes, themeId);
60
0
}
61
62
/*static*/ OUString
63
IconThemeScanner::GetStandardIconThemePath()
64
6
{
65
6
    SvtPathOptions aPathOptions;
66
6
    return aPathOptions.GetIconsetPath();
67
6
}
68
69
namespace
70
{
71
    class SameTheme
72
    {
73
    private:
74
        const OUString& m_rThemeId;
75
    public:
76
0
        explicit SameTheme(const OUString &rThemeId) : m_rThemeId(rThemeId) {}
77
        bool operator()(const vcl::IconThemeInfo &rInfo)
78
0
        {
79
0
            return m_rThemeId == rInfo.GetThemeId();
80
0
        }
81
    };
82
}
83
84
const vcl::IconThemeInfo&
85
IconThemeScanner::GetIconThemeInfo(const OUString& themeId)
86
0
{
87
0
    std::vector<IconThemeInfo>::iterator info = std::find_if(mFoundIconThemes.begin(), mFoundIconThemes.end(),
88
0
        SameTheme(themeId));
89
0
    if (info == mFoundIconThemes.end()) {
90
0
        SAL_WARN("vcl.app", "Requested information for icon theme with id '" << themeId
91
0
                << "' which does not exist.");
92
0
        throw std::runtime_error("Requested information on not-installed icon theme");
93
0
    }
94
0
    return *info;
95
0
}
96
97
} // end namespace vcl
98
99
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */