diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bcb704366cb5e333a626c18c308c7e0448a8e69f (patch) | |
tree | f0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/plugins/latex | |
download | tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/plugins/latex')
-rw-r--r-- | kopete/plugins/latex/Makefile.am | 27 | ||||
-rw-r--r-- | kopete/plugins/latex/icons/Makefile.am | 3 | ||||
-rw-r--r-- | kopete/plugins/latex/icons/cr32-app-latex.png | bin | 0 -> 474 bytes | |||
-rw-r--r-- | kopete/plugins/latex/kopete_latex.desktop | 71 | ||||
-rw-r--r-- | kopete/plugins/latex/kopete_latex_config.desktop | 69 | ||||
-rwxr-xr-x | kopete/plugins/latex/kopete_latexconvert.sh | 234 | ||||
-rw-r--r-- | kopete/plugins/latex/latexchatui.rc | 9 | ||||
-rw-r--r-- | kopete/plugins/latex/latexconfig.kcfg | 19 | ||||
-rw-r--r-- | kopete/plugins/latex/latexconfig.kcfgc | 7 | ||||
-rw-r--r-- | kopete/plugins/latex/latexguiclient.cpp | 76 | ||||
-rw-r--r-- | kopete/plugins/latex/latexguiclient.h | 53 | ||||
-rw-r--r-- | kopete/plugins/latex/latexplugin.cpp | 259 | ||||
-rw-r--r-- | kopete/plugins/latex/latexplugin.h | 77 | ||||
-rw-r--r-- | kopete/plugins/latex/latexpreferences.cpp | 76 | ||||
-rw-r--r-- | kopete/plugins/latex/latexpreferences.h | 48 | ||||
-rw-r--r-- | kopete/plugins/latex/latexprefsbase.ui | 168 |
16 files changed, 1196 insertions, 0 deletions
diff --git a/kopete/plugins/latex/Makefile.am b/kopete/plugins/latex/Makefile.am new file mode 100644 index 00000000..924da747 --- /dev/null +++ b/kopete/plugins/latex/Makefile.am @@ -0,0 +1,27 @@ +METASOURCES = AUTO + +SUBDIRS = icons + +AM_CPPFLAGS = $(KOPETE_INCLUDES) $(all_includes) + +kde_module_LTLIBRARIES = kopete_latex.la kcm_kopete_latex.la + +kopete_latex_la_SOURCES = latexplugin.cpp latexconfig.kcfgc latexguiclient.cpp +kopete_latex_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN) $(all_libraries) +kopete_latex_la_LIBADD = ../../libkopete/libkopete.la + +kcm_kopete_latex_la_SOURCES = latexprefsbase.ui latexpreferences.cpp latexconfig.kcfgc +kcm_kopete_latex_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN) $(all_libraries) +kcm_kopete_latex_la_LIBADD = $(LIB_KOPETECOMPAT) $(LIB_KUTILS) + +service_DATA = kopete_latex.desktop +servicedir = $(kde_servicesdir) + +kcm_DATA = kopete_latex_config.desktop +kcmdir = $(kde_servicesdir)/kconfiguredialog + +bin_SCRIPTS = kopete_latexconvert.sh +kde_kcfg_DATA = latexconfig.kcfg + +mydatadir = $(kde_datadir)/kopete_latex +mydata_DATA = latexchatui.rc
\ No newline at end of file diff --git a/kopete/plugins/latex/icons/Makefile.am b/kopete/plugins/latex/icons/Makefile.am new file mode 100644 index 00000000..224eb420 --- /dev/null +++ b/kopete/plugins/latex/icons/Makefile.am @@ -0,0 +1,3 @@ +kopeteicondir = $(kde_datadir)/kopete/icons +kopeteicon_ICON = AUTO + diff --git a/kopete/plugins/latex/icons/cr32-app-latex.png b/kopete/plugins/latex/icons/cr32-app-latex.png Binary files differnew file mode 100644 index 00000000..69df3f61 --- /dev/null +++ b/kopete/plugins/latex/icons/cr32-app-latex.png diff --git a/kopete/plugins/latex/kopete_latex.desktop b/kopete/plugins/latex/kopete_latex.desktop new file mode 100644 index 00000000..3d957701 --- /dev/null +++ b/kopete/plugins/latex/kopete_latex.desktop @@ -0,0 +1,71 @@ +[Desktop Entry] +Type=Service +X-Kopete-Version=1000900 +Icon=latex +ServiceTypes=Kopete/Plugin +X-KDE-Library=kopete_latex +X-KDE-PluginInfo-Author=Duncan Mac-Vicar +X-KDE-PluginInfo-Name=kopete_latex +X-KDE-PluginInfo-Version=0.8.0 +X-KDE-PluginInfo-Website=http://kopete.kde.org +X-KDE-PluginInfo-Category=Plugins +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=false +Name=KopeTeX +Name[bn]=কপেটেক +Name[ja]=KopeTex +Name[ne]=कोपेटेक्स +Name[sv]=Kopetex +Comment=Render Latex formulas in the chatwindow +Comment[be]=Паказваць формулы Latex у вакне гутаркі +Comment[bg]=Показване на формули на Latex в прозореца за чат +Comment[bn]=চ্যাট উইন্ডোতে লেটেক ফর্মূলা প্রদর্শন করে +Comment[bs]=Iscrtava Latex formule u chat prozoru +Comment[ca]=Representa fórmules Latex a la finestra de xat +Comment[cs]=Vykresluje vzorce LaTeXu v okně rozhovoru +Comment[da]=Viser Latex-formler i chat-vinduet +Comment[de]=Latex-Formeln in einem Chat-Fenster anzeigen +Comment[el]=Εξισώσεις Latex στο παράθυρο συνομιλίας +Comment[es]=Muestra fórmulas LaTeX en la ventana de charla +Comment[et]=LaTeXi valemite renderdamine vestlusaknas +Comment[eu]=Elkarrizketa leihoaetan Latex formulak marrazten ditu +Comment[fa]=نمایش فرمولهای Latex در پنجرۀ گفتگو +Comment[fi]=Renderöi Latex-kaavoja keskusteluikkunaan +Comment[fr]=Affichage de formules LaTeX dans la fenêtre de discussion +Comment[gl]=Debuxar as fórmulas de Laxtex na fiestra de conversa +Comment[he]=מציג נוסחאות של Latex בחלון השיחה +Comment[hu]=Latex-es képletek megjelenítése a csevegési ablakban +Comment[is]=Teikna Latex formúlur í spjallglugganum +Comment[it]=Visualizza formule latex nella finestra di chat +Comment[ja]=チャットウィンドウで LaTeX の数式を表示 +Comment[ka]=Latex ფორმულების საუბრის ფანჯარაში რენდერი +Comment[kk]=Latex формулаларын әңгіме терезесінде келтіру +Comment[km]=បង្ហាញរូបមន្ត Latex នៅក្នុងបង្អួចជជែកកំសាន្ដ +Comment[lt]=Vykdyti Latex formules pokalbių lange +Comment[mk]=Исцртува Latex формули во прозорецот за разговори +Comment[nb]=Tegn LaTeX-formler i pratevinduet +Comment[nds]=Latex-Formeln binnen dat Klöönfinster wiesen +Comment[ne]=कुराकानी सञ्झ्यालमा ल्याटेक्स सूत्र रेन्डर गर्नुहोस् +Comment[nl]=Latex-formules renderen in het gespreksvenster +Comment[nn]=Vis Latex-formlar i pratevindauget +Comment[pl]=Wyświetla wyrażenia Latexa w oknie rozmowy +Comment[pt]=Mostrar formulas de Latex na janela de conversação +Comment[pt_BR]=Renderiza fórmulas do Latex em uma janela de bate-papo +Comment[ro]=Randează formule LaTeX în fereastra de discuţii +Comment[ru]=Вставка и вывод формул Latex в окнах разговоров Kopete +Comment[se]=Sárggo LaTeX-hámuid čáttenláses +Comment[sk]=Zobrazovanie výrazov Latex v okne rozhovoru +Comment[sl]=Izris formul LaTeX v oknu za klepet +Comment[sr]=Приказ Latex формула у прозору за ћаскање +Comment[sr@Latn]=Prikaz Latex formula u prozoru za ćaskanje +Comment[sv]=Visa Latex-formler i chattfönstret +Comment[ta]= Render Latex formulas in the chatwindow +Comment[tg]=Формулаҳои Render Latex дар тирезаи чат +Comment[tr]=Sohbet penceresindeki Latex formüllerini verir +Comment[uk]=Відтворення формул Latex у вікнах розмов Kopete +Comment[zh_CN]=在聊天窗口中渲染 Latex 公式 +Comment[zh_HK]=在聊天視窗內顯示 Latex 方程式 +Comment[zh_TW]=在聊天視窗中加入 Latex 公式 + diff --git a/kopete/plugins/latex/kopete_latex_config.desktop b/kopete/plugins/latex/kopete_latex_config.desktop new file mode 100644 index 00000000..a5e67a2a --- /dev/null +++ b/kopete/plugins/latex/kopete_latex_config.desktop @@ -0,0 +1,69 @@ +[Desktop Entry] +Icon=latex +Type=Service +ServiceTypes=KCModule + +X-KDE-ModuleType=Library +X-KDE-Library=kopete_latex +X-KDE-FactoryName=LatexConfigFactory +X-KDE-ParentApp=kopete_latex +X-KDE-ParentComponents=kopete_latex + +Name=Highlight +Name[ar]=تمييز +Name[bg]=Открояване +Name[bn]=গুরুত্বপূর্ণ +Name[br]=Splannadur +Name[bs]=Isticanje +Name[ca]=Ressaltat +Name[cs]=Zvýraznění +Name[cy]=Amlygu +Name[da]=Fremhæv +Name[de]=Hervorhebung +Name[el]=Τονισμός +Name[eo]=Lumaĵo +Name[es]=Resaltar +Name[et]=Esiletõstmine +Name[eu]=Nabarmendu +Name[fa]=مشخص +Name[fi]=Korostus +Name[fr]=Surlignement +Name[ga]=Aibhsiú +Name[gl]=Resaltar +Name[he]=מודגש +Name[hi]=उभारें +Name[hr]=Isticanje +Name[hu]=Kiemelés +Name[is]=Merkja +Name[it]=Evidenziazione +Name[ja]=強調 +Name[ka]=მარკირებული +Name[kk]=Ерекше +Name[km]=សំខាន់ +Name[lt]=Paryškinti +Name[mk]=Осветлување +Name[nb]=Marker +Name[nds]=Rutheven +Name[ne]=हाइलाइट +Name[nl]=Aanwijzen +Name[nn]=Marker +Name[pa]=ਉਘਾੜਨ +Name[pl]=Podświetlenie +Name[pt]=Realce +Name[pt_BR]=Destaque +Name[ro]=Evidenţiat +Name[ru]=Выделение +Name[se]=Merke +Name[sk]=Zvýrazniť +Name[sl]=Poudarjeno sporočilo +Name[sr]=Истицање +Name[sr@Latn]=Isticanje +Name[sv]=Markera +Name[ta]=முனைப்புறுத்தல் +Name[tg]=Равшаннамоӣ +Name[tr]=Vurgu +Name[uk]=Підсвічування +Name[wa]=E sorbiyance +Name[zh_CN]=突出显示 +Name[zh_HK]=加強顯示 +Name[zh_TW]=高亮度 diff --git a/kopete/plugins/latex/kopete_latexconvert.sh b/kopete/plugins/latex/kopete_latexconvert.sh new file mode 100755 index 00000000..b7f92263 --- /dev/null +++ b/kopete/plugins/latex/kopete_latexconvert.sh @@ -0,0 +1,234 @@ +#!/bin/sh +############################################################# +# TEX2IM: Converts LaTeX formulas to pixel graphics which # +# can be easily included in Text-Processors like # +# M$ or Staroffice. # +# # +# Required software: latex, convert (image magic) # +# to get color, the latex color package is required # +############################################################# +# Version 1.8 (http://www.nought.de/tex2im.html) # +# published under the GNU public licence (GPL) # +# (c) 14. May 2004 by Andreas Reigber # +# Email: [email protected] # +############################################################# + +# +# Default values +# + +resolution="150x150" +format="png" +color1="white" +color2="black" +trans=1 +noformula=0 +aa=1 +extra_header="$HOME/.tex2im_header" + +if [ -f ~/.tex2imrc ]; then + source ~/.tex2imrc +fi + +OPTERR=0 + +if [ $# -lt 1 ]; then + echo "Usage: `basename $0` [options] file.tex, for help give option -h" 1>&2 + exit 1 +fi + +while getopts hanzb:t:f:o:r:vx: Optionen; do + case $Optionen in + h) echo "tex2im [options] latex_expression + +The content of input file should be _plain_ latex mathmode code! +Alternatively, a string containing the latex code can be specified. + +Options: +-v show version +-h show help +-a change status of antialiasing + default is on for normal mode and + off for transparent mode +-o file specifies output filename, + default is inputfile with new extension +-f expr specifies output format, + possible examples: gif, jpg, tif...... + all formates supported by 'convert' should work, + default: png +-r expr specifies desired resolution in dpi, + possible examples: 100x100, 300x300, 200x150, + default is 150x150 +-b expr specifies the background color + default: white +-t expr specifies the text color + default: black +-n no-formula mode (do not wrap in eqnarray* environment) + default: off +-z transparent background + default: off +-x file file containing extra header lines. + default: ~/.tex2im_header" + exit 0 ;; + v) echo "TEX2IM Version 1.8" + exit 0 ;; + r) resolution=$OPTARG;; + o) outfile=$OPTARG;; + z) trans=1 + aa=0;; + a) if [ $aa -eq 0 ]; then + aa=1 + else + aa=0 + fi;; + n) noformula=1;; + b) color1=$OPTARG;; + t) color2=$OPTARG;; + f) format=$OPTARG;; + x) extra_header=$OPTARG;; + esac +done + +# +# Generate temporary directory +# + +if test -n "`type -p mktemp`" ; then + tmpdir="`mktemp /tmp/tex2imXXXXXX`" + rm $tmpdir + mkdir $tmpdir +else + tmpdir=/tmp/tex2im$$ + if [ -e $tmpdir ] ; then + echo "$0: Temporary directory $tmpdir already exists." 1>&2 + exit 1 + fi + mkdir $tmpdir +fi +homedir="`pwd`" || exit 1 + +# +# Names for input and output files +# + +while [ $OPTIND -le $# ] +do + +eval infile=\$${OPTIND} + +if [ -z $outfile ]; then + if [ -e "$infile" ]; then + base=`basename ${infile} .tex` ; + outfile=${base}.$format + else + outfile=out.$format + fi +fi + +# +# Here we go +# + +( +cat << ENDHEADER1 +\documentclass[12pt]{article} +\usepackage{color} +\usepackage[dvips]{graphicx} +\pagestyle{empty} +ENDHEADER1 +) > $tmpdir/out.tex + +# +# Do we have a file containing extra files to include into the header? +# + +if [ -f $extra_header ]; then + ( + cat $extra_header + ) >> $tmpdir/out.tex +fi + +if [ $noformula -eq 1 ]; then +( +cat << ENDHEADER2 +\pagecolor{$color1} +\begin{document} +{\color{$color2} +ENDHEADER2 +) >> $tmpdir/out.tex +else +( +cat << ENDHEADER2 +\pagecolor{$color1} +\begin{document} +{\color{$color2} +\begin{eqnarray*} +ENDHEADER2 +) >> $tmpdir/out.tex +fi + +# Kopete does not need to parse the content of a file. +#if [ -e "$infile" ]; then +# cat $infile >> $tmpdir/out.tex +#else + echo "$infile" >> $tmpdir/out.tex +#fi + +if [ $noformula -eq 1 ]; then +( +cat << ENDFOOTER +}\end{document} +ENDFOOTER +) >> $tmpdir/out.tex +else +( +cat << ENDFOOTER +\end{eqnarray*}} +\end{document} +ENDFOOTER +) >> $tmpdir/out.tex +fi + +cd $tmpdir +for f in $homedir/*.eps; do + test -f ${f##*/} || ln -s $f . # multi-processing! +done +latex -interaction=batchmode out.tex > /dev/null +cd "$homedir" +dvips -o $tmpdir/out.eps -E $tmpdir/out.dvi 2> /dev/null + +# +# Transparent background +# + +if [ $trans -eq 1 ]; then + if [ $aa -eq 1 ]; then + convert +adjoin -antialias -transparent $color1 -density $resolution $tmpdir/out.eps $tmpdir/out.$format + else + convert +adjoin +antialias -transparent $color1 -density $resolution $tmpdir/out.eps $tmpdir/out.$format + fi +else + if [ $aa -eq 1 ]; then + convert +adjoin -antialias -density $resolution $tmpdir/out.eps $tmpdir/out.$format + else + convert +adjoin +antialias -density $resolution $tmpdir/out.eps $tmpdir/out.$format + fi +fi + + +if [ -e $tmpdir/out.$format ]; then + mv $tmpdir/out.$format $outfile +else + mv $tmpdir/out.$format.0 $outfile +fi + +let OPTIND=$OPTIND+1 +outfile="" +done + +# +# Cleanup +# + +rm -rf $tmpdir +exit 0 diff --git a/kopete/plugins/latex/latexchatui.rc b/kopete/plugins/latex/latexchatui.rc new file mode 100644 index 00000000..06e8c03a --- /dev/null +++ b/kopete/plugins/latex/latexchatui.rc @@ -0,0 +1,9 @@ +<!DOCTYPE kpartgui> +<kpartgui version="1" name="kopete_latexchat"> + <MenuBar> + <Menu name="tools"> + <text>&Tools</text> + <Action name="latexPreview" /> + </Menu> + </MenuBar> +</kpartgui> diff --git a/kopete/plugins/latex/latexconfig.kcfg b/kopete/plugins/latex/latexconfig.kcfg new file mode 100644 index 00000000..f6d0b335 --- /dev/null +++ b/kopete/plugins/latex/latexconfig.kcfg @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Author: Stefan Gehn --> +<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 + http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > + <kcfgfile name="kopeterc"/> + + <group name="Latex Plugin"> + <entry name="HorizontalDPI" type="UInt"> + <label>Horizontal Rendering Resolution (DPI).</label> + <default>150</default> + </entry> + <entry name="VerticalDPI" type="UInt"> + <label>Vertical Rendering Resolution (DPI).</label> + <default>150</default> + </entry> + </group> +</kcfg> diff --git a/kopete/plugins/latex/latexconfig.kcfgc b/kopete/plugins/latex/latexconfig.kcfgc new file mode 100644 index 00000000..9e4e4fec --- /dev/null +++ b/kopete/plugins/latex/latexconfig.kcfgc @@ -0,0 +1,7 @@ +# Code generation options for kconfig_compiler +File=latexconfig.kcfg +ClassName=LatexConfig +Singleton=true +Mutators=true +MemberVariables=private +GlobalEnums=true diff --git a/kopete/plugins/latex/latexguiclient.cpp b/kopete/plugins/latex/latexguiclient.cpp new file mode 100644 index 00000000..8d7cbf3e --- /dev/null +++ b/kopete/plugins/latex/latexguiclient.cpp @@ -0,0 +1,76 @@ +/* + latexguiclient.cpp + + Kopete Latex plugin + + Copyright (c) 2003-2005 by Olivier Goffart <ogoffart @ kde.org> + + Kopete (c) 2003-2005 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <qvariant.h> + +#include <kaction.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <qimage.h> +#include <qregexp.h> +#include <qstylesheet.h> + +#include "kopetechatsession.h" +#include "kopeteview.h" +#include "kopetemessage.h" + +#include "latexplugin.h" +#include "latexguiclient.h" + +LatexGUIClient::LatexGUIClient( Kopete::ChatSession *parent, const char *name ) +: QObject( parent, name ), KXMLGUIClient( parent ) +{ + setInstance( LatexPlugin::plugin()->instance() ); + connect( LatexPlugin::plugin(), SIGNAL( destroyed( QObject * ) ), this, SLOT( deleteLater() ) ); + + m_manager = parent; + + new KAction( i18n( "Preview Latex Images" ), "latex", CTRL + Key_L, this, SLOT( slotPreview() ), actionCollection(), "latexPreview" ); + + setXMLFile( "latexchatui.rc" ); +} + +LatexGUIClient::~LatexGUIClient() +{ +} + +void LatexGUIClient::slotPreview() +{ + if ( !m_manager->view() ) + return; + + Kopete::Message msg = m_manager->view()->currentMessage(); + QString messageText = msg.plainBody(); + if(!messageText.contains("$$")) //we haven't found any latex strings + { + KMessageBox::sorry(reinterpret_cast<QWidget*>(m_manager->view()) , i18n("There are no latex in the message you are typing. The latex formula must be included between $$ and $$ "), i18n("No Latex Formula") ); + return; + } + + msg=Kopete::Message( msg.from() , msg.to() , + i18n("<b>Preview of the latex message :</b> <br />%1").arg(msg.plainBody()), + Kopete::Message::Internal , Kopete::Message::RichText); + m_manager->appendMessage(msg) ; +} + + +#include "latexguiclient.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/plugins/latex/latexguiclient.h b/kopete/plugins/latex/latexguiclient.h new file mode 100644 index 00000000..c8ca9e99 --- /dev/null +++ b/kopete/plugins/latex/latexguiclient.h @@ -0,0 +1,53 @@ +/* + latexguiclient.h + + Kopete Latex Plugin + + Copyright (c) 2005 by Olivier Goffart <ogoffart @ kde.org> + + Kopete (c) 2005 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef TRANSLATORGUICLIENT_H +#define TRANSLATORGUICLIENT_H + +#include <qobject.h> +#include <kxmlguiclient.h> + +#include <kio/job.h> + +#include "kopetemessage.h" +#include "kopeteplugin.h" + +namespace Kopete { class ChatSession; } + +/** + * @author Olivier Goffart <ogoffart @ kde.org> + */ + +class LatexGUIClient : public QObject , public KXMLGUIClient +{ + Q_OBJECT + +public: + LatexGUIClient( Kopete::ChatSession *parent, const char *name=0L); + ~LatexGUIClient(); + +private slots: + void slotPreview(); + +private: + Kopete::ChatSession *m_manager; +}; + +#endif + diff --git a/kopete/plugins/latex/latexplugin.cpp b/kopete/plugins/latex/latexplugin.cpp new file mode 100644 index 00000000..7ceab209 --- /dev/null +++ b/kopete/plugins/latex/latexplugin.cpp @@ -0,0 +1,259 @@ +/* + Kopete Latex Plugin + + Copyright (c) 2004 by Duncan Mac-Vicar Prett <[email protected]> + Copyright (c) 2004-2005 by Olivier Goffart <ogoffart@kde. org> + + Kopete (c) 2001-2004 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <qregexp.h> +#include <qimage.h> +#include <qbuffer.h> +#include <qcstring.h> +#include <qstylesheet.h> +#include <kgenericfactory.h> +#include <kdebug.h> +#include <kstandarddirs.h> +#include <kprocess.h> +#include <ktempfile.h> +#include <kmdcodec.h> +#include <kmessagebox.h> + +#include "kopetechatsessionmanager.h" +#include "kopeteuiglobal.h" + +#include "latexplugin.h" +#include "latexconfig.h" +#include "latexguiclient.h" + +#define ENCODED_IMAGE_MODE 0 + +typedef KGenericFactory<LatexPlugin> LatexPluginFactory; +K_EXPORT_COMPONENT_FACTORY( kopete_latex, LatexPluginFactory( "kopete_latex" ) ) + +LatexPlugin::LatexPlugin( QObject *parent, const char *name, const QStringList &/*args*/ ) +: Kopete::Plugin( LatexPluginFactory::instance(), parent, name ) +{ +// kdDebug() << k_funcinfo << endl; + if( !s_pluginStatic ) + s_pluginStatic = this; + + mMagickNotFoundShown = false; + connect( Kopete::ChatSessionManager::self(), SIGNAL( aboutToDisplay( Kopete::Message & ) ), SLOT( slotMessageAboutToShow( Kopete::Message & ) ) ); + connect( Kopete::ChatSessionManager::self(), SIGNAL( aboutToSend(Kopete::Message& ) ), this, SLOT(slotMessageAboutToSend(Kopete::Message& ) ) ); + connect ( this , SIGNAL( settingsChanged() ) , this , SLOT( slotSettingsChanged() ) ); + connect( Kopete::ChatSessionManager::self(), SIGNAL( chatSessionCreated( Kopete::ChatSession * ) ), + this, SLOT( slotNewChatSession( Kopete::ChatSession * ) ) ); + + m_convScript = KStandardDirs::findExe("kopete_latexconvert.sh"); + slotSettingsChanged(); + + //Add GUI action to all already existing kmm (if the plugin is launched when kopete already rining) + QValueList<Kopete::ChatSession*> sessions = Kopete::ChatSessionManager::self()->sessions(); + for (QValueListIterator<Kopete::ChatSession*> it= sessions.begin(); it!=sessions.end() ; ++it) + slotNewChatSession( *it ); +} + +LatexPlugin::~LatexPlugin() +{ + s_pluginStatic = 0L; +} + +LatexPlugin* LatexPlugin::plugin() +{ + return s_pluginStatic ; +} + +LatexPlugin* LatexPlugin::s_pluginStatic = 0L; + +void LatexPlugin::slotNewChatSession( Kopete::ChatSession *KMM ) +{ + new LatexGUIClient( KMM ); +} + + +void LatexPlugin::slotMessageAboutToShow( Kopete::Message& msg ) +{ + QString mMagick = KStandardDirs::findExe("convert"); + if ( mMagick.isEmpty() ) + { + // show just once + if ( !mMagickNotFoundShown ) + { + KMessageBox::queuedMessageBox( + Kopete::UI::Global::mainWidget(), + KMessageBox::Error, i18n("I cannot find the Magick convert program.\nconvert is required to render the Latex formulas.\nPlease go to www.imagemagick.org or to your distribution site and get the right package.") + ); + mMagickNotFoundShown = true; + } + // dont try to parse if convert is not installed + return; + } + + QString messageText = msg.plainBody(); + if( !messageText.contains("$$")) + return; + + //kdDebug() << k_funcinfo << " Using converter: " << m_convScript << endl; + + // /\[([^]]).*?\[/$1\]/ + // \$\$.+?\$\$ + + // this searches for $$formula$$ + QRegExp rg("\\$\\$.+\\$\\$"); + rg.setMinimal(true); + // this searches for [latex]formula[/latex] + //QRegExp rg("\\[([^]\]).*?\\[/$1\\]"); + + int pos = 0; + + QMap<QString, QString> replaceMap; + while (pos >= 0 && (unsigned int)pos < messageText.length()) + { +// kdDebug() << k_funcinfo << " searching pos: " << pos << endl; + pos = rg.search(messageText, pos); + + if (pos >= 0 ) + { + QString match = rg.cap(0); + pos += rg.matchedLength(); + + QString formul=match; + if(!securityCheck(formul)) + continue; + + QString fileName=handleLatex(formul.replace("$$","")); + + // get the image and encode it with base64 + #if ENCODED_IMAGE_MODE + QImage renderedImage( fileName ); + imagePxWidth = renderedImage.width(); + imagePxHeight = renderedImage.height(); + if ( !renderedImage.isNull() ) + { + QByteArray ba; + QBuffer buffer( ba ); + buffer.open( IO_WriteOnly ); + renderedImage.save( &buffer, "PNG" ); + QString imageURL = QString::fromLatin1("data:image/png;base64,%1").arg( KCodecs::base64Encode( ba ) ); + replaceMap[match] = imageURL; + } + #else + replaceMap[match] = fileName; + #endif + } + } + + if(replaceMap.isEmpty()) //we haven't found any latex strings + return; + + 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=QStyleSheet::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 +"\" /> "); + } + + msg.setBody( messageText, Kopete::Message::RichText ); +} + + +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 + KConfig *config = KGlobal::config(); + config->setGroup("Latex Plugin"); + + if(!config->readBoolEntry("ParseOutgoing", false)) + return; + + QString messageText = msg.plainBody(); + if( !messageText.contains("$$")) + return; +/* if( msg.from()->protocol()->pluginId()!="MSNProtocol" ) + return;*/ + + // this searches for $$formula$$ + QRegExp rg("^\\s*\\$\\$([^$]+)\\$\\$\\s*$"); + + if( rg.search(messageText) != -1 ) + { + QString latexFormula = rg.cap(1); + if(!securityCheck( latexFormula )) + return; + + QString url = handleLatex(latexFormula); + + + if(!url.isNull()) + { + QString escapedLATEX= QStyleSheet::escape(messageText).replace("\"","""); + QString messageText="<img src=\"" + url + "\" alt=\"" + escapedLATEX + "\" title=\"" + escapedLATEX +"\" />"; + msg.setBody( messageText, Kopete::Message::RichText ); + } + } +#endif +} + +QString LatexPlugin::handleLatex(const QString &latexFormula) +{ + KTempFile *tempFile=new KTempFile( locateLocal( "tmp", "kopetelatex-" ), ".png" ); + tempFile->setAutoDelete(true); + m_tempFiles.append(tempFile); + m_tempFiles.setAutoDelete(true); + QString fileName = tempFile->name(); + + KProcess p; + + QString argumentRes = "-r %1x%2"; + QString argumentOut = "-o %1"; + //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 ; + + kdDebug() << 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(KProcess::Block); + return fileName; +} + +bool LatexPlugin::securityCheck(const QString &latexFormula) +{ + return !latexFormula.contains(QRegExp("\\\\(def|let|futurelet|newcommand|renewcomment|else|fi|write|input|include" + "|chardef|catcode|makeatletter|noexpand|toksdef|every|errhelp|errorstopmode|scrollmode|nonstopmode|batchmode" + "|read|csname|newhelp|relax|afterground|afterassignment|expandafter|noexpand|special|command|loop|repeat|toks" + "|output|line|mathcode|name|item|section|mbox|DeclareRobustCommand)[^a-zA-Z]")); + +} + +void LatexPlugin::slotSettingsChanged() +{ + LatexConfig::self()->readConfig(); +} + +#include "latexplugin.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/plugins/latex/latexplugin.h b/kopete/plugins/latex/latexplugin.h new file mode 100644 index 00000000..a0fcd7fd --- /dev/null +++ b/kopete/plugins/latex/latexplugin.h @@ -0,0 +1,77 @@ +/* + latexplugin.h + + Kopete Latex Plugin + + Copyright (c) 2004 by Duncan Mac-Vicar Prett <[email protected]> + Copyright (c) 2004-2005 by Olivier Goffart <ogoffart@kde. org> + + Kopete (c) 2001-2004 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef LATEXPLUGIN_H +#define LATEXPLUGIN_H + +#include <qobject.h> +#include <qstring.h> + +#include <ktempfile.h> + +#include "kopetemessage.h" +#include "kopeteplugin.h" + +class QStringList; +class QString; + + +namespace Kopete { class Message; class ChatSession; } + +/** + * @author Duncan Mac-Vicar Prett + */ + +class LatexPlugin : public Kopete::Plugin +{ + Q_OBJECT + +public: + static LatexPlugin *plugin(); + + LatexPlugin( QObject *parent, const char *name, const QStringList &args ); + ~LatexPlugin(); + +public slots: + void slotSettingsChanged(); + void slotMessageAboutToShow( Kopete::Message& msg ); + void slotMessageAboutToSend( Kopete::Message& msg ); + void slotNewChatSession( Kopete::ChatSession *KMM); + +public: + /** + * gives a latex formula, and return the filename of the file where the latex is stored. + */ + QString handleLatex(const QString &latex); + + /** + * return false if the latex formula may contains malicious commands + */ + bool securityCheck(const QString & formula); + + +private: + static LatexPlugin* s_pluginStatic; + QString m_convScript; + bool mMagickNotFoundShown; + QPtrList<KTempFile> m_tempFiles; +}; + +#endif diff --git a/kopete/plugins/latex/latexpreferences.cpp b/kopete/plugins/latex/latexpreferences.cpp new file mode 100644 index 00000000..1727ae49 --- /dev/null +++ b/kopete/plugins/latex/latexpreferences.cpp @@ -0,0 +1,76 @@ +/* + Kopete Latex Plugin + + Copyright (c) 2004 by Duncan Mac-Vicar Prett <[email protected]> + + Kopete (c) 2001-2004 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <qlayout.h> +#include <kparts/componentfactory.h> +#include <klocale.h> +#include <kgenericfactory.h> +#include <kdebug.h> +#include <knuminput.h> + +#include "latexplugin.h" +#include "latexconfig.h" +#include "latexprefsbase.h" +#include "latexpreferences.h" + +typedef KGenericFactory<LatexPreferences> LatexPreferencesFactory; +K_EXPORT_COMPONENT_FACTORY( kcm_kopete_latex, LatexPreferencesFactory( "kcm_kopete_latex" ) ) + +LatexPreferences::LatexPreferences(QWidget *parent, const char* /*name*/, const QStringList &args) + : KCModule(LatexPreferencesFactory::instance(), parent, args) +{ + ( new QVBoxLayout( this ) )->setAutoAdd( true ); + m_preferencesDialog = new LatexPrefsUI(this); + // connect widget signals here + m_preferencesDialog->horizontalDPI->setMinValue(1); + m_preferencesDialog->verticalDPI->setMinValue(1); + + connect(m_preferencesDialog->horizontalDPI, SIGNAL(valueChanged(int)), this, SLOT(slotModified())); + connect(m_preferencesDialog->verticalDPI, SIGNAL(valueChanged(int)), this, SLOT(slotModified())); + + load(); +} + +LatexPreferences::~LatexPreferences() +{ +} + +void LatexPreferences::load() +{ + LatexConfig::self()->readConfig(); + // load widgets here + m_preferencesDialog->horizontalDPI->setValue(LatexConfig::self()->horizontalDPI()); + m_preferencesDialog->verticalDPI->setValue(LatexConfig::self()->verticalDPI()); + emit KCModule::changed(false); +} + +void LatexPreferences::slotModified() +{ + emit KCModule::changed(true); +} + +void LatexPreferences::save() +{ + LatexConfig::self()->setHorizontalDPI(m_preferencesDialog->horizontalDPI->value()); + LatexConfig::self()->setVerticalDPI(m_preferencesDialog->verticalDPI->value()); + LatexConfig::self()->writeConfig(); + emit KCModule::changed(false); +} + +#include "latexpreferences.moc" + +// vim: set noet ts=4 sts=4 sw=4: diff --git a/kopete/plugins/latex/latexpreferences.h b/kopete/plugins/latex/latexpreferences.h new file mode 100644 index 00000000..c08b35b5 --- /dev/null +++ b/kopete/plugins/latex/latexpreferences.h @@ -0,0 +1,48 @@ +/* + Kopete Latex Plugin + + Copyright (c) 2004 by Duncan Mac-Vicar Prett <[email protected]> + + Kopete (c) 2001-2004 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef LatexPREFERENCES_H +#define LatexPREFERENCES_H + +#include <kcmodule.h> +#include <qstring.h> + +class LatexPrefsUI; +class QListViewItem; + +/** + *@author Duncan Mac-Vicar Prett + */ + +class LatexPreferences : public KCModule +{ + Q_OBJECT +public: + + LatexPreferences(QWidget *parent = 0, const char* name = 0, const QStringList &args = QStringList()); + ~LatexPreferences(); + + virtual void save(); + virtual void load(); + +private: + LatexPrefsUI *m_preferencesDialog; +private slots: + void slotModified(); +}; + +#endif diff --git a/kopete/plugins/latex/latexprefsbase.ui b/kopete/plugins/latex/latexprefsbase.ui new file mode 100644 index 00000000..fbb11a21 --- /dev/null +++ b/kopete/plugins/latex/latexprefsbase.ui @@ -0,0 +1,168 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>LatexPrefsUI</class> +<author>Duncan Mac-Vicar</author> +<widget class="QWidget"> + <property name="name"> + <cstring>LatexPrefsUI</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>513</width> + <height>232</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="frameShape"> + <enum>Box</enum> + </property> + <property name="text"> + <string><p>The <font size="+1">KopeTeX</font> plugin allows <font size="+1">Kopet</font>e to render Latex formulas in the chat window. The sender must enclose the formula between two $ signs. ie: $$formula$$</p> +<p>This plugin requires ImageMagick convert program installed in order to work.</p></string> + </property> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>groupBox1</cstring> + </property> + <property name="title"> + <string>Options</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer row="2" column="0"> + <property name="name"> + <cstring>spacer5</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>30</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Rendering resolution (DPI):</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>280</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>horizontalDPI</cstring> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>x</string> + </property> + </widget> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>verticalDPI</cstring> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>220</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + </grid> + </widget> + <spacer> + <property name="name"> + <cstring>spacer6</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> +</includehints> +</UI> |