Am Donnerstag, 22. März 2007 13:24 schrieb Stefan Haun: > > I would recommend to store everything in UTF-8 in the history. This is > > factually a superset of all other possible encodings and is, I think, the > > standard way. > > To achieve this, I'll do the following: > - submit a patch for the history reading/writing mechanism to use UTF-8 > only
This part has been solved this evening, I have attached a patch (changes in
four files). Unfortunately I hat to change the history interface a bit, so
the plugins need a recompile, too.
The solution is not as nice as I would like it to be, but I tried to put the
encoding to the "bottlenecks", i.e. to the places where each history data
must pass and the encoding information is known.
Please check the patch for errors or other things I that could be done better.
CAUTION: If you apply this patch, licq will encode each new history entry with
UTF-8, but not convert the existing history. Do not use this on your
live-data!
To get the special chars right, the peer's encoding must be set (in the
message window for qt-plugin).
> - code a script which converts the existing history into UTF-8,
> dependent on the per-user encoding settings
Still left to do, but not for today.
Stefan
--
____
/ \
/ ^ ^ \ Stefan Haun
I \/ I [EMAIL PROTECTED]
II II http://www.tuxathome.de
II II
I /\/\ I
Index: /home/tux/eclipse-workspace/Licq_Main/include/licq_history.h
===================================================================
--- /home/tux/eclipse-workspace/Licq_Main/include/licq_history.h (revision 4878)
+++ /home/tux/eclipse-workspace/Licq_Main/include/licq_history.h (working copy)
@@ -15,6 +15,7 @@
~CUserHistory();
void SetFile(const char *, unsigned long);
void SetFile(const char *, const char *, unsigned long);
+ void SetEncoding(const char*);
void Append(const char *);
bool Load(HistoryList &);
static void Clear(HistoryList &);
@@ -21,9 +22,16 @@
void Save(const char *);
const char *Description() { return m_szDescription; }
const char *FileName() { return m_szFileName; }
+ const char *Encoding() { return m_szEncoding; }
protected:
char *m_szFileName;
char *m_szDescription;
+ /*
+ * The history is stored using UTF-8. However, the user might
+ * have another encoding set. This property stores the encoding
+ * which is used by the licq backend.
+ */
+ char *m_szEncoding;
};
#endif
Index: /home/tux/eclipse-workspace/Licq_Main/include/licq_user.h
===================================================================
--- /home/tux/eclipse-workspace/Licq_Main/include/licq_user.h (revision 4878)
+++ /home/tux/eclipse-workspace/Licq_Main/include/licq_user.h (working copy)
@@ -708,7 +708,7 @@
void EventPush(CUserEvent *);
void WriteToHistory(const char *);
void SetHistoryFile(const char *);
- int GetHistory(HistoryList &h) { return m_fHistory.Load(h); }
+ int GetHistory(HistoryList &h);
static void ClearHistory(HistoryList &h) { CUserHistory::Clear(h); }
void SaveHistory(const char *buf) { m_fHistory.Save(buf); }
const char *HistoryName() { return m_fHistory.Description(); }
Index: /home/tux/eclipse-workspace/Licq_Main/src/history.cpp
===================================================================
--- /home/tux/eclipse-workspace/Licq_Main/src/history.cpp (revision 4878)
+++ /home/tux/eclipse-workspace/Licq_Main/src/history.cpp (working copy)
@@ -32,6 +32,7 @@
#include "licq_message.h"
#include "licq_icq.h"
#include "licq_user.h"
+#include "licq_translate.h"
//A sleazy hack
extern char *PPIDSTRING(unsigned long);
@@ -47,6 +48,7 @@
{
if (m_szFileName != NULL) free(m_szFileName);
if (m_szDescription != NULL) free(m_szDescription);
+ if (m_szEncoding != NULL) free(m_szEncoding);
}
//---SetFile-------------------------------------------------------------------
@@ -100,6 +102,10 @@
}
}
+void CUserHistory::SetEncoding(const char* _encoding)
+{
+ m_szEncoding = strdup(_encoding);
+}
/* szResult[0] != ':' doubles to check if strlen(szResult) < 1 */
@@ -110,6 +116,11 @@
szResult[strlen(szResult) - 1] = '\0'; \
}
+/*
+ * At the end of this macro, the message is converted from
+ * UTF-8 to the users current encoding. This is the reverse
+ * step to the encoding in ICQUser::WriteToHistory(const char*)
+ */
#define GET_VALID_LINES \
{ \
unsigned short nPos = 0; \
@@ -131,6 +142,14 @@
} \
if (nPos > 0 && szMsg[nPos - 1] == '\n') \
szMsg[nPos - 1] = '\0'; \
+ if (Encoding() != NULL) { \
+ char* _utfMsg = strdup(szMsg); \
+ char* _localMsg = strdup(szMsg); \
+ _localMsg = gTranslator.FromUnicode(_utfMsg, m_szEncoding); \
+ strncpy(szMsg, _localMsg, MAX_HISTORY_MSG_SIZE + 1); \
+ free(_utfMsg); \
+ free(_localMsg); \
+ } \
}
#define SKIP_VALID_LINES \
Index: /home/tux/eclipse-workspace/Licq_Main/src/user.cpp
===================================================================
--- /home/tux/eclipse-workspace/Licq_Main/src/user.cpp (revision 4878)
+++ /home/tux/eclipse-workspace/Licq_Main/src/user.cpp (working copy)
@@ -38,6 +38,7 @@
#include "licq_packets.h"
#include "licq_icqd.h"
#include "licq_socket.h"
+#include "licq_translate.h"
#include "support.h"
#include "pthread_rdwr.h"
@@ -2562,6 +2563,16 @@
SaveLicqInfo();
}
+/// Load the users history
+int ICQUser::GetHistory(HistoryList &h)
+{
+ /*
+ * Set the encoding in case it has been changed.
+ */
+ m_fHistory.SetEncoding(UserEncoding());
+
+ return m_fHistory.Load(h);
+}
void ICQUser::SetIpPort(unsigned long _nIp, unsigned short _nPort)
{
@@ -3625,7 +3636,27 @@
void ICQUser::WriteToHistory(const char *_szText)
{
- m_fHistory.Append(_szText);
+ /* Encode to UTF-8
+ *
+ * This has been added to make assumptions about the encoding used
+ * in the history file possible. Each history is encoded in UTF-8,
+ * independent from the user's encoding.
+ */
+
+ // these are needed as char* by the encoding routine
+ char* _encoding = strdup(UserEncoding());
+ char* _text = strdup(_szText);
+
+ // encode to UTF-8
+ char* _utfText = gTranslator.ToUnicode(_text, _encoding);
+
+ // append to history
+ m_fHistory.Append(_utfText);
+
+ // delete auxiliary variables
+ free(_encoding);
+ free(_text);
+ free(_utfText);
}
pgpxxZ2aZwXkF.pgp
Description: PGP signature
