summaryrefslogtreecommitdiff
path: root/src/backend/drivers/cswordmoduleinfo.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/drivers/cswordmoduleinfo.h')
-rw-r--r--src/backend/drivers/cswordmoduleinfo.h275
1 files changed, 159 insertions, 116 deletions
diff --git a/src/backend/drivers/cswordmoduleinfo.h b/src/backend/drivers/cswordmoduleinfo.h
index a767c41..d7397de 100644
--- a/src/backend/drivers/cswordmoduleinfo.h
+++ b/src/backend/drivers/cswordmoduleinfo.h
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2008 by the BibleTime developers.
+* Copyright 1999-2011 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -162,25 +162,28 @@ class CSwordModuleInfo: public QObject {
*/
QString config( const CSwordModuleInfo::ConfigEntry entry ) const;
- CSwordModuleInfo( sword::SWModule* module, CSwordBackend* const = 0 );
- /** Copy constructor to copy the passed parameter.
- * @param m The module to be copied
- */
- CSwordModuleInfo( const CSwordModuleInfo& m );
- /** Reimplementation to return a valid clone.
- */
- virtual CSwordModuleInfo* clone();
- /** Destructor.
- */
- virtual ~CSwordModuleInfo();
+ CSwordModuleInfo(sword::SWModule *module,
+ CSwordBackend * const = 0,
+ ModuleType type = Unknown);
+
+ CSwordModuleInfo(const CSwordModuleInfo &copy);
+
+ virtual CSwordModuleInfo *clone() const = 0;
+
+ virtual inline ~CSwordModuleInfo() {}
+
/**
* Returns the module object so all objects can access the original Sword module.
*/
- sword::SWModule* module() const;
+ inline sword::SWModule *module() const {
+ return m_module;
+ }
+
/**
- * Sets the unlock key of the modules and writes the key into the cofig file.
- * @return True if the unlock process was succesful, if the key was wrong, or if the config file was write protected return false.
+ * Sets the unlock key of the modules and writes the key into the config file.
+ * @return True if the unlock process was succesful, if the key was
+wrong, or if the config file was write protected return false.
*/
bool unlock( const QString& unlockKey );
/**
@@ -200,99 +203,130 @@ class CSwordModuleInfo: public QObject {
/**
* This function returns true if this module is locked (encrypted + correct cipher key),
* otherwise return false.
- * \todo Make CSwordModuleInfo::isLocked() const.
* @return True if this module is locked, i.e. encrypted but without a key set
*/
- bool isLocked();
+ bool isLocked() const;
- bool unlockKeyIsValid();
- /** The module version.
- * @return true if this module has a version number and false if it doesn't have one.
+ /**
+ This function makes an estimate if a module was properly unlocked. It
+ returns true if the first entry of the module is not empty and
+ contains only printable characters (for the first 100 chars or so). If
+ that is the case, we can safely assume that a) the module was properly
+ unlocked and b) no buffer overflows will occur, which can happen when
+ Sword filters process garbage text which was not properly decrypted.
*/
- inline bool hasVersion() const;
+ bool unlockKeyIsValid() const;
/**
- * Returns true if the module's index has been built.
+ \retval true if this module has a version number
+ \retval false if it doesn't have a version number
*/
- virtual bool hasIndex();
+ inline bool hasVersion() const {
+ return m_cachedHasVersion;
+ }
+
/**
- * Returns the path to this module's index base dir
+ \returns true if the module's index has been built.
*/
- virtual QString getModuleBaseIndexLocation() const;
+ bool hasIndex() const;
+
/**
- * Returns the path to this module's standard index
+ \returns the path to this module's index base dir
*/
- virtual QString getModuleStandardIndexLocation() const;
- /**
- * Builds a search index for this module
- */
- virtual void buildIndex();
+ QString getModuleBaseIndexLocation() const;
+
/**
- * Returns index size
+ \returns the path to this module's standard index
*/
- virtual unsigned long indexSize() const;
+ QString getModuleStandardIndexLocation() const;
+
/**
- * Returns true if something was found, otherwise return false.
- * This function uses CLucene to perform and index based search. It also
- * overwrites the variable containing the last search result.
+ Builds a search index for this module
*/
- virtual bool searchIndexed(const QString& searchedText, sword::ListKey& scope);
+ void buildIndex();
+
/**
- * Returns the last search result for this module.
- * The last result is cleared by @ref search
+ \returns index size
*/
- virtual sword::ListKey& searchResult( const sword::ListKey* newResult = 0 );
+ unsigned long indexSize() const;
+
/**
- * Clears the last search result.
- * This does immediately clean the last search result,
- * no matter if search is in progress or not.
+ This function uses CLucene to perform and index based search. It also
+ overwrites the variable containing the last search result.
+ \returns the number of results found
*/
- void clearSearchResult();
+ int searchIndexed(const QString &searchedText,
+ const sword::ListKey &scope,
+ sword::ListKey &results) const;
+
/**
- * Returns the type of the module.
+ \returns the type of the module.
*/
- virtual CSwordModuleInfo::ModuleType type() const;
+ inline ModuleType type() const {
+ return m_type;
+ }
+
/**
* Returns the required Sword version for this module.
* Returns -1 if no special Sword version is required.
*/
- sword::SWVersion minimumSwordVersion();
+ sword::SWVersion minimumSwordVersion() const;
+
/**
- * Returns the name of the module.
- * @return The name of this module.
+ \note The Sword library takes care of the duplicate names: _n is added
+ after each duplicate.
+ \returns The name of this module.
*/
- QString name() const;
+ inline const QString &name() const {
+ return m_cachedName;
+ }
+
/**
* Snaps to the closest entry in the module if the current key is
* not present in the data files.
*/
- virtual bool snap() {
+ virtual inline bool snap() const {
return false;
}
- bool has( const CSwordModuleInfo::Feature ) const;
- bool has( const CSwordModuleInfo::FilterTypes ) const;
/**
- * Returns the text direction of the module's text.,
+ \returns whether the module supports the feature given as parameter.
+ */
+ bool has(const CSwordModuleInfo::Feature) const;
+
+ bool has(const CSwordModuleInfo::FilterTypes ) const;
+
+ /**
+ \returns the text direction of the module's text.
*/
- virtual CSwordModuleInfo::TextDirection textDirection();
+ CSwordModuleInfo::TextDirection textDirection() const;
+
/**
- * Writes the new text at the given position into the module. This does only work for writabe modules.
+ Writes the new text at the given position into the module. This does
+ only work for writabe modules.
*/
- virtual void write( CSwordKey* key, const QString& newText );
+ void write(CSwordKey *key, const QString &newText);
+
/**
- * Deletes the current entry and removes it from the module.
+ Deletes the current entry and removes it from the module.
*/
- bool deleteEntry( CSwordKey* const key );
+ bool deleteEntry(CSwordKey * const key);
+
/**
- * Returns the language of the module.
+ \returns the language of the module.
*/
- const CLanguageMgr::Language* language() const;
+ inline const CLanguageMgr::Language *language() const {
+ return m_cachedLanguage;
+ }
+
/**
- * Returns true if this module may be written by the write display windows.
+ \returns whether this module may be written to.
*/
- inline virtual bool isWritable() const;
+ inline virtual bool isWritable() const {
+ return false;
+ }
+
/**
* Returns true if this module is hidden (not to be shown with other modules in certain views).
*/
@@ -308,9 +342,12 @@ class CSwordModuleInfo: public QObject {
bool setHidden(bool hide);
/**
- * Returns the category of this module. See CSwordModuleInfo::Category for possible values.
+ \returns the category of this module.
*/
- CSwordModuleInfo::Category category() const;
+ inline CSwordModuleInfo::Category category() const {
+ return m_cachedCategory;
+ }
+
/**
* The about text which belongs to this module.
*/
@@ -320,9 +357,39 @@ class CSwordModuleInfo: public QObject {
* Protected because it should not be used outside of the CSword*ModuleInfo classes.
*/
inline bool isUnicode() const {
- return m_dataCache.isUnicode;
+ return m_module->isUnicode();
}
+ /**
+ Returns an icon for the given module.
+ \param[in] module The module whose icon to return.
+ */
+ static QIcon moduleIcon(const CSwordModuleInfo *module);
+
+ /**
+ Returns the icon filename for the given module.
+ \param[in] module The module whose icon filename to return.
+ */
+ static const QString &moduleIconFilename(const CSwordModuleInfo *module);
+
+ /**
+ Returns an icon for the category of given module.
+ \param[in] module The module whose category icon to return.
+ */
+ static QIcon categoryIcon(const CSwordModuleInfo::Category &category);
+
+ /**
+ Returns the icon filename for the category of given module.
+ \param[in] module The module whose category icon filename to return.
+ */
+ static const QString &categoryIconFilename(const CSwordModuleInfo::Category &category);
+
+ /**
+ Returns a translated name for the given category.
+ \param[in] module The category whose translated name to return.
+ */
+ static QString categoryName(const CSwordModuleInfo::Category &category);
+
public slots:
inline void cancelIndexing() {
m_cancelIndexing = true;
@@ -344,66 +411,42 @@ class CSwordModuleInfo: public QObject {
QString getSimpleConfigEntry(const QString& name) const;
QString getFormattedConfigEntry(const QString& name) const;
+ private: /* Methods: */
+ /**
+ Initializes CSwordModuleInfo::m_cachedCategory.
+ \pre m_module must be set
+ */
+ void initCachedCategory();
+
+ /**
+ Initializes CSwordModuleInfo::m_cachedLanguage.
+ \pre CSwordModuleInfo::m_module must be set
+ \pre CSwordModuleInfo::m_cachedLanguage must be set
+ */
+ void initCachedLanguage();
+
signals:
- void hasIndexChanged(bool);
- void hiddenChanged(bool);
+ void hasIndexChanged(bool hasIndex);
+ void hiddenChanged(bool hidden);
+ void unlockedChanged(bool unlocked);
void indexingFinished();
void indexingProgress(int);
private:
- sword::SWModule* m_module;
- sword::ListKey m_searchResult;
-
- mutable struct DataCache {
- DataCache() {
- language = 0;
- }
-
- QString name;
- bool isUnicode;
- CSwordModuleInfo::Category category;
- const CLanguageMgr::Language* language;
- bool hasVersion;
- }
-
- m_dataCache;
-
- CSwordBackend* m_backend;
-
+ sword::SWModule * const m_module;
+ CSwordBackend *m_backend;
+ ModuleType m_type;
bool m_hidden;
-
bool m_cancelIndexing;
+
+ // Cached data:
+ const QString m_cachedName;
+ CSwordModuleInfo::Category m_cachedCategory;
+ const CLanguageMgr::Language *m_cachedLanguage;
+ bool m_cachedHasVersion;
};
Q_DECLARE_METATYPE(CSwordModuleInfo::Category);
Q_DECLARE_OPERATORS_FOR_FLAGS(CSwordModuleInfo::Categories)
-inline CSwordModuleInfo::ModuleType CSwordModuleInfo::type() const {
- return CSwordModuleInfo::Unknown;
-}
-
-inline sword::SWModule* CSwordModuleInfo::module() const {
- return m_module;
-}
-
-inline bool CSwordModuleInfo::hasVersion() const {
- return m_dataCache.hasVersion;
-}
-
-
-/**
-* Returns the name of the module.
-* The Sword library takes care of the duplicate names: _n is added after each duplicate.
-*/
-inline QString CSwordModuleInfo::name() const {
- return m_dataCache.name;
-}
-
-/** Returns true if this module may be written by the write display windows. */
-inline bool CSwordModuleInfo::isWritable() const {
- return false;
-}
-
-//#include "util/cpointers.h"
-
#endif