From a652432c9298ae52737ee993dc6bd9f07eb7c995 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mateusz=20P=C3=B3=C5=82rola?= Date: Fri, 3 Sep 2010 08:23:17 +0200 Subject: [PATCH] Changed include folder name --- mdictionary.pro | 21 ++- src/common/AccentsNormalizer.h | 81 --------- src/common/CommonDictInterface.h | 141 ---------------- src/common/DictDialog.h | 51 ------ src/common/GUIInterface.h | 195 ---------------------- src/common/History.h | 70 -------- src/common/Notify.h | 45 ----- src/common/settings.h | 71 -------- src/common/translation.h | 80 --------- src/include/AccentsNormalizer.h | 81 +++++++++ src/include/CommonDictInterface.h | 141 ++++++++++++++++ src/include/DictDialog.h | 51 ++++++ src/include/GUIInterface.h | 195 ++++++++++++++++++++++ src/include/History.h | 70 ++++++++ src/include/Notify.h | 45 +++++ src/include/settings.h | 71 ++++++++ src/include/translation.h | 80 +++++++++ src/mdictionary/backbone/BookmarkTranslations.h | 4 +- src/mdictionary/backbone/Bookmarks.h | 6 +- src/mdictionary/backbone/History.cpp | 2 +- src/mdictionary/backbone/backbone.h | 10 +- src/mdictionary/gui/AboutWidget.h | 2 +- src/mdictionary/gui/BookmarksWidget.h | 2 +- src/mdictionary/gui/DictManagerWidget.cpp | 2 +- src/mdictionary/gui/DictManagerWidget.h | 2 +- src/mdictionary/gui/DictTypeSelectDialog.h | 4 +- src/mdictionary/gui/HistoryListDialog.h | 2 +- src/mdictionary/gui/MainWindow.h | 4 +- src/mdictionary/gui/NotifyManager.h | 2 +- src/mdictionary/gui/SearchBarWidget.cpp | 2 +- src/mdictionary/gui/SearchBarWidget.h | 2 +- src/mdictionary/gui/SettingsWidget.h | 4 +- src/mdictionary/gui/TranslationWidget.h | 2 +- src/mdictionary/gui/WordListWidget.cpp | 2 +- src/mdictionary/gui/main.cpp | 4 +- src/mdictionary/mdictionary.pro | 34 +++- src/plugins/google/GoogleDictDialog.h | 4 +- src/plugins/google/GooglePlugin.h | 6 +- src/plugins/google/GoogleSettingsDialog.h | 2 +- src/plugins/google/TranslationGoogle.h | 2 +- src/plugins/google/google.pro | 8 +- src/plugins/xdxf/TranslationXdxf.h | 2 +- src/plugins/xdxf/XdxfDictDialog.h | 2 +- src/plugins/xdxf/XdxfLoadDialog.h | 2 +- src/plugins/xdxf/XdxfSettingsDialog.h | 2 +- src/plugins/xdxf/xdxf.pro | 8 +- src/plugins/xdxf/xdxfplugin.cpp | 2 +- src/plugins/xdxf/xdxfplugin.h | 4 +- src/src.pro | 10 ++ tests/mDictionaryTests/CommonDictInterfaceMock.h | 2 +- tests/mDictionaryTests/TranslationMock.h | 2 +- tests/mDictionaryTests/mDictionaryTests.pro | 20 ++- tests/tests.pro | 7 +- 53 files changed, 865 insertions(+), 801 deletions(-) delete mode 100644 src/common/AccentsNormalizer.h delete mode 100644 src/common/CommonDictInterface.h delete mode 100644 src/common/DictDialog.h delete mode 100644 src/common/GUIInterface.h delete mode 100644 src/common/History.h delete mode 100644 src/common/Notify.h delete mode 100644 src/common/settings.h delete mode 100644 src/common/translation.h create mode 100644 src/include/AccentsNormalizer.h create mode 100644 src/include/CommonDictInterface.h create mode 100644 src/include/DictDialog.h create mode 100644 src/include/GUIInterface.h create mode 100644 src/include/History.h create mode 100644 src/include/Notify.h create mode 100644 src/include/settings.h create mode 100644 src/include/translation.h diff --git a/mdictionary.pro b/mdictionary.pro index ee0ade9..f501bf2 100644 --- a/mdictionary.pro +++ b/mdictionary.pro @@ -1,6 +1,13 @@ TEMPLATE = subdirs +SUBDIRS = src tests +CONFIG += ordered include (mdictionary.pri) -SUBDIRS = src + + +check.CONFIG += recursive +check.recurse = src tests +check.depends = install +QMAKE_EXTRA_TARGETS += check message("Enabled sources: "$$ENABLED_SRC) message("Enabled plugins: "$$ENABLED_PLUGINS) @@ -10,3 +17,15 @@ message("Binary directory: "$$BIN_DIR) message("Data directory: "$$DATA_DIR) message("Plugins directory: "$$PLUGINS_DIR) message("Documentation directory: "$$DOCS_DIR) + + +if(coverage) { + coverage-report.CONFIG = recursive + coverage-report.recurse = src + QMAKE_EXTRA_TARGETS += coverage-report + message('******************************************************************' ) + message('* Remember to disable CCACHE in scratchbox to make Code Coverage' ) + message('* report!' ) + message('* use command: export SBOX_USE_CCACHE="no"' ) + message('******************************************************************' ) +} diff --git a/src/common/AccentsNormalizer.h b/src/common/AccentsNormalizer.h deleted file mode 100644 index 0343e88..0000000 --- a/src/common/AccentsNormalizer.h +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - - This file is part of mDictionary. - - mDictionary 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 3 of the License, or - (at your option) any later version. - - mDictionary is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mDictionary. If not, see . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -/*! /file AccentsNormalizer.h -\brief Common functionality for all classes that need to remove accents from strings - -\author Bartosz Szatkowski -*/ - -#ifndef ACCENTSNORMALIZER_H -#define ACCENTSNORMALIZER_H - -#include -#include -#include - - -class AccentsNormalizer { - protected: - QMap letters; - QRegExp noLetter; - - QString removeAccents(QString string) { - string = string.toLower(); - QString normalized = string.normalized(QString::NormalizationForm_KD); - foreach(QChar let, letters.keys()) { - normalized.replace(letters[let], QString(let)); - } - normalized.replace(noLetter, ""); - return normalized; - } - - void initAccents() { - letters['a'] = QRegExp(QString::fromUtf8("[ÀàÁáÂÂâÃãÄäÅåæÆĀāĂ㥹ǠȀǡȁǢȂǣȃȦȧǺȺǻǼǍǽǎǞǟⱥ]"), Qt::CaseInsensitive); - letters['b'] = QRegExp(QString::fromUtf8("[ƀƁƂƃɃƄƅ]"), Qt::CaseInsensitive); - letters['c'] = QRegExp(QString::fromUtf8("[ÇçÈçŒĆćĈĉĊċČčƇƈȻȼ]"), Qt::CaseInsensitive); - letters['d'] = QRegExp(QString::fromUtf8("[ÐĐđĎďȡƉ]"), Qt::CaseInsensitive); - letters['e'] = QRegExp(QString::fromUtf8("[ÈéèÉÊêËëĒēĔĕĖėĘęĚěēȄȅȆɆȇɇȨȩ]"), Qt::CaseInsensitive); - letters['f'] = QRegExp(QString::fromUtf8("[ſƑƒꜰ]"), Qt::CaseInsensitive); - letters['g'] = QRegExp(QString::fromUtf8("[ĠġĢģĜĝĞğƓǤǴǥǵǦǧ]"), Qt::CaseInsensitive); - letters['h'] = QRegExp(QString::fromUtf8("[ħĤĥĦȞȟⱧⱨ]"), Qt::CaseInsensitive); - letters['i'] = QRegExp(QString::fromUtf8("[ÌìÍíÎîÏïİijĨĩĪīĬĭĮįǐƗȈȉȊȋǏꟾ]"), Qt::CaseInsensitive); - letters['j'] = QRegExp(QString::fromUtf8("[ĴĵǰȷɈɉⱼ]"), Qt::CaseInsensitive); - letters['k'] = QRegExp(QString::fromUtf8("[ĶķĸƘǨƙǩⱩⱪ]"), Qt::CaseInsensitive); - letters['l'] = QRegExp(QString::fromUtf8("[ŀŁłĹĺĻļĽľĿȴȽⱠⱡⱢꝈ]"), Qt::CaseInsensitive); - letters['m'] = QRegExp(QString::fromUtf8("[Ɱ]"), Qt::CaseInsensitive); - letters['n'] = QRegExp(QString::fromUtf8("[ÑñŃńŅņŇňʼnŊŋȵǸǹƝ]"), Qt::CaseInsensitive); - letters['o'] = QRegExp(QString::fromUtf8("[ÒòÓóÔÕõÖöØøŐőœŌōŎŏƠȰơǑȱǒǪȪǫȫǬȌȬǭȍȭǾȎȮǿȏȯⱺ]"), Qt::CaseInsensitive); - letters['p'] = QRegExp(QString::fromUtf8("[ƤƥⱣ]"), Qt::CaseInsensitive); - letters['q'] = QRegExp(QString::fromUtf8("[Ɋɋ]"), Qt::CaseInsensitive); - letters['r'] = QRegExp(QString::fromUtf8("[ŕŖŖŗŘřȐȑȒȓɌɍⱤ]"), Qt::CaseInsensitive); - letters['s'] = QRegExp(QString::fromUtf8("[ߊšŚśŜŝŞşȘșȿꜱ]"), Qt::CaseInsensitive); - letters['t'] = QRegExp(QString::fromUtf8("[ŢţŤťŦŧȶȚƫțƬƮȾⱦ]"), Qt::CaseInsensitive); - letters['u'] = QRegExp(QString::fromUtf8("[ÙùÚúÛûÜüŰűŲųŨũŪūŬŮůưǓǔȔɄǕȕǖȖǗȗǘǙǚǛǜƯ]"), Qt::CaseInsensitive); - letters['v'] = QRegExp(QString::fromUtf8("[Ʋⱱⱴⱽ]"), Qt::CaseInsensitive); - letters['w'] = QRegExp(QString::fromUtf8("[ŴŵⱲⱳ]"), Qt::CaseInsensitive); - letters['y'] = QRegExp(QString::fromUtf8("[ÿÝýŶŷŸȲƳȳƴɎɏ]"), Qt::CaseInsensitive); - letters['z'] = QRegExp(QString::fromUtf8("[ŹźŻżŽžɀȤƵȥƶⱫⱬ]"), Qt::CaseInsensitive); - noLetter = QRegExp("[^-a-z '\"]", Qt::CaseInsensitive); - } -}; - -#endif // ACCENTSNORMALIZER_H diff --git a/src/common/CommonDictInterface.h b/src/common/CommonDictInterface.h deleted file mode 100644 index 899843a..0000000 --- a/src/common/CommonDictInterface.h +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - - This file is part of mDictionary. - - mDictionary 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 3 of the License, or - (at your option) any later version. - - mDictionary is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mDictionary. If not, see . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -/*! \file CommonDictInterface.h -\brief Common interface for all dicts and plugins \see CommonDictInterface - -\author Bartosz Szatkowski -*/ - -#ifndef COMMONDICTINTERFACE_H -#define COMMONDICTINTERFACE_H - -#include -#include -#include -#include -#include "translation.h" -#include "Notify.h" -#include "settings.h" -#include "AccentsNormalizer.h" - -class DictDialog; - - -//! Interface for dict engines plugins -class CommonDictInterface : public QObject, public AccentsNormalizer { - Q_OBJECT - public: - CommonDictInterface(QObject *parent = 0):QObject(parent) {} - - virtual ~CommonDictInterface() {} - - //! returns source language code iso 639-2 - virtual QString langFrom() const = 0; - - //! returns destination language code iso 639-2 - virtual QString langTo() const = 0; - - //! returns dictionary name (like "old English" or so) - virtual QString name() const = 0; - - //! returns dictionary type (xdxf, google translate, etc) - virtual QString type() const = 0; - - //! returns information about dictionary in html (name, authors, etc) - virtual QString infoNote() const = 0; - - /*! returns DictDialog object that creates dialogs - for adding new dictionary and changing plugin settings*/ - virtual DictDialog* dictDialog() = 0; - - - //! returns new, clean copy of plugin with settings set as in Settings* - virtual CommonDictInterface* getNew(const Settings*) const = 0; - - //! returns whether plugin can start searching - virtual bool isAvailable() const = 0; - - //! returns the actual translation of a word given in key - virtual QString search(QString key) = 0; - - //! \returns unique value (unique for every dictionary, not plugin) - virtual uint hash() const = 0; - - //! sets unique value (unique for every dictionary, not plugin) - virtual void setHash(uint) = 0; - - //! returns current plugin settings - virtual Settings* settings() = 0; - - //! returns plugin icon - virtual QIcon* icon() = 0; - - //! returns empty translation object (to be fetched later) for given key - virtual Translation* getTranslationFor(QString ) {return 0;} - - /*! plugin should delete any files (eg. cache) that have been created and are ready - to be deleted - */ - virtual void clean() {} - - - public Q_SLOTS: - /*! performs search in dictionary - \param word word to search in dictionary - \param limit limit on number of results, - if limit=0 all matching words are returned - - After finishing search it has to emit - \see CommonDictInterface:finalTranslation finalTranslation - */ - virtual QList searchWordList(QString word, int limit=0) = 0; - - //! stops current operation - virtual void stop() = 0; - - Q_SIGNALS: - - //! emitted when dictionary is ready to use afer being loaded - void loaded(CommonDictInterface*); - - //! emitted after change in dictionary settings - void settingsChanged(); - - /*! emitted to backbone when it's needed to inform user about something - \param Backbone::NotifyType GUI may decide to show different types in - different ways - \param QString text of the notification - */ - void notify(Notify::NotifyType, QString); - - -protected: - QString removeAccents(QString string) { - if(settings()->value("strip_accents") == "true") - return AccentsNormalizer::removeAccents(string); - return string; - } -}; - -Q_DECLARE_INTERFACE(CommonDictInterface, "CommonDictInterface/0.1"); - -#endif diff --git a/src/common/DictDialog.h b/src/common/DictDialog.h deleted file mode 100644 index fc83744..0000000 --- a/src/common/DictDialog.h +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - - This file is part of mDictionary. - - mDictionary 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 3 of the License, or - (at your option) any later version. - - mDictionary is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mDictionary. If not, see . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -//Created by Mateusz Półrola - -#ifndef DICTDIALOG_H -#define DICTDIALOG_H - -#include - -class Settings; - -//! Interface for plugin dialog provider -class DictDialog : public QObject { - Q_OBJECT - -public: - DictDialog(QObject *parent = 0) : QObject(parent) {} - - /*! - Shows "add new dictionary" dialog and returns settings of new dict - \param parent parent widget on which dialog will be displayed - */ - virtual Settings* addNewDictionary(QWidget*parent=0)=0; - - /*! - Shows "settings" dialog and saves new settings in plugin - \param parent parent widget on which dialog will be displayed - */ - virtual void changeSettings(QWidget *parent = 0) = 0; -}; - -#endif // DICTDIALOG_H diff --git a/src/common/GUIInterface.h b/src/common/GUIInterface.h deleted file mode 100644 index 2f10cc1..0000000 --- a/src/common/GUIInterface.h +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - - This file is part of mDictionary. - - mDictionary 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 3 of the License, or - (at your option) any later version. - - mDictionary is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mDictionary. If not, see . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ -//! \file GUIInterface.h -//! \brief Defines interface for GUI -//! \author Mateusz Półrola - - - -#ifndef GUIINTERFACE_H -#define GUIINTERFACE_H -#include -#include - -#include "translation.h" -#include "CommonDictInterface.h" - -class Settings; - -//! Interface for different GUIs -/*! - Default base class for all GUIs is QMainWindow - */ -class GUIInterface : public QMainWindow { - Q_OBJECT - -public: - GUIInterface(QWidget *parent = 0) :QMainWindow(parent) {} - - virtual ~GUIInterface() {} - - //! Returns all loaded dictionaries with information about that they are - //! active/inactive - /*! - \return Hash of pointers to dictionary and boolean flag indicating if - dictionary is active - */ - virtual QHash getDictionaries() = 0; - - - //! Returns all loaded plugins - /*! - \return List of pointers to plugins - */ - virtual QList getPlugins() = 0; - - //! Indicates if GUI is in exact search mode. - /*! When GUI is in exact search mode it searches for word, and - if it finds exactly matching translation it directly displays it, without - displaying matching word list. This mode should be - used for browsing search history and searching words from application - arguments. - \returns flag indicating if GUI is in exact search mode - */ - bool exactSearch(); - - //! Sets GUI exact search mode. - /*! \sa exactSearch() */ - void setExactSearch(bool exactSearch); - - virtual Settings* settings() = 0; - - virtual void setSettings(Settings*) = 0; - - -public Q_SLOTS: - //! Searches in exact mode for given word - /*! - GUI will be automatically set into exact search mode, and after search or - break it will be unset from exact search mode. - \param word which will be searched in dictionaries - */ - virtual void searchExact(QString word) = 0; - - //! Adds key words from given translations to history - /*! - By default this slot is connected to searchTranslations signal, and - passed translations list contains only translations with the same key, so - only one word is added to history. - \param list of translations with key words - \sa searchTranslations(); - */ - virtual void addToHistory(QList) = 0; - - //! Shows history dialog - virtual void showHistory(QPoint) = 0; - - //! Shows translation of next word in history - /*! - It will work only if there is next word available in history. - Translation of word is searched with searchExact() function - \sa searchExact() - */ - virtual void historyNext() = 0; - - //! Shows translation of previous word in history - /*! - It will work only if there is previous word available in history. - Translation of word is searched with searchExact() function - \sa searchExact() - */ - virtual void historyPrev() = 0; - - //! Gets words list from backbone and prepares received list to display - /*! - Checks if received list is empty, in that case it displays suitable - information. If GUI is in exact search mode it will search for exact - word in received list, and if word is found it will emit signal to - display its translation. Otherwise it will display list of matching - words and show suitable information. - \sa exactSearch() - \sa showTranslation() - */ - virtual void wordListReady() = 0; - - //! Gets translation strings from backbone and emits signal to display them - virtual void translationsReady() = 0; - -Q_SIGNALS: - //! Should be emitted when user wants to close application to stop - //! all ongoing searches - void quit(); - - //! Emitted when user wants to search for list of words matching given word - /*! \param word word which will be matched, it can contain wildcards - */ - void searchWordList(QString word); - - //! Emitted when user wants to see translation of words. - /*! \param list of translations for given word which will be received - in wordListReady() slot - \sa wordListReady() - */ - void searchTranslations(QList); - - //! Emitted when starting search, will disable GUI components - //! and show progress bars - void setBusy(); - - //! Emitted when searching ends, will enable GUI components - void setIdle(); - - //! Emitted when user wants to break search - void stopSearching(); - - //! Emitted after receiving word list in wordListReady() slot, will display - //! list of matched words - /*! \param hash of word and list of translations of this word found - in dictionaries - */ - void showWordList(QHash >); - - //! Emitted after receiving translation strings in translationsReady() slot, - //! will display translation of given word - /*! \param list of translations from different dictionaries - in dictionaries - */ - void showTranslation(QStringList); - - //! Emitted when user wants to add new dictionary - /*! \param new dictionary returned by specific plugin dialog - */ - void addNewDictionary(CommonDictInterface*); - - //! Emitted when user wants to remove dictionary - /*! \param dictionary which will be removed - */ - void removeDictionary(CommonDictInterface*); - - //! Emitted when user changes dictionaries active/inactive states - /*! \param list of only active dictionaries - */ - void selectedDictionaries(QList); - - void addToBookmarks(QList); -}; - -#endif // GUIINTERFACE_H diff --git a/src/common/History.h b/src/common/History.h deleted file mode 100644 index 133b3ad..0000000 --- a/src/common/History.h +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - - This file is part of mDictionary. - - mDictionary 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 3 of the License, or - (at your option) any later version. - - mDictionary is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mDictionary. If not, see . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -//Created by Mateusz Półrola - -#ifndef HISTORY_H -#define HISTORY_H - -#include -#include -#include - -class History : public QObject -{ - Q_OBJECT -public: - explicit History(int maxSize = 5, QObject *parent = 0); - -Q_SIGNALS: - void historyChanged(bool prevAvailable, - bool nextAvailable, - bool listAvailable); - -public Q_SLOTS: - void refreshStatus(); - -public: - void add(QString); - QString previous(); - QString next(); - QStringList list(); - - bool prevAvailable(); - bool nextAvailable(); - bool listAvailable(); - - void setCurrentElement(int element); - - int maxSize(); - - void setMaxSize(int size); - -private: - QVector _history; - int _maxSize; - int currentElement; - bool _prevAvailable; - bool _nextAvailable; - bool _listAvailable; -}; - -#endif // HISTORY_H diff --git a/src/common/Notify.h b/src/common/Notify.h deleted file mode 100644 index a5266e9..0000000 --- a/src/common/Notify.h +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - - This file is part of mDictionary. - - mDictionary 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 3 of the License, or - (at your option) any later version. - - mDictionary is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mDictionary. If not, see . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -/*! /file Notify.h -\brief Declaration of common notify subsystem (NotifyType for now) - -\author Bartosz Szatkowski -*/ - -#ifndef NOTIFY_H -#define NOTIFY_H - -#include -#include - -/*! Notify wraps NotifyType which is interpreted by GUI and may change way in - which GUI handles given notification - */ -class Notify : QObject { - Q_OBJECT -public: - Notify() : QObject(0) {} - Notify(const Notify&) : QObject(0) {} - enum notifytype {Error, Warning, Info}; - Q_DECLARE_FLAGS(NotifyType, notifytype); -}; -#endif // NOTIFY_H diff --git a/src/common/settings.h b/src/common/settings.h deleted file mode 100644 index 6843a79..0000000 --- a/src/common/settings.h +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - - This file is part of mDictionary. - - mDictionary 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 3 of the License, or - (at your option) any later version. - - mDictionary is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mDictionary. If not, see . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -/*! \file settings.h -\brief Settings object for plugins \see Settings - -\author Bartosz Szatkowski -*/ - -#ifndef SETTINGS_H -#define SETTINGS_H - -#include -#include -#include - -/*! Plugins or dictionaries may need to keep some of configuration between - sessions, moreover Backbone or GUI may want to store some additional info in - plugin Settings. - - It's important for plugin to store all information given to it in Settings.*/ -class Settings { - public: - Settings(){} - Settings(const Settings* set) { - _settings = QHash(set->_settings); - } - ~Settings(){} - - /*! \returns value fo given key - \param key - */ - QString value(const QString key) const { - if(!_settings.contains(key)) { - return QString(); - } - return _settings[key]; - } - - //! sets key to value - void setValue(const QString key, const QString value) { - _settings.insert(key, value); - } - - QList keys() const { - return _settings.keys(); - } - -private: - QHash _settings; -}; - -#endif // SETTINGS_H diff --git a/src/common/translation.h b/src/common/translation.h deleted file mode 100644 index a6a20a9..0000000 --- a/src/common/translation.h +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - - This file is part of mDictionary. - - mDictionary 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 3 of the License, or - (at your option) any later version. - - mDictionary is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with mDictionary. If not, see . - - Copyright 2010 Comarch S.A. - -*******************************************************************************/ - -/*! \file translation.h -\brief Interface for translation instances \see Translation - -\author Bartosz Szatkowski -*/ - -#ifndef TRANSLATION_H -#define TRANSLATION_H - -#include -#include -#include - -class CommonDictInterface; - - -/*! Translation is kind of GoF proxy, it stores key:translation pair and - provides it in lazy way -> key is available always, but translation is fetched - as late as possible*/ -class Translation { - public: - Translation () { _bookmark = 0;} - virtual ~Translation () {} - //! \return word to be translated - virtual QString key() const = 0; - - bool operator==(Translation* translation) { - return this->key()==translation->key(); - } - - /*! \returns dictionary information (plugin name, languages, etc)\ - to be displayed in translation table header */ - virtual QString dictionaryInfo() const = 0; - - //! \return parsed raw format into html - virtual QString toHtml() const = 0; - - //! \return whether given translation is taken from bookmarks - virtual bool isBookmark() const { - return _bookmark; - } - - //! \param b if true then translation is from bookmarks - void setBookmark(bool b) { - _bookmark = b; - } - - //! returns coresponding dict object - virtual uint dict() const {return 0;} - - protected: - bool _bookmark; - -}; - -Q_DECLARE_METATYPE(Translation*); -Q_DECLARE_METATYPE(QList); - -#endif diff --git a/src/include/AccentsNormalizer.h b/src/include/AccentsNormalizer.h new file mode 100644 index 0000000..0343e88 --- /dev/null +++ b/src/include/AccentsNormalizer.h @@ -0,0 +1,81 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! /file AccentsNormalizer.h +\brief Common functionality for all classes that need to remove accents from strings + +\author Bartosz Szatkowski +*/ + +#ifndef ACCENTSNORMALIZER_H +#define ACCENTSNORMALIZER_H + +#include +#include +#include + + +class AccentsNormalizer { + protected: + QMap letters; + QRegExp noLetter; + + QString removeAccents(QString string) { + string = string.toLower(); + QString normalized = string.normalized(QString::NormalizationForm_KD); + foreach(QChar let, letters.keys()) { + normalized.replace(letters[let], QString(let)); + } + normalized.replace(noLetter, ""); + return normalized; + } + + void initAccents() { + letters['a'] = QRegExp(QString::fromUtf8("[ÀàÁáÂÂâÃãÄäÅåæÆĀāĂ㥹ǠȀǡȁǢȂǣȃȦȧǺȺǻǼǍǽǎǞǟⱥ]"), Qt::CaseInsensitive); + letters['b'] = QRegExp(QString::fromUtf8("[ƀƁƂƃɃƄƅ]"), Qt::CaseInsensitive); + letters['c'] = QRegExp(QString::fromUtf8("[ÇçÈçŒĆćĈĉĊċČčƇƈȻȼ]"), Qt::CaseInsensitive); + letters['d'] = QRegExp(QString::fromUtf8("[ÐĐđĎďȡƉ]"), Qt::CaseInsensitive); + letters['e'] = QRegExp(QString::fromUtf8("[ÈéèÉÊêËëĒēĔĕĖėĘęĚěēȄȅȆɆȇɇȨȩ]"), Qt::CaseInsensitive); + letters['f'] = QRegExp(QString::fromUtf8("[ſƑƒꜰ]"), Qt::CaseInsensitive); + letters['g'] = QRegExp(QString::fromUtf8("[ĠġĢģĜĝĞğƓǤǴǥǵǦǧ]"), Qt::CaseInsensitive); + letters['h'] = QRegExp(QString::fromUtf8("[ħĤĥĦȞȟⱧⱨ]"), Qt::CaseInsensitive); + letters['i'] = QRegExp(QString::fromUtf8("[ÌìÍíÎîÏïİijĨĩĪīĬĭĮįǐƗȈȉȊȋǏꟾ]"), Qt::CaseInsensitive); + letters['j'] = QRegExp(QString::fromUtf8("[ĴĵǰȷɈɉⱼ]"), Qt::CaseInsensitive); + letters['k'] = QRegExp(QString::fromUtf8("[ĶķĸƘǨƙǩⱩⱪ]"), Qt::CaseInsensitive); + letters['l'] = QRegExp(QString::fromUtf8("[ŀŁłĹĺĻļĽľĿȴȽⱠⱡⱢꝈ]"), Qt::CaseInsensitive); + letters['m'] = QRegExp(QString::fromUtf8("[Ɱ]"), Qt::CaseInsensitive); + letters['n'] = QRegExp(QString::fromUtf8("[ÑñŃńŅņŇňʼnŊŋȵǸǹƝ]"), Qt::CaseInsensitive); + letters['o'] = QRegExp(QString::fromUtf8("[ÒòÓóÔÕõÖöØøŐőœŌōŎŏƠȰơǑȱǒǪȪǫȫǬȌȬǭȍȭǾȎȮǿȏȯⱺ]"), Qt::CaseInsensitive); + letters['p'] = QRegExp(QString::fromUtf8("[ƤƥⱣ]"), Qt::CaseInsensitive); + letters['q'] = QRegExp(QString::fromUtf8("[Ɋɋ]"), Qt::CaseInsensitive); + letters['r'] = QRegExp(QString::fromUtf8("[ŕŖŖŗŘřȐȑȒȓɌɍⱤ]"), Qt::CaseInsensitive); + letters['s'] = QRegExp(QString::fromUtf8("[ߊšŚśŜŝŞşȘșȿꜱ]"), Qt::CaseInsensitive); + letters['t'] = QRegExp(QString::fromUtf8("[ŢţŤťŦŧȶȚƫțƬƮȾⱦ]"), Qt::CaseInsensitive); + letters['u'] = QRegExp(QString::fromUtf8("[ÙùÚúÛûÜüŰűŲųŨũŪūŬŮůưǓǔȔɄǕȕǖȖǗȗǘǙǚǛǜƯ]"), Qt::CaseInsensitive); + letters['v'] = QRegExp(QString::fromUtf8("[Ʋⱱⱴⱽ]"), Qt::CaseInsensitive); + letters['w'] = QRegExp(QString::fromUtf8("[ŴŵⱲⱳ]"), Qt::CaseInsensitive); + letters['y'] = QRegExp(QString::fromUtf8("[ÿÝýŶŷŸȲƳȳƴɎɏ]"), Qt::CaseInsensitive); + letters['z'] = QRegExp(QString::fromUtf8("[ŹźŻżŽžɀȤƵȥƶⱫⱬ]"), Qt::CaseInsensitive); + noLetter = QRegExp("[^-a-z '\"]", Qt::CaseInsensitive); + } +}; + +#endif // ACCENTSNORMALIZER_H diff --git a/src/include/CommonDictInterface.h b/src/include/CommonDictInterface.h new file mode 100644 index 0000000..899843a --- /dev/null +++ b/src/include/CommonDictInterface.h @@ -0,0 +1,141 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file CommonDictInterface.h +\brief Common interface for all dicts and plugins \see CommonDictInterface + +\author Bartosz Szatkowski +*/ + +#ifndef COMMONDICTINTERFACE_H +#define COMMONDICTINTERFACE_H + +#include +#include +#include +#include +#include "translation.h" +#include "Notify.h" +#include "settings.h" +#include "AccentsNormalizer.h" + +class DictDialog; + + +//! Interface for dict engines plugins +class CommonDictInterface : public QObject, public AccentsNormalizer { + Q_OBJECT + public: + CommonDictInterface(QObject *parent = 0):QObject(parent) {} + + virtual ~CommonDictInterface() {} + + //! returns source language code iso 639-2 + virtual QString langFrom() const = 0; + + //! returns destination language code iso 639-2 + virtual QString langTo() const = 0; + + //! returns dictionary name (like "old English" or so) + virtual QString name() const = 0; + + //! returns dictionary type (xdxf, google translate, etc) + virtual QString type() const = 0; + + //! returns information about dictionary in html (name, authors, etc) + virtual QString infoNote() const = 0; + + /*! returns DictDialog object that creates dialogs + for adding new dictionary and changing plugin settings*/ + virtual DictDialog* dictDialog() = 0; + + + //! returns new, clean copy of plugin with settings set as in Settings* + virtual CommonDictInterface* getNew(const Settings*) const = 0; + + //! returns whether plugin can start searching + virtual bool isAvailable() const = 0; + + //! returns the actual translation of a word given in key + virtual QString search(QString key) = 0; + + //! \returns unique value (unique for every dictionary, not plugin) + virtual uint hash() const = 0; + + //! sets unique value (unique for every dictionary, not plugin) + virtual void setHash(uint) = 0; + + //! returns current plugin settings + virtual Settings* settings() = 0; + + //! returns plugin icon + virtual QIcon* icon() = 0; + + //! returns empty translation object (to be fetched later) for given key + virtual Translation* getTranslationFor(QString ) {return 0;} + + /*! plugin should delete any files (eg. cache) that have been created and are ready + to be deleted + */ + virtual void clean() {} + + + public Q_SLOTS: + /*! performs search in dictionary + \param word word to search in dictionary + \param limit limit on number of results, + if limit=0 all matching words are returned + + After finishing search it has to emit + \see CommonDictInterface:finalTranslation finalTranslation + */ + virtual QList searchWordList(QString word, int limit=0) = 0; + + //! stops current operation + virtual void stop() = 0; + + Q_SIGNALS: + + //! emitted when dictionary is ready to use afer being loaded + void loaded(CommonDictInterface*); + + //! emitted after change in dictionary settings + void settingsChanged(); + + /*! emitted to backbone when it's needed to inform user about something + \param Backbone::NotifyType GUI may decide to show different types in + different ways + \param QString text of the notification + */ + void notify(Notify::NotifyType, QString); + + +protected: + QString removeAccents(QString string) { + if(settings()->value("strip_accents") == "true") + return AccentsNormalizer::removeAccents(string); + return string; + } +}; + +Q_DECLARE_INTERFACE(CommonDictInterface, "CommonDictInterface/0.1"); + +#endif diff --git a/src/include/DictDialog.h b/src/include/DictDialog.h new file mode 100644 index 0000000..fc83744 --- /dev/null +++ b/src/include/DictDialog.h @@ -0,0 +1,51 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//Created by Mateusz Półrola + +#ifndef DICTDIALOG_H +#define DICTDIALOG_H + +#include + +class Settings; + +//! Interface for plugin dialog provider +class DictDialog : public QObject { + Q_OBJECT + +public: + DictDialog(QObject *parent = 0) : QObject(parent) {} + + /*! + Shows "add new dictionary" dialog and returns settings of new dict + \param parent parent widget on which dialog will be displayed + */ + virtual Settings* addNewDictionary(QWidget*parent=0)=0; + + /*! + Shows "settings" dialog and saves new settings in plugin + \param parent parent widget on which dialog will be displayed + */ + virtual void changeSettings(QWidget *parent = 0) = 0; +}; + +#endif // DICTDIALOG_H diff --git a/src/include/GUIInterface.h b/src/include/GUIInterface.h new file mode 100644 index 0000000..2f10cc1 --- /dev/null +++ b/src/include/GUIInterface.h @@ -0,0 +1,195 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ +//! \file GUIInterface.h +//! \brief Defines interface for GUI +//! \author Mateusz Półrola + + + +#ifndef GUIINTERFACE_H +#define GUIINTERFACE_H +#include +#include + +#include "translation.h" +#include "CommonDictInterface.h" + +class Settings; + +//! Interface for different GUIs +/*! + Default base class for all GUIs is QMainWindow + */ +class GUIInterface : public QMainWindow { + Q_OBJECT + +public: + GUIInterface(QWidget *parent = 0) :QMainWindow(parent) {} + + virtual ~GUIInterface() {} + + //! Returns all loaded dictionaries with information about that they are + //! active/inactive + /*! + \return Hash of pointers to dictionary and boolean flag indicating if + dictionary is active + */ + virtual QHash getDictionaries() = 0; + + + //! Returns all loaded plugins + /*! + \return List of pointers to plugins + */ + virtual QList getPlugins() = 0; + + //! Indicates if GUI is in exact search mode. + /*! When GUI is in exact search mode it searches for word, and + if it finds exactly matching translation it directly displays it, without + displaying matching word list. This mode should be + used for browsing search history and searching words from application + arguments. + \returns flag indicating if GUI is in exact search mode + */ + bool exactSearch(); + + //! Sets GUI exact search mode. + /*! \sa exactSearch() */ + void setExactSearch(bool exactSearch); + + virtual Settings* settings() = 0; + + virtual void setSettings(Settings*) = 0; + + +public Q_SLOTS: + //! Searches in exact mode for given word + /*! + GUI will be automatically set into exact search mode, and after search or + break it will be unset from exact search mode. + \param word which will be searched in dictionaries + */ + virtual void searchExact(QString word) = 0; + + //! Adds key words from given translations to history + /*! + By default this slot is connected to searchTranslations signal, and + passed translations list contains only translations with the same key, so + only one word is added to history. + \param list of translations with key words + \sa searchTranslations(); + */ + virtual void addToHistory(QList) = 0; + + //! Shows history dialog + virtual void showHistory(QPoint) = 0; + + //! Shows translation of next word in history + /*! + It will work only if there is next word available in history. + Translation of word is searched with searchExact() function + \sa searchExact() + */ + virtual void historyNext() = 0; + + //! Shows translation of previous word in history + /*! + It will work only if there is previous word available in history. + Translation of word is searched with searchExact() function + \sa searchExact() + */ + virtual void historyPrev() = 0; + + //! Gets words list from backbone and prepares received list to display + /*! + Checks if received list is empty, in that case it displays suitable + information. If GUI is in exact search mode it will search for exact + word in received list, and if word is found it will emit signal to + display its translation. Otherwise it will display list of matching + words and show suitable information. + \sa exactSearch() + \sa showTranslation() + */ + virtual void wordListReady() = 0; + + //! Gets translation strings from backbone and emits signal to display them + virtual void translationsReady() = 0; + +Q_SIGNALS: + //! Should be emitted when user wants to close application to stop + //! all ongoing searches + void quit(); + + //! Emitted when user wants to search for list of words matching given word + /*! \param word word which will be matched, it can contain wildcards + */ + void searchWordList(QString word); + + //! Emitted when user wants to see translation of words. + /*! \param list of translations for given word which will be received + in wordListReady() slot + \sa wordListReady() + */ + void searchTranslations(QList); + + //! Emitted when starting search, will disable GUI components + //! and show progress bars + void setBusy(); + + //! Emitted when searching ends, will enable GUI components + void setIdle(); + + //! Emitted when user wants to break search + void stopSearching(); + + //! Emitted after receiving word list in wordListReady() slot, will display + //! list of matched words + /*! \param hash of word and list of translations of this word found + in dictionaries + */ + void showWordList(QHash >); + + //! Emitted after receiving translation strings in translationsReady() slot, + //! will display translation of given word + /*! \param list of translations from different dictionaries + in dictionaries + */ + void showTranslation(QStringList); + + //! Emitted when user wants to add new dictionary + /*! \param new dictionary returned by specific plugin dialog + */ + void addNewDictionary(CommonDictInterface*); + + //! Emitted when user wants to remove dictionary + /*! \param dictionary which will be removed + */ + void removeDictionary(CommonDictInterface*); + + //! Emitted when user changes dictionaries active/inactive states + /*! \param list of only active dictionaries + */ + void selectedDictionaries(QList); + + void addToBookmarks(QList); +}; + +#endif // GUIINTERFACE_H diff --git a/src/include/History.h b/src/include/History.h new file mode 100644 index 0000000..133b3ad --- /dev/null +++ b/src/include/History.h @@ -0,0 +1,70 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +//Created by Mateusz Półrola + +#ifndef HISTORY_H +#define HISTORY_H + +#include +#include +#include + +class History : public QObject +{ + Q_OBJECT +public: + explicit History(int maxSize = 5, QObject *parent = 0); + +Q_SIGNALS: + void historyChanged(bool prevAvailable, + bool nextAvailable, + bool listAvailable); + +public Q_SLOTS: + void refreshStatus(); + +public: + void add(QString); + QString previous(); + QString next(); + QStringList list(); + + bool prevAvailable(); + bool nextAvailable(); + bool listAvailable(); + + void setCurrentElement(int element); + + int maxSize(); + + void setMaxSize(int size); + +private: + QVector _history; + int _maxSize; + int currentElement; + bool _prevAvailable; + bool _nextAvailable; + bool _listAvailable; +}; + +#endif // HISTORY_H diff --git a/src/include/Notify.h b/src/include/Notify.h new file mode 100644 index 0000000..a5266e9 --- /dev/null +++ b/src/include/Notify.h @@ -0,0 +1,45 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! /file Notify.h +\brief Declaration of common notify subsystem (NotifyType for now) + +\author Bartosz Szatkowski +*/ + +#ifndef NOTIFY_H +#define NOTIFY_H + +#include +#include + +/*! Notify wraps NotifyType which is interpreted by GUI and may change way in + which GUI handles given notification + */ +class Notify : QObject { + Q_OBJECT +public: + Notify() : QObject(0) {} + Notify(const Notify&) : QObject(0) {} + enum notifytype {Error, Warning, Info}; + Q_DECLARE_FLAGS(NotifyType, notifytype); +}; +#endif // NOTIFY_H diff --git a/src/include/settings.h b/src/include/settings.h new file mode 100644 index 0000000..6843a79 --- /dev/null +++ b/src/include/settings.h @@ -0,0 +1,71 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file settings.h +\brief Settings object for plugins \see Settings + +\author Bartosz Szatkowski +*/ + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include +#include + +/*! Plugins or dictionaries may need to keep some of configuration between + sessions, moreover Backbone or GUI may want to store some additional info in + plugin Settings. + + It's important for plugin to store all information given to it in Settings.*/ +class Settings { + public: + Settings(){} + Settings(const Settings* set) { + _settings = QHash(set->_settings); + } + ~Settings(){} + + /*! \returns value fo given key + \param key + */ + QString value(const QString key) const { + if(!_settings.contains(key)) { + return QString(); + } + return _settings[key]; + } + + //! sets key to value + void setValue(const QString key, const QString value) { + _settings.insert(key, value); + } + + QList keys() const { + return _settings.keys(); + } + +private: + QHash _settings; +}; + +#endif // SETTINGS_H diff --git a/src/include/translation.h b/src/include/translation.h new file mode 100644 index 0000000..a6a20a9 --- /dev/null +++ b/src/include/translation.h @@ -0,0 +1,80 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary 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 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file translation.h +\brief Interface for translation instances \see Translation + +\author Bartosz Szatkowski +*/ + +#ifndef TRANSLATION_H +#define TRANSLATION_H + +#include +#include +#include + +class CommonDictInterface; + + +/*! Translation is kind of GoF proxy, it stores key:translation pair and + provides it in lazy way -> key is available always, but translation is fetched + as late as possible*/ +class Translation { + public: + Translation () { _bookmark = 0;} + virtual ~Translation () {} + //! \return word to be translated + virtual QString key() const = 0; + + bool operator==(Translation* translation) { + return this->key()==translation->key(); + } + + /*! \returns dictionary information (plugin name, languages, etc)\ + to be displayed in translation table header */ + virtual QString dictionaryInfo() const = 0; + + //! \return parsed raw format into html + virtual QString toHtml() const = 0; + + //! \return whether given translation is taken from bookmarks + virtual bool isBookmark() const { + return _bookmark; + } + + //! \param b if true then translation is from bookmarks + void setBookmark(bool b) { + _bookmark = b; + } + + //! returns coresponding dict object + virtual uint dict() const {return 0;} + + protected: + bool _bookmark; + +}; + +Q_DECLARE_METATYPE(Translation*); +Q_DECLARE_METATYPE(QList); + +#endif diff --git a/src/mdictionary/backbone/BookmarkTranslations.h b/src/mdictionary/backbone/BookmarkTranslations.h index 34a3dfc..6dbd1b9 100644 --- a/src/mdictionary/backbone/BookmarkTranslations.h +++ b/src/mdictionary/backbone/BookmarkTranslations.h @@ -28,8 +28,8 @@ #ifndef BOOKMARKTRANSLATIONS_H #define BOOKMARKTRANSLATIONS_H -#include "../../common/settings.h" -#include "../../common/translation.h" +#include "../../include/settings.h" +#include "../../include/translation.h" #include "Bookmarks.h" #include "QObject" diff --git a/src/mdictionary/backbone/Bookmarks.h b/src/mdictionary/backbone/Bookmarks.h index 5696296..472ac2b 100644 --- a/src/mdictionary/backbone/Bookmarks.h +++ b/src/mdictionary/backbone/Bookmarks.h @@ -40,9 +40,9 @@ #include #include #include -#include "../../common/settings.h" -#include "../../common/translation.h" -#include "../../common/AccentsNormalizer.h" +#include "../../include/settings.h" +#include "../../include/translation.h" +#include "../../include/AccentsNormalizer.h" class BookmarkTranslation; diff --git a/src/mdictionary/backbone/History.cpp b/src/mdictionary/backbone/History.cpp index 6187976..0fe31e8 100644 --- a/src/mdictionary/backbone/History.cpp +++ b/src/mdictionary/backbone/History.cpp @@ -21,7 +21,7 @@ //Created by Mateusz Półrola -#include "../../common/History.h" +#include "../../include/History.h" #include History::History(int maxSize, QObject *parent) : diff --git a/src/mdictionary/backbone/backbone.h b/src/mdictionary/backbone/backbone.h index 3e8396c..89a9da7 100644 --- a/src/mdictionary/backbone/backbone.h +++ b/src/mdictionary/backbone/backbone.h @@ -44,11 +44,11 @@ #include #include #include -#include "../../common/CommonDictInterface.h" -#include "../../common/settings.h" -#include "../../common/translation.h" -#include "../../common/History.h" -#include "../../common/Notify.h" +#include "../../include/CommonDictInterface.h" +#include "../../include/settings.h" +#include "../../include/translation.h" +#include "../../include/History.h" +#include "../../include/Notify.h" #include "ConfigGenerator.h" #include "Bookmarks.h" diff --git a/src/mdictionary/gui/AboutWidget.h b/src/mdictionary/gui/AboutWidget.h index 413469d..972b3f7 100644 --- a/src/mdictionary/gui/AboutWidget.h +++ b/src/mdictionary/gui/AboutWidget.h @@ -30,7 +30,7 @@ #include #include #include -#include "../../common/GUIInterface.h" +#include "../../include/GUIInterface.h" class AboutWidget : public QDialog { diff --git a/src/mdictionary/gui/BookmarksWidget.h b/src/mdictionary/gui/BookmarksWidget.h index 55b7b28..c5188fa 100644 --- a/src/mdictionary/gui/BookmarksWidget.h +++ b/src/mdictionary/gui/BookmarksWidget.h @@ -27,7 +27,7 @@ #include #include -#include "../../common/GUIInterface.h" +#include "../../include/GUIInterface.h" //! Implements bookmarks management widget /*! diff --git a/src/mdictionary/gui/DictManagerWidget.cpp b/src/mdictionary/gui/DictManagerWidget.cpp index 292e47c..249230b 100644 --- a/src/mdictionary/gui/DictManagerWidget.cpp +++ b/src/mdictionary/gui/DictManagerWidget.cpp @@ -26,7 +26,7 @@ #include "DictManagerWidget.h" #include "DictTypeSelectDialog.h" #include -#include "../../common/DictDialog.h" +#include "../../include/DictDialog.h" DictManagerWidget::DictManagerWidget(GUIInterface *parent) : QDialog(parent) { diff --git a/src/mdictionary/gui/DictManagerWidget.h b/src/mdictionary/gui/DictManagerWidget.h index 324be83..ada3af8 100644 --- a/src/mdictionary/gui/DictManagerWidget.h +++ b/src/mdictionary/gui/DictManagerWidget.h @@ -27,7 +27,7 @@ #include #include -#include "../../common/GUIInterface.h" +#include "../../include/GUIInterface.h" //! Implements dictionaries management widget diff --git a/src/mdictionary/gui/DictTypeSelectDialog.h b/src/mdictionary/gui/DictTypeSelectDialog.h index d63d082..11b1e0a 100644 --- a/src/mdictionary/gui/DictTypeSelectDialog.h +++ b/src/mdictionary/gui/DictTypeSelectDialog.h @@ -26,8 +26,8 @@ #include #include -#include "../../common/settings.h" -#include "../../common/CommonDictInterface.h" +#include "../../include/settings.h" +#include "../../include/CommonDictInterface.h" #define PLUGIN_ROW_ROLE 99 //TODO remove this diff --git a/src/mdictionary/gui/HistoryListDialog.h b/src/mdictionary/gui/HistoryListDialog.h index 591794f..767a968 100644 --- a/src/mdictionary/gui/HistoryListDialog.h +++ b/src/mdictionary/gui/HistoryListDialog.h @@ -26,7 +26,7 @@ #include #include "SearchBarWidget.h" -#include "../../common/History.h" +#include "../../include/History.h" #include diff --git a/src/mdictionary/gui/MainWindow.h b/src/mdictionary/gui/MainWindow.h index 9e9a988..b4738b3 100644 --- a/src/mdictionary/gui/MainWindow.h +++ b/src/mdictionary/gui/MainWindow.h @@ -25,8 +25,8 @@ #define MAINWINDOW_H #include -#include "../../common/GUIInterface.h" -#include "../../common/settings.h" +#include "../../include/GUIInterface.h" +#include "../../include/settings.h" #include "../backbone/backbone.h" #include "TranslationWidget.h" #include "WordListWidget.h" diff --git a/src/mdictionary/gui/NotifyManager.h b/src/mdictionary/gui/NotifyManager.h index 2286abb..57bd309 100644 --- a/src/mdictionary/gui/NotifyManager.h +++ b/src/mdictionary/gui/NotifyManager.h @@ -29,7 +29,7 @@ #include #include #include -#include "../../common/Notify.h" +#include "../../include/Notify.h" //! Manages notifications in applications /*! diff --git a/src/mdictionary/gui/SearchBarWidget.cpp b/src/mdictionary/gui/SearchBarWidget.cpp index ea7d30d..7bd9b26 100644 --- a/src/mdictionary/gui/SearchBarWidget.cpp +++ b/src/mdictionary/gui/SearchBarWidget.cpp @@ -25,7 +25,7 @@ #include "SearchBarWidget.h" #include -#include "../../common/DictDialog.h" +#include "../../include/DictDialog.h" #include "HistoryListDialog.h" diff --git a/src/mdictionary/gui/SearchBarWidget.h b/src/mdictionary/gui/SearchBarWidget.h index 71d33cb..4c04bf6 100644 --- a/src/mdictionary/gui/SearchBarWidget.h +++ b/src/mdictionary/gui/SearchBarWidget.h @@ -28,7 +28,7 @@ #include #include #include "../backbone/backbone.h" -#include "../../common/History.h" +#include "../../include/History.h" //! Displays search bar /*! diff --git a/src/mdictionary/gui/SettingsWidget.h b/src/mdictionary/gui/SettingsWidget.h index b281f22..7cc5ce4 100644 --- a/src/mdictionary/gui/SettingsWidget.h +++ b/src/mdictionary/gui/SettingsWidget.h @@ -28,8 +28,8 @@ #include #include #include -#include "../../common/GUIInterface.h" -#include "../../common/settings.h" +#include "../../include/GUIInterface.h" +#include "../../include/settings.h" //! Implements applications settings widget /*! diff --git a/src/mdictionary/gui/TranslationWidget.h b/src/mdictionary/gui/TranslationWidget.h index da13431..4e3352b 100644 --- a/src/mdictionary/gui/TranslationWidget.h +++ b/src/mdictionary/gui/TranslationWidget.h @@ -32,7 +32,7 @@ #include #include "TranslationTextEdit.h" #include -#include "../../common/GUIInterface.h" +#include "../../include/GUIInterface.h" //! Displays translation of word found in dictionaries /*! diff --git a/src/mdictionary/gui/WordListWidget.cpp b/src/mdictionary/gui/WordListWidget.cpp index 7d6eaab..379e691 100644 --- a/src/mdictionary/gui/WordListWidget.cpp +++ b/src/mdictionary/gui/WordListWidget.cpp @@ -25,7 +25,7 @@ #include "WordListWidget.h" #include "WordListProxyStyle.h" -#include "../../common/translation.h" +#include "../../include/translation.h" WordListWidget::WordListWidget(QWidget *parent): diff --git a/src/mdictionary/gui/main.cpp b/src/mdictionary/gui/main.cpp index c19b931..3f166be 100644 --- a/src/mdictionary/gui/main.cpp +++ b/src/mdictionary/gui/main.cpp @@ -25,8 +25,8 @@ #include #include "MainWindow.h" #include "../backbone/backbone.h" -#include "../../common/translation.h" -#include "../../common/Notify.h" +#include "../../include/translation.h" +#include "../../include/Notify.h" #include "DBusAdapter.h" #include #include diff --git a/src/mdictionary/mdictionary.pro b/src/mdictionary/mdictionary.pro index 00aafe9..00118ca 100644 --- a/src/mdictionary/mdictionary.pro +++ b/src/mdictionary/mdictionary.pro @@ -34,26 +34,26 @@ HEADERS += gui/MainWindow.h \ gui/WordListWidget.h \ gui/TranslationWidget.h \ backbone/backbone.h \ - ../common/translation.h \ - ../common/settings.h \ - ../common/CommonDictInterface.h \ + ../include/translation.h \ + ../include/settings.h \ + ../include/CommonDictInterface.h \ gui/MenuWidget.h \ gui/MenuTabWidget.h \ gui/DictManagerWidget.h \ gui/DictTypeSelectDialog.h \ - ../common/History.h \ + ../include/History.h \ gui/HistoryListDialog.h \ - ../common/GUIInterface.h \ + ../include/GUIInterface.h \ gui/WordListProxyStyle.h \ backbone/Bookmarks.h \ backbone/BookmarkTranslations.h \ gui/SettingsWidget.h \ gui/BookmarksWidget.h \ gui/WelcomeScreenWidget.h \ - ../common/Notify.h \ + ../include/Notify.h \ gui/TranslationTextEdit.h \ - ../common/AccentsNormalizer.h \ - ../common/DictDialog.h \ + ../include/AccentsNormalizer.h \ + ../include/DictDialog.h \ gui/DBusAdapter.h \ gui/NotifyManager.h @@ -83,3 +83,21 @@ unix { INSTALLS += desktop icon64 bookmarks service } + + + +coverage { + # add flags to compiler + LIBS += -lgcov + QMAKE_CXXFLAGS += -ftest-coverage -fprofile-arcs -fno-elide-constructors + + # and add a target for generating report + QMAKE_EXTRA_TARGETS += coverage-report + coverage-report.commands = lcov -d .obj --capture --output-file all.cov -b . && + coverage-report.commands += lcov -r all.cov '*thumbtest*' -r all.cov '*/src/dbus/*' -r all.cov '*/src/.moc/*' -o to_test.cov && + coverage-report.commands += lcov -e to_test.cov '*/*/src/*.cpp*' -e to_test.cov '*/*/src/*.h*' -e to_test.cov '*/*/src/common/*.h*' -o final.cov && + coverage-report.commands += genhtml -o coverage final.cov +} + +check.commands = echo 'No check here' +QMAKE_EXTRA_TARGETS += check diff --git a/src/plugins/google/GoogleDictDialog.h b/src/plugins/google/GoogleDictDialog.h index 3929032..7823dab 100644 --- a/src/plugins/google/GoogleDictDialog.h +++ b/src/plugins/google/GoogleDictDialog.h @@ -28,8 +28,8 @@ #ifndef GOOGLEDICTDIALOG_H #define GOOGLEDICTDIALOG_H -#include "../../common/DictDialog.h" -#include "../../common/settings.h" +#include "../../include/DictDialog.h" +#include "../../include/settings.h" #include "GooglePlugin.h" #include "GoogleSettingsDialog.h" diff --git a/src/plugins/google/GooglePlugin.h b/src/plugins/google/GooglePlugin.h index 87c709a..5942596 100644 --- a/src/plugins/google/GooglePlugin.h +++ b/src/plugins/google/GooglePlugin.h @@ -34,9 +34,9 @@ #include #include -#include "../../common/CommonDictInterface.h" -#include "../../common/settings.h" -#include "../../common/DictDialog.h" +#include "../../include/CommonDictInterface.h" +#include "../../include/settings.h" +#include "../../include/DictDialog.h" #include "TranslationGoogle.h" #include "GoogleDictDialog.h" diff --git a/src/plugins/google/GoogleSettingsDialog.h b/src/plugins/google/GoogleSettingsDialog.h index ff4503f..24d1857 100644 --- a/src/plugins/google/GoogleSettingsDialog.h +++ b/src/plugins/google/GoogleSettingsDialog.h @@ -28,7 +28,7 @@ #define GOOGLESETTINGSDIALOG_H #include -#include "../../common/settings.h" +#include "../../include/settings.h" #include #include "GooglePlugin.h" diff --git a/src/plugins/google/TranslationGoogle.h b/src/plugins/google/TranslationGoogle.h index 963ac90..4068136 100644 --- a/src/plugins/google/TranslationGoogle.h +++ b/src/plugins/google/TranslationGoogle.h @@ -26,7 +26,7 @@ #ifndef TRANSLATIONGOOGLE_H #define TRANSLATIONGOOGLE_H -#include "../../common/translation.h" +#include "../../include/translation.h" #include "GooglePlugin.h" class GooglePlugin; diff --git a/src/plugins/google/google.pro b/src/plugins/google/google.pro index 61bbe42..3b39bc5 100644 --- a/src/plugins/google/google.pro +++ b/src/plugins/google/google.pro @@ -10,10 +10,10 @@ SOURCES += \ HEADERS += \ GooglePlugin.h \ - ../../common/DictDialog.h \ - ../../common/translation.h \ - ../../common/settings.h \ - ../../common/CommonDictInterface.h \ + ../../include/DictDialog.h \ + ../../include/translation.h \ + ../../include/settings.h \ + ../../include/CommonDictInterface.h \ TranslationGoogle.h \ GoogleDictDialog.h \ GoogleSettingsDialog.h diff --git a/src/plugins/xdxf/TranslationXdxf.h b/src/plugins/xdxf/TranslationXdxf.h index 7809758..c28af27 100644 --- a/src/plugins/xdxf/TranslationXdxf.h +++ b/src/plugins/xdxf/TranslationXdxf.h @@ -24,7 +24,7 @@ #define TRANSLATIONXDXF_H #include -#include "../../common/translation.h" +#include "../../include/translation.h" #include "xdxfplugin.h" class TranslationXdxf : public Translation diff --git a/src/plugins/xdxf/XdxfDictDialog.h b/src/plugins/xdxf/XdxfDictDialog.h index 34649c6..f7b06f2 100644 --- a/src/plugins/xdxf/XdxfDictDialog.h +++ b/src/plugins/xdxf/XdxfDictDialog.h @@ -25,7 +25,7 @@ #ifndef XDXFDICTDIALOG_H #define XDXFDICTDIALOG_H -#include "../../common/DictDialog.h" +#include "../../include/DictDialog.h" #include "XdxfLoadDialog.h" class XdxfPlugin; diff --git a/src/plugins/xdxf/XdxfLoadDialog.h b/src/plugins/xdxf/XdxfLoadDialog.h index d9480d1..97e79e5 100644 --- a/src/plugins/xdxf/XdxfLoadDialog.h +++ b/src/plugins/xdxf/XdxfLoadDialog.h @@ -27,7 +27,7 @@ #include #include -#include "../../common/settings.h" +#include "../../include/settings.h" //! Displays dialog which allows user to add new xdxf dictionary class XdxfLoadDialog : public QDialog { diff --git a/src/plugins/xdxf/XdxfSettingsDialog.h b/src/plugins/xdxf/XdxfSettingsDialog.h index 4baf322..b7543f8 100644 --- a/src/plugins/xdxf/XdxfSettingsDialog.h +++ b/src/plugins/xdxf/XdxfSettingsDialog.h @@ -26,7 +26,7 @@ #define XDXFSETTINGSDIALOG_H #include -#include "../../common/settings.h" +#include "../../include/settings.h" #include #include "xdxfplugin.h" diff --git a/src/plugins/xdxf/xdxf.pro b/src/plugins/xdxf/xdxf.pro index 4bc26f3..91955f4 100644 --- a/src/plugins/xdxf/xdxf.pro +++ b/src/plugins/xdxf/xdxf.pro @@ -15,11 +15,11 @@ HEADERS += \ xdxfplugin.h \ TranslationXdxf.h \ XdxfLoadDialog.h \ - ../../common/DictDialog.h \ + ../../include/DictDialog.h \ XdxfDictDialog.h \ - ../../common/translation.h \ - ../../common/settings.h \ - ../../common/CommonDictInterface.h \ + ../../include/translation.h \ + ../../include/settings.h \ + ../../include/CommonDictInterface.h \ XdxfSettingsDialog.h \ XdxfCachingDialog.h diff --git a/src/plugins/xdxf/xdxfplugin.cpp b/src/plugins/xdxf/xdxfplugin.cpp index 9335759..fe3dde3 100644 --- a/src/plugins/xdxf/xdxfplugin.cpp +++ b/src/plugins/xdxf/xdxfplugin.cpp @@ -25,7 +25,7 @@ #include "xdxfplugin.h" #include -#include "../../common/Notify.h" +#include "../../include/Notify.h" XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent), _langFrom(""), _langTo(""),_name(""), _infoNote("") { diff --git a/src/plugins/xdxf/xdxfplugin.h b/src/plugins/xdxf/xdxfplugin.h index 287426d..2bc7930 100644 --- a/src/plugins/xdxf/xdxfplugin.h +++ b/src/plugins/xdxf/xdxfplugin.h @@ -37,8 +37,8 @@ #include #include -#include "../../common/CommonDictInterface.h" -#include "../../common/settings.h" +#include "../../include/CommonDictInterface.h" +#include "../../include/settings.h" #include "XdxfDictDialog.h" #include "XdxfCachingDialog.h" #include "TranslationXdxf.h" diff --git a/src/src.pro b/src/src.pro index d6fdbde..6c65bf4 100644 --- a/src/src.pro +++ b/src/src.pro @@ -2,3 +2,13 @@ include(src.pri) TEMPLATE = subdirs SUBDIRS = $$ENABLED_SRC + +check.CONFIG = recursive +check.recurse = $$ENABLED_SRC +QMAKE_EXTRA_TARGETS += check + +coverage { + # add flags to compiler + LIBS += -lgcov + QMAKE_CXXFLAGS += -ftest-coverage -fprofile-arcs -fno-elide-constructors +} diff --git a/tests/mDictionaryTests/CommonDictInterfaceMock.h b/tests/mDictionaryTests/CommonDictInterfaceMock.h index 326bf54..7d67498 100644 --- a/tests/mDictionaryTests/CommonDictInterfaceMock.h +++ b/tests/mDictionaryTests/CommonDictInterfaceMock.h @@ -31,7 +31,7 @@ #ifndef COMMONDICTINTERFACEMOCK_H #define COMMONDICTINTERFACEMOCK_H -#include "../../src/common/CommonDictInterface.h" +#include "../../src/include/CommonDictInterface.h" #include "TranslationMock.h" /*! CommonDictInterfaceMock simulates dict/plugin behaviour without any diff --git a/tests/mDictionaryTests/TranslationMock.h b/tests/mDictionaryTests/TranslationMock.h index 1b4ed4a..fcc8771 100644 --- a/tests/mDictionaryTests/TranslationMock.h +++ b/tests/mDictionaryTests/TranslationMock.h @@ -29,7 +29,7 @@ #ifndef TRANSLATIONMOCK_H #define TRANSLATIONMOCK_H -#include "../../src/common/translation.h" +#include "../../src/include/translation.h" /*! Translation mock is intended to simulate behaviour of real plugins translation, but without dependency and any kind of complicated operations*/ diff --git a/tests/mDictionaryTests/mDictionaryTests.pro b/tests/mDictionaryTests/mDictionaryTests.pro index eaca07e..1287425 100644 --- a/tests/mDictionaryTests/mDictionaryTests.pro +++ b/tests/mDictionaryTests/mDictionaryTests.pro @@ -21,14 +21,26 @@ SOURCES += tst_Backbone.cpp \ DEFINES += SRCDIR=\\\"$$PWD/\\\" HEADERS += CommonDictInterfaceMock.h \ ../../src/mdictionary/backbone/backbone.h \ - ../../src/common/translation.h \ - ../../src/common/settings.h \ - ../../src/common/CommonDictInterface.h \ - ../../src/common/History.h \ + ../../src/include/translation.h \ + ../../src/include/settings.h \ + ../../src/include/CommonDictInterface.h \ + ../../src/include/History.h \ TranslationMock.h \ ../../src/mdictionary/backbone/BookmarkTranslations.h \ ../../src/mdictionary/backbone/Bookmarks.h \ ../../src/mdictionary/backbone/ConfigGenerator.h + + target.path = . target.commands += ./mDictionaryTests INSTALLS += target + + +coverage { + LIBS += -lgcov + QMAKE_CXXFLAGS += -ftest-coverage -fprofile-arcs -fno-elide-constructors +} + +check.depends = $$TARGET +check.commands = ./mDictionaryTests +QMAKE_EXTRA_TARGETS += check diff --git a/tests/tests.pro b/tests/tests.pro index ea018f0..18f3045 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,7 +1,12 @@ TEMPLATE=subdirs SUBDIRS = mDictionaryTests -check.target = check check.CONFIG = recursive check.recurse = mDictionaryTests QMAKE_EXTRA_TARGETS += check + +coverage { + # add flags to compiler + LIBS += -lgcov + QMAKE_CXXFLAGS += -ftest-coverage -fprofile-arcs -fno-elide-constructors +} -- 1.7.9.5