LibreOffice Module sfx2 (master) 1
alienwarn.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
20#include <alienwarn.hxx>
21#include <officecfg/Office/Common.hxx>
22
24 std::u16string_view _rFormatName,
25 const OUString& _rDefaultExtension,
26 bool rDefaultIsAlien)
27 : MessageDialogController(pParent, "sfx/ui/alienwarndialog.ui", "AlienWarnDialog", "ask")
28 , m_xKeepCurrentBtn(m_xBuilder->weld_button("save"))
29 , m_xUseDefaultFormatBtn(m_xBuilder->weld_button("cancel"))
30 , m_xWarningOnBox(m_xBuilder->weld_check_button("ask"))
31{
32 OUString aExtension = "ODF";
33
34 // replace formatname (text)
35 OUString sInfoText = m_xDialog->get_primary_text();
36 sInfoText = sInfoText.replaceAll("%FORMATNAME", _rFormatName);
37 m_xDialog->set_primary_text(sInfoText);
38
39 // replace formatname (button)
40 sInfoText = m_xKeepCurrentBtn->get_label();
41 sInfoText = sInfoText.replaceAll("%FORMATNAME", _rFormatName);
42 m_xKeepCurrentBtn->set_label(sInfoText);
43
44 // hide ODF explanation if default format is alien
45 // and set the proper extension in the button
46 if (rDefaultIsAlien)
47 {
48 m_xDialog->set_secondary_text(OUString());
49 aExtension = _rDefaultExtension.toAsciiUpperCase();
50 }
51
52 // replace defaultextension (button)
53 sInfoText = m_xUseDefaultFormatBtn->get_label();
54 sInfoText = sInfoText.replaceAll("%DEFAULTEXTENSION", aExtension);
55 m_xUseDefaultFormatBtn->set_label(sInfoText);
56
57 // load value of "warning on" checkbox from save options
58 m_xWarningOnBox->set_active(officecfg::Office::Common::Save::Document::WarnAlienFormat::get());
59}
60
62{
63 try
64 {
65 // save value of "warning off" checkbox, if necessary
66 bool bChecked = m_xWarningOnBox->get_active();
67 if (officecfg::Office::Common::Save::Document::WarnAlienFormat::get() != bChecked)
68 {
70 officecfg::Office::Common::Save::Document::WarnAlienFormat::set(bChecked, xChanges);
71 xChanges->commit();
72 }
73 }
74 catch (...)
75 {
76 }
77}
78
79/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xUseDefaultFormatBtn
Definition: alienwarn.hxx:28
std::unique_ptr< weld::Button > m_xKeepCurrentBtn
Definition: alienwarn.hxx:27
SfxAlienWarningDialog(weld::Window *pParent, std::u16string_view _rFormatName, const OUString &_rDefaultExtension, bool rDefaultIsAlien)
Definition: alienwarn.cxx:23
std::unique_ptr< weld::CheckButton > m_xWarningOnBox
Definition: alienwarn.hxx:29
virtual ~SfxAlienWarningDialog() override
Definition: alienwarn.cxx:61
static std::shared_ptr< ConfigurationChanges > create()
std::unique_ptr< weld::MessageDialog > m_xDialog
std::unique_ptr< weld::CheckButton > m_xWarningOnBox