xref: /aoo41x/main/sc/source/ui/dbgui/imoptdlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 #include "imoptdlg.hxx"
34 #include "scresid.hxx"
35 #include "imoptdlg.hrc"
36 #include <rtl/tencinfo.h>
37 
38 static const sal_Char pStrFix[] = "FIX";
39 
40 //------------------------------------------------------------------------
41 //	Der Options-String darf kein Semikolon mehr enthalten (wegen Pickliste)
42 //	darum ab Version 336 Komma stattdessen
43 
44 
45 ScImportOptions::ScImportOptions( const String& rStr )
46 {
47     // Use the same string format as ScAsciiOptions,
48     // because the import options string is passed here when a CSV file is loaded and saved again.
49     // The old format is still supported because it might be used in macros.
50 
51     bFixedWidth = sal_False;
52     nFieldSepCode = 0;
53     nTextSepCode = 0;
54     eCharSet = RTL_TEXTENCODING_DONTKNOW;
55     bSaveAsShown = sal_True;    // "true" if not in string (after CSV import)
56     bQuoteAllText = sal_False;
57     xub_StrLen nTokenCount = rStr.GetTokenCount(',');
58     if ( nTokenCount >= 3 )
59 	{
60         // first 3 tokens: common
61         String aToken( rStr.GetToken( 0, ',' ) );
62         if( aToken.EqualsIgnoreCaseAscii( pStrFix ) )
63             bFixedWidth = sal_True;
64         else
65             nFieldSepCode = (sal_Unicode) aToken.ToInt32();
66 		nTextSepCode  = (sal_Unicode) rStr.GetToken(1,',').ToInt32();
67 		aStrFont	  = rStr.GetToken(2,',');
68 		eCharSet	  = ScGlobal::GetCharsetValue(aStrFont);
69 
70         if ( nTokenCount == 4 )
71         {
72             // compatibility with old options string: "Save as shown" as 4th token, numeric
73             bSaveAsShown = (rStr.GetToken( 3, ',' ).ToInt32() ? sal_True : sal_False);
74             bQuoteAllText = sal_True;   // use old default then
75         }
76         else
77         {
78             // look at the same positions as in ScAsciiOptions
79             if ( nTokenCount >= 7 )
80                 bQuoteAllText = rStr.GetToken(6, ',').EqualsAscii("true");
81             if ( nTokenCount >= 9 )
82                 bSaveAsShown = rStr.GetToken(8, ',').EqualsAscii("true");
83         }
84 	}
85 }
86 
87 //------------------------------------------------------------------------
88 
89 String ScImportOptions::BuildString() const
90 {
91 	String	aResult;
92 
93     if( bFixedWidth )
94         aResult.AppendAscii( pStrFix );
95     else
96         aResult += String::CreateFromInt32(nFieldSepCode);
97 	aResult += ',';
98 	aResult += String::CreateFromInt32(nTextSepCode);
99 	aResult += ',';
100 	aResult += aStrFont;
101                                                             // use the same string format as ScAsciiOptions:
102     aResult.AppendAscii( ",1,,0," );                        // first row, no column info, default language
103     aResult.AppendAscii(bQuoteAllText ? "true" : "false");  // same as "quoted field as text" in ScAsciiOptions
104     aResult.AppendAscii( ",true," );                        // "detect special numbers"
105     aResult.AppendAscii(bSaveAsShown ? "true" : "false");   // "save as shown": not in ScAsciiOptions
106 
107 	return aResult;
108 }
109 
110 //------------------------------------------------------------------------
111 
112 void ScImportOptions::SetTextEncoding( rtl_TextEncoding nEnc )
113 {
114 	eCharSet = (nEnc == RTL_TEXTENCODING_DONTKNOW ?
115 		gsl_getSystemTextEncoding() : nEnc);
116 	aStrFont = ScGlobal::GetCharsetString( nEnc );
117 }
118