Hi,
this is the patch of the other day ported to KDE 4.
It lets us export the Latex formulae as INK Draw gif's, however, it doesn't
work with MSN Plus yet (it seems there is some kind of wrong base64 encoding in
that extension).
Greets.
P.S: I hope this is enough for inclusion.
P.S2: Apply as patch -p0 < patch.txt inside kopete directory (against SVN
revision #681396)
---
Ezequiel R. Aguerre
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
diff -ur ./plugins/latex/kopete_latexconvert.sh
../../kdenetwork/kopete/plugins/latex/kopete_latexconvert.sh
--- ./plugins/latex/kopete_latexconvert.sh 2007-06-28 16:13:32.000000000
-0300
+++ ../../kdenetwork/kopete/plugins/latex/kopete_latexconvert.sh
2007-06-28 16:14:24.000000000 -0300
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#############################################################
# TEX2IM: Converts LaTeX formulas to pixel graphics which #
# can be easily included in Text-Processors like #
@@ -21,7 +21,7 @@
format="png"
color1="white"
color2="black"
-trans=1
+trans=0
noformula=0
aa=1
extra_header="$HOME/.tex2im_header"
diff -ur ./plugins/latex/latexplugin.cpp
../../kdenetwork/kopete/plugins/latex/latexplugin.cpp
--- ./plugins/latex/latexplugin.cpp 2007-06-28 16:13:32.000000000 -0300
+++ ../../kdenetwork/kopete/plugins/latex/latexplugin.cpp 2007-06-28
16:14:24.000000000 -0300
@@ -16,15 +16,16 @@
*************************************************************************
*/
-#include <qregexp.h>
-#include <qimage.h>
-#include <qbuffer.h>
+#include <QRegExp>
+#include <QImage>
+#include <QBuffer>
#include <QTextDocument>
+#include <QMap>
#include <kgenericfactory.h>
#include <kdebug.h>
#include <kstandarddirs.h>
-#include <k3process.h>
+#include <kprocess.h>
#include <ktemporaryfile.h>
#include <kcodecs.h>
#include <kmessagebox.h>
@@ -82,9 +83,11 @@
new LatexGUIClient( KMM );
}
-
void LatexPlugin::slotMessageAboutToShow( Kopete::Message& msg )
{
+ if ( msg.direction() != Kopete::Message::Inbound )
+ return;
+
QString mMagick = KStandardDirs::findExe("convert");
if ( mMagick.isEmpty() )
{
@@ -160,17 +163,8 @@
messageText= msg.escapedBody();
- int imagePxWidth,imagePxHeight;
for (QMap<QString,QString>::ConstIterator it = replaceMap.begin(); it
!= replaceMap.end(); ++it)
- {
- QImage theImage(*it);
- if(theImage.isNull())
- continue;
- imagePxWidth = theImage.width();
- imagePxHeight = theImage.height();
- QString
escapedLATEX=Qt::escape(it.key()).replace("\"","""); //we need the
escape quotes because that string will be in a title="" argument, but not the \n
- messageText.replace(Kopete::Message::escape(it.key()), " <img
width=\"" + QString::number(imagePxWidth) + "\" height=\"" +
QString::number(imagePxHeight) + "\" src=\"" + (*it) + "\" alt=\"" +
escapedLATEX +"\" title=\"" + escapedLATEX +"\" /> ");
- }
+ messageText.replace(Kopete::Message::escape(it.key()),
it.value());
msg.setHtmlBody( messageText );
}
@@ -178,67 +172,61 @@
void LatexPlugin::slotMessageAboutToSend( Kopete::Message& msg)
{
- Q_UNUSED(msg)
- //disabled because to work correctly, we need to find what special has
the gif we can send over MSN
-#if 0
- KSharedConfig::Ptr config = KGlobal::config();
- config->setGroup("Latex Plugin");
-
- if(!config->readEntry("ParseOutgoing", false))
- return;
-
QString messageText = msg.plainBody();
if( !messageText.contains("$$"))
return;
-/* if( msg.from()->protocol()->pluginId()!="MSNProtocol" )
- return;*/
+
+ //if( msg.from()->protocol()->pluginId()!="MSNProtocol" )
+ // return;
// this searches for $$formula$$
QRegExp rg("^\\s*\\$\\$([^$]+)\\$\\$\\s*$");
- if( rg.search(messageText) != -1 )
+ if( rg.indexIn(messageText) != -1 )
{
QString latexFormula = rg.cap(1);
if(!securityCheck( latexFormula ))
return;
- QString url = handleLatex(latexFormula);
-
-
- if(!url.isNull())
- {
- QString escapedLATEX=
Qt::escape(messageText).replace("\"",""");
- QString messageText="<img src=\"" + url + "\" alt=\"" +
escapedLATEX + "\" title=\"" + escapedLATEX +"\" />";
- msg.setBody( messageText, Kopete::Message::RichText );
- }
+ msg.setHtmlBody( handleLatex(latexFormula) );
}
-#endif
}
QString LatexPlugin::handleLatex(const QString &latexFormula)
{
+ static QMap < QString, QString > latexFormulaMap;
+ QMap < QString, QString >::ConstIterator it = latexFormulaMap.constFind
( latexFormula );
+
+ if ( it != latexFormulaMap.constEnd () )
+ return it.value();
+
KTemporaryFile *tempFile=new KTemporaryFile();
tempFile->setPrefix("kopetelatex-");
- tempFile->setSuffix(".png");
+ tempFile->setSuffix(".gif");
tempFile->open();
m_tempFiles.append(tempFile);
QString fileName = tempFile->fileName();
- K3Process p;
+ KProcess p;
QString argumentRes = "-r %1x%2";
QString argumentOut = "-o %1";
- //QString argumentFormat = "-fgif"; //we uses gif format because MSN
only handle gif
+ QString argumentFormat = "-fgif"; //we uses gif format because MSN
only handle gif
int hDPI, vDPI;
hDPI = LatexConfig::self()->horizontalDPI();
vDPI = LatexConfig::self()->verticalDPI();
- p << m_convScript << argumentRes.arg(QString::number(hDPI),
QString::number(vDPI)) << argumentOut.arg(fileName) /*<< argumentFormat*/ <<
latexFormula ;
+ p << m_convScript << argumentRes.arg(QString::number(hDPI),
QString::number(vDPI)) << argumentFormat << argumentOut.arg(fileName) <<
latexFormula;
kDebug() << k_funcinfo << " Rendering " << m_convScript << " " <<
argumentRes.arg(QString::number(hDPI), QString::number(vDPI)) << " " <<
argumentOut.arg(fileName) << endl;
// FIXME our sucky sync filter API limitations :-)
- p.start(K3Process::Block);
- return fileName;
+ p.execute();
+
+ QString escapedLATEX=Qt::escape(latexFormula).replace("\"",""");
+ QString messageText="<img src=\"" + fileName + "\" alt=\"$$" +
escapedLATEX + "$$\" title=\"$$" + escapedLATEX + "$$\" />";
+
+ latexFormulaMap.insert( latexFormula, messageText );
+ return messageText;
}
bool LatexPlugin::securityCheck(const QString &latexFormula)
diff -ur ./protocols/msn/msnswitchboardsocket.cpp
../../kdenetwork/kopete/protocols/msn/msnswitchboardsocket.cpp
--- ./protocols/msn/msnswitchboardsocket.cpp 2007-06-28 16:13:40.000000000
-0300
+++ ../../kdenetwork/kopete/protocols/msn/msnswitchboardsocket.cpp
2007-06-28 16:27:49.000000000 -0300
@@ -667,6 +667,9 @@
// this sends a short message to the server
int MSNSwitchBoardSocket::sendMsg( const Kopete::Message &msg )
{
+ bool inkSend = false;
+ QString head, inkArgs = "A", message;
+
if ( onlineStatus() != Connected || m_chatMembers.empty())
{
// m_messagesQueue.append(msg);
@@ -699,69 +702,91 @@
if( msg.format() & Qt::RichText )
{
- QRegExp regex("^\\s*<img src=\"([^>\"]+)\"[^>]*>\\s*$");
+ QRegExp regex("^.*<img src=\"([^>\"]+)\"[^>]*>.*$");
if(regex.indexIn(msg.escapedBody()) != -1)
{
- // FIXME why are we sending the images.. the contact
should request them.
- PeerDispatcher()->sendImage(regex.cap(1), m_msgHandle);
- return -3;
+ QFile imageFile(regex.cap(1));
+ // If the image exists and is a GIF, then is suitable
to send as an ink draw.
+ if ( imageFile.exists() &&
imageFile.fileName().endsWith( "GIF", Qt::CaseInsensitive ) )
+ {
+ imageFile.open ( QIODevice::ReadOnly );
+ QByteArray ba = imageFile.readAll();
+ imageFile.close ();
+
+ message = QString::fromLatin1 ( "base64:%1"
).arg ( QString ( KCodecs::base64Encode ( ba ) ) );
+ inkSend = true;
+ }
+ // FIXME P2P is the new and right way to go
+ //PeerDispatcher()->sendImage(regex.cap(1),
m_msgHandle);
+ //return -3;
}
}
- // User-Agent is not a official flag, but GAIM has it
- QString UA;
- if( config.readEntry("SendClientInfo", true) )
- {
- UA="User-Agent:
Kopete/"+escape(KGlobal::mainComponent().aboutData()->version())+"\r\n";
- }
-
- QString head =
- "MIME-Version: 1.0\r\n"
- "Content-Type: text/plain; charset=UTF-8\r\n"
- "User-Agent:
Kopete/"+escape(KGlobal::mainComponent().aboutData()->version())+"\r\n"
- "X-MMS-IM-Format: ";
-
- if(msg.font() != QFont() )
- {
- //It's verry strange that if the font name is bigger than 31
char, the _server_ close the socket and don't deliver the message.
- // the real question is why ? my guess is that MS patched
the server because a bug in their client, but that's just a guess.
- head += "FN=" + escape( msg.font().family().left(31));
- head += "; EF=";
- if(msg.font().bold())
- head += 'B';
- if(msg.font().italic())
- head += 'I';
- if(msg.font().strikeOut())
- head += 'S';
- if(msg.font().underline())
- head += 'U';
- head += "; ";
- }
- else head+="FN=; EF=; ";
- /*
- * I don't know what to set by default, so i decided to set nothing.
CF Bug 82734
- * (but don't forgeto to add an empty FN= and EF= , or webmessenger
will break. (CF Bug 102371) )
- else head+="FN=MS%20Serif; EF=; ";
- */
-
- // Color support
- if (msg.foregroundColor().isValid())
+ if ( inkSend )
{
- QString colorCode =
QColor(msg.foregroundColor().blue(),msg.foregroundColor().green(),msg.foregroundColor().red()).name().remove(0,1);
//colors aren't sent in RGB but in BGR (O.G.)
- head += "CO=" + colorCode;
+ inkArgs = "N";
+ head =
+ "MIME-Version: 1.0\r\n"
+ "Content-Type: image/gif\r\n";
}
else
{
- head += "CO=0";
- }
+ // NOTE: Is this safe in an ink draw??
+ // User-Agent is not a official flag, but GAIM has it
+ QString UA;
+ if( config.readEntry("SendClientInfo", true) )
+ {
+ UA="User-Agent:
Kopete/"+escape(KGlobal::mainComponent().aboutData()->version())+"\r\n";
+ }
- head += "; CS=0; PF=0";
- if (msg.plainBody().isRightToLeft())
- head += "; RL=1";
- head += "\r\n";
+ head =
+ "MIME-Version: 1.0\r\n"
+ "Content-Type: text/plain; charset=UTF-8\r\n"
+ "User-Agent:
Kopete/"+escape(KGlobal::mainComponent().aboutData()->version())+"\r\n"
+ "X-MMS-IM-Format: ";
- QString message= msg.plainBody().replace( '\n' , "\r\n" );
+ if(msg.font() != QFont() )
+ {
+ //It's verry strange that if the font name is bigger
than 31 char, the _server_ close the socket and don't deliver the message.
+ // the real question is why ? my guess is that MS
patched the server because a bug in their client, but that's just a guess.
+ head += "FN=" + escape( msg.font().family().left(31));
+ head += "; EF=";
+ if(msg.font().bold())
+ head += 'B';
+ if(msg.font().italic())
+ head += 'I';
+ if(msg.font().strikeOut())
+ head += 'S';
+ if(msg.font().underline())
+ head += 'U';
+ head += "; ";
+ }
+ else head+="FN=; EF=; ";
+ /*
+ * I don't know what to set by default, so i decided to set
nothing. CF Bug 82734
+ * (but don't forgeto to add an empty FN= and EF= , or
webmessenger will break. (CF Bug 102371) )
+ else head+="FN=MS%20Serif; EF=; ";
+ */
+ // Color support
+ if (msg.foregroundColor().isValid())
+ {
+ QString colorCode =
QColor(msg.foregroundColor().blue(),msg.foregroundColor().green(),msg.foregroundColor().red()).name().remove(0,1);
//colors aren't sent in RGB but in BGR (O.G.)
+ head += "CO=" + colorCode;
+ }
+ else
+ {
+ head += "CO=0";
+ }
+
+ head += "; CS=0; PF=0";
+ if (msg.plainBody().isRightToLeft())
+ head += "; RL=1";
+
+ head += "\r\n";
+ message= msg.plainBody().replace( '\n' , "\r\n" );
+ }
+
//-- Check if the message isn't too big, TODO: do that at the
libkopete level.
int len_H=head.toUtf8().length(); // != head.length() because i
need the size in butes and
int len_M=message.toUtf8().length(); // some utf8 char may be
longer than one byte
@@ -778,8 +803,7 @@
//int futurmessages_size=1664-len_H;
int nb=(int)ceil((float)(len_M)/(float)(futurmessages_size));
-
- if(KMessageBox::warningContinueCancel(0L /* FIXME: we should
try to find a parent somewere*/ ,
+ if( inkSend || KMessageBox::warningContinueCancel(0L /* FIXME:
we should try to find a parent somewere*/ ,
i18n("The message you are trying to send is too long;
it will be split into %1 messages.", nb) ,
i18n("Message too big - MSN Plugin" ),
KStandardGuiItem::cont(), KStandardGuiItem::cancel(), "SendLongMessages" )
== KMessageBox::Continue )
@@ -819,7 +843,7 @@
{
kDebug(14140) << k_funcinfo <<"The
message is slit in more than initially estimated" <<endl;
}
- result=sendCommand( "MSG", "A", true,
(head+chunk_str+"\r\n"+m).toUtf8() );
+ result=sendCommand( "MSG", inkArgs, true,
(head+chunk_str+"\r\n"+m).toUtf8() );
chunk++;
}
while(place < len_M) ;
@@ -828,10 +852,10 @@
{
kDebug(14140) << k_funcinfo <<"The message is
plit in less than initially estimated. Sending empty message to complete"
<<endl;
QString chunk_str="Chunk:
"+QString::number(chunk);
- sendCommand( "MSG", "A", true,
(head+chunk_str+"\r\n").toUtf8() );
+ sendCommand( "MSG", inkArgs, true,
(head+chunk_str+"\r\n").toUtf8() );
chunk++;
}
- return result;
+ return ( inkSend ? -3 : result );
}
return -2; //the message hasn't been sent.
}
@@ -844,8 +868,8 @@
m_keepAlive->start(50*1000);
}
-
- return sendCommand( "MSG", "A", true, (head+"\r\n"+message).toUtf8() );
+ int result = sendCommand( "MSG", inkArgs, true,
(head+"\r\n"+message).toUtf8() );
+ return ( inkSend ? -3 : result );
}
void MSNSwitchBoardSocket::slotSocketClosed( )
_______________________________________________
kopete-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kopete-devel