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

List:       kde-commits
Subject:    kdebase/kdesktop/lock
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2003-08-23 20:41:53
[Download RAW message or body]

CVS commit by aseigo: 

patch to properly show UNICODE system names in the lock dialog from
ismail.donmez@boun.edu.tr


  M +31 -1     lockdlg.cc   1.27
  M +1 -0      lockdlg.h   1.8


--- kdebase/kdesktop/lock/lockdlg.cc  #1.26:1.27
@@ -74,4 +74,34 @@ PasswordDlg::PasswordDlg(LockProcess *pa
 }
 
+QString PasswordDlg::checkForUtf8(QString txt)
+{
+    /* Code borrowed from KGpg  which in turn took from Gpa */
+    const char *s;
+
+    /* Make sure the encoding is UTF-8. Test structure suggested by Werner Koch */
+    if (txt.isEmpty())
+        return "";
+
+    for (s = txt.ascii(); *s && !(*s & 0x80); s++);
+
+    if (*s && !strchr (txt.ascii(), 0xc3) && (txt.find("\\x")==-1))
+        return txt;
+
+    /* The string is not in UTF-8 */
+    if (txt.find("\\x") == -1)
+      return QString::fromUtf8(txt.ascii());
+
+    for ( int idx = 0 ; (idx = txt.find( "\\x", idx )) >= 0 ; ++idx ) {
+      char str[2] = "x";
+      str[0] = (char) QString( txt.mid( idx + 2, 2 ) ).toShort( 0, 16 );
+      txt.replace( idx, 4, str );
+    }
+
+    if (!strchr(txt.ascii(), 0xc3))
+      return QString::fromUtf8(txt.ascii());
+    else
+      return QString::fromUtf8(QString::fromUtf8(txt.ascii()).ascii());
+}
+
 //---------------------------------------------------------------------------
 //
@@ -91,5 +121,5 @@ QString PasswordDlg::labelText()
     }
 
-    QString username = QString::fromLocal8Bit(current->pw_name);
+    QString username = checkForUtf8(QString::fromLocal8Bit(current->pw_name));
 
     return i18n("Enter the password for user %1 (%2)").arg(fullname).arg(username);

--- kdebase/kdesktop/lock/lockdlg.h  #1.7:1.8
@@ -26,4 +26,5 @@ class PasswordDlg : public LockDlgImpl
 public:
     PasswordDlg(LockProcess *parent, bool msess);
+    QString checkForUtf8(QString txt);
     virtual void show();
 


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

Configure | About | News | Add a list | Sponsored by KoreLogic