--- kopete/kopete/chatwindow/chatmessagepart.cpp 2005-02-23 11:30:49.000000000 +0100 +++ kopete/kopete/chatwindow/chatmessagepart.cpp 2005-05-12 14:40:07.000000000 +0200 @@ -23,9 +23,11 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -162,7 +164,7 @@ { d->xsltParser = new Kopete::XSLT( KopetePrefs::prefs()->styleContents() ); d->transformAllMessages = ( d->xsltParser->flags() & Kopete::XSLT::TransformAllMessages ); - + codepage="Unicode"; backgroundFile = 0; root = 0; messageId = 0; @@ -176,12 +178,11 @@ setMetaRefreshEnabled( false ); begin(); - write( QString::fromLatin1( "\n" - "\n") ); + write( QString::fromLatin1( "\n" + "\n") ); end(); - view()->setFocusPolicy( QWidget::NoFocus ); new ToolTip( this ); @@ -338,7 +339,7 @@ slotRefreshNodes(); } -void ChatMessagePart::appendMessage( Kopete::Message &message ) +void ChatMessagePart::appendMessage( Kopete::Message &message,bool encode) { //parse emoticons and URL now. message.setBody( message.parsedBody() , Kopete::Message::ParsedHTML ); @@ -348,7 +349,6 @@ message.setRtfOverride( d->rtfOverride ); messageMap.append( message.asXML().toString() ); - uint bufferLen = (uint)KopetePrefs::prefs()->chatViewBufferSize(); // transform all messages every time. needed for Adium style. @@ -364,7 +364,13 @@ QDomDocument domMessage = message.asXML(); domMessage.documentElement().setAttribute( QString::fromLatin1( "id" ), QString::number( messageId ) ); QString resultHTML = addNickLinks( d->xsltParser->transform( domMessage.toString() ) ); - + if(encode && (codepage != "Unicode")) + { + QCString locallyEncoded = resultHTML.ascii(); + QTextCodec *codec = QTextCodec::codecForName(codepage.ascii()); + if(codec) + resultHTML = codec->toUnicode( locallyEncoded ); + } QString direction = ( message.plainBody().isRightToLeft() ? QString::fromLatin1("rtl") : QString::fromLatin1("ltr") ); DOM::HTMLElement newNode = document().createElement( QString::fromLatin1("span") ); newNode.setAttribute( QString::fromLatin1("dir"), direction ); @@ -891,3 +897,52 @@ // vim: set noet ts=4 sts=4 sw=4: +void ChatMessagePart::slotConvert(const QString& string) +{ + + + DOM::DOMString text=htmlDocument().body().innerHTML(); + if(codepage!="Unicode") + { + QCString locallyEncoded; + QTextCodec *codec = QTextCodec::codecForName(codepage.ascii()); + if(!codec) + { + kdDebug()<<"codec for this name not exisit\n"; + return; + } + locallyEncoded=codec->fromUnicode(text.string()); + if(string!="Unicode") + { + QTextCodec *codec = QTextCodec::codecForName(string.ascii()); + if(!codec) + { + kdDebug()<<"codec for this name not exisit\n"; + return; + } + text=codec->toUnicode(locallyEncoded); + } + else + text=QString(locallyEncoded); + } + else + { + if(string!="Unicode") + { + QTextCodec *codec = QTextCodec::codecForName(string.ascii()); + if(!codec) + { + kdDebug()<<"codec for this name not exisit\n"; + return; + } + text=codec->toUnicode(text.string().ascii()); + } + } + htmlDocument().body().setInnerHTML(text); + setCodepage(string); +} + +void ChatMessagePart::setCodepage(const QString& page) +{ + codepage=page; +} diff -u -r -N kopete/chatwindow/chatmessagepart.h kopete/chatwindow/chatmessagepart.h --- kopete/kopete/chatwindow/chatmessagepart.h 2005-02-03 23:52:01.000000000 +0100 +++ kopete/kopete/chatwindow/chatmessagepart.h 2005-05-12 10:51:14.000000000 +0200 @@ -55,6 +55,7 @@ * use */ void keepScrolledDown(); + void setCodepage(const QString& page); public slots: /** @@ -91,7 +92,8 @@ * Appends a message to the messave view * @param message The message to be appended */ - void appendMessage( Kopete::Message &message ); + void appendMessage( Kopete::Message &message,bool encode=true ); + void slotConvert(const QString& string); signals: /** @@ -157,6 +159,7 @@ KAction *printAction; KAction *closeAction; KAction *copyURLAction; + QString codepage; void readOverrides(); diff -u -r -N kopete/chatwindow/chatview.cpp kopete/chatwindow/chatview.cpp --- kopete/kopete/chatwindow/chatview.cpp 2005-02-23 11:30:49.000000000 +0100 +++ kopete/kopete/chatwindow/chatview.cpp 2005-05-11 16:13:20.000000000 +0200 @@ -693,8 +693,11 @@ void ChatView::appendMessage(Kopete::Message &message) { remoteTyping( message.from(), false ); - - messagePart()->appendMessage( message ); + + if ( message.direction() != Kopete::Message::Inbound ) + messagePart()->appendMessage( message,false); + else + messagePart()->appendMessage(message); if( !d->isActive ) { switch ( message.importance() ) diff -u -r -N kopete/chatwindow/kopetechatwindow.cpp kopete/chatwindow/kopetechatwindow.cpp --- kopete/kopete/chatwindow/kopetechatwindow.cpp 2005-02-23 11:30:49.000000000 +0100 +++ kopete/kopete/chatwindow/kopetechatwindow.cpp 2005-05-12 14:51:37.000000000 +0200 @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ #include #include "chatmessagepart.h" +#include "chatmemberslistwidget.h" #include "chattexteditpart.h" #include "chatview.h" #include "kopetechatwindow.h" @@ -161,6 +163,12 @@ return myWindow; } +/** + * + * @param parent + * @param name + * @return + */ KopeteChatWindow::KopeteChatWindow( QWidget *parent, const char* name ) : KParts::MainWindow( parent, name ) { @@ -213,6 +221,11 @@ KGlobal::config()->setGroup( QString::fromLatin1("ChatWindowSettings") ); m_alwaysShowTabs = KGlobal::config()->readBoolEntry( QString::fromLatin1("AlwaysShowTabs"), false ); + kdDebug(14010)<<"creating toolbar"<removeClient(m_activeView->msgManager()); + disconnect(m_encoding,SIGNAL(activated( const QString&)), + m_activeView->messagePart(),SLOT(slotConvert( const QString&))); + disconnect(m_encoding,SIGNAL(activated( const QString&)), + this,SLOT(slotEncodingSelected( const QString&))); + } guiFactory()->addClient(view->msgManager()); @@ -808,11 +826,43 @@ m_activeView = view; + + if( !chatViewList.contains( view ) ) attachChatView( view ); connect( m_activeView, SIGNAL( canSendChanged(bool) ), this, SLOT( slotUpdateSendEnabled() ) ); + Kopete::ContactPtrList cList; + cList=m_activeView->membersList()->session()->members(); + Kopete::Contact* ct; + ct=cList.first(); + QString uid; + if(ct) + { + KConfig* cf=KGlobal::config(); + uid=ct->contactId(); + QString gr=cf->group(); + cf->setGroup("Encodings"); + QString enc=cf->readEntry(uid,"Unicode"); + cf->setGroup(gr); + m_activeView->messagePart()->slotConvert(enc); + int i; + for(i=0;imaxCount();i++) + { + if(m_encoding->text(i)==enc) + { + m_encoding->setCurrentItem(i); + break; + } + } + } + + connect(m_encoding,SIGNAL(activated( const QString&)), + m_activeView->messagePart(),SLOT(slotConvert( const QString&))); + connect(m_encoding,SIGNAL(activated( const QString&)), + this,SLOT(slotEncodingSelected( const QString&))); + //Tell it it is active m_activeView->setActive( true ); @@ -1095,6 +1145,9 @@ dlg.configure(); } +/** + * + */ void KopeteChatWindow::slotConfToolbar() { saveMainWindowSettings(KGlobal::config(), QString::fromLatin1( "KopeteChatWindow" )); @@ -1117,3 +1170,72 @@ // vim: set noet ts=4 sts=4 sw=4: + + +void KopeteChatWindow::initEncodings() +{ + QStringList lst=QStringList::split('\n', +"Unicode\n\ +Big5\n\ +Big5-HKSCS\n\ +eucJP\n\ +eucKR\n\ +GB2312\n\ +GBK\n\ +GB18030\n\ +JIS7\n\ +Shift-JIS\n\ +TSCII\n\ +KOI8-R\n\ +KOI8-U\n\ +ISO8859-1\n\ +ISO8859-2\n\ +ISO8859-3\n\ +ISO8859-4\n\ +ISO8859-5\n\ +ISO8859-6\n\ +ISO8859-7\n\ +ISO8859-8\n\ +ISO8859-8-i\n\ +ISO8859-9\n\ +ISO8859-10\n\ +ISO8859-13\n\ +ISO8859-14\n\ +ISO8859-15\n\ +IBM 850\n\ +IBM 866\n\ +CP874\n\ +CP1250\n\ +CP1251\n\ +CP1252\n\ +CP1253\n\ +CP1254\n\ +CP1255\n\ +CP1256\n\ +CP1257\n\ +CP1258\n\ +Apple Roman\n\ +TIS-620"); + m_encoding->insertStringList(lst); +} + + +void KopeteChatWindow::slotEncodingSelected(const QString& string) +{ + if(!m_activeView) + return; + Kopete::ContactPtrList cList; + cList=m_activeView->membersList()->session()->members(); + Kopete::Contact* ct; + ct=cList.first(); + QString uid; + if(ct) + { + KConfig* cf=KGlobal::config(); + uid=ct->contactId(); + QString gr=cf->group(); + cf->setGroup("Encodings"); + cf->writeEntry(uid,string); + cf->setGroup(gr); + } +} diff -u -r -N kopete/chatwindow/kopetechatwindow.h kopete/chatwindow/kopetechatwindow.h --- kopete/kopete/chatwindow/kopetechatwindow.h 2004-11-17 13:05:31.000000000 +0100 +++ kopete/kopete/chatwindow/kopetechatwindow.h 2005-05-12 14:32:09.000000000 +0200 @@ -28,6 +28,7 @@ class KToggleAction; class KActionMenu; class KTempFile; +class KComboBox; class QPixmap; class QTabWidget; class KSqueezedTextLabel; @@ -116,6 +117,7 @@ void addTab( ChatView* ); void setPrimaryChatView( ChatView* ); const QString fileContents( const QString &file ) const; + void initEncodings(); ChatView *m_activeView; ChatView *m_popupView; @@ -129,6 +131,7 @@ QLabel *anim; QMovie animIcon; QPixmap normalIcon; + KComboBox* m_encoding; KAction *chatSend; KAction *historyUp; @@ -210,6 +213,7 @@ void slotStopAnimation( ChatView* ); void slotNickComplete(); void slotCloseChat( QWidget* ); + void slotEncodingSelected(const QString& string); protected: virtual void closeEvent( QCloseEvent *e ); diff -u -r -N kopete/kopeteiface.cpp kopete/kopeteiface.cpp --- kopete/kopete/kopeteiface.cpp 2004-12-04 23:23:42.000000000 +0100 +++ kopete/kopete/kopeteiface.cpp 2005-05-11 08:29:50.000000000 +0200 @@ -84,7 +84,6 @@ { return Kopete::ContactList::self()->contactFileProtocols(displayName); } - QString KopeteIface::messageContact( const QString &contactId, const QString &messageText ) { Kopete::MetaContact *mc = Kopete::ContactList::self()->findMetaContactByContactId( contactId ); diff -u -r -N kopete/systemtray.cpp kopete/systemtray.cpp --- kopete/kopete/systemtray.cpp 2005-02-03 23:52:01.000000000 +0100 +++ kopete/kopete/systemtray.cpp 2005-05-13 08:04:50.000000000 +0200 @@ -19,6 +19,7 @@ #include "systemtray.h" +#include #include #include #include @@ -28,6 +29,8 @@ #include #include #include +#include + #include "kopeteuiglobal.h" #include "kopetemessagemanagerfactory.h" #include "kopeteballoon.h" @@ -245,10 +248,26 @@ msgFrom = msg.from()->metaContact()->displayName(); else msgFrom = msg.from()->contactId(); - + + KConfig* cf=KGlobal::config(); + QString uid=msg.from()->contactId(); + QString gr=cf->group(); + cf->setGroup("Encodings"); + QString codepage=cf->readEntry(uid,"Unicode"); + cf->setGroup(gr); + if(codepage != "Unicode") + { + QCString locallyEncoded = msgText.ascii(); + QTextCodec *codec = QTextCodec::codecForName(codepage.ascii()); + if(codec) + msgText=codec->toUnicode( locallyEncoded ); + } + m_balloon = new KopeteBalloon( i18n( "New Message from %1:
\"%2\"
" ) .arg( msgFrom, msgText ), QString::null ); + kdDebug()<<"baloon from "<