[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-10-03 17:21:15
[Download RAW message or body]

On Monday 01 October 2001 17:42, Hans Petter Bieker wrote:
>On Fri, 28 Sep 2001, 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. 2. I can not input Japanese.
>
>Please replace i18n() with m_locale->translate().

Ok, fixed. Please review.

Thank you.


["kdebase-kcontrol-locale-encoding-20011004.diff" (text/plain)]

? kdebase-kcontrol-locale-encoding-20011004.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/10/03 14:57:18
@@ -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, m_locale->translate( "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/10/03 14:57:18
@@ -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