summaryrefslogtreecommitdiffstats
path: root/kbabel/kbabeldict/modules/tmx
diff options
context:
space:
mode:
Diffstat (limited to 'kbabel/kbabeldict/modules/tmx')
-rw-r--r--kbabel/kbabeldict/modules/tmx/Makefile.am34
-rw-r--r--kbabel/kbabeldict/modules/tmx/pc_factory.cpp111
-rw-r--r--kbabel/kbabeldict/modules/tmx/pc_factory.h62
-rw-r--r--kbabel/kbabeldict/modules/tmx/preferenceswidget.cpp334
-rw-r--r--kbabel/kbabeldict/modules/tmx/preferenceswidget.h97
-rw-r--r--kbabel/kbabeldict/modules/tmx/pwidget.ui216
-rw-r--r--kbabel/kbabeldict/modules/tmx/tmxcompendium.cpp1007
-rw-r--r--kbabel/kbabeldict/modules/tmx/tmxcompendium.desktop50
-rw-r--r--kbabel/kbabeldict/modules/tmx/tmxcompendium.h137
-rw-r--r--kbabel/kbabeldict/modules/tmx/tmxcompendiumdata.cpp308
-rw-r--r--kbabel/kbabeldict/modules/tmx/tmxcompendiumdata.h106
11 files changed, 2462 insertions, 0 deletions
diff --git a/kbabel/kbabeldict/modules/tmx/Makefile.am b/kbabel/kbabeldict/modules/tmx/Makefile.am
new file mode 100644
index 00000000..f0f54b01
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/Makefile.am
@@ -0,0 +1,34 @@
+## Makefile.am for tmxcompendium
+
+# this has all of the subdirectories that make will recurse into. if
+# there are none, comment this out
+#SUBDIRS =
+
+
+# this is the program that gets installed. it's name is used for all
+# of the other Makefile.am variables
+kde_module_LTLIBRARIES = kbabeldict_tmxcompendium.la
+
+# set the include path for X, qt and KDE
+INCLUDES = -I$(srcdir)/../.. -I../../../common -I$(srcdir)/../../../common $(all_includes)
+
+
+# which sources should be compiled for kbabel
+kbabeldict_tmxcompendium_la_SOURCES = tmxcompendium.cpp preferenceswidget.cpp \
+ pc_factory.cpp pwidget.ui tmxcompendiumdata.cpp
+
+kbabeldict_tmxcompendium_la_LIBADD = ../../libkbabeldictplugin.la ../../../common/libkbabelcommon.la $(LIB_KDEUI) $(LIB_KIO)
+kbabeldict_tmxcompendium_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined
+
+
+
+# these are the headers for your project
+noinst_HEADERS = tmxcompendium.h preferenceswidget.h pc_factory.h \
+ tmxcompendiumdata.h
+
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+kde_services_DATA = tmxcompendium.desktop
+EXTRA_DIST = $(kde_services_DATA)
diff --git a/kbabel/kbabeldict/modules/tmx/pc_factory.cpp b/kbabel/kbabeldict/modules/tmx/pc_factory.cpp
new file mode 100644
index 00000000..a3dcfdf9
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/pc_factory.cpp
@@ -0,0 +1,111 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2000 by Matthias Kiefer <matthias.kiefer@gmx.de>
+ 2002 by Stanislav Visnovsky <visnovsky@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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+
+
+#include <klocale.h>
+#include <kinstance.h>
+#include <kaboutdata.h>
+#include <kdebug.h>
+
+#include "pc_factory.h"
+#include "tmxcompendium.h"
+
+
+extern "C"
+{
+ KDE_EXPORT void *init_kbabeldict_tmxcompendium()
+ {
+ return new PcFactory;
+ }
+}
+
+
+KInstance *PcFactory::s_instance = 0;
+KAboutData *PcFactory::s_about = 0;
+
+
+PcFactory::PcFactory( QObject *parent, const char *name)
+ : KLibFactory(parent,name)
+{
+}
+
+PcFactory::~PcFactory()
+{
+ if(s_instance)
+ {
+ delete s_instance;
+ s_instance=0;
+ }
+
+ if(s_about)
+ {
+ delete s_about;
+ s_about=0;
+ }
+}
+
+
+QObject *PcFactory::createObject( QObject *parent, const char *name
+ , const char *classname, const QStringList &)
+{
+ if(QCString(classname) != "SearchEngine")
+ {
+ kdError() << "not a SearchEngine requested" << endl;
+ return 0;
+ }
+
+ return new TmxCompendium(parent,name);
+}
+
+
+KInstance *PcFactory::instance()
+{
+ if(!s_instance)
+ {
+ s_about = new KAboutData( "tmxcompendium", I18N_NOOP("TMX Compendium")
+ , "1.0"
+ , I18N_NOOP("A module for searching in a TMX file")
+ , KAboutData::License_GPL
+ , "Copyright 2002, Stanislav Visnovsky"
+ ,0,0, "visnovsky@kde.org");
+
+ s_about->addAuthor("Matthias Kiefer",0,"kiefer@kde.org");
+ s_about->addAuthor("Stanislav Visnovsky",0,"visnovsky@kde.org");
+
+ s_instance = new KInstance(s_about);
+ }
+
+ return s_instance;
+}
+
+#include "pc_factory.moc"
diff --git a/kbabel/kbabeldict/modules/tmx/pc_factory.h b/kbabel/kbabeldict/modules/tmx/pc_factory.h
new file mode 100644
index 00000000..5ef08277
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/pc_factory.h
@@ -0,0 +1,62 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2000 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2002 by Stanislav Visnovsky
+ <visnovsky@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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+
+
+#ifndef PC_FACTORY_H
+#define PC_FACTORY_H
+
+#include <klibloader.h>
+class KInstance;
+class KAboutData;
+
+class PcFactory : public KLibFactory
+{
+ Q_OBJECT
+public:
+ PcFactory( QObject *parent=0, const char *name=0);
+ ~PcFactory();
+
+ virtual QObject *createObject( QObject *parent=0, const char *name=0
+ , const char *classname="QObject"
+ , const QStringList &args = QStringList());
+
+ static KInstance *instance();
+
+private:
+ static KInstance *s_instance;
+ static KAboutData *s_about;
+};
+
+#endif
diff --git a/kbabel/kbabeldict/modules/tmx/preferenceswidget.cpp b/kbabel/kbabeldict/modules/tmx/preferenceswidget.cpp
new file mode 100644
index 00000000..1202496d
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/preferenceswidget.cpp
@@ -0,0 +1,334 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2000 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2002 by Stanislav Visnovsky
+ <visnovsky@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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+
+#include <kfiledialog.h>
+#include <qpushbutton.h>
+#include <qwhatsthis.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kurlrequester.h>
+
+#include "preferenceswidget.h"
+#include "pwidget.h"
+
+TmxCompendiumPreferencesWidget::TmxCompendiumPreferencesWidget(QWidget *parent, const char* name)
+ : PrefWidget(parent,name)
+ , changed(false)
+{
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ prefWidget = new TmxCompendiumPWidget(this);
+ layout->addWidget(prefWidget);
+
+ connect(prefWidget->caseBtn, SIGNAL(toggled(bool))
+ , this, SLOT(setChanged()));
+ connect(prefWidget->equalBtn, SIGNAL(toggled(bool))
+ , this, SLOT(setChanged()));
+ connect(prefWidget->ngramBtn, SIGNAL(toggled(bool))
+ , this, SLOT(setChanged()));
+ connect(prefWidget->isContainedBtn, SIGNAL(toggled(bool))
+ , this, SLOT(setChanged()));
+ connect(prefWidget->containsBtn, SIGNAL(toggled(bool))
+ , this, SLOT(setChanged()));
+ connect(prefWidget->hasWordBtn, SIGNAL(toggled(bool))
+ , this, SLOT(setChanged()));
+ connect(prefWidget->wholeBtn, SIGNAL(toggled(bool))
+ , this, SLOT(setChanged()));
+
+ connect(prefWidget->urlInput->lineEdit(),SIGNAL(textChanged(const QString&))
+ , this, SLOT(setChanged()));
+
+ connect(prefWidget->equalBtn, SIGNAL(toggled(bool))
+ , this, SLOT(equalBtnToggled(bool)));
+ connect(prefWidget->ngramBtn, SIGNAL(toggled(bool))
+ , this, SLOT(ngramBtnToggled(bool)));
+ connect(prefWidget->isContainedBtn, SIGNAL(toggled(bool))
+ , this, SLOT(isContainedBtnToggled(bool)));
+ connect(prefWidget->containsBtn, SIGNAL(toggled(bool))
+ , this, SLOT(containsBtnToggled(bool)));
+ connect(prefWidget->hasWordBtn, SIGNAL(toggled(bool))
+ , this, SLOT(hasWordBtnToggled(bool)));
+
+
+ QString whatsthis=i18n("<qt><p><b>Parameters</b></p>"
+ "<p>Here you can fine-tune searching within the PO file. "
+ "For example, if you want to perform a case sensitive search.</p></qt>" );
+ QWhatsThis::add(prefWidget->caseBtn,whatsthis);
+ QWhatsThis::add(prefWidget->wholeBtn,whatsthis);
+
+ whatsthis = i18n("<qt><p><b>Comparison Options</b></p>"
+ "<p>Choose here which messages you want to have treated as a matching "
+ "message.</p></qt>");
+ QWhatsThis::add(prefWidget->equalBtn,whatsthis);
+ QWhatsThis::add(prefWidget->containsBtn,whatsthis);
+ QWhatsThis::add(prefWidget->isContainedBtn,whatsthis);
+ QWhatsThis::add(prefWidget->hasWordBtn,whatsthis);
+
+ whatsthis = i18n("<qt><p><b>3-Gram-matching</b></p>"
+ "<p>A message matches another if most of its 3-letter groups are "
+ "contained in the other message. e.g. 'abc123' matches 'abcx123c12'.</p></qt>");
+ QWhatsThis::add(prefWidget->ngramBtn,whatsthis);
+
+ whatsthis = i18n("<qt><p><b>Location</b></p>"
+ "<p>Configure here which file is to be used for searching."
+ "</p></qt>");
+ QWhatsThis::add(prefWidget->urlInput,whatsthis);
+}
+
+TmxCompendiumPreferencesWidget::~TmxCompendiumPreferencesWidget()
+{
+}
+
+
+void TmxCompendiumPreferencesWidget::apply()
+{
+ emit applySettings();
+}
+
+void TmxCompendiumPreferencesWidget::cancel()
+{
+ emit restoreSettings();
+}
+
+void TmxCompendiumPreferencesWidget::standard()
+{
+ prefWidget->urlInput->setURL("http://i18n.kde.org/po_overview/@LANG@.messages");
+ prefWidget->caseBtn->setChecked(false);
+ prefWidget->equalBtn->setChecked(true);
+ prefWidget->ngramBtn->setChecked(true);
+ prefWidget->isContainedBtn->setChecked(false);
+ prefWidget->containsBtn->setChecked(false);
+ prefWidget->wholeBtn->setChecked(true);
+ prefWidget->hasWordBtn->setChecked(true);
+
+ changed=true;
+}
+
+void TmxCompendiumPreferencesWidget::setURL(const QString url)
+{
+ prefWidget->urlInput->setURL(url);
+ changed=false;
+}
+
+void TmxCompendiumPreferencesWidget::setCaseSensitive(bool on)
+{
+ prefWidget->caseBtn->setChecked(on);
+ changed=false;
+}
+
+void TmxCompendiumPreferencesWidget::setMatchEqual(bool on)
+{
+ prefWidget->equalBtn->setChecked(on);
+ changed=false;
+}
+
+void TmxCompendiumPreferencesWidget::setMatchNGram(bool on)
+{
+ prefWidget->ngramBtn->setChecked(on);
+ changed=false;
+}
+
+void TmxCompendiumPreferencesWidget::setMatchIsContained(bool on)
+{
+ prefWidget->isContainedBtn->setChecked(on);
+ changed=false;
+}
+
+void TmxCompendiumPreferencesWidget::setMatchContains(bool on)
+{
+ prefWidget->containsBtn->setChecked(on);
+ changed=false;
+}
+
+void TmxCompendiumPreferencesWidget::setWholeWords(bool on)
+{
+ prefWidget->wholeBtn->setChecked(on);
+ changed=false;
+}
+
+
+void TmxCompendiumPreferencesWidget::setMatchWords(bool on)
+{
+ prefWidget->hasWordBtn->setChecked(on);
+ changed=false;
+}
+
+
+
+QString TmxCompendiumPreferencesWidget::url()
+{
+ changed=false;
+ return prefWidget->urlInput->url();
+}
+
+bool TmxCompendiumPreferencesWidget::caseSensitive()
+{
+ changed=false;
+
+ return prefWidget->caseBtn->isChecked();
+}
+
+bool TmxCompendiumPreferencesWidget::matchEqual()
+{
+ changed=false;
+
+ return prefWidget->equalBtn->isChecked();
+}
+
+bool TmxCompendiumPreferencesWidget::matchNGram()
+{
+ changed=false;
+
+ return prefWidget->ngramBtn->isChecked();
+}
+
+bool TmxCompendiumPreferencesWidget::matchIsContained()
+{
+ changed=false;
+
+ return prefWidget->isContainedBtn->isChecked();
+}
+
+bool TmxCompendiumPreferencesWidget::matchContains()
+{
+ changed=false;
+
+ return prefWidget->containsBtn->isChecked();
+}
+
+bool TmxCompendiumPreferencesWidget::wholeWords()
+{
+ changed=false;
+
+ return prefWidget->wholeBtn->isChecked();
+}
+
+
+bool TmxCompendiumPreferencesWidget::matchWords()
+{
+ changed=false;
+
+ return prefWidget->hasWordBtn->isChecked();
+}
+
+
+
+bool TmxCompendiumPreferencesWidget::settingsChanged() const
+{
+ return changed;
+}
+
+void TmxCompendiumPreferencesWidget::setChanged()
+{
+ changed=true;
+}
+
+
+void TmxCompendiumPreferencesWidget::equalBtnToggled(bool on)
+{
+ if(!on)
+ {
+ if(!prefWidget->isContainedBtn->isChecked()
+ && !prefWidget->ngramBtn->isChecked()
+ && !prefWidget->containsBtn->isChecked()
+ && !prefWidget->hasWordBtn->isChecked())
+ {
+ prefWidget->equalBtn->setChecked(true);
+ }
+ }
+}
+
+void TmxCompendiumPreferencesWidget::ngramBtnToggled(bool on)
+{
+ if(!on)
+ {
+ if(!prefWidget->isContainedBtn->isChecked()
+ && !prefWidget->equalBtn->isChecked()
+ && !prefWidget->containsBtn->isChecked()
+ && !prefWidget->hasWordBtn->isChecked())
+ {
+ prefWidget->equalBtn->setChecked(true);
+ }
+ }
+}
+
+void TmxCompendiumPreferencesWidget::isContainedBtnToggled(bool on)
+{
+ if(!on)
+ {
+ if(!prefWidget->equalBtn->isChecked()
+ && !prefWidget->ngramBtn->isChecked()
+ && !prefWidget->containsBtn->isChecked()
+ && !prefWidget->hasWordBtn->isChecked())
+ {
+ prefWidget->isContainedBtn->setChecked(true);
+ }
+ }
+}
+
+void TmxCompendiumPreferencesWidget::containsBtnToggled(bool on)
+{
+ if(!on)
+ {
+ if(!prefWidget->isContainedBtn->isChecked()
+ && !prefWidget->ngramBtn->isChecked()
+ && !prefWidget->equalBtn->isChecked()
+ && !prefWidget->hasWordBtn->isChecked())
+ {
+ prefWidget->containsBtn->setChecked(true);
+ }
+ }
+}
+
+void TmxCompendiumPreferencesWidget::hasWordBtnToggled(bool on)
+{
+ if(!on)
+ {
+ if(!prefWidget->isContainedBtn->isChecked()
+ && !prefWidget->ngramBtn->isChecked()
+ && !prefWidget->equalBtn->isChecked()
+ && !prefWidget->containsBtn->isChecked())
+ {
+ prefWidget->hasWordBtn->setChecked(true);
+ }
+ }
+}
+
+
+
+#include "preferenceswidget.moc"
diff --git a/kbabel/kbabeldict/modules/tmx/preferenceswidget.h b/kbabel/kbabeldict/modules/tmx/preferenceswidget.h
new file mode 100644
index 00000000..c8356c3d
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/preferenceswidget.h
@@ -0,0 +1,97 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2000 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2002 by Stanislav Visnovsky
+ <visnovsky@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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+
+
+#ifndef PREFERENCESWIDGET_H
+#define PREFERENCESWIDGET_H
+
+#include "searchengine.h"
+
+class TmxCompendiumPWidget;
+
+class TmxCompendiumPreferencesWidget : public PrefWidget
+{
+ Q_OBJECT
+
+public:
+ TmxCompendiumPreferencesWidget(QWidget *parent=0, const char* name=0);
+ virtual ~TmxCompendiumPreferencesWidget();
+
+ virtual void apply();
+ virtual void cancel();
+ virtual void standard();
+
+ void setURL(const QString url);
+ void setMatchEqual(bool);
+ void setMatchNGram(bool);
+ void setMatchIsContained(bool);
+ void setMatchContains(bool);
+ void setMatchWords(bool);
+ void setWholeWords(bool);
+ void setCaseSensitive(bool);
+
+ QString url();
+ bool matchEqual();
+ bool matchNGram();
+ bool matchIsContained();
+ bool matchContains();
+ bool matchWords();
+ bool wholeWords();
+ bool caseSensitive();
+
+
+ bool settingsChanged() const;
+
+signals:
+ void restoreSettings();
+ void applySettings();
+
+public:
+ TmxCompendiumPWidget *prefWidget;
+
+protected slots:
+ void setChanged();
+ void equalBtnToggled(bool);
+ void ngramBtnToggled(bool);
+ void isContainedBtnToggled(bool);
+ void containsBtnToggled(bool);
+ void hasWordBtnToggled(bool);
+
+private:
+ bool changed;
+
+};
+
+#endif
diff --git a/kbabel/kbabeldict/modules/tmx/pwidget.ui b/kbabel/kbabeldict/modules/tmx/pwidget.ui
new file mode 100644
index 00000000..ef6c9967
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/pwidget.ui
@@ -0,0 +1,216 @@
+<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
+<class>TmxCompendiumPWidget</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>TMXPWidget</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>452</width>
+ <height>291</height>
+ </rect>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>11</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>GroupBox1</cstring>
+ </property>
+ <property name="title">
+ <string>&amp;Path to Compendium File</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>11</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="KURLRequester">
+ <property name="name">
+ <cstring>urlInput</cstring>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QButtonGroup">
+ <property name="name">
+ <cstring>ButtonGroup1</cstring>
+ </property>
+ <property name="title">
+ <string>Options</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>11</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>Layout4</cstring>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="QCheckBox" row="0" column="1">
+ <property name="name">
+ <cstring>wholeBtn</cstring>
+ </property>
+ <property name="text">
+ <string>Onl&amp;y whole words</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="0" column="0">
+ <property name="name">
+ <cstring>caseBtn</cstring>
+ </property>
+ <property name="text">
+ <string>Case sensiti&amp;ve</string>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>TextLabel3</cstring>
+ </property>
+ <property name="text">
+ <string>A text matches if:</string>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>Layout3</cstring>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="QCheckBox" row="0" column="0">
+ <property name="name">
+ <cstring>equalBtn</cstring>
+ </property>
+ <property name="text">
+ <string>E&amp;qual to searched text</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="2" column="1">
+ <property name="name">
+ <cstring>hasWordBtn</cstring>
+ </property>
+ <property name="text">
+ <string>Contains a &amp;word of searched text</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="1" column="1">
+ <property name="name">
+ <cstring>isContainedBtn</cstring>
+ </property>
+ <property name="text">
+ <string>Co&amp;ntained in searched text</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="1" column="0">
+ <property name="name">
+ <cstring>ngramBtn</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Similar to searched text</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="0" column="1">
+ <property name="name">
+ <cstring>containsBtn</cstring>
+ </property>
+ <property name="text">
+ <string>Contains searched te&amp;xt</string>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ </vbox>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>Spacer1</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>
+ </vbox>
+</widget>
+<customwidgets>
+ <customwidget>
+ <class>KURLRequester</class>
+ <header location="global">kurlrequester.h</header>
+ <sizehint>
+ <width>-1</width>
+ <height>-1</height>
+ </sizehint>
+ <container>0</container>
+ <sizepolicy>
+ <hordata>5</hordata>
+ <verdata>5</verdata>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ <pixmap>image0</pixmap>
+ </customwidget>
+</customwidgets>
+<images>
+ <image name="image0">
+ <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
+ </image>
+</images>
+<tabstops>
+ <tabstop>caseBtn</tabstop>
+</tabstops>
+<includes>
+ <include location="global" impldecl="in declaration">kseparator.h</include>
+</includes>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>kurlrequester.h</includehint>
+</includehints>
+</UI>
diff --git a/kbabel/kbabeldict/modules/tmx/tmxcompendium.cpp b/kbabel/kbabeldict/modules/tmx/tmxcompendium.cpp
new file mode 100644
index 00000000..152bc536
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/tmxcompendium.cpp
@@ -0,0 +1,1007 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2000 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2002 by Stanislav Visnovsky
+ <visnovsky@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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+#include <klocale.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kstaticdeleter.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kinstance.h>
+#include <kio/netaccess.h>
+
+#include <qtextstream.h>
+#include <qtimer.h>
+
+#include "tmxcompendiumdata.h"
+#include "tmxcompendium.h"
+#include "preferenceswidget.h"
+#include "pc_factory.h"
+
+#include <catalogitem.h>
+
+// ngram length and minimal matching for fuzzy search
+#define NGRAM_LEN 3
+#define LIM_NGRAM 50
+
+static KStaticDeleter< QDict<TmxCompendiumData> > compDataDeleter;
+QDict<TmxCompendiumData> *TmxCompendium::_compDict = 0;
+
+TmxCompendium::TmxCompendium(QObject *parent, const char *name)
+ : SearchEngine(parent, name)
+{
+ prefWidget=0;
+ data=0;
+ error=false;
+ stop=false;
+ active=false;
+ initialized=false;
+ loading=false;
+
+ langCode = KGlobal::locale()->language();
+
+ caseSensitive = false;
+ wholeWords=true;
+
+ matchEqual = true;
+ matchNGram = true;
+ matchIsContained = false;
+ matchContains = true;
+ matchWords=true;
+
+
+ loadTimer = new QTimer(this);
+ connect(loadTimer,SIGNAL(timeout()),this,SLOT(slotLoadCompendium()));
+}
+
+TmxCompendium::~TmxCompendium()
+{
+ if(isSearching())
+ {
+ stopSearch();
+ }
+
+ unregisterData();
+}
+
+bool TmxCompendium::isReady() const
+{
+ return (isSearching() || !error);
+}
+
+
+bool TmxCompendium::isSearching() const
+{
+ return (active || loading);
+}
+
+
+void TmxCompendium::saveSettings(KConfigBase *config)
+{
+ if(autoUpdate && prefWidget && prefWidget->settingsChanged())
+ {
+ applySettings();
+ }
+
+ config->writeEntry("CaseSensitive",caseSensitive);
+ config->writeEntry("WholeWords", wholeWords);
+
+ config->writeEntry("MatchEqual", matchEqual);
+ config->writeEntry("MatchIsContained",matchIsContained);
+ config->writeEntry("MatchContains", matchContains);
+ config->writeEntry("MatchWords", matchWords);
+ config->writeEntry("MatchNGram", matchNGram);
+
+ config->writeEntry("Compendium", url);
+}
+
+void TmxCompendium::readSettings(KConfigBase *config)
+{
+ caseSensitive = config->readBoolEntry("CaseSensitive", false);
+ wholeWords = config->readBoolEntry("WholeWords",true);
+
+ matchEqual = config->readBoolEntry("MatchEqual", true);
+ matchIsContained = config->readBoolEntry("MatchIsContained", false);
+ matchContains = config->readBoolEntry("MatchContains",true);
+ matchWords = config->readBoolEntry("MatchWords",true);
+ matchNGram = config->readBoolEntry("MatchNGram",true);
+
+ QString newPath = config->readEntry("Compendium","http://i18n.kde.org/po_overview/@LANG@.messages");
+ if(!initialized)
+ {
+ url = newPath;
+ }
+ else if(newPath != url)
+ {
+ url = newPath;
+ loadCompendium();
+ }
+
+
+ restoreSettings();
+}
+
+PrefWidget *TmxCompendium::preferencesWidget(QWidget *parent)
+{
+ prefWidget = new TmxCompendiumPreferencesWidget(parent,"tmxcompendium_prefwidget");
+ connect(prefWidget, SIGNAL(applySettings()), this, SLOT(applySettings()));
+ connect(prefWidget, SIGNAL(restoreSettings())
+ , this, SLOT(restoreSettings()));
+
+ restoreSettings();
+
+ return prefWidget;
+}
+
+const KAboutData *TmxCompendium::about() const
+{
+ return PcFactory::instance()->aboutData();
+}
+
+
+QString TmxCompendium::name() const
+{
+ return i18n("TMX Compendium");
+}
+
+QString TmxCompendium::id() const
+{
+ return "tmxcompendium";
+}
+
+QString TmxCompendium::lastError()
+{
+ return errorMsg;
+}
+
+
+bool TmxCompendium::startSearch(const QString& text, uint pluralForm, const SearchFilter*)
+{
+ if(autoUpdate && prefWidget && prefWidget->settingsChanged())
+ {
+ applySettings();
+ }
+
+ if(isSearching())
+ return false;
+
+ clearResults();
+ stop = false;
+ active = true;
+
+ if(!initialized)
+ {
+ if(loadTimer->isActive())
+ loadTimer->stop();
+
+ slotLoadCompendium();
+ }
+
+ if(error || !data)
+ {
+ active = false;
+ return false;
+ }
+
+ if(data->active())
+ {
+ active = false;
+ return true;
+ }
+
+ emit started();
+
+
+ QValueList<int> foundIndices;
+ QValueList<int> checkedIndices;
+ uint checkCounter=0;
+
+ const int *index = data->exactDict(text);
+ if(index)
+ {
+ foundIndices.append(*index);
+
+ SearchResult *result = new SearchResult;
+ result->requested = text;
+ result->found = data->msgid(*index);
+ result->translation = data->msgstr(*index);
+ result->score = 100;
+
+ TranslationInfo *info = new TranslationInfo;
+ info->location = directory(realURL,0);
+ info->translator = QString::null;
+ info->description = QString::null;
+ result->descriptions.append(info);
+
+ results.append(result);
+
+ emit numberOfResultsChanged(results.count());
+ emit resultFound(result);
+ }
+
+ QString searchStr=TmxCompendiumData::simplify(text);
+
+
+ if(!caseSensitive)
+ {
+ searchStr = searchStr.lower();
+ }
+
+ QString temp = searchStr;
+ temp = temp.lower();
+
+ const QValueList<int> *indexList = data->allDict(temp);
+ if(indexList)
+ {
+ QValueList<int>::ConstIterator it;
+ for( it = indexList->begin(); it != indexList->end(); ++it )
+ {
+ if(foundIndices.contains(*it))
+ {
+ continue;
+ }
+
+ QString origStr = data->msgid(*it);
+ origStr = TmxCompendiumData::simplify(origStr);
+
+
+ if(!caseSensitive)
+ {
+ origStr = origStr.lower();
+ }
+
+ if(origStr==searchStr)
+ {
+ foundIndices.append(*it);
+
+ SearchResult *result = new SearchResult;
+ result->requested = text;
+ result->found = data->msgid(*it);
+ result->translation = data->msgstr(*it);
+ // FIXME: handle plural forms properly
+ result->score = score(result->requested,result->found.first());
+
+ TranslationInfo *info = new TranslationInfo;
+ info->location = directory(realURL,0);
+ info->translator = QString::null;
+ info->description = QString::null;
+ result->descriptions.append(info);
+
+ addResult(result);
+ }
+ }
+ }
+
+ QStringList wList = TmxCompendiumData::wordList(searchStr);
+ for ( QStringList::Iterator wit = wList.begin()
+ ; wit != wList.end(); ++wit )
+ {
+ if(stop)
+ break;
+
+ indexList = data->wordDict((*wit).lower());
+ if(indexList)
+ {
+ QValueList<int>::ConstIterator it;
+ for( it = indexList->begin(); it != indexList->end(); ++it )
+ {
+ if(stop)
+ break;
+
+ if(foundIndices.contains(*it))
+ {
+ continue;
+ }
+
+ if(checkedIndices.contains(*it))
+ {
+ continue;
+ }
+
+ checkedIndices.append(*it);
+ checkCounter++;
+
+ if( (100*(checkCounter+1))%data->numberOfEntries() < 100)
+ {
+ emit progress( (100*(checkCounter+1))/data->numberOfEntries());
+ }
+
+ kapp->processEvents(100);
+
+ QString origStr = data->msgid(*it);
+ origStr = TmxCompendiumData::simplify(origStr);
+
+
+ if(!caseSensitive)
+ {
+ origStr = origStr.lower();
+ }
+
+ bool found = false;
+ if(matchWords)
+ {
+ if(!caseSensitive)
+ {
+ found=true;
+ }
+ else
+ {
+ QString s=*wit;
+ QString o=origStr;
+
+ if(wholeWords)
+ {
+ s=" "+*wit+" ";
+ o=" "+origStr+" ";
+ }
+ if(o.contains(s))
+ {
+ found=true;
+ }
+ }
+ }
+
+
+ if(!found && origStr==searchStr)
+ {
+ found =true;
+ }
+
+ // if there is an string which just contains ignored characters,
+ // continue
+ if(!found && origStr.isEmpty() ||
+ (origStr.length() == 1 && text.length() > 1))
+ {
+ continue;
+ }
+
+
+ if(!found && matchContains && !wholeWords)
+ {
+ QString s=maskString(searchStr);
+ QRegExp searchReg(s);
+
+ if(searchReg.search(origStr) >= 0)
+ found=true;
+ }
+
+ if(!found && matchIsContained && !wholeWords)
+ {
+ QString s=maskString(origStr);
+ QRegExp reg(s);
+
+ if(reg.search(searchStr) >= 0)
+ {
+ found = true;
+ }
+ }
+ if(!found && matchWords && !wholeWords)
+ {
+ QStringList list = TmxCompendiumData::wordList(searchStr);
+
+ for ( QStringList::Iterator wit2 = list.begin()
+ ; wit2 != list.end(); ++wit2 )
+ {
+ QString s=maskString(*wit2);
+ QRegExp reg(s);
+
+ if(reg.search(origStr) >= 0)
+ {
+ found = true;
+ }
+ }
+ }
+
+ if(found)
+ {
+ foundIndices.append(*it);
+
+ SearchResult *result = new SearchResult;
+ result->requested = text;
+ result->found = data->msgid(*it);
+ result->translation = data->msgstr(*it);
+ // FIXME: handle plural forms properly
+ result->score = score(result->requested,(result->found.first()));
+
+ TranslationInfo *info = new TranslationInfo;
+ info->location = directory(realURL,0);
+ info->translator = QString::null;
+ info->description = QString::null;
+ result->descriptions.append(info);
+
+ addResult(result);
+ }
+ }
+ }
+ }
+
+
+ if( matchNGram ||
+ (!wholeWords && (matchContains || matchIsContained || matchWords))
+ )
+ {
+ QRegExp searchReg;
+ if(matchContains)
+ {
+ QString s=maskString(searchStr);
+ searchReg.setPattern(s);
+ }
+
+
+ bool breakLoop=false;
+ int i=-1;
+ while(!breakLoop)
+ {
+ if(stop)
+ {
+ breakLoop=true;
+ break;
+ }
+
+ i++;
+
+ if(checkedIndices.contains(i))
+ {
+ continue;
+ }
+
+ checkedIndices.append(i);
+ checkCounter++;
+
+ if(foundIndices.contains(i))
+ {
+ continue;
+ }
+
+ kapp->processEvents(100);
+
+ if(i >= data->numberOfEntries())
+ {
+ breakLoop = true;
+ break;
+ }
+
+ if( (100*(checkCounter+1))%data->numberOfEntries() < 100)
+ {
+ emit progress( (100*(checkCounter+1))/data->numberOfEntries());
+ }
+
+ QString origStr = data->msgid(i);
+ origStr = TmxCompendiumData::simplify(origStr);
+
+ if(!caseSensitive)
+ {
+ origStr = origStr.lower();
+ }
+
+
+ // if there is an string which just contains ignored characters,
+ // continue
+ if(origStr.isEmpty() ||
+ (origStr.length() == 1 && text.length() > 1))
+ {
+ continue;
+ }
+
+ bool found = false;
+ if(matchContains && searchReg.search(origStr) >= 0)
+ {
+ found=true;
+ }
+
+
+ if(!found && matchIsContained)
+ {
+ QString s=maskString(origStr);
+ QRegExp reg(s);
+
+ if(reg.search(searchStr) >= 0)
+ {
+ found = true;
+ }
+ }
+ if(!found && matchWords)
+ {
+ QStringList list = TmxCompendiumData::wordList(searchStr);
+
+ for ( QStringList::Iterator wit2 = list.begin()
+ ; wit2 != list.end(); ++wit2 )
+ {
+ QString s=maskString(*wit2);
+
+ if(wholeWords)
+ {
+ origStr = " "+origStr+" ";
+ s=" "+s+" ";
+ }
+ QRegExp reg(s);
+
+ if(reg.search(origStr) >= 0)
+ {
+ found = true;
+ }
+ }
+ }
+
+ if(!found && matchNGram)
+ {
+ // to get more results one could
+ // interchange searchStr and origStr when
+ // the latter is shorter
+
+ found = ( ngramMatch(searchStr,origStr,NGRAM_LEN)
+ > LIM_NGRAM );
+ }
+
+ if(found)
+ {
+ foundIndices.append(i);
+
+ SearchResult *result = new SearchResult;
+ result->requested = text;
+ result->found = data->msgid(i);
+ result->translation = data->msgstr(i);
+ // FIXME: handle plural forms properly
+ result->score = score(result->requested,(result->found.first()));
+
+ TranslationInfo *info = new TranslationInfo;
+ info->location = directory(realURL,0);
+ info->translator = QString::null;
+ info->description = QString::null;
+ result->descriptions.append(info);
+
+ addResult(result);
+ }
+ }
+ }
+
+ if( (100*(checkCounter+1))/data->numberOfEntries() < 100 && !stop)
+ {
+ for(int i=(100*(checkCounter+1))/data->numberOfEntries(); i<=100; i++)
+ {
+ emit progress(i);
+ }
+ }
+
+
+ active = false;
+ stop = false;
+ emit finished();
+
+ return true;
+}
+
+void TmxCompendium::stopSearch()
+{
+ stop=true;
+}
+
+
+void TmxCompendium::applySettings()
+{
+ if(!prefWidget)
+ return;
+
+ if(isSearching())
+ stopSearch();
+
+ caseSensitive = prefWidget->caseSensitive();
+ wholeWords = prefWidget->wholeWords();
+
+ matchEqual = prefWidget->matchEqual();
+ matchNGram = prefWidget->matchNGram();
+ matchIsContained = prefWidget->matchIsContained();
+ matchContains = prefWidget->matchContains();
+ matchWords = prefWidget->matchWords();
+
+
+ bool needLoading=false;
+
+
+ QString newPath = prefWidget->url();
+ if(!initialized)
+ {
+ url = newPath;
+ }
+ else if(newPath != url)
+ {
+ url = newPath;
+ needLoading = true;
+ }
+
+ if(needLoading)
+ {
+ loadCompendium();
+ initialized=false;
+ }
+}
+
+void TmxCompendium::restoreSettings()
+{
+ if(!prefWidget)
+ return;
+
+ prefWidget->setCaseSensitive(caseSensitive);
+ prefWidget->setWholeWords(wholeWords);
+ prefWidget->setURL(url);
+
+ prefWidget->setMatchEqual(matchEqual);
+ prefWidget->setMatchNGram(matchNGram);
+ prefWidget->setMatchIsContained(matchIsContained);
+ prefWidget->setMatchContains(matchContains);
+ prefWidget->setMatchWords(matchWords);
+}
+
+void TmxCompendium::loadCompendium()
+{
+ if(!loading && !loadTimer->isActive())
+ loadTimer->start(100,true);
+}
+
+void TmxCompendium::slotLoadCompendium()
+{
+ if(loading)
+ return;
+
+ if(loadTimer->isActive())
+ loadTimer->stop();
+
+ loading = true;
+
+ if(data)
+ {
+ unregisterData();
+ }
+
+
+ QString path=url;
+
+ if(path.contains("@LANG@"))
+ {
+ path.replace("@LANG@",langCode);
+ }
+ KURL u=KCmdLineArgs::makeURL(path.local8Bit());
+ realURL = u.url();
+
+ registerData();
+
+
+ if(!data)
+ {
+ kdError() << "no data object in tmxcompendium?" << endl;
+
+ loading=false;
+ return;
+ }
+
+ if(!data->initialized())
+ {
+ if(!data->active())
+ {
+ data->load(u,langCode);
+ recheckData();
+ if(error)
+ {
+ emit hasError(errorMsg);
+ }
+ }
+ else
+ {
+ connect(data, SIGNAL(progressEnds()), this, SLOT(recheckData()));
+ }
+ }
+ else
+ {
+ recheckData();
+ if(error)
+ {
+ emit hasError(errorMsg);
+ }
+ }
+
+ initialized=true;
+}
+
+void TmxCompendium::recheckData()
+{
+ if(data)
+ {
+ disconnect(data, SIGNAL(progressEnds()), this, SLOT(recheckData()));
+
+ error = data->hasErrors();
+ errorMsg = data->errorMsg();
+ }
+
+ loading=false;
+}
+
+QString TmxCompendium::maskString(QString s) const
+{
+ s.replace('\\',"\\\\");
+ s.replace('?',"\\?");
+ s.replace('[',"\\[");
+ s.replace('.',"\\.");
+ s.replace('*',"\\*");
+ s.replace('+',"\\+");
+ s.replace('^',"\\^");
+ s.replace('$',"\\$");
+ s.replace('(',"\\(");
+ s.replace(')',"\\)");
+ s.replace('{',"\\{");
+ s.replace('}',"\\}");
+ s.replace('|',"\\|");
+
+ return s;
+}
+
+void TmxCompendium::addResult(SearchResult *result)
+{
+ if(results.last() && results.last()->score >= result->score)
+ {
+ results.append(result);
+ }
+ else
+ {
+ SearchResult *sr;
+ for(sr = results.first(); sr != 0; sr=results.next())
+ {
+ if(sr->score < result->score)
+ {
+ results.insert(results.at(),result);
+ emit resultsReordered();
+ break;
+ }
+ }
+
+ if(!sr)
+ {
+ results.append(result);
+ }
+ }
+
+ emit numberOfResultsChanged(results.count());
+ emit resultFound(result);
+}
+
+
+void TmxCompendium::setLanguageCode(const QString& lang)
+{
+ if(initialized && url.contains("@LANG@") && lang!=langCode
+ && !loadTimer->isActive() )
+ {
+ initialized=false;
+ }
+
+ langCode=lang;
+}
+
+QString TmxCompendium::translate(const QString& text, uint pluralForm)
+{
+ if(!initialized)
+ {
+ if(loadTimer->isActive())
+ loadTimer->stop();
+
+ slotLoadCompendium();
+ }
+
+ if(error || !data || data->active())
+ {
+ return QString::null;
+ }
+
+
+ const int *index = data->exactDict(text);
+
+ if(index)
+ {
+ return data->msgstr(*index);
+ }
+
+ return QString::null;
+}
+
+QString TmxCompendium::fuzzyTranslation(const QString& text, int &score, uint pluralForm)
+{
+ if(!initialized)
+ {
+ if(loadTimer->isActive())
+ loadTimer->stop();
+
+ slotLoadCompendium();
+ }
+
+ if(error || !data || data->active())
+ {
+ return QString::null;
+ }
+
+ // try to find fuzzy string
+ bool breakLoop = false;
+ stop = false;
+ int i=-1;
+ int best_matching = -1;
+ int best_match = 0;
+ int total = data->numberOfEntries();
+
+ QString searchStr = TmxCompendiumData::simplify(text);
+
+ //kdDebug(750) << "find best match for " << searchStr << endl;
+
+ while(!breakLoop)
+ {
+
+ // progress and loop control
+ if(stop)
+ {
+ breakLoop=true;
+ break;
+ }
+
+ i++;
+
+ if(i >= total)
+ {
+ breakLoop = true;
+ break;
+ }
+
+ if( (100*(i+1))%total < 100)
+ {
+ emit progress( (100*(i+1))/total);
+ }
+
+ // get a message from the catalog
+ QString origStr = data->msgid(i);
+ origStr = TmxCompendiumData::simplify(origStr);
+
+ // don't match too long strings for short search string
+ if (origStr.length() > 2*searchStr.length())
+ continue;
+ // kdDebug(750) << i << ": matching " << origStr << endl;
+
+ int ngram_result = ngramMatch(searchStr,origStr);
+
+ if (ngram_result > best_match) {
+ best_match = ngram_result;
+ best_matching = i;
+
+ // kdDebug(750) << "[" << ngram_result << "] " << text << "-"
+ // << origStr << endl;
+ }
+ }
+
+ if (best_match > LIM_NGRAM) {
+ score = best_match;
+ return data->msgstr(best_matching);
+ }
+
+ return QString::null;
+}
+
+
+void TmxCompendium::unregisterData()
+{
+ if(data)
+ {
+ disconnect(data, SIGNAL(progressStarts(const QString&)), this
+ , SIGNAL(progressStarts(const QString&)));
+ disconnect(data, SIGNAL(progressEnds()), this , SIGNAL(progressEnds()));
+ disconnect(data, SIGNAL(progress(int)), this , SIGNAL(progress(int)));
+
+ if(data->active())
+ {
+ disconnect(data,SIGNAL(progressEnds()),this,SLOT(recheckData()));
+ }
+
+ if(data->unregisterObject(this))
+ {
+ if(!data->active())
+ {
+ compendiumDict()->remove(realURL);
+ }
+ else
+ {
+ connect(data,SIGNAL(progressEnds()),this,SLOT(removeData()));
+ }
+ }
+
+ data=0;
+ }
+}
+
+void TmxCompendium::registerData()
+{
+ data = compendiumDict()->find(realURL);
+ if(!data)
+ {
+ data = new TmxCompendiumData;
+ compendiumDict()->insert(realURL,data);
+ }
+
+ data->registerObject(this);
+
+ if(data->active())
+ {
+ emit progressStarts(i18n("Loading PO compendium"));
+ }
+
+ connect(data, SIGNAL(progressStarts(const QString&)), this
+ , SIGNAL(progressStarts(const QString&)));
+ connect(data, SIGNAL(progressEnds()), this , SIGNAL(progressEnds()));
+ connect(data, SIGNAL(progress(int)), this , SIGNAL(progress(int)));
+}
+
+void TmxCompendium::removeData()
+{
+ const QObject *s=sender();
+ if(s && s->inherits("TmxCompendiumData"))
+ {
+ const TmxCompendiumData *d=static_cast<const TmxCompendiumData*>(s);
+ if(d)
+ {
+ QDictIterator<TmxCompendiumData> it(*compendiumDict());
+ while(it.current())
+ {
+ if(it.current() == d)
+ {
+ if(!d->hasObjects())
+ {
+ compendiumDict()->remove(it.currentKey());
+ }
+
+ break;
+ }
+
+ ++it;
+ }
+ }
+
+ }
+}
+
+QDict<TmxCompendiumData> *TmxCompendium::compendiumDict()
+{
+ if(!_compDict)
+ {
+ _compDict=compDataDeleter.setObject( new QDict<TmxCompendiumData> );
+ _compDict->setAutoDelete(true);
+ }
+
+ return _compDict;
+}
+
+
+
+#include "tmxcompendium.moc"
diff --git a/kbabel/kbabeldict/modules/tmx/tmxcompendium.desktop b/kbabel/kbabeldict/modules/tmx/tmxcompendium.desktop
new file mode 100644
index 00000000..cae7d333
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/tmxcompendium.desktop
@@ -0,0 +1,50 @@
+[Desktop Entry]
+Type=Service
+Name=TMX Compendium Module for KBabelDict
+Name[bg]=TMX компендиум за KBabelDict
+Name[bs]=Modul TMX kompendijuma za KBabelDict
+Name[ca]=Mòdul del Compendi TMX per a KBabelDict
+Name[cs]=Modul s TMX kompendiem pro KBabelDict
+Name[cy]=Modiwl Compendiwm TMX i KBabelDict
+Name[da]=TMX kompendium-module for KBabelDict
+Name[de]=TMX-Kompendium-Modul für KBabelDict
+Name[el]=Άρθρωμα επιτομής TMX για το KBabelDict
+Name[es]=Módulo de compendio TMX para KBabelDict
+Name[et]=KBabelDicti TMX kompendiumi moodul
+Name[eu]=TMX laburpen modulua KBabelDict-entzat
+Name[fa]=پیمانۀ مختصر TMX برای KBabelDict
+Name[fi]=KBabelDict-ohjelman TMX-kokoelmatiedostomoduuli
+Name[fr]=Module de fichier de référence des TMX pour KBabelDict
+Name[gl]=Módulo de compendio TMX para KBabelDict
+Name[hi]=के-बेबल-डिक्श के लिए टीएमएक्स कम्पेंडियम मॉड्यूल
+Name[hu]=TMX összefoglaló modul a KBabelDicthez
+Name[is]=TMX ágrips eining fyrir KBabel orðabókina
+Name[it]=Modulo TMX Compendium per KBabelDict
+Name[ja]=KBabelDict TMX 要約モジュール
+Name[ka]=TMX კონსპექტის მოდული KBabelDict-სთვის
+Name[kk]=KBabelDict-тың TMX аудармалар жиынтық модулі
+Name[lt]=KBabelDict TMX tekstyno modulis
+Name[ms]=Modul Kompendium TMX untuk KBabelDict
+Name[nb]=TMX-kompendium-modul for KBabelDict
+Name[nds]=TMX-Kompendiummoduul för KBabelDict
+Name[ne]=KBabelDict का लागि टीएमएक्स संक्षेप मोड्युल
+Name[nl]=TMX-samenvattingmodule voor KBabelDict
+Name[nn]=TMX-kompendiemodul for KBabelDict
+Name[pa]=ਕੇਬਬੇਲ-ਸ਼ਬਦਕੋਸ਼ ਲਈ TMX ਅਨੁਵਾਦ ਮੈਡੀਊਲ
+Name[pl]=Moduł Kompendium TMX dla KBabelDict
+Name[pt]=Módulo de Compêndio de TMX para o KBabelDict
+Name[pt_BR]=Módulo de Compêndio TMX para o KBabelDict
+Name[ru]=Модуль описания TMX для KBabelDict
+Name[sk]=TMX kompendium pre KBabelDict
+Name[sl]=Modul zbornika TMX za KBabelDict
+Name[sr]=Модул TMX зборника за KBabelDict
+Name[sr@Latn]=Modul TMX zbornika za KBabelDict
+Name[sv]=TMX-kompendiemodul för Kbabeldict
+Name[ta]=Kபாபேலுக்கான காம்பென்டியம் TMX கூறு
+Name[tg]=Модули тасвири TMX барои KBabelDict
+Name[tr]=KBabelDict için TMX Özet Modülü
+Name[uk]=Модуль збірки перекладів TMX для KBabelDict
+Name[zh_CN]=KBabelDict 的 TMX 概要词典模块
+Name[zh_TW]=KBabelDict TMX 摘要模組
+X-KDE-Library=kbabeldict_tmxcompendium
+ServiceTypes=KBabelDictModule
diff --git a/kbabel/kbabeldict/modules/tmx/tmxcompendium.h b/kbabel/kbabeldict/modules/tmx/tmxcompendium.h
new file mode 100644
index 00000000..9a2f8fba
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/tmxcompendium.h
@@ -0,0 +1,137 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2000 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2002 by Stanislav Visnovsky
+ <visnovsky@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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+
+#ifndef TMXCOMPENDIUM_H
+#define TMXCOMPENDIUM_H
+
+#include "tmxcompendiumdata.h"
+#include "searchengine.h"
+
+#include <qdict.h>
+#include <qfile.h>
+#include <qguardedptr.h>
+
+class TmxCompendiumPreferencesWidget;
+class KConfigBase;
+class QTimer;
+
+class TmxCompendium : public SearchEngine
+{
+ Q_OBJECT
+
+public:
+ TmxCompendium(QObject *parent=0, const char *name=0);
+ virtual ~TmxCompendium();
+
+ virtual bool isReady() const;
+
+ virtual QString translate(const QString& text, uint pluralForm);
+ virtual QString fuzzyTranslation(const QString& text, int &score, uint pluralForm);
+
+ virtual bool isSearching() const;
+
+ virtual void saveSettings(KConfigBase *config);
+ virtual void readSettings(KConfigBase *config);
+
+ virtual PrefWidget *preferencesWidget(QWidget *parent);
+
+ virtual const KAboutData *about() const;
+
+ virtual QString name() const;
+
+ virtual QString id() const;
+
+ virtual QString lastError();
+
+
+public slots:
+ virtual bool startSearch(const QString& text, uint pluralForm, const SearchFilter* filter);
+ virtual void stopSearch();
+ virtual void setLanguageCode(const QString& lang);
+
+protected slots:
+ /** reads the current settings from the preferences dialog */
+ void applySettings();
+
+ /** sets the current settings in the preferences dialog */
+ void restoreSettings();
+
+ void slotLoadCompendium();
+
+ void recheckData();
+ void removeData();
+
+protected:
+ void loadCompendium();
+ void addResult(SearchResult *);
+ QString maskString(QString string) const;
+
+ void registerData();
+ void unregisterData();
+
+private:
+ QGuardedPtr<TmxCompendiumPreferencesWidget> prefWidget;
+ TmxCompendiumData *data;
+ QTimer *loadTimer;
+
+ QString url;
+ QString realURL;
+ QString langCode;
+
+ bool caseSensitive;
+ bool wholeWords;
+
+ bool matchEqual;
+ bool matchIsContained;
+ bool matchContains;
+ bool matchWords;
+ bool matchNGram;
+
+ bool buildIndex;
+ uint freeMemDelay;
+
+ bool error;
+ QString errorMsg;
+
+ bool stop;
+ bool active;
+ bool initialized;
+ bool loading;
+
+ static QDict<TmxCompendiumData> *_compDict;
+ static QDict<TmxCompendiumData> *compendiumDict();
+};
+
+#endif
diff --git a/kbabel/kbabeldict/modules/tmx/tmxcompendiumdata.cpp b/kbabel/kbabeldict/modules/tmx/tmxcompendiumdata.cpp
new file mode 100644
index 00000000..3fa84aa4
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/tmxcompendiumdata.cpp
@@ -0,0 +1,308 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2001 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2002 by Stanislav Visnovsky
+ <visnovsky@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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+#include "tmxcompendiumdata.h"
+
+#include <qdom.h>
+#include <qfile.h>
+
+#include <tagextractor.h>
+#include <resources.h>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kio/netaccess.h>
+
+using namespace KBabel;
+
+TmxCompendiumData::TmxCompendiumData(QObject *parent)
+ : QObject(parent)
+ , _active(false)
+ , _error(false)
+ , _initialized(false)
+ , _exactDict(9887)
+ , _allDict(9887)
+ , _wordDict(9887)
+{
+ _exactDict.setAutoDelete(true);
+ _allDict.setAutoDelete(true);
+ _wordDict.setAutoDelete(true);
+}
+
+
+bool TmxCompendiumData::load(const KURL& url, const QString& language)
+{
+ kdDebug(KBABEL_SEARCH) << "Load " << url.url() << " in " << language << endl;
+ if(_active)
+ return false;
+
+
+ _error = false;
+ _active = true;
+
+ _exactDict.clear();
+ _allDict.clear();
+ _wordDict.clear();
+
+
+ emit progressStarts(i18n("Loading TMX compendium"));
+
+ QDomDocument doc( "mydocument" );
+
+ QString target;
+
+ if( KIO::NetAccess::download( url, target ) )
+ {
+ QFile f( target );
+ if ( !f.open( IO_ReadOnly ) )
+ {
+ _error = true;
+ _errorMsg = i18n( "Cannot open the file." );
+ }
+ else if ( !doc.setContent( &f ) ) {
+ _error = true;
+ _errorMsg = i18n( "Cannot parse XML data." );
+ }
+ f.close();
+ KIO::NetAccess::removeTempFile(target);
+ } else {
+ _error = true;
+ _errorMsg = i18n( "Cannot open the file." );
+ }
+
+ QDomElement docElem = doc.documentElement();
+
+ if( docElem.tagName() != "tmx" || !(docElem.hasAttribute("version")
+ && docElem.attribute("version") == "1.4" ) )
+ {
+ _error = true;
+ _errorMsg = i18n( "Unsupported format.");
+ }
+
+
+ if( _error )
+ {
+ _errorMsg = i18n("Error while trying to read file for TMX Compendium module:\n"
+ "%1\n"
+ "Reason: %2")
+ .arg(url.prettyURL()).arg(_errorMsg);
+
+ kdDebug(KBABEL_SEARCH) << "Error: " << _errorMsg << endl;
+
+ emit progressEnds();
+
+ _active = false;
+ _initialized=true;
+
+ return false;
+ }
+
+ emit progressStarts(i18n("Building indices"));
+
+ QDomNodeList tuTags = docElem.elementsByTagName("tu");
+ uint total = tuTags.count();
+
+ _originals.clear();
+ _originals.resize(total);
+ _translations.clear();
+ _translations.resize(total);
+
+ uint lastindex = 0;
+
+ for(uint i=0; i < total; i++)
+ {
+ if( (100*(i+1))%total < 100 )
+ {
+ emit progress((100*(i+1))/total);
+ kapp->processEvents(100);
+ }
+
+ QDomNodeList tuvTags = tuTags.item(i).toElement().elementsByTagName("tuv");
+ QString english, other;
+ for( uint j = 0 ; j < tuvTags.count() ; j++ )
+ {
+ QDomElement el = tuvTags.item(j).toElement();
+ if( el.attribute("xml:lang").upper() == "EN" ) english = el.text();
+ if( el.attribute("xml:lang").upper().startsWith(language.upper()) )
+ other = el.text();
+ }
+
+ if( !english.isEmpty() && !other.isEmpty() )
+ {
+ kdDebug(KBABEL_SEARCH) << english << " to " << lastindex << endl;
+ _originals[lastindex] = english;
+ _translations[lastindex] = other;
+
+ QString temp = english;
+
+ int *index = new int(lastindex);
+ _exactDict.insert(temp,index);
+
+ temp = simplify(temp);
+ temp = temp.lower();
+
+ if(!temp.isEmpty() && temp.length() > 1)
+ {
+ QValueList<int> *indexList=_allDict[temp];
+
+ if(!indexList)
+ {
+ indexList = new QValueList<int>;
+ _allDict.insert(temp,indexList);
+ }
+
+ indexList->append(lastindex);
+
+ QStringList wList = wordList(temp);
+ for ( QStringList::Iterator it = wList.begin()
+ ; it != wList.end(); ++it )
+ {
+ if( (*it).length() > 1)
+ {
+ indexList=_wordDict[*it];
+
+ if(!indexList)
+ {
+ indexList = new QValueList<int>;
+ _wordDict.insert(*it,indexList);
+ }
+
+ indexList->append(lastindex);
+ }
+ }
+ }
+ lastindex++;
+ }
+ }
+
+
+ // remove words, that are too frequent
+ uint max=_allDict.count()/10;
+ QDictIterator< QValueList<int> > it(_wordDict);
+ while ( it.current() )
+ {
+ if(it.current()->count() > max)
+ {
+ _wordDict.remove(it.currentKey());
+ }
+ else
+ {
+ ++it;
+ }
+ }
+
+ if( lastindex == 0)
+ {
+ _error = true;
+ _errorMsg = i18n("Empty database.");
+ }
+
+ kdDebug(KBABEL_SEARCH) << "load done" << endl;
+
+ _initialized=true;
+
+ emit progressEnds();
+
+ _active = false;
+
+ return true;
+}
+
+const int* TmxCompendiumData::exactDict(const QString& text) const
+{
+ return _exactDict[text];
+}
+
+const QValueList<int>* TmxCompendiumData::allDict(const QString& text) const
+{
+ return _allDict[text];
+}
+
+const QValueList<int>* TmxCompendiumData::wordDict(const QString& text) const
+{
+ return _wordDict[text];
+}
+
+const QString TmxCompendiumData::msgid(const int index) const
+{
+ return _originals[index];
+}
+
+const QString TmxCompendiumData::msgstr(const int index) const
+{
+ return _translations[index];
+}
+
+
+void TmxCompendiumData::registerObject(QObject *obj)
+{
+ if(!_registered.containsRef(obj))
+ _registered.append(obj);
+}
+
+bool TmxCompendiumData::unregisterObject(QObject *obj)
+{
+ _registered.removeRef(obj);
+
+ return _registered.count()==0;
+}
+
+bool TmxCompendiumData::hasObjects() const
+{
+ return _registered.count()==0;
+}
+
+QString TmxCompendiumData::simplify(const QString& string)
+{
+ QString result;
+
+ TagExtractor te;
+ te.setString(string);
+ result=te.plainString();
+
+ result=result.simplifyWhiteSpace();
+ result=result.stripWhiteSpace();
+
+ return result;
+}
+
+QStringList TmxCompendiumData::wordList(const QString& string)
+{
+ QString result=TmxCompendiumData::simplify(string);
+
+ return QStringList::split(' ',result);
+}
+
+#include "tmxcompendiumdata.moc"
diff --git a/kbabel/kbabeldict/modules/tmx/tmxcompendiumdata.h b/kbabel/kbabeldict/modules/tmx/tmxcompendiumdata.h
new file mode 100644
index 00000000..bc88a92e
--- /dev/null
+++ b/kbabel/kbabeldict/modules/tmx/tmxcompendiumdata.h
@@ -0,0 +1,106 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2001 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2002 by Stanislav Visnovsky
+ <visnovsky@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.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+#ifndef TMXCOMPENDIUMDATA_H
+#define TMXCOMPENDIUMDATA_H
+
+
+#include <kurl.h>
+#include <qdict.h>
+#include <qobject.h>
+#include <qstringlist.h>
+#include <qvaluelist.h>
+#include <qvaluevector.h>
+#include <qptrlist.h>
+
+class TmxCompendiumData : public QObject
+{
+ Q_OBJECT
+
+public:
+ TmxCompendiumData(QObject *parent=0);
+
+ bool load(const KURL& url, const QString& language);
+
+ const int *exactDict(const QString& text) const;
+ const QValueList<int> *allDict(const QString& text) const;
+ const QValueList<int> *wordDict(const QString& text) const;
+
+ const QString msgid(const int index) const;
+ const QString msgstr(const int index) const;
+ const int numberOfEntries() const { return _exactDict.count(); }
+
+ bool active() const { return _active; }
+ bool initialized() const { return _initialized; }
+ bool hasErrors() const { return _error; }
+ QString errorMsg() const { return _errorMsg; }
+
+ /** registers an object, that uses this data */
+ void registerObject(QObject *);
+ /**
+ * unregisters an object, that uses this data
+ *
+ * @return true, if this was the last object
+ */
+ bool unregisterObject(QObject *);
+
+ bool hasObjects() const;
+
+
+ static QString simplify(const QString& text);
+ static QStringList wordList(const QString& text);
+
+signals:
+ void progressStarts(const QString&);
+ void progressEnds();
+ void progress(int);
+
+
+private:
+ bool _active;
+ bool _error;
+ bool _initialized;
+ QString _errorMsg;
+
+ QDict<int> _exactDict;
+ QDict< QValueList<int> > _allDict;
+ QDict< QValueList<int> > _wordDict;
+
+ QValueVector<QString> _originals;
+ QValueVector<QString> _translations;
+
+ QPtrList<QObject> _registered;
+};
+
+#endif