[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-13 12:18:58
[Download RAW message or body]

On Thursday 04 October 2001 21:25, Hans Petter Bieker wrote:
> On Thu, 4 Oct 2001, Toshitaka Fujioka wrote:
> > Ok, fixed. Please review.
>
> * I don't know why you check if it's iso-8859-6, and changes it to
>   iso-8859-1. Maybe you have explained it before
> * You shouldn't call it loadBlablabla, as it doesn't load anything. It
>   converts the index of the listbox to the mib number. Fix the name.
> * Shouldn't you use KCharsets to get mib number instead of using
>   QTextCodec directly? Then you don't have to use .latin1()
> * AFAIK you used descriptiveEncodingNames(). It uses translated strings,
>   so you would have to make sure it's translated each time the user
>   changes the language. And I guess that's not easy because KCharset uses
>   i18n() and not our KLocale object.

Sorry, I was late to reply.
I remade a patch newly. Is this bad idea ?

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

-- A journey of a thousand miles must begin with a single step.  Lao-zi --  


["kdebase-kcontrol-locale-encoding-20011013.diff" (text/x-diff)]

? kdebase-kcontrol-locale-encoding-20011013.diff
Index: locale.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/locale/locale.cpp,v
retrieving revision 1.94
diff -u -3 -d -p -r1.94 locale.cpp
--- locale.cpp	2001/10/10 16:31:47	1.94
+++ locale.cpp	2001/10/13 12:14:40
@@ -31,6 +31,7 @@
 #include <qiconset.h>
 #include <qwhatsthis.h>
 #include <qcombobox.h>
+#include <qtextcodec.h>
 
 #include <qhbox.h>
 
@@ -92,9 +93,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( descriptiveEncodingNames() );
+  connect( m_encoding, SIGNAL(activated(const QString &)),
+           this, SLOT(changedEncoding(const QString &)) );
 
   lay->setRowStretch(2, 5);
 
@@ -312,6 +315,7 @@ void KLocaleConfig::save()
   else
     config->writeEntry("Language",
 		       m_locale->languageList(), ':', true, true);
+  config->writeEntry("EncodingMib", m_locale->encodingMib(), true, true);
 
   config->sync();
 }
@@ -341,6 +345,7 @@ void KLocaleConfig::slotLocaleChanged()
   slotCheckButtons();
 
   m_comboCountry->setCurrentItem( m_locale->country() );
+  m_encoding->setCurrentItem( getListPositionOfCurrentEncodingName() );
 }
 
 void KLocaleConfig::slotTranslate()
