LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / dialog / alienwarn.cxx
blob8d27ef81d412e355c09bfc71f72906d01b9b67e9
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 <unotools/saveopt.hxx>
21 #include <alienwarn.hxx>
22 #include <officecfg/Office/Common.hxx>
24 SfxAlienWarningDialog::SfxAlienWarningDialog(weld::Window* pParent,
25 std::u16string_view _rFormatName,
26 const OUString& _rDefaultExtension,
27 bool rDefaultIsAlien)
28 : MessageDialogController(pParent, "sfx/ui/alienwarndialog.ui", "AlienWarnDialog", "ask")
29 , m_xKeepCurrentBtn(m_xBuilder->weld_button("save"))
30 , m_xUseDefaultFormatBtn(m_xBuilder->weld_button("cancel"))
31 , m_xWarningOnBox(m_xBuilder->weld_check_button("ask"))
33 OUString aExtension = "ODF";
35 // replace formatname (text)
36 OUString sInfoText = m_xDialog->get_primary_text();
37 sInfoText = sInfoText.replaceAll("%FORMATNAME", _rFormatName);
38 m_xDialog->set_primary_text(sInfoText);
40 // replace formatname (button)
41 sInfoText = m_xKeepCurrentBtn->get_label();
42 sInfoText = sInfoText.replaceAll("%FORMATNAME", _rFormatName);
43 m_xKeepCurrentBtn->set_label(sInfoText);
45 // hide ODF explanation if default format is alien
46 // and set the proper extension in the button
47 if (rDefaultIsAlien)
49 m_xDialog->set_secondary_text(OUString());
50 aExtension = _rDefaultExtension.toAsciiUpperCase();
53 // replace defaultextension (button)
54 sInfoText = m_xUseDefaultFormatBtn->get_label();
55 sInfoText = sInfoText.replaceAll("%DEFAULTEXTENSION", aExtension);
56 m_xUseDefaultFormatBtn->set_label(sInfoText);
58 // load value of "warning on" checkbox from save options
59 m_xWarningOnBox->set_active(officecfg::Office::Common::Save::Document::WarnAlienFormat::get());
62 SfxAlienWarningDialog::~SfxAlienWarningDialog()
64 try
66 // save value of "warning off" checkbox, if necessary
67 bool bChecked = m_xWarningOnBox->get_active();
68 if (officecfg::Office::Common::Save::Document::WarnAlienFormat::get() != bChecked)
70 auto xChanges = comphelper::ConfigurationChanges::create();
71 officecfg::Office::Common::Save::Document::WarnAlienFormat::set(bChecked, xChanges);
72 xChanges->commit();
75 catch (...)
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */