cid#1607171 Data race condition
[LibreOffice.git] / vcl / source / app / brand.cxx
blob78493d58eb306b6e0956c4169f259a938cb9e6be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <string_view>
24 #include <config_folders.h>
26 #include <rtl/ustring.hxx>
27 #include <rtl/bootstrap.hxx>
28 #include <osl/process.h>
29 #include <tools/urlobj.hxx>
30 #include <tools/stream.hxx>
31 #include <i18nlangtag/languagetag.hxx>
32 #include <vcl/filter/PngImageReader.hxx>
33 #include <vcl/bitmapex.hxx>
34 #include <vcl/svapp.hxx>
36 namespace {
37 bool loadPng( std::u16string_view rPath, BitmapEx &rBitmap)
39 INetURLObject aObj( rPath );
40 SvFileStream aStrm( aObj.PathToFileName(), StreamMode::STD_READ );
41 if ( !aStrm.GetError() ) {
42 vcl::PngImageReader aReader( aStrm );
43 rBitmap = aReader.read();
44 return !rBitmap.IsEmpty();
46 else
47 return false;
49 bool tryLoadPng( std::u16string_view rBaseDir, std::u16string_view rName, BitmapEx& rBitmap )
51 return loadPng( rtl::Concat2View(OUString::Concat(rBaseDir) + "/" LIBO_ETC_FOLDER + rName), rBitmap);
55 bool Application::LoadBrandBitmap (std::u16string_view pName, BitmapEx &rBitmap)
57 // TODO - if we want more flexibility we could add a branding path
58 // in an rc file perhaps fallback to "about.bmp"
59 OUString aBaseDir( u"$BRAND_BASE_DIR"_ustr);
60 rtl::Bootstrap::expandMacros( aBaseDir );
61 OUString aBaseName(OUStringChar('/') + pName);
62 OUString aPng( u".png"_ustr );
64 rtl_Locale *pLoc = nullptr;
65 osl_getProcessLocale (&pLoc);
66 LanguageTag aLanguageTag( *pLoc);
68 ::std::vector< OUString > aFallbacks( aLanguageTag.getFallbackStrings( true));
69 for (const OUString & aFallback : aFallbacks)
71 if (tryLoadPng( aBaseDir, Concat2View(aBaseName + "-" + aFallback + aPng), rBitmap))
72 return true;
75 return tryLoadPng( aBaseDir, Concat2View(aBaseName + aPng), rBitmap);
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */