Bug 107329 - Konsole doesn't save Encoding setting
Summary: Konsole doesn't save Encoding setting
Status: RESOLVED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-13 12:21 UTC by clcevboxvjeo
Modified: 2007-12-25 23:54 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description clcevboxvjeo 2005-06-13 12:21:49 UTC
Version:            (using KDE KDE 3.4.1)
Installed from:    Unlisted Binary Package
OS:                Linux

1. Konsole - Settings - Encoding - C.E(iso8859-2)
2. Settings - Save as default
3. Open new tab or Restart Konsole and see Settings - Encoding is set to Default!

It's annoying
Comment 1 clcevboxvjeo 2005-06-16 09:22:37 UTC
Hey guys, why noone answers to this? I don't believe it's working fine in your case. Please try it:

From Konsole menu select some Encoding and Save it as default.

Then run another instance of Konsole and you'll see that Encoding settings ARE NOT APPLIED!
Comment 2 Kurt Hindenburg 2005-06-16 16:56:50 UTC
Yes, I'm aware of this. The person who supplied the patch for the Encoding didn't take into account saving/loading the encoding at start time.  Although session management should work.
I'll see if I can fix by 3.4.2
Comment 3 clcevboxvjeo 2005-06-17 10:37:16 UTC
Yes, you're right. Session management works, after startup it loads enverything correctly. But manually saving doesn't work.
Comment 4 Kurt Hindenburg 2005-06-18 17:14:11 UTC
SVN commit 426784 by hindenburg:

Allow saving/loading of Encoding in 'Save as Default'.
Will backport to 3.4

BUG: 107329


 M  +55 -1     konsole.cpp  
 M  +2 -0      konsole.h  


--- trunk/KDE/kdebase/konsole/konsole/konsole.cpp #426783:426784
@@ -1469,6 +1469,7 @@
   config->writeEntry("TabColor", tabwidget->tabColor(se->widget()));
 
   if (se) {
+    config->writeEntry("EncodingName", se->encoding());
     config->writeEntry("history", se->history().getSize());
     config->writeEntry("historyenabled", b_histEnabled);
   }
@@ -1595,6 +1596,8 @@
       b_autoResizeTabs = config->readBoolEntry("AutoResizeTabs", false);
       m_tabColor = config->readColorEntry("TabColor");
       if ( !m_tabColor.isValid() ) m_tabColor = QColor( Qt::black );
+
+      s_encodingName = config->readEntry( "EncodingName", "" ).lower();
    }
 
    if (m_menuCreated)
@@ -1615,6 +1618,7 @@
       showMenubar->setChecked(!menuBar()->isHidden());
       selectScrollbar->setCurrentItem(n_scroll);
       selectBell->setCurrentItem(n_bell);
+      selectSetEncoding->setCurrentItem( se->encodingNo() );
       updateRMBMenu();
    }
    updateKeytabMenu();
@@ -2541,6 +2545,54 @@
   activateSession(oldSession);
 }
 
