Related tdf#150928: replace character set by encoding (sc/part 3+connectivity)

Change-Id: I78d3c989be9e02e39d646b3c1eb672e3f37bd43c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209380
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
This commit is contained in:
Julien Nabet
2026-09-07 10:15:23 +02:00
parent 9fc9e5bc9e
commit 296b49f581
8 changed files with 84 additions and 84 deletions
+3 -3
View File
@@ -1992,7 +1992,7 @@ OSQLColumns::const_iterator find(OSQLColumns::const_iterator first,
namespace dbase
{
bool dbfDecodeCharset(rtl_TextEncoding &_out_encoding, sal_uInt8 nType, sal_uInt8 nCodepage)
bool dbfDecodeEncoding(rtl_TextEncoding &_out_encoding, sal_uInt8 nType, sal_uInt8 nCodepage)
{
switch (nType)
{
@@ -2055,7 +2055,7 @@ namespace dbase
return false;
}
bool dbfReadCharset(rtl_TextEncoding &nCharSet, SvStream* dbf_Stream)
bool dbfReadEncoding(rtl_TextEncoding &nCharSet, SvStream* dbf_Stream)
{
sal_uInt8 nType=0;
dbf_Stream->ReadUChar( nType );
@@ -2069,7 +2069,7 @@ namespace dbase
{
sal_uInt8 nEncoding=0;
dbf_Stream->ReadUChar( nEncoding );
return dbfDecodeCharset(nCharSet, nType, nEncoding);
return dbfDecodeEncoding(nCharSet, nType, nEncoding);
}
}
+1 -1
View File
@@ -254,7 +254,7 @@ void ODbaseTable::readHeader()
case FoxProMemo:
m_pFileStream->SetEndian(SvStreamEndian::LITTLE);
if( getConnection()->isTextEncodingDefaulted() &&
!dbfDecodeCharset(m_eEncoding, nType, m_aHeader.trailer[17]))
!dbfDecodeEncoding(m_eEncoding, nType, m_aHeader.trailer[17]))
{
m_eEncoding = RTL_TEXTENCODING_IBM_850;
}
+12 -12
View File
@@ -842,33 +842,33 @@ namespace dbase
FoxProMemo = 0xF5
};
/** decode a DBase file's codepage byte to a RTL charset
@param _out_nCharset
in case of success, the decoded RTL charset is written there.
/** decode a DBase file's codepage byte to a RTL encoding
@param _out_nEncoding
in case of success, the decoded RTL encoding is written there.
else, this is not written to.
@param nType
the file's type byte
@param nCodepage
the file's codepage byte
@return
true if a RTL charset was successfully decoded and written to _out_nCharset
false if nothing was written to _out_nCharset
true if a RTL charset was successfully decoded and written to _out_nEncoding
false if nothing was written to _out_nEncoding
*/
OOO_DLLPUBLIC_DBTOOLS bool dbfDecodeCharset(rtl_TextEncoding &_out_nCharset, sal_uInt8 nType, sal_uInt8 nCodepage);
OOO_DLLPUBLIC_DBTOOLS bool dbfDecodeEncoding(rtl_TextEncoding &_out_nCharset, sal_uInt8 nType, sal_uInt8 nCodepage);
/** decode a DBase file's codepage byte to a RTL charset
@param _out_nCharset
in case of success, the decoded RTL charset is written there.
/** decode a DBase file's codepage byte to a RTL encoding
@param _out_nEncoding
in case of success, the decoded RTL encoding is written there.
else, this is not written to.
@param dbf_Stream
pointer to a SvStream encapsulating the DBase file.
The stream will be rewound and read from.
No guarantee is made on its position afterwards. Caller must reposition it itself.
@return
true if a RTL charset was successfully decoded and written to _out_nCharset
false if nothing was written to _out_nCharset
true if a RTL encoding was successfully decoded and written to _out_nEncoding
false if nothing was written to _out_nEncoding
*/
OOO_DLLPUBLIC_DBTOOLS bool dbfReadCharset(rtl_TextEncoding &nCharSet, SvStream* dbf_Stream);
OOO_DLLPUBLIC_DBTOOLS bool dbfReadEncoding(rtl_TextEncoding &nCharSet, SvStream* dbf_Stream);
} // namespace connectivity::dbase
} // namespace connectivity
@@ -933,10 +933,10 @@
<info>
<desc>Contains settings for DBF Import dialog</desc>
</info>
<prop oor:name="CharSet" oor:type="xs:int" oor:nillable="false">
<prop oor:name="Encoding" oor:type="xs:int" oor:nillable="false">
<info>
<desc>Charset/Language</desc>
<label>CharSet</label>
<desc>Encoding/Language</desc>
<label>Encoding</label>
</info>
<value>-1</value>
</prop>
@@ -945,10 +945,10 @@
<info>
<desc>Contains settings for DBF Export dialog</desc>
</info>
<prop oor:name="CharSet" oor:type="xs:int" oor:nillable="false">
<prop oor:name="Encoding" oor:type="xs:int" oor:nillable="false">
<info>
<desc>Charset/Language</desc>
<label>CharSet</label>
<desc>Encoding/Language</desc>
<label>Encoding</label>
</info>
<value>-1</value>
</prop>
@@ -957,10 +957,10 @@
<info>
<desc>Contains setting for Text CSV Export</desc>
</info>
<prop oor:name="CharSet" oor:type="xs:int" oor:nillable="false">
<prop oor:name="Encoding" oor:type="xs:int" oor:nillable="false">
<info>
<desc>Char Set</desc>
<label>CharSet</label>
<desc>Encoding/Language</desc>
<label>Encoding</label>
</info>
<value>-1</value>
</prop>
+27 -27
View File
@@ -95,17 +95,17 @@ OUString ScDelimiterTable::GetDelimiter( sal_Unicode nCode ) const
void ScImportOptionsDlg::FillFromTextEncodingTable(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
{
if (m_bIsAsciiImport)
m_xLbCharset->FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags);
m_xLbEncoding->FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags);
else
m_xTvCharset->FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags);
m_xTvEncoding->FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags);
}
void ScImportOptionsDlg::FillFromDbTextEncodingMap(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
{
if (m_bIsAsciiImport)
m_xLbCharset->FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
m_xLbEncoding->FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
else
m_xTvCharset->FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
m_xTvEncoding->FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
}
// ScImportOptionsDlg
@@ -117,7 +117,7 @@ ScImportOptionsDlg::ScImportOptionsDlg(weld::Window* pParent, bool bAscii,
: GenericDialogController(pParent, u"modules/scalc/ui/imoptdialog.ui"_ustr, u"ImOptDialog"_ustr)
, m_bIsAsciiImport(bAscii)
, m_xFieldFrame(m_xBuilder->weld_frame(u"fieldframe"_ustr))
, m_xFtCharset(m_xBuilder->weld_label(u"charsetft"_ustr))
, m_xFtEncoding(m_xBuilder->weld_label(u"encodingft"_ustr))
, m_xEncGrid(m_xBuilder->weld_widget(u"grid2"_ustr))
, m_xFtFieldSep(m_xBuilder->weld_label(u"fieldft"_ustr))
, m_xEdFieldSep(m_xBuilder->weld_combo_box(u"field"_ustr))
@@ -127,23 +127,23 @@ ScImportOptionsDlg::ScImportOptionsDlg(weld::Window* pParent, bool bAscii,
, m_xCbFormulas(m_xBuilder->weld_check_button(u"formulas"_ustr))
, m_xCbQuoteAll(m_xBuilder->weld_check_button(u"quoteall"_ustr))
, m_xCbFixed(m_xBuilder->weld_check_button(u"fixedwidth"_ustr))
, m_xLbCharset(new SvxTextEncodingBox(m_xBuilder->weld_combo_box(u"charsetdropdown"_ustr)))
, m_xTvCharset(new SvxTextEncodingTreeView(m_xBuilder->weld_tree_view(u"charsetlist"_ustr)))
, m_xLbEncoding(new SvxTextEncodingBox(m_xBuilder->weld_combo_box(u"encodingdropdown"_ustr)))
, m_xTvEncoding(new SvxTextEncodingTreeView(m_xBuilder->weld_tree_view(u"encodinglist"_ustr)))
{
if (bAscii)
{
m_xDialog->set_help_id(m_xDialog->get_help_id() + "?config=NonTextImport");
m_xLbCharset->show();
m_xTvCharset->hide();
m_xFtCharset->set_mnemonic_widget(&m_xLbCharset->getComboBox());
m_xLbEncoding->show();
m_xTvEncoding->hide();
m_xFtEncoding->set_mnemonic_widget(&m_xLbEncoding->getComboBox());
}
else
{
m_xTvCharset->set_size_request(-1, m_xTvCharset->get_height_rows(6));
m_xTvEncoding->set_size_request(-1, m_xTvEncoding->get_height_rows(6));
m_xEncGrid->set_vexpand(true);
m_xLbCharset->hide();
m_xTvCharset->show();
m_xFtCharset->set_mnemonic_widget(&m_xTvCharset->getTreeView());
m_xLbEncoding->hide();
m_xTvEncoding->show();
m_xFtEncoding->set_mnemonic_widget(&m_xTvEncoding->getTreeView());
}
OUString sFieldSep(SCSTR_FIELDSEP);
@@ -215,7 +215,7 @@ ScImportOptionsDlg::ScImportOptionsDlg(weld::Window* pParent, bool bAscii,
if( bAscii )
{
sal_Int32 nCharSet = officecfg::Office::Calc::Dialogs::CSVExport::CharSet::get();
sal_Int32 nEncoding = officecfg::Office::Calc::Dialogs::CSVExport::Encoding::get();
OUString strFieldSeparator = officecfg::Office::Calc::Dialogs::CSVExport::FieldSeparator::get();
OUString strTextSeparator = officecfg::Office::Calc::Dialogs::CSVExport::TextSeparator::get();
bool bSaveTrueCellContent = officecfg::Office::Calc::Dialogs::CSVExport::SaveTrueCellContent::get();
@@ -234,31 +234,31 @@ ScImportOptionsDlg::ScImportOptionsDlg(weld::Window* pParent, bool bAscii,
m_xCbFormulas->show();
// default option for "save formulas" is no longer taken from view shell but from persisted dialog settings
m_xCbFormulas->set_active( bSaveCellFormulas );
// if no charset, text separator or field separator exist, keep the values from dialog initialization
// if no encoding, text separator or field separator exist, keep the values from dialog initialization
if (strFieldSeparator.getLength() > 0)
m_xEdFieldSep->set_entry_text(strFieldSeparator);
if (strTextSeparator.getLength() > 0)
m_xEdTextSep->set_entry_text(strTextSeparator);
if (nCharSet < 0 || nCharSet == RTL_TEXTENCODING_DONTKNOW )
m_xLbCharset->SelectTextEncoding(pOptions ? pOptions->eEncoding : osl_getThreadTextEncoding());
if (nEncoding < 0 || nEncoding == RTL_TEXTENCODING_DONTKNOW )
m_xLbEncoding->SelectTextEncoding(pOptions ? pOptions->eEncoding : osl_getThreadTextEncoding());
else
m_xLbCharset->SelectTextEncoding(nCharSet);
m_xLbEncoding->SelectTextEncoding(nEncoding);
}
else
{
m_xFieldFrame->set_label(m_xFtCharset->get_label());
m_xFieldFrame->set_label(m_xFtEncoding->get_label());
m_xFtFieldSep->hide();
m_xFtTextSep->hide();
m_xFtCharset->hide();
m_xFtEncoding->hide();
m_xEdFieldSep->hide();
m_xEdTextSep->hide();
m_xCbFixed->hide();
m_xCbShown->hide();
m_xCbQuoteAll->hide();
m_xCbFormulas->hide();
m_xTvCharset->grab_focus();
m_xTvCharset->connect_item_activated(LINK(this, ScImportOptionsDlg, DoubleClickHdl));
m_xTvCharset->SelectTextEncoding(pOptions ? pOptions->eEncoding : osl_getThreadTextEncoding());
m_xTvEncoding->grab_focus();
m_xTvEncoding->connect_item_activated(LINK(this, ScImportOptionsDlg, DoubleClickHdl));
m_xTvEncoding->SelectTextEncoding(pOptions ? pOptions->eEncoding : osl_getThreadTextEncoding());
}
// optional title:
@@ -279,7 +279,7 @@ ScImportOptionsDlg::~ScImportOptionsDlg()
void ScImportOptionsDlg::GetImportOptions( ScImportOptions& rOptions ) const
{
auto nEncoding = m_bIsAsciiImport ? m_xLbCharset->GetSelectTextEncoding() : m_xTvCharset->GetSelectTextEncoding();
auto nEncoding = m_bIsAsciiImport ? m_xLbEncoding->GetSelectTextEncoding() : m_xTvEncoding->GetSelectTextEncoding();
rOptions.SetTextEncoding(nEncoding);
if (m_xCbFixed->get_visible())
@@ -339,8 +339,8 @@ IMPL_LINK_NOARG(ScImportOptionsDlg, DoubleClickHdl, const weld::TreeIter&, bool)
void ScImportOptionsDlg::SaveImportOptions() const
{
std::shared_ptr < comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create());
auto nEncoding = m_bIsAsciiImport ? m_xLbCharset->GetSelectTextEncoding() : m_xTvCharset->GetSelectTextEncoding();
officecfg::Office::Calc::Dialogs::CSVExport::CharSet::set(nEncoding, batch);
auto nEncoding = m_bIsAsciiImport ? m_xLbEncoding->GetSelectTextEncoding() : m_xTvEncoding->GetSelectTextEncoding();
officecfg::Office::Calc::Dialogs::CSVExport::Encoding::set(nEncoding, batch);
officecfg::Office::Calc::Dialogs::CSVExport::FieldSeparator::set(m_xEdFieldSep->get_active_text(), batch);
officecfg::Office::Calc::Dialogs::CSVExport::TextSeparator::set(m_xEdTextSep->get_active_text(), batch);
officecfg::Office::Calc::Dialogs::CSVExport::FixedWidth::set(m_xCbFixed->get_active(), batch);
+3 -3
View File
@@ -55,7 +55,7 @@ private:
bool m_bIsAsciiImport;
std::unique_ptr<weld::Frame> m_xFieldFrame;
std::unique_ptr<weld::Label> m_xFtCharset;
std::unique_ptr<weld::Label> m_xFtEncoding;
std::unique_ptr<weld::Widget> m_xEncGrid;
std::unique_ptr<weld::Label> m_xFtFieldSep;
std::unique_ptr<weld::ComboBox> m_xEdFieldSep;
@@ -65,8 +65,8 @@ private:
std::unique_ptr<weld::CheckButton> m_xCbFormulas;
std::unique_ptr<weld::CheckButton> m_xCbQuoteAll;
std::unique_ptr<weld::CheckButton> m_xCbFixed;
std::unique_ptr<SvxTextEncodingBox> m_xLbCharset;
std::unique_ptr<SvxTextEncodingTreeView> m_xTvCharset;
std::unique_ptr<SvxTextEncodingBox> m_xLbEncoding;
std::unique_ptr<SvxTextEncodingTreeView> m_xTvEncoding;
private:
sal_uInt16 GetCodeFromCombo( const weld::ComboBox& rEd ) const;
+21 -21
View File
@@ -61,30 +61,30 @@ constexpr OUStringLiteral SC_UNONAME_FILTERNAME = u"FilterName";
constexpr OUString SC_UNONAME_FILTEROPTIONS = u"FilterOptions"_ustr;
constexpr OUStringLiteral SC_UNONAME_INPUTSTREAM = u"InputStream";
constexpr OUString DBF_CHAR_SET = u"CharSet"_ustr;
constexpr OUString DBF_ENCODING = u"Encoding"_ustr;
constexpr OUString DBF_SEP_PATH_IMPORT = u"Office.Calc/Dialogs/DBFImport"_ustr;
constexpr OUString DBF_SEP_PATH_EXPORT = u"Office.Calc/Dialogs/DBFExport"_ustr;
namespace
{
enum class charsetSource
enum class encodingSource
{
charset_from_file,
charset_from_user_setting,
charset_default
encoding_from_file,
encoding_from_user_setting,
encoding_default
};
charsetSource load_CharSet(rtl_TextEncoding &nCharSet, bool bExport, SvStream* dbf_Stream)
encodingSource load_Encoding(rtl_TextEncoding &nEncoding, bool bExport, SvStream* dbf_Stream)
{
if (dbf_Stream && dbfReadCharset(nCharSet, dbf_Stream))
if (dbf_Stream && dbfReadEncoding(nEncoding, dbf_Stream))
{
return charsetSource::charset_from_file;
return encodingSource::encoding_from_file;
}
Sequence<Any> aValues;
const Any *pProperties;
Sequence<OUString> aNames { DBF_CHAR_SET };
Sequence<OUString> aNames { DBF_ENCODING };
ScLinkConfigItem aItem( bExport ? DBF_SEP_PATH_EXPORT : DBF_SEP_PATH_IMPORT );
aValues = aItem.GetProperties( aNames );
@@ -96,26 +96,26 @@ namespace
pProperties[0] >>= nChar;
if( nChar >= 0)
{
nCharSet = static_cast<rtl_TextEncoding>(nChar);
return charsetSource::charset_from_user_setting;
nEncoding = static_cast<rtl_TextEncoding>(nChar);
return encodingSource::encoding_from_user_setting;
}
}
// Default choice
nCharSet = RTL_TEXTENCODING_IBM_850;
return charsetSource::charset_default;
nEncoding = RTL_TEXTENCODING_IBM_850;
return encodingSource::encoding_default;
}
void save_CharSet( rtl_TextEncoding nCharSet, bool bExport )
void save_Encoding( rtl_TextEncoding nEncoding, bool bExport )
{
Sequence<Any> aValues;
Any *pProperties;
Sequence<OUString> aNames { DBF_CHAR_SET };
Sequence<OUString> aNames { DBF_ENCODING };
ScLinkConfigItem aItem( bExport ? DBF_SEP_PATH_EXPORT : DBF_SEP_PATH_IMPORT );
aValues = aItem.GetProperties( aNames );
pProperties = aValues.getArray();
pProperties[0] <<= static_cast<sal_Int32>(nCharSet);
pProperties[0] <<= static_cast<sal_Int32>(nEncoding);
aItem.PutProperties(aNames, aValues);
}
@@ -293,13 +293,13 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
std::unique_ptr<SvStream> pInStream;
if ( xInputStream.is() )
pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
switch(load_CharSet( eEncoding, bExport, pInStream.get()))
switch(load_Encoding( eEncoding, bExport, pInStream.get()))
{
case charsetSource::charset_from_file:
case encodingSource::encoding_from_file:
skipDialog = true;
break;
case charsetSource::charset_from_user_setting:
case charsetSource::charset_default:
case encodingSource::encoding_from_user_setting:
case encodingSource::encoding_default:
break;
}
bDBEnc = true;
@@ -343,7 +343,7 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
{
pDlg->SaveImportOptions();
pDlg->GetImportOptions( aOptions );
save_CharSet( aOptions.eEncoding, bExport );
save_Encoding( aOptions.eEncoding, bExport );
nRet = ui::dialogs::ExecutableDialogResults::OK;
}
}
+8 -8
View File
@@ -99,10 +99,10 @@
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkLabel" id="charsetft">
<object class="GtkLabel" id="encodingft">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" context="imoptdialog|charsetft">_Character set:</property>
<property name="label" translatable="yes" context="imoptdialog|encodingft">_Encoding:</property>
<property name="use-underline">True</property>
<property name="xalign">0</property>
</object>
@@ -118,13 +118,13 @@
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkComboBoxText" id="charsetdropdown">
<object class="GtkComboBoxText" id="encodingdropdown">
<property name="can-focus">False</property>
<property name="no-show-all">True</property>
<property name="hexpand">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="charsetdropdown-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="imoptdialog|extended_tip|charsetdropdown">Specifies the character set for text export.</property>
<object class="AtkObject" id="encodingdropdown-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="imoptdialog|extended_tip|encodingdropdown">Specifies the encoding for text export.</property>
</object>
</child>
</object>
@@ -142,7 +142,7 @@
<property name="hscrollbar-policy">never</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView" id="charsetlist">
<object class="GtkTreeView" id="encodinglist">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@@ -168,8 +168,8 @@
</object>
</child>
<child internal-child="accessible">
<object class="AtkObject" id="charsetlist-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="imoptdialog|extended_tip|charsetlist">Select the character set from the options used for import/export.</property>
<object class="AtkObject" id="encodinglist-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="imoptdialog|extended_tip|encodinglist">Select the encoding from the options used for import/export.</property>
</object>
</child>
</object>