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

List:       kde-pim
Subject:    [Kde-pim] [PATCH] KOrganizer's encoding (local8Bit -> UTF8)
From:       Reinhold Kainhofer <reinhold () kainhofer ! com>
Date:       2003-10-30 10:19:29
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yesterday night I played around a bit with libkcal's encoding problem. I 
basically changed all calls that used local8Bit to utf8, and set UnicodeUTF8 
encoding for the QTextStream on reading/writing icalendar files. For me this 
seems to fix most of the encoding problems when restarting korganizer: All 
unicode characters like Chinese, Korean etc. were lost once you restarted 
korganizer. Furthermore if you changed LC_ALL and then restarted korganizer, 
the unicode characters like Russian were also messed up (they worked in some 
cases when you didn't change LC_*). See bugs 55541, 58754, 59106, 55387, 
54023, 52687 and 65815.

Can anybody please check the patch and tell me if it's correct or not?

Since my kmail currently crashes (my fault, but I haven't found the time to 
recompile) I couldn't check the groupware issues, but at least the calendar 
file is now correctly in UTF8 and the unicode characters are preserved. That 
should also fix most of the group scheduling encoding problems, but who 
knows.

There is still one problem left: libkcal seems to insert a line break and a 
space into long summaries/descriptions of events. This leads to a broken 
character every 25 letters or so (see 
http://reinhold.kainhofer.com/Linux/pictures/Unicode1.png). Any idea how to 
prevent this? 
I suspect that I have to add some property to the calendar to indicate utf8 
encoding, but I have no ideas where, what and how.

Reinhold

PS: Before trying out the patch, please back up your calendar and/or disable 
any valuable resources. This patch *might* mess up your unicode characters 
(not that it didn't mess them up so far too).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/oOWxTqjEwhXvPN0RAqgEAKCVHU7w1gX1tRKEhYJNvqKJuFZ4YACfUY9m
WlH2TDzrsabLj8wJyZ8tq40=
=XD7f
-----END PGP SIGNATURE-----

["utf8.patch" (text/x-diff)]

Index: libkcal/calformat.cpp
===================================================================
RCS file: /home/kde/kdepim/libkcal/calformat.cpp,v
retrieving revision 1.11
diff -u -p -3 -r1.11 calformat.cpp
--- libkcal/calformat.cpp	11 Oct 2002 22:35:08 -0000	1.11
+++ libkcal/calformat.cpp	30 Oct 2003 09:18:12 -0000
@@ -91,7 +91,7 @@ QString CalFormat::createUniqueId()
 int CalFormat::calendarVersion(const char* prodId)
 {
   for (const CalVersion* cv = prodIds;  cv->version;  ++cv) {
-    if (!strcmp(prodId, cv->prodId.local8Bit()))
+    if (!strcmp(prodId, cv->prodId.utf8()))
       return cv->version;
   }
   return 0;
Index: libkcal/htmlexport.cpp
===================================================================
RCS file: /home/kde/kdepim/libkcal/htmlexport.cpp,v
retrieving revision 1.5
diff -u -p -3 -r1.5 htmlexport.cpp
--- libkcal/htmlexport.cpp	25 Oct 2003 18:50:18 -0000	1.5
+++ libkcal/htmlexport.cpp	30 Oct 2003 09:18:12 -0000
@@ -67,7 +67,7 @@ bool HtmlExport::save(QTextStream *ts)
   *ts << "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=";
   *ts << "UTF-8\" />\n";
   if (!mTitle.isEmpty())
-    *ts << "  <title>" << mTitle.local8Bit() << "</title>\n";
+    *ts << "  <title>" << mTitle << "</title>\n";
   *ts << "  <style type=\"text/css\">\n";
   *ts << styleSheet();
   *ts << "  </style>\n";
@@ -78,7 +78,7 @@ bool HtmlExport::save(QTextStream *ts)
 
   if (eventsEnabled() || monthViewEnabled()) {
     if (!mTitle.isEmpty())
-      *ts << "<h1>" << mTitle.local8Bit() << "</h1>\n";
+      *ts << "<h1>" << mTitle << "</h1>\n";
   }
 
   // Write Month View
@@ -95,7 +95,7 @@ bool HtmlExport::save(QTextStream *ts)
   // Write Todo List
   if (todosEnabled()) {
     if (!mTitleTodo.isEmpty())
-      *ts << "<h1>" << mTitleTodo.local8Bit() << "</h1>\n";
+      *ts << "<h1>" << mTitleTodo << "</h1>\n";
 
     // Write HTML page content
     createHtmlTodoList(ts);
Index: libkcal/icalformat.cpp
===================================================================
RCS file: /home/kde/kdepim/libkcal/icalformat.cpp,v
retrieving revision 1.50
diff -u -p -3 -r1.50 icalformat.cpp
--- libkcal/icalformat.cpp	15 Aug 2003 15:58:45 -0000	1.50
+++ libkcal/icalformat.cpp	30 Oct 2003 09:18:12 -0000
@@ -74,6 +74,7 @@ bool ICalFormat::load( Calendar *calenda
     return false;
   }
   QTextStream ts( &file );
+  ts.setEncoding( QTextStream::UnicodeUTF8 );
   QString text = ts.read();
   file.close();
 
@@ -104,6 +105,7 @@ bool ICalFormat::save( Calendar *calenda
     return false;
   }
   QTextStream ts( &file );
+  ts.setEncoding( QTextStream::UnicodeUTF8 );
   ts << text;
   file.close();
 
@@ -118,7 +120,7 @@ bool ICalFormat::fromString( Calendar *c
   // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components
   icalcomponent *calendar;
 
-  calendar = icalcomponent_new_from_string( text.local8Bit().data());
+  calendar = icalcomponent_new_from_string( text.utf8().data());
   //  kdDebug(5800) << "Error: " << icalerror_perror() << endl;
   if (!calendar) {
     kdDebug(5800) << "ICalFormat::load() parse error" << endl;
@@ -218,8 +220,8 @@ QString ICalFormat::toString( Calendar *
   Journal::List journals = cal->journals();
   Journal::List::ConstIterator it3;
   for( it3 = journals.begin(); it3 != journals.end(); ++it3 ) {
-//    kdDebug(5800) << "ICalFormat::toString() write journal "
-//                  << (*it3)->uid() << endl;
+    kdDebug(5800) << "ICalFormat::toString() write journal "
+                  << (*it3)->uid() << endl;
     component = mImpl->writeJournal( *it3 );
     icalcomponent_add_component( calendar, component );
   }
@@ -234,7 +236,7 @@ QString ICalFormat::toString( Calendar *
     return QString::null;
   }
 
-  return QString::fromLocal8Bit( text );
+  return QString::fromUtf8( text );
 }
 
 QString ICalFormat::toICalString( Incidence *incidence )
@@ -254,7 +256,7 @@ QString ICalFormat::toString( Incidence 
 
   icalcomponent_free( component );
 
-  return QString::fromLocal8Bit( text );
+  return QString::fromUtf8( text );
 }
 
 QString ICalFormat::toString( Recurrence *recurrence )
@@ -263,7 +265,7 @@ QString ICalFormat::toString( Recurrence
   property = mImpl->writeRecurrenceRule( recurrence );
   const char *text = icalproperty_as_ical_string( property );
   icalproperty_free( property );
-  return QString::fromLocal8Bit( text );
+  return QString::fromUtf8( text );
 }
 
 bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule )
@@ -309,7 +311,7 @@ ScheduleMessage *ICalFormat::parseSchedu
   if (messageText.isEmpty()) return 0;
 
   icalcomponent *message;
-  message = icalparser_parse_string(messageText.local8Bit());
+  message = icalparser_parse_string(messageText.utf8());
 
   if (!message) return 0;
 
Index: libkcal/icalformatimpl.cpp
===================================================================
RCS file: /home/kde/kdepim/libkcal/icalformatimpl.cpp,v
retrieving revision 1.91
diff -u -p -3 -r1.91 icalformatimpl.cpp
--- libkcal/icalformatimpl.cpp	20 Oct 2003 15:22:19 -0000	1.91
+++ libkcal/icalformatimpl.cpp	30 Oct 2003 09:18:13 -0000
@@ -1684,7 +1684,7 @@ icaltimetype ICalFormatImpl::writeICalDa
     if (mParent->timeZoneId().isEmpty())
       t = icaltime_as_utc(t, 0);
     else
-      t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit());
+      t = icaltime_as_utc(t,mParent->timeZoneId().utf8());
   }
 
   return t;
@@ -1706,7 +1706,7 @@ QDateTime ICalFormatImpl::readICalDateTi
     if (mParent->timeZoneId().isEmpty())
       t = icaltime_as_zone(t, 0);
     else
-      t = icaltime_as_zone(t,mParent->timeZoneId().local8Bit());
+      t = icaltime_as_zone(t,mParent->timeZoneId().utf8());
   }
   QDateTime result(QDate(t.year,t.month,t.day),
                    QTime(t.hour,t.minute,t.second));


_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

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

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