+// Set session encoding; don't use any menu items.
+// System's encoding list may change, so search for encoding string.
+// FIXME: A lot of duplicate code from slotSetSessionEncoding
+void Konsole::setSessionEncoding( const QString &encoding, TESession *session )
+{
+    if ( encoding.isEmpty() )
+        return;
+
+    if ( !session )
+        session = se;
+
+    // availableEncodingNames and descriptEncodingNames are NOT returned
+    // in the same order.
+    QStringList items = KGlobal::charsets()->descriptiveEncodingNames();
+    QString enc;
+
+    // For purposes of using 'find' add a space after name,
+    // otherwise 'iso 8859-1' will find 'iso 8859-13'
+    QString t_enc = encoding + " ";
+    unsigned int i = 0;
+
+    for( QStringList::ConstIterator it = items.begin(); it != items.end(); 
+         ++it, ++i)
+    {
+        if ( (*it).find( t_enc ) != -1 )
+        {
+            enc = *it;
+            break;
+        }
+    }
+    if (i >= items.count())
+        return;
+
+    bool found = false;
+    enc = KGlobal::charsets()->encodingForName(enc);
+    QTextCodec * qtc = KGlobal::charsets()->codecForName(enc, found);
+
+    //kdDebug()<<"setSessionEncoding="<<enc<<"; "<<i<<"; found="<<found<<endl;
+    if ( !found )
+        return;
+
+    session->setEncodingNo( i + 1 );    // Take into account Default
+    session->getEmulation()->setCodec(qtc);
+    if (se == session)
+        activateSession(se);
+
+}
+
 void Konsole::slotSetSessionEncoding(TESession *session, const QString &encoding)
 {
   if (!selectSetEncoding)
@@ -2567,7 +2619,7 @@
   if(!found)
      return;
 
-  session->setEncodingNo(i);
+  session->setEncodingNo( i + 1 );    // Take into account Default
   session->getEmulation()->setCodec(qtc);
   if (se == session)
      activateSession(se);
@@ -2820,6 +2872,8 @@
   else
     s->setHistory(HistoryTypeNone());
 
+  setSessionEncoding( s_encodingName, s );
+
   addSession(s);
   runSession(s); // activate and run
   return sessionId;
--- trunk/KDE/kdebase/konsole/konsole/konsole.h #426783:426784
@@ -86,6 +86,7 @@
   void setSchema(const QString & path);
   void setEncoding(int);
   void setSessionTitle(QString&, TESession* = 0);
+  void setSessionEncoding(const QString&, TESession* = 0);
 
   void enableFullScripting(bool b);
   void enableFixedSize(bool b);
@@ -294,6 +295,7 @@
   TESession*     se_previous;
   TESession*     m_initialSession;
   ColorSchemaList* colors;
+  QString        s_encodingName;
 
   QPtrDict<KRootPixmap> rootxpms;
   KWinModule*    kWinModule;
Comment 5 Kurt Hindenburg 2005-06-18 17:32:27 UTC
SVN commit 426796 by hindenburg:

Allow saving/loading of Encoding in 'Save as Default'.

CCBUG: 107329


 M  +55 -1     konsole.cpp  
 M  +2 -0      konsole.h  


--- branches/KDE/3.4/kdebase/konsole/konsole/konsole.cpp #426795:426796
@@ -1470,6 +1470,7 @@
   config->writeEntry("AutoResizeTabs", b_autoResizeTabs);
 
   if (se) {
+    config->writeEntry("EncodingName", se->encoding());
     config->writeEntry("history", se->history().getSize());
     config->writeEntry("historyenabled", b_histEnabled);
   }
@@ -1595,6 +1596,8 @@
       m_tabViewMode = TabViewModes(config->readNumEntry("TabViewMode", ShowIconAndText));
       b_dynamicTabHide = config->readBoolEntry("DynamicTabHide", false);
       b_autoResizeTabs = config->readBoolEntry("AutoResizeTabs", false);
+
+      s_encodingName = config->readEntry( "EncodingName", "" ).lower();
    }
 
    if (m_menuCreated)
@@ -1615,6 +1618,7 @@
       showMenubar->setChecked(!menuBar()->isHidden());
       selectScrollbar->setCurrentItem(n_scroll);
       selectBell->setCurrentItem(n_bell);
+      selectSetEncoding->setCurrentItem( se->encodingNo() );
       updateRMBMenu();
    }
    updateKeytabMenu();
@@ -2575,6 +2579,54 @@
   activateSession(oldSession);
 }
 
