diff --git a/keduvocdocument/CMakeLists.txt b/keduvocdocument/CMakeLists.txt index e57df5e..87160b0 100644 --- a/keduvocdocument/CMakeLists.txt +++ b/keduvocdocument/CMakeLists.txt @@ -1,248 +1,250 @@ if (BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) endif() ########### next target ############### include(ECMSetupVersion) ecm_setup_version(5.0.0 VARIABLE_PREFIX KDEEDU VERSION_HEADER "${CMAKE_BINARY_DIR}/keduvocdocument/keduvocdocument_version.h" PACKAGE_VERSION_FILE "${CMAKE_BINARY_DIR}/KEduVocDocumentVersion.cmake") include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) set(keduvocdocument_LIB_SRCS keduvocdocument.cpp keduvocidentifier.cpp keduvocexpression.cpp keduvoctranslation.cpp keduvoccontainer.cpp keduvoclesson.cpp keduvocleitnerbox.cpp keduvoctext.cpp keduvocarticle.cpp keduvocconjugation.cpp keduvocpersonalpronoun.cpp keduvocdeclension.cpp keduvocwordtype.cpp keduvockvtmlcompability.cpp keduvockvtml2writer.cpp keduvoccsvwriter.cpp keduvoccontainermodel.cpp keduvoclessonmodel.cpp keduvocreadonlycontainermodel.cpp keduvocvocabularymodel.cpp keduvocwordclassmodel.cpp keduvoccontainermimedata.cpp keduvocvocabularymimedata.cpp keduvocvocabularyfilter.cpp keduvoctranslator.cpp keduvocvocabularydelegate.cpp keduvocvocabularyheaderview.cpp keduvocvocabularycolumnsdialog.cpp keduvoccontainerview.cpp keduvocvocabularyview.cpp keduvocwordtypeview.cpp keduvoclessonview.cpp keduvocaudiowidget.cpp keduvocmultiplechoicewidget.cpp keduvoccomparisonwidget.cpp keduvocdeclensionwidget.cpp keduvocconjugationwidget.cpp keduvocinflectionwidget.cpp keduvocimagewidget.cpp keduvocimagechooserwidget.cpp keduvocsynonymwidget.cpp keduvocsummarywordwidget.cpp keduvoclatexrenderer.cpp keduvoclatexwidget.cpp keduvocscript.cpp keduvocdocumentproperties.cpp keduvoclanguagepropertiespage.cpp keduvoclanguageproperties.cpp keduvoceditordocument.cpp keduvocexportdialog.cpp + keduvocscriptmanager.cpp readerwriters/dummyreader.cpp readerwriters/failedreader.cpp readerwriters/keduvockvtmlreader.cpp readerwriters/keduvockvtml2reader.cpp readerwriters/keduvoccsvreader.cpp readerwriters/keduvocpaukerreader.cpp readerwriters/keduvocvokabelnreader.cpp readerwriters/keduvocwqlreader.cpp readerwriters/keduvocxdxfreader.cpp readerwriters/readermanager.cpp sharedkvtmlfiles.cpp ) ki18n_wrap_ui(keduvocdocument_LIB_SRCS keduvocaudiowidget.ui keduvocmultiplechoicewidget.ui keduvoccomparisonwidget.ui keduvocdeclensionwidget.ui keduvocconjugationwidget.ui keduvocimagechooserwidget.ui keduvocsynonymwidget.ui keduvocsummarywordwidget.ui keduvoclatexwidget.ui keduvocdocumentproperties.ui keduvoclanguagepropertiespage.ui keduvocexportdialog.ui ) include(ECMGenerateHeaders) ecm_generate_headers( KdeEdu_HEADERS HEADER_NAMES KEduVocDocument KEduVocIdentifier KEduVocExpression KEduVocText KEduVocArticle KEduVocConjugation KEduVocLesson KEduVocLeitnerBox KEduVocContainer KEduVocWordFlags KEduVocMultipleChoice KEduVocTranslation KEduVocWordtype KEduVocPersonalPronoun SharedKVTMLFiles KEduVocDeclension KEduVocKVTML2Writer KEduVocContainerModel KEduVocLessonModel KEduVocReadOnlyContainerModel KEduVocVocabularyModel KEduVocWordClassModel KEduVocContainerMimeData KEduVocVocabularyMimeData KEduVocVocabularyFilter KEduVocTranslator KEduVocVocabularyDelegate KEduVocVocabularyHeaderView KEduVocVocabularyColumnsDialog KEduVocContainerView KEduVocVocabularyView KEduVocWordTypeView KEduVocLessonView KEduVocAudioWidget KEduVocMultipleChoiceWidget KEduVocComparisonWidget KEduVocDeclensionWidget KEduVocConjugationWidget KEduVocInflectionWidget KEduVocImageWidget KEduVocImageChooserWidget KEduVocSynonymWidget KEduVocSummaryWordWidget KEduVocLatexRenderer KEduVocLatexWidget KEduVocScript KEduVocDocumentProperties KEduVocLanguagePropertiesPage KEduVocLanguageProperties KEduVocEditorDocument KEduVocExportDialog + KEduVocScriptManager REQUIRED_HEADERS KdeEdu_HEADERS ) add_library(KEduVocDocument SHARED ${keduvocdocument_LIB_SRCS}) generate_export_header(KEduVocDocument BASE_NAME KEduVocDocument) # vHanda: Add library alias? target_link_libraries(KEduVocDocument PUBLIC Qt5::Xml Qt5::Gui Qt5::Core Qt5::Widgets Qt5::DBus Qt5::Multimedia ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} PRIVATE KF5::I18n KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets KF5::KIONTLM KF5::Archive KF5::Completion KF5::WidgetsAddons KF5::SonnetCore KF5::SonnetUi KF5::Notifications KF5::XmlGui KF5::KrossCore KF5::KrossUi KF5::NewStuff ) # vHanda: Add Export Name? set_target_properties(KEduVocDocument PROPERTIES VERSION ${KDEEDU_VERSION_STRING} SOVERSION ${KDEEDU_SOVERSION} ) target_include_directories(KEduVocDocument INTERFACE "$") #Library for non-api unittests add_library(keduvocdocument_static STATIC ${keduvocdocument_LIB_SRCS}) set_target_properties(keduvocdocument_static PROPERTIES COMPILE_FLAGS -DKEDUVOCDOCUMENT_STATIC_DEFINE) target_link_libraries(keduvocdocument_static PUBLIC KF5::KIOCore Qt5::Xml Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus Qt5::Multimedia ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} PRIVATE KF5::I18n KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets KF5::KIONTLM KF5::Archive KF5::Completion KF5::WidgetsAddons KF5::SonnetCore KF5::SonnetUi KF5::Notifications KF5::XmlGui KF5::KrossCore KF5::KrossUi KF5::NewStuff ) # if we want to set our own version instead of following kde generic #set(LIB_KEDUVOCDOCUMENT_VERSION "5.0.0") #set(LIB_KEDUVOCDOCUMENT_SOVERSION "5") #set_target_properties(keduvocdocument # PROPERTIES VERSION ${LIB_KEDUVOCDOCUMENT_VERSION} # SOVERSION ${LIB_KEDUVOCDOCUMENT_SOVERSION} #) install(TARGETS KEduVocDocument EXPORT LibKEduVocDocumentTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install(FILES ${CMAKE_CURRENT_BINARY_DIR}/keduvocdocument_export.h ${KdeEdu_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/libkeduvocdocument COMPONENT Devel ) diff --git a/keduvocdocument/keduvocscriptmanager.cpp b/keduvocdocument/keduvocscriptmanager.cpp new file mode 100644 index 0000000..9636e9b --- /dev/null +++ b/keduvocdocument/keduvocscriptmanager.cpp @@ -0,0 +1,219 @@ +/*************************************************************************** + + Copyright 2008 Avgoustinos Kadis + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "keduvocscriptmanager.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +//using namespace Editor; + +class KEduVocScriptManager::Private +{ +public: + Private( QWidget *parent, KEduVocEditorDocument* document, KEduVocVocabularyModel* vocabularyModel, QString separator ); + + QList m_scripts; + QMap m_scriptObjects; + QList m_scriptActions; + KEduVocEditorDocument* m_document; + KEduVocVocabularyModel* m_vocabularyModel; + QString m_separator; + QWidget *m_parent; + ///script objects (objects that will be used from inside the scripts) + Scripting::KEduVocDocument* m_scriptingDoc; +}; + +KEduVocScriptManager::Private::Private( QWidget *parent, KEduVocEditorDocument* document, KEduVocVocabularyModel* vocabularyModel, QString separator ) +{ + m_parent = parent; + m_document = document; + m_vocabularyModel = vocabularyModel; + m_separator = separator; +} + + +KEduVocScriptManager::KEduVocScriptManager( QWidget *parent, KEduVocEditorDocument* document, KEduVocVocabularyModel* vocabularyModel, QString separator ) + : d( new Private( parent, document, vocabularyModel, separator ) ) +{ + //add Scripting::KEduVocDocument + d->m_scriptingDoc = new Scripting::KEduVocDocument( d->m_document->document(), d->m_vocabularyModel, d->m_separator ); + addObject( d->m_scriptingDoc, QApplication::applicationName() ); +} + + +KEduVocScriptManager::~KEduVocScriptManager() +{ + delete d; +} + + +QStringList KEduVocScriptManager::getDesktopFiles() +{ +// QStringList scriptsAvailable; + QStringList dirs( + QStandardPaths::locateAll( + QStandardPaths::DataLocation, "plugins", QStandardPaths::LocateDirectory ) ); + QStringList filenames; + foreach( const QString dir, dirs ) { + foreach( const QString filename, QDir( dir ).entryList( QDir::Files ) ) { + if( filename.endsWith( QLatin1String( ".desktop" ) ) ) { + filenames << dir + '/' + filename; + } + } + } + return filenames; +} + + +QMap KEduVocScriptManager::categories() +{ + QMap categories; + categories["translation"] = "Translation"; + return categories; +} + + +QString KEduVocScriptManager::getScriptEntry( QString desktopFile ) +{ + //open it as a raw configuration file and read the script entry + KConfig scriptconfig( desktopFile, KConfig::SimpleConfig ); + KConfigGroup group = scriptconfig.group( "Desktop Entry" ); + return group.readEntry( "Script" ); +} + + +QString KEduVocScriptManager::getScriptFileName( QString desktopFile ) +{ + QFileInfo desktopFileInfo( desktopFile ); + return desktopFileInfo.absolutePath() + '/' + KEduVocScriptManager::getScriptEntry( desktopFile ); +} + + +QStringList KEduVocScriptManager::enabledScripts() +{ + QStringList enabledScripts; + // Open parleyrc to read the state of the plugins (enabled/disabled) + QString fileName = QApplication::applicationName().toLower() + "rc"; + KConfigGroup cfg( KSharedConfig::openConfig( fileName ), "Plugins" ); + // Get list of KPluginInfo for each of the desktop files found + QList pluginsInfoList = KPluginInfo::fromFiles( getDesktopFiles() ); + // Find which plugins are enabled and add them to enabledScripts list + KPluginInfo inf; + foreach( inf, pluginsInfoList ) { + inf.load( cfg ); + if( inf.isPluginEnabled() ) + enabledScripts.push_back( inf.entryPath() ); +// qDebug() << inf.name() << inf.isPluginEnabled() << inf.pluginName(); + } + return enabledScripts; +} + + +void KEduVocScriptManager::disablePlugin( QString desktopFile ) +{ + KConfigGroup cfg( KSharedConfig::openConfig( QApplication::applicationName().toLower() + "rc" ), "Plugins"); + KPluginInfo inf( desktopFile ); + //load parleyrc enabled value + inf.load( cfg ); + inf.setPluginEnabled( false ); + //save enabled=true in parleyrc + inf.save( cfg ); +} + + +void KEduVocScriptManager::loadScripts() +{ + QStringList scripts = enabledScripts(); + QStringList failed; + QStringList errorDetails; + foreach( const QString & script, scripts ) { + //create a new Script and add it to the m_scripts list + KEduVocScript * s = new KEduVocScript( getScriptFileName( script ) ); + s->addObjects( d->m_scriptObjects ); + s->activate(); + d->m_scripts.push_back( s ); + if( !s->isActivated() ) { + failed << getScriptFileName( script ); //TODO: real name? + errorDetails << s->errorMessage(); + disablePlugin( script ); + } + } + //inform with a message box when a script could not be activated + if( !failed.empty() ) { + QString errorMessage = "

