/src/libreoffice/unotools/source/config/docinfohelper.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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <rtl/ustrbuf.hxx> |
21 | | #include <unotools/configmgr.hxx> |
22 | | #include <unotools/bootstrap.hxx> |
23 | | #include <unotools/docinfohelper.hxx> |
24 | | #include <rtl/bootstrap.hxx> |
25 | | #include <officecfg/Office/Common.hxx> |
26 | | |
27 | | using namespace ::com::sun::star; |
28 | | |
29 | | namespace utl |
30 | | { |
31 | | |
32 | | OUString DocInfoHelper::GetGeneratorString() |
33 | 104 | { |
34 | 104 | static const OUString sGenerator = []() |
35 | 104 | { |
36 | 1 | OUString aResultOverride = officecfg::Office::Common::Save::Document::GeneratorOverride::get(); |
37 | 1 | if( !aResultOverride.isEmpty()) |
38 | 0 | return aResultOverride; |
39 | | |
40 | 1 | OUStringBuffer aResult(128); |
41 | | |
42 | | // First product: branded name + version |
43 | | // version is <product_versions>_<product_extension>$<platform> |
44 | | |
45 | | // plain product name |
46 | 1 | OUString aValue( utl::ConfigManager::getProductName() ); |
47 | 1 | if ( !aValue.isEmpty() ) |
48 | 0 | { |
49 | 0 | aResult.append( aValue.replace( ' ', '_' ) + "/" ); |
50 | |
|
51 | 0 | aValue = utl::ConfigManager::getProductVersion(); |
52 | 0 | if ( !aValue.isEmpty() ) |
53 | 0 | { |
54 | 0 | aResult.append( aValue.replace( ' ', '_' ) ); |
55 | |
|
56 | 0 | aValue = utl::ConfigManager::getProductExtension(); |
57 | 0 | if ( !aValue.isEmpty() ) |
58 | 0 | { |
59 | 0 | aResult.append( aValue.replace( ' ', '_' ) ); |
60 | 0 | } |
61 | 0 | } |
62 | |
|
63 | 0 | OUString os( u"$_OS"_ustr ); |
64 | 0 | OUString arch( u"$_ARCH"_ustr ); |
65 | 0 | ::rtl::Bootstrap::expandMacros(os); |
66 | 0 | ::rtl::Bootstrap::expandMacros(arch); |
67 | 0 | aResult.append( "$" + os + "_" + arch + " " ); |
68 | 0 | } |
69 | | |
70 | | // second product: LibreOffice_project/<build_information> |
71 | | // build_information has '(' and '[' encoded as '$', ')' and ']' ignored |
72 | | // and ':' replaced by '-' |
73 | 1 | { |
74 | 1 | aResult.append( "LibreOffice_project/" ); |
75 | 1 | OUString aBuildId( Bootstrap::getBuildIdData( OUString() ) ); |
76 | 1 | for( sal_Int32 i=0; i < aBuildId.getLength(); i++ ) |
77 | 0 | { |
78 | 0 | sal_Unicode c = aBuildId[i]; |
79 | 0 | switch( c ) |
80 | 0 | { |
81 | 0 | case '(': |
82 | 0 | case '[': |
83 | 0 | aResult.append( '$' ); |
84 | 0 | break; |
85 | 0 | case ')': |
86 | 0 | case ']': |
87 | 0 | break; |
88 | 0 | case ':': |
89 | 0 | aResult.append( '-' ); |
90 | 0 | break; |
91 | 0 | default: |
92 | 0 | aResult.append( c ); |
93 | 0 | break; |
94 | 0 | } |
95 | 0 | } |
96 | 1 | } |
97 | | |
98 | 1 | return aResult.makeStringAndClear(); |
99 | 1 | }(); |
100 | 104 | return sGenerator; |
101 | 104 | } |
102 | | |
103 | | } // end of namespace utl |
104 | | |
105 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |