diff options
Diffstat (limited to 'kvoctrain')
246 files changed, 43201 insertions, 0 deletions
diff --git a/kvoctrain/AUTHORS b/kvoctrain/AUTHORS new file mode 100644 index 00000000..f28bf63e --- /dev/null +++ b/kvoctrain/AUTHORS @@ -0,0 +1,10 @@ +Ewald Arnold + + original author + ewald@ewald-arnold.de (preferred) + http://www.ewald-arnold.de + +Peter Hedlund + + current maintainer + peter@peterandlinda.com
\ No newline at end of file diff --git a/kvoctrain/Makefile.am b/kvoctrain/Makefile.am new file mode 100644 index 00000000..a4d49867 --- /dev/null +++ b/kvoctrain/Makefile.am @@ -0,0 +1,20 @@ +SUBDIRS = kvoctrain + +EXTRA_DIST = AUTHORS kvoctrain.kdevprj + +AUTOMAKE_OPTIONS = foreign + +install-data-local: + +clean_distdir: + -rm -rf $(distdir) + + +lsm : $(PACKAGE)/$(PACKAGE).lsm.tpl $(distdir).tar.bz2 + let "_arclen=`ls -l -d -G $(distdir).tar.bz2 | cut -b23-32`/1000+1";\ + sed $(PACKAGE)/$(PACKAGE).lsm.tpl >$(PACKAGE)-$(VERSION).lsm -e s/=VERSION=/$(VERSION)/g -e "s,=DATE=,`date +"%Y %B %d."`,g" -e "s,=ARCLEN=,$$_arclen,g" + cp $(PACKAGE)-$(VERSION).lsm $(PACKAGE).lsm + + + +include ../admin/Doxyfile.am diff --git a/kvoctrain/kvoctrain/Makefile.am b/kvoctrain/kvoctrain/Makefile.am new file mode 100644 index 00000000..b8b4ed01 --- /dev/null +++ b/kvoctrain/kvoctrain/Makefile.am @@ -0,0 +1,69 @@ +METASOURCES = AUTO + +kvoctrain_SOURCES = kva_io.cpp kvoctrain.cpp kvoctrainview.cpp main.cpp \ + kva_init.cpp kva_config.cpp kva_header.cpp kva_clip.cpp kva_query.cpp \ + kvoctraintable.cpp kvoctraintableitem.cpp kvtnewstuff.cpp + +kvoctrain_COMPILE_FIRST = common-dialogs/prefs.h + +spotlight2kvtml_SOURCES = spotlight2kvtml.cpp + +spotlight2kvtml_LDADD = $(LIB_KDECORE) + +kvoctrain_LDADD = ./docprop-dialogs/libdocpropdlg.la \ + ./entry-dialogs/libentrydlg.la ./kvt-core/libkvoctraincore.la ./kvt-core/kvt-xml/libkvtxml.la \ + ./query-dialogs/libquerydlg.la ./statistik-dialogs/libstatdlg.la ./common-dialogs/libcommondlg.la \ + -lknewstuff $(LIB_KDEPRINT) + +EXTRA_DIST = kvoctrainui.rc + +SUBDIRS = common-dialogs query-dialogs docprop-dialogs entry-dialogs \ + statistik-dialogs kvt-core examples pics + + + +rcdir = $(kde_datadir)/kvoctrain +rc_DATA = kvoctrainui.rc +kde_conf_DATA = kvoctrainrc +xdg_apps_DATA = kvoctrain.desktop + +mimetypetextdata_DATA = x-kvtml.desktop +mimetypetextdatadir = $(kde_mimedir)/text + +install-data-local: + $(mkinstalldirs) $(DESTDIR)$(mimetypetextdatadir) + +INCLUDES = -I$(srcdir)/.. -I$(srcdir)/kvt-core -Icommon-dialogs \ + -I$(srcdir)/common-dialogs -I$(srcdir)/docprop-dialogs -Idocprop-dialogs -I$(srcdir)/query-dialogs \ + -Iquery-dialogs -I$(srcdir)/entry-dialogs -Ientry-dialogs $(all_includes) + +bin_PROGRAMS = kvoctrain spotlight2kvtml + +# the library search path. +kvoctrain_LDFLAGS = $(all_libraries) $(KDE_RPATH) +spotlight2kvtml_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +CLEANFILES = *.i.c + +i18n_files= query-dialogs/*.cpp \ + entry-dialogs/*.cpp \ + common-dialogs/*.cpp \ + docprop-dialogs/*.cpp \ + statistik-dialogs/*.cpp \ + kvt-core/*.cpp \ + kvt-core/kvt-xml/*.cpp \ + $(spotlight2kvtml_SOURCES) \ + $(kvoctrain_SOURCES) \ + kvt-core/*.h \ + kv_resource.h + +messages: rc.cpp + $(EXTRACTRC) `find . -name "*.ui"` >> rc.cpp + $(XGETTEXT) `ls $(i18n_files)` rc.cpp -kI18N_NOOP2 -o $(podir)/kvoctrain.pot + -rm rc.cpp + +messages-local: + $(MAKE) messages EXTRACTRC=extractrc podir=. XGETTEXT="xgettext -C -kI18N_NOOP -ki18n" + iconv -futf-8 -tutf-16 kvoctrain.pot > /dev/null + +noinst_HEADERS = kvtnewstuff.h diff --git a/kvoctrain/kvoctrain/common-dialogs/Makefile.am b/kvoctrain/kvoctrain/common-dialogs/Makefile.am new file mode 100644 index 00000000..1bf3dd20 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/Makefile.am @@ -0,0 +1,18 @@ +INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../kvt-core $(all_includes) + +noinst_LTLIBRARIES = libcommondlg.la + +libcommondlg_la_SOURCES = ProgressDlg.cpp ProgressDlgForm.ui \ + languagesettings.kcfgc prefs.kcfgc presettings.kcfgc kvoctrainprefs.cpp kvoctrainprefs.h \ + generaloptionsbase.ui generaloptions.cpp viewoptionsbase.ui viewoptions.cpp \ + pasteoptionsbase.ui pasteoptions.cpp blockoptionsbase.ui groupoptionsbase.ui \ + languageoptionsbase.ui queryoptionsbase.ui thresholdoptionsbase.ui blockoptions.cpp \ + groupoptions.cpp languageoptions.cpp queryoptions.cpp thresholdoptions.cpp \ + profilesdialog.cpp + +METASOURCES = AUTO + +kde_kcfg_DATA = kvoctrain.kcfg languagesettings.kcfg presettings.kcfg + +noinst_HEADERS = generaloptions.h viewoptions.h pasteoptions.h blockoptions.h \ + groupoptions.h languageoptions.h queryoptions.h thresholdoptions.h profilesdialog.h diff --git a/kvoctrain/kvoctrain/common-dialogs/ProgressDlg.cpp b/kvoctrain/kvoctrain/common-dialogs/ProgressDlg.cpp new file mode 100644 index 00000000..96d9c23e --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/ProgressDlg.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** + + progress dialog + + ----------------------------------------------------------------------- + + begin : Mon Aug 16 17:41:11 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#undef stack +#include <kvoctraindoc.h> +#include "ProgressDlg.h" + +#include <qprogressbar.h> +#include <qlabel.h> + +#include <kstandarddirs.h> + + +ProgressDlg::ProgressDlg(const QString &doctitle, const QString &filename, const QString &title, QWidget* parent, const char* name) + : ProgressDlgForm( parent, name ) +{ + doc = 0; + setCaption (title); + l_title->setText (doctitle); + l_file->setText (filename); + progress-> setTotalSteps(100); +} + + +void ProgressDlg::setValue( kvoctrainDoc *new_doc, int val) +{ + progress->setProgress(val); + if (doc == 0 && new_doc != 0) + { + doc = new_doc; + l_title->setText (doc->getTitle()); + l_file->setText (doc->URL().fileName()); + } +} + + +#include "ProgressDlg.moc" diff --git a/kvoctrain/kvoctrain/common-dialogs/ProgressDlg.h b/kvoctrain/kvoctrain/common-dialogs/ProgressDlg.h new file mode 100644 index 00000000..6be7a8a6 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/ProgressDlg.h @@ -0,0 +1,56 @@ +/*************************************************************************** + + progress dialog + + ----------------------------------------------------------------------- + + begin : Mon Aug 16 17:41:11 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 ProgressDlg_included +#define ProgressDlg_included + +#include "ProgressDlgForm.h" + +class kvoctrainDoc; + +class ProgressDlg : public ProgressDlgForm +{ + Q_OBJECT + +public: + + ProgressDlg + ( + const QString &doctitle, + const QString &filename, + const QString &title, + QWidget* parent = NULL, + const char* name = NULL + ); + + public slots: + void setValue( kvoctrainDoc *doc, int ); + + protected: + kvoctrainDoc *doc; +}; +#endif // ProgressDlg_included diff --git a/kvoctrain/kvoctrain/common-dialogs/ProgressDlgForm.ui b/kvoctrain/kvoctrain/common-dialogs/ProgressDlgForm.ui new file mode 100644 index 00000000..2c5d44cb --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/ProgressDlgForm.ui @@ -0,0 +1,142 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ProgressDlgForm</class> +<widget class="QDialog"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>127</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>400</width> + <height>120</height> + </size> + </property> + <property name="caption"> + <string>-</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QFrame" row="0" column="0"> + <property name="name"> + <cstring>Frame3</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + </font> + </property> + <property name="text"> + <string>Filename:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="font"> + <font> + </font> + </property> + <property name="text"> + <string>Title:</string> + </property> + </widget> + <widget class="QLabel" row="0" column="1"> + <property name="name"> + <cstring>l_file</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>file.kvtml</string> + </property> + </widget> + <widget class="QLabel" row="1" column="1"> + <property name="name"> + <cstring>l_title</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>title</string> + </property> + </widget> + </grid> + </widget> + <spacer row="1" column="0"> + <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> + <widget class="QProgressBar" row="2" column="0"> + <property name="name"> + <cstring>progress</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>340</width> + <height>22</height> + </size> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/common-dialogs/blockoptions.cpp b/kvoctrain/kvoctrain/common-dialogs/blockoptions.cpp new file mode 100644 index 00000000..3a52d912 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/blockoptions.cpp @@ -0,0 +1,359 @@ +/*************************************************************************** + + blocking options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qcombobox.h> +#include <qcheckbox.h> + +#include <klocale.h> +#include <kmessagebox.h> + +#include "blockoptions.h" +#include "prefs.h" + +struct ListRef +{ + const char *text; + long int num; +}; + +static ListRef date_itemlist [] = +{ + {I18N_NOOP("Do not Care"), 0}, + + {I18N_NOOP("30 Min"), 30*60}, + {I18N_NOOP("1 Hour"), 1 * 60*60}, + {I18N_NOOP("2 Hours"), 2 * 60*60}, + {I18N_NOOP("4 Hours"), 4 * 60*60}, + {I18N_NOOP("8 Hours"), 8 * 60*60}, + {I18N_NOOP("12 Hours"), 12 * 60*60}, + {I18N_NOOP("18 Hours"), 18 * 60*60}, + + {I18N_NOOP("1 Day"), 1 * 60*60*24}, + {I18N_NOOP("2 Days"), 2 * 60*60*24}, + {I18N_NOOP("3 Days"), 3 * 60*60*24}, + {I18N_NOOP("4 Days"), 4 * 60*60*24}, + {I18N_NOOP("5 Days"), 5 * 60*60*24}, + {I18N_NOOP("6 Days"), 6 * 60*60*24}, + + {I18N_NOOP("1 Week"), 1 * 60*60*24*7}, + {I18N_NOOP("2 Weeks"), 2 * 60*60*24*7}, + {I18N_NOOP("3 Weeks"), 3 * 60*60*24*7}, + {I18N_NOOP("4 Weeks"), 4 * 60*60*24*7}, + + {I18N_NOOP("1 Month"), 1 * 60*60*24*30}, + {I18N_NOOP("2 Months"), 2 * 60*60*24*30}, + {I18N_NOOP("3 Months"), 3 * 60*60*24*30}, + {I18N_NOOP("4 Months"), 4 * 60*60*24*30}, + {I18N_NOOP("5 Months"), 5 * 60*60*24*30}, + {I18N_NOOP("6 Months"), 6 * 60*60*24*30}, + {I18N_NOOP("10 Months"), 10 * 60*60*24*30}, + {I18N_NOOP("12 Months"), 12 * 60*60*24*30}, + {0 , 0} +}; + + +BlockOptions::BlockOptions(QWidget* parent, const char* name, WFlags fl) +: BlockOptionsBase(parent, name, fl) +{ + connect(expire1, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(block1, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(expire2, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(block2, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(expire3, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(block3, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(expire4, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(block4, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(expire5, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(block5, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(expire6, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(block6, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(expire7, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + connect(block7, SIGNAL(activated(int)), this, SLOT(slotComboBoxActivated(int))); + + connect(kcfg_Block, SIGNAL(toggled(bool)), this, SLOT(slotBlockToggled(bool))); + connect(kcfg_Expire, SIGNAL(toggled(bool)), this, SLOT(slotExpireToggled(bool))); + + fillWidgets(); + updateWidgets(); +} + +void BlockOptions::fillWidgets() +{ + fillComboBox(block1); + fillComboBox(block2); + fillComboBox(block3); + fillComboBox(block4); + fillComboBox(block5); + fillComboBox(block6); + fillComboBox(block7); + + m_blockComboList.append(block1); + m_blockComboList.append(block2); + m_blockComboList.append(block3); + m_blockComboList.append(block4); + m_blockComboList.append(block5); + m_blockComboList.append(block6); + m_blockComboList.append(block7); + + fillComboBox(expire1); + fillComboBox(expire2); + fillComboBox(expire3); + fillComboBox(expire4); + fillComboBox(expire5); + fillComboBox(expire6); + fillComboBox(expire7); + + m_expireComboList.append(expire1); + m_expireComboList.append(expire2); + m_expireComboList.append(expire3); + m_expireComboList.append(expire4); + m_expireComboList.append(expire5); + m_expireComboList.append(expire6); + m_expireComboList.append(expire7); +} + +void BlockOptions::updateWidgets() +{ + updateComboBox(Prefs::blockItem(KV_LEV1_GRADE), block1); + updateComboBox(Prefs::blockItem(KV_LEV2_GRADE), block2); + updateComboBox(Prefs::blockItem(KV_LEV3_GRADE), block3); + updateComboBox(Prefs::blockItem(KV_LEV4_GRADE), block4); + updateComboBox(Prefs::blockItem(KV_LEV5_GRADE), block5); + updateComboBox(Prefs::blockItem(KV_LEV6_GRADE), block6); + updateComboBox(Prefs::blockItem(KV_LEV7_GRADE), block7); + + updateComboBox(Prefs::expireItem(KV_LEV1_GRADE), expire1); + updateComboBox(Prefs::expireItem(KV_LEV2_GRADE), expire2); + updateComboBox(Prefs::expireItem(KV_LEV3_GRADE), expire3); + updateComboBox(Prefs::expireItem(KV_LEV4_GRADE), expire4); + updateComboBox(Prefs::expireItem(KV_LEV5_GRADE), expire5); + updateComboBox(Prefs::expireItem(KV_LEV6_GRADE), expire6); + updateComboBox(Prefs::expireItem(KV_LEV7_GRADE), expire7); + + bool block = Prefs::block(); + kcfg_Block->setChecked(block); + block1->setEnabled(block); + block2->setEnabled(block); + block3->setEnabled(block); + block4->setEnabled(block); + block5->setEnabled(block); + block6->setEnabled(block); + block7->setEnabled(block); + + bool expire = Prefs::expire(); + kcfg_Expire->setChecked(expire); + expire1->setEnabled(expire); + expire2->setEnabled(expire); + expire3->setEnabled(expire); + expire4->setEnabled(expire); + expire5->setEnabled(expire); + expire6->setEnabled(expire); + expire7->setEnabled(expire); + + emit blockExpireChanged(block, expire); +} + +void BlockOptions::fillComboBox(QComboBox * cb) +{ + ListRef *ref = date_itemlist; + + cb->clear(); + while (ref->text != 0) + { + cb->insertItem (i18n(ref->text)); + ref++; + } +} + +void BlockOptions::updateComboBox(int value, QComboBox * cb) +{ + ListRef *ref = date_itemlist; + int index = 0; + + while (ref->text != 0) + { + if (value == ref->num) + index = ref - date_itemlist; + ref++; + } + cb->setCurrentItem(index); +} + +void BlockOptions::slotBlockToggled(bool state) +{ + block1->setEnabled(state); + block2->setEnabled(state); + block3->setEnabled(state); + block4->setEnabled(state); + block5->setEnabled(state); + block6->setEnabled(state); + block7->setEnabled(state); + emit blockExpireChanged(state, kcfg_Expire->isChecked()); +} + +void BlockOptions::slotExpireToggled(bool state) +{ + expire1->setEnabled(state); + expire2->setEnabled(state); + expire3->setEnabled(state); + expire4->setEnabled(state); + expire5->setEnabled(state); + expire6->setEnabled(state); + expire7->setEnabled(state); + emit blockExpireChanged(kcfg_Block->isChecked(), state); +} + +void BlockOptions::slotComboBoxActivated(int) +{ + emit widgetModified(); + checkValidity(); +} + + +void BlockOptions::checkValidity() +{ + QString message; + bool found = false; + for (int i = 1; i <= 6; i++) + { + if (kcfg_Block->isChecked()) + { + /*if(Prefs::blockItem(i-1) != 0 && + Prefs::blockItem(i) != 0 && + Prefs::blockItem(i-1) >= Prefs::blockItem(i))*/ + if (date_itemlist[m_blockComboList[i - 1]->currentItem()].num != 0 && + date_itemlist[m_blockComboList[i]->currentItem()].num != 0 && + date_itemlist[m_blockComboList[i - 1]->currentItem()].num >= date_itemlist[m_blockComboList[i]->currentItem()].num) + { + QString format; + if (!found) + message.append(i18n("Illogical blocking times.\n")); + found = true; + message.append(i18n("The time for level %1 should be lower than the time for level %2.\n").arg(i).arg(i + 1)); + } + } + } + + for (int i = 1; i <= 6; i++) + { + found = false; + if (kcfg_Expire->isChecked()) + { + if (date_itemlist[m_expireComboList[i - 1]->currentItem()].num != 0 && + date_itemlist[m_expireComboList[i]->currentItem()].num != 0 && + date_itemlist[m_expireComboList[i - 1]->currentItem()].num >= + date_itemlist[m_expireComboList[i]->currentItem()].num) + { + QString format; + if (!found) + message.append(i18n("\nIllogical expiration times.\n")); + found = true; + message.append(i18n("The time for level %1 should be lower than the time for level %2.\n").arg(i).arg(i + 1)); + } + } + } + + if (message.length() == 0) + { + found = false; + for (int i = 0; i <= 6; i++) + { + if (kcfg_Block->isChecked() && + kcfg_Expire->isChecked() && + date_itemlist[m_expireComboList[i]->currentItem()].num != 0 && + date_itemlist[m_blockComboList[i]->currentItem()].num != 0 && + date_itemlist[m_blockComboList[i]->currentItem()].num >= date_itemlist[m_expireComboList[i]->currentItem()].num) + { + QString format; + if (!found) + message.append(i18n("\nIllogical blocking vs. expiration times.\n")); + found = true; + message.append(i18n("The blocking time at level %1 should be lower than the expiration time.\n").arg(i + 1)); + } + } + } + + if (message.length() != 0) + KMessageBox::sorry(this, message, i18n("Illogical Values")); +} + + +bool BlockOptions::isDefault() +{ + return date_itemlist[block7->currentItem()].num == 5184000 && + date_itemlist[block6->currentItem()].num == 2592000 && + date_itemlist[block5->currentItem()].num == 1209600 && + date_itemlist[block4->currentItem()].num == 604800 && + date_itemlist[block3->currentItem()].num == 345600 && + date_itemlist[block2->currentItem()].num == 172800 && + date_itemlist[block1->currentItem()].num == 86400 && + date_itemlist[expire7->currentItem()].num == 10368000 && + date_itemlist[expire6->currentItem()].num == 5184000 && + date_itemlist[expire5->currentItem()].num == 2592000 && + date_itemlist[expire4->currentItem()].num == 1209600 && + date_itemlist[expire3->currentItem()].num == 604800 && + date_itemlist[expire2->currentItem()].num == 345600 && + date_itemlist[expire1->currentItem()].num == 172800; +} + + +void BlockOptions::updateSettings() +{ + Prefs::setBlockItem(KV_LEV7_GRADE, date_itemlist[block7->currentItem()].num); + Prefs::setBlockItem(KV_LEV6_GRADE, date_itemlist[block6->currentItem()].num); + Prefs::setBlockItem(KV_LEV5_GRADE, date_itemlist[block5->currentItem()].num); + Prefs::setBlockItem(KV_LEV4_GRADE, date_itemlist[block4->currentItem()].num); + Prefs::setBlockItem(KV_LEV3_GRADE, date_itemlist[block3->currentItem()].num); + Prefs::setBlockItem(KV_LEV2_GRADE, date_itemlist[block2->currentItem()].num); + Prefs::setBlockItem(KV_LEV1_GRADE, date_itemlist[block1->currentItem()].num); + + Prefs::setExpireItem(KV_LEV7_GRADE, date_itemlist[expire7->currentItem()].num); + Prefs::setExpireItem(KV_LEV6_GRADE, date_itemlist[expire6->currentItem()].num); + Prefs::setExpireItem(KV_LEV5_GRADE, date_itemlist[expire5->currentItem()].num); + Prefs::setExpireItem(KV_LEV4_GRADE, date_itemlist[expire4->currentItem()].num); + Prefs::setExpireItem(KV_LEV3_GRADE, date_itemlist[expire3->currentItem()].num); + Prefs::setExpireItem(KV_LEV2_GRADE, date_itemlist[expire2->currentItem()].num); + Prefs::setExpireItem(KV_LEV1_GRADE, date_itemlist[expire1->currentItem()].num); +} + +bool BlockOptions::hasChanged() +{ + return date_itemlist[block7->currentItem()].num != Prefs::blockItem(KV_LEV7_GRADE) || + date_itemlist[block6->currentItem()].num != Prefs::blockItem(KV_LEV6_GRADE) || + date_itemlist[block5->currentItem()].num != Prefs::blockItem(KV_LEV5_GRADE) || + date_itemlist[block4->currentItem()].num != Prefs::blockItem(KV_LEV4_GRADE) || + date_itemlist[block3->currentItem()].num != Prefs::blockItem(KV_LEV3_GRADE) || + date_itemlist[block2->currentItem()].num != Prefs::blockItem(KV_LEV2_GRADE) || + date_itemlist[block1->currentItem()].num != Prefs::blockItem(KV_LEV1_GRADE) || + date_itemlist[expire7->currentItem()].num != Prefs::expireItem(KV_LEV7_GRADE) || + date_itemlist[expire6->currentItem()].num != Prefs::expireItem(KV_LEV6_GRADE) || + date_itemlist[expire5->currentItem()].num != Prefs::expireItem(KV_LEV5_GRADE) || + date_itemlist[expire4->currentItem()].num != Prefs::expireItem(KV_LEV4_GRADE) || + date_itemlist[expire3->currentItem()].num != Prefs::expireItem(KV_LEV3_GRADE) || + date_itemlist[expire2->currentItem()].num != Prefs::expireItem(KV_LEV2_GRADE) || + date_itemlist[expire1->currentItem()].num != Prefs::expireItem(KV_LEV1_GRADE); +} + +#include "blockoptions.moc" diff --git a/kvoctrain/kvoctrain/common-dialogs/blockoptions.h b/kvoctrain/kvoctrain/common-dialogs/blockoptions.h new file mode 100644 index 00000000..366d2eb2 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/blockoptions.h @@ -0,0 +1,67 @@ +/*************************************************************************** + + blocking options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 BLOCKOPTIONS_H +#define BLOCKOPTIONS_H + +#include <qvaluelist.h> + +#include "blockoptionsbase.h" +#include "QueryManager.h" + +class QComboBox; + +class BlockOptions : public BlockOptionsBase +{ + Q_OBJECT + +public: + BlockOptions(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + void updateWidgets(); + bool hasChanged(); + bool isDefault(); + void updateSettings(); + +signals: + void widgetModified(); + void blockExpireChanged(bool block, bool expire); + +protected slots: + void slotBlockToggled(bool); + void slotExpireToggled(bool); + void slotComboBoxActivated(int); + +private: + void fillWidgets(); + void fillComboBox(QComboBox *); + void updateComboBox(int, QComboBox *); + void checkValidity(); + + QValueList<QComboBox *> m_blockComboList; + QValueList<QComboBox *> m_expireComboList; +}; + +#endif + diff --git a/kvoctrain/kvoctrain/common-dialogs/blockoptionsbase.ui b/kvoctrain/kvoctrain/common-dialogs/blockoptionsbase.ui new file mode 100644 index 00000000..2bd5c449 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/blockoptionsbase.ui @@ -0,0 +1,272 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>BlockOptionsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>BlockOptionsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>402</width> + <height>255</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QComboBox" row="6" column="2"> + <property name="name"> + <cstring>expire2</cstring> + </property> + </widget> + <widget class="QComboBox" row="1" column="2"> + <property name="name"> + <cstring>expire7</cstring> + </property> + </widget> + <widget class="QLabel" row="6" column="0"> + <property name="name"> + <cstring>l_lev2</cstring> + </property> + <property name="text"> + <string>Level &2:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>block2</cstring> + </property> + </widget> + <widget class="QComboBox" row="7" column="2"> + <property name="name"> + <cstring>expire1</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>l_lev5</cstring> + </property> + <property name="text"> + <string>Level &5:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>block5</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>l_lev6</cstring> + </property> + <property name="text"> + <string>Level &6:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>block6</cstring> + </property> + </widget> + <widget class="QCheckBox" row="0" column="2"> + <property name="name"> + <cstring>kcfg_Expire</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>E&xpiring</string> + </property> + </widget> + <widget class="QComboBox" row="4" column="1"> + <property name="name"> + <cstring>block4</cstring> + </property> + </widget> + <widget class="QCheckBox" row="0" column="1"> + <property name="name"> + <cstring>kcfg_Block</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Bl&ocking</string> + </property> + </widget> + <widget class="QComboBox" row="7" column="1"> + <property name="name"> + <cstring>block1</cstring> + </property> + </widget> + <widget class="QComboBox" row="1" column="1"> + <property name="name"> + <cstring>block7</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QComboBox" row="2" column="2"> + <property name="name"> + <cstring>expire6</cstring> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>l_lev4</cstring> + </property> + <property name="text"> + <string>Level &4:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>block4</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>l_lev7</cstring> + </property> + <property name="text"> + <string>Level &7:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>block7</cstring> + </property> + </widget> + <widget class="QComboBox" row="3" column="2"> + <property name="name"> + <cstring>expire5</cstring> + </property> + </widget> + <widget class="QComboBox" row="5" column="1"> + <property name="name"> + <cstring>block3</cstring> + </property> + </widget> + <widget class="QComboBox" row="6" column="1"> + <property name="name"> + <cstring>block2</cstring> + </property> + </widget> + <widget class="QComboBox" row="4" column="2"> + <property name="name"> + <cstring>expire4</cstring> + </property> + </widget> + <widget class="QLabel" row="7" column="0"> + <property name="name"> + <cstring>l_lev1</cstring> + </property> + <property name="text"> + <string>Level &1:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>block1</cstring> + </property> + </widget> + <spacer row="0" column="0"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Minimum</enum> + </property> + <property name="sizeHint"> + <size> + <width>41</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QComboBox" row="5" column="2"> + <property name="name"> + <cstring>expire3</cstring> + </property> + </widget> + <widget class="QComboBox" row="3" column="1"> + <property name="name"> + <cstring>block5</cstring> + </property> + </widget> + <widget class="QComboBox" row="2" column="1"> + <property name="name"> + <cstring>block6</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>l_lev3</cstring> + </property> + <property name="text"> + <string>Level &3:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>block3</cstring> + </property> + </widget> + <spacer row="8" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>spacer10</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>380</width> + <height>30</height> + </size> + </property> + </spacer> + </grid> +</widget> +<tabstops> + <tabstop>kcfg_Block</tabstop> + <tabstop>kcfg_Expire</tabstop> + <tabstop>block7</tabstop> + <tabstop>expire7</tabstop> + <tabstop>block6</tabstop> + <tabstop>expire6</tabstop> + <tabstop>block5</tabstop> + <tabstop>expire5</tabstop> + <tabstop>block4</tabstop> + <tabstop>expire4</tabstop> + <tabstop>block3</tabstop> + <tabstop>expire3</tabstop> + <tabstop>block2</tabstop> + <tabstop>expire2</tabstop> + <tabstop>block1</tabstop> + <tabstop>expire1</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/common-dialogs/generaloptions.cpp b/kvoctrain/kvoctrain/common-dialogs/generaloptions.cpp new file mode 100644 index 00000000..ba3f0b14 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/generaloptions.cpp @@ -0,0 +1,40 @@ +/*************************************************************************** + + general options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Mar 29 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qcheckbox.h> + +#include <knuminput.h> + +#include "generaloptions.h" + +GeneralOptions::GeneralOptions(QWidget* parent, const char* name, WFlags fl) +: GeneralOptionsBase(parent,name,fl) +{ + kcfg_BackupTime->setEnabled(kcfg_AutoBackup->isChecked()); +} + + +#include "generaloptions.moc" + diff --git a/kvoctrain/kvoctrain/common-dialogs/generaloptions.h b/kvoctrain/kvoctrain/common-dialogs/generaloptions.h new file mode 100644 index 00000000..c4c7cc0b --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/generaloptions.h @@ -0,0 +1,40 @@ +/*************************************************************************** + + general options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Mar 29 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 GENERALOPTIONS_H +#define GENERALOPTIONS_H + +#include "generaloptionsbase.h" + +class GeneralOptions : public GeneralOptionsBase +{ + Q_OBJECT + +public: + GeneralOptions(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); +}; + +#endif + diff --git a/kvoctrain/kvoctrain/common-dialogs/generaloptionsbase.ui b/kvoctrain/kvoctrain/common-dialogs/generaloptionsbase.ui new file mode 100644 index 00000000..3e8b5425 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/generaloptionsbase.ui @@ -0,0 +1,189 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>GeneralOptionsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>GeneralOptionsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>332</width> + <height>369</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QCheckBox" row="0" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>kcfg_AutoSave</cstring> + </property> + <property name="text"> + <string>&Save vocabularies automatically on close and quit</string> + </property> + <property name="toolTip" stdset="0"> + <string>Allow automatic saving of your work</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Your work will be automatically saved if you check this option</string> + </property> + </widget> + <widget class="QCheckBox" row="1" column="0"> + <property name="name"> + <cstring>kcfg_AutoBackup</cstring> + </property> + <property name="text"> + <string>&Create a backup every</string> + </property> + <property name="toolTip" stdset="0"> + <string>Allow automatic saving of your work</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Your work will be automatically saved if you check this option</string> + </property> + </widget> + <widget class="KIntSpinBox" row="1" column="1"> + <property name="name"> + <cstring>kcfg_BackupTime</cstring> + </property> + <property name="maxValue"> + <number>120</number> + </property> + <property name="minValue"> + <number>5</number> + </property> + </widget> + <widget class="QLabel" row="1" column="2"> + <property name="name"> + <cstring>lblBackupInterva</cstring> + </property> + <property name="text"> + <string>minutes</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kIntSpinBox1</cstring> + </property> + </widget> + <widget class="QCheckBox" row="2" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>kcfg_SmartAppend</cstring> + </property> + <property name="text"> + <string>Smart a&ppending</string> + </property> + <property name="toolTip" stdset="0"> + <string>If checked, the entry dialog will popup repeatedly</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If this feature is activated, you will repeatedly be prompted with the entry dialog. After entering the first original you have to enter the corresponding translations. Afterwards you proceed with the next original and its translations until you stop by pressing the ESC key.</string> + </property> + </widget> + <widget class="QCheckBox" row="3" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>kcfg_AutoEntryApply</cstring> + </property> + <property name="text"> + <string>Appl&y changes without asking</string> + </property> + <property name="toolTip" stdset="0"> + <string>Your changes will be applied automatically.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If checked, you will not be asked if you really want this change; it will be applied automatically.</string> + </property> + </widget> + <widget class="QButtonGroup" row="4" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>kcfg_HeaderResizeMode</cstring> + </property> + <property name="title"> + <string>Column Resizing</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>hb_auto</cstring> + </property> + <property name="text"> + <string>A&utomatic</string> + </property> + <property name="toolTip" stdset="0"> + <string>KVocTrain determines the resizing of the columns</string> + </property> + <property name="whatsThis" stdset="0"> + <string>KVocTrain makes each column the same width except the leftmost with the lesson names, which is half the size of the others. The second column, which contains the picture that describes the state of the row, has a fixed width.</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>hb_percent</cstring> + </property> + <property name="text"> + <string>P&ercentage</string> + </property> + <property name="toolTip" stdset="0"> + <string>The columns resize using the same factor that the window is resized to.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If this is checked, the columns resize by the same amount as the window</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>hb_fixed</cstring> + </property> + <property name="text"> + <string>&Fixed</string> + </property> + <property name="toolTip" stdset="0"> + <string>There is no resizing of the columns</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When checked, the columns are not resized</string> + </property> + </widget> + </vbox> + </widget> + <spacer row="5" column="0"> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>51</width> + <height>123</height> + </size> + </property> + </spacer> + </grid> +</widget> +<connections> + <connection> + <sender>kcfg_AutoBackup</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_BackupTime</receiver> + <slot>setEnabled(bool)</slot> + </connection> +</connections> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>knuminput.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/common-dialogs/groupoptions.cpp b/kvoctrain/kvoctrain/common-dialogs/groupoptions.cpp new file mode 100644 index 00000000..fae9cfa4 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/groupoptions.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** + + group options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qpushbutton.h> +#include <qcombobox.h> + +#include "groupoptions.h" + +GroupOptions::GroupOptions(QWidget* parent, const char* name, WFlags fl) +: GroupOptionsBase(parent,name,fl) +{ + +} + +void GroupOptions::updateButtons() +{ + ps_del->setEnabled (ps_name->count() > 0); + ps_store->setEnabled (ps_name->count() > 0); + ps_recall->setEnabled (ps_name->count() > 0); + ps_name->setEnabled (ps_name->count() > 0); +} + +#include "groupoptions.moc" + diff --git a/kvoctrain/kvoctrain/common-dialogs/groupoptions.h b/kvoctrain/kvoctrain/common-dialogs/groupoptions.h new file mode 100644 index 00000000..bc8993af --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/groupoptions.h @@ -0,0 +1,42 @@ +/*************************************************************************** + + group options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 GROUPOPTIONS_H +#define GROUPOPTIONS_H + +#include "groupoptionsbase.h" + +class GroupOptions : public GroupOptionsBase +{ + Q_OBJECT + +public: + GroupOptions(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + + void updateButtons(); +}; + +#endif + diff --git a/kvoctrain/kvoctrain/common-dialogs/groupoptionsbase.ui b/kvoctrain/kvoctrain/common-dialogs/groupoptionsbase.ui new file mode 100644 index 00000000..ee90fe3a --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/groupoptionsbase.ui @@ -0,0 +1,147 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>GroupOptionsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>GroupOptionsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>336</width> + <height>93</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>l_name</cstring> + </property> + <property name="text"> + <string>N&ame:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>ps_name</cstring> + </property> + </widget> + <widget class="QLayoutWidget" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>ps_store</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Save</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>ps_recall</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Load</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>ps_new</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&New</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>ps_del</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Delete</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QComboBox" row="0" column="1"> + <property name="name"> + <cstring>ps_name</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <spacer row="2" column="1"> + <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>150</width> + <height>16</height> + </size> + </property> + </spacer> + </grid> +</widget> +<tabstops> + <tabstop>ps_name</tabstop> + <tabstop>ps_store</tabstop> + <tabstop>ps_recall</tabstop> + <tabstop>ps_new</tabstop> + <tabstop>ps_del</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/common-dialogs/kvoctrain.kcfg b/kvoctrain/kvoctrain/common-dialogs/kvoctrain.kcfg new file mode 100644 index 00000000..32469ed7 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/kvoctrain.kcfg @@ -0,0 +1,264 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 + http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > + <kcfgfile name="kvoctrainrc"/> + <group name="General"> + <entry name="NumPreSetting" type="Int"> + <label>Number of stored setting profiles</label> + <default>0</default> + </entry> + <entry name="NumLangSet" type="Int"> + <label>Number of defined languages</label> + <default>0</default> + </entry> + <entry name="AutoEntryApply" type="Bool"> + <label></label> + <default>false</default> + </entry> + <entry name="SmartAppend" type="Bool"> + <label>If true, when using the entry dialog, new rows will be appended as needed</label> + <default>false</default> + </entry> + <entry name="UseCurrent" type="Bool"> + <label>If true, it uses the same language order as the current document for the clipboard</label> + <default>true</default> + </entry> + <entry name="Separator" type="String"> + <label>This sets the separator used when copying/pasting text, default is Tab</label> + <default code="true">QChar('\t')</default> + </entry> + <entry name="PasteOrder" type="StringList"> + <label>The order in which languages get pasted</label> + <default></default> + </entry> + <entry name="EntriesPerLesson" type="Int"> + <label>The number of entries per lesson</label> + <default>50</default> + </entry> + <entry name="AutoSave" type="Bool"> + <label>If true, vocabularies are automatically saved on close and exit</label> + <default>false</default> + </entry> + <entry name="AutoBackup" type="Bool"> + <label>If true, a backup is save every BackupTime minutes</label> + <default>false</default> + </entry> + <entry name="BackupTime" type="Int"> + <label>Time interval between two automatic backups</label> + <default>15</default> + </entry> + <entry name="HeaderResizeMode" type="Enum"> + <label>How the columns should be resized.</label> + <choices> + <choice name="Automatic"/> + <choice name="Fixed"/> + <choice name="Percent"/> + </choices> + <default>Automatic</default> + </entry> + </group> + <group name="QueryProperties"> + <entry name="Block" type="Bool"> + <label>In Blocking Query Tab Dialog, if checked then the Query is blocked</label> + <default>true</default> + </entry> + <entry name="Expire" type="Bool"> + <label>In Blocking Query Tab Dialog, if checked then the Query accepts an expiring time</label> + <default>true</default> + </entry> + <entry name="AltLearn" type="Bool"> + <label>Use the Leitner learning method</label> + <default>false</default> + </entry> + <entry name="SwapDirection" type="Bool"> + <label>Swap direction randomly</label> + <default>false</default> + </entry> + <entry name="ShowCounter" type="Bool"> + <label>Get a progress bar to show remaining time if true.</label> + <default>false</default> + </entry> + <entry name="QueryTimeout" type="Enum"> + <label>If true, there is no time set to answer each query</label> + <choices> + <choice name="NoTimeout"/> + <choice name="Show"/> + <choice name="Continue"/> + </choices> + <default>NoTimeout</default> + </entry> + <entry name="MaxTimePer" type="Int"> + <label>Maximum time allowed per query</label> + <default>20</default> + </entry> + <entry name="Suggestions" type="Bool"> + <label>Enable suggestion lists in Random Query.</label> + <default>false</default> + </entry> + <entry name="Split" type="Bool"> + <label>Split translations in Random Query.</label> + <default>false</default> + </entry> + <entry name="Periods" type="Bool"> + <label>Split translations at periods.</label> + <default>true</default> + </entry> + <entry name="Colons" type="Bool"> + <label>Split translations at colons.</label> + <default>false</default> + </entry> + <entry name="Semicolons" type="Bool"> + <label>Split translations at semicolons.</label> + <default>true</default> + </entry> + <entry name="Commas" type="Bool"> + <label>Split translations at commas.</label> + <default>false</default> + </entry> + <entry name="Fields" type="Int"> + <label>Maximum number of fields to split translations into.</label> + <default>5</default> + </entry> + <entry name="ShowMore" type="Bool"> + <label>Enable Show More button in Random Query.</label> + <default>true</default> + </entry> + <entry name="IKnow" type="Bool"> + <label>Enable I Know button in Random Query.</label> + <default>true</default> + </entry> + </group> + <group name="Appearance"> + <entry name="TableFont" type="Font"> + <label>The font used in the vocabulary table</label> + <default code="true">KGlobalSettings::generalFont()</default> + </entry> + <entry name="IPAFont" type="Font"> + <label>The font used for phonetics</label> + <default code="true">KGlobalSettings::generalFont()</default> + </entry> + <entry name="CurrentCol" type="Int"> + <label>Currently selected column</label> + <default code="true">KV_COL_ORG</default> + </entry> + <entry name="CurrentRow" type="Int"> + <label>Currently selected row</label> + <default>0</default> + </entry> + <entry name="UseGradeCol" type="Bool"> + <label>Use your own colors</label> + <default>true</default> + </entry> + <entry name="GradeCol$(Number)" type="Color" key="GradeCol$(Number)"> + <parameter name="Number" type="Int" max="7"/> + <label>Colors used to display different grades</label> + <default param="0">0, 0, 0</default> + <default param="1">255, 0, 0</default> + <default param="2">255, 0, 0</default> + <default param="3">255, 0, 0</default> + <default param="4">0, 255, 0</default> + <default param="5">0, 255, 0</default> + <default param="6">0, 255, 0</default> + <default param="7">0, 255, 0</default> + </entry> + </group> + + <group name="QueryManager"> + <entry name="CompType$(Type)" type="Enum" key="CompType$(Type)"> + <parameter name="Type" type="Enum"> + <values> + <value>Date</value> + <value>Lesson</value> + <value>Query</value> + <value>Bad</value> + <value>WordType</value> + <value>Grade</value> + </values> + </parameter> + <label>Types of comparisons</label> + <choices> + <choice name="DontCare"/> + <choice name="MoreEqThan"/> + <choice name="MoreThan"/> + <choice name="Before"/> + <choice name="Within"/> + <choice name="WorseThan"/> + <choice name="WorseEqThan"/> + <choice name="EqualTo"/> + <choice name="NotEqual"/> + <choice name="LessEqThan"/> + <choice name="LessThan"/> + <choice name="BetterThan"/> + <choice name="BetterEqThan"/> + <choice name="Current"/> + <choice name="NotAssigned"/> + <choice name="NotQueried"/> + <choice name="Auto_Time"/> + <choice name="Auto_Count"/> + <choice name="OneOf"/> + <choice name="NotOneOf"/> + </choices> + <default>DontCare</default> + <default param="Lesson">Current</default> + </entry> + <entry name="DateItem" type="Int"> + <label></label> + <default>0</default> + </entry> + <entry name="BadItem" type="Int"> + <label></label> + <default>0</default> + </entry> + <entry name="QueryItem" type="Int"> + <label></label> + <default>0</default> + </entry> + <entry name="GradeItem" type="Int"> + <label></label> + <default>0</default> + </entry> + <entry name="TypeItem" type="String"> + <label></label> + <default code="true">QString::null</default> + </entry> + <entry name="BlockItem$(Grade)" type="Int" key="BlockItem$(Grade)"> + <parameter name="Grade" type="Int" max="7"/> + <label>Amount of time different grades should be blocked</label> + <default param="1">86400</default> + <default param="2">172800</default> + <default param="3">345600</default> + <default param="4">604800</default> + <default param="5">1209600</default> + <default param="6">2592000</default> + <default param="7">5184000</default> + </entry> + <entry name="ExpireItem$(Grade)" type="Int" key="ExpireItem$(Grade)"> + <parameter name="Grade" type="Int" max="7"/> + <label>Amount of time after which different grades should expire</label> + <default param="1">172800</default> + <default param="2">345600</default> + <default param="3">604800</default> + <default param="4">1209600</default> + <default param="5">2592000</default> + <default param="6">5184000</default> + <default param="7">10368000</default> + </entry> + </group> + <group name="KNewStuff"> + <entry name="ProvidersUrl" type="Path"> + <label>The Providers path for KVocTrain</label> + <default>"http://edu.kde.org/kvoctrain/providers.xml"</default> + </entry> + <entry name="InstallationCommand" type="String"> + <label>The command used to start a downloaded vocabulary</label> + <default>kvoctrain %f</default> + </entry> + <entry name="InstallPath" type="Path"> + <label>The folder where downloaded vocabularies are saved by +default (relative to $HOME)</label> + <default>Vocabularies</default> + </entry> + </group> +</kcfg> diff --git a/kvoctrain/kvoctrain/common-dialogs/kvoctrainprefs.cpp b/kvoctrain/kvoctrain/common-dialogs/kvoctrainprefs.cpp new file mode 100644 index 00000000..2af07f63 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/kvoctrainprefs.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + kvoctrainprefs.cpp - KVocTrain configuration dialog + + ------------------- + begin : Fri Mar 25 2005 + + copyright : (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qwidgetstack.h> +#include <qlayout.h> +#include <qradiobutton.h> +#include <qcheckbox.h> +#include <qlistview.h> +#include <qlabel.h> + +#include <klocale.h> +#include <kstandarddirs.h> +#include <kiconloader.h> +#include <krestrictedline.h> +#include <kmessagebox.h> +#include <kpushbutton.h> +#include <kdebug.h> +#include <kconfigskeleton.h> +#include <kcolorbutton.h> +#include <kfontrequester.h> +#include <kcombobox.h> + +#include "kvoctrainprefs.h" +#include "kvoctraindoc.h" +#include "generaloptions.h" +#include "languageoptions.h" +#include "viewoptions.h" +#include "pasteoptions.h" +#include "groupoptions.h" +#include "queryoptions.h" +#include "thresholdoptions.h" +#include "blockoptions.h" +#include "langset.h" +#include "QueryManager.h" +#include "profilesdialog.h" + +static const char unapplied[] = I18N_NOOP( + "You have made changes that are not yet applied.\n" + "If you save a profile, those changes will not be included.\n" + "Do you wish to continue?"); + +KVocTrainPrefs::KVocTrainPrefs(LangSet & ls, kvoctrainDoc * doc, KComboBox * lessons, QueryManager * m, QWidget *parent, + const char *name, KConfigSkeleton *config, DialogType dialogType, int /*dialogButtons*/, ButtonCode /*defaultButton*/, + bool /*modal*/) + : KConfigDialog(parent, name, config, dialogType, Default|Ok|Apply|Cancel|Help|User1, Ok, true), m_langSet(ls) +{ + m_config = config; + m_queryManager = m; + + m_generalOptions = new GeneralOptions(0, "General Settings"); + addPage(m_generalOptions, i18n("General"), "kvoctrain", i18n("General Settings"), true); + + m_languageOptions = new LanguageOptions(m_langSet, 0, "Language Settings"); + addPage(m_languageOptions, i18n("Languages"), "set_language", i18n("Language Settings"), true); + connect(m_languageOptions, SIGNAL(widgetModified()), this, SLOT(updateButtons())); + + m_viewOptions = new ViewOptions(0, "View Settings"); + addPage(m_viewOptions, i18n("View"), "view_choose", i18n("View Settings"), true); + + m_pasteOptions = new PasteOptions(m_langSet, doc, 0, "Copy & Paste Settings"); + addPage(m_pasteOptions, i18n("Copy & Paste"), "editpaste", i18n("Copy & Paste Settings"), true); + connect(m_pasteOptions, SIGNAL(widgetModified()), this, SLOT(updateButtons())); + + m_queryOptions = new QueryOptions(0, "Query Settings"); + addPage(m_queryOptions, i18n("Query"), "run_query", i18n("Query Settings"), true); + + m_thresholdOptions = new ThresholdOptions(lessons, m_queryManager, 0, "Threshold Settings"); + addPage(m_thresholdOptions, i18n("Thresholds"), "configure", i18n("Threshold Settings"), true); + connect(m_thresholdOptions, SIGNAL(widgetModified()), this, SLOT(updateButtons())); + + m_blockOptions = new BlockOptions(0, "Blocking Settings"); + addPage(m_blockOptions, i18n("Blocking"), "configure", i18n("Blocking Settings"), true); + connect(m_blockOptions, SIGNAL(widgetModified()), this, SLOT(updateButtons())); + connect(m_blockOptions, SIGNAL(blockExpireChanged(bool, bool)), m_thresholdOptions, SLOT(slotBlockExpire(bool, bool))); + + setButtonGuiItem(KDialogBase::User1, KGuiItem(i18n("&Profiles..."))); + setButtonTip(KDialogBase::User1, i18n("Save or load specific Query settings which consist in a profile")); + setButtonWhatsThis(KDialogBase::User1, i18n("A Profile is a set of settings (settings related to queries) which you can save/load in order to use again later. This button allows you to see existing profiles, to load a new profile and to save your current settings in a new profile.")); +} + +void KVocTrainPrefs::selectPage(int index) +{ + showPage(index); +} + +bool KVocTrainPrefs::hasChanged() +{ + return m_pasteOptions->hasChanged() | + m_languageOptions->hasChanged() | + m_thresholdOptions->hasChanged() | + m_blockOptions->hasChanged(); +} + +bool KVocTrainPrefs::isDefault() +{ + return m_pasteOptions->isDefault() && + m_languageOptions->isDefault() && + m_thresholdOptions->isDefault() && + m_blockOptions->isDefault(); +} + +void KVocTrainPrefs::updateSettings() +{ + m_pasteOptions->updateSettings(); + m_languageOptions->updateSettings(); + m_thresholdOptions->updateSettings(); + m_blockOptions->updateSettings(); + emit settingsChanged(); +} + +void KVocTrainPrefs::updateWidgetsDefault() +{ + bool bUseDefaults = m_config->useDefaults(true); + m_pasteOptions->updateWidgets(); + m_languageOptions->updateWidgets(); + m_thresholdOptions->updateWidgets(); + m_blockOptions->updateWidgets(); + m_config->useDefaults(bUseDefaults); +} + +void KVocTrainPrefs::slotUser1() +{ + bool showDlg = true; + if (hasChanged()) + if (KMessageBox::Yes != KMessageBox::questionYesNo(this, i18n(unapplied), i18n("Unapplied Changes"))) + showDlg = false; + + if (showDlg) + { + ProfilesDialog * dlg = new ProfilesDialog(m_queryManager, this, 0, true); + connect(dlg, SIGNAL(profileActivated()), this, SLOT(updateWidgets())); + dlg->show(); + } +} + +void KVocTrainPrefs::updateWidgets() +{ + m_queryOptions->updateWidgets(); + m_thresholdOptions->updateWidgets(); + m_blockOptions->updateWidgets(); +} + +#include "kvoctrainprefs.moc" diff --git a/kvoctrain/kvoctrain/common-dialogs/kvoctrainprefs.h b/kvoctrain/kvoctrain/common-dialogs/kvoctrainprefs.h new file mode 100644 index 00000000..ca723129 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/kvoctrainprefs.h @@ -0,0 +1,104 @@ +/*************************************************************************** + kvoctrainprefs.h - KVocTrain configuration dialog + + ------------------- + begin : Fri Mar 25 2005 + + copyright : (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KVOCTRAINPREFS_H +#define KVOCTRAINPREFS_H + +#include <kconfigdialog.h> + +/** + *@author Peter Hedlund +*/ + +class GeneralOptions; +class LanguageOptions; +class ViewOptions; +class PasteOptions; +class QueryOptions; +class ThresholdOptions; +class BlockOptions; + +class LangSet; +class kvoctrainDoc; +class QueryManager; +class KComboBox; + +class KVocTrainPrefs : public KConfigDialog +{ + Q_OBJECT + +public: + /** + * Creates a configuration dialog. + */ + KVocTrainPrefs(LangSet & ls, kvoctrainDoc * doc, KComboBox * lessons, QueryManager * m, QWidget *parent=0, + const char *name=0, KConfigSkeleton *config=0, DialogType dialogType=IconList, + int dialogButtons=Default|Ok|Apply|Cancel|Help, ButtonCode defaultButton=Ok, bool modal=false); + + /** + * calls showPage() to display a particular page in the dialog. + * @param page The page to display + */ + void selectPage(int page); + +protected slots: + /** + * Called when the user clicks Apply or OK. + */ + void updateSettings(); + /** + * Updates dialog widgets. Here only used after loading a profile. + * Profiles only store the settings of the last three pages in the dialog. + */ + void updateWidgets(); + /** + * Called when the user clicks Default + */ + void updateWidgetsDefault(); + /** + * Called when the user clicks Profiles... + */ + void slotUser1(); + +protected: + /** + * Returns true if the current state of the dialog is different from the saved settings + */ + bool hasChanged(); + /** + * Returns true if the current state of the dialog represents the default settings. + */ + bool isDefault(); + +private: + GeneralOptions * m_generalOptions; + LanguageOptions * m_languageOptions; + ViewOptions * m_viewOptions; + PasteOptions * m_pasteOptions; + QueryOptions * m_queryOptions; + ThresholdOptions * m_thresholdOptions; + BlockOptions * m_blockOptions; + + KConfigSkeleton * m_config; + LangSet & m_langSet; + kvoctrainDoc * m_doc; + KComboBox m_lessons; + QueryManager * m_queryManager; +}; + +#endif diff --git a/kvoctrain/kvoctrain/common-dialogs/languageoptions.cpp b/kvoctrain/kvoctrain/common-dialogs/languageoptions.cpp new file mode 100644 index 00000000..cbe8f08f --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/languageoptions.cpp @@ -0,0 +1,1285 @@ +/*************************************************************************** + + language options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +//based on code copyright (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + +#include <qpushbutton.h> +#include <qlineedit.h> +#include <qlabel.h> +#include <qfileinfo.h> + +#include <kapplication.h> +#include <klocale.h> +#include <kcombobox.h> +#include <dcopclient.h> +#include <kstandarddirs.h> +#include <kfiledialog.h> +#include <kmessagebox.h> + +#include "languageoptions.h" +#include "kvoctraincore.h" +#include "languagesettings.h" +#include "prefs.h" + +// automatically extracted from http://www.loc.gov/standards/iso639-2/englangn.html +// with .../tools/extractlang + +struct KV_ISO639_Code { + const char *iso1code; + const char *iso2code; + const char *langname; +}; + +// german language names at: +// http://www.rn.inf.tu-dresden.de/scripts_lsrn/lehre/rnd/www/iso639.htm + +KV_ISO639_Code kv_iso639_1[] = { + {"aa", "aar", I18N_NOOP("Afar")}, + {"ab", "abk", I18N_NOOP("Abkhazian")}, + {"ae", "ave", I18N_NOOP("Avestan")}, + {"af", "afr", I18N_NOOP("Afrikaans")}, + {"am", "amh", I18N_NOOP("Amharic")}, + {"ar", "ara", I18N_NOOP("Arabic")}, + {"as", "asm", I18N_NOOP("Assamese")}, + {"ay", "aym", I18N_NOOP("Aymara")}, + {"az", "aze", I18N_NOOP("Azerbaijani")}, + {"ba", "bak", I18N_NOOP("Bashkir")}, + {"be", "bel", I18N_NOOP("Belarusian")}, + {"bg", "bul", I18N_NOOP("Bulgarian")}, + {"bh", "bih", I18N_NOOP("Bihari")}, + {"bi", "bis", I18N_NOOP("Bislama")}, + {"bn", "ben", I18N_NOOP("Bengali")}, + {"bo", "tib", I18N_NOOP("Tibetan")}, + {"br", "bre", I18N_NOOP("Breton")}, + {"bs", "bos", I18N_NOOP("Bosnian")}, + {"ca", "cat", I18N_NOOP("Catalan")}, + {"ce", "che", I18N_NOOP("Chechen")}, + {"ch", "cha", I18N_NOOP("Chamorro")}, + {"co", "cos", I18N_NOOP("Corsican")}, + {"cs", "cze", I18N_NOOP("Czech")}, + {"cu", "chu", I18N_NOOP("Church Slavic")}, + {"cv", "chv", I18N_NOOP("Chuvash")}, + {"cy", "wel", I18N_NOOP("Welsh")}, + {"da", "dan", I18N_NOOP("Danish")}, + {"de", "ger", I18N_NOOP("German")}, + {"dz", "dzo", I18N_NOOP("Dzongkha")}, + {"el", "gre", I18N_NOOP("Greek")}, + {"en", "eng", I18N_NOOP("English")}, + {"eo", "epo", I18N_NOOP("Esperanto")}, + {"es", "spa", I18N_NOOP("Spanish")}, + {"et", "est", I18N_NOOP("Estonian")}, + {"eu", "baq", I18N_NOOP("Basque")}, + {"fa", "per", I18N_NOOP("Persian")}, + {"fi", "fin", I18N_NOOP("Finnish")}, + {"fj", "fij", I18N_NOOP("Fijian")}, + {"fo", "fao", I18N_NOOP("Faroese")}, + {"fr", "fre", I18N_NOOP("French")}, + {"fy", "fry", I18N_NOOP("Frisian")}, + {"ga", "gle", I18N_NOOP("Irish")}, + {"gd", "gla", I18N_NOOP("Gaelic")}, + {"gd", "gla", I18N_NOOP("Scottish Gaelic")}, + {"gl", "glg", I18N_NOOP("Gallegan")}, + {"gn", "grn", I18N_NOOP("Guarani")}, + {"gu", "guj", I18N_NOOP("Gujarati")}, + {"gv", "glv", I18N_NOOP("Manx")}, + {"ha", "hau", I18N_NOOP("Hausa")}, + {"he", "heb", I18N_NOOP("Hebrew")}, + {"hi", "hin", I18N_NOOP("Hindi")}, + {"ho", "hmo", I18N_NOOP("Hiri Motu")}, + {"hr", "scr", I18N_NOOP("Croatian")}, + {"hu", "hun", I18N_NOOP("Hungarian")}, + {"hy", "arm", I18N_NOOP("Armenian")}, + {"hz", "her", I18N_NOOP("Herero")}, + {"id", "ind", I18N_NOOP("Indonesian")}, + {"ie", "ile", I18N_NOOP("Interlingue")}, + {"ik", "ipk", I18N_NOOP("Inupiaq")}, + {"is", "ice", I18N_NOOP("Icelandic")}, + {"it", "ita", I18N_NOOP("Italian")}, + {"iu", "iku", I18N_NOOP("Inuktitut")}, + {"ja", "jpn", I18N_NOOP("Japanese")}, + {"jv", "jav", I18N_NOOP("Javanese")}, + {"ka", "geo", I18N_NOOP("Georgian")}, + {"ki", "kik", I18N_NOOP("Kikuyu")}, + {"kj", "kua", I18N_NOOP("Kuanyama")}, + {"kk", "kaz", I18N_NOOP("Kazakh")}, + {"kl", "kal", I18N_NOOP("Kalaallisut")}, + {"km", "khm", I18N_NOOP("Khmer")}, + {"kn", "kan", I18N_NOOP("Kannada")}, + {"ko", "kor", I18N_NOOP("Korean")}, + {"ks", "kas", I18N_NOOP("Kashmiri")}, + {"ku", "kur", I18N_NOOP("Kurdish")}, + {"kv", "kom", I18N_NOOP("Komi")}, + {"kw", "cor", I18N_NOOP("Cornish")}, + {"ky", "kir", I18N_NOOP("Kirghiz")}, + {"la", "lat", I18N_NOOP("Latin")}, + {"lb", "ltz", I18N_NOOP("Letzeburgesch")}, + {"ln", "lin", I18N_NOOP("Lingala")}, + {"lo", "lao", I18N_NOOP("Lao")}, + {"lt", "lit", I18N_NOOP("Lithuanian")}, + {"lv", "lav", I18N_NOOP("Latvian")}, + {"mg", "mlg", I18N_NOOP("Malagasy")}, + {"mh", "mah", I18N_NOOP("Marshall")}, + {"mi", "mao", I18N_NOOP("Maori")}, + {"mk", "mac", I18N_NOOP("Macedonian")}, + {"ml", "mal", I18N_NOOP("Malayalam")}, + {"mn", "mon", I18N_NOOP("Mongolian")}, + {"mo", "mol", I18N_NOOP("Moldavian")}, + {"mr", "mar", I18N_NOOP("Marathi")}, + {"ms", "may", I18N_NOOP("Malay")}, + {"mt", "mlt", I18N_NOOP("Maltese")}, + {"my", "bur", I18N_NOOP("Burmese")}, + {"na", "nau", I18N_NOOP("Nauru")}, + {"nb", "nob", I18N_NOOP("Bokmål")}, + {"nd", "nde", I18N_NOOP("Ndebele, North")}, + {"ne", "nep", I18N_NOOP("Nepali")}, + {"ng", "ndo", I18N_NOOP("Ndonga")}, + {"nl", "dut", I18N_NOOP("Dutch")}, + {"nn", "nno", I18N_NOOP("Norwegian Nynorsk")}, + {"no", "nor", I18N_NOOP("Norwegian")}, + {"nr", "nbl", I18N_NOOP("Ndebele, South")}, + {"nv", "nav", I18N_NOOP("Navajo")}, + {"ny", "nya", I18N_NOOP("Chichewa")}, + {"ny", "nya", I18N_NOOP("Nyanja")}, + {"oc", "oci", I18N_NOOP("Occitan")}, + {"oc", "oci", I18N_NOOP("Provencal")}, + {"om", "orm", I18N_NOOP("Oromo")}, + {"or", "ori", I18N_NOOP("Oriya")}, + {"os", "oss", I18N_NOOP("Ossetic")}, + {"pa", "pan", I18N_NOOP("Panjabi")}, + {"pi", "pli", I18N_NOOP("Pali")}, + {"pl", "pol", I18N_NOOP("Polish")}, + {"ps", "pus", I18N_NOOP("Pushto")}, + {"pt", "por", I18N_NOOP("Portuguese")}, + {"qu", "que", I18N_NOOP("Quechua")}, + {"rm", "roh", I18N_NOOP("Raeto-Romance")}, + {"rn", "run", I18N_NOOP("Rundi")}, + {"ro", "rum", I18N_NOOP("Romanian")}, + {"ru", "rus", I18N_NOOP("Russian")}, + {"rw", "kin", I18N_NOOP("Kinyarwanda")}, + {"sa", "san", I18N_NOOP("Sanskrit")}, + {"sc", "srd", I18N_NOOP("Sardinian")}, + {"sd", "snd", I18N_NOOP("Sindhi")}, + {"se", "sme", I18N_NOOP("Northern Sami")}, + {"sg", "sag", I18N_NOOP("Sango")}, + {"si", "sin", I18N_NOOP("Sinhalese")}, + {"sk", "slo", I18N_NOOP("Slovak")}, + {"sl", "slv", I18N_NOOP("Slovenian")}, + {"sm", "smo", I18N_NOOP("Samoan")}, + {"sn", "sna", I18N_NOOP("Shona")}, + {"so", "som", I18N_NOOP("Somali")}, + {"sq", "alb", I18N_NOOP("Albanian")}, + {"sr", "scc", I18N_NOOP("Serbian")}, + {"ss", "ssw", I18N_NOOP("Swati")}, + {"st", "sot", I18N_NOOP("Sotho, Southern")}, + {"su", "sun", I18N_NOOP("Sundanese")}, + {"sv", "swe", I18N_NOOP("Swedish")}, + {"sw", "swa", I18N_NOOP("Swahili")}, + {"ta", "tam", I18N_NOOP("Tamil")}, + {"te", "tel", I18N_NOOP("Telugu")}, + {"tg", "tgk", I18N_NOOP("Tajik")}, + {"th", "tha", I18N_NOOP("Thai")}, + {"ti", "tir", I18N_NOOP("Tigrinya")}, + {"tk", "tuk", I18N_NOOP("Turkmen")}, + {"tl", "tgl", I18N_NOOP("Tagalog")}, + {"tn", "tsn", I18N_NOOP("Tswana")}, + {"to", "ton", I18N_NOOP("Tonga")}, + {"tr", "tur", I18N_NOOP("Turkish")}, + {"ts", "tso", I18N_NOOP("Tsonga")}, + {"tt", "tat", I18N_NOOP("Tatar")}, + {"tw", "twi", I18N_NOOP("Twi")}, + {"ty", "tah", I18N_NOOP("Tahitian")}, + {"ug", "uig", I18N_NOOP("Uighur")}, + {"uk", "ukr", I18N_NOOP("Ukrainian")}, + {"ur", "urd", I18N_NOOP("Urdu")}, + {"uz", "uzb", I18N_NOOP("Uzbek")}, + {"vi", "vie", I18N_NOOP("Vietnamese")}, + {"vo", "vol", I18N_NOOP("Volapük")}, + {"wo", "wol", I18N_NOOP("Wolof")}, + {"xh", "xho", I18N_NOOP("Xhosa")}, + {"yi", "yid", I18N_NOOP("Yiddish")}, + {"yo", "yor", I18N_NOOP("Yoruba")}, + {"za", "zha", I18N_NOOP("Zhuang")}, + {"zh", "chi", I18N_NOOP("Chinese")}, + {"zu", "zul", I18N_NOOP("Zulu")}, + {0, 0, 0} +}; + +/* only when really needed + +KV_ISO639_Code kv_iso639_2[] = { + {"ab", "abk", I18N_NOOP("Abkhazian")}, + {"", "ace", I18N_NOOP("Achinese")}, + {"", "ach", I18N_NOOP("Acoli")}, + {"", "ada", I18N_NOOP("Adangme")}, + {"aa", "aar", I18N_NOOP("Afar")}, + {"", "afh", I18N_NOOP("Afrihili")}, + {"af", "afr", I18N_NOOP("Afrikaans")}, + {"", "afa", I18N_NOOP("Afro-Asiatic (Other)")}, + {"", "aka", I18N_NOOP("Akan")}, + {"", "akk", I18N_NOOP("Akkadian")}, + {"sq", "alb", I18N_NOOP("Albanian")}, + {"", "ale", I18N_NOOP("Aleut")}, + {"", "alg", I18N_NOOP("Algonquian languages")}, + {"", "tut", I18N_NOOP("Altaic (Other)")}, + {"am", "amh", I18N_NOOP("Amharic")}, + {"", "apa", I18N_NOOP("Apache languages")}, + {"ar", "ara", I18N_NOOP("Arabic")}, + {"", "arc", I18N_NOOP("Aramaic")}, + {"", "arp", I18N_NOOP("Arapaho")}, + {"", "arn", I18N_NOOP("Araucanian")}, + {"", "arw", I18N_NOOP("Arawak")}, + {"hy", "arm", I18N_NOOP("Armenian")}, + {"", "art", I18N_NOOP("Artificial (Other)")}, + {"as", "asm", I18N_NOOP("Assamese")}, + {"", "ath", I18N_NOOP("Athapascan languages")}, + {"", "aus", I18N_NOOP("Australian languages")}, + {"", "map", I18N_NOOP("Austronesian (Other)")}, + {"", "ava", I18N_NOOP("Avaric")}, + {"ae", "ave", I18N_NOOP("Avestan")}, + {"", "awa", I18N_NOOP("Awadhi")}, + {"ay", "aym", I18N_NOOP("Aymara")}, + {"az", "aze", I18N_NOOP("Azerbaijani")}, + {"", "ban", I18N_NOOP("Balinese")}, + {"", "bat", I18N_NOOP("Baltic (Other)")}, + {"", "bal", I18N_NOOP("Baluchi")}, + {"", "bam", I18N_NOOP("Bambara")}, + {"", "bai", I18N_NOOP("Bamileke languages")}, + {"", "bad", I18N_NOOP("Banda")}, + {"", "bnt", I18N_NOOP("Bantu (Other)")}, + {"", "bas", I18N_NOOP("Basa")}, + {"ba", "bak", I18N_NOOP("Bashkir")}, + {"eu", "baq", I18N_NOOP("Basque")}, + {"", "btk", I18N_NOOP("Batak (Indonesia)")}, + {"", "bej", I18N_NOOP("Beja")}, + {"be", "bel", I18N_NOOP("Belarusian")}, + {"", "bem", I18N_NOOP("Bemba")}, + {"bn", "ben", I18N_NOOP("Bengali")}, + {"", "ber", I18N_NOOP("Berber (Other)")}, + {"", "bho", I18N_NOOP("Bhojpuri")}, + {"bh", "bih", I18N_NOOP("Bihari")}, + {"", "bik", I18N_NOOP("Bikol")}, + {"", "bin", I18N_NOOP("Bini")}, + {"bi", "bis", I18N_NOOP("Bislama")}, + {"nb", "nob", I18N_NOOP("Bokmål, Norwegian; Norwegian Bokmål")}, + {"bs", "bos", I18N_NOOP("Bosnian")}, + {"", "bra", I18N_NOOP("Braj")}, + {"br", "bre", I18N_NOOP("Breton")}, + {"", "bug", I18N_NOOP("Buginese")}, + {"bg", "bul", I18N_NOOP("Bulgarian")}, + {"", "bua", I18N_NOOP("Buriat")}, + {"my", "bur", I18N_NOOP("Burmese")}, + {"", "cad", I18N_NOOP("Caddo")}, + {"", "car", I18N_NOOP("Carib")}, + {"es", "spa", I18N_NOOP("Castilian; Spanish")}, + {"ca", "cat", I18N_NOOP("Catalan")}, + {"", "cau", I18N_NOOP("Caucasian (Other)")}, + {"", "ceb", I18N_NOOP("Cebuano")}, + {"", "cel", I18N_NOOP("Celtic (Other)")}, + {"", "chg", I18N_NOOP("Chagatai")}, + {"", "cmc", I18N_NOOP("Chamic languages")}, + {"ch", "cha", I18N_NOOP("Chamorro")}, + {"ce", "che", I18N_NOOP("Chechen")}, + {"", "chr", I18N_NOOP("Cherokee")}, + {"", "chy", I18N_NOOP("Cheyenne")}, + {"", "chb", I18N_NOOP("Chibcha")}, + {"ny", "nya", I18N_NOOP("Chichewa; Nyanja")}, + {"zh", "chi", I18N_NOOP("Chinese")}, + {"", "chn", I18N_NOOP("Chinook jargon")}, + {"", "chp", I18N_NOOP("Chipewyan")}, + {"", "cho", I18N_NOOP("Choctaw")}, + {"za", "zha", I18N_NOOP("Chuang; Zhuang")}, + {"cu", "chu", I18N_NOOP("Church Slavic")}, + {"", "chk", I18N_NOOP("Chuukese")}, + {"cv", "chv", I18N_NOOP("Chuvash")}, + {"", "cop", I18N_NOOP("Coptic")}, + {"kw", "cor", I18N_NOOP("Cornish")}, + {"co", "cos", I18N_NOOP("Corsican")}, + {"", "cre", I18N_NOOP("Cree")}, + {"", "mus", I18N_NOOP("Creek")}, + {"", "crp", I18N_NOOP("Creoles and pidgins (Other)")}, + {"hr", "scr", I18N_NOOP("Croatian")}, + {"", "cus", I18N_NOOP("Cushitic (Other)")}, + {"cs", "cze", I18N_NOOP("Czech")}, + {"", "dak", I18N_NOOP("Dakota")}, + {"da", "dan", I18N_NOOP("Danish")}, + {"", "day", I18N_NOOP("Dayak")}, + {"", "del", I18N_NOOP("Delaware")}, + {"", "din", I18N_NOOP("Dinka")}, + {"", "div", I18N_NOOP("Divehi")}, + {"", "doi", I18N_NOOP("Dogri")}, + {"", "dgr", I18N_NOOP("Dogrib")}, + {"", "dra", I18N_NOOP("Dravidian (Other)")}, + {"", "dua", I18N_NOOP("Duala")}, + {"nl", "dut", I18N_NOOP("Dutch")}, + {"", "dum", I18N_NOOP("Dutch, Middle (ca. 1050-1350)")}, + {"", "dyu", I18N_NOOP("Dyula")}, + {"dz", "dzo", I18N_NOOP("Dzongkha")}, + {"", "efi", I18N_NOOP("Efik")}, + {"", "egy", I18N_NOOP("Egyptian (Ancient)")}, + {"", "eka", I18N_NOOP("Ekajuk")}, + {"", "elx", I18N_NOOP("Elamite")}, + {"en", "eng", I18N_NOOP("English")}, + {"", "enm", I18N_NOOP("English, Middle (1100-1500)")}, + {"", "ang", I18N_NOOP("English, Old (ca.450-1100)")}, + {"eo", "epo", I18N_NOOP("Esperanto")}, + {"et", "est", I18N_NOOP("Estonian")}, + {"", "ewe", I18N_NOOP("Ewe")}, + {"", "ewo", I18N_NOOP("Ewondo")}, + {"", "fan", I18N_NOOP("Fang")}, + {"", "fat", I18N_NOOP("Fanti")}, + {"fo", "fao", I18N_NOOP("Faroese")}, + {"fj", "fij", I18N_NOOP("Fijian")}, + {"fi", "fin", I18N_NOOP("Finnish")}, + {"", "fiu", I18N_NOOP("Finno-Ugrian (Other)")}, + {"", "fon", I18N_NOOP("Fon")}, + {"fr", "fre", I18N_NOOP("French")}, + {"", "frm", I18N_NOOP("French, Middle (ca.1400-1600)")}, + {"", "fro", I18N_NOOP("French, Old (842-ca.1400)")}, + {"fy", "fry", I18N_NOOP("Frisian")}, + {"", "fur", I18N_NOOP("Friulian")}, + {"", "ful", I18N_NOOP("Fulah")}, + {"", "gaa", I18N_NOOP("Ga")}, + {"gd", "gla", I18N_NOOP("Gaelic; Scottish Gaelic")}, + {"gl", "glg", I18N_NOOP("Gallegan")}, + {"", "lug", I18N_NOOP("Ganda")}, + {"", "gay", I18N_NOOP("Gayo")}, + {"", "gba", I18N_NOOP("Gbaya")}, + {"", "gez", I18N_NOOP("Geez")}, + {"ka", "geo", I18N_NOOP("Georgian")}, + {"de", "ger", I18N_NOOP("German")}, + {"", "nds", I18N_NOOP("German, Low; Saxon, Low; Low German; Low Saxon")}, + {"", "gmh", I18N_NOOP("German, Middle High (ca.1050-1500)")}, + {"", "goh", I18N_NOOP("German, Old High (ca.750-1050)")}, + {"", "gem", I18N_NOOP("Germanic (Other)")}, + {"ki", "kik", I18N_NOOP("Gikuyu; Kikuyu")}, + {"", "gil", I18N_NOOP("Gilbertese")}, + {"", "gon", I18N_NOOP("Gondi")}, + {"", "gor", I18N_NOOP("Gorontalo")}, + {"", "got", I18N_NOOP("Gothic")}, + {"", "grb", I18N_NOOP("Grebo")}, + {"", "grc", I18N_NOOP("Greek, Ancient (to 1453)")}, + {"el", "gre", I18N_NOOP("Greek, Modern (1453-)")}, + {"gn", "grn", I18N_NOOP("Guarani")}, + {"gu", "guj", I18N_NOOP("Gujarati")}, + {"", "gwi", I18N_NOOP("Gwich´in")}, + {"", "hai", I18N_NOOP("Haida")}, + {"ha", "hau", I18N_NOOP("Hausa")}, + {"", "haw", I18N_NOOP("Hawaiian")}, + {"he", "heb", I18N_NOOP("Hebrew")}, + {"hz", "her", I18N_NOOP("Herero")}, + {"", "hil", I18N_NOOP("Hiligaynon")}, + {"", "him", I18N_NOOP("Himachali")}, + {"hi", "hin", I18N_NOOP("Hindi")}, + {"ho", "hmo", I18N_NOOP("Hiri Motu")}, + {"", "hit", I18N_NOOP("Hittite")}, + {"", "hmn", I18N_NOOP("Hmong")}, + {"hu", "hun", I18N_NOOP("Hungarian")}, + {"", "hup", I18N_NOOP("Hupa")}, + {"", "iba", I18N_NOOP("Iban")}, + {"is", "ice", I18N_NOOP("Icelandic")}, + {"", "ibo", I18N_NOOP("Igbo")}, + {"", "ijo", I18N_NOOP("Ijo")}, + {"", "ilo", I18N_NOOP("Iloko")}, + {"", "inc", I18N_NOOP("Indic (Other)")}, + {"", "ine", I18N_NOOP("Indo-European (Other)")}, + {"id", "ind", I18N_NOOP("Indonesian")}, + {"ie", "ile", I18N_NOOP("Interlingue")}, + {"iu", "iku", I18N_NOOP("Inuktitut")}, + {"ik", "ipk", I18N_NOOP("Inupiaq")}, + {"", "ira", I18N_NOOP("Iranian (Other)")}, + {"ga", "gle", I18N_NOOP("Irish")}, + {"", "mga", I18N_NOOP("Irish, Middle (900-1200)")}, + {"", "sga", I18N_NOOP("Irish, Old (to 900)")}, + {"", "iro", I18N_NOOP("Iroquoian languages")}, + {"it", "ita", I18N_NOOP("Italian")}, + {"ja", "jpn", I18N_NOOP("Japanese")}, + {"jv", "jav", I18N_NOOP("Javanese")}, + {"", "jrb", I18N_NOOP("Judeo-Arabic")}, + {"", "jpr", I18N_NOOP("Judeo-Persian")}, + {"", "kab", I18N_NOOP("Kabyle")}, + {"", "kac", I18N_NOOP("Kachin")}, + {"kl", "kal", I18N_NOOP("Kalaallisut")}, + {"", "kam", I18N_NOOP("Kamba")}, + {"kn", "kan", I18N_NOOP("Kannada")}, + {"", "kau", I18N_NOOP("Kanuri")}, + {"", "kaa", I18N_NOOP("Kara-Kalpak")}, + {"", "kar", I18N_NOOP("Karen")}, + {"ks", "kas", I18N_NOOP("Kashmiri")}, + {"", "kaw", I18N_NOOP("Kawi")}, + {"kk", "kaz", I18N_NOOP("Kazakh")}, + {"", "kha", I18N_NOOP("Khasi")}, + {"km", "khm", I18N_NOOP("Khmer")}, + {"", "khi", I18N_NOOP("Khoisan (Other)")}, + {"", "kho", I18N_NOOP("Khotanese")}, + {"ki", "kik", I18N_NOOP("Kikuyu; Gikuyu")}, + {"", "kmb", I18N_NOOP("Kimbundu")}, + {"rw", "kin", I18N_NOOP("Kinyarwanda")}, + {"ky", "kir", I18N_NOOP("Kirghiz")}, + {"kv", "kom", I18N_NOOP("Komi")}, + {"", "kon", I18N_NOOP("Kongo")}, + {"", "kok", I18N_NOOP("Konkani")}, + {"ko", "kor", I18N_NOOP("Korean")}, + {"", "kos", I18N_NOOP("Kosraean")}, + {"", "kpe", I18N_NOOP("Kpelle")}, + {"", "kro", I18N_NOOP("Kru")}, + {"kj", "kua", I18N_NOOP("Kuanyama")}, + {"", "kum", I18N_NOOP("Kumyk")}, + {"ku", "kur", I18N_NOOP("Kurdish")}, + {"", "kru", I18N_NOOP("Kurukh")}, + {"", "kut", I18N_NOOP("Kutenai")}, + {"", "lad", I18N_NOOP("Ladino")}, + {"", "lah", I18N_NOOP("Lahnda")}, + {"", "lam", I18N_NOOP("Lamba")}, + {"lo", "lao", I18N_NOOP("Lao")}, + {"la", "lat", I18N_NOOP("Latin")}, + {"lv", "lav", I18N_NOOP("Latvian")}, + {"lb", "ltz", I18N_NOOP("Letzeburgesch")}, + {"", "lez", I18N_NOOP("Lezghian")}, + {"ln", "lin", I18N_NOOP("Lingala")}, + {"lt", "lit", I18N_NOOP("Lithuanian")}, + {"", "nds", I18N_NOOP("Low German; Low Saxon; German, Low; Saxon, Low")}, + {"", "nds", I18N_NOOP("Low Saxon; Low German; Saxon, Low; German, Low")}, + {"", "loz", I18N_NOOP("Lozi")}, + {"", "lub", I18N_NOOP("Luba-Katanga")}, + {"", "lua", I18N_NOOP("Luba-Lulua")}, + {"", "lui", I18N_NOOP("Luiseno")}, + {"", "lun", I18N_NOOP("Lunda")}, + {"", "luo", I18N_NOOP("Luo (Kenya and Tanzania)")}, + {"", "lus", I18N_NOOP("Lushai")}, + {"mk", "mac", I18N_NOOP("Macedonian")}, + {"", "mad", I18N_NOOP("Madurese")}, + {"", "mag", I18N_NOOP("Magahi")}, + {"", "mai", I18N_NOOP("Maithili")}, + {"", "mak", I18N_NOOP("Makasar")}, + {"mg", "mlg", I18N_NOOP("Malagasy")}, + {"ms", "may", I18N_NOOP("Malay")}, + {"ml", "mal", I18N_NOOP("Malayalam")}, + {"mt", "mlt", I18N_NOOP("Maltese")}, + {"", "mnc", I18N_NOOP("Manchu")}, + {"", "mdr", I18N_NOOP("Mandar")}, + {"", "man", I18N_NOOP("Mandingo")}, + {"", "mni", I18N_NOOP("Manipuri")}, + {"", "mno", I18N_NOOP("Manobo languages")}, + {"gv", "glv", I18N_NOOP("Manx")}, + {"mi", "mao", I18N_NOOP("Maori")}, + {"mr", "mar", I18N_NOOP("Marathi")}, + {"", "chm", I18N_NOOP("Mari")}, + {"mh", "mah", I18N_NOOP("Marshall")}, + {"", "mwr", I18N_NOOP("Marwari")}, + {"", "mas", I18N_NOOP("Masai")}, + {"", "myn", I18N_NOOP("Mayan languages")}, + {"", "men", I18N_NOOP("Mende")}, + {"", "mic", I18N_NOOP("Micmac")}, + {"", "min", I18N_NOOP("Minangkabau")}, + {"", "mis", I18N_NOOP("Miscellaneous languages")}, + {"", "moh", I18N_NOOP("Mohawk")}, + {"mo", "mol", I18N_NOOP("Moldavian")}, + {"", "mkh", I18N_NOOP("Mon-Khmer (Other)")}, + {"", "lol", I18N_NOOP("Mongo")}, + {"mn", "mon", I18N_NOOP("Mongolian")}, + {"", "mos", I18N_NOOP("Mossi")}, + {"", "mul", I18N_NOOP("Multiple languages")}, + {"", "mun", I18N_NOOP("Munda languages")}, + {"", "nah", I18N_NOOP("Nahuatl")}, + {"na", "nau", I18N_NOOP("Nauru")}, + {"nv", "nav", I18N_NOOP("Navajo")}, + {"nd", "nde", I18N_NOOP("Ndebele, North")}, + {"nr", "nbl", I18N_NOOP("Ndebele, South")}, + {"ng", "ndo", I18N_NOOP("Ndonga")}, + {"ne", "nep", I18N_NOOP("Nepali")}, + {"", "new", I18N_NOOP("Newari")}, + {"", "nia", I18N_NOOP("Nias")}, + {"", "nic", I18N_NOOP("Niger-Kordofanian (Other)")}, + {"", "ssa", I18N_NOOP("Nilo-Saharan (Other)")}, + {"", "niu", I18N_NOOP("Niuean")}, + {"", "non", I18N_NOOP("Norse, Old")}, + {"", "nai", I18N_NOOP("North American Indian (Other)")}, + {"se", "sme", I18N_NOOP("Northern Sami")}, + {"no", "nor", I18N_NOOP("Norwegian")}, + {"nb", "nob", I18N_NOOP("Norwegian Bokmål; Bokmål, Norwegian")}, + {"nn", "nno", I18N_NOOP("Norwegian Nynorsk; Nynorsk, Norwegian")}, + {"", "nub", I18N_NOOP("Nubian languages")}, + {"", "nym", I18N_NOOP("Nyamwezi")}, + {"ny", "nya", I18N_NOOP("Nyanja; Chichewa")}, + {"", "nyn", I18N_NOOP("Nyankole")}, + {"nn", "nno", I18N_NOOP("Nynorsk, Norwegian; Norwegian Nynorsk")}, + {"", "nyo", I18N_NOOP("Nyoro")}, + {"", "nzi", I18N_NOOP("Nzima")}, + {"oc", "oci", I18N_NOOP("Occitan (post 1500); Provençal")}, + {"", "oji", I18N_NOOP("Ojibwa")}, + {"or", "ori", I18N_NOOP("Oriya")}, + {"om", "orm", I18N_NOOP("Oromo")}, + {"", "osa", I18N_NOOP("Osage")}, + {"os", "oss", I18N_NOOP("Ossetian; Ossetic")}, + {"os", "oss", I18N_NOOP("Ossetic; Ossetian")}, + {"", "oto", I18N_NOOP("Otomian languages")}, + {"", "pal", I18N_NOOP("Pahlavi")}, + {"", "pau", I18N_NOOP("Palauan")}, + {"pi", "pli", I18N_NOOP("Pali")}, + {"", "pam", I18N_NOOP("Pampanga")}, + {"", "pag", I18N_NOOP("Pangasinan")}, + {"pa", "pan", I18N_NOOP("Panjabi")}, + {"", "pap", I18N_NOOP("Papiamento")}, + {"", "paa", I18N_NOOP("Papuan (Other)")}, + {"fa", "per", I18N_NOOP("Persian")}, + {"", "peo", I18N_NOOP("Persian, Old (ca.600-400 B.C.)")}, + {"", "phi", I18N_NOOP("Philippine (Other)")}, + {"", "phn", I18N_NOOP("Phoenician")}, + {"", "pon", I18N_NOOP("Pohnpeian")}, + {"pl", "pol", I18N_NOOP("Polish")}, + {"pt", "por", I18N_NOOP("Portuguese")}, + {"", "pra", I18N_NOOP("Prakrit languages")}, + {"oc", "oci", I18N_NOOP("Provençal; Occitan (post 1500)")}, + {"", "pro", I18N_NOOP("Provençal, Old (to 1500)")}, + {"ps", "pus", I18N_NOOP("Pushto")}, + {"qu", "que", I18N_NOOP("Quechua")}, + {"rm", "roh", I18N_NOOP("Raeto-Romance")}, + {"", "raj", I18N_NOOP("Rajasthani")}, + {"", "rap", I18N_NOOP("Rapanui")}, + {"", "rar", I18N_NOOP("Rarotongan")}, + {"", "qaa-qtz", I18N_NOOP("Reserved for local use")}, + {"", "roa", I18N_NOOP("Romance (Other)")}, + {"ro", "rum", I18N_NOOP("Romanian")}, + {"", "rom", I18N_NOOP("Romany")}, + {"rn", "run", I18N_NOOP("Rundi")}, + {"ru", "rus", I18N_NOOP("Russian")}, + {"", "sal", I18N_NOOP("Salishan languages")}, + {"", "sam", I18N_NOOP("Samaritan Aramaic")}, + {"", "smi", I18N_NOOP("Sami languages (Other)")}, + {"sm", "smo", I18N_NOOP("Samoan")}, + {"", "sad", I18N_NOOP("Sandawe")}, + {"sg", "sag", I18N_NOOP("Sango")}, + {"sa", "san", I18N_NOOP("Sanskrit")}, + {"", "sat", I18N_NOOP("Santali")}, + {"sc", "srd", I18N_NOOP("Sardinian")}, + {"", "sas", I18N_NOOP("Sasak")}, + {"", "sco", I18N_NOOP("Scots")}, + {"gd", "gla", I18N_NOOP("Scottish Gaelic; Gaelic")}, + {"", "sel", I18N_NOOP("Selkup")}, + {"", "sem", I18N_NOOP("Semitic (Other)")}, + {"sr", "scc", I18N_NOOP("Serbian")}, + {"", "srr", I18N_NOOP("Serer")}, + {"", "shn", I18N_NOOP("Shan")}, + {"sn", "sna", I18N_NOOP("Shona")}, + {"", "sid", I18N_NOOP("Sidamo")}, + {"", "sgn", I18N_NOOP("Sign languages")}, + {"", "bla", I18N_NOOP("Siksika")}, + {"sd", "snd", I18N_NOOP("Sindhi")}, + {"si", "sin", I18N_NOOP("Sinhalese")}, + {"", "sit", I18N_NOOP("Sino-Tibetan (Other)")}, + {"", "sio", I18N_NOOP("Siouan languages")}, + {"", "den", I18N_NOOP("Slave (Athapascan)")}, + {"", "sla", I18N_NOOP("Slavic (Other)")}, + {"sk", "slo", I18N_NOOP("Slovak")}, + {"sl", "slv", I18N_NOOP("Slovenian")}, + {"", "sog", I18N_NOOP("Sogdian")}, + {"so", "som", I18N_NOOP("Somali")}, + {"", "son", I18N_NOOP("Songhai")}, + {"", "snk", I18N_NOOP("Soninke")}, + {"", "wen", I18N_NOOP("Sorbian languages")}, + {"", "nso", I18N_NOOP("Sotho, Northern")}, + {"st", "sot", I18N_NOOP("Sotho, Southern")}, + {"", "sai", I18N_NOOP("South American Indian (Other)")}, + {"es", "spa", I18N_NOOP("Spanish; Castilian")}, + {"", "suk", I18N_NOOP("Sukuma")}, + {"", "sux", I18N_NOOP("Sumerian")}, + {"su", "sun", I18N_NOOP("Sundanese")}, + {"", "sus", I18N_NOOP("Susu")}, + {"sw", "swa", I18N_NOOP("Swahili")}, + {"ss", "ssw", I18N_NOOP("Swati")}, + {"sv", "swe", I18N_NOOP("Swedish")}, + {"", "syr", I18N_NOOP("Syriac")}, + {"tl", "tgl", I18N_NOOP("Tagalog")}, + {"ty", "tah", I18N_NOOP("Tahitian")}, + {"", "tai", I18N_NOOP("Tai (Other)")}, + {"tg", "tgk", I18N_NOOP("Tajik")}, + {"", "tmh", I18N_NOOP("Tamashek")}, + {"ta", "tam", I18N_NOOP("Tamil")}, + {"tt", "tat", I18N_NOOP("Tatar")}, + {"te", "tel", I18N_NOOP("Telugu")}, + {"", "ter", I18N_NOOP("Tereno")}, + {"", "tet", I18N_NOOP("Tetum")}, + {"th", "tha", I18N_NOOP("Thai")}, + {"bo", "tib", I18N_NOOP("Tibetan")}, + {"", "tig", I18N_NOOP("Tigre")}, + {"ti", "tir", I18N_NOOP("Tigrinya")}, + {"", "tem", I18N_NOOP("Timne")}, + {"", "tiv", I18N_NOOP("Tiv")}, + {"", "tli", I18N_NOOP("Tlingit")}, + {"", "tpi", I18N_NOOP("Tok Pisin")}, + {"", "tkl", I18N_NOOP("Tokelau")}, + {"", "tog", I18N_NOOP("Tonga (Nyasa)")}, + {"to", "ton", I18N_NOOP("Tonga (Tonga Islands)")}, + {"", "tsi", I18N_NOOP("Tsimshian")}, + {"ts", "tso", I18N_NOOP("Tsonga")}, + {"tn", "tsn", I18N_NOOP("Tswana")}, + {"", "tum", I18N_NOOP("Tumbuka")}, + {"tr", "tur", I18N_NOOP("Turkish")}, + {"", "ota", I18N_NOOP("Turkish, Ottoman (1500-1928)")}, + {"tk", "tuk", I18N_NOOP("Turkmen")}, + {"", "tvl", I18N_NOOP("Tuvalu")}, + {"", "tyv", I18N_NOOP("Tuvinian")}, + {"tw", "twi", I18N_NOOP("Twi")}, + {"", "uga", I18N_NOOP("Ugaritic")}, + {"ug", "uig", I18N_NOOP("Uighur")}, + {"uk", "ukr", I18N_NOOP("Ukrainian")}, + {"", "umb", I18N_NOOP("Umbundu")}, + {"", "und", I18N_NOOP("Undetermined")}, + {"ur", "urd", I18N_NOOP("Urdu")}, + {"uz", "uzb", I18N_NOOP("Uzbek")}, + {"", "vai", I18N_NOOP("Vai")}, + {"", "ven", I18N_NOOP("Venda")}, + {"vi", "vie", I18N_NOOP("Vietnamese")}, + {"vo", "vol", I18N_NOOP("Volapük")}, + {"", "vot", I18N_NOOP("Votic")}, + {"", "wak", I18N_NOOP("Wakashan languages")}, + {"", "wal", I18N_NOOP("Walamo")}, + {"", "war", I18N_NOOP("Waray")}, + {"", "was", I18N_NOOP("Washo")}, + {"cy", "wel", I18N_NOOP("Welsh")}, + {"wo", "wol", I18N_NOOP("Wolof")}, + {"xh", "xho", I18N_NOOP("Xhosa")}, + {"", "sah", I18N_NOOP("Yakut")}, + {"", "yao", I18N_NOOP("Yao")}, + {"", "yap", I18N_NOOP("Yapese")}, + {"yi", "yid", I18N_NOOP("Yiddish")}, + {"yo", "yor", I18N_NOOP("Yoruba")}, + {"", "ypk", I18N_NOOP("Yupik languages")}, + {"", "znd", I18N_NOOP("Zande")}, + {"", "zap", I18N_NOOP("Zapotec")}, + {"", "zen", I18N_NOOP("Zenaga")}, + {"za", "zha", I18N_NOOP("Zhuang; Chuang")}, + {"zu", "zul", I18N_NOOP("Zulu")}, + {"", "zun", I18N_NOOP("Zuni")}, + {0, 0, 0} +}; +*/ + +LanguageOptions::LanguageOptions(LangSet & langset, QWidget* parent, const char* name, WFlags fl) + : LanguageOptionsBase(parent, name, fl), m_langSet(langset) +{ + langset_popup = 0; + + connect(b_langDel, SIGNAL(clicked()), this, SLOT(slotDeleteClicked())); + connect(b_langNew, SIGNAL(clicked()), this, SLOT(slotNewClicked())); + connect(b_langPixmap, SIGNAL(clicked()), SLOT(slotPixmapClicked())); + connect(e_newName, SIGNAL(textChanged(const QString&)), this, SLOT(slotNewNameChanged(const QString&))); + connect(d_shortName, SIGNAL(activated(const QString&)), this, SLOT(slotShortActivated(const QString&))); + connect(e_langLong, SIGNAL(textChanged(const QString&)), this, SLOT(slotLangChanged(const QString&))); + connect(e_shortName2, SIGNAL(textChanged(const QString&)), this, SLOT(slotShort2Changed(const QString&))); + connect(d_kblayout, SIGNAL(activated(const QString&)), this, SLOT(slotKeyboardLayoutChanged(const QString&))); + + // Load the languages first, then the countries and create the + // menus for the languages last, so they will have flags + loadISO6391Data(); + + loadCountryData(); + b_lang_kde->setPopup(langset_popup); + + createISO6391Menus(); + b_lang_iso1->setPopup(iso6391_popup); + + b_langNew->setEnabled(false); // activate after data is entered + + for (int i = 0; i < (int) m_langSet.size() && i < MAX_LANGSET; i++) + d_shortName->insertItem (m_langSet.shortId(i)); + + enableLangWidgets(); + + if (d_shortName->count() ) + { + d_shortName->setCurrentItem(0); + e_langLong->setText(m_langSet.longId(0)); + e_shortName2->setText(m_langSet.shortId2(0)); + if (!m_langSet.PixMapFile(0).isEmpty() ) + { + QPixmap pix(m_langSet.PixMapFile(0)); + if (!pix.isNull() ) + { + m_lastPix = m_langSet.PixMapFile(0); + b_langPixmap->setPixmap (pix); + } + else + b_langPixmap->setText (i18n("Picture is Invalid")); + } + else + b_langPixmap->setText (i18n("No Picture Selected")); + } + else + { + b_langPixmap->setText (i18n("No Picture Selected...")); + b_langPixmap->setEnabled(false); + } + m_hasChanged = false; +} + + +LanguageOptions::~LanguageOptions () +{ + delete langset_popup; +} + +void LanguageOptions::slotDeleteClicked() +{ + if (d_shortName->count() != 0) + { + m_langSet.erase(d_shortName->currentItem()); + emit widgetModified(); + m_hasChanged = true; + d_shortName->removeItem(d_shortName->currentItem()); + if (d_shortName->count() != 0) + d_shortName->setCurrentItem (0); + } + + if (d_shortName->count() != 0) + { + setPixmap(m_langSet.PixMapFile(d_shortName->currentItem())); + e_langLong->setText(m_langSet.longId(d_shortName->currentItem())); + e_shortName2->setText(m_langSet.shortId2(d_shortName->currentItem())); + } + else { + b_langPixmap->setText (i18n("No picture selected")); + e_langLong->setText(""); + e_shortName2->setText(""); + b_langPixmap->setEnabled(false); + } + enableLangWidgets(); + + // doesn't work yet + if (d_shortName->count() != 0 && d_kblayout->isEnabled()) + { + for (int i = 0; i < d_kblayout->count(); i++) + { + if (d_kblayout->text(i) == m_langSet.keyboardLayout(d_shortName->currentItem())) + { + d_kblayout->setCurrentItem(i); + break; + } + } + } +} + + +void LanguageOptions::slotKeyboardLayoutChanged(const QString& layout) +{ + m_langSet.setKeyboardLayout(layout, d_shortName->currentItem()); + emit widgetModified(); + m_hasChanged = true; +} + +void LanguageOptions::enableLangWidgets() +{ + bool enabled = d_shortName->count() != 0; + b_langDel->setEnabled(enabled); + b_langPixmap->setEnabled(enabled); + d_shortName->setEnabled(enabled); + e_langLong->setEnabled(enabled); + e_shortName2->setEnabled(enabled); + + //kdDebug() << "enabled? " << enabled << endl; + + if (enabled && KApplication::dcopClient()->isApplicationRegistered("kxkb")) + { + QByteArray data; + QCString replyType; + QByteArray replyData; + + if (!KApplication::dcopClient()->call("kxkb", "kxkb", "getLayoutsList()", data, replyType, replyData)) + { + //kdDebug() << "kxkb dcop error" << endl; + } + else + { + if (replyType == "QStringList") + { + QStringList layouts; + QDataStream stream(replyData, IO_ReadOnly); + stream >> layouts; + layouts.prepend(QString::null); + d_kblayout->clear(); + d_kblayout->insertStringList(layouts); + } + } + } + else + { + //kdDebug() << "kxkb not enabled" << endl; + d_kblayout->clear(); + d_kblayout->setEnabled(false); + } +} + + +void LanguageOptions::slotNewNameChanged(const QString& _s) +{ + QString s = _s; + b_langNew->setEnabled(s.stripWhiteSpace().length() >= 2); +} + + +void LanguageOptions::slotNewClicked() +{ + QString s = e_newName->text(); + d_shortName->insertItem(s.stripWhiteSpace()); + d_shortName->setCurrentItem(d_shortName->count()-1); + enableLangWidgets(); + slotShortActivated(s); + e_newName->setText(""); + e_langLong->setFocus(); +} + + +void LanguageOptions::slotShortActivated(const QString& _id) +{ + int i = 0; + QString id = _id.stripWhiteSpace(); + if (d_shortName->count() > (int) m_langSet.size() ) + { + // avoid duplicates in language code + for (i = 0; i < d_shortName->count(); i++) + if (d_shortName->text(i).isNull()) + { + d_shortName->removeItem(d_shortName->currentItem()); + d_shortName->setCurrentItem(0); + } + + for (i = 0; i < d_shortName->count()-1; i++) // omit last + if (id == d_shortName->text(i)) + { + d_shortName->removeItem(d_shortName->currentItem()); + d_shortName->setCurrentItem(i); + return; + } + + if (d_shortName->count() > (int) m_langSet.size() && m_langSet.size() < MAX_LANGSET ) + { + m_langSet.addSet(id, "", ""); + emit widgetModified(); + m_hasChanged = true; + } + } + + if (d_shortName->count() != 0) + { + b_langPixmap->setEnabled(true); + e_langLong->setText(m_langSet.longId(d_shortName->currentItem())); + e_shortName2->setText(m_langSet.shortId2(d_shortName->currentItem())); + + if (!m_langSet.PixMapFile(d_shortName->currentItem()).isEmpty()) + { + QPixmap pix(m_langSet.PixMapFile(d_shortName->currentItem())); + if (!pix.isNull()) + b_langPixmap->setPixmap(pix); + else + b_langPixmap->setText(i18n("Picture is Invalid")); + } + else + b_langPixmap->setText (i18n("No Picture Selected")); + + QString layout = m_langSet.keyboardLayout(d_shortName->currentItem()); + + //kdDebug() << "layout to select " << layout << endl; + + for (int i = 0; i < d_kblayout->count(); i++) + { + if (d_kblayout->text(i) == layout) + { + d_kblayout->setCurrentItem(i); + break; + } + } + // not found + if (d_kblayout->currentText() != layout) + { + d_kblayout->setCurrentItem(0); + } + } +} + + +void LanguageOptions::slotLangChanged(const QString& s) +{ + if (d_shortName->count() != 0 && d_shortName->currentItem() < (int) m_langSet.size()) + { + m_langSet.setLongId(s, d_shortName->currentItem()); + emit widgetModified(); + m_hasChanged = true; + } +} + + +void LanguageOptions::slotShort2Changed(const QString& s) +{ + if (d_shortName->count() != 0 && d_shortName->currentItem() < (int) m_langSet.size()) + { + m_langSet.setShortId2(s, d_shortName->currentItem()); + emit widgetModified(); + m_hasChanged = true; + } +} + + +bool LanguageOptions::setPixmap(QString pm) +{ + if (d_shortName->count() ) + { + QPixmap pix (pm); + if (!pix.isNull() ) { + m_langSet.setPixMapFile(pm, d_shortName->currentItem()); + b_langPixmap->setPixmap (pix); + emit widgetModified(); + m_hasChanged = true; + return true; + } + } + return false; + +} + + +void LanguageOptions::slotPixmapClicked() +{ + if (m_langSet.size() > 0 ) + { + if (m_lastPix.isNull() || QPixmap(m_lastPix).isNull()) + { + QString s; + if (!m_langSet.shortId(d_shortName->currentItem()).isNull()) + { + s = m_langSet.shortId(d_shortName->currentItem()); + m_lastPix = locate ("locale", "l10n/"+s+"/flag.png"); + if (m_lastPix.isNull()) { + m_lastPix = locate ("locale", "l10n/"); + } + } + else + { + m_lastPix = locate ("locale", "l10n/"); + } + } + else + { + QFileInfo fi (m_lastPix); + m_lastPix = fi.dirPath()+"/flag.png"; + } + + QString s = KFileDialog::getOpenFileName (m_lastPix, "*.png *.xpm *.gif *.xbm"); + if (!s.isEmpty() ) + { + if (setPixmap (s)) + m_lastPix = s; + else { + b_langPixmap->setText (i18n("Picture is invalid")); + KMessageBox::sorry(this, i18n("File does not contain a valid graphics format\n")); + } + } + } +} + +LangSet LanguageOptions::getLangSet () const +{ + return m_langSet; +} + + +void LanguageOptions::loadCountryData() +{ + // temperary use of our locale as the global locale + KLocale *lsave = KGlobal::_locale; + QString curr_lang = lsave->language(); + +// KLocale locale("kvoctrain"); + KLocale locale(QString::null); + locale.setLanguage(curr_lang); + KGlobal::_locale = &locale; + + QString sub = QString::fromLatin1("l10n/"); + QStringList regionlist = KGlobal::dirs()->findAllResources("locale", sub + QString::fromLatin1("*.desktop")); + regionlist.sort(); + + QMap<QString, Region> regions; + + for (QStringList::ConstIterator it = regionlist.begin(); it != regionlist.end(); ++it) + { + QString tag = *it; + int index; + + index = tag.findRev('/'); + if (index != -1) tag = tag.mid(index + 1); + + index = tag.findRev('.'); + if (index != -1) tag.truncate(index); + + KSimpleConfig entry(*it); + entry.setGroup(QString::fromLatin1("KCM Locale")); + QString name = entry.readEntry(QString::fromLatin1("Name"), i18n("without name")); + + regions.insert(tag, Region(name)); + } + + // add all languages to the list + QStringList countrylist = KGlobal::dirs()->findAllResources("locale", sub + QString::fromLatin1("*/entry.desktop")); + + int idx = 0; + for (QStringList::ConstIterator sit = countrylist.begin(); sit != countrylist.end(); ++sit) + { + KSimpleConfig entry(*sit); + entry.setGroup(QString::fromLatin1("KCM Locale")); + QString name = entry.readEntry(QString::fromLatin1("Name"), i18n("without name")); + QString submenu = entry.readEntry(QString::fromLatin1("Region")); + + QString tag = *sit; + int index = tag.findRev('/'); + tag.truncate(index); + index = tag.findRev('/'); + tag = tag.mid(index+1); + + if (tag == "C") + continue; + + QStringList all_langs = QStringList::split(",", entry.readEntry(QString::fromLatin1("Languages"))); + QValueList<int> langs; + + QString pixmap = *sit; + index = pixmap.findRev('/'); + pixmap.truncate(index); + pixmap += "/flag.png"; + + for (QStringList::Iterator it = all_langs.begin(); it != all_langs.end(); ++it) + { + // Treat ie "en_GB" and "en_USE" as "en" because the language list + // only contains the first letters + if ((*it).find("_")) + *it = (*it).left((*it).find("_")); + + int id = global_langset.indexShortId(*it); + if (id > 0) + { + langs.append(id); + // Set the pixmap of the language to the flag of the first contry that + // has the language as official language + if (global_langset.PixMapFile(id).isEmpty()) + global_langset.setPixMapFile(pixmap, id); + } + //else + //kdDebug() << "Couldn't find the language for: " << *it << endl; + } + + int id = idx++; + countryIdMap.insert(id, Country(name, langs, pixmap, id)); + regions[submenu].countries.append(countryIdMap[id]); + } + + langset_popup = new QPopupMenu(); + + // To have it sorted by name + QMap<QString, Region> regmap; + for (QMap<QString, Region>::Iterator it = regions.begin(); it != regions.end(); ++it) + regmap.insert(it.data().region, it.data()); + + connect(langset_popup, SIGNAL(activated(int)), this, SLOT(slotLangFromGlobalActivated(int))); + for (QMap<QString, Region>::Iterator it = regmap.begin(); it != regmap.end(); ++it) + { + QPopupMenu *regpop = new QPopupMenu(); + connect(regpop, SIGNAL(activated(int)), this, SLOT(slotLangFromGlobalActivated(int))); + langset_popup->insertItem(it.key(), regpop); + Region r = it.data(); + + // To have it sorted by name + QMap<QString, Country> countrymap; + for (QValueList<Country>::Iterator it = r.countries.begin(); it != r.countries.end(); ++it) + { + countrymap.insert((*it).country, *it); + } + for (QMap<QString, Country>::Iterator it = countrymap.begin(); it != countrymap.end(); ++it) + { + regpop->insertItem(QPixmap(it.data().pixmap), it.key(), it.data().id); + } + } + + // restore the old global locale + KGlobal::_locale = lsave; +} + + +void LanguageOptions::slotLangFromGlobalActivated(int i) +{ + if (countryIdMap.contains(i)) + { + Country c = countryIdMap[i]; + bool first = true; + for (QValueList<int>::Iterator it = c.langs.begin(); it != c.langs.end(); ++it) + { + QString s = global_langset.shortId(*it); + + if (d_shortName->contains(s.stripWhiteSpace())) + { + if (first) + { + d_shortName->setCurrentItem(s); + slotShortActivated(s); + first = false; + } + continue; + } + + d_shortName->insertItem(s.stripWhiteSpace()); + m_langSet.addSet(s, global_langset.longId(*it), global_langset.PixMapFile(*it), global_langset.shortId2(*it)); + emit widgetModified(); + m_hasChanged = true; + + if (first) + { + d_shortName->setCurrentItem(d_shortName->count()-1); + slotShortActivated(s); + enableLangWidgets(); + + e_shortName2->setText(global_langset.shortId2(*it)); + slotShort2Changed(e_shortName2->text()); + + e_langLong->setText(global_langset.longId(*it)); + slotLangChanged(global_langset.longId(*it)); + + setPixmap(c.pixmap); + e_newName->setText(""); + e_langLong->setFocus(); + e_langLong->selectAll(); + first = false; + } + } + } +} + + +void LanguageOptions::loadISO6391Data() +{ + for (unsigned id = 0; id < (int)(sizeof(kv_iso639_1) / sizeof(kv_iso639_1[0])) && kv_iso639_1[id].iso1code != 0; ++id) + { + QString s = i18n(kv_iso639_1[id].langname); + global_langset.addSet(kv_iso639_1[id].iso1code, s, QString::null, kv_iso639_1[id].iso2code); + } +} + +void LanguageOptions::createISO6391Menus() +{ + // To have it sorted by name + QMap<QString, int> languages; + for (unsigned id = 0; id < global_langset.size(); ++id) + { + QString s = global_langset.longId(id); + languages.insert(s, id); + } + + iso6391_popup = new QPopupMenu(); + + QPopupMenu *pop = 0; + QString lang = ""; + for (QMap<QString, int>::Iterator it = languages.begin(); it != languages.end(); ++it) + { + if (it.key()[0].upper() != lang[0].upper()) + { + pop = new QPopupMenu(); + connect(pop, SIGNAL(activated(int)), this, SLOT(slotLangFromISO6391Activated(int))); + iso6391_popup->insertItem(it.key()[0].upper(), pop, 1); + } + + lang = it.key(); + QString shortid = global_langset.shortId(it.data()); + QString short2id = global_langset.shortId2(it.data()); + lang += "\t("+shortid+")"; + QString pixmap = global_langset.PixMapFile(it.data()); + if (pixmap.isEmpty()) + pop->insertItem(lang, it.data()); + else + pop->insertItem(QPixmap(pixmap), lang, it.data()); + } +} + +void LanguageOptions::slotLangFromISO6391Activated(int id) +{ + if (id < (int)global_langset.size()) + { + QString shortid = global_langset.shortId(id); + + if (d_shortName->contains(shortid.stripWhiteSpace())) + { + d_shortName->setCurrentItem(shortid); + slotShortActivated(shortid); + return; + } + + d_shortName->insertItem(shortid.stripWhiteSpace()); + d_shortName->setCurrentItem(d_shortName->count()-1); + slotShortActivated(shortid); + enableLangWidgets(); + + e_shortName2->setText(global_langset.shortId2(id)); + slotShort2Changed(global_langset.shortId2(id)); + + e_langLong->setText(global_langset.longId(id)); + slotLangChanged(e_langLong->text()); + + setPixmap(global_langset.PixMapFile(id)); + e_newName->setText(""); + e_langLong->setFocus(); + e_langLong->selectAll(); + } +} + +void LanguageOptions::updateWidgets() +{ +// +} + +bool LanguageOptions::hasChanged() +{ + return m_hasChanged; +} + +bool LanguageOptions::isDefault() +{ + return true; +} + +void LanguageOptions::updateSettings() +{ + Prefs::setNumLangSet(m_langSet.size()); + + for (int i = 0 ; i < (int) m_langSet.size(); i++) + { + LanguageSettings languageSettings(QString::number(i)); + languageSettings.setShortId(m_langSet.shortId(i)); + languageSettings.setShort2Id(m_langSet.shortId2(i)); + languageSettings.setLongId(m_langSet.longId(i)); + languageSettings.setPixmapFile(m_langSet.PixMapFile(i)); + languageSettings.setKeyboardLayout(m_langSet.keyboardLayout(i)); + languageSettings.writeConfig(); + } + m_hasChanged = false; +} + + +#include "languageoptions.moc" + diff --git a/kvoctrain/kvoctrain/common-dialogs/languageoptions.h b/kvoctrain/kvoctrain/common-dialogs/languageoptions.h new file mode 100644 index 00000000..b36d49a3 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/languageoptions.h @@ -0,0 +1,101 @@ +/*************************************************************************** + + language options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 LANGUAGEOPTIONS_H +#define LANGUAGEOPTIONS_H + +#include <qpopupmenu.h> + +#include "languageoptionsbase.h" +#include "langset.h" + +class LanguageOptions : public LanguageOptionsBase +{ + Q_OBJECT + +public: + LanguageOptions(LangSet & langset, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + virtual ~LanguageOptions (); + + LangSet getLangSet () const; + + struct Country + { + Country(const QString& c, const QValueList<int> l, const QString& p, int i) + : country(c), langs(l), pixmap(p), id(i) { } + Country() { } + QString country; + QValueList<int> langs; + QString pixmap; + int id; + }; + + struct Region + { + Region (const QString& reg) + : region(reg) {} + Region() {} + QString region; + QValueList<Country> countries; + }; + + void updateWidgets(); + bool hasChanged(); + bool isDefault(); + void updateSettings(); + +signals: + void widgetModified(); + +protected slots: + void slotDeleteClicked(); + void slotNewClicked(); + void slotPixmapClicked(); + void slotLangChanged(const QString&); + void slotShort2Changed(const QString&); + void slotShortActivated(const QString&); + void slotNewNameChanged(const QString&); + void slotLangFromGlobalActivated(int); + void slotLangFromISO6391Activated(int); + void slotKeyboardLayoutChanged(const QString&); + +private: + bool setPixmap(QString pm); + void enableLangWidgets(); + void loadCountryData(); + void loadISO6391Data(); + void createISO6391Menus(); + + LangSet global_langset; + QMap<int, Country> countryIdMap; + QPopupMenu * langset_popup; + QPopupMenu * iso6391_popup; + LangSet m_langSet; + QString m_lastPix; + bool m_hasChanged; +}; + +#endif + diff --git a/kvoctrain/kvoctrain/common-dialogs/languageoptionsbase.ui b/kvoctrain/kvoctrain/common-dialogs/languageoptionsbase.ui new file mode 100644 index 00000000..84698be7 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/languageoptionsbase.ui @@ -0,0 +1,352 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>LanguageOptionsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>LanguageOptionsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>392</width> + <height>327</height> + </rect> + </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="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>GroupBox3</cstring> + </property> + <property name="title"> + <string>Available Languages</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton" row="0" column="2"> + <property name="name"> + <cstring>b_langDel</cstring> + </property> + <property name="text"> + <string>&Delete</string> + </property> + <property name="toolTip" stdset="0"> + <string>Delete the selected language</string> + </property> + <property name="whatsThis" stdset="0"> + <string>By clicking on this button you can delete the selected language.</string> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>e_shortName2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip" stdset="0"> + <string>Alternative language code</string> + </property> + <property name="whatsThis" stdset="0"> + <string>An alternative language code is set here but you can change it if you want</string> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>e_langLong</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip" stdset="0"> + <string>Your own description of the language code.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>A description of the language is written here and you can modify it if you want.</string> + </property> + </widget> + <widget class="KComboBox" row="4" column="1"> + <property name="name"> + <cstring>d_kblayout</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>Select a language or use the Add New Language Code to add one.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>You can select a language with the drop down box or use the Add New Language Code dialog below to add one.</string> + </property> + </widget> + <widget class="QPushButton" row="3" column="1"> + <property name="name"> + <cstring>b_langPixmap</cstring> + </property> + <property name="text"> + <string></string> + </property> + <property name="toolTip" stdset="0"> + <string>The flag representing the language</string> + </property> + <property name="whatsThis" stdset="0"> + <string>The default flag representing the language is set here but you can choose another picture by clicking on the button.</string> + </property> + </widget> + <widget class="KComboBox" row="0" column="1"> + <property name="name"> + <cstring>d_shortName</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>Select a language or use the Add New Language Code to add one.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>You can select a language with the drop down box or use the Add New Language Code dialog below to add one.</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>label_shortName</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Language c&ode:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>d_shortName</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>You can assign a language to each column</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Each column can be assigned a language. This is internally done with the usual international language codes.</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>label_shortName2</cstring> + </property> + <property name="text"> + <string>Alte&rnative code:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>e_shortName2</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>Select a second language code if necessary</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Sometimes it may be useful to have a second language code because some languages have the usual short code and one or two longer codes.</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>label_langLong</cstring> + </property> + <property name="text"> + <string>Lang&uage name:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>e_langLong</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>Describe the language in your own terms.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Here you can give the language code a descriptive name in your own language which is shown in the header buttons in the main view. </string> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>label_langPixmap</cstring> + </property> + <property name="text"> + <string>&Picture:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>b_langPixmap</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>Set a picture for the language</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Choose a picture to represent the language above.</string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>label_kblayout</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Keyboard layout:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>d_kblayout</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>You can assign a language to each column</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Each column can be assigned a language. This is internally done with the usual international language codes.</string> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox" row="1" column="0"> + <property name="name"> + <cstring>GroupBox2</cstring> + </property> + <property name="title"> + <string>Add New Language Code</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>b_lang_kde</cstring> + </property> + <property name="text"> + <string>Add Language Data From &KDE Database</string> + </property> + <property name="toolTip" stdset="0"> + <string>Obtains the language choices from the KDE database</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Pressing this button opens a menu that contains all the countries that are known in your KDE installation. Ordered by country you can add your desired language properties to your personal list.</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>b_lang_iso1</cstring> + </property> + <property name="text"> + <string>Add Language Data From ISO639-&1</string> + </property> + <property name="accel"> + <string>Alt+1</string> + </property> + <property name="toolTip" stdset="0"> + <string>List of languages covered by ISO639-1</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Pressing this button opens a menu that contains all the language codes that are covered by "ISO639-1"</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>b_langNew</cstring> + </property> + <property name="text"> + <string>&Add</string> + </property> + <property name="toolTip" stdset="0"> + <string>Allow addition of the language you typed.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>This button becomes available when you type a language code in the field.</string> + </property> + </widget> + <widget class="QLineEdit" row="0" column="0"> + <property name="name"> + <cstring>e_newName</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip" stdset="0"> + <string>Type your language code if you know it.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Type the language code if you know it or use one of the 2 buttons below to choose a language code.</string> + </property> + </widget> + </grid> + </widget> + <spacer row="2" column="0"> + <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>390</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> +</widget> +<tabstops> + <tabstop>d_shortName</tabstop> + <tabstop>e_shortName2</tabstop> + <tabstop>e_langLong</tabstop> + <tabstop>b_langPixmap</tabstop> + <tabstop>d_kblayout</tabstop> + <tabstop>b_langDel</tabstop> + <tabstop>e_newName</tabstop> + <tabstop>b_langNew</tabstop> + <tabstop>b_lang_kde</tabstop> + <tabstop>b_lang_iso1</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kcombobox.h</includehint> + <includehint>kcombobox.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/common-dialogs/languagesettings.kcfg b/kvoctrain/kvoctrain/common-dialogs/languagesettings.kcfg new file mode 100644 index 00000000..0203b080 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/languagesettings.kcfg @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 + http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > + <kcfgfile name="kvoctrainrc"> + <parameter name="langId" /> + </kcfgfile> + <group name="Language #$(langId)"> + <entry name="ShortId" type="String"> + <label></label> + <whatsthis></whatsthis> + <default>id</default> + </entry> + <entry name="Short2Id" type="String"> + <label></label> + <whatsthis></whatsthis> + </entry> + <entry name="LongId" type="String"> + <label></label> + <whatsthis></whatsthis> + <default>ident</default> + </entry> + <entry name="PixmapFile" type="String"> + <label></label> + <whatsthis></whatsthis> + <default></default> + </entry> + <entry name="KeyboardLayout" type="String"> + <label></label> + <whatsthis></whatsthis> + <default></default> + </entry> + + </group> + +</kcfg> diff --git a/kvoctrain/kvoctrain/common-dialogs/languagesettings.kcfgc b/kvoctrain/kvoctrain/common-dialogs/languagesettings.kcfgc new file mode 100644 index 00000000..e658d6ac --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/languagesettings.kcfgc @@ -0,0 +1,5 @@ +File=languagesettings.kcfg +ClassName=LanguageSettings +Mutators=true +ItemAccessors=true +SetUserTexts=true diff --git a/kvoctrain/kvoctrain/common-dialogs/pasteoptions.cpp b/kvoctrain/kvoctrain/common-dialogs/pasteoptions.cpp new file mode 100644 index 00000000..cbfcadf4 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/pasteoptions.cpp @@ -0,0 +1,313 @@ +/*************************************************************************** + + paste options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 31 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qpushbutton.h> +#include <qlistbox.h> +#include <qcheckbox.h> +#include <qstringlist.h> + +#include <kcombobox.h> +#include <klocale.h> + +#include "pasteoptions.h" +#include "prefs.h" +#include "kvoctraindoc.h" +#include "langset.h" + +static const char *separator_id[] = +{ + ";", // 0 + "#", // 1 + "!", // 2 + "|", // 3 + ",", // 4 + "\t", // 5 + " ", // 6 + ":", // 7 + "::", // 8 + 0 +}; + +PasteOptions::PasteOptions(LangSet & langset, kvoctrainDoc * doc, QWidget* parent, const char* name, WFlags fl) +: PasteOptionsBase(parent,name,fl), m_langSet(langset) +{ + OrderList->setEnabled(!kcfg_UseCurrent->isChecked()); + UpButton->setEnabled(!kcfg_UseCurrent->isChecked()); + SkipButton->setEnabled(!kcfg_UseCurrent->isChecked()); + DownButton->setEnabled(!kcfg_UseCurrent->isChecked()); + + connect(OrderList, SIGNAL(selectionChanged()), this, SLOT(syncButtons())); + connect(DownButton, SIGNAL(clicked()), this, SLOT(slotDownButtonClicked())); + connect(SkipButton, SIGNAL(clicked()), this, SLOT(slotSkipButtonClicked())); + connect(UpButton, SIGNAL(clicked()), this, SLOT(slotUpButtonClicked())); + + connect(SeparatorCombo, SIGNAL(activated(int)), this, SLOT(slotSeparatorComboActivated(int))); + connect(kcfg_UseCurrent, SIGNAL(toggled(bool)), this, SLOT(slotUseCurrentDocToggled(bool))); + + m_doc = doc; + fillWidgets(); + updateWidgets(); +} + +void PasteOptions::fillWidgets() +{ + SeparatorCombo->insertItem(i18n(";")); + SeparatorCombo->insertItem(i18n("#")); + SeparatorCombo->insertItem(i18n("!")); + SeparatorCombo->insertItem(i18n("|")); + SeparatorCombo->insertItem(i18n(",")); + SeparatorCombo->insertItem(i18n("TAB")); + SeparatorCombo->insertItem(i18n(">= 2 SPACES")); + SeparatorCombo->insertItem(i18n(" : ")); + SeparatorCombo->insertItem(i18n(" :: ")); + + QStringList sl = Prefs::pasteOrder(); + OrderList->clear(); + for (int i = 0; i < (int) sl.count(); i++) + { + QString codename = m_langSet.findLongId(sl[i]); + if (codename.isEmpty()) + codename = sl[i]; + OrderList->insertItem(codename); + } + // any new languages to add to the listbox? + for (int i = 0; i < (int) m_langSet.size(); i++) + { + bool found = false; + for (int j = 0; j < (int) OrderList->count(); j++) + if (OrderList->text(j) == m_langSet.longId(i)) + found = true; + + if (!found) + OrderList->insertItem(m_langSet.longId(i)); + } +} + +void PasteOptions::updateWidgets() +{ + for (int i = 0; i < 9; ++i) + { + if (separator_id[i] == Prefs::separator()) + { + SeparatorCombo->setCurrentItem(i); + break; + } + } +} + + +void PasteOptions::syncButtons() +{ + bool usingCurrent = kcfg_UseCurrent->isChecked(); + OrderList->setDisabled(usingCurrent); + if (OrderList->count() > 1 && !usingCurrent) + { + DownButton->setEnabled(OrderList->currentItem() < (int) OrderList->count()-1); + SkipButton->setEnabled(true); + UpButton->setEnabled(OrderList->currentItem() != 0); + } + else + { + DownButton->setEnabled(false); + SkipButton->setEnabled(false); + UpButton->setEnabled(false); + } +} + +void PasteOptions::slotUpButtonClicked() +{ + if (OrderList->currentItem() > 0 && (int) OrderList->count() > 1) + { + int pos = OrderList->currentItem(); + QString item = OrderList->text(pos); + OrderList->removeItem(pos); + OrderList->insertItem(item, pos-1); + OrderList->setCurrentItem(pos-1); + emit widgetModified(); + } + syncButtons(); +} + +void PasteOptions::slotSkipButtonClicked() +{ + int pos = OrderList->currentItem(); + OrderList->insertItem("", OrderList->currentItem()); + OrderList->setCurrentItem(pos); + syncButtons(); + emit widgetModified(); +} + +void PasteOptions::slotDownButtonClicked() +{ + if ((int)OrderList->currentItem() < (int) OrderList->count()-1 && (int) OrderList->count() > 1) + { + int pos = OrderList->currentItem(); + QString item = OrderList->text(pos); + OrderList->removeItem(pos); + OrderList->insertItem(item, pos+1); + OrderList->setCurrentItem(pos+1); + emit widgetModified(); + } + syncButtons(); +} + +void PasteOptions::slotSeparatorComboActivated(int) +{ + emit widgetModified(); +} + +void PasteOptions::slotUseCurrentDocToggled(bool) +{ + OrderList->clear(); + OrderList->insertItem (m_langSet.findLongId(m_doc->getOriginalIdent())); + for (int i = 1; i < (int) m_doc->numLangs(); i++) + OrderList->insertItem (m_langSet.findLongId(m_doc->getIdent(i))); + + // any other languages to append besides those from doc? + for (int i = 0; i < (int) m_langSet.size(); i++) + { + bool found = false; + for (int j = 0; j < (int) OrderList->count(); j++) + if (OrderList->text(j) == m_langSet.longId(i)) + found = true; + + if (!found) + OrderList->insertItem(m_langSet.longId(i)); + } + + OrderList->setCurrentItem (0); +} + +bool PasteOptions::hasChanged() +{ + bool result; + result = ((separator_id[SeparatorCombo->currentItem()] != Prefs::separator())); + if (result) + return true; + QStringList ol, pl; + pl = Prefs::pasteOrder(); + ol = preparePasteOrderList(); + result = (pl.count() != ol.count()); + if (result) + return true; + for (uint i = 0; i < ol.count(); i--) + { + result = (ol[i] != pl[i]); + if (result) + return true; + } + return false; +} + +bool PasteOptions::isDefault() +{ + return !strcmp(separator_id[SeparatorCombo->currentItem()], "\t"); +} + +void PasteOptions::updateSettings() +{ + Prefs::setSeparator((separator_id[SeparatorCombo->currentItem()])); + Prefs::setPasteOrder(preparePasteOrderList()); +} + + +void PasteOptions::slotSyncPasteOrderList() +{ + for (int j = (int) OrderList->count()-1; j > 1; j--) + { + QString comp = OrderList->text(j); + for (int i = (int) j-1; i >=0; i--) + { + if (OrderList->text(i) == comp && !OrderList->text(i).isEmpty()) + { + OrderList->removeItem(j); + break; + } + } + } + + // order_list contains elements unknown in language set? remove them + for (int i = (int) OrderList->count()-1; i >=0; i--) + { + if (!OrderList->text(i).isEmpty()) + { + if (m_langSet.indexLongId(OrderList->text(i)) < 0) + { + OrderList->removeItem(i); + } + } + } + + // language set contains new elements? append them + for (int i = 0; i < (int) m_langSet.size(); i++) + { + bool found = false; + for (int j = 0; j < (int) OrderList->count(); j++) + if (m_langSet.longId(i) == OrderList->text(j)) + found = true; + + if (!found) + { + if (m_langSet.longId(i).isEmpty()) + OrderList->insertItem(m_langSet.shortId(i)); + else + OrderList->insertItem(m_langSet.longId(i)); + } + } + + // skip "skip" elements at tail + int i; + for (i = (int) OrderList->count()-1; i >= 0 && OrderList->text(i).isEmpty(); i--) + { + if (OrderList->currentItem() > (int) OrderList->count()-2) + OrderList->setCurrentItem(OrderList->count()-2); + OrderList->removeItem(i); + } +} + +QStringList PasteOptions::preparePasteOrderList() +{ + slotSyncPasteOrderList(); + QStringList sl; + // skip "skip" elements at tail + int i; + for (i = (int) OrderList->count()-1; i >= 0 && OrderList->text(i).isEmpty(); i--); + + // insert language codes and "skips" between them + for ( /**/; i >= 0; i--) + { + QString code = m_langSet.findShortId(OrderList->text(i)); + if (code.isEmpty()) + code = OrderList->text(i); // no longId previously available + if (OrderList->text(i).isEmpty()) + sl.insert (sl.begin(), ""); + else + sl.insert (sl.begin(), code); + } + return sl; +} + +#include "pasteoptions.moc" + diff --git a/kvoctrain/kvoctrain/common-dialogs/pasteoptions.h b/kvoctrain/kvoctrain/common-dialogs/pasteoptions.h new file mode 100644 index 00000000..15b1015b --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/pasteoptions.h @@ -0,0 +1,68 @@ +/*************************************************************************** + + paste options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 31 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 PASTEOPTIONS_H +#define PASTEOPTIONS_H + +#include "pasteoptionsbase.h" +#include "langset.h" + +class kvoctrainDoc; + +class PasteOptions : public PasteOptionsBase +{ + Q_OBJECT + +public: + PasteOptions(LangSet & langset, kvoctrainDoc * doc, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + + void updateWidgets(); + bool hasChanged(); + bool isDefault(); + void updateSettings(); + +signals: + void widgetModified(); + void syncPasteOrderList(); + +private slots: + void fillWidgets(); + void syncButtons(); + void slotUpButtonClicked(); + void slotSkipButtonClicked(); + void slotDownButtonClicked(); + void slotSeparatorComboActivated(int); + void slotUseCurrentDocToggled(bool); + +private: + void slotSyncPasteOrderList(); + QStringList preparePasteOrderList(); + kvoctrainDoc * m_doc; + LangSet m_langSet; + +}; + +#endif + diff --git a/kvoctrain/kvoctrain/common-dialogs/pasteoptionsbase.ui b/kvoctrain/kvoctrain/common-dialogs/pasteoptionsbase.ui new file mode 100644 index 00000000..3ee107fc --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/pasteoptionsbase.ui @@ -0,0 +1,214 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>PasteOptionsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>PasteOptionsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>379</width> + <height>275</height> + </rect> + </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="QLabel" row="0" column="0"> + <property name="name"> + <cstring>label_sep</cstring> + </property> + <property name="text"> + <string>Sep&arator:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>SeparatorCombo</cstring> + </property> + </widget> + <widget class="KComboBox" row="0" column="1"> + <property name="name"> + <cstring>SeparatorCombo</cstring> + </property> + <property name="minimumSize"> + <size> + <width>140</width> + <height>0</height> + </size> + </property> + <property name="toolTip" stdset="0"> + <string>Choose which separator you want to use to separate your data.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Choose one separator which will divide the parts of an expression when transferring data from or to another application over the clipboard.</string> + </property> + </widget> + <spacer row="0" column="2"> + <property name="name"> + <cstring>Spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>310</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QGroupBox" row="1" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>label_order</cstring> + </property> + <property name="title"> + <string>Order</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QListBox" row="1" column="0" rowspan="4" colspan="1"> + <property name="name"> + <cstring>OrderList</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QPushButton" row="3" column="1"> + <property name="name"> + <cstring>DownButton</cstring> + </property> + <property name="text"> + <string>&Down</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="1"> + <property name="name"> + <cstring>SkipButton</cstring> + </property> + <property name="text"> + <string>S&kip</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>UpButton</cstring> + </property> + <property name="text"> + <string>&Up</string> + </property> + </widget> + <widget class="QCheckBox" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>kcfg_UseCurrent</cstring> + </property> + <property name="text"> + <string>Use &current document</string> + </property> + <property name="toolTip" stdset="0"> + <string>Check this if you want the items in the clipboard to be in the same language order as the current document.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When checked, the items in the clipboard are assumed to be in the same language order as the current document.</string> + </property> + </widget> + <spacer row="4" column="1"> + <property name="name"> + <cstring>spacer5</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>21</width> + <height>21</height> + </size> + </property> + </spacer> + </grid> + </widget> + <spacer row="2" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>80</width> + <height>31</height> + </size> + </property> + </spacer> + </grid> +</widget> +<connections> + <connection> + <sender>kcfg_UseCurrent</sender> + <signal>toggled(bool)</signal> + <receiver>OrderList</receiver> + <slot>setDisabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseCurrent</sender> + <signal>toggled(bool)</signal> + <receiver>UpButton</receiver> + <slot>setDisabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseCurrent</sender> + <signal>toggled(bool)</signal> + <receiver>DownButton</receiver> + <slot>setDisabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseCurrent</sender> + <signal>toggled(bool)</signal> + <receiver>SkipButton</receiver> + <slot>setDisabled(bool)</slot> + </connection> +</connections> +<tabstops> + <tabstop>SeparatorCombo</tabstop> + <tabstop>kcfg_UseCurrent</tabstop> + <tabstop>OrderList</tabstop> + <tabstop>UpButton</tabstop> + <tabstop>SkipButton</tabstop> + <tabstop>DownButton</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kcombobox.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/common-dialogs/prefs.kcfgc b/kvoctrain/kvoctrain/common-dialogs/prefs.kcfgc new file mode 100644 index 00000000..bb9ed639 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/prefs.kcfgc @@ -0,0 +1,7 @@ +# Code generation options for kconfig_compiler +IncludeFiles=../kv_resource.h,../kvt-core/kvoctrainexpr.h +File=kvoctrain.kcfg +ClassName=Prefs +Singleton=true +Mutators=true +Visibility=KDE_EXPORT
\ No newline at end of file diff --git a/kvoctrain/kvoctrain/common-dialogs/presettings.kcfg b/kvoctrain/kvoctrain/common-dialogs/presettings.kcfg new file mode 100644 index 00000000..3a20eeca --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/presettings.kcfg @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 + http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > + <kcfgfile name="kvoctrainrc"> + <parameter name="settingsId" /> + </kcfgfile> + <group name="Presetting #$(settingsId)"> + <entry name="Name" type="String"> + <label>Name of the settings profile</label> + <whatsthis></whatsthis> + </entry> + <entry name="Query" type="String"> + <label></label> + <whatsthis></whatsthis> + </entry> + <entry name="Threshold" type="String"> + <label></label> + <whatsthis></whatsthis> + </entry> + <entry name="Blocking" type="String"> + <label></label> + <whatsthis></whatsthis> + </entry> + </group> +</kcfg> diff --git a/kvoctrain/kvoctrain/common-dialogs/presettings.kcfgc b/kvoctrain/kvoctrain/common-dialogs/presettings.kcfgc new file mode 100644 index 00000000..9c389dfe --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/presettings.kcfgc @@ -0,0 +1,5 @@ +File=presettings.kcfg +ClassName=PreSettings +Mutators=true +ItemAccessors=true +SetUserTexts=true diff --git a/kvoctrain/kvoctrain/common-dialogs/profilesdialog.cpp b/kvoctrain/kvoctrain/common-dialogs/profilesdialog.cpp new file mode 100644 index 00000000..d6669e7b --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/profilesdialog.cpp @@ -0,0 +1,370 @@ +/*************************************************************************** + profilesdialog.cpp - KVocTrain profiles dialog + + ------------------- + begin : Fri Apr 29 2005 + + copyright : (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qcombobox.h> +#include <qpushbutton.h> + +#include <kdialogbase.h> +#include <klocale.h> +#include <kinputdialog.h> +#include <klocale.h> + +#include "profilesdialog.h" +#include "groupoptions.h" +#include "presettings.h" +#include "prefs.h" +#include "QueryManager.h" + +SettingsProfile::SettingsProfile( ) +{ +} + +SettingsProfile::SettingsProfile(QString n, QString q, QString t, QString b) +: name(n), query_set(q), thresh_set(t), block_set(b) +{ +} + +ProfilesDialog::ProfilesDialog(QueryManager * m, QWidget *parent, const char *name, bool modal) + : KDialogBase(Swallow, i18n("Profiles"), Close, Close, parent, name, modal, false) +{ + m_queryManager = m; + mw = new GroupOptions(this); + setMainWidget(mw); + + connect(mw->ps_del, SIGNAL(clicked()), this, SLOT(slotDeleteGroup())); + connect(mw->ps_new, SIGNAL(clicked()), this, SLOT(slotNewGroup())); + connect(mw->ps_recall, SIGNAL(clicked()), this, SLOT(slotRecallGroup())); + connect(mw->ps_store, SIGNAL(clicked()), this, SLOT(slotStoreGroup())); + + int ls = Prefs::numPreSetting(); + for (int i = 0 ; i < ls; i++) + { + PreSettings preSettings(QString::number(i)); + preSettings.readConfig(); + profiles.append(SettingsProfile(preSettings.name(), preSettings.query(), + preSettings.threshold(), preSettings.blocking())); + mw->ps_name->insertItem(preSettings.name()); + } + + mw->updateButtons(); +} + +void ProfilesDialog::slotDeleteGroup() +{ + if (mw->ps_name->count() != 0) + { + int curr = mw->ps_name->currentItem(); + mw->ps_name->removeItem(curr); + profiles.remove(profiles.at(curr)); + if (curr >= mw->ps_name->count()-1) + mw->ps_name->setCurrentItem(mw->ps_name->count()-1); + } + saveProfiles(); + mw->updateButtons(); +} + +void ProfilesDialog::slotNewGroup() +{ + bool ok; + QString newGroupName = KInputDialog::getText(i18n("Profile Description"), + i18n("Enter profile description:"), QString::null, &ok); + + if (ok) + { + newGroupName = newGroupName.stripWhiteSpace(); + mw->ps_name->insertItem(newGroupName); + profiles.append(SettingsProfile(newGroupName, "", "", "")); + modifyProfile(profiles.count()-1); + mw->ps_name->setCurrentItem(mw->ps_name->count()-1); + selectProfile(mw->ps_name->currentItem()); + mw->updateButtons(); + } +} + +void ProfilesDialog::slotRecallGroup() +{ + if (mw->ps_name->count() != 0) + selectProfile(mw->ps_name->currentItem()); +} + + +void ProfilesDialog::slotStoreGroup() +{ + if (mw->ps_name->count() != 0) + modifyProfile(mw->ps_name->currentItem()); +} + + + +static bool extract (QString &line, QString &ret) +{ + int lim = line.find (","); + if (lim < 0) + { + ret = ""; + line = ""; + return false; + } + else + { + ret = line.left(lim); + line.remove(0, lim+1); + } + + return true; +} + +void ProfilesDialog::selectProfile(int profile) +{ + if (profile < (int) profiles.count()) + { + QString line = profiles[profile].query_set; + QString s; + Prefs::setMaxTimePer(0); + Prefs::setSwapDirection(false); + Prefs::setAltLearn(false); + Prefs::setShowCounter(false); + //kvq_timeout_t type_to = kvq_notimeout; + Prefs::setSuggestions(false); + Prefs::setSplit(false); + Prefs::setPeriods(true); + Prefs::setColons(false); + Prefs::setSemicolons(true); + Prefs::setCommas(false); + Prefs::setFields(5); + Prefs::setShowMore(true); + Prefs::setIKnow(true); + if (extract (line, s)) + Prefs::setMaxTimePer(s.toInt()); + if (extract (line, s)) + Prefs::setSwapDirection((bool) s.toInt()); + if (extract (line, s)) + Prefs::setAltLearn((bool) s.toInt()); + if (extract (line, s)) + Prefs::setShowCounter((bool) s.toInt()); + if (extract (line, s)) + Prefs::setQueryTimeout(s.toInt()); + if (extract (line, s)) + Prefs::setSuggestions((bool) s.toInt()); + if (extract (line, s)) + Prefs::setSplit((bool) s.toInt()); + if (extract (line, s)) + Prefs::setPeriods((bool) s.toInt()); + if (extract (line, s)) + Prefs::setColons((bool) s.toInt()); + if (extract (line, s)) + Prefs::setSemicolons((bool) s.toInt()); + if (extract (line, s)) + Prefs::setCommas((bool) s.toInt()); + if (extract (line, s)) + Prefs::setFields(s.toInt()); + if (extract (line, s)) + Prefs::setShowMore((bool) s.toInt()); + if (extract (line, s)) + Prefs::setIKnow((bool) s.toInt()); + +#define QCT(x) Prefs::EnumCompType::type(x) + + line = profiles[profile].thresh_set; + + line.stripWhiteSpace(); + if (line.length() != 0 && line[0] == '(') + { // new style: multiple lessons + int pos; + line.remove(0, 1); + if ((pos = line.find(')')) > 0) + { + s = line.left (pos); + line.remove (0, pos+1); + } + else + { + s = line; + line = ""; + } + m_queryManager->setLessonItemStr(s); + } + else if (extract (line, s)) + m_queryManager->setLessonItemStr(s); + + if (extract (line, s)) + Prefs::setCompType(Prefs::EnumType::Lesson, QCT(s.toInt())); + if (extract (line, s)) + Prefs::setTypeItem(s); // s.toInt() + if (extract (line, s)) + Prefs::setCompType(Prefs::EnumType::WordType, QCT(s.toInt())) /*manager.setTypeComp(QCT(s.toInt()))*/; + if (extract (line, s)) + Prefs::setGradeItem(s.toInt()); + if (extract (line, s)) + Prefs::setCompType(Prefs::EnumType::Grade, QCT(s.toInt())); + if (extract (line, s)) + Prefs::setQueryItem(s.toInt()); + if (extract (line, s)) + Prefs::setCompType(Prefs::EnumType::Query, QCT(s.toInt())); + if (extract (line, s)) + Prefs::setBadItem(s.toInt()); + if (extract (line, s)) + Prefs::setCompType(Prefs::EnumType::Bad, QCT(s.toInt())); + if (extract (line, s)) + Prefs::setDateItem(s.toInt()); + if (extract (line, s)) + Prefs::setCompType(Prefs::EnumType::Date, QCT(s.toInt())); + +#undef QCT + + line = profiles[profile].block_set; + Prefs::setBlock(false); + Prefs::setExpire(false); + + if (extract (line, s)) + Prefs::setBlock((bool) s.toInt()); + if (extract (line, s)) + Prefs::setBlockItem(KV_LEV1_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setBlockItem(KV_LEV2_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setBlockItem(KV_LEV3_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setBlockItem(KV_LEV4_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setBlockItem(KV_LEV5_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setBlockItem(KV_LEV6_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setBlockItem(KV_LEV7_GRADE, s.toInt()); + + if (extract (line, s)) + Prefs::setExpire((bool) s.toInt()); + if (extract (line, s)) + Prefs::setExpireItem(KV_LEV1_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setExpireItem(KV_LEV2_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setExpireItem(KV_LEV3_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setExpireItem(KV_LEV4_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setExpireItem(KV_LEV5_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setExpireItem(KV_LEV6_GRADE, s.toInt()); + if (extract (line, s)) + Prefs::setExpireItem(KV_LEV7_GRADE, s.toInt()); + } + emit profileActivated(); +} + +void ProfilesDialog::modifyProfile(int profile) +{ + if (profile == -1) + return; + + if (profile < (int) profiles.count()) + { + QString s; + QString line; + + s.setNum(Prefs::maxTimePer()); + line += s + ','; + s.setNum(Prefs::swapDirection()); + line += s + ','; + s.setNum(Prefs::altLearn()); + line += s + ','; + s.setNum((int) Prefs::showCounter()); + line += s + ','; + s.setNum( (int) Prefs::queryTimeout() /*getTypeQueryTimeout()*/); + line += s + ','; + s.setNum((int) Prefs::suggestions()); + line += s + ','; + s.setNum((int) Prefs::split()); + line += s + ','; + s.setNum((int) Prefs::periods()); + line += s + ','; + s.setNum((int) Prefs::colons()); + line += s + ','; + s.setNum((int) Prefs::semicolons()); + line += s + ','; + s.setNum((int) Prefs::commas()); + line += s + ','; + s.setNum(Prefs::fields()); + line += s + ','; + s.setNum((int) Prefs::showMore()); + line += s + ','; + s.setNum((int) Prefs::iKnow()); + line += s + ','; + profiles[profile].query_set = line; + + line = '(' + m_queryManager->lessonItemStr() + ')'; + s.setNum((int) Prefs::compType(Prefs::EnumType::Lesson)); + line += s + ','; + s = Prefs::typeItem(); + line += s + ','; + s.setNum((int) Prefs::compType(Prefs::EnumType::WordType) /*manager.typeComp()*/); + line += s + ','; + s.setNum(Prefs::gradeItem()); + line += s + ','; + s.setNum((int) Prefs::compType(Prefs::EnumType::Grade)); + line += s + ','; + s.setNum(Prefs::queryItem()); + line += s + ','; + s.setNum((int) Prefs::compType(Prefs::EnumType::Query)); + line += s + ','; + s.setNum(Prefs::badItem()); + line += s + ','; + s.setNum((int) Prefs::compType(Prefs::EnumType::Bad)); + line += s + ','; + s.setNum(Prefs::dateItem()); + line += s + ','; + s.setNum((int) Prefs::compType(Prefs::EnumType::WordType)); + line += s + ','; + profiles[profile].thresh_set = line; + + s.setNum(Prefs::block()); + line = s + ','; + for (int i = KV_LEV1_GRADE; i <= KV_MAX_GRADE; i++) + { + s.setNum(Prefs::blockItem(i)); + line += s + ','; + } + + s.setNum(Prefs::expire()); + line += s + ','; + for (int i = KV_LEV1_GRADE; i <= KV_MAX_GRADE; i++) + { + s.setNum(Prefs::expireItem(i)); + line += s + ','; + } + profiles[profile].block_set = line; + } + saveProfiles(); +} + +void ProfilesDialog::saveProfiles( ) +{ + Prefs::setNumPreSetting(profiles.count()); + for (int i = 0 ; i < (int) profiles.count(); i++) + { + PreSettings preSettings(QString::number(i)); + preSettings.setName(profiles[i].name); + preSettings.setQuery(profiles[i].query_set); + preSettings.setThreshold(profiles[i].thresh_set); + preSettings.setBlocking(profiles[i].block_set); + preSettings.writeConfig(); + } +} + +#include "profilesdialog.moc" diff --git a/kvoctrain/kvoctrain/common-dialogs/profilesdialog.h b/kvoctrain/kvoctrain/common-dialogs/profilesdialog.h new file mode 100644 index 00000000..827ba191 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/profilesdialog.h @@ -0,0 +1,73 @@ +/*************************************************************************** + profilesdialog.h - KVocTrain profiles dialog + + ------------------- + begin : Fri Apr 29 2005 + + copyright : (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 PROFILESDIALOG_H +#define PROFILESDIALOG_H + +#include <qvaluelist.h> + +#include <kdialogbase.h> + +/** +@author Peter Hedlund +*/ + +class QueryManager; +class GroupOptions; + +class SettingsProfile +{ +public: + SettingsProfile(); + SettingsProfile (QString n, QString q, QString t, QString b); + + QString name; + QString query_set; + QString thresh_set; + QString block_set; +}; + +class ProfilesDialog : public KDialogBase +{ + Q_OBJECT + +public: + ProfilesDialog(QueryManager * m, QWidget *parent = 0, const char *name = 0, bool modal = true); + +signals: + void profileActivated(); + +protected slots: + void slotDeleteGroup(); + void slotNewGroup(); + void slotStoreGroup(); + void slotRecallGroup(); + +private: + void selectProfile(int profile); + void modifyProfile(int profile); + void saveProfiles(); + + typedef QValueList<SettingsProfile> Profiles; + Profiles profiles; + QueryManager * m_queryManager; + GroupOptions * mw; +}; + +#endif diff --git a/kvoctrain/kvoctrain/common-dialogs/queryoptions.cpp b/kvoctrain/kvoctrain/common-dialogs/queryoptions.cpp new file mode 100644 index 00000000..b1677e3f --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/queryoptions.cpp @@ -0,0 +1,72 @@ +/*************************************************************************** + + query options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qgroupbox.h> +#include <qcheckbox.h> +#include <qradiobutton.h> +#include <qlabel.h> +#include <qbuttongroup.h> + +#include <knuminput.h> + +#include "queryoptions.h" +#include "prefs.h" + +QueryOptions::QueryOptions(QWidget* parent, const char* name, WFlags fl) +: QueryOptionsBase(parent,name,fl) +{ + kcfg_MaxTimePer->setDisabled(r_no_limit->isChecked()); + kcfg_ShowCounter->setDisabled(r_no_limit->isChecked()); + label_mqtime->setDisabled(r_no_limit->isChecked()); + kcfg_Periods->setEnabled(kcfg_Split->isChecked()); + kcfg_Colons->setEnabled(kcfg_Split->isChecked()); + kcfg_Semicolons->setEnabled(kcfg_Split->isChecked()); + kcfg_Commas->setEnabled(kcfg_Split->isChecked()); + kcfg_Fields->setEnabled(kcfg_Split->isChecked()); + label_at->setEnabled(kcfg_Split->isChecked()); + label_split_max_fields->setEnabled(kcfg_Split->isChecked()); +} + +void QueryOptions::updateWidgets() +{ + //This is required for loading profiles properly + kcfg_QueryTimeout->setButton((int) Prefs::queryTimeout()); + kcfg_MaxTimePer->setValue(Prefs::maxTimePer()); + kcfg_ShowCounter->setChecked(Prefs::showCounter()); + kcfg_SwapDirection->setChecked(Prefs::swapDirection()); + kcfg_AltLearn->setChecked(Prefs::altLearn()); + kcfg_Suggestions->setChecked(Prefs::suggestions()); + kcfg_Split->setChecked(Prefs::split()); + kcfg_Periods->setChecked(Prefs::periods()); + kcfg_Colons->setChecked(Prefs::colons()); + kcfg_Semicolons->setChecked(Prefs::semicolons()); + kcfg_Commas->setChecked(Prefs::commas()); + kcfg_Fields->setValue(Prefs::fields()); + kcfg_ShowMore->setChecked(Prefs::showMore()); + kcfg_IKnow->setChecked(Prefs::iKnow()); +} + +#include "queryoptions.moc" + diff --git a/kvoctrain/kvoctrain/common-dialogs/queryoptions.h b/kvoctrain/kvoctrain/common-dialogs/queryoptions.h new file mode 100644 index 00000000..b424cbb2 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/queryoptions.h @@ -0,0 +1,42 @@ +/*************************************************************************** + + query options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 QUERYOPTIONS_H +#define QUERYOPTIONS_H + +#include "queryoptionsbase.h" + +class QueryOptions : public QueryOptionsBase +{ + Q_OBJECT + +public: + QueryOptions(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + + void updateWidgets(); +}; + +#endif + diff --git a/kvoctrain/kvoctrain/common-dialogs/queryoptionsbase.ui b/kvoctrain/kvoctrain/common-dialogs/queryoptionsbase.ui new file mode 100644 index 00000000..24e70c58 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/queryoptionsbase.ui @@ -0,0 +1,573 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>QueryOptionsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>QueryOptionsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>452</width> + <height>404</height> + </rect> + </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="2" column="0"> + <property name="name"> + <cstring>kcfg_AltLearn</cstring> + </property> + <property name="text"> + <string>&Use alternative learning method</string> + </property> + <property name="toolTip" stdset="0"> + <string>Use the Leitner learning method</string> + </property> + <property name="whatsThis" stdset="0"> + <string>By checking this, you will use the Leitner method of learning which requires you to answer correctly to each question 4 times in a row. </string> + </property> + </widget> + <widget class="QCheckBox" row="1" column="0"> + <property name="name"> + <cstring>kcfg_SwapDirection</cstring> + </property> + <property name="text"> + <string>S&wap direction randomly</string> + </property> + </widget> + <widget class="QGroupBox" row="3" column="0"> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="title"> + <string>Random Query Options</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox" row="0" column="0" rowspan="1" colspan="7"> + <property name="name"> + <cstring>kcfg_Suggestions</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>&Enable suggestion lists</string> + </property> + <property name="toolTip" stdset="0"> + <string>If checked, pressing F5 or F6 will display a list of suggestions</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When this options is enabled, you can enter part of an answer, then press F5 or F6 to get a list of translations starting with or containing the text you typed.</string> + </property> + </widget> + <widget class="QCheckBox" row="1" column="0" rowspan="1" colspan="7"> + <property name="name"> + <cstring>kcfg_Split</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Split &translations</string> + </property> + <property name="toolTip" stdset="0"> + <string>Split translations and show multiple answer fields</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When this options is enabled, the program will split translations into several parts, show multiple answer fields, and you will need to answer each one of them. This is useful for example when a word has several meanings that have different translations in the other language.</string> + </property> + </widget> + <widget class="QLabel" row="3" column="1" rowspan="1" colspan="3"> + <property name="name"> + <cstring>label_split_max_fields</cstring> + </property> + <property name="text"> + <string>Maximum number of &fields:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_Fields</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>Maximum number of fields to split translations into</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Enter the maximum number of answer fields you want to have. When splitting translations, the program will only split into this many parts, and the last part will contain the rest of the translation.</string> + </property> + </widget> + <widget class="QCheckBox" row="5" column="0" rowspan="1" colspan="7"> + <property name="name"> + <cstring>kcfg_IKnow</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Enable I Know &button</string> + </property> + <property name="toolTip" stdset="0"> + <string>Enable the I Know It button on the Random Query screen</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If this is checked, the I Know button will be available. It allows you to tell the query that you know the result without writing it or having it checked. This is available by default. If you uncheck this, the I Know button will not be available.</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>label_at</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>at</string> + </property> + </widget> + <widget class="QCheckBox" row="2" column="2"> + <property name="name"> + <cstring>kcfg_Periods</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>pe&riods</string> + </property> + <property name="toolTip" stdset="0"> + <string>Split translations at periods</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When this options is enabled, translations will be split at periods if they have any (except any trailing periods that will be removed).</string> + </property> + </widget> + <widget class="QCheckBox" row="2" column="4"> + <property name="name"> + <cstring>kcfg_Semicolons</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>sem&icolons</string> + </property> + <property name="toolTip" stdset="0"> + <string>Split translations at semicolons</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When this options is enabled, translations that have not been split at periods or colons will be split at semicolons if they have any.</string> + </property> + </widget> + <widget class="QCheckBox" row="2" column="5" rowspan="1" colspan="2"> + <property name="name"> + <cstring>kcfg_Commas</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>co&mmas</string> + </property> + <property name="toolTip" stdset="0"> + <string>Split translations at commas</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When this options is enabled, translations that have not been split at periods, colons or semicolons will be split at commas if they have any.</string> + </property> + </widget> + <widget class="QCheckBox" row="2" column="3"> + <property name="name"> + <cstring>kcfg_Colons</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>co&lons</string> + </property> + <property name="toolTip" stdset="0"> + <string>Split translations at colons</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When this options is enabled, translations that have not been split at periods will be split at colons if they have any.</string> + </property> + </widget> + <widget class="QCheckBox" row="4" column="0" rowspan="1" colspan="7"> + <property name="name"> + <cstring>kcfg_ShowMore</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Enable S&how More button</string> + </property> + <property name="toolTip" stdset="0"> + <string>Enable the Show More button on the Random Query screen</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When this is checked, you will be able to use a Show More button which allow you to get the next letter in your answer in the query. If this is unchecked, the Show More button will not be enabled, you will not be able to use it.</string> + </property> + </widget> + <spacer row="2" column="0" rowspan="2" colspan="1"> + <property name="name"> + <cstring>spacer12</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Minimum</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>48</height> + </size> + </property> + </spacer> + <widget class="KIntNumInput" row="3" column="4" rowspan="1" colspan="2"> + <property name="name"> + <cstring>kcfg_Fields</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>32767</height> + </size> + </property> + <property name="minValue"> + <number>2</number> + </property> + <property name="maxValue"> + <number>10</number> + </property> + <property name="toolTip" stdset="0"> + <string>Maximum number of fields to split translations into</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Enter the maximum number of answer fields you want to have. When splitting translations, the program will only split into this many parts, and the last part will contain the rest of the translation.</string> + </property> + </widget> + <spacer row="3" column="6"> + <property name="name"> + <cstring>spacer13</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>111</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> + </widget> + <spacer row="4" column="0"> + <property name="name"> + <cstring>spacer6</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>290</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>QueryTimeout</cstring> + </property> + <property name="title"> + <string>Time Per Query</string> + </property> + <property name="exclusive" stdset="0"> + <bool>false</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QButtonGroup" row="0" column="0" rowspan="2" colspan="1"> + <property name="name"> + <cstring>kcfg_QueryTimeout</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="title"> + <string></string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QRadioButton" row="1" column="0"> + <property name="name"> + <cstring>r_show_to</cstring> + </property> + <property name="text"> + <string>&Show solution</string> + </property> + <property name="buttonGroupId"> + <number>1</number> + </property> + </widget> + <widget class="QRadioButton" row="0" column="0"> + <property name="name"> + <cstring>r_no_limit</cstring> + </property> + <property name="text"> + <string>&No time limitation</string> + </property> + <property name="buttonGroupId"> + <number>0</number> + </property> + <property name="toolTip" stdset="0"> + <string>Check this if you do not want any time limitation per query.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When this is checked, there is no time limitation for each query</string> + </property> + </widget> + <widget class="QRadioButton" row="2" column="0"> + <property name="name"> + <cstring>r_cont_to</cstring> + </property> + <property name="text"> + <string>&Continue after timeout</string> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget" row="0" column="1"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>label_mqtime</cstring> + </property> + <property name="text"> + <string>Ma&x. time (s):</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_MaxTimePer</cstring> + </property> + </widget> + <widget class="QCheckBox" row="1" column="1"> + <property name="name"> + <cstring>kcfg_ShowCounter</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>S&how remaining time</string> + </property> + <property name="toolTip" stdset="0"> + <string>If checked, activate a progress bar to show the remaining time.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Check this button if you want to activate a progress bar to show the remaining time for each query.</string> + </property> + </widget> + <spacer row="1" column="0"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Minimum</enum> + </property> + <property name="sizeHint"> + <size> + <width>83</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KIntNumInput" row="0" column="1"> + <property name="name"> + <cstring>kcfg_MaxTimePer</cstring> + </property> + <property name="minValue"> + <number>0</number> + </property> + <property name="maxValue"> + <number>604800</number> + </property> + <property name="toolTip" stdset="0"> + <string>Set the maximum time allowed per query.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>You may set a time limit KVocTrain grants you to remember the correct answer. Set here the maximum time you want to allow per query.</string> + </property> + </widget> + </grid> + </widget> + <spacer row="1" column="1"> + <property name="name"> + <cstring>spacer9</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>200</width> + <height>16</height> + </size> + </property> + </spacer> + </grid> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>kcfg_Split</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_Periods</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_Split</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_Colons</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_Split</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_Semicolons</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_Split</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_Commas</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_Split</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_Fields</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>r_no_limit</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_MaxTimePer</receiver> + <slot>setDisabled(bool)</slot> + </connection> + <connection> + <sender>r_no_limit</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_ShowCounter</receiver> + <slot>setDisabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_Split</sender> + <signal>toggled(bool)</signal> + <receiver>label_at</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_Split</sender> + <signal>toggled(bool)</signal> + <receiver>label_split_max_fields</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>r_no_limit</sender> + <signal>toggled(bool)</signal> + <receiver>label_mqtime</receiver> + <slot>setDisabled(bool)</slot> + </connection> +</connections> +<tabstops> + <tabstop>kcfg_MaxTimePer</tabstop> + <tabstop>kcfg_ShowCounter</tabstop> + <tabstop>kcfg_SwapDirection</tabstop> + <tabstop>kcfg_AltLearn</tabstop> + <tabstop>kcfg_Suggestions</tabstop> + <tabstop>kcfg_Split</tabstop> + <tabstop>kcfg_Periods</tabstop> + <tabstop>kcfg_Colons</tabstop> + <tabstop>kcfg_Semicolons</tabstop> + <tabstop>kcfg_Commas</tabstop> + <tabstop>kcfg_Fields</tabstop> + <tabstop>kcfg_ShowMore</tabstop> + <tabstop>kcfg_IKnow</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/common-dialogs/thresholdoptions.cpp b/kvoctrain/kvoctrain/common-dialogs/thresholdoptions.cpp new file mode 100644 index 00000000..e611eb36 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/thresholdoptions.cpp @@ -0,0 +1,450 @@ +/*************************************************************************** + + threshold options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qlistbox.h> +#include <qpushbutton.h> +#include <qlabel.h> +#include <qcombobox.h> + +#include <kcombobox.h> +#include <klocale.h> + +#include "thresholdoptions.h" +#include "QueryManager.h" +#include "prefs.h" + + +static Prefs::EnumCompType::type bad_complist[] = + {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::MoreThan, Prefs::EnumCompType::MoreEqThan, + Prefs::EnumCompType::EqualTo, Prefs::EnumCompType::NotEqual, Prefs::EnumCompType::LessEqThan, + Prefs::EnumCompType::LessThan, Prefs::EnumCompType::type(-1)}; + +static Prefs::EnumCompType::type query_complist[] = + {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::MoreThan, Prefs::EnumCompType::MoreEqThan, + Prefs::EnumCompType::EqualTo, Prefs::EnumCompType::NotEqual, Prefs::EnumCompType::LessEqThan, + Prefs::EnumCompType::LessThan, Prefs::EnumCompType::type(-1)}; + +static Prefs::EnumCompType::type grade_complist[] = + {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::WorseThan, Prefs::EnumCompType::WorseEqThan, + Prefs::EnumCompType::EqualTo, Prefs::EnumCompType::NotEqual, Prefs::EnumCompType::BetterEqThan, + Prefs::EnumCompType::BetterThan, Prefs::EnumCompType::type(-1)}; + +static Prefs::EnumCompType::type type_complist[] = + {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::EqualTo, Prefs::EnumCompType::NotEqual, + Prefs::EnumCompType::type(-1)}; + +static Prefs::EnumCompType::type date_complist[] = + {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::Before, Prefs::EnumCompType::Within, + Prefs::EnumCompType::NotQueried, Prefs::EnumCompType::type(-1)}; + +static Prefs::EnumCompType::type less_complist[] = + {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::OneOf, Prefs::EnumCompType::NotOneOf, + Prefs::EnumCompType::Current, Prefs::EnumCompType::NotAssigned, Prefs::EnumCompType::type(-1)}; + +struct ThreshListRef +{ + const char *text; + long int num; +}; + +static ThreshListRef Threshdate_itemlist [] = + { + {I18N_NOOP("30 Min"), 30*60}, + {I18N_NOOP("1 Hour"), 1 * 60*60}, + {I18N_NOOP("2 Hours"), 2 * 60*60}, + {I18N_NOOP("4 Hours"), 4 * 60*60}, + {I18N_NOOP("8 Hours"), 8 * 60*60}, + {I18N_NOOP("12 Hours"), 12 * 60*60}, + {I18N_NOOP("18 Hours"), 18 * 60*60}, + + {I18N_NOOP("1 Day"), 1 * 60*60*24}, + {I18N_NOOP("2 Days"), 2 * 60*60*24}, + {I18N_NOOP("3 Days"), 3 * 60*60*24}, + {I18N_NOOP("4 Days"), 4 * 60*60*24}, + {I18N_NOOP("5 Days"), 5 * 60*60*24}, + {I18N_NOOP("6 Days"), 6 * 60*60*24}, + + {I18N_NOOP("1 Week"), 1 * 60*60*24*7}, + {I18N_NOOP("2 Weeks"), 2 * 60*60*24*7}, + {I18N_NOOP("3 Weeks"), 3 * 60*60*24*7}, + {I18N_NOOP("4 Weeks"), 4 * 60*60*24*7}, + + {I18N_NOOP("1 Month"), 1 * 60*60*24*30}, + {I18N_NOOP("2 Months"), 2 * 60*60*24*30}, + {I18N_NOOP("3 Months"), 3 * 60*60*24*30}, + {I18N_NOOP("4 Months"), 4 * 60*60*24*30}, + {I18N_NOOP("5 Months"), 5 * 60*60*24*30}, + {I18N_NOOP("6 Months"), 6 * 60*60*24*30}, + {0, 0} + }; + + +ThresholdOptions::ThresholdOptions(KComboBox * lessons, QueryManager * m, QWidget* parent, const char* name, WFlags fl) +: ThresholdOptionsBase(parent, name, fl), m_lessons(lessons) +{ + connect(lessoncomp, SIGNAL(activated(int)), SLOT(slotSetLessonComp(int))); + connect(lessonlist, SIGNAL(selectionChanged()), SIGNAL(widgetModified())); + connect(b_all_less, SIGNAL(clicked()), SLOT(slotSelectAll())); + connect(b_none_less, SIGNAL(clicked()), SLOT(slotSelectNone())); + connect(typecomp, SIGNAL(activated(int)), SLOT(slotSetTypeComp(int))); + connect(typelist, SIGNAL(activated(int)), SLOT(slotComboActivated(int))); + connect(gradecomp, SIGNAL(activated(int)), SLOT(slotSetGradeComp(int))); + connect(gradelist, SIGNAL(activated(int)), SLOT(slotComboActivated(int))); + connect(querycomp, SIGNAL(activated(int)), SLOT(slotSetQueryComp(int))); + connect(querylist, SIGNAL(activated(int)), SLOT(slotComboActivated(int))); + connect(badcomp, SIGNAL(activated(int)), SLOT(slotSetBadComp(int))); + connect(badlist, SIGNAL(activated(int)), SLOT(slotComboActivated(int))); + connect(datecomp, SIGNAL(activated(int)), SLOT(slotSetDateComp(int))); + connect(datelist, SIGNAL(activated(int)), SLOT(slotComboActivated(int))); + + m_queryManager = m; + fillWidgets(); + updateWidgets(); +} + +void ThresholdOptions::fillWidgets() +{ + Prefs::EnumCompType::type *ct; + ThreshListRef *ref; + + lessonlist->clear(); + for (int i = 1; i < (int) m_lessons->count(); i++ ) // first in lessons is <no lesson> ! + lessonlist->insertItem (m_lessons->text(i)); + + // limits and threshholds (the five comboboxes on the right) + gradelist->clear(); + for (int i = 1; i <= KV_MAX_GRADE; i++) + gradelist->insertItem (m_queryManager->gradeStr(i)); + + typelist->clear(); + all_maintypes = QueryManager::getRelation(true); // collect main types + for (int i = 0; i < (int) all_maintypes.size(); i++) + typelist->insertItem (all_maintypes[i].longStr()); + + badlist->clear(); + querylist->clear(); + for (int i = 0; i <= 15; i++) + { + badlist->insertItem(QString::number(i)); + querylist->insertItem(QString::number(i)); + } + + ref = Threshdate_itemlist; + datelist->clear(); + while (ref->text != 0 ) + { + datelist->insertItem (i18n(ref->text)); + ref++; + } + + //compare-functions (the lesson combobox and the five comboboxes on the left) + ct = less_complist; + lessoncomp->clear(); + while (*ct != Prefs::EnumCompType::type(-1) ) + { + lessoncomp->insertItem (m_queryManager->compStr(*ct)); + ct++; + } + + ct = type_complist; + typecomp->clear(); + while (*ct != Prefs::EnumCompType::type(-1) ) + { + typecomp->insertItem (m_queryManager->compStr(*ct)); + ct++; + } + + ct = query_complist; + querycomp->clear(); + while (*ct != Prefs::EnumCompType::type(-1) ) + { + querycomp->insertItem (m_queryManager->compStr(*ct)); + ct++; + } + + ct = bad_complist; + badcomp->clear(); + while (*ct != Prefs::EnumCompType::type(-1) ) { + badcomp->insertItem (m_queryManager->compStr(*ct)); + ct++; + } + + ct = grade_complist; + gradecomp->clear(); + while (*ct != Prefs::EnumCompType::type(-1) ) { + gradecomp->insertItem (m_queryManager->compStr(*ct)); + ct++; + } + + ct = date_complist; + datecomp->clear(); + while (*ct != Prefs::EnumCompType::type(-1) ) { + datecomp->insertItem (m_queryManager->compStr(*ct)); + ct++; + } +} + +void ThresholdOptions::updateWidgets() +{ + int index = 0; + Prefs::EnumCompType::type *ct; + ThreshListRef *ref; + + vector<int> sel = m_queryManager->lessonItems(); + if (sel.size() != 0) + { + for (int i = 0; i < (int) sel.size(); i++) + { + if (sel[i] > 0 && sel[i]-1 < (int) lessonlist->count()) // 0 = not assigned lesson + { + lessonlist->setCurrentItem(sel[i]-1); // important with qt1.x! + lessonlist->setSelected(sel[i]-1, true); + } + } + } + + gradelist->setCurrentItem(Prefs::gradeItem()); + + for (int i = 0; i < typelist->count(); i++) + { + if (Prefs::typeItem() == all_maintypes[i].shortStr()) + index = i; + } + typelist->setCurrentItem(index); + + badlist->setCurrentItem(Prefs::badItem()); + querylist->setCurrentItem(Prefs::queryItem()); + + ref = Threshdate_itemlist; + while (ref->text != 0 ) { + if (Prefs::dateItem() == ref->num) + index = ref - Threshdate_itemlist; + ref++; + } + datelist->setCurrentItem(index); + + //compare-functions (the lesson combobox and the five comboboxes on the left) + ct = less_complist; + while (*ct != Prefs::compType(Prefs::EnumType::Lesson)) + ct++; + lessoncomp->setCurrentItem (ct - less_complist); + slotSetLessonComp(ct - less_complist); + + ct = type_complist; + while (*ct != Prefs::compType(Prefs::EnumType::WordType)) + ct++; + typecomp->setCurrentItem(ct - type_complist); + typelist->setEnabled(ct - type_complist != 0); // don`t care == 0 + + ct = query_complist; + while (*ct != Prefs::compType(Prefs::EnumType::Query)) + ct++; + querycomp->setCurrentItem (ct - query_complist); + querylist->setEnabled(ct - query_complist != 0); // don`t care == 0 + + ct = bad_complist; + while (*ct != Prefs::compType(Prefs::EnumType::Bad)) + ct++; + badcomp->setCurrentItem(ct - bad_complist); + badlist->setEnabled(ct - bad_complist != 0); // don`t care == 0 + + ct = grade_complist; + while (*ct != Prefs::compType(Prefs::EnumType::Grade)) + ct++; + gradecomp->setCurrentItem (ct - grade_complist); + gradelist->setEnabled(ct - grade_complist != 0); // don`t care == 0 + + ct = date_complist; + while (*ct != Prefs::compType(Prefs::EnumType::Date)) + ct++; + datecomp->setCurrentItem (ct - date_complist); + if (date_complist[ct - date_complist] == Prefs::EnumCompType::Before || + date_complist[ct - date_complist] == Prefs::EnumCompType::Within) + datelist->setEnabled(true); + else + datelist->setEnabled(false); +} + +void ThresholdOptions::slotSelectAll() +{ + lessonlist->selectAll(true); + emit widgetModified(); +} + +void ThresholdOptions::slotSelectNone() +{ + lessonlist->selectAll(false); + emit widgetModified(); +} + + +void ThresholdOptions::slotComboActivated(int) +{ + emit widgetModified(); +} + + +void ThresholdOptions::slotSetGradeComp(int i) +{ + gradelist->setEnabled(i != 0); // don`t care == 0 + emit widgetModified(); +} + +void ThresholdOptions::slotSetBadComp(int i) +{ + badlist->setEnabled(i != 0); // don`t care == 0 + emit widgetModified(); +} + +void ThresholdOptions::slotSetQueryComp(int i) +{ + querylist->setEnabled(i != 0); // don`t care == 0 + emit widgetModified(); +} + +void ThresholdOptions::slotSetTypeComp(int i) +{ + typelist->setEnabled(i != 0); // don`t care == 0 + emit widgetModified(); +} + +void ThresholdOptions::slotSetLessonItems() +{ + vector<int> sel; + int cnt = 0; + + for (int i = 0; i < (int) lessonlist->count(); i++) + { + if (lessonlist->isSelected(i)) + { + sel.push_back(i+1); // 0 = not assigned lesson + cnt++; + } + } + + QString s; + s.setNum(cnt); + l_count->setText (s); + + m_queryManager->setLessonItems(sel); +} + +void ThresholdOptions::slotSetLessonComp(int i) +{ + if (less_complist[i] == Prefs::EnumCompType::OneOf || less_complist[i] == Prefs::EnumCompType::NotOneOf) + { + lessonlist->setEnabled(true); + b_all_less->setEnabled(true); + b_none_less->setEnabled(true); + l_count->setEnabled(true); + l_lesson->setEnabled(true); + } + else + { + l_count->setEnabled(false); + lessonlist->setEnabled(false); + b_all_less->setEnabled(false); + b_none_less->setEnabled(false); + l_lesson->setEnabled(false); + } + + if (i < 0) + return; + + emit widgetModified(); +} + +void ThresholdOptions::slotSetDateComp(int i) +{ + if (date_complist[i] == Prefs::EnumCompType::Before || date_complist[i] == Prefs::EnumCompType::Within) + datelist->setEnabled(true); + else + datelist->setEnabled(false); + emit widgetModified(); +} + +void ThresholdOptions::slotBlockExpire(bool block, bool expire) +{ + bool enable = !(block | expire); + + gradecomp->setEnabled(enable); + gradelist->setEnabled(enable && gradecomp->currentItem() != 0); + label_grade->setEnabled(enable); + + datecomp->setEnabled(enable); + datelist->setEnabled(enable && datecomp->currentItem() != 0); + label_qdate->setEnabled(enable); + + querycomp->setEnabled(enable); + querylist->setEnabled(enable && querycomp->currentItem() != 0); + label_qcount->setEnabled(enable); + + badcomp->setEnabled(enable); + badlist->setEnabled(enable && badcomp->currentItem() != 0); + label_bcount->setEnabled(enable); +} + +bool ThresholdOptions::isDefault() +{ + return less_complist[lessoncomp->currentItem()] == Prefs::EnumCompType::Current && + type_complist[typecomp->currentItem()] == Prefs::EnumCompType::DontCare && + grade_complist[gradecomp->currentItem()] == Prefs::EnumCompType::DontCare && + date_complist[datecomp->currentItem()] == Prefs::EnumCompType::DontCare && + query_complist[querycomp->currentItem()] == Prefs::EnumCompType::DontCare && + bad_complist[badcomp->currentItem()] == Prefs::EnumCompType::DontCare; +} + +void ThresholdOptions::updateSettings() +{ + Prefs::setCompType(Prefs::EnumType::Lesson, less_complist[lessoncomp->currentItem()]); + slotSetLessonItems(); + Prefs::setCompType(Prefs::EnumType::WordType, type_complist[typecomp->currentItem()]); + Prefs::setTypeItem(all_maintypes[typelist->currentItem()].shortStr()); + Prefs::setCompType(Prefs::EnumType::Grade, grade_complist[gradecomp->currentItem()]); + Prefs::setGradeItem(gradelist->currentItem() + 1); + Prefs::setCompType(Prefs::EnumType::Query, query_complist[querycomp->currentItem()]); + Prefs::setQueryItem(querylist->currentItem()); + Prefs::setCompType(Prefs::EnumType::Bad, bad_complist[badcomp->currentItem()]); + Prefs::setBadItem(badlist->currentItem()); + Prefs::setCompType(Prefs::EnumType::Date, date_complist[datecomp->currentItem()]); + Prefs::setDateItem(Threshdate_itemlist[datelist->currentItem()].num); +} + +bool ThresholdOptions::hasChanged() +{ + return less_complist[lessoncomp->currentItem()] != Prefs::compType(Prefs::EnumType::Lesson) || + type_complist[typecomp->currentItem()] != Prefs::compType(Prefs::EnumType::WordType) || + grade_complist[gradecomp->currentItem()] != Prefs::compType(Prefs::EnumType::Grade) || + query_complist[querycomp->currentItem()] != Prefs::compType(Prefs::EnumType::Query) || + bad_complist[badcomp->currentItem()] != Prefs::compType(Prefs::EnumType::Bad) || + date_complist[datecomp->currentItem()] != Prefs::compType(Prefs::EnumType::Date) || + all_maintypes[typelist->currentItem()].shortStr() != Prefs::typeItem() || + gradelist->currentItem() + 1 != Prefs::gradeItem() || + querylist->currentItem() != Prefs::queryItem() || + badlist->currentItem() != Prefs::badItem() || + Threshdate_itemlist[datelist->currentItem()].num != Prefs::dateItem(); +} + +#include "thresholdoptions.moc" diff --git a/kvoctrain/kvoctrain/common-dialogs/thresholdoptions.h b/kvoctrain/kvoctrain/common-dialogs/thresholdoptions.h new file mode 100644 index 00000000..f64a99bb --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/thresholdoptions.h @@ -0,0 +1,71 @@ +/*************************************************************************** + + threshold options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Apr 5 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 THRESHOLDOPTIONS_H +#define THRESHOLDOPTIONS_H + +#include "thresholdoptionsbase.h" +#include "QueryManager.h" + +class KComboBox; + +class ThresholdOptions : public ThresholdOptionsBase +{ + Q_OBJECT + +public: + ThresholdOptions(KComboBox * lessons, QueryManager * m, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + + void updateWidgets(); + bool hasChanged(); + bool isDefault(); + void updateSettings(); + +signals: + void widgetModified(); + +protected slots: + void slotSelectAll(); + void slotSelectNone(); + void slotComboActivated(int); + void slotSetGradeComp(int); + void slotSetBadComp(int); + void slotSetQueryComp(int); + void slotSetTypeComp(int); + void slotSetLessonItems(); + void slotSetLessonComp(int); + void slotSetDateComp(int); + void slotBlockExpire(bool block, bool expire); + +private: + void fillWidgets(); + + KComboBox * m_lessons; + QueryManager * m_queryManager; + vector<TypeRelation> all_maintypes; +}; + +#endif + diff --git a/kvoctrain/kvoctrain/common-dialogs/thresholdoptionsbase.ui b/kvoctrain/kvoctrain/common-dialogs/thresholdoptionsbase.ui new file mode 100644 index 00000000..4cf771c2 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/thresholdoptionsbase.ui @@ -0,0 +1,298 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ThresholdOptionsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ThresholdOptionsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>402</width> + <height>313</height> + </rect> + </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="QComboBox" row="1" column="1"> + <property name="name"> + <cstring>typecomp</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QComboBox" row="3" column="1"> + <property name="name"> + <cstring>querycomp</cstring> + </property> + </widget> + <widget class="QComboBox" row="4" column="1"> + <property name="name"> + <cstring>badcomp</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>label_grade</cstring> + </property> + <property name="text"> + <string>G&rade:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>gradecomp</cstring> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>label_bcount</cstring> + </property> + <property name="text"> + <string>&Bad count:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>badcomp</cstring> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>label_qdate</cstring> + </property> + <property name="text"> + <string>Last q&uery:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>datecomp</cstring> + </property> + </widget> + <widget class="QComboBox" row="5" column="1"> + <property name="name"> + <cstring>datecomp</cstring> + </property> + </widget> + <widget class="QComboBox" row="4" column="2"> + <property name="name"> + <cstring>badlist</cstring> + </property> + </widget> + <widget class="QComboBox" row="3" column="2"> + <property name="name"> + <cstring>querylist</cstring> + </property> + </widget> + <widget class="QComboBox" row="5" column="2"> + <property name="name"> + <cstring>datelist</cstring> + </property> + </widget> + <widget class="QComboBox" row="1" column="2"> + <property name="name"> + <cstring>typelist</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>label_type</cstring> + </property> + <property name="text"> + <string>Word t&ype:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>typecomp</cstring> + </property> + </widget> + <widget class="QComboBox" row="2" column="2"> + <property name="name"> + <cstring>gradelist</cstring> + </property> + </widget> + <widget class="QComboBox" row="2" column="1"> + <property name="name"> + <cstring>gradecomp</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>label_qcount</cstring> + </property> + <property name="text"> + <string>Query c&ount:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>querycomp</cstring> + </property> + </widget> + <widget class="QLayoutWidget" row="0" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>layout8</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton" row="2" column="1"> + <property name="name"> + <cstring>b_all_less</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&All</string> + </property> + </widget> + <widget class="QListBox" row="1" column="3" rowspan="3" colspan="2"> + <property name="name"> + <cstring>lessonlist</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="selectionMode"> + <enum>Multi</enum> + </property> + </widget> + <widget class="QPushButton" row="2" column="2"> + <property name="name"> + <cstring>b_none_less</cstring> + </property> + <property name="text"> + <string>&None</string> + </property> + </widget> + <widget class="QLabel" row="0" column="3"> + <property name="name"> + <cstring>l_lesson</cstring> + </property> + <property name="text"> + <string>Selected lessons:</string> + </property> + </widget> + <spacer row="3" column="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>50</height> + </size> + </property> + </spacer> + <spacer row="2" column="0" rowspan="2" colspan="1"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>MinimumExpanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>80</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="0" column="4"> + <property name="name"> + <cstring>l_count</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>label_lesson</cstring> + </property> + <property name="text"> + <string>&Lesson:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>lessoncomp</cstring> + </property> + </widget> + <widget class="QComboBox" row="1" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>lessoncomp</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + <spacer row="6" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>spacer12</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>290</width> + <height>16</height> + </size> + </property> + </spacer> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/common-dialogs/viewoptions.cpp b/kvoctrain/kvoctrain/common-dialogs/viewoptions.cpp new file mode 100644 index 00000000..8c0cd2c6 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/viewoptions.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + + view options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 31 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qcheckbox.h> + +#include "viewoptions.h" + +ViewOptions::ViewOptions(QWidget* parent, const char* name, WFlags fl) +: ViewOptionsBase(parent,name,fl) +{ + kcfg_GradeCol0->setEnabled(kcfg_UseGradeCol->isChecked()); + kcfg_GradeCol1->setEnabled(kcfg_UseGradeCol->isChecked()); + kcfg_GradeCol2->setEnabled(kcfg_UseGradeCol->isChecked()); + kcfg_GradeCol3->setEnabled(kcfg_UseGradeCol->isChecked()); + kcfg_GradeCol4->setEnabled(kcfg_UseGradeCol->isChecked()); + kcfg_GradeCol5->setEnabled(kcfg_UseGradeCol->isChecked()); + kcfg_GradeCol6->setEnabled(kcfg_UseGradeCol->isChecked()); + kcfg_GradeCol7->setEnabled(kcfg_UseGradeCol->isChecked()); +} + +#include "viewoptions.moc" + diff --git a/kvoctrain/kvoctrain/common-dialogs/viewoptions.h b/kvoctrain/kvoctrain/common-dialogs/viewoptions.h new file mode 100644 index 00000000..fd3b3b1d --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/viewoptions.h @@ -0,0 +1,41 @@ +/*************************************************************************** + + view options for kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 31 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 VIEWOPTIONS_H +#define VIEWOPTIONS_H + +#include "viewoptionsbase.h" + +class ViewOptions : public ViewOptionsBase +{ + Q_OBJECT + +public: + ViewOptions(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + +}; + +#endif + diff --git a/kvoctrain/kvoctrain/common-dialogs/viewoptionsbase.ui b/kvoctrain/kvoctrain/common-dialogs/viewoptionsbase.ui new file mode 100644 index 00000000..3bb2af24 --- /dev/null +++ b/kvoctrain/kvoctrain/common-dialogs/viewoptionsbase.ui @@ -0,0 +1,536 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ViewOptionsBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ViewOptionsBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>592</width> + <height>412</height> + </rect> + </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="KFontRequester" row="0" column="1"> + <property name="name"> + <cstring>kcfg_TableFont</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>TableFontLabel</cstring> + </property> + <property name="text"> + <string>&Table font:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_TableFont</cstring> + </property> + </widget> + <widget class="KFontRequester" row="1" column="1"> + <property name="name"> + <cstring>kcfg_IPAFont</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>IPAFontLabel</cstring> + </property> + <property name="text"> + <string>&IPA font:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_IPAFont</cstring> + </property> + </widget> + <widget class="QGroupBox" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>gradegroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Grade Colors</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>l_lev4</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &4:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_GradeCol4</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>l_lev5</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &5:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_GradeCol5</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>l_lev7</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &7:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_GradeCol7</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>l_lev6</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &6:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_GradeCol6</cstring> + </property> + </widget> + <widget class="KColorButton" row="8" column="1"> + <property name="name"> + <cstring>kcfg_GradeCol0</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&N</string> + </property> + </widget> + <widget class="QLabel" row="8" column="0"> + <property name="name"> + <cstring>l_lev0</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Not &queried:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_GradeCol0</cstring> + </property> + </widget> + <widget class="KColorButton" row="7" column="1"> + <property name="name"> + <cstring>kcfg_GradeCol1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&1</string> + </property> + <property name="accel"> + <string>Alt+1</string> + </property> + <property name="toolTip" stdset="0"> + <string>Color for the grade 1</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to change the color for grade 1.</string> + </property> + </widget> + <widget class="QLabel" row="7" column="0"> + <property name="name"> + <cstring>l_lev1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &1:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_GradeCol1</cstring> + </property> + </widget> + <widget class="QLabel" row="6" column="0"> + <property name="name"> + <cstring>l_lev2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &2:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_GradeCol2</cstring> + </property> + </widget> + <widget class="KColorButton" row="6" column="1"> + <property name="name"> + <cstring>kcfg_GradeCol2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&2</string> + </property> + <property name="accel"> + <string>Alt+2</string> + </property> + <property name="toolTip" stdset="0"> + <string>Color for the grade 2</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to change the color for grade 2.</string> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>l_lev3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &3:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>kcfg_GradeCol3</cstring> + </property> + </widget> + <widget class="KColorButton" row="5" column="1"> + <property name="name"> + <cstring>kcfg_GradeCol3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&3</string> + </property> + <property name="accel"> + <string>Alt+3</string> + </property> + <property name="toolTip" stdset="0"> + <string>Color for the grade 3</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to change the color for grade 3.</string> + </property> + </widget> + <widget class="KColorButton" row="4" column="1"> + <property name="name"> + <cstring>kcfg_GradeCol4</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&4</string> + </property> + <property name="accel"> + <string>Alt+4</string> + </property> + <property name="toolTip" stdset="0"> + <string>Color for the grade 4</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to change the color for grade 4.</string> + </property> + </widget> + <widget class="KColorButton" row="3" column="1"> + <property name="name"> + <cstring>kcfg_GradeCol5</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&5</string> + </property> + <property name="accel"> + <string>Alt+5</string> + </property> + <property name="toolTip" stdset="0"> + <string>Color for the grade 5</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to change the color for grade 5.</string> + </property> + </widget> + <widget class="KColorButton" row="2" column="1"> + <property name="name"> + <cstring>kcfg_GradeCol6</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&6</string> + </property> + <property name="accel"> + <string>Alt+6</string> + </property> + <property name="toolTip" stdset="0"> + <string>Color for the grade 6</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to change the color for grade 6.</string> + </property> + </widget> + <widget class="KColorButton" row="1" column="1"> + <property name="name"> + <cstring>kcfg_GradeCol7</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&7</string> + </property> + <property name="accel"> + <string>Alt+7</string> + </property> + <property name="toolTip" stdset="0"> + <string>Color for the grade 7</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Click here to change the color for grade 7.</string> + </property> + </widget> + <widget class="QCheckBox" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>kcfg_UseGradeCol</cstring> + </property> + <property name="text"> + <string>&Use colors</string> + </property> + <property name="toolTip" stdset="0"> + <string>If it is unchecked, you will just have black on white for the grades; if it is checked, the colors below will be chosen.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>If it is unchecked, you will just have black on white for the grades; if it is checked, the colors below will be chosen.</string> + </property> + </widget> + </grid> + </widget> + <spacer row="3" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>spacer9</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>61</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> +</widget> +<connections> + <connection> + <sender>kcfg_UseGradeCol</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_GradeCol7</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseGradeCol</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_GradeCol6</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseGradeCol</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_GradeCol5</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseGradeCol</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_GradeCol4</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseGradeCol</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_GradeCol3</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseGradeCol</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_GradeCol2</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseGradeCol</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_GradeCol1</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>kcfg_UseGradeCol</sender> + <signal>toggled(bool)</signal> + <receiver>kcfg_GradeCol0</receiver> + <slot>setEnabled(bool)</slot> + </connection> +</connections> +<tabstops> + <tabstop>kcfg_GradeCol0</tabstop> + <tabstop>kcfg_GradeCol7</tabstop> + <tabstop>kcfg_GradeCol6</tabstop> + <tabstop>kcfg_GradeCol5</tabstop> + <tabstop>kcfg_GradeCol4</tabstop> + <tabstop>kcfg_GradeCol3</tabstop> + <tabstop>kcfg_GradeCol2</tabstop> + <tabstop>kcfg_GradeCol1</tabstop> +</tabstops> +<includes> + <include location="global" impldecl="in declaration">kcolorbutton.h</include> +</includes> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kfontrequester.h</includehint> + <includehint>kfontrequester.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>kcolorbutton.h</includehint> + <includehint>kcolorbutton.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPage.cpp b/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPage.cpp new file mode 100644 index 00000000..3a6e3a5a --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPage.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + + internal doc options dialog class + + ----------------------------------------------------------------------- + + begin : Thu Nov 25 12:00:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "DocOptionsPage.h" + +#include <qcheckbox.h> + +DocOptionsPage::DocOptionsPage(bool sort, QWidget *parent, const char *name):DocOptionsPageForm(parent, name) +{ + sorter = sort; + docsort->setChecked(sort); + + connect( docsort, SIGNAL(toggled(bool)), SLOT(docSortToggled(bool)) ); +} + +void DocOptionsPage::docSortToggled(bool state) +{ + sorter = state; +} + +#include "DocOptionsPage.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPage.h b/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPage.h new file mode 100644 index 00000000..97655e4c --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPage.h @@ -0,0 +1,49 @@ +/*************************************************************************** + + internal doc options dialog class + + ----------------------------------------------------------------------- + + begin : Thu Nov 25 12:00:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 DocOptionsPage_included +#define DocOptionsPage_included + +#include "DocOptionsPageForm.h" + + +class DocOptionsPage : public DocOptionsPageForm +{ + Q_OBJECT + +public: + + DocOptionsPage(bool sort, QWidget *parent, const char *name); + + bool getSorting () const { return sorter; } + +protected slots: + void docSortToggled(bool); + +private: + bool sorter; +}; + +#endif // DocOptionsPage_included diff --git a/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPageForm.ui b/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPageForm.ui new file mode 100644 index 00000000..137d3df5 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/DocOptionsPageForm.ui @@ -0,0 +1,58 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>DocOptionsPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Document_options</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>323</width> + <height>260</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>GroupBox1</cstring> + </property> + <property name="title"> + <string>Document Options</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QCheckBox" row="0" column="0"> + <property name="name"> + <cstring>docsort</cstring> + </property> + <property name="text"> + <string>Allo&w sorting</string> + </property> + </widget> + </grid> + </widget> + </hbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/docprop-dialogs/DocPropDlg.cpp b/kvoctrain/kvoctrain/docprop-dialogs/DocPropDlg.cpp new file mode 100644 index 00000000..5f430175 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/DocPropDlg.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + + options dialog class + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include <qlayout.h> + +#include <klocale.h> +#include <kstandarddirs.h> +#include <kapplication.h> + +#include "DocPropDlg.h" +#include <langset.h> + + +class kvoctraindoc; + +DocPropsDlg::DocPropsDlg +( + kvoctrainDoc *doc, + const char * /*start_page*/, + QComboBox *lessons, + QString title, + QString author, + QString license, + QString doc_remark, + vector<QString> types, + vector<QString> tenses, + vector<QString> usages, + QWidget *parent, + const char *name, + bool modal +) + : + KDialogBase(Tabbed, i18n("Document Properties"), Ok|Cancel, Ok, parent, name, modal) +{ + QFrame *page = addPage( i18n("&General") ); + QVBoxLayout *topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + titleOptPage = new TitlePage (title, author, license, doc_remark, page, name); + topLayout->addWidget( titleOptPage ); + + page = addPage( i18n("L&essons")); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + lessOptPage = new LessOptPage (lessons, doc, page, name); + topLayout->addWidget( lessOptPage ); + + page = addPage( i18n("word types","T&ypes")); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + typeOptPage = new TypeOptPage (types, doc, page, name); + topLayout->addWidget( typeOptPage ); + + page = addPage( i18n("Te&nses")); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + tenseOptPage = new TenseOptPage (tenses, doc, page, name); + topLayout->addWidget( tenseOptPage ); + + page = addPage( i18n("usage (area) of an expression", "&Usage")); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + useOptPage = new UsageOptPage (usages, doc, page, name); + topLayout->addWidget( useOptPage ); + + page = addPage( i18n("&Options")); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + docOptPage = new DocOptionsPage (doc->isAllowedSorting(), page, name); + topLayout->addWidget( docOptPage ); +} + + +#include "DocPropDlg.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/DocPropDlg.h b/kvoctrain/kvoctrain/docprop-dialogs/DocPropDlg.h new file mode 100644 index 00000000..31651c8e --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/DocPropDlg.h @@ -0,0 +1,98 @@ +/*************************************************************************** + + document properties dialog class + + ----------------------------------------------------------------------- + + begin : Fri Sep 10 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 DocPropsDlg_included +#define DocPropsDlg_included + +#include <kdialogbase.h> + +#include "DocOptionsPage.h" +#include "LessOptPage.h" +#include "TypeOptPage.h" +#include "TenseOptPage.h" +#include "UsageOptPage.h" +#include "TitlePage.h" + +#include <vector> +using namespace std; + +class kvoctrainDoc; +class LangPropPage; + +class DocPropsDlg : public KDialogBase +{ + Q_OBJECT + +public: + + DocPropsDlg + ( + kvoctrainDoc *doc, + const char *start_page, + QComboBox *lessons, + QString title, + QString author, + QString license, + QString doc_remark, + vector<QString> types, + vector<QString> tenses, + vector<QString> usages, + QWidget *parent = NULL, + const char *name = NULL, + bool modal = true + ); + + inline bool getSorting() const { return docOptPage->getSorting(); } + + inline QString getTitle() { return titleOptPage->getTitle(); } + inline QString getAuthor() { return titleOptPage->getAuthor(); } + inline QString getLicense() { return titleOptPage->getLicense(); } + inline QString getDocRemark() { return titleOptPage->getDocRemark(); } + + inline void getLesson (QComboBox *lessons, vector<int>& ret_index) const + { lessOptPage->getLesson (lessons, ret_index); } + + inline void getTypeNames (vector<QString> &types, vector<int>& ret_index) const + { typeOptPage->getTypeNames (types, ret_index); } + + inline void getTenseNames (vector<QString> &tenses, vector<int>& ret_index) const + { tenseOptPage->getTenseNames (tenses, ret_index); } + + inline void getUsageLabels (vector<QString> &usages, vector<int>& ret_index) const + { useOptPage->getUsageLabels (usages, ret_index); } + + +protected: + + UsageOptPage *useOptPage; + TypeOptPage *typeOptPage; + TenseOptPage *tenseOptPage; + LessOptPage *lessOptPage; + TitlePage *titleOptPage; + DocOptionsPage *docOptPage; +}; + +#endif // DocPropsDlg_included + diff --git a/kvoctrain/kvoctrain/docprop-dialogs/DocPropLangDlg.cpp b/kvoctrain/kvoctrain/docprop-dialogs/DocPropLangDlg.cpp new file mode 100644 index 00000000..597978c0 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/DocPropLangDlg.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + + document language dialog class + + ----------------------------------------------------------------------- + + begin : Sat Jun 2 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "DocPropLangDlg.h" +#include "LangPropPage.h" + +#include <qstringlist.h> +#include <qlayout.h> +#include <qvaluelist.h> +#include <qtabwidget.h> + +#include <kapplication.h> +#include <klocale.h> +#include <kstandarddirs.h> + +#include <kvoctraindoc.h> +#include <langset.h> + + +class kvoctraindoc; + +DocPropsLangDlg::DocPropsLangDlg(kvoctrainDoc *doc, LangSet *langset, QWidget *parent, const char *name, bool modal) + : + KDialogBase(Tabbed, i18n("Language Properties"), Ok|Cancel, Ok, parent, name, modal) +{ + QFrame * page; + QVBoxLayout * topLayout; + LangPropPage* lpp; + + for (int i = 0; i < (int) doc->numLangs(); i++) + { + QString s; + if (i == 0) + s = doc->getOriginalIdent(); + else + s = doc->getIdent(i); + + int idx = langset->indexShortId(s); + + QString tabCaption; + + if (idx >= 0) + tabCaption = (langset->longId(idx)); + else + tabCaption = (s); + + page = addPage(s, s, QPixmap(langset->PixMapFile(idx))); ///@todo The pixmaps don't show up in tabbed dialog + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + lpp = new LangPropPage (doc, s, doc->getConjugation(i), doc->getArticle(i), page, name); + topLayout->addWidget( lpp ); + + langPages.append (lpp); + } +} + + +Conjugation DocPropsLangDlg::getConjugation(int idx) const +{ + if (idx < (int) langPages.size()) + return langPages[idx]->getConjugation(); + else + return Conjugation(); +} + + +Article DocPropsLangDlg::getArticle(int idx) const +{ + if (idx < (int) langPages.size() ) + return langPages[idx]->getArticle(); + else + return Article(); +} + +#include "DocPropLangDlg.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/DocPropLangDlg.h b/kvoctrain/kvoctrain/docprop-dialogs/DocPropLangDlg.h new file mode 100644 index 00000000..e2fd9bf6 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/DocPropLangDlg.h @@ -0,0 +1,56 @@ +/*************************************************************************** + + document language dialog class + + ----------------------------------------------------------------------- + + begin : Sat Jun 2 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 DocPropsLangDlg_included +#define DocPropsLangDlg_included + +#include <qvaluelist.h> + +#include <kdialogbase.h> + +#include <grammarmanager.h> + +class kvoctrainDoc; +class LangPropPage; +class LangSet; + +class DocPropsLangDlg : public KDialogBase +{ + Q_OBJECT + +public: + + DocPropsLangDlg(kvoctrainDoc *doc, LangSet *langset, QWidget *parent = NULL, const char *name = NULL, bool modal = true); + + Conjugation getConjugation(int idx) const; + Article getArticle(int idx) const; + +protected: + typedef QValueList<LangPropPage*> LangPagesList; + LangPagesList langPages; +}; + +#endif // DocPropsLangDlg_included + diff --git a/kvoctrain/kvoctrain/docprop-dialogs/LangPropPage.cpp b/kvoctrain/kvoctrain/docprop-dialogs/LangPropPage.cpp new file mode 100644 index 00000000..879b45d5 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/LangPropPage.cpp @@ -0,0 +1,243 @@ +/*************************************************************************** + + language properties dialog page + + ----------------------------------------------------------------------- + + begin : Wed Oct 13 18:37:13 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <langset.h> + +#include "LangPropPage.h" + +#include <klocale.h> + +#include <qlineedit.h> +#include <qcheckbox.h> +#include <qlabel.h> + +LangPropPage::LangPropPage +( + kvoctrainDoc *_doc, + QString curr_lang, + const Conjugation &conjug, + const Article &art, + QWidget *parent, + const char *name +) + : + LangPropPageForm( parent, name ), + doc(_doc), + conjugations(conjug), + articles(art) +{ + l_langcode->setText(curr_lang); + + connect( indef_female, SIGNAL(textChanged(const QString&)), SLOT(indefFemaleChanged(const QString&)) ); + connect( def_female, SIGNAL(textChanged(const QString&)), SLOT(defFemaleChanged(const QString&)) ); + connect( def_male, SIGNAL(textChanged(const QString&)), SLOT(defMaleChanged(const QString&)) ); + connect( indef_male, SIGNAL(textChanged(const QString&)), SLOT(indefMaleChanged(const QString&)) ); + connect( def_natural, SIGNAL(textChanged(const QString&)), SLOT(defNaturalChanged(const QString&)) ); + connect( indef_natural, SIGNAL(textChanged(const QString&)), SLOT(indefNaturalChanged(const QString&)) ); + connect( first_singular, SIGNAL(textChanged(const QString&)), SLOT(firstSingularChanged(const QString&)) ); + connect( first_plural, SIGNAL(textChanged(const QString&)), SLOT(firstPluralChanged(const QString&)) ); + connect( second_singular, SIGNAL(textChanged(const QString&)), SLOT(secondSingularChanged(const QString&)) ); + connect( second_plural, SIGNAL(textChanged(const QString&)), SLOT(secondPluralChanged(const QString&)) ); + connect( thirdF_singular, SIGNAL(textChanged(const QString&)), SLOT(thirdFSingularChanged(const QString&)) ); + connect( thirdF_plural, SIGNAL(textChanged(const QString&)), SLOT(thirdFPluralChanged(const QString&)) ); + connect( thirdM_singular, SIGNAL(textChanged(const QString&)), SLOT(thirdMSingularChanged(const QString&)) ); + connect( thirdM_plural, SIGNAL(textChanged(const QString&)), SLOT(thirdMPluralChanged(const QString&)) ); + connect( thirdN_singular, SIGNAL(textChanged(const QString&)), SLOT(thirdNSingularChanged(const QString&)) ); + connect( thirdN_plural, SIGNAL(textChanged(const QString&)), SLOT(thirdNPluralChanged(const QString&)) ); + + connect( thirdS_common, SIGNAL(toggled(bool)), SLOT(slotThirdSCommonToggled(bool)) ); + connect( thirdP_common, SIGNAL(toggled(bool)), SLOT(slotThirdPCommonToggled(bool)) ); + + conjugations = conjug; + + first_plural->setText (conjugations.pers1Plural (CONJ_PREFIX)); + first_singular->setText (conjugations.pers1Singular (CONJ_PREFIX)); + second_singular->setText (conjugations.pers2Singular (CONJ_PREFIX)); + second_plural->setText (conjugations.pers2Plural (CONJ_PREFIX)); + thirdF_plural->setText (conjugations.pers3FemalePlural (CONJ_PREFIX)); + thirdF_singular->setText (conjugations.pers3FemaleSingular (CONJ_PREFIX)); + thirdN_plural->setText (conjugations.pers3NaturalPlural (CONJ_PREFIX)); + thirdN_singular->setText (conjugations.pers3NaturalSingular (CONJ_PREFIX)); + thirdM_plural->setText (conjugations.pers3MalePlural (CONJ_PREFIX)); + thirdM_singular->setText (conjugations.pers3MaleSingular (CONJ_PREFIX)); + + bool common = conjugations.pers3SingularCommon(CONJ_PREFIX); + thirdS_common->setChecked(common); + thirdM_singular->setEnabled(!common); + thirdN_singular->setEnabled(!common); + + common = conjugations.pers3PluralCommon(CONJ_PREFIX); + thirdP_common->setChecked(common); + thirdN_plural->setEnabled(!common); + thirdM_plural->setEnabled(!common); + + QString def, indef; + articles.female(def, indef); + def_female->setText (def); + indef_female->setText (indef); + + articles.male(def, indef); + def_male->setText (def); + indef_male->setText (indef); + + articles.natural(def, indef); + def_natural->setText (def); + indef_natural->setText (indef); + +} + + +Conjugation LangPropPage::getConjugation() +{ + conjugations.cleanUp(); + return conjugations; +} + + +void LangPropPage::firstPluralChanged(const QString& s) +{ + conjugations.setPers1Plural (CONJ_PREFIX, s); +} + + +void LangPropPage::firstSingularChanged(const QString& s) +{ + conjugations.setPers1Singular (CONJ_PREFIX, s); +} + + +void LangPropPage::secondSingularChanged(const QString& s) +{ + conjugations.setPers2Singular (CONJ_PREFIX, s); +} + + +void LangPropPage::secondPluralChanged(const QString& s) +{ + conjugations.setPers2Plural (CONJ_PREFIX, s); +} + + +void LangPropPage::thirdFPluralChanged(const QString& s) +{ + conjugations.setPers3FemalePlural (CONJ_PREFIX, s); +} + + +void LangPropPage::thirdFSingularChanged(const QString& s) +{ + conjugations.setPers3FemaleSingular (CONJ_PREFIX, s); +} + + +void LangPropPage::thirdMSingularChanged(const QString& s) +{ + conjugations.setPers3MaleSingular (CONJ_PREFIX, s); +} + + +void LangPropPage::thirdNSingularChanged(const QString& s) +{ + conjugations.setPers3NaturalSingular(CONJ_PREFIX, s); +} + + +void LangPropPage::thirdNPluralChanged(const QString& s) +{ + conjugations.setPers3NaturalPlural (CONJ_PREFIX, s); +} + + +void LangPropPage::thirdMPluralChanged(const QString& s) +{ + conjugations.setPers3MalePlural (CONJ_PREFIX, s); +} + + +void LangPropPage::slotThirdSCommonToggled(bool common) +{ + conjugations.setPers3SingularCommon(CONJ_PREFIX, common); + thirdN_singular->setEnabled(!common); + thirdM_singular->setEnabled(!common); +} + + +void LangPropPage::slotThirdPCommonToggled(bool common) +{ + conjugations.setPers3PluralCommon(CONJ_PREFIX, common); + thirdN_plural->setEnabled(!common); + thirdM_plural->setEnabled(!common); +} + + +void LangPropPage::defFemaleChanged(const QString& s) +{ + QString def, indef; + articles.female(def, indef); + articles.setFemale(s, indef); +} + + +void LangPropPage::indefFemaleChanged(const QString& s) +{ + QString def, indef; + articles.female(def, indef); + articles.setFemale(def, s); +} + + +void LangPropPage::defMaleChanged(const QString& s) +{ + QString def, indef; + articles.male(def, indef); + articles.setMale(s, indef); +} + + +void LangPropPage::indefMaleChanged(const QString& s) +{ + QString def, indef; + articles.male(def, indef); + articles.setMale(def, s); +} + + +void LangPropPage::defNaturalChanged(const QString& s) +{ + QString def, indef; + articles.natural(def, indef); + articles.setNatural(s, indef); +} + + +void LangPropPage::indefNaturalChanged(const QString& s) +{ + QString def, indef; + articles.natural(def, indef); + articles.setNatural(def, s); +} + +#include "LangPropPage.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/LangPropPage.h b/kvoctrain/kvoctrain/docprop-dialogs/LangPropPage.h new file mode 100644 index 00000000..e98c9604 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/LangPropPage.h @@ -0,0 +1,84 @@ +/*************************************************************************** + + language properties dialog page + + ----------------------------------------------------------------------- + + begin : Wed Oct 13 18:37:13 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 LangPropPage_included +#define LangPropPage_included + +#include "LangPropPageForm.h" + +#include <grammarmanager.h> + +class kvoctrainDoc; + +class LangPropPage : public LangPropPageForm +{ + Q_OBJECT + +public: + + LangPropPage + ( + kvoctrainDoc *doc, + QString curr_lang, + const Conjugation &conjugations, + const Article &article, + QWidget *parent = NULL, + const char *name = NULL + ); + + Conjugation getConjugation(); + Article getArticle() const { return articles; } + +protected slots: + + void secondPluralChanged(const QString&); + void secondSingularChanged(const QString&); + void thirdNSingularChanged(const QString&); + void thirdFPluralChanged(const QString&); + void thirdMSingularChanged(const QString&); + void thirdFSingularChanged(const QString&); + void thirdMPluralChanged(const QString&); + void thirdNPluralChanged(const QString&); + void firstPluralChanged(const QString&); + void firstSingularChanged(const QString&); + void slotThirdSCommonToggled(bool); + void slotThirdPCommonToggled(bool); + + void defNaturalChanged(const QString& ); + void indefMaleChanged(const QString& ); + void indefNaturalChanged(const QString& ); + void defFemaleChanged(const QString& ); + void indefFemaleChanged(const QString& ); + void defMaleChanged(const QString& ); + +protected: + + kvoctrainDoc *doc; + Conjugation conjugations; + Article articles; +}; + +#endif // LangPropPage_included diff --git a/kvoctrain/kvoctrain/docprop-dialogs/LangPropPageForm.ui b/kvoctrain/kvoctrain/docprop-dialogs/LangPropPageForm.ui new file mode 100644 index 00000000..cce69a3f --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/LangPropPageForm.ui @@ -0,0 +1,592 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>LangPropPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>LangPropPage</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>504</width> + <height>444</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </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="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>GroupBox2</cstring> + </property> + <property name="title"> + <string>Language Elements</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Language code (ISO 639):</string> + </property> + </widget> + <widget class="QLabel" row="0" column="1"> + <property name="name"> + <cstring>l_langcode</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>70</width> + <height>0</height> + </size> + </property> + <property name="frameShape"> + <enum>WinPanel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + </widget> + <spacer row="0" column="2"> + <property name="name"> + <cstring>Spacer5</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>MinimumExpanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QGroupBox" row="1" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>GroupBox3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Articles</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>female_label</cstring> + </property> + <property name="text"> + <string>&Female:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>def_female</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>male_label</cstring> + </property> + <property name="text"> + <string>&Male:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>def_male</cstring> + </property> + </widget> + <widget class="QLineEdit" row="2" column="2"> + <property name="name"> + <cstring>indef_male</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="0" column="1"> + <property name="name"> + <cstring>TextLabel3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Definite</string> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>def_male</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="2"> + <property name="name"> + <cstring>indef_female</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>def_female</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <spacer row="0" column="0"> + <property name="name"> + <cstring>Spacer8</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Minimum</enum> + </property> + <property name="sizeHint"> + <size> + <width>50</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLineEdit" row="3" column="1"> + <property name="name"> + <cstring>def_natural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="3" column="2"> + <property name="name"> + <cstring>indef_natural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>natural_label</cstring> + </property> + <property name="text"> + <string>&Neutral:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>def_natural</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="2"> + <property name="name"> + <cstring>TextLabel4</cstring> + </property> + <property name="text"> + <string>Indefinite</string> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox" row="2" column="0" rowspan="1" colspan="3"> + <property name="name"> + <cstring>GroupBox4</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Conjugation</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>pers1_label</cstring> + </property> + <property name="text"> + <string>&1. Person:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>first_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>pers2_label</cstring> + </property> + <property name="text"> + <string>&2. Person:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>second_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>pers3_label</cstring> + </property> + <property name="text"> + <string>3. Person:</string> + </property> + </widget> + <widget class="QLineEdit" row="4" column="2"> + <property name="name"> + <cstring>thirdF_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="6" column="2"> + <property name="name"> + <cstring>thirdN_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="5" column="2"> + <property name="name"> + <cstring>thirdM_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QCheckBox" row="3" column="2"> + <property name="name"> + <cstring>thirdP_common</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>C&ommon</string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>female_c_label</cstring> + </property> + <property name="text"> + <string>F&emale:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>thirdF_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>male_c_label</cstring> + </property> + <property name="text"> + <string>M&ale:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>thirdM_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="6" column="0"> + <property name="name"> + <cstring>natural_c_label</cstring> + </property> + <property name="text"> + <string>Neu&tral:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>thirdN_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="2"> + <property name="name"> + <cstring>TextLabel4_2</cstring> + </property> + <property name="text"> + <string>Plural</string> + </property> + </widget> + <widget class="QCheckBox" row="3" column="1"> + <property name="name"> + <cstring>thirdS_common</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Common</string> + </property> + </widget> + <widget class="QLabel" row="0" column="1"> + <property name="name"> + <cstring>TextLabel4_2</cstring> + </property> + <property name="text"> + <string>Singular</string> + </property> + </widget> + <spacer row="0" column="0"> + <property name="name"> + <cstring>Spacer9</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Minimum</enum> + </property> + <property name="sizeHint"> + <size> + <width>50</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>second_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="4" column="1"> + <property name="name"> + <cstring>thirdF_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="5" column="1"> + <property name="name"> + <cstring>thirdM_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="6" column="1"> + <property name="name"> + <cstring>thirdN_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>first_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="2"> + <property name="name"> + <cstring>first_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="2" column="2"> + <property name="name"> + <cstring>second_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + </grid> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>def_female</tabstop> + <tabstop>def_male</tabstop> + <tabstop>def_natural</tabstop> + <tabstop>indef_female</tabstop> + <tabstop>indef_male</tabstop> + <tabstop>indef_natural</tabstop> + <tabstop>first_singular</tabstop> + <tabstop>second_singular</tabstop> + <tabstop>thirdS_common</tabstop> + <tabstop>thirdF_singular</tabstop> + <tabstop>thirdM_singular</tabstop> + <tabstop>thirdN_singular</tabstop> + <tabstop>first_plural</tabstop> + <tabstop>second_plural</tabstop> + <tabstop>thirdP_common</tabstop> + <tabstop>thirdF_plural</tabstop> + <tabstop>thirdM_plural</tabstop> + <tabstop>thirdN_plural</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/docprop-dialogs/LessOptPage.cpp b/kvoctrain/kvoctrain/docprop-dialogs/LessOptPage.cpp new file mode 100644 index 00000000..b5503228 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/LessOptPage.cpp @@ -0,0 +1,257 @@ +/*************************************************************************** + + lesson properties dialog page + + ----------------------------------------------------------------------- + + begin : Thu Jun 3 22:03:50 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "LessOptPage.h" + +#include <kapplication.h> +#include <kinputdialog.h> +#include <klocale.h> +#include <kmessagebox.h> + +#include <qcombobox.h> +#include <qpushbutton.h> +#include <qlayout.h> + +#include <kvoctraindoc.h> + +#define LESS_TAG ". " + +LessOptPage::LessOptPage +( + QComboBox *lessons, + kvoctrainDoc *_doc, + QWidget *parent, + const char *name +) + : + LessOptPageForm( parent, name ) +{ + connect( lessonList, SIGNAL(highlighted(int)), SLOT(slotLessonChosen(int)) ); + connect( b_new, SIGNAL(clicked()), SLOT(slotNewLesson()) ); + connect( b_modify, SIGNAL(clicked()), SLOT(slotModifyLesson()) ); + connect( b_delete, SIGNAL(clicked()), SLOT(slotDeleteLesson()) ); + connect( b_cleanup, SIGNAL(clicked()), SLOT(slotCleanup()) ); + + doc = _doc; + + QString str; + for (int i = 1; i < lessons->count(); i++) { + str.setNum (i); + if (i <= 9) + str.insert (0, " "); + lessonList->insertItem (str+LESS_TAG+lessons->text(i)); + lessonIndex.push_back(i-1); + } + + act_lesson = 0; + if (lessonList->count() != 0) + lessonList->setCurrentItem (act_lesson); + lessonList->setFocus(); + + b_modify->setEnabled(lessonList->count() != 0); + b_delete->setEnabled(lessonList->count() != 0); +} + + +void LessOptPage::slotLessonChosen(int index) +{ + act_lesson = index; +} + + +void LessOptPage::slotNewLesson() +{ + bool ok; + QString getLesson = KInputDialog::getText( + i18n( "Lesson Description" ), i18n( "Enter lesson description:" ), QString::null, &ok ); + if( !ok ) + return; + QString str; + int i = lessonList->count()+1; + str.setNum (i); + if (i <= 9) + str.insert (0, " "); + lessonList->insertItem (str+LESS_TAG+getLesson.stripWhiteSpace()); + lessonIndex.push_back(-(i-1)); + act_lesson = lessonList->count(); + lessonList->setCurrentItem (i-1); + b_modify->setEnabled(true); + b_delete->setEnabled(true); +} + + +void LessOptPage::slotModifyLesson() +{ + if (lessonList->count() != 0 && (int) lessonList->count() > act_lesson) + { + QString str = lessonList->text (act_lesson); + int pos = str.find (LESS_TAG); + str.remove (0, pos+strlen (LESS_TAG)); + bool ok; + QString getLesson = KInputDialog::getText( + i18n( "Lesson Description" ), i18n( "Enter lesson description:" ), str, &ok ); + if( !ok ) + return; + QString str2; + str2.setNum (act_lesson+1); + if (act_lesson <= 9) + str2.insert (0, " "); + lessonList->changeItem (str2+LESS_TAG+getLesson.stripWhiteSpace(), act_lesson); + } +} + + +void LessOptPage::updateListBox(int start) +{ + QString str, str2; + for (int i = start; i < (int) lessonList->count(); i++) + { + str = lessonList->text (i); + int pos = str.find (LESS_TAG); + str.remove (0, pos+strlen (LESS_TAG)); + str2.setNum (i+1); + if (i <= 9) + str2.insert (0, " "); + lessonList->changeItem (str2+LESS_TAG+str, i); + } +} + + +void LessOptPage::slotDeleteLesson() +{ + int act = act_lesson; + if (lessonList->count() != 0 + && (int) lessonList->count() > act) { + + for (int ent = 0; ent < doc->numEntries(); ent++) { + // FIXME: ProgressDlg here? + if (doc->getEntry(ent)->getLesson() == lessonIndex[act_lesson]+1) { + KMessageBox::information(this, + i18n("This lesson could not be deleted\nbecause it is in use."), + kapp->makeStdCaption(i18n("Deleting Lesson"))); + return; + } + } + + lessonList->removeItem (act); + lessonIndex.erase (lessonIndex.begin() + act); + + if ((int) lessonList->count() <= act) + act = lessonList->count()-1; + else + updateListBox(act); // update items after current + + if (act >= 0) + lessonList->setCurrentItem (act); + } + b_modify->setEnabled(lessonList->count() != 0); + b_delete->setEnabled(lessonList->count() != 0); +} + + +void LessOptPage::getLesson (QComboBox *ret_lesson, vector<int> &ret_Index) +{ + while (ret_lesson->count() > 1) /* first entry is "no lesson" */ + ret_lesson->removeItem (1); + + QString str; + for (int i = 0; i < (int) lessonList->count(); i++) { + str = lessonList->text(i); + int pos = str.find (LESS_TAG); + str.remove (0, pos+strlen (LESS_TAG)); + ret_lesson->insertItem (str); + } + ret_Index = lessonIndex; +} + + +void LessOptPage::slotCleanup() +{ + vector<bool> used_lesson; + for (int i = 0; i < (int) lessonList->count(); i++) + used_lesson.push_back(false); + + for (int i = 0; i < (int) doc->numEntries(); i++) { + int idx = doc->getEntry(i)->getLesson(); + if ((int) used_lesson.size() < idx) + used_lesson.resize(idx); + if (idx != 0) + used_lesson[idx-1] = true ; + } + + for (int i = used_lesson.size()-1; i >= 0; i--) + if (!used_lesson[i]) { + for (int u = 0; u < (int) lessonIndex.size() ; u++) { + if (lessonIndex[u] == i || lessonIndex[u] < 0) { + act_lesson = i; + slotDeleteLesson(); + break; + } + } + } + + act_lesson = 0; + lessonList->setCurrentItem (act_lesson); +} + + +void LessOptPage::cleanUnused (kvoctrainDoc *doc, + const QComboBox * /*lessons*/, + const vector<int> &lessonIndex, + int old_lessons, + vector<int> &lessons_in_query) +{ + vector<int> translate_index; + + ///////////////////////////////////////////////////// + // translate_index contains new index number for each + // old index + for (int i = 0; i <= QMAX (old_lessons, (int) lessonIndex.size()); i++) + translate_index.push_back(0); + + // now adjust lesson descriptions to new index + for (int i = 0; i < (int) lessonIndex.size(); i++) { + if (lessonIndex[i] >= 0) + translate_index[lessonIndex[i]+1] = i+1; + } + + // now adjust for query selected lessons to new index + for (int i = (int) lessons_in_query.size()-1; i >= 0; i--) { + if (translate_index[lessons_in_query[i]] > 0) + lessons_in_query[i] = translate_index[lessons_in_query[i]]; + else + lessons_in_query.erase(lessons_in_query.begin() + i); + } + + // only keep remaining lesson member indices + + // set lesson index to 0 when not needed any more + // and translate to new index + for (int i = 0; i < doc->numEntries(); i++) { + if (doc->getEntry(i)->getLesson () != 0) + doc->getEntry(i)->setLesson (translate_index[doc->getEntry(i)->getLesson ()]); + } +} +#include "LessOptPage.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/LessOptPage.h b/kvoctrain/kvoctrain/docprop-dialogs/LessOptPage.h new file mode 100644 index 00000000..faeb981d --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/LessOptPage.h @@ -0,0 +1,76 @@ +/*************************************************************************** + + lesson properties dialog page + + ----------------------------------------------------------------------- + + begin : Thu Jun 3 22:03:50 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 LessOptPage_included +#define LessOptPage_included + +#include "LessOptPageForm.h" + +#include <vector> +using namespace std; + +class kvoctrainDoc; +class QComboBox; + +class LessOptPage : public LessOptPageForm +{ + Q_OBJECT + +public: + + LessOptPage + ( + QComboBox *lessons, + kvoctrainDoc *doc, + QWidget *parent = NULL, + const char *name = NULL + ); + + void getLesson (QComboBox *ret_lesson, vector<int>& ret_Index); + + static void cleanUnused(kvoctrainDoc *doc, + const QComboBox *lessons, + const vector<int> &lessonIndex, + int old_lessons, + vector<int> &lessons_in_use); + +protected: + void updateListBox(int start); + +protected slots: + + void slotDeleteLesson(); + void slotNewLesson(); + void slotLessonChosen(int); + void slotModifyLesson(); + void slotCleanup(); + +private: + kvoctrainDoc *doc; + int act_lesson; + vector<int> lessonIndex; // contains indices of lesson on exec() + // negative values are new lessons +}; +#endif // LessOptPage_included diff --git a/kvoctrain/kvoctrain/docprop-dialogs/LessOptPageForm.ui b/kvoctrain/kvoctrain/docprop-dialogs/LessOptPageForm.ui new file mode 100644 index 00000000..311ab3bc --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/LessOptPageForm.ui @@ -0,0 +1,143 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>LessOptPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Lesson_Descriptions</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>584</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </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="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>lesson_group</cstring> + </property> + <property name="title"> + <string>Lesson Descriptions</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer row="2" column="3"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton" row="2" column="0"> + <property name="name"> + <cstring>b_new</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&New...</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="1"> + <property name="name"> + <cstring>b_modify</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Modify...</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="2"> + <property name="name"> + <cstring>b_delete</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Delete</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="4"> + <property name="name"> + <cstring>b_cleanup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Clean Up</string> + </property> + </widget> + <widget class="QListBox" row="1" column="0" rowspan="1" colspan="5"> + <property name="name"> + <cstring>lessonList</cstring> + </property> + </widget> + </grid> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>lessonList</tabstop> + <tabstop>b_new</tabstop> + <tabstop>b_modify</tabstop> + <tabstop>b_delete</tabstop> + <tabstop>b_cleanup</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/docprop-dialogs/Makefile.am b/kvoctrain/kvoctrain/docprop-dialogs/Makefile.am new file mode 100644 index 00000000..6ec873cc --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/Makefile.am @@ -0,0 +1,13 @@ +INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../kvt-core \ + -I$(top_builddir)/kvoctrain/kvoctrain/common-dialogs $(all_includes) + +noinst_LTLIBRARIES = libdocpropdlg.la + +libdocpropdlg_la_SOURCES = \ + TitlePage.cpp TypeOptPage.cpp TenseOptPage.cpp UsageOptPage.cpp \ + TitlePageForm.ui TypeOptPageForm.ui TenseOptPageForm.ui UsageOptPageForm.ui \ + LessOptPage.cpp DocOptionsPage.cpp LangPropPage.cpp \ + LessOptPageForm.ui DocOptionsPageForm.ui LangPropPageForm.ui \ + DocPropDlg.cpp DocPropLangDlg.cpp + +METASOURCES = AUTO diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPage.cpp b/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPage.cpp new file mode 100644 index 00000000..0e3ece95 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPage.cpp @@ -0,0 +1,284 @@ +/*************************************************************************** + + user tense options dialog page + + ----------------------------------------------------------------------- + + begin : Sun May 28 12:14:31 2000 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "TenseOptPage.h" + +#include <qpushbutton.h> + +#include <kapplication.h> +#include <kinputdialog.h> +#include <kmessagebox.h> +#include <klocale.h> + +#include <QueryManager.h> + +#define TENSE_TAG ". " + +TenseOptPage::TenseOptPage +( + const vector<QString> &tenses, + kvoctrainDoc *_doc, + QWidget *parent, + const char *name +) + : + TenseOptPageForm( parent, name ) +{ + connect( tenseList, SIGNAL(highlighted(int)), SLOT(slotTenseChosen(int)) ); + connect( b_cleanup, SIGNAL(clicked()), SLOT(slotCleanup()) ); + connect( b_delete, SIGNAL(clicked()), SLOT(slotDeleteTense()) ); + connect( b_modify, SIGNAL(clicked()), SLOT(slotModifyTense()) ); + connect( b_new, SIGNAL(clicked()), SLOT(slotNewTense()) ); + + QString str; + for (int i = 0; i < (int) tenses.size(); i++) { + str.setNum (i+1); + if (i <= 9) + str.insert (0, " "); + tenseList->insertItem (str+TENSE_TAG+tenses[i]); + tenseIndex.push_back(i); + } + + act_tense = 0; + if (tenses.size() != 0) + tenseList->setCurrentItem (act_tense); + + b_modify->setEnabled(tenseList->count() != 0); + b_delete->setEnabled(tenseList->count() != 0); + + tenseList->setFocus(); + doc = _doc; +} + + +void TenseOptPage::slotTenseChosen(int index) +{ + act_tense = index; +} + + +void TenseOptPage::slotNewTense() +{ + bool ok; + QString getTense = KInputDialog::getText( + i18n( "Tense Description" ), i18n( "Enter tense description:" ), QString::null, &ok ); + if( !ok ) + return; + + QString str; + int i = tenseList->count()+1; + str.setNum (i); + if (i <= 9) + str.insert (0, " "); + tenseList->insertItem (str+TENSE_TAG+getTense.stripWhiteSpace()); + tenseIndex.push_back(-(i-1)); + act_tense = tenseList->count(); + tenseList->setCurrentItem (i-1); + b_modify->setEnabled(true); + b_delete->setEnabled(true); +} + + +void TenseOptPage::slotModifyTense() +{ + if (tenseList->count() != 0 && (int) tenseList->count() > act_tense) + { + QString str = tenseList->text (act_tense); + int pos = str.find (TENSE_TAG); + str.remove (0, pos+strlen (TENSE_TAG)); + bool ok; + QString getTense = KInputDialog::getText( + i18n( "Tense Description" ), i18n( "Enter tense description:" ), str, &ok ); + if( !ok ) + return; + QString str2; + str2.setNum (act_tense+1); + if (act_tense <= 9) + str2.insert (0, " "); + tenseList->changeItem (str2+TENSE_TAG+getTense.stripWhiteSpace(), act_tense); + } +} + + +void TenseOptPage::updateListBox(int start) +{ + QString str, str2; + for (int i = start; i < (int) tenseList->count(); i++) + { + str = tenseList->text (i); + int pos = str.find (TENSE_TAG); + str.remove (0, pos+strlen (TENSE_TAG)); + str2.setNum (i+1); + if (i <= 9) + str2.insert (0, " "); + tenseList->changeItem (str2+TENSE_TAG+str, i); + } +} + + +void TenseOptPage::slotDeleteTense() +{ + int act = act_tense; + if (tenseList->count() != 0 + && (int) tenseList->count() > act) { + + QString t; + t.setNum(tenseIndex[act_tense]+1); + t.insert (0, QM_USER_TYPE); + for (int ent = 0; ent < doc->numEntries(); ent++) { + // FIXME: ProgressDlg here? + kvoctrainExpr *exp = doc->getEntry(ent); + for (int lang = 0; lang < doc->numLangs(); lang++) { + Conjugation conj = exp->getConjugation(lang); + for (int con = 0; con < conj.numEntries(); con++ ) { + if (conj.getType(con) == t) { + KMessageBox::information(this, + i18n("This user defined tense could not be deleted\nbecause it is in use."), + kapp->makeStdCaption(i18n("Deleting Tense Description"))); + return; + } + } + } + } + + tenseList->removeItem (act); + tenseIndex.erase (tenseIndex.begin() + act); + + if ((int) tenseList->count() <= act) + act = tenseList->count()-1; + else + updateListBox(act); // update items after current + + if (act >= 0) + tenseList->setCurrentItem (act); + } + b_modify->setEnabled(tenseList->count() != 0); + b_delete->setEnabled(tenseList->count() != 0); +} + + +void TenseOptPage::getTenseNames (vector<QString> &ret_tense, vector<int> &ret_Index) +{ + QString str; ret_tense.clear(); + for (int i = 0; i < (int) tenseList->count(); i++) + { + str = tenseList->text(i); + int pos = str.find (TENSE_TAG); + str.remove (0, pos+strlen (TENSE_TAG)); + ret_tense.push_back (str); + } + ret_Index = tenseIndex; +} + + +void TenseOptPage::slotCleanup() +{ + vector<bool> used_tense; + for (int i = 0; i <= (int) tenseList->count(); i++) + used_tense.push_back(false); + + for (int col = 0; col < doc->numLangs(); col++) + for (int i = 0; i < (int) doc->numEntries(); i++) { + Conjugation conj = doc->getEntry(i)->getConjugation(col); + for (int ci = 0; ci < conj.numEntries(); ci++) { + QString t = conj.getType(ci); + if (t.left(strlen(UL_USER_TENSE)) == UL_USER_TENSE) { + t.remove (0, strlen(UL_USER_TENSE)); + int idx = t.toInt(); + if ((int) used_tense.size() < idx) + used_tense.resize(idx); + if (idx != 0) + used_tense[idx-1] = true; + } + } + } + + for (int i = used_tense.size()-1; i >= 0; i--) + if (!used_tense[i]) { + for (int u = 0; u < (int) tenseIndex.size() ; u++) { + if (tenseIndex[u] == i || tenseIndex[u] < 0) { + act_tense = i; + slotDeleteTense(); + break; + } + } + } + + act_tense = 0; + tenseList->setCurrentItem (act_tense); +} + + +void TenseOptPage::cleanUnused(kvoctrainDoc *doc, const vector<int> &tenseIndex, int old_tenses) +{ + vector<int> translate_index; + vector<QString> new_tenseStr; + + ///////////////////////////////////////////////////// + // translate_index contains new index number for each + // old index + for (int i = 0; i <= QMAX (old_tenses, (int) tenseIndex.size()); i++) + translate_index.push_back(0); + + // now adjust lesson descriptions to new index + + for (int i = 0; i < (int) tenseIndex.size(); i++) { + if (tenseIndex[i] >= 0) + translate_index[tenseIndex[i]+1] = i+1; + } + + // only keep remaining tense indices + + // set tense index to 0 when not needed any more + // and translate to new index + + for (int col = 0; col < doc->numLangs(); col++) { + for (int i = 0; i < doc->numEntries(); i++) { + Conjugation conj = doc->getEntry(i)->getConjugation (col); + bool dirty = false; + for (int ci = 0; ci < conj.numEntries(); ci++) { + QString old = conj.getType(ci); + if (!old.isEmpty() && old.left(strlen(QM_USER_TYPE)) == QM_USER_TYPE) { + old.remove (0, 1); + int o = old.toInt(); + + dirty = true; + QString newtense; + if (translate_index[o] != 0) { + newtense.setNum (translate_index[o]); + newtense.insert (0, QM_USER_TYPE); + conj.setType(ci, newtense); + } + else + conj.setType(ci, ""); + } + } + if (dirty) + doc->getEntry(i)->setConjugation (col, conj); + } + } +} + +#include "TenseOptPage.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPage.h b/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPage.h new file mode 100644 index 00000000..2ae20b7f --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPage.h @@ -0,0 +1,74 @@ +/*************************************************************************** + + user tense options dialog page + + ----------------------------------------------------------------------- + + begin : Sun May 28 12:14:31 2000 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 TenseOptPage_included +#define TenseOptPage_included + +#include "TenseOptPageForm.h" + +#include <vector> +using namespace std; + +class kvoctrainDoc; +class QStrList; + +class TenseOptPage : public TenseOptPageForm +{ + Q_OBJECT + +public: + + TenseOptPage + ( + const vector<QString> &tenses, + kvoctrainDoc *doc, + QWidget *parent = NULL, + const char *name = NULL + ); + + void getTenseNames (vector<QString> &ret_types, vector<int> &ret_Index); + + static void cleanUnused(kvoctrainDoc *doc, const vector<int> &tenseIndex, int old_tenses); + +protected: + + void updateListBox(int start); + +protected slots: + + void slotDeleteTense(); + void slotNewTense(); + void slotTenseChosen(int); + void slotModifyTense(); + void slotCleanup(); + +private: + kvoctrainDoc *doc; + int act_tense; + vector<int> tenseIndex; // contains indices of tenses on exec() + // negative values are new tenses +}; +#endif // TenseOptPage_included diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPageForm.ui b/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPageForm.ui new file mode 100644 index 00000000..b0471df8 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TenseOptPageForm.ui @@ -0,0 +1,143 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>TenseOptPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Tense_Descriptions</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>580</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>tense_group</cstring> + </property> + <property name="title"> + <string>Tense Descriptions</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer row="1" column="3"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>b_new</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&New...</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>b_modify</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Modify...</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="2"> + <property name="name"> + <cstring>b_delete</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Delete</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="4"> + <property name="name"> + <cstring>b_cleanup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Clean Up</string> + </property> + </widget> + <widget class="QListBox" row="0" column="0" rowspan="1" colspan="5"> + <property name="name"> + <cstring>tenseList</cstring> + </property> + </widget> + </grid> + </widget> + </vbox> +</widget> +<tabstops> + <tabstop>tenseList</tabstop> + <tabstop>b_new</tabstop> + <tabstop>b_modify</tabstop> + <tabstop>b_delete</tabstop> + <tabstop>b_cleanup</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TitlePage.cpp b/kvoctrain/kvoctrain/docprop-dialogs/TitlePage.cpp new file mode 100644 index 00000000..038bceac --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TitlePage.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + + enter document title and author + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "TitlePage.h" + + +#include <kapplication.h> +#include <klocale.h> + +#include <qlineedit.h> +#include <qmultilineedit.h> +#include <qlabel.h> + +TitlePage::TitlePage +( + QString _title, + QString _author, + QString _license, + QString _doc_remark, + QWidget* parent, + const char* name +) + : + TitlePageForm( parent, name ) +{ + title = _title; + author = _author; + license = _license; + doc_remark = _doc_remark; + + e_author->setText (author); + label_author->setBuddy(e_author); + + e_title->setText (title); + e_title->setFocus(); + e_title->selectAll(); + label_title->setBuddy(e_title); + + e_license->setText (license); + label_license->setBuddy(e_license); + + e_remark->setText (doc_remark); + label_remark->setBuddy(e_remark); + + connect( e_author, SIGNAL(textChanged()), SLOT(slotAuthorChanged()) ); + connect( e_title, SIGNAL(textChanged(const QString&)), SLOT(slotTitleChanged(const QString&)) ); + connect( e_license, SIGNAL(textChanged(const QString&)), SLOT(slotLicenseChanged(const QString&)) ); + connect( e_remark, SIGNAL(textChanged()), SLOT(slotDocRemarkChanged()) ); +} + + +void TitlePage::slotTitleChanged(const QString& s) +{ + title = s; +} + + +void TitlePage::slotAuthorChanged() +{ + author = e_author->text(); +} + + +void TitlePage::slotLicenseChanged(const QString& s) +{ + license = s; +} + + +void TitlePage::slotDocRemarkChanged() +{ + doc_remark = e_remark->text(); +} + +#include "TitlePage.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TitlePage.h b/kvoctrain/kvoctrain/docprop-dialogs/TitlePage.h new file mode 100644 index 00000000..45b85ee6 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TitlePage.h @@ -0,0 +1,68 @@ +/*************************************************************************** + + enter document title and author + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 TitleDialog_included +#define TitleDialog_included + +#include "TitlePageForm.h" + +class TitlePage : public TitlePageForm +{ + Q_OBJECT + +public: + + TitlePage + ( + QString title, + QString author, + QString license, + QString doc_remark, + QWidget *parent = NULL, + const char *name = NULL + ); + + QString getTitle() { return title; } + QString getAuthor() { return author; } + QString getLicense() { return license; } + QString getDocRemark() { return doc_remark; } + +protected slots: + + void slotTitleChanged(const QString&); + void slotAuthorChanged(); + void slotLicenseChanged(const QString&); + void slotDocRemarkChanged(); + +private: + + QString title; + QString author; + QString license; + QString doc_remark; +}; + +#endif // TitlePage_included diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TitlePageForm.ui b/kvoctrain/kvoctrain/docprop-dialogs/TitlePageForm.ui new file mode 100644 index 00000000..b2a49e51 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TitlePageForm.ui @@ -0,0 +1,186 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>TitlePageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>TitlePage</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>564</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>tiltle_group</cstring> + </property> + <property name="title"> + <string>General Document Properties</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>label_title</cstring> + </property> + <property name="text"> + <string>&Title:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>e_title</cstring> + </property> + </widget> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>e_title</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>label_author</cstring> + </property> + <property name="text"> + <string>&Authors:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>e_author</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>label_remark</cstring> + </property> + <property name="text"> + <string>&Remark:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>e_remark</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>label_license</cstring> + </property> + <property name="text"> + <string>&License:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>e_license</cstring> + </property> + </widget> + <spacer row="4" column="0"> + <property name="name"> + <cstring>Spacer3</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> + <spacer row="4" column="1"> + <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> + <widget class="QMultiLineEdit" row="3" column="1"> + <property name="name"> + <cstring>e_remark</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QMultiLineEdit" row="1" column="1"> + <property name="name"> + <cstring>e_author</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>e_license</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + </vbox> +</widget> +<tabstops> + <tabstop>e_title</tabstop> + <tabstop>e_author</tabstop> + <tabstop>e_license</tabstop> + <tabstop>e_remark</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPage.cpp b/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPage.cpp new file mode 100644 index 00000000..9ab25379 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPage.cpp @@ -0,0 +1,269 @@ +/*************************************************************************** + + types options dialog page + + ----------------------------------------------------------------------- + + begin : Sun Sep 12 15:38:31 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "TypeOptPage.h" + +#include <kapplication.h> +#include <kinputdialog.h> +#include <kmessagebox.h> +#include <klocale.h> + +#include <qpushbutton.h> + +#include <QueryManager.h> + +#define TYPE_TAG ". " + +TypeOptPage::TypeOptPage +( + const vector<QString> &types, + kvoctrainDoc *_doc, + QWidget *parent, + const char *name +) + : + TypeOptPageForm( parent, name ), + doc(_doc) +{ + connect( typeList, SIGNAL(highlighted(int)), SLOT(slotTypeChosen(int)) ); + connect( b_cleanup, SIGNAL(clicked()), SLOT(slotCleanup()) ); + connect( b_delete, SIGNAL(clicked()), SLOT(slotDeleteType()) ); + connect( b_modify, SIGNAL(clicked()), SLOT(slotModifyType()) ); + connect( b_new, SIGNAL(clicked()), SLOT(slotNewType()) ); + + QString str; + for (int i = 0; i < (int) types.size(); i++) { + str.setNum (i+1); + if (i <= 9) + str.insert (0, " "); + typeList->insertItem (str+TYPE_TAG+types[i]); + typeIndex.push_back(i); + } + + act_type = 0; + if (types.size() != 0) + typeList->setCurrentItem (act_type); + + b_modify->setEnabled(typeList->count() != 0); + b_delete->setEnabled(typeList->count() != 0); + + typeList->setFocus(); +} + + +void TypeOptPage::slotTypeChosen(int index) +{ + act_type = index; +} + + +void TypeOptPage::slotNewType() +{ + bool ok; + QString getType = KInputDialog::getText( + i18n( "Type Description" ), i18n( "Enter type description:" ), QString::null, &ok ); + if( !ok ) + return; + QString str; + int i = typeList->count()+1; + str.setNum (i); + if (i <= 9) + str.insert (0, " "); + typeList->insertItem (str+TYPE_TAG+getType.stripWhiteSpace()); + typeIndex.push_back(-(i-1)); + act_type = typeList->count(); + typeList->setCurrentItem (i-1); + b_modify->setEnabled(true); + b_delete->setEnabled(true); +} + + +void TypeOptPage::slotModifyType() +{ + if (typeList->count() != 0 + && (int) typeList->count() > act_type) { + QString str = typeList->text (act_type); + int pos = str.find (TYPE_TAG); + str.remove (0, pos+strlen (TYPE_TAG)); + bool ok; + QString getType = KInputDialog::getText( + i18n( "Type Description" ), i18n( "Enter type description:" ), str, &ok ); + if( !ok ) + return; + QString str2; + str2.setNum (act_type+1); + if (act_type <= 9) + str2.insert (0, " "); + typeList->changeItem (str2+TYPE_TAG+getType.stripWhiteSpace(), act_type); + } +} + + +void TypeOptPage::updateListBox(int start) +{ + QString str, str2; + for (int i = start; i < (int) typeList->count(); i++) { + str = typeList->text (i); + int pos = str.find (TYPE_TAG); + str.remove (0, pos+strlen (TYPE_TAG)); + str2.setNum (i+1); + if (i <= 9) + str2.insert (0, " "); + typeList->changeItem (str2+TYPE_TAG+str, i); + } +} + + +void TypeOptPage::slotDeleteType() +{ + int act = act_type; + if (typeList->count() != 0 + && (int) typeList->count() > act) { + + QString t; + t.setNum(typeIndex[act_type]+1); + t.insert (0, QM_USER_TYPE); + for (int ent = 0; ent < doc->numEntries(); ent++) { + // FIXME: ProgressDlg here? + kvoctrainExpr *exp = doc->getEntry(ent); + for (int lang = 0; lang < (int) doc->numLangs(); lang++) { + if (exp->getType(lang) == t) { + KMessageBox::information(this, + i18n("This user defined type could not be deleted\nbecause it is in use."), + kapp->makeStdCaption(i18n("Deleting Type Description"))); + return; + } + } + } + + typeList->removeItem (act); + typeIndex.erase (typeIndex.begin() + act); + + if ((int) typeList->count() <= act) + act = typeList->count()-1; + else + updateListBox(act); // update items after current + + if (act >= 0) + typeList->setCurrentItem (act); + } + b_modify->setEnabled(typeList->count() != 0); + b_delete->setEnabled(typeList->count() != 0); +} + + +void TypeOptPage::getTypeNames (vector<QString> &ret_type, vector<int> &ret_Index) +{ + QString str; ret_type.clear(); + for (int i = 0; i < (int) typeList->count(); i++) { + str = typeList->text(i); + int pos = str.find (TYPE_TAG); + str.remove (0, pos+strlen (TYPE_TAG)); + ret_type.push_back (str); + } + ret_Index = typeIndex; +} + + +void TypeOptPage::slotCleanup() +{ + vector<bool> used_type; + for (int i = 0; i <= (int) typeList->count(); i++) + used_type.push_back(false); + + for (int col = 0; col < doc->numLangs(); col++) + for (int i = 0; i < (int) doc->numEntries(); i++) { + QString t = doc->getEntry(i)->getType(col); + if (t.left(strlen(QM_USER_TYPE)) == QM_USER_TYPE) { + t.remove (0, 1); + int idx = t.toInt(); + if ((int) used_type.size() < idx) + used_type.resize(idx); + if (idx != 0) + used_type[idx-1] = true ; + } + } + + for (int i = used_type.size()-1; i >= 0; i--) + if (!used_type[i]) { + for (int u = 0; u < (int) typeIndex.size() ; u++) { + if (typeIndex[u] == i || typeIndex[u] < 0) { + act_type = i; + slotDeleteType(); + break; + } + } + } + + act_type = 0; + typeList->setCurrentItem (act_type); +} + + +void TypeOptPage::cleanUnused(kvoctrainDoc *doc, const vector<int> &typeIndex, int old_types) +{ + vector<int> translate_index; + vector<QString> new_typeStr; + + ///////////////////////////////////////////////////// + // translate_index contains new index number for each + // old index + for (int i = 0; i <= QMAX (old_types, (int) typeIndex.size()); i++) + translate_index.push_back(0); + + // now adjust lesson descriptions to new index + + for (int i = 0; i < (int) typeIndex.size(); i++) { + if (typeIndex[i] >= 0) + translate_index[typeIndex[i]+1] = i+1; + } + + // only keep remaining type indices + + // set type index to 0 when not needed any more + // and translate to new index + + for (int col = 0; col < doc->numLangs(); col++) { + for (int i = 0; i < doc->numEntries(); i++) { + QString old = doc->getEntry(i)->getType (col); + if (!old.isEmpty() && old.left(strlen(QM_USER_TYPE)) == QM_USER_TYPE) { + old.remove (0, 1); + int o = old.toInt(); + + QString newtype; + if (translate_index[o] != 0) { + newtype.setNum (translate_index[o]); + newtype.insert (0, QM_USER_TYPE); + doc->getEntry(i)->setType (col, newtype); + } + else + doc->getEntry(i)->setType (col, ""); + } + } + } + +} + +#include "TypeOptPage.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPage.h b/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPage.h new file mode 100644 index 00000000..e497e361 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPage.h @@ -0,0 +1,72 @@ +/*************************************************************************** + + types options dialog page + + ----------------------------------------------------------------------- + + begin : Sun Sep 12 15:38:31 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 TypeOptPage_included +#define TypeOptPage_included + +#include "TypeOptPageForm.h" + +#include <vector> +using namespace std; + +class kvoctrainDoc; +class QStrList; + +class TypeOptPage : public TypeOptPageForm +{ + Q_OBJECT + +public: + + TypeOptPage + ( + const vector<QString> &types, + kvoctrainDoc *doc, + QWidget *parent = NULL, + const char *name = NULL + ); + + void getTypeNames (vector<QString> &ret_types, vector<int> &ret_Index); + + static void cleanUnused(kvoctrainDoc *doc, const vector<int> &lessonIndex, int old_lessons); + +protected: + void updateListBox(int start); + +protected slots: + + void slotDeleteType(); + void slotNewType(); + void slotTypeChosen(int); + void slotModifyType(); + void slotCleanup(); + +private: + kvoctrainDoc *doc; + int act_type; + vector<int> typeIndex; // contains indices of types on exec() + // negative values are new lessons +}; +#endif // TypeOptPage_included diff --git a/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPageForm.ui b/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPageForm.ui new file mode 100644 index 00000000..f1735015 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/TypeOptPageForm.ui @@ -0,0 +1,143 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>TypeOptPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Type_Descriptions</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>580</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>type_group</cstring> + </property> + <property name="title"> + <string>Type Descriptions</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer row="1" column="3"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>b_new</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&New...</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>b_modify</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Modify...</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="2"> + <property name="name"> + <cstring>b_delete</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Delete</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="4"> + <property name="name"> + <cstring>b_cleanup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Clean Up</string> + </property> + </widget> + <widget class="QListBox" row="0" column="0" rowspan="1" colspan="5"> + <property name="name"> + <cstring>typeList</cstring> + </property> + </widget> + </grid> + </widget> + </vbox> +</widget> +<tabstops> + <tabstop>typeList</tabstop> + <tabstop>b_new</tabstop> + <tabstop>b_modify</tabstop> + <tabstop>b_delete</tabstop> + <tabstop>b_cleanup</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPage.cpp b/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPage.cpp new file mode 100644 index 00000000..007622a8 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPage.cpp @@ -0,0 +1,314 @@ +/*************************************************************************** + + usage labels dialog page + + ----------------------------------------------------------------------- + + begin : Thu Mar 30 20:38:31 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "UsageOptPage.h" + +#include <kapplication.h> +#include <kinputdialog.h> +#include <kmessagebox.h> +#include <klocale.h> + +#include <qgroupbox.h> +#include <qpushbutton.h> + +#include <QueryManager.h> + +#define USAGE_TAG ". " + +UsageOptPage::UsageOptPage +( + const vector<QString> &usages, + kvoctrainDoc *_doc, + QWidget *parent, + const char *name +) + : + UsageOptPageForm( parent, name ), + doc(_doc) +{ + connect( b_cleanup, SIGNAL(clicked()), SLOT(slotCleanup()) ); + connect( b_delete, SIGNAL(clicked()), SLOT(slotDeleteUsage()) ); + connect( b_modify, SIGNAL(clicked()), SLOT(slotModifyUsage()) ); + connect( b_new, SIGNAL(clicked()), SLOT(slotNewUsage()) ); + connect( usageList, SIGNAL(highlighted(int)), SLOT(slotUsageChosen(int)) ); + + QString str; + for (int i = 0; i < (int) usages.size(); i++) { + str.setNum (i+1); + if (i <= 9) + str.insert (0, " "); + usageList->insertItem (str+USAGE_TAG+usages[i]); + usageIndex.push_back(i); + } + + act_usage = 0; + if (usages.size() != 0) + usageList->setCurrentItem (act_usage); + + b_modify->setEnabled(usageList->count() != 0); + b_delete->setEnabled(usageList->count() != 0); + + usageList->setFocus(); +} + + +void UsageOptPage::slotUsageChosen(int index) +{ + act_usage = index; +} + + +void UsageOptPage::slotNewUsage() +{ + bool ok; + QString getUsage = KInputDialog::getText( + i18n( "usage (area) of an expression", "Usage Description" ), i18n( "Enter usage description:" ), QString::null, &ok ); + if( !ok ) + return; + QString str; + int i = usageList->count()+1; + str.setNum (i); + if (i <= 9) + str.insert (0, " "); + usageList->insertItem (str+USAGE_TAG+getUsage.stripWhiteSpace()); + usageIndex.push_back(-(i-1)); + act_usage = usageList->count(); + usageList->setCurrentItem (i-1); + b_modify->setEnabled(true); + b_delete->setEnabled(true); +} + + +void UsageOptPage::slotModifyUsage() +{ + if (usageList->count() != 0 + && (int) usageList->count() > act_usage) { + QString str = usageList->text (act_usage); + int pos = str.find (USAGE_TAG); + str.remove (0, pos+strlen (USAGE_TAG)); + + bool ok; + QString getUsage = KInputDialog::getText( + i18n( "usage (area) of an expression", "Usage Description" ), i18n( "Enter usage description:" ), str, &ok ); + if( !ok ) + return; + QString str2; + str2.setNum (act_usage+1); + if (act_usage <= 9) + str2.insert (0, " "); + usageList->changeItem (str2+USAGE_TAG+getUsage.stripWhiteSpace(), act_usage); + } +} + + +void UsageOptPage::updateListBox(int start) +{ + QString str, str2; + for (int i = start; i < (int) usageList->count(); i++) + { + str = usageList->text (i); + int pos = str.find (USAGE_TAG); + str.remove (0, pos+strlen (USAGE_TAG)); + str2.setNum (i+1); + if (i <= 9) + str2.insert (0, " "); + usageList->changeItem (str2+USAGE_TAG+str, i); + } +} + + +void UsageOptPage::slotDeleteUsage() +{ + int act = act_usage; + if (usageList->count() != 0 && (int) usageList->count() > act) + { + QString t; + t.setNum(usageIndex[act_usage]+1); + t.insert (0, UL_USER_USAGE); + t += UL_USAGE_DIV; + for (int ent = 0; ent < doc->numEntries(); ent++) { + // FIXME: ProgressDlg here? + kvoctrainExpr *exp = doc->getEntry(ent); + for (int lang = 0; lang < doc->numLangs(); lang++) { + QString ul = exp->getUsageLabel(lang) + UL_USAGE_DIV; + if (ul.find(t) >= 0 ) { + KMessageBox::information(this, + i18n("usage (area) of an expression", + "This user-defined usage label could not be deleted " + "because it is in use."), + kapp->makeStdCaption(i18n("usage (area) of an expression", + "Deleting Usage Label"))); + return; + } + } + } + + usageList->removeItem (act); + usageIndex.erase (usageIndex.begin() + act); + + if ((int) usageList->count() <= act) + act = usageList->count()-1; + else + updateListBox(act); // update items after current + + if (act >= 0) + usageList->setCurrentItem (act); + } + b_modify->setEnabled(usageList->count() != 0); + b_delete->setEnabled(usageList->count() != 0); +} + + +void UsageOptPage::getUsageLabels (vector<QString> &ret_usage, + vector<int> &ret_Index) +{ + QString str; ret_usage.clear(); + for (int i = 0; i < (int) usageList->count(); i++) { + str = usageList->text(i); + int pos = str.find (USAGE_TAG); + str.remove (0, pos+strlen (USAGE_TAG)); + ret_usage.push_back (str); + } + ret_Index = usageIndex; +} + + +void UsageOptPage::slotCleanup() +{ + vector<bool> used_usage; + for (int i = 0; i <= (int) usageList->count(); i++) + used_usage.push_back(false); + + for (int col = 0; col < doc->numLangs(); col++) + for (int i = 0; i < (int) doc->numEntries(); i++) { + QString t = doc->getEntry(i)->getUsageLabel(col); + QString n; + while (t.left(strlen(UL_USER_USAGE)) == UL_USER_USAGE) { + t.remove (0, 1); + + int next; + if ((next = t.find(UL_USAGE_DIV)) >= 0) { + n = t.left(next); + t.remove (0, next+1); + } + else { + n = t; + t = ""; + } + + int idx = n.toInt(); + if ((int) used_usage.size() < idx) + used_usage.resize(idx); + if (idx != 0) + used_usage[idx-1] = true ; + } + } + + for (int i = used_usage.size()-1; i >= 0; i--) { + if (!used_usage[i]) { + for (int u = 0; u < (int) usageIndex.size() ; u++) { + if (usageIndex[u] == i || usageIndex[u] < 0) { + act_usage = i; + slotDeleteUsage(); + break; + } + } + } + } + + act_usage = 0; + usageList->setCurrentItem (act_usage); +} + + +void UsageOptPage::cleanUnused(kvoctrainDoc *doc, + const vector<int> &usageIndex, + int old_usages) +{ + vector<int> translate_index; + vector<QString> new_usageStr; + + ///////////////////////////////////////////////////// + // translate_index contains new index number for each + // old index + for (int i = 0; i <= QMAX (old_usages, (int) usageIndex.size()); i++) + translate_index.push_back(0); + + // now adjust lesson descriptions to new index + + for (int i = 0; i < (int) usageIndex.size(); i++) { + if (usageIndex[i] >= 0) + translate_index[usageIndex[i]+1] = i+1; + } + + // only keep remaining usage indices + + // set usage index to 0 when not needed any more + // and translate to new index + + for (int col = 0; col < doc->numLangs(); col++) { + for (int i = 0; i < doc->numEntries(); i++) { + QString t = doc->getEntry(i)->getUsageLabel (col); + if (!t.isEmpty() && t.left(strlen(UL_USER_USAGE)) == UL_USER_USAGE) { + QString tg; + while (t.left(strlen(UL_USER_USAGE)) == UL_USER_USAGE) { + QString n; + t.remove (0, 1); + int next; + if ((next = t.find(UL_USAGE_DIV)) >= 0) { + n = t.left(next); + t.remove (0, next+1); + } + else { + n = t; + t = ""; + } + + QString newusage; + int o = n.toInt(); + if (translate_index[o] != 0) { + newusage.setNum (translate_index[o]); + newusage.insert (0, UL_USER_USAGE); + } + + if (tg.length() == 0) + tg = newusage; + else + if (newusage.length() ) + tg += UL_USAGE_DIV + newusage; + } + + if (tg.length() == 0) + tg = t; + else if (t.length() != 0) + tg += UL_USAGE_DIV + t; + + doc->getEntry(i)->setUsageLabel (col, tg); + } + } + } +} + +#include "UsageOptPage.moc" diff --git a/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPage.h b/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPage.h new file mode 100644 index 00000000..f9e8d978 --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPage.h @@ -0,0 +1,74 @@ +/*************************************************************************** + + usage labels dialog page + + ----------------------------------------------------------------------- + + begin : Sun Sep 12 15:38:31 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 UsageOptPage_included +#define UsageOptPage_included + +#include "UsageOptPageForm.h" + +#include <UsageManager.h> + +#include <vector> +using namespace std; + +class kvoctrainDoc; +class QStrList; + +class UsageOptPage : public UsageOptPageForm +{ + Q_OBJECT + +public: + + UsageOptPage + ( + const vector<QString> &usages, + kvoctrainDoc *doc, + QWidget *parent = NULL, + const char *name = NULL + ); + + void getUsageLabels (vector<QString> &ret_usages, vector<int> &ret_Index); + + static void cleanUnused(kvoctrainDoc *doc, const vector<int> &lessonIndex, int old_lessons); + +protected: + void updateListBox(int start); + +protected slots: + + void slotDeleteUsage(); + void slotNewUsage(); + void slotUsageChosen(int); + void slotModifyUsage(); + void slotCleanup(); + +private: + kvoctrainDoc *doc; + int act_usage; + vector<int> usageIndex; // contains indices of usages on exec() + // negative values are new lessons +}; +#endif // UsageOptPage_included diff --git a/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPageForm.ui b/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPageForm.ui new file mode 100644 index 00000000..dbdf58fe --- /dev/null +++ b/kvoctrain/kvoctrain/docprop-dialogs/UsageOptPageForm.ui @@ -0,0 +1,143 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>UsageOptPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Usage_Labels</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>572</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>usage_group</cstring> + </property> + <property name="title"> + <string>Usage Labels</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer row="1" column="3"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>b_new</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&New...</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>b_modify</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Modify...</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="2"> + <property name="name"> + <cstring>b_delete</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Delete</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="4"> + <property name="name"> + <cstring>b_cleanup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Clean Up</string> + </property> + </widget> + <widget class="QListBox" row="0" column="0" rowspan="1" colspan="5"> + <property name="name"> + <cstring>usageList</cstring> + </property> + </widget> + </grid> + </widget> + </vbox> +</widget> +<tabstops> + <tabstop>usageList</tabstop> + <tabstop>b_new</tabstop> + <tabstop>b_modify</tabstop> + <tabstop>b_delete</tabstop> + <tabstop>b_cleanup</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/docs/elek.lex b/kvoctrain/kvoctrain/docs/elek.lex new file mode 100644 index 00000000..46b23aaa --- /dev/null +++ b/kvoctrain/kvoctrain/docs/elek.lex @@ -0,0 +1,191 @@ +Vocabulary Trainer V5.0
+LEX|Deutsch|Englisch| 259 260 1 1 1 0 0 268 0 1 1 1 1 145 6 23 1999 255 1 1 653 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 1 1 0 0 |
+-11 700
+System
+Energie- und Automatisierungstechnik. V. Manuela Lutz. Danke.
+1 1 der die das|he she it|
+1 1 eine einer eines einen einem|has have had is be|
+1 1 er sie es|his him her its|
+1 1 wir ihr euch|in to into on at too|
+1 1 in an auf bei|the a an|
+1 1 zu um zur zum|out by with of off|
+1 1 ist sind seid|something someone some|
+1 1 dies dieser dieses|under below|
+1 1 ||
+1 1 ||
+der die das ein eine einer eines einen einem|the a an|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+Sachgebiete|
+|
+|
+|
+|
+|
+|
+|
+|
+32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
+1 0 255 255 255 255 255 255 0 0 1 Abbildung||||mapping||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abblendkappe||||anti-dazzle device||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abdeckblech||||cover sheet||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abfallstoffe|products|||waste||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abfalltechnik||||waste engineering||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abfangblech||||locating plate||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abfrageprotokoll||||inquiry log||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgabeleistung||||power output||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgang||||outgoing circuit||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgangsbaugruppe||||outgoing unit||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgas||||exhaust gas||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgasdruck||||exhaust gas pressure||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgasemission||||exhaust gas emission||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgasgegendruck||||exhaust gas back pressure||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgaskatalysator||||exhaust gas catalytic converter||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgaskomponenten||||exhaust gas components||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgasmegert||||exhaust gas measuring equipment||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgasrckfhrung||||exhaust gas recycling||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abgedeckter Druckknopf||||covered pushbutton||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abgedichtete Kunststoffleuchte||||sealed plastic luminaire||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abgehende Leitung||||outgoing feeder||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abgeschirmte Drucktaste||||shrouded pushbutton||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abgesichert||||fused||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abgetastet||||sampled||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abgeteilt||||segregated||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abgleich||||adjustment||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abisolieren||||to strip||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abklemmen||||disconnect||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Ablauf||||sequence||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Ablaufplan||||flow diagram||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Ableiter||||surge arrester||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Ableitung||||terminal lead||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Ablenkung||||deflection||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abluft||||exhaust air||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abschaltautomatic bei Spannungsabfall||||automatic loss-of-voltage tripping equipment||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abschirmung||||screening||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Absolutwert||||absolute value||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abstand||||distance||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abstraktionsebene||||level of abstraction||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abteilung||||department||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abwasseraufbereitung||||effluent treatment||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abwasserbehandlung||||waste water treatment||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abwassertechnik||||sewage technology||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Abweichung||||deviation||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 abzhlbar||||countable||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Achse||||axis||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 adaptiver||||adaptive||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Aggregate||||aggregates||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Aktoren|Aktuatoren|||actuators||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Akustik||||acoustics||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Alterungsbestndig||||durability||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Altlasten||||polluted areas||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Analogeingabe||||analog input||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Arbeitswissenschaften||||ergonomics||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Aufbau- und Verbindungstechnik||||packaging of integrated circuits||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Aufbereitung||||preparation||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Auflsung||||resolution||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Aufspannplatte||||mounting plate||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Auftragsabwicklung||||order transaction||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Auftragsbearbeitung||||order processing||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Ausfhrung||||conducting||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Beleuchtungstechnik||||illumination engineering||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Bildcodierung||||image coding||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Bilderkennungssystem||||image recognition system||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Bildkommunikation||||image communication||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Bildmenge||||image set||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Bildschirmanzeige||||screen diplay||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Bildverarbeitung||||image processing||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Borhmaschine||||drilling machine||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+0 47 255 255 255 255 255 255 0 0 1 Datenbertragung||||data transmission||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Druckluft||||compressed air||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Druckluftanlage||||compressed-air system||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Drucktaster||||pushbutton||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Einbautechnik|Einbausystem|||packaging system||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Einheit||||unit||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 elektrisch||||electrical||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Elektrizittszhler||||electricity meter||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 elektromechanische Bauelemente||||electromechanical components||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Elektromotor||||electric motor||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 elektronische Steuerung||||electronic control||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Endschalter||||limit switch||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Fernwirktechnik||||telecontrol||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Freiluftanlage||||outdoor installation||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Gebudeinstallation||||wiring practice||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 gedruckte Schaltung||||printed circuit||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Gleichrichter||||rectifier||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Grenzwert||||limiting value||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Halbleiter||||semiconductor||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Halbleiterbauelement||||semiconductor component||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Hebezeug||||hoisting gear||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Hilfsstromschalter||||control switch||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Innenraumanlage||||indoor installation||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Installationskanal||||trunking and duct system||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Installationsmaterial||||wiring accessoires||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Installationstechnik||||electrical installation||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Isolation|Isolierung|||insulation||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Klimatechnik||||air conditioning||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Kommutator||||commutator||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Kraftwerk||||power station||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Kupplung||||coupling||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Lager||||bearing||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Leistungselektronik||||power electronic||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Leistungsschalter|Leistungsschutzschalter|||circuit-breaker||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Leittechnik||||control engineering||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Lichttechnik||||lightning engineering||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Linearmotor||||linear motor||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 magnetisch||||magnetic||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Magnetschwebebahn||||magnetic levitation system||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Maschine||||machine||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 mechanisch||||mechanical||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Megert||||measuring instrument||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Nherungsschalter||||proximity switch||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Oszilloskop||||oscilloscope||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Positionsschalter||||position switch||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 programmierbares Megert||||programmable measuring apparatus||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 programmierbares Steuergert||||programmable controller||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Prozeleittechnik||||process control technology||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Prfung||||testing||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Regelung||||automatic control||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Relais||||relay||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 rotierende Maschine||||rotating machine||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Rundsteueranlage||||ripple control system||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Rntgenanalyse||||x-ray analysis||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Rckkopplung||||feedback||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Sammelschiene||||busbar||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Schallmessung||||sound measurement||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Schaltanlage|Schaltgert|||switchgear||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Schaltschrank||||switchgear||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Schalttafel||||switchboard||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Schieneninstallationsrohr||||buselectric wiring conduit||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Sicherung|Schmelzsicherung|||fuse||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Steckvorrichtung||||plug-and-socket device||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Steuergert||||controller||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Stromrichter||||static converter||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Supraleiter||||superconductor||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Supraleitung||||superconductivity||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Thyristor||||thyristor||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Vakuumschalter|circuit-breaker|||vacuum swith||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Wasserkraftgenerator||||water-wheel generator||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Wasserkraftwerk||||hydroelectric power station||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Werkzeug||||tool||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Werkzeugmaschine||||machine tool||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 0 255 255 255 255 255 255 0 0 1 Wert||||value||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Wicklung||||winding||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+1 47 255 255 255 255 255 255 0 0 1 Zugangskontrollsystem||||access control system||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
diff --git a/kvoctrain/kvoctrain/docs/kvtml-aufbau.txt b/kvoctrain/kvoctrain/docs/kvtml-aufbau.txt new file mode 100644 index 00000000..e606bd80 --- /dev/null +++ b/kvoctrain/kvoctrain/docs/kvtml-aufbau.txt @@ -0,0 +1,264 @@ +<?xml version="1.0"?> +<!doctype kvtml system "kvoctrain.dtd"> +<!-- +This is a machine generated file. +Be careful when editing here. + +Short definition: + +lesson lesson group + desc name + %no its index + %current is current lesson +type type group + desc name + %no its index +e entry of dictionary + %s is selected + %m lesson member + %t common expression type + o original + %q in query ("o" is given, "t" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type (see QueryManager.h) + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + t translation .. + %q in query ("t" is given, "o" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + + %d last query date (from;to) + %w dito, compressed + %g grade (from;to) + %c count (from;to) + %b bad count (from;to) + + +Valid xml means: + - Close all tags + - Keep proper hierarchy + - All attributes are quoted + +-- +> +<kvtml + encoding="8Bit" <!-- Kodierung (ab hier) 8Bit oder UTF8 --> + generator="kvoctrain v0.7.0pre3" <!-- fr alle Flle --> + cols="3" <!-- ebenfalls Reserve --> + lines="3" <!-- nur fr Fortschrittsbalken zu Beginn --> + title="Beispieldatei: Deutsch - Englisch/Franzsisch" <!-- 4 selbsterklrende Zeilen ;-) --> + author="Ewald Arnold" + license="OpenContent" + remark="Beispieldatei mit allen Eigenschaften"> + + <lesson width="104"> <!-- Block mit Lektionen, width ist die zuletzt eingestellte Breite der Spalte --> + <desc no="1">Lektion eins</desc> + <desc no="2">Lektion zwei</desc> + <desc no="3">Lektion drei</desc> + <desc no="4">Lektion vier</desc> + </lesson> + + <article> <!-- Definition mit den Artikeln je Sprache --> + <e l="de"> <!-- bestimmter und unbestimmter Artikel --> + <fd>die</fd> + <fi>eine</fi> + <md>der</md> + <mi>einer</mi> + <nd>das</nd> + <ni>ein</ni> + </e> + <e l="en"> + <fd>fd en</fd> + <fi>fi en</fi> + <md>md en</md> + <mi>mi en</mi> + <nd>nd en</nd> + <ni>ni en</ni> + </e> + <e l="fr"> + <fd>la</fd> + <fi>une</fi> + <md>le</md> + <mi>un</mi> + </e> + </article> + + <conjugation> <!-- Prfixe fr Konjugationen --> + <e l="de"> <!-- ebenfalls fr alle Sprachen --> + <s1>ich</s1> <!-- wobei die Reihenfolge de-en-fr gleich sein muss wie vorher --> + <s2>du</s2> + <s3f>sie</s3f> + <s3m>er</s3m> + <s3n>es</s3n> + <p1>wir</p1> + <p2>ihr</p2> + <p3f common="1">sie</p3f> + <p3m>sie</p3m> + <p3n>sie</p3n> + </e> + <e l="en"> + <s1>I</s1> + <s2>you</s2> + <s3f>he</s3f> + <s3m>she</s3m> + <s3n>it</s3n> + <p1>we</p1> + <p2>you</p2> + <p3f common="1">they</p3f> + </e> + <e l="fr"> + <s1>je</s1> + <s2>tu</s2> + <s3f>elle</s3f> + <s3m>il</s3m> + <p1>nous</p1> + <p2>vous</p2> + <p3f>elles</p3f> + <p3m>ils</p3m> + </e> + </conjugation> + + <options> <!-- Dokument-Optionen, z.B. nicht sortieren --> + <sort on="1"/> + </options> + + <type> <!-- eigene Worttypen --> + <desc no="1">Mein Typ 1</desc> + <desc no="2">Mein Typ 2</desc> + <desc no="3">Mein Typ 3</desc> + </type> + + <tense> <!-- eigene Worttypen --> + <desc no="1">Benutzer-Konjugation 1</desc> + </tense> + + <usage> <!-- eigene Sprachebenen --> + <desc no="1">Benutzersprachebene 1</desc> + </usage> + + <e + m="3" <!-- Lektionsindex 3, Name siehe oben --> + s="1" <!-- selektiert, Rest einer abgebrochenen Abfrage --> + t="v"> <!-- Worttyp, Verb --> + + <o width="208" <!-- Originalausdruck, zuletzt benutzte Spaltenbreite --> + l="de" <!-- Sprache deutsch --> + charset="ISO 8859-1" <!-- Zeichensatz, alle 8859-x, auch Unicode und Japanisch, soweit eben von QT2/KDE2 untersttzt --> + y="laufen"> <!-- Synonyme, derzeit durch Kommas notdrftig getrennt --> + + <conjugation <!-- Konjugationen zum aktuellen Verb --> + <!-- angedacht: hier knnten weitere Attribute wie oben fr + Noten, Abfrage usw. stehen --> + + > + <t n="PrSi"> <!-- Typ, Simple Present --> + <s1>gehe</s1> <!-- ich, du, er, ... --> + <s2>gehst</s2> + <s3f common="1">geht</s3f> <!-- er, sie, es gemeinsam weil gleich --> + <p1>gehen</p1> + <p2>gehen</p2> + <p3f common="1">gehen</p3f></t> + <t n="PaSi"><s1>schwamm</s1><s2>schwammst</s2></t> + </conjugation> + gehen</o> <!-- eigentliche Vokabel --> + + + + <t <!-- erste Fremdsprache --> + width="208" + l="en" <!-- Sprachcode --> + g="1;2" <!-- Note fr Richtung von/zum Original, 1..7 --> + c="2;0" <!-- Anzahl Abfragen von/zum Original --> + b="1;0" <!-- davon falsche Abfragen von/zum Original --> + w="AiHzA;AiHzA" <!-- letztes Abfragedatum von/zum Original, hier etwas "komprimiert", eigentlich aber time()-Funktion --> + ff="falscher Freund" <!-- falscher Freund vom Original --> + tf="Freund falscher"> <!-- falscher Freund zum Original --> + + <conjugation + <!-- angedacht: hier knnten weitere Attribute wie oben fr + Noten, Abfrage usw. stehen --> + > + <t n="PaSi"><s1>went</s1></t> + <t n="PaPa"><s1>have gone</s1></t> + </conjugation> + go</t> + + <t width="208" <!-- zweite Fremdsprache --> + l="fr" <!-- Franzsisch --> + charset="Unicode" <!-- Unicode kodiert --> + >aller</t></e> <!-- Ende dieses Datensatzes --> + + <e m="4" + s="1" + t="aj"> <!-- Typ Adjektiv --> + + <o r="unregelmssiges Adjektiv" <!-- eigene Bemerkung --> + a="schlecht"> <!-- Antonym dieser Vokabel --> + + <comparison> <!-- Block mit Steigerungsformen --> + <l1>gut</l1> + <l2>besser</l2> + <l3>am besten</l3> + </comparison> + gut</o><t> + <comparison> + <l1>good</l1><l2>better</l2><l3>best</l3> + </comparison> + good</t><t> + <comparison> + <l1>bon</l1><l2>meilleur</l2><l3>le meilleur</l3> + </comparison> + bon</t></e> + <e m="2" t="n"> + <o y="Fugelenk" <!-- Synonyme --> + u="anat" <!-- Sprachebene, Anatomie --> + >Knchel</o> + + <t p="nackls"> <!-- Aussprache, derzeit nach Geschmack, spter zustzlich mit Unicode + und den Zeichen aus dem Phonetischen Alphabet --> + knuckles</t><t g="2;3" c="1;1" b="1;1">cheville</t></e> +</kvtml> + + +<!-- + + noch einige Bemerkungen: + + Alle Eigenschaften sind darauf ausgelegt, mit anderen austauschbar zu sein, + auch ber Sprachgrenzen hinweg. + + Es wird immer ber einen "Platzhalter" referenziert. + Der Typ "Verb" z.B. mit "v", Hauptwrter zunchst mit "n", knnen + aber mit "n:f" nher spezifiziert werden, in diesem Fall "Nomen,weiblich". + + u="anat" ist ebenfalls in allen Sprachen das selbe und wird nur fr die Anzeige + intern in "Anatomie" der "anatomy" umgesetzt. Bei den Benutzerebenen sind mehrere + in Kombination mglich, jeweils durch Kommas getrennt. + + Benutzerdefinierte Eigenschaften beginnen immer mit einem "#" und einer darauf + folgenden Nummer. Z.B. t="#1" = benutzer-definierter Worttyp, mit dem Namen des ersten + Eintrages des entsprechenden Blockes. Mehrsprachigkeit ist hier nicht mglich und meist auch + nicht ntig, aber immerhin kann man die Blcke im Programm oder einem Texteditor anpassen, + wenn Bedarf ist. + +--> +
\ No newline at end of file diff --git a/kvoctrain/kvoctrain/docs/kvtml-structure.txt b/kvoctrain/kvoctrain/docs/kvtml-structure.txt new file mode 100644 index 00000000..3a289208 --- /dev/null +++ b/kvoctrain/kvoctrain/docs/kvtml-structure.txt @@ -0,0 +1,258 @@ +<?xml version="1.0"?> +<!doctype kvtml system "kvoctrain.dtd"> +<!-- +This is a machine generated file. +Be careful when editing here. + +Short definition: <!-- The level of indentation shows the relation: right is "owned" by left --> + <!-- attributes are preceded by % -> + +lesson lesson group + desc name + %no its index + %current is current lesson +type type group + desc name + %no its index +e expression of dictionary + %s is selected + %m lesson member + %t common expression type + o original + %q in query ("o" is given, "t" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type (see QueryManager.h) + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + t translation .. + %q in query ("t" is given, "o" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + + %d last query date (from;to) + %w dito, compressed + %g grade (from;to) + %c count (from;to) + %b bad count (from;to) + + +Valid xml means: + - Close all tags + - Keep proper hierarchy + - All attributes are quoted + +-- +> +<kvtml + encoding="8Bit" <!-- Encoding (starting from here) 8Bit or UTF8 --> + generator="kvoctrain v0.7.0pre3" <!-- just in case --> + cols="3" <!-- as well: just in case --> + lines="3" <!-- just for progressbar on startup --> + title="Beispieldatei: Deutsch - Englisch/Franzsisch" <!-- 4 self explaining lines ;-) --> + author="Ewald Arnold" + license="OpenContent" + remark="Beispieldatei mit allen Eigenschaften"> + + <lesson width="104"> <!-- block with lesson names, width designates the last width of the leftmiost column --> + <desc no="1">Lektion eins</desc> + <desc no="2">Lektion zwei</desc> + <desc no="3">Lektion drei</desc> + <desc no="4">Lektion vier</desc> + </lesson> + + <article> <!-- Define all the articles of the languages --> + <e l="de"> <!-- definete and indefinite atricle --> + <fd>die</fd> <!-- use iso codes for languge reference --> + <fi>eine</fi> + <md>der</md> + <mi>einer</mi> + <nd>das</nd> + <ni>ein</ni> + </e> + <e l="en"> + <fd>fd en</fd> + <fi>fi en</fi> + <md>md en</md> + <mi>mi en</mi> + <nd>nd en</nd> + <ni>ni en</ni> + </e> + <e l="fr"> + <fd>la</fd> + <fi>une</fi> + <md>le</md> + <mi>un</mi> + </e> + </article> + + <conjugation> <!-- Prefix for conjugations --> + <e l="de"> <!-- all languages must be listed --> + <s1>ich</s1> <!-- same order as above --> + <s2>du</s2> + <s3f>sie</s3f> + <s3m>er</s3m> + <s3n>es</s3n> + <p1>wir</p1> + <p2>ihr</p2> + <p3f common="1">sie</p3f> <!-- third person is the same for all --> + <p3m>sie</p3m> + <p3n>sie</p3n> + </e> + <e l="en"> + <s1>I</s1> + <s2>you</s2> + <s3f>he</s3f> + <s3m>she</s3m> + <s3n>it</s3n> + <p1>we</p1> + <p2>you</p2> + <p3f common="1">they</p3f> + </e> + <e l="fr"> + <s1>je</s1> + <s2>tu</s2> + <s3f>elle</s3f> + <s3m>il</s3m> + <p1>nous</p1> + <p2>vous</p2> + <p3f>elles</p3f> + <p3m>ils</p3m> + </e> + </conjugation> + + <options> <!-- document related options, e.g. don't sort --> + <sort on="1"/> + </options> + + <type> <!-- user defined word types --> + <desc no="1">Mein Typ 1</desc> + <desc no="2">Mein Typ 2</desc> + <desc no="3">Mein Typ 3</desc> + </type> + + <tense> <!-- user defined tenses --> + <desc no="1">Benutzer-Konjugation 1</desc> + </tense> + + <usage> <!-- user defined usage labels --> + <desc no="1">Benutzersprachebene 1</desc> + </usage> + + <e + m="3" <!-- lesson index 3, name see above --> + s="1" <!-- selected from last query (not yet queried) --> + t="v"> <!-- type of word: here verb--> + + <o width="208" <!-- original expression, width of column when last saved --> + l="de" <!-- language code de: german --> + charset="ISO 8859-1" <!-- charset needed for correct displaing --> + y="laufen"> <!-- synonyms, separated by commas currently --> + + <conjugation <!-- list the conjugations for the current verb --> + + > + <t n="PrSi"> <!-- internal tense: simple present --> + <s1>gehe</s1> <!-- I, you, he, she ... --> + <s2>gehst</s2> + <s3f common="1">geht</s3f> <!-- he, she, it the same --> + <p1>gehen</p1> + <p2>gehen</p2> + <p3f common="1">gehen</p3f></t> + <t n="PaSi"><s1>schwamm</s1><s2>schwammst</s2></t> + </conjugation> + gehen</o> <!-- the base word --> + + + + <t <!-- first translation --> + width="208" + l="en" <!-- lang code --> + g="1;2" <!-- current grade #from# original ; #to# original. 0=not queried, 1..7 (7 is best)) --> + c="2;0" <!-- number of queries so far (from/to the original) --> + b="1;0" <!-- number of wrong answers (from/to) --> + d="12312;123123" <!-- last query date (from/to) using time()-function --> + ff="falscher Freund" <!-- false friend (from original) --> + tf="Freund falscher"> <!-- false friend (to original) --> + + <conjugation + > + <t n="PaSi"><s1>went</s1></t> + <t n="PaPa"><s1>have gone</s1></t> + </conjugation> + go</t> + + <t width="208" <!-- second translation --> + l="fr" <!-- french --> + charset="Unicode" <!-- encoding in unicode --> + >aller</t></e> <!-- end of this record --> + + <e m="4" <!-- language code may be omitted from second line on --> + s="1" + t="aj"> <!-- word type: adjectiv --> + + <o r="unregelmssiges Adjektiv" <!-- user defined comment --> + a="schlecht"> <!-- antonym of this word --> + + <comparison> <!-- block with comparison forms for this word --> + <l1>gut</l1> + <l2>besser</l2> + <l3>am besten</l3> + </comparison> + gut</o><t> <!-- first translation --> + <comparison> + <l1>good</l1><l2>better</l2><l3>best</l3> + </comparison> + good</t><t> <!-- second translation --> + <comparison> + <l1>bon</l1><l2>meilleur</l2><l3>le meilleur</l3> + </comparison> + bon</t></e> + <e m="2" t="n"> + <o y="Fugelenk" <!-- synonyms --> + u="anat" <!-- usage label, internal code for "anatomy" --> + >Knchel</o> + + <t p="nackls"> <!-- pronunciation according to your personal taste. With unicode you may + as well use the phonetic alphabet --> + knuckles</t><t g="2;3" c="1;1" b="1;1">cheville</t></e> +</kvtml> + + +<!-- + + Some additional comments: + + All properties are intended to be shared with other users, even between totally different + languages and encodings. + + The document always uses placeholders which are used to display "real" names according + to the users language. E.g. "v" means "Verb" whereas "n" means noun which can be extended + by a subtyp to "noun, female" by writing a placeholder "n:f". + + The same applies to usage labels. Here you may concatenate an arbitrary number of usage + labels with a comma: u="anat,biol" will result in "Anatomy, Biology" + + User defined properties always start with "#" and a number (internal properties always start + with a letter). e.g. t="#1" references the first entry in the user defined tenses. + Of course one can't provide automatic translation of the user defined properties this way. + +--> +
\ No newline at end of file diff --git a/kvoctrain/kvoctrain/docs/lex-aufbau1.txt b/kvoctrain/kvoctrain/docs/lex-aufbau1.txt new file mode 100644 index 00000000..cbdcf364 --- /dev/null +++ b/kvoctrain/kvoctrain/docs/lex-aufbau1.txt @@ -0,0 +1,58 @@ +From: Michael Werner <Michael_M_Werner@compuserve.com> + +Hallo Ewald, + +es freut mich, da Dir mein VT zusagt. Wobei ich mir nicht ganz im Klaren +bin, ob es eher mein Programm oder die beigefgten Lexika sind. ;-) + +Du hast vllig Recht, da ich der Opensource-Bewegung positiv gegenber +stehe. + +Viele Gre +Michael + + +----------kleine Format-Beschreibung (bitte mit Font Courier +"nichtproportional" ansehen)---------- + +Lexikon-Format-Beschreibung: + +Format eines minimalen Eintrags (mit zwei Dummy-Eintrgen x und y) + 0 255 255 255 255 255 255 0 0 1 +x||||y|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| + | | | | | | + | |___________________| | | Lektionszugehrigkeit (1-9) + | | | | + | | beide Sprachseiten sind ungelernt + | | + | diese Nummern bitte unverndert bernehmen + | +Attribut: 0 fr --NONE-- + +Format eines maximalen Eintrags + 0 255 255 255 255 255 255 0 0 1 +MAIN#0|SYNONYM#1|SYNONYM#2|SYNONYM#3|MAIN#1|SYNONYM#1|SYNONYM#2|SYNONYM#3|| +||||||||||||||||||||||||||||||||||||||||||||||||||||||| + + +Eine Konvertierung (zur Erstellung einer LEX-Datei) knnte nun +folgendermaen aussehen: + +erster Schritt: +Formatkopf einer bestehenden Lexikon-Datei nehmen und vor die erste +Vokabelzeile kopieren. + + +zweiter Schritt: +0 255 255 255 255 255 255 0 0 1 an den Anfang jeder Vokabelzeile +(entspricht einem Vokabeleintrag) schreiben. Wortbestandteile durch | +trennen. Minimal mu ein MAIN#0 und ein MAIN#1 existieren und mindestens 1 +Vokabelzeile. + + +dritter Schritt: +neues Lexikon laden. Dadurch werden beim nchsten Abspeichern die Anzahl +der Vokabeleintrge und das Datum korrekt gesetzt. Die Vokabelliste wird +hierbei auch sortiert. + + diff --git a/kvoctrain/kvoctrain/docs/lex-aufbau2.txt b/kvoctrain/kvoctrain/docs/lex-aufbau2.txt new file mode 100644 index 00000000..ea7f3583 --- /dev/null +++ b/kvoctrain/kvoctrain/docs/lex-aufbau2.txt @@ -0,0 +1,127 @@ +# Format eines minimalen Eintrags (mit zwei Dummy-Eintrgen x und y) +# 0 255 255 255 255 255 255 0 0 1 x||||y|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +# | | | | | | +# | |___________________| | | Lektionszugehrigkeit (1-9) + +? maximal 9 Lektionen? "Namen" der +Lektionen? +Das Lektionenmaximum ist auf 9 festgelegt. Die Lektionsbezeichnungen werden +weiter oben abgespeichert! Ausprobieren, dann siehst Du wo. + +# | | | | +# | | beide Sprachseiten sind ungelernt + +? 1..x = Note? +0..2 (0=ungelernt, 1=unsicher, 2=gelernt) + +# | | +# | diese Nummern bitte unverndert bernehmen + +? was bedeuten sie? + +# | +# Attribut: 0 fr --NONE-- + +? weitere Attribute? +Alle aus der Eingabemaske "Edit Entry" ersichtlichen + 20 extra zu +definierenden Attributen + +# Format eines maximalen Eintrags +# 0 255 255 255 255 255 255 0 0 1 +MAIN#0|SYNONYM#1|SYNONYM#2|SYNONYM#3|MAIN#1|SYNONYM#1|SYNONYM#2|SYNONYM#3||||||||||||||||||||||||||||||||||||||||||||||||||||||||| + +? Das Lexikon beinhaltet immer 2 Sprachen, MAIN ist der "normale" Ausdruck +und +? es folgen bis zu 3 Synonyme jeweils fr beide Sprachen. Was folgt +hierauf? +Alle Konjugationsformen die evtl. fr das Konjugationstraining eingegeben +wurden. (siehe ITALIAN.LEX) +? Ich speichere jeweils das letzte Abfragedatum, die Anzahl der Abfragen +? und Fehler sowie eine Art Note. Gibt es dies bei dir ebenfalls? +Nein, wozu? Meiner Meinung nach, ist der Anwender am Lernen interessiert +und nicht an einer Statistikreiterei. + +? Hier der Anfang von elek.lex mit meinen Vermutungen: + +# Vocabulary Trainer V5.0 + +? 1. Zeile: Version + +# LEX|Deutsch|Englisch| 259 260 1 1 1 0 0 268 0 1 1 1 1 145 6 23 1999 255 1 1 653 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 1 1 0 0 | + +? 2. Zeile: Kennung, Sprachen 1+2 und viele Daten (aber welche ? ;-) +Programminterne: Abspeicherung der Trainingsoptionen und viele andere Infos +die meiner Meinung nach Lexikaspezifisch abgespeichert werden sollen. + +# -11 700 +verwendeter Zeichensatz +? 3. Zeile: nochmal 2 Daten +# System +? 4. Zeile: Beschreibung ? +Nein! Nochmals verwendeter Zeichensatz + +# Energie- und Automatisierungstechnik. V. Manuela Lutz. Danke. + +? 5. Zeile: nochmal Beschreibung/Herkunft ? +Eigentliche Lexikonbeschreibung + +? danach ein Stck Wrterbuch, allerdings ein anderer Aufbau als oben +-> siehe Trainingsoptionen +# 1 1 der die das|he she it| +# 1 1 eine einer eines einen einem|has have had is be| +# 1 1 er sie es|his him her its| +# 1 1 wir ihr euch|in to into on at too| +# 1 1 in an auf bei|the a an| +# 1 1 zu um zur zum|out by with of off| +# 1 1 ist sind seid|something someone some| +# 1 1 dies dieser dieses|under below| +# 1 1 || +# 1 1 || + +? Zeile ohne Zahlen? +-> siehe ebenfalls Trainingsoptionen +# der die das ein eine einer eines einen einem|the a an| + +? viele Leerzeilen ? +-> eigene selbst zu definierende Attribute +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# | +# Sachgebiete| +# | +# | +# | +# | +# | +# | +# | +# | + +# 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 +? ab hier scheint das Lexikon zu starten, aber was bedeuten die 32 32 ... +Funktionstastenbelegungen + +# 1 0 255 255 255 255 255 255 0 0 1 Abbildung||||mapping||||||||||||||||||||||||||||||||||||||||||||||||||||||| +||||| +# 1 0 255 255 255 255 255 255 0 0 1 Abblendkappe||||anti-dazzle device|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| + +Mein Tip fr Dich: Verwende das Lexikon ITALIAN.LEX von mir. Dort findest +Du die meisten Funktionen verwendet und vielleicht wird fr Dich vieles +klarer, wenn Du Dich mehr mit der VT-Funktionalitt auseinandersetzt. diff --git a/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPage.cpp b/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPage.cpp new file mode 100644 index 00000000..ce97d871 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPage.cpp @@ -0,0 +1,108 @@ +/*************************************************************************** + + dialog page for adjectives (comparison) + + ----------------------------------------------------------------------- + + begin : Sat Dec 4 18:09:29 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "AdjEntryPage.h" +#include "EntryDlg.h" + +#include <langset.h> + +#include <qlineedit.h> + + +AdjEntryPage::AdjEntryPage(EntryDlg *_dlgbook, bool multi_sel, const Comparison &comp, QWidget *parent, const char *name) + : AdjEntryPageForm( parent, name ), dlgbook(_dlgbook) +{ + comparisons = comp; + + connect( lev1Field, SIGNAL(textChanged(const QString&)), SLOT(lev1Changed(const QString&)) ); + connect( lev2Field, SIGNAL(textChanged(const QString&)), SLOT(lev2Changed(const QString&)) ); + connect( lev3Field, SIGNAL(textChanged(const QString&)), SLOT(lev3Changed(const QString&)) ); + + setData(multi_sel, comp); +} + + +void AdjEntryPage::setData(bool multi_sel, const Comparison &comp) +{ + if (multi_sel) { + lev1Field->setEnabled(false); + lev2Field->setEnabled(false); + lev3Field->setEnabled(false); + } + else { + lev1Field->setText (comp.l1()); + lev2Field->setText (comp.l2()); + lev3Field->setText (comp.l3()); + } + setModified(false); +} + + +void AdjEntryPage::lev1Changed(const QString& s) +{ + setModified(true); + comparisons.setL1 (s); +} + + +void AdjEntryPage::lev2Changed(const QString& s) +{ + setModified(true); + comparisons.setL2 (s); +} + + +void AdjEntryPage::lev3Changed(const QString& s) +{ + setModified(true); + comparisons.setL3 (s); +} + + +bool AdjEntryPage::isModified() +{ + return modified; +} + + +void AdjEntryPage::setEnabled(int enable) +{ + bool ena = enable == EntryDlg::EnableAll; + + lev1Field->setEnabled (ena); + lev2Field->setEnabled (ena); + lev3Field->setEnabled (ena); +} + + +void AdjEntryPage::setModified(bool mod) +{ + modified = mod; + if (mod) + emit sigModified(); +} + +#include "AdjEntryPage.moc" diff --git a/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPage.h b/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPage.h new file mode 100644 index 00000000..095e22d7 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPage.h @@ -0,0 +1,63 @@ +/*************************************************************************** + + dialog page for adjectives (comparison) + + ----------------------------------------------------------------------- + + begin : Sat Dec 4 18:09:29 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 AdjEntryPage_included +#define AdjEntryPage_included + +#include "AdjEntryPageForm.h" + +#include <grammarmanager.h> + +class EntryDlg; + +class AdjEntryPage : public AdjEntryPageForm +{ + Q_OBJECT + +public: + AdjEntryPage(EntryDlg *_dlgbook, bool multi_sel, const Comparison &comp, QWidget *parent = NULL, const char *name = NULL); + + void setData (bool multi_sel, const Comparison &comp); + + Comparison getComparison() const { return comparisons; } + + bool isModified(); + void setModified(bool mod = true); + void setEnabled(int enable_type); + +signals: + void sigModified(); + +protected slots: + void lev1Changed(const QString&); + void lev2Changed(const QString&); + void lev3Changed(const QString&); + +protected: + Comparison comparisons; + bool modified; + EntryDlg *dlgbook; +}; +#endif // AdjEntryPage_included diff --git a/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPageForm.ui b/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPageForm.ui new file mode 100644 index 00000000..a2213edb --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/AdjEntryPageForm.ui @@ -0,0 +1,146 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>AdjEntryPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>AdjEntryPageForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>576</width> + <height>129</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>GroupBox1</cstring> + </property> + <property name="title"> + <string>Comparison of Adjectives</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>lev1Label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &1:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>lev1Field</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>lev2Label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &2:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>lev2Field</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>lev3Label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Level &3:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>lev3Field</cstring> + </property> + </widget> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>lev1Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>lev2Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>lev3Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPage.cpp b/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPage.cpp new file mode 100644 index 00000000..b7c1837e --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPage.cpp @@ -0,0 +1,192 @@ +/*************************************************************************** + + edit "additional" properties + + ----------------------------------------------------------------------- + + begin : Thu Nov 25 17:29:44 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qmultilineedit.h> + +#include "AuxInfoEntryPage.h" +#include "EntryDlg.h" + +#include <langset.h> + +#include <LineList.h> + +AuxInfoEntryPage::AuxInfoEntryPage +( + EntryDlg *_dlgbook, + bool multi_sel, + QString syno, + QString anto, + QString exam, + QString rem, + QString para, + QWidget *parent, + const char *name +) + : AuxInfoEntryPageForm( parent, name ), dlgbook(_dlgbook) + +{ + QFontMetrics fm (synonym_line->font()); + int sz = fm.lineSpacing(); + + synonym_line->setMaximumHeight(sz*3); + antonym_line->setMaximumHeight(sz*3); + para_line->setMaximumHeight(sz*3); + remark_line->setMaximumHeight(sz*3); + examp_line->setMaximumHeight(sz*3); + + connect( para_line, SIGNAL(textChanged()), SLOT(slotParaSelected()) ); + connect( remark_line, SIGNAL(textChanged()), SLOT(slotRemarkSelected()) ); + connect( examp_line, SIGNAL(textChanged()), SLOT(slotExampSelected()) ); + connect( antonym_line, SIGNAL(textChanged()), SLOT(slotAntonymSelected()) ); + connect( synonym_line, SIGNAL(textChanged()), SLOT(slotSynonymSelected()) ); + + setData(multi_sel, syno, anto, exam, rem, para); +} + + +void AuxInfoEntryPage::setData(bool multi_sel, QString syno, QString anto, QString example, QString remark, QString para) +{ + synonym_line->setText(syno); + antonym_line->setText(anto); + examp_line->setText(example); + remark_line->setText(remark); + para_line->setText(para); + + if (multi_sel) { + synonym_line ->setEnabled(false); + antonym_line ->setEnabled(false); + remark_line ->setEnabled(false); + examp_line ->setEnabled(false); + para_line ->setEnabled(false); + } + + setModified(false); +} + + +void AuxInfoEntryPage::slotSynonymSelected() +{ + setModified(true); + synonym = synonym_line->text(); +} + + +void AuxInfoEntryPage::slotAntonymSelected() +{ + setModified(true); + antonym = antonym_line->text(); +} + + +void AuxInfoEntryPage::slotRemarkSelected () +{ + setModified(true); + remark = remark_line->text(); +} + + +void AuxInfoEntryPage::slotExampSelected () +{ + setModified(true); + example = examp_line->text(); +} + + +void AuxInfoEntryPage::slotParaSelected () +{ + setModified(true); + paraphrase = para_line->text(); +} + + +QString AuxInfoEntryPage::getSynonym () +{ + normalize(synonym); + return synonym; +} + + +QString AuxInfoEntryPage::getAntonym () +{ + normalize(antonym); + return antonym; +} + + +QString AuxInfoEntryPage::getExample () +{ + normalize(example); + return example; +} + + +QString AuxInfoEntryPage::getRemark () +{ + normalize(remark); + return remark; +} + + +QString AuxInfoEntryPage::getParaphrase () +{ + normalize(paraphrase); + return paraphrase; +} + + +void AuxInfoEntryPage::normalize (QString &str) +{ + LineList ll (str); + ll.normalizeWS(); + str = ll.allLines(); +} + + +bool AuxInfoEntryPage::isModified() +{ + return modified; +} + + +void AuxInfoEntryPage::setEnabled(int enable) +{ + bool ena = enable == EntryDlg::EnableAll; + + synonym_line->setEnabled (ena); + antonym_line->setEnabled (ena); + para_line->setEnabled (ena); + remark_line->setEnabled (ena); + examp_line->setEnabled (ena); +} + + +void AuxInfoEntryPage::setModified(bool mod) +{ + modified = mod; + if (mod) + emit sigModified(); +} + +#include "AuxInfoEntryPage.moc" diff --git a/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPage.h b/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPage.h new file mode 100644 index 00000000..c9e78bf3 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPage.h @@ -0,0 +1,86 @@ +/*************************************************************************** + + edit "additional" properties + + ----------------------------------------------------------------------- + + begin : Thu Nov 25 17:29:44 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 AuxInfoEntryPage_included +#define AuxInfoEntryPage_included + +#include "AuxInfoEntryPageForm.h" + +class EntryDlg; + +class AuxInfoEntryPage : public AuxInfoEntryPageForm +{ + Q_OBJECT + +public: + AuxInfoEntryPage + ( + EntryDlg *dlgbook, + bool multi_sel, + QString syno, + QString anto, + QString example, + QString remark, + QString para, + QWidget *parent = 0, + const char *name = 0 + ); + + void setData(bool multi_sel, QString syno, QString anto, QString example, QString remark, QString para); + + QString getSynonym (); + QString getAntonym (); + QString getExample (); + QString getRemark (); + QString getParaphrase(); + + bool isModified(); + void setModified(bool mod = true); + void setEnabled(int enable_type); + +signals: + void sigModified(); + +protected: + void normalize(QString &str); + +protected slots: + void slotAntonymSelected(); + void slotSynonymSelected(); + void slotExampSelected(); + void slotRemarkSelected(); + void slotParaSelected(); + +protected: + QString synonym; + QString antonym; + QString example; + QString remark; + QString paraphrase; + bool modified; + EntryDlg *dlgbook; +}; + +#endif // AuxInfoEntryPage_included diff --git a/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPageForm.ui b/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPageForm.ui new file mode 100644 index 00000000..632973bc --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/AuxInfoEntryPageForm.ui @@ -0,0 +1,229 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>AuxInfoEntryPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>AuxInfoEntryPageForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>576</width> + <height>494</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>-</string> + </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="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>GroupBox1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Additional Properties</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QMultiLineEdit" row="2" column="1"> + <property name="name"> + <cstring>examp_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>80</height> + </size> + </property> + </widget> + <widget class="QMultiLineEdit" row="3" column="1"> + <property name="name"> + <cstring>remark_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>80</height> + </size> + </property> + </widget> + <widget class="QMultiLineEdit" row="4" column="1"> + <property name="name"> + <cstring>para_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>80</height> + </size> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>synonym_label</cstring> + </property> + <property name="text"> + <string>S&ynonyms:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>synonym_line</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>antonym_label</cstring> + </property> + <property name="text"> + <string>Ant&onyms:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>antonym_line</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>examp_label</cstring> + </property> + <property name="text"> + <string>E&xample:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>examp_line</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>remark_label</cstring> + </property> + <property name="text"> + <string>&Remark:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>remark_line</cstring> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>para_label</cstring> + </property> + <property name="text"> + <string>&Paraphrase:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>para_line</cstring> + </property> + </widget> + <widget class="QMultiLineEdit" row="0" column="1"> + <property name="name"> + <cstring>synonym_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>80</height> + </size> + </property> + <property name="cursor"> + <cursor>0</cursor> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QMultiLineEdit" row="1" column="1"> + <property name="name"> + <cstring>antonym_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>80</height> + </size> + </property> + </widget> + </grid> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>synonym_line</tabstop> + <tabstop>antonym_line</tabstop> + <tabstop>examp_line</tabstop> + <tabstop>remark_line</tabstop> + <tabstop>para_line</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPage.cpp b/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPage.cpp new file mode 100644 index 00000000..9f5bc8b6 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPage.cpp @@ -0,0 +1,444 @@ +/*************************************************************************** + + edit common properties + + ----------------------------------------------------------------------- + + begin : Mon Jun 28 21:02:16 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "CommonEntryPage.h" +#include "EntryDlg.h" + +#include <qlineedit.h> +#include <qlabel.h> +#include <qlistbox.h> +#include <qcombobox.h> +#include <qcheckbox.h> +#include <qgroupbox.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kiconloader.h> +#include <kdialogbase.h> + +#include <QueryManager.h> +#include <langset.h> + +#include "DocPropDlg.h" +#include "blockall.h" +#include "PhoneticEntryPage.h" + + +CommonEntryPage::CommonEntryPage +( + EntryDlg *_dlgbook, + kvoctrainDoc *_doc, + bool multi_sel, + QString expr, + int less, + QComboBox *lessbox, + QString lang, + QString act_type, + QString pron, + QString act_usage, + QString label, + QueryManager &_querymanager, + bool active, + const QFont& _ipafont, + QWidget *parent, + const char *name +) + : + CommonEntryPageForm( parent, name ), + pronunce(pron), + expression(expr), + usageCollection (act_usage), + lesson(less), + type (act_type), + dlgbook(_dlgbook), + doc(_doc), + querymanager(_querymanager), + entry_active(active), + ipafont(_ipafont) +{ + + connect( b_usageDlg, SIGNAL(clicked()), SLOT(invokeUsageDlg()) ); + connect( b_LessDlg, SIGNAL(clicked()), SLOT(invokeLessDlg()) ); + connect( b_pronDlg, SIGNAL(clicked()), SLOT(invokePronDlg()) ); + connect( b_TypeDlg, SIGNAL(clicked()), SLOT(invokeTypeDlg()) ); + connect( usage_box, SIGNAL(selectionChanged()), SLOT(slotUsageChanged()) ); + connect( lesson_box, SIGNAL(activated(int)), SLOT(slotLessonSelected(int)) ); + connect( subtype_box, SIGNAL(activated(int)), SLOT(slotSubTypeSelected(int)) ); + connect( type_box, SIGNAL(activated(int)), SLOT(slotTypeSelected(int)) ); + connect( c_active, SIGNAL(toggled(bool)), SLOT(slotActiveChanged(bool)) ); + + connect( pronunce_line, SIGNAL(textChanged(const QString&)), SLOT(slotPronunceSelected(const QString&)) ); + connect( expr_line, SIGNAL(textChanged(const QString&)), SLOT(slotExprSelected(const QString&)) ); + + usage_label->setTitle(i18n("Usage (area) of an Expression", "&Usage Labels")); + pronunce_line->setFont(ipafont); + + lesson_box->setValidator (new BlockAllValidator() ); + type_box->setValidator (new BlockAllValidator() ); + subtype_box->setValidator (new BlockAllValidator() ); + + QPixmap list_pm = SmallIcon("view_text"); + b_LessDlg->setPixmap(list_pm); + b_TypeDlg->setPixmap(list_pm); + b_usageDlg->setPixmap(list_pm); + + QPixmap pron_pm = SmallIcon("view_icon"); + b_pronDlg->setPixmap(pron_pm); + + setData(multi_sel, expr, less, lessbox, lang, type, pronunce, act_usage, label, querymanager, active); +} + + +void CommonEntryPage::setData( + bool multi_sel, + QString expr, + int less, + QComboBox *lessBox, + QString /*lang*/, + QString type, + QString pronunce, + QString usage, + QString /*label*/, + QueryManager &/*querymanager*/, + bool active) +{ + setLessonBox (lessBox, less); + setUsageBox (usage); + + //expr_label->setText( label ); + expr_line->setText(expr); + + setTypeBox(type); + pronunce_line->setText(pronunce); + c_active->setChecked(active); + + int start = -1; + int i = 0; + while (start < 0 && i < (int) all_types.size()) { + if (all_types [i].shortStr() == QueryManager::getMainType(type)) + start = i; + i++; + } + int offset = -1; + while (offset < 0 && i < (int) all_types.size()) { + if (all_types [i].shortStr() == type) + offset = i - start; + i++; + } + if (offset >= 0) { + slotSubTypeSelected(offset); + subtype_box->setCurrentItem(offset); + } + + if (multi_sel) { + expr_line->setEnabled (false); + pronunce_line->setEnabled (false); + expr_line->setText (""); + pronunce_line->setText (""); + lesson_box->clearEdit(); + type_box->clearEdit(); + subtype_box->clearEdit(); + } + + lesson_dirty = false; + type_dirty = false; + usage_dirty = false; + active_dirty = false; + + setModified(false); +} + + +void CommonEntryPage::setTypeBox(const QString &act_type) +{ + all_types = QueryManager::getRelation(false); + all_maintypes = QueryManager::getRelation(true); + + QString s = QueryManager::getMainType(act_type)+QM_TYPE_DIV; + int curr_type = 0; + type_box->clear(); + type_box->insertItem (i18n("<none>")); + for (int i = 0; i < (int) all_maintypes.size(); i++) { + type_box->insertItem (all_maintypes[i].longStr()); + if (s == all_maintypes[i].shortStr()+QM_TYPE_DIV) + curr_type = i+1; + } + type_box->setCurrentItem(curr_type); + slotTypeSelected(curr_type); +} + + +void CommonEntryPage::setLessonBox(QComboBox *lessbox, int lesson) +{ + lesson_box->clear(); + for (int i = 0; i < lessbox->count(); i++) + lesson_box->insertItem (lessbox->text(i)); + if (lesson >= lesson_box->count() ) + lesson = 0; + lesson_box->setCurrentItem(lesson); +} + + +void CommonEntryPage::setUsageBox(const QString & act_usage) +{ + usages = UsageManager::getRelation(); + usage_box->clear(); + for (int i = 0; i < (int) usages.size(); i++) { + usage_box->insertItem (usages[i].longStr()); + if (UsageManager::contains(QString(usages[i].identStr()), act_usage)) { + usage_box->setSelected (i, true); + } + } + slotUsageChanged(); +} + + +void CommonEntryPage::slotUsageChanged() +{ + setModified(true); + usageCollection = ""; + usage_dirty = true; + QString s; + for (int i = 0; i < (int) usage_box->count(); i++) { + if (usage_box->isSelected(i)) { + + if (!usageCollection.isEmpty() ) + usageCollection += UL_USAGE_DIV; + usageCollection += usages[i].identStr(); + + if (!s.isEmpty() ) + s += ", "; + s += usages[i].shortStr(); + } + } + usage_line->setText (s); +} + + +void CommonEntryPage::slotLessonSelected (int l) +{ + setModified(true); + lesson = l; + lesson_dirty = true; +} + + +void CommonEntryPage::slotActiveChanged(bool state) +{ + setModified(true); + entry_active = state; + active_dirty = true; +} + + +void CommonEntryPage::slotExprSelected (const QString& s) +{ + setModified(true); + expression = s; +} + + +void CommonEntryPage::slotPronunceSelected (const QString& s) +{ + setModified(true); + pronunce = s; +} + + +void CommonEntryPage::slotSubTypeSelected(int i) +{ + setModified(true); + if (i < (int) current_subtypes.size()) { + type = current_subtypes[i]; + emit typeSelected(type); + type_dirty = true; + } +} + + +void CommonEntryPage::slotTypeSelected(int idx) +{ + setModified(true); + subtype_box->clear(); + current_subtypes.clear(); + bool first = true; + + if (idx == 0) { // 0 == none ! + type = ""; + emit typeSelected(type); + } + else { + type = all_maintypes[idx-1].shortStr(); + emit typeSelected(type); + QString main_patt = all_maintypes[idx-1].shortStr()+QM_TYPE_DIV; + int sub_idx; + if ( idx-1 < (int) all_types.size() ){ + for (sub_idx = 0; sub_idx < (int) all_types.size(); sub_idx++) { + if (all_types[sub_idx].shortStr().left(main_patt.length()) == main_patt) { + if (first) { + subtype_box->insertItem (i18n("<none>")); + current_subtypes.push_back(all_maintypes[idx-1].shortStr()); + first = false; + } + QString s = all_types[sub_idx].longStr(); + subtype_box->insertItem (s.stripWhiteSpace()); + current_subtypes.push_back(all_types[sub_idx].shortStr()); + } + } + } + } + type_dirty = true; + + subtype_box->setEnabled(!first); + subtype_label->setEnabled(!first); +} + + +void CommonEntryPage::phoneticSelected(wchar_t wc) +{ + setModified(true); + pronunce += QChar(wc); + pronunce_line->setText(pronunce); +} + + +void CommonEntryPage::invokePronDlg() +{ + //if (phoneticDlg == 0) { + PhoneticEntryPage * phoneticDlg = new PhoneticEntryPage (ipafont, this); + connect (phoneticDlg, SIGNAL(charSelected(wchar_t)), SLOT(phoneticSelected(wchar_t)) ); + phoneticDlg->show(); + //} + //else + //phoneticDlg->show(); +} + + +void CommonEntryPage::invokeUsageDlg() +{ + vector<int> usageIndex; + vector<QString> new_usageStr; + + int old_usages = (int) doc->getUsageDescr().size(); + + KDialogBase usageOpt(KDialogBase::Swallow, i18n("usage (area) of an expression", "Edit User-Defined Usage Labels"), + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, dlgbook, "usage", true); + + UsageOptPage *usageOptPage = new UsageOptPage (doc->getUsageDescr(), doc, this, "name"); + usageOpt.setMainWidget(usageOptPage); + + if (usageOpt.exec() == QDialog::Accepted) + { + usageOptPage->getUsageLabels(new_usageStr, usageIndex); + UsageOptPage::cleanUnused(doc, usageIndex, old_usages); + UsageManager::setUsageNames (new_usageStr); + setUsageBox(usageCollection); + doc->setUsageDescr (new_usageStr); + doc->setModified(); + } +} + + +void CommonEntryPage::invokeLessDlg() +{ + vector<int> lessonIndex; + vector<QString> new_lessonStr; + + int old_lessons = (int) lesson_box->count(); + KDialogBase lessOpt(KDialogBase::Swallow, i18n("Edit Lesson Names"), + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, dlgbook, "lesson", true); + + LessOptPage *lessOptPage = new LessOptPage (lesson_box, doc, this, "name"); + lessOpt.setMainWidget(lessOptPage); + + vector<int> lessoninquery = doc->getLessonsInQuery(); + if (lessOpt.exec() == QDialog::Accepted) + { + lessOptPage->getLesson(lesson_box, lessonIndex); + LessOptPage::cleanUnused(doc, lesson_box, lessonIndex, old_lessons, lessoninquery); + for (int i = 1; i < lesson_box->count(); i++) + new_lessonStr.push_back(lesson_box->text(i)); + doc->setLessonDescr (new_lessonStr); + doc->setLessonsInQuery(lessoninquery); + querymanager.setLessonItems(lessoninquery); + doc->setModified(); + } +} + + +void CommonEntryPage::invokeTypeDlg() +{ + vector<int> typeIndex; + vector<QString> new_typeStr; + + int old_types = (int) doc->getTypeDescr().size(); + KDialogBase typeOpt(KDialogBase::Swallow, i18n("Edit User Defined Types"), + KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, dlgbook, "types", true); + + TypeOptPage *typeOptPage = new TypeOptPage (doc->getTypeDescr(), doc, this, "name"); + typeOpt.setMainWidget(typeOptPage); + + if (typeOpt.exec() == QDialog::Accepted) + { + typeOptPage->getTypeNames(new_typeStr, typeIndex); + TypeOptPage::cleanUnused(doc, typeIndex, old_types); + QueryManager::setTypeNames (new_typeStr); + setTypeBox(type); + doc->setTypeDescr (new_typeStr); + doc->setModified(); + } +} + + +bool CommonEntryPage::isModified() +{ + return modified; +} + + +void CommonEntryPage::setEnabled(int enable) +{ + bool ena = enable == EntryDlg::EnableAll; + + usage_box->setEnabled(ena); + subtype_box->setEnabled(ena); + type_box->setEnabled(ena); + pronunce_line->setEnabled(ena); + expr_line->setEnabled(ena); + + lesson_box->setEnabled(ena || enable == EntryDlg::EnableOnlyCommon); + c_active->setEnabled(ena || enable == EntryDlg::EnableOnlyCommon); +} + + +void CommonEntryPage::setModified(bool mod) +{ + modified = mod; + if (mod) + emit sigModified(); +} + +#include "CommonEntryPage.moc" diff --git a/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPage.h b/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPage.h new file mode 100644 index 00000000..71bbd84a --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPage.h @@ -0,0 +1,140 @@ +/*************************************************************************** + + edit common properties + + ----------------------------------------------------------------------- + + begin : Mon Jun 28 21:02:16 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 CommonEntryPage_included +#define CommonEntryPage_included + +#include "CommonEntryPageForm.h" + +#include <QueryManager.h> +#include <UsageManager.h> + +class PhoneticEntryPage; +class EntryDlg; + +class CommonEntryPage : public CommonEntryPageForm +{ + Q_OBJECT + +public: + CommonEntryPage + ( + EntryDlg *dlgbook, + kvoctrainDoc *doc, + bool multi_sel, + QString expr, + int less, + QComboBox *lessBox, + QString lang, + QString type, + QString pronunce, + QString usage, + QString label, + QueryManager &querymanager, + bool active, + const QFont& ipafont, + QWidget* parent = NULL, + const char* name = NULL + ); + + void setData( + bool multi_sel, + QString expr, + int less, + QComboBox *lessBox, + QString lang, + QString type, + QString pronunce, + QString usage, + QString label, + QueryManager &querymanager, + bool active); + + bool isDirty() const; + bool lessonDirty () const { return lesson_dirty; } + bool activeDirty () const { return active_dirty; } + bool typeDirty () const { return type_dirty; } + bool usageDirty () const { return usage_dirty; } + + int getLesson () const { return lesson; } + QString getType () const { return type; } + QString getExpr () const { return expression; } + QString getPronunce () const { return pronunce; } + QString getUsageLabel() const { return usageCollection; } + bool getActive () const { return entry_active; } + + bool isModified(); + void setModified(bool mod = true); + void setEnabled(int enable_type); + +signals: + void typeSelected(const QString &); + +protected: + void setTypeBox(const QString &act_type); + void setLessonBox(QComboBox *lessbox, int lesson); + void setUsageBox(const QString & act_type); + +protected slots: + void slotLessonSelected(int); + void slotExprSelected(const QString&); + void slotTypeSelected(int); + void slotSubTypeSelected(int); + void slotPronunceSelected (const QString&); + void slotUsageChanged(); + void slotActiveChanged(bool state); + void phoneticSelected(wchar_t); + void invokeLessDlg(); + void invokeTypeDlg(); + void invokePronDlg(); + void invokeUsageDlg(); + +signals: + void sigModified(); + +protected: + QString pronunce; + QString expression; + QString usageCollection; + int lesson; + QString type; + EntryDlg *dlgbook; + bool lesson_dirty; + bool type_dirty; + kvoctrainDoc *doc; + QueryManager &querymanager; + bool entry_active; + bool active_dirty; + bool usage_dirty; + + vector<TypeRelation> all_maintypes; + vector<TypeRelation> all_types; + vector<UsageRelation> usages; + vector<QString> current_subtypes; + + QFont ipafont; + bool modified; +}; +#endif // CommonEntryPage_included diff --git a/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPageForm.ui b/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPageForm.ui new file mode 100644 index 00000000..5e67f8a4 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/CommonEntryPageForm.ui @@ -0,0 +1,479 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>CommonEntryPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>CommonEntryPageForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>516</width> + <height>364</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>-</string> + </property> + <property name="toolTip" stdset="0"> + <string>Invokes lesson input dialog</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>asdf</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Common Properties</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="QFrame"> + <property name="name"> + <cstring>Frame4</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>expr_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>pronunce_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QComboBox" row="1" column="1"> + <property name="name"> + <cstring>lesson_box</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>expr_label</cstring> + </property> + <property name="text"> + <string>&Expression:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>expr_line</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>pronunce_label</cstring> + </property> + <property name="text"> + <string>&Pronunciation:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>pronunce_line</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>lesson_label</cstring> + </property> + <property name="text"> + <string>&Lesson:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>lesson_box</cstring> + </property> + </widget> + <widget class="QPushButton" row="1" column="2"> + <property name="name"> + <cstring>b_LessDlg</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>30</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>30</width> + <height>30</height> + </size> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="toolTip" stdset="0"> + <string>Invokes input dialog for lessons</string> + </property> + </widget> + <widget class="QPushButton" row="2" column="2"> + <property name="name"> + <cstring>b_pronDlg</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>30</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>30</width> + <height>30</height> + </size> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="toolTip" stdset="0"> + <string>Invokes dialog page with characters from phonetic alphabet</string> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>type_label</cstring> + </property> + <property name="title"> + <string>T&ype</string> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QComboBox"> + <property name="name"> + <cstring>type_box</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Minimum</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel"> + <property name="name"> + <cstring>subtype_label</cstring> + </property> + <property name="text"> + <string>&Subtype:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>subtype_box</cstring> + </property> + </widget> + <widget class="QComboBox"> + <property name="name"> + <cstring>subtype_box</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>b_TypeDlg</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>30</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>30</width> + <height>30</height> + </size> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="toolTip" stdset="0"> + <string>Invokes input dialog for word types</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>usage_label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>-</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton" row="0" column="2"> + <property name="name"> + <cstring>b_usageDlg</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>30</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>30</width> + <height>24</height> + </size> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="toolTip" stdset="0"> + <string>Invokes input dialog for usage labels</string> + </property> + </widget> + <spacer row="1" column="2"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Preferred</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QListBox" row="0" column="0" rowspan="2" colspan="1"> + <property name="name"> + <cstring>usage_box</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>32767</width> + <height>90</height> + </size> + </property> + <property name="selectionMode"> + <enum>Multi</enum> + </property> + </widget> + <widget class="QLabel" row="0" column="1" rowspan="2" colspan="1"> + <property name="name"> + <cstring>usage_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>80</height> + </size> + </property> + <property name="frameShape"> + <enum>WinPanel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="alignment"> + <set>WordBreak|AlignTop|AlignLeft</set> + </property> + <property name="vAlign" stdset="0"> + </property> + <property name="wordwrap" stdset="0"> + </property> + </widget> + </grid> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>c_active</cstring> + </property> + <property name="text"> + <string>Acti&ve</string> + </property> + </widget> + </vbox> + </widget> + </vbox> +</widget> +<tabstops> + <tabstop>expr_line</tabstop> + <tabstop>lesson_box</tabstop> + <tabstop>b_LessDlg</tabstop> + <tabstop>pronunce_line</tabstop> + <tabstop>b_pronDlg</tabstop> + <tabstop>type_box</tabstop> + <tabstop>subtype_box</tabstop> + <tabstop>b_TypeDlg</tabstop> + <tabstop>usage_box</tabstop> + <tabstop>b_usageDlg</tabstop> + <tabstop>c_active</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/entry-dialogs/EntryDlg.cpp b/kvoctrain/kvoctrain/entry-dialogs/EntryDlg.cpp new file mode 100644 index 00000000..2d60ddb1 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/EntryDlg.cpp @@ -0,0 +1,467 @@ +/*************************************************************************** + + entry dialog for table cell contents + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "EntryDlg.h" + +#include <qlayout.h> +#include <qlineedit.h> + +#include <kmainwindow.h> +#include <kapplication.h> +#include <kwinmodule.h> + +#include <langset.h> +#include <klocale.h> + +EntryDlg::EntryDlg( + KMainWindow *main, + kvoctrainDoc *doc, + bool multi_sel, + bool origin, + grade_t f_grd, + grade_t t_grd, + count_t f_qcount, + count_t t_qcount, + count_t f_bcount, + count_t t_bcount, + time_t f_qdate, + time_t t_qdate, + QString f_faux_ami, + QString t_faux_ami, + QString expr, + int lesson, + QComboBox *lessonbox, + QString lang, + LangSet &langset, + QString rem, + QString type, + QString pronunce, + QString synonym, + QString antonym, + QString example, + QString usagelabel, + QString paraphrase, + const Conjugation &con_prefix, + const Conjugation &conjugations, + const Article &/*article*/, + const Comparison &comp, + const MultipleChoice &mc, + QueryManager &querymanager, + const QString &title, + bool active, + const QFont& ipafont, + QWidget *parent, + const char *name, + bool modal) + : + KDialogBase(Tabbed, title, User1|User2|User3|Apply|Close, Apply, parent, name, modal, false, + KGuiItem(i18n("&Reset")), + KGuiItem(QString::null, "view_left_right"), + KGuiItem(QString::null, "view_top_bottom")) + +{ + mainwin = main; + docked = false; + edit_row = -1; + edit_col = -1; + from_page = 0; + to_page = 0; + + QString s; + if (langset.findLongId(lang).isEmpty() ) + s = lang; + else + s = langset.findLongId(lang); + + QFrame *page; + QVBoxLayout *topLayout; + + if (origin) + { + page = addPage( i18n("Co&mmon") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + comm_page = new CommonEntryPage (this, doc, multi_sel, expr, lesson, lessonbox, + lang, type, pronunce, usagelabel, + i18n("Original &expression in %1:").arg(s), querymanager, active, + ipafont, page, name); + topLayout->addWidget(comm_page); + + page = addPage( i18n("A&dditional") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + aux_page = new AuxInfoEntryPage (this, multi_sel, synonym, antonym, example, rem, paraphrase, page, name); + topLayout->addWidget(aux_page); + + page = addPage( i18n("&Multiple Choice") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + mc_page = new MCEntryPage (this, multi_sel, mc, page, "MultipleChoice"); + topLayout->addWidget(mc_page); + + page = addPage( i18n("Con&jugation") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + tense_page = new TenseEntryPage (this, multi_sel, con_prefix, conjugations, page, "Conjugation"); + topLayout->addWidget(tense_page); + + page = addPage( i18n("Compar&ison") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + adj_page = new AdjEntryPage (this, multi_sel, comp, page, "Comparison"); + topLayout->addWidget(adj_page); + } + else + { + page = addPage( i18n("Co&mmon") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + comm_page = new CommonEntryPage (this, doc, multi_sel, expr, lesson, lessonbox, + lang, type, pronunce, usagelabel, + i18n("Translated &expression in %1:").arg(s), querymanager, active, + ipafont, page, name); + topLayout->addWidget(comm_page); + + page = addPage( i18n("A&dditional") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + aux_page = new AuxInfoEntryPage (this, multi_sel, synonym, antonym, example, rem, paraphrase, page, name); + topLayout->addWidget(aux_page); + + page = addPage( i18n("&Multiple Choice") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + mc_page = new MCEntryPage (this, multi_sel, mc, page, "MultipleChoice"); + topLayout->addWidget(mc_page); + + page = addPage( i18n("Con&jugation") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + tense_page = new TenseEntryPage (this, multi_sel, con_prefix, conjugations, page, "Conjugation"); + topLayout->addWidget(tense_page); + + page = addPage( i18n("Compar&ison") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + adj_page = new AdjEntryPage (this, multi_sel, comp, page, "Comparison"); + topLayout->addWidget(adj_page); + } + + page = addPage( i18n("&From Original") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + from_page = new FromToEntryPage (this, multi_sel, f_grd, f_qdate, f_qcount, f_bcount, + f_faux_ami, + i18n("Properties From Original"), page, name); + topLayout->addWidget(from_page); + + page = addPage( i18n("&To Original") ); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + to_page = new FromToEntryPage (this, multi_sel, t_grd, t_qdate, t_qcount, t_bcount, + t_faux_ami, + i18n("Properties to Original"), page, name); + topLayout->addWidget(to_page); + + updatePages (type); + + connect(comm_page, SIGNAL(typeSelected(const QString&)), SLOT(updatePages(const QString&)) ); + + connect( this, SIGNAL(user1Clicked()), this, SLOT(slotUndo()) ); + connect( this, SIGNAL(applyClicked()), this, SLOT(slotApply()) ); + connect( this, SIGNAL(user2Clicked()), this, SLOT(slotDockVertical()) ); + connect( this, SIGNAL(user3Clicked()), this, SLOT(slotDockHorizontal()) ); + + connect (comm_page, SIGNAL(sigModified()), this, SLOT(slotDisplayModified() )); + connect (aux_page, SIGNAL(sigModified()), this, SLOT(slotDisplayModified() )); + connect (adj_page, SIGNAL(sigModified()), this, SLOT(slotDisplayModified() )); + connect (mc_page, SIGNAL(sigModified()), this, SLOT(slotDisplayModified() )); + connect (tense_page, SIGNAL(sigModified()), this, SLOT(slotDisplayModified() )); + + if (from_page != 0) + connect (from_page, SIGNAL(sigModified()), this, SLOT(slotDisplayModified() )); + if (to_page != 0) + connect (to_page, SIGNAL(sigModified()), this, SLOT(slotDisplayModified() )); + + enableButtonApply(false); + enableButton(User1, false); + comm_page->expr_line->setFocus(); +} + + +void EntryDlg::setData( + kvoctrainDoc */*doc*/, + bool multi_sel, + bool origin, + grade_t f_grd, + grade_t t_grd, + count_t f_qcount, + count_t t_qcount, + count_t f_bcount, + count_t t_bcount, + time_t f_qdate, + time_t t_qdate, + QString f_faux_ami, + QString t_faux_ami, + QString expr, + int lesson, + QComboBox *lessonbox, + QString lang, + LangSet &langset, + QString rem, + QString type, + QString pronunce, + QString synonym, + QString antonym, + QString example, + QString usagelabel, + QString paraphrase, + const Conjugation &/*con_prefix*/, + const Conjugation &conjugations, + const Article &/*article*/, + const Comparison &comp, + const MultipleChoice &mc, + QueryManager &querymanager, + const QString &title, + bool active) +{ + setCaption (kapp->makeStdCaption(title)); + + QString s; + if (langset.findLongId(lang).isEmpty() ) + s = lang; + else + s = langset.findLongId(lang); + + if (origin) + comm_page->setData(multi_sel, expr, lesson, lessonbox, lang, type, pronunce, usagelabel, + i18n("Original &expression in %1:").arg(s), querymanager, active); + else + comm_page->setData(multi_sel, expr, lesson, lessonbox, lang, type, pronunce, usagelabel, + i18n("Translated &expression in %1:").arg(s), querymanager, active); + + adj_page->setData(multi_sel, comp); + aux_page->setData(multi_sel, synonym, antonym, example, rem, paraphrase); + mc_page->setData(multi_sel, mc); + tense_page->setData(multi_sel, conjugations); + if (from_page != 0) + from_page->setData(multi_sel, f_grd, f_qdate, f_qcount, f_bcount, f_faux_ami, i18n("Properties From Original")); + if (to_page != 0) + to_page->setData(multi_sel, t_grd, t_qdate, t_qcount, t_bcount, t_faux_ami, i18n("Properties to Original")); + + setModified(false); + updatePages (type); +} + + +void EntryDlg::updatePages(const QString &type) +{ + QString main; + int pos; + if ((pos = type.find (QM_TYPE_DIV)) < 0) // only use main type + main = type; + else + main = type.left(pos); + + if (main == QM_VERB) { + tense_page->setEnabled(EntryDlg::EnableAll); + adj_page->setEnabled(EntryDlg::EnableNone); + } + else if (main == QM_ADJ) { + tense_page->setEnabled(EntryDlg::EnableNone); + adj_page->setEnabled(EntryDlg::EnableAll); + } + else { + tense_page->setEnabled(EntryDlg::EnableNone); + adj_page->setEnabled(EntryDlg::EnableNone); + } +} + + +void EntryDlg::setModified(bool mod) +{ + comm_page->setModified(mod); + aux_page->setModified(mod); + mc_page->setModified(mod); + tense_page->setModified(mod); + mc_page->setModified(mod); + adj_page->setModified(mod); + if (from_page != 0) + from_page->setModified(mod); + if (to_page != 0) + to_page->setModified(mod); + enableButtonApply(false); + enableButton(User1, false); +} + + +void EntryDlg::setEnabled(int enable) +{ + QString type = comm_page->getType(); + QString main; + int pos; + if ((pos = type.find (QM_TYPE_DIV)) < 0) // only use main type + main = type; + else + main = type.left(pos); + + if (enable == EnableOnlyOriginal) + { + comm_page->setEnabled(EnableAll); + aux_page->setEnabled(EnableAll); + mc_page->setEnabled(EnableAll); + tense_page->setEnabled(main == QM_VERB ? EnableAll : EnableNone); + mc_page->setEnabled(EnableAll); + adj_page->setEnabled(main == QM_ADJ ? EnableAll : EnableNone); + if (from_page != 0) + from_page->setEnabled(EnableNone); + if (to_page != 0) + to_page->setEnabled(EnableNone); + } + else + { + comm_page->setEnabled(enable); + aux_page->setEnabled(enable); + mc_page->setEnabled(enable); + tense_page->setEnabled(main == QM_VERB ? enable : EnableNone); + mc_page->setEnabled(enable); + adj_page->setEnabled(main == QM_ADJ ? enable : EnableNone); + if (from_page != 0) + from_page->setEnabled(enable); + if (to_page != 0) + to_page->setEnabled(enable); + } +} + + +void EntryDlg::slotApply() +{ + emit sigEditChoice(EditApply); +} + + +void EntryDlg::slotUndo() +{ + emit sigEditChoice(EditUndo); +} + + +bool EntryDlg::isModified() +{ + bool mod = comm_page->isModified() + || aux_page->isModified() + || tense_page->isModified() + || mc_page->isModified() + || adj_page->isModified(); + + if (from_page != 0) + mod |= from_page->isModified(); + + if (to_page != 0) + mod |= to_page->isModified(); + + return mod; +} + + +void EntryDlg::slotDisplayModified() +{ + enableButtonApply(true); + enableButton(User1, true); +} + + +void EntryDlg::setCell(int row, int col, const vector<QTableSelection>& sel) +{ + edit_row = row; + edit_col = col; + selections = sel; +} + + +void EntryDlg::getCell(int &row, int &col, vector<QTableSelection>& sel) const +{ + row = edit_row; + col = edit_col; + sel = selections; +} + + +void EntryDlg::slotDockVertical() +{ + if (!docked) { + oldMainPos = mainwin->pos(); + oldMainSize = mainwin->size(); + docked = true; + } + + KWinModule info; + QRect rect = info.workArea(); + + int diff_x = frameGeometry().width()-width(); + int diff_y = frameGeometry().height()-height(); + resize(minimumWidth(), rect.height()-diff_y); + mainwin->resize(rect.width()-frameGeometry().width()-diff_x, + rect.height()-diff_y); + move (0, 0); + mainwin->move(frameGeometry().width(), 0); +} + + +void EntryDlg::slotDockHorizontal() +{ + if (!docked) { + oldMainPos = mainwin->pos(); + oldMainSize = mainwin->size(); + docked = true; + } + + KWinModule info; + QRect rect = info.workArea(); + + int diff_x = frameGeometry().width()-width(); + int diff_y = frameGeometry().height()-height(); + + resize(rect.width()-diff_x, minimumHeight()); + mainwin->resize(rect.width()-diff_x, + rect.height()-frameGeometry().height()-diff_y); + move(0, 0); + mainwin->move (0, frameGeometry().height()); +} + + +EntryDlg::~EntryDlg() +{ + if (docked) { + docked = false; + mainwin->resize(oldMainSize); + mainwin->move(oldMainPos); + } +} + + +void EntryDlg::reject () +{ + emit sigEditChoice(EditCancel); +} + + +void EntryDlg::closeEvent (QCloseEvent * /*e*/) +{ + emit sigEditChoice(EditCancel); +} + + +#include "EntryDlg.moc" + diff --git a/kvoctrain/kvoctrain/entry-dialogs/EntryDlg.h b/kvoctrain/kvoctrain/entry-dialogs/EntryDlg.h new file mode 100644 index 00000000..f349ccfc --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/EntryDlg.h @@ -0,0 +1,222 @@ +/*************************************************************************** + + entry dialog for table cell contents + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 EntryDlg_included +#define EntryDlg_included + +#include <qtable.h> + +#include <kdialogbase.h> + +#include "FromToEntryPage.h" +#include "CommonEntryPage.h" +#include "AuxInfoEntryPage.h" +#include "TenseEntryPage.h" +#include "AdjEntryPage.h" +#include "MCEntryPage.h" + +class LangSet; +class QTabWidget; +class KMainWindow; +class kvoctrainDoc; + +class EntryDlg : public KDialogBase +{ + Q_OBJECT + +public: + + enum EditResult {EditCancel, EditApply, EditUndo, EditPageUp, EditPageDown, EditUp, EditDown, EditLeft, EditRight}; + + enum EnableType {EnableAll, EnableOnlyCommon, EnableNone, EnableOnlyOriginal }; + + EntryDlg + ( KMainWindow *main, + kvoctrainDoc *doc, + bool multi_sel, + bool origin, + grade_t f_grd, + grade_t t_grd, + count_t f_qcount, + count_t t_qcount, + count_t f_bcount, + count_t t_bcount, + time_t f_qdate, + time_t t_qdate, + QString f_faux_ami, + QString t_faux_ami, + QString _expr, + int _lesson, + QComboBox *_lessonBox, + QString lang, + LangSet &langset, + QString remark, + QString _type, + QString pronunce, + QString synonym, + QString antonym, + QString example, + QString usagelabel, + QString paraphrase, + const Conjugation &con_prefix, + const Conjugation &conjugations, + const Article &article, + const Comparison &comp, + const MultipleChoice &mc, + QueryManager &querymanager, + const QString &title, + bool active, + const QFont& ipafont, + QWidget *parent = 0, + const char *name = 0, + bool modal = false + ); + + ~EntryDlg (); + + void setData + (kvoctrainDoc *doc, + bool multi_sel, + bool origin, + grade_t f_grd, + grade_t t_grd, + count_t f_qcount, + count_t t_qcount, + count_t f_bcount, + count_t t_bcount, + time_t f_qdate, + time_t t_qdate, + QString f_faux_ami, + QString t_faux_ami, + QString _expr, + int _lesson, + QComboBox *_lessonBox, + QString lang, + LangSet &langset, + QString remark, + QString _type, + QString pronunce, + QString synonym, + QString antonym, + QString example, + QString usagelabel, + QString paraphrase, + const Conjugation &con_prefix, + const Conjugation &conjugations, + const Article &article, + const Comparison &comp, + const MultipleChoice &mc, + QueryManager &querymanager, + const QString &title, + bool active); + + bool fromDateDirty () const { return from_page ? from_page->dateDirty() : false; } + bool fromGradeDirty () const { return from_page ? from_page->gradeDirty() : false; } + bool fromBCountDirty () const { return from_page ? from_page->bCountDirty() : false; } + bool fromQCountDirty () const { return from_page ? from_page->qCountDirty() : false; } + QString getFromFauxAmi () const { return from_page ? from_page->getFauxAmi() : QString(""); } + + time_t getFromDate () const { return from_page ? from_page->getDate() : 0; } + grade_t getFromGrade () const { return from_page ? from_page->getGrade() : KV_NORM_GRADE; } + count_t getFromBCount () const { return from_page ? from_page->getBCount() : 0; } + count_t getFromQCount () const { return from_page ? from_page->getQCount() : 0; } + + bool toDateDirty () const { return to_page ? to_page->dateDirty() : false; } + bool toGradeDirty () const { return to_page ? to_page->gradeDirty() : false; } + bool toBCountDirty () const { return to_page ? to_page->bCountDirty() : false; } + bool toQCountDirty () const { return to_page ? to_page->qCountDirty() : false; } + QString getToFauxAmi () const { return to_page ? to_page->getFauxAmi() : QString(""); } + + time_t getToDate () const { return to_page ? to_page->getDate() : 0; } + grade_t getToGrade () const { return to_page ? to_page->getGrade() : KV_NORM_GRADE; } + count_t getToBCount () const { return to_page ? to_page->getBCount() : 0; } + count_t getToQCount () const { return to_page ? to_page->getQCount() : 0; } + + bool lessonDirty () const { return comm_page->lessonDirty(); } + bool usageDirty () const { return comm_page->usageDirty(); } + bool typeDirty () const { return comm_page->typeDirty (); } + bool activeDirty () const { return comm_page->activeDirty (); } + + int getLesson () const { return comm_page->getLesson(); } + QString getType () const { return comm_page->getType(); } + QString getExpr () const { return comm_page->getExpr(); } + QString getPronunce () const { return comm_page->getPronunce(); } + QString getUsageLabel() const { return comm_page->getUsageLabel(); } + bool getActive() const { return comm_page->getActive(); } + + QString getSynonym () const { return aux_page->getSynonym(); } + QString getAntonym () const { return aux_page->getAntonym(); } + QString getRemark () const { return aux_page->getRemark(); } + QString getExample () const { return aux_page->getExample(); } + QString getParaphrase () const { return aux_page->getParaphrase(); } + + Conjugation getConjugation() const { return tense_page->getConjugation(); } + + Comparison getComparison() const { return adj_page->getComparison(); } + + MultipleChoice getMultipleChoice() const { return mc_page->getMultipleChoice(); } + + bool isModified(); + void setModified(bool mod); + void setEnabled(int); + + void setCell(int row, int col, const vector<QTableSelection>& sel); + void getCell(int &row, int &col, vector<QTableSelection>& sel) const; + +signals: + void sigEditChoice(int); + +public slots: + void slotDisplayModified(); + void slotApply(); + void slotUndo(); + void slotDockHorizontal(); + void slotDockVertical(); + +protected slots: + void updatePages(const QString &type); + virtual void reject (); + +protected: + virtual void closeEvent (QCloseEvent*e); + + FromToEntryPage *from_page, + *to_page; + CommonEntryPage *comm_page; + AuxInfoEntryPage *aux_page; + TenseEntryPage *tense_page; + AdjEntryPage *adj_page; + MCEntryPage *mc_page; + int edit_row, edit_col; + QTabWidget *tabber; + + vector<QTableSelection> selections; + KMainWindow *mainwin; + QSize oldMainSize; + QPoint oldMainPos; + bool docked; +}; + +#endif // EntryDlg_included diff --git a/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPage.cpp b/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPage.cpp new file mode 100644 index 00000000..462cdbf0 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPage.cpp @@ -0,0 +1,395 @@ +/*************************************************************************** + + edit properties from/to original + + ----------------------------------------------------------------------- + + begin : Mon Jun 28 21:02:16 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "FromToEntryPage.h" +#include "EntryDlg.h" + +#include <qlineedit.h> +#include <qcombobox.h> +#include <qpushbutton.h> +#include <qgroupbox.h> + +#include <klocale.h> + +#include <QueryManager.h> +#include <langset.h> + +#include "blockall.h" +#include "MySpinBox.h" + +#include <stdlib.h> + +static QStringList monthnames; + +FromToEntryPage::FromToEntryPage +( + EntryDlg *_dlgbook, + bool multi_sel, + grade_t _grade, + time_t _time, + count_t _qcount, + count_t _bcount, + QString faux, + QString label, + QWidget *parent, + const char *name +) + : + FromToEntryPageForm( parent, name ), fauxami(faux), dlgbook(_dlgbook) +{ + monthnames.clear(); + monthnames.append (""); + monthnames.append (i18n("January")); + monthnames.append (i18n("February")); + monthnames.append (i18n("March")); + monthnames.append (i18n("April")); + monthnames.append (i18n("May")); + monthnames.append (i18n("June")); + monthnames.append (i18n("July")); + monthnames.append (i18n("August")); + monthnames.append (i18n("September")); + monthnames.append (i18n("October")); + monthnames.append (i18n("November")); + monthnames.append (i18n("December")); + + connect( bcount_line, SIGNAL(textChanged(const QString&)), SLOT(slotBCount(const QString&)) ); + connect( qcount_line, SIGNAL(textChanged(const QString&)), SLOT(slotQCount(const QString&)) ); + connect( fauxami_line, SIGNAL(textChanged(const QString&)), SLOT(slotFauxAmiSelected(const QString&)) ); + + connect( never, SIGNAL(clicked()), SLOT(slotNever()) ); + connect( today, SIGNAL(clicked()), SLOT(slotToday()) ); + connect( gradebox, SIGNAL(activated(int)), SLOT(slotGradeSelected(int)) ); + + connect( year_spin, SIGNAL(valueChanged(int)), SLOT(slotYearChanged(int)) ); + connect( month_spin, SIGNAL(valueChanged(int)), SLOT(slotMonthChanged(int)) ); + connect( day_spin, SIGNAL(valueChanged(int)), SLOT(slotDayChanged(int)) ); + + year_spin->setData ((QStringList *) 0, 1980, 2100); + month_spin->setData (&monthnames, 1, 12); + day_spin->setData ((QStringList *) 0, 1, 31); + + QString s; + for (int i = 0; i <= KV_MAX_GRADE; i++) { + s.setNum (i); + gradebox->insertItem( QueryManager::gradeStr(i) ); + } + gradebox->setValidator (new BlockAllValidator() ); + + setTabOrder(fauxami_line, year_spin); + setTabOrder(year_spin, month_spin); + setTabOrder(month_spin, day_spin); + setTabOrder(day_spin, today); + + setData(multi_sel, _grade, _time, _qcount, _bcount, faux, label); +} + + +void FromToEntryPage::setData( + bool multi_sel, + grade_t _grade, + time_t _time, + count_t _qcount, + count_t _bcount, + QString faux, + QString label) +{ + grade = _grade; + qcount = _qcount; + bcount = _bcount; + fauxami = faux; + fauxami_line->setText(fauxami); + + valid_date = false; + QDateTime dt; + QDate date; + if (_time != 0 && !multi_sel) { + dt.setTime_t (_time); + valid_date = true; + + date = dt.date(); + year = date.year(); + month = date.month(); + day = date.day(); + + day_spin->setValue(day); + month_spin->setValue(month); + year_spin->setValue(year); + year_spin->setSpecial(QString::null); + month_spin->setSpecial(QString::null); + day_spin->setSpecial(QString::null); + } + else { + dt.setTime_t (time(0L)); + date = dt.date(); + year = date.year(); + month = date.month(); + day = date.day(); + year_spin->setSpecial("----"); + month_spin->setSpecial("----"); + day_spin->setSpecial("--"); + } + + direc_label->setTitle (label); + + gradebox->setCurrentItem (grade); + + QString s; + s.setNum (qcount); + qcount_line->setText (s); + + s.setNum (bcount); + bcount_line->setText (s); + + if (multi_sel) { + fauxami_line->setEnabled(false); + valid_date = false; + bcount_line->setText (""); + qcount_line->setText (""); + month_spin->setSpecial(" "); + day_spin->setSpecial(" "); + // FIXME: possibly derive new combobox type + // which filters ALL charcters to prevent new input + // in edit field + gradebox->clearEdit(); + } + + bcount_dirty = false; + qcount_dirty = false; + date_dirty = false; + grade_dirty = false; + + setModified(false); +} + + +void FromToEntryPage::slotFauxAmiSelected(const QString& s) +{ + setModified(true); + fauxami = s; +} + + +void FromToEntryPage::slotGradeSelected (int g) +{ + setModified(true); + grade_dirty = true; + grade = g; +} + + +void FromToEntryPage::slotQCount(const QString& s) +{ + setModified(true); + qcount_dirty = true; + qcount = atoi (s.local8Bit()); +} + + +void FromToEntryPage::slotBCount(const QString& s) +{ + setModified(true); + bcount_dirty = true; + bcount = atoi (s.local8Bit()); +} + + +time_t FromToEntryPage::getDate () const +{ + // FIXME: warning dialog/don`t quit dialog when date invalid + if (valid_date) { + QDate act_date (year, month, day); + QDateTime time_null (QDate (1970, 1, 1), QTime (0,0,0)); + return -QDateTime(act_date).secsTo (time_null); + } + else + return 0; +} + + +void FromToEntryPage::validate() +{ + if (!valid_date) { + valid_date = true; + day_spin->setValue(day); + month_spin->setValue(month); + year_spin->setValue(year); + } +} + + +void FromToEntryPage::slotYearChanged(int new_year) +{ + setModified(true); + date_dirty = true; + if (!valid_date) { + slotToday(); + new_year = year; + } + + year_spin->setSpecial(QString::null); + + year = new_year; + validate(); +} + + +void FromToEntryPage::slotDecYear() +{ + setModified(true); +} + + +// FIXME: dec month when day decrease below 1 +void FromToEntryPage::slotIncYear() +{ + setModified(true); +} + + +void FromToEntryPage::slotMonthChanged(int new_month) +{ + setModified(true); + date_dirty = true; + if (!valid_date) { + slotToday(); + new_month = month; + } + + month_spin->setSpecial(QString::null); + + month = new_month; + validate(); +} + + +void FromToEntryPage::slotDecMonth() +{ + setModified(true); +} + + +void FromToEntryPage::slotIncMonth() +{ + setModified(true); +} + + +void FromToEntryPage::slotDayChanged(int new_day) +{ + setModified(true); + date_dirty = true; + if (!valid_date) { + slotToday(); + new_day = day; + } + + day_spin->setSpecial(QString::null); + + day = new_day; + validate(); +} + + +void FromToEntryPage::slotDecDay() +{ + setModified(true); +} + + +void FromToEntryPage::slotIncDay() +{ + setModified(true); +} + + +void FromToEntryPage::slotToday() +{ + setModified(true); + date_dirty = true; + QDateTime dt; + dt.setTime_t (time(0L)); + + year = dt.date().year(); + month = dt.date().month(); + day = dt.date().day(); + + day_spin->setValue(day); + month_spin->setValue(month); + year_spin->setValue(year); + year_spin->setSpecial(QString::null); + month_spin->setSpecial(QString::null); + day_spin->setSpecial(QString::null); + validate(); +} + + +void FromToEntryPage::slotNever() +{ + setModified(true); + date_dirty = true; + year = 0; + month = 0; + day = 0; + year_spin->setSpecial("----"); + month_spin->setSpecial("----"); + day_spin->setSpecial("--"); + valid_date = false; +} + + +bool FromToEntryPage::isModified() +{ + return modified; +} + + +void FromToEntryPage::setEnabled(int enable) +{ + bool ena = enable == EntryDlg::EnableAll; + + bcount_line->setEnabled(ena); + qcount_line->setEnabled(ena); + fauxami_line->setEnabled(ena); + + never->setEnabled(ena); + today->setEnabled(ena); + gradebox->setEnabled(ena); + + year_spin->setEnabled(ena); + month_spin->setEnabled(ena); + day_spin->setEnabled(ena); +} + + +void FromToEntryPage::setModified(bool mod) +{ + modified = mod; + if (mod) + emit sigModified(); +} + +#include "FromToEntryPage.moc" + diff --git a/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPage.h b/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPage.h new file mode 100644 index 00000000..ad322eff --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPage.h @@ -0,0 +1,124 @@ +/*************************************************************************** + + edit properties from/to original + + ----------------------------------------------------------------------- + + begin : Mon Jun 28 21:02:16 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 FromToEntryPage_included +#define FromToEntryPage_included + +#include "FromToEntryPageForm.h" +#include <time.h> +#include <qdatetime.h> + +#include <kvoctraindoc.h> + +class EntryDlg; + +class FromToEntryPage : public FromToEntryPageForm +{ + Q_OBJECT + +public: + + FromToEntryPage + ( + EntryDlg *dlgbook, + bool multi_sel, + grade_t _grade, + time_t _date, + count_t _qcount, + count_t _bcount, + QString faux, + QString label, + QWidget *parent = NULL, + const char *name = NULL + ); + + void setData( + bool multi_sel, + grade_t _grade, + time_t _date, + count_t _qcount, + count_t _bcount, + QString faux, + QString label); + + time_t dateDirty () const { return date_dirty; } + grade_t gradeDirty () const { return grade_dirty; } + count_t qCountDirty () const { return qcount_dirty; } + count_t bCountDirty () const { return bcount_dirty; } + + time_t getDate () const; + grade_t getGrade () const { return grade; } + count_t getQCount () const { return qcount; } + count_t getBCount () const { return bcount; } + + QString getFauxAmi () const { return fauxami; } + + bool isModified(); + void setModified(bool mod = true); + void setEnabled(int enable_type); + +signals: + void sigModified(); + +protected slots: + void slotGradeSelected(int); + void slotQCount(const QString&); + void slotBCount(const QString&); + + void slotIncYear(); + void slotIncMonth(); + void slotIncDay(); + void slotDecYear(); + void slotDecMonth(); + void slotDecDay(); + void slotToday(); + void slotNever(); + void slotFauxAmiSelected(const QString&); + + void slotDayChanged(int); + void slotMonthChanged(int); + void slotYearChanged(int); + +protected: + void validate(); + + QString fauxami; + bool valid_date; + bool date_dirty, + qcount_dirty, + bcount_dirty, + grade_dirty; + grade_t grade; + count_t qcount; + count_t bcount; + int year, + month, + day; + EntryDlg *dlgbook; + bool modified; +}; + +#endif // FromToEntryPage_included diff --git a/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPageForm.ui b/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPageForm.ui new file mode 100644 index 00000000..9fea8f70 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/FromToEntryPageForm.ui @@ -0,0 +1,320 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>FromToEntryPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>FromToEntryPageForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>552</width> + <height>292</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>direc_label</cstring> + </property> + <property name="title"> + <string>Properties From Original</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="QFrame"> + <property name="name"> + <cstring>Frame3</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer row="0" column="2"> + <property name="name"> + <cstring>Spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QComboBox" row="0" column="1"> + <property name="name"> + <cstring>gradebox</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1" rowspan="1" colspan="2"> + <property name="name"> + <cstring>fauxami_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>fauxami_label</cstring> + </property> + <property name="text"> + <string>False fr&iend:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>fauxami_line</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>grade_label</cstring> + </property> + <property name="text"> + <string>&Grade:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>gradebox</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>GroupBox2</cstring> + </property> + <property name="title"> + <string>Last Query &Date</string> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="MySpinBox"> + <property name="name"> + <cstring>year_spin</cstring> + </property> + <property name="minimumSize"> + <size> + <width>60</width> + <height>0</height> + </size> + </property> + </widget> + <widget class="MySpinBox"> + <property name="name"> + <cstring>month_spin</cstring> + </property> + <property name="minimumSize"> + <size> + <width>110</width> + <height>0</height> + </size> + </property> + </widget> + <widget class="MySpinBox"> + <property name="name"> + <cstring>day_spin</cstring> + </property> + <property name="minimumSize"> + <size> + <width>60</width> + <height>0</height> + </size> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>today</cstring> + </property> + <property name="text"> + <string>T&oday</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>never</cstring> + </property> + <property name="text"> + <string>&Never</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>GroupBox3</cstring> + </property> + <property name="title"> + <string>Query Counters</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>bcount_label</cstring> + </property> + <property name="text"> + <string>&Wrong:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>bcount_line</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>qcount_label</cstring> + </property> + <property name="text"> + <string>&Altogether:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>qcount_line</cstring> + </property> + </widget> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>qcount_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>bcount_line</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + </vbox> + </widget> + </hbox> +</widget> +<customwidgets> + <customwidget> + <class>MySpinBox</class> + <header location="local">MySpinBox.h</header> + <sizehint> + <width>60</width> + <height>30</height> + </sizehint> + <container>0</container> + <sizepolicy> + <hordata>0</hordata> + <verdata>0</verdata> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + <pixmap>image0</pixmap> + </customwidget> +</customwidgets> +<images> + <image name="image0"> + <data format="PNG" length="256">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000000c749444154789cad55db1184200c4c180bb81a28c73aad811228c356f42b3792db3cc0db2fc724bb7901dc7b270f27ed17fa5fa9b117b7cd90211f4ba0ac906a7f1453b4d30ca917bb590681552af23f69bfc4ffa71519d2c8f62546ea5ea03738b1c18c33a4d156f0d13f43b61952e4af6d6e8fb3a408f080448419a433d6486d85052fdba892a295f5d45785cd8c51a9d6de6a814a8d2131da51f98e7a3b64ec9da04a8db53d43be3c3c0b22cacf17e4cdb5a931649ceddf34b190cf0aa019f03f1fd3e7457f03b5a66c9e1f13d0b20000000049454e44ae426082</data> + </image> +</images> +<tabstops> + <tabstop>gradebox</tabstop> + <tabstop>fauxami_line</tabstop> + <tabstop>today</tabstop> + <tabstop>never</tabstop> + <tabstop>qcount_line</tabstop> + <tabstop>bcount_line</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/entry-dialogs/MCEntryPage.cpp b/kvoctrain/kvoctrain/entry-dialogs/MCEntryPage.cpp new file mode 100644 index 00000000..a26e43ed --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/MCEntryPage.cpp @@ -0,0 +1,131 @@ +/*************************************************************************** + + dialog page for multiple choice suggestions + + ----------------------------------------------------------------------- + + begin : Mon Oct 29 18:09:29 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "MCEntryPage.h" +#include "EntryDlg.h" + +#include <langset.h> + +#include <qlineedit.h> + + +MCEntryPage::MCEntryPage(EntryDlg *_dlgbook, bool multi_sel, const MultipleChoice &mc, QWidget *parent, const char *name) + : MCEntryPageForm( parent, name ), dlgbook(_dlgbook) +{ + multiplechoice = mc; + + connect( mc1Field, SIGNAL(textChanged(const QString&)), SLOT(mc1Changed(const QString&)) ); + connect( mc2Field, SIGNAL(textChanged(const QString&)), SLOT(mc2Changed(const QString&)) ); + connect( mc3Field, SIGNAL(textChanged(const QString&)), SLOT(mc3Changed(const QString&)) ); + connect( mc4Field, SIGNAL(textChanged(const QString&)), SLOT(mc4Changed(const QString&)) ); + connect( mc5Field, SIGNAL(textChanged(const QString&)), SLOT(mc5Changed(const QString&)) ); + + setData(multi_sel, mc); +} + + +void MCEntryPage::setData(bool multi_sel, const MultipleChoice &mc) +{ + mc1Field->setText (mc.mc1()); + mc2Field->setText (mc.mc2()); + mc3Field->setText (mc.mc3()); + mc4Field->setText (mc.mc4()); + mc5Field->setText (mc.mc5()); + + if (multi_sel) + { + mc1Field->setEnabled(false); + mc2Field->setEnabled(false); + mc3Field->setEnabled(false); + mc4Field->setEnabled(false); + mc5Field->setEnabled(false); + } + + setModified(false); +} + + +void MCEntryPage::mc1Changed(const QString& s) +{ + setModified(true); + multiplechoice.setMC1 (s); +} + + +void MCEntryPage::mc2Changed(const QString& s) +{ + setModified(true); + multiplechoice.setMC2 (s); +} + + +void MCEntryPage::mc3Changed(const QString& s) +{ + setModified(true); + multiplechoice.setMC3 (s); +} + + +void MCEntryPage::mc4Changed(const QString& s) +{ + setModified(true); + multiplechoice.setMC4 (s); +} + + +void MCEntryPage::mc5Changed(const QString& s) +{ + setModified(true); + multiplechoice.setMC5 (s); +} + + +bool MCEntryPage::isModified() +{ + return modified; +} + + +void MCEntryPage::setModified(bool mod) +{ + modified = mod; + if (mod) + emit sigModified(); +} + + +void MCEntryPage::setEnabled(int enable) +{ + bool ena = enable == EntryDlg::EnableAll; + + mc1Field->setEnabled (ena); + mc2Field->setEnabled (ena); + mc3Field->setEnabled (ena); + mc4Field->setEnabled (ena); + mc5Field->setEnabled (ena); +} + +#include "MCEntryPage.moc" diff --git a/kvoctrain/kvoctrain/entry-dialogs/MCEntryPage.h b/kvoctrain/kvoctrain/entry-dialogs/MCEntryPage.h new file mode 100644 index 00000000..23fb441a --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/MCEntryPage.h @@ -0,0 +1,66 @@ +/*************************************************************************** + + dialog page for multiple choice suggestions + + ----------------------------------------------------------------------- + + begin : Mon Oct 29 18:09:29 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 MCEntryPage_included +#define MCEntryPage_included + +#include "MCEntryPageForm.h" + +#include <MultipleChoice.h> + +class EntryDlg; + +class MCEntryPage : public MCEntryPageForm +{ + Q_OBJECT + +public: + MCEntryPage(EntryDlg *dlgbook, bool multi_sel, const MultipleChoice &mc, QWidget *parent = NULL, const char *name = NULL); + + void setData(bool multi_sel, const MultipleChoice &mc); + + MultipleChoice getMultipleChoice() const { return multiplechoice; } + + bool isModified(); + void setModified(bool mod = true); + void setEnabled(int enable_type); + +signals: + void sigModified(); + +protected slots: + void mc1Changed(const QString&); + void mc2Changed(const QString&); + void mc3Changed(const QString&); + void mc4Changed(const QString&); + void mc5Changed(const QString&); + +protected: + MultipleChoice multiplechoice; + bool modified; + EntryDlg *dlgbook; +}; + +#endif // MCEntryPage_included diff --git a/kvoctrain/kvoctrain/entry-dialogs/MCEntryPageForm.ui b/kvoctrain/kvoctrain/entry-dialogs/MCEntryPageForm.ui new file mode 100644 index 00000000..b03b2de6 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/MCEntryPageForm.ui @@ -0,0 +1,217 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>MCEntryPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>MCEntryPageForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>583</width> + <height>181</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>GroupBox1</cstring> + </property> + <property name="title"> + <string>Suggestions for Multiple Choice</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>mc1Label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&1:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>mc1Field</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>mc2Label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&2:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>mc2Field</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>mc3Label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&3:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>mc3Field</cstring> + </property> + </widget> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>mc1Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>mc2Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>mc3Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="4" column="1"> + <property name="name"> + <cstring>mc5Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="3" column="1"> + <property name="name"> + <cstring>mc4Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>mc4Label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&4:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>mc4Field</cstring> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>mc5Label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&5:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>mc5Field</cstring> + </property> + </widget> + </grid> + </widget> + </vbox> +</widget> +<tabstops> + <tabstop>mc1Field</tabstop> + <tabstop>mc2Field</tabstop> + <tabstop>mc3Field</tabstop> + <tabstop>mc4Field</tabstop> + <tabstop>mc5Field</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/entry-dialogs/Makefile.am b/kvoctrain/kvoctrain/entry-dialogs/Makefile.am new file mode 100644 index 00000000..520cbdb5 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/Makefile.am @@ -0,0 +1,13 @@ +INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../kvt-core \ + -I../docprop-dialogs -I$(srcdir)/../docprop-dialogs -I$(top_builddir)/kvoctrain/kvoctrain/common-dialogs $(all_includes) + +noinst_LTLIBRARIES = libentrydlg.la + +libentrydlg_la_SOURCES = PhoneticEntryPage.cpp FromToEntryPage.cpp \ + CommonEntryPage.cpp AuxInfoEntryPage.cpp FromToEntryPageForm.ui CommonEntryPageForm.ui \ + AuxInfoEntryPageForm.ui TenseEntryPage.cpp AdjEntryPage.cpp MCEntryPage.cpp \ + TenseEntryPageForm.ui AdjEntryPageForm.ui MCEntryPageForm.ui EntryDlg.cpp MySpinBox.cpp \ + blockall.cpp + +METASOURCES = AUTO + diff --git a/kvoctrain/kvoctrain/entry-dialogs/MySpinBox.cpp b/kvoctrain/kvoctrain/entry-dialogs/MySpinBox.cpp new file mode 100644 index 00000000..f8d1e6f9 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/MySpinBox.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + + display special spinbox (only meaningful for QT2x) + + ----------------------------------------------------------------------- + + begin : Sat Oct 21 18:02:16 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "MySpinBox.h" + +MySpinBox::MySpinBox (QWidget* parent, const char* name ): QSpinBox(parent, name ), spin_names (0) +{ + setWrapping(true); +} + + +void MySpinBox::setData (QStringList *names, int minValue, int maxValue) +{ + spin_names = names; + setRange (minValue, maxValue); +} + + +QString MySpinBox::mapValueToText( int value ) +{ + if (special_str.length() != 0 ) + return special_str; + + if (spin_names != 0) + return (*spin_names)[value]; + else + return QString("%1").arg(value); +} + + +int MySpinBox::MySpinBox::mapTextToValue(bool *) +{ + return 0; +} + + +void MySpinBox::setSpecial(const QString &str) +{ + special_str = str; + setSuffix(""); // update display +} + + + diff --git a/kvoctrain/kvoctrain/entry-dialogs/MySpinBox.h b/kvoctrain/kvoctrain/entry-dialogs/MySpinBox.h new file mode 100644 index 00000000..284bb8ea --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/MySpinBox.h @@ -0,0 +1,48 @@ +/*************************************************************************** + + display special spinbox + + ----------------------------------------------------------------------- + + begin : Sat Oct 21 18:02:16 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 MySpinbox_included +#define MySpinbox_included + +#include <qspinbox.h> + +class QStringlist; + +class MySpinBox : public QSpinBox +{ +public: + MySpinBox (QWidget* parent = 0, const char* name = 0); + + void setSpecial(const QString &str); + void setData (QStringList *names, int minValue, int maxValue); + virtual QString mapValueToText( int value ); + virtual int mapTextToValue( bool* ok ); + +protected: + QStringList *spin_names; + QString special_str; +}; + +#endif // MySpinbox_included diff --git a/kvoctrain/kvoctrain/entry-dialogs/PhoneticEntryPage.cpp b/kvoctrain/kvoctrain/entry-dialogs/PhoneticEntryPage.cpp new file mode 100644 index 00000000..6d26be5a --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/PhoneticEntryPage.cpp @@ -0,0 +1,229 @@ + /*************************************************************************** + + dialog page for characters from the phonetic alphabet + + ----------------------------------------------------------------------- + + begin : Sun Dec 9 2001 + + copyright : (C) 2001-2002 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001-2002 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "PhoneticEntryPage.h" + +#include <qlayout.h> +#include <qframe.h> +#include <qgroupbox.h> +#include <qtooltip.h> + +#include <kdebug.h> +#include <klocale.h> + +#define KV_MAX_HORIZ 20 +#define KV_FONTSIZE 14 + +#define I18N_NOOP_maybe(x) x + +// provide Unicode chars U0250 - U02AF + +struct KV_Unicode_Ref { + wchar_t code; + const char *unicodename; + const char *audible; +}; + +KV_Unicode_Ref kv_unicode_ref[] = { + + {0x00E6, "LATIN SMALL LETTER AE", I18N_NOOP_maybe("")}, + {0x00E7, "LATIN SMALL LETTER C WITH CEDILLA", I18N_NOOP_maybe("")}, + {0x00F0, "LATIN SMALL LETTER ETH", I18N_NOOP_maybe("")}, + {0x00F8, "LATIN SMALL LETTER O WITH STROKE", I18N_NOOP_maybe("")}, + {0x0127, "LATIN SMALL LETTER H WITH STROKE", I18N_NOOP_maybe("")}, + {0x014B, "LATIN SMALL LETTER ENG", I18N_NOOP_maybe("")}, + {0x0153, "LATIN SMALL LIGATURE OE", I18N_NOOP_maybe("")}, + {0x01F0, "LATIN SMALL LETTER J WITH CARON", I18N_NOOP_maybe("")}, + + {0x03B2, "GREEK SMALL LETTER BETA", I18N_NOOP_maybe("")}, + {0x03B8, "GREEK SMALL LETTER THETA", I18N_NOOP_maybe("")}, + {0x03BB, "GREEK SMALL LETTER LAMDA", I18N_NOOP_maybe("")}, + {0x03C7, "GREEK SMALL LETTER CHI", I18N_NOOP_maybe("")}, + + {0x0250, "LATIN SMALL LETTER TURNED A", I18N_NOOP_maybe("low central unrounded vowel")}, + {0x0251, "LATIN SMALL LETTER ALPHA", I18N_NOOP_maybe("low back unrounded vowel")}, + {0x0252, "LATIN SMALL LETTER TURNED ALPHA", I18N_NOOP_maybe("low back rounded vowel")}, + {0x0253, "LATIN SMALL LETTER B WITH HOOK", I18N_NOOP_maybe("implosive bilabial stop")}, + {0x0254, "LATIN SMALL LETTER OPEN O", I18N_NOOP_maybe("lower-mid back rounded vowel")}, + {0x0255, "LATIN SMALL LETTER C WITH CURL", I18N_NOOP_maybe("voiceless alveolo-palatal laminal fricative")}, + {0x0256, "LATIN SMALL LETTER D WITH TAIL", I18N_NOOP_maybe("voiced retroflex stop")}, + {0x0257, "LATIN SMALL LETTER D WITH HOOK", I18N_NOOP_maybe("implosive dental or alveolar stop")}, + {0x0258, "LATIN SMALL LETTER REVERSED E", I18N_NOOP_maybe("upper-mid central unrounded vowel")}, + {0x0259, "LATIN SMALL LETTER SCHWA", I18N_NOOP_maybe("mid-central unrounded vowel")}, + {0x025A, "LATIN SMALL LETTER SCHWA WITH HOOK", I18N_NOOP_maybe("rhotacized schwa")}, + {0x025B, "LATIN SMALL LETTER OPEN E", I18N_NOOP_maybe("lower-mid front unrounded vowel")}, + {0x025C, "LATIN SMALL LETTER REVERSED OPEN E", I18N_NOOP_maybe("lower-mid central unrounded vowel")}, + {0x025D, "LATIN SMALL LETTER REVERSED OPEN E WITH HOOK", I18N_NOOP_maybe("rhotacized lower-mid central vowel")}, + {0x025E, "LATIN SMALL LETTER CLOSED REVERSED OPEN E", I18N_NOOP_maybe("lower-mid central rounded vowel")}, + {0x025F, "LATIN SMALL LETTER DOTLESS J WITH STROKE", I18N_NOOP_maybe("voiced palatal stop")}, + {0x0260, "LATIN SMALL LETTER G WITH HOOK", I18N_NOOP_maybe("implosive velar stop")}, + {0x0261, "LATIN SMALL LETTER SCRIPT G", I18N_NOOP_maybe("voiced velar stop")}, + {0x0262, "LATIN LETTER SMALL CAPITAL G", I18N_NOOP_maybe("voiced uvular stop")}, + {0x0263, "LATIN SMALL LETTER GAMMA", I18N_NOOP_maybe("voiced velar fricative")}, + {0x0264, "LATIN SMALL LETTER RAMS HORN", I18N_NOOP_maybe("")}, + {0x0265, "LATIN SMALL LETTER TURNED H", I18N_NOOP_maybe("voiced rounded palatal approximant")}, + {0x0266, "LATIN SMALL LETTER H WITH HOOK", I18N_NOOP_maybe("breathy-voiced glottal fricative")}, + {0x0267, "LATIN SMALL LETTER HENG WITH HOOK", I18N_NOOP_maybe("voiceless coarticulated velar and palatoalveolar fricative")}, + {0x0268, "LATIN SMALL LETTER I WITH STROKE", I18N_NOOP_maybe("high central unrounded vowel")}, + {0x0269, "LATIN SMALL LETTER IOTA", I18N_NOOP_maybe("semi-high front unrounded vowel")}, + {0x026A, "LATIN LETTER SMALL CAPITAL I", I18N_NOOP_maybe("semi-high front unrounded vowel")}, + {0x026B, "LATIN SMALL LETTER L WITH MIDDLE TILDE", I18N_NOOP_maybe("velarized voiced alveolar lateral approximant")}, + {0x026C, "LATIN SMALL LETTER L WITH BELT", I18N_NOOP_maybe("voiceless alveolar lateral fricative")}, + {0x026D, "LATIN SMALL LETTER L WITH RETROFLEX HOOK", I18N_NOOP_maybe("voiced retroflex lateral")}, + {0x026E, "LATIN SMALL LETTER LEZH", I18N_NOOP_maybe("voiced lateral fricative")}, + {0x026F, "LATIN SMALL LETTER TURNED M", I18N_NOOP_maybe("high back unrounded vowel")}, + {0x0270, "LATIN SMALL LETTER TURNED M WITH LONG LEG", I18N_NOOP_maybe("voiced velar approximant")}, + {0x0271, "LATIN SMALL LETTER M WITH HOOK", I18N_NOOP_maybe("voiced labiodental nasal")}, + {0x0272, "LATIN SMALL LETTER N WITH LEFT HOOK", I18N_NOOP_maybe("voiced palatal nasal")}, + {0x0273, "LATIN SMALL LETTER N WITH RETROFLEX HOOK", I18N_NOOP_maybe("voiced retroflex nasal")}, + {0x0274, "LATIN LETTER SMALL CAPITAL N", I18N_NOOP_maybe("voiced uvular nasal")}, + {0x0275, "LATIN SMALL LETTER BARRED O", I18N_NOOP_maybe("rounded mid-central vowel, i.e. rounded schwa")}, + {0x0276, "LATIN LETTER SMALL CAPITAL OE", I18N_NOOP_maybe("low front rounded vowel")}, + {0x0277, "LATIN SMALL LETTER CLOSED OMEGA", I18N_NOOP_maybe("semi-high back rounded vowel")}, + {0x0278, "LATIN SMALL LETTER PHI", I18N_NOOP_maybe("voiceless bilabial fricative")}, + {0x0279, "LATIN SMALL LETTER TURNED R", I18N_NOOP_maybe("voiced alveolar approximant")}, + {0x027A, "LATIN SMALL LETTER TURNED R WITH LONG LEG", I18N_NOOP_maybe("voiced lateral flap")}, + {0x027B, "LATIN SMALL LETTER TURNED R WITH HOOK", I18N_NOOP_maybe("voiced retroflex approximant")}, + {0x027C, "LATIN SMALL LETTER R WITH LONG LEG", I18N_NOOP_maybe("voiced strident apico-alveolar trill")}, + {0x027D, "LATIN SMALL LETTER R WITH TAIL", I18N_NOOP_maybe("voiced retroflex flap")}, + {0x027E, "LATIN SMALL LETTER R WITH FISHHOOK", I18N_NOOP_maybe("voiced alveolar flap or tap")}, + {0x027F, "LATIN SMALL LETTER REVERSED R WITH FISHHOOK", I18N_NOOP_maybe("apical dental vowel")}, + {0x0280, "LATIN LETTER SMALL CAPITAL R", I18N_NOOP_maybe("voiced uvular trill")}, + {0x0281, "LATIN LETTER SMALL CAPITAL INVERTED R", I18N_NOOP_maybe("voiced uvular fricative or approximant")}, + {0x0282, "LATIN SMALL LETTER S WITH HOOK", I18N_NOOP_maybe("voiceless retroflex fricative")}, + {0x0283, "LATIN SMALL LETTER ESH", I18N_NOOP_maybe("voiceless postalveolar fricative")}, + {0x0284, "LATIN SMALL LETTER DOTLESS J WITH STROKE AND HOOK", I18N_NOOP_maybe("implosive palatal stop")}, + {0x0285, "LATIN SMALL LETTER SQUAT REVERSED ESH", I18N_NOOP_maybe("apical retroflex vowel")}, + {0x0286, "LATIN SMALL LETTER ESH WITH CURL", I18N_NOOP_maybe("palatalized voiceless postalveolar fricative")}, + {0x0287, "LATIN SMALL LETTER TURNED T", I18N_NOOP_maybe("dental click")}, + {0x0288, "LATIN SMALL LETTER T WITH RETROFLEX HOOK", I18N_NOOP_maybe("voiceless retroflex stop")}, + {0x0289, "LATIN SMALL LETTER U BAR", I18N_NOOP_maybe("high central rounded vowel")}, + {0x028A, "LATIN SMALL LETTER UPSILON", I18N_NOOP_maybe("semi-high back rounded vowel")}, + {0x028B, "LATIN SMALL LETTER V WITH HOOK", I18N_NOOP_maybe("voiced labiodental approximant")}, + {0x028C, "LATIN SMALL LETTER TURNED V", I18N_NOOP_maybe("lower-mid back unrounded vowel")}, + {0x028D, "LATIN SMALL LETTER TURNED W", I18N_NOOP_maybe("voiceless rounded labiovelar approximant")}, + {0x028E, "LATIN SMALL LETTER TURNED Y", I18N_NOOP_maybe("voiced lateral approximant")}, + {0x028F, "LATIN LETTER SMALL CAPITAL Y", I18N_NOOP_maybe("semi-high front rounded vowel")}, + {0x0290, "LATIN SMALL LETTER Z WITH RETROFLEX HOOK", I18N_NOOP_maybe("voiced retroflex fricative")}, + {0x0291, "LATIN SMALL LETTER Z WITH CURL", I18N_NOOP_maybe("voiced alveolo-palatal laminal fricative")}, + {0x0292, "LATIN SMALL LETTER EZH", I18N_NOOP_maybe("voiced postalveolar fricative")}, + {0x0293, "LATIN SMALL LETTER EZH WITH CURL", I18N_NOOP_maybe("palatalized voiced postalveolar fricative")}, + {0x0294, "LATIN LETTER GLOTTAL STOP", I18N_NOOP_maybe("")}, + {0x0295, "LATIN LETTER PHARYNGEAL VOICED FRICATIVE", I18N_NOOP_maybe("voiced pharyngeal fricative")}, + {0x0296, "LATIN LETTER INVERTED GLOTTAL STOP", I18N_NOOP_maybe("lateral click")}, + {0x0297, "LATIN LETTER STRETCHED C", I18N_NOOP_maybe("palatal (or alveolar) click")}, + {0x0298, "LATIN LETTER BILABIAL CLICK", I18N_NOOP_maybe("")}, + {0x0299, "LATIN LETTER SMALL CAPITAL B", I18N_NOOP_maybe("bilabial trill")}, + {0x029A, "LATIN SMALL LETTER CLOSED OPEN E", I18N_NOOP_maybe("lower-mid front rounded vowel")}, + {0x029B, "LATIN LETTER SMALL CAPITAL G WITH HOOK", I18N_NOOP_maybe("voiced uvular implosive")}, + {0x029C, "LATIN LETTER SMALL CAPITAL H", I18N_NOOP_maybe("voiceless epiglottal fricative")}, + {0x029D, "LATIN SMALL LETTER J WITH CROSSED-TAIL", I18N_NOOP_maybe("voiced palatal fricative")}, + {0x029E, "LATIN SMALL LETTER TURNED K", I18N_NOOP_maybe("proposed for velar click")}, + {0x029F, "LATIN LETTER SMALL CAPITAL L", I18N_NOOP_maybe("velar lateral approximant")}, + {0x02A0, "LATIN SMALL LETTER Q WITH HOOK", I18N_NOOP_maybe("voiceless uvular implosive")}, + {0x02A1, "LATIN LETTER GLOTTAL STOP WITH STROKE", I18N_NOOP_maybe("voiced epiglottal stop")}, + {0x02A2, "LATIN LETTER REVERSED GLOTTAL STOP WITH STROKE", I18N_NOOP_maybe("voiced epiglottal fricative")}, + {0x02A3, "LATIN SMALL LETTER DZ DIGRAPH", I18N_NOOP_maybe("voiced dental affricate")}, + {0x02A4, "LATIN SMALL LETTER DEZH DIGRAPH", I18N_NOOP_maybe("voiced postalveolar affricate")}, + {0x02A5, "LATIN SMALL LETTER DZ DIGRAPH WITH CURL", I18N_NOOP_maybe("voiced alveolo-palatal affricate")}, + {0x02A6, "LATIN SMALL LETTER TS DIGRAPH", I18N_NOOP_maybe("voiceless dental affricate")}, + {0x02A7, "LATIN SMALL LETTER TESH DIGRAPH", I18N_NOOP_maybe("voiceless postalveolar affricate")}, + {0x02A8, "LATIN SMALL LETTER TC DIGRAPH WITH CURL", I18N_NOOP_maybe("voiceless alveolo-palatal affricate")}, + {0x02A9, "LATIN SMALL LETTER FENG DIGRAPH", I18N_NOOP_maybe("velopharyngeal fricative")}, + {0x02AA, "LATIN SMALL LETTER LS DIGRAPH", I18N_NOOP_maybe("lateral alveolar fricative (lisp)")}, + {0x02AB, "LATIN SMALL LETTER LZ DIGRAPH", I18N_NOOP_maybe("voiced lateral alveolar fricative")}, + {0x02AC, "LATIN LETTER BILABIAL PERCUSSIVE", I18N_NOOP_maybe("audible lip smack")}, + {0x02AD, "LATIN LETTER BIDENTAL PERCUSSIVE", I18N_NOOP_maybe("audible teeth gnashing")}, + + {0x02CA, "MODIFIER LETTER ACUTE ACCENT (Mandarin Chinese second tone)", I18N_NOOP_maybe("high-rising tone")}, + {0x02CB, "MODIFIER LETTER GRAVE ACCENT (Mandarin Chinese fourth tone)", I18N_NOOP_maybe("high-falling tone")}, + + {0x2191, "UPWARDS ARROW", I18N_NOOP_maybe("egressive airflow")}, + {0x2193, "DOWNWARDS ARROW", I18N_NOOP_maybe("ingressive airflow")}, + + {0, 0, 0} +}; + + +void PhoneticButton::slotClicked() +{ + if (text().length() != 0) + emit page->charSelected(text()[0].unicode()); +} + + +PhoneticEntryPage::PhoneticEntryPage(const QFont &ipafont, QWidget *parent, const char *name, bool modal) + : KDialogBase(Plain, i18n("Select Characters From Phonetic Alphabet"), Close, Close, parent, name, modal) +{ + int num = sizeof(kv_unicode_ref) / sizeof(kv_unicode_ref[0]); + QFrame * phoneticbox = plainPage(); + QGridLayout *gbox = new QGridLayout(phoneticbox, KV_MAX_HORIZ, (num+KV_MAX_HORIZ-1)/KV_MAX_HORIZ, 1); + + KV_Unicode_Ref *uni_ref = kv_unicode_ref; + int vert = 0; + int horiz = 0; + while (uni_ref->code != 0) { + QChar qc = uni_ref->code; + QString text = qc; + PhoneticButton *butt = new PhoneticButton(text, phoneticbox, this); + connect (butt, SIGNAL(clicked()), butt, SLOT(slotClicked()) ); + QString tip = i18n("Unicode name: "); + tip += QString::fromLatin1(uni_ref->unicodename); + tip += "\n"; + tip += i18n("Describing the sound of the character", "Sound: "); + tip += i18n(uni_ref->audible); + butt->setFont(ipafont); + butt->setSizePolicy(QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed)); + int sz = QMAX(14, int(1.7*ipafont.pointSize())); + butt->setMaximumSize(QSize (sz, sz)); + gbox->addWidget( butt, vert, horiz, AlignCenter ); + QToolTip::add (butt, tip); + + if (++horiz >= KV_MAX_HORIZ) { + ++vert; + horiz = 0; + } + ++uni_ref; + } + resize(sizeHint()); +} + + +void PhoneticEntryPage::keyPressEvent( QKeyEvent *e ) +{ + if ((e->state() & (ControlButton | AltButton)) == 0) { + QString s = e->text(); + for (unsigned i = 0; i < s.length(); ++i) { + emit charSelected(s[i].unicode()); + } + e->accept(); + } + else + e->ignore(); +} + + +#include "PhoneticEntryPage.moc" diff --git a/kvoctrain/kvoctrain/entry-dialogs/PhoneticEntryPage.h b/kvoctrain/kvoctrain/entry-dialogs/PhoneticEntryPage.h new file mode 100644 index 00000000..cf12ef48 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/PhoneticEntryPage.h @@ -0,0 +1,67 @@ + /*************************************************************************** + + dialog page for characters from the phonetic alphabet + + ----------------------------------------------------------------------- + + begin : Sun Dec 9 2001 + + copyright : (C) 2001-2002 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001-2002 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 PHONETICENTRYPAGE_H +#define PHONETICENTRYPAGE_H + +#include <qpushbutton.h> + +#include <kdialogbase.h> + +class PhoneticEntryPage : public KDialogBase +{ + Q_OBJECT + +public: + PhoneticEntryPage(const QFont &ipafont, QWidget *parent = 0, const char *name = 0, bool modal = false); + +signals: + void charSelected(wchar_t); + +protected: + void keyPressEvent( QKeyEvent *e ); + + friend class PhoneticButton; +}; + + +class PhoneticButton : public QPushButton +{ + Q_OBJECT + +public: + PhoneticButton (const QString & text, QWidget * parent, PhoneticEntryPage *_page, const char * name = 0) + : QPushButton (text, parent, name), page(_page) {} + +protected slots: + void slotClicked(); + +protected: + PhoneticEntryPage *page; +}; + + +#endif diff --git a/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPage.cpp b/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPage.cpp new file mode 100644 index 00000000..30fa4fdd --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPage.cpp @@ -0,0 +1,317 @@ +/*************************************************************************** + + tenses of irreg. verbs dialog page + + ----------------------------------------------------------------------- + + begin : Sat Nov 27 20:20:34 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qcombobox.h> +#include <qcheckbox.h> +#include <qpushbutton.h> +#include <qlineedit.h> + +#include <langset.h> + +#include "TenseEntryPage.h" +#include "EntryDlg.h" + +TenseEntryPage::TenseEntryPage +( + EntryDlg *_dlgbook, + bool multi_sel, + const Conjugation &con_prefix, + const Conjugation &conjug, + QWidget *parent, + const char *name +) + : TenseEntryPageForm( parent, name ), multi_mode(multi_sel), dlgbook(_dlgbook) +{ + + connect( third_p_common, SIGNAL(toggled(bool)), SLOT(slotThirdPCommonToggled(bool)) ); + connect( third_s_common, SIGNAL(toggled(bool)), SLOT(slotThirdSCommonToggled(bool)) ); + connect( b_next, SIGNAL(clicked()), SLOT(slotNextConj()) ); + connect( tensebox, SIGNAL(activated(int)), SLOT(slotTenseSelected(int)) ); + + connect( thirdN_plural, SIGNAL(textChanged(const QString&)), SLOT(thirdNPluralChanged(const QString&)) ); + connect( thirdN_singular, SIGNAL(textChanged(const QString&)), SLOT(thirdNSingularChanged(const QString&)) ); + connect( thirdM_plural, SIGNAL(textChanged(const QString&)), SLOT(thirdMPluralChanged(const QString&)) ); + connect( thirdM_singular, SIGNAL(textChanged(const QString&)), SLOT(thirdMSingularChanged(const QString&)) ); + connect( thirdF_plural, SIGNAL(textChanged(const QString&)), SLOT(thirdFPluralChanged(const QString&)) ); + connect( thirdF_singular, SIGNAL(textChanged(const QString&)), SLOT(thirdFSingularChanged(const QString&)) ); + connect( second_plural, SIGNAL(textChanged(const QString&)), SLOT(secondPluralChanged(const QString&)) ); + connect( second_singular, SIGNAL(textChanged(const QString&)), SLOT(secondSingularChanged(const QString&)) ); + connect( first_plural, SIGNAL(textChanged(const QString&)), SLOT(firstPluralChanged(const QString&)) ); + connect( first_singular, SIGNAL(textChanged(const QString&)), SLOT(firstSingularChanged(const QString&)) ); + + prefix = con_prefix; + selection = ""; +/* + // FIXME: fill labels with prefixes ? + + label_first_plural->setText (con_prefix.pers1Plural (CONJ_PREFIX)); + label_first_singular->setText (con_prefix.pers1Singular (CONJ_PREFIX)); + label_second_singular->setText (con_prefix.pers2Singular (CONJ_PREFIX)); + label_second_plural->setText (con_prefix.pers2Plural (CONJ_PREFIX)); + label_thirdF_plural->setText (con_prefix.pers3FemalePlural (CONJ_PREFIX)); + label_thirdF_singular->setText (con_prefix.pers3FemaleSingular (CONJ_PREFIX)); + label_thirdM_singular->setText (con_prefix.pers3MaleSingular (CONJ_PREFIX)); + label_thirdN_singular->setText (con_prefix.pers3NaturalSingular (CONJ_PREFIX)); + label_thirdN_plural->setText (con_prefix.pers3NaturalPlural (CONJ_PREFIX)); + label_thirdM_plural->setText (con_prefix.pers3MalePlural (CONJ_PREFIX)); +*/ + + setData(multi_sel, conjug); +} + + +void TenseEntryPage::setData(bool /*multi_sel*/, const Conjugation &conjug) +{ + if (multi_mode) + tensebox->setEnabled(false); + + for (int i = 0; i < Conjugation::numTenses(); i++) + tensebox->insertItem (Conjugation::getName(i) ); + + conjugations = conjug; + slotTenseSelected(0); + updateFields(); + + setModified(false); +} + + +void TenseEntryPage::firstPluralChanged(const QString& s) +{ + conjugations.setPers1Plural (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::firstSingularChanged(const QString& s) +{ + conjugations.setPers1Singular (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::secondSingularChanged(const QString& s) +{ + conjugations.setPers2Singular (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::secondPluralChanged(const QString& s) +{ + conjugations.setPers2Plural (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::thirdFPluralChanged(const QString& s) +{ + conjugations.setPers3FemalePlural (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::thirdFSingularChanged(const QString& s) +{ + conjugations.setPers3FemaleSingular (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::thirdMSingularChanged(const QString& s) +{ + conjugations.setPers3MaleSingular (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::thirdNSingularChanged(const QString& s) +{ + conjugations.setPers3NaturalSingular(selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::thirdNPluralChanged(const QString& s) +{ + conjugations.setPers3NaturalPlural (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::thirdMPluralChanged(const QString& s) +{ + conjugations.setPers3MalePlural (selection, s); + updateFields(); + setModified(true); +} + + +void TenseEntryPage::slotTenseSelected(int sel) +{ + if (multi_mode) + { + b_next->setEnabled(false); + third_s_common->setEnabled(false); + third_p_common->setEnabled(false); + first_plural->setEnabled(false); + first_singular->setEnabled(false); + second_singular->setEnabled(false); + second_plural->setEnabled(false); + thirdF_plural->setEnabled(false); + thirdF_singular->setEnabled(false); + thirdM_singular->setEnabled(false); + thirdN_singular->setEnabled(false); + thirdN_plural->setEnabled(false); + thirdM_plural->setEnabled(false); + } + else + { + selection = Conjugation::getAbbrev(sel); + first_plural->setText (conjugations.pers1Plural (selection )); + first_singular->setText (conjugations.pers1Singular (selection )); + second_plural->setText (conjugations.pers2Plural (selection )); + second_singular->setText (conjugations.pers2Singular (selection )); + thirdF_plural->setText (conjugations.pers3FemalePlural (selection )); + thirdF_singular->setText (conjugations.pers3FemaleSingular (selection )); + thirdM_plural->setText (conjugations.pers3MalePlural (selection)); + thirdM_singular->setText (conjugations.pers3MaleSingular (selection )); + thirdN_plural->setText (conjugations.pers3NaturalPlural (selection)); + thirdN_singular->setText (conjugations.pers3NaturalSingular (selection )); + + bool common = conjugations.pers3SingularCommon(selection); + third_s_common->setChecked(common); + thirdM_singular->setEnabled(!common); + thirdN_singular->setEnabled(!common); + + common = conjugations.pers3PluralCommon(selection); + third_p_common->setChecked(common); + thirdN_plural->setEnabled(!common); + thirdM_plural->setEnabled(!common); + } +} + + +void TenseEntryPage::slotThirdSCommonToggled(bool common) +{ + conjugations.setPers3SingularCommon(selection, common); + thirdM_singular->setEnabled(!common); + thirdN_singular->setEnabled(!common); + setModified(true); +} + + +void TenseEntryPage::slotThirdPCommonToggled(bool common) +{ + conjugations.setPers3PluralCommon(selection, common); + thirdN_plural->setEnabled(!common); + thirdM_plural->setEnabled(!common); + setModified(true); +} + + +void TenseEntryPage::slotNextConj() +{ + int j; + for (int i = tensebox->currentItem()+1; i < tensebox->count(); i++) { + + for (j = 0; j < conjugations.numEntries(); j++ ) { + if (Conjugation::getAbbrev(i) == conjugations.getType(j)) { + tensebox->setCurrentItem (i); + slotTenseSelected(i); + return; + } + } + } + + for (int i = 0; i < tensebox->currentItem()-1; i++) { + for (j = 0; j < conjugations.numEntries(); j++ ) { + if (Conjugation::getAbbrev(i) == conjugations.getType(j)) { + tensebox->setCurrentItem (i); + slotTenseSelected(i); + return; + } + } + } +} + + +Conjugation TenseEntryPage::getConjugation() +{ + conjugations.cleanUp(); + return conjugations; +} + + +void TenseEntryPage::updateFields() +{ + b_next->setEnabled(conjugations.numEntries() > 1); // next button +} + + +bool TenseEntryPage::isModified() +{ + return modified; +} + + +void TenseEntryPage::setEnabled(int enable) +{ + bool ena = enable == EntryDlg::EnableAll; + + b_next->setEnabled(ena); + tensebox->setEnabled(ena); + third_s_common->setEnabled(ena); + third_p_common->setEnabled(ena); + first_plural->setEnabled(ena); + first_singular->setEnabled(ena); + second_singular->setEnabled(ena); + second_plural->setEnabled(ena); + thirdF_plural->setEnabled(ena); + thirdF_singular->setEnabled(ena); + thirdM_singular->setEnabled(ena); + thirdN_singular->setEnabled(ena); + thirdN_plural->setEnabled(ena); + thirdM_plural->setEnabled(ena); +} + + +void TenseEntryPage::setModified(bool mod) +{ + modified = mod; + if (mod) + emit sigModified(); +} + +#include "TenseEntryPage.moc" diff --git a/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPage.h b/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPage.h new file mode 100644 index 00000000..5c118e8d --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPage.h @@ -0,0 +1,89 @@ +/*************************************************************************** + + tenses of irreg. verbs dialog page + + ----------------------------------------------------------------------- + + begin : Sat Nov 27 20:20:34 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 TenseEntryPage_included +#define TenseEntryPage_included + +#include "TenseEntryPageForm.h" + +#include <grammarmanager.h> + +class EntryDlg; + +class TenseEntryPage : public TenseEntryPageForm +{ + Q_OBJECT + +public: + TenseEntryPage + ( + EntryDlg *dlgbook, + bool multi_sel, + const Conjugation &con_prefix, + const Conjugation &conjugations, + QWidget *parent = NULL, + const char *name = NULL + ); + + void setData(bool multi_sel, const Conjugation &conjugations); + + Conjugation getConjugation(); + + bool isModified(); + void setModified(bool mod = true); + void setEnabled(int enable_type); + +signals: + void sigModified(); + +protected: + void updateFields(); + +protected slots: + void secondPluralChanged(const QString&); + void secondSingularChanged(const QString&); + void thirdNSingularChanged(const QString&); + void thirdFPluralChanged(const QString&); + void thirdMSingularChanged(const QString&); + void thirdFSingularChanged(const QString&); + void slotTenseSelected(int); + void thirdMPluralChanged(const QString&); + void thirdNPluralChanged(const QString&); + void firstSingularChanged(const QString&); + void firstPluralChanged(const QString&); + void slotThirdSCommonToggled(bool); + void slotThirdPCommonToggled(bool); + void slotNextConj(); + +protected: + Conjugation prefix, + conjugations; + QString selection; + bool multi_mode; + bool modified; + EntryDlg *dlgbook; +}; + +#endif // TenseEntryPage_included diff --git a/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPageForm.ui b/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPageForm.ui new file mode 100644 index 00000000..1c3c4ee5 --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/TenseEntryPageForm.ui @@ -0,0 +1,387 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>TenseEntryPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>TenseEntryPageForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>546</width> + <height>270</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </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="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>GroupBox8</cstring> + </property> + <property name="title"> + <string>Conjugation of Verbs</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLineEdit" row="6" column="2"> + <property name="name"> + <cstring>thirdN_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QCheckBox" row="3" column="2"> + <property name="name"> + <cstring>third_p_common</cstring> + </property> + <property name="text"> + <string>C&ommon</string> + </property> + </widget> + <widget class="QLineEdit" row="2" column="2"> + <property name="name"> + <cstring>second_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="5" column="2"> + <property name="name"> + <cstring>thirdM_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QCheckBox" row="3" column="1"> + <property name="name"> + <cstring>third_s_common</cstring> + </property> + <property name="text"> + <string>&Common</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>pers1_label</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&1. Person:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>first_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>female_label</cstring> + </property> + <property name="text"> + <string>&Female:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>thirdF_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="1"> + <property name="name"> + <cstring>TextLabel4_2_2</cstring> + </property> + <property name="text"> + <string>Singular</string> + </property> + </widget> + <widget class="QLineEdit" row="4" column="2"> + <property name="name"> + <cstring>thirdF_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="4" column="1"> + <property name="name"> + <cstring>thirdF_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>pers3_label</cstring> + </property> + <property name="text"> + <string>&3. Person:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>third_s_common</cstring> + </property> + </widget> + <widget class="QLineEdit" row="1" column="2"> + <property name="name"> + <cstring>first_plural</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="5" column="1"> + <property name="name"> + <cstring>thirdM_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>first_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <spacer row="0" column="0"> + <property name="name"> + <cstring>Spacer6</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Fixed</enum> + </property> + <property name="sizeHint"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLineEdit" row="6" column="1"> + <property name="name"> + <cstring>thirdN_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="6" column="0"> + <property name="name"> + <cstring>natural_label</cstring> + </property> + <property name="text"> + <string>&Neutral:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>thirdN_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>male_label</cstring> + </property> + <property name="text"> + <string>&Male:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>thirdM_singular</cstring> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>second_singular</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>pers2_label</cstring> + </property> + <property name="text"> + <string>&2. Person:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>second_singular</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="2"> + <property name="name"> + <cstring>TextLabel4_2</cstring> + </property> + <property name="text"> + <string>Plural</string> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>tenselabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Tense:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>tensebox</cstring> + </property> + </widget> + <widget class="QPushButton" row="0" column="2"> + <property name="name"> + <cstring>b_next</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Ne&xt</string> + </property> + </widget> + <widget class="QComboBox" row="0" column="1"> + <property name="name"> + <cstring>tensebox</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + </grid> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>tensebox</tabstop> + <tabstop>b_next</tabstop> + <tabstop>first_singular</tabstop> + <tabstop>second_singular</tabstop> + <tabstop>first_plural</tabstop> + <tabstop>second_plural</tabstop> + <tabstop>third_s_common</tabstop> + <tabstop>thirdF_singular</tabstop> + <tabstop>thirdM_singular</tabstop> + <tabstop>thirdN_singular</tabstop> + <tabstop>third_p_common</tabstop> + <tabstop>thirdF_plural</tabstop> + <tabstop>thirdM_plural</tabstop> + <tabstop>thirdN_plural</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/entry-dialogs/blockall.cpp b/kvoctrain/kvoctrain/entry-dialogs/blockall.cpp new file mode 100644 index 00000000..879acd8d --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/blockall.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + + dummy validator which blocks all + + ----------------------------------------------------------------------- + + begin : Sat Mar 25 15:02:16 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "blockall.h" + +BlockAllValidator::BlockAllValidator() : QValidator (0, 0) +{ +} + + +BlockAllValidator::State BlockAllValidator::validate (QString&, int& ) const +{ + return Invalid; +} + + diff --git a/kvoctrain/kvoctrain/entry-dialogs/blockall.h b/kvoctrain/kvoctrain/entry-dialogs/blockall.h new file mode 100644 index 00000000..96b115be --- /dev/null +++ b/kvoctrain/kvoctrain/entry-dialogs/blockall.h @@ -0,0 +1,38 @@ +/*************************************************************************** + + dummy validator which blocks all + + ----------------------------------------------------------------------- + + begin : Sat Mar 25 15:02:16 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 BlockAll_included +#define BlockAll_included + +#include <qvalidator.h> + +class BlockAllValidator : public QValidator +{ +public: + BlockAllValidator (); + State validate (QString&, int& ) const; +}; + +#endif // BlockAll_included diff --git a/kvoctrain/kvoctrain/examples/Makefile.am b/kvoctrain/kvoctrain/examples/Makefile.am new file mode 100644 index 00000000..b3454f21 --- /dev/null +++ b/kvoctrain/kvoctrain/examples/Makefile.am @@ -0,0 +1,6 @@ + +examples_DATA = sample-de.kvtml sample-en.kvtml +examplesdir = $(kde_datadir)/kvoctrain/examples + +EXTRA_DIST = sample-template-ascii.kvtml + diff --git a/kvoctrain/kvoctrain/examples/sample-de.kvtml b/kvoctrain/kvoctrain/examples/sample-de.kvtml new file mode 100644 index 00000000..716e3d28 --- /dev/null +++ b/kvoctrain/kvoctrain/examples/sample-de.kvtml @@ -0,0 +1,203 @@ +<?xml version="1.0"?> +<!DOCTYPE kvtml SYSTEM "kvoctrain.dtd"> +<!-- +This is a machine generated file. +Be careful when editing here. + +Short definition: + +lesson lesson group + desc name + %no its index + %query is in query selection + %current is current lesson +type type group + desc name + %no its index +e entry of dictionary + %s is selected + %m lesson member + %t common expression type + o original + %q in query ("o" is given, "t" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type (see QueryManager.h) + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + t translation .. + %q in query ("t" is given, "o" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + + %d last query date (from;to) + %w dito, compressed and deprecated + %g grade (from;to) + %c count (from;to) + %b bad count (from;to) + + +Valid xml means: + - Close all tags + - Keep proper hierarchy + - All attributes are quoted +--> + + <kvtml + encoding="UTF-8" + generator="kvoctrain v0.8.1" + cols="3" + lines="20" + title="Beispieldatei: Deutsch - Englisch/Französisch" + author="Ewald Arnold"> + + <lesson width="123"> + <desc no="1">Lektion eins</desc> + <desc no="2">Lektion zwei</desc> + <desc no="3" current="1">Lektion drei</desc> + <desc no="4">Lektion vier</desc> + </lesson> + + <article> + <e l="de"> + <fd>die</fd> + <fi>eine</fi> + <md>der</md> + <mi>einer</mi> + <nd>das</nd> + <ni>ein</ni> + </e> + <e l="en"> + <fd>fd en</fd> + <fi>fi en</fi> + <md>md en</md> + <mi>mi en</mi> + <nd>nd en</nd> + <ni>ni en</ni> + </e> + <e l="fr"> + <fd>la</fd> + <fi>une</fi> + <md>le</md> + <mi>un</mi> + </e> + </article> + + <conjugation> + <e l="de"> + <s1>ich</s1> + <s2>du</s2> + <s3f>sie</s3f> + <s3m>er</s3m> + <s3n>es</s3n> + <p1>wir</p1> + <p2>ihr</p2> + <p3f common="1">sie</p3f> + <p3m>sie</p3m> + <p3n>sie</p3n> + </e> + <e l="en"> + <s1>I</s1> + <s2>you</s2> + <s3f>he</s3f> + <s3m>she</s3m> + <s3n>it</s3n> + <p1>we</p1> + <p2>you</p2> + <p3f common="1">they</p3f> + </e> + <e l="fr"> + <s1>je</s1> + <s2>tu</s2> + <s3f>elle</s3f> + <s3m>il</s3m> + <p1>nous</p1> + <p2>vous</p2> + <p3f>elles</p3f> + <p3m>ils</p3m> + </e> + </conjugation> + + <options> + <sort on="1"/> + </options> + + <type> + <desc no="1">Mein Typ 1</desc> + <desc no="2">Mein Typ 2</desc> + <desc no="3">Mein Typ 3</desc> + </type> + + <e m="3" s="1" t="v"><o width="246" l="de" q="o" y="-"> + <conjugation> + <t n="PrSi"><s1>schwimme</s1><s2>du schwimmst</s2><p1>schwimmen</p1></t> + <t n="PaSi"><s1>schwamm</s1><s2>schwammst</s2></t> + </conjugation> + gehen</o><t width="246" l="en" q="t" u="Am:anat:biol:contp"> + <conjugation> + <t n="PrSi"><s1>go</s1></t> + <t n="PaSi"><s1>went</s1></t> + <t n="PaPa"><s1>have gone</s1></t> + </conjugation> + go</t><t width="252" l="fr">aller</t></e> + <e m="4"><o y="-" t="n:m">Klotz</o><t p="tschank" t="n">chunk</t><t g="3;1" c="1;11" b="1;1" t="n">bloc</t></e> + <e m="4" t="aj"><o> + <comparison> + <l1>gut</l1><l2>besser</l2><l3>am besten</l3> + </comparison> + gut</o><t> + <comparison> + <l1>good</l1><l2>better</l2><l3>best</l3> + </comparison> + good</t><t> + <comparison> + <l1>bon</l1><l2>meilleur</l2><l3>le meilleur</l3> + </comparison> + bon</t></e> + <e m="2"><o t="n:m">Knöchel</o><t p="nackls" t="n">knuckles</t><t g="2;3" c="1;1" b="1;1" t="n">cheville</t></e> + <e m="1" t="aj"><o> + <comparison> + <l1>mild</l1><l2>milder</l2><l3>am mildesten</l3> + </comparison> + mild</o><t>balmy</t><t g="2;4" c="1;1" b="1;1">doux</t></e> + <e m="1" t="n"><o>Unheil, Schaden</o><t p="mistschif">mischief</t><t g="4;1" c="1;1" b="1;1">détriment</t></e> + <e m="3" t="#1"><o>starrsinnig</o><t>opinionated</t><t g="2;3" c="1;1" b="1;1">entêté</t></e> + <e m="2" t="n"><o y="-">Gunst, Gefallen</o><t y="-">favour</t><t g="3;2" c="1;1" b="1;1">faveur</t></e> + <e m="2" t="ar"><o y="-">Kniebeugen</o><t u="npr">genuflect</t><t g="4;1" c="1;1" b="1;1">flexion de genoux</t></e> + <e m="1" s="1" t="v"><o>behindern</o><t> + <conjugation> + <t n="PrSi"><s1>encumber</s1><s2>encumber</s2><p1>encumber</p1></t> + </conjugation> + encumber</t><t g="2;3" c="1;1" b="1;1">gêner</t></e> + <e m="4"><o>stattlich</o><t>handsome</t><t g="3;2" c="1;1" b="1;1">imposant</t></e> + <e m="4"><o t="n:m">Saft</o><t t="n">sap</t><t g="3;2" c="1;1" b="1;1" t="n:m">jus</t></e> + <e m="2" t="#2"><o>schwerfällig, mühsam</o><t p="leibrd">laboured</t><t g="1;4" c="1;1" b="1;1">lourd</t></e> + <e m="3"><o>niedlich, ordentlich</o><t p="niit">neat</t><t g="3;2" c="1;1" b="1;1">mignon</t></e> + <e m="3"><o t="n:f">Erbse</o><t p="pi" t="n">pea</t><t g="1;4" c="1;1" b="1;1" t="n:m">pois</t></e> + <e m="4"><o t="n:m">Talg</o><t t="n">tallow</t><t g="2;3" c="2;3" b="1;1" t="n">suif</t></e> + <e m="4" t="#2"><o y="-">gänzlich</o><t y="-">utterly</t><t g="1;4" c="1;1" b="1;1">tout à fait</t></e> + <e m="4" s="1" t="v"><o>bezwingen</o><t> + <conjugation> + <t n="PrSi"><s1>quell</s1></t> + </conjugation> + quell</t><t g="4;1" c="1;1" b="1;1">vaincre</t></e> + <e m="1"><o>verblüfft</o><t g="1;0" c="1;0" d="1010163035;0">taken aback</t><t g="1;0" c="1;0" b="1;0">ébahi</t></e> + <e m="1"><o t="n:m">Verfall</o><t g="1;0" c="1;0" d="1010165496;0" t="n">decline</t><t g="1;4" c="1;1" b="1;1" t="n">échéance</t></e> +</kvtml> diff --git a/kvoctrain/kvoctrain/examples/sample-en.kvtml b/kvoctrain/kvoctrain/examples/sample-en.kvtml new file mode 100644 index 00000000..64fa90a2 --- /dev/null +++ b/kvoctrain/kvoctrain/examples/sample-en.kvtml @@ -0,0 +1,205 @@ +<?xml version="1.0"?> +<!doctype kvtml system "kvoctrain.dtd"> +<!-- +This is a machine generated file. +Be careful when editing here. + +Short definition: + +lesson lesson group + desc name + %no its index + %query is in query selection + %current is current lesson +type type group + desc name + %no its index +e entry of dictionary + %s is selected + %m lesson member + %t common expression type + o original + %q in query ("o" is given, "t" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type (see QueryManager.h) + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + t translation .. + %q in query ("t" is given, "o" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + + %d last query date (from;to) + %w dito, compressed and deprecated + %g grade (from;to) + %c count (from;to) + %b bad count (from;to) + + +Valid xml means: + - Close all tags + - Keep proper hierarchy + - All attributes are quoted + +-- +> +<kvtml + encoding="UTF-8" + generator="kvoctrain v0.8.0" + cols="3" + lines="20" + title="Sample vocabulary file" + author="Ewald Arnold"> + + <lesson width="123"> + <desc no="1">Lesson 1</desc> + <desc no="2">Lesson 2</desc> + <desc no="3">Lesson 3</desc> + <desc no="4">Lesson 4</desc> + </lesson> + + <article> + <e l="de"> + <fd>die</fd> + <fi>eine</fi> + <md>der</md> + <mi>einer</mi> + <nd>das</nd> + <ni>ein</ni> + </e> + <e l="en"> + <fd>the</fd> + <fi>a</fi> + <md>the</md> + <mi>a</mi> + <nd>the</nd> + <ni>a</ni> + </e> + <e l="fr"> + <fd>la</fd> + <fi>une</fi> + <md>le</md> + <mi>un</mi> + </e> + </article> + + <conjugation> + <e l="de"> + <s1>ich</s1> + <s2>du</s2> + <s3f>sie</s3f> + <s3m>er</s3m> + <s3n>es</s3n> + <p1>wir</p1> + <p2>ihr</p2> + <p3f common="1">sie</p3f> + <p3m>sie</p3m> + <p3n>sie</p3n> + </e> + <e l="en"> + <s1>I</s1> + <s2>you</s2> + <s3f>he</s3f> + <s3m>she</s3m> + <s3n>it</s3n> + <p1>we</p1> + <p2>you</p2> + <p3f common="1">they</p3f> + </e> + <e l="fr"> + <s1>je</s1> + <s2>tu</s2> + <s3f>elle</s3f> + <s3m>il</s3m> + <p1>nous</p1> + <p2>vous</p2> + <p3f>elles</p3f> + <p3m>ils</p3m> + </e> + </conjugation> + + <options> + <sort on="1"/> + </options> + + <type> + <desc no="1">My Type 1</desc> + <desc no="2">My Type 2</desc> + <desc no="3">My Type 3</desc> + </type> + + <e m="4" t="#2"><o width="246" l="de" q="t">gänzlich</o><t width="246" l="en" q="o" g="4;0" c="17;0" b="6;0" d="934731325;0">utterly</t><t width="249" l="fr" g="1;4" c="1;1" b="1;1">tout à fait</t></e> + <e m="4"><o t="n:m">Talg</o><t g="1;2" c="4;1" d="934731796;0" t="n">tallow</t><t g="2;3" c="2;3" b="1;1" t="n">suif</t></e> + <e m="1"><o>verblüfft</o><t g="7;1" c="9;2" b="2;1" d="977077597;961317468">taken aback</t><t g="1;1" c="1;1" b="1;0" d="0;977075246">ébahi</t></e> + <e m="4"><o t="n:m">Saft</o><t g="3;4" c="4;2" d="934731800;0" t="n">sap</t><t g="3;2" c="1;1" b="1;1" t="n:m">jus</t></e> + <e m="4" s="1" t="v"><o>bezwingen</o><t g="1;2" c="1;3" d="934675200;0"> + <conjugation> + <t n="PrSi"><s1>quell</s1></t> + </conjugation> + quell</t><t g="4;1" c="1;1" b="1;1">vaincre</t></e> + <e m="3"><o t="n:f">Erbse</o><t g="2;2" c="5;1" b="1;0" d="938974981;0" p="pi" t="n">pea</t><t g="1;4" c="1;1" b="1;1" t="n:m">pois</t></e> + <e m="3" t="#1"><o>starrsinnig</o><t g="4;0" c="5;0" b="1;0" d="934731793;0">opinionated</t><t g="2;3" c="1;1" b="1;1">entêté</t></e> + <e m="3"><o>niedlich, ordentlich</o><t g="4;0" c="4;0" d="934675200;0" p="niit">neat</t><t g="3;2" c="1;1" b="1;1">mignon</t></e> + <e m="3" t="n"><o>Unheil, Schaden</o><t g="2;0" c="2;0" d="934675200;0" p="mistschif">mischief</t><t g="4;1" c="1;1" b="1;1">détriment</t></e> + <e m="2" t="#2"><o>schwerfällig, mühsam</o><t g="4;1" c="5;1" b="1;0" d="934675200;949757271" p="leibrd">laboured</t><t g="1;4" c="1;1" b="1;1">lourd</t></e> + <e m="2"><o t="n:m">Knöchel</o><t g="4;1" c="4;1" d="934675200;949757271" p="nackls" t="n">knuckles</t><t g="2;3" c="1;1" b="1;1" t="n">cheville</t></e> + <e m="4"><o>stattlich</o><t g="2;0" c="4;0" d="934335883;0">handsome</t><t g="3;2" c="1;1" b="1;1">imposant</t></e> + <e m="4" t="aj"><o> + <comparison> + <l1>gut</l1><l2>besser</l2><l3>am besten</l3> + </comparison> + gut</o><t> + <comparison> + <l1>good</l1><l2>better</l2><l3>best</l3> + </comparison> + good</t><t> + <comparison> + <l1>bon</l1><l2>meilleur</l2><l3>le meilleur</l3> + </comparison> + bon</t></e> + <e m="3" s="1" t="v"><o> + <conjugation> + <t n="PrSi"><s1>schwimme</s1><s2>du schwimmst</s2></t> + <t n="PaSi"><s1>schwamm</s1><s2>schwammst</s2></t> + </conjugation> + gehen</o><t> + <conjugation> + <t n="PrSi"><s1>go</s1></t> + <t n="PaSi"><s1>went</s1></t> + <t n="PaPa"><s1>have gone</s1></t> + </conjugation> + go</t><t>aller</t></e> + <e m="2"><o t="n:f">Kniebeugen</o><t g="3;1" c="2;1" d="934731856;949757271" t="n">genuflect</t><t g="4;1" c="1;1" b="1;1" t="n">flexion de genoux</t></e> + <e m="2" t="n"><o>Gunst, Gefallen</o><t g="1;1" c="4;1" d="934731795;949757271">favour</t><t g="3;2" c="1;1" b="1;1">faveur</t></e> + <e m="1" s="1" t="v"><o>behindern</o><t g="4;6" c="6;6" b="1;0" d="977077375;982000284"> + <conjugation> + <t n="PrSi"><s1>encumber</s1><s2>encumber</s2><p1>encumber</p1></t> + </conjugation> + encumber</t><t g="2;3" c="1;1" b="1;1">gêner</t></e> + <e m="1"><o t="n:m">Verfall</o><t g="1;2" c="7;2" b="1;0" d="961317477;976221514" t="n">decline</t><t g="1;4" c="1;1" b="1;1" t="n">échéance</t></e> + <e m="1"><o t="n:m">Klotz</o><t g="1;2" c="3;3" b="1;0" d="961317457;982000304" p="tschank" t="n">chunk</t><t g="3;1" c="1;11" b="1;1" t="n">bloc</t></e> + <e m="1" t="aj"><o> + <comparison> + <l1>mild</l1><l2>milder</l2><l3>am mildesten</l3> + </comparison> + mild</o><t g="2;1" c="4;3" b="1;0" d="976221574;961317485">balmy</t><t g="2;5" c="1;2" b="1;1" d="0;976221651">doux</t></e> +</kvtml> + diff --git a/kvoctrain/kvoctrain/examples/sample-template-ascii.kvtml b/kvoctrain/kvoctrain/examples/sample-template-ascii.kvtml new file mode 100644 index 00000000..fb590851 --- /dev/null +++ b/kvoctrain/kvoctrain/examples/sample-template-ascii.kvtml @@ -0,0 +1,165 @@ +<?xml version="1.0"?> +<!doctype kvtml system "kvoctrain.dtd"> +<!-- +This is a machine generated file. +Be careful when editing here. + +Short definition: + +lesson lesson group + desc name + %no its index + %query is in query selection + %current is current lesson +type type group + desc name + %no its index +e entry of dictionary + %s is selected + %m lesson member + %t common expression type + o original + %q in query ("o" is given, "t" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type (see QueryManager.h) + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + t translation .. + %q in query ("t" is given, "o" is wanted) + %l language code + %r remark + %p pronunciation + %width column width + %t expression type + %tf false friend from + %ff false friend to + %a antonym + %y synonym + %x example + %u usage label + %h paraphrase + + %d last query date (from;to) + %w dito, compressed and deprecated + %g grade (from;to) + %c count (from;to) + %b bad count (from;to) + + +Valid xml means: + - Close all tags + - Keep proper hierarchy + - All attributes are quoted + +-- +> +<kvtml + encoding="UTF-8" + generator="kvoctrain v0.8.0" + cols="2" + lines="6" + title="Example file: your language - English" + author="Your Name" + license="Your License" + remark="Your remark about the document"> + + <lesson width="172"> + <desc no="1">Lesson one</desc> + <desc no="2">Lesson two</desc> + <desc no="3">Lesson three</desc> + <desc no="4">Lesson four</desc> + </lesson> + + <article> + <e l="gb"> + <fd>die</fd> + <fi>eine</fi> + <md>der</md> + <mi>einer</mi> + <nd>das</nd> + <ni>ein</ni> + </e> + <e l="en"> + <fd>fd en</fd> + <fi>fi en</fi> + <md>md en</md> + <mi>mi en</mi> + <nd>nd en</nd> + <ni>ni en</ni> + </e> + </article> + + <conjugation> + <e l="gb"> + <s1>ich</s1> + <s2>du</s2> + <s3f>sie</s3f> + <s3m>er</s3m> + <s3n>es</s3n> + <p1>wir</p1> + <p2>ihr</p2> + <p3f common="1">sie</p3f> + <p3m>sie</p3m> + <p3n>sie</p3n> + </e> + <e l="en"> + <s1>I</s1> + <s2>you</s2> + <s3f>he</s3f> + <s3m>she</s3m> + <s3n>it</s3n> + <p1>we</p1> + <p2>you</p2> + <p3f common="1">they</p3f> + </e> + </conjugation> + + <options> + <sort on="1"/> + </options> + + <type> + <desc no="1">grammar type a</desc> + <desc no="2">grammer type b</desc> + </type> + + <tense> + <desc no="1">Special tense</desc> + </tense> + + <usage> + <desc no="1">slang usage</desc> + <desc no="2">professional usage</desc> + </usage> + + <e m="1" t="v:ir"><o width="344" l="gb" q="t">encumber</o><t width="348" l="en" q="o">encumber</t></e> + <e m="1" t="n:f"><o y="-">pea</o><t p="pi">pea</t></e> + <e m="2" t="v:re"><o y="-">go</o><t>go</t></e> + <e m="2" t="aj"><o u="#1:#2"> + <comparison> + <l1>gut</l1><l2>besser</l2><l3>am besten</l3> + </comparison> + good</o><t> + <comparison> + <l1>good</l1><l2>better</l2><l3>best</l3> + </comparison> + good</t></e> + <e m="3" t="aj"><o> + <comparison> + <l1>bad</l1><l2>worse</l2><l3>worst</l3> + </comparison> + bad</o><t> + <comparison> + <l1>bad</l1><l2>worse</l2><l3>worst</l3> + </comparison> + bad</t></e> + <e m="3" t="#1"><o u="Am:anat">utterly</o><t>utterly</t></e> +</kvtml> diff --git a/kvoctrain/kvoctrain/kv_resource.h b/kvoctrain/kvoctrain/kv_resource.h new file mode 100644 index 00000000..6f704913 --- /dev/null +++ b/kvoctrain/kvoctrain/kv_resource.h @@ -0,0 +1,73 @@ +/*************************************************************************** + + common #defines for kvoctrain gui + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 RESSOURCE_H +#define RESSOURCE_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <klocale.h> + +/////////////////////////////////////////////////////////////////// +// kv_resource.h -- contains macros used for commands +#define KV_EXTRA_COLS 2 // add col for lesson number + +#define KV_COL_LESS 0 // col: lesson number +#define KV_COL_MARK 1 // col: mark +#define KV_COL_ORG 2 // col: original +#define KV_COL_TRANS 3 // col: first translation + +//#define IDS_DEFAULT (doc && doc->isModified() ? " * Ready." : " Ready.") +static const char *IDS_DEFAULT = I18N_NOOP("Ready."); + +/////////////////////////////////////////////////////////////////// +// header-menu entries +#define IDH_NULL 0 +#define IDH_REMOVE 1 +#define IDH_APPEND 2 +#define IDH_START_QUERY 3 +#define IDH_RESET_GRADE 4 +#define IDH_CREATE_LESSON 5 +#define IDH_SET_LANG 6 +#define IDH_SORT_COL_ALPHA 7 +#define IDH_SORT_COL_NUM 8 +#define IDH_START_MULTIPLE 9 +#define IDH_START_ARTICLE 10 +#define IDH_START_VERB 11 +#define IDH_START_ADJECTIVE 12 +#define IDH_START_SYNONYM 13 +#define IDH_START_ANTONYM 14 +#define IDH_START_EXAMPLE 15 +#define IDH_START_PARAPHRASE 16 +#define ID_RESUME_QUERY 13070 +#define ID_RESUME_MULTIPLE 13110 + + +#endif // RESOURCE_H + diff --git a/kvoctrain/kvoctrain/kva_clip.cpp b/kvoctrain/kvoctrain/kva_clip.cpp new file mode 100644 index 00000000..fdbb2744 --- /dev/null +++ b/kvoctrain/kvoctrain/kva_clip.cpp @@ -0,0 +1,234 @@ +/*************************************************************************** + + clipboard part of kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kvoctrain.h" + +#include <qclipboard.h> + +#include <klineedit.h> +#include <klocale.h> + +#include "prefs.h" +#include <algorithm> +using namespace std; + +void kvoctrainApp::slotSmartSearchClip() +{ + QString s; + QString entries = QApplication::clipboard()->text(); + + if (!entries.isEmpty()) { + int pos = entries.find ('\n'); // search for a line end + if (pos < 0) + pos = entries.find ('\r'); + + if (pos < 0) // just first "line" + s = entries; + else + s = entries.left(pos); + + searchpos = 0; // search from beginning + searchstr = s.stripWhiteSpace(); // in case RETURN is pressed + searchLine->setFocus(); + searchLine->setText (searchstr); + } + else + searchLine->setFocus(); +} + + +vector<int> kvoctrainApp::getCsvOrder(kvoctrainDoc *doc) +{ + vector<int> csv_order; + QStringList lang_order = Prefs::pasteOrder(); + + if (!Prefs::useCurrent()) + { + if (/*lang_order &&*/ lang_order.count() != 0) { + for (int i = 0; i < (int) lang_order.count(); i++) + { + int j = doc->findIdent((lang_order)[i]); + if (j >= 0) + csv_order.push_back (j); + else + csv_order.push_back (-1); + } + } + } +/* + for (int i = 0; i < csv_order.size(); i++) + cout << csv_order[i] << " "; + cout << endl; +*/ + +/* perhaps skip missing ?? + for (int i = csv_order.size()-1; i >= 0; i--) + if (csv_order[i] == -1) + csv_order.erase(csv_order.begin() + i); +*/ + // append indices from doc if no order given + for (int i = 0; i < doc->numLangs(); i++) + if (::find (csv_order.begin(), csv_order.end(), i) == csv_order.end()) + csv_order.push_back(i); +/* + if (csv_order.size() > doc->numLangs() ) + csv_order.erase(csv_order.begin() + doc->numLangs(), csv_order.end()); +*/ + + // remove trailing garbage + for (int i = csv_order.size()-1; i >= 0; i--) { + if (csv_order[i] != -1) + break; + else + csv_order.erase(csv_order.begin() + i); + } + + return csv_order; +} + + +void kvoctrainApp::slotEditCopy() +{ + slotStatusMsg(i18n("Copying selection to clipboard...")); + + QApplication::setOverrideCursor( waitCursor ); + QString exp; + QString s; + + vector <int> csv_order = getCsvOrder(doc); + + KVocTrainTable *table = view->getTable(); + + for (int j = table->numRows()-1; j >= 0; j--) { + if (table->isRowSelected(j)) + { + kvoctrainExpr *expr = table->getRow(j); + if (expr == 0 ) return; + + bool sep = false; + for (int i = 0; i < (int) csv_order.size(); i++) { + if (!sep) + sep = true; + else + exp += Prefs::separator(); + + if (csv_order[i] >= 0) { + if (csv_order[i] == 0) + exp += expr->getOriginal(); + else + exp += expr->getTranslation(csv_order[i]); + } + } + } + if (!exp.isEmpty()) + exp += '\n'; + } + if (!exp.isEmpty()) { +#if defined(_WS_X11_) +// disconnect(QApplication::clipboard(),SIGNAL(dataChanged()),this,0); +#endif + QApplication::clipboard()->setText(exp); +#if defined(_WS_X11_) +// connect(QApplication::clipboard(),SIGNAL(dataChanged()), this,SLOT(clipboardChanged())); +#endif + } + + QApplication::restoreOverrideCursor(); + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotEditPaste() +{ + slotStatusMsg(i18n("Inserting clipboard contents...")); + + QApplication::setOverrideCursor( waitCursor ); + QString s; + QString entries = QApplication::clipboard()->text(); + + vector <int> csv_order = getCsvOrder(doc); + + bool changed = false; + QString num; +// view->setView(0, langset, gradecols); + while (!entries.isEmpty()) { + int pos = entries.find ('\n'); // search for a line end + if (pos < 0) { + pos = entries.find ('\r'); // mac style ? + } + + if (pos < 0) { + s = entries; + entries = ""; + } + else { + s = entries.left(pos); + entries.remove (0, pos+1); + } + + // similar block in kvd_csv.cpp::loadFromCsv() + + if (!s.stripWhiteSpace().isEmpty()) { + if (Prefs::pasteOrder().count() != 0) { + kvoctrainExpr bucket (s, Prefs::separator(), act_lesson); + kvoctrainExpr expr; + expr.setLesson(act_lesson); + // now move columns according to paste-order + QString s; + for (int i = 0; i < (int) csv_order.size(); i++) { + if (csv_order[i] >= 0) { + if (i == 0) + s = bucket.getOriginal(); + else + s = bucket.getTranslation(i); + + if (csv_order[i] == 0) + expr.setOriginal(s); + else + expr.setTranslation(csv_order[i], s); + } + } + changed = true; + doc->appendEntry (&expr); + } + else { + kvoctrainExpr expr (s, Prefs::separator(), act_lesson); + changed = true; + doc->appendEntry (&expr); + } + } + } + + if (changed) { + doc->setModified(); + view->getTable()->updateContents(view->getTable()->numRows()-1, KV_COL_ORG); + } + + QApplication::restoreOverrideCursor(); + slotStatusMsg(IDS_DEFAULT); +} + + diff --git a/kvoctrain/kvoctrain/kva_config.cpp b/kvoctrain/kvoctrain/kva_config.cpp new file mode 100644 index 00000000..b5376c1e --- /dev/null +++ b/kvoctrain/kvoctrain/kva_config.cpp @@ -0,0 +1,172 @@ +/*************************************************************************** + + configuration part of kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004, 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qfile.h> + +#include "kvoctrain.h" +#include <kvoctraincore.h> +#include "common-dialogs/ProgressDlg.h" +#include "prefs.h" +#include "languagesettings.h" +#include "presettings.h" + +void kvoctrainApp::saveOptions() +{ + KConfig *config = KApplication::kApplication()->config(); + fileOpenRecent->saveEntries(config, "Recent Files"); + + if (view) + { + Prefs::setCurrentRow(view->getTable()->currentRow()); + Prefs::setCurrentCol(view->getTable()->currentColumn()); + } + /* + Prefs::setNumPreSetting(presettings.size()); + for (int i = 0 ; i < (int) presettings.size(); i++) + { + PreSettings preSettings(QString::number(i)); + preSettings.setName(presettings[i].name); + preSettings.setQuery(presettings[i].query_set); + preSettings.setThreshold(presettings[i].thresh_set); + preSettings.setBlocking(presettings[i].block_set); + preSettings.writeConfig(); + } + */ + saveLanguages(); + Prefs::writeConfig(); +} + +void kvoctrainApp::saveLanguages() +{ + Prefs::setNumLangSet(langset.size()); + for (int i = 0 ; i < (int) langset.size(); i++) + { + LanguageSettings languageSettings(QString::number(i)); + languageSettings.setShortId(langset.shortId(i)); + languageSettings.setShort2Id(langset.shortId2(i)); + languageSettings.setLongId(langset.longId(i)); + languageSettings.setPixmapFile(langset.PixMapFile(i)); + languageSettings.setKeyboardLayout(langset.keyboardLayout(i)); + languageSettings.writeConfig(); + } +} + +void kvoctrainApp::readOptions() +{ + KConfig *config = KApplication::kApplication()->config(); + fileOpenRecent->loadEntries(config, "Recent Files"); + /* + int ls = Prefs::numPreSetting(); + for (int i = 0 ; i < ls; i++) + { + PreSettings preSettings(QString::number(i)); + preSettings.readConfig(); + presettings.push_back(PreSetting(preSettings.name(), preSettings.query(), + preSettings.threshold(), preSettings.blocking())); + } + */ + readLanguages(); +} + +void kvoctrainApp::readLanguages() +{ + langset.clear(); + int ls = Prefs::numLangSet(); + for (int i = 0 ; i < ls; i++) + { + LanguageSettings languageSettings(QString::number(i)); + languageSettings.readConfig(); + + QString shortId = languageSettings.shortId(); + if (shortId.stripWhiteSpace().length() == 0) { + shortId.setNum (i); + shortId.insert (0, "id"); + } + + QString longId = languageSettings.longId(); + if (longId.stripWhiteSpace().length() == 0) { + longId.setNum (i); + longId.insert (0, "ident"); + } + + langset.addSet (shortId, longId, languageSettings.pixmapFile(), languageSettings.short2Id(), + languageSettings.keyboardLayout()); + } +} +void kvoctrainApp::saveProperties(KConfig *config ) +{ + saveOptions(); + if (doc) { + config->writeEntry(CFG_FILENAME,doc->URL().path()); + config->writeEntry(CFG_TITLE,doc->getTitle()); + config->writeEntry(CFG_MODIFIED,doc->isModified()); + + config->writeEntry(CFG_QUERYMODE, querymode); + + QString filename=doc->URL().path(); + QString tempname = kapp->tempSaveName(filename); + saveDocProps(doc); + doc->saveAs(this, KURL(tempname), doc->getTitle(), kvoctrainDoc::automatic); + } +} + + +void kvoctrainApp::readProperties(KConfig *config) +{ + querymode = config->readBoolEntry(CFG_QUERYMODE, 0); + + QString filename = config->readEntry(CFG_FILENAME); + QString title = config->readEntry(CFG_TITLE); + bool modified = config->readBoolEntry(CFG_MODIFIED,false); + if( modified ){ + bool b_canRecover; + QString tempname = kapp->checkRecoverFile(filename,b_canRecover); + + if(b_canRecover){ + pdlg = new ProgressDlg(QString(), QString(), kapp->makeStdCaption("")); + pdlg->show(); + doc = new kvoctrainDoc(this, KURL(tempname)); + removeProgressBar(); + doc->setModified(); + doc->setTitle(title); + doc->setURL(KURL(filename)); + setCaption(kapp->makeStdCaption(doc->getTitle(), false, doc->isModified())); + QFile::remove(tempname); + } + } + else if(!filename.isEmpty()){ + pdlg = new ProgressDlg (QString(), QString(), + kapp->makeStdCaption("")); + pdlg->show(); + doc = new kvoctrainDoc(this, KURL(filename)); + removeProgressBar(); + setCaption(kapp->makeStdCaption(doc->getTitle(), false, doc->isModified())); + } + + show(); + kapp->setTopWidget(this); + kapp->setMainWidget( this ); +} + diff --git a/kvoctrain/kvoctrain/kva_header.cpp b/kvoctrain/kvoctrain/kva_header.cpp new file mode 100644 index 00000000..2aad63c3 --- /dev/null +++ b/kvoctrain/kvoctrain/kva_header.cpp @@ -0,0 +1,570 @@ +/*************************************************************************** + + header buttons part of kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/************x*************************************************************** + * * + * 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 "kvoctrain.h" +#include "query-dialogs/RandomQueryDlg.h" +#include "query-dialogs/MCQueryDlg.h" +#include "query-dialogs/AdjQueryDlg.h" +#include "query-dialogs/VerbQueryDlg.h" +#include "query-dialogs/ArtQueryDlg.h" +#include "query-dialogs/SimpleQueryDlg.h" + + +#include <kcombobox.h> +#include <klocale.h> +#include <kdebug.h> +#include <kstandarddirs.h> +#include <kiconloader.h> + +static const char *SORT_ALPHA = I18N_NOOP("&Sort alphabetically"); +static const char *SORT_NUM = I18N_NOOP("Sort by &index"); + +void kvoctrainApp::slotHeaderMenu(int header, int x, int y) /*FOLD00*/ +{ + delete header_m; + header_m = 0; + + if (header == KV_COL_LESS) { + header_m = new QPopupMenu(); + header_m->insertItem(SmallIconSet("sort_incr"), i18n(SORT_ALPHA), (header << 16) | IDH_SORT_COL_ALPHA); + header_m->insertItem(SmallIconSet("sort_num"), i18n(SORT_NUM), (header << 16) | IDH_SORT_COL_NUM); + + connect (header_m, SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect (header_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + + header_m->exec(QPoint (x, y)); + return; + } + + header -= KV_EXTRA_COLS; // adjust doc == header button + + vector<QString> names; + QString curr_lang; + QString id = header == 0 ? doc->getOriginalIdent() + : doc->getIdent(header); + + if (langset.indexShortId(id) >= 0) + curr_lang = langset.longId(langset.indexShortId(id)); + + // select one of the available languages for the column + QPopupMenu *langs_m = new QPopupMenu(); + // hack: ID => header-id + language + + for (int i = 0; i < (int) langset.size(); i++) { + if(langset.longId(i).isEmpty() ) + names.push_back(langset.shortId(i)); + else + names.push_back(langset.longId(i)); + } + + for (int i = 0; i < (int) langset.size(); i++) { + if( !langset.PixMapFile(i).isEmpty() + && !langset.longId(i).isEmpty() ) + langs_m->insertItem(QPixmap(langset.PixMapFile(i)), names[i], + (header << 16) | (i << (16+8)) | IDH_SET_LANG); + else + langs_m->insertItem(names[i], + (header << 16) | (i << (16+8)) | IDH_SET_LANG); + } + connect (langs_m, SIGNAL(activated(int)), this, SLOT(slotSetHeaderProp(int))); + connect (langs_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + + header_m = new QPopupMenu(); + + if (header != KV_COL_ORG - KV_EXTRA_COLS ) { + header_m->insertItem(SmallIconSet("run_query"), i18n("Create Random &Query"), (header << 16) | IDH_START_QUERY); + header_m->insertItem(SmallIconSet("run_multi"), i18n("Create &Multiple Choice"), (header << 16) | IDH_START_MULTIPLE); + header_m->setItemEnabled((header << 16) | IDH_START_MULTIPLE, doc->numLangs() > 1); + header_m->setItemEnabled((header << 16) | IDH_START_QUERY, doc->numLangs() > 1); + header_m->insertSeparator(); + header_m->insertItem(i18n("&Verbs"), (header << 16) | IDH_START_VERB); + header_m->insertItem(i18n("&Articles"), (header << 16) | IDH_START_ARTICLE); + header_m->insertItem(i18n("&Comparison Forms"), (header << 16) | IDH_START_ADJECTIVE); + header_m->insertSeparator(); + header_m->insertItem(i18n("S&ynonyms"), (header << 16) | IDH_START_SYNONYM); + header_m->insertItem(i18n("A&ntonyms"), (header << 16) | IDH_START_ANTONYM); + header_m->insertItem(i18n("E&xamples"), (header << 16) | IDH_START_EXAMPLE); + header_m->insertItem(i18n("&Paraphrase"), (header << 16) | IDH_START_PARAPHRASE); + header_m->insertSeparator(); + header_m->insertItem(SmallIconSet("sort_incr"), i18n(SORT_ALPHA), (header+KV_EXTRA_COLS << 16) | IDH_SORT_COL_ALPHA); + header_m->insertItem(SmallIconSet("set_language"), i18n("Set &Language"), langs_m, (2 << 16) | IDH_NULL); + header_m->insertSeparator(); + header_m->insertItem(i18n("Reset &Grades"), (header << 16) | IDH_RESET_GRADE); + header_m->insertItem(SmallIconSet("delete_table_col"), i18n("&Remove Column"), (header << 16) | IDH_REMOVE ); + } + else { + QPopupMenu *query_m = new QPopupMenu(); + QPopupMenu *multiple_m = new QPopupMenu(); + + names.clear(); + for (int j = 1; j < (int) doc->numLangs(); j++) { + int i; + if ((i = langset.indexShortId(doc->getIdent(j))) >= 0) + names.push_back(langset.longId(i)); + else + names.push_back(doc->getIdent(j)); + } + + for (int i = 1; i < (int) doc->numLangs(); i++) { + // show pixmap and long name if available + int j; + if((j = langset.indexShortId(doc->getIdent(i))) >= 0 + && !langset.PixMapFile(j).isEmpty() + && !langset.longId(j).isEmpty() ) { + query_m->insertItem(QPixmap(langset.PixMapFile(j)), i18n("From %1").arg(names[i-1]), + (i << (16+8)) | IDH_START_QUERY); // hack: IDs => header-ids + cmd + } + else { + query_m->insertItem(i18n("From %1").arg(doc->getIdent(i)), (i << (16+8)) | IDH_START_QUERY); + } + } + header_m->insertItem(SmallIconSet("run_query"), i18n("Create Random &Query"), query_m, (3 << 16) | IDH_NULL); + connect (query_m, SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect (query_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + for (int i = 1; i < (int) doc->numLangs(); i++) { + // show pixmap and long name if available + int j; + if((j = langset.indexShortId(doc->getIdent(i))) >= 0 + && !langset.PixMapFile(j).isEmpty() + && !langset.longId(j).isEmpty() ) { + multiple_m->insertItem(QPixmap(langset.PixMapFile(j)), i18n("From %1").arg(names[i-1]), + (i << (16+8)) | IDH_START_MULTIPLE); // hack: IDs => header-ids + cmd + } + else { + multiple_m->insertItem(i18n("From %1").arg(doc->getIdent(i)), (i << (16+8)) | IDH_START_MULTIPLE); + } + } + header_m->insertItem(SmallIconSet("run_multi"), i18n("Create &Multiple Choice"), multiple_m, (4 << 16) | IDH_NULL); + header_m->insertSeparator(); + header_m->insertItem(i18n("Train &Verbs"), (header << 16) | IDH_START_VERB); + header_m->insertItem(i18n("&Article Training"), (header << 16) | IDH_START_ARTICLE); + header_m->insertItem(i18n("&Comparison Training"), (header << 16) | IDH_START_ADJECTIVE); + header_m->insertSeparator(); + header_m->insertItem(i18n("&Synonyms"), (header << 16) | IDH_START_SYNONYM); + header_m->insertItem(i18n("&Antonyms"), (header << 16) | IDH_START_ANTONYM); + header_m->insertItem(i18n("E&xamples"), (header << 16) | IDH_START_EXAMPLE); + header_m->insertItem(i18n("&Paraphrase"), (header << 16) | IDH_START_PARAPHRASE); + connect (multiple_m, SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect (multiple_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + + header_m->insertSeparator(); + header_m->insertItem(SmallIconSet("sort_incr"), i18n(SORT_ALPHA), (header+KV_EXTRA_COLS << 16) | IDH_SORT_COL_ALPHA); + header_m->insertItem(SmallIconSet("set_language"), i18n("Set &Language"), langs_m, (2 << 16) | IDH_NULL); + } + + connect (header_m, SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect (header_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + header_m->exec(QPoint(x, y)); +} + + +void kvoctrainApp::slotSetHeaderProp (int header_and_id) /*FOLD00*/ +{ + int header1 = (header_and_id >> 16) & 0xFF; // org, trans1, trans2, .. + int id = header_and_id >> (16+8); // language ident +//int cmd = header_and_id & 0xFFFF; // always SET_LANG + + if (id >= (int) langset.size()) + return; // ??? + + QString lid = langset.shortId(id); + if (!langset.longId(id).isEmpty() ) + lid = langset.longId(id); + + QString pm = ""; + if (!langset.PixMapFile(id).isEmpty() ) + pm = langset.PixMapFile(id); + + view->setHeaderProp (header1+KV_EXTRA_COLS, lid, pm); + +/* + cout << "shp 1: " << (void*) doc << endl << flush; + for (int i = 0; i < (int) langset.size(); i++) { + cout << " " << EA_LOCAL(langset.shortId(i)) << " " + << EA_LOCAL(langset.longId(i)) << " " + << EA_LOCAL(langset.PixMapFile(i)) << " " + << hex << (const void*) EA_LOCAL(langset.PixMapFile(i)) << endl; + } +*/ + if (header1 > 0) + doc->setIdent(header1, langset.shortId(id)); + else + doc->setOriginalIdent(langset.shortId(id)); +/* + for (int i = 0; i < (int) langset.size(); i++) { + cout << " " << EA_LOCAL(langset.shortId(i)) << " " + << EA_LOCAL(langset.longId(i)) << " " + << EA_LOCAL(langset.PixMapFile(i)) << " " + << hex << (const void*) EA_LOCAL(langset.PixMapFile(i)) << endl; + } +*/ + doc->setModified(); + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotHeaderStatus (int header_and_cmd) /*FOLD00*/ +{ + int header1 = (header_and_cmd >> 16) & 0xFF; + int header2 = header_and_cmd >> (16+8); + int cmd = header_and_cmd & 0xFFFF; + +//cout << header1 << " " << header2 << " " << cmd << endl; + + switch (cmd) { + case IDH_NULL: + break; + + case ID_RESUME_QUERY: + slotStatusHelpMsg(i18n("Resumes random query with existing selection")); + break; + + case ID_RESUME_MULTIPLE: + slotStatusHelpMsg(i18n("Resumes multiple choice with existing selection")); + break; + + case IDH_SORT_COL_ALPHA: + slotStatusHelpMsg(i18n("Sorts column alphabetically up/down")); + break; + + case IDH_SORT_COL_NUM: + slotStatusHelpMsg(i18n("Sorts column by lesson index up/down")); + break; + + case IDH_SET_LANG: { + QString from = langset.longId(header2); + if (from.isEmpty()) + from = langset.shortId(header2); + + QString msg; + if (header1 == 0) { + QString format = i18n("Sets %1 as language for original"); + msg = format.arg(from); + } + else { + QString format = i18n("Sets %1 as language for translation %2"); + msg = format.arg(from).arg(header1); + } + slotStatusHelpMsg(msg); + } + break; + + case IDH_APPEND: { + + QString msg; + if (header1 == 0xFF) { + msg = i18n("Appends a new language"); + slotStatusHelpMsg(msg); + } + else if (header1 < (int) langset.size() ) { + QString from = langset.longId(header1); + QString format = i18n("Appends %1 as new language"); + msg = format.arg(from); + slotStatusHelpMsg(msg); + } + } + break; + + case IDH_REMOVE: { + QString from = header1 ? doc->getIdent(header1) : doc->getOriginalIdent(); + if (!langset.findLongId(from).isEmpty()) + from = langset.findLongId(from); + QString msg; + QString format = i18n("Removes %1 irrevocably from dictionary"); + msg = format.arg(from); + slotStatusHelpMsg(msg); + } + break; + + case IDH_START_QUERY: + case IDH_START_MULTIPLE: { + QString to = header1 ? doc->getIdent(header1) : doc->getOriginalIdent(); + if (!langset.findLongId(to).isEmpty()) + to = langset.findLongId(to); + + QString from = header2 ? doc->getIdent(header2) : doc->getOriginalIdent(); + if (!langset.findLongId(from).isEmpty()) + from = langset.findLongId(from); + + QString msg; + QString format; + + if (doc->numLangs() == 1) { + if (cmd == IDH_START_QUERY) + format = i18n("Creates and starts query to %1"); + else + format = i18n("Creates and starts multiple choice to %1"); + msg = format.arg(to); + } + else { + if (cmd == IDH_START_QUERY) + format = i18n("Creates and starts query from %1 to %2"); + else + format = i18n("Creates and starts multiple choice from %1 to %2"); + msg = format.arg(from).arg(to); + } + + slotStatusHelpMsg(msg); + } + break; + + case IDH_START_VERB: { + slotStatusHelpMsg(i18n("Starts training with verbs")); + } + break; + + case IDH_START_ARTICLE: { + slotStatusHelpMsg(i18n("Starts training with articles")); + } + break; + + case IDH_START_ADJECTIVE: { + slotStatusHelpMsg(i18n("Starts training with adjectives")); + } + break; + + case IDH_START_SYNONYM: { + slotStatusHelpMsg(i18n("Starts training with synonyms")); + } + break; + + case IDH_START_ANTONYM: { + slotStatusHelpMsg(i18n("Starts training with antonyms")); + } + break; + + case IDH_START_EXAMPLE: { + slotStatusHelpMsg(i18n("Starts training with examples")); + } + break; + + case IDH_START_PARAPHRASE: { + slotStatusHelpMsg(i18n("Starts training with paraphrases")); + } + break; + + case IDH_CREATE_LESSON: { + slotStatusHelpMsg(i18n("Creates lesson")); + } + break; + + case IDH_RESET_GRADE: { + QString from = header1 ? doc->getIdent(header1) : doc->getOriginalIdent(); + if (!langset.findLongId(from).isEmpty()) + from = langset.findLongId(from); + QString format = i18n("Resets all properties for %1"); + QString msg = format.arg(from); + slotStatusHelpMsg(msg); + } + break; + + default: + kdError() << "kvoctrainApp::slotHeaderStatus: got unknown command :" << cmd << endl; + } +} + + +void kvoctrainApp::slotHeaderCallBack (int header_and_cmd) /*FOLD00*/ +{ + int header1 = (header_and_cmd >> 16) & 0xFF; + int header2 = header_and_cmd >> (16+8); + int cmd = header_and_cmd & 0xFFFF; + + kdDebug() << header1 << " " << header2 << " " << cmd << endl; + + switch (cmd) { + case IDH_SORT_COL_ALPHA: + view->getTable()->sortByColumn_alpha(header1); + return; + break; + + case IDH_SORT_COL_NUM: + view->getTable()->sortByColumn_index(header1); + return; + break; + } + + if (header1 >= (int) doc->numLangs()) { + kdError() << "header1 >= (int) doc->numLangs()\n"; + return; + } + + if (header2 >= (int) doc->numLangs()) { + kdError() << "header2 >= (int) doc->numLangs()\n"; + return; + } + + switch (cmd) { + case IDH_NULL: + break; + + case ID_RESUME_QUERY: + queryType = QT_Random; + slotRestartQuery(); + break; + + case ID_RESUME_MULTIPLE: + queryType = QT_Multiple; + slotRestartQuery(); + break; + + case IDH_REMOVE: { + QString msg; + QString name; + + name = doc->getIdent(header1); + int i= langset.indexShortId(name); + if ( i >= 0 + && !langset.longId(i).isEmpty() ) + name = langset.longId(i); + + QString format = i18n("You are about to delete a language completely.\n" + "Do you really want to delete \"%1\"?"); + msg = format.arg(name); + + int exit = KMessageBox::warningContinueCancel(this, msg, + kapp->makeStdCaption(""),KStdGuiItem::del()); + if(exit==KMessageBox::Continue) { + doc->removeIdent(header1); + view->setView (doc, langset); + doc->setModified(); + } + } + break; + + case IDH_START_QUERY: + delete randomQueryDlg; + randomQueryDlg = 0; + queryType = QT_Random; + slotStartQuery(header1 ? doc->getIdent(header1) : doc->getOriginalIdent(), + header2 ? doc->getIdent(header2) : doc->getOriginalIdent(), true); + break; + + case IDH_START_MULTIPLE: + delete mcQueryDlg; + mcQueryDlg = 0; + queryType = QT_Multiple; + slotStartQuery(header1 ? doc->getIdent(header1) : doc->getOriginalIdent(), + header2 ? doc->getIdent(header2) : doc->getOriginalIdent(), true); + break; + + case IDH_START_VERB: { + delete verbQueryDlg; + verbQueryDlg = 0; + queryType = QT_Conjugation; + slotStartTypeQuery (header1, QM_VERB); + } + break; + + case IDH_START_ARTICLE: { + delete artQueryDlg; + artQueryDlg = 0; + queryType = QT_Articles; + slotStartTypeQuery (header1, QM_NOUN); + } + break; + + case IDH_START_ADJECTIVE: { + delete adjQueryDlg; + adjQueryDlg = 0; + queryType = QT_Comparison; + slotStartTypeQuery (header1, QM_ADJ); + } + break; + + case IDH_START_SYNONYM: { + delete simpleQueryDlg; + simpleQueryDlg = 0; + slotStartPropertyQuery (header1, QT_Synonym); + } + break; + + case IDH_START_ANTONYM: { + delete simpleQueryDlg; + simpleQueryDlg = 0; + slotStartPropertyQuery (header1, QT_Antonym); + } + break; + + case IDH_START_EXAMPLE: { + delete simpleQueryDlg; + simpleQueryDlg = 0; + slotStartPropertyQuery (header1, QT_Example); + } + break; + + case IDH_START_PARAPHRASE: { + delete simpleQueryDlg; + simpleQueryDlg = 0; + slotStartPropertyQuery (header1, QT_Paraphrase); + } + break; + + case IDH_CREATE_LESSON: + slotCreateLesson(header1); + break; + + case IDH_RESET_GRADE: { + QString msg; + QString name; + QString format; + + if (act_lesson == 0) { + name = doc->getIdent(header1); + int i = langset.indexShortId(doc->getIdent(header1)); + if (i >= 0 + && !langset.longId(i).isEmpty() ) + name = langset.longId(i); + + format = i18n("You are about to reset the knowledge data of a " + "whole language.\n\nDo you really want to reset \"%1\"?"); + } + else { + name = lessons->text(act_lesson); + format = i18n("You are about to reset the knowledge data of a " + "lesson.\n\nDo you really want to reset \"%1\"?"); + } + + msg = format.arg(name); + + int exit = KMessageBox::warningContinueCancel(this, msg, + kapp->makeStdCaption(""),i18n("Reset")); + if(exit==KMessageBox::Continue) { + doc->resetEntry (header1, act_lesson); + doc->setModified(); + view->getTable()->updateContents(); + } + } + break; + + default: + kdError() << "kvoctrainApp::slotHeaderCallBack: got unknown command\n"; + + } + slotStatusMsg(IDS_DEFAULT); +} + + diff --git a/kvoctrain/kvoctrain/kva_init.cpp b/kvoctrain/kvoctrain/kva_init.cpp new file mode 100644 index 00000000..8d8ef995 --- /dev/null +++ b/kvoctrain/kvoctrain/kva_init.cpp @@ -0,0 +1,300 @@ +/*************************************************************************** + + initialisation part of kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kvoctrain.h" + +#include "common-dialogs/ProgressDlg.h" + +#include <qclipboard.h> +#include <qtimer.h> + +#include <klineedit.h> +#include <kcombobox.h> +#include <kstatusbar.h> +#include <kpopupmenu.h> +#include <kiconloader.h> +#include <kstandarddirs.h> +#include <klocale.h> + +#include "prefs.h" + +kvoctrainApp::kvoctrainApp(QWidget *parent, const char *name) +: KMainWindow(parent, name) +{ + doc = 0; + view = 0; + header_m = 0; + btimer = 0; + querymode = false; + shiftActive = false; + altActive = false; + controlActive = false; + act_lesson = 0; + searchpos = 0; + vslide_label = 0; + pron_label = 0; + rem_label = 0; + type_label = 0; + pdlg = 0; + pbar = 0; + m_newStuff = 0; + + simpleQueryDlg = 0; + mcQueryDlg = 0; + verbQueryDlg = 0; + randomQueryDlg = 0; + adjQueryDlg = 0; + artQueryDlg = 0; + entryDlg = 0; + + initStatusBar(); + initActions(); + + readOptions(); + + initDoc(); + initView(); + + int cc = Prefs::currentCol(); + int cr = Prefs::currentRow(); + if (cc <= KV_COL_LESS) + cc = KV_COL_LESS+1; + + view->getTable()->updateContents(cr, cc); + view->getTable()->clearSelection(); + view->getTable()->selectRow(cr); + + editRemoveSelectedArea->setEnabled(view->getTable()->numRows() > 0); + + querying = false; + btimer = new QTimer( this ); + connect( btimer, SIGNAL(timeout()), this, SLOT(slotTimeOutBackup()) ); + if (Prefs::autoBackup()) + btimer->start(Prefs::backupTime() * 60 * 1000, TRUE); +} + + +void kvoctrainApp::initActions() +{ + fileNew = KStdAction::openNew(this, SLOT(slotFileNew()), actionCollection()); + fileNew->setWhatsThis(i18n("Creates a new blank vocabulary document")); + fileNew->setToolTip(fileNew->whatsThis()); + + fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection()); + fileOpen->setWhatsThis(i18n("Opens an existing vocabulary document")); + fileOpen->setToolTip(fileOpen->whatsThis()); + + fileOpenExample = new KAction(i18n("Open &Example..."), "fileopen", 0, this, SLOT(slotFileOpenExample()), actionCollection(), "file_open_example"); + fileOpen->setWhatsThis(i18n("Open a vocabulary document")); + fileOpen->setToolTip(fileOpen->whatsThis()); + + fileGHNS = new KAction(i18n("&Get New Vocabularies..."), "knewstuff", CTRL+Key_G, this, SLOT(slotGHNS()), actionCollection(), "file_ghns"); + fileGHNS->setWhatsThis(i18n("Downloads new vocabularies")); + fileGHNS->setToolTip(fileGHNS->whatsThis()); + + fileOpenRecent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection()); + + fileMerge = new KAction(i18n("&Merge..."), 0, 0, this, SLOT(slotFileMerge()), actionCollection(), "file_merge"); + fileMerge->setWhatsThis(i18n("Merge an existing vocabulary document with the current one")); + fileMerge->setToolTip(fileOpen->whatsThis()); + + fileSave = KStdAction::save(this, SLOT(slotFileSave()), actionCollection()); + fileSave->setWhatsThis(i18n("Save the active vocabulary document")); + fileSave->setToolTip(fileSave->whatsThis()); + + fileSaveAs = KStdAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection()); + fileSaveAs->setWhatsThis(i18n("Save the active vocabulary document with a different name")); + fileSaveAs->setToolTip(fileSaveAs->whatsThis()); + + filePrint = KStdAction::print(this, SLOT(slotFilePrint()), actionCollection()); + filePrint->setWhatsThis(i18n("Print the active vocabulary document")); + filePrint->setToolTip(filePrint->whatsThis()); + + fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection()); + fileQuit->setWhatsThis(i18n("Quit KVocTrain")); + fileQuit->setToolTip(fileQuit->whatsThis()); + + editCopy = KStdAction::copy(this, SLOT(slotEditCopy()), actionCollection()); + editCopy->setWhatsThis(i18n("Copy")); + editCopy->setToolTip(editCopy->whatsThis()); + + editPaste = KStdAction::paste(this, SLOT(slotEditPaste()), actionCollection()); + editPaste->setWhatsThis(i18n("Paste")); + editPaste->setToolTip(editPaste->whatsThis()); + + editSelectAll = KStdAction::selectAll(this, SLOT(slotSelectAll()), actionCollection()); + editSelectAll->setWhatsThis(i18n("Select all rows")); + editSelectAll->setToolTip(editSelectAll->whatsThis()); + + editClearSelection = KStdAction::deselect(this, SLOT(slotCancelSelection()), actionCollection()); + editClearSelection->setWhatsThis(i18n("Deselect all rows")); + editClearSelection->setToolTip(editClearSelection->whatsThis()); + + editSearchFromClipboard = KStdAction::find(this, SLOT(slotSmartSearchClip()), actionCollection()); + editSearchFromClipboard->setWhatsThis(i18n("Search for the clipboard contents in the vocabulary")); + editSearchFromClipboard->setToolTip(editSearchFromClipboard->whatsThis()); + + editAppend = new KAction(i18n("&Append New Entry"), "insert_table_row", "Insert", this, SLOT(slotAppendRow()), actionCollection(),"edit_append"); + editAppend->setWhatsThis(i18n("Append a new row to the vocabulary")); + editAppend->setToolTip(editAppend->whatsThis()); + + editEditSelectedArea = new KAction(i18n("&Edit Selected Area..."), "edit_table_row", "Ctrl+Return", this, SLOT(slotEditRow()), actionCollection(),"edit_edit_selected_area"); + editEditSelectedArea->setWhatsThis(i18n("Edit the entries in the selected rows")); + editEditSelectedArea->setToolTip(editEditSelectedArea->whatsThis()); + + editRemoveSelectedArea = new KAction(i18n("&Remove Selected Area"), "delete_table_row", "Delete", this, SLOT(slotRemoveRow()), actionCollection(),"edit_remove_selected_area"); + editRemoveSelectedArea->setWhatsThis(i18n("Delete the selected rows")); + editRemoveSelectedArea->setToolTip(editRemoveSelectedArea->whatsThis()); + + editSaveSelectedArea = new KAction(i18n("Save E&ntries in Query As..."), KGlobal::iconLoader()->loadIcon("filesaveas", KIcon::Small), 0, this, SLOT(slotSaveSelection()), actionCollection(),"edit_save_selected_area"); + editSaveSelectedArea->setWhatsThis(i18n("Save the entries in the query as a new vocabulary")); + editSaveSelectedArea->setToolTip(editSaveSelectedArea->whatsThis()); + + vocabShowStatistics = new KAction(i18n("Show &Statistics"), "statistics", 0, this, SLOT(slotShowStatist()), actionCollection(),"vocab_show_statistics"); + vocabShowStatistics->setWhatsThis(i18n("Show statistics for the current vocabulary")); + vocabShowStatistics->setToolTip(vocabShowStatistics->whatsThis()); + + vocabAssignLessons = new KAction(i18n("Assign L&essons..."), "rand_less", 0, this, SLOT(slotCreateRandom()), actionCollection(),"vocab_assign_lessons"); + vocabAssignLessons->setWhatsThis(i18n("Create random lessons with unassigned entries")); + vocabAssignLessons->setToolTip(vocabAssignLessons->whatsThis()); + + vocabCleanUp = new KAction(i18n("&Clean Up"), "cleanup", 0, this, SLOT(slotCleanVocabulary()), actionCollection(),"vocab_clean_up"); + vocabCleanUp->setWhatsThis(i18n("Remove entries with same content from vocabulary")); + vocabCleanUp->setToolTip(vocabCleanUp->whatsThis()); + + vocabAppendLanguage = new KSelectAction(i18n("&Append Language"), "insert_table_col", 0, actionCollection(), "vocab_append_language"); + connect(vocabAppendLanguage->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowVocabAppendLanguage())); + connect (vocabAppendLanguage->popupMenu(), SIGNAL(activated(int)), this, SLOT(slotAppendLang(int))); + connect (vocabAppendLanguage->popupMenu(), SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + + vocabSetLanguage = new KSelectAction(i18n("Set &Language"), "set_language", 0, actionCollection(), "vocab_set_language"); + connect(vocabSetLanguage->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowVocabSetLanguage())); + + vocabRemoveLanguage = new KSelectAction(i18n("&Remove Language"), "delete_table_col", 0, actionCollection(), "vocab_remove_language"); + connect(vocabRemoveLanguage->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowVocabRemoveLanguage())); + connect(vocabRemoveLanguage->popupMenu(), SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect(vocabRemoveLanguage->popupMenu(), SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + + vocabDocumentProperties = new KAction(i18n("Document &Properties"), 0, 0, this, SLOT(slotDocProps()), actionCollection(), "vocab_document_properties"); + vocabDocumentProperties->setWhatsThis(i18n("Edit document properties")); + vocabDocumentProperties->setToolTip(vocabAppendLanguage->whatsThis()); + + vocabLanguageProperties = new KAction(i18n("Lan&guage Properties"), 0, 0, this, SLOT(slotDocPropsLang()), actionCollection(), "vocab_language_properties"); + vocabLanguageProperties->setWhatsThis(i18n("Edit language properties in current document")); + vocabLanguageProperties->setToolTip(vocabSetLanguage->whatsThis()); + + lessons = new KComboBox(this); + lessons->setMinimumWidth(160); + connect(lessons, SIGNAL(highlighted(int)), this, SLOT(slotChooseLesson(int))); + lessons->setFocusPolicy(QWidget::NoFocus); + + vocabLessons = new KWidgetAction(lessons, i18n("Lessons"), 0, this, 0, actionCollection(), "vocab_lessons"); + vocabLessons->setWhatsThis(i18n("Choose current lesson")); + vocabLessons->setToolTip(vocabLessons->whatsThis()); + + searchLine = new KLineEdit(this); + searchLine->setFocusPolicy(QWidget::ClickFocus); + connect (searchLine, SIGNAL(returnPressed()), this, SLOT(slotSearchNext())); + connect (searchLine, SIGNAL(textChanged(const QString&)), this, SLOT(slotResumeSearch(const QString&))); + + vocabSearch = new KWidgetAction(searchLine, i18n("Smart Search"), 0, this, 0, actionCollection(), "vocab_search"); + vocabSearch->setAutoSized(true); + vocabSearch->setWhatsThis(i18n("Search vocabulary for specified text ")); + vocabSearch->setToolTip(vocabSearch->whatsThis()); + /* + learningResumeQuery = new KAction(i18n("Resume &Query..."), "run_query", 0, this, SLOT(slotRestartQuery()), actionCollection(),"learning_resume_query"); + //learningResumeQuery->setWhatsThis(i18n("")); + learningResumeQuery->setToolTip(learningResumeQuery->whatsThis()); + + learningResumeMultipleChoice = new KAction(i18n("&Resume Multiple Choice..."), "run_multi", 0, this, SLOT(slotRestartQuery()), actionCollection(),"learning_resume_multiple_choice"); + //learningResumeMultipleChoice->setWhatsThis(i18n("")); + learningResumeMultipleChoice->setToolTip(learningResumeMultipleChoice->whatsThis()); + */ + configApp = KStdAction::preferences(this, SLOT( slotGeneralOptions()), actionCollection()); + configApp->setWhatsThis(i18n("Show the configuration dialog")); + configApp->setToolTip(configApp->whatsThis()); + + /*configQueryOptions = new KAction(i18n("Configure &Query..."), "configure_query", 0, this, SLOT(slotQueryOptions()), actionCollection(),"config_query_options"); + configQueryOptions->setWhatsThis(i18n("Show the query configuration dialog")); + configQueryOptions->setToolTip(configQueryOptions->whatsThis());*/ + + actionCollection()->setHighlightingEnabled(true); + connect(actionCollection(), SIGNAL(actionStatusText(const QString &)), this, SLOT(slotStatusHelpMsg(const QString &))); + //connect(actionCollection(), SIGNAL(actionHighlighted(KAction *, bool)), this, SLOT(slotActionHighlighted(KAction *, bool))); + + if (!initialGeometrySet()) + resize( QSize(550, 400).expandedTo(minimumSizeHint())); + setupGUI(ToolBar | Keys | StatusBar | Create); + setAutoSaveSettings(); + + configToolbar = actionCollection()->action("options_configure_toolbars"); + configToolbar->setWhatsThis(i18n("Toggle display of the toolbars")); + configToolbar->setToolTip(configToolbar->whatsThis()); + + learn_menu = (QPopupMenu*) child( "learning", "KPopupMenu" ); + connect(learn_menu, SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect(learn_menu, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + connect(learn_menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowLearn())); +} + + +void kvoctrainApp::initStatusBar() +{ + type_label = new QLabel(statusBar()); + type_label->setFrameStyle(QFrame::NoFrame); + statusBar()->addWidget(type_label, 150); + + pron_label = new QLabel(statusBar()); + pron_label->setFrameStyle(QFrame::NoFrame); + pron_label->setFont(Prefs::iPAFont()); + statusBar()->addWidget(pron_label, 200); + + rem_label = new QLabel(statusBar()); + rem_label->setFrameStyle(QFrame::NoFrame); + statusBar()->addWidget(rem_label, 150); +} + + +void kvoctrainApp::initDoc( ) +{ + if (fileOpenRecent->items().count() > 0) + doc = new kvoctrainDoc(this, fileOpenRecent->items()[0]); + else + doc = new kvoctrainDoc(this, KURL("")); + + loadDocProps(doc); + if (doc->numLangs() == 0) + doc->appendLang("en"); + connect (doc, SIGNAL (docModified(bool)), this, SLOT(slotModifiedDoc(bool))); + doc->setModified(false); +} + + +void kvoctrainApp::initView() +{ + view = new kvoctrainView(doc, langset, this); + setCentralWidget(view); + slotStatusMsg(IDS_DEFAULT); +} diff --git a/kvoctrain/kvoctrain/kva_io.cpp b/kvoctrain/kvoctrain/kva_io.cpp new file mode 100644 index 00000000..22df3874 --- /dev/null +++ b/kvoctrain/kvoctrain/kva_io.cpp @@ -0,0 +1,697 @@ +/*************************************************************************** + + i/o part of kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <unistd.h> + +#include <qtimer.h> + +#include <kfiledialog.h> +#include <kcombobox.h> +#include <kprogress.h> +#include <krecentdocument.h> +#include <kstatusbar.h> +#include <klocale.h> +#include <kstandarddirs.h> +#include <kdebug.h> +#include <knewstuff/downloaddialog.h> + +#include "kvoctrain.h" +#include "UsageManager.h" +#include "common-dialogs/ProgressDlg.h" +#include <prefs.h> + +static const char *PATTERN_ALL = I18N_NOOP("*|All Files (*)\n"); +static const char *PATTERN_ML = I18N_NOOP("*.kvtml|KVocTrain Markup (*.kvtml)\n"); +static const char *PATTERN_LEX = I18N_NOOP("*.lex|Vocabulary Trainer 5.0 (*.lex)\n"); +static const char *PATTERN_VL = I18N_NOOP("*.vl|KVoclearn (*.vl)\n"); +static const char *PATTERN_QVO = I18N_NOOP("*.qvo|QVocab (*.qvo)\n"); +static const char *PATTERN_VOC = I18N_NOOP("*.voc|Vokabeltrainer (*.voc)\n"); +static const char *PATTERN_CSV = I18N_NOOP("*.csv|Text (*.csv)\n"); +static const char *PATTERN_VCB = I18N_NOOP("*.vocab|Vocabbox (*.vocab)\n"); + +// we can read these +#define FILTER_RPATTERN i18n(PATTERN_ML)+i18n(PATTERN_VCB)+i18n(PATTERN_VOC)+i18n(PATTERN_CSV)+i18n(PATTERN_LEX)+i18n(PATTERN_ALL) + +// we can write these +#define FILTER_WPATTERN i18n(PATTERN_ML)+i18n(PATTERN_VCB)+i18n(PATTERN_CSV)+i18n(PATTERN_LEX)+i18n(PATTERN_ALL) + + +void kvoctrainApp::slotTimeOutBackup() +{ + if (Prefs::autoBackup() && doc && doc->isModified() ) { + slotStatusMsg(i18n("Autobackup in progress")); + slotFileSave(); + } + if (Prefs::backupTime() > 0) + btimer->start(Prefs::backupTime() * 60 * 1000, TRUE); + slotStatusMsg(IDS_DEFAULT); +} + + +bool kvoctrainApp::queryClose() +{ + bool erg = queryExit(); + if (erg) + doc->setModified(false); // avoid double query on exit via system menu + return erg; +} + + +bool kvoctrainApp::queryExit() +{ + saveOptions(); + if (!doc || !doc->isModified() ) return true; + + bool save = (Prefs::autoSave()); //save without asking + + if (!save) + { + int exit = KMessageBox::warningYesNoCancel(this, + i18n("Vocabulary is modified.\n\nSave file before exit?\n"), + kapp->makeStdCaption(""), + KStdGuiItem::save(), KStdGuiItem::discard()); + if (exit==KMessageBox::Yes) { + save = true; // save and exit + } + else if (exit == KMessageBox::No) { + save = false; // dont save but exit + } + else { + return false; // continue work + } + } + + if (save) { + if (!doc->URL().isEmpty()) + slotFileSave(); // save and exit + if (doc->isModified()) + { + // Error while saving or no name + slotFileSaveAs(); + } + } + return true; +} + + +void kvoctrainApp::slotFileQuit() +{ + /////////////////////////////////////////////////////////////////// + // exits the Application + if(queryExit()) + { + doc->setModified(false); // Make sure not to bother about saving again. + kapp->quit(); + } + else + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotProgress(kvoctrainDoc *curr_doc, int percent) +{ + if (pdlg != 0) + pdlg->setValue (curr_doc, percent); + else if (pbar != 0) + pbar->setValue (percent); + kapp->processEvents(); +} + + +void kvoctrainApp::slotFileOpenRecent(const KURL& url) +{ + slotStatusMsg(i18n("Opening file...")); + if (queryExit() && fileOpenRecent->items().count() > 0) + { + fileOpenRecent->setCurrentItem(-1); + loadfileFromPath(url); + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotFileNew() +{ + slotStatusMsg(i18n("Creating new file...")); + + if (queryExit() ) { + view->setView (0, langset); + delete doc; + QString name = ""; + doc = new kvoctrainDoc (this, 0 /*KURL(name)*/); + loadDocProps(doc); + if (doc->numLangs() == 0) { + QString l = "en"; + doc->appendLang(l); + } + view->setView(doc, langset); + view->getTable()->setFont(Prefs::tableFont()); + view->adjustContent(); + connect (doc, SIGNAL (docModified(bool)), this, SLOT(slotModifiedDoc(bool))); + doc->setModified(false); + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotFileOpen() +{ + slotStatusMsg(i18n("Opening file...")); + + if (queryExit() ) { + QString s; + KURL url = KFileDialog::getOpenURL(QString::null, FILTER_RPATTERN, parentWidget(), i18n("Open Vocabulary File")); + loadfileFromPath(url, true); + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::loadfileFromPath(const KURL & url, bool addRecent) +{ + if (!url.path().isEmpty()) + { + view->setView(0, langset); + delete doc; + doc = 0; + + QString format = i18n("Loading %1"); + QString msg = format.arg(url.path()); + + slotStatusMsg(msg); + prepareProgressBar(); + doc = new kvoctrainDoc (this, url); + removeProgressBar(); + loadDocProps(doc); + view->setView(doc, langset); + view->getTable()->setFont(Prefs::tableFont()); + view->adjustContent(); + if (addRecent) + fileOpenRecent->addURL(url) /*addRecentFile (url.path())*/; + connect (doc, SIGNAL (docModified(bool)), this, SLOT(slotModifiedDoc(bool))); + doc->setModified(false); + } +} + +void kvoctrainApp::slotFileOpenExample() +{ + slotStatusMsg(i18n("Opening example file...")); + + if (queryExit() ) { + QString s; + s = locate("data", "kvoctrain/examples/"); + KURL url = KFileDialog::getOpenURL(s, FILTER_RPATTERN, parentWidget(), i18n("Open Example Vocabulary File")); + loadfileFromPath(url, false); + if (doc) + doc->URL().setFileName(QString::null); + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotGHNS() +{ + if (!m_newStuff) + m_newStuff = new KVTNewStuff(this); + m_newStuff->download(); +} + + +void kvoctrainApp::slotFileMerge() +{ + slotStatusMsg(i18n("Merging file...")); + + QString s; + KURL url = KFileDialog::getOpenURL(QString::null, FILTER_RPATTERN, parentWidget(), i18n("Merge Vocabulary File")); + + if (!url.isEmpty() ) { + + QString format = i18n("Loading %1"); + QString msg = format.arg(url.path()); + + slotStatusMsg(msg); + prepareProgressBar(); + kvoctrainDoc *new_doc = new kvoctrainDoc (this, url); + connect (new_doc, SIGNAL (docModified(bool)), this, SLOT(slotModifiedDoc(bool))); + doc->setModified(false); + removeProgressBar(); + + vector<QString> old_names = doc->getLessonDescr(); + vector<QString> new_names = new_doc->getLessonDescr(); + + vector<QString> old_types = doc->getTypeDescr(); + vector<QString> new_types = new_doc->getTypeDescr(); + + vector<QString> old_tenses = doc->getTenseDescr(); + vector<QString> new_tenses = new_doc->getTenseDescr(); + + vector<int> old_in_query = doc->getLessonsInQuery(); + vector<int> new_in_query = new_doc->getLessonsInQuery(); + + vector<QString> old_usages = doc->getUsageDescr(); + vector<QString> new_usages = new_doc->getUsageDescr(); + + format = i18n("Merging %1"); + msg = format.arg(url.path()); + slotStatusMsg(msg); + + QApplication::setOverrideCursor( waitCursor ); + + int lesson_offset = lessons->count()-1; + for (int i = 0; i < (int) new_names.size(); i++) { + lessons->insertItem (new_names[i]); + old_names.push_back(new_names[i]); + } + doc->setLessonDescr(old_names); + + for (int i = 0; i < (int) new_in_query.size(); i++) + old_in_query.push_back(new_in_query[i]+lesson_offset); + doc->setLessonsInQuery(old_in_query); + querymanager.setLessonItems(old_in_query); + + int types_offset = old_types.size(); + for (int i = 0; i < (int) new_types.size(); i++) { + old_types.push_back(new_types[i]); + } + doc->setTypeDescr(old_types); + QueryManager::setTypeNames(old_types); + + + int tenses_offset = old_tenses.size(); + for (int i = 0; i < (int) new_tenses.size(); i++) { + old_tenses.push_back(new_tenses[i]); + } + doc->setTenseDescr(old_tenses); + Conjugation::setTenseNames(old_tenses); + + + int usages_offset = old_usages.size(); + for (int i = 0; i < (int) new_usages.size(); i++) { + old_usages.push_back(new_usages[i]); + } + doc->setUsageDescr(old_usages); + UsageManager::setUsageNames(old_usages); + + + bool equal = true; + if (doc->getOriginalIdent() != new_doc->getOriginalIdent()) + equal = false; + for (int i = 1; i < doc->numLangs(); i++) + if (doc->getIdent(i) != new_doc->getIdent(i)) + equal = false; + + if (equal) { // easy way: same language codes, just append + + for (int i = 0; i < new_doc->numEntries(); i++) { + kvoctrainExpr *expr = new_doc->getEntry(i); + + expr->setLesson(expr->getLesson()+lesson_offset); + + for (int lang = 0; lang <= (int) expr->numTranslations(); lang++) { + QString t = expr->getType (lang); + // adjust type offset + if (!t.isEmpty() && t.left(1) == QM_USER_TYPE) { + QString t2; + t.remove (0, 1); + t2.setNum (t.toInt()+types_offset); + t2.insert (0, QM_USER_TYPE); + expr->setType (lang, t2); + } + + t = expr->getUsageLabel (lang); + // adjust usage offset + QString tg; + if (!t.isEmpty() ) { + QString t2; + while (t.left(strlen(UL_USER_USAGE)) == UL_USER_USAGE) { + QString n; + t.remove (0, 1); + int next; + if ((next = t.find(UL_USAGE_DIV)) >= 0) { + n = t.left(next); + t.remove (0, next+1); + } + else { + n = t; + t = ""; + } + + t2.setNum (n.toInt()+usages_offset); + t2.insert (0, UL_USER_USAGE); + if (tg.length() == 0) + tg = t2; + else + tg += UL_USAGE_DIV + t2; + } + + if (tg.length() == 0) + tg = t; + else if (t.length() != 0) + tg += UL_USAGE_DIV + t; + + expr->setUsageLabel (lang, tg); + } + + Conjugation conj = expr->getConjugation(lang); + bool condirty = false; + for (int ci = 0; ci < conj.numEntries(); ci++) { + t = conj.getType(ci); + if (!t.isEmpty() && t.left(1) == UL_USER_TENSE) { + t.remove (0, strlen(UL_USER_TENSE)); + QString t2; + t2.setNum (t.toInt()+tenses_offset); + t2.insert (0, UL_USER_TENSE); + conj.setType(ci, t2); + condirty = true; + } + if (condirty) + expr->setConjugation(lang, conj); + } + } + + doc->appendEntry (expr); + } + doc->setModified(); + } + else { // hard way: move entries around, most attributes get lost + vector<int> move_matrix; + + vector <bool> cs_equal; + for (int i = 0; i < QMAX (doc->numLangs(), new_doc->numLangs()); i++) + cs_equal.push_back (false); + + move_matrix.push_back(new_doc->findIdent(doc->getOriginalIdent())); + for (int i = 1; i < doc->numLangs(); i++) + move_matrix.push_back(new_doc->findIdent(doc->getIdent(i))); + + for (int j = 0; j < new_doc->numEntries(); j++) { + kvoctrainExpr new_expr; + kvoctrainExpr *expr = new_doc->getEntry(j); + new_expr.setLesson(expr->getLesson()+lesson_offset); + + for (int i = 0; i < (int) move_matrix.size(); i++) { + int lpos = move_matrix[i]; + if (lpos >= 0) { + + if (lpos == 0) + s = expr->getOriginal(); + else + s = expr->getTranslation(lpos); + + if (!cs_equal[lpos]) { + cs_equal[lpos] = true; + QString id = lpos == 0 ? doc->getOriginalIdent() + : doc->getIdent(lpos); + } + + if (i == 0) + new_expr.setOriginal(s); + else + new_expr.setTranslation(i, s); + QString r = expr->getRemark(lpos); + new_expr.setRemark (i, r); + + QString t = expr->getType(lpos); + if (!t.isEmpty() && t.left(1) == QM_USER_TYPE) { + QString t2; + t.remove (0, 1); + t2.setNum (t.toInt()+types_offset); + t2.insert (0, QM_USER_TYPE); + new_expr.setType (i, t2); + } + + t = expr->getUsageLabel(lpos); + if (!t.isEmpty() && t.left(1) == QM_USER_TYPE) { + QString t2; + t.remove (0, 1); + t2.setNum (t.toInt()+usages_offset); + t2.insert (0, QM_USER_TYPE); + new_expr.setUsageLabel (i, t2); + } + + Conjugation conj = expr->getConjugation(lpos); + for (int ci = 0; ci < conj.numEntries(); ci++) { + t = conj.getType(ci); + if (!t.isEmpty() && t.left(1) == QM_USER_TYPE) { + t.remove (0, strlen(QM_USER_TYPE)); + QString t2; + t2.setNum (t.toInt()+tenses_offset); + t2.insert (0, QM_USER_TYPE); + conj.setType(ci, t2); + } + } + + } + } + // only append if entries are used + bool used = !new_expr.getOriginal().isEmpty(); + for (int i = 1; i < (int) doc->numLangs(); i++) + if (!new_expr.getTranslation(i).isEmpty()) + used = true; + + if (used) { + doc->appendEntry(&new_expr); + doc->setModified(); + } + } + } + delete (new_doc); + fileOpenRecent->addURL(url); // addRecentFile (url.path()); + } + + view->setView(doc, langset); + view->getTable()->setFont(Prefs::tableFont()); + view->adjustContent(); + QApplication::restoreOverrideCursor(); + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotFileSave() +{ + if (entryDlg != 0) + commitEntryDlg(false); + + if (doc->URL().fileName() == i18n("Untitled") ) { + slotFileSaveAs(); + return; + } + + QString format = i18n("Saving %1"); + QString msg = format.arg(doc->URL().path()); + slotStatusMsg(msg); + + // remove previous backup + QFile::remove(QFile::encodeName(doc->URL().path()+"~")); + ::rename (QFile::encodeName(doc->URL().path()), + QFile::encodeName(doc->URL().path()+"~")); + + prepareProgressBar(); + saveDocProps(doc); + doc->saveAs(this, doc->URL(), doc->getTitle(), kvoctrainDoc::automatic); + fileOpenRecent->addURL(doc->URL()); + removeProgressBar(); + + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::fillLessonBox(kvoctrainDoc *the_doc) +{ + lessons->clear(); + lessons->insertItem (the_doc->getLessonDescr(0)); + vector<QString> names = the_doc->getLessonDescr(); + for (int i = 0; i < (int) names.size(); i++) + lessons->insertItem (names[i]); + act_lesson = the_doc->getCurrentLesson(); + if (act_lesson > lessons->count() ) { + act_lesson = 0; + the_doc->setCurrentLesson(act_lesson); + } + lessons->setCurrentItem (act_lesson); +} + + +void kvoctrainApp::loadDocProps(kvoctrainDoc *the_doc) +{ + fillLessonBox(the_doc); + + random_expr1.clear(); + random_expr2.clear(); + queryList.clear(); + the_doc->getQueryLang (act_query_org, act_query_trans); + if (!act_query_org.isEmpty() && !act_query_trans.isEmpty() ) { + for (int i = 0; i < the_doc->numEntries(); i++) + { + kvoctrainExpr *entry = the_doc->getEntry(i); + if (entry->isInQuery()) + { + int less = entry->getLesson(); + for (int l = (int) queryList.size(); l <= less; l++) { + vector<QueryEntryRef> ref_vec; + queryList.push_back(ref_vec); + } + QueryEntryRef ref(entry, i); + queryList[less].push_back(ref); + } + } + } + + QueryManager::setTypeNames (doc->getTypeDescr() ); + UsageManager::setUsageNames (doc->getUsageDescr() ); + Conjugation::setTenseNames (doc->getTenseDescr() ); + + querymanager.setLessonItems(doc->getLessonsInQuery() ); + + // remove empty elements + for (int i = (int) queryList.size()-1; i >= 0; i--) + if (queryList[i].size() == 0) { + queryList.erase(queryList.begin() + i); + } + + query_cycle = 1; + query_startnum = 0; + for (int i = 0; i < (int) queryList.size(); i++) + query_startnum += queryList[i].size(); + query_num = query_startnum; +} + + +void kvoctrainApp::saveDocProps(kvoctrainDoc *the_doc) +{ + the_doc->setQueryLang (act_query_org, act_query_trans); +} + + +void kvoctrainApp::slotFileSaveAs() +{ + slotStatusMsg(i18n("Saving file under new filename...")); + + if (entryDlg != 0) + commitEntryDlg(false); + + KURL url = KFileDialog::getSaveURL(QString::null, FILTER_WPATTERN, parentWidget(), i18n("Save Vocabulary As")); + + if (!url.isEmpty() ) { + QFileInfo fileinfo(url.path()); + if (fileinfo.exists() && KMessageBox::warningContinueCancel(0, + i18n("<qt>The file<br><b>%1</b><br>already exists. Do you want to overwrite it?</qt>") + .arg(url.path()),QString::null,i18n("Overwrite")) == KMessageBox::Cancel) + { + // do nothing + } + else + + if (doc) { + QString format = i18n("Saving %1"); + QString msg = format.arg(url.path()); + slotStatusMsg(msg); + + QFile::remove(QFile::encodeName(url.path()+"~")); // remove previous backup + ::rename (QFile::encodeName(url.path()), QFile::encodeName(QString(url.path()+"~"))); + saveDocProps(doc); + + prepareProgressBar(); + doc->saveAs(this, url, doc->getTitle(), kvoctrainDoc::automatic); + fileOpenRecent->addURL(doc->URL()); + removeProgressBar(); + } + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotSaveSelection () +{ + if (entryDlg != 0) + commitEntryDlg(false); + + slotStatusMsg(i18n("Saving selected area under new filename...")); + QString save_separator = Prefs::separator(); + Prefs::setSeparator("\t"); + kvoctrainDoc seldoc(this, ""); + // transfer most important parts + seldoc.appendLang(doc->getOriginalIdent()); + for (int i = 1; i < doc->numLangs(); i++) + seldoc.appendLang(doc->getIdent(i)); + seldoc.setAuthor(doc->getAuthor()); + seldoc.setLessonDescr(doc->getLessonDescr()); + seldoc.setTypeDescr(doc->getTypeDescr()); + + for (int i = doc->numEntries()-1; i >= 0; i--) + if (doc->getEntry(i)->isInQuery() ) + seldoc.appendEntry(doc->getEntry(i)); + + KURL url = KFileDialog::getSaveURL(QString::null, FILTER_WPATTERN, parentWidget(), i18n("Save Vocabulary As")); + + if (!url.isEmpty() ) + { + QFileInfo fileinfo(url.path()); + if (fileinfo.exists() && KMessageBox::warningContinueCancel(0, + i18n("<qt>The file<br><b>%1</b><br>already exists. Do you want to overwrite it?</qt>") + .arg(url.path()),QString::null,i18n("Overwrite")) == KMessageBox::Cancel) + { + // do nothing + } + else + { + QString format = i18n("Saving %1"); + QString msg = format.arg(url.path()); + slotStatusMsg(msg); + + QFile::remove(url.path()+"~"); // remove previous backup + // FIXME: check error + ::rename (QFile::encodeName(url.path()), QFile::encodeName(url.path()+"~")); + saveDocProps(&seldoc); + + prepareProgressBar(); + seldoc.saveAs(this, url, i18n ("Part of: ") + doc->getTitle(), kvoctrainDoc::automatic); + removeProgressBar(); + } + } + Prefs::setSeparator(save_separator); + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::prepareProgressBar () +{ + statusBar()->clear (); + pbar = new KProgress (statusBar()); + pbar->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + statusBar()->addWidget(pbar, 150, true); + pbar->show(); +} + + +void kvoctrainApp::removeProgressBar () +{ + statusBar()->clear (); + statusBar()->removeWidget(pbar); + delete pbar; + pbar = 0; + delete pdlg; + pdlg = 0; +} diff --git a/kvoctrain/kvoctrain/kva_query.cpp b/kvoctrain/kvoctrain/kva_query.cpp new file mode 100644 index 00000000..98e1ed30 --- /dev/null +++ b/kvoctrain/kvoctrain/kva_query.cpp @@ -0,0 +1,1021 @@ +/*************************************************************************** + + query parts of kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <kdebug.h> +#include <klocale.h> + +#include "kvoctrain.h" +#include "query-dialogs/RandomQueryDlg.h" +#include "query-dialogs/MCQueryDlg.h" +#include "query-dialogs/VerbQueryDlg.h" +#include "query-dialogs/ArtQueryDlg.h" +#include "query-dialogs/AdjQueryDlg.h" +#include "query-dialogs/SimpleQueryDlg.h" +#include "prefs.h" + +#define MAX_QUERY_TIMEOUT 3 + + +static const char not_answered[] = I18N_NOOP( + "The query dialog was not answered several times in a row.\n" + "It is assumed that there is currently nobody in front of " + "the screen, and for that reason the query is stopped."); + + +static const char not_contain[] = I18N_NOOP( + "There are currently no suitable expressions for the " + "query you started.\n" + "There are several possible reasons for this; maybe you do not have " + "any expressions for the type of query you requested.\n" + "Most likely, you should adjust your settings referring to " + "thresholds and blocking values in the query options:\n" + "should the configuration dialog be invoked now?"); + +/* +void kvoctrainApp::slotQueryOptions() +{ + slotQueryOptions(-1); +} + + +void kvoctrainApp::slotQueryOptions(int pageindex) +{ + vector<int> old_liq = doc->getLessonsInQuery(); + QueryOptionsDlg qodlg ( + Prefs::maxTimePer() /1000, + Prefs::showCounter(), + doc, + lessons, + &querymanager, + Prefs::swapDirection(), + Prefs::suggestions(), + Prefs::split(), + Prefs::periods(), + Prefs::colons(), + Prefs::semicolons(), + Prefs::commas(), + Prefs::fields(), + Prefs::showMore(), + Prefs::iKnow(), + Prefs::altLearn(), + Prefs::block(), + Prefs::expire(), + presettings); + + if (pageindex >= 0) + qodlg.selectPage(pageindex); + + int res = qodlg.exec(); + if (res == QDialog::Accepted) { + + //type_querytimeout = qodlg.getTypeQueryTimeout(); + Prefs::setMaxTimePer(qodlg.getMQueryTime()*1000); + Prefs::setShowCounter(qodlg.getShowCounter()); + querymanager = qodlg.getQueryManager(); + Prefs::setSwapDirection(qodlg.getSwapDir()); + Prefs::setSuggestions(qodlg.getSuggestions()); + Prefs::setSplit(qodlg.getSplit()); + Prefs::setPeriods(qodlg.getPeriods()); + Prefs::setColons(qodlg.getColons()); + Prefs::setSemicolons(qodlg.getSemicolons()); + Prefs::setCommas(qodlg.getCommas()); + Prefs::setFields(qodlg.getFields()); + Prefs::setShowMore(qodlg.getShowMore()); + Prefs::setIKnow(qodlg.getIKnow()); + Prefs::setAltLearn(qodlg.getAltLearn()); + Prefs::setBlock(qodlg.getBlock()); + Prefs::setExpire(qodlg.getExpire()); + presettings = qodlg.getPreSetting(); + if (old_liq != qodlg.getQueryManager().lessonItems()) { + doc->setModified(); + doc->setLessonsInQuery(qodlg.getQueryManager().lessonItems() ); + querymanager.setLessonItems(qodlg.getQueryManager().lessonItems() ); + } + + slotStatusMsg(IDS_DEFAULT); + } +} + +*/ +void kvoctrainApp::slotStartPropertyQuery(int col, QueryType property) +{ + removeEntryDlg(); + slotStatusMsg(i18n("Starting property query...")); + queryType = property; + querymode = false; + num_queryTimeout = 0; + act_query_col = col; + + if (view->getTable()->count() < 1) + return; + + prepareProgressBar(); + QApplication::setOverrideCursor( waitCursor ); + random_expr2.clear(); + queryList = querymanager.select (doc, act_lesson, act_query_col, property); + + query_startnum = 0; + if (queryList.size() > 0) { + random_expr1 = queryList[0]; + queryList.erase(queryList.begin()); + query_startnum = (int) random_expr1.size(); + } + + for (int i = 0; i < (int) queryList.size(); i++) { + int n = queryList[i].size(); + query_startnum += n; + } + query_num = query_startnum; + + QApplication::restoreOverrideCursor(); + removeProgressBar(); + query_cycle = 1; + + // something left to query ? + if (query_startnum == 0) { + if( KMessageBox::Yes == KMessageBox::questionYesNo(this, + i18n(not_contain), + kapp->makeStdCaption(i18n("Starting Query")))) + slotGeneralOptionsPage(5); + return; + } + + hide(); + querymode = true; + + random_query_nr = random.getLong(random_expr1.size()); + kvoctrainExpr *exp = random_expr1[random_query_nr].exp; + + simpleQueryDlg = new SimpleQueryDlg ( + queryType, + random_expr1[random_query_nr].nr, + act_query_col, + query_cycle, + query_num, + query_startnum, + exp, + doc); + + connect( simpleQueryDlg, SIGNAL(sigEditEntry(int,int)), + this, SLOT(slotEditEntry(int,int))); + + connect( simpleQueryDlg, SIGNAL(sigQueryChoice(QueryDlgBase::Result)), + this, SLOT(slotTimeOutProperty(QueryDlgBase::Result))); + + simpleQueryDlg->initFocus(); + simpleQueryDlg->show(); + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotTimeOutProperty(QueryDlgBase::Result res) +{ + + if (simpleQueryDlg == 0) { + kdError() << "simpleQueryDlg == 0\n"; + slotStopQuery(true); + return; + } + + // FIXME: keep track of knowledge ? + + doc->setModified(); + switch (res) { + case QueryDlgBase::Timeout: + if (++num_queryTimeout >= MAX_QUERY_TIMEOUT) { + slotStopQuery(true); + KMessageBox::information(this, i18n(not_answered), + kapp->makeStdCaption(i18n("Stopping Query"))); + return; + } + else { + random_expr2.push_back (random_expr1[random_query_nr]); + random_expr1.erase (random_expr1.begin() + random_query_nr); + } + break; + + case QueryDlgBase::Unknown : + num_queryTimeout = 0; + random_expr2.push_back (random_expr1[random_query_nr]); + random_expr1.erase (random_expr1.begin() + random_query_nr); + break; + + case QueryDlgBase::Known : + num_queryTimeout = 0; + query_num--; + + random_expr1.erase (random_expr1.begin() + random_query_nr); + if ( random_expr1.size() != 0 + || random_expr2.size() != 0 + || queryList.size() != 0 ) { + } + else { + slotStopQuery (true); + return; + } + break; + + case QueryDlgBase::StopIt : + num_queryTimeout = 0; + slotStopQuery(true); + return; + break; + + default : + kdError() << "unknown result from QueryDlg\n"; + slotStopQuery(true); + return; + } + + if (random_expr1.size() == 0 ) { + if ( random_expr2.size() == 0 + && queryList.size() == 0) { + slotStopQuery(true); + return; + } + + if (random_expr2.size() != 0) { // next cycle with current lesson + random_expr1 = random_expr2; + random_expr2.clear(); + query_cycle++; + } + else { // next lesson + query_cycle = 1; + random_expr1 = queryList[0]; + queryList.erase(queryList.begin()); + } + } + + if (random_expr1.size() == 0) { // should not happen !! + kdError() << "kvoctrainApp::slotTimeProperty: random_expr1.size() == 0\n"; + slotStopQuery(true); + return; + } + + random_query_nr = random.getLong(random_expr1.size()); + kvoctrainExpr *exp = random_expr1[random_query_nr].exp; + + simpleQueryDlg->setQuery(queryType, + random_expr1[random_query_nr].nr, + act_query_col, + query_cycle, + query_num, + query_startnum, + exp, + doc); + + simpleQueryDlg->initFocus(); + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotStartTypeQuery(int col, const QString & type) +{ + removeEntryDlg(); + slotStatusMsg(i18n("Starting special query...")); + querymode = false; + num_queryTimeout = 0; + act_query_col = col; + + if (view->getTable()->count() < 1) + return; + + prepareProgressBar(); + QApplication::setOverrideCursor( waitCursor ); + random_expr2.clear(); + + queryList = querymanager.select (doc, act_lesson, act_query_col, type); + + query_startnum = 0; + if (queryList.size() > 0) { + random_expr1 = queryList[0]; + queryList.erase(queryList.begin()); + query_startnum = (int) random_expr1.size(); + } + for (int i = 0; i < (int) queryList.size(); i++) { + int n = queryList[i].size(); + query_startnum += n; + } + query_num = query_startnum; + + QApplication::restoreOverrideCursor(); + removeProgressBar(); + query_cycle = 1; + + // something left to query ? + if (query_startnum == 0) { + if( KMessageBox::Yes == KMessageBox::questionYesNo(this, + i18n(not_contain), + kapp->makeStdCaption(i18n("Starting Query")))) + slotGeneralOptionsPage(5); + return; + } + + random_query_nr = random.getLong(random_expr1.size()); + kvoctrainExpr *exp = random_expr1[random_query_nr].exp; + + hide(); + querymode = true; + if (queryType == QT_Conjugation) { + verbQueryDlg = new VerbQueryDlg (exp->getType(act_query_col), + random_expr1[random_query_nr].nr, + act_query_col, + query_cycle, + query_num, + query_startnum, + exp, + doc, + doc->getConjugation(act_query_col), + exp->getConjugation(act_query_col)); + + verbQueryDlg->initFocus(); + connect( verbQueryDlg, SIGNAL(sigEditEntry(int,int)), + this, SLOT(slotEditEntry(int,int))); + + connect(verbQueryDlg, SIGNAL(sigQueryChoice(QueryDlgBase::Result)), + this, SLOT(slotTimeOutType(QueryDlgBase::Result))); + verbQueryDlg->show(); + } + else if (queryType == QT_Articles) { + artQueryDlg = new ArtQueryDlg(exp->getType(act_query_col), + random_expr1[random_query_nr].nr, + act_query_col, + query_cycle, + query_num, + query_startnum, + exp, + doc, + doc->getArticle(act_query_col)); + artQueryDlg->initFocus(); + connect( artQueryDlg, SIGNAL(sigEditEntry(int,int)), + this, SLOT(slotEditEntry(int,int))); + connect(artQueryDlg, SIGNAL(sigQueryChoice(QueryDlgBase::Result)), + this, SLOT(slotTimeOutType(QueryDlgBase::Result))); + artQueryDlg->show(); + } + else if (queryType == QT_Comparison) { + adjQueryDlg = new AdjQueryDlg(exp->getType(act_query_col), + random_expr1[random_query_nr].nr, + act_query_col, + query_cycle, + query_num, + query_startnum, + exp, + doc, + exp->getComparison(act_query_col)); + adjQueryDlg->initFocus(); + connect( adjQueryDlg, SIGNAL(sigEditEntry(int,int)), + this, SLOT(slotEditEntry(int,int))); + + connect(adjQueryDlg, SIGNAL(sigQueryChoice(QueryDlgBase::Result)), + this, SLOT(slotTimeOutType(QueryDlgBase::Result))); + adjQueryDlg->show(); + } + else { + kdError() << "kvoctrainApp::slotTimeOutType: unknown type\n"; + slotStopQuery(true); + return; + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotTimeOutType(QueryDlgBase::Result res) +{ + + // FIXME: keep track of knowledge ? + + doc->setModified(); + switch (res) { + case QueryDlgBase::Timeout: + if (++num_queryTimeout >= MAX_QUERY_TIMEOUT) { + slotStopQuery(true); + KMessageBox::information(this, i18n(not_answered), + kapp->makeStdCaption(i18n("Stopping Query"))); + return; + } + else { + random_expr2.push_back (random_expr1[random_query_nr]); + random_expr1.erase (random_expr1.begin() + random_query_nr); + } + break; + + case QueryDlgBase::Unknown : + num_queryTimeout = 0; + random_expr2.push_back (random_expr1[random_query_nr]); + random_expr1.erase (random_expr1.begin() + random_query_nr); + break; + + case QueryDlgBase::Known : + num_queryTimeout = 0; + query_num--; + + random_expr1.erase (random_expr1.begin() + random_query_nr); + if ( random_expr1.size() != 0 + || random_expr2.size() != 0 + || queryList.size() != 0 ) { + } + else { + slotStopQuery (true); + return; + } + break; + + case QueryDlgBase::StopIt : + num_queryTimeout = 0; + slotStopQuery(true); + return; + break; + + default : + kdError() << "unknown result from QueryDlg\n"; + slotStopQuery(true); + return; + } + + + if (random_expr1.size() == 0 ) { + if ( random_expr2.size() == 0 + && queryList.size() == 0) { + slotStopQuery(true); + return; + } + + if (random_expr2.size() != 0) { // next cycle with current lesson + random_expr1 = random_expr2; + random_expr2.clear(); + query_cycle++; + } + else { // next lesson + query_cycle = 1; + random_expr1 = queryList[0]; + queryList.erase(queryList.begin()); + } + } + hide(); + + if (random_expr1.size() == 0) { // should not happen !! + kdError() << "kvoctrainApp::slotTimeSpecial: random_expr1.size() == 0\n"; + slotStopQuery(true); + return; + } + + random_query_nr = random.getLong(random_expr1.size()); + kvoctrainExpr *exp = random_expr1[random_query_nr].exp; + + if (queryType == QT_Conjugation) { + if (verbQueryDlg == 0) { + kdError() << "verbQueryDlg == 0\n"; + slotStopQuery(true); + return; + } + verbQueryDlg->setQuery (exp->getType(act_query_col), + random_expr1[random_query_nr].nr, + act_query_col, + query_cycle, + query_num, + query_startnum, + exp, + doc, + doc->getConjugation(act_query_col), + exp->getConjugation(act_query_col)); + + verbQueryDlg->initFocus(); + } + else if (queryType == QT_Articles) { + if (artQueryDlg == 0) { + kdError() << "artQueryDlg == 0\n"; + slotStopQuery(true); + return; + } + artQueryDlg->setQuery(exp->getType(act_query_col), + random_expr1[random_query_nr].nr, + act_query_col, + query_cycle, + query_num, + query_startnum, + exp, + doc, + doc->getArticle(act_query_col)); + artQueryDlg->initFocus(); + } + else if (queryType == QT_Comparison) { + if (adjQueryDlg == 0) { + kdError() << "adjQueryDlg == 0\n"; + slotStopQuery(true); + return; + } + adjQueryDlg->setQuery(exp->getType(act_query_col), + random_expr1[random_query_nr].nr, + act_query_col, + query_cycle, + query_num, + query_startnum, + exp, + doc, + exp->getComparison(act_query_col)); + adjQueryDlg->initFocus(); + } + else { + kdError() << "kvoctrainApp::slotTimeOutType: unknown type\n"; + slotStopQuery(true); + return; + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotRestartQuery() +{ + if (random_expr1.size() != 0) { + queryList.insert(queryList.begin(), random_expr1); + random_expr1.clear(); + } + slotStartQuery(act_query_trans, act_query_org, false); +} + + +void kvoctrainApp::slotStartQuery(const QString & translang, const QString & orglang, bool create_new) +{ + removeEntryDlg(); + slotStatusMsg(i18n("Starting random query...")); + querymode = false; + num_queryTimeout = 0; + + if (view->getTable()->count() < 1) + return; + + int tindex = view->getTable()->findIdent(translang); + if (tindex < 0) + return; + + int oindex = view->getTable()->findIdent(orglang); + if (oindex < 0) + return; + + act_query_trans = translang; + act_query_org = orglang; + + prepareProgressBar(); + QApplication::setOverrideCursor( waitCursor ); + random_expr2.clear(); + + if (create_new || queryList.size() == 0) + queryList = querymanager.select (doc, act_lesson, oindex, tindex); + + query_startnum = 0; + if (queryList.size() > 0) { + random_expr1 = queryList[0]; + queryList.erase(queryList.begin()); + query_startnum = (int) random_expr1.size(); + } + for (int i = 0; i < (int) queryList.size(); i++) { + int n = queryList[i].size(); + query_startnum += n; + } + query_num = query_startnum; + + QApplication::restoreOverrideCursor(); + removeProgressBar(); + query_cycle = 1; + + // something left to query ? + if (query_startnum == 0) { + if( KMessageBox::Yes == KMessageBox::questionYesNo(this, + i18n(not_contain), + kapp->makeStdCaption(i18n("Starting Query")))) + slotGeneralOptionsPage(5); + return; + } + + hide(); + querymode = true; + + random_query_nr = random.getLong(random_expr1.size()); + kvoctrainExpr *exp = random_expr1[random_query_nr].exp; + + QString q_org, + q_trans; + + if (oindex == 0) { // usual: give original, ask for translation x + q_org = exp->getOriginal(); + q_trans = exp->getTranslation(tindex); + } + else { // alternative: give translation x, ask for original + q_org = exp->getTranslation(oindex); + q_trans = exp->getOriginal(); + } + + if (queryType == QT_Random) { + randomQueryDlg = new RandomQueryDlg ( + q_org, + q_trans, + random_expr1[random_query_nr].nr, + oindex, + tindex, + query_cycle, + query_num, + query_startnum, + exp, + doc); + randomQueryDlg->initFocus(); + connect( randomQueryDlg, SIGNAL(sigEditEntry(int,int)), + this, SLOT(slotEditEntry(int,int))); + connect(randomQueryDlg, SIGNAL(sigQueryChoice(QueryDlgBase::Result)), + this, SLOT(slotTimeOutRandomQuery(QueryDlgBase::Result))); + randomQueryDlg->show(); + } + else if (queryType == QT_Multiple) { + mcQueryDlg = new MCQueryDlg( + q_org, + q_trans, + random_expr1[random_query_nr].nr, + oindex, + tindex, + query_cycle, + query_num, + query_startnum, + exp, + doc); + mcQueryDlg->initFocus(); + connect( mcQueryDlg, SIGNAL(sigEditEntry(int,int)), + this, SLOT(slotEditEntry(int,int))); + connect(mcQueryDlg, SIGNAL(sigQueryChoice(QueryDlgBase::Result)), + this, SLOT(slotTimeOutMultipleChoice(QueryDlgBase::Result))); + mcQueryDlg->show(); + } + else { + kdError() << "kvoctrainApp::slotStartQuery: unknown type\n"; + slotStopQuery(true); + return; + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotTimeOutRandomQuery(QueryDlgBase::Result res) +{ + queryType = QT_Random; + slotTimeOutQuery(res); +} + + +void kvoctrainApp::slotTimeOutMultipleChoice(QueryDlgBase::Result res) +{ + queryType = QT_Multiple; + slotTimeOutQuery(res); +} + + +void kvoctrainApp::slotTimeOutQuery(QueryDlgBase::Result res) +{ + doc->setModified(); + + + int tindex = view->getTable()->findIdent(act_query_trans); + int oindex = view->getTable()->findIdent(act_query_org); + QueryEntryRef qer = random_expr1[random_query_nr]; + kvoctrainExpr *exp = qer.exp; + + if (res != QueryDlgBase::StopIt) { + doc->setModified(); + time_t now = time(0); + if (oindex == 0) { + exp->incQueryCount(tindex, false); + exp->setQueryDate(tindex, now, false); + } + else { + exp->incQueryCount(oindex, true); + exp->setQueryDate(oindex, now, true); + } + } + + switch (res) { + case QueryDlgBase::Timeout: + if (++num_queryTimeout >= MAX_QUERY_TIMEOUT) { + slotStopQuery(true); + KMessageBox::information(this, i18n(not_answered), + kapp->makeStdCaption(i18n("Stopping Query"))); + return; + } + else { + random_expr1.erase (random_expr1.begin() + random_query_nr); + + //When you get it wrong Leisner style, it ends up in the back + //of the line + if (Prefs::altLearn()) + random_expr1.push_back (qer); + else + random_expr2.push_back (qer); + + if (oindex == 0) { + exp->incBadCount(tindex, false); + exp->setGrade(tindex, KV_LEV1_GRADE, false); // unknown: reset grade + } + else { + exp->incBadCount(oindex, true); + exp->setGrade(oindex, KV_LEV1_GRADE, true); + } + } + break; + + case QueryDlgBase::Unknown : + num_queryTimeout = 0; + random_expr1.erase (random_expr1.begin() + random_query_nr); + + //When you get it wrong Leisner style, it ends up in the back + //of the line + if (Prefs::altLearn()) + random_expr1.push_back (qer); + else + random_expr2.push_back (qer); + + if (oindex == 0) { + exp->incBadCount(tindex, false); + exp->setGrade(tindex, KV_LEV1_GRADE, false); // unknown: reset grade + } + else { + exp->incBadCount(oindex, true); + exp->setGrade(oindex, KV_LEV1_GRADE, true); + } + break; + + case QueryDlgBase::Known : + num_queryTimeout = 0; + if (Prefs::altLearn()) { + //we always store the current question in the random_expr + //array, so delete it from there. + random_expr1.erase (random_expr1.begin() + random_query_nr); + + //The user guessed right (or she actually knew the + //answer). Move the exp up to next level. + switch (query_cycle) { + case 1: + correct_1_times.push_back (qer); + break; + case 2: + correct_2_times.push_back (qer); + break; + case 3: + correct_3_times.push_back (qer); + break; + case 4: + //The user has answered correctly four times in a row. She + //is good! + exp->setInQuery(false); + + query_num--; + if (oindex == 0) { + exp->incGrade(tindex, false); + } + else { + exp->incGrade(oindex, true); + } + break; + default: + kdError() << "You should not be able to answer correctly more than 4 times\n"; + slotStopQuery(true); + return; + } + + if (random_expr1.size() == 0 + && correct_1_times.size() == 0 + && correct_2_times.size() == 0 + && correct_3_times.size() == 0) { + slotStopQuery (true); + return; + } + + } + else { //not Prefs::altLearn() + query_num--; + if (query_cycle <= 1) { + if (oindex == 0) { + exp->incGrade(tindex, false); // incr grade only in first cycle + } + else { + exp->incGrade(oindex, true); + } + } + else { + if (oindex == 0) { + exp->setGrade(tindex, KV_LEV1_GRADE, false); // reset grade + } + else { + exp->setGrade(oindex, KV_LEV1_GRADE, true); + } + } + + exp->setInQuery(false); + random_expr1.erase (random_expr1.begin() + random_query_nr); + if (!( random_expr1.size() != 0 + || random_expr2.size() != 0 + || queryList.size() != 0 )) { + slotStopQuery (true); + return; + } + } + break; + + case QueryDlgBase::StopIt : + num_queryTimeout = 0; + slotStopQuery(true); + return; + break; + + default : + kdError() << "unknown result from QueryDlg\n"; + slotStopQuery(true); + return; + } + + if (Prefs::altLearn()) { + + if (correct_3_times.size() > 7 || + (correct_3_times.size() > 0 + && correct_2_times.size() == 0 + && correct_1_times.size() == 0 + && random_expr1.size() == 0)) { + QueryEntryRef t_qer = correct_3_times[0]; + correct_3_times.erase(correct_3_times.begin()); + random_query_nr = random_expr1.size(); + random_expr1.push_back(t_qer); + query_cycle = 4; + } + else if (correct_2_times.size() > 5 || + (correct_2_times.size() > 0 + && correct_1_times.size() == 0 + && random_expr1.size() == 0)) { + QueryEntryRef t_qer = correct_2_times[0]; + correct_2_times.erase(correct_2_times.begin()); + random_query_nr = random_expr1.size(); + random_expr1.push_back(t_qer); + query_cycle = 3; + } + else if (correct_1_times.size() > 5 || + (correct_1_times.size() > 0 + && random_expr1.size() == 0)) { + QueryEntryRef t_qer = correct_1_times[0]; + correct_1_times.erase(correct_1_times.begin()); + random_query_nr = random_expr1.size(); + random_expr1.push_back(t_qer); + query_cycle = 2; + } + else { + //else we just pick from random_expr1 then + if (random_expr1.size() == 0 ) { + slotStopQuery(true); + return; + } + query_cycle = 1; + + random_query_nr = random.getLong(random_expr1.size()); + } + + } + else { // not Prefs::altLearn() + if (random_expr1.size() == 0 ) { + if ( random_expr2.size() == 0 + && queryList.size() == 0) { + slotStopQuery(true); + return; + } + + if (random_expr2.size() != 0) { // next cycle with current lesson + random_expr1 = random_expr2; + random_expr2.clear(); + query_cycle++; + } + else { // next lesson + query_cycle = 1; + random_expr1 = queryList[0]; + queryList.erase(queryList.begin()); + } + } + + if (random_expr1.size() == 0) { // should not happen !! + kdError() << "kvoctrainApp::slotTimeOutQuery: random_expr1.size() == 0\n"; + slotStopQuery(true); + return; + } + + random_query_nr = random.getLong(random_expr1.size()); + } + + exp = random_expr1[random_query_nr].exp; + + tindex = view->getTable()->findIdent(act_query_trans); + oindex = view->getTable()->findIdent(act_query_org); + QString q_org, + q_trans; + + if (Prefs::swapDirection()) { + bool rand_swap = random.getBool(); + + if (rand_swap) { // random direction + int tmp = oindex; + oindex = tindex; + tindex = tmp; + } + + if (!querymanager.validate (exp, act_lesson, oindex, tindex)) { + int tmp = oindex; // must use other direction which is the only valid + oindex = tindex; + tindex = tmp; + } + } + + if (oindex == 0) { // usual: give original, ask for translation x + q_org = exp->getOriginal(); + q_trans = exp->getTranslation(tindex); + } + else { // alternative: give translation x, ask for original + q_org = exp->getTranslation(oindex); + q_trans = exp->getOriginal(); + } + + if (queryType == QT_Random) { + if (randomQueryDlg == 0) { + kdError() << "randomQueryDlg == 0\n"; + slotStopQuery(true); + return; + } + randomQueryDlg->setQuery(q_org, + q_trans, + random_expr1[random_query_nr].nr, + oindex, + tindex, + query_cycle, + query_num, + query_startnum, + exp, + doc); + randomQueryDlg->initFocus(); + } + else if (queryType == QT_Multiple) { + if (mcQueryDlg == 0) { + kdError() << "mcQueryDlg == 0\n"; + slotStopQuery(true); + return; + } + mcQueryDlg->setQuery(q_org, + q_trans, + random_expr1[random_query_nr].nr, + oindex, + tindex, + query_cycle, + query_num, + query_startnum, + exp, + doc); + mcQueryDlg->initFocus(); + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotStopQuery(bool ) +{ + delete simpleQueryDlg; + delete mcQueryDlg; + delete verbQueryDlg; + delete randomQueryDlg; + delete adjQueryDlg; + delete artQueryDlg; + + simpleQueryDlg = 0; + mcQueryDlg = 0; + verbQueryDlg = 0; + randomQueryDlg = 0; + adjQueryDlg = 0; + artQueryDlg = 0; + + querying = false; + querymode = false; + show(); + kapp->setTopWidget(this); + kapp->setMainWidget( this ); +} diff --git a/kvoctrain/kvoctrain/kvoctrain.cpp b/kvoctrain/kvoctrain/kvoctrain.cpp new file mode 100644 index 00000000..86a306d9 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrain.cpp @@ -0,0 +1,1337 @@ +/*************************************************************************** + + main part of kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <kstatusbar.h> +#include <klineedit.h> +#include <kcombobox.h> +#include <kprogress.h> +#include <kconfig.h> +#include <kstandarddirs.h> +#include <klocale.h> +#include <kdebug.h> +#include <kiconloader.h> +#include <kprinter.h> + +#include <kinputdialog.h> +#include <qtimer.h> + +#include <time.h> +#include <ctype.h> + +#include <kvoctraincore.h> +#include "kvoctrain.h" +#include "entry-dialogs/EntryDlg.h" +#include "docprop-dialogs/DocPropDlg.h" +#include "docprop-dialogs/DocPropLangDlg.h" +#include "statistik-dialogs/StatistikDlg.h" +#include "common-dialogs/kvoctrainprefs.h" +#include "prefs.h" + +/*void kvoctrainApp::slotSaveOptions() +{ + saveOptions(true); +} +*/ + +kvoctrainApp::~kvoctrainApp() +{ + removeEntryDlg(); + delete header_m; + delete btimer; + delete view; + delete doc; +} + + +void kvoctrainApp::slotCancelSelection () +{ + view->getTable()->clearSelection(); +} + + +void kvoctrainApp::slotSelectAll () +{ + QTableSelection ts; + KVocTrainTable *table = view->getTable(); + table->clearSelection(); + ts.init(0,0); + ts.expandTo(table->numRows()-1, table->numCols()-1); + table->addSelection(ts); +} + + +void kvoctrainApp::slotCurrentCellChanged(int row, int col) +{ + col -= KV_EXTRA_COLS; + bool noData = false; + kvoctrainExpr *expr; + + statusBar()->clear(); + if (doc->numEntries() <= row || doc->numLangs() <= col || row < 0 || col < 0) + noData = true; + else + expr = doc->getEntry(row); + + if (rem_label != 0) + rem_label->setText(i18n("Abbreviation for R)emark","R: %1") + .arg(noData ? QString::null : expr->getRemark(col))); + if (pron_label != 0) + pron_label->setText(i18n("Abbreviation for P)ronouncation","P: %1") + .arg(noData ? QString::null : expr->getPronunce(col))); + if (type_label != 0) + type_label->setText(i18n("Abbreviation for T)ype of word", "T: %1") + .arg(noData ? QString::null : QueryManager::typeStr(expr->getType(col)))); + + if (entryDlg != 0) { + if (noData) + entryDlg->setEnabled(EntryDlg::EnableOnlyCommon); + else { + if (col == 0) + entryDlg->setEnabled(EntryDlg::EnableOnlyOriginal); + else + entryDlg->setEnabled(EntryDlg::EnableAll); + } + slotEditEntry(row, col + KV_EXTRA_COLS); + } +} + + +void kvoctrainApp::slotEditRow() +{ + slotEditEntry (view->getTable()->currentRow(), view->getTable()->currentColumn()); +} + + +void kvoctrainApp::slotEditCallBack(int res) +{ +// cout << "secb\n"; + switch (res) { + case EntryDlg::EditCancel: + removeEntryDlg(); + break; + + case EntryDlg::EditApply: + commitEntryDlg(true); + if (Prefs::smartAppend()) + { + int row = view->getTable()->currentRow(); + if (row == view->getTable()->numRows()-1) + { + int col = view->getTable()->currentColumn(); + if (col < view->getTable()->numCols()-1 && col >= KV_COL_ORG ) + { + int lesson = doc->getEntry(row)->getLesson(); + if (lesson >= lessons->count()) + lesson = QMAX (0, lessons->count()-1); + slotChooseLesson(lesson); + + QString exp; + exp = doc->getEntry(row)->getTranslation(col+1-KV_COL_ORG); + if (exp.isEmpty()) + view->getTable()->setCurrentRow(row, col+1); + } + else + slotAppendRow(); + } + } + break; + + case EntryDlg::EditUndo: + int row, col; + vector<QTableSelection> tabsel; + entryDlg->getCell(row, col, tabsel); + setDataEntryDlg(row, col); + break; + } +} + + +void kvoctrainApp::commitEntryDlg(bool force) +{ +// cout << "ced\n"; + if (entryDlg == 0) { + kdError() << "kvoctrainApp::commitEntryDlg: entryDlg == 0\n"; + return; + } + + if (!force && entryDlg->isModified() && !Prefs::autoEntryApply()) { + if( KMessageBox::No == KMessageBox::warningYesNo(this, + i18n("The entry dialog contains unsaved changes.\n" + "Do you want to apply or discard your changes?"), + kapp->makeStdCaption(i18n("Unsaved Changes")), + KStdGuiItem::apply(), KStdGuiItem::discard())) { + return; + } + } + + int row, col; + vector<QTableSelection> tabsel; + entryDlg->getCell(row, col, tabsel); + int hasSel = tabsel.size() > 1; + if (tabsel.size() == 1) + hasSel = (tabsel[0].bottomRow() - tabsel[0].topRow()) > 0; + + fillLessonBox(doc); + if (!hasSel) { + kvoctrainExpr *expr = doc->getEntry(row); + if (col >= KV_COL_ORG) { + col -= KV_EXTRA_COLS; + if (col == 0) + expr->setOriginal(entryDlg->getExpr()); + else + expr->setTranslation(col, entryDlg->getExpr()); + + expr->setRemark (col, entryDlg->getRemark()); + expr->setPronunce (col, entryDlg->getPronunce()); + + expr->setSynonym (col, entryDlg->getSynonym()); + expr->setAntonym (col, entryDlg->getAntonym()); + expr->setExample (col, entryDlg->getExample()); + expr->setUsageLabel (col, entryDlg->getUsageLabel()); + expr->setParaphrase (col, entryDlg->getParaphrase()); + expr->setConjugation (col, entryDlg->getConjugation()); + expr->setComparison(col, entryDlg->getComparison() ); + expr->setMultipleChoice(col, entryDlg->getMultipleChoice() ); + + expr->setFauxAmi (col, entryDlg->getFromFauxAmi(), false); + expr->setFauxAmi (col, entryDlg->getToFauxAmi(), true); + expr->setGrade(col, entryDlg->getFromGrade(), false); + expr->setGrade(col, entryDlg->getToGrade(), true); + expr->setQueryCount(col, entryDlg->getFromQCount(), false); + expr->setQueryCount(col, entryDlg->getToQCount(), true); + expr->setBadCount(col, entryDlg->getFromBCount(), false); + expr->setBadCount(col, entryDlg->getToBCount(), true); + expr->setQueryDate(col, entryDlg->getFromDate(), false); + expr->setQueryDate(col, entryDlg->getToDate(), true); + expr->setType (col, entryDlg->getType()); + + for (int j = 0; j <= expr->numTranslations(); j++) + if (expr->getType(j).isEmpty() ) + expr->setType(j, entryDlg->getType()); + + for (int j = 0; j <= expr->numTranslations(); j++) + if (QueryManager::getMainType(expr->getType(j)) + != + QueryManager::getMainType(entryDlg->getType()) ) + expr->setType(j, entryDlg->getType()); + } + expr->setLesson(entryDlg->getLesson()); + expr->setActive(entryDlg->getActive()); + + entryDlg->setModified(false); + doc->setModified(true); + view->getTable()->updateCell(row, col+KV_EXTRA_COLS); + view->getTable()->updateCell(row, KV_COL_LESS); + } + else { + col -= KV_EXTRA_COLS; + for (uint ts = 0; ts < tabsel.size(); ++ts) { + for (int er = tabsel[ts].topRow(); er <= tabsel[ts].bottomRow(); ++er) { + kvoctrainExpr *expr = doc->getEntry(er); + + if (col >= 0) { + // only updated "common" props in multimode + if (entryDlg->fromGradeDirty() ) + expr->setGrade(col, entryDlg->getFromGrade(), false); + if (entryDlg->toGradeDirty() ) + expr->setGrade(col, entryDlg->getToGrade(), true); + + if (entryDlg->fromQCountDirty() ) + expr->setQueryCount(col, entryDlg->getFromQCount(), false); + if (entryDlg->toQCountDirty() ) + expr->setQueryCount(col, entryDlg->getToQCount(), true); + + if (entryDlg->fromBCountDirty() ) + expr->setBadCount(col, entryDlg->getFromBCount(), false); + if (entryDlg->toBCountDirty() ) + expr->setBadCount(col, entryDlg->getToBCount(), true); + + if (entryDlg->fromDateDirty() ) + expr->setQueryDate(col, entryDlg->getFromDate(), false); + if (entryDlg->toDateDirty() ) + expr->setQueryDate(col, entryDlg->getToDate(), true); + + if (entryDlg->usageDirty() ) { + for (int j = 0; j <= expr->numTranslations(); j++) + expr->setUsageLabel (j, entryDlg->getUsageLabel()); + } + + if (entryDlg->typeDirty() ) + for (int j = 0; j <= expr->numTranslations(); j++) + expr->setType(j, entryDlg->getType()); + } + + if (entryDlg->activeDirty() ) + expr->setActive(entryDlg->getActive()); + + if (entryDlg->lessonDirty() ) + expr->setLesson (entryDlg->getLesson()); + } + } + entryDlg->setModified(false); + doc->setModified(true); + for (uint ts = 0; ts < tabsel.size(); ++ts) + for (int r = tabsel[ts].topRow(); r <= tabsel[ts].bottomRow(); ++r) + for (int c = 0; c < view->getTable()->numCols(); ++c) + view->getTable()->updateCell(r, c); + + } +} + + +void kvoctrainApp::createEntryDlg(int row, int col) +{ + if (entryDlg != 0) { + kdError() << "kvoctrainApp::createEntryDlg: entryDlg != 0\n"; + return; + } + + if ((row < 0) || (col < 0) || (view->getTable()->numRows() <= 0)) + return; + + QString title, text, lang; + + int lesson = doc->getEntry(row)->getLesson(); + if (lesson >= lessons->count()) + lesson = QMAX (0, lessons->count()-1); + + if (col < KV_EXTRA_COLS) { + title = i18n("Edit General Properties"); + col -= KV_EXTRA_COLS; + entryDlg = new EntryDlg ( + this, + doc, + hasSelection(), + true, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + QString::null, + QString::null, + QString::null, + lesson, + lessons, + doc->getOriginalIdent(), + langset, + QString::null, + doc->getEntry(row)->getType(col), + QString::null, + QString::null, + QString::null, + QString::null, + QString::null, + QString::null, + doc->getConjugation(0), + Conjugation(), + doc->getArticle(0), + Comparison(), + MultipleChoice(), + querymanager, + title, + doc->getEntry(row)->isActive(), + Prefs::iPAFont()); + } + else { + col -= KV_EXTRA_COLS; + + if (col == 0) { + lang = doc->getOriginalIdent(); + text = doc->getEntry(row)->getOriginal(); + title = i18n("Edit Properties for Original"); + } + else { + lang = doc->getIdent(col); + text = doc->getEntry(row)->getTranslation(col); + title = i18n("Edit Properties of a Translation"); + } + + entryDlg = new EntryDlg ( + this, + doc, + hasSelection(), + col==0, + doc->getEntry(row)->getGrade(col, false), + doc->getEntry(row)->getGrade(col, true), + doc->getEntry(row)->getQueryCount(col, false), + doc->getEntry(row)->getQueryCount(col, true), + doc->getEntry(row)->getBadCount(col, false), + doc->getEntry(row)->getBadCount(col, true), + doc->getEntry(row)->getQueryDate(col, false), + doc->getEntry(row)->getQueryDate(col, true), + doc->getEntry(row)->getFauxAmi(col, false), + doc->getEntry(row)->getFauxAmi(col, true), + text, + lesson, + lessons, + lang, + langset, + doc->getEntry(row)->getRemark(col), + doc->getEntry(row)->getType(col), + doc->getEntry(row)->getPronunce(col), + doc->getEntry(row)->getSynonym(col), + doc->getEntry(row)->getAntonym(col), + doc->getEntry(row)->getExample(col), + doc->getEntry(row)->getUsageLabel(col), + doc->getEntry(row)->getParaphrase(col), + doc->getConjugation(col), + doc->getEntry(row)->getConjugation(col), + doc->getArticle(col), + doc->getEntry(row)->getComparison(col), + doc->getEntry(row)->getMultipleChoice(col), + querymanager, + title, + doc->getEntry(row)->isActive(), + Prefs::iPAFont()); + } + connect( entryDlg, SIGNAL(sigEditChoice(int)), + this, SLOT(slotEditCallBack(int))); + + view->getTable()->setReadOnly(true); + + if (col == 0) + entryDlg->setEnabled(EntryDlg::EnableOnlyOriginal); + else + entryDlg->setEnabled(EntryDlg::EnableAll); + + vector<QTableSelection> tabsel; + entryDlg->setCell(row, col+KV_EXTRA_COLS, tabsel); + entryDlg->show(); +} + + +void kvoctrainApp::removeEntryDlg() +{ +// cout << "red\n"; + if (entryDlg != 0) { + commitEntryDlg(false); + delete entryDlg; + entryDlg = 0; + } + + view->getTable()->setReadOnly(false); +} + + +void kvoctrainApp::slotEditEntry (int row, int col) +{ + if (entryDlg == 0) { + createEntryDlg(row, col); + return; + } + + if (entryDlg->isModified()) { + commitEntryDlg(false); + } + + setDataEntryDlg(row, col); +} + + +void kvoctrainApp::setDataEntryDlg (int row, int col) +{ +// cout << "sded\n"; + if (entryDlg == 0) { + kdError() << "kvoctrainApp::setDataEntryDlg: entryDlg == 0\n"; + return; + } + + if ((row < 0) || (col < 0) || (view->getTable()->numRows() <= 0)) + return; + + QString text, lang, title; + + kvoctrainExpr *expr = doc->getEntry(row); + + if (expr == 0) + return; // entry delete in the meantime + + int lesson = expr->getLesson(); + if (lesson >= lessons->count()) + lesson = QMAX (0, lessons->count()-1); + + bool hasSel = hasSelection(); + + if (col < KV_EXTRA_COLS) { + title = i18n("Edit General Properties"); + col -= KV_EXTRA_COLS; + entryDlg->setData(doc, + hasSel, + true, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + QString::null, + QString::null, + QString::null, + lesson, + lessons, + doc->getOriginalIdent(), + langset, + QString::null, + doc->getEntry(row)->getType(0), + QString::null, + QString::null, + QString::null, + QString::null, + QString::null, + QString::null, + doc->getConjugation(0), + Conjugation(), + doc->getArticle(0), + Comparison(), + MultipleChoice(), + querymanager, + title, + doc->getEntry(row)->isActive()); + } + else { + col -= KV_EXTRA_COLS; + + if (col == 0) { + title = i18n("Edit Properties for Original"); + lang = doc->getOriginalIdent(); + text = doc->getEntry(row)->getOriginal(); + } + else { + lang = doc->getIdent(col); + text = doc->getEntry(row)->getTranslation(col); + title = i18n("Edit Properties of a Translation"); + } + + entryDlg->setData(doc, + hasSel, + col==0, + doc->getEntry(row)->getGrade(col, false), + doc->getEntry(row)->getGrade(col, true), + doc->getEntry(row)->getQueryCount(col, false), + doc->getEntry(row)->getQueryCount(col, true), + doc->getEntry(row)->getBadCount(col, false), + doc->getEntry(row)->getBadCount(col, true), + doc->getEntry(row)->getQueryDate(col, false), + doc->getEntry(row)->getQueryDate(col, true), + doc->getEntry(row)->getFauxAmi(col, false), + doc->getEntry(row)->getFauxAmi(col, true), + text, + lesson, + lessons, + lang, + langset, + doc->getEntry(row)->getRemark(col), + doc->getEntry(row)->getType(col), + doc->getEntry(row)->getPronunce(col), + doc->getEntry(row)->getSynonym(col), + doc->getEntry(row)->getAntonym(col), + doc->getEntry(row)->getExample(col), + doc->getEntry(row)->getUsageLabel(col), + doc->getEntry(row)->getParaphrase(col), + doc->getConjugation(col), + doc->getEntry(row)->getConjugation(col), + doc->getArticle(col), + doc->getEntry(row)->getComparison(col), + doc->getEntry(row)->getMultipleChoice(col), + querymanager, + title, + doc->getEntry(row)->isActive()); + } + view->getTable()->updateCell(row, col); + view->getTable()->updateCell(row, KV_COL_LESS); + vector<QTableSelection> tabsel; + if (hasSel) { + for (int i = 0; i < view->getTable()->numSelections(); ++i) + tabsel.push_back(view->getTable()->selection(i)); + } + entryDlg->setCell(row, col+KV_EXTRA_COLS, tabsel); +} + + +void kvoctrainApp::slotDocProps () +{ + int old_lessons = (int) lessons->count(); + int old_types = (int) doc->getTypeDescr().size(); + int old_tenses = (int) doc->getTenseDescr().size(); + int old_usages = (int) doc->getUsageDescr().size(); + vector<int> old_lessoninquery = doc->getLessonsInQuery(); + + DocPropsDlg ddlg (doc, + 0, + lessons, + doc->getTitle(), + doc->getAuthor(), + doc->getLicense(), + doc->getDocRemark(), + doc->getTypeDescr(), + doc->getTenseDescr(), + doc->getUsageDescr()); + + int res = ddlg.exec(); + + if (res == QDialog::Accepted) { + vector<int> typeIndex; + vector<int> tenseIndex; + vector<int> usageIndex; + vector<int> lessonIndex; + vector<QString> new_typeStr; + vector<QString> new_tenseStr; + vector<QString> new_usageStr; + vector<QString> new_lessonStr; + vector<int> new_lessoninquery; + + doc->allowSorting(ddlg.getSorting() ); + + doc->setTitle(ddlg.getTitle() ); + doc->setAuthor(ddlg.getAuthor() ); + doc->setLicense(ddlg.getLicense() ); + doc->setDocRemark(ddlg.getDocRemark() ); + + slotStatusMsg(i18n("Updating lesson indices...")); + QApplication::setOverrideCursor( waitCursor ); + + ddlg.getLesson(lessons, lessonIndex); + ddlg.getTypeNames(new_typeStr, typeIndex); + ddlg.getTenseNames(new_tenseStr, tenseIndex); + ddlg.getUsageLabels(new_usageStr, usageIndex); + + new_lessoninquery = old_lessoninquery; + LessOptPage::cleanUnused(doc, lessons, lessonIndex, old_lessons, new_lessoninquery); + for (int i = 1; i < lessons->count(); i++) + new_lessonStr.push_back(lessons->text(i)); + + slotStatusMsg(i18n("Updating type indices...")); + TypeOptPage::cleanUnused(doc, typeIndex, old_types); + QueryManager::setTypeNames (new_typeStr); + + slotStatusMsg(i18n("Updating tense indices...")); + TenseOptPage::cleanUnused(doc, tenseIndex, old_tenses); + Conjugation::setTenseNames (new_tenseStr); + + slotStatusMsg(i18n("usage (area) of an expression", + "Updating usage label indices...")); + UsageOptPage::cleanUnused(doc, usageIndex, old_usages); + UsageManager::setUsageNames (new_usageStr); + + doc->setTypeDescr (new_typeStr); + doc->setTenseDescr (new_tenseStr); + doc->setUsageDescr (new_usageStr); + doc->setLessonDescr (new_lessonStr); + doc->setLessonsInQuery(new_lessoninquery); + querymanager.setLessonItems(new_lessoninquery); + + doc->setModified(); + view->getTable()->updateContents(); + + setCaption(kapp->makeStdCaption(doc->getTitle(), false, doc->isModified())); + + QApplication::restoreOverrideCursor(); + slotStatusMsg(IDS_DEFAULT); + } +} + + +void kvoctrainApp::slotDocPropsLang () +{ + DocPropsLangDlg ldlg (doc, &langset); + int res = ldlg.exec(); + + if (res == QDialog::Accepted) { + for (int i = 0; i < doc->numLangs(); i++) { + doc->setArticle(i, ldlg.getArticle(i) ); + doc->setConjugation(i, ldlg.getConjugation(i) ); + } + + doc->setModified(); + view->getTable()->updateContents(); + setCaption(kapp->makeStdCaption(doc->getTitle(), false, doc->isModified())); + + slotStatusMsg(IDS_DEFAULT); + } +} + + +void kvoctrainApp::slotModifiedDoc(bool mod) +{ + setCaption(kapp->makeStdCaption(doc->getTitle(), false, doc->isModified())); + slotStatusMsg(IDS_DEFAULT); +} + + +bool kvoctrainApp::hasSelection() +{ + int num = view->getTable()->numSelections(); + if (num < 1) return false; + if (num > 1) return true; + QTableSelection ts = view->getTable()->selection(0); + return (ts.bottomRow() - ts.topRow()) > 0; +} + + +void kvoctrainApp::slotRemoveRow() +{ + if (!hasSelection()) { + if( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, + i18n("Do you really want to delete the selected entry?\n"), + kapp->makeStdCaption(""),KStdGuiItem::del())) + { + KVocTrainTable *table = view->getTable(); + doc->removeEntry(table->currentRow()); + doc->setModified(); + table->updateContents(); + } + } + else { + if(KMessageBox::Continue == KMessageBox::warningContinueCancel(this, + i18n("Do you really want to delete the selected range?\n"), + kapp->makeStdCaption(""),KStdGuiItem::del())) + { + KVocTrainTable *table = view->getTable(); + + int numRows = table->numRows(); + // Must count backwards otherwise entry-numbering goes wrong when + // deleting. + for (int i = numRows-1; i >= 0; i--) + if (table->isRowSelected(i) ) + doc->removeEntry(i); + doc->setModified(); + table->updateContents(); + } + } + editRemoveSelectedArea->setEnabled(view->getTable()->numRows() > 0); +} + + +void kvoctrainApp::slotAppendRow () +{ + kvoctrainExpr expr; + expr.setLesson(act_lesson); + doc->appendEntry(&expr); + doc->setModified(); + int row = doc->numEntries()-1; + view->getTable()->setRowHeight(row, view->getTable()->fontMetrics().lineSpacing() ); + view->getTable()->setCurrentRow(row, KV_COL_ORG); + view->getTable()->updateContents(row, KV_COL_ORG); + view->getTable()->clearSelection(); + view->getTable()->selectRow(row); + editRemoveSelectedArea->setEnabled(view->getTable()->numRows() > 0); +} + + +void kvoctrainApp::keyReleaseEvent( QKeyEvent *e ) +{ + switch( e->key() ) { + case Key_Shift: shiftActive = false; + break; + + case Key_Alt: altActive = false; + break; + + case Key_Control: controlActive = false; + break; + } +} + + +void kvoctrainApp::keyPressEvent( QKeyEvent *e ) +{ + controlActive = (e->state() & ControlButton) != 0; + shiftActive = (e->state() & ShiftButton) != 0; + altActive = (e->state() & AltButton) != 0; + + switch( e->key() ) { + case Key_Plus: + if (controlActive) { + int less = lessons->currentItem(); + if (less == lessons->count()-1) + lessons->setCurrentItem(0); + else + lessons->setCurrentItem(less+1); + slotChooseLesson(lessons->currentItem()); + } + break; + + case Key_Minus: + if (controlActive) { + int less = lessons->currentItem(); + if (less == 0) + lessons->setCurrentItem(lessons->count()-1); + else + lessons->setCurrentItem(less-1); + slotChooseLesson(lessons->currentItem()); + } + break; + + case Key_Shift: shiftActive = true; + break; + + case Key_Alt: altActive = true; + break; + + case Key_Control: controlActive = true; + break; + + case Key_Tab: + if (view->getTable()->hasFocus() ) { + searchLine->setFocus(); + searchLine->selectAll(); + } + else + view->getTable()->setFocus(); + break; + + case Key_Backtab: + if (searchLine->hasFocus() ) + view->getTable()->setFocus(); + else { + searchLine->setFocus(); + searchLine->selectAll(); + } + break; + + case Key_Delete: + slotRemoveRow(); + break; + + case Key_Insert: { + slotAppendRow(); + } + break; + + default: + bool found = false; + if (!found) + e->ignore(); + } + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotChooseLesson(int idx) +{ + act_lesson = idx; + doc->setCurrentLesson(idx); + doc->setModified(true); +} + + +void kvoctrainApp::slotCreateLesson(int header) +{ + vector <int> sel; + doc->setModified(); + for (int i = 0; i < view->getTable()->count(); i++) { + kvoctrainExpr *kv = view->getTable()->getRow(i); + kv->setLesson(0); + if (kv->getGrade(header) > THRESH_LESSON + && !kv->getTranslation(header).isEmpty() ) + sel.push_back(i); + } + + int cnt = 0; + while (cnt < MAX_LESSON && sel.size() != 0) { + int nr = random.getLong(sel.size()); + kvoctrainExpr *kv = view->getTable()->getRow(sel[nr]); + // include non-lesson and non-empty string + if (kv->getLesson() == 0) { + kv->setLesson(1); + sel.erase (sel.begin() + nr); + cnt++; + } + } + view->getTable()->updateContents(); +} + + +void kvoctrainApp::slotShowStatist() +{ + StatistikDlg sdlg (langset, doc); + sdlg.exec(); +} + + +void kvoctrainApp::slotCleanVocabulary () +{ + prepareProgressBar(); + QApplication::setOverrideCursor( waitCursor ); + int num = doc->cleanUp(); + QApplication::restoreOverrideCursor(); + removeProgressBar(); + + slotStatusMsg(IDS_DEFAULT); + + if (num != 0) { + view->setView(doc, langset); + QString s = + i18n("1 entry with the same content has been found and removed.", + "%n entries with the same content have been found and removed.", num); + + KMessageBox::information(this, + s, + kapp->makeStdCaption(i18n("Clean Up"))); + } +} + + +void kvoctrainApp::slotCreateRandom() +{ + bool ok = FALSE; + int res = KInputDialog::getInteger(i18n( "Entries in Lesson" ), + i18n( "Enter number of entries in lesson:" ), Prefs::entriesPerLesson(), 1, 1000, 1, &ok, this ); + if (!ok) + return; + + Prefs::setEntriesPerLesson(res); + + slotStatusMsg(i18n("Creating random lessons...")); + QApplication::setOverrideCursor( waitCursor ); + + vector<kvoctrainExpr*> randomList; + for (int i = 0; i < doc->numEntries(); i++) { + kvoctrainExpr *expr = doc->getEntry(i); + if (expr->getLesson() == 0) + randomList.push_back(expr); + } + + if (randomList.size () != 0) { + int less_no = lessons->count() /* +1 anyway */ ; + QString s; + s.setNum (less_no); + s.insert (0, "- "); + lessons->insertItem (s); + int less_cnt = Prefs::entriesPerLesson(); + while (randomList.size () != 0) { + if (--less_cnt <= 0) { + less_cnt = Prefs::entriesPerLesson(); + less_no++; + s.setNum (less_no); + s.insert (0, "- "); + lessons->insertItem (s); + } + int nr = random.getLong(randomList.size()); + randomList[nr]->setLesson(less_no); + randomList.erase(randomList.begin() + nr); + } + + vector<QString> new_lessonStr; + for (int i = 1; i < lessons->count(); i++) + new_lessonStr.push_back(lessons->text(i)); + doc->setLessonDescr (new_lessonStr); + view->getTable()->updateContents(); + doc->setModified (); + } + QApplication::restoreOverrideCursor(); + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotGeneralOptions() +{ + slotGeneralOptionsPage(-1); +} + + +void kvoctrainApp::slotGeneralOptionsPage(int index) +{ + KVocTrainPrefs* dialog = new KVocTrainPrefs(langset, doc, lessons, &querymanager, this, "settings", Prefs::self() ); + connect(dialog, SIGNAL(settingsChanged()), this, SLOT(slotApplyPreferences())); + if (index >= 0) + dialog->selectPage(index); + dialog->show(); +} + + +void kvoctrainApp::slotApplyPreferences() +{ + kdDebug() << "Prefs Update" << endl; + if (pron_label) + pron_label->setFont(Prefs::iPAFont()); + view->getTable()->setFont(Prefs::tableFont()); + view->getTable()->updateContents(); + + readLanguages(); + // update header buttons + for (int i = 0; i < (int) doc->numLangs(); i++) + { + QString sid = i>0 ? doc->getIdent(i): doc->getOriginalIdent(); + int idx = langset.indexShortId(sid); + QString pm = ""; + QString lid = sid; + if (idx >= 0) + { + lid = langset.longId(idx); + pm = langset.PixMapFile(idx); + } + view->setHeaderProp(i + KV_EXTRA_COLS, lid, pm); + } +} + + +void kvoctrainApp::slotAppendLang(int header_and_cmd) +{ + int lang_id = (header_and_cmd >> 16) & 0xFF; + + if (lang_id == 0xFF) { + QString msg = i18n("To append a new language which is not listed in " + "the submenu, you must first add its data in the " + "general options dialog.\n" + "Should this dialog be invoked now?"); + if( KMessageBox::Yes == KMessageBox::questionYesNo(this, + msg, + kapp->makeStdCaption(""),i18n("Invoke Dialog"), i18n("Do Not Invoke"))) + { + slotGeneralOptionsPage(1); + } + return; + } + + if (lang_id >= (int) langset.size()) + return; + doc->appendLang(""); + int num = doc->numEntries()-1; + for (int i = 0; i < (int) num; i++) { + kvoctrainExpr *expr = doc->getEntry(i); + expr->setType (num, expr->getType(0)); + } + + doc->setIdent(doc->numLangs()-1, langset.shortId(lang_id)); + view->setView(doc, langset); + doc->setModified(); +} + + +void kvoctrainApp::slotInitSearch() +{ + searchpos = 0; + searchstr = ""; +} + + +void kvoctrainApp::slotSearchNext() +{ + slotResumeSearch(searchstr); +} + + +void kvoctrainApp::slotResumeSearch(const QString& s) +{ + if (s.length() == 0) { + slotInitSearch(); + return; + } + + slotStatusMsg(i18n("Searching expression...")); + QApplication::setOverrideCursor( waitCursor ); + + // new word or shortend word + if (s.length() < searchstr.length() ) + searchpos = 0; + + // search in current col from current row till end + // SHIFT means start search from beginning of word + bool word_beg = controlActive; + int idx = doc->search(s, view->getTable()->currentColumn()-KV_EXTRA_COLS, searchpos, -1, word_beg, false); + if (idx >= 0) { + view->getTable()->clearSelection(); + view->getTable()->setCurrentRow(idx, view->getTable()->currentColumn()); + searchpos = idx+1; + } + else { // try again from beginning up to current pos + int idx = doc->search(s, view->getTable()->currentColumn()-KV_EXTRA_COLS, 0, searchpos, word_beg, false); + if (idx >= 0) { + view->getTable()->clearSelection(); + view->getTable()->setCurrentRow(idx, view->getTable()->currentColumn()); + searchpos = idx+1; + } + else + searchpos = 0; + } + + searchstr = s; + QApplication::restoreOverrideCursor(); + slotStatusMsg(IDS_DEFAULT); +} + + +void kvoctrainApp::slotStatusMsg(const QString &/*text*/) +{ +// +} + + +void kvoctrainApp::aboutToShowLearn() +{ + learn_menu->clear(); + + vector<QString> set_names; + for (int i = 0; i < (int) langset.size(); i++) { + if(langset.longId(i).isEmpty() ) + set_names.push_back(langset.shortId(i)); + else + set_names.push_back(langset.longId(i)); + } + + vector<QString> main_names; + for (int j = 0; j < (int) doc->numLangs(); j++) { + int i; + QString did = j == 0 ? doc->getOriginalIdent() + : doc->getIdent(j); + if ((i = langset.indexShortId(did)) >= 0) + main_names.push_back(langset.longId(i)); + else + main_names.push_back(did); + } + + for (int header = 0; header < (int) doc->numLangs(); header++) { + // show pixmap and long name if available + int j; + header_m = new QPopupMenu(); + if (header != 0 ) { + header_m->insertItem(SmallIconSet("run_query"), i18n("Create Random &Query"), (header << 16) | IDH_START_QUERY); + header_m->insertItem(SmallIconSet("run_multi"), i18n("Create &Multiple Choice"), (header << 16) | IDH_START_MULTIPLE); + + header_m->setItemEnabled((header << 16) | IDH_START_MULTIPLE, doc->numLangs() > 1); + header_m->setItemEnabled((header << 16) | IDH_START_QUERY, doc->numLangs() > 1); + header_m->insertSeparator(); + + header_m->insertItem(i18n("&Verbs"), (header << 16) | IDH_START_VERB); + header_m->insertItem(i18n("&Articles"), (header << 16) | IDH_START_ARTICLE); + header_m->insertItem(i18n("&Comparison Forms"), (header << 16) | IDH_START_ADJECTIVE); + header_m->insertSeparator(); + header_m->insertItem(i18n("S&ynonyms"), (header << 16) | IDH_START_SYNONYM); + header_m->insertItem(i18n("A&ntonyms"), (header << 16) | IDH_START_ANTONYM); + header_m->insertItem(i18n("E&xamples"), (header << 16) | IDH_START_EXAMPLE); + header_m->insertItem(i18n("&Paraphrase"), (header << 16) | IDH_START_PARAPHRASE); + } + else { + QPopupMenu *query_m = new QPopupMenu(); + QPopupMenu *multiple_m = new QPopupMenu(); + + for (int i = 1; i < (int) doc->numLangs(); i++) { + // show pixmap and long name if available + int j; + if((j = langset.indexShortId(doc->getIdent(i))) >= 0 + && !langset.PixMapFile(j).isEmpty() + && !langset.longId(j).isEmpty() ) { + query_m->insertItem(QPixmap(langset.PixMapFile(j)), i18n("From %1").arg(main_names[i]), + (i << (16+8)) | IDH_START_QUERY); // hack: IDs => header-ids + cmd + } + else { + query_m->insertItem(i18n("From %1").arg(doc->getIdent(i)), (i << (16+8)) | IDH_START_QUERY); + } + } + + header_m->insertItem(SmallIconSet("run_query"), i18n("Create Random &Query"), query_m, (3 << 16) | IDH_NULL); + connect (query_m, SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect (query_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + + for (int i = 1; i < (int) doc->numLangs(); i++) { + // show pixmap and long name if available + int j; + if((j = langset.indexShortId(doc->getIdent(i))) >= 0 + && !langset.PixMapFile(j).isEmpty() + && !langset.longId(j).isEmpty() ) { + multiple_m->insertItem(QPixmap(langset.PixMapFile(j)), i18n("From %1").arg(main_names[i]), + (i << (16+8)) | IDH_START_MULTIPLE); // hack: IDs => header-ids + cmd + } + else { + multiple_m->insertItem(i18n("From %1").arg(doc->getIdent(i)), (i << (16+8)) | IDH_START_MULTIPLE); + } + } + header_m->insertItem(SmallIconSet("run_multi"), i18n("Create &Multiple Choice"), multiple_m, (4 << 16) | IDH_NULL); + header_m->insertSeparator(); + + header_m->insertItem(i18n("Train &Verbs"), (header << 16) | IDH_START_VERB); + header_m->insertItem(i18n("&Article Training"), (header << 16) | IDH_START_ARTICLE); + header_m->insertItem(i18n("&Comparison Training"), (header << 16) | IDH_START_ADJECTIVE); + header_m->insertSeparator(); + header_m->insertItem(i18n("&Synonyms"), (header << 16) | IDH_START_SYNONYM); + header_m->insertItem(i18n("&Antonyms"), (header << 16) | IDH_START_ANTONYM); + header_m->insertItem(i18n("E&xamples"), (header << 16) | IDH_START_EXAMPLE); + header_m->insertItem(i18n("&Paraphrase"), (header << 16) | IDH_START_PARAPHRASE); + + connect (multiple_m, SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect (multiple_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + } + + connect (header_m, SIGNAL(activated(int)), this, SLOT(slotHeaderCallBack(int))); + connect (header_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + + QString id = header == 0 ? doc->getOriginalIdent() + : doc->getIdent(header); + if((j = langset.indexShortId(id)) >= 0 + && !langset.PixMapFile(j).isEmpty() + && !langset.longId(j).isEmpty() ) { + learn_menu->insertItem(QPixmap(langset.PixMapFile(j)), main_names[header], header_m, IDH_NULL); + } + else { + learn_menu->insertItem(id, header_m, IDH_NULL); + } + } + + learn_menu->insertSeparator(); + learn_menu->insertItem(SmallIconSet("run_query"), i18n("Resume &Query"), ID_RESUME_QUERY ); + learn_menu->insertItem(SmallIconSet("run_multi"), i18n("Resume &Multiple Choice"), ID_RESUME_MULTIPLE ); + + learn_menu->setItemEnabled(ID_RESUME_QUERY, query_num != 0); + learn_menu->setItemEnabled(ID_RESUME_MULTIPLE, query_num != 0); + +} + +void kvoctrainApp::aboutToShowVocabAppendLanguage() +{ + if (doc != 0) + { + vocabAppendLanguage->clear(); + QPopupMenu * add_m = vocabAppendLanguage->popupMenu(); + + QStringList names; + for (int i = 0; i < (int) langset.size(); i++) + { + if(langset.longId(i).isEmpty() ) + names.append(langset.shortId(i)); + else + names.append(langset.longId(i)); + } + + for (int i = 0; i < (int) langset.size(); i++) + { + if(!langset.PixMapFile(i).isEmpty() && !langset.longId(i).isEmpty()) + add_m->insertItem(QPixmap(langset.PixMapFile(i)), names[i], (i << 16) | IDH_APPEND); + else + add_m->insertItem(names[i], (i << 16) | IDH_APPEND); + } + + add_m->insertItem(i18n("Another Language..."), (0xFF << 16) | IDH_APPEND); + } +} + + +void kvoctrainApp::aboutToShowVocabSetLanguage() +{ + if (doc != 0) + { + vocabSetLanguage->clear(); + QPopupMenu * set_m = vocabSetLanguage->popupMenu(); + + QStringList names; + for (int i = 0; i < (int) langset.size(); i++) + { + if(langset.longId(i).isEmpty() ) + names.append(langset.shortId(i)); + else + names.append(langset.longId(i)); + } + + for (int header = 0; header < doc->numLangs(); ++header ) + { + // select one of the available languages for the column + QPopupMenu *langs_m = new QPopupMenu(); + // hack: ID => header-id + language + + for (int i = 0; i < (int) langset.size(); i++) { + if(!langset.PixMapFile(i).isEmpty() && !langset.longId(i).isEmpty()) + langs_m->insertItem(QPixmap(langset.PixMapFile(i)), names[i], (header << 16) | (i << (16+8)) | IDH_SET_LANG); + else + langs_m->insertItem(names[i], (header << 16) | (i << (16+8)) | IDH_SET_LANG); + } + + connect (langs_m, SIGNAL(activated(int)), this, SLOT(slotSetHeaderProp(int))); + connect (langs_m, SIGNAL(highlighted(int)), this, SLOT(slotHeaderStatus(int))); + + if (header == 0) + set_m->insertItem(i18n("&Original"), langs_m, (2 << 16) | IDH_NULL); + else { + if (doc->numLangs() <= 2) + set_m->insertItem(i18n("&Translation"), langs_m, (2 << 16) | IDH_NULL); + else + set_m->insertItem(i18n("&%1. Translation").arg(header), langs_m, (2 << 16) | IDH_NULL); + } + } + } +} + + +void kvoctrainApp::aboutToShowVocabRemoveLanguage() +{ + if (doc != 0) + { + vocabRemoveLanguage->clear(); + QPopupMenu * remove_m = vocabRemoveLanguage->popupMenu(); + + QStringList names; + for (int j = 1; j < (int) doc->numLangs(); j++) + { + int i; + if ((i = langset.indexShortId(doc->getIdent(j))) >= 0) + names.append(langset.longId(i)); + else + names.append(doc->getIdent(j)); + } + + for (int i = 1; i < (int) doc->numLangs(); i++) + { + // show pixmap and long name if available + int j; + if((j = langset.indexShortId(doc->getIdent(i))) >= 0 + && !langset.PixMapFile(j).isEmpty() + && !langset.longId(j).isEmpty() ) + remove_m->insertItem(QPixmap(langset.PixMapFile(j)), names[i-1], (i << 16) | IDH_REMOVE); // hack: IDs => header-ids + cmd + else + remove_m->insertItem(doc->getIdent(i), (i << 16) | IDH_REMOVE); + } + } +} + + +void kvoctrainApp::slotStatusHelpMsg(const QString &text) +{ + /////////////////////////////////////////////////////////////////// + // change status message of whole statusbar temporary (text, msec) + if (pbar == 0 || !pbar->isVisible() ) + statusBar()->message(text, 3000); +} + +void kvoctrainApp::slotFilePrint() +{ + slotStatusMsg(i18n("Printing...")); + KPrinter printer; + printer.setFullPage(true); + if (printer.setup(this)) + { + view->print(&printer); + } + + slotStatusMsg(i18n("Ready")); +} + +#include "kvoctrain.moc" + + diff --git a/kvoctrain/kvoctrain/kvoctrain.desktop b/kvoctrain/kvoctrain/kvoctrain.desktop new file mode 100644 index 00000000..c0297b92 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrain.desktop @@ -0,0 +1,80 @@ +[Desktop Entry] +GenericName=Vocabulary Trainer +GenericName[af]=Woordeskat-afrigter +GenericName[ar]=مدرب الكلمات +GenericName[be]=Пашырэнне слоўнікавага запасу +GenericName[bg]=Речникови тренировки +GenericName[bn]=শব্দভাণ্ডার সমৃদ্ধকারী +GenericName[bs]=Učitelj rječnika +GenericName[ca]=Entrenador de vocabulari +GenericName[cs]=Procvičování slovní zásoby +GenericName[csb]=Trener słowiznë +GenericName[cy]=Hyfforddwr Geirfa +GenericName[da]=Ordforrådsøvelser +GenericName[de]=Vokabeltrainer +GenericName[el]=Εκπαιδευτής λεξιλογίου +GenericName[eo]=Vortara trejnado +GenericName[es]=Entrenador de vocabulario +GenericName[et]=Sõnavara treening +GenericName[eu]=Hiztegi entrenatzailea +GenericName[fa]=مربی واژهها +GenericName[fi]=Sanaston harjoittaja +GenericName[fr]=Tester son vocabulaire +GenericName[gl]=Entrenador de Vocabulario +GenericName[he]=מאמן אוצר מילים +GenericName[hi]=शब्दावली प्रशिक्षक +GenericName[hr]=Vježbanje vokabulara +GenericName[hu]=Szótárfüzet +GenericName[is]=Æfir orðaforða +GenericName[it]=Apprendimento di vocaboli +GenericName[ja]=ボキャブラリの強化 +GenericName[ka]=სიტყვათა მარაგის შემოწმება +GenericName[km]=កម្មវិធីបង្ហាត់វាក្យសព្ទ +GenericName[lt]=Žodyno treniruoklis +GenericName[lv]=Mācību Vārdnīca +GenericName[mk]=Тренер за речник +GenericName[mn]=Эгшигийн дасгал +GenericName[ms]=Jurulatih Perbendaharaan Kata +GenericName[nb]=Glosetrening +GenericName[nds]=Vokaveln lehren +GenericName[ne]=शब्दकोश प्रशिक्षक +GenericName[nl]=Woordenschattrainer +GenericName[nn]=Glosetrening +GenericName[nso]=Morutisi wa Tsebo ya Mantsu +GenericName[pl]=Trening słownictwa +GenericName[pt]=Treinar o Vocabulário +GenericName[pt_BR]=Treinador de vocabulário +GenericName[ru]=Тренировка словарного запаса +GenericName[se]=Sátnehárjeheapmi +GenericName[sk]=Tréning slovnej zásoby +GenericName[sl]=Učitelj besednega zaklada +GenericName[sr]=Тренер речника +GenericName[sr@Latn]=Trener rečnika +GenericName[sv]=Ordförrådsträning +GenericName[ta]=சொல்லாக்க பயிற்சியாளர் +GenericName[tg]=Машқи Луғат +GenericName[uk]=Тренування словникового запасу +GenericName[ven]=Mugudisi wa ndivho +GenericName[vi]=Luyện tập Từ vựng +GenericName[xh]=Uqeqeshi Wonobumba ababekwe ngokulandelelana +GenericName[zh_CN]=单词练习 +GenericName[zh_TW]=字彙訓練師 +GenericName[zu]=Umlolongi Wokusetshenziswa kwamagama +Name=KVocTrain +Name[af]=K-woord-leerder +Name[ar]=معلم الكلمات ك +Name[bn]=কে-ভকট্রেন +Name[hi]=के-वॉक-ट्रेन +Name[mn]=KЭгшигийн дасгал +Name[sv]=Kvoctrain +Name[ta]=கேவிஒசி பயிற்சி +Name[ven]=U gudiswa ha K +Name[vi]=Tập Từ vựng K +Name[zu]=KVocIsitimela +MimeType=application/x-kvoctrain;text/x-kvtml; +Exec=kvoctrain +Icon=kvoctrain +DocPath=kvoctrain/index.html +Type=Application +Terminal=false +Categories=Qt;KDE;Education;Languages; diff --git a/kvoctrain/kvoctrain/kvoctrain.dtd b/kvoctrain/kvoctrain/kvoctrain.dtd new file mode 100644 index 00000000..5ba3b81a --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrain.dtd @@ -0,0 +1,52 @@ +<!ELEMENT kvtml - - (lesson?, e*) > +<!ATTLIST kvtml generator CDATA #REQUIRED + title CDATA #REQUIRED> + +<!-- xml tree + kvtml + lesson lesson group + desc description + %no its number + e element + %m + %s + o original + %l language code + %r + t translation + %l language code + %g grade + %d last querydate + %c count of queries + %b count of failed queries + %r +--> + +<!ELEMENT lesson - - (desc*) > + +<!ELEMENT desc - - (#PCDATA)> +<!ATTLIST desc no NUMBER #OPTIONAL > + +<!ELEMENT e - - (o, t+) > +<!ATTLIST e lm NUMBER #OPTIONAL > + +<!ELEMENT o - - (#PCDATA)> +<!ATTLIST o l CDATA #IMPLIED -- must at least appear in first entry ! + d CDATA #IMPLIED +> + +<!ELEMENT t - - (#PCDATA)> +<!ATTLIST t l CDATA #IMPLIED -- must at least appear in first entry ! + g NUMBER #IMPLIED -- assume 1 if missing + d CDATA #IMPLIED + c NUMBER #IMPLIED -- assume 0 if missing + r CDATA #IMPLIED +> + +<!ENTITY ouml ""> +<!ENTITY Ouml ""> +<!ENTITY uuml ""> +<!ENTITY Uuml ""> +<!ENTITY auml ""> +<!ENTITY Auml ""> +<!ENTITY szlig ""> diff --git a/kvoctrain/kvoctrain/kvoctrain.h b/kvoctrain/kvoctrain/kvoctrain.h new file mode 100644 index 00000000..ff81c414 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrain.h @@ -0,0 +1,336 @@ +/*************************************************************************** + + main part of kvoctrain + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KVOCTRAIN_H +#define KVOCTRAIN_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +// include files for QT +#include <qpainter.h> + +// include files for KDE +#include <kapplication.h> +#include <kmainwindow.h> +#include <kaction.h> +#include <kmenubar.h> +#include <kmessagebox.h> +#include <krandomsequence.h> + +// application specific includes +#include "kvoctrainview.h" +#include "kvoctraintable.h" +#include "query-dialogs/QueryDlgBase.h" +#include "kvtnewstuff.h" +#include "langset.h" + +class QTimer; +class KLined; +class ProgressDlg; +class kvoctrainDoc; +class SimpleQueryDlg; +class MCQueryDlg; +class VerbQueryDlg; +class RandomQueryDlg; +class AdjQueryDlg; +class ArtQueryDlg; +class EntryDlg; + +class KLineEdit; +class KComboBox; +class KProgress; + +class KVTNewStuff; + +/** + * This Class is the base class for your application. It sets up the main + * window and reads the config file as well as providing a menubar, toolbar + * and statusbar. For the main view, an instance of class kvoctrainView is + * created which creates your view. + */ +class kvoctrainApp : public KMainWindow +{ + Q_OBJECT + +public: + /** construtor */ + kvoctrainApp(QWidget *parent = NULL, const char *name = NULL); + /** destructor */ + ~kvoctrainApp(); + void initActions(); + + /** setup the statusbar */ + void initStatusBar(); + /** setup the main document*/ + void initDoc(); + /** setup the main view*/ + void initView(); + /** save the app-specific options on slotAppExit or by an Options dialog */ + void saveOptions(); + /** read the app-specific options on init() or by an Options dialog */ + void readOptions(); + + void saveLanguages(); + void readLanguages(); + + /** saves the window properties for each open window during session end to the session config file, including saving the currently + * opened file by a temporary filename provided by KApplication. + * @see KMainWindow#saveProperties + */ + virtual void saveProperties(KConfig* ); + /** reads the session config file and restores the application's state including the last opened files and documents by reading the + * temporary files saved by saveProperties() + * @see KMainWindow#readProperties + */ + virtual void readProperties(KConfig* ); + + /** Whether the user has selected a range of items. **/ + bool hasSelection(); + + signals: + void progressChanged (kvoctrainDoc *, int curr_percent); + + public slots: + void keyPressEvent( QKeyEvent *e ); + void keyReleaseEvent( QKeyEvent *e ); + void slotModifiedDoc(bool mod); + void slotCurrentCellChanged(int row, int col); +// void slotSelectEntry (int row, int col, int key_state); + + /** edit an entry */ + void slotEditEntry(int row, int col); + void slotEditCallBack(int res); + + void commitEntryDlg(bool force); + void createEntryDlg(int row, int col); + void setDataEntryDlg (int row, int col); + void removeEntryDlg(); + + /** select an entry */ + void slotSaveSelection (); + void slotCancelSelection (); + void slotSelectAll(); + void slotProgress(kvoctrainDoc*,int); + void slotResumeSearch(const QString&); + void slotSearchNext(); + void slotInitSearch(); + void slotCreateLesson(int header); + void slotCleanVocabulary (); + void slotChooseLesson(int id); +// void slotSearchClip(); + void slotSetHeaderProp (int header_and_id); + void slotHeaderCallBack (int cmd_and_id); + void slotHeaderStatus (int cmd_and_id); + void slotHeaderMenu(int header, int x, int y); + /** append language to table */ + void slotAppendLang(int header); + /** exit query mode */ + void slotStopQuery(bool show_view); + bool queryClose(); + /** overloaded for Message box on last window exit */ + bool queryExit(); + /** set up options */ + void slotGeneralOptionsPage(int index); + void slotGeneralOptions(); + //void slotQueryOptions(); + //void slotQueryOptions(int pageindex); + void slotApplyPreferences(); + void slotDocProps(); + void slotDocPropsLang(); + void slotShowStatist(); + void slotCreateRandom(); + /** set up vocabulary and learning submenus */ + void aboutToShowVocabAppendLanguage(); + void aboutToShowVocabSetLanguage(); + void aboutToShowVocabRemoveLanguage(); + void aboutToShowLearn(); + + /** starts random query mode */ + void slotRestartQuery(); + void slotStartTypeQuery(int col, const QString & type); + void slotStartPropertyQuery(int col, QueryType property); + void slotStartQuery(const QString & trans, const QString & org, bool create_new); + + void slotTimeOutRandomQuery(QueryDlgBase::Result res); + void slotTimeOutMultipleChoice(QueryDlgBase::Result res); + void slotTimeOutQuery(QueryDlgBase::Result res); + void slotTimeOutType(QueryDlgBase::Result res); + void slotTimeOutProperty(QueryDlgBase::Result res); + + + void slotTimeOutBackup(); + + /** open a new application window */ + void slotFileNew(); + /** open a document */ + void slotFileOpen(); + /** opens a file from the recent files menu */ + void slotFileOpenRecent(const KURL& url); + /** open a sample document */ + void slotFileOpenExample(); + /** download new vocabularies */ + void slotGHNS(); + void loadfileFromPath(const KURL &, bool addRecent=true); + /** merge a document */ + void slotFileMerge(); + /** save a document */ + void slotFileSave(); + /** save a document under a different filename*/ + void slotFileSaveAs(); + void slotFilePrint(); + void slotFileQuit(); + + /** put the marked text/object into the clipboard*/ + void slotEditCopy(); + void slotSmartSearchClip(); + void slotAppendRow(); + void slotRemoveRow(); + void slotEditRow(); + /** paste the clipboard into the document*/ + void slotEditPaste(); + + /** change the status message to text */ + void slotStatusMsg(const QString &text); + /** change the status message of the whole statusbar temporary */ + void slotStatusHelpMsg(const QString &text); + +public: + void removeProgressBar(); + void prepareProgressBar(); + void fillLessonBox(kvoctrainDoc *); + void loadDocProps(kvoctrainDoc *); + void saveDocProps(kvoctrainDoc *); + static vector<int> getCsvOrder(kvoctrainDoc *); + +private: + // KAction pointers to enable/disable actions + KAction* fileNew; + KAction* fileOpen; + KAction* fileOpenExample; + KAction* fileGHNS; + KRecentFilesAction* fileOpenRecent; + KAction* fileMerge; + KAction* fileSave; + KAction* fileSaveAs; + KAction* filePrint; + KAction* fileQuit; + + KAction* editCopy; + KAction* editPaste; + KAction* editSelectAll; + KAction* editClearSelection; + KAction* editSearchFromClipboard; + KAction* editAppend; + KAction* editEditSelectedArea; + KAction* editRemoveSelectedArea; + KAction* editSaveSelectedArea; + + KAction* vocabShowStatistics; + KAction* vocabAssignLessons; + KAction* vocabCleanUp; + KSelectAction* vocabAppendLanguage; + KSelectAction* vocabSetLanguage; + KSelectAction* vocabRemoveLanguage; + KAction* vocabDocumentProperties; + KAction* vocabLanguageProperties; + KWidgetAction* vocabLessons; + KWidgetAction* vocabSearch; + + //KAction* learningResumeQuery; + //KAction* learningResumeMultipleChoice; + + KAction* configToolbar; + KAction* configNotifications; + KAction* configApp; + //KAction* configQueryOptions; + + QString lastPixName; + + QPopupMenu *learn_menu; + + /** view is the main widget which represents your working area. The View + * class should handle all events of the view widget. It is kept empty so + * you can create your view according to your application's needs by + * changing the view class. */ + kvoctrainView *view; + /** doc represents your actual document and is created only once. It keeps + * information such as filename and does the serialization of your files. + */ + kvoctrainDoc *doc; + + friend class kvoctrainView; + + vector<QueryEntryRef> random_expr1, random_expr2; + // Vectors for use in Leitner style learning. There is no + // correct_0_times, we simply reuse random_expr1. + vector<QueryEntryRef> correct_1_times, correct_2_times, correct_3_times; + QuerySelection queryList; + //KNewStuff *m_GHNS; + QTimer *btimer; + int random_query_nr; + bool querymode; + bool querying; + QString def_lang; + QPopupMenu *header_m; + int act_query_col; + QString act_query_trans; + QString act_query_org; + LangSet langset; + int searchpos; + QString searchstr; + KLineEdit *searchLine; + KComboBox *lessons; + int act_lesson; + QueryManager querymanager; + bool controlActive; + bool shiftActive; + bool altActive; + ProgressDlg *pdlg; + KProgress *pbar; + QLabel *vslide_label; + QLabel *pron_label; + QLabel *rem_label; + QLabel *type_label; + SimpleQueryDlg *simpleQueryDlg; + EntryDlg *entryDlg; + MCQueryDlg *mcQueryDlg; + VerbQueryDlg *verbQueryDlg; + RandomQueryDlg *randomQueryDlg; + AdjQueryDlg *adjQueryDlg; + ArtQueryDlg *artQueryDlg; + int num_queryTimeout; + int query_cycle; + int query_num; + int query_startnum; + QueryType queryType; + KRandomSequence random; + KVTNewStuff *m_newStuff; +}; + +#endif // KVOCTRAIN_H + diff --git a/kvoctrain/kvoctrain/kvoctrain.lsm.tpl b/kvoctrain/kvoctrain/kvoctrain.lsm.tpl new file mode 100644 index 00000000..8a607c06 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrain.lsm.tpl @@ -0,0 +1,23 @@ +Begin3 +Title: kvoctrain +Version: =VERSION= +Entered-date: =DATE= +Description: Helps you to train your vocabulary (in almost any language) + based on your own dictionary + Attention: + ---------- + This package contains no documentation +Keywords: Unix, KDE, X11, vocabulary, dictionary, learn, train +Author: <ewald@ewald-arnold.de> Ewald Arnold +Maintained-by: <ewald@ewald-arnold.de> Ewald Arnold +Primary-site: http://sourceforge.net/project/showfiles.php?group_id=9265 + =ARCLEN=kB kvoctrain-=VERSION=.tar.bz2 +Home-Page: http://kvoctrain.sourceforge.net +Alternate-site: http://sourceforge.net/projects/kvoctrain +Original-site: +Platform: every system KDE runs on. + Tested with: (see README.kde1x-kde2x in case of problems) + - KDE 1.1.2/QT1.45 + - KDE2.0/QT2.2 +Copying-policy: GPL +End diff --git a/kvoctrain/kvoctrain/kvoctrainrc b/kvoctrain/kvoctrain/kvoctrainrc new file mode 100644 index 00000000..f9839cc4 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrainrc @@ -0,0 +1,2 @@ +[KNewStuff] +ProvidersUrl=http://edu.kde.org/contrib/kvtml/providers.xml diff --git a/kvoctrain/kvoctrain/kvoctraintable.cpp b/kvoctrain/kvoctrain/kvoctraintable.cpp new file mode 100644 index 00000000..98e64c13 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctraintable.cpp @@ -0,0 +1,606 @@ +/*************************************************************************** + + table for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Jan 4 19:04:53 PST 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qpainter.h> +#include <qstyle.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <kmessagebox.h> +#include <dcopclient.h> +#include <klocale.h> +#include <kglobalsettings.h> +#include <kstandarddirs.h> +#include <kiconloader.h> + +#include "kvoctraintable.h" +#include "kv_resource.h" +#include "prefs.h" + +KVocTrainTable::KVocTrainTable(kvoctrainDoc *doc, const LangSet *ls, QWidget *parent, const char *name) + : QTable(parent, name), langs(ls) +{ + m_doc = doc; + defaultItem = 0; + setNumCols(m_doc->numLangs()); + setNumRows(m_doc->numEntries()); + + setLeftMargin(0); + setSelectionMode(MultiRow); + setColumnMovingEnabled(false); + setRowMovingEnabled(false); + setSorting(false); + + setDoc(m_doc); + + triggerSect = -1; + + m_pixInQuery = QPixmap(KGlobal::iconLoader()->loadIcon("ok", KIcon::Small)); + m_pixInactive = QPixmap(KGlobal::iconLoader()->loadIcon("no", KIcon::Small)); + + delayTimer = new QTimer(this); + connect(delayTimer, SIGNAL(timeout()), this, SLOT(menuTriggerTimeout())); + + QHeader *header = horizontalHeader(); + connect(header, SIGNAL(pressed(int)), this, SLOT(headerPressEvent(int))); + connect(header, SIGNAL(released(int)), this, SLOT(headerReleaseEvent(int))); + + connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(slotCurrentChanged(int, int))); +} + + +void KVocTrainTable::setCurrentItem(int row) +{ + setCurrentRow(row, currentColumn()); +} +/* +QWidget* KVocTrainTable::beginEdit(int row, int col, bool replace) +{ + if (KApplication::dcopClient()->isApplicationRegistered("kxkb")) + { + if (m_doc) + { + QString id = (col == KV_COL_ORG) ? m_doc->getOriginalIdent() : m_doc->getIdent(col - KV_EXTRA_COLS); + + if (langs) + { + QString kbLayout(langs->keyboardLayout(langs->indexShortId(id))); + kdDebug() << "Keyboard Layout: " << kbLayout << endl; + if (!kbLayout.isEmpty()) + { + QByteArray data, replyData; + QCString replyType; + QDataStream arg(data, IO_WriteOnly); + arg << kbLayout; + + if (!KApplication::dcopClient()->call("kxkb", "kxkb", "setLayout(QString)", data, replyType, replyData)) + { + kdDebug() << "kxkb dcop error: beginEdit()" << endl; + } + } + } + } + } + return QTable::beginEdit(row, col, replace); +} + +void KVocTrainTable::endEdit(int row, int col, bool accept, bool replace) +{ + QTable::endEdit(row, col, accept, replace); +} +*/ +void KVocTrainTable::sortByColumn(int header, bool alpha) { + if (header == KV_COL_MARK) + return; + + if (header >= numRows()) { + kdError() << "header >= numRows()\n"; + return; + } + + if (m_doc && !m_doc->isAllowedSorting()) { + KMessageBox::information(this, i18n("Sorting is currently turned off for this document.\n" + "\nUse the document properties dialog to turn sorting on."), kapp->makeStdCaption("")); + return; + } + + QApplication::setOverrideCursor(waitCursor); + + clearSelection(); + + bool sortdir = false; + if (m_doc) { + if (header >= KV_COL_ORG) + sortdir = m_doc->sort(header-KV_EXTRA_COLS); + else + if (alpha) + sortdir = m_doc->sortByLesson_alpha(); + else + sortdir = m_doc->sortByLesson_index(); + } + horizontalHeader()->setSortIndicator(header, sortdir); + repaintContents(); + m_doc->setModified(); + emit currentChanged(currentRow(), currentColumn()); + QApplication::restoreOverrideCursor(); +} + +void KVocTrainTable::sortByColumn_alpha(int header) +{ + sortByColumn(header, true); +} + + +void KVocTrainTable::slotSelectionChanged() +{ + emit currentChanged(currentRow(), currentColumn()); +} + + +void KVocTrainTable::sortByColumn_index(int header) +{ + sortByColumn(header, false); +} + +void KVocTrainTable::setCurrentRow(int row, int col) +{ + QTable::setCurrentCell(row, col); +} + +void KVocTrainTable::updateContents(int row, int col) +{ + int current_row = row; + if (current_row < 0) + current_row = currentRow(); + int current_col = col; + if (current_col < 0) + current_col = currentColumn(); + int ncols, nrows; + if (m_doc) { + nrows = m_doc->numEntries(); + ncols = QMAX(1, m_doc->numLangs())+KV_EXTRA_COLS; + } + else { + nrows = 0; + ncols = 1+KV_EXTRA_COLS; + } + if (nrows != numRows()) { + // remember number of new rows (typically one) + unsigned int new_rows = QMAX(0, nrows - numRows()); + // adjust number of rows + setNumRows(nrows); + // adjust row heights for added rows + for (int i=nrows-new_rows; i<nrows; ++i) + setRowHeight(i, fontMetrics().lineSpacing()); + } + if (ncols != numCols()) + setNumCols(ncols); + current_row = QMIN(current_row, QMAX(0, numRows()-1)); + current_col = QMIN(current_col, QMAX(0, numCols()-1)); + bool b = signalsBlocked(); + blockSignals(true); + setCurrentRow(current_row, current_col); + blockSignals(b); + viewport()->update(); + emit currentChanged(current_row, current_col); +} + +kvoctrainExpr *KVocTrainTable::getRow(int row) +{ + if (m_doc) + return m_doc->getEntry(row); + else + return 0; +} + +void KVocTrainTable::setDoc(kvoctrainDoc * rows) +{ + if (defaultItem) + endEdit(defaultItem->row(), defaultItem->col(), true, false); + + KVocTrainTableItem *d = defaultItem; + defaultItem = 0; + + if (rows) { + m_doc = rows; + setNumRows(rows->numEntries()); + setNumCols(QMAX(1+KV_EXTRA_COLS, m_doc->numLangs()+KV_EXTRA_COLS)); + setCurrentRow(0, 0); + } + else { + setNumRows(0); + setNumCols(1+KV_EXTRA_COLS); + m_doc = 0; + } + + if (d == 0) { + defaultItem = new KVocTrainTableItem(this, QTableItem::OnTyping, rows); + } + else { + defaultItem = d; + defaultItem->setDoc(rows); + } + //gradecols = gc; +} + +void KVocTrainTable::menuTriggerTimeout() +{ + delayTimer->stop(); + if (triggerSect == -1) + return; + + int mt = triggerSect; + triggerSect = -1; + + QHeader *header = horizontalHeader(); + int x = leftMargin(); + for (int i = 0; i < mt; ++i) + x += header->sectionSize(i); + QPoint mpos = mapToGlobal(QPoint(x, topMargin())); + + if (mt != KV_COL_MARK) + emit rightButtonClicked(mt, mpos.x(), mpos.y()); + + QMouseEvent me(QEvent::MouseButtonRelease, QPoint(0, 0), QMouseEvent::LeftButton, QMouseEvent::LeftButton); + QApplication::sendEvent(header, &me); +} + +void KVocTrainTable::headerReleaseEvent(int /*sec*/) +{ + delayTimer->stop(); + if(triggerSect == -1) { // long enough pressed for popup menu + return; + } + int mt = triggerSect; + triggerSect = -1; + emit selected(mt); +} + +void KVocTrainTable::headerPressEvent(int sec) +{ + triggerSect = sec; + delayTimer->stop(); + delayTimer->start(500, true); +} + +void KVocTrainTable::setFont(const QFont & font) +{ + QTable::setFont(font); + horizontalHeader()->setFont(KGlobalSettings::generalFont()); + for (unsigned i = 0; i < (unsigned) numRows(); ++i) + setRowHeight(i, fontMetrics().lineSpacing()); +} + +int cellAlignment(const QString & text) +{ + bool num; + bool ok1 = false; + bool ok2 = false; + text.toInt(&ok1); + if (!ok1) + text.toDouble(&ok2); + num = ok1 || ok2; + + return ( num ? Qt::AlignRight : Qt::AlignAuto ) | Qt::AlignVCenter; +} + + +void KVocTrainTable::paintCell(QPainter * p, int row, int col, const QRect & cr, bool selected, const QColorGroup &cg) +{ + if (cr.width() == 0 || cr.height() == 0) + return; + + if (selected && row == currentRow() && col == currentColumn() && (hasFocus() || viewport()->hasFocus())) + selected = false; + + int w = cr.width(); + int h = cr.height(); + int x2 = w - 1; + int y2 = h - 1; + + p->fillRect( 0, 0, w, h, selected ? cg.brush( QColorGroup::Highlight ) : cg.brush( QColorGroup::Base ) ); + + kvoctrainExpr *expr = getRow(row); + if (expr) + { + p->save(); + //cell->paint(p, col, w, selected, m_doc, numCols() == KV_EXTRA_COLS+2 ? KV_COL_TRANS : currentColumn(), gradecols); + + QColor color = KV_NORM_COLOR; + int current_col = numCols() == KV_EXTRA_COLS+2 ? KV_COL_TRANS : currentColumn(); + + if (Prefs::useGradeCol()) + { + if (col > KV_COL_ORG) + { + color = Prefs::gradeCol(0); + if (expr->getQueryCount(col - KV_EXTRA_COLS, false) != 0) + { + switch (expr->getGrade(col-KV_EXTRA_COLS, false)) + { + case KV_NORM_GRADE: color = Prefs::gradeCol(0); break; + case KV_LEV1_GRADE: color = Prefs::gradeCol(1); break; + case KV_LEV2_GRADE: color = Prefs::gradeCol(2); break; + case KV_LEV3_GRADE: color = Prefs::gradeCol(3); break; + case KV_LEV4_GRADE: color = Prefs::gradeCol(4); break; + case KV_LEV5_GRADE: color = Prefs::gradeCol(5); break; + case KV_LEV6_GRADE: color = Prefs::gradeCol(6); break; + case KV_LEV7_GRADE: color = Prefs::gradeCol(7); break; + default : color = Prefs::gradeCol(1); + } + } + } + else if ( col == KV_COL_ORG ) + { + color = Prefs::gradeCol(0); + if (expr->numTranslations() != 0 && current_col > KV_COL_ORG ) + { + if (expr->getQueryCount(current_col - KV_EXTRA_COLS, true) != 0 ) + { + switch (expr->getGrade(current_col - KV_EXTRA_COLS, true)) + { + case KV_LEV1_GRADE: color = Prefs::gradeCol(1); break; + case KV_LEV2_GRADE: color = Prefs::gradeCol(2); break; + case KV_LEV3_GRADE: color = Prefs::gradeCol(3); break; + case KV_LEV4_GRADE: color = Prefs::gradeCol(4); break; + case KV_LEV5_GRADE: color = Prefs::gradeCol(5); break; + case KV_LEV6_GRADE: color = Prefs::gradeCol(6); break; + case KV_LEV7_GRADE: color = Prefs::gradeCol(7); break; + default : color = Prefs::gradeCol(1); + } + } + } + } + } + + if (selected) + p->setPen (cg.highlightedText()); + else + p->setPen (color); + + int fontpos = (p->fontMetrics().lineSpacing() - p->fontMetrics().lineSpacing()) / 2; + + switch (col) + { + case KV_COL_LESS: // lesson + { + QString less_str; + if (m_doc != 0 && expr->getLesson() != 0) + less_str = m_doc->getLessonDescr(expr->getLesson()); + p->drawText( 3, fontpos, w, p->fontMetrics().lineSpacing(), Qt::AlignLeft, less_str); + } + break; + + case KV_COL_MARK: // mark + { + if (!expr->isActive()) + { + p->drawPixmap((w - m_pixInactive.width()) / 2, + (p->fontMetrics().lineSpacing() - m_pixInactive.height())/2, m_pixInactive); + } + else if (expr->isInQuery() ) + { + p->drawPixmap((w - m_pixInQuery.width()) / 2, + (p->fontMetrics().lineSpacing() - m_pixInQuery.height())/2, m_pixInQuery); + } + } + break; + + case KV_COL_ORG: // original + { + QString s = expr->getOriginal(); + p->drawText(3, fontpos, w - 6, p->fontMetrics().lineSpacing(), cellAlignment(s), s); + } + break; + + default: // translation x + QString s = expr->getTranslation(col - KV_COL_ORG); + p->drawText(3, fontpos, w - 6, p->fontMetrics().lineSpacing(), cellAlignment(s), s); + break; + } + p->restore(); + } + + QPen pen( p->pen() ); + int gridColor = style().styleHint( QStyle::SH_Table_GridLineColor, this ); + if (gridColor != -1) { + const QPalette &pal = palette(); + if (cg != colorGroup() + && cg != pal.disabled() + && cg != pal.inactive()) + p->setPen(cg.mid()); + else + p->setPen((QRgb)gridColor); + } else { + p->setPen(cg.mid()); + } + p->drawLine( x2, 0, x2, y2 ); + p->drawLine( 0, y2, x2, y2 ); + p->setPen( pen ); +} + +void KVocTrainTable::setItem(int row, int col, QTableItem * /*item*/) +{ + // ignore item! + updateContents(row, col); +} + +QTableItem * KVocTrainTable::item(int row, int col) const +{ + if (defaultItem) + defaultItem->setPosition(row, col); + return defaultItem; +} + +void KVocTrainTable::keyPressEvent(QKeyEvent * e) +{ + delayTimer->stop(); + switch(e->key()) + { + case Key_Right: { + int topCell = rowAt(0); + int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight())); + if (numCols() > 2) + for (int i = topCell; i <= lastRowVisible; i++) + updateCell(i, KV_COL_ORG); + } // fallthrough + case Key_Up: + case Key_Down: + case Key_Next: + case Key_Prior: + QTable::keyPressEvent(e); + break; + + case Key_Left: { + QTable::keyPressEvent(e); + int topCell = rowAt(0); + int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight())); + if (numCols() > 2) + for (int i = topCell; i <= lastRowVisible; i++) + updateCell(i, KV_COL_ORG); + } + break; + + case Key_Shift: + case Key_Alt: + case Key_Control: // fallthrough + QTable::keyPressEvent(e); + emit forwardKeyPressEvent(e); + break; + + case Key_Minus: + case Key_Plus: + case Key_Tab: + case Key_Backtab: // fallthrough + emit forwardKeyPressEvent(e); + break; + + default: + QTable::keyPressEvent(e); + break; + } +} + +void KVocTrainTable::keyReleaseEvent(QKeyEvent * e) +{ + delayTimer->stop(); + switch(e->key()) + { + case Key_Shift: + case Key_Alt: + case Key_Control: // fallthrough + QTable::keyPressEvent(e); + emit forwardKeyReleaseEvent(e); + break; + } +} + +void KVocTrainTable::contentsMousePressEvent(QMouseEvent * e) +{ + delayTimer->stop(); + int cc = columnAt(e->x()); + int cr = rowAt(e->y()); + int co = currentColumn(); + + QTable::contentsMousePressEvent(e); + + if(cc >= KV_EXTRA_COLS) { + // update color of original when column changes and more than 1 translation + bool update_org = false; + if (cc != co && numCols() > 2) + update_org = true; + + int topCell = rowAt(0); + int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight())); + if (update_org) + for (int i = topCell; i <= lastRowVisible; i++) + updateCell(i, KV_COL_ORG); + } + if(e->button() == LeftButton) + setCurrentCell(cr, cc); +} + +void KVocTrainTable::contentsMouseDoubleClickEvent(QMouseEvent * e) +{ + delayTimer->stop(); + QTable::contentsMouseDoubleClickEvent(e); +} + +void KVocTrainTable::activateNextCell() +{ + int currRow = currentRow(); + int currCol = currentColumn(); + + QTableSelection currentSel = selection(0); + + int tr = currentSel.topRow(); + int br = currentSel.bottomRow(); + int lc = currentSel.leftCol(); + int rc = currentSel.rightCol(); + + if (currCol == rc) + { + if (currRow < br) + setCurrentCell(currRow + 1, lc); + else + setCurrentCell(tr, lc); + } + else + setCurrentCell(currRow, currCol + 1); + +} + +void KVocTrainTable::slotCurrentChanged(int row, int col) +{ + Q_UNUSED(row); + if (KApplication::dcopClient()->isApplicationRegistered("kxkb")) + { + if (m_doc) + { + QString id = (col == KV_COL_ORG) ? m_doc->getOriginalIdent() : m_doc->getIdent(col - KV_EXTRA_COLS); + + if (langs) + { + QString kbLayout(langs->keyboardLayout(langs->indexShortId(id))); + //kdDebug() << "Keyboard Layout: " << kbLayout << endl; + if (!kbLayout.isEmpty()) + { + QByteArray data, replyData; + QCString replyType; + QDataStream arg(data, IO_WriteOnly); + arg << kbLayout; + + if (!KApplication::dcopClient()->call("kxkb", "kxkb", "setLayout(QString)", data, replyType, replyData)) + { + kdDebug() << "kxkb dcop error: beginEdit()" << endl; + } + } + } + } + } + +} + +#include "kvoctraintable.moc" diff --git a/kvoctrain/kvoctrain/kvoctraintable.h b/kvoctrain/kvoctrain/kvoctraintable.h new file mode 100644 index 00000000..f42e0140 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctraintable.h @@ -0,0 +1,106 @@ +/*************************************************************************** + + table for kvoctrain + + ----------------------------------------------------------------------- + + begin : Tue Jan 4 19:04:53 PST 2005 + + copyright :(C) 2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KVOCTRAINTABLE_H +#define KVOCTRAINTABLE_H + +#include <qtable.h> +#include <qtimer.h> + +#include "kvt-core/kvoctraindoc.h" +#include "kvt-core/kvoctrainexpr.h" +#include "kvt-core/langset.h" +#include "kvoctraintableitem.h" + +/** +@author Peter Hedlund +*/ +class KVocTrainTable : public QTable +{ +Q_OBJECT +public: + public: + KVocTrainTable( kvoctrainDoc *_doc, const LangSet *ls, QWidget *parent = NULL, const char *name = NULL ); + + friend class kvoctrainView; + + int currentItem() { return currentRow(); } + void setCurrentItem(int row); + int count() { return numRows(); } + + void setModified(bool _dirty = true) { m_doc->setModified(_dirty); } + QString getIdent(int i) const { return m_doc->getIdent(i); } + QString getOriginalIdent() const { return m_doc->getOriginalIdent(); } + int findIdent(QString id) const { return m_doc->findIdent(id); } + void setCurrentRow(int row, int col); + void updateContents(int row = -1, int col = -1); + kvoctrainExpr *getRow(int row); + void setDoc(kvoctrainDoc *rows); + void setFont(const QFont &); + + signals: + void selected(int row); + void rightButtonClicked(int header, int x, int y); + void forwardKeyPressEvent(QKeyEvent *); + void forwardKeyReleaseEvent(QKeyEvent *); + void edited(int, int); + + public slots: + void sortByColumn_alpha(int index); + void sortByColumn_index(int index); + void slotSelectionChanged(); + void slotCurrentChanged(int, int); + + protected slots: + void menuTriggerTimeout(); + void headerReleaseEvent(int sec); + void headerPressEvent(int sec); + + protected: + int current; + //QWidget* beginEdit(int row, int col, bool replace); + //void endEdit(int row, int col, bool accept, bool replace); + void paintCell(QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg); + void setItem(int row, int col, QTableItem * item); + QTableItem* item (int row, int col) const; + void keyPressEvent(QKeyEvent *e); + void keyReleaseEvent(QKeyEvent *e); + void contentsMousePressEvent(QMouseEvent *e); + void contentsMouseDoubleClickEvent(QMouseEvent *e); + void activateNextCell(); + + private: + kvoctrainDoc * m_doc; + void sortByColumn(int, bool); + const LangSet* langs; + //const GradeCols *gradecols; + KVocTrainTableItem *defaultItem; + QTimer *delayTimer; + int triggerSect; + QPixmap m_pixInactive; + QPixmap m_pixInQuery; +}; + +#endif diff --git a/kvoctrain/kvoctrain/kvoctraintableitem.cpp b/kvoctrain/kvoctrain/kvoctraintableitem.cpp new file mode 100644 index 00000000..9972cd6d --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctraintableitem.cpp @@ -0,0 +1,154 @@ +/*************************************************************************** + + table item for the main view + + ----------------------------------------------------------------------- + + begin : Mon Dec 27 17:05:53 PST 2004 + + copyright : (C) 2004-2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qlineedit.h> +#include <qcombobox.h> + +#include <klocale.h> +#include <kglobalsettings.h> + +#include "kvoctraintableitem.h" + + +KVocTrainTableItem::KVocTrainTableItem( QTable *t, EditType et, kvoctrainDoc *doc) + : QTableItem( t, et, QString::null ) +{ + m_doc = doc; + // we do not want that this item can be replaced + setReplaceable(false); +} + + +void KVocTrainTableItem::setPosition(int curr_row, int curr_col) +{ + setRow(curr_row); + setCol(curr_col); +} + + +void KVocTrainTableItem::setDoc(kvoctrainDoc *doc) +{ + m_doc = doc; +} + + +QWidget *KVocTrainTableItem::createEditor() const +{ + if (m_doc != 0 && m_doc->numEntries() != 0 && row() >= 0 && col() >= 0) { + switch (col()) { + case KV_COL_LESS: { + QComboBox *lessonbox = new QComboBox(table()->viewport() ); + lessonbox->setFont(KGlobalSettings::generalFont()); + lessonbox->insertItem (m_doc->getLessonDescr(0)); + for (unsigned i = 1; i <= (unsigned) m_doc->numLessons(); ++i) + lessonbox->insertItem (m_doc->getLessonDescr(i)); + lessonbox->setCurrentItem(m_doc->getEntry(row())->getLesson()); + return lessonbox; + } + break; + + case KV_COL_MARK: { + QComboBox *statebox = new QComboBox(table()->viewport() ); + statebox->setFont(KGlobalSettings::generalFont()); + statebox->insertItem (i18n("state of a row", "Active, Not in Query")); + statebox->insertItem (i18n("state of a row", "In Query")); + statebox->insertItem (i18n("state of a row", "Inactive")); + QSize sz = statebox->sizeHint(); + sz.setHeight(table()->rowHeight(row())); + statebox->setMinimumSize(sz); + if (!m_doc->getEntry(row())->isActive() ) + statebox->setCurrentItem(2); + else if (m_doc->getEntry(row())->isInQuery() ) + statebox->setCurrentItem(1); + else + statebox->setCurrentItem(0); + return statebox; + } + break; + + default: { + QLineEdit *edit = new QLineEdit(table()->viewport() ); + edit->setFrame(false); + if (col() == KV_COL_ORG) + edit->setText(m_doc->getEntry(row())->getOriginal()); + else + edit->setText(m_doc->getEntry(row())->getTranslation(col()-KV_COL_ORG)); + return edit; + } + } + } + return 0; +} + + +void KVocTrainTableItem::setContentFromEditor( QWidget *w ) +{ + if (m_doc != 0) { + if ( w->inherits( "QComboBox" ) ) { + if (col() == KV_COL_MARK) { + QComboBox *statebox = (QComboBox*) w; + kvoctrainExpr *expr = m_doc->getEntry(row()); + bool inq = false; + bool act = true; + if (statebox->currentItem() == 0) { + inq = false; + act = true; + } + else if (statebox->currentItem() == 1) { + inq = true; + act = true; + } + else if (statebox->currentItem() == 2) { + inq = false; + act = false; + } + if (inq != expr->isInQuery() || + act != expr->isActive() ) + m_doc->setModified(); + expr->setInQuery(inq); + expr->setActive(act); + } + else if (col() == KV_COL_LESS) { + QComboBox *lessonbox = (QComboBox*) w; + if (m_doc->getEntry(row())->getLesson() != lessonbox->currentItem()) + m_doc->setModified(); + m_doc->getEntry(row())->setLesson(lessonbox->currentItem()); + } + } + else { + QLineEdit *edit = (QLineEdit*) w; + if (col() == KV_COL_ORG) { + if (m_doc->getEntry(row())->getOriginal() != edit->text()) + m_doc->setModified(); + m_doc->getEntry(row())->setOriginal(edit->text()); + } + else { + if (m_doc->getEntry(row())->getTranslation(col()-KV_COL_ORG) != edit->text()) + m_doc->setModified(); + m_doc->getEntry(row())->setTranslation(col()-KV_COL_ORG, (edit->text())); + } + } + } +} diff --git a/kvoctrain/kvoctrain/kvoctraintableitem.h b/kvoctrain/kvoctrain/kvoctraintableitem.h new file mode 100644 index 00000000..fc347e43 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctraintableitem.h @@ -0,0 +1,51 @@ +/*************************************************************************** + + table item for the main view + + ----------------------------------------------------------------------- + + begin : Mon Dec 27 17:05:53 PST 2004 + + copyright : (C) 2004-2005 Peter Hedlund + + email : peter.hedlund@kdemail.net + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KVOCTRAINTABLEITEM_H +#define KVOCTRAINTABLEITEM_H + +#include <qtable.h> + +#include "kvoctraindoc.h" +#include "kv_resource.h" + +/** +@author Peter Hedlund + */ +class KVocTrainTableItem : public QTableItem +{ + public: + KVocTrainTableItem( QTable *t, EditType et, kvoctrainDoc *doc ); + QWidget *createEditor() const; + void setContentFromEditor( QWidget *w ); + void setPosition(int row, int col); + void setDoc(kvoctrainDoc *doc); + + private: + kvoctrainDoc * m_doc; +}; + +#endif + diff --git a/kvoctrain/kvoctrain/kvoctrainui.rc b/kvoctrain/kvoctrain/kvoctrainui.rc new file mode 100644 index 00000000..b52d6824 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrainui.rc @@ -0,0 +1,55 @@ +<!DOCTYPE kpartgui> +<kpartgui version="0.4" name="kvoctrain" > + <MenuBar> + <Menu name="file" > + <Action append="open_merge" name="file_open_example" /> + <Action append="open_merge" name="file_ghns" /> + <Separator append="open_merge" /> + <Action append="open_merge" name="file_merge" /> + <Action append="save_merge" name="edit_save_selected_area" /> + <Separator/> + </Menu> + <Menu name="edit" > + <Separator/> + <Action name="edit_append" /> + <Action name="edit_edit_selected_area" /> + <Action name="edit_remove_selected_area" /> + </Menu> + <Menu name="vocabulary" > + <text>Vo&cabulary</text> + <Action name="vocab_show_statistics" /> + <Action name="vocab_assign_lessons" /> + <Action name="vocab_clean_up" /> + <Separator/> + <Action name="vocab_append_language" /> + <Action name="vocab_set_language" /> + <Action name="vocab_remove_language" /> + <Separator/> + <Action name="vocab_document_properties" /> + <Action name="vocab_language_properties" /> + </Menu> + <Menu name="learning" > + <text>&Learning</text> +<!--<Action name="learning_language" /> + <Separator/> + <Action name="learning_resume_query" /> + <Action name="learning_resume_multiple_choice" /> --> + </Menu> +<!-- <Menu name="settings" > + <Action append="configure_merge" name="config_query_options" /> + </Menu>--> + </MenuBar> + <ToolBar noMerge="1" name="mainToolBar" > + <text>Main Toolbar</text> + <Action name="file_open" /> + <Action name="file_save" /> + <Separator name="separator_2" /> + <Action name="edit_copy" /> + <Action name="edit_paste" /> + <Separator name="separator_1" /> + <Action name="vocab_lessons" /> + <Separator name="separator_0" /> + <Action name="edit_find" /> + <Action name="vocab_search" /> + </ToolBar> +</kpartgui> diff --git a/kvoctrain/kvoctrain/kvoctrainview.cpp b/kvoctrain/kvoctrain/kvoctrainview.cpp new file mode 100644 index 00000000..e4ccc163 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrainview.cpp @@ -0,0 +1,397 @@ +/*************************************************************************** + + view to kvoctrain parts + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <kvoctraincore.h> +#include "kvoctrain.h" +#include "kvoctrainview.h" +#include "prefs.h" +#include "langset.h" + +#include <kstandarddirs.h> +#include <kconfig.h> +#include <klocale.h> +#include <kdebug.h> +#include <dcopclient.h> +#include <kapplication.h> +#include <kprinter.h> + +#include <qlayout.h> +#include <qbitmap.h> +#include <qfile.h> + +#include <ctype.h> + +#define HEADER_MINSIZE 24 +#define KV_COLWIDTH_MARK 20 + +kvoctrainView::kvoctrainView(kvoctrainDoc* doc, const LangSet &ls, kvoctrainApp *_parent) : QWidget(_parent) +{ + m_doc = doc; + parent = _parent; + + m_table = new KVocTrainTable(m_doc, &ls, this, "ListBox_1"); + m_table->setFont(Prefs::tableFont()); + m_table->setLineWidth( 2 ); + + if (m_doc->numLangs() == 0) + m_doc->appendLang(i18n("Original")); + + connect(m_table, SIGNAL(selected(int)), m_table, SLOT(sortByColumn_alpha(int))); + connect(m_table, SIGNAL(rightButtonClicked(int, int, int)), parent, SLOT(slotHeaderMenu(int, int, int))); + connect(m_table, SIGNAL(edited(int, int)), parent, SLOT(slotEditEntry(int, int))); + connect(m_table, SIGNAL(currentChanged(int, int)), parent, SLOT(slotCurrentCellChanged(int, int))); + connect(m_table, SIGNAL(selectionChanged()), m_table, SLOT(slotSelectionChanged())); + connect(m_table, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), parent, SLOT(keyPressEvent(QKeyEvent *))); + connect(m_table, SIGNAL(forwardKeyReleaseEvent(QKeyEvent*)), parent, SLOT(keyReleaseEvent(QKeyEvent *))); + + list_layout = new QGridLayout( this, 2, 1/*, 4 */); + list_layout->addWidget(m_table, 1, 0); + list_layout->setRowStretch(1, 1); + list_layout->activate(); + + setView(m_doc, ls); +} + + +void kvoctrainView::showEvent (QShowEvent * s_ev) +{ + QWidget::showEvent(s_ev); + QResizeEvent r_ev(size(), size()); + resizeEvent(&r_ev); +} + + +void kvoctrainView::adjustContent() +{ + QResizeEvent r_ev(size(), size()); + resizeEvent (&r_ev); +} + + +void kvoctrainView::resizeEvent (QResizeEvent *r_ev) +{ + QWidget::resizeEvent(r_ev); + + if (r_ev == 0) + return; + + QHeader *header = m_table->horizontalHeader(); + unsigned oldwidth = 0; + for (int i = 0; i < m_table->numCols(); ++i) + oldwidth += header->sectionSize(i); + + unsigned newwidth = m_table->clipper()->width(); + int remain = newwidth; + + switch (Prefs::headerResizeMode()) + { + case Prefs::EnumHeaderResizeMode::Automatic: + { + // lesson is only half as wide as a original/translation + // exclude fixed size of "mark"-column + int x = (remain -KV_COLWIDTH_MARK) / ((m_table->numCols() - 1) * 2 - 1); + header->resizeSection(KV_COL_LESS, x); + m_table->setColumnWidth (KV_COL_LESS, x); + remain -= x; + header->resizeSection(KV_COL_MARK, KV_COLWIDTH_MARK); + m_table->setColumnWidth (KV_COL_MARK, KV_COLWIDTH_MARK); + remain -= KV_COLWIDTH_MARK; + for (int i = KV_COL_ORG; i < m_table->numCols()-1; i++) + { + remain -= 2 * x; + header->resizeSection(i, 2 * x); + m_table->setColumnWidth (i, 2 * x); + } + header->resizeSection(m_table->numCols() - 1, remain); + m_table->setColumnWidth(m_table->numCols() - 1, remain); + } + break; + + case Prefs::EnumHeaderResizeMode::Percent: + { + float grow = float(newwidth) / float(oldwidth); + header->resizeSection(KV_COL_MARK, KV_COLWIDTH_MARK); + m_table->setColumnWidth(KV_COL_MARK, KV_COLWIDTH_MARK); + int remain = newwidth - KV_COLWIDTH_MARK; + int x = QMAX(20, (int)((header->sectionSize(KV_COL_LESS) * grow) + 0.5)); + header->resizeSection(KV_COL_LESS, x); + m_table->setColumnWidth(KV_COL_LESS, x); + remain -= x; + + for (int i = KV_COL_ORG; i < m_table->numCols() - 1; i++) + { + x = QMAX(20, (int)((header->sectionSize(i) * grow) + 0.5)); + remain -= x; + header->resizeSection(i, x); + m_table->setColumnWidth(i, x); + } + header->resizeSection(m_table->numCols() - 1, QMAX(20, remain)); + m_table->setColumnWidth(m_table->numCols() - 1, QMAX(20, remain)); + } + break; + + case Prefs::EnumHeaderResizeMode::Fixed: + // nix + break; + } + + if (m_doc != 0) { + for (int i = KV_COL_ORG; i < m_table->numCols(); i++) + { + m_doc->setSizeHint (i - KV_EXTRA_COLS, header->sectionSize(i)); + } + m_doc->setSizeHint (-1, header->sectionSize(KV_COL_LESS)); + } +} + + +void kvoctrainView::setView(kvoctrainDoc *doc, const LangSet& ls) +{ + // set header + m_doc = doc; + m_table->setDoc(m_doc); + if (m_doc) { + int id = ls.indexShortId (m_doc->getOriginalIdent()); + + setHeaderProp(KV_COL_LESS, i18n("Lesson"), QString::null); + setHeaderProp(KV_COL_MARK, "", QString::null); + m_table->setColumnWidth(KV_COL_MARK, KV_COLWIDTH_MARK); + + if (id < 0) + setHeaderProp(KV_COL_ORG, m_doc->getOriginalIdent()); + else + setHeaderProp(KV_COL_ORG, ls.longId(id), ls.PixMapFile(id)); + + for (int i = KV_COL_TRANS; i < m_table->numCols(); i++) + { + int id = ls.indexShortId(m_doc->getIdent(i - KV_EXTRA_COLS)); + + if (id < 0) + setHeaderProp(i, m_doc->getIdent(i-KV_EXTRA_COLS)); + else + setHeaderProp(i, ls.longId(id), ls.PixMapFile(id)); + } + + if (m_table->currentColumn() < KV_COL_ORG) + m_table->setCurrentRow(m_table->currentRow(), KV_COL_ORG); + } + m_table->updateContents(); +} + + +kvoctrainView::~kvoctrainView() +{ +} + + +void kvoctrainView::setHeaderProp (int id, const QString &name, const QString &pixfile) +{ + QHeader *header = m_table->horizontalHeader(); + + if (pixfile.isEmpty()) + { + header->setLabel(id, name); + } + else + { + QPixmap pix; + if (QFile::exists(pixfile)) + pix.load(pixfile); + else + { + //this is the code used by kxkb when a flag image can't be found + //see kdebase/kxkb/pixmap.cpp/LayoutIcon::findPixmap() + pix.resize(21, 14); + pix.fill(Qt::white); + + QPainter p(&pix); + + QFont font("sans"); + font.setPixelSize(10); + font.setWeight(QFont::Bold); + p.setFont(font); + p.setPen(Qt::red); + p.drawText(2, 1, pix.width(), pix.height()-2, Qt::AlignCenter, "err"); + p.setPen(Qt::blue); + p.drawText(1, 0, pix.width(), pix.height()-2, Qt::AlignCenter, "err"); + } + + int w = pix.width(); + int h = pix.height(); + + QPixmap arrow(w + 14, h); + QBitmap mask(arrow.width(), arrow.height()); + arrow.fill(Qt::white); + mask.fill(Qt::black); + + bitBlt(&arrow, 0, 0, &pix, 0, 0); + if (pix.mask() != 0) + bitBlt(&mask, 0, 0, pix.mask(), 0, 0); + else { + QBitmap bmp(pix.createHeuristicMask()); + bitBlt(&mask, 0, 0, &bmp, 0, 0); + } + + QPainter p, pm; + p.begin(&arrow); + pm.begin(&mask); + + p.setPen(QColor(0, 0, 0)); + p.drawLine(w + 5, h - 2, w + 5 + 1, h - 2); + p.drawLine(w + 4, h - 3, w + 6 + 1, h - 3); + p.drawLine(w + 3, h - 4, w + 7 + 1, h - 4); + p.drawLine(w + 2, h - 5, w + 8 + 1, h - 5); + p.drawLine(w + 2, h - 6, w + 8 + 1, h - 6); + + pm.setPen(QColor(255, 255, 255)); + pm.drawLine(w + 5, h - 2, w + 5 + 1, h - 2); + pm.drawLine(w + 4, h - 3, w + 6 + 1, h - 3); + pm.drawLine(w + 3, h - 4, w + 7 + 1, h - 4); + pm.drawLine(w + 2, h - 5, w + 8 + 1, h - 5); + pm.drawLine(w + 2, h - 6, w + 8 + 1, h - 6); + + pm.end(); + p.end(); + arrow.setMask(mask); + + QIconSet set(arrow, QIconSet::Small); + header->setLabel(id, set, name); + } +} + +void kvoctrainView::print(KPrinter * pPrinter) +{ + QPainter painter; + int res = pPrinter->resolution(); + int marg = res; + + int pw; + int c = 0; + int currentWidth; + int startCol; + int pageNum = 1; + + int colCount = m_table->numCols(); + int hh = m_table->horizontalHeader()->height(); + int tPos = marg + hh; + + QColorGroup cg; + + painter.begin(pPrinter); + QRect w = painter.window(); + QRect cr; + + pw = w.width() - (2 * marg); + + while (c < colCount) + { + startCol = c; + currentWidth = marg; + + while ((currentWidth < pw) && (c < colCount)) + { + currentWidth = currentWidth + m_table->columnWidth(c); + c++; + } + if (c < colCount) + c--; + + newPage(painter, res, startCol, c); + + for (int rc = 0; rc < m_table->numRows(); ++rc) + { + int rh = m_table->rowHeight(rc); + + painter.resetXForm(); + painter.setFont(Prefs::tableFont()); + painter.translate(marg, tPos); + painter.drawLine(-1 , 0, -1, rh - 1); + + for (int i = startCol; i <= c && i < colCount; ++i) + { + cr.setRect(0, 0, m_table->columnWidth(i), rh); + m_table->paintCell(&painter, rc, i, cr, false, cg); + painter.translate(m_table->columnWidth(i), 0); + } + + tPos = tPos + m_table->rowHeight(rc); + + if (tPos + m_table->rowHeight(rc + 1) > w.height() - marg) + { + endOfPage(painter, pageNum++, res); + tPos = marg + hh; + pPrinter->newPage(); + newPage(painter, res, startCol, c); + } + } + endOfPage(painter, pageNum++, res); + + if (c < colCount) + { + pPrinter->newPage(); + tPos = marg + hh; + c++; + kdDebug() << c <<endl; + } + } + painter.end(); +} + +void kvoctrainView::newPage(QPainter & painter, int res, int startCol, int endCol) +{ + int marg = res; + int hh = m_table->horizontalHeader()->height(); + int cw; + QRect cr; + QRect w = painter.window(); + painter.resetXForm(); + painter.setFont(KGlobalSettings::generalFont()); + painter.drawText(marg, marg - 20, i18n("KVocTrain - %1").arg(m_doc->getTitle())); + painter.translate(marg, marg); + painter.drawLine(-1 , 0, -1, hh - 1); + for (int i = startCol; i <= endCol && i < m_table->numCols(); ++i) + { + cw = m_table->columnWidth(i); + painter.drawLine(0, -1, cw - 1, -1); + painter.drawLine(0, hh - 1, cw - 1, hh - 1); + painter.drawLine(cw - 1, 0, cw - 1, hh - 1); + cr.setRect(3, 0, m_table->columnWidth(i)- 6, hh); + painter.drawText(cr, AlignAuto | AlignVCenter, m_table->horizontalHeader()->label(i)); + painter.translate(cw, 0); + } +} + +void kvoctrainView::endOfPage(QPainter & painter, int pageNum, int res) +{ + painter.resetXForm(); + painter.setFont(KGlobalSettings::generalFont()); + QRect w = painter.window(); + QRect r = painter.boundingRect(0, 0, 0, 0, AlignAuto, QString::number(pageNum)); + painter.drawText((w.width()/2) - (r.width()/2), w.height() - res + 20, QString::number(pageNum)); +} + + +#include "kvoctrainview.moc" diff --git a/kvoctrain/kvoctrain/kvoctrainview.h b/kvoctrain/kvoctrain/kvoctrainview.h new file mode 100644 index 00000000..f332e9a8 --- /dev/null +++ b/kvoctrain/kvoctrain/kvoctrainview.h @@ -0,0 +1,87 @@ +/*************************************************************************** + + view to kvoctrain parts + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KVOCTRAINVIEW_H +#define KVOCTRAINVIEW_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +class QGridLayout; +class QFrame; +class KApplication; +class KPrinter; +class kvoctrainExpr; +class KVocTrainTable; +class kvoctrainApp; +class kvoctrainDoc; +class GradeCols; +class LangSet; + +#include "kvoctraindoc.h" + +/** + * This class provides an incomplete base for your application view. + */ + +class kvoctrainView : public QWidget +{ + Q_OBJECT + + public: + /** Constructor for the main view */ + kvoctrainView(kvoctrainDoc* doc, const LangSet &ls, kvoctrainApp *parent = 0); + + /** Destructor for the main view */ + ~kvoctrainView(); + + /** sets view to another vocabulary */ + void setView(kvoctrainDoc *doc, const LangSet &ls); + + KVocTrainTable* getTable() { return m_table; } + void setHeaderProp(int id, const QString &name, const QString &pixfile=QString::null); + + void adjustContent(); + void print(KPrinter *pPrinter); + +private: + void newPage(QPainter &, int, int, int); + void endOfPage(QPainter &, int, int); + +protected: + KVocTrainTable * m_table; + bool autoResize; + kvoctrainDoc * m_doc; + QGridLayout * list_layout; + kvoctrainApp * parent; + + /** resizes table when frame is resized */ + virtual void resizeEvent(QResizeEvent *); + void showEvent(QShowEvent * s_ev); +}; + +#endif // KVOCTRAINVIEW_H diff --git a/kvoctrain/kvoctrain/kvt-core/LineList.cpp b/kvoctrain/kvoctrain/kvt-core/LineList.cpp new file mode 100644 index 00000000..5b79b3b9 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/LineList.cpp @@ -0,0 +1,95 @@ +/*************************************************************************** + + maintain list of lines from QMultiLineEdit + + ----------------------------------------------------------------------- + + begin : Sun Aug 13 10:00:53 MET 2000 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "LineList.h" + +#include <kdebug.h> + +LineList::LineList (const QString &multilines) +{ + setLines (multilines); +} + + +void LineList::setLines(const QString &the_lines ) +{ + multilines.clear(); + QString lines = the_lines; + int pos; + if ((pos = lines.find ('\n')) >= 0) { + while (pos >= 0) { + multilines.push_back(lines.left(pos)); + lines.remove (0, pos+1); + pos = lines.find ('\n'); + } + } + + if (lines.length() > 0) // empty string at end ==> not an entry! + multilines.push_back(lines); + + normalizeWS(); +} + + +void LineList::normalizeWS() +{ + for (int i = 0; i < (int) multilines.size(); i++) { + multilines[i] = multilines[i].stripWhiteSpace(); +// FIXME: more tolerance with WS? 2*SPC = 1*SPC... + } +} + + +int LineList::count() const +{ + return multilines.size(); +} + + +QString LineList::getLine (int index) const +{ + if (index < (int) multilines.size()) + return multilines[index]; + else { + kdError() << "LineList::getLine: index too big"; + return ""; + } +} + + +QString LineList::allLines() const +{ + QString ret; + if (multilines.size() > 0) + ret = multilines[0]; + + if (multilines.size() > 1) { + for (int i = 1; i < (int) multilines.size(); i++) + ret += "\n" + multilines[i]; + } + return ret; +} + diff --git a/kvoctrain/kvoctrain/kvt-core/LineList.h b/kvoctrain/kvoctrain/kvt-core/LineList.h new file mode 100644 index 00000000..b1d6f01f --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/LineList.h @@ -0,0 +1,49 @@ +/*************************************************************************** + + maintain list of lines from QMultiLineEdit + + ----------------------------------------------------------------------- + + begin : Sun Aug 13 10:00:53 MET 2000 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 LineList_h +#define LineList_h + +#include <qstring.h> + +#include <vector> +using namespace std; + +class LineList { + public: + LineList (const QString &multilines = ""); + + void setLines(const QString &lines); + void normalizeWS(); + int count() const; + QString getLine (int index) const; + QString allLines() const; + + protected: + vector<QString> multilines; +}; + +#endif // LineList_h diff --git a/kvoctrain/kvoctrain/kvt-core/Makefile.am b/kvoctrain/kvoctrain/kvt-core/Makefile.am new file mode 100644 index 00000000..fe356907 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES = -I$(srcdir)/.. -I../queryoption-dialogs \ + -I$(srcdir)/../queryoption-dialogs -I$(top_builddir)/kvoctrain/kvoctrain/common-dialogs $(all_includes) + +lib_LTLIBRARIES = libkvoctraincore.la + +METASOURCES = AUTO + +libkvoctraincore_la_SOURCES = langset.cpp LineList.cpp kvoctrainexpr.cpp \ + kvoctraindoc.cpp kvd_rh_kvtml.cpp kvd_rb_kvtml1.cpp kvd_rb_kvtml2.cpp kvd_wkvtml.cpp \ + kvd_csv.cpp kvd_lex.cpp kvd_vcb.cpp UsageManager.cpp QueryManager.cpp \ + MultipleChoice.cpp grammarmanager.cpp kvd_voc.cpp + +SUBDIRS = kvt-xml + +libkvoctraincore_la_LIBADD= kvt-xml/libkvtxml.la + +noinst_HEADERS = grammarmanager.h diff --git a/kvoctrain/kvoctrain/kvt-core/MultipleChoice.cpp b/kvoctrain/kvoctrain/kvt-core/MultipleChoice.cpp new file mode 100644 index 00000000..e73f358a --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/MultipleChoice.cpp @@ -0,0 +1,119 @@ +/*************************************************************************** + + manage multiple choice suggestions for queries + + ----------------------------------------------------------------------- + + begin : Mon Oct 29 18:09:29 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "MultipleChoice.h" + +MultipleChoice::MultipleChoice ( + const QString &mc1, + const QString &mc2, + const QString &mc3, + const QString &mc4, + const QString &mc5 + ) +{ + setMC1 (mc1); + setMC2 (mc2); + setMC3 (mc3); + setMC4 (mc4); + setMC5 (mc5); +} + + +bool MultipleChoice::isEmpty() const +{ + return muc1.stripWhiteSpace().isEmpty() + && muc2.stripWhiteSpace().isEmpty() + && muc3.stripWhiteSpace().isEmpty() + && muc4.stripWhiteSpace().isEmpty() + && muc5.stripWhiteSpace().isEmpty(); +} + + +void MultipleChoice::clear() +{ + muc1 = ""; + muc2 = ""; + muc3 = ""; + muc4 = ""; + muc5 = ""; +} + + +QString MultipleChoice::mc (unsigned idx) const +{ + switch (idx) { + case 0: return muc1; + case 1: return muc2; + case 2: return muc3; + case 3: return muc4; + case 4: return muc5; + } + return ""; +} + + +unsigned MultipleChoice::size() +{ + normalize(); + unsigned num = 0; + if (!muc1.isEmpty() ) + ++num; + if (!muc2.isEmpty() ) + ++num; + if (!muc3.isEmpty() ) + ++num; + if (!muc4.isEmpty() ) + ++num; + if (!muc5.isEmpty() ) + ++num; + return num; +} + + +void MultipleChoice::normalize() +{ + // fill from first to last + + if (muc1.isEmpty()) { + muc1 = muc2; + muc2 = ""; + } + + if (muc2.isEmpty()) { + muc2 = muc3; + muc3 = ""; + } + + if (muc3.isEmpty()) { + muc3 = muc4; + muc4 = ""; + } + + if (muc4.isEmpty()) { + muc4 = muc5; + muc5 = ""; + } + +} diff --git a/kvoctrain/kvoctrain/kvt-core/MultipleChoice.h b/kvoctrain/kvoctrain/kvt-core/MultipleChoice.h new file mode 100644 index 00000000..99bc56ea --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/MultipleChoice.h @@ -0,0 +1,74 @@ +/*************************************************************************** + + manage multiple choice suggestions for queries + + ----------------------------------------------------------------------- + + begin : Mon Oct 29 18:09:29 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 MultipleChoice_included +#define MultipleChoice_included + +#include <qstring.h> + +#define MAX_MULTIPLE_CHOICE 5 // select one out of x + +class MultipleChoice +{ + +public: + + MultipleChoice() {} + + MultipleChoice ( + const QString &mc1, + const QString &mc2, + const QString &mc3, + const QString &mc4, + const QString &mc5 + ); + + void setMC1 (const QString &s) { muc1 = s; } + void setMC2 (const QString &s) { muc2 = s; } + void setMC3 (const QString &s) { muc3 = s; } + void setMC4 (const QString &s) { muc4 = s; } + void setMC5 (const QString &s) { muc5 = s; } + + QString mc1 () const { return muc1; } + QString mc2 () const { return muc2; } + QString mc3 () const { return muc3; } + QString mc4 () const { return muc4; } + QString mc5 () const { return muc5; } + + QString mc (unsigned idx) const; + + bool isEmpty() const; + void normalize(); + void clear(); + unsigned size(); + +protected: + + QString muc1, muc2, muc3, muc4, muc5; +}; + + +#endif // MultipleChoice_included diff --git a/kvoctrain/kvoctrain/kvt-core/QueryManager.cpp b/kvoctrain/kvoctrain/kvt-core/QueryManager.cpp new file mode 100644 index 00000000..2c7b76ca --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/QueryManager.cpp @@ -0,0 +1,673 @@ +/*************************************************************************** + + manage queries + + ----------------------------------------------------------------------- + + begin : Sat Jul 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <kconfig.h> + +#include <iostream> +#include <vector> +using namespace std; + +#include "QueryManager.h" +#include "kvoctraincore.h" +#include <prefs.h> + +vector<QString> QueryManager::userTypes; + +struct t_type_rel +{ + const char *short_ref; + const char *long_ref; +}; + +// types are hierarchical ! +// - . divides main from sub type +// - sub types must follow main type + +// user types are strings-references like this: #1 + +static t_type_rel InternalTypeRelations [] = +{ + { QM_ADJ, I18N_NOOP("Adjective") }, + + { QM_ADV, I18N_NOOP("Adverb") }, + + { QM_ART, I18N_NOOP("Article") }, + { QM_ART QM_TYPE_DIV QM_ART_DEF, I18N_NOOP("Article Definite") }, + { QM_ART QM_TYPE_DIV QM_ART_IND, I18N_NOOP("Article Indefinite") }, + + { QM_CON, I18N_NOOP("Conjunction") }, + + { QM_NAME, I18N_NOOP("Name") }, // old type "3" + + { QM_NOUN, I18N_NOOP("Noun") }, // old type "2" + { QM_NOUN QM_TYPE_DIV QM_NOUN_M, I18N_NOOP("Noun Male") }, + { QM_NOUN QM_TYPE_DIV QM_NOUN_F, I18N_NOOP("Noun Female") }, + { QM_NOUN QM_TYPE_DIV QM_NOUN_S, I18N_NOOP("Noun Neutral") }, + + { QM_NUM, I18N_NOOP("Numeral") }, + { QM_NUM QM_TYPE_DIV QM_NUM_ORD, I18N_NOOP("Numeral Ordinal") }, + { QM_NUM QM_TYPE_DIV QM_NUM_CARD, I18N_NOOP("Numeral Cardinal") }, + + { QM_PHRASE, I18N_NOOP("Phrase") }, + + { QM_PREP, I18N_NOOP("Preposition") }, + + { QM_PRON, I18N_NOOP("Pronoun") }, + { QM_PRON QM_TYPE_DIV QM_PRON_POS, I18N_NOOP("Pronoun Possessive") }, + { QM_PRON QM_TYPE_DIV QM_PRON_PER, I18N_NOOP("Pronoun Personal") }, + + { QM_QUEST, I18N_NOOP("Question") }, + + { QM_VERB, I18N_NOOP("Verb") }, // old type "1" + { QM_VERB QM_TYPE_DIV QM_VERB_IRR, I18N_NOOP("Verb Irregular") }, + { QM_VERB QM_TYPE_DIV QM_VERB_REG, I18N_NOOP("Verb Regular") }, + + { 0, 0 } // the end +}; + + +QString QueryManager::getSubType (const QString & type) +{ + int i; + QString t = type; + if ((i = t.find(QM_TYPE_DIV)) >= 0) { + t.remove(0, i+1); + return t; + } + else + return QString::null; +} + + +QString QueryManager::getMainType (const QString & type) +{ + int i; + if ((i = type.find(QM_TYPE_DIV)) >= 0) + return type.left(i); + else + return type; +} + + +QueryManager::QueryManager() +{ + lessonitems.clear(); +} + + +QuerySelection QueryManager::select(kvoctrainDoc *doc, int act_lesson, int oindex, int tindex) +{ + QuerySelection random; + random.resize(doc->numLessons()+1); + for (int i = 0; i < doc->numEntries(); i++) + doc->getEntry(i)->setInQuery(false); + + // selecting might take rather long + int ent_no = 0; + int ent_percent = doc->numEntries() / 100; + float f_ent_percent = doc->numEntries() / 100.0; + emit doc->progressChanged(doc, 0); + + //Note that Leitner style learning (altlearn) normally only uses 20 + //entries, we just ignore that here + for (int i = 0; i < doc->numEntries(); i++) { + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit doc->progressChanged(doc, int (ent_no / f_ent_percent)); + + kvoctrainExpr *expr = doc->getEntry(i); + unsigned int lessonno; + if (Prefs::altLearn()) + lessonno = 0; //We only use a single array in Leitner style + else + lessonno = expr->getLesson(); + + if (expr->isActive() ){ + if (Prefs::swapDirection()) { + if ( validate (expr, act_lesson, oindex, tindex) + || validate (expr, act_lesson, tindex, oindex)) { + random[lessonno].push_back (QueryEntryRef(expr, i)); + expr->setInQuery(true); + } + } + else { + if (validate (expr, act_lesson, oindex, tindex)) { + random[lessonno].push_back (QueryEntryRef(expr, i)); + expr->setInQuery(true); + } + } + } + } + + // remove empty lesson elements + for (int i = (int) random.size()-1; i >= 0; i--) + if (random[i].size() == 0) + random.erase(random.begin() + i); + return random; +} + + +bool QueryManager::validate(kvoctrainExpr *expr, int act_lesson, int oindex, int tindex) +{ + int index = tindex ? tindex : oindex; + if ((compareExpiring(expr->getGrade(index, oindex != 0), + expr->getQueryDate(index, oindex != 0), Prefs::expire()) + || + + ( + compareGrade ((CompType) Prefs::compType(Prefs::EnumType::Grade), expr->getGrade(index, oindex != 0), Prefs::gradeItem()) + && compareQuery ((CompType) Prefs::compType(Prefs::EnumType::Query), expr->getQueryCount(index, oindex != 0), Prefs::queryItem()) + && compareBad ((CompType) Prefs::compType(Prefs::EnumType::Bad), expr->getBadCount(index, oindex != 0), Prefs::badItem()) + && compareDate ((CompType) Prefs::compType(Prefs::EnumType::Date), expr->getQueryDate(index, oindex != 0), Prefs::dateItem()) + + && compareBlocking(expr->getGrade(index, oindex != 0), + expr->getQueryDate(index, oindex != 0), Prefs::block()) + ) + ) +// lesson + word type must ALWAYS match +// (and there must be a word on both sides) + && compareLesson ((CompType) Prefs::compType(Prefs::EnumType::Lesson), expr->getLesson(), lessonitems, act_lesson) + && compareType ((CompType) Prefs::compType(Prefs::EnumType::WordType), expr->getType(index), Prefs::typeItem()) + && !expr->getOriginal().stripWhiteSpace().isEmpty() + && !expr->getTranslation(index).stripWhiteSpace().isEmpty() + ) + return true; + else + return false; + +} + + +QuerySelection QueryManager::select(kvoctrainDoc *doc, int act_lesson, int idx, QString type) +{ + QuerySelection random; + random.resize(doc->numLessons()+1); + for (int i = 0; i < doc->numEntries(); i++) + doc->getEntry(i)->setInQuery(false); + + // selecting might take rather long + int ent_no = 0; + int ent_percent = doc->numEntries() / 100; + float f_ent_percent = doc->numEntries() / 100.0; + emit doc->progressChanged(doc, 0); + + for (int i = 0; i < doc->numEntries(); i++) { + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit doc->progressChanged(doc, int (ent_no / f_ent_percent)); + + kvoctrainExpr *expr = doc->getEntry(i); + if (expr->isActive() && validate (expr, act_lesson, idx, type)) { + random[expr->getLesson()].push_back (QueryEntryRef(expr, i)); + expr->setInQuery(true); + } + } + + // remove empty lesson elements + for (int i = (int) random.size()-1; i >= 0; i--) + if (random[i].size() == 0) + random.erase(random.begin() + i); + + return random; +} + + +bool QueryManager::validate(kvoctrainExpr *expr, int act_lesson, int idx, QString query_type) +{ + QString qtype; + int pos = query_type.find (QM_TYPE_DIV); + if (pos >= 0) + qtype = query_type.left (pos); + else + qtype = query_type; + + QString expr_type = expr->getType(idx); + bool type_ok = false; + if (qtype == QM_NOUN) { + type_ok = expr_type == QM_NOUN QM_TYPE_DIV QM_NOUN_S + || expr_type == QM_NOUN QM_TYPE_DIV QM_NOUN_M + || expr_type == QM_NOUN QM_TYPE_DIV QM_NOUN_F; + + } + else if (qtype == QM_VERB) { + type_ok = ( expr_type == QM_VERB + || expr_type == QM_VERB QM_TYPE_DIV QM_VERB_IRR + || expr_type == QM_VERB QM_TYPE_DIV QM_VERB_REG + ) + && expr->getConjugation(idx).numEntries() > 0; + + } + else if (qtype == QM_ADJ) { + type_ok = expr_type == QM_ADJ + && !expr->getComparison(idx).isEmpty(); + } + else + return false; + + if (compareLesson ((CompType) Prefs::compType(Prefs::EnumType::Lesson), expr->getLesson(), + lessonitems, act_lesson) + && type_ok) { + return true; + } + else { + return false; + } +} + + +QuerySelection QueryManager::select(kvoctrainDoc *doc, int act_lesson, int idx, QueryType type) +{ + QuerySelection random; + random.resize(doc->numLessons()+1); + for (int i = 0; i < doc->numEntries(); i++) + doc->getEntry(i)->setInQuery(false); + + // selecting might take rather long + int ent_no = 0; + int ent_percent = doc->numEntries() / 100; + float f_ent_percent = doc->numEntries() / 100.0; + emit doc->progressChanged(doc, 0); + + for (int i = 0; i < doc->numEntries(); i++) { + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit doc->progressChanged(doc, int (ent_no / f_ent_percent)); + + kvoctrainExpr *expr = doc->getEntry(i); + if (expr->isActive() && validate (expr, act_lesson, idx, type)) { + random[expr->getLesson()].push_back (QueryEntryRef(expr, i)); + expr->setInQuery(true); + } + } + + // remove empty lesson elements + for (int i = (int) random.size()-1; i >= 0; i--) + if (random[i].size() == 0) + random.erase(random.begin() + i); + + return random; +} + + +bool QueryManager::validate(kvoctrainExpr *expr, int act_lesson, int idx, QueryType query_type) +{ + bool type_ok = false; + if (query_type == QT_Synonym) { + type_ok = !expr->getSynonym(idx).stripWhiteSpace().isEmpty(); + } + else if (query_type == QT_Antonym) { + type_ok = !expr->getAntonym(idx).stripWhiteSpace().isEmpty(); + } + else if (query_type == QT_Paraphrase) { + type_ok = !expr->getParaphrase(idx).stripWhiteSpace().isEmpty(); + } + else if (query_type == QT_Example) { + type_ok = !expr->getExample(idx).stripWhiteSpace().isEmpty(); + } + + if (compareLesson ((CompType) Prefs::compType(Prefs::EnumType::Lesson), expr->getLesson(), + lessonitems, act_lesson) + && type_ok) + return true; + + return false; +} + + +QString QueryManager::compStr(Prefs::EnumCompType::type type) +{ + QString str = "???"; + switch (type) + { + case DontCare: str = i18n("Do not Care"); break; + case WorseThan: str = i18n("Worse Than"); break; + case WorseEqThan: str = i18n("Equal/Worse Than"); break; + case MoreThan: str = i18n(">"); break; + case MoreEqThan: str = i18n(">="); break; + case BetterEqThan: str = i18n("Equal/Better Than"); break; + case BetterThan: str = i18n("Better Than"); break; + case LessEqThan: str = i18n("<="); break; + case LessThan: str = i18n("<"); break; + + case EqualTo : str = i18n("Equal To"); break; + case NotEqual: str = i18n("Not Equal"); break; + + case OneOf : str = i18n("Contained In"); break; + case NotOneOf: str = i18n("Not Contained In"); break; + + case Within : str = i18n("Within Last"); break; + case Before : str = i18n("Before"); break; + case NotQueried: str = i18n("Not Queried"); break; + + case Current : return i18n("Current Lesson"); break; + case NotAssigned: return i18n("Not Assigned"); break; + default: + ; + } + return str; +} + + +QString QueryManager::gradeStr (int i) +{ + switch (i) { + case KV_NORM_GRADE: return i18n(KV_NORM_TEXT); break; + case KV_LEV1_GRADE: return i18n(KV_LEV1_TEXT); break; + case KV_LEV2_GRADE: return i18n(KV_LEV2_TEXT); break; + case KV_LEV3_GRADE: return i18n(KV_LEV3_TEXT); break; + case KV_LEV4_GRADE: return i18n(KV_LEV4_TEXT); break; + case KV_LEV5_GRADE: return i18n(KV_LEV5_TEXT); break; + case KV_LEV6_GRADE: return i18n(KV_LEV6_TEXT); break; + case KV_LEV7_GRADE: return i18n(KV_LEV7_TEXT); break; + default: return i18n(KV_LEV1_TEXT); break; + } +} + + +vector<TypeRelation> QueryManager::getRelation (bool only_maintypes) +{ + vector<TypeRelation> vec; + for (int i = 0; i < (int) userTypes.size(); i++) { + QString s; + s.setNum(i+1); + s.insert(0, QM_USER_TYPE); + vec.push_back(TypeRelation(s, userTypes[i])); + } + + + t_type_rel *type = InternalTypeRelations; + while (type->short_ref != 0) { + if (!only_maintypes || strstr (type->short_ref, QM_TYPE_DIV) == 0) + vec.push_back(TypeRelation(type->short_ref, i18n(type->long_ref))); + type++; + } + + return vec; +} + + +QString QueryManager::typeStr (const QString id) +{ + if (id.left(1) == QM_USER_TYPE) { + QString num = id; + num.remove (0, 1); + int i = num.toInt()-1; + if (i >= 0 && i < (int) userTypes.size() ) + return userTypes[i]; + else + return QString::null; + } + else { + t_type_rel *type = InternalTypeRelations; + while (type->short_ref != 0) { + if (type->short_ref == id) + return i18n(type->long_ref); + type++; + } + } + return QString::null; +} + + +bool QueryManager::compareBlocking (int grade, int date, bool use_it) +{ + time_t cmp = Prefs::blockItem(grade); + if (grade == KV_NORM_GRADE || cmp == 0 || !use_it) // don't care || all off + return true; + else { + time_t now = time(0); + return date+cmp < now; + } +} + + +bool QueryManager::compareExpiring (int grade, int date, bool use_it) +{ + time_t cmp = Prefs::expireItem(grade); + if (grade == KV_NORM_GRADE || cmp == 0 || !use_it) // don't care || all off + return false; + else { + time_t now = time(0); + return date+cmp < now; + } +} + + +bool QueryManager::compareDate (CompType type, time_t qd, time_t limit) +{ + time_t now = time(0); + bool erg = true; + switch (type) { + case DontCare: erg = true; + break; + + case Before: erg = qd == 0 || qd < now-limit; // never queried or older date + break; + + case Within: erg = qd >= now-limit; // newer date + break; + + case NotQueried: erg = qd == 0; + break; + + default: + ; + } + return erg; +} + + +bool QueryManager::compareQuery (CompType type, int qgrade, int limit) +{ + bool erg = true; + switch (type) { + case DontCare: erg = true; + break; + + case MoreThan: erg = qgrade > limit; // sel has higher query count + break; + + case MoreEqThan: erg = qgrade >= limit; + break; + + case EqualTo: erg = qgrade == limit; + break; + + case NotEqual: erg = qgrade != limit; + break; + + case LessEqThan: erg = qgrade <= limit; // sel has less count + break; + + case LessThan: erg = qgrade < limit; + break; + + default: + ; + } + return erg; +} + + +bool QueryManager::compareBad (CompType type, int bcount, int limit) +{ + bool erg = true; + switch (type) { + case DontCare: erg = true; + break; + + case MoreThan: erg = bcount > limit; // sel has higher bad count + break; + + case MoreEqThan: erg = bcount >= limit; + break; + + case EqualTo: erg = bcount == limit; + break; + + case NotEqual: erg = bcount != limit; + break; + + case LessEqThan: erg = bcount <= limit; // sel has less count + break; + + case LessThan: erg = bcount < limit; + break; + + default: + ; + } + return erg; +} + + +bool QueryManager::compareGrade (CompType type, grade_t qgrade, grade_t limit) +{ + bool erg = true; + switch (type) { + case DontCare: erg = true; + break; + + case WorseThan: erg = qgrade < limit; // sel has worse grade + break; + + case WorseEqThan: erg = qgrade <= limit; + break; + + case EqualTo: erg = qgrade == limit; + break; + + case NotEqual: erg = qgrade != limit; + break; + + case BetterEqThan: erg = qgrade >= limit; // sel has better grade + break; + + case BetterThan: erg = qgrade > limit; + break; + + default: + ; + } + return erg; +} + + +bool QueryManager::compareType (CompType type, const QString & exprtype, const QString & limit) +{ + bool erg = true; + switch (type) { + case DontCare: erg = true; + break; + + case EqualTo: erg = getMainType(exprtype) == getMainType(limit); // type is same + break; + + case NotEqual: erg = getMainType(exprtype) != getMainType(limit); // other type + break; + + default: + ; + } + return erg; +} + + +bool QueryManager::compareLesson (CompType type, int less, const vector<int> &limit, int current) +{ + bool erg = true; + switch (type) { + case DontCare: + erg = true; + break; + + case OneOf: + { + erg = false; + for (int i = 0; !erg && i < (int) limit.size(); i++) + if (limit[i] == less) + erg = true; + } + break; + + case NotOneOf: + { + erg = true; + for (int i = 0; erg && i < (int) limit.size(); i++) + if (limit[i] == less) + erg = false; + } + break; + + case Current: + erg = less == current; + break; + + case NotAssigned: + erg = less == 0; + break; + + default: + ; + } + return erg; +} + + +void QueryManager::setTypeNames (vector<QString> names) +{ + userTypes = names; +} + + +void QueryManager::setLessonItemStr (const QString & indices) +{ + int pos; + QString indices_copy = indices; + lessonitems.clear(); + while ((pos = indices_copy.find(' ')) >= 0) { + QString s = indices_copy.left(pos); + indices_copy.remove(0, pos+1); + lessonitems.push_back(s.toInt()); + } + if (indices_copy.length() != 0) { + lessonitems.push_back(indices_copy.toInt()); + } +} + + +QString QueryManager::lessonItemStr() const +{ + QString s, ret; + for (int i = 0; i < (int) lessonitems.size(); i++) { + s.setNum (lessonitems[i]); + if (i != 0) + ret += ' '; + ret += s; + } + return ret; +} + diff --git a/kvoctrain/kvoctrain/kvt-core/QueryManager.h b/kvoctrain/kvoctrain/kvt-core/QueryManager.h new file mode 100644 index 00000000..07567d22 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/QueryManager.h @@ -0,0 +1,223 @@ +/*************************************************************************** + + manage queries + + ----------------------------------------------------------------------- + + begin : Sat Jul 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 QueryManager_included +#define QueryManager_included + +#include <vector> +using namespace std; + +#include "kvoctraindoc.h" +#include "prefs.h" + +class kvoctrainDoc; +class KConfig; +class kvoctrainExpr; +class Prefs; + +// internal types, indented are subtypes + +#define QM_VERB "v" // go +#define QM_VERB_IRR "ir" +#define QM_VERB_REG "re" +#define QM_NOUN "n" // table, coffee +#define QM_NOUN_F "f" +#define QM_NOUN_M "m" +#define QM_NOUN_S "s" +#define QM_NAME "nm" +#define QM_ART "ar" // article +#define QM_ART_DEF "def" // definite a/an +#define QM_ART_IND "ind" // indefinite the +#define QM_ADJ "aj" // adjective expensive, good +#define QM_ADV "av" // adverb today, strongly +#define QM_PRON "pr" // pronoun you, she +#define QM_PRON_POS "pos" // possessive my, your +#define QM_PRON_PER "per" // personal +#define QM_PHRASE "ph" +#define QM_NUM "num" // numeral +#define QM_NUM_ORD "ord" // ordinal first, second +#define QM_NUM_CARD "crd" // cardinal one, two +#define QM_INFORMAL "ifm" +#define QM_FIG "fig" +#define QM_CON "con" // conjuncton and, but +#define QM_PREP "pre" // preposition behind, between +#define QM_QUEST "qu" // question who, what + +// type delimiters + +#define QM_USER_TYPE "#" // designates number of user type +#define QM_TYPE_DIV ":" // divide main from subtype + +//enum kvq_timeout_t { kvq_notimeout, kvq_show, kvq_cont }; + +enum QueryType { QT_Random, QT_Multiple, + QT_Articles, QT_Conjugation, QT_Comparison, + QT_Synonym, QT_Antonym, QT_Example, QT_Paraphrase }; + + +class TypeRelation +{ + public: + + TypeRelation (const QString & _short, const QString & _long) + : shortId (_short), longId(_long) {} + + QString shortStr() const { return shortId; } + QString longStr() const { return longId; } + + protected: + + QString shortId, longId; +}; + + +struct QueryEntryRef { + QueryEntryRef (kvoctrainExpr *_exp, + int _nr) + : exp(_exp), nr(_nr) {} + + + kvoctrainExpr *exp; + int nr; +}; + +typedef vector<vector<QueryEntryRef> > QuerySelection; + +class QueryManager +{ + public: + // dont change the order/remove one of these, + // just APPEND new types + enum CompType { DontCare, + MoreEqThan, MoreThan, + Before, Within, + WorseThan, WorseEqThan, + EqualTo, NotEqual, + LessEqThan, LessThan, + BetterThan, BetterEqThan, + Current, NotAssigned, NotQueried, + Auto_Time, Auto_Count, + OneOf, NotOneOf + }; + + QueryManager (); + + //void loadConfig (KConfig *); + //void saveConfig (KConfig *); + + static vector<TypeRelation> getRelation (bool only_maintypes); + static void setTypeNames (vector<QString> names); + static QString getSubType (const QString & type); + static QString getMainType (const QString & type); + + static QString compStr(Prefs::EnumCompType::type type); + static QString gradeStr(int i); + static QString typeStr(const QString id); + + void setLessonItems(vector<int> indices) { lessonitems = indices; } + void setLessonItemStr(const QString & indices); + //void setDateItem (time_t time) { dateitem = time; } + //void setQueryItem (int query) { queryitem = query; } + //void setBadItem (int bad) { baditem = bad; } + //void setTypeItem (const QString & type) { typeitem = type; } + //void setGradeItem (grade_t grade) { gradeitem = grade; } + //void setBlockItem (int item, int grade); + //void setExpireItem (int item, int grade); + + vector<int> lessonItems() const { return lessonitems; } + QString lessonItemStr() const; + //time_t dateItem () const { return dateitem; } + //int queryItem () const { return queryitem; } + //int badItem () const { return baditem; } + //QString typeItem () const { return typeitem; } + //grade_t gradeItem () const { return gradeitem; } + //int blockItem (int grade) const; + //int expireItem (int grade) const; + + //void setDateComp (CompType time) { datecomp = time; } + //void setLessonComp (CompType less) { lessoncomp = less; } + //void setQueryComp (CompType query) { querycomp = query; } + //void setBadComp (CompType bad) { badcomp = bad; } + //void setTypeComp (CompType type) { typecomp = type; } + //void setGradeComp (CompType grade) { gradecomp = grade; } + + //CompType dateComp () const { return datecomp; } + //CompType lessonComp () const { return lessoncomp; } + //CompType queryComp () const { return querycomp; } + //CompType badComp () const { return badcomp; } + //CompType typeComp () const { return typecomp; } + //CompType gradeComp () const { return gradecomp; } + + bool validate(kvoctrainExpr *expr, int act_lesson, + int oindex, int tindex); + + QuerySelection select(kvoctrainDoc*, int act_lesson, + int oindex, int tindex); + + bool validate(kvoctrainExpr *expr, int act_lesson, + int index, QString type); + + QuerySelection select(kvoctrainDoc*, int act_lesson, + int index, QString type); + + bool validate(kvoctrainExpr *expr, int act_lesson, + int index, QueryType type); + + QuerySelection select(kvoctrainDoc*, int act_lesson, + int index, QueryType type); + + protected: + + bool compareBlocking (int grade, int limit, bool use_it); + bool compareExpiring (int grade, int limit, bool use_it); + bool compareDate (CompType, time_t, time_t); + bool compareQuery (CompType, int, int); + bool compareBad (CompType, int, int); + bool compareGrade (CompType, grade_t, grade_t); + bool compareType (CompType, const QString &, const QString &); + bool compareLesson (CompType type, int less, const vector<int> &limit, int current); + + /* CompType typecomp, + querycomp, + badcomp, + gradecomp, + lessoncomp, + datecomp;*/ + + //time_t dateitem; + //int queryitem, + // baditem; + //QString typeitem; + //grade_t gradeitem; + vector<int> lessonitems; + + //vector<int> blockItems, + // expireItems; + + private: + static vector<QString> userTypes; +}; + +#endif // QueryManager_included diff --git a/kvoctrain/kvoctrain/kvt-core/UsageManager.cpp b/kvoctrain/kvoctrain/kvt-core/UsageManager.cpp new file mode 100644 index 00000000..7f98665a --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/UsageManager.cpp @@ -0,0 +1,155 @@ +/*************************************************************************** + + manage usage labels + + ----------------------------------------------------------------------- + + begin : Fri Mar 31 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "UsageManager.h" + +#include <klocale.h> + + +#include <iostream> +#include <vector> +using namespace std; + +vector<QString> UsageManager::userUsages; + +// user usages are strings like this: #1 + +struct internalRelation_t +{ + const char *ident, + *context, + *shortid, + *longId; +}; + +#ifndef I18N_NOOP2 +#define I18N_NOOP2(context, str) context, str +#endif + +static internalRelation_t InternalUsageRelations [] = +{ + { UL_AM, 0, I18N_NOOP("Am."), I18N_NOOP("Americanism")}, + { UL_ABBR, 0, I18N_NOOP("abbr."), I18N_NOOP("abbreviation")}, + { UL_ANAT, 0, I18N_NOOP("anat."), I18N_NOOP("anatomy")}, + { UL_ASTR, 0, I18N_NOOP("astr."), I18N_NOOP("astronomy")}, + { UL_BIOL, 0, I18N_NOOP("biol."), I18N_NOOP("biology")}, + { UL_BS, 0, I18N_NOOP("b.s."), I18N_NOOP("bad sense")}, + { UL_CONTP, 0, I18N_NOOP("contp."), I18N_NOOP("contemptuously")}, + { UL_ECCL, 0, I18N_NOOP("eccl."), I18N_NOOP("ecclesiastical")}, + { UL_FIG, 0, I18N_NOOP("fig."), I18N_NOOP("figuratively")}, + { UL_GEOL, 0, I18N_NOOP("geol."), I18N_NOOP("geology")}, + { UL_HIST, 0, I18N_NOOP("hist."), I18N_NOOP("historical")}, + { UL_ICHT, 0, I18N_NOOP("icht."), I18N_NOOP("ichthyology")}, + { UL_IFML, 0, I18N_NOOP("ifml."), I18N_NOOP("informal")}, + { UL_IRONIC, 0, I18N_NOOP("iro."), I18N_NOOP("ironic")}, + { UL_IRR, 0, I18N_NOOP("irr."), I18N_NOOP("irregular")}, + { UL_LIT, 0, I18N_NOOP("lit."), I18N_NOOP("literary")}, + { UL_META, 0, I18N_NOOP("metall."), I18N_NOOP("metallurgy")}, + { UL_METEO, 0, I18N_NOOP("meteor."), I18N_NOOP("meteorology")}, + { UL_MIN, 0, I18N_NOOP("min."), I18N_NOOP("mineralogy")}, + { UL_MOT, 0, I18N_NOOP("mot."), I18N_NOOP("motoring")}, + { UL_MOUNT, 0, I18N_NOOP("mount."), I18N_NOOP("mountaineering")}, + { UL_MYT, 0, I18N_NOOP("myth."), I18N_NOOP("mythology")}, + { UL_NPR, 0, I18N_NOOP2("abbreviation: proper name", "npr."), I18N_NOOP("proper name")}, + { UL_OPT, 0, I18N_NOOP("opt."), I18N_NOOP("optics")}, + { UL_ORN, 0, I18N_NOOP("orn."), I18N_NOOP("ornithology")}, + { UL_OS, 0, I18N_NOOP("o.s."), I18N_NOOP("oneself")}, + { UL_P, 0, I18N_NOOP("pers."), I18N_NOOP("person")}, + { UL_PARL, 0, I18N_NOOP("parl."), I18N_NOOP("parliamentary")}, + { UL_PHARM, 0, I18N_NOOP("pharm."), I18N_NOOP("pharmacy")}, + { UL_PHLS, 0, I18N_NOOP("phls."), I18N_NOOP("philosophy")}, + { UL_PHOT, 0, I18N_NOOP("phot."), I18N_NOOP("photography")}, + { UL_PHYS, 0, I18N_NOOP("phys."), I18N_NOOP("physics")}, + { UL_PHYSIOL, 0, I18N_NOOP("physiol."), I18N_NOOP("physiology")}, + { UL_PL, 0, I18N_NOOP("pl."), I18N_NOOP("plural")}, + { UL_POET, 0, I18N_NOOP("poet."), I18N_NOOP("poetry")}, + { UL_POL, 0, I18N_NOOP("pol."), I18N_NOOP("politics")}, + { UL_PROV, 0, I18N_NOOP("prov."), I18N_NOOP("provincialism")}, + { UL_PSYCH, 0, I18N_NOOP("psych."), I18N_NOOP("psychology")}, + { UL_RHET, 0, I18N_NOOP("rhet."), I18N_NOOP("rhetoric")}, + { UL_SURV, 0, I18N_NOOP("surv."), I18N_NOOP("surveying")}, + { UL_TEL, 0, I18N_NOOP("tel."), I18N_NOOP("telegraphy")}, + { UL_TELEPH, 0, I18N_NOOP("teleph."), I18N_NOOP("telephony")}, + { UL_THEA, 0, I18N_NOOP("thea."), I18N_NOOP("theater")}, + { UL_TYP, 0, I18N_NOOP("typ."), I18N_NOOP("typography")}, + { UL_UNIV, 0, I18N_NOOP("univ."), I18N_NOOP("university")}, + { UL_VET, 0, I18N_NOOP("vet."), I18N_NOOP("veterinary medicine")}, + { UL_ZO, 0, I18N_NOOP("zo."), I18N_NOOP("zoology")}, +//{ UL_, 0, I18N_NOOP(""), I18N_NOOP("")}, + { 0, 0, 0, 0 } // the end +}; + + +UsageManager::UsageManager () +{ +} + + +vector<UsageRelation> UsageManager::getRelation () +{ + vector<UsageRelation> vec; + for (int i = 0; i < (int) userUsages.size(); i++) { + QString s; + s.setNum(i+1); + s.insert(0, UL_USER_USAGE); + vec.push_back(UsageRelation(s, userUsages[i], userUsages[i])); + } + + internalRelation_t *usage = InternalUsageRelations; + while (usage->ident != 0) { + QString s; + if (usage->context == 0) + s = i18n(usage->shortid); + else + s = i18n(usage->context, usage->shortid); + vec.push_back(UsageRelation(usage->ident, + s, + i18n(usage->longId))); + usage++; + } + + return vec; +} + + +bool UsageManager::contains (const QString& label, const QString& collection) +{ + QString s = collection; + int pos; + while ((pos = s.find(UL_USAGE_DIV)) >= 0) { + if (s.left(pos) == label) + return true; + s.remove (0, pos+1); + } + + return s == label; +} + + +void UsageManager::setUsageNames (vector<QString> names) +{ + userUsages = names; +} diff --git a/kvoctrain/kvoctrain/kvt-core/UsageManager.h b/kvoctrain/kvoctrain/kvt-core/UsageManager.h new file mode 100644 index 00000000..e49a6c85 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/UsageManager.h @@ -0,0 +1,127 @@ +/*************************************************************************** + + manage usage labels + + ----------------------------------------------------------------------- + + begin : Sun Dec 19 11:26:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 UsageManager_included +#define UsageManager_included + +#include <vector> +using namespace std; + +#include "kvoctraindoc.h" + +class kvoctrainDoc; +class KConfig; +class kvoctrainExpr; + +// internal usage labels, never change ! + +#define UL_AM "Am" +#define UL_ABBR "abbr" +#define UL_ANAT "anat" +#define UL_ASTR "astr" +#define UL_BIOL "biol" +#define UL_BS "bs" +#define UL_CONTP "contp" +#define UL_ECCL "eccl" +#define UL_FIG "fig" +#define UL_GEOL "geol" +#define UL_HIST "hist" +#define UL_ICHT "icht" +#define UL_IFML "ifm" +#define UL_IRONIC "iro" +#define UL_IRR "irr" +#define UL_LIT "lit" +#define UL_META "metal" +#define UL_METEO "meteo" +#define UL_MIN "miner" +#define UL_MOT "mot" +#define UL_MOUNT "mount" +#define UL_MYT "myth" +#define UL_NPR "npr" +#define UL_OPT "opt" +#define UL_ORN "orn" +#define UL_OS "os" +#define UL_P "p" +#define UL_PARL "parl" +#define UL_PHARM "pharm" +#define UL_PHLS "phls" +#define UL_PHOT "phot" +#define UL_PHYS "phys" +#define UL_PHYSIOL "physio" +#define UL_PL "pl" +#define UL_POET "poet" +#define UL_POL "pol" +#define UL_PROV "prov" +#define UL_PSYCH "psych" +#define UL_RHET "rhet" +#define UL_SURV "surv" +#define UL_TEL "telg" +#define UL_TELEPH "telph" +#define UL_THEA "thea" +#define UL_TYP "typo" +#define UL_UNIV "univ" +#define UL_VET "vet" +#define UL_ZO "zoo" + +// usage delimiters +#define UL_USER_USAGE "#" // designates number of user type +#define UL_USAGE_DIV ":" // divide different labels + +struct UsageRelation +{ + public: + + UsageRelation (const QString & id, const QString & shorty, const QString & longy) + :ident(id), shortId(shorty), longId(longy) {} + + QString identStr() const { return ident; } + QString shortStr() const { return shortId; } + QString longStr() const { return longId; } + + protected: + QString ident, + shortId, + longId; +}; + + +class UsageManager +{ + public: + + UsageManager (); + + static bool contains (const QString& label, const QString& collection); + static vector<UsageRelation> getRelation (); + static void setUsageNames (vector<QString> names); + + protected: + + private: + static vector<QString> userUsages; +}; + +#endif // UsageManager_included diff --git a/kvoctrain/kvoctrain/kvt-core/grammarmanager.cpp b/kvoctrain/kvoctrain/kvt-core/grammarmanager.cpp new file mode 100644 index 00000000..2c789890 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/grammarmanager.cpp @@ -0,0 +1,503 @@ +/*************************************************************************** + + manage grammar parts (articles, conjugation) + + ----------------------------------------------------------------------- + + begin : Sat Nov 27 09:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "grammarmanager.h" + +#include <klocale.h> + +Conjugation::conjug_name_t +Conjugation::names [] = +{ + { CONJ_SIMPLE_PRESENT, I18N_NOOP("Simple Present") }, + { CONJ_PRESENT_PROGR, I18N_NOOP("Preset Progressive") }, + { CONJ_PRESENT_PERFECT, I18N_NOOP("Preset Perfect") }, + + { CONJ_SIMPLE_PAST, I18N_NOOP("Simple Past") }, + { CONJ_PAST_PROGR, I18N_NOOP("Past Progressive") }, + { CONJ_PAST_PARTICIPLE, I18N_NOOP("Past Participle") }, + + { CONJ_FUTURE, I18N_NOOP("Future") } +}; + + +vector<QString> Conjugation::userTenses; + + +//================================================================ + +Comparison::Comparison ( + const QString &l1, + const QString &l2, + const QString &l3 + ) +{ + setL1 (l1); + setL2 (l2); + setL3 (l3); +} + + +bool Comparison::isEmpty() const +{ + return ls1.stripWhiteSpace().isEmpty() + && ls2.stripWhiteSpace().isEmpty() + && ls3.stripWhiteSpace().isEmpty(); +} + + +void Comparison::clear() +{ + ls1 = ""; + ls2 = ""; + ls3 = ""; +} + + +//================================================================= + + +Article::Article + (const QString &fem_def, const QString &fem_indef, + const QString &mal_def, const QString &mal_indef, + const QString &nat_def, const QString &nat_indef + ) +{ + setFemale (fem_def, fem_indef); + setMale (mal_def, mal_indef); + setNatural (nat_def, nat_indef); +} + + +void Article::setFemale + (const QString &def, const QString &indef) +{ + fem_def = def; + fem_indef = indef; +} + + +void Article::setMale + (const QString &def, const QString &indef) +{ + mal_def = def; + mal_indef = indef; +} + + +void Article::setNatural + (const QString &def, const QString &indef) +{ + nat_def = def; + nat_indef = indef; +} + + +void Article::female + (QString &def, QString &indef) const +{ + def = fem_def; + indef = fem_indef; +} + + +void Article::male + (QString &def, QString &indef) const +{ + def = mal_def; + indef = mal_indef; +} + + +void Article::natural + (QString &def, QString &indef) const +{ + def = nat_def; + indef = nat_indef; +} + + + +//============================================================== + + +int Conjugation::numEntries() const +{ + return conjugations.size(); +} + + +vector<TenseRelation> Conjugation::getRelation () +{ + vector<TenseRelation> vec; + + for (int i = 0; i < numInternalNames(); i++) { + vec.push_back(TenseRelation(names[i].abbrev, + i18n(names[i].name))); + } + + for (int i = 0; i < (int) userTenses.size(); i++) { + QString s; + s.setNum(i+1); + s.insert(0, UL_USER_TENSE); + vec.push_back(TenseRelation(s, userTenses[i])); + } + + return vec; +} + + +void Conjugation::setTenseNames (vector<QString> names) +{ + userTenses = names; +} + + +QString Conjugation::getName (const QString &abbrev) +{ + if (abbrev.length() >= 2 && abbrev[0] == QString(UL_USER_TENSE)) { + QString s = abbrev; + s.remove(0, 1); + int i = s.toInt() - 1; + + if (i < (int) userTenses.size() ) + return userTenses[i]; + else + return ""; + } + else { + for (int i = 0; i < (int) numInternalNames(); i++) + if (names[i].abbrev == abbrev) { + return i18n(names[i].name); + } + } + + return ""; +} + + +QString Conjugation::getName (int idx) +{ + if (idx < numInternalNames() ) + return i18n(names[idx].name); + + else if (idx < numTenses() ) + return userTenses[idx-numInternalNames()]; + + else + return ""; +} + + +QString Conjugation::getAbbrev (const QString &name) +{ + for (int i = 0; i < (int) userTenses.size(); i++) + if (userTenses[i] == name) { + QString s; + s.setNum(i+1); + s.insert(0, UL_USER_TENSE); + return s; + } + + for (int i = 0; i < (int) numInternalNames(); i++) + if (names[i].name == name) + return names[i].abbrev; + + return ""; +} + + +QString Conjugation::getAbbrev (int idx) +{ + if (idx < numInternalNames() ) + return names[idx].abbrev; + + else if (idx < numTenses() ) { + QString s; + s.setNum(idx-numInternalNames()+1); + s.insert(0, UL_USER_TENSE); + return s; + } + + else + return ""; +} + + +int Conjugation::numInternalNames() +{ + return sizeof(names) / sizeof(names[0]); +} + + +int Conjugation::numTenses() +{ + return numInternalNames()+userTenses.size(); +} + + +QString Conjugation::getType (int idx) +{ + if (idx >= (int) conjugations.size() ) + return ""; + + return conjugations[idx].type; +} + + +void Conjugation::setType (int idx, const QString & type) +{ + if (idx >= (int) conjugations.size() ) + return; + + conjugations[idx].type = type; +} + + +void Conjugation::cleanUp () +{ + for (int i = (int)conjugations.size()-1; i >= 0; i--) { + const conjug_t *ctp = &conjugations[i]; + if ( ctp->pers1_sing.stripWhiteSpace().isEmpty() + && ctp->pers2_sing.stripWhiteSpace().isEmpty() + && ctp->pers3_m_sing.stripWhiteSpace().isEmpty() + && ctp->pers3_f_sing.stripWhiteSpace().isEmpty() + && ctp->pers3_n_sing.stripWhiteSpace().isEmpty() + && ctp->pers1_plur.stripWhiteSpace().isEmpty() + && ctp->pers2_plur.stripWhiteSpace().isEmpty() + && ctp->pers3_m_plur.stripWhiteSpace().isEmpty() + && ctp->pers3_f_plur.stripWhiteSpace().isEmpty() + && ctp->pers3_n_plur.stripWhiteSpace().isEmpty() + ) + conjugations.erase(conjugations.begin() + i); + } +} + + +bool Conjugation::isEmpty (int idx) +{ + if (idx < (int) conjugations.size()) { + const conjug_t *ctp = &conjugations[idx]; + return ctp->pers1_sing.stripWhiteSpace().isEmpty() + && ctp->pers2_sing.stripWhiteSpace().isEmpty() + && ctp->pers3_m_sing.stripWhiteSpace().isEmpty() + && ctp->pers3_f_sing.stripWhiteSpace().isEmpty() + && ctp->pers3_n_sing.stripWhiteSpace().isEmpty() + && ctp->pers1_plur.stripWhiteSpace().isEmpty() + && ctp->pers2_plur.stripWhiteSpace().isEmpty() + && ctp->pers3_m_plur.stripWhiteSpace().isEmpty() + && ctp->pers3_f_plur.stripWhiteSpace().isEmpty() + && ctp->pers3_n_plur.stripWhiteSpace().isEmpty(); + } + return true; +} + + +#define _GET_CON_(elem, type, default) \ + for (int i = 0; i < (int) conjugations.size(); i++) \ + if (conjugations[i].type == type) \ + return conjugations[i].elem; \ + return default; + + +bool Conjugation::pers3SingularCommon(const QString &type) const +{ + _GET_CON_(s3common, type, false); +} + + +bool Conjugation::pers3PluralCommon(const QString &type) const +{ + _GET_CON_(p3common, type, false); +} + + +QString Conjugation::pers1Singular + (const QString &type) const +{ + _GET_CON_(pers1_sing, type, ""); +} + + +QString Conjugation::pers2Singular + (const QString &type) const +{ + _GET_CON_(pers2_sing, type, ""); +} + + +QString Conjugation::pers3FemaleSingular + (const QString &type) const +{ + _GET_CON_(pers3_f_sing, type, ""); +} + + +QString Conjugation::pers3MaleSingular + (const QString &type) const +{ + _GET_CON_(pers3_m_sing, type, ""); +} + + +QString Conjugation::pers3NaturalSingular + (const QString &type) const +{ + _GET_CON_(pers3_n_sing, type, ""); +} + + +QString Conjugation::pers1Plural + (const QString &type) const +{ + _GET_CON_(pers1_plur, type, ""); +} + + +QString Conjugation::pers2Plural + (const QString &type) const +{ + _GET_CON_(pers2_plur, type, ""); +} + + +QString Conjugation::pers3FemalePlural + (const QString &type) const +{ + _GET_CON_(pers3_f_plur, type, ""); +} + + +QString Conjugation::pers3MalePlural + (const QString &type) const +{ + _GET_CON_(pers3_m_plur, type, ""); +} + + +QString Conjugation::pers3NaturalPlural + (const QString &type) const +{ + _GET_CON_(pers3_n_plur, type, ""); +} + + +#undef _GET_CON_ + + +#define _SET_CON_(elem, type, str) \ + for (int i = 0; i < (int) conjugations.size(); i++) \ + if (conjugations[i].type == type) { \ + conjugations[i].elem = str; \ + return; \ + } \ + conjug_t ct; \ + ct.type = type; \ + ct.elem = str; \ + conjugations.push_back(ct); + + +void Conjugation::setPers3PluralCommon(const QString &type, bool f) +{ + _SET_CON_(p3common, type, f); +} + + +void Conjugation::setPers3SingularCommon(const QString &type, bool f) +{ + _SET_CON_(s3common, type, f); +} + + +void Conjugation::setPers1Singular + (const QString &type, const QString &str) +{ + _SET_CON_(pers1_sing, type, str); +} + + +void Conjugation::setPers2Singular + (const QString &type, const QString &str) +{ + _SET_CON_(pers2_sing, type, str); +} + + +void Conjugation::setPers3FemaleSingular + (const QString &type, const QString &str) +{ + _SET_CON_(pers3_f_sing, type, str); +} + + +void Conjugation::setPers3MaleSingular + (const QString &type, const QString &str) +{ + _SET_CON_(pers3_m_sing, type, str); +} + + +void Conjugation::setPers3NaturalSingular + (const QString &type, const QString &str) +{ + _SET_CON_(pers3_n_sing, type, str); +} + + +void Conjugation::setPers1Plural + (const QString &type, const QString &str) +{ + _SET_CON_(pers1_plur, type, str); +} + + +void Conjugation::setPers2Plural + (const QString &type, const QString &str) +{ + _SET_CON_(pers2_plur, type, str); +} + + +void Conjugation::setPers3FemalePlural + (const QString &type, const QString &str) +{ + _SET_CON_(pers3_f_plur, type, str); +} + + +void Conjugation::setPers3MalePlural + (const QString &type, const QString &str) +{ + _SET_CON_(pers3_m_plur, type, str); +} + + +void Conjugation::setPers3NaturalPlural + (const QString &type, const QString &str) +{ + _SET_CON_(pers3_n_plur, type, str); +} + +#undef _SET_CON_ + diff --git a/kvoctrain/kvoctrain/kvt-core/grammarmanager.h b/kvoctrain/kvoctrain/kvt-core/grammarmanager.h new file mode 100644 index 00000000..1b9cfe76 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/grammarmanager.h @@ -0,0 +1,215 @@ +/*************************************************************************** + + manage grammer parts (articles, conjugation) + + ----------------------------------------------------------------------- + + begin : Sat Nov 27 09:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 grammarmanager_included +#define grammarmanager_included + +#include <qstring.h> + +#include <vector> +using namespace std; + +#define CONJ_SIMPLE_PRESENT "PrSi" // I live at home what you frequently do +#define CONJ_PRESENT_PROGR "PrPr" // I am working what you currently are doing +#define CONJ_PRESENT_PERFECT "PrPe" // I have cleaned tell, #that# something has happened + +#define CONJ_SIMPLE_PAST "PaSi" // the train left 2 min ago when did it happen +#define CONJ_PAST_PROGR "PaPr" // it was raining what happen at a given time in the past +#define CONJ_PAST_PARTICIPLE "PaPa" // I cleaned tell, #that# it happened + +#define CONJ_FUTURE "FuSi" + +#define CONJ_PREFIX "--" // definition of prefixes (I, you, ..) + +#define UL_USER_TENSE "#" // designates number of user tense + +class Article +{ + +public: + + Article() {} + + Article ( + const QString &fem_def, const QString &fem_indef, + const QString &mal_def, const QString &mal_indef, + const QString &nat_def, const QString &nat_indef + ); + + void setFemale (const QString &def, const QString &indef); + void setMale (const QString &def, const QString &indef); + void setNatural (const QString &def, const QString &indef); + + void female (QString &def, QString &indef) const; + void male (QString &def, QString &indef) const; + void natural (QString &def, QString &indef) const; + +protected: + + QString fem_def, fem_indef, + mal_def, mal_indef, + nat_def, nat_indef; +}; + + +class Comparison +{ + +public: + + Comparison() {} + + Comparison ( + const QString &l1, + const QString &l2, + const QString &l3 + ); + + void setL1 (const QString &s) { ls1 = s; } + void setL2 (const QString &s) { ls2 = s; } + void setL3 (const QString &s) { ls3 = s; } + + QString l1 () const { return ls1; } + QString l2 () const { return ls2; } + QString l3 () const { return ls3; } + + bool isEmpty() const; + void clear(); + +protected: + + QString ls1, ls2, ls3; +}; + + +class TenseRelation +{ + public: + + TenseRelation (const QString & _short, const QString & _long) + : shortId (_short), longId(_long) {} + + inline QString shortStr() const { return shortId; } + inline QString longStr() const { return longId; } + + protected: + + QString shortId, longId; +}; + + +class Conjugation +{ + +public: + + Conjugation () {} + + int numEntries() const; + + static vector<TenseRelation> getRelation (); + static void setTenseNames (vector<QString> names); + + static QString getName (const QString &abbrev); + static QString getName (int index); + static QString getAbbrev (const QString &name); + static QString getAbbrev (int index); + static int numInternalNames(); + static int numTenses(); + + QString getType (int index); + void setType (int index, const QString & type); + void cleanUp(); + bool isEmpty (int idx); + + QString pers1Singular(const QString &type) const; + QString pers2Singular(const QString &type) const; + bool pers3SingularCommon(const QString &type) const; + QString pers3FemaleSingular(const QString &type) const; + QString pers3MaleSingular(const QString &type) const; + QString pers3NaturalSingular(const QString &type) const; + + QString pers1Plural(const QString &type) const; + QString pers2Plural(const QString &type) const; + bool pers3PluralCommon(const QString &type) const; + QString pers3FemalePlural(const QString &type) const; + QString pers3MalePlural(const QString &type) const; + QString pers3NaturalPlural(const QString &type) const; + + void setPers1Singular(const QString &type, const QString &str); + void setPers2Singular(const QString &type, const QString &str); + void setPers3SingularCommon(const QString &type, bool f); + void setPers3FemaleSingular(const QString &type, const QString &str); + void setPers3MaleSingular(const QString &type, const QString &str); + void setPers3NaturalSingular(const QString &type, const QString &str); + + void setPers1Plural(const QString &type, const QString &str); + void setPers2Plural(const QString &type, const QString &str); + void setPers3PluralCommon(const QString &type, bool f); + void setPers3FemalePlural(const QString &type, const QString &str); + void setPers3MalePlural(const QString &type, const QString &str); + void setPers3NaturalPlural(const QString &type, const QString &str); + +private: + + struct conjug_t { + + conjug_t() { + p3common = false; + s3common = false; + } + + QString type; + bool p3common, + s3common; + QString pers1_sing, + pers2_sing, + pers3_m_sing, + pers3_f_sing, + pers3_n_sing, + pers1_plur, + pers2_plur, + pers3_m_plur, + pers3_f_plur, + pers3_n_plur; + }; + + struct conjug_name_t { + const char *abbrev; + const char *name; + }; + +protected: + + vector<conjug_t> conjugations; + + static conjug_name_t names []; + static vector<QString> userTenses; +}; + + +#endif // grammarmanager_included + diff --git a/kvoctrain/kvoctrain/kvt-core/kvd_csv.cpp b/kvoctrain/kvoctrain/kvt-core/kvd_csv.cpp new file mode 100644 index 00000000..851e0ea9 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvd_csv.cpp @@ -0,0 +1,243 @@ +/*************************************************************************** + + maintain a document in text format + + ----------------------------------------------------------------------- + + begin : Sat Sep 06 11:00:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kvoctrain.h" + +#include <qtextcodec.h> + +#include <vector> +using namespace std; + +bool kvoctrainDoc::saveTypeNameCsv (QTextStream &) +{ + return true; +} + + +bool kvoctrainDoc::loadTypeNameCsv (QTextStream &) +{ + return true; +} + + +bool kvoctrainDoc::saveLessonCsv (QTextStream &) +{ + return true; +} + + +bool kvoctrainDoc::loadLessonCsv (QTextStream &) +{ + return true; +} + +bool kvoctrainDoc::saveToCsv (QTextStream& os, QString &) +{ + QString separator = Prefs::separator(); + + saveTypeNameCsv (os); + saveLessonCsv (os); + + int ent_no = 0; + int ent_percent = (int) vocabulary.size () / 100; + float f_ent_percent = (int) vocabulary.size () / 100.0; + emit progressChanged(this, 0); + + os << i18n("! Title:") << separator << getTitle() << "\n"; + os << i18n("! Author:") << separator << getAuthor() << "\n"; + + vector <int> csv_order = kvoctrainApp::getCsvOrder(this); + + vector<kvoctrainExpr>::const_iterator first = vocabulary.begin (); + QString exp; + + os.setCodec(QTextCodec::codecForName("UTF-8")); + while (first != vocabulary.end ()) { + + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, ent_no / (int) f_ent_percent); + + exp = ""; + // now concat columns according to paste-order + bool sep = false; + for (int i = 0; i < (int) csv_order.size(); i++) { + if (!sep) + sep = true; + else + exp += separator; + + if (csv_order[i] >= 0) { + if (csv_order[i] == 0) + exp += (*first).getOriginal(); + else + exp += (*first).getTranslation(csv_order[i]); + } + } + + if (!exp.isEmpty()) + os << exp << "\n"; + + first++; + } + + setModified (false); + return os.device()->status() == IO_Ok; +} + + +bool kvoctrainDoc::loadFromCsv (QTextStream& is) +{ + QString separator = Prefs::separator(); + QStringList lang_order = Prefs::pasteOrder(); + + langs.clear(); + vocabulary.clear(); + loadTypeNameCsv (is); + loadLessonCsv (is); + + // autodetect utf8 + // FIXME: provide choice for Latinx? + is.setCodec(QTextCodec::codecForName("ISO 8859-1")); + is.setEncoding(QTextStream::Latin1); + + int size = is.device()->size (); + int ln = size / 20 / 100; // assume each line about 20 chars + float f_ent_percent = size / 100.0; + emit progressChanged (this, 0); + + bool utf8_mode = false; + int lang_num = 0; + for (int l = 0; !is.eof(); l++) { + QString s = is.readLine(); + + // autodetect utf8 + if (!utf8_mode) { + for (int i = 0; !utf8_mode && i < (int) s.length(); ++i) { + ushort trigger = s[i].unicode(); + if (trigger >= 0x80) { + int remain = s.length() - i; + if ((trigger & 0xE0) == 0xC0){ // 110x xxxx + if ( (remain > 1) + && (s[i+1].unicode() & 0xC0) == 0x80) + utf8_mode = true; + } + else if ((trigger & 0xF0) == 0xE0) { // 1110 xxxx + if ( remain > 2 + && s[i+1].unicode() & 0xC0 == 0x80 + && s[i+2].unicode() & 0xC0 == 0x80) + utf8_mode = true; + } + else if ((trigger & 0xF8) == 0xF0) { // 1111 0xxx + if ( remain > 3 + && s[i+1].unicode() & 0xC0 == 0x80 + && s[i+2].unicode() & 0xC0 == 0x80 + && s[i+3].unicode() & 0xC0 == 0x80) + utf8_mode = true; + } + else if ((trigger & 0xFC) == 0xF8) { // 1111 10xx + if ( remain > 4 + && s[i+1].unicode() & 0xC0 == 0x80 + && s[i+2].unicode() & 0xC0 == 0x80 + && s[i+3].unicode() & 0xC0 == 0x80 + && s[i+4].unicode() & 0xC0 == 0x80) + utf8_mode = true; + } + else if ((trigger & 0xFE) == 0xFC) { // 1111 110x + if ( remain > 5 + && s[i+1].unicode() & 0xC0 == 0x80 + && s[i+2].unicode() & 0xC0 == 0x80 + && s[i+3].unicode() & 0xC0 == 0x80 + && s[i+4].unicode() & 0xC0 == 0x80 + && s[i+5].unicode() & 0xC0 == 0x80) + utf8_mode = true; + } + } + } + + if (utf8_mode) { + is.setCodec(QTextCodec::codecForName("UTF-8")); + is.setEncoding(QTextStream::UnicodeUTF8); + s = QString::fromUtf8(s.ascii()); + } + + } + + ln--; + if (ln <= 0) { + ln = size / 20 / 100; // assume each line about 20 chars + emit progressChanged(this, is.device()->at() / (int) f_ent_percent); + } + + // similar in kva_clip.cpp::slotEditPaste() + + if (!s.stripWhiteSpace().isEmpty()) { + kvoctrainExpr bucket (s, separator); + kvoctrainExpr expr; + // now move columns according to paste-order + for (int i = 0; i < bucket.numTranslations()+1; i++) { + lang_num = QMAX (lang_num, bucket.numTranslations()+1); + if (i == 0) + expr.setOriginal(bucket.getOriginal()); + else { + QString ts = bucket.getTranslation(i); + expr.setTranslation(i, ts); + } + } + appendEntry (&expr); + } + } + + for (int j = 0; j < lang_num; j++) { + if (j < (int) lang_order.count() ) { + langs.push_back((lang_order)[j]); + } + else { + if (j == 0) + langs.push_back("org"); + else { + QString s; + s.setNum(j); + s.insert(0, "trans"); + langs.push_back(s); + } + } + } + setModified (false); + return is.device()->status() == IO_Ok; +} + + +void kvoctrainDoc::errorCsv (int /*line*/, const QString &text ) +{ + unknown_elem = true; + QApplication::setOverrideCursor( arrowCursor, true ); + QString s = kapp->makeStdCaption(i18n("Error in csv file")); + QString msg = text; + KMessageBox::error( 0, msg, s); + QApplication::restoreOverrideCursor(); +} diff --git a/kvoctrain/kvoctrain/kvt-core/kvd_lex.cpp b/kvoctrain/kvoctrain/kvt-core/kvd_lex.cpp new file mode 100644 index 00000000..feb160cf --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvd_lex.cpp @@ -0,0 +1,395 @@ +/*************************************************************************** + + maintain a *.lex document (vocabulary trainer for Win) + + ----------------------------------------------------------------------- + + begin : Sat Sep 04 11:00:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <kapplication.h> +#include <klocale.h> +#include <kmessagebox.h> + +#include "kvoctraindoc.h" + + +#include <vector> +using namespace std; + +#define LEX_MAX_ATTR 20 +#define LEX_MAX_LESSON 9 + +/* sample for a lex-file + +Vocabulary Trainer V5.0 +LEX|Deutsch|Englisch| 259 260 1 1 1 0 0 268 0 1 1 1 1 145 6 23 1999 255 1 1 653 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 1 1 0 0 | +-11 700 +System +Energie- und Automatisierungstechnik. V. Manuela Lutz. Danke. +1 1 der die das|he she it| +1 1 eine einer eines einen einem|has have had is be| +1 1 er sie es|his him her its| +1 1 wir ihr euch|in to into on at too| +1 1 in an auf bei|the a an| +1 1 zu um zur zum|out by with of off| +1 1 ist sind seid|something someone some| +1 1 dies dieser dieses|under below| +1 1 || +1 1 || +der die das ein eine einer eines einen einem|the a an| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +Sachgebiete| +| +| +| +| +| +| +| +| +32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 +1 0 255 255 255 255 255 255 0 0 1 Abbildung||||mapping|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +1 0 255 255 255 255 255 255 0 0 1 Abblendkappe||||anti-dazzle device|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +... +*/ + + +static QString extract (QString &line) +{ + QString ret; + int lim = line.find ("|"); + if (lim < 0) { + ret = line; + line = ""; + } + else { + ret = line.left(lim); + line.remove (0, lim+1); + } + + return ret; +} + + +bool kvoctrainDoc::saveTypeNameLex (QTextStream &os) +{ + int i; + for (i = 0; i < (int) type_descr.size() && i < LEX_MAX_ATTR; i++) + os << getTypeName(i) << "|\n"; + + while (i++ < LEX_MAX_ATTR) + os << "|\n"; + + return os.device()->status() == IO_Ok; +} + + +bool kvoctrainDoc::loadTypeNameLex (QTextStream &is) +{ + QString s; + QString attr; + + type_descr.clear(); + + for (int i = 0; i < LEX_MAX_ATTR; i++) { + s = is.readLine(); + attr = extract (s); +/* + if (attr.stripWhiteSpace().isEmpty()) { + attr.setNum (i+1); + attr.insert (0, "#"); + } +*/ + type_descr.push_back (attr); + } + + return is.device()->status() == IO_Ok; +} + + +bool kvoctrainDoc::saveLessonLex (QTextStream &os) +{ + int i; + for (i = 0; i < (int) lesson_descr.size() && i < LEX_MAX_LESSON; i++) + os << lesson_descr[i] << "|\n"; + + while (i++ < LEX_MAX_LESSON) + os << "|\n"; + + return os.device()->status() == IO_Ok; +} + + +bool kvoctrainDoc::loadLessonLex (QTextStream &is) +{ + QString s; + QString lesson; + + lesson_descr.clear(); + + for (int i = 0; i < LEX_MAX_LESSON; i++) { + s = is.readLine(); + lesson = extract (s); + if (lesson.stripWhiteSpace().isEmpty()) { + lesson = "#" + QString::number(i+1); + } + lesson_descr.push_back (lesson); + } + + return is.device()->status() == IO_Ok; +} + + +bool kvoctrainDoc::saveToLex (QTextStream& os, QString & /*title*/) +{ + os << LEX_IDENT_50 "\n"; + os << "LEX|" << getOriginalIdent() << "|" << getIdent(1) << "|" + << "259 260 1 1 1 0 0 268 0 1 1 1 1 "; + os << (int) vocabulary.size(); + os << " 9 5 1999 255 1 1 653 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 1 1 0 0 |#3" << "\n"; + os << "-11 700 0 0 0 0 0 0 0 0 0 0" << "\n"; + os << "System\n"; + os << getTitle() << "\n"; + os << "1 1 der die das|he she it|" << "\n"; + os << "1 1 eine einer eines einen einem|has have had is be|" << "\n"; + os << "1 1 er sie es|his him her its|" << "\n"; + os << "1 1 wir ihr euch|in to into on at too|" << "\n"; + os << "1 1 in an auf bei|the a an|" << "\n"; + os << "1 1 zu um zur zum|out by with of off|" << "\n"; + os << "1 1 ist sind seid|something someone some|" << "\n"; + os << "1 1 dies dieser dieses|under below|" << "\n"; + os << "1 1 ||" << "\n"; + os << "1 1 ||" << "\n"; + os << "der die das ein eine einer eines einen einem|the a an|" << "\n"; + + if (!saveTypeNameLex (os)) + return false; + + if (!saveLessonLex (os)) + return false; + + os << "32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32" << "\n"; + + int ent_no = 0; + int ent_percent = (int) vocabulary.size () / 100; + float f_ent_percent = (int) vocabulary.size () / 100.0; + emit progressChanged(this, 0); + + vector<kvoctrainExpr>::const_iterator first = vocabulary.begin (); + while (first != vocabulary.end ()) { + + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, int(ent_no / f_ent_percent)); + + os << "0" // type + << " " << "255 255 255 255 255 255 255" + << " " << QMIN (2, (*first).getGrade(false)) + << " " << QMIN (2, (*first).getGrade(true)) + << " " << (*first).getLesson() + << " " << (*first).getOriginal() + << " " << "||||" // synonyms + << (*first).getTranslation(1) + << "||||" // synonyms + << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||" + << "\n"; + + first++; + } + + setModified (false); + return os.device()->status() == IO_Ok; +} + + +bool kvoctrainDoc::loadFromLex (QTextStream& is) +{ + + langs.clear(); + vocabulary.clear(); + QString version, + info1, + s_dummy, + title, + f_keys, + ident, + orgID, + transID; + + int i_dummy, + type, + f_grade, + t_grade, + lesson; + + int lines = 10000000; + + version = is.readLine(); + info1 = is.readLine(); + ident = extract (info1); + + orgID = extract (info1); + if (orgID.isEmpty()) + orgID = "original"; + + transID = extract (info1); + if (transID.isEmpty()) + transID = "translation"; + + if (ident != "LEX" || version != LEX_IDENT_50) { + errorLex (1, "invalid file format"); + return false; + } + + // first two chars usually give language code: + // english ==> en + // Deutsch ==> de + // italano ==> it + + langs.push_back (orgID.left(2).lower()); + langs.push_back (transID.left(2).lower()); + + QTextStream params (info1, IO_ReadOnly); + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> i_dummy; + params >> lines; + + s_dummy = is.readLine(); // Font + s_dummy = is.readLine(); // Font + title = is.readLine(); + setTitle (title); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + s_dummy = is.readLine(); + + if (!loadTypeNameLex (is)) + return false; + + if (!loadLessonLex (is)) + return false; + + f_keys = is.readLine(); + + int ent_percent = (int) lines / 100; + float f_ent_percent = (int) lines / 100.0; + emit progressChanged(this, 0); + + for (int i = 0; !is.eof() && i < lines; i++) { + if (ent_percent != 0 && (i % ent_percent) == 0 ) { + emit progressChanged(this, int(i / f_ent_percent)); + } + + is >> type; + is >> i_dummy; + is >> i_dummy; + is >> i_dummy; + is >> i_dummy; + is >> i_dummy; + is >> i_dummy; + is >> i_dummy; + is >> t_grade; + is >> f_grade; + is >> lesson; + + QString line = is.readLine(); + QString s; + + QString original = extract (line); + for (int i = 0; i < 3; i++) { + s = extract (line); + if (!s.isEmpty()) + original += ", " +s; + } + + QString translation = extract (line); + for (int i = 0; i < 3; i++) { + s = extract (line); + if (!s.isEmpty()) + translation += ", " +s; + } + +/* ignore rest + >> "||||||||||||||||||||||||||||||||||||||||||||||||||||||||" + >> "\n"; +*/ + kvoctrainExpr kve (original); + kve.setGrade (1, t_grade, false); + kve.setGrade (1, f_grade, true); + kve.setLesson (lesson); + kve.addTranslation (translation); + +// FIXME: convert attribute to word type ? + + vocabulary.push_back(kve); + + } + + setModified (false); + return is.device()->status() == IO_Ok; +} + + +void kvoctrainDoc::errorLex (int /*line*/, const QString &text ) +{ + unknown_elem = true; + QApplication::setOverrideCursor( arrowCursor, true ); + QString s = kapp->makeStdCaption(i18n("Error in lex file")); + QString msg = text; + KMessageBox::error(0, msg, s); + QApplication::restoreOverrideCursor(); +} diff --git a/kvoctrain/kvoctrain/kvt-core/kvd_rb_kvtml1.cpp b/kvoctrain/kvoctrain/kvt-core/kvd_rb_kvtml1.cpp new file mode 100644 index 00000000..4aea5283 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvd_rb_kvtml1.cpp @@ -0,0 +1,888 @@ +/*************************************************************************** + + read big body of a kvtml document + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "QueryManager.h" +#include "UsageManager.h" + +#include <kapplication.h> +#include <klocale.h> +#include <kmessagebox.h> + +bool kvoctrainDoc::extract_T_DESCR_attr (XmlReader &xml, + XmlElement &elem, int &no) +{ + no = 0; + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + while (first != elem.attributes ().end ()) { + if ((*first).name () == KV_LESS_NO) + no = (*first).intValue(); + else { + if (!unknownAttribute(xml.lineNumber(), "descr", (*first).name ())) + return false; + } + first++; + } + return true; +} + + +bool kvoctrainDoc::extract_T_GROUP_attr (XmlReader &xml, + XmlElement &elem) +{ + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + while (first != elem.attributes ().end ()) { +/* + if ((*first).name () == KV_SIZEHINT) + width = (*first).intValue(); + else */ { + if (!unknownAttribute(xml.lineNumber(), "type", (*first).name ())) + return false; + } + first++; + } + return true; +} + + +bool kvoctrainDoc::loadTypeNameKvtMl (XmlElement elem, XmlReader& xml) +{ + bool endOfGroup = false; + QString s; + type_descr.clear(); + + if (!extract_T_GROUP_attr (xml, elem)) + return false; + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_TYPE_GRP) { + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_TYPE_GRP)); + return false; + } + else + endOfGroup = true; + + } + else if (elem.tag () == KV_TYPE_DESC && !elem.isEndTag() ) { + int no; + if (!extract_T_DESCR_attr (xml, elem, no)) + return false; + + if (!xml.readElement (elem)) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() == "#PCDATA") { // element data + s = xml.getText(); + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + else if (elem.tag() != KV_TYPE_DESC || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_TYPE_DESC)); + return false; + } + } + else { + if (elem.tag() != KV_TYPE_DESC || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_TYPE_DESC)); + return false; + } + + s = ""; + } + type_descr.push_back (s); + } + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + return true; +} + + +bool kvoctrainDoc::loadTenseNameKvtMl (XmlElement elem, XmlReader& xml) +{ + bool endOfGroup = false; + QString s; + tense_descr.clear(); + + if (!extract_T_GROUP_attr (xml, elem)) + return false; + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_TENSE_GRP) { + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_TENSE_GRP)); + return false; + } + else + endOfGroup = true; + + } + else if (elem.tag () == KV_TENSE_DESC && !elem.isEndTag() ) { + int no; + if (!extract_T_DESCR_attr (xml, elem, no)) + return false; + + if (!xml.readElement (elem)) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() == "#PCDATA") { // element data + s = xml.getText(); + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + else if (elem.tag() != KV_TENSE_DESC || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_TENSE_DESC)); + return false; + } + } + else { + if (elem.tag() != KV_TENSE_DESC || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_TENSE_DESC)); + return false; + } + + s = ""; + } + tense_descr.push_back (s); + } + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + return true; +} + + +bool kvoctrainDoc::loadUsageNameKvtMl (XmlElement elem, XmlReader& xml) +{ + bool endOfGroup = false; + QString s; + usage_descr.clear(); + + if (!extract_T_GROUP_attr (xml, elem)) + return false; + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_USAGE_GRP) { + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_USAGE_GRP)); + return false; + } + else + endOfGroup = true; + + } + else if (elem.tag () == KV_USAGE_DESC && !elem.isEndTag() ) { + int no; + if (!extract_T_DESCR_attr (xml, elem, no)) + return false; + + if (!xml.readElement (elem)) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() == "#PCDATA") { // element data + s = xml.getText(); + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + else if (elem.tag() != KV_USAGE_DESC || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_USAGE_DESC)); + return false; + } + } + else { + if (elem.tag() != KV_USAGE_DESC || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_USAGE_DESC)); + return false; + } + + s = ""; + } + usage_descr.push_back (s); + } + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + return true; +} + + +bool kvoctrainDoc::extract_O_T_attr ( + XmlReader &xml, + XmlElement &elem, + QString &lang, + grade_t &grade, grade_t &rev_grade, + int &count, int &rev_count, + time_t &date, time_t &rev_date, + QString &remark, + int &bcount, int &rev_bcount, + QString &query_id, + QString &pronunce, + int &width, + QString &type, + QString &faux_ami_f, + QString &faux_ami_t, + QString &synonym, + QString &example, + QString &antonym, + QString &usage, + QString ¶phrase) +{ + grade = KV_NORM_GRADE; + rev_grade = KV_NORM_GRADE; + count = 0; + rev_count = 0; + bcount = 0; + rev_bcount = 0; + date = 0; + rev_date = 0; + remark = ""; + lang = ""; + query_id = ""; + pronunce = ""; + faux_ami_t = ""; + faux_ami_f = ""; + synonym = ""; + example = ""; + usage = ""; + paraphrase = ""; + antonym = ""; + width = -1; +//type = exprtype + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + int pos; + while (first != elem.attributes ().end ()) { + + if ((*first).name () == KV_LANG) + lang = (*first).stringValue(); + + else if ((*first).name () == KV_SIZEHINT) + width = (*first).intValue(); + + else if ((*first).name () == KV_CHARSET) { + } + + else if ((*first).name () == KV_GRADE) { + QString s = (*first).stringValue(); + + if ((pos = s.find(';')) >= 1) { + grade = s.left(pos).toInt(); + rev_grade = s.mid(pos+1, s.length()).toInt(); + } + else + grade = s.toInt(); + } + + else if ((*first).name () == KV_COUNT) { + QString s = (*first).stringValue(); + if ((pos = s.find(';')) >= 1) { + count = s.left(pos).toInt(); + rev_count = s.mid(pos+1, s.length()).toInt(); + } + else + count = s.toInt(); + } + + else if ((*first).name () == KV_BAD) { + QString s = (*first).stringValue(); + if ((pos = s.find(';')) >= 1) { + bcount = s.left(pos).toInt(); + rev_bcount = s.mid(pos+1, s.length()).toInt(); + } else + bcount = s.toInt(); + } + + else if ((*first).name () == KV_DATE) { + QString s = (*first).stringValue(); + if ((pos = s.find(';')) >= 1) { + date = s.left(pos).toInt(); + rev_date = s.mid(pos+1, s.length()).toInt(); + } + else { + date = s.toInt(); + } + } + + else if ((*first).name () == KV_DATE2) { + QString s = (*first).stringValue(); + if ((pos = s.find(';')) >= 1) { + date = decompressDate (s.left(pos)); + rev_date = decompressDate (s.mid(pos+1, s.length())); + } + else { + date = decompressDate (s); + } + } + + else if ((*first).name () == KV_REMARK) { + remark = (*first).stringValue(); + } + + else if ((*first).name () == KV_FAUX_AMI_F) { + faux_ami_f = (*first).stringValue(); + } + + else if ((*first).name () == KV_FAUX_AMI_T) { + faux_ami_t = (*first).stringValue(); + } + + else if ((*first).name () == KV_SYNONYM) { + synonym = (*first).stringValue(); + } + + else if ((*first).name () == KV_EXAMPLE) { + example = (*first).stringValue(); + } + + else if ((*first).name () == KV_USAGE) { + usage = (*first).stringValue(); + + if (usage.length() != 0 && usage.left(1) == UL_USER_USAGE) { + int num = QMIN(usage.mid (1, 40).toInt(), 1000); // paranioa check + if( num > (int) usage_descr.size() ) { // description missing ? + QString s; + for (int i = usage_descr.size(); i < num; i++) { + s.setNum (i+1); + s.insert (0, "#"); // invent descr according to number + usage_descr.push_back (s); + } + } + } + } + + else if ((*first).name () == KV_PARAPHRASE) { + paraphrase = (*first).stringValue(); + } + + else if ((*first).name () == KV_ANTONYM) { + antonym = (*first).stringValue(); + } + + else if ((*first).name () == KV_EXPRTYPE) { + type = (*first).stringValue(); + if (type == "1") + type = QM_VERB; + else if (type == "2") // convert from pre-0.5 versions + type = QM_NOUN; + else if (type == "3") + type = QM_NAME; + + if (type.length() != 0 && type.left(1) == QM_USER_TYPE) { + int num = QMIN(type.mid (1, 40).toInt(), 1000); // paranoia check + if( num > (int) type_descr.size() ) { // description missing ? + QString s; + for (int i = type_descr.size(); i < num; i++) { + s.setNum (i+1); + s.insert (0, "#"); // invent descr according to number + type_descr.push_back (s); + } + } + } + } + + else if ((*first).name () == KV_PRONUNCE) { + pronunce = (*first).stringValue(); + } + + else if ((*first).name () == KV_QUERY) { + query_id = (*first).stringValue(); + } + + else { + if (!unknownAttribute(xml.lineNumber(), "o> or <t", (*first).name ())) + return false; + } + first++; + } + + return true; +} + + +bool kvoctrainDoc::extract_KVT_E_attr ( + XmlReader& xml, + XmlElement &elem, + int &lesson, + bool &sel, + bool &active, + QString &type) +{ + lesson = 0; + sel = false; + active = true; + type = ""; + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + while (first != elem.attributes ().end ()) { + if ((*first).name () == KV_LESS_MEMBER) + lesson = (*first).intValue(); + else if ((*first).name () == KV_SELECTED) + sel = (*first).intValue() != 0; + else if ((*first).name () == KV_INACTIVE) + active = !(*first).intValue() != 0; + else if ((*first).name () == KV_EXPRTYPE) { + type = (*first).stringValue(); + if (type == "1") + type = QM_VERB; + else if (type == "2") // convert from pre-0.5 versions + type = QM_NOUN; + else if (type == "3") + type = QM_NAME; + + if (type.length() != 0 && type.left(1) == QM_USER_TYPE) { + int num = QMIN(type.mid (1, 40).toInt(), 1000); // paranoia check + if( num > (int) type_descr.size() ) { // description missing ? + QString s; + for (int i = type_descr.size(); i < num; i++) { + s.setNum (i+1); + s.insert (0, "#"); // invent descr according to number + type_descr.push_back (s); + } + } + } + } + else { + if (!unknownAttribute(xml.lineNumber(), "e", (*first).name ())) + return false; + } + first++; + } + return true; +} + + +bool kvoctrainDoc::loadComparison (Comparison &comp, XmlElement elem, + XmlReader &xml) +/* + <comparison> + <l1>good</l1> + <l2>better</l2> + <l3>best</l3> + </comparison> +*/ +{ + bool endOfGroup = false; + QString s; + comp.clear(); + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_COMPARISON_GRP) { + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(elem.tag())); + return false; + } + else + endOfGroup = true; + + } + + else if (elem.tag () == KV_COMP_L1 && !elem.isEndTag() ) { + if (!extract_simple_tag (KV_COMP_L1, xml, elem, s)) + return false; + comp.setL1(s); + } + + else if (elem.tag () == KV_COMP_L2 && !elem.isEndTag() ) { + if (!extract_simple_tag (KV_COMP_L2, xml, elem, s)) + return false; + comp.setL2(s); + } + + else if (elem.tag () == KV_COMP_L3 && !elem.isEndTag() ) { + if (!extract_simple_tag (KV_COMP_L3, xml, elem, s)) + return false; + comp.setL3(s); + } + + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>").arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + return true; +} + + +bool kvoctrainDoc::loadMultipleChoice (MultipleChoice &mc, XmlElement elem, + XmlReader &xml) +/* + <multiplechoice> + <mc1>good</mc1> + <mc2>better</mc2> + <mc3>best</mc3> + <mc4>best 2</mc4> + <mc5>best 3</mc5> + </multiplechoice> +*/ + +{ + bool endOfGroup = false; + QString s; + mc.clear(); + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_MULTIPLECHOICE_GRP) { + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(elem.tag())); + return false; + } + else + endOfGroup = true; + + } + + else if (elem.tag () == KV_MC_1 && !elem.isEndTag() ) { + if (!extract_simple_tag (KV_MC_1, xml, elem, s)) + return false; + mc.setMC1(s); + } + + else if (elem.tag () == KV_MC_2 && !elem.isEndTag() ) { + if (!extract_simple_tag (KV_MC_2, xml, elem, s)) + return false; + mc.setMC2(s); + } + + else if (elem.tag () == KV_MC_3 && !elem.isEndTag() ) { + if (!extract_simple_tag (KV_MC_3, xml, elem, s)) + return false; + mc.setMC3(s); + } + + else if (elem.tag () == KV_MC_4 && !elem.isEndTag() ) { + if (!extract_simple_tag (KV_MC_4, xml, elem, s)) + return false; + mc.setMC4(s); + } + + else if (elem.tag () == KV_MC_5 && !elem.isEndTag() ) { + if (!extract_simple_tag (KV_MC_5, xml, elem, s)) + return false; + mc.setMC5(s); + } + + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>").arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + mc.normalize(); + return true; +} + + +bool kvoctrainDoc::parseBody_kvtml (XmlElement elem, XmlReader& xml) +{ + bool endOfBody = false; + bool lessgroup = false; + bool optgroup = false; + bool attrgroup = false; + bool tensegroup = false; + bool usagegroup = false; + bool articlegroup = false; + bool conjuggroup = false; + + int ent_no = 0; + int ent_percent = (int) lines / 100; + float f_ent_percent = (int) lines / 100.0; + if (lines != 0) + emit progressChanged(this, 0); + + do { + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag () == KV_DOCTYPE) { + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(elem.tag())); + return false; + } + else + endOfBody = true; + } + + else if (elem.tag () == KV_LESS_GRP && !elem.isEndTag() ) { + if (lessgroup) { + errorKvtMl (xml.lineNumber(), + i18n("repeated occurrence of tag <%1>").arg(elem.tag())); + return false; + } + lessgroup = true; + if (!loadLessonKvtMl (elem, xml)) + return false; + } + + else if (elem.tag () == KV_ARTICLE_GRP && !elem.isEndTag() ) { + if (articlegroup) { + errorKvtMl (xml.lineNumber(), + i18n("repeated occurrence of tag <%1>").arg(elem.tag())); + return false; + } + articlegroup = true; + if (!loadArticleKvtMl (elem, xml)) + return false; + } + + else if (elem.tag () == KV_CONJUG_GRP && !elem.isEndTag() ) { + if (conjuggroup) { + errorKvtMl (xml.lineNumber(), + i18n("repeated occurrence of tag <%1>").arg(elem.tag())); + return false; + } + conjuggroup = true; + if (!loadConjugKvtMl (conjugations, KV_CON_ENTRY, elem, xml)) + return false; + } + + else if (elem.tag () == KV_OPTION_GRP && !elem.isEndTag() ) { + if (optgroup) { + errorKvtMl (xml.lineNumber(), + i18n("repeated occurrence of tag <%1>").arg(elem.tag())); + return false; + } + optgroup = true; + if (!loadOptionsKvtMl (elem, xml)) + return false; + } + + else if (elem.tag () == KV_TYPE_GRP && !elem.isEndTag() ) { + if (attrgroup) { + errorKvtMl (xml.lineNumber(), + i18n("repeated occurrence of tag <%1>").arg(elem.tag())); + return false; + } + attrgroup = true; + if (!loadTypeNameKvtMl (elem, xml)) + return false; + } + + else if (elem.tag () == KV_TENSE_GRP && !elem.isEndTag() ) { + if (tensegroup) { + errorKvtMl (xml.lineNumber(), + i18n("repeated occurrence of tag <%1>").arg(elem.tag())); + return false; + } + tensegroup = true; + if (!loadTenseNameKvtMl (elem, xml)) + return false; +// Conjugation::setTenseNames(tense_descr); + } + + else if (elem.tag () == KV_USAGE_GRP && !elem.isEndTag() ) { + if (usagegroup) { + errorKvtMl (xml.lineNumber(), + i18n("repeated occurrence of tag <%1>").arg(elem.tag())); + return false; + } + usagegroup = true; + if (!loadUsageNameKvtMl (elem, xml)) + return false; + } + + else if (elem.tag () == KV_EXPR && !elem.isEndTag() ) { + // found expression <e> + + if (lines != 0) { + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, int(ent_no / f_ent_percent)); + } + if (!parseBody_e (elem, xml)) return false; + } + + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag()); + return false; + } + } + + } while (! endOfBody); + + return true; +} + + +bool kvoctrainDoc::unknownAttribute (int line, const QString &name, + const QString &attr ) +{ + if (unknown_attr) // show dialog only once + return true; // proceed + + unknown_attr = true; + + QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(URL().path()).arg(line); + + QString format = i18n( + "Your document contains an unknown attribute <%1> " // keep trailing space + "in tag <%2>.\n" + "Maybe your version of KVocTrain is too old, " + "or the document is damaged.\n" + "If you proceed and save afterwards you are likely to lose data;\n" + "do you want to proceed anyway?\n" + ); + QString msg = format.arg(attr).arg(name); + + QApplication::setOverrideCursor( arrowCursor, true ); + QString s = kapp->makeStdCaption(i18n("Unknown attribute")); + bool result = (KMessageBox::warningContinueCancel(0, ln+msg, s) == KMessageBox::Continue); + QApplication::restoreOverrideCursor(); + return result; +} + + +void kvoctrainDoc::unknownElement (int line, const QString &elem ) +{ + unknown_elem = true; + + QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(URL().path()).arg(line); + + QString format = i18n( + "Your document contains an unknown tag <%1>. " // keep trailing space + "Maybe your version of KVocTrain is too old, " + "or the document is damaged.\n" + "Loading is aborted because KVocTrain cannot " + "read documents with unknown elements.\n" + ); + QString msg = format.arg(elem); + QApplication::setOverrideCursor( arrowCursor, true ); + QString s = kapp->makeStdCaption(i18n("Unknown element")); + KMessageBox::sorry(0, ln+msg, s); + QApplication::restoreOverrideCursor(); +} + + +void kvoctrainDoc::errorKvtMl (int line, const QString &text ) +{ + QApplication::setOverrideCursor( arrowCursor, true ); + QString s = kapp->makeStdCaption(i18n("Error")); + QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(URL().path()).arg(line); + + QString msg = text; + KMessageBox::error(0, ln+msg, s); + QApplication::restoreOverrideCursor(); +} + + +void kvoctrainDoc::warningKvtMl (int line, const QString &text ) +{ + QApplication::setOverrideCursor( arrowCursor, true ); + QString s = kapp->makeStdCaption(i18n("Warning")); + QString ln = i18n("File:\t%1\nLine:\t%2\n").arg(URL().path()).arg(line); + QString msg = text; + KMessageBox::information(0, ln+msg, s); + QApplication::restoreOverrideCursor(); +} diff --git a/kvoctrain/kvoctrain/kvt-core/kvd_rb_kvtml2.cpp b/kvoctrain/kvoctrain/kvt-core/kvd_rb_kvtml2.cpp new file mode 100644 index 00000000..8179bfa6 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvd_rb_kvtml2.cpp @@ -0,0 +1,464 @@ +/*************************************************************************** + + read big body of a kvtml document + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "QueryManager.h" + +#include <klocale.h> + + +bool kvoctrainDoc::parseBody_e (XmlElement elem, XmlReader& xml) +{ + grade_t grade, + r_grade; + int qcount, + r_qcount; + int bcount, + r_bcount; + QString remark; + QString pronunce; + time_t qdate, + r_qdate; + bool inquery; + bool active; + QString lang; + QString textstr; + QString exprtype; + bool org_found = false; + QString q_org, + q_trans; + QString query_id; + kvoctrainExpr expr; + int lesson; + int width; + QString type; + QString faux_ami_f; + QString faux_ami_t; + QString synonym; + QString example; + QString antonym; + QString usage; + QString paraphrase; + vector<Conjugation> conjug; + Comparison comparison; + MultipleChoice mc; + + if (!extract_KVT_E_attr (xml, elem, lesson, inquery, active, exprtype)) + return false; + + if (lesson + && lesson > (int) lesson_descr.size() ) { // description missing ? + QString s; + for (int i = lesson_descr.size(); i < lesson; i++) { + s.setNum (i+1); + s.insert (0, "#"); // invent descr according to number + lesson_descr.push_back (s); + } + } + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() == KV_EXPR && !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(elem.tag())); + return false; + } + + unsigned int count = 0; + org_found = false; + while (elem.tag() != KV_EXPR) { + + // now want "original" and one or more "translations" + + // found original <o> + + if (elem.tag() == KV_ORG && !elem.isEndTag() ) { + if (org_found) { + errorKvtMl (xml.lineNumber(), + i18n("repeated occurrence of tag <%1>").arg(elem.tag())); + return false; + } + org_found = true; + + type = exprtype; + if (!extract_O_T_attr ( + xml, + elem, + lang, + grade, r_grade, + qcount, r_qcount, + qdate, r_qdate, + remark, + bcount, r_bcount, + query_id, + pronunce, + width, + type, + faux_ami_t, + faux_ami_f, + synonym, + example, + antonym, + usage, + paraphrase)) + return false; + + + if (vocabulary.size() == 0) { // only accept in first entry + if (width >= 0) + setSizeHint (count, width); + + if (query_id == KV_O) + q_org = lang; + + if (query_id == KV_T) + q_trans = lang; + } + + if (langs.size() == 0) { // first entry + if (lang.isEmpty()) // no definition in first entry + lang = "original"; + langs.push_back(lang); + + } + else { + if (lang != langs[0] && !lang.isEmpty()) { // different originals ? + errorKvtMl (xml.lineNumber(), + i18n("ambiguous definition of language code")); + return false; + } + } + count = 0; + +//======================================== +// FIXME:: make loop for this + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag () == KV_CONJUG_GRP && !elem.isEndTag() ) { + if (!loadConjugKvtMl (conjug, (QString) KV_CON_TYPE, elem, xml)) + return false; + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + } + + comparison.clear(); + if (elem.tag () == KV_COMPARISON_GRP && !elem.isEndTag() ) { + if (!loadComparison (comparison, elem, xml)) + return false; + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + } + + mc.clear(); + if (elem.tag () == KV_MULTIPLECHOICE_GRP && !elem.isEndTag() ) { + if (!loadMultipleChoice (mc, elem, xml)) + return false; + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + } + + if (elem.tag() == "#PCDATA") { // element data + textstr = xml.getText(); + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() != KV_ORG || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_ORG)); + return false; + } + } + else { + if (elem.tag() != KV_ORG || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_ORG)); + return false; + } + textstr = ""; + } + +//======================================== + + expr = kvoctrainExpr (textstr); + expr.setLesson (lesson); + expr.setInQuery(inquery); + expr.setActive(active); + + if (conjug.size() > 0) { + expr.setConjugation(0, conjug[0]); + conjug.clear(); + } + if (!comparison.isEmpty()) { + expr.setComparison(0, comparison); + comparison.clear(); + } + if (!mc.isEmpty()) { + expr.setMultipleChoice(0, mc); + mc.clear(); + } + if (!remark.isEmpty() ) + expr.setRemark (0, remark); + if (!pronunce.isEmpty() ) + expr.setPronunce (0, pronunce); + if (!type.isEmpty() ) + expr.setType(0, type); + if (!synonym.isEmpty() ) + expr.setSynonym(0, synonym); + if (!example.isEmpty() ) + expr.setExample(0, example); + if (!usage.isEmpty() ) + expr.setUsageLabel(0, usage); + if (!paraphrase.isEmpty() ) + expr.setParaphrase(0, paraphrase); + if (!antonym.isEmpty() ) + expr.setAntonym(0, antonym); + } + + // found translation <t> + + else if (elem.tag() == KV_TRANS && !elem.isEndTag() ) { + if (!org_found) { // must be preceded by "original" + errorKvtMl (xml.lineNumber(), + i18n("starting tag <%1> is missing").arg(KV_ORG)); + return false; + } + + count++; + type = exprtype; + if (!extract_O_T_attr ( + xml, + elem, + lang, + grade, r_grade, + qcount, r_qcount, + qdate, r_qdate, + remark, + bcount, r_bcount, + query_id, + pronunce, + width, + type, + faux_ami_f, + faux_ami_t, + synonym, + example, + antonym, + usage, + paraphrase)) + return false; + + if (vocabulary.size() == 0) { // only accept in first entry + if (width >= 0) + setSizeHint (count, width); + + if (query_id == KV_O) + q_org = lang; + + if (query_id == KV_T) + q_trans = lang; + + } + + if (langs.size() <= count) { // new translation + if (lang.isEmpty()) { // no definition in first entry ? + lang.setNum (langs.size() ); + lang.insert (0, "translation "); + } + langs.push_back(lang); + + } + else { + if (lang != langs[count] && !lang.isEmpty()) { // different language ? + errorKvtMl (xml.lineNumber(), + i18n("ambiguous definition of language code")); + return false; + } + } + +//======================================== +// FIXME:: make loop for this + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag () == KV_CONJUG_GRP && !elem.isEndTag() ) { + if (!loadConjugKvtMl (conjug, (QString) KV_CON_TYPE, elem, xml)) + return false; + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + } + + comparison.clear(); + if (elem.tag () == KV_COMPARISON_GRP && !elem.isEndTag() ) { + if (!loadComparison (comparison, elem, xml)) + return false; + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + } + + mc.clear(); + if (elem.tag () == KV_MULTIPLECHOICE_GRP && !elem.isEndTag() ) { + if (!loadMultipleChoice (mc, elem, xml)) + return false; + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + } + + textstr = ""; + if (elem.tag() == "#PCDATA") { // element data + textstr = xml.getText(); + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() != KV_TRANS || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_TRANS)); + return false; + } + // expr ... + } + else { + if (elem.tag() != KV_TRANS || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_TRANS)); + return false; + } + textstr = ""; + } + +//======================================== + + if (!org_found) { + errorKvtMl (xml.lineNumber(), + i18n("starting tag <%1> is missing").arg(KV_ORG)); + return false; + } +/* + if (qcount == 0) { + grade = KV_NORM_GRADE; + } + + if (r_qcount == 0) { + r_grade = KV_NORM_GRADE; + } +*/ + expr.addTranslation (textstr, grade, r_grade); + expr.setQueryCount (count, qcount, false); + expr.setQueryCount (count, r_qcount, true); + expr.setBadCount (count, bcount, false); + expr.setBadCount (count, r_bcount, true); + expr.setQueryDate (count, qdate, false); + expr.setQueryDate (count, r_qdate, true); + + if (conjug.size() > 0) { + expr.setConjugation(count, conjug[0]); + conjug.clear(); + } + if (!comparison.isEmpty()) { + expr.setComparison(count, comparison); + comparison.clear(); + } + if (!mc.isEmpty()) { + expr.setMultipleChoice(count, mc); + mc.clear(); + } + if (!type.isEmpty() ) + expr.setType (count, type); + if (!remark.isEmpty() ) + expr.setRemark (count, remark); + if (!pronunce.isEmpty() ) + expr.setPronunce (count, pronunce); + if (!faux_ami_f.isEmpty() ) + expr.setFauxAmi (count, faux_ami_f, false); + if (!faux_ami_t.isEmpty() ) + expr.setFauxAmi (count, faux_ami_t, true); + if (!synonym.isEmpty() ) + expr.setSynonym (count, synonym); + if (!example.isEmpty() ) + expr.setExample (count, example); + if (!usage.isEmpty() ) + expr.setUsageLabel (count, usage); + if (!paraphrase.isEmpty() ) + expr.setParaphrase (count, paraphrase); + if (!antonym.isEmpty() ) + expr.setAntonym (count, antonym); + } + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag()); + return false; + } + } + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + } + if (numEntries() == 0) + setQueryLang (q_org, q_trans); + vocabulary.push_back (expr); + + return true; +} + + diff --git a/kvoctrain/kvoctrain/kvt-core/kvd_rh_kvtml.cpp b/kvoctrain/kvoctrain/kvt-core/kvd_rh_kvtml.cpp new file mode 100644 index 00000000..e6588675 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvd_rh_kvtml.cpp @@ -0,0 +1,856 @@ +/*************************************************************************** + + read header parts of a kvtml document + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "QueryManager.h" + +#include <klocale.h> + +#include <qtextcodec.h> + +bool kvoctrainDoc::loadFromKvtMl (QTextStream& is) +{ + // important, first action + // switch to actual encoding afterwards, otherwise blocked + is.setCodec(QTextCodec::codecForName("UTF-8")); + is.setEncoding(QTextStream::UnicodeUTF8); + + langs.clear(); + vocabulary.clear(); + XmlReader xml (is); + + if (! xml.validHeader ()) { + errorKvtMl (xml.lineNumber(), i18n("invalid xml file header") ); + return false; + } + + generator = ""; + cols = 0; + lines = 0; + doctitle = ""; + author = ""; + license = ""; + doc_remark = ""; + XmlElement elem; + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag () != KV_DOCTYPE) { + errorKvtMl (xml.lineNumber(), + i18n("Tag <%1> was expected " + "but tag <%2> was read." ).arg(KV_DOCTYPE).arg(elem.tag())); + return false; + } + + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + doctitle = i18n("Untitled"); + while (first != elem.attributes ().end ()) { + + if ((*first).name () == KV_ENCODING) { + + if ((*first).stringValue().upper() == (QString)"UTF-8" ) { + is.setCodec(QTextCodec::codecForName("UTF-8")); + is.setEncoding(QTextStream::UnicodeUTF8); + } + else if ((*first).stringValue().upper() == (QString)"8BIT" ) { // old compatibility mode + is.setCodec(QTextCodec::codecForName("ISO 8859-1")); + is.setEncoding(QTextStream::Latin1); + } + else { + is.setCodec(QTextCodec::codecForName("ISO 8859-1")); + is.setEncoding(QTextStream::Latin1); + QString format = i18n("Unknown document encoding \"%1\" was encountered.\n\n" + "It will be ignored. Encoding is now \"%2\"."); + QString msg =format.arg((*first).stringValue ().upper()).arg("ISO 8859-1"); + warningKvtMl (xml.lineNumber(), msg); + } + + } + else if ((*first).name () == KV_TITLE) { + doctitle = (*first).stringValue (); + } + else if ((*first).name () == KV_AUTHOR) { + author = (*first).stringValue (); + } + else if ((*first).name () == KV_LICENSE) { + license = (*first).stringValue (); + } + else if ((*first).name () == KV_DOC_REM) { + doc_remark = (*first).stringValue (); + } + else if ((*first).name () == KV_GENERATOR) { + generator = (*first).stringValue (); + int pos = generator.findRev (KVD_VERS_PREFIX); + if (pos >= 0) { + doc_version = generator; + doc_version.remove (0, pos+2); + } + } + else if ((*first).name () == KV_COLS) { + cols = (*first).intValue (); + } + else if ((*first).name () == KV_LINES) { + lines = (*first).intValue (); + } + else { + if (!unknownAttribute(xml.lineNumber(), "kvtml", (*first).name ())) + return false; + } + + first++; + } + + bool result = parseBody_kvtml (elem, xml); // read vocabulary + + setModified (false); + return result; +} + + +bool kvoctrainDoc::extract_L_DESCR_attr (XmlReader &xml, + XmlElement &elem, int &no, + bool &isCurr, bool &inQuery) +{ + no = 0; + isCurr = false; + inQuery = false; + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + while (first != elem.attributes ().end ()) { + if ((*first).name () == KV_LESS_NO) + no = (*first).intValue(); + else if ((*first).name () == KV_LESS_CURR) + isCurr = (*first).intValue() != 0; + else if ((*first).name () == KV_LESS_QUERY) + inQuery = (*first).intValue() != 0; + else { + if (!unknownAttribute(xml.lineNumber(), "descr", (*first).name ())) + return false; + } + first++; + } + return true; +} + + +bool kvoctrainDoc::check_Empty_attr (QString tag_name, + XmlReader &xml, + XmlElement &elem) +{ + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + if (first != elem.attributes ().end ()) { + if (!unknownAttribute(xml.lineNumber(), tag_name, (*first).name ())) + return false; + } + return true; +} + + +bool kvoctrainDoc::extract_simple_tag (QString tag_name, + XmlReader& xml, + XmlElement &elem, + QString &data, + bool check_it) +{ + if (check_it) + if (!check_Empty_attr (tag_name, xml, elem)) + return false; + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() == "#PCDATA") { // element data + data = xml.getText(); + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + else if (elem.tag() != tag_name || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), i18n("expected ending tag <%1>").arg(tag_name)); + return false; + } + } + else { + if (elem.tag() != tag_name || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), i18n("expected ending tag <%1>").arg(tag_name)); + return false; + } + data = ""; + } + + return true; +} + + +bool kvoctrainDoc::extract_CON_E_attr (XmlReader& xml, + XmlElement &elem, + QString &lang) +{ + lang = ""; + + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + while (first != elem.attributes ().end ()) { + + if ((*first).name () == KV_LANG) + lang = (*first).stringValue(); + + else { + if (!unknownAttribute(xml.lineNumber(), "e", (*first).name ())) + return false; + } + first++; + } + return true; +} + + +bool kvoctrainDoc::loadArticleKvtMl (XmlElement elem, XmlReader& xml) + +/* + <article> + <e l="de"> lang determines also lang order in entries !! + <fi>eine</fi> which must NOT differ + <fd>die</fd> + <mi>ein</mi> + <md>der</md> + <ni>ein</ni> + <nd>das</nd> + </e> + </article> +*/ + +{ + bool endOfGroup = false; + bool inEntry = false; + QString s; + articles.clear(); + + if (!check_Empty_attr (KV_ARTICLE_GRP, xml, elem)) + return false; + + QString fem_def, + mal_def, + nat_def, + fem_indef, + mal_indef, + nat_indef; + QString lang; + int count = 0; + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_ARTICLE_GRP) { + if (inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_ARTICLE_GRP)); + return false; + } + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_ARTICLE_GRP)); + return false; + } + else + endOfGroup = true; + } + else if (elem.tag () == KV_ART_ENTRY) { + if (! elem.isEndTag ()) { + if (inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_ART_ENTRY)); + return false; + } + inEntry = true; + + if (!extract_CON_E_attr (xml, elem, lang) ) + return false; + + if ((int)langs.size() <= count) { // first entry + if (lang.isEmpty()) // no definition in first entry + lang = "original"; + langs.push_back(lang); + } + else { + if (lang != langs[count] && !lang.isEmpty()) { // different originals ? + errorKvtMl (xml.lineNumber(), + i18n("ambiguous definition of language code")); + return false; + } + } + fem_def = ""; + mal_def = ""; + nat_def = ""; + fem_indef = ""; + mal_indef = ""; + nat_indef = ""; + } + else { + count++; + inEntry = false; + articles.push_back (Article(fem_def, fem_indef, + mal_def, mal_indef, + nat_def, nat_indef)); + } + } + else if (elem.tag () == KV_ART_FD && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_ART_FD)); + return false; + } + if (!extract_simple_tag (KV_ART_FD, xml, elem, fem_def)) + return false; + } + else if (elem.tag () == KV_ART_FI && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_ART_FI)); + return false; + } + if (!extract_simple_tag (KV_ART_FI, xml, elem, fem_indef)) + return false; + } + else if (elem.tag () == KV_ART_MD && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_ART_MD)); + return false; + } + if (!extract_simple_tag (KV_ART_MD, xml, elem, mal_def)) + return false; + } + else if (elem.tag () == KV_ART_MI && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_ART_MI)); + return false; + } + if (!extract_simple_tag (KV_ART_MI, xml, elem, mal_indef)) + return false; + } + else if (elem.tag () == KV_ART_ND && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_ART_ND)); + return false; + } + if (!extract_simple_tag (KV_ART_ND, xml, elem, nat_def)) + return false; + } + else if (elem.tag () == KV_ART_NI && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_ART_NI)); + return false; + } + if (!extract_simple_tag (KV_ART_NI, xml, elem, nat_indef)) + return false; + } + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + return true; +} + + +bool kvoctrainDoc::extract_T_attr (XmlReader &xml, + XmlElement &elem, + QString &name) +{ + name = ""; + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + while (first != elem.attributes ().end ()) { + + if ((*first).name () == KV_CON_NAME) + name = (*first).stringValue(); + + else { + if (!unknownAttribute(xml.lineNumber(), "e", (*first).name ())) + return false; + } + first++; + } + return true; +} + + +bool kvoctrainDoc::extract_BOOL_attr ( + XmlReader &xml, + XmlElement &elem, + const QString &tag_name, + const QString &attr_name, + bool &flag) +{ + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + while (first != elem.attributes ().end ()) { + if ((*first).name () == attr_name) + flag = (bool) (*first).intValue(); + else { + if (!unknownAttribute(xml.lineNumber(), tag_name, (*first).name ())) + return false; + } + first++; + } + return true; +} + + +bool kvoctrainDoc::loadConjugKvtMl (vector<Conjugation> &curr_conjug, + const QString &entry_tag, + XmlElement elem, XmlReader& xml) + +/* + <conjugation> used in header for definiton of "prefix" + <e l="de"> lang determines also lang order in entries !! + <s1>I</s1> which must NOT differ + <s2>you<2> + <s3f>he</s3f> + <s3m>she</s3m> + <s3n>it</s3n> + <p1>we</p1> + <p2>you</p2> + <p3f>they</p3f> + <p3m>they</p3m> + <p3n>they</p3n> + </e> + </conjugation> + + <conjugation> and in entry for definition of tenses of (irreg.) verbs + <t n="sipa"> + <s1>go</s1> + <s2>go</s2> + <s3f>goes</s3f> + <s3m>goes</s3m> + <s3n>goes</s3n> + <p1>go</p1> + <p2>go</p2> + <p3f>go</p3f> + <p3m>go</p3m> + <p3n>go</p3n> + </t> + </conjugation> +*/ + +{ + bool endOfGroup = false; + bool inEntry = false; + QString s; + + curr_conjug.clear(); + + if (!check_Empty_attr (KV_CONJUG_GRP, xml, elem)) + return false; + + bool p3_common, + s3_common; + QString pers1_sing, + pers2_sing, + pers3_m_sing, + pers3_f_sing, + pers3_n_sing, + pers1_plur, + pers2_plur, + pers3_m_plur, + pers3_f_plur, + pers3_n_plur; + + QString lang; + QString type; + int count = 0; + curr_conjug.push_back (Conjugation()); + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_CONJUG_GRP) { + if (inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CONJUG_GRP)); + return false; + } + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(elem.tag())); + return false; + } + else + endOfGroup = true; + } + else if (elem.tag () == entry_tag) { + if (! elem.isEndTag ()) { + if (inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(entry_tag)); + return false; + } + inEntry = true; + + if (entry_tag == KV_CON_ENTRY) { + type = CONJ_PREFIX; + if (!extract_CON_E_attr (xml, elem, lang) ) + return false; + + if ((int)langs.size() <= count) { // first entry + if (lang.isEmpty()) // no definition in first entry + lang = "original"; + langs.push_back(lang); + } + else { + if (lang != langs[count] && !lang.isEmpty()) { // different originals ? + errorKvtMl (xml.lineNumber(), + i18n("ambiguous definition of language code")); + return false; + } + } + } + else if (entry_tag == KV_CON_TYPE) { + if (!extract_T_attr (xml, elem, type)) + return false; + if (type.length() != 0 && type.left(1) == UL_USER_TENSE) { + int num = QMIN(type.mid (1, 40).toInt(), 1000); // paranoia check + if( num > (int) tense_descr.size() ) { // description missing ? + QString s; + for (int i = tense_descr.size(); i < num; i++) { + s.setNum (i+1); + s.insert (0, "#"); // invent descr according to number + tense_descr.push_back (s); + } + } + } + } + + pers1_sing = ""; + pers2_sing = ""; + pers3_m_sing = ""; + pers3_f_sing = ""; + pers3_n_sing = ""; + pers1_plur = ""; + pers2_plur = ""; + pers3_m_plur = ""; + pers3_f_plur = ""; + pers3_n_plur = ""; + p3_common = false; + s3_common = false; + } + else { + inEntry = false; + if (entry_tag == KV_CON_ENTRY) + while (count+1 > (int) curr_conjug.size() ) + curr_conjug.push_back (Conjugation()); + + curr_conjug[count].setPers3SingularCommon(type, s3_common); + curr_conjug[count].setPers3PluralCommon(type, p3_common); + curr_conjug[count].setPers1Singular(type, pers1_sing); + curr_conjug[count].setPers2Singular(type, pers2_sing); + curr_conjug[count].setPers3FemaleSingular(type, pers3_f_sing); + curr_conjug[count].setPers3MaleSingular(type, pers3_m_sing); + curr_conjug[count].setPers3NaturalSingular(type, pers3_n_sing); + curr_conjug[count].setPers1Plural(type, pers1_plur); + curr_conjug[count].setPers2Plural(type, pers2_plur); + curr_conjug[count].setPers3FemalePlural(type, pers3_f_plur); + curr_conjug[count].setPers3MalePlural(type, pers3_m_plur); + curr_conjug[count].setPers3NaturalPlural(type, pers3_n_plur); + + if (entry_tag == KV_CON_ENTRY) + count++; + } + } + else if (elem.tag () == KV_CON_P1S && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P1S)); + return false; + } + if (!extract_simple_tag (KV_CON_P1S, xml, elem, pers1_sing) ) + return false; + } + else if (elem.tag () == KV_CON_P2S && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P2S)); + return false; + } + if (!extract_simple_tag (KV_CON_P2S, xml, elem, pers2_sing)) + return false; + } + else if (elem.tag () == KV_CON_P3SF && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P3SF)); + return false; + } + + if (!extract_BOOL_attr (xml, elem,KV_CON_P3SF, KV_CONJ_COMMON, + s3_common)) + return false; + + if (!extract_simple_tag (KV_CON_P3SF, xml, elem, pers3_f_sing, false)) + return false; + } + else if (elem.tag () == KV_CON_P3SM && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P3SM)); + return false; + } + if (!extract_simple_tag (KV_CON_P3SM, xml, elem, pers3_m_sing)) + return false; + } + else if (elem.tag () == KV_CON_P3SN && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P3SN)); + return false; + } + if (!extract_simple_tag (KV_CON_P3SN, xml, elem, pers3_n_sing)) + return false; + } + else if (elem.tag () == KV_CON_P1P && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P1P)); + return false; + } + if (!extract_simple_tag (KV_CON_P1P, xml, elem, pers1_plur) ) + return false; + } + else if (elem.tag () == KV_CON_P2P && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P2P)); + return false; + } + if (!extract_simple_tag (KV_CON_P2P, xml, elem, pers2_plur)) + return false; + } + else if (elem.tag () == KV_CON_P3PF && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P3PF)); + return false; + } + + if (!extract_BOOL_attr (xml, elem, KV_CON_P3PF, KV_CONJ_COMMON, + p3_common)) + return false; + + if (!extract_simple_tag (KV_CON_P3PF, xml, elem, pers3_f_plur, false)) + return false; + } + else if (elem.tag () == KV_CON_P3PM && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P3PM)); + return false; + } + if (!extract_simple_tag (KV_CON_P3PM, xml, elem, pers3_m_plur)) + return false; + } + else if (elem.tag () == KV_CON_P3PN && !elem.isEndTag() ) { + if (!inEntry) { + errorKvtMl (xml.lineNumber(), + i18n("disallowed occurrence of tag <%1>").arg(KV_CON_P3PN)); + return false; + } + if (!extract_simple_tag (KV_CON_P3PN, xml, elem, pers3_n_plur)) + return false; + } + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + return true; +} + + +bool kvoctrainDoc::extract_L_GROUP_attr (XmlReader &xml, + XmlElement &elem, + int &width) +{ + width = 0; + list<XmlAttribute>::const_iterator first = elem.attributes ().begin (); + while (first != elem.attributes ().end ()) { + if ((*first).name () == KV_SIZEHINT) + width = (*first).intValue(); + else { + if (!unknownAttribute(xml.lineNumber(), "lesson", (*first).name ())) + return false; + } + first++; + } + return true; +} + + +bool kvoctrainDoc::loadLessonKvtMl (XmlElement elem, XmlReader& xml) +{ + bool endOfGroup = false; + QString s; + bool isCurr; + bool inQuery = false; + lesson_descr.clear(); + int width; + + if (!extract_L_GROUP_attr (xml, elem, width)) + return false; + setSizeHint (-1, width); + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_LESS_GRP) { + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(elem.tag())); + return false; + } + else + endOfGroup = true; + + } + else if (elem.tag () == KV_LESS_DESC && !elem.isEndTag() ) { + int no; + if (!extract_L_DESCR_attr (xml, elem, no, isCurr, inQuery)) + return false; + + lessons_in_query.push_back(inQuery); + + if (isCurr && no != 0) + setCurrentLesson (no); + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() == "#PCDATA") { // element data + s = xml.getText(); + + if (! xml.readElement (elem) ) { + errorKvtMl (xml.lineNumber(), i18n("I/O failure") ); + return false; + } + + if (elem.tag() != KV_LESS_DESC || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_LESS_DESC)); + return false; + } + } + else { + if (elem.tag() != KV_LESS_DESC || !elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(KV_LESS_DESC)); + return false; + } + s = ""; + } + lesson_descr.push_back (s); + } + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + return true; +} + + +bool kvoctrainDoc::loadOptionsKvtMl (XmlElement elem, XmlReader& xml) +{ + bool endOfGroup = false; + QString s; + + do { + if (! xml.readElement (elem)) + break; + + if (elem.tag () == KV_OPTION_GRP) { + if (! elem.isEndTag ()) { + errorKvtMl (xml.lineNumber(), + i18n("expected ending tag <%1>").arg(elem.tag())); + return false; + } + else + endOfGroup = true; + + } + else if (elem.tag () == KV_OPT_SORT) { + sort_allowed = true; + + if (!extract_BOOL_attr (xml, elem, KV_OPTION_GRP, KV_BOOL_FLAG, + sort_allowed)) + return false; + + } + else { + if (elem.isEndTag() ) { + errorKvtMl (xml.lineNumber(), + i18n("unexpected ending tag <%1>" ).arg(elem.tag())); + return false; + } + else { + unknownElement (xml.lineNumber(), elem.tag() ); + return false; + } + } + } while (! endOfGroup); + + return true; +} + diff --git a/kvoctrain/kvoctrain/kvt-core/kvd_vcb.cpp b/kvoctrain/kvoctrain/kvt-core/kvd_vcb.cpp new file mode 100644 index 00000000..2dfde3fe --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvd_vcb.cpp @@ -0,0 +1,199 @@ +/*************************************************************************** + + maintain a document in vocabbox format + + ----------------------------------------------------------------------- + + begin : Thr Mar 23 21:00:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <kapplication.h> +#include <kmessagebox.h> + +#include "kvoctraindoc.h" +#include "kvoctraincore.h" + + + +bool kvoctrainDoc::saveTypeNameVcb (QTextStream &/*os*/) +{ + return true; +} + + +bool kvoctrainDoc::loadTypeNameVcb (QTextStream &/*is*/) +{ + return true; +} + + +bool kvoctrainDoc::saveLessonVcb (QTextStream &/*os*/) +{ + return true; +} + + +bool kvoctrainDoc::loadLessonVcb (QTextStream &/*is*/) +{ + return true; +} + + +bool kvoctrainDoc::saveToVcb (QTextStream& os, QString &/*title*/) +{ + saveTypeNameVcb (os); + saveLessonVcb (os); + + int ent_no = 0; + int ent_percent = (int) vocabulary.size () / 100; + float f_ent_percent = (int) vocabulary.size () / 100.0; + emit progressChanged(this, 0); + + vector<kvoctrainExpr>::const_iterator first = vocabulary.begin (); + while (first != vocabulary.end ()) { + + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, int(ent_no / f_ent_percent)); + + QString s, exp; + + exp = (*first).getOriginal()+VCB_SEPARATOR; + exp += (*first).getTranslation(1)+VCB_SEPARATOR; + + exp += (*first).gradeStr (1, false)+VCB_SEPARATOR; + exp += (*first).gradeStr (1, true)+VCB_SEPARATOR; + s.setNum ((*first).getQueryDate (1, false)); + exp += s+VCB_SEPARATOR; + s.setNum ((*first).getQueryDate (1, true)); + exp += s; + + os << exp << "\n"; + + first++; + } + + setModified (false); + return os.device()->status() == IO_Ok; +} + + +bool kvoctrainDoc::loadFromVcb (QTextStream& is) +{ + + langs.clear(); + vocabulary.clear(); + loadTypeNameVcb (is); + loadLessonVcb (is); + + int size = is.device()->size (); + int ln = size / 40 / 100; // assume each line about 40 chars + float f_ent_percent = size / 100.0; + emit progressChanged (this, 0); + + for (int l = 0; !is.eof(); l++) { + QString s = is.readLine(); + + ln--; + if (ln <= 0) { + ln = size / 40 / 100; // assume each line about 40 chars + emit progressChanged(this, int(is.device()->at() / f_ent_percent)); + } + + if (!s.stripWhiteSpace().isEmpty()) { + QString o, t; + grade_t ograde = KV_LEV1_GRADE, + tgrade = KV_LEV1_GRADE; + size_t odate = time(0), + tdate = time(0); + + int pos = s.find (VCB_SEPARATOR); + if (pos >= 0) { + o = s.left(pos); + s.remove (0, pos+QString(VCB_SEPARATOR).length()); + } + + pos = s.find (VCB_SEPARATOR); + if (pos >= 0) { + t = s.left(pos); + s.remove (0, pos+QString(VCB_SEPARATOR).length()); + } + else { + t = s; + } + + pos = s.find (VCB_SEPARATOR); + if (pos >= 0) { + ograde = s.left(pos).toInt(); + s.remove (0, pos+QString(VCB_SEPARATOR).length()); + } + + pos = s.find (VCB_SEPARATOR); + if (pos >= 0) { + tgrade = s.left(pos).toInt(); + s.remove (0, pos+QString(VCB_SEPARATOR).length()); + } + + pos = s.find (VCB_SEPARATOR); + if (pos >= 0) { + odate = s.left(pos).toInt(); + s.remove (0, pos+QString(VCB_SEPARATOR).length()); + } + + if (s.stripWhiteSpace().length() > 0) { + tdate = s.toInt(); + } + + kvoctrainExpr bucket; + bucket.setOriginal(o); + bucket.addTranslation(t); + + bucket.setGrade(1, ograde, false); + if (ograde != 0) + bucket.setQueryCount(1, 1, false); + + bucket.setGrade(1, tgrade, true); + if (tgrade != 0) + bucket.setQueryCount(1, 1, true); + + bucket.setQueryDate(1, odate, false); + bucket.setQueryDate(1, tdate, true); + + appendEntry (&bucket); + } + } + + langs.push_back("en"); + langs.push_back("en"); + + setModified (false); + return is.device()->status() == IO_Ok; +} + + +void kvoctrainDoc::errorVcb (int /*line*/, const QString &text ) +{ + unknown_elem = true; + QApplication::setOverrideCursor( arrowCursor, true ); + QString s = kapp->makeStdCaption(i18n("Error in vocabbox file")); + QString msg = text; + KMessageBox::error(0, msg, s); + QApplication::restoreOverrideCursor(); +} diff --git a/kvoctrain/kvoctrain/kvt-core/kvd_voc.cpp b/kvoctrain/kvoctrain/kvt-core/kvd_voc.cpp new file mode 100644 index 00000000..e99c2e31 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvd_voc.cpp @@ -0,0 +1,141 @@ +/*************************************************************************** + + maintain a document in Vokabletrainer format + + ----------------------------------------------------------------------- + + begin : Wed Jun 15 19:32:00 PDT 2005 + + copyright : (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <kapplication.h> +#include <kmessagebox.h> +#include <kdebug.h> + +#include "kvoctraindoc.h" +#include "kvoctraincore.h" + + +bool kvoctrainDoc::loadFromVoc(QTextStream& is) +{ + author = "http://www.vokabeln.de"; //DO NOT translate + + langs.clear(); + vocabulary.clear(); + lesson_descr.clear(); + + QString title, + lang1, + lang2, + expression, + original, + translation, + lessonDescr, + temp; + + int i, + wordCount, + lesson; + + int lines = 10000; + + QStringList titles, + languages, + words; + + bool keepGoing = true; + + while (keepGoing) + { + temp = is.readLine(); + keepGoing = !(temp.find("\",") > 0); + title.append(temp); + if (keepGoing) + title.append(" "); + } + + titles = QStringList::split("\",", title); + doctitle = titles[0].mid(1); + wordCount = titles[1].section(',', 0, 0).toInt(); + + is.readLine(); + is.readLine(); + + lang1 = is.readLine(); + languages = QStringList::split("\",", lang1); + + langs.push_back(languages[0].mid(1)); + langs.push_back(languages[1].mid(1)); + + keepGoing = true; + while (keepGoing) + keepGoing = !(is.readLine().find("8. Lernhilfe") > 0); //DO NOT translate + + for (i = 0; i <= 14; i++) + is.readLine(); + + for (i = 0; i < wordCount - 1; i++) + { + int c = 0; + expression.setLength(0); + + while (c < 2) + { + temp = is.readLine(); + c+= temp.contains("\","); + expression.append(temp); + if (c < 2) + expression.append(" "); + } + + words = QStringList::split("\",", expression); + original = words[0].mid(1); + translation = words[1].mid(1); + lesson = words[2].toInt(); + + kvoctrainExpr kve; + kve.setOriginal(original); + kve.setGrade(1, 0, false); + kve.setGrade(1, 0, true); + kve.setLesson(lesson); + kve.addTranslation(translation); + + vocabulary.push_back(kve); + + is.readLine(); + is.readLine(); + } + + is.readLine(); + is.readLine(); + is.readLine(); + + for (int i = 0; !is.eof() && i < lines; i++) + { + lessonDescr = is.readLine(); + lessonDescr = lessonDescr.mid(1, lessonDescr.length() - 2); + if (!lessonDescr.isEmpty()) + lesson_descr.push_back(lessonDescr); + else + break; + is.readLine(); + } + + setModified(false); + doc_url.setFileName(i18n("Untitled")); + return is.device()->status() == IO_Ok; +} diff --git a/kvoctrain/kvoctrain/kvt-core/kvd_wkvtml.cpp b/kvoctrain/kvoctrain/kvt-core/kvd_wkvtml.cpp new file mode 100644 index 00000000..af0ba06d --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvd_wkvtml.cpp @@ -0,0 +1,960 @@ +/*************************************************************************** + + write a kvtml document + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kvoctraincore.h" +#include "QueryManager.h" + +#include <kdebug.h> + +#include <qtextcodec.h> + +bool kvoctrainDoc::saveTypeNameKvtMl (XmlWriter &xml) +{ + if (type_descr.size() == 0) + return true; + + xml.writeText(" "); + xml.startTag (KV_TYPE_GRP, true, false, true); + + for (int lfn = 0; lfn < (int) type_descr.size(); lfn++) { + if (!type_descr[lfn].isNull() ) { + xml.writeText(" "); + xml.startTag (KV_TYPE_DESC, false); + xml.addAttribute (KV_TYPE_NO, lfn+1 ); + xml.closeTag(); + xml.writeText (type_descr[lfn]); + xml.endTag (KV_TYPE_DESC, true); + } + } + + xml.writeText(" "); + xml.endTag (KV_TYPE_GRP, true); + xml.writeText("\n"); + return true; +} + + +bool kvoctrainDoc::saveTenseNameKvtMl (XmlWriter &xml) +{ + if (tense_descr.size() == 0) + return true; + + xml.writeText(" "); + xml.startTag (KV_TENSE_GRP, true, false, true); + + for (int lfn = 0; lfn < (int) tense_descr.size(); lfn++) { + if (!tense_descr[lfn].isNull() ) { + xml.writeText(" "); + xml.startTag (KV_TENSE_DESC, false); + xml.addAttribute (KV_TENSE_NO, lfn+1 ); + xml.closeTag(); + xml.writeText (tense_descr[lfn]); + xml.endTag (KV_TENSE_DESC, true); + } + } + + xml.writeText(" "); + xml.endTag (KV_TENSE_GRP, true); + xml.writeText("\n"); + return true; +} + + +bool kvoctrainDoc::saveUsageNameKvtMl (XmlWriter &xml) +{ + if (usage_descr.size() == 0) + return true; + + xml.writeText(" "); + xml.startTag (KV_USAGE_GRP, true, false, true); + + for (int lfn = 0; lfn < (int) usage_descr.size(); lfn++) { + if (!usage_descr[lfn].isNull() ) { + xml.writeText(" "); + xml.startTag (KV_USAGE_DESC, false); + xml.addAttribute (KV_USAGE_NO, lfn+1 ); + xml.closeTag(); + xml.writeText (usage_descr[lfn]); + xml.endTag (KV_USAGE_DESC, true); + } + } + + xml.writeText(" "); + xml.endTag (KV_USAGE_GRP, true); + xml.writeText("\n"); + return true; +} + + +bool kvoctrainDoc::saveLessonKvtMl (XmlWriter &xml) +{ + if (lesson_descr.size() == 0) + return true; + + xml.writeText(" "); // indent entry a bit + xml.startTag (KV_LESS_GRP, false); + xml.addAttribute (KV_SIZEHINT, getSizeHint (-1)); + xml.closeTag(false, true); + + for (int lfn = 0; lfn < (int) lesson_descr.size(); lfn++) { + if (!lesson_descr[lfn].isNull() ) { + xml.writeText(" "); + xml.startTag (KV_LESS_DESC, false); + xml.addAttribute (KV_LESS_NO, lfn+1 ); + if (getCurrentLesson() == lfn+1) + xml.addAttribute (KV_LESS_CURR, (QString) "1" ); + if (lfn < (int) lessons_in_query.size() && lessons_in_query[lfn]) + xml.addAttribute (KV_LESS_QUERY, (QString) "1" ); + xml.closeTag(); + xml.writeText (lesson_descr[lfn]); + xml.endTag (KV_LESS_DESC, true); + } + } + + xml.writeText(" "); + xml.endTag (KV_LESS_GRP, true); + xml.writeText("\n"); + return true; +} + + +bool kvoctrainDoc::saveConjug (const Conjugation &curr_conjug, QString type, + XmlWriter &xml, QString identstr) +{ + bool linefeed = type == CONJ_PREFIX; + if (linefeed) + identstr+" "; + else + identstr = ""; + + if (!curr_conjug.pers1Singular(type).isEmpty() ) { + xml.writeText(identstr); + xml.startTag (KV_CON_P1S, true, false, false); + xml.writeText (curr_conjug.pers1Singular(type)); + xml.endTag (KV_CON_P1S, linefeed); + } + + if (!curr_conjug.pers2Singular(type).isEmpty() ) { + xml.writeText(identstr); + xml.startTag (KV_CON_P2S, true, false, false); + xml.writeText (curr_conjug.pers2Singular(type)); + xml.endTag (KV_CON_P2S, linefeed); + } + + bool common = curr_conjug.pers3SingularCommon(type); + if (!curr_conjug.pers3FemaleSingular(type).isEmpty() + || common) { + xml.writeText(identstr); + xml.startTag (KV_CON_P3SF, false, false, false); + if (common) + xml.addAttribute (KV_CONJ_COMMON, common); + xml.closeTag(false, false); + xml.writeText (curr_conjug.pers3FemaleSingular(type)); + xml.endTag (KV_CON_P3SF, linefeed); + } + + if (!curr_conjug.pers3MaleSingular(type).isEmpty() ) { + xml.writeText(identstr); + xml.startTag (KV_CON_P3SM, true, false, false); + xml.writeText (curr_conjug.pers3MaleSingular(type)); + xml.endTag (KV_CON_P3SM, linefeed); + } + + if (!curr_conjug.pers3NaturalSingular(type).isEmpty() ) { + xml.writeText(identstr); + xml.startTag (KV_CON_P3SN, true, false, false); + xml.writeText (curr_conjug.pers3NaturalSingular(type)); + xml.endTag (KV_CON_P3SN, linefeed); + } + + if (!curr_conjug.pers1Plural(type).isEmpty() ) { + xml.writeText(identstr); + xml.startTag (KV_CON_P1P, true, false, false); + xml.writeText (curr_conjug.pers1Plural(type)); + xml.endTag (KV_CON_P1P, linefeed); + } + + if (!curr_conjug.pers2Plural(type).isEmpty() ) { + xml.writeText(identstr); + xml.startTag (KV_CON_P2P, true, false, false); + xml.writeText (curr_conjug.pers2Plural(type)); + xml.endTag (KV_CON_P2P, linefeed); + } + + common = curr_conjug.pers3PluralCommon(type); + if (!curr_conjug.pers3FemalePlural(type).isEmpty() + || common) { + xml.writeText(identstr); + xml.startTag (KV_CON_P3PF, false, false, false); + if (common) + xml.addAttribute (KV_CONJ_COMMON, common); + xml.closeTag(false, false); + xml.writeText (curr_conjug.pers3FemalePlural(type)); + xml.endTag (KV_CON_P3PF, linefeed); + } + + if (!curr_conjug.pers3MalePlural(type).isEmpty() ) { + xml.writeText(identstr); + xml.startTag (KV_CON_P3PM, true, false, false); + xml.writeText (curr_conjug.pers3MalePlural(type)); + xml.endTag (KV_CON_P3PM, linefeed); + } + + if (!curr_conjug.pers3NaturalPlural(type).isEmpty() ) { + xml.writeText(identstr); + xml.startTag (KV_CON_P3PN, true, false, false); + xml.writeText (curr_conjug.pers3NaturalPlural(type)); + xml.endTag (KV_CON_P3PN, linefeed); + } + + return true; + +} + +bool kvoctrainDoc::saveConjugHeader(vector<Conjugation> &curr_conjug, + XmlWriter &xml) +{ +/* + <conjugation> used in header for definiton of "prefix" + <e l="de"> lang determines also lang order in entries !! + <s1>I</s1> which must NOT differ + <s2>you<2> + <s3f common="0">he</s3f> + <s3m>she</s3m> + <s3n>it</s3n> + <p1>we</p1> + <p2>you</p2> + <p3f common="1">they</p3f> + <p3m>they</p3m> + <p3n>they</p3n> + </e> + </conjugation> + +*/ + if (curr_conjug.size() == 0) + return true; + + xml.writeText(" "); // indent entry a bit + xml.startTag (KV_CONJUG_GRP, false); + xml.closeTag(false, true); + + QString def, indef, s; + for (int ent = 0; ent < QMIN((int) curr_conjug.size(), numLangs()); ent++) { + xml.writeText(" "); // indent entry a bit + xml.startTag (KV_CON_ENTRY, false); + + if (ent == 0) { + s = getOriginalIdent().stripWhiteSpace(); + if (s.isEmpty() ) + s = "original"; + } + else { + s = getIdent(ent).stripWhiteSpace(); + if (s.isEmpty() ) { + s.setNum (ent); + s.insert (0, "translation "); + } + } + xml.addAttribute (KV_LANG, s); + xml.closeTag(false, true); + + if (!saveConjug (curr_conjug[ent], CONJ_PREFIX, xml, " ") ) + return false; + + xml.writeText(" "); + xml.endTag (KV_CON_ENTRY, true); + } + + xml.writeText(" "); + xml.endTag (KV_CONJUG_GRP, true); + xml.writeText("\n"); + return true; +} + + +bool kvoctrainDoc::saveComparison (const Comparison &comp, + XmlWriter &xml, int ident) + +/* + <comparison> + <l1>good</l1> + <l2>better</l2> + <l3>best</l3> + </comparison> +*/ + +{ + if (comp.isEmpty()) + return true; + + xml.writeText("\n"); + QString identstr; + identstr.fill (' ', ident+1); + + xml.writeText(identstr); + xml.startTag (KV_COMPARISON_GRP, false); + xml.closeTag(false, true); + xml.writeText(identstr+" "); + + if (!comp.l1().isEmpty() ) { + xml.startTag (KV_COMP_L1, true, false, false); + xml.writeText (comp.l1()); + xml.endTag (KV_COMP_L1, false); + } + + if (!comp.l2().isEmpty() ) { + xml.startTag (KV_COMP_L2, true, false, false); + xml.writeText (comp.l2()); + xml.endTag (KV_COMP_L2, false); + } + + if (!comp.l3().isEmpty() ) { + xml.startTag (KV_COMP_L3, true, false, false); + xml.writeText (comp.l3()); + xml.endTag (KV_COMP_L3, false); + } + + xml.writeText("\n"+identstr); + xml.endTag (KV_COMPARISON_GRP, true); + xml.writeText(identstr); // indent next element + return true; +} + + +bool kvoctrainDoc::saveMultipleChoice (const MultipleChoice &mc, + XmlWriter &xml, int ident) + +/* + <multiplechoice> + <mc1>good</mc1> + <mc2>better</mc2> + <mc3>best</mc3> + <mc4>best 2</mc4> + <mc5>best 3</mc5> + </multiplechoice> +*/ + +{ + if (mc.isEmpty()) + return true; + + xml.writeText("\n"); + QString identstr; + identstr.fill (' ', ident+1); + + xml.writeText(identstr); + xml.startTag (KV_MULTIPLECHOICE_GRP, false); + xml.closeTag(false, true); + xml.writeText(identstr+" "); + + if (!mc.mc1().isEmpty() ) { + xml.startTag (KV_MC_1, true, false, false); + xml.writeText (mc.mc1()); + xml.endTag (KV_MC_1, false); + } + + if (!mc.mc2().isEmpty() ) { + xml.startTag (KV_MC_2, true, false, false); + xml.writeText (mc.mc2()); + xml.endTag (KV_MC_2, false); + } + + if (!mc.mc3().isEmpty() ) { + xml.startTag (KV_MC_3, true, false, false); + xml.writeText (mc.mc3()); + xml.endTag (KV_MC_3, false); + } + + if (!mc.mc4().isEmpty() ) { + xml.startTag (KV_MC_4, true, false, false); + xml.writeText (mc.mc4()); + xml.endTag (KV_MC_4, false); + } + + if (!mc.mc5().isEmpty() ) { + xml.startTag (KV_MC_5, true, false, false); + xml.writeText (mc.mc5()); + xml.endTag (KV_MC_5, false); + } + + xml.writeText("\n"+identstr); + xml.endTag (KV_MULTIPLECHOICE_GRP, true); + xml.writeText(identstr); // indent next element + return true; +} + + +bool kvoctrainDoc::saveConjugEntry (Conjugation &curr_conjug, + XmlWriter &xml, + int ident) + +/* + <conjugation> in entry for definition of tenses of (irreg.) verbs + <t n="sipa"> + <s1>go</s1> + <s2>go</s2> + <s3f>goes</s3f> + <s3m>goes</s3m> + <s3n>goes</s3n> + <p1>go</p1> + <p2>go</p2> + <p3f>go</p3f> + <p3m>go</p3m> + <p3n>go</p3n> + </t> + </conjugation> +*/ +{ + curr_conjug.cleanUp(); + if (curr_conjug.numEntries() == 0 ) + return true; + + QString identstr; + identstr.fill (' ', ident+1); + xml.writeText("\n"); + + xml.writeText(identstr); // indent entry a bit + xml.startTag (KV_CONJUG_GRP, false); + xml.closeTag(false, true); + + QString def, indef, s; + QString type; + for (int lfn = 0; lfn < (int) curr_conjug.numEntries(); lfn++) { + xml.writeText(identstr+" "); // indent entry a bit + xml.startTag (KV_CON_TYPE, false); + type = curr_conjug.getType(lfn); + xml.addAttribute (KV_CON_NAME, type); + xml.closeTag(false, false); + + if (!saveConjug (curr_conjug, curr_conjug.getType(lfn), xml, identstr) ) + return false; + + xml.endTag (KV_CON_TYPE, true); + } + + xml.writeText(identstr); + xml.endTag (KV_CONJUG_GRP, true); + xml.writeText(identstr); // indent next element + return true; +} + + +bool kvoctrainDoc::saveArticleKvtMl (XmlWriter &xml) + +/* + <article> + <e l="de"> lang determines also lang order in entries !! + <fi>eine</fi> which must NOT differ + <fd>die</fd> + <mi>ein</mi> + <md>der</md> + <ni>ein</ni> + <nd>das</nd> + </e> + </article> +*/ + +{ + if (articles.size() == 0) + return true; + + xml.writeText(" "); // indent entry a bit + xml.startTag (KV_ARTICLE_GRP, false); + xml.closeTag(false, true); + + QString def, indef, s; + for (int lfn = 0; lfn < QMIN((int) articles.size(), numLangs()); lfn++) { + xml.writeText(" "); // indent entry a bit + xml.startTag (KV_ART_ENTRY, false); + if (lfn == 0) { + s = getOriginalIdent().stripWhiteSpace(); + if (s.isEmpty() ) + s = "original"; + } + else { + s = getIdent(lfn).stripWhiteSpace(); + if (s.isEmpty() ) { + s.setNum (lfn); + s.insert (0, "translation "); + } + } + xml.addAttribute (KV_LANG, s); + xml.closeTag(false, true); + + articles[lfn].female(def, indef); + if (!def.isEmpty() ) { + xml.writeText(" "); + xml.startTag (KV_ART_FD, true, false, false); + xml.writeText (def); + xml.endTag (KV_ART_FD, true); + } + if (!indef.isEmpty() ) { + xml.writeText(" "); + xml.startTag (KV_ART_FI, true, false, false); + xml.writeText (indef); + xml.endTag (KV_ART_FI, true); + } + + articles[lfn].male(def, indef); + if (!def.isEmpty() ) { + xml.writeText(" "); + xml.startTag (KV_ART_MD, true, false, false); + xml.writeText (def); + xml.endTag (KV_ART_MD, true); + } + if (!indef.isEmpty() ) { + xml.writeText(" "); + xml.startTag (KV_ART_MI, true, false, false); + xml.writeText (indef); + xml.endTag (KV_ART_MI, true); + } + + articles[lfn].natural(def, indef); + if (!def.isEmpty() ) { + xml.writeText(" "); + xml.startTag (KV_ART_ND, true, false, false); + xml.writeText (def); + xml.endTag (KV_ART_ND, true); + } + if (!indef.isEmpty() ) { + xml.writeText(" "); + xml.startTag (KV_ART_NI, true, false, false); + xml.writeText (indef); + xml.endTag (KV_ART_NI, true); + } + + xml.writeText(" "); + xml.endTag (KV_ART_ENTRY, true); + xml.writeText(""); + } + + xml.writeText(" "); + xml.endTag (KV_ARTICLE_GRP, true); + xml.writeText("\n"); + return true; +} + + +bool kvoctrainDoc::saveOptionsKvtMl (XmlWriter &xml) +{ + xml.writeText(" "); // indent entry a bit + xml.startTag (KV_OPTION_GRP, false); + xml.closeTag(false, true); + + xml.writeText(" "); + xml.startTag (KV_OPT_SORT, false); + xml.addAttribute (KV_BOOL_FLAG, sort_allowed ); + xml.closeTag (true, true); + + xml.writeText(" "); + xml.endTag (KV_OPTION_GRP, true); + xml.writeText("\n"); + return true; +} + + +bool kvoctrainDoc::saveToKvtMl (QTextStream& os, QString &title) { + bool first_expr = true; + + os.setCodec(QTextCodec::codecForName("UTF-8")); + + XmlWriter xml (os); + xml.setAutoEndl (false); + + xml.startTag ("!DOCTYPE", false); + xml.writeText (" kvtml SYSTEM \"kvoctrain.dtd\""); + xml.closeTag (false, true); + + xml.startTag ("!--", false, true, true); + xml.writeText ("\nThis is a machine generated file.\n" + "Be careful when editing here.\n" + "\n" + "Short definition:\n" + "\n" + "lesson lesson group\n" + " desc name\n" + " %no its index\n" + " %query is in query selection\n" + " %current is current lesson\n" + "type type group\n" + " desc name\n" + " %no its index\n" + "e entry of dictionary\n" + " %s is selected\n" + " %m lesson member\n" + " %t common expression type\n" + " o original\n" + " %q in query (\"o\" is given, \"t\" is wanted)\n" + " %l language code\n" + " %r remark\n" + " %p pronunciation\n" + " %width column width\n" + " %t expression type (see QueryManager.h)\n" + " %tf false friend from\n" + " %ff false friend to\n" + " %a antonym\n" + " %y synonym\n" + " %x example\n" + " %u usage label\n" + " %h paraphrase\n" + " t translation ..\n" + " %q in query (\"t\" is given, \"o\" is wanted)\n" + " %l language code\n" + " %r remark\n" + " %p pronunciation\n" + " %width column width\n" + " %t expression type\n" + " %tf false friend from\n" + " %ff false friend to\n" + " %a antonym\n" + " %y synonym\n" + " %x example\n" + " %u usage label\n" + " %h paraphrase\n" + "\n" + " %d last query date (from;to)\n" + " %w dito, compressed and deprecated\n" + " %g grade (from;to)\n" + " %c count (from;to)\n" + " %b bad count (from;to)\n" + "\n" + "\nValid xml means:\n" + " - Close all tags\n" + " - Keep proper hierarchy\n" + " - All attributes are quoted\n" + "--"); + xml.closeTag (false, true); + + xml.writeText ("\n "); + xml.startTag (KV_DOCTYPE, false); + xml.writeText ("\n "); + xml.addAttribute (KV_ENCODING, (QString)"UTF-8"); + xml.writeText ("\n "); + + xml.addAttribute (KV_GENERATOR, (QString) "kvoctrain" KVD_VERS_PREFIX KVOCTRAIN_VERSION_STRING); + xml.writeText ("\n "); + xml.addAttribute (KV_COLS, numLangs() ); + xml.writeText ("\n "); + xml.addAttribute (KV_LINES, numEntries() ); + if (!title.isEmpty()) { + xml.writeText ("\n "); + xml.addAttribute (KV_TITLE, getTitle() ); + doctitle = title; + } + else if (!doctitle.isEmpty()) { + xml.writeText ("\n "); + xml.addAttribute (KV_TITLE, doctitle); + } + + if (!author.isEmpty()) { + xml.writeText ("\n "); + xml.addAttribute (KV_AUTHOR, getAuthor() ); + } + + if (!license.isEmpty()) { + xml.writeText ("\n "); + xml.addAttribute (KV_LICENSE, getLicense() ); + } + + if (!doc_remark.isEmpty()) { + xml.writeText ("\n "); + xml.addAttribute (KV_DOC_REM, getDocRemark() ); + } + + xml.closeTag (false, true); + xml.writeText ("\n"); + + if (!saveLessonKvtMl(xml)) + return false; + + if (!saveArticleKvtMl(xml)) + return false; + + if (!saveConjugHeader(conjugations, xml)) + return false; + + if (!saveOptionsKvtMl(xml)) + return false; + + if (!saveTypeNameKvtMl(xml)) + return false; + + if (!saveTenseNameKvtMl(xml)) + return false; + + if (!saveUsageNameKvtMl(xml)) + return false; + + QString q_org, q_trans; + vector<kvoctrainExpr>::const_iterator first = vocabulary.begin (); + getQueryLang (q_org, q_trans); + + int ent_no = 0; + int ent_percent = (int) vocabulary.size () / 100; + float f_ent_percent = (int) vocabulary.size () / 100.0; + emit progressChanged(this, 0); + + while (first != vocabulary.end ()) { + xml.writeText(" "); // indent entry a bit + xml.startTag (KV_EXPR, false); + + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, ent_no / (int) f_ent_percent); + + if ((*first).getLesson() != 0) { // entry belongs to lesson x + QString ls; + int lm = (*first).getLesson(); + if (lm > (int) lesson_descr.size() ) { // should not be + kdError() << "index of lesson member too high: " << lm << endl; + lm = 0; + } + ls.setNum (lm); + xml.addAttribute (KV_LESS_MEMBER, ls); + } + + if ((*first).isInQuery()) { // entry was selected for query + xml.addAttribute (KV_SELECTED, (QString) "1"); + } + + if (!(*first).isActive()) { // entry was inactive + xml.addAttribute (KV_INACTIVE, (QString) "1"); + } + + if ((*first).uniqueType() && !(*first).getType(0).isEmpty()) { + xml.addAttribute (KV_EXPRTYPE, (*first).getType(0)); + } + + xml.closeTag (); + xml.startTag (KV_ORG, false); + if (first_expr) { // save space, only tell language in first entry + QString s; + s.setNum (getSizeHint (0)); + xml.addAttribute (KV_SIZEHINT, s); + + s = getOriginalIdent().stripWhiteSpace(); + if (s.isEmpty() ) + s = "original"; + xml.addAttribute (KV_LANG, s); + if (s == q_org) + xml.addAttribute (KV_QUERY, (QString) KV_O); + else if (s == q_trans) + xml.addAttribute (KV_QUERY, (QString) KV_T); + + } + + if (!(*first).getRemark(0).isEmpty() ) { + xml.addAttribute (KV_REMARK, (*first).getRemark(0)); + } + + if (!(*first).getSynonym(0).isEmpty() ) { + xml.addAttribute (KV_SYNONYM, (*first).getSynonym(0)); + } + + if (!(*first).getExample(0).isEmpty() ) { + xml.addAttribute (KV_EXAMPLE, (*first).getExample(0)); + } + + if (!(*first).getUsageLabel(0).isEmpty() ) { + xml.addAttribute (KV_USAGE, (*first).getUsageLabel(0)); + } + + if (!(*first).getParaphrase(0).isEmpty() ) { + xml.addAttribute (KV_PARAPHRASE, (*first).getParaphrase(0)); + } + + if (!(*first).getAntonym(0).isEmpty() ) { + xml.addAttribute (KV_ANTONYM, (*first).getAntonym(0)); + } + + if (!(*first).getPronunce(0).isEmpty() ) { + xml.addAttribute (KV_PRONUNCE, (*first).getPronunce(0)); + } + + if (!(*first).uniqueType() && !(*first).getType(0).isEmpty()) { + xml.addAttribute (KV_EXPRTYPE, (*first).getType(0)); + } + + xml.closeTag (); + + if (!saveMultipleChoice ((*first).getMultipleChoice(0), xml, 1)) + return false; + + QString s; + QString entype = s = (*first).getType(0); + int pos = s.find (QM_TYPE_DIV); + if (pos >= 0) + entype = s.left (pos); + else + entype = s; + + if ( entype == QM_VERB + && (*first).getConjugation(0).numEntries() > 0) { + Conjugation conj = (*first).getConjugation(0); + if (!saveConjugEntry(conj, xml, 1)) + return false; + } + else if (entype == QM_ADJ + && !(*first).getComparison(0).isEmpty()) { + Comparison comp = (*first).getComparison(0); + if (!saveComparison (comp, xml, 1)) + return false; + } + + xml.writeText( (*first).getOriginal()); + xml.endTag (KV_ORG); + + int trans = 1; + while (trans < (int)langs.size()) { + xml.startTag (KV_TRANS, false); + if (first_expr) { // save space, only tell language in first entry + QString s; + s.setNum (getSizeHint (trans)); + xml.addAttribute (KV_SIZEHINT, s); + + s = getIdent(trans).stripWhiteSpace(); + if (s.isEmpty() ) { + s.setNum (trans); + s.insert (0, "translation "); + } + xml.addAttribute (KV_LANG, s); + if (s == q_org) + xml.addAttribute (KV_QUERY, (QString) KV_O); + else if (s == q_trans) + xml.addAttribute (KV_QUERY, (QString) KV_T); + } + + QString s1, s2; + + if ((*first).getGrade(trans, false) != 0 + ||(*first).getGrade(trans, true) != 0) { + xml.addAttribute (KV_GRADE, (*first).gradeStr(trans, false) + +';' + +(*first).gradeStr(trans, true)); + } + + if ((*first).getQueryCount(trans, false) != 0 + ||(*first).getQueryCount(trans, true) != 0) { + s1.setNum((*first).getQueryCount(trans, false)); + s2.setNum((*first).getQueryCount(trans, true)); + xml.addAttribute (KV_COUNT, s1 +';' +s2); + } + + if ((*first).getBadCount(trans, false) != 0 + ||(*first).getBadCount(trans, true) != 0) { + s1.setNum((*first).getBadCount(trans, false)); + s2.setNum((*first).getBadCount(trans, true)); + xml.addAttribute (KV_BAD, s1 +';' +s2); + } + + if ((*first).getQueryDate(trans, false) != 0 + ||(*first).getQueryDate(trans, true) != 0) { + s1.setNum((*first).getQueryDate(trans, false)); + s2.setNum((*first).getQueryDate(trans, true)); + xml.addAttribute (KV_DATE, s1 +';' +s2); + } + + if (!(*first).getRemark(trans).isEmpty() ) { + xml.addAttribute (KV_REMARK, (*first).getRemark(trans)); + } + + if (!(*first).getFauxAmi(trans, false).isEmpty() ) { + xml.addAttribute (KV_FAUX_AMI_F, (*first).getFauxAmi(trans, false)); + } + + if (!(*first).getFauxAmi(trans, true).isEmpty() ) { + xml.addAttribute (KV_FAUX_AMI_T, (*first).getFauxAmi(trans, true)); + } + + if (!(*first).getSynonym(trans).isEmpty() ) { + xml.addAttribute (KV_SYNONYM, (*first).getSynonym(trans)); + } + + if (!(*first).getExample(trans).isEmpty() ) { + xml.addAttribute (KV_EXAMPLE, (*first).getExample(trans)); + } + + if (!(*first).getUsageLabel(trans).isEmpty() ) { + xml.addAttribute (KV_USAGE, (*first).getUsageLabel(trans)); + } + + if (!(*first).getParaphrase(trans).isEmpty() ) { + xml.addAttribute (KV_PARAPHRASE, (*first).getParaphrase(trans)); + } + + if (!(*first).getAntonym(trans).isEmpty() ) { + xml.addAttribute (KV_ANTONYM, (*first).getAntonym(trans)); + } + + if (!(*first).getPronunce(trans).isEmpty() ) { + xml.addAttribute (KV_PRONUNCE, (*first).getPronunce(trans)); + } + + if (!(*first).uniqueType() && !(*first).getType(trans).isEmpty()) { + xml.addAttribute (KV_EXPRTYPE, (*first).getType(trans)); + } + + xml.closeTag (); + + // only save conjugations when type == verb + + if (!saveMultipleChoice ((*first).getMultipleChoice(trans), xml, 1)) + return false; + + QString s; + QString entype = s = (*first).getType(0); + int pos = s.find (QM_TYPE_DIV); + if (pos >= 0) + entype = s.left (pos); + else + entype = s; + + if ( entype == QM_VERB + && (*first).getConjugation(trans).numEntries() > 0) { + Conjugation conj = (*first).getConjugation(trans); + if (!saveConjugEntry(conj, xml, 1+trans)) + return false; + } + + if ( entype == QM_ADJ + && !(*first).getComparison(trans).isEmpty()) { + Comparison comp = (*first).getComparison(trans); + if (!saveComparison (comp, xml, 1+trans)) + return false; + } + + xml.writeText((*first).getTranslation(trans)); + xml.endTag (KV_TRANS); + trans++; + } + xml.endTag (KV_EXPR, true); + first++; + first_expr = false; + } + xml.endTag (KV_DOCTYPE, true); + + setModified (false); + return os.device()->status() == IO_Ok; +} diff --git a/kvoctrain/kvoctrain/kvt-core/kvoctraincore.h b/kvoctrain/kvoctrain/kvt-core/kvoctraincore.h new file mode 100644 index 00000000..365882c6 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvoctraincore.h @@ -0,0 +1,115 @@ +/*************************************************************************** + + common #defines for kvoctrain core + + ----------------------------------------------------------------------- + + begin : Thu Nov 25 10:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KVOCTRAINCORE_H +#define KVOCTRAINCORE_H + +/////////////////////////////////////////////////////////////////// +// Config file entries + +#define CFG_MODIFIED "Modified" +#define CFG_FILENAME "Filename" +#define CFG_TITLE "Title" + +#define CFG_APPEARANCE "Appearance" +#define CFG_XMLOPS_R "XmlOps_R" +#define CFG_XMLOPS_W "XmlOps_W" +#define CFG_XMLOPS_S "XmlOps_S" +#define CFG_IPA_FSIZE "IPAFontSize" +#define CFG_IPA_FFAMILY "IPAFontFamily" +#define CFG_FSIZE "FontSize" +#define CFG_FFAMILY "FontFamily" +#define CFG_FCHARSET "FontCharSet" +#define CFG_SHOW_TOOLBAR "ShowToolbar" +#define CFG_SHOW_STATUSBAR "ShowStatusbar" +#define CFG_TOOLBAR_POS "ToolBar_Pos" + +#define CFG_GENERAL "General" +#define CFG_LASTFILE "LastFile" +#define CFG_PASTEORDER "PasteOrder" +#define CFG_ENTRIESLESSON "EntriesPerLesson" +#define CFG_HEADER_RESIZER "HeaderResizer" +#define CFG_AUTOSAVEOPT "AutoSaveOptions" +#define CFG_ENTRYAUTOAPPLY "EntryAutomaticApply" + +#define CFG_LESSONSIZE "LessonSize" + +#define CFG_QUERYPROP "QueryProperties" +#define CFG_QUERYMODE "QueryMode" +#define CFG_DEFTRANS "DefaultTranslation" +#define CFG_DEFORG "DefaultOriginal" + +#define CFG_NUMLANGSET "NumLangSet" +#define CFG_L_SHORT "ShortId" +#define CFG_L_SHORT2 "Short2Id" +# define CFG_L_LANG "LongId_KDE2" +# define CFG_L_PIXMAP "Pixmap_KDE2" +#define CFG_L_KBLAYOUT "KeyboardLayout" +#define CFG_L_FONT "Font" +#define CFG_L_STDFONT "SpecialFont" + +#define CFG_QUERYMANAG "QueryManager" +#define CFG_QM_DATE_ITEM "DateItem" +#define CFG_QM_DATE_COMP "DateComp" +#define CFG_QM_QUERY_ITEM "QueryItem" +#define CFG_QM_QUERY_COMP "QueryComp" +#define CFG_QM_BAD_ITEM "BadItem" +#define CFG_QM_BAD_COMP "BadComp" +#define CFG_QM_TYPE_ITEM "TypeItem" +#define CFG_QM_TYPE_COMP "TypeComp" +#define CFG_QM_GRADE_ITEM "GradeItem" +#define CFG_QM_GRADE_COMP "GradeComp" +#define CFG_QM_LESSON_ITEM "LessonItem" +#define CFG_QM_LESSON_COMP "LessonComp" +#define CFG_QM_BLOCK_ITEM "BlockItem" +#define CFG_QM_EXPIRE_ITEM "ExpireItem" + +#define CFG_QUERY_PRESETTING "QueryPreSettings" +#define CFG_QP_NUM "NumPreSetting" +#define CFG_QP_NAME "Name" +#define CFG_QP_THRESH "Threshhold" +#define CFG_QP_BLOCK "Blocking" +#define CFG_QP_QUERY "Query" + +#define KVTML_EXT "kvtml" +#define VT5_LEX_EXT "lex" +#define QVOCAB_EXT "qvo" +#define VCB_EXT "vocab" +#define KVL_EXT "vl" +#define CSV_EXT "csv" +#define TXT_EXT "txt" + +#define VCB_SEPARATOR "__" + +#define MAX_LESSON 25 +#define THRESH_LESSON KV_MIN_GRADE +#define MAX_LANGSET 100 + +#define KVTLIB_DEBUG_AREA 12003 +#define KVOCTRAIN_VERSION_STRING "0.8.3" // maybe split KVTLIB_VERSION/KVAPP_VERSION + +#endif // KVOCTRAINCORE_H diff --git a/kvoctrain/kvoctrain/kvt-core/kvoctraindoc.cpp b/kvoctrain/kvoctrain/kvt-core/kvoctraindoc.cpp new file mode 100644 index 00000000..f2701bed --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvoctraindoc.cpp @@ -0,0 +1,1061 @@ +/*************************************************************************** + + + maintain a kvoctrain document + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kvoctraindoc.h" + +#include <kapplication.h> +#include <klocale.h> +#include <kdebug.h> +#include <kmessagebox.h> +#include <kio/netaccess.h> + +#include <qfileinfo.h> +#include <qregexp.h> + +#include <algorithm> +#include <functional> +#include <vector> +using namespace std; + +#include <iostream> + +#include <float.h> + +#include "kvoctraincore.h" +#include "prefs.h" + +//******************************************************** +// kvoctrainDoc +//******************************************************** + +void kvoctrainDoc::setVersion (const QString & vers) +{ + doc_version = vers; +} + + +void kvoctrainDoc::getVersion(int &, int &, int &) +{ +} + + +void kvoctrainDoc::Init () +{ + + setVersion (QString::fromUtf8(KVOCTRAIN_VERSION_STRING)); + lesson_descr.clear(); + type_descr.clear(); + tense_descr.clear(); + langs.clear(); + extraSizehints.clear(); + sizehints.clear(); + vocabulary.clear(); + dirty = false; + sort_allowed = true; + unknown_attr = false; + unknown_elem = false; + sort_lesson = false; + for (int i = 0; i < (int) langs.size(); i++) + sort_lang.push_back(false); + setCurrentLesson (0); + queryorg = ""; + querytrans = ""; + doc_url.setFileName(i18n("Untitled")); + doctitle = ""; + author = ""; +} + + +kvoctrainDoc::kvoctrainDoc(QObject *parent, const KURL& url) +{ + Init(); + if (!url.isEmpty()) + doc_url = url; + + connect( this, SIGNAL(progressChanged(kvoctrainDoc*,int)), parent, SLOT(slotProgress(kvoctrainDoc*,int)) ); + + QString tmpfile; + if (KIO::NetAccess::download( url, tmpfile, 0 )) + { + QFile f(tmpfile); + if (!f.open(IO_ReadOnly)) + { + KMessageBox::error(0, i18n("<qt>Cannot open file<br><b>%1</b></qt>").arg(url.path())); + return; + } + + FileType ft = detectFT(tmpfile); + + bool read = false; + while (!read) { + + QApplication::setOverrideCursor( waitCursor ); + switch (ft) { + case kvtml: + { + QTextStream is (&f); + read = loadFromKvtMl (is); + } + break; + + case vt_lex: + { + QTextStream is (&f); + read = loadFromLex (is); + } + break; + + case vt_vcb: + { + QTextStream is (&f); + read = loadFromVcb (is); + } + break; + + case vt_voc: + { + QTextStream is (&f); + read = loadFromVoc(is); + } + break; + + case csv: + { + QTextStream is(&f); + read = loadFromCsv(is); + } + break; + + default: + { + QTextStream is (&f); + read = loadFromKvtMl (is); + } + } + + QApplication::restoreOverrideCursor(); + + if (!read) { + if (unknown_attr || unknown_elem ) { + Init(); + return; + } + QString format = i18n("Could not load \"%1\"\nDo you want to try again?"); + QString msg = format.arg(url.path()); + int result = KMessageBox::warningContinueCancel(0, msg, + kapp->makeStdCaption(i18n("I/O Failure")), + i18n("&Retry")); + if ( result == KMessageBox::Cancel ) { + Init(); + return; + } + } + } + f.close(); + KIO::NetAccess::removeTempFile( tmpfile ); + } +} + + +kvoctrainDoc::~kvoctrainDoc() +{ +} + + +bool kvoctrainDoc::saveAs (QObject *parent, const KURL & url, QString title, FileType ft) +{ + connect( this, SIGNAL(progressChanged(kvoctrainDoc*,int)), parent, SLOT(slotProgress(kvoctrainDoc*,int)) ); + + KURL tmp (url); + if (title == i18n("Untitled")) + title = QString::null; + if (title == doc_url.fileName()) + title = QString::null; + + if (ft == automatic) + { + if (tmp.path().right(strlen("." KVTML_EXT)) == "." KVTML_EXT) + ft = kvtml; + else if (tmp.path().right(strlen("." VT5_LEX_EXT)) == "." VT5_LEX_EXT) + ft = vt_lex; + else if (tmp.path().right(strlen("." VCB_EXT)) == "." VCB_EXT) + ft = vt_vcb; + else if (tmp.path().right(strlen("." CSV_EXT)) == "." CSV_EXT) + ft = csv; + else + { + tmp.setFileName(tmp.path() + "." KVTML_EXT); + ft = kvtml; + } + } + + bool saved = false; + while (!saved) + { + + QFile f(tmp.path()); + + if (!f.open(IO_WriteOnly)) + { + KMessageBox::error(0, i18n("<qt>Cannot write to file<br><b>%1</b></qt>").arg(tmp.path())); + return false; + } + + QApplication::setOverrideCursor( waitCursor ); + switch (ft) { + case kvtml: { + QTextStream os( &f ); // serialize using f + saved = saveToKvtMl(os, title); + } + break; + + case vt_lex: { + QTextStream os( &f ); // serialize using f + saved = saveToLex(os, title); + } + break; + + case vt_vcb: { + QTextStream os( &f ); // serialize using f + saved = saveToVcb(os, title); + } + break; + + case csv: { + QTextStream os( &f ); // serialize using f + saved = saveToCsv(os, title); + } + break; + + default: { + kdError() << "kvcotrainDoc::saveAs(): unknown filetype" << endl; + } + break; + } + f.close(); + QApplication::restoreOverrideCursor(); + + if (!saved) { + QString format = i18n("Could not save \"%1\"\nDo you want to try again?"); + QString msg = format.arg(tmp.path()); + int result = KMessageBox::warningContinueCancel(0, msg, + kapp->makeStdCaption(i18n("I/O Failure")), + i18n("&Retry")); + if ( result == KMessageBox::Cancel ) return false; + } + } + doc_url = tmp; + dirty = false; + emit docModified(false); + return true; +} + + +kvoctrainExpr *kvoctrainDoc::getEntry(int index) +{ + if (index < 0 || index >= (int)vocabulary.size() ) + return 0; + else + return &vocabulary[index]; +} + + +void kvoctrainDoc::removeEntry(int index) +{ + if (index >= 0 && index < (int)vocabulary.size() ) + vocabulary.erase (vocabulary.begin() + index); +} + + +int kvoctrainDoc::findIdent (const QString &lang) const +{ + vector<QString>::const_iterator first = langs.begin(); + int count = 0; + while (first != langs.end()) { + if ( *first == lang) + return count; + first++; + count++; + } + return -1; +} + + +QString kvoctrainDoc::getIdent (int index) const +{ + if (index >= (int)langs.size() || index < 1 ) + return ""; + else + return langs[index]; +} + + +void kvoctrainDoc::setIdent (int idx, const QString &id) +{ + if (idx < (int)langs.size() && idx >= 1 ) { + langs[idx] = id; + } +} + + +QString kvoctrainDoc::getTypeName (int index) const +{ + if (index >= (int)type_descr.size()) + return ""; + else + return type_descr[index]; +} + + +void kvoctrainDoc::setTypeName (int idx, QString &id) +{ + if (idx >= (int)type_descr.size()) + for (int i = (int)type_descr.size(); i <= idx; i++) + type_descr.push_back (""); + + type_descr[idx] = id; +} + + +QString kvoctrainDoc::getTenseName (int index) const +{ + if (index >= (int)tense_descr.size()) + return ""; + else + return tense_descr[index]; +} + + +void kvoctrainDoc::setTenseName (int idx, QString &id) +{ + if (idx >= (int)tense_descr.size()) + for (int i = (int)tense_descr.size(); i <= idx; i++) + tense_descr.push_back (""); + + tense_descr[idx] = id; +} + + +QString kvoctrainDoc::getUsageName (int index) const +{ + if (index >= (int)usage_descr.size()) + return ""; + else + return usage_descr[index]; +} + + +void kvoctrainDoc::setUsageName (int idx, QString &id) +{ + if (idx >= (int)usage_descr.size()) + for (int i = (int)usage_descr.size(); i <= idx; i++) + usage_descr.push_back (""); + + usage_descr[idx] = id; +} + + +void kvoctrainDoc::setConjugation (int idx, const Conjugation &con) +{ + if ( idx < 0) return; + + // extend conjugation with empty elements + if ((int)conjugations.size() <= idx ) + for (int i = conjugations.size(); i < idx+1; i++) + conjugations.push_back (Conjugation()); + + conjugations[idx] = con; +} + + +Conjugation kvoctrainDoc::getConjugation (int idx) const +{ + if (idx >= (int)conjugations.size() || idx < 0) { + return Conjugation(); + } + else { + return conjugations[idx]; + } +} + + +void kvoctrainDoc::setArticle (int idx, const Article &art) +{ + if ( idx < 0) return; + + // extend conjugation with empty elements + if ((int)articles.size() <= idx ) + for (int i = articles.size(); i < idx+1; i++) + articles.push_back (Article()); + + articles[idx] = art; +} + + +Article kvoctrainDoc::getArticle (int idx) const +{ + if (idx >= (int)articles.size() || idx < 0) { + return Article(); + } + else { + return articles[idx]; + } +} + + +int kvoctrainDoc::getSizeHint (int idx) const +{ + if (idx < 0) { + idx = -idx; + if (idx >= (int)extraSizehints.size() ) + return 80; // make a good guess about column size + else { +// cout << "gsh " << idx << " " << extraSizehints[idx] << endl; + return extraSizehints[idx]; + } + } + else { + if (idx >= (int)sizehints.size() ) + return 150; // make a good guess about column size + else { +// cout << "gsh " << idx << " " << sizehints[idx] << endl; + return sizehints[idx]; + } + } +} + + +void kvoctrainDoc::setSizeHint (int idx, const int width) +{ +// cout << "ssh " << idx << " " << width << endl; + if (idx < 0) { + idx = -idx; + if (idx >= (int)extraSizehints.size()) { + for (int i = (int)extraSizehints.size(); i <= idx; i++) + extraSizehints.push_back (80); + } + extraSizehints[idx] = width; + + } + else { + if (idx >= (int)sizehints.size()) { + for (int i = (int)sizehints.size(); i <= idx; i++) + sizehints.push_back (150); + } + sizehints[idx] = width; + } +} + + +class eraseTrans : public unary_function<kvoctrainExpr, void> +{ + +public: + + eraseTrans (int idx) + : index (idx) {} + + void operator() (kvoctrainExpr& x) const + { + x.removeTranslation(index); + } + + private: + int index; +}; + + +void kvoctrainDoc::removeIdent (int index) +{ + if (index < (int)langs.size() && index >= 1 ) { + langs.erase(langs.begin() + index); + for_each (vocabulary.begin(), vocabulary.end(), eraseTrans(index)); + } +} + + +QString kvoctrainDoc::getOriginalIdent () const +{ + if (langs.size() > 0) + return langs[0]; + else + return ""; +} + + +void kvoctrainDoc::setOriginalIdent (const QString &id) +{ + if (langs.size() > 0) { + langs[0] = id; + } +} + + +class sortByOrg : public binary_function<kvoctrainExpr, kvoctrainExpr, bool> +{ + +public: + + sortByOrg (bool _dir) + : dir (_dir) {} + + bool operator() (const kvoctrainExpr& x, const kvoctrainExpr& y) const + { + return + !dir + ? (QString::compare(x.getOriginal().upper(), + y.getOriginal().upper() ) < 0) + : (QString::compare(x.getOriginal().upper(), + y.getOriginal().upper() ) > 0); + } + + private: + bool dir; +}; + + +class sortByLessonAndOrg_alpha + : public binary_function<kvoctrainExpr, kvoctrainExpr, bool> +{ + +public: + + sortByLessonAndOrg_alpha (bool _dir, kvoctrainDoc &_doc) + : dir (_dir), doc(_doc) {} + + bool operator() (const kvoctrainExpr& x, const kvoctrainExpr& y) const + { + if (x.getLesson() != y.getLesson() ) + return + !dir + ? (QString::compare(doc.getLessonDescr(x.getLesson()).upper(), + doc.getLessonDescr(y.getLesson()).upper() ) < 0) + : (QString::compare(doc.getLessonDescr(x.getLesson()).upper(), + doc.getLessonDescr(y.getLesson()).upper() ) > 0); + else + return + !dir + ? (QString::compare(x.getOriginal().upper(), + y.getOriginal().upper() ) < 0) + : (QString::compare(x.getOriginal().upper(), + y.getOriginal().upper() ) > 0); + } + + private: + bool dir; + kvoctrainDoc &doc; +}; + + +class sortByLessonAndOrg_index + : public binary_function<kvoctrainExpr, kvoctrainExpr, bool> +{ + +public: + + sortByLessonAndOrg_index (bool _dir, kvoctrainDoc &_doc) + : dir (_dir), doc(_doc) {} + + bool operator() (const kvoctrainExpr& x, const kvoctrainExpr& y) const + { + if (x.getLesson() != y.getLesson() ) + return + !dir + ? x.getLesson() < y.getLesson() + : y.getLesson() < x.getLesson(); + else + return + !dir + ? (QString::compare(x.getOriginal().upper(), + y.getOriginal().upper() ) < 0) + : (QString::compare(x.getOriginal().upper(), + y.getOriginal().upper() ) > 0); + } + + private: + bool dir; + kvoctrainDoc &doc; +}; + + +class sortByTrans : public binary_function<kvoctrainExpr, kvoctrainExpr, bool> +{ + +public: + + sortByTrans (int i, bool _dir) + : index(i), dir (_dir) {} + + bool operator() (const kvoctrainExpr& x, const kvoctrainExpr& y) const + { + return + !dir + ? (QString::compare(x.getTranslation(index).upper(), + y.getTranslation(index).upper() ) < 0) + : (QString::compare(x.getTranslation(index).upper(), + y.getTranslation(index).upper() ) > 0); + } + + private: + int index; + bool dir; +}; + + +bool kvoctrainDoc::sort (int index) +{ + if (!sort_allowed) + return false; + + if (index >= numLangs()) + return false; + + if (sort_lang.size() < langs.size()) + for (int i = sort_lang.size(); i < (int) langs.size(); i++) + sort_lang.push_back(false); + + if (index == 0) + std::sort (vocabulary.begin(), vocabulary.end(), sortByOrg(sort_lang[0])); + else + std::sort (vocabulary.begin(), vocabulary.end(), sortByTrans(index, sort_lang[index])); + sort_lang[index] = !sort_lang[index]; + return sort_lang[index]; +} + + +bool kvoctrainDoc::sortByLesson_alpha () +{ + if (!sort_allowed) + return false; + + std::sort (vocabulary.begin(), vocabulary.end(), sortByLessonAndOrg_alpha(sort_lesson, *this )); + sort_lesson = !sort_lesson; + return sort_lesson; +} + + +bool kvoctrainDoc::sortByLesson_index () +{ + if (!sort_allowed) + return false; + + if (sort_lang.size() < langs.size()) + for (int i = sort_lang.size(); i < (int) langs.size(); i++) + sort_lang.push_back(false); + + std::sort (vocabulary.begin(), vocabulary.end(), sortByLessonAndOrg_index(sort_lesson, *this )); + sort_lesson = !sort_lesson; + sort_lang[0] = sort_lesson; + return sort_lesson; +} + + +class resetAll : public unary_function<kvoctrainExpr, void> +{ + +public: + + resetAll (int less) + : lesson(less) {} + + void operator() (kvoctrainExpr& x) + { + for (int i = 0; i <= x.numTranslations(); i++) { + if (lesson == 0 || lesson == x.getLesson() ) { + x.setGrade(i, KV_NORM_GRADE, false); + x.setGrade(i, KV_NORM_GRADE, true); + x.setQueryCount (i, 0, true); + x.setQueryCount (i, 0, false); + x.setBadCount (i, 0, true); + x.setBadCount (i, 0, false); + x.setQueryDate (i, 0, true); + x.setQueryDate (i, 0, false); + } + } + } + private: + int lesson; +}; + + +class resetOne : public unary_function<kvoctrainExpr, void> +{ + +public: + + resetOne (int idx, int less) + : index (idx), lesson(less) {} + + void operator() (kvoctrainExpr& x) + { + if (lesson == 0 || lesson == x.getLesson() ) { + x.setGrade(index, KV_NORM_GRADE, false); + x.setGrade(index, KV_NORM_GRADE, true); + x.setQueryCount (index, 0, true); + x.setQueryCount (index, 0, false); + x.setBadCount (index, 0, true); + x.setBadCount (index, 0, false); + x.setQueryDate (index, 0, true); + x.setQueryDate (index, 0, false); + } + } + + private: + int index; + int lesson; +}; + + +void kvoctrainDoc::resetEntry (int index, int lesson) +{ + if (index < 0) + for_each (vocabulary.begin(), vocabulary.end(), resetAll(lesson) ); + else + for_each (vocabulary.begin(), vocabulary.end(), resetOne(index, lesson) ); +} + + +QString kvoctrainDoc::getLessonDescr(int idx) const +{ + if (idx == 0) + return i18n("<no lesson>"); + + if (idx <= 0 || idx > (int) lesson_descr.size() ) + return ""; + + return lesson_descr[idx-1]; +} + + +vector<int> kvoctrainDoc::getLessonsInQuery() const +{ + vector<int> iqvec; + for (unsigned i = 0; i < lessons_in_query.size(); i++) + if (lessons_in_query[i]) { + iqvec.push_back(i+1); // Offset <no lesson> +// cout << "getliq: " << i+1 << endl; + } + return iqvec; +} + + +void kvoctrainDoc::setLessonsInQuery(vector<int> lesson_iq) +{ + lessons_in_query.clear(); + for (unsigned i = 0; i < lesson_descr.size(); i++) + lessons_in_query.push_back(false); + + for (unsigned i = 0; i < lesson_iq.size(); i++) + if (lesson_iq[i] <= (int) lessons_in_query.size() ) { + lessons_in_query[lesson_iq[i]-1] = true; // Offset <no lesson> +// cout << "setliq: " << lesson_iq[i] << " " << i << endl; + } +} + + +QString kvoctrainDoc::getTitle() const +{ + if (doctitle.isEmpty()) + return doc_url.fileName(); + else + return doctitle; +} + + +QString kvoctrainDoc::getAuthor() const +{ + return author; +} + + +QString kvoctrainDoc::getLicense() const +{ + return license; +} + + +QString kvoctrainDoc::getDocRemark() const +{ + return doc_remark; +} + + +void kvoctrainDoc::setTitle(const QString & title) +{ + doctitle = title.stripWhiteSpace(); +} + + +void kvoctrainDoc::setAuthor(const QString & s) +{ + author = s.stripWhiteSpace(); +} + + +void kvoctrainDoc::setLicense(const QString & s) +{ + license = s.stripWhiteSpace(); +} + + +void kvoctrainDoc::setDocRemark(const QString & s) +{ + doc_remark = s.stripWhiteSpace(); +} + + +int kvoctrainDoc::search(QString substr, int id, + int first, int last, + bool word_start, + bool) +{ + if (last >= numEntries() + || last < 0 ) + last = numEntries(); + + if (first < 0) + first = 0; + + for (int i = first; i < last; i++) { + if (word_start) { + + for (id = 0; id <= numLangs(); id++) + { + if (id == 0) + { + if (getEntry(i)->getOriginal().find (substr, 0, false) == 0) // case insensitive + return i; + } else { + if (getEntry(i)->getTranslation(id).find (substr, 0, false) == 0) // case insensitive + return i; + } + } + } + else { + for (id = 0; id <= numLangs(); id++){ + + if (id == 0) + { + if (getEntry(i)->getOriginal().find (substr, 0, false) > -1) // case insensitive + return i; + } else { + if (getEntry(i)->getTranslation(id).find (substr, 0, false) > -1) // case insensitive + return i; + } + } + } + } + return -1; +} + +#define _OFFSET 0x40 +#define _BITMASK 0x3F +#define _BITUSED 6 + +QString kvoctrainDoc::compressDate(unsigned long l) const +{ + if (l == 0) + return ""; + + QString res; + if (l <= KVD_ZERO_TIME) + l = 1; + else + l -= KVD_ZERO_TIME; + while (l != 0) { + char c = _OFFSET + (l & _BITMASK); + res.insert (0, c); + l >>= _BITUSED; + } + return res; +} + + +unsigned long kvoctrainDoc::decompressDate(QString s) const +{ + if (s.isEmpty()) + return 0; + + long res = 0; + unsigned incr = 0; + for (int i = s.length()-1; i >= 0; i--) { + char c = s.local8Bit()[i]; + res += ((c - _OFFSET) & _BITMASK) << incr ; + incr += _BITUSED; + } + return res > 48 ? res+KVD_ZERO_TIME : 0; // early bug with "0" +} + + +kvoctrainDoc::FileType kvoctrainDoc::detectFT(const QString &filename) +{ + QFile f( filename ); + if (!f.open( IO_ReadOnly )) + return csv; + + QDataStream is( &f ); + + Q_INT8 c1, c2, c3, c4, c5; + is >> c1 + >> c2 + >> c3 + >> c4 + >> c5; // guess filetype by first x bytes + + QTextStream ts (&f); + QString line; + line = ts.readLine(); + line.insert (0, c5); + line.insert (0, c4); + line.insert (0, c3); + line.insert (0, c2); + line.insert (0, c1); + f.close(); + + bool stat = is.device()->status(); + if (stat != IO_Ok) + return kvd_none; + if (c1 == '<' && c2 == '?' && c3 == 'x' && c4 == 'm' && c5 == 'l') + return kvtml; + + if (line.find (VCB_SEPARATOR) >= 0) + return vt_vcb; + + if (line == LEX_IDENT_50) + return vt_lex; + + if (c1 == '"' && (line.contains('"') == 1 || line.contains(QRegExp("\",[0-9]")))) + return vt_voc; + + return csv; +} + + +class expRef { + +public: + + expRef (kvoctrainExpr *_exp, int _idx) + { + idx = _idx; + exp = _exp; + } + + bool operator< (const expRef& y) const + { + QString s1 = exp->getOriginal(); + QString s2 = y.exp->getOriginal(); + int cmp = QString::compare(s1.upper(), s2.upper()); + if (cmp != 0) + return cmp < 0; + + for (int i = 1; i < (int) exp->numTranslations(); i++) { + + s1 = exp->getTranslation(i); + s2 = y.exp->getTranslation(i); + cmp = QString::compare(s1.upper(), s2.upper() ); + if (cmp != 0) + return cmp < 0; + } + return cmp < 0; + } + + int idx; + kvoctrainExpr *exp; +}; + + +int kvoctrainDoc::cleanUp() +{ + int count = 0; + kvoctrainExpr *kve1, *kve2; + vector<expRef> shadow; + vector<int> to_delete; + + for (int i = 0; i < (int) vocabulary.size(); i++) + shadow.push_back (expRef (getEntry(i), i)); + std::sort(shadow.begin(), shadow.end()); + +#ifdef CLEAN_BUG + ofstream sso ("shadow.out"); + for (int i = shadow.size()-1; i > 0; i--) { + kve1 = shadow[i].exp; + sso << kve1->getOriginal() << " "; + for (int l = 1; l < (int) numLangs(); l++ ) + sso << kve1->getTranslation(l) << " "; + sso << endl; + } +#endif + + int ent_no = 0; + int ent_percent = vocabulary.size () / 100; + float f_ent_percent = vocabulary.size () / 100.0; + emit progressChanged(this, 0); + + for (int i = shadow.size()-1; i > 0; i--) { + kve1 = shadow[i].exp; + kve2 = shadow[i-1].exp; + + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, (int)((ent_no / f_ent_percent) / 2.0)); + + bool equal = true; + if (kve1->getOriginal() == kve2->getOriginal() ) { + for (int l = 1; equal && l < (int) numLangs(); l++ ) + if (kve1->getTranslation(l) != kve2->getTranslation(l)) + equal = false; + + if (equal) { + to_delete.push_back(shadow[i-1].idx); + count++; + } + } + } + + // removing might take very long + ent_no = 0; + ent_percent = to_delete.size () / 100; + f_ent_percent = to_delete.size () / 100.0; + emit progressChanged(this, 0); + + std::sort (to_delete.begin(), to_delete.end() ); + for (int i = (int) to_delete.size()-1; i >= 0; i--) { + ent_no++; + if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) + emit progressChanged(this, (int)(50 + ent_no / f_ent_percent / 2.0)); +#ifdef CLEAN_BUG + sso << getEntry(to_delete[i])->getOriginal() << endl; +#endif + removeEntry (to_delete[i]); + setModified(); + } + + return count; +} +#include "kvoctraindoc.moc" diff --git a/kvoctrain/kvoctrain/kvt-core/kvoctraindoc.h b/kvoctrain/kvoctrain/kvt-core/kvoctraindoc.h new file mode 100644 index 00000000..d0defb5a --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvoctraindoc.h @@ -0,0 +1,747 @@ +/*************************************************************************** + + maintain a kvoctrain document + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 KVOCTRAINDOC_H +#define KVOCTRAINDOC_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <qobject.h> + +#include <kurl.h> + +#include "kvoctrainexpr.h" + +#include "kvt-xml/XmlReader.h" +#include "kvt-xml/XmlWriter.h" + +#define KVD_ZERO_TIME 934329599 // 1999-08-10 23:59:59, never change +#define KVD_VERS_PREFIX " v" // kvoctrain v0.1.0 + +/** XML tags and attribute names */ + +#define KV_DOCTYPE "kvtml" // doctype +#define KV_TITLE "title" // doc title +#define KV_AUTHOR "author" // doc author +#define KV_LICENSE "license" // doc license +#define KV_DOC_REM "remark" // doc remark +#define KV_LINES "lines" // entries +#define KV_GENERATOR "generator" // who generated the doc +#define KV_COLS "cols" // columns +#define KV_ENCODING "encoding" // document encoding (obsolete!) + +#define KV_EXPR "e" // entry for one expression +#define KV_ORG "o" // original expression in specified language +#define KV_TRANS "t" // translated expression in specified language +#define KV_LANG "l" // language: en, de, it, fr ... +#define KV_QUERY "q" // query: org or translation +#define KV_O "o" // org +#define KV_T "t" // translation +#define KV_GRADE "g" // grade of knowledge: 0=well known, x=not known for x times +#define KV_LESS_MEMBER "m" // member of lesson 1 .. x +#define KV_COUNT "c" // number of times queried +#define KV_SIZEHINT "width" // recommended column width +#define KV_CHARSET "charset" // recommended charset (obsolete!) +#define KV_BAD "b" // number of times failed +#define KV_DATE "d" // last query date +#define KV_DATE2 "w" // last query date, compressed format +#define KV_REMARK "r" // remark for this entry +#define KV_FAUX_AMI_F "ff" // false friend of this entry from org +#define KV_FAUX_AMI_T "tf" // false friend of this entry to org +#define KV_SYNONYM "y" // synonym (same meaning) of expr +#define KV_ANTONYM "a" // antonym (oppositite) of expr +#define KV_PRONUNCE "p" // how to pronunce this expression +#define KV_SELECTED "s" // entry selected for queries +#define KV_INACTIVE "i" // entry inactive (for queries) +#define KV_EXPRTYPE "t" // type of expression +#define KV_EXAMPLE "x" // example string with word +#define KV_USAGE "u" // usage label +#define KV_PARAPHRASE "h" // paraphrase for expression + +/* + <type> + <desc no="1">My type 1</desc> + <desc no="2">My type 2</desc> + </type> +*/ + +#define KV_TYPE_GRP "type" // type descriptor group +#define KV_TYPE_DESC "desc" // type descriptor +#define KV_TYPE_NO "no" // type descriptor number + +/* + <usage> + <desc no="1">My usage 1</desc> + <desc no="2">My usage 2</desc> + </type> +*/ + +#define KV_USAGE_GRP "usage" // usage descriptor group +#define KV_USAGE_DESC "desc" // usage descriptor +#define KV_USAGE_NO "no" // usage descriptor number + +/* + <lesson width="138"> + <desc no="1">Lesson #1</desc> + <desc no="2" query="1">Lesson #2</desc> + </lesson> +*/ + +#define KV_LESS_GRP "lesson" // lesson descriptor group +#define KV_LESS_CURR "current" // is current lesson +#define KV_LESS_DESC "desc" // lesson descriptor +#define KV_LESS_QUERY "query" // lesson contained in query +#define KV_LESS_NO "no" // lesson descriptor number + +/* + <tense> + <desc no="1">user tense #1</desc> + <desc no="2">user tense #2</desc> + </tense> +*/ + +#define KV_TENSE_GRP "tense" // tense descriptor group +#define KV_TENSE_DESC "desc" // tense descriptor +#define KV_TENSE_NO "no" // tense descriptor number + +/* + <options> + <sort on="1"/> + </options> +*/ + +#define KV_OPTION_GRP "options" // internal options group +#define KV_OPT_SORT "sort" // allow sorting +#define KV_BOOL_FLAG "on" // general boolean flag + +/* + <article> + <e l="de"> lang determines also lang order in entries !! + <fi>eine</fi> which must NOT differ + <fd>die</fd> + <mi>ein</mi> + <md>der</md> + <ni>ein</ni> + <nd>das</nd> + </e> + </article> +*/ + +#define KV_ARTICLE_GRP "article" // article descriptor group +#define KV_ART_ENTRY "e" // article entry +#define KV_ART_FD "fd" // female definite +#define KV_ART_MD "md" // male definite +#define KV_ART_ND "nd" // natural definite +#define KV_ART_FI "fi" // female indefinite +#define KV_ART_MI "mi" // male indefinite +#define KV_ART_NI "ni" // natural indefinite + +/* + <comparison> + <l1>good</l1> + <l2>better</l2> + <l3>best</l3> + </comparison> +*/ + +#define KV_COMPARISON_GRP "comparison" // comparison descriptor group +#define KV_COMP_L1 "l1" // base form +#define KV_COMP_L2 "l2" // next form +#define KV_COMP_L3 "l3" // last form + +/* + <multiplechoice> + <mc1>good</mc1> + <mc2>better</mc2> + <mc3>best</mc3> + <mc4>best 2</mc4> + <mc5>best 3</mc5> + </multiplechoice> +*/ + +#define KV_MULTIPLECHOICE_GRP "multiplechoice" // multiple choice descriptor group +#define KV_MC_1 "mc1" // choice 1 +#define KV_MC_2 "mc2" // choice 2 +#define KV_MC_3 "mc3" // choice 3 +#define KV_MC_4 "mc4" // choice 4 +#define KV_MC_5 "mc5" // choice 5 + +/* + <conjugation> used in header for definiton of "prefix" + <e l="de"> lang determines also lang order in entries !! + <s1>I</s1> which must NOT differ in subsequent <e>-tags + <s2>you<2> + <s3f>he</s3f> + <s3m>she</s3m> + <s3n>it</s3n> + <p1>we</p1> + <p2>you</p2> + <p3f>they</p3f> + <p3m>they</p3m> + <p3n>they</p3n> + </e> + </conjugation> + + <conjugation> and in entry for definition of tenses of (irreg.) verbs + <t n="sipa"> + <s1>go</s1> + <s2>go</s2> + <s3f>goes</s3f> + <s3m>goes</s3m> + <s3n>goes</s3n> + <p1>go</p1> + <p2>go</p2> + <p3f>go</p3f> + <p3m>go</p3m> + <p3n>go</p3n> + </t> + </conjugation> +*/ + +#define KV_CONJUG_GRP "conjugation" // conjugation descriptor group +#define KV_CON_ENTRY "e" // conjugation entry (header) +#define KV_CON_TYPE "t" // conjugation type (voc entries) +#define KV_CON_NAME "n" // conjugation type name (voc entries) +#define KV_CON_P1S "s1" // 1. person singular +#define KV_CON_P2S "s2" // 2. person singular +#define KV_CON_P3SF "s3f" // 3. person singular female +#define KV_CON_P3SM "s3m" // 3. person singular male +#define KV_CON_P3SN "s3n" // 3. person singular natural +#define KV_CON_P1P "p1" // 1. person plural +#define KV_CON_P2P "p2" // 2. person plural +#define KV_CON_P3PF "p3f" // 3. person plural female +#define KV_CON_P3PM "p3m" // 3. person plural male +#define KV_CON_P3PN "p3n" // 3. person plural natural +#define KV_CONJ_COMMON "common" // female contains common for all three + +#define LEX_IDENT_50 "Vocabulary Trainer V5.0" + + +class QTextStream; +class QStringList; +class MultipleChoice; + +/************************************************************* + * This class contains the expressions of your vocabulary + ************************************************************/ + +class kvoctrainDoc : public QObject +{ + Q_OBJECT + public: + + enum FileType { kvd_none, automatic, + kvtml, + kvtbin, + vt_lex, vt_vcb, csv, vt_voc /*, kvoclearn, qvocab*/ }; + + /** Constructor for the fileclass of the application + * + * @param obj calling object + * @param url URL of file to parse + */ + kvoctrainDoc(QObject* obj, const KURL& url); + + /** Destructor for the fileclass of the application */ + ~kvoctrainDoc(); + + /** indicates that doc is (not) modified + * + * @param dirty new state + */ + inline void setModified (bool _dirty = true) { emit docModified(dirty = _dirty); } + + /** appends another entry at the end + * + * @param expr expression to append + */ + inline void appendEntry (kvoctrainExpr *expr) + { vocabulary.push_back (*expr); dirty = true; } + + /** removes entry from doc + * + * @param index index of entry + */ + void removeEntry (int index); + + /** sorts vocabulary alphabetically + * + * @param index index expression + * @result direction of sorting: true = ascending + */ + bool sort (int index); + + /** removes equal entries (orig + all translations) + * + * @result number of removed entries + */ + int cleanUp(); + + /** sorts vocabulary by lesson indices + * @result direction of sorting: true = ascending + */ + bool sortByLesson_index (); + + /** sorts vocabulary by lesson name + * @result direction of sorting: true = ascending + */ + bool sortByLesson_alpha (); + + /** enables sorting + */ + inline void allowSorting(bool allow) { sort_allowed = allow; } + + /** enables sorting + */ + inline bool isAllowedSorting() { return sort_allowed; } + + /** returns the modification state of the doc */ + inline bool isModified () const { return dirty; } + + /** returns originals identifier + */ + QString getOriginalIdent () const; + + /** set originals identifier + */ + void setOriginalIdent (const QString &id); + + /** returns identifier of translation x + * + * @param index number of translation 1..x + * @result ident string: de=german, en=englisch, .. + */ + QString getIdent (int index) const; + + /** sets identifier of translation + * + * @param index number of translation 1..x + * @param lang ident string: de=german, en=englisch, .. + */ + void setIdent (int index, const QString &lang); + + /** removes identifier an the according translation in all entries + * + * @param index number of translation 1..x + */ + void removeIdent (int index); + + /** determines if given translation is available and where + * + * @param lang identifier of language + * @result index of translation, 0=original, -1=none + */ + int findIdent (const QString &lang) const; + + /** returns attribute string + * + * @param index number of attribute + * @result string + */ + QString getTypeName (int index) const; + + /** sets attribute string + * + * @param index number of attribute + * @param str name of attribute + */ + void setTypeName (int index, QString &str); + + /** gets descr of types */ + inline vector<QString> getTypeDescr() const { return type_descr; } + + /** sets descr of types */ + inline void setTypeDescr(vector<QString> names) { type_descr = names; } + + /** returns tense string + * + * @param index number of tense + * @result string + */ + QString getTenseName (int index) const; + + /** sets tense string + * + * @param index number of tense + * @param str name of tense + */ + void setTenseName (int index, QString &str); + + /** gets descr of tenses */ + inline vector<QString> getTenseDescr() const { return tense_descr; } + + /** sets descr of tenses */ + inline void setTenseDescr(vector<QString> names) { tense_descr = names; } + + /** returns usage string + * + * @param index number of usage + * @result string + */ + QString getUsageName (int index) const; + + /** sets usage string + * + * @param index number of usage + * @param str name of usage + */ + void setUsageName (int index, QString &str); + + /** gets descr of usages */ + inline vector<QString> getUsageDescr() const { return usage_descr; } + + /** sets descr of usages */ + inline void setUsageDescr(vector<QString> names) { usage_descr = names; } + + + /** saves the data under the given name + * + * @param url if url is empty (or NULL) actual name is preserved + * @result true if successful + */ + bool saveAs (QObject *parent, const KURL & url, QString title, FileType ft); + + /** returns count of entries + */ + inline int numEntries() const { return vocabulary.size(); } + + /** sets grades to KV_NORM_GRADE, counts to 0 ... + * + * @param index index of language 0..x, -1 = all + * @param lesson lesson id, if this is 0 all lesson are affected, + * otherwise only matching numbers + */ + void resetEntry (int index = -1, int lesson = 0); + + /** returns count of different languages + */ + inline int numLangs() const { return langs.size(); } // org + translations + + /** append new lang ident + */ + inline void appendLang(const QString & id) { langs.push_back(id); } + + /** returns pointer to expression object x + * + * @param index index of desired entry + * @result pointer to object or NULL if index out of range + */ + kvoctrainExpr *getEntry(int index); + + /** search substring in vocabulary (case insensitive always) + * + * @param substr partial string to search + * @param id which language to search: 0=org, 1..x=translation + * @param first index from where to start + * @param last index of last entry, -1 goes till end + * @param word_start false: search partial string, + * true:always from beginning of word + * @param tolerant + * @result index of found entry, -1 if none + */ + int search(QString substr, int id, + int first=0, int last=-1, bool word_start = false, bool tolerant=false); + + /** returns url of xml file */ + inline KURL URL() const {return doc_url; } + + /** sets url of xml file */ + inline void setURL(const KURL& url) {doc_url = url;} + + /** returns title of xml file */ + QString getTitle() const; + + /** returns author of file */ + QString getAuthor() const; + + /** returns license of file */ + QString getLicense() const; + + /** returns remark of file */ + QString getDocRemark() const; + + inline void getQueryLang(QString &org, QString &trans) const + { org = queryorg; trans = querytrans; } + + inline void setQueryLang(const QString &org, const QString &trans) + { queryorg = org; querytrans = trans; } + + /** sets title of xml file */ + void setTitle(const QString & title); + + /** sets author of file */ + void setAuthor(const QString & author); + + /** sets license of file */ + void setLicense(const QString & license); + + /** sets remark of file */ + void setDocRemark(const QString & rem); + + /** gets version of loaded file */ + void getVersion(int &major, int &minor, int &patch); + + /** returns current lesson index */ + inline int getCurrentLesson() const { return current_lesson; } + + /** sets current lesson index + * @param lesson index of lesson + */ + inline void setCurrentLesson(int lesson) { current_lesson = lesson; } + + /** returns descr of lesson */ + QString getLessonDescr(int index) const; + + /** returns lessons in current query */ + vector<int> getLessonsInQuery() const; + + /** sets lessons in current query */ + void setLessonsInQuery(vector<int>); + + inline vector<QString> getLessonDescr() const { return lesson_descr; } + + inline int numLessons () const {return (int) lesson_descr.size(); } + + /** sets descr of lesson */ + inline void setLessonDescr(vector<QString> names) { lesson_descr = names; } + + /** returns pointer to conjugations if available + * + * @param index index of translation + */ + Conjugation getConjugation(int index) const; + + /** sets conjugations + * + * @param index index of translation + * @param con conjugation block + */ + void setConjugation(int index, const Conjugation &con); + + /** returns pointer to articles if available + * + * @param index index of translation + */ + Article getArticle(int index) const; + + /** sets articles + * + * @param index index of translation + * @param art article block + */ + void setArticle(int index, const Article &art); + + /** compress date */ + QString compressDate(unsigned long) const; + + /** decompress date */ + unsigned long decompressDate(QString) const; + + /** returns recommended size + * + * @param index number of expr, -1 = lesson + * @result width of column + */ + int getSizeHint (int index) const; + + /** sets recommended size + * + * @param index number of expr, -1 = lesson + * @param width width of column + */ + void setSizeHint (int index, const int width); + + bool unknownAttribute (int line, const QString &name, const QString &attr); + void unknownElement (int line, const QString &elem ); + void errorKvtMl (int line, const QString &text ); + void warningKvtMl (int line, const QString &text ); + + void errorLex (int line, const QString &text ); + + void errorCsv (int line, const QString &text ); + + FileType detectFT(const QString &filename); + + friend class QueryManager; + +signals: + void progressChanged (kvoctrainDoc *, int curr_percent); + void docModified (bool mod); + +protected: + + void Init(); + + /** sets version of loaded file */ + void setVersion(const QString & ver); + + bool saveToKvtMl (QTextStream& os, QString &title); + bool loadFromKvtMl (QTextStream& is); + bool parseBody_kvtml (XmlElement elem, XmlReader& xml); + bool parseBody_e (XmlElement elem, XmlReader& xml); + bool extract_simple_tag (QString tag_name, XmlReader& xml, + XmlElement &elem, QString &data, + bool check_empty = true); + + bool extract_T_GROUP_attr (XmlReader &xml, + XmlElement &elem); + bool extract_T_DESCR_attr (XmlReader &xml, + XmlElement &elem, int &no); + bool extract_O_T_attr (XmlReader &xml, + XmlElement &elem, + QString &lang, + grade_t &grade, grade_t &rev_grade, + int &count, int &rev_count, + time_t &date, time_t &rev_date, + QString &remark, + int &bcount, int &rev_bcount, + QString &query_id, + QString &pronunce, + int &width, + QString &type, + QString &faux_ami_f, + QString &faux_ami_t, + QString &synonym, + QString &example, + QString &antonym, + QString &usage, + QString ¶phrase); + bool extract_L_DESCR_attr (XmlReader &xml, + XmlElement &elem, int &no, + bool &isCurr, bool &inQuery); + bool extract_KVT_E_attr (XmlReader& xml, + XmlElement &elem, + int &lesson, + bool &sel, + bool &active, + QString &type); + bool check_Empty_attr (QString tag_name, + XmlReader &xml, + XmlElement &elem); + bool extract_CON_E_attr (XmlReader& xml, + XmlElement &elem, + QString &lang); + bool extract_T_attr (XmlReader &xml, + XmlElement &elem, + QString &name); + bool extract_BOOL_attr (XmlReader &xml, + XmlElement &elem, + const QString &tag_name, + const QString &attr_name, + bool &flag); + bool extract_L_GROUP_attr (XmlReader &xml, + XmlElement &elem, + int &width); + + bool saveLessonKvtMl (XmlWriter &xml); + bool loadLessonKvtMl (XmlElement elem, XmlReader& xml); + bool saveTypeNameKvtMl (XmlWriter &xml); + bool loadTypeNameKvtMl (XmlElement elem, XmlReader& xml); + bool saveTenseNameKvtMl (XmlWriter &xml); + bool loadTenseNameKvtMl (XmlElement elem, XmlReader& xml); + bool saveUsageNameKvtMl (XmlWriter &xml); + bool loadUsageNameKvtMl (XmlElement elem, XmlReader& xml); + bool saveOptionsKvtMl (XmlWriter &xml); + bool loadOptionsKvtMl (XmlElement elem, XmlReader& xml); + bool saveArticleKvtMl (XmlWriter &xml); + bool loadArticleKvtMl (XmlElement elem, XmlReader& xml); + bool saveConjugHeader (vector<Conjugation> &curr_conjug, + XmlWriter &xml); + bool saveConjug (const Conjugation &curr_conjug, QString type, + XmlWriter &xml, QString identstr); + bool saveConjugEntry (Conjugation &curr_conjug, + XmlWriter &xml, int ident); + bool loadConjugKvtMl (vector<Conjugation> &curr_conjug, const QString &entry_tag, + XmlElement elem, XmlReader& xml); + + bool saveComparison (const Comparison &comp, XmlWriter &xml, int ident); + bool loadComparison (Comparison &comp, XmlElement elem, XmlReader &xml); + + bool saveMultipleChoice(const MultipleChoice &mc, XmlWriter &xml, int ident); + bool loadMultipleChoice(MultipleChoice &mc, XmlElement elem, XmlReader &xml); + + bool saveToLex (QTextStream& os, QString &title); + bool loadFromLex (QTextStream& is); + bool loadLessonLex (QTextStream& is); + bool saveLessonLex (QTextStream& os); + bool saveTypeNameLex (QTextStream& os); + bool loadTypeNameLex (QTextStream& is); + + bool saveToCsv (QTextStream& os, QString &title); + bool loadFromCsv (QTextStream& is); + bool loadLessonCsv (QTextStream& is); + bool saveLessonCsv (QTextStream& os); + bool saveTypeNameCsv (QTextStream& os); + bool loadTypeNameCsv (QTextStream& is); + + bool saveTypeNameVcb (QTextStream &os); + bool loadTypeNameVcb (QTextStream &is); + bool saveLessonVcb (QTextStream &os); + bool loadLessonVcb (QTextStream &is); + bool saveToVcb (QTextStream& os, QString &title); + bool loadFromVcb (QTextStream& is); + bool loadFromVoc(QTextStream& is); + void errorVcb (int line, const QString &text ); + + private: + bool dirty; + KURL doc_url; + vector<bool> sort_lang; + bool sort_lesson; + bool unknown_attr; + bool unknown_elem; + bool sort_allowed; + + // save these to document + vector<QString> langs; //0= origin, 1,.. translations + int cols, + lines; + int current_lesson; + vector<int> extraSizehints; + vector<int> sizehints; + QString generator; + QString queryorg, + querytrans; + vector<kvoctrainExpr> vocabulary; + vector<bool> lessons_in_query; + vector<QString> lesson_descr; + vector<QString> type_descr; + vector<QString> tense_descr; + vector<QString> usage_descr; + QString doctitle; + QString author; + QString license; + QString doc_remark; + QString doc_version; + + vector<Article> articles; + vector<Conjugation> conjugations; +}; + + +#endif // KVOCTRAINDOC_H diff --git a/kvoctrain/kvoctrain/kvt-core/kvoctrainexpr.cpp b/kvoctrain/kvoctrain/kvt-core/kvoctrainexpr.cpp new file mode 100644 index 00000000..2faba172 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvoctrainexpr.cpp @@ -0,0 +1,799 @@ +/*************************************************************************** + + maintain a kvoctrain expression + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kvoctrainexpr.h" + +void kvoctrainExpr::Init() +{ + grades.push_back(KV_NORM_GRADE); + rev_grades.push_back(KV_NORM_GRADE); + inquery = false; + active = true; + qcounts.push_back(0); + rev_qcounts.push_back(0); + bcounts.push_back(0); + rev_bcounts.push_back(0); + qdates.push_back(0); + rev_qdates.push_back(0); + lesson = 0; +} + + +kvoctrainExpr::kvoctrainExpr (QString &expr, int _lesson) +{ + Init(); + setOriginal(expr.stripWhiteSpace() ); + lesson = _lesson; +} + + +kvoctrainExpr::kvoctrainExpr () +{ + Init(); +} + + +kvoctrainExpr::kvoctrainExpr (QString &s, QString separator, int _lesson) +{ + Init(); + QString se; + lesson = _lesson; + + if (separator.length() ) { + int pos = s.find(separator); + + if (pos == -1) { + setOriginal(s.stripWhiteSpace()); + } + else { + se = s.left(pos).stripWhiteSpace(); + setOriginal(se); + s.remove (0, pos+separator.length() ); +// s.stripWhiteSpace(); + + // gather all translations + while ((pos = s.find(separator)) != -1) { + se = s.left(pos).stripWhiteSpace(); + addTranslation(se, KV_NORM_GRADE, KV_NORM_GRADE); + s.remove (0, pos+separator.length() ); +// s.stripWhiteSpace(); + } + addTranslation(s.stripWhiteSpace(), KV_NORM_GRADE, KV_NORM_GRADE); + } + } +} + + +kvoctrainExpr::~kvoctrainExpr() +{ +} + + +int kvoctrainExpr::numTranslations() const +{ + return translations.size(); +} + + +QString kvoctrainExpr::getRemark (int idx) const +{ + if (idx >= (int)remarks.size() || idx < 0) { + return ""; + } + else { + return remarks[idx]; + } +} + + +void kvoctrainExpr::setRemark (int idx, const QString & expr) +{ + if ( idx < 0) return; + + // extend remarks with empty strings if necessary + if ((int)remarks.size() <= idx ) + for (int i = remarks.size(); i < idx+1; i++) + remarks.push_back (""); + + remarks[idx] = expr.stripWhiteSpace(); +} + + +void kvoctrainExpr::setFauxAmi (int idx, const QString & expr, bool rev_ami) +{ + if (idx < 1) return; + + if (rev_ami) { + // extend friend with empty strings if necessary + if ((int)rev_fauxAmi.size() <= idx ) + for (int i = rev_fauxAmi.size(); i < idx+1; i++) + rev_fauxAmi.push_back (""); + + rev_fauxAmi[idx] = expr.stripWhiteSpace(); + + } + else { + // extend friend with empty strings if necessary + if ((int)fauxAmi.size() <= idx ) + for (int i = fauxAmi.size(); i < idx+1; i++) + fauxAmi.push_back (""); + + fauxAmi[idx] = expr.stripWhiteSpace(); + } +} + + +QString kvoctrainExpr::getFauxAmi (int idx, bool rev_ami) const +{ + if (rev_ami) { + if (idx >= (int)rev_fauxAmi.size() || idx < 1 ) { + return ""; + } + + return rev_fauxAmi[idx]; + } + + if (idx >= (int)fauxAmi.size() || idx < 1 ) { + return ""; + } + + return fauxAmi[idx]; +} + + +void kvoctrainExpr::setSynonym (int idx, const QString & expr) +{ + if ( idx < 0) return; + + // extend synonym with empty strings if necessary + if ((int)synonym.size() <= idx ) + for (int i = synonym.size(); i < idx+1; i++) + synonym.push_back ("-"); + + synonym[idx] = expr.stripWhiteSpace(); +} + + +QString kvoctrainExpr::getSynonym (int idx) const +{ + if (idx >= (int)synonym.size() || idx < 0) { + return ""; + } + else { + return synonym[idx]; + } +} + + +void kvoctrainExpr::setExample (int idx, const QString & expr) +{ + if ( idx < 0) return; + + // extend exampls with empty strings if necessary + if ((int)example.size() <= idx ) + for (int i = example.size(); i < idx+1; i++) + example.push_back (""); + + example[idx] = expr.stripWhiteSpace(); +} + + +QString kvoctrainExpr::getExample (int idx) const +{ + if (idx >= (int)example.size() || idx < 0) { + return ""; + } + else { + return example[idx]; + } +} + + +void kvoctrainExpr::setUsageLabel (int idx, const QString & expr) +{ + if ( idx < 0) return; + + // extend labels with empty strings if necessary + if ((int)usageLabels.size() <= idx ) + for (int i = usageLabels.size(); i < idx+1; i++) + usageLabels.push_back (""); + + usageLabels[idx] = expr.stripWhiteSpace(); +} + + +QString kvoctrainExpr::getUsageLabel (int idx) const +{ + if (idx >= (int)usageLabels.size() || idx < 0) { + return ""; + } + else { + return usageLabels[idx]; + } +} + + +void kvoctrainExpr::setParaphrase (int idx, const QString & expr) +{ + if ( idx < 0) return; + + // extend phrase with empty strings if necessary + if ((int) paraphrases.size() <= idx ) + for (int i = paraphrases.size(); i < idx+1; i++) + paraphrases.push_back (""); + + paraphrases[idx] = expr.stripWhiteSpace(); +} + + +QString kvoctrainExpr::getParaphrase (int idx) const +{ + if (idx >= (int)paraphrases.size() || idx < 0) { + return ""; + } + else { + return paraphrases[idx]; + } +} + + +void kvoctrainExpr::setAntonym (int idx, const QString & expr) +{ + if ( idx < 0) return; + + // extend antonym with empty strings if necessary + if ((int)antonym.size() <= idx ) + for (int i = antonym.size(); i < idx+1; i++) + antonym.push_back (""); + + antonym[idx] = expr.stripWhiteSpace(); +} + + +QString kvoctrainExpr::getAntonym (int idx) const +{ + if (idx >= (int)antonym.size() || idx < 0) { + return ""; + } + else { + return antonym[idx]; + } +} + + +void kvoctrainExpr::setConjugation (int idx, const Conjugation &con) +{ + if ( idx < 0) return; + + // extend conjugation with empty elements + if ((int)conjugations.size() <= idx ) + for (int i = conjugations.size(); i < idx+1; i++) + conjugations.push_back (Conjugation()); + + conjugations[idx] = con; +} + + +Conjugation kvoctrainExpr::getConjugation (int idx) const +{ + if (idx >= (int)conjugations.size() || idx < 0) { + return Conjugation(); + } + else { + return conjugations[idx]; + } +} + + +void kvoctrainExpr::setComparison (int idx, const Comparison &con) +{ + if ( idx < 0) return; + + // extend comparison with empty elements + if ((int)comparisons.size() <= idx ) + for (int i = comparisons.size(); i < idx+1; i++) + comparisons.push_back (Comparison()); + + comparisons[idx] = con; +} + + +Comparison kvoctrainExpr::getComparison (int idx) const +{ + if (idx >= (int)comparisons.size() || idx < 0) { + return Comparison(); + } + else { + return comparisons[idx]; + } +} + + +void kvoctrainExpr::setMultipleChoice (int idx, const MultipleChoice &mc) +{ + if ( idx < 0) return; + + // extend comparison with empty elements + if ((int)mcs.size() <= idx ) + for (int i = mcs.size(); i < idx+1; i++) + mcs.push_back (MultipleChoice()); + + mcs[idx] = mc; +} + + +MultipleChoice kvoctrainExpr::getMultipleChoice (int idx) const +{ + if (idx >= (int)mcs.size() || idx < 0) { + return MultipleChoice(); + } + else { + return mcs[idx]; + } +} + + +QString kvoctrainExpr::getPronunce (int idx) const +{ + if (idx >= (int)pronunces.size() || idx < 0) { + return ""; + } + else { + return pronunces[idx]; + } +} + + +void kvoctrainExpr::setPronunce (int idx, const QString & expr) +{ + if ( idx < 0) return; + + // extend with empty strings if necessary + if ((int)pronunces.size() <= idx ) + for (int i = pronunces.size(); i < idx+1; i++) + pronunces.push_back (""); + + pronunces[idx] = expr.stripWhiteSpace(); +} + + +void kvoctrainExpr::addTranslation (QString expr, + grade_t grade, grade_t rev_grade) +{ + if (grade > KV_MAX_GRADE) + grade = KV_MAX_GRADE; + + if (rev_grade > KV_MAX_GRADE) + rev_grade = KV_MAX_GRADE; + + grades.push_back (grade); + rev_grades.push_back (rev_grade); + translations.push_back (expr.stripWhiteSpace()); +} + + +QString kvoctrainExpr::getTranslation (int idx) const +{ + if (idx > (int)translations.size() || idx < 1) + return ""; + else + return translations[idx-1]; +} + + +void kvoctrainExpr::removeTranslation (int idx) +{ + if (idx <= 0) + return; + + if (idx <= numTranslations()) + translations.erase (translations.begin() + idx-1); + + if (idx < (int)remarks.size() ) + remarks.erase (remarks.begin() + idx); + + if (idx < (int)conjugations.size() ) + conjugations.erase (conjugations.begin() + idx); + + if (idx < (int)comparisons.size() ) + comparisons.erase (comparisons.begin() + idx); + + if (idx < (int)fauxAmi.size() ) + fauxAmi.erase (fauxAmi.begin() + idx); + + if (idx < (int)rev_fauxAmi.size() ) + rev_fauxAmi.erase (rev_fauxAmi.begin() + idx); + + if (idx < (int)synonym.size() ) + synonym.erase (synonym.begin() + idx); + + if (idx < (int)example.size() ) + example.erase (example.begin() + idx); + + if (idx < (int)usageLabels.size() ) + usageLabels.erase (usageLabels.begin() + idx); + + if (idx < (int)paraphrases.size() ) + paraphrases.erase (paraphrases.begin() + idx); + + if (idx < (int)antonym.size() ) + antonym.erase (antonym.begin() + idx); + + if (idx < (int)exprtypes.size() ) + exprtypes.erase (exprtypes.begin() + idx); + + if (idx < (int)pronunces.size() ) + pronunces.erase (pronunces.begin() + idx); + + if (idx < (int)grades.size() ) + grades.erase (grades.begin() + idx); + + if (idx < (int)rev_grades.size() ) + rev_grades.erase (rev_grades.begin() + idx); + + if (idx < (int)qcounts.size() ) + qcounts.erase (qcounts.begin() + idx); + + if (idx < (int)rev_qcounts.size() ) + rev_qcounts.erase (rev_qcounts.begin() + idx); + + if (idx < (int)bcounts.size() ) + bcounts.erase (bcounts.begin() + idx); + + if (idx < (int)rev_bcounts.size() ) + rev_bcounts.erase (rev_bcounts.begin() + idx); + + if (idx < (int)qdates.size() ) + qdates.erase (qdates.begin() + idx); + + if (idx < (int)rev_qdates.size() ) + rev_qdates.erase (rev_qdates.begin() + idx); +} + + +void kvoctrainExpr::setTranslation (int idx, const QString & expr) +{ + if ( idx <= 0) return; + + // extend translations with empty strings if necessary + if ((int)translations.size() < idx ) + for (int i = translations.size(); i < idx; i++) + translations.push_back (""); + +// if (idx <= (int)translations.size()) + translations[idx-1] = expr.stripWhiteSpace(); +} + + +QString kvoctrainExpr::gradeStr (int idx, bool rev_grade) const +{ + QString s; + s.setNum(getGrade(idx, rev_grade)); + return s; +} + + +grade_t kvoctrainExpr::getGrade (int idx, bool rev_grade) const +{ + if (rev_grade) { + if (idx >= (int)rev_grades.size() || idx < 1 ) { + return KV_NORM_GRADE; + } + else if (rev_grades[idx] > KV_MAX_GRADE) { + return KV_MAX_GRADE; + } + + return rev_grades[idx]; + + } + else { + if (idx >= (int)grades.size() || idx < 1 ) { + return KV_NORM_GRADE; + } + else if (grades[idx] > KV_MAX_GRADE) { + return KV_MAX_GRADE; + } + + return grades[idx]; + } +} + + +void kvoctrainExpr::setGrade (int idx, grade_t grade, bool rev_grade) +{ + if (idx < 1) return; + + if (grade > KV_MAX_GRADE) + grade = KV_MAX_GRADE; + if (grade < KV_MIN_GRADE) + grade = KV_MIN_GRADE; + + if (rev_grade) { + // extend rev grades with standard grade if necessary + if ((int)rev_grades.size() <= idx ) + for (int i = rev_grades.size(); i <= idx; i++) { + rev_grades.push_back (KV_NORM_GRADE); + } + rev_grades[idx] = grade; + } + else { + // extend grades with standard grade if necessary + if ((int)grades.size() <= idx ) + for (int i = grades.size(); i <= idx; i++) { + grades.push_back (KV_NORM_GRADE); + } + grades[idx] = grade; + } +} + + +void kvoctrainExpr::incGrade (int idx, bool rev_grade) +{ + if (idx < 1) return; + + if (rev_grade) { + // extend rev grades with standard grade if necessary + if ((int)rev_grades.size() <= idx ) + for (int i = rev_grades.size(); i <= idx; i++) { + rev_grades.push_back (KV_NORM_GRADE); + } + if (rev_grades[idx] < KV_MAX_GRADE) + rev_grades[idx]++; + } + else { + // extend grades with standard grade if necessary + if ((int)grades.size() <= idx ) + for (int i = grades.size(); i <= idx; i++) { + grades.push_back (KV_NORM_GRADE); + } + if (grades[idx] < KV_MAX_GRADE) + grades[idx]++; + } +} + + +void kvoctrainExpr::decGrade (int idx, bool rev_grade) +{ + if (idx < 1) return; + + if (rev_grade) { + // extend rev grades with standard grade if necessary + if ((int)rev_grades.size() <= idx ) + for (int i = rev_grades.size(); i <= idx; i++) { + rev_grades.push_back (KV_NORM_GRADE); + } + if (rev_grades[idx] > KV_MIN_GRADE) + rev_grades[idx]--; + } + else { + // extend grades with standard grade if necessary + if ((int)grades.size() <= idx ) + for (int i = grades.size(); i <= idx; i++) { + grades.push_back (KV_NORM_GRADE); + } + if (grades[idx] > KV_MIN_GRADE) + grades[idx]--; + } +} + + +count_t kvoctrainExpr::getQueryCount (int idx, bool rev_count) const +{ + if (rev_count) { + if (idx >= (int)rev_qcounts.size() || idx < 1 ) { + return 0; + } + + return rev_qcounts[idx]; + } + + if (idx >= (int)qcounts.size() || idx < 1 ) { + return 0; + } + + return qcounts[idx]; +} + + +void kvoctrainExpr::setQueryCount (int idx, count_t count, bool rev_count) +{ + if (idx < 1) return; + + if (rev_count) { + // extend rev counts with 0 if necessary + if ((int)rev_qcounts.size() <= idx ) + for (int i = rev_qcounts.size(); i <= idx; i++) { + rev_qcounts.push_back (0); + } + + rev_qcounts[idx] = count; + + } + else { + // extend counts with 0 if necessary + if ((int)qcounts.size() <= idx ) + for (int i = qcounts.size(); i <= idx; i++) { + qcounts.push_back (0); + } + qcounts[idx] = count; + } +} + + +count_t kvoctrainExpr::getBadCount (int idx, bool rev_count) const +{ + if (rev_count) { + if (idx >= (int)rev_bcounts.size() || idx < 1 ) { + return 0; + } + + return rev_bcounts[idx]; + } + + if (idx >= (int)bcounts.size() || idx < 1 ) { + return 0; + } + + return bcounts[idx]; +} + + +void kvoctrainExpr::setBadCount (int idx, count_t count, bool rev_count) +{ + if (idx < 1) return; + + if (rev_count) { + // extend rev counts with 0 if necessary + if ((int)rev_bcounts.size() <= idx ) + for (int i = rev_bcounts.size(); i <= idx; i++) { + rev_bcounts.push_back (0); + } + + rev_bcounts[idx] = count; + + } + else { + // extend counts with 0 if necessary + if ((int)bcounts.size() <= idx ) + for (int i = bcounts.size(); i <= idx; i++) { + bcounts.push_back (0); + } + bcounts[idx] = count; + } +} + + +time_t kvoctrainExpr::getQueryDate (int idx, bool rev_date) const +{ + if (rev_date) { + if (idx >= (int)rev_qdates.size() || idx < 1 ) { + return 0; + } + + return rev_qdates[idx]; + } + + if (idx >= (int)qdates.size() || idx < 1 ) { + return 0; + } + + return qdates[idx]; +} + + +void kvoctrainExpr::setQueryDate (int idx, time_t date, bool rev_date) +{ + if (idx < 1) return; + + if (rev_date) { + // extend rev dates with 0 if necessary + if ((int)rev_qdates.size() <= idx ) + for (int i = rev_qdates.size(); i <= idx; i++) { + rev_qdates.push_back (0); + } + + rev_qdates[idx] = date; + + } + else { + // extend dates with 0 if necessary + if ((int)qdates.size() <= idx ) + for (int i = qdates.size(); i <= idx; i++) { + qdates.push_back (0); + } + qdates[idx] = date; + } +} + + +bool kvoctrainExpr::uniqueType () const +{ + bool unique = true; + QString type0 = getType(0); + for (int i = 1; i < numTranslations(); i++) + if (type0 != getType(i) ) + unique = false; + return unique; +} + + +QString kvoctrainExpr::getType (int idx) const +{ + if (idx >= (int)exprtypes.size() || idx < 0) { + return ""; + } + else { + return exprtypes[idx]; + } +} + + +int kvoctrainExpr::getLesson () const +{ + return lesson; +} + +void kvoctrainExpr::incQueryCount (int index, bool rev_count) +{ + setQueryCount (index, getQueryCount(index, rev_count)+1, rev_count); +} + + +void kvoctrainExpr::incBadCount (int index, bool rev_count) +{ + setBadCount (index, getBadCount(index, rev_count)+1, rev_count); +} + + +void kvoctrainExpr::setOriginal ( const QString & expr) +{ + origin = expr; +} + + +QString kvoctrainExpr::getOriginal () const +{ + return origin; +} + + +void kvoctrainExpr::setLesson (int l) +{ + lesson = l; +} + + +void kvoctrainExpr::setType (int idx, const QString &type) +{ + if ( idx < 0) return; + + // extend types with empty strings if necessary + if ((int)exprtypes.size() <= idx ) + for (int i = exprtypes.size(); i < idx+1; i++) + exprtypes.push_back (""); + + exprtypes[idx] = type.stripWhiteSpace(); +} + diff --git a/kvoctrain/kvoctrain/kvt-core/kvoctrainexpr.h b/kvoctrain/kvoctrain/kvt-core/kvoctrainexpr.h new file mode 100644 index 00000000..ecdefa4d --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvoctrainexpr.h @@ -0,0 +1,465 @@ +/*************************************************************************** + + maintain a kvoctrain expression + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 KVOCTRAINEXPR_H +#define KVOCTRAINEXPR_H + +#include <klocale.h> + +#define KV_MAX_GRADE 7 +#define KV_MIN_GRADE 0 + +#define KV_NORM_GRADE 0 // not queried yet +#define KV_NORM_COLOR Qt::black +static const char *KV_NORM_TEXT = I18N_NOOP("Not Queried Yet"); + +#define KV_LEV1_GRADE 1 +static const char *KV_LEV1_TEXT = I18N_NOOP("Level 1"); + +#define KV_LEV2_GRADE 2 +static const char *KV_LEV2_TEXT = I18N_NOOP("Level 2"); + +#define KV_LEV3_GRADE 3 +static const char *KV_LEV3_TEXT = I18N_NOOP("Level 3"); + +#define KV_LEV4_GRADE 4 +static const char *KV_LEV4_TEXT = I18N_NOOP("Level 4"); + +#define KV_LEV5_GRADE 5 +static const char *KV_LEV5_TEXT = I18N_NOOP("Level 5"); + +#define KV_LEV6_GRADE 6 +static const char *KV_LEV6_TEXT = I18N_NOOP("Level 6"); + +#define KV_LEV7_GRADE 7 +static const char *KV_LEV7_TEXT = I18N_NOOP("Level 7"); + +#include <time.h> +#include <vector> +using namespace std; + +#include "grammarmanager.h" +#include "MultipleChoice.h" + +typedef signed char grade_t; +typedef unsigned short count_t; + +/*************************************************************** + * This class contains one expression as original or in one + * translations + **************************************************************/ + +class kvoctrainExpr +{ + public: + + /** default constructor for an expression in different languages + */ + ~kvoctrainExpr (); + + kvoctrainExpr (); + + kvoctrainExpr (QString &s, QString separator, int lesson = 0); + + /** Constructor for an expression in different languages + * + * @param expr expression + */ + kvoctrainExpr (QString &expr, int lesson = 0); + + /** adds a new translation of this entry + * @param expr translation + * @param grade grade of knowledge of this translation + * @param rev_grade dito, in opposite direction + */ + void addTranslation (QString expr, grade_t grade=KV_NORM_GRADE, + grade_t rev_grade=KV_NORM_GRADE); + + /** removes translation + * + * @param index number of translation 1..x + */ + void removeTranslation (int index); + + /** returns index of lesson (0 = none) + */ + int getLesson () const; + + /** sets index of lesson (0 = none) + */ + void setLesson (int l); + + /** returns original expression of this entry + */ + QString getOriginal () const; + + /** sets original expression of this entry + */ + void setOriginal (const QString & expr); + + /** returns number of max. translations of all expressions + */ + int numTranslations() const; + + /** returns flag if entry is "selected" for queries + */ + bool isInQuery() const {return inquery; } + + /** set entry "selected" + */ + void setInQuery(bool flag = true) { inquery = flag; } + + /** returns flag if entry is activated for queries + */ + bool isActive() const {return active; } + + /** set entry active (enabled for queries) + */ + void setActive(bool flag = true) { active = flag; } + + /** returns translation of this expression + * + * @param index number of translation + * @result expression or "" if no translation available + */ + QString getTranslation (int index) const; + + /** sets translation of this expression + * + * @param index number of translation + * @param expr expression of this index + */ + void setTranslation (int index, const QString & expr); + + /** sets remark of this expression + * + * @param index index of expression + * @param expr remark of this index + */ + void setPronunce (int index, const QString & expr); + + /** returns pronunciation of this expression + * + * @param index index of expression + * @result pronunciation or "" if none available + */ + QString getPronunce (int index) const; + + /** returns remarks of this expression + * + * @param index index of expression + * @result remark or "" if no remark available + */ + QString getRemark (int index) const; + + /** sets remark of this expression + * + * @param index index of expression + * @param expr remark of this index + */ + void setRemark (int index, const QString & expr); + + + /** sets false friend of this expression + * + * @param index index of expression + * @param expr false friend of this index + * @param rev_grade dito, in opposite direction + */ + void setFauxAmi (int index, const QString & expr, bool rev_ami = false); + + + /** returns false friend of this expression + * + * @param index index of expression + * @param rev_grade dito, in opposite direction + * @result false friend or "" if no string available + */ + QString getFauxAmi (int index, bool rev_ami = false) const; + + /** sets synonym this expression + * + * @param index index of expression + * @param expr synonym of this index + */ + void setSynonym (int index, const QString & expr); + + + /** returns synonym of this expression + * + * @param index index of expression + * @result synonym or "" if no string available + */ + QString getSynonym (int index) const; + + /** sets example this expression + * + * @param index index of expression + * @param expr example of this index + */ + void setExample (int index, const QString & expr); + + + /** returns example of this expression + * + * @param index index of expression + * @result example or "" if no string available + */ + QString getExample (int index) const; + + /** sets usage label this expression + * + * @param index index of expression + * @param usage usage label of this index + */ + void setUsageLabel (int index, const QString & usage); + + + /** returns usage label of this expression + * + * @param index index of expression + * @result usage or "" if no string available + */ + QString getUsageLabel (int index) const; + + /** sets paraphrase of this expression + * + * @param index index of expression + * @param usage paraphrase of this index + */ + void setParaphrase (int index, const QString & usage); + + + /** returns paraphrase of this expression + * + * @param index index of expression + * @result paraphrase or "" if no string available + */ + QString getParaphrase (int index) const; + + /** sets antonym this expression + * + * @param index index of expression + * @param expr antonym of this index + */ + void setAntonym (int index, const QString & expr); + + + /** returns antonym of this expression + * + * @param index index of expression + * @result antonym or "" if no string available + */ + QString getAntonym (int index) const; + + /** returns type of this expression + * + * @result type or "" if no type available + */ + QString getType (int index) const; + + /** all langs have same type ? + * + * @result true if all have same type + */ + bool uniqueType () const; + + /** sets type of this expression + * + * @param index index of type + * @param type type of this expression ("" = none) + */ + void setType (int index, const QString &type); + + /** returns grade of given translation as string + * + * @param index index of expression + * @param rev_grade dito, in opposite direction + * @result number of knowlegde: 0=known, x=numbers not knows + */ + QString gradeStr (int index, bool rev_grade = false) const; + + /** sets grade of given translation + * + * @param index index of translation + * @param grade number of knowlegde: 0=known, x=numbers not knows + */ + void setGrade (int index, grade_t grade, bool rev_grade = false); + + /** returns grade of given translation as int + * + * @param index index of translation + * @param rev_grade dito, in opposite direction + * @result number of knowlegde: 0=known, x=numbers not knows + */ + grade_t getGrade (int index, bool rev_grade = false) const; + + /** increments grade of given translation + * + * @param index index of translation + * @param rev_grade dito, in opposite direction + */ + void incGrade (int index, bool rev_grade = false); + + /** decrements grade of given translation + * + * @param index index of translation + * @param rev_grade dito, in opposite direction + */ + void decGrade (int index, bool rev_grade = false); + + /** returns last query date of given translation as int + * + * @param index index of translation + * @param rev_date dito, in opposite direction + */ + time_t getQueryDate (int index, bool rev_date = false) const; + + /** set last query date of given translation as int + * + * @param index index of translation + * @param rev_date dito, in opposite direction + */ + void setQueryDate (int index, time_t date, bool rev_date = false); + + /** returns conjugations if available + * + * @param index index of translation + */ + Conjugation getConjugation(int index) const; + + /** sets conjugations + * + * @param index index of translation + * @param con conjugation block + */ + void setConjugation(int index, const Conjugation &con); + + /** returns comparison if available + * + * @param index index of translation + */ + Comparison getComparison(int index) const; + + /** sets comparison + * + * @param index index of translation + * @param con comparison block + */ + void setComparison(int index, const Comparison &comp); + + /** returns multiple choice if available + * + * @param index index of multiple choice + */ + MultipleChoice getMultipleChoice(int index) const; + + /** sets multiple choice + * + * @param index index of translation + * @param con multiple choice block + */ + void setMultipleChoice(int index, const MultipleChoice &mc); + + /** returns query count of given translation as int + * + * @param index index of translation + * @param rev_count dito, in opposite direction + */ + count_t getQueryCount (int index, bool rev_count = false) const; + + /** set query count of given translation as int + * + * @param index index of translation + * @param rev_count dito, in opposite direction + */ + void setQueryCount (int index, count_t count, bool rev_count = false); + + /** returns bad query count of given translation as int + * + * @param index index of translation + * @param rev_count dito, in opposite direction + */ + count_t getBadCount (int index, bool rev_count = false) const; + + /** set bad query count of given translation as int + * + * @param index index of translation + * @param rev_count dito, in opposite direction + */ + void setBadCount (int index, count_t count, bool rev_count = false); + + /** increment bad query count of given translation by 1 + * + * @param index index of translation + * @param rev_count dito, in opposite direction + */ + void incBadCount (int index, bool rev_count = false); + + /** increment query count of given translation by 1 + * + * @param index index of translation + * @param rev_count dito, in opposite direction + */ + void incQueryCount (int index, bool rev_count = false); + + protected: + + void Init(); + + private: + QString origin; + + // all these vectors must be deleted in removeTranslation() + vector<QString> exprtypes; + vector<QString> translations; + vector<QString> remarks; + vector<QString> usageLabels; + vector<QString> paraphrases; + vector<QString> fauxAmi; + vector<QString> rev_fauxAmi; + vector<QString> synonym; + vector<QString> example; + vector<QString> antonym; + vector<QString> pronunces; + vector<grade_t> grades; + vector<grade_t> rev_grades; + vector<count_t> qcounts; + vector<count_t> rev_qcounts; + vector<count_t> bcounts; + vector<count_t> rev_bcounts; + vector<time_t> qdates; + vector<time_t> rev_qdates; + vector<Conjugation> conjugations; + vector<Comparison> comparisons; + vector<MultipleChoice> mcs; + + int lesson; + bool inquery; + bool active; +}; + +#endif // KVOCTRAINEXPR_H + diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/Makefile.am b/kvoctrain/kvoctrain/kvt-core/kvt-xml/Makefile.am new file mode 100644 index 00000000..f44e9fea --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/Makefile.am @@ -0,0 +1,10 @@ +INCLUDES = -I$(top_srcdir)/kvoctrain \ + -I$(top_srcdir)/kvoctrain/kvoctrain \ + $(all_includes) + +noinst_LTLIBRARIES = libkvtxml.la + +libkvtxml_la_SOURCES = XmlReader.cpp XmlTokenizer.cpp XmlElement.cpp XmlWriter.cpp + +# CLEANFILES += *~ # This breaks badly with automake 1.5 + diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlElement.cpp b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlElement.cpp new file mode 100644 index 00000000..7b070c4f --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlElement.cpp @@ -0,0 +1,99 @@ +/* -*- C++ -*- + + This file is part of KIllustrator. + Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de) + + modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April 99 + + ----------------------------------------------------------------------- + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library 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 Library 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. + +*/ + +#include <stdlib.h> +#include "XmlElement.h" + +XmlAttribute::XmlAttribute (const KOXML_STRING& n, const KOXML_STRING& v) : + aname (n), value (v) { +} + + +XmlAttribute::XmlAttribute (const XmlAttribute& attr) : + aname (attr.aname), value (attr.value) { +} + +XmlAttribute::~XmlAttribute () { +} + + +XmlAttribute& XmlAttribute::operator= (const XmlAttribute& attr) { + aname = attr.aname; + value = attr.value; + return *this; +} + + +float XmlAttribute::floatValue () const { +#ifndef KOXML_USE_STL + return atof (value.local8Bit()); +#else + return atof (value.data()); +#endif +} + + +int XmlAttribute::intValue () const { +#ifndef KOXML_USE_STL + return atoi (value.local8Bit()); +#else + return atoi (value.data()); +#endif +} + + +XmlElement::XmlElement () { + closed = false; + endTag = false; +} + + +XmlElement::XmlElement (const XmlElement& elem) : + tagId (elem.tagId), closed (elem.closed), endTag (elem.endTag), + attribs (elem.attribs) { +} + + +XmlElement::~XmlElement () { +} + + +void XmlElement::reset () { + tagId = ""; + closed = false; + endTag = false; + attribs.erase (attribs.begin (), attribs.end ()); +} + + +XmlElement& XmlElement::operator= (const XmlElement& elem) { + tagId = elem.tagId; + closed = elem.closed; + endTag = elem.endTag; + attribs = elem.attribs; + return *this; +} + diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlElement.h b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlElement.h new file mode 100644 index 00000000..50bb8e42 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlElement.h @@ -0,0 +1,156 @@ +/* -*- C++ -*- + + This file is part of KIllustrator. + Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de) + + modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April 99 + +*/ + +#ifndef XmlElement_h_ +#define XmlElement_h_ + +#include "koxml_config.h" +#include <list> + +/** + * An instance of XmlAttribute represents an attribute of + * XML elements. It provides methods for accessing the attribute + * value. + * + * @short A class for representing attributes of XML elements. + * @author Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de), modifications: Ewald Arnold (kvoctrain@ewald-arnold.de) + * @version 2000/07/02 + */ +class XmlAttribute { +public: + /** + * Construct an attribute from the given name and value. + * + * @param n The name of the attribute. + * @param v The attribute value. + */ + XmlAttribute (const KOXML_STRING& n, const KOXML_STRING& v); + + /** + * Copy constructor. + */ + XmlAttribute (const XmlAttribute& attr); + + /** + * Destructor. + */ + ~XmlAttribute (); + + /** + * The assignment operator. + */ + XmlAttribute& operator= (const XmlAttribute& attr); + + /** + * Return the name of the attribute. + * + * @return The attribute name. + */ + inline const KOXML_STRING& name () const { return aname; } + + /** + * Return a string representation of the attribute value. + * + * @return The attribute value as string. + */ + inline const KOXML_STRING& stringValue () const { return value; } + + /** + * Return a float representation of the attribute value. + * + * @return The attribute value as float. + */ + float floatValue () const; + + /** + * Return a integer representation of the attribute value. + * + * @return The attribute value as integer. + */ + int intValue () const; + +private: + KOXML_STRING aname, value; +}; + +/** + * An instance of XmlElement represents an element (object) of a XML + * document. The elements consists of the tag (element ID) and a list + * of attributes. + * + * @short A class for representing XML elements. + * @author Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de), modifications: Ewald Arnold (kvoctrain@ewald-arnold.de) + * @version 2000/07/02 + */ +class XmlElement { +friend class XmlReader; +public: + /** + * Construct a new XML element. + */ + XmlElement (); + + /** + * Copy constructor. + */ + XmlElement (const XmlElement& elem); + + /** + * Destructor. + */ + ~XmlElement (); + + void reset (); + + /** + * The assignment operator. + */ + XmlElement& operator= (const XmlElement& elem); + + /** + * Return the ID of the element. + * + * @return The element ID. + */ + inline const KOXML_STRING& tag () const { return tagId; } + + /** + * Return the attributes of the element. + * @see XmlAttribute + * + * @return The list of attributes. + */ + inline const std::list<XmlAttribute>& attributes () const { return attribs; } + + /** + * Return @p true if the element is closed. + * + * @return @p true for a closed element. + */ + inline bool isClosed () const { return closed; } + + /** + * Return @p true if the element is an end tag. + * + * @return @p true for an end tag. + */ + inline bool isEndTag () const { return endTag; } + +private: + KOXML_STRING tagId; + bool closed; + bool endTag; + std::list<XmlAttribute> attribs; +}; + +#endif + + + + diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlReader.cpp b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlReader.cpp new file mode 100644 index 00000000..819d79a6 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlReader.cpp @@ -0,0 +1,264 @@ +/* -*- C++ -*- + + This file is part of KIllustrator. + Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de) + + modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April 99 + + ----------------------------------------------------------------------- + + ----------------------------------------------------------------------- + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library 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 Library 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. + +*/ + +#include <iostream> +using namespace std; +#include "XmlReader.h" + +XmlReader::XmlReader (KOXML_ISTREAM& is) + : tokenizer (is) +{ +} + +XmlReader::~XmlReader () { +} + +bool XmlReader::validHeader () { + // Check for: <? xml version="1.0" ?> + if (tokenizer.nextToken () != XmlTokenizer::Tok_Lt) + return false; + if (tokenizer.nextToken () != XmlTokenizer::Tok_QSign) + return false; + + if (tokenizer.nextToken () != XmlTokenizer::Tok_Symbol) + return false; + else if (tokenizer.element () != "xml") + return false; + + if (tokenizer.nextToken () != XmlTokenizer::Tok_Symbol) + return false; + else if (tokenizer.element () != "version") + return false; + if (tokenizer.nextToken () != XmlTokenizer::Tok_Eq) + return false; + if (tokenizer.nextToken () != XmlTokenizer::Tok_String) + return false; + else if (tokenizer.element () != "1.0") + return false; + + if (tokenizer.nextToken () != XmlTokenizer::Tok_QSign) + return false; + if (tokenizer.nextToken () != XmlTokenizer::Tok_Gt) + return false; + + // Check for: <(!)doctype symbol system string> + + if (tokenizer.nextToken () != XmlTokenizer::Tok_Lt) + return false; + + XmlTokenizer::Token token = tokenizer.nextToken (); + if (token == XmlTokenizer::Tok_Exclam) + token = tokenizer.nextToken (); + + if (token != XmlTokenizer::Tok_Symbol) + return false; + else if (tokenizer.element().lower() != "doctype") + return false; + + if (tokenizer.nextToken () != XmlTokenizer::Tok_Symbol) + return false; + s_dtype = tokenizer.element (); + + if (tokenizer.nextToken () != XmlTokenizer::Tok_Symbol) + return false; + else if (tokenizer.element().lower() != "system") + return false; + + if (tokenizer.nextToken () != XmlTokenizer::Tok_String) + return false; + s_dtd = tokenizer.element (); + + if (tokenizer.nextToken () != XmlTokenizer::Tok_Gt) + return false; + + return true; +} + +const KOXML_STRING& XmlReader::doctype () const { + return s_dtype; +} + +const KOXML_STRING& XmlReader::dtd () const { + return s_dtd; +} + +const KOXML_STRING& XmlReader::getText () { + return text; +} + +bool XmlReader::readElement (XmlElement& elem) { + XmlTokenizer::Token tok; + bool result = false; + bool ready = false; + + elem.reset (); + + while (! ready) { + tok = tokenizer.nextToken (); + if (tok == XmlTokenizer::Tok_Lt) { + tok = tokenizer.nextToken (); + if (tok == XmlTokenizer::Tok_Comment) { + // skip comment + } + else { + if (tok == XmlTokenizer::Tok_Slash) + result = parseEndElement (elem); + else if (tok == XmlTokenizer::Tok_Symbol) + result = parseElement (tokenizer.element (), elem); + else if (tok == XmlTokenizer::Tok_EOF) + result = false; + ready = true; + } + } + else if (tok == XmlTokenizer::Tok_Text) { + elem.tagId = "#PCDATA"; + text = tokenizer.element (); + result = true; + ready = true; + } + else + return false; + } + return result; +} + +bool XmlReader::parseEndElement (XmlElement& elem) { + bool result = false; + + XmlTokenizer::Token tok = tokenizer.nextToken (); + if (tok == XmlTokenizer::Tok_Symbol) { + KOXML_STRING tag = tokenizer.element (); + tok = tokenizer.nextToken (); + if (tok == XmlTokenizer::Tok_Gt) { + elem.tagId = tag; + elem.endTag = true; + elem.closed = true; + result = true; + } + } + return result; +} + +bool XmlReader::parseElement (const KOXML_STRING& id, XmlElement& elem) { + KOXML_STRING tag = id; + bool closed = false; + std::list<XmlAttribute> attrib_list; + + XmlTokenizer::Token tok = tokenizer.nextToken (); + while (tok != XmlTokenizer::Tok_Gt) { + if (tok == XmlTokenizer::Tok_Slash) { + if (closed) + return false; + else + closed = true; + } + else if (tok == XmlTokenizer::Tok_Symbol) { + if (! attrib_list.empty () || closed) + return false; + tokenizer.unget (); + if (! readAttributes (attrib_list)) + return false; + } + else + return false; + + tok = tokenizer.nextToken (); + } + elem.tagId = tag; + elem.endTag = false; + elem.closed = closed; + elem.attribs = attrib_list; + return true; +} + +bool XmlReader::readAttributes (std::list<XmlAttribute>& attrib_list) { + XmlTokenizer::Token tok = tokenizer.nextToken (); + + while (tok != XmlTokenizer::Tok_Gt) { + if (tok == XmlTokenizer::Tok_Symbol) { + KOXML_STRING id = tokenizer.element (); + if (tokenizer.nextToken () == XmlTokenizer::Tok_Eq) { + if (tokenizer.nextToken () == XmlTokenizer::Tok_String) { + + // un-escape dangerous characters in reverted order + KOXML_STRING val = tokenizer.element(); + int pos = 0; + while ((pos = val.find(""", pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos, 6); + KOXML_STRING_INSERT( val, pos, "\""); + pos += 1; // skip " + } + pos = 0; + while ((pos = val.find("&lf;", pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos, 4); + KOXML_STRING_INSERT( val, pos, "\r"); + pos += 1; // skip \r + } + pos = 0; + while ((pos = val.find("&nl;", pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos, 4); + KOXML_STRING_INSERT( val, pos, "\n"); + pos += 1; // skip \n + } + pos = 0; + while ((pos = val.find("<", pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos, 4); + KOXML_STRING_INSERT( val, pos, "<"); + pos += 1; // skip < + } + pos = 0; + while ((pos = val.find ("&", pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos+1, 4); + pos += 1; // skip & + } + + XmlAttribute attrib (id, val); + attrib_list.push_back (attrib); + } + else { + cerr << "invalid attribute value" << endl; + return false; + } + } + else { + cerr << "missing '='" << endl; + return false; + } + } + else if (tok == XmlTokenizer::Tok_Slash) { + break; + } + else { + cerr << "invalid attribute name: " << (int) tok << endl; + return false; + } + tok = tokenizer.nextToken (); + } + tokenizer.unget (); + return true; +} diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlReader.h b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlReader.h new file mode 100644 index 00000000..0c7904af --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlReader.h @@ -0,0 +1,104 @@ +/* -*- C++ -*- + + This file is part of KIllustrator. + Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de) + + modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April 99 +*/ + +#ifndef XmlReader_h_ +#define XmlReader_h_ + +#include "XmlElement.h" +#include "XmlTokenizer.h" + +class KOXML_ISTREAM; + +/** + * The XMLReader class supports reading elements from a XML stream. + * + * @short A class for reading XML elements from a stream. + * @author Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de), modifications: Ewald Arnold (kvoctrain@ewald-arnold.de) + * @version 2000/07/02 + */ +class XmlReader { +public: + /** + * Construct a XmlReader instance for the given input stream. + * + * @param is The open input stream. + */ + XmlReader (KOXML_ISTREAM& is); + + /** + * Desctructor + */ + ~XmlReader (); + + /** + * Check the input stream for a valid XML header. + * A header should look like + * <pre> + * <?xml version="1.0"?> + * <!doctype dtype system dtd> + * </pre> + * where @p dtype and @p dtd are simple strings. + * + * @return @p true if the header conforms to XML, otherwise + * @p false. + */ + bool validHeader (); + + /** + * Return the document type. + * + * @return The name of the document type. + */ + const KOXML_STRING& doctype () const; + + /** + * Return the name of the document type definition. + * + * @return The name of the DTD. + */ + const KOXML_STRING& dtd () const; + + /** + * Read a XML element from the stream. If the content is plain text + * (no tag), an element with the pseudo ID @p #PCDATA is returned + * and the text is available via method getText. + * + * @see #getText + * + * @param elem The XML element which is initialized by the method. + * @return @p true for successful reading. + */ + bool readElement (XmlElement& elem); + + /** + * Read plain text from the stream. + * + * @return The text as a string. + */ + const KOXML_STRING& getText (); + + /** + * Returns current line number + * + * @return The current line number + */ + inline int lineNumber() { return tokenizer.lineNumber(); } + +protected: + bool parseEndElement (XmlElement& elem); + bool parseElement (const KOXML_STRING& id, XmlElement& elem); + bool readAttributes (std::list<XmlAttribute>& attrib_list); + +private: + XmlTokenizer tokenizer; + KOXML_STRING s_dtype, + s_dtd; + KOXML_STRING text; +}; + +#endif diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlTokenizer.cpp b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlTokenizer.cpp new file mode 100644 index 00000000..b2fde685 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlTokenizer.cpp @@ -0,0 +1,411 @@ +/* -*- C++ -*- + + This file is part of KIllustrator. + Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de) + + modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April 99 + + ----------------------------------------------------------------------- + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library 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 Library 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. +*/ + +#include "XmlTokenizer.h" +#include <ctype.h> + +XmlTokenizer::XmlTokenizer (KOXML_ISTREAM& is) : + last_chars (""), istrm (is), use_last (false), is_open (false), lineno(1) { +} + +XmlTokenizer::~XmlTokenizer () { +} + + +/* +bool XmlTokenizer::hasMoreTokens () { + return ! istrm.eof (); +} +*/ + +void XmlTokenizer::skipWhitespace () { + KOXML_CHAR c; + do { + c = readchar (); + if (c == '\n') + lineno++; + if (! isspace (c)) { + putback (c); + return; + } + else if (istrm.eof ()) + return; + } while (1); +} + + +void XmlTokenizer::putback (KOXML_CHAR c) { + last_chars += c; +} + + +KOXML_CHAR XmlTokenizer::readchar () { + + KOXML_CHAR c; + + if (last_chars.length() > 0) { + c = last_chars[0]; + KOXML_STRING_REMOVE (last_chars, 0, 1); + } + else { + +# ifndef KOXML_USE_STL + istrm >> c; +# else + istrm.get(c); +# endif + } + + return c; +} + + +void XmlTokenizer::unget () { + use_last = true; +} + +XmlTokenizer::Token XmlTokenizer::nextToken () { + KOXML_CHAR c; + + if (use_last) { + use_last = false; + return last_tok; + } + + skipWhitespace (); + if (istrm.eof ()) + return last_tok = Tok_EOF; + + c = readchar (); + if (c == '\n') + lineno++; + + if (!is_open) { + if (c != '<') { + putback (c); + return last_tok = readText (); + } + } + switch (c) { + case '<': + is_open = true; + return last_tok = Tok_Lt; + break; + case '>': + is_open = false; + return last_tok = Tok_Gt; + break; + case '?': + return last_tok = Tok_QSign; + break; + case '/': + return last_tok = Tok_Slash; + break; + case '=': + return last_tok = Tok_Eq; + break; + case '(': + return last_tok = Tok_LParen; + break; + case ')': + return last_tok = Tok_RParen; + break; + case '[': + return last_tok = Tok_LBracket; + break; + case ']': + return last_tok = Tok_RBracket; + break; + case '|': + return last_tok = Tok_Bar; + break; + case '*': + return last_tok = Tok_Asterisk; + break; + case '+': + return last_tok = Tok_Plus; + break; + case ',': + return last_tok = Tok_Comma; + break; + case ';': + return last_tok = Tok_Semicolon; + break; + case '%': + return last_tok = Tok_Percent; + break; + case '#': + return last_tok = Tok_NSign; + break; + case '\'': + return last_tok = Tok_Apostr; + break; + case '"': + // String einlesen + return last_tok = readString (); + break; + default: + if (is_open) { + if (isalpha (c) || isdigit (c)) { + // Symbol (Element oder Attributbezeichner) + putback (c); + return last_tok = readSymbol (); + } + else if (c == '!') { + c = readchar (); + if (c == '\n') + lineno++; + putback (c); + if (c == '-') + return last_tok = readComment (); + else + return last_tok = Tok_Exclam; + } + else { + return last_tok = Tok_Invalid; + } + } + else { + putback (c); + return last_tok = readText (); + } + break; + } +} + + +const KOXML_STRING& XmlTokenizer::element () { + return elem; +} + + +XmlTokenizer::Token XmlTokenizer::readSymbol () { + KOXML_CHAR c; + elem = ""; + + while (1) { + c = readchar (); + if (c == '\n') + lineno++; + if (istrm.eof () || isspace (c)) + // Symbol ist abgeschlossen + break; + else if (c == '=' || c == '/' || c == '>' || c == '?' || c == '|' || + c == ')' || c == '\'' || c == ',' || c == ';') { + // Symbol ist abgeschlossen, das gelesene Zeichen wird + // aber noch benoetigt + putback (c); + break; + } + else if (isalnum (c) || c == '-' || (c == '_' && elem.length () > 0)) + // korrektes Zeichen -> anhaengen +// elem += tolower (c); ????????? + elem += c; + else { + // Zeichen nicht erlaubt ? + return Tok_Invalid; + } + } + // alle Grossbuchstaben in Kleinbuchstaben aendern !!!! + return Tok_Symbol; +} + + +XmlTokenizer::Token XmlTokenizer::readString () { + KOXML_CHAR c; + elem = ""; + + while (1) { + c = readchar (); + if (c == '\n') + lineno++; + + if (istrm.eof ()) + // String ist noch nicht abgeschlossen + return Tok_Invalid; + else if (c == '\\') { + // naechstes Zeichen quoten + } + else if (c == '"') { + // String ist abgeschlossen + return Tok_String; + } + else + elem += c; + } +} + +XmlTokenizer::Token XmlTokenizer::readComment () { + KOXML_CHAR c1, c2; + elem = ""; + + c1 = readchar (); + if (c1 == '\n') + lineno++; + c2 = readchar (); + if (c2 == '\n') + lineno++; + + if (c1 != '-' || c2 != '-' || istrm.eof ()) + return Tok_Invalid; + + while (1) { + c1 = readchar (); + if (istrm.eof ()) + return Tok_Invalid; + else if (c1 == '\n') + lineno++; + else if (c1 == '>') + return Tok_Comment; + else + elem += c1; + } +} + +XmlTokenizer::Token XmlTokenizer::readText () { + KOXML_CHAR c; + elem = ""; + + while (1) { + c = readchar (); + if (c == '\n') + lineno++; + + if (istrm.eof ()) + return Tok_EOF; + else if (c == '<') { + putback (c); + return Tok_Text; + } + else if (c == '&') { + KOXML_STRING s; + while (c != ';') { + s += c; + c = readchar (); + if (c == '\n') + lineno++; + if (istrm.eof ()) + return Tok_EOF; + } + if (s == "<") + elem += "<"; + else if (s == ">") + elem += ">"; + else if (s == "&") + elem += "&"; + else if (s == "&lf") + elem += "\r"; + else if (s == "&nl") + elem += "\n"; +// entities ? +// elem += "[" + s +";]"; + } + else + elem += c; + } +} + +#ifdef TEST +int main (int argc, char** argv) { + XmlTokenizer::Token tok; + + XmlTokenizer tokenizer (cin); + + while ((tok = tokenizer.nextToken ()) != XmlTokenizer::Tok_EOF) { + switch (tok) { + case XmlTokenizer::Tok_Exclam: + cout << "! "; + break; + case XmlTokenizer::Tok_Bar: + cout << "| "; + break; + case XmlTokenizer::Tok_LParen: + cout << "( "; + break; + case XmlTokenizer::Tok_RParen: + cout << ") "; + break; + case XmlTokenizer::Tok_LBracket: + cout << "[ "; + break; + case XmlTokenizer::Tok_RBracket: + cout << "] "; + break; + case XmlTokenizer::Tok_Plus: + cout << "+ "; + break; + case XmlTokenizer::Tok_Asterisk: + cout << "* "; + break; + case XmlTokenizer::Tok_Comma: + cout << ", "; + break; + case XmlTokenizer::Tok_Semicolon: + cout << "; "; + break; + case XmlTokenizer::Tok_NSign: + cout << "# "; + break; + case XmlTokenizer::Tok_Apostr: + cout << "' "; + break; + case XmlTokenizer::Tok_Percent: + cout << "% "; + break; + case XmlTokenizer::Tok_Lt: + cout << "< "; + break; + case XmlTokenizer::Tok_Gt: + cout << "> "; + break; + case XmlTokenizer::Tok_QSign: + cout << "? "; + break; + case XmlTokenizer::Tok_Slash: + cout << "/ "; + break; + case XmlTokenizer::Tok_Eq: + cout << "= "; + break; + case XmlTokenizer::Tok_Symbol: + cout << "SYMBOL(" << tokenizer.element () << ") "; + break; + case XmlTokenizer::Tok_String: + cout << "STRING(" << tokenizer.element () << ") "; + break; + case XmlTokenizer::Tok_Comment: + cout << "COMMENT > "; + break; + case XmlTokenizer::Tok_Text: + cout << "TEXT(" << tokenizer.element () << ") "; + break; + default: + cout << "INVALID(" << tok << ")" << endl; + return 1; + break; + } + } +} +#endif diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlTokenizer.h b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlTokenizer.h new file mode 100644 index 00000000..d78b6c7e --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlTokenizer.h @@ -0,0 +1,108 @@ +/* -*- C++ -*- + + This file is part of KIllustrator. + Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de) + + modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April 99 + +*/ + +#ifndef XmlTokenizer_h_ +#define XmlTokenizer_h_ + +#include "koxml_config.h" + +/** + * The XMLTokenizer class allows an application to break a XML stream + * into tokens. + * + * @short A class for tokenizing an XML stream. + * @author Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de), modifications: Ewald Arnold (kvoctrain@ewald-arnold.de) + * @version 2000/07/02 + */ +class XmlTokenizer { +public: + /** + * The expected tokens for a XML stream. + */ + enum Token { Tok_Invalid, /* 0 */ + Tok_EOF, /* 1 */ + Tok_Symbol, /* 2 */ + Tok_String, /* 3 */ + Tok_Text, /* 4 */ + Tok_Comment, /* 5 */ + Tok_Lt, /* < 6 */ + Tok_Gt, /* > 7 */ + Tok_QSign, /* ? 8 */ + Tok_Eq, /* = 9 */ + Tok_Slash, /* / 10 */ + Tok_Exclam, /* ! 11 */ + Tok_Bar, /* | 12 */ + Tok_LParen, /* ( 13 */ + Tok_RParen, /* ) 14 */ + Tok_LBracket, /* [ 15 */ + Tok_RBracket, /* ] 16 */ + Tok_Plus, /* + 17 */ + Tok_Asterisk, /* * 18 */ + Tok_Comma, /* , 19 */ + Tok_Semicolon,/* ; 20 */ + Tok_NSign, /* # 21 */ + Tok_Apostr, /* ' 22 */ + Tok_Percent /* % 23 */ + }; + + /** + * Create a XmlTokenizer instance for the given input stream. + * + * @param is The open input stream for reading. + */ + XmlTokenizer (KOXML_ISTREAM& is); + + /** + * Destructor. + */ + ~XmlTokenizer (); + + /** + * Return the next token from the stream. + * @return The next token from the stream. + */ + Token nextToken (); + + /** + * Return the string representation of the current token. + * + * @return The string representation. + */ + const KOXML_STRING& element (); + + KOXML_CHAR readchar (); + void putback (KOXML_CHAR c); + + /** + * Cause the next call to method @p nextToken of this tokenizer + * to return the current token. + */ + void unget (); + + inline int lineNumber() { return lineno; } + +protected: + void skipWhitespace (); + Token readString (); + Token readSymbol (); + Token readText (); + Token readComment (); + +private: +// QIODevice *strm; + KOXML_STRING last_chars; + KOXML_ISTREAM &istrm; + KOXML_STRING elem; + Token last_tok; + bool use_last; + bool is_open; + int lineno; +}; + +#endif diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlWriter.cpp b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlWriter.cpp new file mode 100644 index 00000000..38dfdbf2 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlWriter.cpp @@ -0,0 +1,253 @@ +/* -*- C++ -*- + + This file is part of KIllustrator. + Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de) + + modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April 99 + + ----------------------------------------------------------------------- + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library 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 Library 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. +*/ + +#include "XmlWriter.h" + +XmlWriter::XmlWriter (KOXML_OSTREAM& os) + : strm (os) +{ + autoendl = true; + isapo = false; + apo = 0; + strm << "<?xml version=\"1.0\"?>" << endl; // "encoding=UTF8" +} + + +XmlWriter::~XmlWriter () { + flush (); +} + + +void XmlWriter::startTag (KOXML_STRING id, bool closeIt, bool empty, bool eol) +{ + if (!id) return; + + strm << "<" << id; + if (!empty) { + lastTags.push (id); + } + + if (closeIt) { + if (empty) + strm << "/"; + strm << ">"; + if (eol || autoendl) { + isapo = false; + apo = 0; + strm << endl; + } + } +} + + +void XmlWriter::endTag (KOXML_STRING id, bool eol) +{ + strm << "</"; + if (id.length() != 0) + strm << id; + else { + KOXML_STRING tag = lastTags.top (); + lastTags.pop (); + strm << tag; + } + strm << ">"; + if (eol || autoendl) { + isapo = false; + apo = 0; + strm << endl; + } +} + +void XmlWriter::closeTag (bool empty, bool eol) +{ + if (empty) { + strm << "/"; + lastTags.pop (); + } + strm << ">"; + if (eol || autoendl) { + isapo = false; + apo = 0; + strm << endl; + } +} + + +void XmlWriter::setAutoEndl (const bool flag) +{ + autoendl = flag; +} + + +void XmlWriter::endline() +{ + isapo = false; + apo = 0; + strm << endl; +} + + +void XmlWriter::addAttribute (KOXML_STRING name, const KOXML_STRING& value) +{ + if (!name) return; + + KOXML_STRING val = value; + // escape dangerous characters in sgml-style + int pos = 0; + while ((pos = val.find ('&', pos)) >= 0) { + KOXML_STRING_INSERT( val, pos+1, "amp;"); + pos += 5; // skip & + } + pos = 0; + while ((pos = val.find ('<', pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos, 1); + KOXML_STRING_INSERT( val, pos, "<"); + pos += 4; // skip &nl; + } + pos = 0; + while ((pos = val.find ('\n', pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos, 1); + KOXML_STRING_INSERT( val, pos, "&nl;"); + pos += 4; // skip &nl; + } + pos = 0; + while ((pos = val.find ('\r', pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos, 1); + KOXML_STRING_INSERT( val, pos+1, "lf;"); + pos += 4; // skip &lf; + } + pos = 0; + while ((pos = val.find ('\"', pos)) >= 0) { + KOXML_STRING_REMOVE( val, pos, 1); + KOXML_STRING_INSERT( val, pos, """); + pos += 6; // skip &qout; + } + + strm << " "; + strm << name << "=\""; + strm << val; + strm << "\""; +} + + +void XmlWriter::addAttribute (KOXML_STRING name, int value) +{ + if (name.length() == 0) + return; + + strm << " "; + strm << name << "=\""; + strm << value; + strm << "\""; +} + + +void XmlWriter::addAttribute (KOXML_STRING name, float value) +{ + if (name.length() == 0) + return; + + strm << " "; + strm << name << "=\""; + strm << value; + strm << "\""; +} + + +void XmlWriter::addAttribute (KOXML_STRING name, double value) +{ + if (name.length() == 0) + return; + + strm << " "; + strm << name << "=\""; + strm << value; + strm << "\""; +} + + +void XmlWriter::writeText (KOXML_STRING c) +{ + int i = 0; + while (i < (int) c.length()) { + if (c[i] == '<') + strm << "<"; + else if (c[i] == '&') + strm << "&"; + else if (c[i] == '>') + strm << ">"; + else if (c[i] == '\"' || c[i] == '\'' || c[i] == '`') { + strm << c[i]; + if (isapo) { + if (apo == c[i]) + isapo = false; + } + else { + isapo = true; + apo = c[i]; + } + } + else if (c[i] == '\n') { + if (isapo) + strm << "&nl;"; + else + strm << c[i]; + } + else if (c[i] == '\r') { + if (isapo) + strm << "&lf;"; + else + strm << c[i]; + } + else + strm << c[i]; + i++; + } +} + + +void XmlWriter::indent (int i) +{ + for (; i > 0; i--) + strm << " "; +} + + +void XmlWriter::writeTag (KOXML_STRING s) +{ + strm << "<" + << s + << ">"; +} + + +void XmlWriter::flush () +{ +#ifndef KOXML_USE_STL + stream()->flush (); +#else + strm.flush(); +#endif +} diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlWriter.h b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlWriter.h new file mode 100644 index 00000000..d73bce59 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/XmlWriter.h @@ -0,0 +1,187 @@ +/* -*- C++ -*- + + This file is part of KIllustrator. + Copyright (C) 1998 Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de) + + modified for kvoctrain by Ewald Arnold kvoctrain@ewald-arnold.dein April 99 + +*/ + +#ifndef XmlWriter_h_ +#define XmlWriter_h_ + +#if defined(stack) +#undef stack +#endif + +#include <stack> +#include <vector> +using namespace std; + +#include "koxml_config.h" + +class KOXML_OSTREAM; +/** + * The XMLWriter class provides support for writing XML streams. + * It contains methods for output XML elements with attributes. + * + * Sample code: + * <pre> + * KOXML_OSTREAM os (fname); + * XmlWriter xml (os); // writes the XML header + * + * xml.startTag ("head"); // writes <head> + * + * // write <layout format="a4" orientation="landscape"> + * xml.startTag ("layout", false); + * xml.addAttribute ("format", "a4"); + * xml.addAttribute ("orientation", "landscape"); + * xml.closeTag (true); + * </pre> + * + * @short A helper class for writing XML. + * @author Kai-Uwe Sattler (kus@iti.cs.uni-magdeburg.de), modifications: Ewald Arnold (kvoctrain@ewald-arnold.de) + * @version 2000/07/02 + + */ +class XmlWriter { +public: + /** + * Create a XmlWriter instance for the given output stream. + * + * @param os The open output stream for writing. + */ + XmlWriter (KOXML_OSTREAM& os); + + /** + * Desctructor. + */ + ~XmlWriter (); + + /** + * Write an element with the given ID to the XML stream. Attributes + * can be added later. + * + * @param id The element ID. + * @param closeIt If @p true the tag is closed by >, + * otherwise not. + * @param empty If @p true an empty element is written, which + * is closed by />. + * @param eol If @p true an eol char is appended + * even if autoendl is false + */ + void startTag (KOXML_STRING id, bool closeIt = true, bool empty = false, bool eol = false); + + /** + * Write the end tag according to the given element ID or to the + * last opened element. + * + * @param id The element ID. If @p "" the last opened + * element is ended. (default). + * @param eol If @p true an eol char is appended + * even if autoendl is false + */ + void endTag (KOXML_STRING id = "", bool eol = false); + + /** + * flag, indicating to automatically append end-of-line character after + * closing bracket + * + * @param autoflag If @p true, append eol character. Otherwise caller has to do it + */ + void setAutoEndl (const bool autoflag = true); + + /** + * append end-of-line char to stream + */ + void endline (); + + /** + * Close the current open element. + * + * @param empty If @p true an empty element is closed. + * @param eol If @p true an eol char is appended + * even if autoendl is false + */ + void closeTag (bool empty = false, bool eol = false); + + /** + * Add an attribute with the given value to the current element. + * This method doesn't check, if an element is open. + * + * @param name The attribute name. + * @param value The string value of the attribute. + */ + void addAttribute (KOXML_STRING name, const KOXML_STRING& value); + + /** + * Add an attribute with the given value to the current element. + * This method doesn't check, if an element is open. + * + * @param name The attribute name. + * @param value The integer value of the attribute. + */ + void addAttribute (KOXML_STRING name, int value); + + /** + * Add an attribute with the given value to the current element. + * This method doesn't check, if an element is open. + * + * @param name The attribute name. + * @param value The float value od the attribute. + */ + void addAttribute (KOXML_STRING name, float value); + + /** + * Add an attribute with the given value to the current element. + * This method doesn't check, if an element is open. + * + * @param name The attribute name. + * @param value The double value of the attribute. + */ + void addAttribute (KOXML_STRING name, double value); + + /** + * Write text to the XML stream. The method encodes the special + * characters @p <, @p > and @p &. + * + * @param s The text. + */ + void writeText (KOXML_STRING s); + + /** + * Write a tag to the XML stream. + * + * @param s The tag without the brackets. + */ + void writeTag (KOXML_STRING s); + + /** + * indents next text string with some spaces + * + * @param i number of spaces to indent + */ + void indent (int i); + + /** + * Flush the XML output stream. + */ + void flush (); + +#ifndef KOXML_USE_STL + /** + * Get the raw output stream. + */ + inline QIODevice *stream () { return strm.device(); } +#endif + +private: + stack<KOXML_STRING, vector<KOXML_STRING> > lastTags; + + KOXML_OSTREAM &strm; + bool autoendl; + bool isapo; + KOXML_CHAR apo; +}; + +#endif diff --git a/kvoctrain/kvoctrain/kvt-core/kvt-xml/koxml_config.h b/kvoctrain/kvoctrain/kvt-core/kvt-xml/koxml_config.h new file mode 100644 index 00000000..2f0daecb --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/kvt-xml/koxml_config.h @@ -0,0 +1,47 @@ +//#define KOXML_USE_STL + +/* + ----------------------------------------------------------------------- + + ----------------------------------------------------------------------- +*/ + +#ifndef KOXML_USE_STL + +# include <qtextstream.h> +# define KOXML_ISTREAM QTextStream +# define KOXML_OSTREAM QTextStream + +# include <qstring.h> +# define KOXML_STRING QString + +// Unicode character +# define KOXML_CHAR QChar + +# define KOXML_STRING_REMOVE( string_var, pos, count) string_var.remove (pos, count) +# define KOXML_STRING_INSERT( string_var, pos, str) string_var.insert(pos, str) + +#else + +# include <iostream> +using namespace std; +# define KOXML_ISTREAM istream +# define KOXML_OSTREAM ostream + +# define KOXML_CHAR char // evtl. wchar + +//////////////////////////////////////////////////////// +//evtl. an MFC o.. anpassen +#ifdef __MFC_STRING_BENUTZT__ + +#else + +# include <string> +# define KOXML_STRING string // evtl. wstring + +# define KOXML_STRING_REMOVE( string_var, pos, count) string_var.erase (pos, count) +# define KOXML_STRING_INSERT( string_var, pos, str) string_var.insert(pos, (string)str) + +#endif + +#endif diff --git a/kvoctrain/kvoctrain/kvt-core/langset.cpp b/kvoctrain/kvoctrain/kvt-core/langset.cpp new file mode 100644 index 00000000..644878e7 --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/langset.cpp @@ -0,0 +1,220 @@ +/*************************************************************************** + + properties for a language + + ----------------------------------------------------------------------- + + begin : Wed Jun 30 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "langset.h" + +// void LangSet::addSet (QString _shortId, QString _longId, +// QString _PixMapFile, const QString& keyboardLayout) +// { +// LangDef def; +// def.shortId = _shortId; +// def.shortId2 = ""; +// def.longId = _longId; +// def.PixMapFile = _PixMapFile; +// def.keyboardLayout = keyboardLayout; +// langs.push_back (def); +// } + + +void LangSet::addSet (QString _shortId, QString _longId, + QString _PixMapFile, const QString& _shortId2, + const QString& keyboardLayout) + +{ + LangDef def; + def.shortId = _shortId; + def.shortId2 = _shortId2; + def.longId = _longId; + def.PixMapFile = _PixMapFile; + def.keyboardLayout = keyboardLayout; + langs.push_back (def); +} + + +void LangSet::appendSet(const LangSet &set) +{ + for (int i = 0; i < (int) set.size(); ++i) { + addSet(set.langs[i].shortId, set.langs[i].longId, set.langs[i].PixMapFile, + set.langs[i].shortId2, set.langs[i].keyboardLayout); + } +} + + +void LangSet::clear() +{ + langs.clear(); +} + + +void LangSet::erase (int idx) +{ + if (idx >= 0 && idx < (int) langs.size() ) + langs.erase (langs.begin() + idx); +} + + +QString LangSet::shortId (int index) const +{ + if (index >= 0 && index < (int) langs.size() ) + return langs[index].shortId; + + return QString::null; +} + + +QString LangSet::shortId2 (int index) const +{ + if (index >= 0 && index < (int) langs.size() ) + return langs[index].shortId2; + + return QString::null; +} + + +QString LangSet::longId (int index) const +{ + if (index >= 0 && index < (int) langs.size() ) + return langs[index].longId; + + return QString::null; +} + + +QString LangSet::PixMapFile (int index) const +{ + if (index >= 0 && index < (int) langs.size() ) + return langs[index].PixMapFile; + return ""; +} + +QString LangSet::keyboardLayout (int index) const +{ + if (index >= 0 && index < (int) langs.size()) { + return langs[index].keyboardLayout; + } + else { + return QString::null; + } +} + + +QString LangSet::findShortId (const QString &_longId) const +{ + if (_longId.isEmpty()) + return ""; + + for (int i = 0; i < (int) langs.size(); i++ ) + if (_longId == langs[i].longId) + return langs[i].shortId; + + return QString::null; +} + + +QString LangSet::findLongId (const QString &_shortId) const +{ + if (_shortId.isEmpty()) + return ""; + + for (int i = 0; i < (int) langs.size(); i++ ) + if ( _shortId == langs[i].shortId + || _shortId == langs[i].shortId2) + return langs[i].longId; + + return QString::null; +} + + +int LangSet::indexShortId (QString _shortId) const +{ + if (_shortId.isEmpty()) + return -1; + + for (int i = 0; i < (int) langs.size(); i++) { + if ( langs[i].shortId == _shortId + ||langs[i].shortId2 == _shortId ) + return i; + } + return -1; +} + + +int LangSet::indexLongId (QString _longId) const +{ + if (_longId.isEmpty()) + return -1; + + for (int i = 0; i < (int) langs.size(); i++) { + if (langs[i].longId == _longId) + return i; + } + return -1; +} + + +int LangSet::indexPixMapFile (QString PixMapFile) const +{ + int id = -1; + for (int i = 0; i < (int) langs.size(); i++) + if (langs[i].PixMapFile == PixMapFile) + id = i; + return id; +} + +void LangSet::setShortId (const QString & s, int index) +{ + if (index < (int) langs.size() ) + langs[index].shortId = s; +} + + +void LangSet::setShortId2 (const QString & s, int index) +{ + if (index < (int) langs.size() ) + langs[index].shortId2 = s; +} + + +void LangSet::setLongId (const QString & s, int index) +{ + if (index < (int) langs.size() ) + langs[index].longId = s; +} + + +void LangSet::setPixMapFile (const QString & s, int index) +{ + if (index < (int) langs.size() ) + langs[index].PixMapFile = s; +} + +void LangSet::setKeyboardLayout(const QString& layout, int index) +{ + if (index < (int) langs.size()) { + langs[index].keyboardLayout = layout; + } +} diff --git a/kvoctrain/kvoctrain/kvt-core/langset.h b/kvoctrain/kvoctrain/kvt-core/langset.h new file mode 100644 index 00000000..f0da2a5a --- /dev/null +++ b/kvoctrain/kvoctrain/kvt-core/langset.h @@ -0,0 +1,92 @@ +/*************************************************************************** + + properties for a language + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 langset_h +#define langset_h + +#include <vector> +using namespace std; + +#include <qstring.h> + + +class LangSet +{ + public: + + LangSet () {} + + void addSet (QString shortId, QString longId, QString PixMapFile, + const QString& shortId2 = QString::null, + const QString& keyboardLayout = QString::null); + +/* void addSet (QString shortId, QString shortId2, QString longId, */ +/* QString PixMapFile, */ +/* const QString& keyboardLayout = QString::null); */ + + void appendSet(const LangSet &set); + + unsigned int size () const { return langs.size(); } + void erase (int idx); + void clear (); + + QString shortId (int index) const; + QString shortId2 (int index) const; + QString longId (int index) const; + QString PixMapFile (int index) const; + QString keyboardLayout (int index) const; + + int indexShortId (QString shortId) const; + int indexLongId (QString longId) const; + int indexPixMapFile (QString PixMapFile) const; + // doesn't make sense for keyboard layouts since there is no 1-to-1 relation to languages + + void setShortId (const QString & shortId, int index); + void setShortId2 (const QString & shortId2, int index); + void setLongId (const QString & longId, int index); + void setPixMapFile (const QString & PixMapFile, int index); + void setKeyboardLayout(const QString & layout, int index); + + QString findShortId (const QString & longId) const; + QString findLongId (const QString & shortId) const; + + private: + + struct LangDef { + QString shortId, + shortId2, + longId, + PixMapFile, + keyboardLayout; + }; + + vector<LangDef> langs; +}; + + +#endif // langset_h diff --git a/kvoctrain/kvoctrain/kvtnewstuff.cpp b/kvoctrain/kvoctrain/kvtnewstuff.cpp new file mode 100644 index 00000000..b1004c56 --- /dev/null +++ b/kvoctrain/kvoctrain/kvtnewstuff.cpp @@ -0,0 +1,92 @@ +// +// C++ Implementation: kvtnewstuff +// +// Description: +// +// +// Author: Peter Hedlund <peter.hedlund@kdemail.net>, (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include <qdir.h> + +#include <kprocess.h> +#include <klocale.h> +#include <kstandarddirs.h> +#include <kmessagebox.h> +#include <knewstuff/entry.h> + +#include "kvoctrain.h" +#include "kvtnewstuff.h" +#include "prefs.h" + +KVTNewStuff::KVTNewStuff(QWidget *parent, const char * /*name*/) : QObject(), KNewStuff("kdeedu/vocabulary", parent) +{ + m_app = (kvoctrainApp*) parent; +} + + +bool KVTNewStuff::install(const QString & fileName) +{ + if (m_app->queryExit()) + m_app->loadfileFromPath(fileName, true); + return true; +} + + +bool KVTNewStuff::createUploadFile(const QString & /*fileName*/) +{ + return true; +} + + +QString KVTNewStuff::destinationPath(KNS::Entry * entry) +{ + if (entry) + { + KURL url = entry->payload(); + QString fileName = url.fileName(); + + QString path = Prefs::installPath(); //default is Vocabularies which will be created in the user's home directory + QString file; + + if (path.isEmpty()) + file = KNewStuff::downloadDestination(entry); //fall back on a temp file, should never happen + else + { + file = QDir::home().path() + "/" + path + "/"; + KStandardDirs::makeDir(file); //ensure the directory exists + file += fileName; + } + return file; + } + else + return QString::null; +} + + +QString KVTNewStuff::downloadDestination(KNS::Entry * entry) +{ + QString file = destinationPath(entry); + + if (KStandardDirs::exists(file)) + { + int result = KMessageBox::warningContinueCancel(parentWidget(), + i18n("The file '%1' already exists. Do you want to overwrite it?") + .arg(file), + QString::null, i18n("Overwrite") ); + if (result == KMessageBox::Cancel) + return QString::null; + } + KMessageBox::information(parentWidget(), + i18n("<qt>The selected file will now be downloaded and saved as\n<b>'%1'</b>.</qt>") + .arg(file), + QString::null, + "NewStuffDownloadLocation"); + return file; +} + + +#include "kvtnewstuff.moc" diff --git a/kvoctrain/kvoctrain/kvtnewstuff.h b/kvoctrain/kvoctrain/kvtnewstuff.h new file mode 100644 index 00000000..9953ac1a --- /dev/null +++ b/kvoctrain/kvoctrain/kvtnewstuff.h @@ -0,0 +1,60 @@ +// +// C++ Interface: kvtnewstuff +// +// Description: +// +// +// Author: Peter Hedlund <peter.hedlund@kdemail.net>, (C) 2005 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef KVTNEWSTUFF_H +#define KVTNEWSTUFF_H + +#include <knewstuff/knewstuff.h> + +class kvoctrainApp; + +/** +@author Peter Hedlund +*/ +class KVTNewStuff : public QObject, public KNewStuff +{ +Q_OBJECT +public: + KVTNewStuff(QWidget *parent = 0, const char *name = 0); + + /** + Installs a downloaded file according to the application's configuration. + + @param fileName filename of the donwloaded file + @return @c true in case of installation success, @c false otherwise + */ + bool install(const QString &fileName); + + /** + Creates a file suitable for upload. + Note that this method always fails, since using KNewStuffGeneric + means that the provided file must already be in a usable format. + + @param fileName the name of the file to upload after its creation + @return @c true in case of creation success, @c false otherwise + */ + bool createUploadFile(const QString &fileName); + + /** + Queries the preferred destination file for a download. + + @param entry a Hotstuff data entry + @return destination filename, or 0 to return directory only + */ + QString downloadDestination(KNS::Entry *entry); + +private: + QString destinationPath(KNS::Entry *entry); + + kvoctrainApp * m_app; +}; + +#endif diff --git a/kvoctrain/kvoctrain/latin1_to_utf8 b/kvoctrain/kvoctrain/latin1_to_utf8 new file mode 100644 index 00000000..d53e855d --- /dev/null +++ b/kvoctrain/kvoctrain/latin1_to_utf8 @@ -0,0 +1 @@ +recode ISO_8859-1..UTF8 $1 diff --git a/kvoctrain/kvoctrain/main.cpp b/kvoctrain/kvoctrain/main.cpp new file mode 100644 index 00000000..9eb124cd --- /dev/null +++ b/kvoctrain/kvoctrain/main.cpp @@ -0,0 +1,121 @@ +/*************************************************************************** + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kvoctrain.h" +#include "kvoctraincore.h" + +# include <kcmdlineargs.h> +# include <kaboutdata.h> +# include <klocale.h> + +int main(int argc, char* argv[]) { + +static KCmdLineOptions options[] = +{ + { I18N_NOOP("+[file]"), I18N_NOOP("Document file to open"), 0 }, + KCmdLineLastOption +}; + +static const char description[] = I18N_NOOP("Vocabulary Trainer"); +static const char version[] = KVOCTRAIN_VERSION_STRING; + + KAboutData aboutData("kvoctrain", + I18N_NOOP("KVocTrain"), + version, + description, + KAboutData::License_GPL, + I18N_NOOP("© 1999-2002\tEwald Arnold\n" + "© 2001-2002\tThe KDE team\n" + "© 2004-2007\tPeter Hedlund\n" + "© 2007 \tFrederik Gladhorn\n"), + I18N_NOOP("Helps you train your vocabulary"), + "http://edu.kde.org/kvoctrain", + "submit@bugs.kde.org"); + + aboutData.addAuthor("Frederik Gladhorn", + I18N_NOOP("Current Maintainer"), "frederik.gladhorn@kdemail.net"); + + aboutData.addAuthor("Peter Hedlund", + I18N_NOOP("Former Maintainer and Countless Improvements"), "peter.hedlund@kdemail.net"); + + aboutData.addAuthor("Ewald Arnold", I18N_NOOP("Original Author"), "kvoctrain@ewald-arnold.de", + "http://www.ewald-arnold.de" ); + + aboutData.addCredit("Waldo Bastian", + I18N_NOOP("Help with port to Qt3/KDE3")); + + aboutData.addCredit("Andrea Marconi", + I18N_NOOP("Initial Italian localization")); + + aboutData.addCredit("Hans Kottmann", + I18N_NOOP("Initial French localization")); + + aboutData.addCredit("Grzegorz Ilczuk", + I18N_NOOP("Initial Polish localization")); + + aboutData.addCredit("Eric Bischoff", + I18N_NOOP("Converting documentation to docbook format")); + + aboutData.addCredit("Kevin Kramer", + I18N_NOOP("Tool to create lists with ISO639 codes")); + + aboutData.addCredit("Andreas Neuper", + I18N_NOOP("Converter script \"langen2kvtml\" \nDownload files at http://www.vokabeln.de/files.htm")); + + aboutData.addCredit("Dennis Haney", + I18N_NOOP("Patch to implement Leitner learning method")); + + aboutData.addCredit("Anne-Marie Mahfouf", + I18N_NOOP("Port to KConfig XT")); + + aboutData.addCredit(I18N_NOOP("KDE Team"), + I18N_NOOP("Many small enhancements")); + + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); + KApplication app; + + kvoctrainApp *kva = 0; + if (app.isRestored()) { + int n = 1; + while (KMainWindow::canBeRestored(n)){ + kva = new kvoctrainApp; + kva->restore(n); + kva->show(); + n++; + } + } + else + { + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + kva = new kvoctrainApp; + + if ( args && args->count() == 1 ) + kva->loadfileFromPath(args->arg(0), true); + + kva->show(); + } + return app.exec(); +} + diff --git a/kvoctrain/kvoctrain/pics/Makefile.am b/kvoctrain/kvoctrain/pics/Makefile.am new file mode 100644 index 00000000..b16824c2 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/Makefile.am @@ -0,0 +1,6 @@ +kvoctrainiconsdir = $(kde_datadir)/kvoctrain/icons + +kvoctrainicons_ICON = AUTO + +KDE_ICON = kvoctrain + diff --git a/kvoctrain/kvoctrain/pics/cr16-action-cleanup.png b/kvoctrain/kvoctrain/pics/cr16-action-cleanup.png Binary files differnew file mode 100644 index 00000000..a0d74214 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-cleanup.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-configure_query.png b/kvoctrain/kvoctrain/pics/cr16-action-configure_query.png Binary files differnew file mode 100644 index 00000000..2872eb5b --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-configure_query.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-delete_table_col.png b/kvoctrain/kvoctrain/pics/cr16-action-delete_table_col.png Binary files differnew file mode 100644 index 00000000..1abaf290 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-delete_table_col.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-delete_table_row.png b/kvoctrain/kvoctrain/pics/cr16-action-delete_table_row.png Binary files differnew file mode 100644 index 00000000..490b130d --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-delete_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-edit_table_row.png b/kvoctrain/kvoctrain/pics/cr16-action-edit_table_row.png Binary files differnew file mode 100644 index 00000000..9033f93c --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-edit_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-insert_table_col.png b/kvoctrain/kvoctrain/pics/cr16-action-insert_table_col.png Binary files differnew file mode 100644 index 00000000..ea93906d --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-insert_table_col.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-insert_table_row.png b/kvoctrain/kvoctrain/pics/cr16-action-insert_table_row.png Binary files differnew file mode 100644 index 00000000..dfe962c6 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-insert_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-rand_less.png b/kvoctrain/kvoctrain/pics/cr16-action-rand_less.png Binary files differnew file mode 100644 index 00000000..ebbe29e2 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-rand_less.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-run_multi.png b/kvoctrain/kvoctrain/pics/cr16-action-run_multi.png Binary files differnew file mode 100644 index 00000000..8bc1e26c --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-run_multi.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-run_query.png b/kvoctrain/kvoctrain/pics/cr16-action-run_query.png Binary files differnew file mode 100644 index 00000000..35179284 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-run_query.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-set_language.png b/kvoctrain/kvoctrain/pics/cr16-action-set_language.png Binary files differnew file mode 100644 index 00000000..b683de4d --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-set_language.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-sort_incr.png b/kvoctrain/kvoctrain/pics/cr16-action-sort_incr.png Binary files differnew file mode 100644 index 00000000..f64da9a7 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-sort_incr.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-sort_num.png b/kvoctrain/kvoctrain/pics/cr16-action-sort_num.png Binary files differnew file mode 100644 index 00000000..c76887e1 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-sort_num.png diff --git a/kvoctrain/kvoctrain/pics/cr16-action-statistics.png b/kvoctrain/kvoctrain/pics/cr16-action-statistics.png Binary files differnew file mode 100644 index 00000000..ad4b7784 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr16-action-statistics.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-cleanup.png b/kvoctrain/kvoctrain/pics/cr22-action-cleanup.png Binary files differnew file mode 100644 index 00000000..403ce466 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-cleanup.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-configure_query.png b/kvoctrain/kvoctrain/pics/cr22-action-configure_query.png Binary files differnew file mode 100644 index 00000000..8379a830 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-configure_query.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-delete_table_col.png b/kvoctrain/kvoctrain/pics/cr22-action-delete_table_col.png Binary files differnew file mode 100644 index 00000000..076e8c9a --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-delete_table_col.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-delete_table_row.png b/kvoctrain/kvoctrain/pics/cr22-action-delete_table_row.png Binary files differnew file mode 100644 index 00000000..8953710b --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-delete_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-edit_table_row.png b/kvoctrain/kvoctrain/pics/cr22-action-edit_table_row.png Binary files differnew file mode 100644 index 00000000..7eea5193 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-edit_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-insert_table_col.png b/kvoctrain/kvoctrain/pics/cr22-action-insert_table_col.png Binary files differnew file mode 100644 index 00000000..17df97aa --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-insert_table_col.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-insert_table_row.png b/kvoctrain/kvoctrain/pics/cr22-action-insert_table_row.png Binary files differnew file mode 100644 index 00000000..fde61559 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-insert_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-rand_less.png b/kvoctrain/kvoctrain/pics/cr22-action-rand_less.png Binary files differnew file mode 100644 index 00000000..938f9bc5 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-rand_less.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-run_multi.png b/kvoctrain/kvoctrain/pics/cr22-action-run_multi.png Binary files differnew file mode 100644 index 00000000..b3362226 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-run_multi.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-run_query.png b/kvoctrain/kvoctrain/pics/cr22-action-run_query.png Binary files differnew file mode 100644 index 00000000..070f0869 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-run_query.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-set_language.png b/kvoctrain/kvoctrain/pics/cr22-action-set_language.png Binary files differnew file mode 100644 index 00000000..33c99bf3 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-set_language.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-sort_incr.png b/kvoctrain/kvoctrain/pics/cr22-action-sort_incr.png Binary files differnew file mode 100644 index 00000000..80f4638f --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-sort_incr.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-sort_num.png b/kvoctrain/kvoctrain/pics/cr22-action-sort_num.png Binary files differnew file mode 100644 index 00000000..064292aa --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-sort_num.png diff --git a/kvoctrain/kvoctrain/pics/cr22-action-statistics.png b/kvoctrain/kvoctrain/pics/cr22-action-statistics.png Binary files differnew file mode 100644 index 00000000..782ecec3 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr22-action-statistics.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-cleanup.png b/kvoctrain/kvoctrain/pics/cr32-action-cleanup.png Binary files differnew file mode 100644 index 00000000..b91649f4 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-cleanup.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-configure_query.png b/kvoctrain/kvoctrain/pics/cr32-action-configure_query.png Binary files differnew file mode 100644 index 00000000..f3f56113 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-configure_query.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-delete_table_col.png b/kvoctrain/kvoctrain/pics/cr32-action-delete_table_col.png Binary files differnew file mode 100644 index 00000000..1d30ad74 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-delete_table_col.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-delete_table_row.png b/kvoctrain/kvoctrain/pics/cr32-action-delete_table_row.png Binary files differnew file mode 100644 index 00000000..58712c56 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-delete_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-edit_table_row.png b/kvoctrain/kvoctrain/pics/cr32-action-edit_table_row.png Binary files differnew file mode 100644 index 00000000..7045d41f --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-edit_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-insert_table_col.png b/kvoctrain/kvoctrain/pics/cr32-action-insert_table_col.png Binary files differnew file mode 100644 index 00000000..d7dbe222 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-insert_table_col.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-insert_table_row.png b/kvoctrain/kvoctrain/pics/cr32-action-insert_table_row.png Binary files differnew file mode 100644 index 00000000..af5e61d0 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-insert_table_row.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-rand_less.png b/kvoctrain/kvoctrain/pics/cr32-action-rand_less.png Binary files differnew file mode 100644 index 00000000..e3cfa454 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-rand_less.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-run_multi.png b/kvoctrain/kvoctrain/pics/cr32-action-run_multi.png Binary files differnew file mode 100644 index 00000000..ed53f36e --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-run_multi.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-run_query.png b/kvoctrain/kvoctrain/pics/cr32-action-run_query.png Binary files differnew file mode 100644 index 00000000..be185c46 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-run_query.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-set_language.png b/kvoctrain/kvoctrain/pics/cr32-action-set_language.png Binary files differnew file mode 100644 index 00000000..2e89ab95 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-set_language.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-sort_incr.png b/kvoctrain/kvoctrain/pics/cr32-action-sort_incr.png Binary files differnew file mode 100644 index 00000000..5843d08c --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-sort_incr.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-sort_num.png b/kvoctrain/kvoctrain/pics/cr32-action-sort_num.png Binary files differnew file mode 100644 index 00000000..e49d430a --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-sort_num.png diff --git a/kvoctrain/kvoctrain/pics/cr32-action-statistics.png b/kvoctrain/kvoctrain/pics/cr32-action-statistics.png Binary files differnew file mode 100644 index 00000000..2c5010ce --- /dev/null +++ b/kvoctrain/kvoctrain/pics/cr32-action-statistics.png diff --git a/kvoctrain/kvoctrain/pics/hi16-app-kvoctrain.png b/kvoctrain/kvoctrain/pics/hi16-app-kvoctrain.png Binary files differnew file mode 100644 index 00000000..a0314763 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/hi16-app-kvoctrain.png diff --git a/kvoctrain/kvoctrain/pics/hi22-app-kvoctrain.png b/kvoctrain/kvoctrain/pics/hi22-app-kvoctrain.png Binary files differnew file mode 100644 index 00000000..7c5e8b9f --- /dev/null +++ b/kvoctrain/kvoctrain/pics/hi22-app-kvoctrain.png diff --git a/kvoctrain/kvoctrain/pics/hi32-app-kvoctrain.png b/kvoctrain/kvoctrain/pics/hi32-app-kvoctrain.png Binary files differnew file mode 100644 index 00000000..c7926cd9 --- /dev/null +++ b/kvoctrain/kvoctrain/pics/hi32-app-kvoctrain.png diff --git a/kvoctrain/kvoctrain/pics/hi48-app-kvoctrain.png b/kvoctrain/kvoctrain/pics/hi48-app-kvoctrain.png Binary files differnew file mode 100644 index 00000000..4d5274ee --- /dev/null +++ b/kvoctrain/kvoctrain/pics/hi48-app-kvoctrain.png diff --git a/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlg.cpp b/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlg.cpp new file mode 100644 index 00000000..c643ba01 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlg.cpp @@ -0,0 +1,303 @@ +/*************************************************************************** + + query dialog for adjectives + + ----------------------------------------------------------------------- + + begin : Sat Dec 4 15:09:18 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "AdjQueryDlg.h" + +#include <kv_resource.h> +#include <langset.h> + +#include <kapplication.h> +#include <kstandarddirs.h> +#include <klocale.h> +#include <kprogress.h> + +#include <qtimer.h> +#include <qpushbutton.h> +#include <qlineedit.h> +#include <qlabel.h> + +AdjQueryDlg::AdjQueryDlg +( + QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Comparison &_comp) + : QueryDlgBase(i18n("Comparison Training")) +{ + mw = new AdjQueryDlgForm(this); + setMainWidget(mw); + + connect(mw->dont_know, SIGNAL(clicked()), SLOT(dontKnowClicked()) ); + connect(mw->know_it, SIGNAL(clicked()), SLOT(knowItClicked()) ); + connect(mw->verify, SIGNAL(clicked()), SLOT(verifyClicked()) ); + connect(mw->show_all, SIGNAL(clicked()), SLOT(showAllClicked()) ); + + connect(mw->lev1Field, SIGNAL(returnPressed()), SLOT(returnPressed()) ); + connect(mw->lev2Field, SIGNAL(returnPressed()), SLOT(returnPressed()) ); + connect(mw->lev3Field, SIGNAL(returnPressed()), SLOT(returnPressed()) ); + + connect(mw->lev1Field, SIGNAL(textChanged(const QString&)), SLOT(lev1Changed(const QString&)) ); + connect(mw->lev2Field, SIGNAL(textChanged(const QString&)), SLOT(lev2Changed(const QString&)) ); + connect(mw->lev3Field, SIGNAL(textChanged(const QString&)), SLOT(lev3Changed(const QString&)) ); + + qtimer = 0; + + mw->lev1Label->setBuddy(mw->lev1Field); + mw->lev2Label->setBuddy(mw->lev2Field); + mw->lev3Label->setBuddy(mw->lev3Field); + + setQuery (type, entry, col, query_cycle, query_num, query_startnum, exp, doc, _comp); + mw->countbar->setFormat("%v/%m"); + mw->timebar->setFormat("%v"); + resize(configDialogSize("AdjQueryDialog")); +} + + +AdjQueryDlg::~AdjQueryDlg() +{ + saveDialogSize("AdjQueryDialog"); +} + + +void AdjQueryDlg::setQuery(QString, + int entry, + int col, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Comparison &_comp) +{ + //type_timeout = type_to; + kv_doc = doc; + kv_exp = exp; + q_row = entry; + q_ocol = col; + mw->timebar->setEnabled(Prefs::showCounter()); + mw->timelabel->setEnabled(Prefs::showCounter()); + comp = _comp; + mw->show_all->setDefault(true); + QString s; + s.setNum (q_cycle); + mw->progCount->setText (s); + + mw->lev1Field->setText (""); + mw->lev2Field->setText (""); + mw->lev3Field->setText (""); + + int sel = getRandom(3); + switch (sel) { + case 0: mw->lev1Field->setText (comp.l1() ); + break; + + case 1: mw->lev2Field->setText (comp.l2() ); + break; + + case 2: mw->lev3Field->setText (comp.l3() ); + break; + } + + mw->lev1Field->setEnabled(!comp.l1().isEmpty() ); + mw->lev2Field->setEnabled(!comp.l2().isEmpty() ); + mw->lev3Field->setEnabled(!comp.l3().isEmpty() ); + + mw->countbar->setTotalSteps(q_start); + mw->countbar->setProgress(q_start - q_num + 1); + + int mqtime = Prefs::maxTimePer(); + if (mqtime > 0) { + if (qtimer == 0) { + qtimer = new QTimer( this ); + connect( qtimer, SIGNAL(timeout()), this, SLOT(timeoutReached()) ); + } + + if (Prefs::queryTimeout() != Prefs::EnumQueryTimeout::NoTimeout) { + timercount = mqtime; + mw->timebar->setTotalSteps(timercount); + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + else + mw->timebar->setEnabled(false); + } + else + mw->timebar->setEnabled(false); + resetAllFields(); +} + + +void AdjQueryDlg::initFocus() const +{ + mw->lev1Field->setFocus(); +} + + +void AdjQueryDlg::showAllClicked() +{ + resetAllFields(); + mw->lev1Field->setText (comp.l1() ); + mw->lev2Field->setText (comp.l2() ); + mw->lev3Field->setText (comp.l3() ); + + verifyField (mw->lev1Field, comp.l1()); + verifyField (mw->lev2Field, comp.l2()); + verifyField (mw->lev3Field, comp.l3()); + + mw->dont_know->setDefault(true); +} + + +void AdjQueryDlg::verifyClicked() +{ + bool all_known = true; + + if (!verifyField (mw->lev1Field, comp.l1()) ) + all_known = false; + + if (!verifyField (mw->lev2Field, comp.l2()) ) + all_known = false; + + if (!verifyField (mw->lev3Field, comp.l3()) ) + all_known = false; + + if (all_known) +// know_it->setDefault(true); + knowItClicked(); + else + mw->dont_know->setDefault(true); +} + + +void AdjQueryDlg::resetAllFields() +{ + resetField(mw->lev1Field); + resetField(mw->lev2Field); + resetField(mw->lev3Field); +} + + +void AdjQueryDlg::knowItClicked() +{ + emit sigQueryChoice(Known); +} + + +void AdjQueryDlg::timeoutReached() +{ + if (timercount > 0) { + timercount--; + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + + if (timercount <= 0) { + mw->timebar->setProgress(0); + if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Show) { + showAllClicked(); + mw->dont_know->setDefault(true); + } + else if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Continue) + emit sigQueryChoice(Timeout); + } +} + + +void AdjQueryDlg::dontKnowClicked() +{ + emit sigQueryChoice(Unknown); +} + + +void AdjQueryDlg::slotUser2() +{ + + if (qtimer != 0) + qtimer->stop(); + + emit sigEditEntry (q_row, KV_COL_ORG+q_ocol); +} + + +void AdjQueryDlg::keyPressEvent( QKeyEvent *e ) +{ + switch( e->key() ) + { + case Key_Escape: + dontKnowClicked(); + break; + + case Key_Return: + case Key_Enter: + if (mw->dont_know->isDefault() ) + dontKnowClicked(); + else if (mw->know_it->isDefault() ) + knowItClicked(); + else if (mw->show_all->isDefault() ) + showAllClicked(); + else if (mw->verify->isDefault() ) + verifyClicked(); + break; + + default: + e->ignore(); + break; + } +} + + +void AdjQueryDlg::returnPressed() +{ +} + + +void AdjQueryDlg::lev1Changed(const QString&) +{ + mw->verify->setDefault(true); + resetField (mw->lev1Field); +} + + +void AdjQueryDlg::lev2Changed(const QString&) +{ + mw->verify->setDefault(true); + resetField (mw->lev2Field); +} + + +void AdjQueryDlg::lev3Changed(const QString&) +{ + mw->verify->setDefault(true); + resetField (mw->lev3Field); +} + + +#include "AdjQueryDlg.moc" diff --git a/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlg.h b/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlg.h new file mode 100644 index 00000000..29561404 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlg.h @@ -0,0 +1,87 @@ +/*************************************************************************** + + query dialog for adjectives + + ----------------------------------------------------------------------- + + begin : Sat Dec 4 15:09:18 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 AdjQueryDlg_included +#define AdjQueryDlg_included + +#include "AdjQueryDlgForm.h" +#include "QueryDlgBase.h" + +class AdjQueryDlg : public QueryDlgBase +{ + Q_OBJECT + +public: + AdjQueryDlg + ( + QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Comparison &comp); + + ~AdjQueryDlg(); + + void setQuery(QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Comparison &comp); + +public slots: + virtual void initFocus() const; + +protected: + void keyPressEvent(QKeyEvent *e); + void resetAllFields(); + +protected slots: + void lev1Changed(const QString&); + void lev2Changed(const QString&); + void lev3Changed(const QString&); + void showAllClicked(); + void slotUser2(); + void knowItClicked(); + void returnPressed(); + void dontKnowClicked(); + void verifyClicked(); + void timeoutReached(); + +protected: + Comparison comp; + +private: + AdjQueryDlgForm * mw; +}; +#endif // AdjQueryDlg_included diff --git a/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlgForm.ui b/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlgForm.ui new file mode 100644 index 00000000..b8218978 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/AdjQueryDlgForm.ui @@ -0,0 +1,344 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>AdjQueryDlgForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>AdjQueryDlgForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>396</width> + <height>226</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Fill in the missing comparison expressions:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>lev1Label</cstring> + </property> + <property name="text"> + <string>Level &1:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>lev1Field</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>lev3Label</cstring> + </property> + <property name="text"> + <string>Level &3:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>lev3Field</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>lev2Label</cstring> + </property> + <property name="text"> + <string>Level &2:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>lev2Field</cstring> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>lev1Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>lev2Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLineEdit" row="3" column="1"> + <property name="name"> + <cstring>lev3Field</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <spacer row="4" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>spacer5</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>390</width> + <height>60</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget" row="5" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>status</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + </widget> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout6</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>verify</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Verify</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>know_it</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>I &Know It</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="0"> + <property name="name"> + <cstring>show_all</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show &All</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>dont_know</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Do Not Know</string> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox" row="0" column="1" rowspan="2" colspan="1"> + <property name="name"> + <cstring>progressgroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Progress</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="KProgress" row="0" column="1"> + <property name="name"> + <cstring>countbar</cstring> + </property> + </widget> + <widget class="KProgress" row="1" column="1"> + <property name="name"> + <cstring>timebar</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>countlabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Count:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>timelabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Time:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>Cyclelabel</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="text"> + <string>Cycle:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>progCount</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + </grid> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>lev1Field</tabstop> + <tabstop>lev2Field</tabstop> + <tabstop>lev3Field</tabstop> + <tabstop>show_all</tabstop> + <tabstop>verify</tabstop> + <tabstop>know_it</tabstop> + <tabstop>dont_know</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kprogress.h</includehint> + <includehint>kprogress.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlg.cpp b/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlg.cpp new file mode 100644 index 00000000..a35ffa83 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlg.cpp @@ -0,0 +1,346 @@ +/*************************************************************************** + + query dialog for articles + + ----------------------------------------------------------------------- + + begin : Fri Dec 3 18:28:18 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "ArtQueryDlg.h" + +#include <kv_resource.h> + +#include <kstandarddirs.h> +#include <klocale.h> +#include <kapplication.h> +#include <kprogress.h> + +#include <qtimer.h> +#include <qradiobutton.h> +#include <qlabel.h> +#include <qpushbutton.h> +#include <qbuttongroup.h> + +ArtQueryDlg::ArtQueryDlg +( + QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Article &articles) + : QueryDlgBase(i18n("Article Training")) +{ + mw = new ArtQueryDlgForm(this); + setMainWidget(mw); + + qtimer = 0; + + mw->artGroup->insert (mw->natural); + mw->artGroup->insert (mw->male); + mw->artGroup->insert (mw->rb_fem); + + connect(mw->dont_know, SIGNAL(clicked()), SLOT(dontKnowClicked()) ); + connect(mw->know_it, SIGNAL(clicked()), SLOT(knowItClicked()) ); + connect(mw->verify, SIGNAL(clicked()), SLOT(verifyClicked()) ); + connect(mw->show_all, SIGNAL(clicked()), SLOT(showAllClicked()) ); + + connect(mw->natural, SIGNAL(clicked()), SLOT(slotNaturalClicked()) ); + connect(mw->male, SIGNAL(clicked()), SLOT(slotMaleClicked()) ); + connect(mw->rb_fem, SIGNAL(clicked()), SLOT(slotFemClicked()) ); + + setQuery (type, entry, col, query_cycle, query_num, query_startnum, exp, doc, articles); + mw->countbar->setFormat("%v/%m"); + mw->timebar->setFormat("%v"); + resize(configDialogSize("ArtQueryDialog")); +} + + +ArtQueryDlg::~ArtQueryDlg() +{ + saveDialogSize("ArtQueryDialog"); +} + + +void ArtQueryDlg::setQuery(QString, + int entry, + int col, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Article &art) +{ + //type_timeout = type_to; + kv_exp = exp; + kv_doc = doc; + q_row = entry; + q_ocol = col; + mw->timebar->setEnabled(Prefs::showCounter()); + mw->timelabel->setEnabled(Prefs::showCounter()); + mw->show_all->setDefault(true); + articles = art; + + QString s; + if (col == 0) + s = exp->getOriginal().stripWhiteSpace(); + else + s = exp->getTranslation(q_ocol).stripWhiteSpace(); + + QString def, indef; + bool removed = false; + + articles.female(def, indef); + mw->rb_fem->setText (i18n("&female:\t")+def+" / "+indef); + mw->rb_fem->setEnabled (!QString(def+indef).isEmpty() ); + if (!removed && s.find(def+" ") == 0) { + s.remove (0, def.length()+1); + removed = true; + } + if (!removed && s.find(indef+" ") == 0) { + s.remove (0, indef.length()+1); + removed = true; + } + + articles.male(def, indef); + mw->male->setText (i18n("&male:\t")+def+" / "+indef); + mw->male->setEnabled (!QString(def+indef).isEmpty() ); + if (!removed && s.find(def+" ") == 0) { + s.remove (0, def.length()+1); + removed = true; + } + if (!removed && s.find(indef+" ") == 0) { + s.remove (0, indef.length()+1); + removed = true; + } + + articles.natural(def, indef); + mw->natural->setText (i18n("&natural:\t")+def+" / "+indef); + mw->natural->setEnabled (!QString(def+indef).isEmpty() ); + if (!removed && s.find(def+" ") == 0) { + s.remove (0, def.length()+1); + removed = true; + } + if (!removed && s.find(indef+" ") == 0) { + s.remove (0, indef.length()+1); + removed = true; + } + + mw->orgField->setText(s); + s.setNum (q_cycle); + mw->progCount->setText (s); + + mw->countbar->setTotalSteps(q_start); + mw->countbar->setProgress(q_start - q_num + 1); + int mqtime = Prefs::maxTimePer(); + if (mqtime > 0) { + if (qtimer == 0) { + qtimer = new QTimer( this ); + connect( qtimer, SIGNAL(timeout()), this, SLOT(timeoutReached()) ); + } + + if (Prefs::queryTimeout() != Prefs::EnumQueryTimeout::NoTimeout) { + timercount = mqtime; + mw->timebar->setTotalSteps(timercount); + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + else + mw->timebar->setEnabled(false); + } + else + mw->timebar->setEnabled(false); +} + + +void ArtQueryDlg::initFocus() const +{ + mw->rb_fem->setFocus(); +} + + +void ArtQueryDlg::showAllClicked() +{ + resetButton(mw->rb_fem); + resetButton(mw->male); + resetButton(mw->natural); + + if (kv_exp->getType (q_ocol) == QM_NOUN QM_TYPE_DIV QM_NOUN_F) { + mw->rb_fem->setChecked (true); + verifyButton(mw->rb_fem, true); + } + else if (kv_exp->getType (q_ocol) == QM_NOUN QM_TYPE_DIV QM_NOUN_M) { + mw->male->setChecked (true); + verifyButton(mw->male, true); + } + else if (kv_exp->getType (q_ocol) == QM_NOUN QM_TYPE_DIV QM_NOUN_S) { + mw->natural->setChecked (true); + verifyButton(mw->natural, true); + } + mw->dont_know->setDefault(true); +} + + +void ArtQueryDlg::showMoreClicked() +{ +} + + +void ArtQueryDlg::verifyClicked() +{ + bool known = false; + if (kv_exp->getType (q_ocol) == QM_NOUN QM_TYPE_DIV QM_NOUN_F) + known = mw->rb_fem->isChecked (); + else if (kv_exp->getType (q_ocol) == QM_NOUN QM_TYPE_DIV QM_NOUN_M) + known = mw->male->isChecked (); + else if (kv_exp->getType (q_ocol) == QM_NOUN QM_TYPE_DIV QM_NOUN_S) + known = mw->natural->isChecked (); + + if (mw->rb_fem->isChecked() ) { + verifyButton(mw->rb_fem, known); + resetButton(mw->male); + resetButton(mw->natural); + } + else if (mw->male->isChecked() ) { + verifyButton(mw->male, known); + resetButton(mw->rb_fem); + resetButton(mw->natural); + } + else if (mw->natural->isChecked() ) { + verifyButton(mw->natural, known); + resetButton(mw->male); + resetButton(mw->rb_fem); + } + + if (known) +// know_it->setDefault(true); + knowItClicked(); + else + mw->dont_know->setDefault(true); +} + + +void ArtQueryDlg::knowItClicked() +{ + emit sigQueryChoice(Known); +} + + +void ArtQueryDlg::timeoutReached() +{ + if (timercount > 0) { + timercount--; + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + + if (timercount <= 0) { + mw->timebar->setProgress(0); + if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Show) { + showAllClicked(); + mw->dont_know->setDefault(true); + } + else if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Continue) + emit sigQueryChoice(Timeout); + } +} + + +void ArtQueryDlg::dontKnowClicked() +{ + emit sigQueryChoice (Unknown); +} + + +void ArtQueryDlg::slotUser2() +{ + + if (qtimer != 0) + qtimer->stop(); + + emit sigEditEntry (q_row, KV_COL_ORG+q_ocol); +} + + +void ArtQueryDlg::keyPressEvent( QKeyEvent *e ) +{ + switch( e->key() ) + { + case Key_Escape: + dontKnowClicked(); + break; + + case Key_Return: + case Key_Enter: + if (mw->dont_know->isDefault() ) + dontKnowClicked(); + else if (mw->know_it->isDefault() ) + knowItClicked(); + else if (mw->show_all->isDefault() ) + showAllClicked(); + else if (mw->verify->isDefault() ) + verifyClicked(); + break; + + default: + e->ignore(); + break; + } +} + + +void ArtQueryDlg::returnPressed() +{ +} + + +void ArtQueryDlg::slotFemClicked() +{ + resetButton(mw->rb_fem); + resetButton(mw->male); + resetButton(mw->natural); + verifyClicked(); +} + + +void ArtQueryDlg::slotMaleClicked() +{ + resetButton(mw->male); + resetButton(mw->natural); + resetButton(mw->rb_fem); + verifyClicked(); +} + + +void ArtQueryDlg::slotNaturalClicked() +{ + resetButton(mw->natural); + resetButton(mw->male); + resetButton(mw->rb_fem); + verifyClicked(); +} + + +#include "ArtQueryDlg.moc" diff --git a/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlg.h b/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlg.h new file mode 100644 index 00000000..61d84103 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlg.h @@ -0,0 +1,87 @@ +/*************************************************************************** + + query dialog for articles + + ----------------------------------------------------------------------- + + begin : Fri Dec 3 18:28:18 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 ArtQueryDlg_included +#define ArtQueryDlg_included + +#include "ArtQueryDlgForm.h" +#include "QueryDlgBase.h" + +class ArtQueryDlg : public QueryDlgBase +{ + + Q_OBJECT + +public: + ArtQueryDlg( + QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Article &articles); + + ~ArtQueryDlg(); + + void setQuery (QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Article &articles); + +public slots: + virtual void initFocus() const; + +protected: + void keyPressEvent( QKeyEvent *e ); + +protected slots: + void showMoreClicked(); + void showAllClicked(); + void slotFemClicked(); + void slotUser2(); + void knowItClicked(); + void slotNaturalClicked(); + void slotMaleClicked(); + void dontKnowClicked(); + void verifyClicked(); + void returnPressed(); + void timeoutReached(); + +protected: + Article articles; + +private: + ArtQueryDlgForm * mw; +}; + +#endif // ArtQueryDlg_included diff --git a/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlgForm.ui b/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlgForm.ui new file mode 100644 index 00000000..7792ca92 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/ArtQueryDlgForm.ui @@ -0,0 +1,347 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ArtQueryDlgForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ArtQueryDlgForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>369</width> + <height>240</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Select the correct article for this noun:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>orgField</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QButtonGroup" row="2" column="0"> + <property name="name"> + <cstring>artGroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="title"> + <string></string> + </property> + <property name="layoutSpacing" stdset="0"> + </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="QRadioButton" row="0" column="0"> + <property name="name"> + <cstring>rb_fem</cstring> + </property> + <property name="text"> + <string>&female</string> + </property> + </widget> + <widget class="QRadioButton" row="1" column="0"> + <property name="name"> + <cstring>male</cstring> + </property> + <property name="text"> + <string>&male</string> + </property> + </widget> + <widget class="QRadioButton" row="2" column="0"> + <property name="name"> + <cstring>natural</cstring> + </property> + <property name="text"> + <string>&neutral</string> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget" row="3" column="0"> + <property name="name"> + <cstring>layout10</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QGroupBox" row="0" column="1" rowspan="2" colspan="1"> + <property name="name"> + <cstring>progressgroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Progress</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="KProgress" row="0" column="1"> + <property name="name"> + <cstring>countbar</cstring> + </property> + </widget> + <widget class="KProgress" row="1" column="1"> + <property name="name"> + <cstring>timebar</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>countlabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Count:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>timelabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Time:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>Cyclelabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="text"> + <string>Cycle:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>progCount</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout9</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>verify</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Verify</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>know_it</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>I &Know It</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="0"> + <property name="name"> + <cstring>show_all</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show &All</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>dont_know</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Do Not Know</string> + </property> + </widget> + </grid> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>status</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + </grid> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>rb_fem</tabstop> + <tabstop>male</tabstop> + <tabstop>natural</tabstop> + <tabstop>show_all</tabstop> + <tabstop>verify</tabstop> + <tabstop>know_it</tabstop> + <tabstop>dont_know</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kprogress.h</includehint> + <includehint>kprogress.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/query-dialogs/MCQueryDlg.cpp b/kvoctrain/kvoctrain/query-dialogs/MCQueryDlg.cpp new file mode 100644 index 00000000..596492ad --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/MCQueryDlg.cpp @@ -0,0 +1,448 @@ +/*************************************************************************** + + multiple choice query dialog + + ----------------------------------------------------------------------- + + begin : Thu Nov 25 11:45:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "MCQueryDlg.h" + +#include <kv_resource.h> + +#include <kapplication.h> +#include <kstandarddirs.h> +#include <klocale.h> +#include <kdebug.h> +#include <kprogress.h> + +#include <qtimer.h> +#include <qlabel.h> +#include <qradiobutton.h> +#include <qbuttongroup.h> +#include <qpushbutton.h> + +#include <algorithm> +using namespace std; + +MCQueryDlg::MCQueryDlg( + QString org, + QString trans, + int entry, + int orgcol, + int transcol, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc) + : QueryDlgBase(i18n("Multiple Choice")) +{ + mw = new MCQueryDlgForm(this); + setMainWidget(mw); + + mw->transgroup->insert(mw->rb_trans1); + mw->transgroup->insert(mw->rb_trans2); + mw->transgroup->insert(mw->rb_trans3); + mw->transgroup->insert(mw->rb_trans4); + mw->transgroup->insert(mw->rb_trans5); + + connect( mw->dont_know, SIGNAL(clicked()), SLOT(dontKnowClicked()) ); + connect( mw->know_it, SIGNAL(clicked()), SLOT(knowItClicked()) ); +// connect( verify, SIGNAL(clicked()), SLOT(verifyClicked()) ); + connect( mw->show_all, SIGNAL(clicked()), SLOT(showItClicked()) ); + connect( mw->rb_trans5, SIGNAL(clicked()), SLOT(trans5clicked()) ); + connect( mw->rb_trans4, SIGNAL(clicked()), SLOT(trans4clicked()) ); + connect( mw->rb_trans3, SIGNAL(clicked()), SLOT(trans3clicked()) ); + connect( mw->rb_trans2, SIGNAL(clicked()), SLOT(trans2clicked()) ); + connect( mw->rb_trans1, SIGNAL(clicked()), SLOT(trans1clicked()) ); + + qtimer = 0; + + setQuery (org, trans, entry, orgcol, transcol, q_cycle, q_num, q_start, exp, doc); + mw->countbar->setFormat("%v/%m"); + mw->timebar->setFormat("%v"); + resize(configDialogSize("MCQueryDialog")); +} + + +MCQueryDlg::~MCQueryDlg() +{ + saveDialogSize("MCQueryDialog"); +} + + +void MCQueryDlg::setQuery(QString org, + QString trans, + int entry, + int orgcol, + int transcol, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc) +{ + //type_timeout = type_to; + kv_doc = doc; + q_row = entry; + q_ocol = orgcol; + q_tcol = transcol; + translation = trans; + mw->timebar->setEnabled(Prefs::showCounter()); + mw->timelabel->setEnabled(Prefs::showCounter()); + mw->orgField->setFont(Prefs::tableFont()); + mw->orgField->setText (org); + mw->show_all->setDefault(true); + QString s; + s.setNum (q_cycle); + mw->progCount->setText (s); + + mw->countbar->setTotalSteps(q_start); + mw->countbar->setProgress(q_start - q_num + 1); + int mqtime = Prefs::maxTimePer(); + if (mqtime > 0) { + if (qtimer == 0) { + qtimer = new QTimer( this ); + connect( qtimer, SIGNAL(timeout()), this, SLOT(timeoutReached()) ); + } + + if (Prefs::queryTimeout() != Prefs::EnumQueryTimeout::NoTimeout) { + timercount = mqtime; + mw->timebar->setTotalSteps(timercount); + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + else + mw->timebar->setEnabled(false); + } + else + mw->timebar->setEnabled(false); + + vector<QString> strings; + button_ref.clear(); + button_ref.push_back(RB_Label(mw->rb_trans1, mw->trans1)); + button_ref.push_back(RB_Label(mw->rb_trans2, mw->trans2)); + button_ref.push_back(RB_Label(mw->rb_trans3, mw->trans3)); + button_ref.push_back(RB_Label(mw->rb_trans4, mw->trans4)); + button_ref.push_back(RB_Label(mw->rb_trans5, mw->trans5)); + random_shuffle(button_ref.begin(), button_ref.end() ); + resetButton(button_ref[0].rb, button_ref[0].label); + resetButton(button_ref[1].rb, button_ref[1].label); + resetButton(button_ref[2].rb, button_ref[2].label); + resetButton(button_ref[3].rb, button_ref[3].label); + resetButton(button_ref[4].rb, button_ref[4].label); + + solution = 0; + + MultipleChoice mc = exp->getMultipleChoice(q_tcol); + for (unsigned i = 0; i < QMIN(MAX_MULTIPLE_CHOICE, mc.size()); ++i) + strings.push_back(mc.mc(i)); + std::random_shuffle(strings.begin(), strings.end()); + + // always include false friend + QString ff; + if (q_tcol != 0) + ff = exp->getFauxAmi (q_tcol, false).stripWhiteSpace(); + else + ff = exp->getFauxAmi (q_ocol, true).stripWhiteSpace(); + + if (ff.length()) + strings.insert(strings.begin(), ff); + + if (doc->numEntries() <= MAX_MULTIPLE_CHOICE) { + for (int i = strings.size(); i < doc->numEntries(); ++i ) { + kvoctrainExpr *act = doc->getEntry(i); + + if (act != exp) { + if (q_tcol == 0) + strings.push_back(act->getOriginal()); + else + strings.push_back(act->getTranslation(q_tcol)); + } + } + } + else { + vector<kvoctrainExpr*> exprlist; + solution = 0; + + srand((unsigned int)time((time_t *)NULL)); + int count = MAX_MULTIPLE_CHOICE; + // gather random expressions for the choice + while (count > 0) { + int nr = (int) (doc->numEntries() * ((1.0*rand())/RAND_MAX)); + // append if new expr found + bool newex = true; + for (int i = 0; newex && i < (int) exprlist.size(); i++) { + if (exprlist[i] == doc->getEntry(nr)) + newex = false; + } + if (newex && exp != doc->getEntry(nr)) { + count--; + exprlist.push_back(doc->getEntry(nr)); + } + } + + for (int i = 0; i < (int) exprlist.size(); i++) { + if (q_tcol == 0) + strings.push_back(exprlist[i]->getOriginal()); + else + strings.push_back(exprlist[i]->getTranslation(q_tcol)); + } + + } + + // solution is always the first + if (q_tcol == 0) + strings.insert(strings.begin(), exp->getOriginal()); + else + strings.insert(strings.begin(), exp->getTranslation(q_tcol)); + + for (int i = strings.size(); i < MAX_MULTIPLE_CHOICE; i++ ) + strings.push_back(""); + + if (strings.size() > MAX_MULTIPLE_CHOICE) + strings.erase(strings.begin()+MAX_MULTIPLE_CHOICE, strings.end()); + + button_ref[0].rb->setEnabled(!strings[0].isEmpty() ); + button_ref[1].rb->setEnabled(!strings[1].isEmpty() ); + button_ref[2].rb->setEnabled(!strings[2].isEmpty() ); + button_ref[3].rb->setEnabled(!strings[3].isEmpty() ); + button_ref[4].rb->setEnabled(!strings[4].isEmpty() ); + + button_ref[0].label->setEnabled(!strings[0].isEmpty() ); + button_ref[1].label->setEnabled(!strings[1].isEmpty() ); + button_ref[2].label->setEnabled(!strings[2].isEmpty() ); + button_ref[3].label->setEnabled(!strings[3].isEmpty() ); + button_ref[4].label->setEnabled(!strings[4].isEmpty() ); + + button_ref[0].label->setText(strings[0]); + button_ref[0].label->setFont(Prefs::tableFont()); + button_ref[1].label->setText(strings[1]); + button_ref[1].label->setFont(Prefs::tableFont()); + button_ref[2].label->setText(strings[2]); + button_ref[2].label->setFont(Prefs::tableFont()); + button_ref[3].label->setText(strings[3]); + button_ref[3].label->setFont(Prefs::tableFont()); + button_ref[4].label->setText(strings[4]); + button_ref[4].label->setFont(Prefs::tableFont()); + + mw->rb_trans1->setChecked (false); + mw->rb_trans2->setChecked (false); + mw->rb_trans3->setChecked (false); + mw->rb_trans4->setChecked (false); + mw->rb_trans5->setChecked (false); + + mw->show_all->setFocus(); +} + + +void MCQueryDlg::initFocus() const +{ + mw->rb_trans1->setFocus(); +} + + +void MCQueryDlg::showItClicked() +{ + resetButton(button_ref[0].rb, button_ref[0].label); + resetButton(button_ref[1].rb, button_ref[1].label); + resetButton(button_ref[2].rb, button_ref[2].label); + resetButton(button_ref[3].rb, button_ref[3].label); + resetButton(button_ref[4].rb, button_ref[4].label); + + button_ref[solution].rb->setFocus(); + button_ref[solution].rb->setChecked(true); + verifyButton(button_ref[solution].rb, true, button_ref[solution].label); + mw->dont_know->setDefault(true); +} + + +void MCQueryDlg::verifyClicked() +{ + + bool known = false; + if (solution == 0) + known = button_ref[0].rb->isChecked (); + if (solution == 1) + known = button_ref[1].rb->isChecked (); + if (solution == 2) + known = button_ref[2].rb->isChecked (); + if (solution == 3) + known = button_ref[3].rb->isChecked (); + if (solution == 4) + known = button_ref[4].rb->isChecked (); + + if (button_ref[0].rb->isChecked() ) { + verifyButton(button_ref[0].rb, known, button_ref[0].label); + resetButton(button_ref[1].rb, button_ref[1].label); + resetButton(button_ref[2].rb, button_ref[2].label); + resetButton(button_ref[3].rb, button_ref[3].label); + resetButton(button_ref[4].rb, button_ref[4].label); + } + else if (button_ref[1].rb->isChecked() ) { + resetButton(button_ref[0].rb, button_ref[0].label); + verifyButton(button_ref[1].rb, known, button_ref[1].label); + resetButton(button_ref[2].rb, button_ref[2].label); + resetButton(button_ref[3].rb, button_ref[3].label); + resetButton(button_ref[4].rb, button_ref[4].label); + } + else if (button_ref[2].rb->isChecked() ) { + resetButton(button_ref[0].rb, button_ref[0].label); + resetButton(button_ref[1].rb, button_ref[1].label); + verifyButton(button_ref[2].rb, known, button_ref[2].label); + resetButton(button_ref[3].rb, button_ref[3].label); + resetButton(button_ref[4].rb, button_ref[4].label); + } + else if (button_ref[3].rb->isChecked() ) { + resetButton(button_ref[0].rb, button_ref[0].label); + resetButton(button_ref[1].rb, button_ref[1].label); + resetButton(button_ref[2].rb, button_ref[2].label); + verifyButton(button_ref[3].rb, known, button_ref[3].label); + resetButton(button_ref[4].rb, button_ref[4].label); + } + else if (button_ref[4].rb->isChecked() ) { + resetButton(button_ref[0].rb, button_ref[0].label); + resetButton(button_ref[1].rb, button_ref[1].label); + resetButton(button_ref[2].rb, button_ref[2].label); + resetButton(button_ref[3].rb, button_ref[3].label); + verifyButton(button_ref[4].rb, known, button_ref[4].label); + } + + if (known) { + mw->status->setText(getOKComment((mw->countbar->progress()/mw->countbar->totalSteps()) * 100)); + knowItClicked(); + } + else { + mw->status->setText(getNOKComment((mw->countbar->progress()/mw->countbar->totalSteps()) * 100)); + mw->dont_know->setDefault(true); + } +} + + +void MCQueryDlg::knowItClicked() +{ + mw->status->setText(""); + emit sigQueryChoice (Known); +} + + +void MCQueryDlg::timeoutReached() +{ + if (timercount > 0) { + timercount--; + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + + if (timercount <= 0) { + mw->status->setText(getTimeoutComment((mw->countbar->progress()/mw->countbar->totalSteps()) * 100)); + mw->timebar->setProgress(0); + if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Show) + { + showItClicked(); + mw->dont_know->setDefault(true); + } + else if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Continue) + emit sigQueryChoice (Timeout); + } + else + mw->status->setText(""); +} + + +void MCQueryDlg::dontKnowClicked() +{ + mw->status->setText(""); + emit sigQueryChoice (Unknown); +} + + +void MCQueryDlg::slotUser2() +{ + + if (qtimer != 0) + qtimer->stop(); + + emit sigEditEntry (q_row, KV_COL_ORG+q_ocol); + + kvoctrainExpr *exp = kv_doc->getEntry(q_row); + mw->orgField->setText (q_ocol == 0 + ? exp->getOriginal() + : exp->getTranslation(q_ocol)); +} + + +void MCQueryDlg::keyPressEvent( QKeyEvent *e ) +{ + switch( e->key() ) + { + case Key_Escape: + dontKnowClicked(); + break; + + case Key_Return: + case Key_Enter: + if (mw->dont_know->isDefault() ) + dontKnowClicked(); + else if (mw->know_it->isDefault() ) + knowItClicked(); + else if (mw->show_all->isDefault() ) + showItClicked(); + break; + + default: + e->ignore(); + break; + } +} + + +void MCQueryDlg::trans1clicked() +{ + verifyClicked(); +} + + +void MCQueryDlg::trans2clicked() +{ + verifyClicked(); +} + + +void MCQueryDlg::trans3clicked() +{ + verifyClicked(); +} + + +void MCQueryDlg::trans4clicked() +{ + verifyClicked(); +} + + +void MCQueryDlg::trans5clicked() +{ + verifyClicked(); +} + + +#include "MCQueryDlg.moc" diff --git a/kvoctrain/kvoctrain/query-dialogs/MCQueryDlg.h b/kvoctrain/kvoctrain/query-dialogs/MCQueryDlg.h new file mode 100644 index 00000000..4e94f9db --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/MCQueryDlg.h @@ -0,0 +1,90 @@ +/*************************************************************************** + + multiple choice query dialog + + ----------------------------------------------------------------------- + + begin : Thu Nov 25 11:45:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 MCQuery_Dlg_H +#define MCQuery_Dlg_H + +#include "MCQueryDlgForm.h" +#include "QueryDlgBase.h" + +class MCQueryDlg : public QueryDlgBase +{ + Q_OBJECT + +public: + MCQueryDlg( + QString org, + QString trans, + int entry, + int orgcol, + int transcol, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc); + + ~MCQueryDlg(); + + void setQuery(QString org, + QString trans, + int entry, + int orgcol, + int transcol, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc); + +public slots: + virtual void initFocus() const; + +protected: + void keyPressEvent(QKeyEvent *e); + +public slots: + void showItClicked(); + void knowItClicked(); + void dontKnowClicked(); + void timeoutReached(); + void slotUser2(); + void trans1clicked(); + void trans2clicked(); + void trans3clicked(); + void trans4clicked(); + void trans5clicked(); + void verifyClicked(); + +protected: + int solution; + vector<RB_Label> button_ref; + +private: + MCQueryDlgForm * mw; +}; + +#endif // MCQuery_Dlg_H diff --git a/kvoctrain/kvoctrain/query-dialogs/MCQueryDlgForm.ui b/kvoctrain/kvoctrain/query-dialogs/MCQueryDlgForm.ui new file mode 100644 index 00000000..098bf7fa --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/MCQueryDlgForm.ui @@ -0,0 +1,444 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>MCQueryDlgForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>MCQueryDlgForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>425</width> + <height>335</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Select the correct translation:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>orgField</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QButtonGroup" row="2" column="0"> + <property name="name"> + <cstring>transgroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="title"> + <string></string> + </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="QRadioButton" row="1" column="0"> + <property name="name"> + <cstring>rb_trans2</cstring> + </property> + <property name="text"> + <string>&2:</string> + </property> + </widget> + <widget class="QRadioButton" row="2" column="0"> + <property name="name"> + <cstring>rb_trans3</cstring> + </property> + <property name="text"> + <string>&3:</string> + </property> + </widget> + <widget class="QRadioButton" row="0" column="0"> + <property name="name"> + <cstring>rb_trans1</cstring> + </property> + <property name="text"> + <string>&1:</string> + </property> + </widget> + <widget class="QRadioButton" row="3" column="0"> + <property name="name"> + <cstring>rb_trans4</cstring> + </property> + <property name="text"> + <string>&4:</string> + </property> + </widget> + <widget class="QRadioButton" row="4" column="0"> + <property name="name"> + <cstring>rb_trans5</cstring> + </property> + <property name="text"> + <string>&5:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>trans3</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter</set> + </property> + </widget> + <widget class="QLabel" row="1" column="1"> + <property name="name"> + <cstring>trans2</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter</set> + </property> + </widget> + <widget class="QLabel" row="0" column="1"> + <property name="name"> + <cstring>trans1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter</set> + </property> + </widget> + <widget class="QLabel" row="3" column="1"> + <property name="name"> + <cstring>trans4</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter</set> + </property> + </widget> + <widget class="QLabel" row="4" column="1"> + <property name="name"> + <cstring>trans5</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter</set> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget" row="3" column="0"> + <property name="name"> + <cstring>layout14</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout12</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>dont_know</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Do Not Know</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="0"> + <property name="name"> + <cstring>show_all</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show &All</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>know_it</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>I &Know It</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>verify</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="focusPolicy"> + <enum>NoFocus</enum> + </property> + <property name="text"> + <string>&Verify</string> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox" row="0" column="1" rowspan="2" colspan="1"> + <property name="name"> + <cstring>progressgroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Progress</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="KProgress" row="0" column="1"> + <property name="name"> + <cstring>countbar</cstring> + </property> + </widget> + <widget class="KProgress" row="1" column="1"> + <property name="name"> + <cstring>timebar</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>countlabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Count:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>timelabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Time:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>Cyclelabel</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="text"> + <string>Cycle:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>progCount</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>status</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + </grid> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>rb_trans1</tabstop> + <tabstop>rb_trans2</tabstop> + <tabstop>rb_trans3</tabstop> + <tabstop>rb_trans4</tabstop> + <tabstop>rb_trans5</tabstop> + <tabstop>show_all</tabstop> + <tabstop>know_it</tabstop> + <tabstop>dont_know</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kprogress.h</includehint> + <includehint>kprogress.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/query-dialogs/Makefile.am b/kvoctrain/kvoctrain/query-dialogs/Makefile.am new file mode 100644 index 00000000..6b7b40b8 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/Makefile.am @@ -0,0 +1,13 @@ +INCLUDES = -I$(srcdir)/.. -I../common-dialogs -I$(srcdir)/../kvt-core -I$(top_builddir)/kvoctrain/kvoctrain/share $(all_includes) + +noinst_LTLIBRARIES = libquerydlg.la + +libquerydlg_la_COMPILE_FIRST = ../common-dialogs/prefs.h + +libquerydlg_la_SOURCES = QueryDlgBase.cpp MCQueryDlgForm.ui \ + RandomQueryDlgForm.ui SimpleQueryDlgForm.ui MCQueryDlg.cpp RandomQueryDlg.cpp \ + SimpleQueryDlg.cpp VerbQueryDlgForm.ui AdjQueryDlgForm.ui ArtQueryDlgForm.ui \ + VerbQueryDlg.cpp AdjQueryDlg.cpp ArtQueryDlg.cpp + +METASOURCES = AUTO + diff --git a/kvoctrain/kvoctrain/query-dialogs/QueryDlgBase.cpp b/kvoctrain/kvoctrain/query-dialogs/QueryDlgBase.cpp new file mode 100644 index 00000000..97b47c57 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/QueryDlgBase.cpp @@ -0,0 +1,334 @@ +/*************************************************************************** + + base class for query dialogs + + ----------------------------------------------------------------------- + + begin : Wed Feb 16 20:50:53 MET 2000 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "QueryDlgBase.h" + +#include <qlineedit.h> +#include <qmultilineedit.h> +#include <qradiobutton.h> + +#include <LineList.h> + +#include <klocale.h> + +QueryDlgBase::QueryDlgBase(const QString & caption, QWidget *parent, const char *name, bool modal) + : KDialogBase(Swallow, caption, User1|User2, NoDefault, parent, name, modal, false, + KGuiItem(i18n("&Stop Query")), KGuiItem(i18n("&Edit Expression..."))) +{ + kv_doc = 0; + kv_exp = 0; + //type_timeout = kvq_notimeout; +} + + +QueryDlgBase::~QueryDlgBase () +{ +} + + +void QueryDlgBase::initFocus() const +{ + // +} + + +bool QueryDlgBase::smartCompare (const QString& s1, const QString &s2, + int ) const +{ + return s1.stripWhiteSpace() == s2.stripWhiteSpace(); +} + + +bool QueryDlgBase::verifyField(QLineEdit *field, const QString &really) +{ + if (!field->isEnabled() ) + return true; + + QColorGroup u_normal = field->colorGroup(); + u_normal.setColor(QColorGroup::Text, QColor(0xff, 0x00, 0x00)); + QColorGroup k_normal = field->colorGroup(); + k_normal.setColor(QColorGroup::Text, QColor(0x00, 0x80, 0x00)); + + QPalette known_pal( field->palette()); + QPalette unknown_pal( field->palette()); + + QFont ft = field->font(); + if (ft.weight() != QFont::Bold) { + ft.setWeight(QFont::Bold); + field->setFont(ft); + } + + bool ret = false; + if (smartCompare(really, field->text(), 0) ) { + ret = true; + if ( known_pal.inactive() != k_normal + || known_pal.active() != k_normal) { + // replace text colors + known_pal.setActive(k_normal); + known_pal.setInactive(k_normal); + field->setPalette( known_pal ); + } + } + else + if ( unknown_pal.inactive() != u_normal + || unknown_pal.active() != u_normal) { + // replace text colors + unknown_pal.setActive(u_normal); + unknown_pal.setInactive(u_normal); + field->setPalette( unknown_pal ); + } + return ret; +} + + +void QueryDlgBase::resetField(QLineEdit *field) +{ + if (!field->isEnabled() ) + return; + QColorGroup normal = field->colorGroup(); + normal.setColor(QColorGroup::Text, QColor(0x00, 0x00, 0x00)); + + QPalette pal( field->palette()); + // replace text colors + + if ( pal.inactive() != normal + || pal.active() != normal) { + pal.setActive(normal); + pal.setInactive(normal); + field->setPalette( pal ); + } + + QFont ft = field->font(); + if (ft.weight() != QFont::Normal) { + ft.setWeight(QFont::Normal); + field->setFont(ft); + } +} + + +bool QueryDlgBase::verifyField(QMultiLineEdit *field, const QString &really, bool mixed) +{ + if (!field->isEnabled()) + return true; + QColorGroup u_normal = field->colorGroup(); + u_normal.setColor(QColorGroup::Text, QColor(0xff, 0x00, 0x00)); + QColorGroup k_normal = field->colorGroup(); + k_normal.setColor(QColorGroup::Text, QColor(0x00, 0x80, 0x00)); + + QPalette known_pal( field->palette()); + QPalette unknown_pal( field->palette()); + + QFont ft = field->font(); + if (ft.weight() != QFont::Bold) { + ft.setWeight(QFont::Bold); + field->setFont(ft); + } + + bool ret = false; + bool equal = false; + LineList answerlist (really); + LineList inputlist (field->text()); + if (!mixed) // no tolerance + equal = smartCompare(answerlist.allLines(), inputlist.allLines(), 0); + else { + bool all = true; + for (int ai = 0; ai < (int) answerlist.count(); ai++) { + bool found = false; + for (int ii = 0; ii < (int) inputlist.count(); ii++) { + if (answerlist.getLine (ai) == inputlist.getLine(ii) ) { + found = true; + break; + } + } + if (!found) + all = false; + } + if (all) + equal = true; + } + + if (equal) { + ret = true; + if (known_pal.inactive() != k_normal + || known_pal.active() != k_normal) { + // replace text colors + known_pal.setActive(k_normal); + known_pal.setInactive(k_normal); + field->setPalette( known_pal ); + } + } + else + if ( unknown_pal.inactive() != u_normal + || unknown_pal.active() != u_normal) { + // replace text colors + unknown_pal.setActive(u_normal); + unknown_pal.setInactive(u_normal); + field->setPalette( unknown_pal ); + } + return ret; +} + + +void QueryDlgBase::resetField(QMultiLineEdit *field) +{ + if (!field->isEnabled() ) + return; + QColorGroup normal = field->colorGroup(); + normal.setColor(QColorGroup::Text, QColor(0x00, 0x00, 0x00)); + + QPalette pal( field->palette()); + // replace text colors + + if ( pal.inactive() != normal + || pal.active() != normal) { + pal.setActive(normal); + pal.setInactive(normal); + field->setPalette( pal ); + } + + QFont ft = field->font(); + if (ft.weight() != QFont::Normal) { + ft.setWeight(QFont::Normal); + field->setFont(ft); + } +} + + +void QueryDlgBase::verifyButton(QRadioButton *radio, bool is_ok, QWidget *widget2) +{ + if (!radio->isEnabled() ) + return; + + QColorGroup u_normal = radio->colorGroup(); + u_normal.setColor(QColorGroup::Foreground, QColor(0xff, 0x00, 0x00)); + QColorGroup k_normal = radio->colorGroup(); + k_normal.setColor(QColorGroup::Foreground, QColor(0x00, 0x80, 0x00)); + + QPalette known_pal( radio->palette()); + QPalette unknown_pal( radio->palette()); + + // replace text colors + + QFont ft = radio->font(); + if (ft.weight() != QFont::Bold) { + ft.setWeight(QFont::Bold); + radio->setFont(ft); + } + + if (widget2 != 0) { + ft = widget2->font(); + if (ft.weight() != QFont::Bold) { + ft.setWeight(QFont::Bold); + widget2->setFont(ft); + } + } + + if (is_ok) { + if ( known_pal.inactive() != k_normal + || known_pal.active() != k_normal) { + known_pal.setActive(k_normal); + known_pal.setInactive(k_normal); + radio->setPalette( known_pal ); + if (widget2 != 0) + widget2->setPalette( known_pal ); + } + } + else { + if ( unknown_pal.inactive() != u_normal + || unknown_pal.active() != u_normal) { + unknown_pal.setActive(u_normal); + unknown_pal.setInactive(u_normal); + radio->setPalette( unknown_pal ); + if (widget2 != 0) + widget2->setPalette( unknown_pal ); + } + } +} + + + +void QueryDlgBase::resetButton(QRadioButton *radio, QWidget *widget2) +{ + if (!radio->isEnabled() ) + return; + QColorGroup normal = radio->colorGroup(); + normal.setColor(QColorGroup::Foreground, QColor(0x00, 0x00, 0x00)); + + QPalette pal(radio->palette()); + // replace text colors, avoid flickering + if ( pal.inactive() != normal + || pal.active() != normal) { + pal.setActive(normal); + pal.setInactive(normal); + radio->setPalette( pal ); + if (widget2 != 0) + widget2->setPalette( pal ); + } + + QFont ft = radio->font(); + if (ft.weight() != QFont::Normal) { + ft.setWeight(QFont::Normal); + radio->setFont(ft); + } + + if (widget2 != 0) { + ft = widget2->font(); + if (ft.weight() != QFont::Normal) { + ft.setWeight(QFont::Normal); + widget2->setFont(ft); + } + } +} + + +QString QueryDlgBase::getOKComment(int percent_done) +{ + return i18n("Well done, you knew the correct answer. %1% done.").arg(percent_done); +} + + +QString QueryDlgBase::getTimeoutComment(int percent_done) +{ + return i18n("You waited too long to enter the correct answer. %1% done.").arg(percent_done); +} + + +QString QueryDlgBase::getNOKComment(int percent_done) +{ + return i18n("Your answer was wrong. %1% done.").arg(percent_done); +} + +void QueryDlgBase::closeEvent(QCloseEvent * /*e*/) +{ + emit sigQueryChoice(StopIt); +} + +void QueryDlgBase::slotUser1() +{ + emit sigQueryChoice(StopIt); +} + + +#include "QueryDlgBase.moc" diff --git a/kvoctrain/kvoctrain/query-dialogs/QueryDlgBase.h b/kvoctrain/kvoctrain/query-dialogs/QueryDlgBase.h new file mode 100644 index 00000000..6f62ddf0 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/QueryDlgBase.h @@ -0,0 +1,111 @@ +/*************************************************************************** + + base class for query dialogs + + ----------------------------------------------------------------------- + + begin : Thu Nov 25 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 Query_Dlg_Base_H +#define Query_Dlg_Base_H + +#include <time.h> +#include <stdlib.h> + +#include <kdialogbase.h> + +#include <QueryManager.h> +#include <grammarmanager.h> + +class kvoctrainExpr; +class kvoctrainDoc; + +class QLineEdit; +class QMultiLineEdit; +class QLabel; +class QRadioButton; + +class QueryDlgBase : public KDialogBase +{ + + Q_OBJECT + +public: + enum Result { Unknown, Known, Timeout, StopIt }; + + QueryDlgBase(const QString & caption, QWidget *parent = 0, const char *name = 0, bool modal = false); + + virtual ~QueryDlgBase (); + + bool smartCompare (const QString&, const QString&, int level) const; + + bool verifyField(QLineEdit *field, const QString &really); + void resetField (QLineEdit *field); + + bool verifyField(QMultiLineEdit *field, const QString &really, + bool mixed); + void resetField (QMultiLineEdit *field); + + void verifyButton(QRadioButton *radio, bool is_ok, QWidget *widget2 = 0); + void resetButton (QRadioButton *radio, QWidget *widget2 = 0); + + // Show string after selceting known/unknown + // depending on progress and randomness + QString getOKComment(int percent); + QString getNOKComment(int percent); + QString getTimeoutComment(int percent); + + int getRandom(int range) + { +// srand((unsigned int)time((time_t *)NULL)); + return (int) (range * ((1.0*rand())/RAND_MAX)); + } + + virtual void initFocus() const; + +signals: + void sigQueryChoice(QueryDlgBase::Result); + void sigEditEntry(int row, int col); + +protected: + virtual void closeEvent(QCloseEvent*e); + virtual void slotUser1(); + + struct RB_Label { + RB_Label (QRadioButton* _rb, QLabel *_label) + : rb(_rb), label(_label) {} + + QRadioButton *rb; + QLabel *label; + }; + + int q_row, + q_ocol, + q_tcol; + kvoctrainDoc *kv_doc; + kvoctrainExpr *kv_exp; + QString translation; + QTimer *qtimer; + int timercount; +}; + + +#endif // Query_Dlg_Base_H diff --git a/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlg.cpp b/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlg.cpp new file mode 100644 index 00000000..be309563 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlg.cpp @@ -0,0 +1,690 @@ +/*************************************************************************** + + dialog when in query mode + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "RandomQueryDlg.h" +#include "common-dialogs/ProgressDlg.h" + +#include <kv_resource.h> + +#include <kstandarddirs.h> +#include <klocale.h> +#include <kapplication.h> +#include <kprogress.h> + +#include <qcheckbox.h> +#include <qgroupbox.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qpushbutton.h> +#include <qregexp.h> +#include <qtimer.h> + +QStringList RandomQueryDlg::extractTranslations (QString trans) +{ + QRegExp full_stop ("^(.*[^\\. ])\\.* *$"); + //full_stop.setMinimal (true); + if ( full_stop.search (trans) >= 0 ) + trans = full_stop.cap (1); + int i; + QStringList translations; + if ( Prefs::periods() ) + for ( i = fields - 1; i > 0; i -- ) + { + QString regexp ("^ *"); + for ( int j = 0; j < i; j ++ ) + regexp += "([^ ][^.]*)\\.[. ]*"; + regexp += "([^. ].*)$"; + QRegExp regex (regexp); + if ( regex.search (trans) >= 0 ) + { + translations = regex.capturedTexts(); + translations.remove (translations.at (0)); + break; + } + } + if ( Prefs::colons() && translations.count() <= 1 ) + { + translations.clear(); + for ( i = fields - 1; i > 0; i -- ) + { + QString regexp ("^ *"); + for ( int j = 0; j < i; j ++ ) + regexp += "([^ ][^:]*):[: ]*"; + regexp += "([^: ].*)$"; + QRegExp regex (regexp); + if ( regex.search (trans) >= 0 ) + { + translations = regex.capturedTexts(); + translations.remove (translations.at (0)); + break; + } + } + } + if ( Prefs::semicolons() && translations.count() <= 1 ) + { + translations.clear(); + for ( i = fields - 1; i > 0; i -- ) + { + QString regexp ("^ *"); + for ( int j = 0; j < i; j ++ ) + regexp += "([^ ][^;]*);[; ]*"; + regexp += "([^; ].*)$"; + QRegExp regex (regexp); + if ( regex.search (trans) >= 0 ) + { + translations = regex.capturedTexts(); + translations.remove (translations.at (0)); + break; + } + } + } + if ( Prefs::commas() && translations.count() <= 1 ) + { + translations.clear(); + for ( i = fields - 1; i > 0; i -- ) + { + QString regexp ("^ *"); + for ( int j = 0; j < i; j ++ ) + regexp += "([^ ][^,]*),[, ]*"; + regexp += "([^, ].*)$"; + QRegExp regex (regexp); + if ( regex.search (trans) >= 0 ) + { + translations = regex.capturedTexts(); + translations.remove (translations.at (0)); + break; + } + } + } + if ( translations.count() <= 1 ) + translations = QStringList (trans); + return translations; +} + +RandomQueryDlg::RandomQueryDlg( + QString org, + QString trans, + int entry, + int orgcol, + int transcol, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc) + : QueryDlgBase(i18n("Random Query")) +{ + mw = new QueryDlgForm(this); + setMainWidget(mw); + + connect( mw->c_type, SIGNAL(clicked()), SLOT(slotTypeClicked()) ); + connect( mw->c_remark, SIGNAL(clicked()), SLOT(slotRemClicked()) ); + connect( mw->c_falsefriend, SIGNAL(clicked()), SLOT(slotFFClicked()) ); + connect( mw->dont_know, SIGNAL(clicked()), SLOT(dontKnowClicked()) ); + connect( mw->know_it, SIGNAL(clicked()), SLOT(knowItClicked()) ); + connect( mw->verify, SIGNAL(clicked()), SLOT(verifyClicked()) ); + connect( mw->show_all, SIGNAL(clicked()), SLOT(showAllClicked()) ); + connect( mw->show_more, SIGNAL(clicked()), SLOT(showMoreClicked()) ); + + mw->show_more -> setEnabled (Prefs::showMore()); + mw->know_it -> setEnabled (Prefs::iKnow()); + + bool split = Prefs::split(); + fields = Prefs::fields(); + if ( ! split || fields < 1 ) + fields = 1; + else if ( fields > 10 ) + fields = 10; + + QVBoxLayout * vb = new QVBoxLayout(mw->TranslationFrame, 0, KDialog::spacingHint()); + + bool suggestions = Prefs::suggestions(); + int i; + if ( suggestions ) + { + for ( i = 0; i < fields; i ++ ) + { + transCombos.append (new QComboBox (false, mw->TranslationFrame, QCString ("transCombo") + QCString().setNum (i))); + transCombos.at(i) -> setSizePolicy (QSizePolicy ((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)1, 0, 0, transCombos.at(i) -> sizePolicy().hasHeightForWidth())); + transCombos.at(i) -> setEditable (true); + transCombos.at(i) -> setInsertionPolicy (QComboBox::NoInsertion); + transCombos.at(i) -> setDuplicatesEnabled (false); + vb->addWidget(transCombos.at(i)); + connect (transCombos.at(i), SIGNAL (textChanged (const QString&)), SLOT (slotTransChanged (const QString&))); + connect (transCombos.at(i) -> lineEdit(), SIGNAL (lostFocus()), SLOT (slotTransLostFocus())); + } + } + else + { + for ( i = 0; i < fields; i ++ ) + { + transFields.append (new QLineEdit (mw->TranslationFrame, QCString ("transField") + QCString().setNum (i))); + transFields.at(i) -> setSizePolicy (QSizePolicy ((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)1, 0, 0, transFields.at(i) -> sizePolicy().hasHeightForWidth())); + vb->addWidget(transFields.at(i)); + connect (transFields.at(i), SIGNAL (textChanged (const QString&)), SLOT (slotTransChanged (const QString&))); + connect (transFields.at(i), SIGNAL (lostFocus()), SLOT (slotTransLostFocus())); + } + } + + kv_doc = 0; + qtimer = 0; + //setCaption (kapp->makeStdCaption(i18n("Random Query"))); + setQuery (org, trans, entry, orgcol, transcol, q_cycle, q_num, q_start, exp, doc); + mw->countbar->setFormat("%v/%m"); + mw->timebar->setFormat("%v"); + + if ( suggestions ) + { + ProgressDlg* pdlg = 0; + if ( split && kv_doc -> numEntries() >= 500 ) + { + pdlg = new ProgressDlg (QString(), QString(), kapp -> makeStdCaption (i18n("Loading Random Query"))); + pdlg -> resize (pdlg -> width(), pdlg -> minimumSize().height()); + pdlg -> show(); + kapp -> processEvents(); + } + for ( i = 0; i < kv_doc -> numEntries(); i ++ ) + { + kvoctrainExpr* expr = kv_doc -> getEntry (i); + if ( split ) + vocabulary += extractTranslations (q_tcol ? expr -> getTranslation (q_tcol) : expr -> getOriginal()); + else + vocabulary += q_tcol ? expr -> getTranslation (q_tcol) : expr -> getOriginal(); + if ( Prefs::swapDirection() ) + { + if ( split ) + vocabulary += extractTranslations (q_ocol ? expr -> getTranslation (q_ocol) : expr -> getOriginal()); + else + vocabulary += q_ocol ? expr -> getTranslation (q_ocol) : expr -> getOriginal(); + } + if ( pdlg ) + { + pdlg -> setValue (doc, i * 100 / kv_doc -> numEntries()); + kapp -> processEvents(); + } + } + vocabulary.sort(); + for ( uint k = 1; k < vocabulary.count(); k ++ ) + if ( vocabulary [k - 1] == vocabulary [k] ) + vocabulary.remove (vocabulary.at (k --)); + if ( pdlg ) + delete pdlg; + } + resize(configDialogSize("RandomQueryDialog")); +} + + +RandomQueryDlg::~RandomQueryDlg() +{ + saveDialogSize("RandomQueryDialog"); +} + + +void RandomQueryDlg::setQuery(QString org, + QString trans, + int entry, + int orgcol, + int transcol, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *, + kvoctrainDoc *doc) +{ + //type_timeout = type_to; + kv_doc = doc; + q_row = entry; + q_ocol = orgcol; + q_tcol = transcol; + translation = trans; + if ( Prefs::split() ) + translations = extractTranslations (trans); + else + translations = trans; + mw->timebar->setEnabled(Prefs::showCounter()); + mw->timelabel->setEnabled(Prefs::showCounter()); + int i; + uint k; + if ( Prefs::suggestions() ) + { + for ( i = 0; i < fields; i ++ ) + { + transCombos.at(i) -> clearEdit(); + resetField (transCombos.at(i) -> lineEdit()); + } + for ( k = 0; k < translations.count(); k ++ ) + transCombos.at(k) -> show(); + for ( i = k; i < fields; i ++ ) + transCombos.at(i) -> hide(); + } + else + { + for ( i = 0; i < fields; i ++ ) + { + transFields.at(i) -> clear(); + transFields.at(i) -> setFont (Prefs::tableFont()); + resetField (transFields.at(i)); + } + for ( k = 0; k < translations.count(); k ++ ) + transFields.at(k) -> show(); + for ( i = k; i < fields; i ++ ) + transFields.at(i) -> hide(); + } + mw->verify -> setEnabled (true); + mw->orgField->setFont(Prefs::tableFont()); + mw->orgField->setText (org); + mw->show_all->setDefault(true); + QString s; + s.setNum (q_cycle); + mw->progCount->setText (s); + + mw->remark->hide(); + mw->falseFriend->hide(); + mw->type->hide(); + + mw->c_remark->setChecked(false); + mw->c_falsefriend->setChecked(false); + mw->c_type->setChecked(false); + setHintFields(); + + mw->countbar->setTotalSteps(q_start); + mw->countbar->setProgress(q_start - q_num + 1); + int mqtime = Prefs::maxTimePer(); + if (mqtime > 0) { + if (qtimer == 0) { + qtimer = new QTimer( this ); + connect( qtimer, SIGNAL(timeout()), this, SLOT(timeoutReached()) ); + } + + if (Prefs::queryTimeout() != Prefs::EnumQueryTimeout::NoTimeout) { + timercount = mqtime; + mw->timebar->setTotalSteps(timercount); + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + else + mw->timebar->setEnabled(false); + } + else + mw->timebar->setEnabled(false); + + mw->status -> clear(); + suggestion_hint = false; +} + + +void RandomQueryDlg::initFocus() const +{ + RandomQueryDlg* that = (RandomQueryDlg*) this; + if ( Prefs::suggestions() ) + that -> transCombos.at(0) -> setFocus(); + else + that -> transFields.at(0) -> setFocus(); +} + + +void RandomQueryDlg::verifyClicked() +{ + QStringList trans (translations); + uint i, j; + if ( Prefs::suggestions() ) + { + QPtrList<QComboBox> combos (transCombos); + for ( i = combos.count() - 1; i >= translations.count(); i -- ) + combos.remove (i); + for ( i = 0; i < combos.count(); i ++ ) + for ( j = 0; j < trans.count(); j ++ ) + if ( smartCompare (trans[j], combos.at(i) -> currentText(), 0) ) + { + verifyField (combos.at(i) -> lineEdit(), trans[j]); + trans.remove (trans.at(j)); + combos.remove (i --); + break; + } + if ( trans.count() == 0 ) + { + int percent = (mw->countbar->progress()/mw->countbar->totalSteps()) * 100; + //status->setText(getOKComment(countbar->getPercentage())); + mw->status->setText(getOKComment(percent)); + knowItClicked(); + } + else + { + for ( i = 0; i < combos.count(); i ++ ) + verifyField (combos.at(i) -> lineEdit(), "a\na"); // always fail + mw->status->setText(getNOKComment((mw->countbar->progress()/mw->countbar->totalSteps()) * 100)); + mw->dont_know->setDefault(true); + } + } + else + { + QPtrList<QLineEdit> fields (transFields); + for ( i = fields.count() - 1; i >= translations.count(); i -- ) + fields.remove (i); + for ( i = 0; i < fields.count(); i ++ ) + for ( j = 0; j < trans.count(); j ++ ) + if ( smartCompare (trans[j], fields.at(i) -> text(), 0) ) + { + verifyField (fields.at(i), "a\na"); // always fail + trans.remove (trans.at(j)); + fields.remove (i --); + break; + } + if ( trans.count() == 0 ) + { + mw->status->setText(getOKComment((mw->countbar->progress()/mw->countbar->totalSteps()) * 100)); + knowItClicked(); + } + else + { + for ( i = 0; i < fields.count(); i ++ ) + verifyField (fields.at(i), trans[i]); + mw->status->setText(getNOKComment((mw->countbar->progress()/mw->countbar->totalSteps()) * 100)); + mw->dont_know->setDefault(true); + } + } + suggestion_hint = false; +} + + +void RandomQueryDlg::showMoreClicked() +{ + if ( Prefs::suggestions() ) + for ( uint i = 0; i < translations.count(); i ++ ) + { + QComboBox* combo = transCombos.at(i); + if ( ! smartCompare (combo -> currentText(), translations[i], 0) ) + { + uint length = combo -> currentText().length() + 1; + if ( length >= translations[i].length() ) + { + combo -> setEditText (translations[i]); + verifyField (combo -> lineEdit(), translations[i]); + mw->verify -> setEnabled (false); + } + else + { + combo -> setEditText (translations[i].left (length)); + resetField (combo -> lineEdit()); + } + mw->dont_know -> setDefault (true); + break; + } + } + else + for ( uint i = 0; i < translations.count(); i ++ ) + { + QLineEdit* field = transFields.at(i); + if ( ! smartCompare (field -> text(), translations[i], 0) ) + { + uint length = field -> text().length() + 1; + if ( length >= translations[i].length() ) + { + field -> setText (translations[i]); + verifyField (field, translations[i]); + mw->verify -> setEnabled (false); + } + else + { + field -> setText (translations[i].left (length)); + resetField (field); + } + mw->dont_know -> setDefault (true); + break; + } + } + mw->status -> clear(); + suggestion_hint = false; +} + + +void RandomQueryDlg::showAllClicked() +{ + if ( Prefs::suggestions() ) + for ( uint i = 0; i < translations.count(); i ++ ) + { + transCombos.at(i) -> setEditText (translations[i]); + verifyField (transCombos.at(i) -> lineEdit(), translations[i]); + } + else + for ( uint i = 0; i < translations.count(); i ++ ) + { + transFields.at(i) -> setText (translations[i]); + verifyField (transFields.at(i), translations[i]); + } + mw->verify -> setEnabled (false); + mw->dont_know->setDefault(true); + mw->status -> clear(); + suggestion_hint = false; +} + + +void RandomQueryDlg::slotTransChanged(const QString&) +{ + mw->verify->setDefault(true); + bool suggestions = Prefs::suggestions(); + if ( suggestions && sender() && sender() -> isA ("QComboBox") ) + { + QLineEdit* edit = ((QComboBox*) sender()) -> lineEdit(); + resetField (edit); + suggestion_hint = ! edit -> text().isEmpty() && edit -> text().length() <= 10; + if ( suggestion_hint ) + mw->status -> setText (QString (i18n("Press F5 for a list of translations starting with '%1'\n" + "Press F6 for a list of translations containing '%2'")).arg (edit -> text()).arg (edit -> text())); + else + mw->status -> clear(); + } + else if ( ! suggestions && sender() && sender() -> isA ("QLineEdit") ) + resetField ((QLineEdit*) sender()); +} + +void RandomQueryDlg::slotTransLostFocus() +{ + if ( suggestion_hint ) + mw->status -> clear(); + suggestion_hint = false; +} + + +void RandomQueryDlg::knowItClicked() +{ + mw->status -> clear(); + suggestion_hint = false; + emit sigQueryChoice (Known); +} + + +void RandomQueryDlg::timeoutReached() +{ + if (timercount > 0) { + timercount--; + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + + if (timercount <= 0) { + mw->timebar->setProgress(0); + if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Show) { + showAllClicked(); + mw->dont_know->setDefault(true); + } + else if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Continue) { + emit sigQueryChoice (Timeout); + } + mw->status->setText(getTimeoutComment((mw->countbar->progress()/mw->countbar->totalSteps()) * 100)); + } + + suggestion_hint = false; +} + + +void RandomQueryDlg::dontKnowClicked() +{ + mw->status -> clear(); + suggestion_hint = false; + emit sigQueryChoice (Unknown); +} + + +void RandomQueryDlg::setHintFields() +{ + QString s; + kvoctrainExpr *exp = kv_doc->getEntry(q_row); + + s = exp->getRemark(q_ocol); + mw->remark->setText (s); + mw->c_remark->setEnabled(!s.isEmpty() ); + + s = exp->getFauxAmi(q_ocol, q_ocol != 0); + mw->falseFriend->setText (s); + mw->c_falsefriend->setEnabled(!s.isEmpty() ); + + s = ""; + vector<TypeRelation> all_types = QueryManager::getRelation(false); + for (int i = 0; i < (int) all_types.size(); i++) { + if ( exp->getType(q_ocol) == all_types[i].shortStr()) { + s = all_types[i].longStr(); + break; + } + } + mw->type->setText (s); + mw->c_type->setEnabled(!s.isEmpty() ); +} + + +void RandomQueryDlg::slotUser2() +{ + if (qtimer != 0) + qtimer->stop(); + + emit sigEditEntry (q_row, KV_COL_ORG+q_ocol); + + kvoctrainExpr *exp = kv_doc->getEntry(q_row); + mw->orgField->setText (q_ocol == 0 + ? exp->getOriginal() + : exp->getTranslation(q_ocol)); + + if ( Prefs::suggestions() ) + for ( int i = 0; i < fields; i ++ ) + transCombos.at(i) -> clearEdit(); + else + for ( int i = 0; i < fields; i ++ ) + transFields.at(i) -> clear(); + mw->status -> clear(); + suggestion_hint = false; + + setHintFields(); +} + + +void RandomQueryDlg::slotFFClicked() +{ + if (mw->c_falsefriend->isChecked() ) + mw->falseFriend->show(); + else + mw->falseFriend->hide(); +} + + +void RandomQueryDlg::slotRemClicked() +{ + if (mw->c_remark->isChecked()) + mw->remark->show(); + else + mw->remark->hide(); +} + + +void RandomQueryDlg::slotTypeClicked() +{ + if (mw->c_type->isChecked() ) + mw->type->show(); + else + mw->type->hide(); +} + + +void RandomQueryDlg::keyPressEvent( QKeyEvent *e ) +{ + if ( Prefs::suggestions() ) + { + QComboBox* combo = 0; + if ( e -> key() == Key_F4 || e -> key() == Key_F5 || e -> key() == Key_F6 ) + for ( uint i = 0; i < translations.count(); i ++ ) + if ( transCombos.at(i) -> hasFocus() ) + { + combo = transCombos.at(i); + break; + } + switch( e->key() ) + { + case Key_F5: + case Key_F6: + if ( combo && ! combo -> currentText().isEmpty() ) + { + QString curText (combo -> currentText()); + combo -> clear(); + for ( uint i = 0; i < vocabulary.count(); i ++ ) + { + QString trans (vocabulary[i]); + if ( (e -> key() == Key_F5 && trans.startsWith (curText, false) + || e -> key() == Key_F6 && trans.contains (curText, false)) ) + combo -> insertItem (trans); + } + combo -> setEditText (curText); + } + case Key_F4: + if ( combo ) + combo -> popup(); + break; + } + } + + switch( e->key() ) + { + case Key_Escape: + dontKnowClicked(); + break; + + case Key_Return: + case Key_Enter: + if (mw->dont_know->isDefault() ) + dontKnowClicked(); + else if (mw->know_it->isDefault() ) + knowItClicked(); + else if (mw->show_all->isDefault() ) + showAllClicked(); + else if (mw->verify->isDefault() ) + verifyClicked(); + break; + + default: + e->ignore(); + break; + } +} + +#include "RandomQueryDlg.moc" diff --git a/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlg.h b/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlg.h new file mode 100644 index 00000000..92ab7fd7 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlg.h @@ -0,0 +1,106 @@ +/*************************************************************************** + + dialog when in random query mode + + ----------------------------------------------------------------------- + + begin : Thu Mar 11 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 Query_Dlg_H +#define Query_Dlg_H + +#include "RandomQueryDlgForm.h" +#include "QueryDlgBase.h" + +#include <qcombobox.h> +#include <qlineedit.h> + +class kvoctrainDoc; + +class RandomQueryDlg : public QueryDlgBase +{ + Q_OBJECT + +public: + RandomQueryDlg( + QString org, + QString trans, + int entry, + int orgcol, + int transcol, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *); + + ~RandomQueryDlg(); + + void setQuery(QString org, + QString trans, + int entry, + int orgcol, + int transcol, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *); + +public slots: + virtual void initFocus() const; + +public slots: + void verifyClicked(); + void showMoreClicked(); + void showAllClicked(); + void knowItClicked(); + void dontKnowClicked(); + void timeoutReached(); + void slotUser2(); + void slotTransChanged(const QString&); + void slotTransLostFocus(); + void slotFFClicked(); + void slotTypeClicked(); + void slotRemClicked(); + +protected: + virtual void keyPressEvent(QKeyEvent *e); + + void setHintFields(); + QStringList extractTranslations (QString trans); + + kvoctrainDoc * kv_doc; + + QPtrList<QComboBox> transCombos; + QPtrList<QLineEdit> transFields; + + QStringList translations; + QStringList vocabulary; + + bool suggestion_hint; + int fields; + +private: + QueryDlgForm * mw; +}; + +#endif diff --git a/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlgForm.ui b/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlgForm.ui new file mode 100644 index 00000000..fc573bf6 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/RandomQueryDlgForm.ui @@ -0,0 +1,418 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>QueryDlgForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>QueryDlgForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>453</width> + <height>279</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Enter the correct translation:</string> + </property> + </widget> + <widget class="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>GroupBox12</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Original Expression</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="1" column="1"> + <property name="name"> + <cstring>falseFriend</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>remark</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + <widget class="QLabel" row="3" column="1"> + <property name="name"> + <cstring>type</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + <widget class="QCheckBox" row="2" column="0"> + <property name="name"> + <cstring>c_remark</cstring> + </property> + <property name="text"> + <string>&Remark:</string> + </property> + </widget> + <widget class="QCheckBox" row="3" column="0"> + <property name="name"> + <cstring>c_type</cstring> + </property> + <property name="text"> + <string>T&ype:</string> + </property> + </widget> + <widget class="QCheckBox" row="1" column="0"> + <property name="name"> + <cstring>c_falsefriend</cstring> + </property> + <property name="text"> + <string>&False friend:</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>orgField</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + </grid> + </widget> + <widget class="QFrame" row="2" column="0"> + <property name="name"> + <cstring>TranslationFrame</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + </widget> + <spacer row="3" column="0"> + <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>450</width> + <height>40</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget" row="4" column="0"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>status</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>verify</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Verify</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>show_more</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show &More</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="0"> + <property name="name"> + <cstring>show_all</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show &All</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="2"> + <property name="name"> + <cstring>dont_know</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Do Not Know</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="2"> + <property name="name"> + <cstring>know_it</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>I &Know It</string> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox" row="0" column="1" rowspan="2" colspan="1"> + <property name="name"> + <cstring>progressgroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Progress</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>timelabel</cstring> + </property> + <property name="text"> + <string>Time:</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>countlabel</cstring> + </property> + <property name="text"> + <string>Count:</string> + </property> + </widget> + <widget class="KProgress" row="1" column="1"> + <property name="name"> + <cstring>timebar</cstring> + </property> + </widget> + <widget class="KProgress" row="0" column="1"> + <property name="name"> + <cstring>countbar</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>progCount</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>Cyclelabel</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="text"> + <string>Cycle:</string> + </property> + </widget> + </grid> + </widget> + </grid> + </widget> + </grid> +</widget> +<customwidgets> +</customwidgets> +<tabstops> + <tabstop>c_falsefriend</tabstop> + <tabstop>c_remark</tabstop> + <tabstop>c_type</tabstop> + <tabstop>show_all</tabstop> + <tabstop>show_more</tabstop> + <tabstop>verify</tabstop> + <tabstop>know_it</tabstop> + <tabstop>dont_know</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kprogress.h</includehint> + <includehint>kprogress.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlg.cpp b/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlg.cpp new file mode 100644 index 00000000..47421e7a --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlg.cpp @@ -0,0 +1,336 @@ +/*************************************************************************** + + query dialog for properties + + ----------------------------------------------------------------------- + + begin : Sun Apr 9 18:55:34 2000 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "SimpleQueryDlg.h" + +#include <kv_resource.h> + +#include <qtimer.h> +#include <qmultilineedit.h> +#include <qlabel.h> +#include <qpushbutton.h> + +#include <kapplication.h> +#include <kstandarddirs.h> +#include <klocale.h> +#include <kprogress.h> + +SimpleQueryDlg::SimpleQueryDlg( + QueryType querytype, + int entry, + int column, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc) + : QueryDlgBase("") +{ + mw = new SimpleQueryDlgForm(this); + setMainWidget(mw); + + connect(mw->dont_know, SIGNAL(clicked()), SLOT(dontKnowClicked()) ); + connect(mw->know_it, SIGNAL(clicked()), SLOT(knowItClicked()) ); + connect(mw->verify, SIGNAL(clicked()), SLOT(verifyClicked()) ); + connect(mw->show_all, SIGNAL(clicked()), SLOT(showAllClicked()) ); + connect(mw->show_more, SIGNAL(clicked()), SLOT(showMoreClicked()) ); + connect(mw->answerField, SIGNAL(textChanged()), SLOT(slotAnswerChanged()) ); + + kv_doc = 0; + qtimer = 0; + resize(configDialogSize("SimpleQueryDialog")); + setQuery (querytype, entry, column, q_cycle, q_num, q_start, exp, doc); + mw->countbar->setFormat("%v/%m"); + mw->timebar->setFormat("%v"); + +} + + +SimpleQueryDlg::~ SimpleQueryDlg() +{ + saveDialogSize("SimpleQueryDialog"); +} + + +void SimpleQueryDlg::initFocus() const +{ + mw->answerField->setFocus(); +} + + +void SimpleQueryDlg::setQuery(QueryType _querytype, + int entry, + int column, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc) +{ + //type_timeout = type_to; + querytype = _querytype; + kv_doc = doc; + q_row = entry; + q_ocol = column; + mw->timebar->setEnabled(Prefs::showCounter()); + mw->timelabel->setEnabled(Prefs::showCounter()); + mw->queryField->setFont(Prefs::tableFont()); + mw->answerField->setFont(Prefs::tableFont()); + mw->answerField->setText(""); + + QString s; + switch (querytype) + { + case QT_Synonym: + { + mw->queryLabel->setText(i18n("Expression")); + mw->instructionLabel->setText(i18n("Enter the synonym:")); + setCaption (i18n("Synonym Training")); + answerstring = exp->getSynonym(column); + mw->queryField->setAlignment(Qt::AlignVCenter); + mw->queryField->setText(column == 0 ? exp->getOriginal() : exp->getTranslation(column)); + setQueryFieldWordwrap(); + } + break; + + case QT_Antonym: + { + mw->queryLabel->setText(i18n("Expression")); + mw->instructionLabel->setText(i18n("Enter the antonym:")); + setCaption (i18n("Antonym Training")); + answerstring = exp->getAntonym(column); + mw->queryField->setText(column == 0 ? exp->getOriginal() : exp->getTranslation(column)); + setQueryFieldWordwrap(); + } + break; + + case QT_Paraphrase: + { + mw->queryLabel->setText(i18n("Paraphrase")); + mw->instructionLabel->setText(i18n("Enter the word:")); + setCaption (i18n("Paraphrase Training")); + mw->queryField->setText(exp->getParaphrase(column)); + answerstring = column == 0 ? exp->getOriginal() : exp->getTranslation(column); + setQueryFieldWordwrap(); + } + break; + + case QT_Example: + { + mw->queryLabel->setText(i18n("Example sentence")); + mw->instructionLabel->setText(i18n("Fill in the missing word:")); + setCaption(i18n("Example Training")); + s = exp->getExample(column); + answerstring = column == 0 ? exp->getOriginal().stripWhiteSpace() : exp->getTranslation(column).stripWhiteSpace(); + int pos = -1; + while ((pos = s.find(answerstring)) > 0) + { + s.remove(pos, answerstring.length()); + s.insert (pos, ".."); + } + mw->queryField->setText(s); + setQueryFieldWordwrap(); + } + break; + + default: + ; + } + + mw->show_all->setDefault(true); + s.setNum (q_cycle); + mw->progCount->setText (s); + + mw->countbar->setTotalSteps(q_start); + mw->countbar->setProgress(q_start - q_num + 1); + int mqtime = Prefs::maxTimePer(); + + if (mqtime > 0) { + if (qtimer == 0) { + qtimer = new QTimer( this ); + connect( qtimer, SIGNAL(timeout()), this, SLOT(timeoutReached()) ); + } + + if (Prefs::queryTimeout() != Prefs::EnumQueryTimeout::NoTimeout) { + timercount = mqtime; + mw->timebar->setTotalSteps(timercount); + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + else + mw->timebar->setEnabled(false); + } + else + mw->timebar->setEnabled(false); + resetField (mw->answerField); +} + + +void SimpleQueryDlg::slotAnswerChanged() +{ + mw->verify->setDefault(true); + resetField (mw->answerField); +} + + +void SimpleQueryDlg::timeoutReached() +{ + if (timercount > 0) { + timercount--; + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + + if (timercount <= 0) { + mw->timebar->setProgress(0); + if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Show) { + showAllClicked(); + mw->dont_know->setDefault(true); + } + else if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Continue) + emit sigQueryChoice (Timeout); + } +} + + +void SimpleQueryDlg::showMoreClicked() +{ + if (mw->answerField->text().length() < answerstring.length()) { + mw->answerField->setText (answerstring.left(mw->answerField->text().length()+1)); + mw->dont_know->setDefault(true); + } + resetField (mw->answerField); +} + + +void SimpleQueryDlg::showAllClicked() +{ + mw->answerField->setText (answerstring); + verifyField (mw->answerField, answerstring, querytype == QT_Synonym || querytype == QT_Antonym); + mw->dont_know->setDefault(true); +} + + +void SimpleQueryDlg::verifyClicked() +{ + if (verifyField (mw->answerField, answerstring, querytype == QT_Synonym || querytype == QT_Antonym)) + knowItClicked(); + else + mw->dont_know->setDefault(true); +} + + +void SimpleQueryDlg::knowItClicked() +{ + emit sigQueryChoice(Known); +} + + +void SimpleQueryDlg::dontKnowClicked() +{ + emit sigQueryChoice(Unknown); +} + + +void SimpleQueryDlg::slotUser2() +{ + if (qtimer != 0) + qtimer->stop(); + + emit sigEditEntry(q_row, KV_COL_ORG+q_ocol); + + kvoctrainExpr *exp = kv_doc->getEntry(q_row); +// queryField->setText (exp->getTranslation(q_ocol)); + + switch (querytype) { + case QT_Synonym: { + answerstring = exp->getSynonym(q_ocol); + mw->queryField->setText(q_ocol == 0 ? exp->getOriginal() : exp->getTranslation(q_ocol)); + } + break; + + case QT_Antonym: { + answerstring = exp->getAntonym(q_ocol); + mw->queryField->setText(q_ocol == 0 ? exp->getOriginal() : exp->getTranslation(q_ocol)); + } + break; + + case QT_Paraphrase: { + mw->queryField->setText(exp->getParaphrase(q_ocol)); + answerstring = q_ocol == 0 ? exp->getOriginal() : exp->getTranslation(q_ocol); + } + break; + + case QT_Example: { + mw->queryField->setText(exp->getExample(q_ocol)); + answerstring = q_ocol == 0 ? exp->getOriginal() : exp->getTranslation(q_ocol); + } + break; + + default: + ; + } +} + + +void SimpleQueryDlg::keyPressEvent(QKeyEvent *e) +{ + switch( e->key() ) + { + case Key_Escape: + dontKnowClicked(); + break; + + case Key_Return: + case Key_Enter: + if (mw->dont_know->isDefault() ) + dontKnowClicked(); + else if (mw->know_it->isDefault() ) + knowItClicked(); + else if (mw->show_all->isDefault() ) + showAllClicked(); + else if (mw->verify->isDefault() ) + verifyClicked(); + break; + + default: + e->ignore(); + break; + } +} + +void SimpleQueryDlg::setQueryFieldWordwrap() +{ + QFontMetrics fm(Prefs::tableFont()); + int w = fm.width(mw->queryField->text()); + int w2 = mw->width(); + if (w > w2) + mw->queryField->setAlignment(Qt::AlignVCenter | Qt::WordBreak); + else + mw->queryField->setAlignment(Qt::AlignVCenter); +} + + +#include "SimpleQueryDlg.moc" diff --git a/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlg.h b/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlg.h new file mode 100644 index 00000000..adf9827b --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlg.h @@ -0,0 +1,83 @@ +/*************************************************************************** + + query dialog for properties + + ----------------------------------------------------------------------- + + begin : Sun Apr 9 18:55:34 2000 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 SimpleQueryDlg_included +#define SimpleQueryDlg_included + +#include "SimpleQueryDlgForm.h" +#include "QueryDlgBase.h" + +class SimpleQueryDlg : public QueryDlgBase +{ + Q_OBJECT + +public: + SimpleQueryDlg (QueryType querytpe, + int entry, + int column, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc); + + ~SimpleQueryDlg(); + + void setQuery(QueryType querytpe, + int entry, + int column, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc); + +public slots: + virtual void initFocus() const; + +protected: + void keyPressEvent( QKeyEvent *e ); + +public slots: + void showMoreClicked(); + void showAllClicked(); + void knowItClicked(); + void dontKnowClicked(); + void slotAnswerChanged(); + void slotUser2(); + void verifyClicked(); + void timeoutReached(); + +protected: + QString answerstring; + QueryType querytype; + +private: + SimpleQueryDlgForm * mw; + void setQueryFieldWordwrap(); +}; + +#endif // SimpleQueryDlg_included diff --git a/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlgForm.ui b/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlgForm.ui new file mode 100644 index 00000000..3ff31b5f --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/SimpleQueryDlgForm.ui @@ -0,0 +1,348 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>SimpleQueryDlgForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>SimpleQueryDlgForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>471</width> + <height>324</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>queryLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>queryField</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + <property name="alignment"> + <set>WordBreak|AlignVCenter</set> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>instructionLabel</cstring> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + <widget class="QMultiLineEdit"> + <property name="name"> + <cstring>answerField</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </vbox> + </widget> + <spacer> + <property name="name"> + <cstring>spacer9</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>300</width> + <height>16</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout17</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>status</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QGroupBox" row="0" column="1" rowspan="2" colspan="1"> + <property name="name"> + <cstring>progressgroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Progress</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KProgress" row="0" column="1"> + <property name="name"> + <cstring>countbar</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="KProgress" row="1" column="1"> + <property name="name"> + <cstring>timebar</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>countlabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Count:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>timelabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Time:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>Cyclelabel</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="text"> + <string>Cycle:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>progCount</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout16</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton" row="0" column="2"> + <property name="name"> + <cstring>know_it</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>I &Know It</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="2"> + <property name="name"> + <cstring>dont_know</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Do &Not Know</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="0"> + <property name="name"> + <cstring>show_all</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show &All</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>show_more</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show &More</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>verify</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Verify</string> + </property> + </widget> + </grid> + </widget> + </grid> + </widget> + </vbox> +</widget> +<tabstops> + <tabstop>answerField</tabstop> + <tabstop>show_all</tabstop> + <tabstop>show_more</tabstop> + <tabstop>verify</tabstop> + <tabstop>know_it</tabstop> + <tabstop>dont_know</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kprogress.h</includehint> + <includehint>kprogress.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlg.cpp b/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlg.cpp new file mode 100644 index 00000000..8a33d2c3 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlg.cpp @@ -0,0 +1,516 @@ +/*************************************************************************** + + query dialog for verbs + + ----------------------------------------------------------------------- + + begin : Fri Dec 3 18:28:18 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2004-2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "VerbQueryDlg.h" + +#include <kv_resource.h> + +#include <kapplication.h> +#include <kstandarddirs.h> +#include <klocale.h> +#include <kprogress.h> + +#include <qtimer.h> +#include <qpushbutton.h> +#include <qlabel.h> +#include <qlineedit.h> + +VerbQueryDlg::VerbQueryDlg +( + QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Conjugation &prefix, + const Conjugation &conjug) + : QueryDlgBase(i18n("Verb Training")) +{ + mw = new VerbQueryDlgForm(this); + setMainWidget(mw); + + connect(mw->dont_know, SIGNAL(clicked()), SLOT(dontKnowClicked()) ); + connect(mw->know_it, SIGNAL(clicked()), SLOT(knowItClicked()) ); + connect(mw->verify, SIGNAL(clicked()), SLOT(verifyClicked()) ); + connect(mw->show_all, SIGNAL(clicked()), SLOT(showAllClicked()) ); + + connect(mw->p3pmField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p3pnField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p3snField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p3smField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p3pfField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p3sfField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p2pField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p2sField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p1pField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + connect(mw->p1sField, SIGNAL(returnPressed()), SLOT(slotReturnPressed()) ); + + connect(mw->p3pmField, SIGNAL(textChanged(const QString&)), SLOT(slotP3pmChanged(const QString&)) ); + connect(mw->p3snField, SIGNAL(textChanged(const QString&)), SLOT(slotP3snChanged(const QString&)) ); + connect(mw->p3pnField, SIGNAL(textChanged(const QString&)), SLOT(slotP3pnChanged(const QString&)) ); + connect(mw->p3smField, SIGNAL(textChanged(const QString&)), SLOT(slotP3smChanged(const QString&)) ); + connect(mw->p3pfField, SIGNAL(textChanged(const QString&)), SLOT(slotP3pfChanged(const QString&)) ); + connect(mw->p3sfField, SIGNAL(textChanged(const QString&)), SLOT(slotP3sfChanged(const QString&)) ); + connect(mw->p2pField, SIGNAL(textChanged(const QString&)), SLOT(slotP2pChanged(const QString&)) ); + connect(mw->p2sField, SIGNAL(textChanged(const QString&)), SLOT(slotP2sChanged(const QString&)) ); + connect(mw->p1pField, SIGNAL(textChanged(const QString&)), SLOT(slotP1pChanged(const QString&)) ); + connect(mw->p1sField, SIGNAL(textChanged(const QString&)), SLOT(slotP1sChanged(const QString&)) ); + + qtimer = 0; + + setQuery (type, entry, col, query_cycle, query_num, query_startnum, exp, doc, prefix, conjug); + mw->countbar->setFormat("%v/%m"); + mw->timebar->setFormat("%v"); + resize(configDialogSize("VerbQueryDialog")); +} + + +VerbQueryDlg::~ VerbQueryDlg( ) +{ + saveDialogSize("VerbQueryDialog"); +} + + +void VerbQueryDlg::initFocus() const +{ + mw->p1sField->setFocus(); +} + + +void VerbQueryDlg::setQuery(QString, + int entry, + int col, + int q_cycle, + int q_num, + int q_start, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Conjugation &prefix, + const Conjugation &conjug) +{ + //type_timeout = type_to; + kv_doc = doc; + kv_exp = exp; + q_row = entry; + q_ocol = col; + int mqtime = Prefs::maxTimePer(); + mw->timebar->setEnabled(Prefs::showCounter()); + mw->timelabel->setEnabled(Prefs::showCounter()); + mw->show_all->setDefault(true); + QString s; + s.setNum (q_cycle); + mw->progCount->setText (s); + + conjugations = conjug; + + mw->p1sLabel->setText (prefix.pers1Singular(CONJ_PREFIX)); + mw->p2sLabel->setText (prefix.pers2Singular(CONJ_PREFIX)); + mw->p3sfLabel->setText (prefix.pers3FemaleSingular(CONJ_PREFIX)); + mw->p3smLabel->setText (prefix.pers3MaleSingular(CONJ_PREFIX)); + mw->p3snLabel->setText (prefix.pers3NaturalSingular(CONJ_PREFIX)); + + mw->p1pLabel->setText (prefix.pers1Plural(CONJ_PREFIX)); + mw->p2pLabel->setText (prefix.pers2Plural(CONJ_PREFIX)); + mw->p3pfLabel->setText (prefix.pers3FemalePlural(CONJ_PREFIX)); + mw->p3pmLabel->setText (prefix.pers3MalePlural(CONJ_PREFIX)); + mw->p3pnLabel->setText (prefix.pers3NaturalPlural(CONJ_PREFIX)); + + mw->countbar->setTotalSteps(q_start); + mw->countbar->setProgress(q_start - q_num + 1); + + if (mqtime > 0) { // more than 1000 milli-seconds + if (qtimer == 0) { + qtimer = new QTimer( this ); + connect( qtimer, SIGNAL(timeout()), this, SLOT(timeoutReached()) ); + } + + if (Prefs::queryTimeout() != Prefs::EnumQueryTimeout::NoTimeout) { + timercount = mqtime; + mw->timebar->setTotalSteps(timercount); + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + else + mw->timebar->setEnabled(false); + } + else + mw->timebar->setEnabled(false); + all_known = true; + current = -1; + next(); +} + + +bool VerbQueryDlg::next() +{ + resetAllFields(); + QString s, type; + if (q_ocol == 0) + s = kv_exp->getOriginal(); + else + s = kv_exp->getTranslation(q_ocol); + + if (current < (int) conjugations.numEntries()-1 ) + current++; + + type = conjugations.getType(current); + QString format = i18n("Current tense is: %1."); + QString msg = format.arg(conjugations.getName(type)); + + mw->instructionLabel->setText (msg); + mw->baseLabel->setText (s); + + mw->p1sField->setText(""); + mw->p1sField->setEnabled (!conjugations.pers1Singular(type).isEmpty()); + + mw->p2sField->setText(""); + mw->p2sField->setEnabled (!conjugations.pers2Singular(type).isEmpty()); + + mw->p3sfField->setText(""); + mw->p3sfField->setEnabled (!conjugations.pers3FemaleSingular(type).isEmpty()); + + mw->p3smField->setText(""); + mw->p3smField->setEnabled (!conjugations.pers3MaleSingular(type).isEmpty()); + + mw->p3snField->setText(""); + mw->p3snField->setEnabled (!conjugations.pers3NaturalSingular(type).isEmpty()); + + mw->p1pField->setText(""); + mw->p1pField->setEnabled (!conjugations.pers1Plural(type).isEmpty()); + + mw->p2pField->setText(""); + mw->p2pField->setEnabled (!conjugations.pers2Plural(type).isEmpty()); + + mw->p3pfField->setText(""); + mw->p3pfField->setEnabled (!conjugations.pers3FemalePlural(type).isEmpty()); + + mw->p3pmField->setText(""); + mw->p3pmField->setEnabled (!conjugations.pers3MalePlural(type).isEmpty()); + + mw->p3pnField->setText(""); + mw->p3pnField->setEnabled (!conjugations.pers3NaturalPlural(type).isEmpty()); + + bool common = conjugations.pers3SingularCommon(type); + if (common) { + mw->p3smField->setEnabled(false); + mw->p3snField->setEnabled(false); + } + + common = conjugations.pers3PluralCommon(type); + if (common) { + mw->p3pmField->setEnabled(false); + mw->p3pnField->setEnabled(false); + } + + return false; +} + + +void VerbQueryDlg::showAllClicked() +{ + resetAllFields(); + mw->dont_know->setDefault(true); + + QString type = conjugations.getType (current); + + mw->p1sField->setText (conjugations.pers1Singular(type)); + mw->p2sField->setText (conjugations.pers2Singular(type)); + mw->p3sfField->setText (conjugations.pers3FemaleSingular(type)); + mw->p3smField->setText (conjugations.pers3MaleSingular(type)); + mw->p3snField->setText (conjugations.pers3NaturalSingular(type)); + + mw->p1pField->setText (conjugations.pers1Plural(type)); + mw->p2pField->setText (conjugations.pers2Plural(type)); + mw->p3pfField->setText (conjugations.pers3FemalePlural(type)); + mw->p3pmField->setText (conjugations.pers3MalePlural(type)); + mw->p3pnField->setText (conjugations.pers3NaturalPlural(type)); + + verifyField (mw->p1sField, conjugations.pers1Singular(type)); + verifyField (mw->p2sField, conjugations.pers2Singular(type)); + verifyField (mw->p3sfField, conjugations.pers3FemaleSingular(type)); + + bool common = conjugations.pers3SingularCommon(type); + if (!common) { + verifyField (mw->p3smField, conjugations.pers3MaleSingular(type)); + verifyField (mw->p3snField, conjugations.pers3NaturalSingular(type)); + } + + verifyField (mw->p1pField, conjugations.pers1Plural(type)); + verifyField (mw->p2pField, conjugations.pers2Plural(type)); + verifyField (mw->p3pfField, conjugations.pers3FemalePlural(type)); + + common = conjugations.pers3PluralCommon(type); + if (!common) { + verifyField (mw->p3pmField, conjugations.pers3MalePlural(type)); + verifyField (mw->p3pnField, conjugations.pers3NaturalPlural(type)); + } + +} + + +void VerbQueryDlg::verifyClicked() +{ + QString type = conjugations.getType(current); + + bool known = true; + + if (!verifyField (mw->p1sField, conjugations.pers1Singular(type))) + known = false; + + if (!verifyField (mw->p2sField, conjugations.pers2Singular(type))) + known = false; + + if (!verifyField (mw->p3sfField, conjugations.pers3FemaleSingular(type))) + known = false; + + bool common = conjugations.pers3SingularCommon(type); + if (!common) { + if (!verifyField (mw->p3smField, conjugations.pers3MaleSingular(type))) + known = false; + + if (!verifyField (mw->p3snField, conjugations.pers3NaturalSingular(type))) + known = false; + } + + if (!verifyField (mw->p1pField, conjugations.pers1Plural(type))) + known = false; + + if (!verifyField (mw->p2pField, conjugations.pers2Plural(type))) + known = false; + + if (!verifyField (mw->p3pfField, conjugations.pers3FemalePlural(type))) + known = false; + + common = conjugations.pers3PluralCommon(type); + if (!common) { + if (!verifyField (mw->p3pmField, conjugations.pers3MalePlural(type))) + known = false; + + if (!verifyField (mw->p3pnField, conjugations.pers3NaturalPlural(type))) + known = false; + } + + if (known) + knowItClicked(); + else { + all_known = false; + mw->dont_know->setDefault(true); + } +} + + +void VerbQueryDlg::resetAllFields() +{ + resetField(mw->p1sField); + resetField(mw->p2sField); + resetField(mw->p3sfField); + resetField(mw->p3smField); + resetField(mw->p3snField); + + resetField(mw->p1pField); + resetField(mw->p2pField); + resetField(mw->p3pfField); + resetField(mw->p3pmField); + resetField(mw->p3pnField); +} + + +void VerbQueryDlg::timeoutReached() +{ + if (timercount > 0) { + timercount--; + mw->timebar->setProgress(timercount); + qtimer->start(1000, TRUE); + } + + if (timercount <= 0) { + mw->timebar->setProgress(0); + if (current >= (int) conjugations.numEntries()-1 ) { + qtimer->stop(); + if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Show) { + showAllClicked(); + mw->dont_know->setDefault(true); + } + else if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Continue) + emit sigQueryChoice (Timeout); + } + else { + if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Show) { + qtimer->stop(); + showAllClicked(); + mw->dont_know->setDefault(true); + } + else if (Prefs::queryTimeout() == Prefs::EnumQueryTimeout::Continue) { + next(); + qtimer->start(1000, TRUE); + timercount = Prefs::maxTimePer(); + } + } + } +} + + +void VerbQueryDlg::knowItClicked() +{ + resetAllFields(); + if (current >= (int) conjugations.numEntries()-1 ) { + if (all_known) + emit sigQueryChoice (Known); + else + emit sigQueryChoice (Unknown); + } + else + next(); +} + + +void VerbQueryDlg::dontKnowClicked() +{ + all_known = false; + if (current >= (int) conjugations.numEntries()-1 ) + emit sigQueryChoice (Unknown); + else { + qtimer->start(1000, TRUE); + timercount = Prefs::maxTimePer(); + next(); + } +} + + +void VerbQueryDlg::slotUser2() +{ + + if (qtimer != 0) + qtimer->stop(); + + emit sigEditEntry (q_row, KV_COL_ORG+q_ocol); +} + + +void VerbQueryDlg::keyPressEvent( QKeyEvent *e ) +{ + switch( e->key() ) + { + case Key_Escape: + dontKnowClicked(); + break; + + case Key_Return: + case Key_Enter: + if (mw->dont_know->isDefault() ) + dontKnowClicked(); + else if (mw->know_it->isDefault() ) + knowItClicked(); + else if (mw->show_all->isDefault() ) + showAllClicked(); + else if (mw->verify->isDefault() ) + verifyClicked(); + break; + + default: + e->ignore(); + break; + } +} + + +void VerbQueryDlg::slotP3pfChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p3pfField); +} + + +void VerbQueryDlg::slotP3snChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p3snField); +} + + +void VerbQueryDlg::slotReturnPressed() +{ +} + + +void VerbQueryDlg::slotP3smChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p3smField); +} + + +void VerbQueryDlg::slotP3pnChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p3pnField); +} + + +void VerbQueryDlg::slotP3sfChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p3sfField); +} + + +void VerbQueryDlg::slotP1sChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p1sField); +} + + +void VerbQueryDlg::slotP2sChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p2sField); +} + + +void VerbQueryDlg::slotP3pmChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p3pmField); +} + + +void VerbQueryDlg::slotP1pChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p1pField); +} + + +void VerbQueryDlg::slotP2pChanged(const QString&) +{ + mw->verify->setDefault(true); + resetField(mw->p2pField); +} + +#include "VerbQueryDlg.moc" diff --git a/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlg.h b/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlg.h new file mode 100644 index 00000000..e972eb2a --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlg.h @@ -0,0 +1,100 @@ +/*************************************************************************** + + query dialog for verbs + + ----------------------------------------------------------------------- + + begin : Fri Dec 3 18:28:18 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 VerbQueryDlg_included +#define VerbQueryDlg_included + +#include "VerbQueryDlgForm.h" +#include "QueryDlgBase.h" + +class VerbQueryDlg : public QueryDlgBase +{ + Q_OBJECT + +public: + + VerbQueryDlg( + QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Conjugation &prefix, + const Conjugation &conjug); + + ~VerbQueryDlg(); + + void setQuery(QString type, + int entry, + int col, + int query_cycle, + int query_num, + int query_startnum, + kvoctrainExpr *exp, + kvoctrainDoc *doc, + const Conjugation &prefix, + const Conjugation &conjug); + +public slots: + virtual void initFocus() const; + +protected: + bool next(); + void keyPressEvent( QKeyEvent *e ); + void resetAllFields(); + +protected slots: + void slotUser2(); + void slotP3pfChanged(const QString&); + void slotP3snChanged(const QString&); + void showAllClicked(); + void slotReturnPressed(); + void slotP3smChanged(const QString&); + void knowItClicked(); + void dontKnowClicked(); + void slotP3pnChanged(const QString&); + void slotP3sfChanged(const QString&); + void slotP1sChanged(const QString&); + void slotP2sChanged(const QString&); + void slotP3pmChanged(const QString&); + void slotP1pChanged(const QString&); + void slotP2pChanged(const QString&); + void verifyClicked(); + void timeoutReached(); + +protected: + int current; + Conjugation conjugations; + bool all_known; + +private: + VerbQueryDlgForm * mw; +}; + +#endif // VerbQueryDlg_included diff --git a/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlgForm.ui b/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlgForm.ui new file mode 100644 index 00000000..0c7a5cb7 --- /dev/null +++ b/kvoctrain/kvoctrain/query-dialogs/VerbQueryDlgForm.ui @@ -0,0 +1,549 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>VerbQueryDlgForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>VerbQueryDlgForm</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>473</width> + <height>326</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>layout20</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>lab1</cstring> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Enter the correct conjugation forms.</string> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>instructionLabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="font"> + <font> + <bold>1</bold> + </font> + </property> + <property name="text"> + <string>Current tense is %1.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="2" column="0"> + <property name="name"> + <cstring>layout30</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout29</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>p3smLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p3smField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>p2sField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="3" column="1"> + <property name="name"> + <cstring>p3smField</cstring> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>p3snLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p3snField</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>p1sLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p1sField</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>p3sfLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p3sfField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="4" column="1"> + <property name="name"> + <cstring>p3snField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>p3sfField</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>p2sLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p2sField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>p1sField</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout27</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>p2pField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="4" column="1"> + <property name="name"> + <cstring>p3pnField</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>p1pLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p1pField</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>p2pLabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>MShape</enum> + </property> + <property name="frameShadow"> + <enum>MShadow</enum> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p2pField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="3" column="1"> + <property name="name"> + <cstring>p3pmField</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>p3pmLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p3pmField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>p3pfField</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>p3pfLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p3pfField</cstring> + </property> + </widget> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>p1pField</cstring> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>p3pnLabel</cstring> + </property> + <property name="text"> + <string>-</string> + </property> + <property name="buddy" stdset="0"> + <cstring>p3pnField</cstring> + </property> + </widget> + </grid> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout19</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>Base form:</string> + </property> + </widget> + <widget class="QLabel"> + <property name="name"> + <cstring>baseLabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string>-</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="4" column="0"> + <property name="name"> + <cstring>layout32</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout31</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>know_it</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>I &Know It</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>verify</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Verify</string> + </property> + </widget> + <widget class="QPushButton" row="0" column="0"> + <property name="name"> + <cstring>show_all</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Show &All</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="1"> + <property name="name"> + <cstring>dont_know</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Do Not Know</string> + </property> + </widget> + </grid> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>status</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QGroupBox" row="0" column="1" rowspan="2" colspan="1"> + <property name="name"> + <cstring>progressgroup</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Progress</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="KProgress" row="0" column="1"> + <property name="name"> + <cstring>countbar</cstring> + </property> + </widget> + <widget class="KProgress" row="1" column="1"> + <property name="name"> + <cstring>timebar</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>countlabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Count:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>timelabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Time:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>Cyclelabel</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="text"> + <string>Cycle:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>progCount</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + </grid> + </widget> + <spacer row="3" column="0"> + <property name="name"> + <cstring>spacer11</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>390</width> + <height>16</height> + </size> + </property> + </spacer> + </grid> +</widget> +<tabstops> + <tabstop>p1sField</tabstop> + <tabstop>p2sField</tabstop> + <tabstop>p3sfField</tabstop> + <tabstop>p3smField</tabstop> + <tabstop>p3snField</tabstop> + <tabstop>p1pField</tabstop> + <tabstop>p2pField</tabstop> + <tabstop>p3pfField</tabstop> + <tabstop>p3pmField</tabstop> + <tabstop>p3pnField</tabstop> + <tabstop>show_all</tabstop> + <tabstop>verify</tabstop> + <tabstop>know_it</tabstop> + <tabstop>dont_know</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kprogress.h</includehint> + <includehint>kprogress.h</includehint> +</includehints> +</UI> diff --git a/kvoctrain/kvoctrain/spotlight2kvtml.cpp b/kvoctrain/kvoctrain/spotlight2kvtml.cpp new file mode 100644 index 00000000..c0d4ab90 --- /dev/null +++ b/kvoctrain/kvoctrain/spotlight2kvtml.cpp @@ -0,0 +1,347 @@ +/*************************************************************************** + + convert spotlight list to kvtml + + ----------------------------------------------------------------------- + + begin : Thu Sep 30 20:00:00 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold + (C) 2001 The KDE-EDU team + email : kvoctrain@ewald-arnold.de + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 <qfile.h> + +#include <vector> +#include <iostream> +#include <stdlib.h> + +using namespace std; + + +#include <klocale.h> +#include <kapplication.h> + +#define KVD_VERS_PREFIX " v" //#include "kvoctraindoc.h" +#define QM_VERB "v" //#include "QueryManager.h" + +#include "kvoctraincore.h" + +#define SPOT_VERSION "v0.2.1" + +vector<QString> lesson_names; + +struct spotty { + QString type; + int lesson; + QString en_rem, // possibly remarks + de_rem; + QString en, + de; +}; + +vector<spotty> spottys; + +void writeSpotty (QTextStream &os, spotty& spot_line, bool first) { + os << " <e"; + + if (spot_line.lesson != 0 ) + os << " m=\"" << spot_line.lesson << "\""; + + if (!spot_line.type.isEmpty() ) + os << " t=\"" << spot_line.type << "\""; + + os << "><o"; + + if (first) + os << " l=\"en\""; + + if (!spot_line.en_rem.isEmpty() ) + os << " r=\"" << spot_line.en_rem.stripWhiteSpace() << "\""; + + os << ">" << spot_line.en.stripWhiteSpace() << "</o><t"; + + if (first) + os << " l=\"de\""; + + if (!spot_line.de_rem.isEmpty() ) + os << " r=\"" << spot_line.de_rem.stripWhiteSpace() << "\""; + + os << ">" << spot_line.de.stripWhiteSpace() << "</t></e>\n"; +} + + +void readToMem (QTextStream &is, QString month, QString year) +{ + QString line; + bool lesson_pending = false; + QString lesson_str; + spotty spot; + + bool first_line = true; + while (!is.eof() && is.device()->status() == IO_Ok) { + line = is.readLine(); + + int pos; + while ((pos = line.find(" ")) >= 0) + line.remove (pos, 1); + + bool head_line = (!line.stripWhiteSpace().isEmpty() && line == line.upper() ); + + if (first_line && !head_line) { + line = is.readLine(); + head_line = (!line.stripWhiteSpace().isEmpty() && line == line.upper() ); + } + first_line = false; + + if ( line.find ("see p.") >= 0 + || line.find ("see pp.") >= 0 + || line.find ("see also p") >= 0) { + line = ""; + } + + int c = 0x92; + while ((pos = line.find (c)) >= 0) + line[pos] = '\''; + + c = 0x94; + while ((pos = line.find (c)) >= 0) + line[pos] = ' '; + + pos = 0; + while ((pos = line.find ('&', pos)) >= 0) { + line.insert (pos+1, "amp;"); + pos += 5; // skip & + } + + while ((pos = line.find ('<')) >= 0) { + line.remove(pos, 1); + line.insert (pos, "<"); + } + + while ((pos = line.find ('>')) >= 0) { + line.remove(pos, 1); + line.insert (pos, ">"); + } + + if (!line.isEmpty()) { + + if (head_line) { + lesson_pending = true; + lesson_str = line + ", "+month+" "+year; + } + else { + pos = line.find ('\t'); + if (pos < 0) + pos = line.find ('|'); + if (pos >= 0) { + if (lesson_pending) { + lesson_pending = false; + lesson_names.push_back(lesson_str.stripWhiteSpace()); + } + + spot.lesson = lesson_names.size(); + spot.type = ""; + spot.en_rem = ""; + spot.de_rem = ""; + + if (line.left (3) == "to ") { + spot.type = QM_VERB; + line.remove (0, 3); + pos -= 3; + } + spot.en = line.mid(0, pos); + spot.de = line.mid(pos+1, line.length()-pos-1); + + if ((pos = spot.en.find(" UK") ) >= 0) { + spot.en_rem+= i18n("UK ").local8Bit(); + spot.en.remove (pos, 3); + } + if ((pos = spot.en.find("(UK)") ) >= 0) { + spot.en_rem+= i18n("UK ").local8Bit(); + spot.en.remove (pos, 4); + } + + if ((pos = spot.en.find(" N. Am.") ) >= 0) { + spot.en_rem+= i18n("N. Am. ").local8Bit(); + spot.en.remove (pos, 7); + } + if ((pos = spot.en.find("(N. Am.)") ) >= 0) { + spot.en_rem+= i18n("N. Am. ").local8Bit(); + spot.en.remove (pos, 8); + } + + if ((pos = spot.en.find(" US") ) >= 0) { + spot.en_rem+= i18n("US ").local8Bit(); + spot.en.remove (pos, 3); + } + if ((pos = spot.en.find("(US)") ) >= 0) { + spot.en_rem+= i18n("US ").local8Bit(); + spot.en.remove (pos, 4); + } + + if ((pos = spot.en.find("ifml.") ) >= 0) { + spot.en_rem+= i18n("ifml. ").local8Bit(); + spot.en.remove (pos, 5); + } + if ((pos = spot.en.find("(ifml.)") ) >= 0) { + spot.en_rem+= i18n("ifml. ").local8Bit(); + spot.en.remove (pos, 7); + } + + if ((pos = spot.en.find("vulg.") ) >= 0) { + spot.en_rem+= i18n("vulg. ").local8Bit(); + spot.en.remove (pos, 5); + } + if ((pos = spot.en.find("(vulg.)") ) >= 0) { + spot.en_rem+= i18n("vulg. ").local8Bit(); + spot.en.remove (pos, 7); + } + + if (!spot.en.isEmpty() && !spot.de.isEmpty()) + spottys.push_back(spot); + } + } + } + } +} + +void writeToKvtml(QTextStream &os, QString month, QString year) +{ + os << + "<?xml version=\"1.0\"?>\n" + "<!doctype kvtml system \"kvoctrain.dtd\">\n" + "<!--\n" + "This is a machine generated file.\n" + "Be careful when editing here.\n" + "\n" + "Short definition:\n" + "\n" + "lesson lesson group\n" + " desc name\n" + " %no its index\n" + " %current is current lesson\n" + "type type group\n" + " desc name\n" + " %no its index\n" + "e entry of dictionary\n" + " %s is selected\n" + " %m lesson member\n" + " %t common expression type\n" + " o original\n" + " %q in query (\"o\" is given, \"t\" is wanted)\n" + " %l language code\n" + " %r remark\n" + " %p pronunciation\n" + " %width column width\n" + " %t expression type\n" + " t translation ..\n" + " %q in query (\"t\" is given, \"o\" is wanted)\n" + " %l language code\n" + " %r remark\n" + " %p pronunciation\n" + " %width column width\n" + " %t expression type\n" + "\n" + " %d last query date (from;to)\n" + " %w dito, compressed\n" + " %g grade (from;to)\n" + " %c count (from;to)\n" + " %b bad count (from;to)\n" + "\n" + "\n" + "Valid xml means:\n" + " - Close all tags\n" + " - Keep proper hierarchy\n" + " - All options are quoted\n" + "\n" + "--\n" + ">\n" + "<kvtml\n" + " generator=\"spotlight2kvtml " SPOT_VERSION " kvoctrain" KVD_VERS_PREFIX "0.5.0\"\n" + " cols=\"2\"\n" + " lines=\"" << spottys.size() << "\"\n" << + " title=\"" << i18n("Spotlight Online, issue ").local8Bit() << month << " " << "\'" << year << "\"\n" + << " author=" << i18n("\"Spotlight Online, www.spotlight-online.de (converted by spotlight2kvtml)").local8Bit() + << "\">\n\n" + << " <lesson>\n"; + + for (int i = 0; i < (int) lesson_names.size(); i++) { + os << " <desc no=\"" << i+1 << "\">" + << lesson_names[i] << "</desc>\n"; + } + os << " </lesson>\n\n"; + + if (spottys.size() != 0) + writeSpotty (os, spottys[0], true); + + int l = 1; + while (os.device()->status() == IO_Ok && l < (int) spottys.size() ) { + writeSpotty (os, spottys[l], false); + l++; + } + + os << "</kvtml>\n"; +} + + +int main(int argc, char **argv) +{ + // use i18n-strings from kvoctrain + KApplication app(argc,argv, "kvoctrain"); + + if (argc != 4) { + cerr << i18n("usage: spotlight2kvtml spotfile month year\n\n").local8Bit(); + exit (1); + } + + QString spot (argv[1]); + QString kvtml; + + int dot = spot.findRev('.'); + if (dot < 0) { + kvtml = spot + "." KVTML_EXT; + } + else { + kvtml = spot; + kvtml.remove (dot, kvtml.length()-dot); + kvtml += "." KVTML_EXT; + } + + QFile fs(spot); + fs.open( IO_ReadOnly ); + QTextStream is( &fs ); + readToMem (is, argv[2], argv[3]); + fs.close(); + + if (is.device()->status() != IO_Ok ) { + cerr << i18n("Could not read ").local8Bit() << spot.local8Bit() << endl; + exit (1); + } + + QFile fk(kvtml); + fk.open( IO_WriteOnly ); + QTextStream os( &fk ); + writeToKvtml(os, argv[2], argv[3]); + fk.close(); + + if (os.device()->status() != IO_Ok ) { + cerr << i18n("Could not write ").local8Bit() << kvtml.local8Bit() << endl; + exit (1); + } + + exit (0); +} diff --git a/kvoctrain/kvoctrain/statistik-dialogs/GenStatPage.cpp b/kvoctrain/kvoctrain/statistik-dialogs/GenStatPage.cpp new file mode 100644 index 00000000..d9fdea3f --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/GenStatPage.cpp @@ -0,0 +1,46 @@ +/*************************************************************************** + + general statistics dialog page + + ----------------------------------------------------------------------- + + begin : Thu Sep 21 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "GenStatPage.h" + +#include <kvoctraindoc.h> + +#include <qlabel.h> +#include <qvaluevector.h> + +GenStatPage::GenStatPage(kvoctrainDoc *doc, QWidget* parent, const char* name): GenStatPageForm( parent, name ) +{ + l_filename->setText(doc->URL().path()); + l_title->setText(doc->getTitle()); + l_author->setText(doc->getAuthor()); + QString s; + s.setNum(doc->numEntries()); + kcfg_entriesPerLesson->setText(s); + vector<QString> lesson = doc->getLessonDescr(); + s.setNum(lesson.size()); + l_lessons->setText(s); +} + +#include "GenStatPage.moc" diff --git a/kvoctrain/kvoctrain/statistik-dialogs/GenStatPage.h b/kvoctrain/kvoctrain/statistik-dialogs/GenStatPage.h new file mode 100644 index 00000000..b868741f --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/GenStatPage.h @@ -0,0 +1,43 @@ +/*************************************************************************** + + general statistics dialog page + + ----------------------------------------------------------------------- + + begin : Thu Sep 21 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 GenStatPage_included +#define GenStatPage_included + +#include "GenStatPageForm.h" + +class kvoctrainDoc; + +class GenStatPage : public GenStatPageForm +{ + Q_OBJECT + +public: + + GenStatPage(kvoctrainDoc *doc, QWidget* parent = NULL, const char* name = NULL); + +}; +#endif // GenStatPage_included diff --git a/kvoctrain/kvoctrain/statistik-dialogs/GenStatPageForm.ui b/kvoctrain/kvoctrain/statistik-dialogs/GenStatPageForm.ui new file mode 100644 index 00000000..669ec746 --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/GenStatPageForm.ui @@ -0,0 +1,218 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>GenStatPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>423</width> + <height>190</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </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="QLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel1</cstring> + </property> + <property name="font"> + <font> + </font> + </property> + <property name="text"> + <string>Filename:</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel1_2</cstring> + </property> + <property name="font"> + <font> + </font> + </property> + <property name="text"> + <string>Title:</string> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>TextLabel1_2_2_2</cstring> + </property> + <property name="font"> + <font> + </font> + </property> + <property name="text"> + <string>Entries:</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>TextLabel1_2_2</cstring> + </property> + <property name="font"> + <font> + </font> + </property> + <property name="text"> + <string>Author:</string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>TextLabel1_2_2_2_2</cstring> + </property> + <property name="font"> + <font> + </font> + </property> + <property name="text"> + <string>Lessons:</string> + </property> + </widget> + <widget class="QLabel" row="4" column="1"> + <property name="name"> + <cstring>l_lessons</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>Panel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="3" column="1"> + <property name="name"> + <cstring>kcfg_entriesPerLesson</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>Panel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="2" column="1"> + <property name="name"> + <cstring>l_author</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>Panel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="1" column="1"> + <property name="name"> + <cstring>l_title</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>Panel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="0" column="1"> + <property name="name"> + <cstring>l_filename</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>Panel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <spacer row="5" column="0"> + <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/kvoctrain/kvoctrain/statistik-dialogs/Makefile.am b/kvoctrain/kvoctrain/statistik-dialogs/Makefile.am new file mode 100644 index 00000000..50fbb358 --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES = -I$(srcdir)/.. -I$(srcdir)/../kvt-core -I$(top_builddir)/kvoctrain/kvoctrain/common-dialogs $(all_includes) + +noinst_LTLIBRARIES = libstatdlg.la + +libstatdlg_la_SOURCES = \ + StatistikPage.cpp GenStatPage.cpp \ + StatistikPageForm.ui GenStatPageForm.ui \ + StatistikDlg.cpp + +METASOURCES = AUTO + diff --git a/kvoctrain/kvoctrain/statistik-dialogs/StatistikDlg.cpp b/kvoctrain/kvoctrain/statistik-dialogs/StatistikDlg.cpp new file mode 100644 index 00000000..79bdcb99 --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/StatistikDlg.cpp @@ -0,0 +1,64 @@ +/*************************************************************************** + + statistics dialog class + + ----------------------------------------------------------------------- + + begin : Sun Sep 19 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include <qlayout.h> + +#include "StatistikDlg.h" +#include "StatistikPage.h" +#include "GenStatPage.h" + +#include <klocale.h> + +#include <langset.h> +#include <kvoctraindoc.h> + +StatistikDlg::StatistikDlg(LangSet &langset, kvoctrainDoc *doc, QWidget *parent, const char *name, bool modal) + : KDialogBase(Tabbed, i18n("Document Statistics"), Close, Close, parent, name, modal) +{ + QFrame * page; + QVBoxLayout * topLayout; + StatistikPage *spage; + + page = addPage(i18n("General")); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + GenStatPage *gspage = new GenStatPage (doc, page, name); + topLayout->addWidget(gspage); + + for (int i = 1; i < (int) doc->numLangs(); i++) + { + QString s = langset.findLongId(doc->getIdent(i)); + if (s.isEmpty() ) + s = doc->getIdent(i); + else + s = i18n(s.local8Bit()); + + page = addPage(s); + topLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() ); + spage = new StatistikPage (i, doc, page, name); + topLayout->addWidget(spage); + } +} + +#include "StatistikDlg.moc" diff --git a/kvoctrain/kvoctrain/statistik-dialogs/StatistikDlg.h b/kvoctrain/kvoctrain/statistik-dialogs/StatistikDlg.h new file mode 100644 index 00000000..4f519550 --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/StatistikDlg.h @@ -0,0 +1,48 @@ +/*************************************************************************** + + show document statistics + + ----------------------------------------------------------------------- + + begin : Sun Sep 19 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 StatistikDlg_included +#define StatistikDlg_included + +#include <kdialogbase.h> + +#include <vector> +using namespace std; + +class kvoctrainDoc; +class LangSet; +class GradeCols; + +class StatistikDlg : public KDialogBase +{ + Q_OBJECT + +public: + StatistikDlg(LangSet &langset, kvoctrainDoc *doc, QWidget *parent = NULL, const char *name = NULL, bool modal = true); + +}; + +#endif // StatistikDlg_included + diff --git a/kvoctrain/kvoctrain/statistik-dialogs/StatistikPage.cpp b/kvoctrain/kvoctrain/statistik-dialogs/StatistikPage.cpp new file mode 100644 index 00000000..6541d085 --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/StatistikPage.cpp @@ -0,0 +1,289 @@ +/*************************************************************************** + + statistics dialog page + + ----------------------------------------------------------------------- + + begin : Thu Sep 21 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 "StatistikPage.h" + +#include <kpopupmenu.h> +#include <klocale.h> +#include <kdebug.h> + +#include <kvoctraindoc.h> +#include <prefs.h> + +#include <qcursor.h> +#include <qpainter.h> + +#define MIN_COL_WIDTH 2 +#define PIX_SHIFT 2 +#define SIZE_GRADE 100+PIX_SHIFT +#define SIZE_COUNT 70 +#define SIZE_LESSON 300 + +#define TB_FGRADE 0 +#define TB_TGRADE 1 +#define TB_COUNT 2 +#define TB_LESSON 3 + + +class GradeListItem : public QListViewItem +{ +public: + inline GradeListItem (QListView* parent, int _lesson): QListViewItem(parent), lesson(_lesson) {} + inline int getLesson() const { return lesson; } + +private: + int lesson; +}; + + +StatistikPage::StatistikPage(int col, kvoctrainDoc *_doc, QWidget *parent, const char *name) + : StatistikPageForm( parent, name ), doc(_doc) +{ + StatListView->setColumnWidth(0, SIZE_GRADE + 10); + StatListView->setColumnWidth(1, SIZE_GRADE + 10); + StatListView->setColumnWidth(2, SIZE_COUNT); + StatListView->setColumnWidth(3, SIZE_LESSON); + + vector<QString> lesson = doc->getLessonDescr(); + + fsc.resize(lesson.size()+1); + tsc.resize(lesson.size()+1); + + // accumulate numbers of grades per lesson + for (int i = 0; i < (int) doc->numEntries(); i++) { + kvoctrainExpr *expr = doc->getEntry(i); + int fg = QMIN(KV_MAX_GRADE, expr->getGrade(col, false)); + int tg = QMIN(KV_MAX_GRADE, expr->getGrade(col, true)); + int l = expr->getLesson(); + if (l >= 0 && l <= (int) lesson.size() ) { + fsc[l].grade[fg]++; + fsc[l].num++; + tsc[l].grade[tg]++; + tsc[l].num++; + } + } + setupPixmaps(); + connect(StatListView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint& , int ) ), + this, SLOT( slotRMB( QListViewItem *, const QPoint &, int ) ) ); +} + + +void StatistikPage::setupPixmaps() +{ + // create pixmaps with bar charts of numbers of grades + int height; + GradeListItem lvi (StatListView, 0); + height = lvi.height(); + for (int entry = 0; entry < (int) fsc.size(); entry++) { + QPainter p; + QColor color; + QPixmap fpix (SIZE_GRADE, height); + p.begin( &fpix); + p.eraseRect (0, 0, fpix.width(), fpix.height()); + p.setPen( black ); + if (fsc[entry].num != 0) { + + int num = 0; + for (int j = KV_NORM_GRADE; j <= KV_MAX_GRADE; j++) + if (fsc[entry].grade[j] != 0) + num++; + + int maxw = fpix.width() -PIX_SHIFT -PIX_SHIFT -1; + int w = maxw; + int widths [KV_MAX_GRADE+1]; + for (int j = KV_NORM_GRADE; j <= KV_MAX_GRADE; j++) { + if (fsc[entry].grade[j] == 0) + widths[j] = 0; + else { + if (num <= 1) { + widths[j] = w; + w = 0; + } + else { + --num; + widths[j] = QMAX(MIN_COL_WIDTH, fsc[entry].grade[j] * maxw / fsc[entry].num); + w -= widths[j]; + } + } + } + + int x = 0; + int x2 = 1+PIX_SHIFT; + for (int j = KV_MIN_GRADE; j <= KV_MAX_GRADE; j++) { + switch (j) { + case KV_NORM_GRADE: color = Prefs::gradeCol(0); break; + case KV_LEV1_GRADE: color = Prefs::gradeCol(1); break; + case KV_LEV2_GRADE: color = Prefs::gradeCol(2); break; + case KV_LEV3_GRADE: color = Prefs::gradeCol(3); break; + case KV_LEV4_GRADE: color = Prefs::gradeCol(4); break; + case KV_LEV5_GRADE: color = Prefs::gradeCol(5); break; + case KV_LEV6_GRADE: color = Prefs::gradeCol(6); break; + case KV_LEV7_GRADE: color = Prefs::gradeCol(7); break; + default : color = Prefs::gradeCol(1); + } + if (widths[j] != 0) { + x2 += widths[j]; + p.fillRect(x+PIX_SHIFT, 1, x2-x, height-1, color); + p.drawRect(x+PIX_SHIFT, 1, x2-x, height-1); + x = x2-1; + } + } + } + else { + p.fillRect(PIX_SHIFT, 1, fpix.width()-PIX_SHIFT, height-1, Prefs::gradeCol(0)); + p.drawRect(PIX_SHIFT, 1, fpix.width()-PIX_SHIFT, height-1); + } + p.end(); + from_pix.push_back(fpix); + + QPixmap tpix (SIZE_GRADE, height); + p.begin( &tpix ); + p.eraseRect (0, 0, tpix.width(), tpix.height()); + p.setPen( black ); + if (tsc[entry].num != 0) { + int num = 0; + for (int j = KV_NORM_GRADE; j <= KV_MAX_GRADE; j++) + if (tsc[entry].grade[j] != 0) + num++; + + int maxw = tpix.width() -PIX_SHIFT -PIX_SHIFT -1; + int w = maxw; + int widths [KV_MAX_GRADE+1]; + for (int j = KV_NORM_GRADE; j <= KV_MAX_GRADE; j++) { + if (tsc[entry].grade[j] == 0) + widths[j] = 0; + else { + if (num <= 1) { + widths[j] = w; + w = 0; + } + else { + --num; + widths[j] = QMAX(MIN_COL_WIDTH, tsc[entry].grade[j] * maxw / tsc[entry].num); + w -= widths[j]; + } + } + } + + int x = 0; + int x2 = 1+PIX_SHIFT; + for (int j = KV_MIN_GRADE; j <= KV_MAX_GRADE; j++) { + switch (j) { + case KV_NORM_GRADE: color = Prefs::gradeCol(0); break; + case KV_LEV1_GRADE: color = Prefs::gradeCol(1); break; + case KV_LEV2_GRADE: color = Prefs::gradeCol(2); break; + case KV_LEV3_GRADE: color = Prefs::gradeCol(3); break; + case KV_LEV4_GRADE: color = Prefs::gradeCol(4); break; + case KV_LEV5_GRADE: color = Prefs::gradeCol(5); break; + case KV_LEV6_GRADE: color = Prefs::gradeCol(6); break; + case KV_LEV7_GRADE: color = Prefs::gradeCol(7); break; + default : color = Prefs::gradeCol(1); + } + if (widths[j] != 0) { + x2 += widths[j]; + p.fillRect(x+PIX_SHIFT, 1, x2-x, height-1, color); + p.drawRect(x+PIX_SHIFT, 1, x2-x, height-1); + x = x2-1; + } + } + } + else { + p.fillRect(PIX_SHIFT, 1, tpix.width()-PIX_SHIFT, height-1, Prefs::gradeCol(0)); + p.drawRect(PIX_SHIFT, 1, tpix.width()-PIX_SHIFT, height-1); + } + p.end(); + to_pix.push_back(tpix); + } + + // setup rows with pixmaps and strings + vector<QString> lesson = doc->getLessonDescr(); + + QString s; + + GradeListItem *plvi = new GradeListItem(StatListView, 0); + plvi->setPixmap (TB_FGRADE, from_pix[0]); + plvi->setPixmap (TB_TGRADE, to_pix[0]); + s.setNum (tsc[0].num); + plvi->setText (TB_COUNT, s); + plvi->setText (TB_LESSON, i18n("<no lesson>")); + StatListView->insertItem (plvi); + + for (int i = 0; i < (int) lesson.size(); i++) { + plvi = new GradeListItem(StatListView, i+1); + plvi->setPixmap (TB_FGRADE, from_pix[i+1]); + plvi->setPixmap (TB_TGRADE, to_pix[i+1]); + s.setNum (tsc[i+1].num); + plvi->setText (TB_COUNT, s); + plvi->setText (TB_LESSON, lesson[i]); + StatListView->insertItem (plvi); + } +} + + +void StatistikPage::slotRMB( QListViewItem* Item, const QPoint & /*point*/, int col) +{ + if( Item != 0) + slotPopupMenu(((GradeListItem*)Item)->getLesson(), col); +} + + +void StatistikPage::slotPopupMenu(int row, int col) +{ + struct stat_counter *sc; + + if (col == TB_FGRADE) { + if (row >= (int) fsc.size() ) { + kdError() << "row >= fsc.size()" << endl; + return; + } + else + sc = &fsc[row]; + } + else if (col == TB_TGRADE) { + if (row >= (int) tsc.size() ) { + kdError() << "row >= tsc.size()" << endl; + return; + } + else + sc = &tsc[row]; + } + else + return; + + KPopupMenu *header_m = new KPopupMenu(i18n("Number of Entries per Grade")); + + header_m->insertItem (i18n(KV_NORM_TEXT) + "\t" + QString::number(sc->grade[KV_NORM_GRADE]) ); + header_m->insertItem (i18n(KV_LEV1_TEXT) + "\t" + QString::number(sc->grade[KV_LEV1_GRADE]) ); + header_m->insertItem (i18n(KV_LEV2_TEXT) + "\t" + QString::number(sc->grade[KV_LEV2_GRADE]) ); + header_m->insertItem (i18n(KV_LEV3_TEXT) + "\t" + QString::number(sc->grade[KV_LEV3_GRADE]) ); + header_m->insertItem (i18n(KV_LEV4_TEXT) + "\t" + QString::number(sc->grade[KV_LEV4_GRADE]) ); + header_m->insertItem (i18n(KV_LEV5_TEXT) + "\t" + QString::number(sc->grade[KV_LEV5_GRADE]) ); + header_m->insertItem (i18n(KV_LEV6_TEXT) + "\t" + QString::number(sc->grade[KV_LEV6_GRADE]) ); + header_m->insertItem (i18n(KV_LEV7_TEXT) + "\t" + QString::number(sc->grade[KV_LEV7_GRADE]) ); + + header_m->exec(QCursor::pos()+QPoint(10, 0)); +} + +#include "StatistikPage.moc" diff --git a/kvoctrain/kvoctrain/statistik-dialogs/StatistikPage.h b/kvoctrain/kvoctrain/statistik-dialogs/StatistikPage.h new file mode 100644 index 00000000..a5a7d166 --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/StatistikPage.h @@ -0,0 +1,74 @@ +/*************************************************************************** + + statistics dialog page + + ----------------------------------------------------------------------- + + begin : Thu Sep 21 20:50:53 MET 1999 + + copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> + (C) 2001 The KDE-EDU team + (C) 2005 Peter Hedlund <peter.hedlund@kdemail.net> + + ----------------------------------------------------------------------- + + *************************************************************************** + + *************************************************************************** + * * + * 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 StatistikPage_included +#define StatistikPage_included + +#include "StatistikPageForm.h" + +#include <kvoctrainexpr.h> + +#include <qlistview.h> + +class kvoctrainDoc; +class GradeCols; + +class StatistikPage : public StatistikPageForm +{ + Q_OBJECT + +public: + StatistikPage(int col, kvoctrainDoc *doc, QWidget *parent = NULL, const char *name = NULL); + +public slots: + void slotPopupMenu(int row, int col); + void slotRMB( QListViewItem* Item, const QPoint & point, int ); + +protected: + void setupPixmaps(); + + struct stat_counter + { + stat_counter() { + for (int i = 0; i <= KV_MAX_GRADE; i++) + grade[i] = 0; + num = 0; + } + + int grade [KV_MAX_GRADE+1]; + int num; + }; + + int calc_width (struct StatistikPage::stat_counter *gc, int grade, int max_width); + + vector<QPixmap> from_pix, to_pix; + kvoctrainDoc *doc; + + vector<stat_counter> fsc; + vector<stat_counter> tsc; + //GradeCols *gcol; +}; + +#endif // StatistikPage_included diff --git a/kvoctrain/kvoctrain/statistik-dialogs/StatistikPageForm.ui b/kvoctrain/kvoctrain/statistik-dialogs/StatistikPageForm.ui new file mode 100644 index 00000000..7964f7e0 --- /dev/null +++ b/kvoctrain/kvoctrain/statistik-dialogs/StatistikPageForm.ui @@ -0,0 +1,86 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>StatistikPageForm</class> +<widget class="QWidget"> + <property name="name"> + <cstring>Form2</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>502</width> + <height>203</height> + </rect> + </property> + <property name="caption"> + <string>-</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QListView" row="0" column="0"> + <column> + <property name="text"> + <string>Grade FROM</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>false</bool> + </property> + </column> + <column> + <property name="text"> + <string>Grade TO</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Entries</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Lesson</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>StatListView</cstring> + </property> + <property name="minimumSize"> + <size> + <width>500</width> + <height>0</height> + </size> + </property> + <property name="selectionMode"> + <enum>NoSelection</enum> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/kvoctrain/kvoctrain/tools/extractlang.README b/kvoctrain/kvoctrain/tools/extractlang.README new file mode 100644 index 00000000..3d3cdd04 --- /dev/null +++ b/kvoctrain/kvoctrain/tools/extractlang.README @@ -0,0 +1,23 @@ +Hi! + +Hab die neue Version des Parsers fertig und ein neues Language file gener= +iert. +Ich attache auch den parser selbst. + +nachdem man ihn kompiliert hat einfach das html file durch pipen +#> cat englangn.html | ./extractlang > languages.txt + +Leider sind noch ein paar Duplikate drin (zB Spanish, Castillian und +Castillian, Spanish) + +Die Namen hab ich diesmal nicht ge=E4ndert, die meisten passen sowieso, n= +ur bei=20 +einigen steht Zusatzinformationen dabei. + +ciao, +kev + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Kevin Krammer <kevin.krammer@gmx.at> +Developer at the Kmud Project http://www.kmud.de/ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kvoctrain/kvoctrain/tools/extractlang.cpp b/kvoctrain/kvoctrain/tools/extractlang.cpp new file mode 100644 index 00000000..6123214c --- /dev/null +++ b/kvoctrain/kvoctrain/tools/extractlang.cpp @@ -0,0 +1,161 @@ +#include <qtextstream.h> +#include <qstring.h> + +/////////////////////////////////////////////////////////// +// +// (c) Kevin Krammer <kevin.krammer@gmx.at> +// +// 2001-12-08 +// +// automatically extracts a structure from +// http://www.loc.gov/standards/iso639-2/englangn.html +// +// see also extractlang.README +// +/////////////////////////////////////////////////////////// + +QString twoLangs; +QString threeLangs; + +void parseLanguage(QString name, QString three, QString two) +{ + int star = three.find('*'); + if (star > 0) + three.remove(star, 1); + + QString three_1 = three; + + int slash = three_1.find('/'); + if (slash > 0) { + three_1.remove(slash, 1); + three_1.insert(slash, ", "); + } + + if (!two.contains(" ")) { + twoLangs.append("\t{{\""); + twoLangs.append(two); + twoLangs.append("\"}, {\""); + twoLangs.append(three_1); + twoLangs.append("\"}, {I18N_NOOP(\""); + twoLangs.append(name); + twoLangs.append("\")}},\n"); + } + else + two = ""; + + slash = three.find('/'); + if (slash > 0) { + if (two.length() == 0) + two = three.mid(slash+1); + three.remove(slash, three.length()); + } + + threeLangs.append("\t{{\""); + threeLangs.append(two); + threeLangs.append("\"}, {\""); + threeLangs.append(three); + threeLangs.append("\"}, {I18N_NOOP(\""); + threeLangs.append(name); + threeLangs.append("\")}},\n"); +} + +QString parseTD(QString& line) +{ + QCString cline = line.local8Bit(); + uint clineLength = cline.length(); + QCString result = cline; + int pos = -1; + bool inTag = false; + + for (uint i = 0; i < clineLength; ++i) + { + if (cline[i] == '<') + inTag = true; + else if (cline[i] == '>') + inTag = false; + else if (!inTag) + { + pos++; + result[pos] = cline[i]; + } + } + + QString retVal(result); + retVal = retVal.left(pos+1); + + return retVal.simplifyWhiteSpace(); +} + +bool parseTR(QString& line, QTextIStream& in) +{ + QString text[4]; + + line = in.readLine(); + if (line.isNull()) + return true; + + + uint count = 0; + while (line.contains("<td")) + { + if (count > 3) + return true; + + text[count] = parseTD(line); + count++; + line = in.readLine(); + } + + if (count == 4) + { + parseLanguage(text[0], text[2], text[3]); + } + + if (line.contains("/tr")) + return true; + + return false; +} + +int main() +{ + QString line; + bool readNext = true; + + QTextIStream in(stdin); + QTextOStream out(stdout); + + while (!in.atEnd()) + { + if (readNext) + line = in.readLine(); + + if (line.contains("<tr")) + { + readNext = parseTR(line, in); + } + else + readNext = true; + } + + out << "struct KV_ISO639_Code {\n" + " const char *iso1code;\n" + " const char *iso2code;\n" + " const char *langname;\n" + "};\n" + "\n"; + + out << "KV_ISO639_Code kv_iso639_1[] = {\n" + << twoLangs.left(twoLangs.length()-1) << endl + << "\t{{0}, {0}, {0}}\n" + << "};\n"; + + out << endl; + + out << "KV_ISO639_Code kv_iso639_2[] = {\n" + << threeLangs.left(threeLangs.length()-1) << endl + <<"\t{{0}, {0}, {0}}\n" + << "};\n"; + + return 0; +} diff --git a/kvoctrain/kvoctrain/tools/extractlang.mak b/kvoctrain/kvoctrain/tools/extractlang.mak new file mode 100755 index 00000000..740844df --- /dev/null +++ b/kvoctrain/kvoctrain/tools/extractlang.mak @@ -0,0 +1,3 @@ +#!/bin/sh +g++ -I $QTDIR/include -L $QTDIR/lib extractlang.cpp -o extractlang -lqt +cat englangn.html | ./extractlang > languages.txt
\ No newline at end of file diff --git a/kvoctrain/kvoctrain/x-kvtml.desktop b/kvoctrain/kvoctrain/x-kvtml.desktop new file mode 100644 index 00000000..f446947d --- /dev/null +++ b/kvoctrain/kvoctrain/x-kvtml.desktop @@ -0,0 +1,67 @@ +[Desktop Entry] +Comment=Vocabulary Trainer Document +Comment[af]=Woordeskat-afrigter Dokument +Comment[ar]=مستند معلم الكلمات +Comment[be]=Дакумент слоўнікавага запасу +Comment[bg]=Документ с речникови тренировки +Comment[bn]=শব্দভাণ্ডার সমৃদ্ধকারী ডকুমেন্ট +Comment[bs]=Vocabulary Trainer dokument +Comment[ca]=Document de l'entrenador de vocabulari +Comment[cs]=Dokument pro procvičování slovní zásoby +Comment[csb]=Dokùment trenera słowiznë +Comment[cy]=Dogfen Hyfforddwr Geirfa +Comment[da]=Dokument til ordforrådsøvelser +Comment[de]=Dokument für den Vokabeltrainer +Comment[el]=Έγγραφο εκπαιδευτή λεξιλογίου +Comment[eo]=Vorproviza trejnada dokumento +Comment[es]=Documento de entrenador de vocabulario +Comment[et]=Sõnavara treenija dokument +Comment[eu]=Hiztegi entrenatzaile dokumentua +Comment[fa]=سند مربی واژهها +Comment[fi]=Sanastoharjoitusasiakirja +Comment[fr]=Document de test de vocabulaire +Comment[gl]=Documento de KVocTrain +Comment[he]=מסמך מאמן אוצר מילים +Comment[hi]=शब्दावली प्रशिक्षक दस्तावेज़ +Comment[hr]=Dokument za vježbanje vokabulara +Comment[hu]=KVocTrain-dokumentum +Comment[is]=Orðaforða skjal +Comment[it]=Documento KVocTrain +Comment[ja]=ボキャブラリ強化のドキュメント +Comment[ka]=სიტყვათა მარაგის დოკუმენტი +Comment[km]=ឯកសារកម្មវិធីបង្ហាត់វាក្យសព្ទ +Comment[lt]=Žodyno treniruoklio dokumentas +Comment[lv]=Mācību Vārdnīcas Dokuments +Comment[mk]=Документ на тренерот за речник +Comment[mn]=KЭгшигийн дасгалын баримт бичгүүд +Comment[ms]=Dokumen Jurulatih Perbendaharaan Kata +Comment[nb]=Glosetreningsdokument +Comment[nds]=Dokment för't Vokavel-Lehren +Comment[ne]=शब्दकोश प्रशिक्षक कागजात +Comment[nl]=Vocabulary Trainer-document +Comment[nn]=Glosetreningsdokument +Comment[nso]=Tokomane ya Morutisi wa Tsebo ya Mantsu +Comment[pl]=Dokument treningu słownictwa +Comment[pt]=Documento do Treinador de Vocabulário +Comment[pt_BR]=Documento do treinador de vocabulário +Comment[ru]=Тренировка словарного запаса +Comment[se]=Sátnehárjehallan-dokumeanta +Comment[sk]=Dokument KVocTrain +Comment[sl]=Dokument za KVocTrain +Comment[sr]=Документ тренера речника +Comment[sr@Latn]=Dokument trenera rečnika +Comment[sv]=Ordförrådsdokument +Comment[ta]=சொல்லாக்க பயிற்சியாளர் ஆவணம் +Comment[tg]=Ҳуҷҷати Машқи Луғат +Comment[tr]=Sözlük Eğitmen Belgesi +Comment[uk]=Документ тренування словникового запасу +Comment[ven]=Manwalwa a mugudisi wa ndivho +Comment[vi]=Tài liệu Luyện tập Từ vựng +Comment[zh_CN]=单词练习文档 +Comment[zh_TW]=字彙訓練師文件 +Comment[zu]=Idokhumenti Yomlolongi Wokusetshenziswa kwamagama +MimeType=text/x-kvtml; +DefaultApp=kvoctrain +Icon=kvoctrain.xpm +Type=MimeType +Patterns=*.kvtml;*.KVTML; diff --git a/kvoctrain/stamp-h.in b/kvoctrain/stamp-h.in new file mode 100644 index 00000000..9788f702 --- /dev/null +++ b/kvoctrain/stamp-h.in @@ -0,0 +1 @@ +timestamp |