@@ -362,6 +367,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
@@ -383,6 +392,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
@@ -418,4 +432,133 @@ void KLocaleConfig::changedCountry(int i
 
   emit localeChanged();
   emit languageChanged();
+}
+
+void KLocaleConfig::changedEncoding(const QString &_name)
+{
+  QString encodingName = 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 );
+
+    emit localeChanged();
+  }
+  else
+    KMessageBox::sorry( this, m_locale->translate( "Sorry, this encoding is not supported yet." ) );
+}
+
+QStringList KLocaleConfig::descriptiveEncodingNames()
+{
+  QPtrList<QTextCodec> codecList;
+  QTextCodec *codec;
+  for ( int i = 0; (codec = QTextCodec::codecForIndex(i)); ++i )
+    codecList.append( codec );
+
+  QStringList names;
+  for ( uint i = 0; i < codecList.count(); ++i ) {
+    QString descriptiveName;
+    QString codecName = QString::fromLatin1( codecList.at(i)->name() );
+    if ( codecName == QString::fromLatin1( "CP 1256" )
+      || codecName == QString::fromLatin1( "ISO 8859-6-I" ) )
+      descriptiveName = m_locale->translate( "Arabic" );
+
+    else if ( codecName == QString::fromLatin1( "CP 1257" )
+           || codecName == QString::fromLatin1( "ISO 8859-13" )
+           || codecName == QString::fromLatin1( "ISO 8859-4" ) )
+      descriptiveName = m_locale->translate( "Baltic" );
+
+    else if ( codecName == QString::fromLatin1( "CP 1250" )
+           || codecName == QString::fromLatin1( "ISO 8859-2" )
+           || codecName == QString::fromLatin1( "ISO 8859-3" ) )
+      descriptiveName = m_locale->translate( "Central European" );
+
+    else if ( codecName == QString::fromLatin1( "Big5" )
+           || codecName == QString::fromLatin1( "GBK" ) )
+      descriptiveName = m_locale->translate( "Chinese" );
+
+    else if ( codecName == QString::fromLatin1( "CP 1251" )
+           || codecName == QString::fromLatin1( "ISO 8859-5" ) )
+      descriptiveName = m_locale->translate( "Cyrillic" );
+
+    else if ( codecName == QString::fromLatin1( "CP 1253" )
+           || codecName == QString::fromLatin1( "ISO 8859-7" ) )
+      descriptiveName = m_locale->translate( "Greek" );
+
+    else if ( codecName == QString::fromLatin1( "CP 1255" )
+           || codecName == QString::fromLatin1( "ISO 8859-8" )
+           || codecName == QString::fromLatin1( "ISO 8859-8-I" ) )
+      descriptiveName = m_locale->translate( "Hebrew" );
+
+    else if ( codecName == QString::fromLatin1( "eucJP" )
+           || codecName == QString::fromLatin1( "JIS7" )
+           || codecName == QString::fromLatin1( "SJIS" ) )
+      descriptiveName = m_locale->translate( "Japanese" );
+
+    else if ( codecName == QString::fromLatin1( "eucKR" ) )
+      descriptiveName = m_locale->translate( "Korean" );
+
+    else if ( codecName == QString::fromLatin1( "KOI8-R" ) )
+      descriptiveName = m_locale->translate( "Russian" );
+
+    else if ( codecName == QString::fromLatin1( "TSCII" ) )
+      descriptiveName = m_locale->translate( "Tamil" );
+
+    else if ( codecName == QString::fromLatin1( "ISO 8859-11" ) )
+      descriptiveName = m_locale->translate( "Thai" );
+
+    else if ( codecName == QString::fromLatin1( "CP 1254" )
+           || codecName == QString::fromLatin1( "ISO 8859-9" ) )
+      descriptiveName = m_locale->translate( "Turkish" );
+
+    else if ( codecName == QString::fromLatin1( "KOI8-U" ) )
+      descriptiveName = m_locale->translate( "Ukrainian" );
+
+    else if ( codecName == QString::fromLatin1( "ISO-10646-UCS-2" )
+           || codecName == QString::fromLatin1( "UTF-8" ) )
+      descriptiveName = m_locale->translate( "Unicode" );
+
+    else if ( codecName == QString::fromLatin1( "CP 1252" )
+           || codecName == QString::fromLatin1( "ISO 8859-1" )
+           || codecName == QString::fromLatin1( "ISO 8859-15" ) )
+      descriptiveName = m_locale->translate( "Western European" );
+
+    else
+      descriptiveName = m_locale->translate( "other" );
+
+    QString descriptiveEncodingName = descriptiveName + " ( " + codecName + " )";
+    names << descriptiveEncodingName;
+  }
+  names.sort();
+  
+  return names;
+}
+
+QString KLocaleConfig::encodingForName( const QString &descriptiveName )
+{
+  int left = descriptiveName.find( "( " );
+  return descriptiveName.mid( left + 2, descriptiveName.find( " )" ) - left - 2 );
+}
+
+int KLocaleConfig::getListPositionOfCurrentEncodingName()
+{
+  QString encoding = QString( m_locale->encoding() );
+  kdDebug() << "Curent Encoding: " << encoding << endl;
+
+  int count = 0;
+  QStringList encodingList = descriptiveEncodingNames();
+  QStringList::Iterator it;
+  for ( it = encodingList.begin(); it != encodingList.end(); ++it ) {
+    if ( encodingForName( *it ) == encoding )
+      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/13 12:14:40
@@ -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,21 @@ private slots:
 private:
   QStringList languageList() const;
 
+  QStringList descriptiveEncodingNames();
+  QString encodingForName( const QString &descriptiveName );
+  int getListPositionOfCurrentEncodingName();
+
   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