/
qgsencodingfiledialog.cpp
123 lines (110 loc) · 4.61 KB
/
qgsencodingfiledialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/***************************************************************************
qgsencodingfiledialog.cpp - File dialog which queries the encoding type
--------------------------------------
Date : 16-Feb-2005
Copyright : (C) 2005 by Marco Hugentobler
email : marco.hugentobler@autoform.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsencodingfiledialog.h"
#include "qgsproject.h"
#include "qgslogger.h"
#include <QSettings>
#include <QComboBox>
#include <QLabel>
#include <QLayout>
#include <QTextCodec>
QgsEncodingFileDialog::QgsEncodingFileDialog( QWidget * parent,
const QString & caption, const QString & directory,
const QString & filter, const QString & encoding )
: QFileDialog( parent, caption, directory, filter )
{
mEncodingComboBox = new QComboBox( this );
QLabel* l = new QLabel( tr( "Encoding:" ), this );
layout()->addWidget( l );
layout()->addWidget( mEncodingComboBox );
mEncodingComboBox->addItem( "BIG5" );
mEncodingComboBox->addItem( "BIG5-HKSCS" );
mEncodingComboBox->addItem( "EUCJP" );
mEncodingComboBox->addItem( "EUCKR" );
mEncodingComboBox->addItem( "GB2312" );
mEncodingComboBox->addItem( "GBK" );
mEncodingComboBox->addItem( "GB18030" );
mEncodingComboBox->addItem( "JIS7" );
mEncodingComboBox->addItem( "SHIFT-JIS" );
mEncodingComboBox->addItem( "TSCII" );
mEncodingComboBox->addItem( "UTF-8" );
mEncodingComboBox->addItem( "UTF-16" );
mEncodingComboBox->addItem( "KOI8-R" );
mEncodingComboBox->addItem( "KOI8-U" );
mEncodingComboBox->addItem( "ISO8859-1" );
mEncodingComboBox->addItem( "ISO8859-2" );
mEncodingComboBox->addItem( "ISO8859-3" );
mEncodingComboBox->addItem( "ISO8859-4" );
mEncodingComboBox->addItem( "ISO8859-5" );
mEncodingComboBox->addItem( "ISO8859-6" );
mEncodingComboBox->addItem( "ISO8859-7" );
mEncodingComboBox->addItem( "ISO8859-8" );
mEncodingComboBox->addItem( "ISO8859-8-I" );
mEncodingComboBox->addItem( "ISO8859-9" );
mEncodingComboBox->addItem( "ISO8859-10" );
mEncodingComboBox->addItem( "ISO8859-13" );
mEncodingComboBox->addItem( "ISO8859-14" );
mEncodingComboBox->addItem( "ISO8859-15" );
mEncodingComboBox->addItem( "IBM 850" );
mEncodingComboBox->addItem( "IBM 866" );
mEncodingComboBox->addItem( "CP874" );
mEncodingComboBox->addItem( "CP1250" );
mEncodingComboBox->addItem( "CP1251" );
mEncodingComboBox->addItem( "CP1252" );
mEncodingComboBox->addItem( "CP1253" );
mEncodingComboBox->addItem( "CP1254" );
mEncodingComboBox->addItem( "CP1255" );
mEncodingComboBox->addItem( "CP1256" );
mEncodingComboBox->addItem( "CP1257" );
mEncodingComboBox->addItem( "CP1258" );
mEncodingComboBox->addItem( "Apple Roman" );
mEncodingComboBox->addItem( "TIS-620" );
// Use default encoding if none supplied
QString enc = encoding;
if ( encoding.isEmpty() )
{
QSettings settings;
enc = settings.value( "/UI/encoding", QString("System") ).toString();
}
// The specified decoding is added if not existing alread, and then set current.
// This should select it.
int encindex = mEncodingComboBox->findText( enc );
if ( encindex < 0 )
{
mEncodingComboBox->insertItem( 0, enc );
encindex = 0;
}
mEncodingComboBox->setCurrentIndex( encindex );
// if this dialog is being invoked from QgisApp::findFiles_(), then we
// need to force selection of the first filter since that corresponds to
// the file name we're looking for; even if we're not here from
// findFiles_(), it won't hurt to force selection of the first file filter
selectFilter( filters().at( 0 ) );
// Connect our slot to get a signal when the user is done with the file dialog
connect( this, SIGNAL( accepted() ), this, SLOT( saveUsedEncoding() ) );
}
QgsEncodingFileDialog::~QgsEncodingFileDialog()
{
}
QString QgsEncodingFileDialog::encoding() const
{
return mEncodingComboBox->currentText();
}
void QgsEncodingFileDialog::saveUsedEncoding()
{
QSettings settings;
settings.setValue( "/UI/encoding", encoding() );
QgsDebugMsg(QString( "Set encoding " + encoding() + " as default.") );
}