" + i18np( "A script could not be activated and has been disabled.", "%1 scripts could not be activated and have been disabled.", failed.count() ) + ' ' + i18n( "This probably means that there are errors in the script or that the required packages are not installed." ) + "

"; + errorMessage += "
  • " + failed.join( "
  • " ) + "
"; + KMessageBox::detailedError( d->m_parent, errorMessage, errorDetails.join( "
" ), i18n( "Script Activation" ) ); + } +} + +void KEduVocScriptManager::addObject(QObject * obj, const QString & name) +{ + d->m_scriptObjects[name] = obj; +} + +KEduVocTranslator * KEduVocScriptManager::translator() { + return d->m_scriptingDoc->translator(); +} + +void KEduVocScriptManager::reloadScripts() +{ + //deactivate (delete) all the active scripts + foreach( KEduVocScript * s, d->m_scripts ) { + if( s ) + delete s; + } + d->m_scripts.clear(); + + //reload the scripts menu + emit editorUnplugActionList( "scripts_actionlist" ); + d->m_scriptActions.clear(); + emit editorPlugActionList( "scripts_actionlist", d->m_scriptActions ); + + //load all the enabled scripts + loadScripts(); +} + + +void KEduVocScriptManager::addScriptAction( const QString & name, QAction * action ) +{ + //unplug action list (orelse it will add twice the same entries + emit editorUnplugActionList( "scripts_actionlist" ); + + //add to action collection + emit editorActionAdded( name, action ); + + //add it to actions menu list + d->m_scriptActions.push_back( action ); + + //plug the action list + emit editorPlugActionList( "scripts_actionlist", d->m_scriptActions ); +} diff --git a/keduvocdocument/keduvocscriptmanager.h b/keduvocdocument/keduvocscriptmanager.h new file mode 100644 index 0000000..38b0acf --- /dev/null +++ b/keduvocdocument/keduvocscriptmanager.h @@ -0,0 +1,170 @@ +/*************************************************************************** + + Copyright 2008 Avgoustinos Kadis + + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KEDUVOCSCRIPTMANAGER_H +#define KEDUVOCSCRIPTMANAGER_H + +#include +#include +#include + +#include +#include +#include +#include + + +/** + * This class finds the scripts installed in the application directory and manages loading and unloading of the scripts. For each script an instance of Script class is created. + * + * @author Avgoustinos Kadis +*/ +class KEDUVOCDOCUMENT_EXPORT KEduVocScriptManager : public QObject +{ + Q_OBJECT + +public: + + /** + * @param parent: editor + * @param document: editor->m_mainWindow->parleyDocument() + * @param vocabularyModel: editor->m_vocabularyModel + * @param separator: Prefs::separator() + * + * Where 'editor' is an EditorWindow / KXmlGuiWindow object + */ + KEduVocScriptManager( QWidget *parent, KEduVocEditorDocument* document, KEduVocVocabularyModel* vocabularyModel, QString separator ); + + ~KEduVocScriptManager(); + + /** + * Finds all the available desktop files in {PARLEY_DATA_FOLDER}/plugins + * + * @return The list of desktop filenames available for parley + */ + static QStringList getDesktopFiles(); + + /** + * Returns a QMap (from from categories codenames to categories display label) + * to be used in KPluginSelector (ScriptDialog) for displaying the various + * categories + * + * @note this function is not used later on (categories are disabled) + * + * @return the QMap described above + */ + static QMap categories(); + + /** + * Parses the desktop @p desktopFile given and returns the value of "Script" entry. + * + * @param desktopFile The .desktop file that will get the value from + * @return The value of "Script" entry. Empty string of no "Script" entry is found + */ + static QString getScriptEntry(QString desktopFile); + + /** + * Returns the full path to the script name given in the @p desktopFile. + * + * @param desktopFile The desktop file for the parley plugin + * @return The full-path to the script + */ + QString getScriptFileName(QString desktopFile); + + /** + * Returns a list of filenames (full path) of enabled scripts + */ + QStringList enabledScripts(); + + /** + * Modify the parleyrc configuration so it disables the @p dektopFile plugin. + * This function is to be used when the plugin is invalid (wrong script name, + * incorrect desktop file etc) + * + * @param desktopFile + */ + void disablePlugin(QString desktopFile); + + /** + * Loads (activates) all the available scripts and notifies the user if any + * script was not activated (due to errors in the script) + */ + void loadScripts(); + + /** + * Adds a QObject as a module for the script + * @param obj The QObject to be added to the script + * @param name The name of the object as it will appear in the script + */ + void addObject(QObject * obj, const QString & name); + + /** + * Reloads all the scripts + */ + void reloadScripts(); + + /** + * Add a QAction to the Scripts menu + * @param name The action name + * @param action QAction to be added + */ + void addScriptAction(const QString & name, QAction * action); + + /** returns the Translator object the Scripting::KEduVocDocument */ + KEduVocTranslator * translator(); + +signals: + /** + * Sample slot + * + * void unplugAction( QString list ) + * { + * m_editor->unplugActionList( list ); + * } + * + * Where m_editor is EditorWindow object + */ + void editorUnplugActionList( QString ); + + /** + * Sample slot + * + * void plugAction( QString list, QList scriptActions ) + * { + * m_editor->plugActionList( list, scriptActions ); + * } + * + * Where m_editor is EditorWindow object + */ + void editorPlugActionList( QString, QList ); + + /** + * Sample slot + * + * void editorAddActionCollection( const QString& name, QAction* action ) + * { + * m_editor->actionCollection()->addAction( name, action ); + * } + * + * Where m_editor is EditorWindow object + */ + void editorActionAdded( const QString&, QAction* ); + + +private: + class Private; + Private * const d; +}; + +#endif diff --git a/keduvocdocument/keduvoctranslator.h b/keduvocdocument/keduvoctranslator.h index c7e03fe..269aea6 100644 --- a/keduvocdocument/keduvoctranslator.h +++ b/keduvocdocument/keduvoctranslator.h @@ -1,372 +1,373 @@ /*************************************************************************** Copyright 2008 Avgoustinos Kadis ***************************************************************************/ /*************************************************************************** * * * 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 KEDUVOCTRANSLATOR_H #define KEDUVOCTRANSLATOR_H #include #include #include #include #include #include #include /** Keeps the translated words @author Avgoustinos Kadis */ class KEDUVOCDOCUMENT_EXPORT KEduVocTranslator { public: KEduVocTranslator(); KEduVocTranslator(QObject * parent); ~KEduVocTranslator(); /** * Stores the translation of @p word from language @p fromLanguage, to language @p toLanguage. * @param word word that was translated * @param fromLanguage language of @p word * @param toLanguage language of @p translation * @param translation translation of @p word */ void addTranslation(QString word, QString fromLanguage, QString toLanguage, QString translation); /** * Returns a QStringList with all the translations of @p word from @p fromLanguage to @p toLanguage. * This function will call the translateWord function of the translation scripts if this word * wasn't translated before. * @param word * @param fromLanguage * @param toLanguage * @return QStringList with the translations (or an empty QStringList if no translations found) */ QSet* getTranslation(QString word, QString fromLanguage, QString toLanguage); private: class Private; Private * const d; }; -/*namespace Editor +namespace Editor { - class EditorWindow; -}*/ + // TODO uncomment after adding EditorWindow + //class EditorWindow; +} namespace Scripting { /** * @class KEduVocDocument * @brief KEduVocDocument scripting class * * KEduVocDocument class is the main entry point of KEduVocDocument scripting classes. Through it you can access the Document class (KEduVocDocument.doc or KEduVocDocument.document) which provides functionality for viewing/modifying a %KEduVocDocument document , that means access lessons, entries, document languages etc. * * Here follows a list of possible usages of KEduVocDocument class: * * - Add a new Action to the script menu (see KEduVocDocument::newAction() function) * - Add a new translation script (see KEduVocDocument::translateWord() signal) * - Have direct access to the active lesson (see KEduVocDocument::activeLesson property) * - Have access to various enumerations (see KEduVocDocument::Number, KEduVocDocument::Case, KEduVocDocument::Person, KEduVocDocument::Gender and KeduVocDocument::Definiteness enumerations) * - Create a new %KEduVocDocument %Document (see KEduVocDocument::newDocument() function) * * Signals and Slots: To connect a script function (slot) to a signal you just define a function with the same name as the signal or use the KEduVocDocument.connect function: * @code * #how to connect a function to a signal (example with KEduVocDocument::translateWord() signal) * def translateFromInternet(word,fromLang,toLang): * print "Translating from Internet!!.." * * KEduVocDocument.connect("translateWord(const QString &,const QString &,const QString &)",translateFromInternet) * @endcode * * @author Avgoustinos Kadis */ class KEDUVOCDOCUMENT_EXPORT KEduVocDocument : public QObject { Q_OBJECT /// Read-only property of the active document Q_PROPERTY(QObject * document READ getDocument) /// Abreviation of document property (same as KEduVocDocument.document) Q_PROPERTY(QObject * doc READ getDocument) /// Currently active lesson //Q_PROPERTY(QObject * activeLesson READ activeLesson) // Q_ENUMS ( Number Case Person Gender Definiteness ) Q_ENUMS(Flags) public: enum Flags { // This is used for both empty flags and to denote no flags of the correct type were set. NoInformation = 0x0, // Gender Masculine = 0x1, Feminine = 0x2, Neuter = 0x4, // Plurality Singular = 0x10, Dual = 0x20, Plural = 0x40, // Part of Speech Verb = 0x100, Noun = 0x200, Pronoun = 0x400, Adjective = 0x800, Adverb = 0x1000, Article = 0x2000, Conjunction = 0x4000, // Person First = 0x10000, Second = 0x20000, Third = 0x40000, // Declension Case Nominative = 0x80000, Genitive = 0x100000, Dative = 0x200000, Accusative = 0x400000, Ablative = 0x800000, Locative = 0x1000000, Vocative = 0x2000000, // Other assorted flags Definite = 0x4000000, // The article is definite Indefinite = 0x8000000, // The article is indefinite Regular = 0x10000000, Irregular = 0x20000000 }; /** * @param doc Represents a KEduVococument object * For example, when using this function in Parley, pass the doc value like this: * m_editor->m_mainWindow->parleyDocument()->document() * where m_editor is a EditorWindow object * @param vocabularyModel Represents the VocabularyModel object for the KEduVocDocument * For example, when using this function in Parley, pass the vocabularyModel value like this: * m_editor->m_vocabularyModel * where m_editor is a EditorWindow object * @param separator Represents Prefs::separator() */ KEduVocDocument( ::KEduVocDocument * doc, KEduVocVocabularyModel * vocabularyModel, QString separator ); ~KEduVocDocument(); /* * Emits translateWord signal so the script function connected to it translate the @p word * @param word Word to translate * @param fromLanguage The language of @p word to translate from * @param toLanguage The language you want to translate to */ void callTranslateWord(const QString & word, const QString& fromLanguage, const QString& toLanguage); //sets the translator object // void setTranslator ( Translator* translator ) { m_translator = translator; } KEduVocTranslator * translator() { return m_translator; } //Returns the active document QObject* getDocument() { return m_doc; } //Returns the active lesson //KEduVocLesson* activeLesson(); QString separator() { return m_separator; } void setSeparator( QString v ) { m_separator = v; } public Q_SLOTS: QStringList dataDirs() { return QStandardPaths::standardLocations(QStandardPaths::DataLocation); } QStringList pluginDirs() { QStringList basedirs(QStandardPaths::standardLocations(QStandardPaths::DataLocation)); QStringList ret; foreach ( const QString dir , basedirs){ ret << (dir + "/plugins"); } return ret; } /** close the document*/ void close(); /** Returns a list of Expression objects (the selected entries of the active lesson) Usage example: While using in Parley, pass the 'indexes' value like this indexes = m_editor->m_vocabularyView->getSelectedIndexes(); where m_editor is a EditorWindow object TODO Add a KEduVocVocabularyView object to this class (after is is moved to keduvoc from parley) and access getSelectedIndexes() from there */ QVariantList selectedEntries( QModelIndexList indexes ); /** Returns a list of Translation objects (the selected translations of the active lesson) Usage example: While using in Parley, pass the 'indexes' value like this indexes = m_editor->m_vocabularyView->getSelectedIndexes(); where m_editor is a EditorWindow object TODO Add a KEduVocVocabularyView object to this class (after is is moved to keduvoc from parley) and access getSelectedIndexes() from there */ QVariantList selectedTranslations( QModelIndexList indexes ); /** * Adds the found @p translation of the @p word from language @p fromLanguage to language @p toLanguage to %KEduVocDocument translations to be used for translating lesson entries (or anything else). This function is ment to be used by scripts to add a translation of a word by parsing either online or offline dictionaries. * * @code * #example usage of addTranslation function * import KEduVocDocument * #function called by KEduVocDocument whenever a translation of a word is needed * def translateWord(word,fromLang,toLang): * <> * KEduVocDocument.addTranslation(word,fromLang,toLang,foundWord) * <> * @endcode * * @param word Translated word * @param fromLanguage From language * @param toLanguage To language * @param translation %Translation of word */ void addTranslation(QString word, QString fromLanguage, QString toLanguage, QString translation); /** * Returns a list of all available locales (to be used by the scripts) * @return */ QStringList locales(); /** * Gives the language name of the given @p locale * @param locale Language locale * @return Language name */ QString localeName(QString locale); /// @todo Make this function working (not very important function) /* * Open the KEduVocDocument Document @p filename * Usage: * @code * import KEduVocDocument * KEduVocDocument.open("Vocab/MyVocab.kvtml") * @endcode * @param file KEduVocDocument Document file path (ex. /home/kde-user/MyVocab.kvtml) */ bool open(QString filename); /** * Creates a new document and returns a reference to it * * @code * #how to create a new document, add lessons, add entries and save it to a kvtml file * import KEduVocDocument * * #create new document * doc = KEduVocDocument.newDocument() * doc.title = "New document" * * #set identifiers * doc.appendNewIdentifier("English","en_US") * doc.appendNewIdentifier("French","fr") * * #lessons * l1 = doc.newLesson("Lesson1") * doc.rootLesson.appendChildLesson(l1) * * #add a new entry (first way) * e = l1.newEntry() * e.setTranslation(0,"dog") * e.setTranslation(1,"chien") * l1.appendEntry(e) * * #add a new entry (second way) * ee = l1.newEntry(["glass","verre"]) * l1.appendEntry(ee) * #third way * ee = l1.appendNewEntry(["book","livre"]) * * #add a new lesson (fast way) * l2 = doc.appendNewLesson("Lesson 2") * * #add a new child lesson under "Lesson 2" * l3 = doc.appendNewLesson("Lesson 3",l2) * * #add a new entry (third way) * l2.appendNewEntry(["I","je"]); * l3.appendNewEntry(["good morning","bonjour"]) * * #save document * doc.saveAs("/home/kde-devel/test_new_document.kvtml") * @endcode * * @return A Document object, the newly created lesson */ QObject * newDocument() { return new ::KEduVocDocument(); } Q_SIGNALS: /** * Slots (script functions) connected to this signal are called when a translation of @p word is requested. Note that a script function with the same name as a signal will be automatically connected to that signal when the script is activated. * * @code * #example usage of translateWord signal * import KEduVocDocument * #function called by KEduVocDocument whenever a translation of a word is needed * def translateWord(word,fromLang,toLang): * <> * KEduVocDocument.addTranslation(word,fromLang,toLang,foundWord) * <> * @endcode * * @param word Word to translate * @param fromLanguage The language of @p word to translate from * @param toLanguage The language you want to translate to */ void translateWord(const QString & word, const QString& fromLanguage, const QString& toLanguage); /* Emits when the translation of a word is finished (from all the scripts) [not to be used by scripts] */ void translationFinished(const QString & word, const QString& fromLanguage, const QString& toLanguage); /* Emits when the translation of a word starts [not to be used by scripts] */ void translationStarted(const QString & word, const QString& fromLanguage, const QString& toLanguage); /** Emitted when the document pointer is changed. */ void documentChanged(::KEduVocDocument *newDocument); private: KEduVocTranslator* m_translator; ::KEduVocDocument* m_doc; KEduVocVocabularyModel * m_vocabularyModel; QString m_separator; }; } Q_DECLARE_METATYPE( KEduVocTranslation* ) #endif