Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / dbgui / imoptdlg.cxx
blobce2ae0bfa3fd6d845bfda525f4f3dcb0d4b54762
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 "imoptdlg.hxx"
21 #include "asciiopt.hxx"
22 #include "scresid.hxx"
23 #include <comphelper/string.hxx>
24 #include <osl/thread.h>
25 #include <rtl/tencinfo.h>
27 static const sal_Char pStrFix[] = "FIX";
29 // Der Options-String darf kein Semikolon mehr enthalten (wegen Pickliste)
30 // darum ab Version 336 Komma stattdessen
32 ScImportOptions::ScImportOptions( const OUString& rStr )
34 // Use the same string format as ScAsciiOptions,
35 // because the import options string is passed here when a CSV file is loaded and saved again.
36 // The old format is still supported because it might be used in macros.
38 bFixedWidth = false;
39 nFieldSepCode = 0;
40 nTextSepCode = 0;
41 eCharSet = RTL_TEXTENCODING_DONTKNOW;
42 bSaveAsShown = true; // "true" if not in string (after CSV import)
43 bQuoteAllText = false;
44 bSaveFormulas = false;
45 sal_Int32 nTokenCount = comphelper::string::getTokenCount(rStr, ',');
46 if ( nTokenCount >= 3 )
48 // first 3 tokens: common
49 OUString aToken( rStr.getToken( 0, ',' ) );
50 if( aToken.equalsIgnoreAsciiCase( pStrFix ) )
51 bFixedWidth = true;
52 else
53 nFieldSepCode = ScAsciiOptions::GetWeightedFieldSep( aToken, true);
54 nTextSepCode = (sal_Unicode) rStr.getToken(1,',').toInt32();
55 aStrFont = rStr.getToken(2,',');
56 eCharSet = ScGlobal::GetCharsetValue(aStrFont);
58 if ( nTokenCount == 4 )
60 // compatibility with old options string: "Save as shown" as 4th token, numeric
61 bSaveAsShown = rStr.getToken( 3, ',' ).toInt32() != 0;
62 bQuoteAllText = true; // use old default then
64 else
66 // look at the same positions as in ScAsciiOptions
67 if ( nTokenCount >= 7 )
68 bQuoteAllText = rStr.getToken(6, ',') == "true";
69 if ( nTokenCount >= 9 )
70 bSaveAsShown = rStr.getToken(8, ',') == "true";
71 if ( nTokenCount >= 10 )
72 bSaveFormulas = rStr.getToken(9, ',') == "true";
77 OUString ScImportOptions::BuildString() const
79 OUString aResult;
81 if( bFixedWidth )
82 aResult += pStrFix;
83 else
84 aResult += OUString::number(nFieldSepCode);
85 aResult += "," + OUString::number(nTextSepCode) + "," + aStrFont +
86 // use the same string format as ScAsciiOptions:
87 ",1,,0," + // first row, no column info, default language
88 OUString::boolean( bQuoteAllText ) + // same as "quoted field as text" in ScAsciiOptions
89 ",true," + // "detect special numbers"
90 OUString::boolean( bSaveAsShown ) + // "save as shown": not in ScAsciiOptions
91 "," +
92 OUString::boolean( bSaveFormulas ); // "save formulas": not in ScAsciiOptions
94 return aResult;
97 void ScImportOptions::SetTextEncoding( rtl_TextEncoding nEnc )
99 eCharSet = (nEnc == RTL_TEXTENCODING_DONTKNOW ?
100 osl_getThreadTextEncoding() : nEnc);
101 aStrFont = ScGlobal::GetCharsetString( nEnc );
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */