Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kencodingfiledialog.cpp
Show All 14 Lines | 2 | /* This file is part of the KDE libraries | |||
---|---|---|---|---|---|
15 | Library General Public License for more details. | 15 | Library General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License | ||
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to | ||
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
20 | Boston, MA 02110-1301, USA. | 20 | Boston, MA 02110-1301, USA. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | // TODO: remove me | | |||
24 | #undef QT_NO_CAST_FROM_ASCII | | |||
25 | | ||||
26 | #include "kencodingfiledialog.h" | 23 | #include "kencodingfiledialog.h" | ||
27 | 24 | | |||
28 | #include "kfilewidget.h" | 25 | #include "kfilewidget.h" | ||
29 | 26 | | |||
30 | #include <defaults-kfile.h> | 27 | #include <defaults-kfile.h> | ||
31 | 28 | | |||
32 | #include <kcombobox.h> | 29 | #include <kcombobox.h> | ||
33 | #include <kconfiggroup.h> | 30 | #include <kconfiggroup.h> | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 59 | { | |||
83 | connect(d->w->cancelButton(), &QAbstractButton::clicked, this, &KEncodingFileDialog::slotCancel); | 80 | connect(d->w->cancelButton(), &QAbstractButton::clicked, this, &KEncodingFileDialog::slotCancel); | ||
84 | connect(d->w, &KFileWidget::accepted, this, &KEncodingFileDialog::accept); | 81 | connect(d->w, &KFileWidget::accepted, this, &KEncodingFileDialog::accept); | ||
85 | 82 | | |||
86 | d->encoding = new KComboBox(this); | 83 | d->encoding = new KComboBox(this); | ||
87 | d->w->setCustomWidget(i18n("Encoding:"), d->encoding); | 84 | d->w->setCustomWidget(i18n("Encoding:"), d->encoding); | ||
88 | 85 | | |||
89 | d->encoding->clear(); | 86 | d->encoding->clear(); | ||
90 | QString sEncoding = encoding; | 87 | QString sEncoding = encoding; | ||
91 | QString systemEncoding = QTextCodec::codecForLocale()->name(); | 88 | QString systemEncoding = QLatin1String(QTextCodec::codecForLocale()->name()); | ||
92 | if (sEncoding.isEmpty() || sEncoding == QLatin1String("System")) { | 89 | if (sEncoding.isEmpty() || sEncoding == QLatin1String("System")) { | ||
93 | sEncoding = systemEncoding; | 90 | sEncoding = systemEncoding; | ||
94 | } | 91 | } | ||
95 | 92 | | |||
96 | const QStringList encodings(KCharsets::charsets()->availableEncodingNames()); | 93 | const QStringList encodings(KCharsets::charsets()->availableEncodingNames()); | ||
97 | int insert = 0, system = 0; | 94 | int insert = 0, system = 0; | ||
98 | bool foundRequested = false; | 95 | bool foundRequested = false; | ||
99 | for (const QString &encoding : encodings) { | 96 | for (const QString &encoding : encodings) { | ||
100 | bool found = false; | 97 | bool found = false; | ||
101 | QTextCodec *codecForEnc = KCharsets::charsets()->codecForName(encoding, found); | 98 | QTextCodec *codecForEnc = KCharsets::charsets()->codecForName(encoding, found); | ||
102 | 99 | | |||
103 | if (found) { | 100 | if (found) { | ||
104 | d->encoding->addItem(encoding); | 101 | d->encoding->addItem(encoding); | ||
105 | if ((codecForEnc->name() == sEncoding) || (encoding == sEncoding)) { | 102 | const QString codecName = QLatin1String(codecForEnc->name()); | ||
103 | if ((codecName == sEncoding) || (encoding == sEncoding)) { | ||||
106 | d->encoding->setCurrentIndex(insert); | 104 | d->encoding->setCurrentIndex(insert); | ||
107 | foundRequested = true; | 105 | foundRequested = true; | ||
108 | } | 106 | } | ||
109 | 107 | | |||
110 | if ((codecForEnc->name() == systemEncoding) || (encoding == systemEncoding)) { | 108 | if ((codecName == systemEncoding) || (encoding == systemEncoding)) { | ||
111 | system = insert; | 109 | system = insert; | ||
112 | } | 110 | } | ||
113 | insert++; | 111 | insert++; | ||
114 | } | 112 | } | ||
115 | } | 113 | } | ||
116 | 114 | | |||
117 | if (!foundRequested) { | 115 | if (!foundRequested) { | ||
118 | d->encoding->setCurrentIndex(system); | 116 | d->encoding->setCurrentIndex(system); | ||
▲ Show 20 Lines • Show All 168 Lines • Show Last 20 Lines |