[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: [PATCH] Add select encoding in Control Center (for CVS HEAD)
From: Toshitaka Fujioka <toshitaka () kde ! gr ! jp>
Date: 2001-09-28 16:22:28
[Download RAW message or body]
On Friday 28 September 2001 05:07, Ilya Konstantinov wrote:
> On Fri, Sep 28, 2001 at 12:55:05AM +0900, Toshitaka Fujioka wrote:
> > This patch can select Encoding with Control Center.
> > Fix some i18n bugs when you set Encoding.
> > BUG:
> > 1. I can not display non-latin1 character of local directory and file
> > justly.
>
> Maybe we should separate the encoding of filenames
> (QFile::setEncodingFunction() and QFile::setDecodingFunction()) from
> the regular default encoding?
Hmm, Perhaps I think that it is needless. Because, directory name (debug
message) of Japanese looks fine when I let konqueror start form konsole.
I think that this problem is same as the following examples.
An example:
See http://www.kde.gr.jp with konqueror and "View -> Set Encoding ->
iso 8859-1". Encoding of this page is eucJP. If encoding is not eucJP,
I can't display Japanese precisely.
> > 2. I can not input Japanese.
>
> A good patch!
>
> Maybe the name should be "Default Encoding", since applications which
> support multiple encodings (e.g. Konqueror) won't necessary use this
> encoding for interchange of text from external sources.
I see.
> > + // pt 154, utf16, iso 8859-6, ibm 852.
>
> UTF-16 should be supported in Qt 3 as well as ISO-8859-6.
But, I looked at $QTDIR/example/qwerty . There was not UTF-16 and
ISO-8858-6. There was ISO 8859-6-I.
> Also, instead of the special checks for utf-8 and iso 8859-1 in
> loadCurrentEncoding(), I think you should've rather created
> a QTextCodec object for the current encoding using
> QTextCodec::codecForName (which should handle approximate matching).
> Then, when you iterate over the menu items, use
> KCharsets::codecForName(KCharsets::encodingForName(menu_encoding))
> to return a QTextCodec object of the current menu item.
> Then you'd compare their ->name()s to find whether they match.
I tried KCharsets::codecForName(KCharsets::encodingForName(menu_encoding)).
But, when menu_encoding is iso 8859-6, ibm852, pt 154 and utf16,
iso 8859-1 returned.
I remade a patch. Please review.
Thank you.
--
Toshitaka Fujioka
http://www.kde.org The K Desktop Environment Project
fujioka@kde.org
http://www.kde.gr.jp Japan KDE User's Group
toshitaka@kde.gr.jp
-- We offer the best Desktop Environment to you. (This is my goal. ;-)) --
["kdebase-kcontrol-locale-encoding-20010929.diff" (text/x-diff)]
? kdebase-kcontrol-locale-encoding-20010929.diff
Index: locale.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/locale/locale.cpp,v
retrieving revision 1.93
diff -u -3 -d -p -r1.93 locale.cpp
--- locale.cpp 2001/09/16 11:58:10 1.93
+++ locale.cpp 2001/09/28 16:18:15
@@ -31,6 +31,7 @@
#include <qiconset.h>
#include <qwhatsthis.h>
#include <qcombobox.h>
+#include <qtextcodec.h>
#include <qhbox.h>
@@ -93,9 +94,11 @@ KLocaleConfig::KLocaleConfig(KLocale *lo
boxlay->insertStretch(-1);
// #### HPB: This should be implemented for KDE 3
- // new QLabel(this, I18N_NOOP("Encoding:"));
- //QComboBox * cb = new QComboBox( this );
- //cb->insertStringList( KGlobal::charsets()->descriptiveEncodingNames() );
+ m_labEncoding = new QLabel(this, I18N_NOOP("Default Encoding:"));
+ m_encoding = new QComboBox( this );
+ m_encoding->insertStringList( KGlobal::charsets()->descriptiveEncodingNames() );
+ connect( m_encoding, SIGNAL(activated(const QString &)),
+ this, SLOT(changedEncoding(const QString &)) );
lay->setRowStretch(2, 5);
@@ -313,6 +316,7 @@ void KLocaleConfig::save()
else
config->writeEntry("Language",
m_locale->languageList(), ':', true, true);
+ config->writeEntry("EncodingMib", m_locale->encodingMib(), true, true);
config->sync();
}
@@ -342,6 +346,7 @@ void KLocaleConfig::slotLocaleChanged()
slotCheckButtons();
m_comboCountry->setCurrentItem( m_locale->country() );
+ m_encoding->setCurrentItem( loadCurrentEncoding() );
}
void KLocaleConfig::slotTranslate()
@@ -363,6 +368,10 @@ void KLocaleConfig::slotTranslate()
"this list. If non of the languages were available, English US "
"will be used.") );
+ QToolTip::add(m_encoding, m_locale->translate
+ ( "This is were you encoding. KDE will use the defaults for "
+ "this encoding.") );
+
QString str;
str = m_locale->translate
@@ -384,6 +393,11 @@ void KLocaleConfig::slotTranslate()
QWhatsThis::add( m_languages, str );
QWhatsThis::add( m_addLanguage, str );
QWhatsThis::add( m_removeLanguage, str );
+
+ str = m_locale->translate
+ ( "Here you can choose your encoding." );
+ QWhatsThis::add( m_labEncoding, str );
+ QWhatsThis::add( m_encoding, str );
}
QStringList KLocaleConfig::languageList() const
@@ -419,4 +433,59 @@ void KLocaleConfig::changedCountry(int i
emit localeChanged();
emit languageChanged();
+}
+
+void KLocaleConfig::changedEncoding(const QString &_name)
+{
+ QString encodingName = KGlobal::charsets()->encodingForName( _name );
+
+ if ( encodingName == QString::fromLatin1( "iso 8859-6" ) )
+ encodingName = QString::fromLatin1( "iso 8859-6-i" );
+
+ kdDebug() << "KLocaleConfig::changedEncoding(...) Encoding Name: " << encodingName << endl;
+
+ QTextCodec *codec = QTextCodec::codecForName( encodingName.latin1() );
+
+ if ( codec ) {
+ int mibEnum = codec->mibEnum();
+
+ kdDebug() << "KLocaleConfig::changedEncoding(...) MIBenum: " << mibEnum << endl;
+ m_locale->setEncoding( mibEnum );
+
+ // Note: tis 620 = iso 8859-11
+
+ emit localeChanged();
+ }
+ else {
+ // Are not these supported yet ?
+ // pt 154, utf16, ibm 852.
+ KMessageBox::sorry( this, i18n( "Sorry, this encoding is not supported yet." ) );
+ }
+}
+
+int KLocaleConfig::loadCurrentEncoding()
+{
+ QString encoding = QString( m_locale->encoding() );
+ kdDebug() << "Curent Encoding: " << encoding << endl;
+
+ if ( encoding == QString::fromLatin1( "UTF-8" ) )
+ encoding = QString::fromLatin1( "utf8" );
+ else if ( encoding == QString::fromLatin1( "ISO 8859-1" ) )
+ encoding += ' ';
+ else if ( encoding == QString::fromLatin1( "ISO 8859-6-I" ) )
+ encoding = QString::fromLatin1( "iso 8859-6" );
+
+ encoding = encoding.lower();
+
+ int count = 0;
+ QStringList encodingList = KGlobal::charsets()->descriptiveEncodingNames();
+ QStringList::Iterator it;
+ for ( it = encodingList.begin(); it != encodingList.end(); ++it ) {
+ if ( (*it).contains( encoding, true ) == 1 )
+ return count;
+
+ ++count;
+ }
+
+ return 0; // no matching
}
Index: locale.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/locale/locale.h,v
retrieving revision 1.38
diff -u -3 -d -p -r1.38 locale.h
--- locale.h 2001/08/13 17:13:17 1.38
+++ locale.h 2001/09/28 16:18:16
@@ -36,6 +36,7 @@ class KAddButton;
class QListBox;
class QPushButton;
+class QComboBox;
#include <qstringlist.h>
@@ -69,6 +70,7 @@ private slots:
void loadCountryList();
void changedCountry(int);
+ void changedEncoding(const QString &_name);
void readLocale(const QString &path, QString &name,
const QString &sub) const;
@@ -79,16 +81,19 @@ private slots:
private:
QStringList languageList() const;
+ int loadCurrentEncoding();
+
KLocale *m_locale;
KLanguageButton *m_comboCountry;
QLabel *m_labCountry,
- *m_labLang;
+ *m_labLang, *m_labEncoding;
QListBox * m_languages;
KMenuButton * m_addLanguage;
QPushButton * m_removeLanguage;
+ QComboBox * m_encoding;
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic