xref: /core/sc/source/ui/dbgui/textimportoptions.cxx (revision 57c7269f)
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 #undef SC_DLLIMPLEMENTATION
21 
22 #include <textimportoptions.hxx>
23 #include <svx/langbox.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/settings.hxx>
26 #include <i18nlangtag/languagetag.hxx>
27 
ScTextImportOptionsDlg(weld::Window * pParent)28 ScTextImportOptionsDlg::ScTextImportOptionsDlg(weld::Window* pParent)
29     : GenericDialogController(pParent, u"modules/scalc/ui/textimportoptions.ui"_ustr, u"TextImportOptionsDialog"_ustr)
30     , m_xBtnOk(m_xBuilder->weld_button(u"ok"_ustr))
31     , m_xRbAutomatic(m_xBuilder->weld_radio_button(u"automatic"_ustr))
32     , m_xRbCustom(m_xBuilder->weld_radio_button(u"custom"_ustr))
33     , m_xCkbConvertDate(m_xBuilder->weld_check_button(u"convertdata"_ustr))
34     , m_xCkbConvertScientific(m_xBuilder->weld_check_button(u"convertscientificnotation"_ustr))
35     , m_xCkbKeepAsking(m_xBuilder->weld_check_button(u"keepasking"_ustr))
36     , m_xLbCustomLang(new SvxLanguageBox(m_xBuilder->weld_combo_box(u"lang"_ustr)))
37 {
38     init();
39 }
40 
~ScTextImportOptionsDlg()41 ScTextImportOptionsDlg::~ScTextImportOptionsDlg()
42 {
43 }
44 
getLanguageType() const45 LanguageType ScTextImportOptionsDlg::getLanguageType() const
46 {
47     if (m_xRbAutomatic->get_active())
48         return LANGUAGE_SYSTEM;
49 
50     return m_xLbCustomLang->get_active_id();
51 }
52 
isDateConversionSet() const53 bool ScTextImportOptionsDlg::isDateConversionSet() const
54 {
55     return m_xCkbConvertDate->get_active();
56 }
57 
isScientificConversionSet() const58 bool ScTextImportOptionsDlg::isScientificConversionSet() const
59 {
60     return m_xCkbConvertScientific->get_active();
61 }
62 
isKeepAskingSet() const63 bool ScTextImportOptionsDlg::isKeepAskingSet() const
64 {
65     return m_xCkbKeepAsking->get_active();
66 }
67 
init()68 void ScTextImportOptionsDlg::init()
69 {
70     m_xBtnOk->connect_clicked(LINK(this, ScTextImportOptionsDlg, OKHdl));
71     Link<weld::Toggleable&,void> aLink = LINK(this, ScTextImportOptionsDlg, RadioCheckHdl);
72     m_xRbAutomatic->connect_toggled(aLink);
73     m_xRbCustom->connect_toggled(aLink);
74     m_xCkbConvertDate->connect_toggled(aLink);
75     m_xCkbConvertScientific->connect_toggled(aLink);
76 
77     m_xRbAutomatic->set_active(true);
78 
79     m_xLbCustomLang->SetLanguageList(
80         SvxLanguageListFlags::ALL | SvxLanguageListFlags::ONLY_KNOWN, false);
81 
82     LanguageType eLang = Application::GetSettings().GetLanguageTag().getLanguageType();
83     m_xLbCustomLang->set_active_id(eLang);
84     m_xLbCustomLang->set_sensitive(false);
85 }
86 
IMPL_LINK_NOARG(ScTextImportOptionsDlg,OKHdl,weld::Button &,void)87 IMPL_LINK_NOARG(ScTextImportOptionsDlg, OKHdl, weld::Button&, void)
88 {
89     m_xDialog->response(RET_OK);
90 }
91 
IMPL_LINK(ScTextImportOptionsDlg,RadioCheckHdl,weld::Toggleable &,rBtn,void)92 IMPL_LINK(ScTextImportOptionsDlg, RadioCheckHdl, weld::Toggleable&, rBtn, void)
93 {
94     if (&rBtn == m_xRbAutomatic.get())
95     {
96         m_xLbCustomLang->set_sensitive(false);
97     }
98     else if (&rBtn == m_xRbCustom.get())
99     {
100         m_xLbCustomLang->set_sensitive(true);
101     }
102     else if (&rBtn == m_xCkbConvertDate.get())
103     {
104         if (m_xCkbConvertDate->get_active())
105         {
106             m_xCkbConvertScientific->set_active(true);
107             m_xCkbConvertScientific->set_sensitive(false);
108         }
109         else
110         {
111             m_xCkbConvertScientific->set_sensitive(true);
112         }
113     }
114     else if (&rBtn == m_xCkbConvertScientific.get())
115     {
116         assert( !m_xCkbConvertDate->get_active() && "ScTextImportOptionsDlg::RadioCheckHdl - scientific option disabled if Detect numbers active" );
117     }
118 }
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
121