+// Set session encoding; don't use any menu items.
+// System's encoding list may change, so search for encoding string.
+// FIXME: A lot of duplicate code from slotSetSessionEncoding
+void Konsole::setSessionEncoding( const QString &encoding, TESession *session )
+{
+    if ( encoding.isEmpty() )
+        return;
+
+    if ( !session )
+        session = se;
+
+    // availableEncodingNames and descriptEncodingNames are NOT returned
+    // in the same order.
+    QStringList items = KGlobal::charsets()->descriptiveEncodingNames();
+    QString enc;
+
+    // For purposes of using 'find' add a space after name,
+    // otherwise 'iso 8859-1' will find 'iso 8859-13'
+    QString t_enc = encoding + " ";
+    unsigned int i = 0;
+
+    for( QStringList::ConstIterator it = items.begin(); it != items.end(); 
+         ++it, ++i)
+    {
+        if ( (*it).find( t_enc ) != -1 )
+        {
+            enc = *it;
+            break;
+        }
+    }
+    if (i >= items.count())
+        return;
+
+    bool found = false;
+    enc = KGlobal::charsets()->encodingForName(enc);
+    QTextCodec * qtc = KGlobal::charsets()->codecForName(enc, found);
+
+    //kdDebug()<<"setSessionEncoding="<<enc<<"; "<<i<<"; found="<<found<<endl;
+    if ( !found )
+        return;
+
+    session->setEncodingNo( i + 1 );    // Take into account Default
+    session->getEmulation()->setCodec(qtc);
+    if (se == session)
+        activateSession(se);
+
+}
+
 void Konsole::slotSetSessionEncoding(TESession *session, const QString &encoding)
 {
   if (!selectSetEncoding)
@@ -2601,7 +2653,7 @@
   if(!found)
      return;
 
-  session->setEncodingNo(i);
+  session->setEncodingNo( i + 1 );    // Take into account Default
   session->getEmulation()->setCodec(qtc);
   if (se == session)
      activateSession(se);
@@ -2855,6 +2907,8 @@
   else
     s->setHistory(HistoryTypeNone());
 
+  setSessionEncoding( s_encodingName, s );
+
   addSession(s);
   runSession(s); // activate and run
   return sessionId;
--- branches/KDE/3.4/kdebase/konsole/konsole/konsole.h #426795:426796
@@ -83,6 +83,7 @@
   void newSession(const QString &program, const QStrList &args, const QString &term, const QString &icon, const QString &title, const QString &cwd);
   void setSchema(const QString & path);
   void setEncoding(int);
+  void setSessionEncoding(const QString&, TESession* = 0);
 
   void enableFullScripting(bool b);
   void enableFixedSize(bool b);
@@ -289,6 +290,7 @@
   TESession*     se_previous;
   TESession*     m_initialSession;
   ColorSchemaList* colors;
+  QString        s_encodingName;
 
   QPtrDict<KRootPixmap> rootxpms;
   KWinModule*    kWinModule;
Comment 6 Ruben Jenster 2005-07-12 14:12:09 UTC
I applied this patch against 3.4.1 and recompiled konsole. 
But encoding still falls back to standard.

Any Suggestions?

Regards 

Ruben
Comment 7 Kurt Hindenburg 2005-07-12 17:35:24 UTC
What is the output of this?

grep EncodingName $KDEHOME/share/config/konsolerc
Comment 8 clcevboxvjeo 2005-08-21 17:06:19 UTC
Just tried it in Klax 3.5 alpha, but the bug is there again.
Comment 9 Kurt Hindenburg 2005-08-22 01:06:33 UTC
The Encoding is saved... if have one tab open and save as default; close Konsole, restart Konsole, that Encoding is used.  

The issue is that new tabs are not getting the Encoding from the 'Save as Default' if you mix the Shells' Encoding...

Comment 10 Joerg Stolzenberg 2005-09-21 03:23:50 UTC
Just tried with Debian unstable (konsole 3.4.2-3).  The setting for encoding is saved correctly in konsolerc, but starts with default setting anyway. Independent if a tab is open or not.
Comment 11 Stefan Scheler 2005-10-19 12:44:27 UTC
Hmm, so what is the status on this? In which version is this bug supposed to be fixed?
Comment 12 Kurt Hindenburg 2005-11-13 10:47:51 UTC
SVN commit 480099 by hindenburg:

The saving and loading of the Encoding should (finally) be fixed now.  This should be in KDE 3.5rc2 (I hope).

BUG: 107329


 M  +27 -27    konsole.cpp  


--- branches/KDE/3.5/kdebase/konsole/konsole/konsole.cpp #480098:480099
@@ -634,6 +634,8 @@
       list.prepend( i18n( "Default" ) );
 
       // BR114535 : Remove jis7 due to infinite loop.
+      // If you fix this issue and remove the line below,  remember to 
+      // remove the line in setSessionEncoding() (search for jis7).
       list.remove( i18n( "Japanese ( jis7 )" ) );
       selectSetEncoding->setItems(list);
       selectSetEncoding->setCurrentItem (0);
@@ -1485,8 +1487,15 @@
   config->writeEntry("DynamicTabHide", b_dynamicTabHide);
   config->writeEntry("AutoResizeTabs", b_autoResizeTabs);
 
+  if (selectSetEncoding)
+  {
+    QString encoding = KGlobal::charsets()->encodingForName(selectSetEncoding->currentText());
+    config->writeEntry("EncodingName", encoding);
+  } else {    // This will not always work (ie 'winsami' saves as 'ws2')
+    if (se) config->writeEntry("EncodingName", se->encoding());
+  }
+
   if (se) {
-    config->writeEntry("EncodingName", se->encoding());
     config->writeEntry("history", se->history().getSize());
     config->writeEntry("historyenabled", b_histEnabled);
   }
@@ -2604,37 +2613,28 @@
     if ( !session )
         session = se;
 
-    // availableEncodingNames and descriptEncodingNames are NOT returned
-    // in the same order.
-    QStringList items = KGlobal::charsets()->descriptiveEncodingNames();
-    QString enc;
+    bool found = false;
+    QString enc = KGlobal::charsets()->encodingForName(encoding);
+    QTextCodec * qtc = KGlobal::charsets()->codecForName(enc, found);
+    if ( !found || !qtc )
+        return;
 
-    // For purposes of using 'find' add a space after name,
-    // otherwise 'iso 8859-1' will find 'iso 8859-13'
-    QString t_enc = encoding + " ";
-    unsigned int i = 0;
-
-    for( QStringList::ConstIterator it = items.begin(); it != items.end();
-         ++it, ++i)
+    // Encoding was found; now try to figure out which Encoding menu item
+    // it corresponds to.
+    int i = 0;
+    QStringList encodingNames = KGlobal::charsets()->descriptiveEncodingNames();
+    QStringList::Iterator it = encodingNames.begin();
+    while ( it != encodingNames.end() && 
+            KGlobal::charsets()->encodingForName(*it) != encoding )
     {
-        if ( (*it).find( t_enc ) != -1 )
-        {
-            enc = *it;
-            break;
-        }
+      i++; it++;
     }
-    if (i >= items.count())
-        return;
 
-    bool found = false;
-    enc = KGlobal::charsets()->encodingForName(enc);
-    QTextCodec * qtc = KGlobal::charsets()->codecForName(enc, found);
+    i++;                 // Take into account the first entry: Default
+    if ( i > 24 ) i--;   // Handle the removed jis7 entry
+    //kdDebug()<<"setSessionEncoding="<<encoding<<"; "<<i<<endl;
 
-    //kdDebug()<<"setSessionEncoding="<<enc<<"; "<<i<<"; found="<<found<<endl;
-    if ( !found )
-        return;
-
-    session->setEncodingNo( i + 1 );    // Take into account Default
+    session->setEncodingNo( i );
     session->getEmulation()->setCodec(qtc);
     if (se == session)
         activateSession(se);
Comment 13 Kurt Hindenburg 2005-11-13 11:45:46 UTC
SVN commit 480103 by hindenburg:

Let's handle the jis7 problem this way.  That way the translators don't have
any new strings and I don't have to worry about the loading/saving not working
again.  It is too bad it is not possible to disable an item in a KSelectAction.

CCBUG: 107329
CCBUG: 114535


 M  +8 -6      konsole.cpp  


--- branches/KDE/3.5/kdebase/konsole/konsole/konsole.cpp #480102:480103
@@ -632,11 +632,6 @@
       selectSetEncoding = new KSelectAction( i18n( "&Encoding" ), SmallIconSet( "charset" ), 0, this, SLOT(slotSetEncoding()), actions, "set_encoding" );
       QStringList list = KGlobal::charsets()->descriptiveEncodingNames();
       list.prepend( i18n( "Default" ) );
-
-      // BR114535 : Remove jis7 due to infinite loop.
-      // If you fix this issue and remove the line below,  remember to 
-      // remove the line in setSessionEncoding() (search for jis7).
-      list.remove( i18n( "Japanese ( jis7 )" ) );
       selectSetEncoding->setItems(list);
       selectSetEncoding->setCurrentItem (0);
       selectSetEncoding->plug(m_options);
@@ -863,6 +858,14 @@
     bool found;
     QString enc = KGlobal::charsets()->encodingForName(selectSetEncoding->currentText());
     qtc = KGlobal::charsets()->codecForName(enc, found);
+
+    // BR114535 : Remove jis7 due to infinite loop.
+    if ( enc == "jis7" ) {
+      kdWarning()<<"Encoding Japanese (jis7) currently does not work!  BR114535"<<endl;
+      qtc = QTextCodec::codecForLocale();
+      selectSetEncoding->setCurrentItem( 0 );
+    }
+
     if(!found)
     {
       kdWarning() << "Codec " << selectSetEncoding->currentText() << " not found!" << endl;
@@ -2631,7 +2634,6 @@
     }
 
     i++;                 // Take into account the first entry: Default
-    if ( i > 24 ) i--;   // Handle the removed jis7 entry
     //kdDebug()<<"setSessionEncoding="<<encoding<<"; "<<i<<endl;
 
     session->setEncodingNo( i );
Comment 14 atom 2005-11-20 03:07:25 UTC
An update:

utf8 encoding save does not work, due to the incorrect specification of the encoding in the savefile.

when saved, the utf8 encoding is saved in the konsolerc as UTF-8. That is not correct, as when loaded up again, the encoding is set to default, and utf8 chars do not work.

when I manually changed UTF-8 to utf8 with vim, it started up just fine and works.

so, I guess that somebody screwed up the savestrings :D.
Comment 15 Kurt Hindenburg 2005-11-20 03:34:44 UTC
atom: Are you using the latest subversion code?  I'm using utf8 w/o any problems.  You might try chossing Encoding->UTF8 and then 'Save as Default' to see what it puts in your konsolerc.

% grep -i encoding $KDEHOME/share/config/konsolerc
EncodingName=utf8
Comment 16 Viorel Tabara 2006-06-23 00:18:10 UTC
Linux 2.6.16-gentoo-r7 #1 SMP Tue Jun 6 12:48:30 MDT 2006
Qt: 3.3.6
KDE: 3.5.2
Konsole: 1.6.2

1.Selected encoding UTF-8 and saved as default. 
2.Closed *all* the sessions one by one with "Ctrl-D". 
3.Reopened Konsole and the new encoding is there.
Comment 17 Sergey Smirnov 2006-10-31 15:44:07 UTC
Is it possible to save encoding for each sessions?
I have a lot of servers working in different LANG.
Now I have to change encoding each times when open ssh session in konsole
Comment 18 shattered 2007-12-25 23:54:20 UTC
Yeah, that feature would be nice to have.