[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] Add select encoding in Control Center (for CVS HEAD)
From:       Toshitaka Fujioka <toshitaka () kde ! gr ! jp>
Date:       2001-09-27 15:55:05
[Download RAW message or body]

Hello,

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 select "Control Center -> Personalization -> Country & Language ->
Encoding -> Your encoding".
 
Please review.
-- 
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-20010928.diff" (text/x-diff)]

? kdebase-kcontrol-locale-encoding-20010928.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/27 15:50:00
@@ -31,6 +31,8 @@
 #include <qiconset.h>
 #include <qwhatsthis.h>
 #include <qcombobox.h>
+#include <qregexp.h>
+#include <qtextcodec.h>
 
 #include <qhbox.h>
 
@@ -93,9 +95,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("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 +317,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 +347,7 @@ void KLocaleConfig::slotLocaleChanged()
   slotCheckButtons();
 
   m_comboCountry->setCurrentItem( m_locale->country() );
+  m_encoding->setCurrentItem( loadCurrentEncoding() );
 }
 
 void KLocaleConfig::slotTranslate()
@@ -363,6 +369,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 +394,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 +434,52 @@ void KLocaleConfig::changedCountry(int i
 
   emit localeChanged();
   emit languageChanged();
+}
+
+void KLocaleConfig::changedEncoding(const QString &_name)
+{
+  QString encodingName = KGlobal::charsets()->encodingForName( _name );
+  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, iso 8859-6, ibm 852.
+    KMessageBox::sorry( this, i18n( "Sorry, this encoding is not supported yet." ) );
+  }
+}
+
+int KLocaleConfig::loadCurrentEncoding()
+{
+  QString encoding = QString( m_locale->encoding() );
+
+  if ( encoding == QString::fromLatin1( "UTF-8" ) )
+    encoding = QString::fromLatin1( "utf8" );
+  else if ( encoding == QString::fromLatin1( "ISO 8859-1" ) )
+    encoding += ' ';
+
+  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/27 15:50:00
@@ -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