summaryrefslogtreecommitdiffstats
path: root/kopete/plugins/translator
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/plugins/translator
downloadtdenetwork-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/translator')
-rw-r--r--kopete/plugins/translator/Makefile.am25
-rw-r--r--kopete/plugins/translator/kopete_translator.desktop128
-rw-r--r--kopete/plugins/translator/kopete_translator_config.desktop127
-rw-r--r--kopete/plugins/translator/translatorchatui.rc9
-rw-r--r--kopete/plugins/translator/translatordialog.cpp44
-rw-r--r--kopete/plugins/translator/translatordialog.h51
-rw-r--r--kopete/plugins/translator/translatorguiclient.cpp100
-rw-r--r--kopete/plugins/translator/translatorguiclient.h63
-rw-r--r--kopete/plugins/translator/translatorlanguages.cpp101
-rw-r--r--kopete/plugins/translator/translatorlanguages.h94
-rw-r--r--kopete/plugins/translator/translatorplugin.cpp402
-rw-r--r--kopete/plugins/translator/translatorplugin.h113
-rw-r--r--kopete/plugins/translator/translatorprefs.cpp52
-rw-r--r--kopete/plugins/translator/translatorprefsbase.ui191
-rw-r--r--kopete/plugins/translator/translatorui.rc12
15 files changed, 1512 insertions, 0 deletions
diff --git a/kopete/plugins/translator/Makefile.am b/kopete/plugins/translator/Makefile.am
new file mode 100644
index 00000000..7ab367f9
--- /dev/null
+++ b/kopete/plugins/translator/Makefile.am
@@ -0,0 +1,25 @@
+METASOURCES = AUTO
+
+AM_CPPFLAGS = $(KOPETE_INCLUDES) $(all_includes)
+
+kde_module_LTLIBRARIES = kopete_translator.la kcm_kopete_translator.la
+
+kopete_translator_la_SOURCES = translatorplugin.cpp \
+ translatordialog.cpp translatorguiclient.cpp translatorlanguages.cpp
+kopete_translator_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN) $(all_libraries)
+kopete_translator_la_LIBADD = ../../libkopete/libkopete.la $(LIB_KIO)
+
+kcm_kopete_translator_la_SOURCES = translatorprefsbase.ui translatorprefs.cpp translatorlanguages.cpp
+kcm_kopete_translator_la_LDFLAGS = -module -no-undefined $(KDE_PLUGIN) $(all_libraries)
+kcm_kopete_translator_la_LIBADD = ../../libkopete/libkopete.la $(LIB_KUTILS)
+
+service_DATA = kopete_translator.desktop
+servicedir = $(kde_servicesdir)
+
+kcm_DATA = kopete_translator_config.desktop
+kcmdir = $(kde_servicesdir)/kconfiguredialog
+
+mydatadir = $(kde_datadir)/kopete_translator
+mydata_DATA = translatorui.rc translatorchatui.rc
+
+
diff --git a/kopete/plugins/translator/kopete_translator.desktop b/kopete/plugins/translator/kopete_translator.desktop
new file mode 100644
index 00000000..5da3f373
--- /dev/null
+++ b/kopete/plugins/translator/kopete_translator.desktop
@@ -0,0 +1,128 @@
+[Desktop Entry]
+Type=Service
+X-Kopete-Version=1000900
+Icon=locale
+ServiceTypes=Kopete/Plugin
+X-KDE-Library=kopete_translator
+X-KDE-PluginInfo-Author=Duncan Mac-Vicar Prett
+X-KDE-PluginInfo-Name=kopete_translator
+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=Translator
+Name[ar]=المترجم
+Name[be]=Перакладнік
+Name[bg]=Автоматичен превод
+Name[bn]=অনুবাদক
+Name[br]=Troer
+Name[bs]=Prevodilac
+Name[ca]=Traductor
+Name[cs]=Překladač
+Name[cy]=Cyfieithydd
+Name[da]=Oversætter
+Name[de]=Übersetzer
+Name[el]=Μεταφραστής
+Name[eo]=Tradukilo
+Name[es]=Traductor
+Name[et]=Tõlketeenus
+Name[eu]=Itzultzailea
+Name[fa]=مترجم
+Name[fi]=Kääntäjä
+Name[fr]=Traducteur
+Name[ga]=Aistritheoir
+Name[gl]=Traductor
+Name[he]=מתרגם
+Name[hi]=अनुवादक
+Name[hr]=Prevoditelj
+Name[hu]=Tolmács
+Name[is]=Þýðandi
+Name[it]=Traduttore
+Name[ja]=翻訳ソフト
+Name[ka]=მთარგმნელი
+Name[km]=កម្មវិធី​បកប្រែ
+Name[lt]=Vertėjas
+Name[mk]=Преведувач
+Name[nb]=Oversetter
+Name[nds]=Översetter
+Name[ne]=अनुवादक
+Name[nl]=Vertaler
+Name[nn]=Omsetjar
+Name[pa]=ਅਨੁਵਾਦ
+Name[pl]=Tłumacz
+Name[pt]=Tradutor
+Name[pt_BR]=Tradutor
+Name[ro]=Traducător
+Name[ru]=Переводчик
+Name[se]=Jorgaleaddji
+Name[sk]=Preklad
+Name[sl]=Prevajalec
+Name[sr]=Преводилац
+Name[sr@Latn]=Prevodilac
+Name[sv]=Översättning
+Name[ta]=மொழிமாற்றி
+Name[tg]=Тарҷумон
+Name[tr]=Çevirmen
+Name[uk]=Перекладач
+Name[uz]=Tarjimon
+Name[uz@cyrillic]=Таржимон
+Name[wa]=Ratournaedje
+Name[zh_CN]=翻译家
+Name[zh_HK]=翻譯者
+Name[zh_TW]=翻譯器
+Comment=Chat with foreign buddies in your native language
+Comment[ar]=تحدث مع أصدقائك اﻷجانب بلغتك اﻷم
+Comment[be]=Гутарка з замежнікамі на роднай мове
+Comment[bg]=Приставка за превод от един език на друг в реално време
+Comment[bn]=আপনার স্থানীয় ভাষাতে বিদেশী বন্ধুর সঙ্গে চ্যাট করুন
+Comment[bs]=Razgovarajte sa prijateljima iz inostranstva u vašem jeziku
+Comment[ca]=Feu un xat amb els vostres amics en la vostra llengua nativa
+Comment[cs]=Pokecejte si s cizinci ve svém rodném jazyku
+Comment[cy]=Sgwrsio â chyfeillion tramor yn eich iaith gyntaf
+Comment[da]=Chat med udenlandske venner på dit eget sprog
+Comment[de]=Chatten mit fremdsprachigen Freunden in der eigenen Muttersprache
+Comment[el]=Συνομιλήστε με ξένους φίλους στη μητρική σας γλώσσα
+Comment[es]=Charle con compañeros extranjeros en su lengua
+Comment[et]=Vestlemine välismaiste semudega enda emakeeles
+Comment[eu]=Atzerriko lagunekin zure ama-hizkuntzan hitz egin
+Comment[fa]=گپ زدن با دوستان خارجی با زبان مادریتان
+Comment[fi]=Juttele ulkomaisten kaveriesi kanssa omalla kielelläsi
+Comment[fr]=Discutez avec des étrangers dans votre langue natale
+Comment[gl]=Fala con amigos extranxeiros na túa lingua nativa
+Comment[he]=שוחח עם חברים מחו"ל בשפת האם שלך
+Comment[hi]=आपकी मातृ भाषा में विदेशी बड्डीस से गपशप करें
+Comment[hr]=Razgovo sa stranim prijateljima na vašem materinjem jeziku
+Comment[hu]=Csevegés más nyelvet beszélőkkel a saját nyelven
+Comment[is]=rabbaðu við útlenda félaga á þínu máli
+Comment[it]=Parla con un tuo amico straniero nella tua lingua
+Comment[ja]=母国語のままで他国の人とチャットする
+Comment[ka]=უცხოელ მეგობრებთან საკუთარ ენაზე საუბარი
+Comment[kk]=Шетел достарымен өз тіліңізде әңгімелесу
+Comment[km]=ជជែក​កំសាន្ត​ជាមួយ​សម្លាញ់​ជនជាតិ​បរទេស ដោយ​ប្រើ​ភាសា​កំណើត​របស់​អ្នក
+Comment[lt]=Bendraukite su bičiuliais iš užsieno gimtąja kalba
+Comment[mk]=Разговарајте со странски пријатели на вашиот мајчин јазик
+Comment[nb]=Snakk med utenlandske venner på ditt eget språk
+Comment[nds]=Klöön in Dien Moderspraak mit frömdspreken Frünnen
+Comment[ne]=तपाईँको मातृ भाषामा विदेशी साथीसँग कुराकानी गर्नुहोस्
+Comment[nl]=Praat met vrienden uit andere landen in uw eigen taal
+Comment[nn]=Prat med utanlandske venner på ditt eige språk
+Comment[pl]=Umożliwia rozmowę z zagranicznymi znajomymi w Twoim macierzystym języku
+Comment[pt]=Converse com amigos estrangeiros na sua língua nativa
+Comment[pt_BR]=Conversa com colegas estrangeiros em seu idioma nativo
+Comment[ru]=Позволяет говорить с иностранцами на вашем родном языке
+Comment[se]=Čátte olgoriikkalaš ustibiiguin iežat gillii
+Comment[sk]=Rozprávajte sa s vašimi priateľmi v cudzine v inom jazyku
+Comment[sl]=Klepetajte s prijatelji iz tujine v svojem domačem jeziku
+Comment[sr]=Ћаскајте са вашим другарима странцима на вашем матерњем језику
+Comment[sr@Latn]=Ćaskajte sa vašim drugarima strancima na vašem maternjem jeziku
+Comment[sv]=Chatta med utländska kompisar på ditt modersmål
+Comment[ta]=வெளிநாட்டு நபருடன் உங்கள் சொந்த மொழியில் அரட்டை அடிக்க முடியும்
+Comment[tg]=Чат бо дӯстони хориҷӣ дар забони модарии шумо
+Comment[tr]=Anadilinizdeki arkadaşlarla sohbet edin
+Comment[uk]=Розмова з іноземними друзями на вашій рідній мові
+Comment[zh_CN]=以您的母语与外国朋友聊天
+Comment[zh_HK]=以您的母語和外地的伙伴聊天
+Comment[zh_TW]=用您的母語跟外國朋友聊天
diff --git a/kopete/plugins/translator/kopete_translator_config.desktop b/kopete/plugins/translator/kopete_translator_config.desktop
new file mode 100644
index 00000000..288709c4
--- /dev/null
+++ b/kopete/plugins/translator/kopete_translator_config.desktop
@@ -0,0 +1,127 @@
+[Desktop Entry]
+Icon=locale
+Type=Service
+ServiceTypes=KCModule
+
+X-KDE-ModuleType=Library
+X-KDE-Library=kopete_translator
+X-KDE-FactoryName=TranslatorConfigFactory
+X-KDE-ParentApp=kopete_translator
+X-KDE-ParentComponents=kopete_translator
+
+Name=Translator
+Name[ar]=المترجم
+Name[be]=Перакладнік
+Name[bg]=Автоматичен превод
+Name[bn]=অনুবাদক
+Name[br]=Troer
+Name[bs]=Prevodilac
+Name[ca]=Traductor
+Name[cs]=Překladač
+Name[cy]=Cyfieithydd
+Name[da]=Oversætter
+Name[de]=Übersetzer
+Name[el]=Μεταφραστής
+Name[eo]=Tradukilo
+Name[es]=Traductor
+Name[et]=Tõlketeenus
+Name[eu]=Itzultzailea
+Name[fa]=مترجم
+Name[fi]=Kääntäjä
+Name[fr]=Traducteur
+Name[ga]=Aistritheoir
+Name[gl]=Traductor
+Name[he]=מתרגם
+Name[hi]=अनुवादक
+Name[hr]=Prevoditelj
+Name[hu]=Tolmács
+Name[is]=Þýðandi
+Name[it]=Traduttore
+Name[ja]=翻訳ソフト
+Name[ka]=მთარგმნელი
+Name[km]=កម្មវិធី​បកប្រែ
+Name[lt]=Vertėjas
+Name[mk]=Преведувач
+Name[nb]=Oversetter
+Name[nds]=Översetter
+Name[ne]=अनुवादक
+Name[nl]=Vertaler
+Name[nn]=Omsetjar
+Name[pa]=ਅਨੁਵਾਦ
+Name[pl]=Tłumacz
+Name[pt]=Tradutor
+Name[pt_BR]=Tradutor
+Name[ro]=Traducător
+Name[ru]=Переводчик
+Name[se]=Jorgaleaddji
+Name[sk]=Preklad
+Name[sl]=Prevajalec
+Name[sr]=Преводилац
+Name[sr@Latn]=Prevodilac
+Name[sv]=Översättning
+Name[ta]=மொழிமாற்றி
+Name[tg]=Тарҷумон
+Name[tr]=Çevirmen
+Name[uk]=Перекладач
+Name[uz]=Tarjimon
+Name[uz@cyrillic]=Таржимон
+Name[wa]=Ratournaedje
+Name[zh_CN]=翻译家
+Name[zh_HK]=翻譯者
+Name[zh_TW]=翻譯器
+Comment=Translates messages from your native language to another language
+Comment[ar]=يترجم رسائل من لغتك اﻷم إلى لغة أخرى
+Comment[be]=Перакладае паведамленні з роднай мовы на замежныя
+Comment[bg]=Приставка за превод от един език на друг в реално време
+Comment[bn]=আপনার স্থানীয় ভাষা থেকে অন্য একটি ভাষাতে বার্তা অনুবাদ করে
+Comment[bs]=Prevodi poruke iz vašeg maternjeg jezika u neki drugi
+Comment[ca]=Tradueix els missatges des del vostre idioma natiu cap a un altre
+Comment[cs]=Překládá zprávy z vašeho rodného jazyka do jiného
+Comment[cy]=Cyfieithu negeseuon o'ch iaith gyntaf i iaith arall
+Comment[da]=Oversætter beskeder fra dit indfødte sprog til et andet sprog
+Comment[de]=Übersetzt Nachrichten von der eigenen in eine fremde Sprache
+Comment[el]=Μεταφράζει μηνύματα από τη μητρική σας γλώσσα σε μια άλλη
+Comment[es]=Traduce mensajes de su lengua a otra
+Comment[et]=Tõlgib sõnumid sinu emakeelest mingisse muusse keelde
+Comment[eu]=Mezuak zure ama-hizkuntzatik beste hizkuntzara itzultzen ditu
+Comment[fa]=ترجمۀ پیامهایی با زبان مادری شما به زبانهای دیگر
+Comment[fi]=Kääntää viestit omasta kielestä toiseen kieleen
+Comment[fr]=Traduit les messages de votre langue natale en une autre langue
+Comment[ga]=Aistríonn seo teachtaireachtaí ó do theanga dúchais go teanga eile
+Comment[gl]=Traduce as túas mensaxes da túa lingua nativa a outra
+Comment[he]=מתרגם את מסריך משפת האם שלך לשפה אחרת
+Comment[hi]=आपकी मातृ भाषा के संदेशों को अन्य भाषा में अनुवाद करे
+Comment[hr]=Prevodi poruke s vašeg maternjeg jezika na neki drugi
+Comment[hu]=Az üzenetek lefordítása a saját nyelvről egy idegen nyelvre
+Comment[is]=Þýðir skeyti úr þinni tungu yfir í annað
+Comment[it]=Traduci messaggi dalla tua lingua in un'altra
+Comment[ja]=母国語から他の言語にメッセージを翻訳する
+Comment[ka]=შეტყობინებებს თარგმნის თქვენი მშობლიური ენიდან სხვა ენაზე
+Comment[kk]=Хабарларды бір тілден басқа тілге аудару
+Comment[km]=បកប្រែ​សារ​ពី​ភាសា​កំណើត​របស់​អ្នក​ទៅ​ជា​ភាសា​មួយ​ទៀត
+Comment[lt]=Verčia žinutes iš gimtosios kalbos į užsienio kalbas
+Comment[mk]=Ги преведува пораките од вашиот мајчин јазик на друг јазик
+Comment[nb]=Oversetter meldinger fra ditt eget språk til et annet
+Comment[nds]=Översett Narichten vun Dien Moderspraak na anner Spraken
+Comment[ne]=तपाईँ मातृ भाषाबाट अर्को भाषामा सन्देश अनुवाद गर्दछ
+Comment[nl]=Vertaalt berichten van uw eigen taal naar een andere taal
+Comment[nn]=Set om meldingar frå ditt eige språk til eit anna
+Comment[pl]=Tłumaczy wiadomości z Twojego języka na inny
+Comment[pt]=Traduz as mensagens da sua língua nativa para outra língua
+Comment[pt_BR]=Traduz mensagens de seu idioma nativo para outro idioma
+Comment[ru]=Переводит сообщение с вашего родного языка на язык вашего собеседника
+Comment[se]=Jorgala dieđáhusaid du gielas muhton eará gillii
+Comment[sk]=Prekladá správy z jedného jazyka do iného
+Comment[sl]=Prevede sporočila iz vašega domačega jezika v drugi jezik
+Comment[sr]=Преводи поруке са вашег матерњег језика на неки други
+Comment[sr@Latn]=Prevodi poruke sa vašeg maternjeg jezika na neki drugi
+Comment[sv]=Översätt meddelanden från ditt modersmål till ett annat språk
+Comment[ta]=உங்கள் மொழியிலிருந்து வேறு மொழிக்கு மொழிபெயர்
+Comment[tg]=Пайёмҳоро аз забони модарии шумо ба дигар забонҳо тарҷума мекунад
+Comment[tr]=Diğer dillerden ana dilinize çevrilen mesajlar
+Comment[uk]=Перекладає повідомлення з вашої рідної мови на якусь іншу мову
+Comment[zh_CN]=将消息从您的母语翻译成其它语言
+Comment[zh_HK]=將您母語的訊息翻譯為另一種語言
+Comment[zh_TW]=將訊息從您的母語翻成其他語言
+
+
diff --git a/kopete/plugins/translator/translatorchatui.rc b/kopete/plugins/translator/translatorchatui.rc
new file mode 100644
index 00000000..7dc86e2c
--- /dev/null
+++ b/kopete/plugins/translator/translatorchatui.rc
@@ -0,0 +1,9 @@
+<!DOCTYPE kpartgui>
+<kpartgui version="1" name="kopete_translatorchat">
+ <MenuBar>
+ <Menu name="tools">
+ <text>&amp;Tools</text>
+ <Action name="translateCurrentMessage" />
+ </Menu>
+ </MenuBar>
+</kpartgui>
diff --git a/kopete/plugins/translator/translatordialog.cpp b/kopete/plugins/translator/translatordialog.cpp
new file mode 100644
index 00000000..c03921fc
--- /dev/null
+++ b/kopete/plugins/translator/translatordialog.cpp
@@ -0,0 +1,44 @@
+/***************************************************************************
+ translatordialog.cpp - description
+ -------------------
+ begin : sam oct 19 2002
+ copyright : (C) 2002 by Olivier Goffart
+ email : ogoffart @ kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 <klocale.h>
+#include <ktextedit.h>
+
+#include "translatordialog.h"
+
+
+TranslatorDialog::TranslatorDialog(const QString &text,QWidget *parent, const char *name ) : KDialogBase(parent,name,true,i18n("Translator Plugin"), Ok)
+{
+ m_textEdit=new KTextEdit(this);
+ setMainWidget(m_textEdit);
+ m_textEdit->setText(text);
+}
+TranslatorDialog::~TranslatorDialog()
+{
+}
+
+QString TranslatorDialog::translatedText()
+{
+ return m_textEdit->text();
+}
+/*void TranslatorDialog::slotFinished()
+{
+ emit finished(m_textEdit->text());
+} */
+
+
+#include "translatordialog.moc"
diff --git a/kopete/plugins/translator/translatordialog.h b/kopete/plugins/translator/translatordialog.h
new file mode 100644
index 00000000..70fd46c0
--- /dev/null
+++ b/kopete/plugins/translator/translatordialog.h
@@ -0,0 +1,51 @@
+/***************************************************************************
+ translatordialog.h - description
+ -------------------
+ begin : sam oct 19 2002
+ copyright : (C) 2002 by Olivier Goffart
+ email : ogoffart @ kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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 TRANSLATORDIALOG_H
+#define TRANSLATORDIALOG_H
+
+#include <qwidget.h>
+#include <kdialogbase.h>
+
+//#include <kopetemessage.h>
+
+class KTextEdit;
+
+/**
+ * @author Olivier Goffart
+ */
+class TranslatorDialog : public KDialogBase
+{
+ Q_OBJECT
+
+public:
+ TranslatorDialog(const QString &translated, QWidget *parent=0, const char *name=0);
+ ~TranslatorDialog();
+
+ QString translatedText();
+
+private:
+ KTextEdit *m_textEdit;
+
+private slots: // Public slots
+// void slotFinished();
+};
+
+#endif
+
+// vim: set noet ts=4 sts=4 sw=4:
+
diff --git a/kopete/plugins/translator/translatorguiclient.cpp b/kopete/plugins/translator/translatorguiclient.cpp
new file mode 100644
index 00000000..ae175f41
--- /dev/null
+++ b/kopete/plugins/translator/translatorguiclient.cpp
@@ -0,0 +1,100 @@
+/*
+ translatorguiclient.cpp
+
+ Kopete Translator plugin
+
+ Copyright (c) 2003-2004 by Olivier Goffart <ogoffart @ kde.org>
+
+ Kopete (c) 2003-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 <qvariant.h>
+
+#include <kdebug.h>
+#include <kaction.h>
+#include <klocale.h>
+
+#include "kopetemessagemanager.h"
+#include "kopeteview.h"
+#include "kopetecontact.h"
+#include "kopetemetacontact.h"
+#include "kopetemessage.h"
+
+#include "translatorplugin.h"
+#include "translatorguiclient.h"
+#include "translatorlanguages.h"
+
+TranslatorGUIClient::TranslatorGUIClient( Kopete::ChatSession *parent, const char *name )
+: QObject( parent, name ), KXMLGUIClient( parent )
+{
+ setInstance( TranslatorPlugin::plugin()->instance() );
+ connect( TranslatorPlugin::plugin(), SIGNAL( destroyed( QObject * ) ), this, SLOT( deleteLater() ) );
+
+ m_manager = parent;
+
+ new KAction( i18n( "Translate" ), "locale", CTRL + Key_T, this, SLOT( slotTranslateChat() ), actionCollection(), "translateCurrentMessage" );
+
+ setXMLFile( "translatorchatui.rc" );
+}
+
+TranslatorGUIClient::~TranslatorGUIClient()
+{
+}
+
+void TranslatorGUIClient::slotTranslateChat()
+{
+ if ( !m_manager->view() )
+ return;
+
+ Kopete::Message msg = m_manager->view()->currentMessage();
+ QString body = msg.plainBody();
+ if ( body.isEmpty() )
+ return;
+
+ QString src_lang = TranslatorPlugin::plugin()->m_myLang;
+ QString dst_lang;
+
+ QPtrList<Kopete::Contact> list = m_manager->members();
+ Kopete::MetaContact *to = list.first()->metaContact();
+ dst_lang = to->pluginData( TranslatorPlugin::plugin(), "languageKey" );
+ if ( dst_lang.isEmpty() || dst_lang == "null" )
+ {
+ kdDebug( 14308 ) << k_funcinfo << "Cannot determine dst Metacontact language (" << to->displayName() << ")" << endl;
+ return;
+ }
+
+ // We search for src_dst
+ TranslatorPlugin::plugin()->translateMessage( body, src_lang, dst_lang, this, SLOT( messageTranslated( const QVariant & ) ) );
+}
+
+void TranslatorGUIClient::messageTranslated( const QVariant &result )
+{
+ QString translated = result.toString();
+ if ( translated.isEmpty() )
+ {
+ kdDebug( 14308 ) << k_funcinfo << "Empty string returned" << endl;
+ return;
+ }
+
+ //if the user close the window before the translation arrive, return
+ if ( !m_manager->view() )
+ return;
+
+ Kopete::Message msg = m_manager->view()->currentMessage();
+ msg.setBody( translated );
+ m_manager->view()->setCurrentMessage( msg );
+}
+
+#include "translatorguiclient.moc"
+
+// vim: set noet ts=4 sts=4 sw=4:
+
diff --git a/kopete/plugins/translator/translatorguiclient.h b/kopete/plugins/translator/translatorguiclient.h
new file mode 100644
index 00000000..32ff015f
--- /dev/null
+++ b/kopete/plugins/translator/translatorguiclient.h
@@ -0,0 +1,63 @@
+/*
+ translatorguiclient.h
+
+ Kopete Translator Plugin
+
+ Copyright (c) 2003 by Olivier Goffart <ogoffart @ kde.org>
+
+ Kopete (c) 2003 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 TranslatorGUIClient : public QObject , public KXMLGUIClient
+{
+ Q_OBJECT
+
+public:
+ TranslatorGUIClient( Kopete::ChatSession *parent, const char *name=0L);
+ ~TranslatorGUIClient();
+
+private slots:
+ void slotTranslateChat();
+ void messageTranslated(const QVariant&);
+
+private:
+ Kopete::ChatSession *m_manager;
+};
+
+#endif
+
+/*
+ * Local variables:
+ * c-indentation-style: k&r
+ * c-basic-offset: 8
+ * indent-tabs-mode: t
+ * End:
+ */
+// vim: set noet ts=4 sts=4 sw=4:
+
diff --git a/kopete/plugins/translator/translatorlanguages.cpp b/kopete/plugins/translator/translatorlanguages.cpp
new file mode 100644
index 00000000..4e59fa79
--- /dev/null
+++ b/kopete/plugins/translator/translatorlanguages.cpp
@@ -0,0 +1,101 @@
+/*
+ translatorlanguages.cpp
+
+ Kopete Translatorfish Translator plugin
+
+ Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <[email protected]>
+ Copyright (c) 2002-2003 by Olivier Goffart <ogoffart @ kde.org>
+ Copyright (c) 2003 by Matt Rogers <[email protected]>
+
+ Kopete (c) 2002-2003 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 <qstring.h>
+#include <qmap.h>
+#include <klocale.h>
+
+#include "translatorlanguages.h"
+
+TranslatorLanguages::TranslatorLanguages()
+{
+ m_lc = 0;
+ m_sc = 0;
+ m_services.insert("babelfish", "BabelFish");
+ m_services.insert("google", "Google");
+
+ m_langs.insert("null", i18n("Unknown"));
+ m_langs.insert("en", i18n("English"));
+ m_langs.insert("zh", i18n("Chinese"));
+ m_langs.insert("fr", i18n("French"));
+ m_langs.insert("de", i18n("German"));
+ m_langs.insert("it", i18n("Italian"));
+ m_langs.insert("ja", i18n("Japanese"));
+ m_langs.insert("ko", i18n("Korean"));
+ m_langs.insert("pt", i18n("Portuguese"));
+ m_langs.insert("ru", i18n("Russian"));
+ m_langs.insert("es", i18n("Spanish"));
+
+ /* English to .. */
+ m_supported["babelfish"].append("en_zh");
+ m_supported["babelfish"].append("en_fr");
+ m_supported["babelfish"].append("en_de");
+ m_supported["babelfish"].append("en_it");
+ m_supported["babelfish"].append("en_ja");
+ m_supported["babelfish"].append("en_ko");
+ m_supported["babelfish"].append("en_pt");
+ m_supported["babelfish"].append("en_es");
+ /* Chinese to .. */
+ m_supported["babelfish"].append("zh_en");
+ /* French to ... */
+ m_supported["babelfish"].append("fr_en");
+ m_supported["babelfish"].append("fr_de");
+ /* German to ... */
+ m_supported["babelfish"].append("de_en");
+ m_supported["babelfish"].append("de_fr");
+
+ m_supported["babelfish"].append("it_en");
+ m_supported["babelfish"].append("ja_en");
+ m_supported["babelfish"].append("ko_en");
+ m_supported["babelfish"].append("pt_en");
+ m_supported["babelfish"].append("ru_en");
+ m_supported["babelfish"].append("es_en");
+
+ /* Google Service */
+ m_supported["google"].append("en_de");
+ m_supported["google"].append("en_es");
+ m_supported["google"].append("en_fr");
+ m_supported["google"].append("en_it");
+ m_supported["google"].append("en_pt");
+ m_supported["google"].append("de_en");
+ m_supported["google"].append("de_fr");
+ m_supported["google"].append("es_en");
+ m_supported["google"].append("fr_en");
+ m_supported["google"].append("fr_de");
+ m_supported["google"].append("it_en");
+ m_supported["google"].append("pt_en");
+
+ QMap<QString,QString>::ConstIterator i;
+
+ for ( i = m_langs.begin(); i != m_langs.end() ; ++i )
+ {
+ m_langIntKeyMap[m_lc] = i.key();
+ m_langKeyIntMap[i.key()] = m_lc;
+ m_lc++;
+ }
+
+ for ( i = m_services.begin(); i != m_services.end() ; ++i )
+ {
+ m_servicesIntKeyMap[m_sc] = i.key();
+ m_servicesKeyIntMap[i.key()] = m_sc;
+ m_sc++;
+ }
+}
diff --git a/kopete/plugins/translator/translatorlanguages.h b/kopete/plugins/translator/translatorlanguages.h
new file mode 100644
index 00000000..cbd6385f
--- /dev/null
+++ b/kopete/plugins/translator/translatorlanguages.h
@@ -0,0 +1,94 @@
+/*
+ translatorlanguages.h
+
+ Kopete Translatorfish Translator plugin
+
+ Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <[email protected]>
+ Copyright (c) 2002-2003 by Olivier Goffart <ogoffart @ kde.org>
+ Copyright (c) 2003 by Matt Rogers <[email protected]>
+
+ Kopete (c) 2002-2003 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 TRANSLATORLANGUAGES_H_
+#define TRANSLATORLANGUAGES_H_
+
+#include <qmap.h>
+#include <qstringlist.h>
+
+class QString;
+
+
+class TranslatorLanguages
+{
+public:
+ TranslatorLanguages();
+
+ /***************************************************************************
+ * Language APIs *
+ ***************************************************************************/
+
+ const QString& languageName( const QString &key )
+ { return m_langs[key]; };
+
+ const int languageIndex ( const QString &key )
+ { return m_langKeyIntMap[key]; };
+
+ const QString& languageKey( const int index )
+ { return m_langIntKeyMap[index]; };
+
+ const QMap<QString,QString>& languagesMap()
+ { return m_langs; };
+
+ const QMap<QString,QString>& servicesMap()
+ { return m_services; };
+
+ const QStringList& supported( const QString &servicekey )
+ { return m_supported[servicekey]; };
+
+ const int serviceIndex ( const QString &key )
+ { return m_servicesKeyIntMap[key]; };
+
+ const QString& serviceKey( const int index )
+ { return m_servicesIntKeyMap[index]; };
+
+ int numLanguages() { return m_lc; };
+
+ int numServices() { return m_sc; };
+
+private:
+
+ /* Known Languages key -> desc ie: en -> English */
+ QMap< QString, QString> m_langs;
+
+ /* Known Services key -> desc ie: en -> English */
+ QMap< QString, QString> m_services;
+
+ /* Supported translations per service, src_dst format ( ie: en_es )*/
+ QMap< QString, QStringList > m_supported;
+
+ /* int to lang key and viceversa*/
+ QMap<int, QString> m_langIntKeyMap;
+ QMap<QString, int> m_langKeyIntMap;
+
+ /* int to services key and viceversa*/
+ QMap<int, QString> m_servicesIntKeyMap;
+ QMap<QString, int> m_servicesKeyIntMap;
+
+ /* Lang counter */
+ int m_lc;
+ /* Service counter */
+ int m_sc;
+
+};
+
+#endif
diff --git a/kopete/plugins/translator/translatorplugin.cpp b/kopete/plugins/translator/translatorplugin.cpp
new file mode 100644
index 00000000..694f0bd1
--- /dev/null
+++ b/kopete/plugins/translator/translatorplugin.cpp
@@ -0,0 +1,402 @@
+/*
+ translatorplugin.cpp
+
+ Kopete Translator plugin
+
+ Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <[email protected]>
+ Copyright (c) 2002-2004 by Olivier Goffart <ogoffart @ kde.org>
+
+ Kopete (c) 2002-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 <qapplication.h>
+#include <qregexp.h>
+#include <qsignal.h>
+#include <qstring.h>
+
+#include <kdebug.h>
+#include <kaction.h>
+#include <kgenericfactory.h>
+#include <kglobal.h>
+#include <kconfig.h>
+#include <kdeversion.h>
+#include <kaboutdata.h>
+
+#include "kopetemetacontact.h"
+#include "kopetecontactlist.h"
+#include "kopetemessagemanagerfactory.h"
+#include "kopetecontact.h"
+
+#include "translatorplugin.h"
+#include "translatordialog.h"
+#include "translatorguiclient.h"
+#include "translatorlanguages.h"
+
+typedef KGenericFactory<TranslatorPlugin> TranslatorPluginFactory;
+#if KDE_IS_VERSION(3,2,90)
+static const KAboutData aboutdata("kopete_translator", I18N_NOOP("Translator") , "1.0" );
+K_EXPORT_COMPONENT_FACTORY( kopete_translator, TranslatorPluginFactory( &aboutdata ) )
+#else
+K_EXPORT_COMPONENT_FACTORY( kopete_translator, TranslatorPluginFactory( "kopete_translator" ) )
+#endif
+
+TranslatorPlugin::TranslatorPlugin( QObject *parent, const char *name, const QStringList & /* args */ )
+: Kopete::Plugin( TranslatorPluginFactory::instance(), parent, name )
+{
+ kdDebug( 14308 ) << k_funcinfo << endl;
+
+
+ if ( pluginStatic_ )
+ kdWarning( 14308 ) << k_funcinfo << "Translator already initialized" << endl;
+ else
+ pluginStatic_ = this;
+
+ m_languages = new TranslatorLanguages;
+
+ connect( Kopete::ChatSessionManager::self(), SIGNAL( aboutToDisplay( Kopete::Message & ) ),
+ this, SLOT( slotIncomingMessage( Kopete::Message & ) ) );
+ connect( Kopete::ChatSessionManager::self(), SIGNAL( aboutToSend( Kopete::Message & ) ),
+ this, SLOT( slotOutgoingMessage( Kopete::Message & ) ) );
+ connect( Kopete::ChatSessionManager::self(), SIGNAL( chatSessionCreated( Kopete::ChatSession * ) ),
+ this, SLOT( slotNewKMM( Kopete::ChatSession * ) ) );
+
+ QStringList keys;
+ QMap<QString, QString> m = m_languages->languagesMap();
+ for ( int k = 0; k <= m_languages->numLanguages(); k++ )
+ keys << m[ m_languages->languageKey( k ) ];
+
+ m_actionLanguage = new KSelectAction( i18n( "Set &Language" ), "locale", 0, actionCollection(), "contactLanguage" );
+ m_actionLanguage->setItems( keys );
+ connect( m_actionLanguage, SIGNAL( activated() ), this, SLOT(slotSetLanguage() ) );
+ connect( Kopete::ContactList::self(), SIGNAL( metaContactSelected( bool ) ), this, SLOT( slotSelectionChanged( bool ) ) );
+
+ setXMLFile( "translatorui.rc" );
+
+ //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)
+ slotNewKMM( *it );
+
+ loadSettings();
+ connect( this, SIGNAL( settingsChanged() ), this, SLOT( loadSettings() ) );
+}
+
+TranslatorPlugin::~TranslatorPlugin()
+{
+ kdDebug( 14308 ) << k_funcinfo << endl;
+ pluginStatic_ = 0L;
+}
+
+TranslatorPlugin* TranslatorPlugin::plugin()
+{
+ return pluginStatic_;
+}
+
+TranslatorPlugin* TranslatorPlugin::pluginStatic_ = 0L;
+
+void TranslatorPlugin::loadSettings()
+{
+ KConfig *config = KGlobal::config();
+ int mode = 0;
+
+ config->setGroup( "Translator Plugin" );
+ m_myLang = m_languages->languageKey( config->readNumEntry( "myLang" , 0 ) );
+ m_service = m_languages->serviceKey( config->readNumEntry( "Service", 0 ) );
+
+ if ( config->readBoolEntry( "IncomingDontTranslate", true ) )
+ mode = 0;
+ else if ( config->readBoolEntry( "IncomingShowOriginal", false ) )
+ mode = 1;
+ else if ( config->readBoolEntry( "IncomingTranslate", false ) )
+ mode = 2;
+
+ m_incomingMode = mode;
+
+ if ( config->readBoolEntry( "OutgoingDontTranslate", true ) )
+ mode = 0;
+ else if ( config->readBoolEntry( "OutgoingShowOriginal", false ) )
+ mode = 1;
+ else if ( config->readBoolEntry( "OutgoingTranslate", false ) )
+ mode = 2;
+ else if ( config->readBoolEntry( "OutgoingAsk", false ) )
+ mode = 3;
+
+ m_outgoingMode = mode;
+}
+
+void TranslatorPlugin::slotSelectionChanged( bool b )
+{
+ m_actionLanguage->setEnabled( b );
+
+ if ( !b )
+ return;
+
+ Kopete::MetaContact *m = Kopete::ContactList::self()->selectedMetaContacts().first();
+
+ if( !m )
+ return;
+
+ QString languageKey = m->pluginData( this, "languageKey" );
+ if ( !languageKey.isEmpty() && languageKey != "null" )
+ m_actionLanguage->setCurrentItem( m_languages->languageIndex( languageKey ) );
+ else
+ m_actionLanguage->setCurrentItem( m_languages->languageIndex( "null" ) );
+}
+
+void TranslatorPlugin::slotNewKMM( Kopete::ChatSession *KMM )
+{
+ new TranslatorGUIClient( KMM );
+}
+
+void TranslatorPlugin::slotIncomingMessage( Kopete::Message &msg )
+{
+ if ( m_incomingMode == DontTranslate )
+ return;
+
+ QString src_lang;
+ QString dst_lang;
+
+ if ( ( msg.direction() == Kopete::Message::Inbound ) && !msg.plainBody().isEmpty() )
+ {
+ Kopete::MetaContact *from = msg.from()->metaContact();
+ if ( !from )
+ {
+// kdDebug( 14308 ) << k_funcinfo << "No metaContact for source contact" << endl;
+ return;
+ }
+ src_lang = from->pluginData( this, "languageKey" );
+ if( src_lang.isEmpty() || src_lang == "null" )
+ {
+// kdDebug( 14308 ) << k_funcinfo << "Cannot determine src Metacontact language (" << from->displayName() << ")" << endl;
+ return;
+ }
+
+ dst_lang = m_myLang;
+
+ sendTranslation( msg, translateMessage( msg.plainBody(), src_lang, dst_lang ) );
+ }
+}
+
+void TranslatorPlugin::slotOutgoingMessage( Kopete::Message &msg )
+{
+ if ( m_outgoingMode == DontTranslate )
+ return;
+
+ QString src_lang;
+ QString dst_lang;
+
+ if ( ( msg.direction() == Kopete::Message::Outbound ) && ( !msg.plainBody().isEmpty() ) )
+ {
+ src_lang = m_myLang;
+
+ // Sad, we have to consider only the first To: metacontact
+ Kopete::MetaContact *to = msg.to().first()->metaContact();
+ if ( !to )
+ {
+// kdDebug( 14308 ) << k_funcinfo << "No metaContact for first contact" << endl;
+ return;
+ }
+ dst_lang = to->pluginData( this, "languageKey" );
+ if ( dst_lang.isEmpty() || dst_lang == "null" )
+ {
+// kdDebug( 14308 ) << k_funcinfo << "Cannot determine dst Metacontact language (" << to->displayName() << ")" << endl;
+ return;
+ }
+
+ sendTranslation( msg, translateMessage( msg.plainBody(), src_lang, dst_lang ) );
+ }
+}
+
+void TranslatorPlugin::translateMessage( const QString &msg, const QString &from, const QString &to, QObject *obj, const char* slot )
+{
+ QSignal completeSignal;
+ completeSignal.connect( obj, slot );
+
+ QString result = translateMessage( msg, from, to );
+
+ if(!result.isNull())
+ {
+ completeSignal.setValue( result );
+ completeSignal.activate();
+ }
+}
+
+QString TranslatorPlugin::translateMessage( const QString &msg, const QString &from, const QString &to )
+{
+ if ( from == to )
+ {
+ kdDebug( 14308 ) << k_funcinfo << "Src and Dst languages are the same" << endl;
+ return QString::null;
+ }
+
+ // We search for src_dst
+ if(! m_languages->supported( m_service ).contains( from + "_" + to ) )
+ {
+ kdDebug( 14308 ) << k_funcinfo << from << "_" << to << " is not supported by service " << m_service << endl;
+ return QString::null;
+ }
+
+
+ if ( m_service == "babelfish" )
+ return babelTranslateMessage( msg ,from, to );
+ else if ( m_service == "google" )
+ return googleTranslateMessage( msg ,from, to );
+ else
+ return QString::null;
+}
+
+QString TranslatorPlugin::googleTranslateMessage( const QString &msg, const QString &from, const QString &to )
+{
+ KURL translatorURL ( "http://translate.google.com/translate_t");
+
+ QString body = KURL::encode_string( msg );
+ QString lp = from + "|" + to;
+
+ QCString postData = QString( "text=" + body + "&langpair=" + lp ).utf8();
+
+ QString gurl = "http://translate.google.com/translate_t?text=" + body +"&langpair=" + lp;
+ kdDebug(14308) << k_funcinfo << " URL: " << gurl << endl;
+ KURL geturl ( gurl );
+
+ KIO::TransferJob *job = KIO::get( geturl, false, true );
+ //job = KIO::http_post( translatorURL, postData, true );
+
+ //job->addMetaData( "content-type", "application/x-www-form-urlencoded" );
+ //job->addMetaData( "referrer", "http://www.google.com" );
+
+ QObject::connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ), this, SLOT( slotDataReceived( KIO::Job *, const QByteArray & ) ) );
+ QObject::connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotJobDone( KIO::Job * ) ) );
+
+ // KIO is async and we use a sync API, so use the processEvents hack to work around that
+ // FIXME: We need to make the libkopete API async to get rid of this processEvents.
+ // It often causes crashes in the code. - Martijn
+ while ( !m_completed[ job ] )
+ qApp->processEvents();
+
+ QString data = QString::fromLatin1( m_data[ job ] );
+
+ // After hacks, we need to clean
+ m_data.remove( job );
+ m_completed.remove( job );
+
+// kdDebug( 14308 ) << k_funcinfo << "Google response:"<< endl << data << endl;
+
+ QRegExp re( "<textarea name=q rows=5 cols=45 wrap=PHYSICAL>(.*)</textarea>" );
+ re.setMinimal( true );
+ re.search( data );
+
+ return re.cap( 1 );
+}
+
+QString TranslatorPlugin::babelTranslateMessage( const QString &msg, const QString &from, const QString &to )
+{
+ QString body = KURL::encode_string( msg);
+ QString lp = from + "_" + to;
+ QString gurl = "http://babelfish.altavista.com/babelfish/tr?enc=utf8&doit=done&tt=urltext&urltext=" + body + "&lp=" + lp;
+ KURL geturl ( gurl );
+
+ kdDebug( 14308 ) << k_funcinfo << "URL: " << gurl << endl;
+
+ KIO::TransferJob *job = KIO::get( geturl, false, true );
+
+ QObject::connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ), this, SLOT( slotDataReceived( KIO::Job *, const QByteArray & ) ) );
+ QObject::connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotJobDone( KIO::Job * ) ) );
+
+ // KIO is async and we use a sync API, so use the processEvents hack to work around that
+ // FIXME: We need to make the libkopete API async to get rid of this processEvents.
+ // It often causes crashes in the code. - Martijn
+ while ( !m_completed[ job ] )
+ qApp->processEvents();
+
+ QString data = QString::fromUtf8( m_data[ job ] );
+
+ // After hacks, we need to clean
+ m_data.remove( job );
+ m_completed.remove( job );
+
+ //kdDebug( 14308 ) << k_funcinfo << "Babelfish response: " << endl << data << endl;
+
+ QRegExp re( "<Div style=padding:10px; lang=..>(.*)</div" );
+ re.setMinimal( true );
+ re.search( data );
+
+ return re.cap( 1 );
+}
+
+void TranslatorPlugin::sendTranslation( Kopete::Message &msg, const QString &translated )
+{
+ if ( translated.isEmpty() )
+ {
+ kdWarning( 14308 ) << k_funcinfo << "Translated text is empty" << endl;
+ return;
+ }
+
+ TranslateMode mode = DontTranslate;
+
+ switch ( msg.direction() )
+ {
+ case Kopete::Message::Outbound:
+ mode = TranslateMode( m_outgoingMode );
+ break;
+ case Kopete::Message::Inbound:
+ mode = TranslateMode( m_incomingMode );
+ break;
+ default:
+ kdWarning( 14308 ) << k_funcinfo << "Can't determine if it is an incoming or outgoing message" << endl;
+ };
+
+ switch ( mode )
+ {
+ case JustTranslate:
+ msg.setBody( translated, msg.format() );
+ break;
+ case ShowOriginal:
+ msg.setBody( i18n( "%2\nAuto Translated: %1" ).arg( translated, msg.plainBody() ), msg.format() );
+ break;
+ case ShowDialog:
+ {
+ TranslatorDialog *d = new TranslatorDialog( translated );
+ d->exec();
+ msg.setBody( d->translatedText(), msg.format() );
+ delete d;
+ break;
+ }
+ case DontTranslate:
+ default:
+ //do nothing
+ break;
+ };
+}
+
+void TranslatorPlugin::slotDataReceived ( KIO::Job *job, const QByteArray &data )
+{
+ m_data[ job ] += QCString( data, data.size() + 1 );
+}
+
+void TranslatorPlugin::slotJobDone ( KIO::Job *job )
+{
+ m_completed[ job ] = true;
+ QObject::disconnect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ), this, SLOT( slotDataReceived( KIO::Job *, const QByteArray & ) ) );
+ QObject::disconnect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotJobDone( KIO::Job * ) ) );
+}
+
+void TranslatorPlugin::slotSetLanguage()
+{
+ Kopete::MetaContact *m = Kopete::ContactList::self()->selectedMetaContacts().first();
+ if( m && m_actionLanguage )
+ m->setPluginData( this, "languageKey", m_languages->languageKey( m_actionLanguage->currentItem() ) );
+}
+
+#include "translatorplugin.moc"
+
+// vim: set noet ts=4 sts=4 sw=4:
+
diff --git a/kopete/plugins/translator/translatorplugin.h b/kopete/plugins/translator/translatorplugin.h
new file mode 100644
index 00000000..2a04b509
--- /dev/null
+++ b/kopete/plugins/translator/translatorplugin.h
@@ -0,0 +1,113 @@
+/*
+ translatorplugin.h
+
+ Kopete Translatorfish Translator plugin
+
+ Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <[email protected]>
+ Copyright (c) 2002-2003 by Olivier Goffart <ogoffart @ kde.org>
+
+ Kopete (c) 2002-2003 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 BABELFISHPLUGIN_H
+#define BABELFISHPLUGIN_H
+
+#include <qobject.h>
+#include <qmap.h>
+#include <qcstring.h>
+#include <qintdict.h>
+
+
+#include <kio/job.h>
+
+#include "kopetemessage.h"
+#include "kopeteplugin.h"
+
+
+class QString;
+class KSelectAction;
+
+namespace Kopete { class Message; }
+namespace Kopete { class MetaContact; }
+namespace Kopete { class ChatSession; }
+
+class TranslatorPreferences;
+class TranslatorGUIClient;
+class TranslatorLanguages;
+
+/**
+ * @author Duncan Mac-Vicar Prett <[email protected]>
+ *
+ * Kopete Translator Plugin
+ */
+class TranslatorPlugin : public Kopete::Plugin
+{
+ Q_OBJECT
+
+friend class TranslatorGUIClient;
+
+public:
+ static TranslatorPlugin *plugin();
+
+ TranslatorPlugin( QObject *parent, const char *name, const QStringList &args );
+ ~TranslatorPlugin();
+
+ enum TranslateMode
+ {
+ DontTranslate = 0,
+ ShowOriginal = 1,
+ JustTranslate = 2,
+ ShowDialog = 3
+ };
+
+private slots:
+ void slotIncomingMessage( Kopete::Message& msg );
+ void slotOutgoingMessage( Kopete::Message& msg );
+ void slotDataReceived ( KIO::Job *, const QByteArray &data);
+ void slotJobDone ( KIO::Job *);
+ void slotSetLanguage();
+ void slotSelectionChanged(bool);
+ void slotNewKMM(Kopete::ChatSession *);
+ void loadSettings();
+
+public:
+ QString translateMessage( const QString &, const QString &, const QString & );
+ void translateMessage( const QString &, const QString &, const QString & , QObject * , const char*);
+
+protected:
+ QString googleTranslateMessage( const QString &, const QString &, const QString & );
+ QString babelTranslateMessage(const QString &, const QString &, const QString & );
+
+private:
+
+ QMap< KIO::Job *, QCString> m_data;
+ QMap< KIO::Job *, bool> m_completed;
+
+ KSelectAction* m_actionLanguage;
+
+ static TranslatorPlugin* pluginStatic_;
+ TranslatorLanguages *m_languages;
+
+ //Settings
+ QString m_myLang;
+ QString m_service;
+ unsigned int m_outgoingMode;
+ unsigned int m_incomingMode;
+
+private:
+ void sendTranslation(Kopete::Message &msg, const QString &translated);
+};
+
+#endif
+
+// vim: set noet ts=4 sts=4 sw=4:
+
diff --git a/kopete/plugins/translator/translatorprefs.cpp b/kopete/plugins/translator/translatorprefs.cpp
new file mode 100644
index 00000000..cb67c4c6
--- /dev/null
+++ b/kopete/plugins/translator/translatorprefs.cpp
@@ -0,0 +1,52 @@
+/*
+ translatorprefs.cpp - Kopete Translator plugin
+
+ Copyright (c) 2001-2002 by Duncan Mac-Vicar Prett <[email protected]>
+ Copyright (c) 2002-2003 by Olivier Goffart <ogoffart @ kde.org>
+ Kopete (c) 2002-2003 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 <kgenericfactory.h>
+#include "kcautoconfigmodule.h"
+#include "translatorprefsbase.h"
+#include "translatorlanguages.h"
+#include <qcombobox.h>
+
+
+class TranslatorPreferences;
+typedef KGenericFactory<TranslatorPreferences> TranslatorConfigFactory;
+K_EXPORT_COMPONENT_FACTORY( kcm_kopete_translator, TranslatorConfigFactory( "kcm_kopete_translator" ) )
+
+class TranslatorPreferences : public KCAutoConfigModule
+{
+public:
+ TranslatorPreferences( QWidget *parent = 0, const char * = 0, const QStringList &args = QStringList() ) : KCAutoConfigModule( TranslatorConfigFactory::instance(), parent, args )
+ {
+ TranslatorPrefsUI *preferencesDialog = new TranslatorPrefsUI(this);
+
+ TranslatorLanguages languages;
+ QMap<QString,QString>::ConstIterator i;
+ QMap<QString,QString> m;
+
+ m = languages.languagesMap();
+ for ( i = m.begin(); i != m.end() ; ++i )
+ preferencesDialog->myLang->insertItem( i.data(), languages.languageIndex(i.key()) );
+
+ m = languages.servicesMap();
+ for ( i = m.begin(); i != m.end() ; ++i )
+ preferencesDialog->Service->insertItem( i.data(), languages.serviceIndex(i.key()) );
+
+ setMainWidget( preferencesDialog , "Translator Plugin");
+ }
+};
+
diff --git a/kopete/plugins/translator/translatorprefsbase.ui b/kopete/plugins/translator/translatorprefsbase.ui
new file mode 100644
index 00000000..56b75543
--- /dev/null
+++ b/kopete/plugins/translator/translatorprefsbase.ui
@@ -0,0 +1,191 @@
+<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
+<class>TranslatorPrefsUI</class>
+<author>Duncan Mac-Vicar P.</author>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>TranslatorPrefsUI</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>401</width>
+ <height>417</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QComboBox" row="1" column="1">
+ <property name="name">
+ <cstring>Service</cstring>
+ </property>
+ </widget>
+ <widget class="QLabel" row="1" column="0">
+ <property name="name">
+ <cstring>TextLabel2_2</cstring>
+ </property>
+ <property name="text">
+ <string>Translation service:</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>TextLabel2</cstring>
+ </property>
+ <property name="text">
+ <string>Default native language:</string>
+ </property>
+ </widget>
+ <widget class="QComboBox" row="0" column="1">
+ <property name="name">
+ <cstring>myLang</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ <widget class="QButtonGroup" row="2" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>IncomingMessages</cstring>
+ </property>
+ <property name="title">
+ <string>Incoming Messages</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>IncomingDontTranslate</cstring>
+ </property>
+ <property name="text">
+ <string>Do not translate</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <property name="buttonGroupId">
+ <number>0</number>
+ </property>
+ </widget>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>IncomingShowOriginal</cstring>
+ </property>
+ <property name="text">
+ <string>Show the original message</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ <property name="buttonGroupId">
+ <number>1</number>
+ </property>
+ </widget>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>IncomingTranslate</cstring>
+ </property>
+ <property name="text">
+ <string>Translate directly</string>
+ </property>
+ <property name="buttonGroupId">
+ <number>2</number>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QButtonGroup" row="3" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>OutgoingMessages</cstring>
+ </property>
+ <property name="title">
+ <string>Outgoing Messages</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>OutgoingDontTranslate</cstring>
+ </property>
+ <property name="text">
+ <string>Do not translate</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <property name="buttonGroupId">
+ <number>0</number>
+ </property>
+ </widget>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>OutgoingShowOriginal</cstring>
+ </property>
+ <property name="text">
+ <string>Show the original message</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ <property name="buttonGroupId">
+ <number>1</number>
+ </property>
+ </widget>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>OutgoingTranslate</cstring>
+ </property>
+ <property name="text">
+ <string>Translate directly</string>
+ </property>
+ </widget>
+ <widget class="QRadioButton">
+ <property name="name">
+ <cstring>OutgoingAsk</cstring>
+ </property>
+ <property name="text">
+ <string>Show dialog before sending</string>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ <spacer row="4" column="0" rowspan="1" colspan="2">
+ <property name="name">
+ <cstring>Spacer2</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </grid>
+</widget>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>
diff --git a/kopete/plugins/translator/translatorui.rc b/kopete/plugins/translator/translatorui.rc
new file mode 100644
index 00000000..d583b6a4
--- /dev/null
+++ b/kopete/plugins/translator/translatorui.rc
@@ -0,0 +1,12 @@
+<!DOCTYPE kpartgui>
+<kpartgui name="kopete_translator" version="1">
+ <MenuBar>
+ <Menu name="edit">
+ <text>&amp;Edit</text>
+ <Action name="contactLanguage" />
+ </Menu>
+ </MenuBar>
+ <Menu name="contact_popup">
+ <Action name="contactLanguage" />
+ </Menu>
+</kpartgui>