File indexing completed on 2024-06-23 04:30:52
0001 /* 0002 Kchmviewer - a CHM and EPUB file viewer with broad language support 0003 SPDX-FileCopyrightText: 2004-2014 George Yunaev gyunaev@ulduzsoft.com 0004 0005 SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 0008 #ifndef EBookSearch_H 0009 #define EBookSearch_H 0010 0011 #include "helper_search_index.h" 0012 #include <QDataStream> 0013 0014 class EBook; 0015 0016 class EBookSearch : public QObject 0017 { 0018 Q_OBJECT 0019 0020 public: 0021 EBookSearch(); 0022 ~EBookSearch() override; 0023 0024 //! Loads the search index from the data stream \param stream. 0025 //! The index should be previously saved with generateIndex(). 0026 bool loadIndex(QDataStream &stream); 0027 0028 //! Generates the search index from the opened CHM file \param chmFile, 0029 //! and saves it to the data stream \param stream which should be writeable. 0030 //! 0031 //! To show the progress, this procedure emits a progressStep() signal periodically 0032 //! with the value showing current progress in percentage (i.e. from 0 to 100) 0033 //! After signal emission, the following event processing function will be called: 0034 //! qApp->processEvents( QEventLoop::ExcludeUserInputEvents ) 0035 //! to make sure the dialogs (if any) are properly updated. 0036 //! 0037 //! If \param progressDls is not null, it will be used to display progress. 0038 //! Returns true if the index has been generated and saved, or false if internal 0039 //! error occurs, or (most likely) the cancelIndexGeneration() slot has been called. 0040 bool generateIndex(EBook *ebook, QDataStream &stream); 0041 0042 //! Executes the search query. The \param query is a string like <i>"C++ language" class</i>, 0043 //! \param results is a pointer to QStringList, and \param limit limits the number of 0044 //! results in case the query is too generic (like \a "a" ). 0045 //! The \param ebookFile is used to get the current encoding information. 0046 //! The return value is false only if the index is not generated, or if a closing quote character 0047 //! is missing. Call hasIndex() to clarify. If search returns no results, the return value is 0048 //! true, but the \param results list will be empty. 0049 //! 0050 //! Note that the function does not clear \param results before adding search results, so if you are 0051 //! not merging search results, make sure it's empty. 0052 bool searchQuery(const QString &query, QList<QUrl> *results, EBook *ebookFile, unsigned int limit = 100); 0053 0054 //! Returns true if a valid search index is present, and therefore search could be executed 0055 bool hasIndex() const; 0056 0057 Q_SIGNALS: 0058 void progressStep(int value, const QString &stepName); 0059 0060 public Q_SLOTS: 0061 void cancelIndexGeneration(); 0062 0063 private Q_SLOTS: 0064 void updateProgress(int value, const QString &stepName); 0065 void processEvents(); 0066 0067 private: 0068 QStringList m_keywordDocuments; 0069 QtAs::Index *m_Index; 0070 }; 0071 0072 #endif