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