/src/libreoffice/vcl/source/printer/Options.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 <comphelper/processfactory.hxx> |
21 | | |
22 | | #include <vcl/printer/Options.hxx> |
23 | | |
24 | | #include <com/sun/star/beans/PropertyValue.hpp> |
25 | | #include <com/sun/star/beans/XPropertySet.hpp> |
26 | | #include <com/sun/star/configuration/theDefaultProvider.hpp> |
27 | | #include <com/sun/star/container/XNameAccess.hpp> |
28 | | #include <com/sun/star/uno/XComponentContext.hpp> |
29 | | #include <com/sun/star/lang/XMultiServiceFactory.hpp> |
30 | | |
31 | | namespace vcl::printer |
32 | | { |
33 | | void Options::ReadFromConfig(bool i_bFile) |
34 | 0 | { |
35 | 0 | bool bSuccess = false; |
36 | | // save old state in case something goes wrong |
37 | 0 | Options aOldValues(*this); |
38 | | |
39 | | // get the configuration service |
40 | 0 | css::uno::Reference<css::lang::XMultiServiceFactory> xConfigProvider; |
41 | 0 | css::uno::Reference<css::container::XNameAccess> xConfigAccess; |
42 | 0 | try |
43 | 0 | { |
44 | | // get service provider |
45 | 0 | const css::uno::Reference<css::uno::XComponentContext>& xContext( |
46 | 0 | comphelper::getProcessComponentContext()); |
47 | | // create configuration hierarchical access name |
48 | 0 | try |
49 | 0 | { |
50 | 0 | xConfigProvider = css::configuration::theDefaultProvider::get(xContext); |
51 | |
|
52 | 0 | css::beans::PropertyValue aVal; |
53 | 0 | aVal.Name = "nodepath"; |
54 | 0 | if (i_bFile) |
55 | 0 | aVal.Value <<= u"/org.openoffice.Office.Common/Print/Option/File"_ustr; |
56 | 0 | else |
57 | 0 | aVal.Value <<= u"/org.openoffice.Office.Common/Print/Option/Printer"_ustr; |
58 | 0 | xConfigAccess.set(xConfigProvider->createInstanceWithArguments( |
59 | 0 | u"com.sun.star.configuration.ConfigurationAccess"_ustr, |
60 | 0 | { css::uno::Any(aVal) }), |
61 | 0 | css::uno::UNO_QUERY); |
62 | 0 | if (xConfigAccess.is()) |
63 | 0 | { |
64 | 0 | css::uno::Reference<css::beans::XPropertySet> xSet(xConfigAccess, |
65 | 0 | css::uno::UNO_QUERY); |
66 | 0 | if (xSet.is()) |
67 | 0 | { |
68 | 0 | sal_Int32 nValue = 0; |
69 | 0 | bool bValue = false; |
70 | 0 | if (xSet->getPropertyValue(u"ReduceTransparency"_ustr) >>= bValue) |
71 | 0 | SetReduceTransparency(bValue); |
72 | 0 | if (xSet->getPropertyValue(u"ReducedTransparencyMode"_ustr) >>= nValue) |
73 | 0 | SetReducedTransparencyMode(static_cast<TransparencyMode>(nValue)); |
74 | 0 | if (xSet->getPropertyValue(u"ReduceGradients"_ustr) >>= bValue) |
75 | 0 | SetReduceGradients(bValue); |
76 | 0 | if (xSet->getPropertyValue(u"ReducedGradientMode"_ustr) >>= nValue) |
77 | 0 | SetReducedGradientMode(static_cast<GradientMode>(nValue)); |
78 | 0 | if (xSet->getPropertyValue(u"ReducedGradientStepCount"_ustr) >>= nValue) |
79 | 0 | SetReducedGradientStepCount(static_cast<sal_uInt16>(nValue)); |
80 | 0 | if (xSet->getPropertyValue(u"ReduceBitmaps"_ustr) >>= bValue) |
81 | 0 | SetReduceBitmaps(bValue); |
82 | 0 | if (xSet->getPropertyValue(u"ReducedBitmapMode"_ustr) >>= nValue) |
83 | 0 | SetReducedBitmapMode(static_cast<BitmapMode>(nValue)); |
84 | 0 | if (xSet->getPropertyValue(u"ReducedBitmapResolution"_ustr) >>= nValue) |
85 | 0 | SetReducedBitmapResolution(static_cast<sal_uInt16>(nValue)); |
86 | 0 | if (xSet->getPropertyValue(u"ReducedBitmapIncludesTransparency"_ustr) |
87 | 0 | >>= bValue) |
88 | 0 | SetReducedBitmapIncludesTransparency(bValue); |
89 | 0 | if (xSet->getPropertyValue(u"ConvertToGreyscales"_ustr) >>= bValue) |
90 | 0 | SetConvertToGreyscales(bValue); |
91 | |
|
92 | 0 | bSuccess = true; |
93 | 0 | } |
94 | 0 | } |
95 | 0 | } |
96 | 0 | catch (const css::uno::Exception&) |
97 | 0 | { |
98 | 0 | } |
99 | 0 | } |
100 | 0 | catch (const css::lang::WrappedTargetException&) |
101 | 0 | { |
102 | 0 | } |
103 | |
|
104 | 0 | if (!bSuccess) |
105 | 0 | *this = aOldValues; |
106 | 0 | } |
107 | | } |
108 | | |
109 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |