Use correct object
[LibreOffice.git] / cui / source / options / optopencl.cxx
blobabc4784e4d7ef73ce4e3ab29e350754af5c2aad3
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 <vcl/svapp.hxx>
21 #include <vcl/weld.hxx>
22 #include <opencl/openclconfig.hxx>
23 #include <opencl/openclwrapper.hxx>
24 #include <officecfg/Office/Common.hxx>
25 #include <svtools/restartdialog.hxx>
27 #include "optopencl.hxx"
29 SvxOpenCLTabPage::SvxOpenCLTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
30 : SfxTabPage(pPage, pController, u"cui/ui/optopenclpage.ui"_ustr, u"OptOpenCLPage"_ustr, &rSet)
31 , maConfig(OpenCLConfig::get())
32 , mxUseOpenCL(m_xBuilder->weld_check_button(u"useopencl"_ustr))
33 , mxUseOpenImg(m_xBuilder->weld_widget(u"lockuseopencl"_ustr))
34 , mxOclUsed(m_xBuilder->weld_label(u"openclused"_ustr))
35 , mxOclNotUsed(m_xBuilder->weld_label(u"openclnotused"_ustr))
37 mxUseOpenCL->set_active(maConfig.mbUseOpenCL);
38 mxUseOpenCL->set_sensitive(!officecfg::Office::Common::Misc::UseOpenCL::isReadOnly());
39 mxUseOpenImg->set_visible(officecfg::Office::Common::Misc::UseOpenCL::isReadOnly());
41 bool bCLUsed = openclwrapper::GPUEnv::isOpenCLEnabled();
42 mxOclUsed->set_visible(bCLUsed);
43 mxOclNotUsed->set_visible(!bCLUsed);
46 SvxOpenCLTabPage::~SvxOpenCLTabPage()
50 std::unique_ptr<SfxTabPage> SvxOpenCLTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
52 return std::make_unique<SvxOpenCLTabPage>(pPage, pController, *rAttrSet);
55 OUString SvxOpenCLTabPage::GetAllStrings()
57 OUString sAllStrings;
58 OUString labels[] = { u"label1"_ustr, u"openclnotused"_ustr, u"openclused"_ustr };
60 for (const auto& label : labels)
62 if (const auto pString = m_xBuilder->weld_label(label))
63 sAllStrings += pString->get_label() + " ";
66 sAllStrings += mxUseOpenCL->get_label() + " ";
68 return sAllStrings.replaceAll("_", "");
71 bool SvxOpenCLTabPage::FillItemSet( SfxItemSet* )
73 bool bModified = false;
74 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
76 if (mxUseOpenCL->get_state_changed_from_saved())
77 maConfig.mbUseOpenCL = mxUseOpenCL->get_active();
79 if (maConfig != OpenCLConfig::get())
81 maConfig.set();
82 bModified = true;
85 if (bModified)
87 batch->commit();
88 SolarMutexGuard aGuard;
89 if (svtools::executeRestartDialog(comphelper::getProcessComponentContext(), nullptr,
90 svtools::RESTART_REASON_OPENCL))
91 GetDialogController()->response(RET_OK);
94 return bModified;
97 void SvxOpenCLTabPage::Reset( const SfxItemSet* )
99 maConfig = OpenCLConfig::get();
101 mxUseOpenCL->set_active(maConfig.mbUseOpenCL);
102 mxUseOpenImg->set_visible(officecfg::Office::Common::Misc::UseOpenCL::isReadOnly());
103 mxUseOpenCL->save_state();
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */