xref: /aoo4110/main/sc/source/ui/dbgui/imoptdlg.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 #include "imoptdlg.hxx"
30 #include "scresid.hxx"
31 #include "imoptdlg.hrc"
32 #include <rtl/tencinfo.h>
33 
34 static const sal_Char pStrFix[] = "FIX";
35 
36 //------------------------------------------------------------------------
37 //	Der Options-String darf kein Semikolon mehr enthalten (wegen Pickliste)
38 //	darum ab Version 336 Komma stattdessen
39 
40 
ScImportOptions(const String & rStr)41 ScImportOptions::ScImportOptions( const String& rStr )
42 {
43     // Use the same string format as ScAsciiOptions,
44     // because the import options string is passed here when a CSV file is loaded and saved again.
45     // The old format is still supported because it might be used in macros.
46 
47     bFixedWidth = sal_False;
48     nFieldSepCode = 0;
49     nTextSepCode = 0;
50     eCharSet = RTL_TEXTENCODING_DONTKNOW;
51     bSaveAsShown = sal_True;    // "true" if not in string (after CSV import)
52     bQuoteAllText = sal_False;
53     xub_StrLen nTokenCount = rStr.GetTokenCount(',');
54     if ( nTokenCount >= 3 )
55 	{
56         // first 3 tokens: common
57         String aToken( rStr.GetToken( 0, ',' ) );
58         if( aToken.EqualsIgnoreCaseAscii( pStrFix ) )
59             bFixedWidth = sal_True;
60         else
61             nFieldSepCode = (sal_Unicode) aToken.ToInt32();
62 		nTextSepCode  = (sal_Unicode) rStr.GetToken(1,',').ToInt32();
63 		aStrFont	  = rStr.GetToken(2,',');
64 		eCharSet	  = ScGlobal::GetCharsetValue(aStrFont);
65 
66         if ( nTokenCount == 4 )
67         {
68             // compatibility with old options string: "Save as shown" as 4th token, numeric
69             bSaveAsShown = (rStr.GetToken( 3, ',' ).ToInt32() ? sal_True : sal_False);
70             bQuoteAllText = sal_True;   // use old default then
71         }
72         else
73         {
74             // look at the same positions as in ScAsciiOptions
75             if ( nTokenCount >= 7 )
76                 bQuoteAllText = rStr.GetToken(6, ',').EqualsAscii("true");
77             if ( nTokenCount >= 9 )
78                 bSaveAsShown = rStr.GetToken(8, ',').EqualsAscii("true");
79         }
80 	}
81 }
82 
83 //------------------------------------------------------------------------
84 
BuildString() const85 String ScImportOptions::BuildString() const
86 {
87 	String	aResult;
88 
89     if( bFixedWidth )
90         aResult.AppendAscii( pStrFix );
91     else
92         aResult += String::CreateFromInt32(nFieldSepCode);
93 	aResult += ',';
94 	aResult += String::CreateFromInt32(nTextSepCode);
95 	aResult += ',';
96 	aResult += aStrFont;
97                                                             // use the same string format as ScAsciiOptions:
98     aResult.AppendAscii( ",1,,0," );                        // first row, no column info, default language
99     aResult.AppendAscii(bQuoteAllText ? "true" : "false");  // same as "quoted field as text" in ScAsciiOptions
100     aResult.AppendAscii( ",true," );                        // "detect special numbers"
101     aResult.AppendAscii(bSaveAsShown ? "true" : "false");   // "save as shown": not in ScAsciiOptions
102 
103 	return aResult;
104 }
105 
106 //------------------------------------------------------------------------
107 
SetTextEncoding(rtl_TextEncoding nEnc)108 void ScImportOptions::SetTextEncoding( rtl_TextEncoding nEnc )
109 {
110 	eCharSet = (nEnc == RTL_TEXTENCODING_DONTKNOW ?
111 		gsl_getSystemTextEncoding() : nEnc);
112 	aStrFont = ScGlobal::GetCharsetString( nEnc );
113 }
114