[bt-devel] Strong's utilities patch

Lee Carpenter elc at carpie.net
Thu Jan 19 22:02:59 MST 2006


I have merged in Jim's changes.  Jim, please make sure I got it all right :)

Also, the change in csearchdialog.cpp for the Yes/No question box causes 
the dialog on my system to ignore my selection.  I saw your comment 
about having to use 0 or 1 with 0 being "Yes".  I suspect one of the 
other of us has a problem in our build environments or we're fighting a 
Qt version issue or something.  I'm using Qt 3.3.4 and qmessagebox.h has 
an enum where QMessageBox::Yes = 3.  Please check on your system to see 
why/if this is different.  For now, I used your change.  Perhaps others 
could try the "build an index" dialog and see what their results are. 
Either way, we should be able to get it worked out...

Thanks again for the patch!

Lee C.

jdc wrote:
> The following are attached:
>    1) a diff of the bibletime/frontend/searchdialog directory.
>    2) the three modified files
>          a. csearchdialog.cpp
>          b. csearchdialogpages.cpp
>          c. csearchdialogpages.h
> 
> The modifications include:
>    1) Highlighting Strong's text for a Strong's number search.
>    2) A fix for a bug in the setSearchText() function.
>    3) An implementation for showing a Strong's number search with text 
> count. (reference previous e-mails).
>       I believe this is technically called an "Englishman's Search".
>    4) There are some changes to the search dialog which are not 
> necessary because the search dialog will be rewritten.
>       Basically, I just put the dialog back to the original.
> 
> Thanks
> Jim
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> diff -U 3 -H -d -r -N -- bibletime-new/bibletime/frontend/searchdialog/csearchdialog.cpp bibletime-cvs/bibletime/frontend/searchdialog/csearchdialog.cpp
> --- bibletime-new/bibletime/frontend/searchdialog/csearchdialog.cpp	2006-01-16 20:34:36.000000000 -0700
> +++ bibletime-cvs/bibletime/frontend/searchdialog/csearchdialog.cpp	2006-01-02 10:26:07.000000000 -0700
> @@ -56,11 +56,6 @@
>  	}
>  
>  	m_staticDialog->raise();
> -
> -   // this is needed to make the dialog box adjust properly.
> -   // without it the search and close buttons are hidden.
> -   m_staticDialog->adjustSize();
> -
>  	if (modules.count() && !searchText.isEmpty()) {
>  		m_staticDialog->startSearch();
>  	}
> @@ -99,14 +94,9 @@
>  		int result = QMessageBox::question(this, i18n("Missing indices"),
>  			i18n("One or more modules need indexing before they can be searched.\n"
>  			"This could take a long time. Proceed with indexing?"),
> -      	QMessageBox::Yes | QMessageBox::Default,
> -         QMessageBox::No | QMessageBox::Escape);
> -      // The result is 0 for Yes/Ok and 1 for No/Cancel.
> -      // It does not seem to matter what the two button constants are.
> -      // I have tried Yes/No, Ok/Cancel and they both show a Yes/No dialog with
> -      // Yes on the left and No on the right.  When Yes is clicked the result is 0,
> -      // when No is clicked the result is 1.
> -		if (result == 0) {
> +			QMessageBox::Yes | QMessageBox::Default,
> +			QMessageBox::No | QMessageBox::Escape);
> +		if (result == QMessageBox::Yes) {
>  			// FIXME - add a proper progress dialog for indexing
>  			m_searcher.indexModules( modules() );
>  		}
> @@ -186,19 +176,14 @@
>  void CSearchDialog::initView() {
>  	setButtonTip(User1, CResMgr::searchdialog::searchButton::tooltip);
>  
> -   // this is to get the search results page to have a sane default size.
> -   // there might be a better fix but I don't know of one.
> -   setInitialSize(QSize(575, 200));
> -
> -	QVBoxLayout* box = new QVBoxLayout (plainPage());
> + 	QVBoxLayout* box = new QVBoxLayout ( plainPage() );
>  	box->setSpacing(3);
>  
>  	m_searchOptionsPage = new CSearchOptionsPage(plainPage());
> -	box->addWidget( m_searchOptionsPage );
> + 	box->addWidget( m_searchOptionsPage );
>  
>  	m_searchResultPage = new CSearchResultPage(plainPage());
>  	box->addWidget( m_searchResultPage );
> -
>  }
>  
>  void CSearchDialog::searchFinished() {
> diff -U 3 -H -d -r -N -- bibletime-new/bibletime/frontend/searchdialog/csearchdialogpages.cpp bibletime-cvs/bibletime/frontend/searchdialog/csearchdialogpages.cpp
> --- bibletime-new/bibletime/frontend/searchdialog/csearchdialogpages.cpp	2006-01-16 20:29:21.000000000 -0700
> +++ bibletime-cvs/bibletime/frontend/searchdialog/csearchdialogpages.cpp	2006-01-03 15:08:42.000000000 -0700
> @@ -52,97 +52,6 @@
>  #include <kiconloader.h>
>  #include <kmessagebox.h>
>  
> -
> -/********************************************
> -************  StrongsResultList *************
> -********************************************/
> -void StrongsResultClass::initStrongsResults(void)
> -   {
> -   using namespace Rendering;
> -   CDisplayRendering render;
> -   ListCSwordModuleInfo modules;
> -   CTextRendering::KeyTreeItem::Settings settings;
> -   QString rText, lText, key;
> -   bool found;
> -   int sIndex;
> -   int count;
> -   int index;
> -   QString text;
> -
> -   modules.append(srModule);
> -   sword::ListKey& result = srModule->searchResult();
> -
> -   count = result.Count();
> -   if (!count)
> -      return;
> -
> -   srList.clear();
> -
> -   for (index = 0; index < count; index++)
> -      {
> -      key = QString::fromUtf8(result.GetElement(index)->getText());
> -      text = render.renderSingleKey(key, modules, settings);
> -      sIndex = 0;
> -      while ((rText = getStrongsNumberText(text, &sIndex)) != "")
> -         {
> -         StrongsResultList::iterator it;
> -         found = FALSE;
> -         for ( it = srList.begin(); it != srList.end(); ++it )
> -            {
> -            lText = (*it).keyText();
> -            if (lText == rText)
> -               {
> -               found = TRUE;
> -               (*it).addKeyName(key);
> -               break;
> -               }
> -            }
> -         if (found == FALSE)
> -            srList.append( StrongsResult(rText, key) );
> -         }
> -      }
> -   //qHeapSort(srList);
> -   }
> -
> -QString StrongsResultClass::getStrongsNumberText(const QString& verseContent, int *startIndex)
> -   {
> -   // get the strongs text
> -   int idx1, idx2, index;
> -   QString sNumber, strongsText;
> -   const bool cs = CSwordModuleSearch::caseSensitive;
> -
> -   if (*startIndex == 0)
> -      index = verseContent.find("<body", 0);
> -   else
> -      index = *startIndex;
> -   // find all the "lemma=" inside the the content
> -   while((index = verseContent.find("lemma=", index, cs)) != -1)
> -      {
> -      // get the strongs number after the lemma and compare it with the
> -      // strongs number we are looking for
> -      idx1 = verseContent.find("\"", index) + 1;
> -      idx2 = verseContent.find("\"", idx1 + 1);
> -      sNumber = verseContent.mid(idx1, idx2 - idx1);
> -      if (sNumber.find(lemmaText) >= 0)
> -         {
> -         // strongs number is found now we need to get the text of this node
> -         // search right until the ">" is found.  Get the text from here to
> -         // the next "<".
> -         index = verseContent.find(">", index, cs) + 1;
> -         idx2  = verseContent.find("<", index, cs);
> -         strongsText = verseContent.mid(index, idx2 - index);
> -         index = idx2;
> -         *startIndex = index;
> -         return(strongsText);
> -         }
> -      else
> -         {
> -         index += 6; // 6 is the length of "lemma="
> -         }
> -      }
> -   return("");
> -   }
> -
>  /********************************************
>  ************  ModuleResultList **************
>  ********************************************/
> @@ -226,36 +135,6 @@
>  	executed(currentItem());
>  }
>  
> -void CSearchResultView::setupStrongsTree(CSwordModuleInfo* m, QStringList* vList)
> -{
> -   clear();
> -   if (!m) {
> -      return;
> -   }
> -
> -   m_module = m;
> -
> -   if (vList->count() <= 0)
> -      return;
> -
> -   setUpdatesEnabled(false);
> -
> -   KListViewItem* oldItem = 0;
> -   KListViewItem* item = 0;
> -
> -   for ( QStringList::Iterator it = vList->begin(); it != vList->end(); ++it )
> -      {
> -      item = new KListViewItem(this, oldItem);
> -      item->setText(0, (*it));
> -      oldItem = item;
> -      }
> -
> -   setUpdatesEnabled(true);
> -
> -   setSelected(firstChild(), true);
> -   executed(currentItem());
> -}
> -
>  /** Is connected to the signal executed, which is emitted when a mew item was chosen. */
>  void CSearchResultView::executed(QListViewItem* item) {
>  	//  Q_ASSERT(item);
> @@ -384,7 +263,6 @@
>  CModuleResultView::CModuleResultView(QWidget* parent) : KListView(parent) {
>  	initView();
>  	initConnections();
> -   strongsResults = NULL;
>  };
>  
>  CModuleResultView::~CModuleResultView() {}
> @@ -436,16 +314,12 @@
>  }
>  
>  /** Setups the tree using the given list of modules. */
> -void CModuleResultView::setupTree( ListCSwordModuleInfo modules, const QString& searchedText ) {
> +void CModuleResultView::setupTree( ListCSwordModuleInfo modules ) {
>  	clear();
>  	QListViewItem* item = 0;
>  	QListViewItem* oldItem = 0;
>  	sword::ListKey result;
>  
> -   if (strongsResults) {
> -      delete(strongsResults);
> -      strongsResults = NULL;
> -      }
>  	ListCSwordModuleInfo::iterator end_it = modules.end();
>  	for (ListCSwordModuleInfo::iterator it(modules.begin()); it != end_it; ++it) {
>  		//   for (modules.first(); modules.current(); modules.next()) {
> @@ -454,78 +328,27 @@
>  		item = new KListViewItem(this, (*it)->name(), QString::number(result.Count()) );
>  		item->setPixmap(0,CToolClass::getIconForModule(*it) );
>  		oldItem = item;
> -      if (searchedText.find("strong:", 0) == 0) {
> -         QString sNumber;
> -         sNumber = searchedText.right(searchedText.length() - 7);
> -         setupStrongsResults((*it), item, sNumber);
> -         item->setOpen(TRUE);
> -      }
>  	};
>  
>  	setSelected(currentItem(), true);
>  	executed(currentItem());
>  }
>  
> -void CModuleResultView::setupStrongsResults(CSwordModuleInfo* module, QListViewItem* parent,
> -                                            const QString& sNumber)
> -   {
> -   QString lText;
> -   KListViewItem* item = 0;
> -
> -   strongsResults = new StrongsResultClass(module, sNumber);
> -
> -   for (int cnt = 0; cnt < strongsResults->Count(); cnt++)
> -      {
> -      lText = strongsResults->keyText(cnt);
> -      item = new KListViewItem(parent, lText, QString::number(strongsResults->keyCount(cnt)));
> -      item->setText(0, lText);
> -      }
> -   }
> -
>  
>  /** Is executed when an item was selected in the list. */
>  void CModuleResultView::executed( QListViewItem* i ) {
> -   QString itemText, lText;
> -
>  	if (CSwordModuleInfo* m = CPointers::backend()->findModuleByName(i->text(0))) {
>  		emit moduleChanged();
>  		emit moduleSelected(m);
> -      return;
>  	}
> -   if (!strongsResults)
> -      return;
> -
> -   itemText = i->text(0);
> -   for (int cnt = 0; cnt < strongsResults->Count(); cnt++)
> -      {
> -      lText = strongsResults->keyText(cnt);
> -      if (lText == itemText)
> -         {
> -         //clear the verses list
> -         emit moduleChanged();
> -         emit strongsSelected(activeModule(), strongsResults->getKeyList(cnt));
> -         return;
> -         }
> -      }
>  }
>  
>  /** Returns the currently active module. */
>  CSwordModuleInfo* const CModuleResultView::activeModule() {
>  	Q_ASSERT(currentItem());
> -   QListViewItem* item = currentItem();
> -
> -   if (item == NULL)
> -      return 0;
> -
> -   // we need to find the parent most node because that is the node
> -   // that is the module name.
> -   while (item->parent())
> -      item = item->parent();
> -
> -   if (item)
> -      return CPointers::backend()->findModuleByName(item->text(0));
> -
> -   return 0;
> +	if (currentItem())
> +		return CPointers::backend()->findModuleByName(currentItem()->text(0));
> +	return 0;
>  }
>  
>  /** No descriptions */
> @@ -595,41 +418,36 @@
>  void CSearchResultPage::initView() {
>  
>  	QWidget* insideFrame = new QWidget( this );
> +	QGridLayout* gridLayout = new QGridLayout(insideFrame, 3, 2);
> +	gridLayout->setSpacing( 3 );
> +	gridLayout->setRowStretch( 1, 5);
> +	gridLayout->setColStretch( 1, 5);
>  
> -   QVBoxLayout* mainLayout = new QVBoxLayout(insideFrame);
> -
> -   QSplitter* splitter = new QSplitter(Vertical, insideFrame);
> -   mainLayout->addWidget(splitter);
> -
> -   QSplitter* hSplitter = new QSplitter(Horizontal, splitter);
> -
> -   m_moduleListBox = new CModuleResultView(hSplitter);
> -
> -   m_resultListBox = new CSearchResultView(hSplitter);
> -
> -   hSplitter->setResizeMode(m_moduleListBox, QSplitter::FollowSizeHint);
> -   hSplitter->setResizeMode(m_resultListBox, QSplitter::Stretch);
> +	m_moduleListBox = new CModuleResultView(insideFrame);
> +	m_moduleListBox->setFixedHeight( 100 );
> +	gridLayout->addWidget(m_moduleListBox, 0, 0);
>  
> -   m_previewDisplay = CDisplay::createReadInstance(0, splitter);
> +	m_resultListBox = new CSearchResultView(insideFrame);
> +	gridLayout->addWidget(m_resultListBox, 1, 0);
>  
> -   m_moduleListBox->resize(m_moduleListBox->sizeHint());
> -   splitter->setResizeMode(hSplitter, QSplitter::KeepSize);
> -   splitter->setResizeMode(m_previewDisplay->view(), QSplitter::Stretch);
> +	m_analyseButton = new QPushButton(i18n("Analyze search"), insideFrame);
> +	connect(m_analyseButton, SIGNAL(clicked()), SLOT(showAnalysis()));
> +	gridLayout->addWidget(m_analyseButton, 2, 0);
>  
> -   m_analyseButton = new QPushButton(i18n("Show search analysis"), this);
> -   connect(m_analyseButton, SIGNAL(clicked()), SLOT(showAnalysis()));
> -   mainLayout->addSpacing(5);
> -   mainLayout->addWidget(m_analyseButton);
> +	m_previewDisplay = CDisplay::createReadInstance(0, insideFrame);
> +	gridLayout->addMultiCellWidget(m_previewDisplay->view(), 0, 2, 1, 1);
>  }
>  
>  /** Sets the modules which contain the result of each. */
>  void CSearchResultPage::setSearchResult(ListCSwordModuleInfo modules) {
> -   const QString searchedText = CSearchDialog::getSearchDialog()->searchText();
>  	reset(); //clear current modules
>  
> -
>  	m_modules = modules;
> -	m_moduleListBox->setupTree(modules, searchedText);
> +	m_moduleListBox->setupTree(modules);
> +	m_moduleListBox->setMinimumWidth(m_moduleListBox->sizeHint().width());
> +	m_moduleListBox->adjustSize();
> +	//  m_moduleListBox->parentWidget()->adjustSize();
> +
>  
>  	//have a Bible or commentary in the modules?
>  	bool enable = false;
> @@ -716,33 +534,8 @@
>  	const QString rep2("</span>");
>  	const unsigned int repLength = rep1.length() + rep1.length();
>  
> -   if (searchedText.find("strong:", 0) == 0)
> -      {
> -      int idx1, idx2;
> -      QString sNumber, lemmaText;
> -      const QString rep3("style=\"background-color:#FFFF66;\" ");
> -      const unsigned int rep3Length = rep3.length();
> -      // get the strongs number from the search text
> -      sNumber = searchedText.right(searchedText.length() - 7);
> -      // find all the "lemma=" inside the the content
> -      while((index = ret.find("lemma=", index, cs)) != -1)
> -         {
> -         // get the strongs number after the lemma and compare it with the
> -         // strongs number we are looking for
> -         idx1 = ret.find("\"", index) + 1;
> -         idx2 = ret.find("\"", idx1 + 1);
> -         lemmaText = ret.mid(idx1, idx2 - idx1);
> -         if (lemmaText.find(sNumber) >= 0)
> -            {
> -            // strongs number is found now we need to highlight it
> -            // I believe the easiest way is to insert rep3 just before "lemma="
> -            ret = ret.insert(index, rep3);
> -            index += rep3Length;
> -            }
> -         index += 6; // 6 is the length of "lemma="
> -         }
> -      }
> -	else if (searchFlags & CSwordModuleSearch::exactPhrase) { //exact phrase matching
> +
> +	if (searchFlags & CSwordModuleSearch::exactPhrase) { //exact phrase matching
>  		while ( (index = ret.find(searchedText, index, cs)) != -1 ) {
>  			if (!CToolClass::inHTMLTag(index, ret)) {
>  				ret = ret.insert( index+length, rep2 );
> @@ -797,9 +590,6 @@
>  			m_resultListBox, SLOT(setupTree(CSwordModuleInfo*)));
>  	connect(m_moduleListBox, SIGNAL(moduleChanged()),
>  			m_previewDisplay->connectionsProxy(), SLOT(clear()));
> -   // connect the strongs list
> -   connect(m_moduleListBox, SIGNAL(strongsSelected(CSwordModuleInfo*, QStringList*)),
> -         m_resultListBox, SLOT(setupStrongsTree(CSwordModuleInfo*, QStringList*)));
>  }
>  
>  /** Shows a dialog with the search analysis of the current search. */
> @@ -834,9 +624,7 @@
>  			found = true;
>  		}
>  	}
> -   // This is needed because in the for loop i is incremented before the comparison (++i)
> -   // As a result the index i is actually one greater than expected.
> -   i--;
> +
>  	if (!found) {
>  		i = 0;
>  		m_searchTextCombo->insertItem( text,0 );
> @@ -850,8 +638,7 @@
>  /** Initializes this page. */
>  void CSearchOptionsPage::initView() {
>  
> -   // I commented this out because the Search Option page looks better when it resizes.
> -	//this->setSizePolicy( QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
> +	this->setSizePolicy( QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
>  
>  	QWidget* insideFrame = new QWidget( this );
>  	QBoxLayout* vLayout = new QBoxLayout( insideFrame, QBoxLayout::Down);
> diff -U 3 -H -d -r -N -- bibletime-new/bibletime/frontend/searchdialog/csearchdialogpages.h bibletime-cvs/bibletime/frontend/searchdialog/csearchdialogpages.h
> --- bibletime-new/bibletime/frontend/searchdialog/csearchdialogpages.h	2006-01-15 18:36:58.000000000 -0700
> +++ bibletime-cvs/bibletime/frontend/searchdialog/csearchdialogpages.h	2006-01-02 10:26:07.000000000 -0700
> @@ -30,86 +30,6 @@
>  
>  class CReadDisplay;
>  
> -/**
> -* This class is used to keep track of the text strongs results.
> -* It only keeps track of one instance of a strongs text result.
> -*
> -*    The functions of the class are:
> -*       - Store an instance of a strongs text result.
> -*       - Each strongs text result will contain a list of verses (keyNames).
> -*       - The number of verses (keyNames) is returned by keyCount().
> -*       - The text for the strongs text result is returned by keyText().
> -*       - The list of verses (keyNames) is returned by getKeyList() [as QStringList].
> -*
> -*   To add a new verse to a strongs text result use addKeyName.
> -*/
> -class StrongsResult
> -   {
> -   public:
> -      StrongsResult() : text("") { keyNameList.clear(); }
> -      StrongsResult(const QString& text, const QString &keyName)
> -         : text(text)
> -         { keyNameList.clear(); keyNameList.append(keyName); }
> -
> -      QString keyText() const { return text; }
> -      int keyCount() const { return keyNameList.count(); }
> -      void addKeyName(const QString& keyName) { keyNameList.append(keyName); }
> -      QStringList* getKeyList() { return &keyNameList; }
> -
> -      /* ????
> -      bool operator==(const StrongsResult &l, const StrongsResult &r)
> -         { return (l.keyText() == r.keyText()); }
> -
> -      bool operator<(const StrongsResult &l, const StrongsResult &r)
> -         { return (l->keyText() < r->keyText()); }
> -
> -      bool operator>(const StrongsResult &l, const StrongsResult &r)
> -         { return (l->keyText() > r->keyText()); }
> -      */
> -   private:
> -      QString text;
> -      QStringList keyNameList;
> -   };
> -
> -typedef QValueList<StrongsResult> StrongsResultList;
> -
> -/**
> -* This class is used to keep track of the text strongs results.
> -* It keeps track of all instances of all strongs text results.
> -* This class makes use of the above class StrongsResult.
> -*
> -*    The functions of the class are:
> -*       - Store an instance of a strongs text result.
> -*       - Each strongs text result will contain a list of verses (keyNames).
> -*       - The number of verses (keyNames) is returned by keyCount().
> -*       - The text for the strongs text result is returned by keyText().
> -*       - The list of verses (keyNames) is returned by getKeyList() [as QStringList].
> -*
> -*   To add a new verse to a strongs text result use addKeyName.
> -*/
> -class StrongsResultClass
> -   {
> -   public:
> -      StrongsResultClass(CSwordModuleInfo* module, const QString& strongsNumber)
> -         : srModule(module), lemmaText(strongsNumber)
> -         { initStrongsResults(); }
> -
> -      QString keyText(int index) const { return srList[index].keyText(); }
> -      int keyCount(int index) const { return srList[index].keyCount(); }
> -      QStringList* getKeyList(int index) { return srList[index].getKeyList(); }
> -      int Count() const { return srList.count(); }
> -
> -   private:
> -      void initStrongsResults(void);
> -      QString getStrongsNumberText(const QString& verseContent, int *startIndex);
> -
> -      StrongsResultList srList;
> -      CSwordModuleInfo* srModule;
> -      QString lemmaText;
> -   };
> -
> -
> -
>  class CModuleResultView : public KListView {
>  	Q_OBJECT
>  public:
> @@ -118,7 +38,7 @@
>  	/**
>  	* Setups the tree using the given list of modules.
>  	*/
> -	void setupTree( ListCSwordModuleInfo modules, const QString& searchedText );
> +	void setupTree( ListCSwordModuleInfo modules );
>  	/**
>  	* Returns the currently active module.
>  	*/
> @@ -134,8 +54,6 @@
>  	*/
>  	void initConnections();
>  
> -   void setupStrongsResults(CSwordModuleInfo* module, QListViewItem* parent, const QString& searchedText);
> -
>  protected slots: // Protected slots
>  	/**
>  	* Is executed when an item was selected in the list.
> @@ -169,7 +87,6 @@
>  signals:
>  	void moduleSelected(CSwordModuleInfo*);
>  	void moduleChanged();
> -   void strongsSelected(CSwordModuleInfo*, QStringList*);
>  
>  private:
>  	struct {
> @@ -196,7 +113,6 @@
>  	}
>  	m_actions;
>  	KPopupMenu* m_popup;
> -   StrongsResultClass* strongsResults;
>  };
>  
>  class CSearchResultView  : public KListView {
> @@ -221,7 +137,6 @@
>  	* Setups the list with the given module.
>  	*/
>  	void setupTree(CSwordModuleInfo*);
> -   void setupStrongsTree(CSwordModuleInfo*, QStringList*);
>  	void copyItemsWithText();
>  	void copyItems();
>  	void saveItemsWithText();
> 
> 
> ------------------------------------------------------------------------
> 
> /********* Read the file LICENSE for license details. *********/
> 
> #include "csearchdialog.h"
> #include "csearchanalysis.h"
> #include "backend/cswordmodulesearch.h"
> 
> 
> #include "backend/cswordkey.h"
> #include "backend/cswordversekey.h"
> 
> #include "frontend/cbtconfig.h"
> 
> #include "util/cresmgr.h"
> #include "util/ctoolclass.h"
> 
> //Qt includes
> #include <qhbox.h>
> #include <qvbox.h>
> #include <qptrlist.h>
> #include <qpainter.h>
> #include <qlayout.h>
> #include <qmap.h>
> #include <qlineedit.h>
> #include <qtextedit.h>
> #include <qlabel.h>
> #include <qsizepolicy.h>
> #include <qpushbutton.h>
> #include <qheader.h>
> #include <qregexp.h>
> #include <qmessagebox.h>
> 
> //KDE includes
> #include <kapplication.h>
> #include <kfiledialog.h>
> #include <klocale.h>
> #include <kiconloader.h>
> 
> static CSearchDialog* m_staticDialog = 0;
> 
> void CSearchDialog::openDialog(const ListCSwordModuleInfo modules, const QString& searchText, QWidget* parentDialog) {
> 	if (!m_staticDialog) {
> 		m_staticDialog = new CSearchDialog(parentDialog);
> 	};
> 	m_staticDialog->reset();
> 
> 	if (modules.count()) {
> 		m_staticDialog->setModules(modules);
> 	}
> 	else {
> 		m_staticDialog->showModulesSelector();
> 	}
> 
> 	m_staticDialog->setSearchText(searchText);
> 	if (m_staticDialog->isHidden()) {
> 		m_staticDialog->show();
> 	}
> 
> 	m_staticDialog->raise();
> 
>    // this is needed to make the dialog box adjust properly.
>    // without it the search and close buttons are hidden.
>    m_staticDialog->adjustSize();
> 
> 	if (modules.count() && !searchText.isEmpty()) {
> 		m_staticDialog->startSearch();
> 	}
> };
> 
> CSearchDialog* const CSearchDialog::getSearchDialog() {
> 	Q_ASSERT(m_staticDialog);
> 	return m_staticDialog;
> };
> 
> CSearchDialog::CSearchDialog(QWidget *parent)
> : KDialogBase(Plain, i18n("Search dialog"), Close | User1, User1, parent, "CSearchDialog", false, true, i18n("Search")) {
> 
> 	setWFlags( getWFlags() | Qt::WStyle_MinMax );
> 	setIcon(CResMgr::searchdialog::icon);
> 
> 	m_searcher.connectFinished( this, SLOT(searchFinished()));
> 
> 	initView();
> 	initConnections();
> }
> 
> // CSearchDialog::~CSearchDialog(){
> // }
> 
> /** Starts the search with the set modules and the set search text. */
> void CSearchDialog::startSearch() {
> 	QString searchText(m_searchOptionsPage->searchText());
> 
> 	if (searchText.isEmpty()) {
> 		return;
> 	}
> 
> 	// check that we have the indices we need for searching
> 	if (!m_searcher.modulesHaveIndices( modules() ) )	{
> 		int result = QMessageBox::question(this, i18n("Missing indices"),
> 			i18n("One or more modules need indexing before they can be searched.\n"
> 			"This could take a long time. Proceed with indexing?"),
>       	QMessageBox::Yes | QMessageBox::Default,
>          QMessageBox::No | QMessageBox::Escape);
>       // The result is 0 for Yes/Ok and 1 for No/Cancel.
>       // It does not seem to matter what the two button constants are.
>       // I have tried Yes/No, Ok/Cancel and they both show a Yes/No dialog with
>       // Yes on the left and No on the right.  When Yes is clicked the result is 0,
>       // when No is clicked the result is 1.
> 		if (result == 0) {
> 			// FIXME - add a proper progress dialog for indexing
> 			m_searcher.indexModules( modules() );
> 		}
> 		else {
> 			return;
> 		}
> 	}
> 
> 	m_searchResultPage->reset();
> 
> 	int searchFlags = m_searchOptionsPage->searchFlags();
> 
> 	const CSwordModuleSearch::scopeType scopeType = m_searchOptionsPage->scopeType();
> 	if (scopeType == CSwordModuleSearch::Scope_LastSearch) {
> 		searchFlags |= CSwordModuleSearch::useLastResult;
> 	}
> 	else if ( (scopeType == CSwordModuleSearch::Scope_Bounds)
> 			  && strlen(m_searchOptionsPage->searchScope().getRangeText())) {
> 		//we need the scope flag and a valid scope!
> 		searchFlags |= CSwordModuleSearch::useScope;
> 		m_searcher.setSearchScope( m_searchOptionsPage->searchScope() );
> 	}
> 
> 	m_searcher.setModules( modules() );
> 	m_searcher.setSearchedText(searchText);
> 	m_searcher.setSearchOptions(searchFlags);
> 
> 	m_searcher.startSearch();
> }
> 
> /** Starts the search with the given module list and given search text. */
> void CSearchDialog::startSearch( const ListCSwordModuleInfo modules, const QString& searchText) {
> 	m_searchResultPage->reset();
> 	m_searchOptionsPage->reset();
> 	setModules(modules);
> 	setSearchText(searchText);
> 
> 	startSearch();
> }
> 
> /** Returns the list of used modules. */
> const ListCSwordModuleInfo CSearchDialog::modules() {
> 	return m_searchOptionsPage->modules();
> }
> 
> /** Sets the list of modules for the search. */
> void CSearchDialog::setModules( const ListCSwordModuleInfo modules ) {
> 	m_searchOptionsPage->setModules(modules);
> 	resize( sizeHint() );
> }
> 
> /** Returns the search text which is set currently. */
> const QString CSearchDialog::searchText() {
> 	return m_searchOptionsPage->searchText();
> }
> 
> sword::ListKey CSearchDialog::searchScope() {
> 	return m_searchOptionsPage->searchScope();
> };
> 
> /** Returns true if the search used a scope, otherwise false. */
> const CSwordModuleSearch::scopeType CSearchDialog::searchScopeType() const {
> 	return m_searchOptionsPage->scopeType();
> }
> 
> /** Returns true if the search used a scope, otherwise false. */
> const int CSearchDialog::searchFlags() const {
> 	return m_searchOptionsPage->searchFlags();
> }
> 
> /** Returns the search text which is used for the search. */
> void CSearchDialog::setSearchText( const QString searchText ) {
> 	m_searchOptionsPage->setSearchText(searchText);
> }
> 
> /** Initializes this object. */
> void CSearchDialog::initView() {
> 	setButtonTip(User1, CResMgr::searchdialog::searchButton::tooltip);
> 
>    // this is to get the search results page to have a sane default size.
>    // there might be a better fix but I don't know of one.
>    setInitialSize(QSize(575, 200));
> 
> 	QVBoxLayout* box = new QVBoxLayout (plainPage());
> 	box->setSpacing(3);
> 
> 	m_searchOptionsPage = new CSearchOptionsPage(plainPage());
> 	box->addWidget( m_searchOptionsPage );
> 
> 	m_searchResultPage = new CSearchResultPage(plainPage());
> 	box->addWidget( m_searchResultPage );
> 
> }
> 
> void CSearchDialog::searchFinished() {
> // 	qWarning("CSearchDialog::searchFinished()");
> 	if ( m_searcher.foundItems() ) {
> 		m_searchResultPage->setSearchResult(modules());
> 	}
> 	else
> 		m_searchResultPage->reset();
> }
> 
> void CSearchDialog::showModulesSelector() {
> 	m_searchOptionsPage->chooseModules();
> }
> 
> /** Initializes the signal slot connections */
> void CSearchDialog::initConnections() {
> 	connect(this, SIGNAL(user1Clicked()), SLOT(startSearch()));
> 	connect(this, SIGNAL(closeClicked()), SLOT(slotDelayedDestruct()));
> }
> 
> /** Resets the parts to the default. */
> void CSearchDialog::reset() {
> 	m_searchOptionsPage->reset();
> 	m_searchResultPage->reset();
> }
> 
> /** Reimplementation. */
> void CSearchDialog::slotClose() {
> 	delayedDestruct();
> 	m_staticDialog = 0;
> }
> 
> 
> ------------------------------------------------------------------------
> 
> /********* Read the file LICENSE for license details. *********/
> 
> #include "csearchdialogpages.h"
> 
> #include "csearchdialog.h"
> #include "csearchanalysis.h"
> #include "crangechooser.h"
> 
> #include "backend/cswordversekey.h"
> #include "backend/cswordmoduleinfo.h"
> #include "backend/cdisplayrendering.h"
> 
> #include "frontend/cbtconfig.h"
> #include "frontend/cdragdropmgr.h"
> #include "frontend/cexportmanager.h"
> #include "frontend/display/cdisplay.h"
> #include "frontend/display/creaddisplay.h"
> 
> #include "util/cresmgr.h"
> #include "util/cpointers.h"
> #include "util/ctoolclass.h"
> 
> //Qt includes
> #include <qlayout.h>
> #include <qhbox.h>
> #include <qvbox.h>
> #include <qvgroupbox.h>
> #include <qlabel.h>
> #include <qlistview.h>
> #include <qpushbutton.h>
> #include <qradiobutton.h>
> #include <qsplitter.h>
> #include <qtooltip.h>
> #include <qbuttongroup.h>
> #include <qcheckbox.h>
> 
> #include <qheader.h>
> #include <qgroupbox.h>
> #include <qregexp.h>
> 
> //KDE includes
> #include <klocale.h>
> #include <kaction.h>
> #include <klistview.h>
> #include <kcombobox.h>
> #include <kprogress.h>
> #include <kpopupmenu.h>
> #include <ksqueezedtextlabel.h>
> #include <kparts/componentfactory.h> //KParts
> #include <kregexpeditorinterface.h>
> #include <ktextedit.h>
> #include <kiconloader.h>
> #include <kmessagebox.h>
> 
> 
> /********************************************
> ************  StrongsResultList *************
> ********************************************/
> void StrongsResultClass::initStrongsResults(void)
>    {
>    using namespace Rendering;
>    CDisplayRendering render;
>    ListCSwordModuleInfo modules;
>    CTextRendering::KeyTreeItem::Settings settings;
>    QString rText, lText, key;
>    bool found;
>    int sIndex;
>    int count;
>    int index;
>    QString text;
> 
>    modules.append(srModule);
>    sword::ListKey& result = srModule->searchResult();
> 
>    count = result.Count();
>    if (!count)
>       return;
> 
>    srList.clear();
> 
>    for (index = 0; index < count; index++)
>       {
>       key = QString::fromUtf8(result.GetElement(index)->getText());
>       text = render.renderSingleKey(key, modules, settings);
>       sIndex = 0;
>       while ((rText = getStrongsNumberText(text, &sIndex)) != "")
>          {
>          StrongsResultList::iterator it;
>          found = FALSE;
>          for ( it = srList.begin(); it != srList.end(); ++it )
>             {
>             lText = (*it).keyText();
>             if (lText == rText)
>                {
>                found = TRUE;
>                (*it).addKeyName(key);
>                break;
>                }
>             }
>          if (found == FALSE)
>             srList.append( StrongsResult(rText, key) );
>          }
>       }
>    //qHeapSort(srList);
>    }
> 
> QString StrongsResultClass::getStrongsNumberText(const QString& verseContent, int *startIndex)
>    {
>    // get the strongs text
>    int idx1, idx2, index;
>    QString sNumber, strongsText;
>    const bool cs = CSwordModuleSearch::caseSensitive;
> 
>    if (*startIndex == 0)
>       index = verseContent.find("<body", 0);
>    else
>       index = *startIndex;
>    // find all the "lemma=" inside the the content
>    while((index = verseContent.find("lemma=", index, cs)) != -1)
>       {
>       // get the strongs number after the lemma and compare it with the
>       // strongs number we are looking for
>       idx1 = verseContent.find("\"", index) + 1;
>       idx2 = verseContent.find("\"", idx1 + 1);
>       sNumber = verseContent.mid(idx1, idx2 - idx1);
>       if (sNumber.find(lemmaText) >= 0)
>          {
>          // strongs number is found now we need to get the text of this node
>          // search right until the ">" is found.  Get the text from here to
>          // the next "<".
>          index = verseContent.find(">", index, cs) + 1;
>          idx2  = verseContent.find("<", index, cs);
>          strongsText = verseContent.mid(index, idx2 - index);
>          index = idx2;
>          *startIndex = index;
>          return(strongsText);
>          }
>       else
>          {
>          index += 6; // 6 is the length of "lemma="
>          }
>       }
>    return("");
>    }
> 
> /********************************************
> ************  ModuleResultList **************
> ********************************************/
> 
> CSearchResultView::CSearchResultView(QWidget* parent) : KListView(parent), m_module(0) {
> 	initView();
> 	initConnections();
> };
> 
> CSearchResultView::~CSearchResultView() {}
> ;
> 
> /** Initializes the view of this widget. */
> void CSearchResultView::initView() {
> 	addColumn(i18n("Results"));
> 	setSorting(-1);
> 	setDragEnabled(true);
> 	setSelectionModeExt(KListView::Extended);
> 
> 	//setup the popup menu
> 	m_popup = new KPopupMenu(this);
> 
> 	m_actions.copyMenu = new KActionMenu(i18n("Copy..."), CResMgr::searchdialog::result::foundItems::copyMenu::icon, m_popup);
> 	m_actions.copy.result = new KAction(i18n("Reference only"), KShortcut(0), this, SLOT(copyItems()), this);
> 	m_actions.copyMenu->insert(m_actions.copy.result);
> 	m_actions.copy.resultWithText = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(copyItemsWithText()), this);
> 	m_actions.copyMenu->insert(m_actions.copy.resultWithText);
> 	m_actions.copyMenu->plug(m_popup);
> 
> 	m_actions.saveMenu = new KActionMenu(i18n("Save..."),CResMgr::searchdialog::result::foundItems::saveMenu::icon, m_popup);
> 	m_actions.save.result = new KAction(i18n("Reference only"), KShortcut(0), this, SLOT(saveItems()), this);
> 	m_actions.saveMenu->insert(m_actions.save.result);
> 	m_actions.save.resultWithText = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(saveItemsWithText()), this);
> 	m_actions.saveMenu->insert(m_actions.save.resultWithText);
> 	m_actions.saveMenu->plug(m_popup);
> 
> 	m_actions.printMenu = new KActionMenu(i18n("Print..."),CResMgr::searchdialog::result::foundItems::printMenu::icon, m_popup);
> 	m_actions.print.result = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(printItems()), this);
> 	m_actions.printMenu->insert(m_actions.print.result);
> 	m_actions.printMenu->plug(m_popup);
> }
> 
> /** No descriptions */
> void CSearchResultView::initConnections() {
> 	//  connect(this, SIGNAL(executed(QListViewItem*)),
> 	//   this, SLOT(executed(QListViewItem*)));
> 	connect(this, SIGNAL(currentChanged(QListViewItem*)),
> 			this, SLOT(executed(QListViewItem*)));
> 
> 	connect(this, SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint&)),
> 			this, SLOT(showPopup(KListView*, QListViewItem*, const QPoint&)));
> }
> 
> /** Setups the list with the given module. */
> void CSearchResultView::setupTree(CSwordModuleInfo* m) {
> 	clear();
> 	if (!m) {
> 		return;
> 	}
> 
> 	m_module = m;
> 
> 	sword::ListKey& result = m->searchResult();
> 	const int count = result.Count();
> 	if (!count)
> 		return;
> 
> 	setUpdatesEnabled(false);
> 
> 	QListViewItem* oldItem = 0;
> 	KListViewItem* item = 0;
> 	for (int index = 0; index < count; index++) {
> 		item = new KListViewItem(this, oldItem);
> 		item->setText(0, QString::fromUtf8(result.GetElement(index)->getText()));
> 		oldItem = item;
> 	}
> 
> 	setUpdatesEnabled(true);
> 
> 	setSelected(firstChild(), true);
> 	executed(currentItem());
> }
> 
> void CSearchResultView::setupStrongsTree(CSwordModuleInfo* m, QStringList* vList)
> {
>    clear();
>    if (!m) {
>       return;
>    }
> 
>    m_module = m;
> 
>    if (vList->count() <= 0)
>       return;
> 
>    setUpdatesEnabled(false);
> 
>    KListViewItem* oldItem = 0;
>    KListViewItem* item = 0;
> 
>    for ( QStringList::Iterator it = vList->begin(); it != vList->end(); ++it )
>       {
>       item = new KListViewItem(this, oldItem);
>       item->setText(0, (*it));
>       oldItem = item;
>       }
> 
>    setUpdatesEnabled(true);
> 
>    setSelected(firstChild(), true);
>    executed(currentItem());
> }
> 
> /** Is connected to the signal executed, which is emitted when a mew item was chosen. */
> void CSearchResultView::executed(QListViewItem* item) {
> 	//  Q_ASSERT(item);
> 	//  qWarning("executed");
> 	emit keySelected(item->text(0));
> }
> 
> /** Reimplementation to show the popup menu. */
> void CSearchResultView::showPopup(KListView*, QListViewItem*, const QPoint& point) {
> 	m_popup->exec(point);
> }
> 
> /** No descriptions */
> void CSearchResultView::printItems() {
> 	QPtrList<QListViewItem> items = selectedItems();
> 	CExportManager mgr(i18n("Print search result..."), true, i18n("Printing search result"));
> 
> 	QStringList list;
> 	for (QListViewItem* k = items.first(); k; k = items.next()) {
> 		list.append( k->text(0) );
> 	};
> 	mgr.printKeyList( list, module() );
> }
> 
> /** No descriptions */
> void CSearchResultView::saveItems() {
> 	CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
> 
> 	CSwordModuleInfo* m = module();
> 	CSwordKey* k = 0;
> 	QPtrList<QListViewItem> items = selectedItems();
> 	QPtrList<CSwordKey> keys;
> 	for (QListViewItem* i = items.first(); i; i = items.next()) {
> 		k = CSwordKey::createInstance( m );
> 		k->key(i->text(0));
> 		keys.append( k );
> 	};
> 	mgr.saveKeyList( keys, CExportManager::Text, false);
> 
> 	keys.setAutoDelete(true);
> 	keys.clear(); //delete all the keys we created
> }
> 
> /** No descriptions */
> void CSearchResultView::saveItemsWithText() {
> 	CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
> 
> 	CSwordModuleInfo* m = module();
> 	CSwordKey* k = 0;
> 	QPtrList<QListViewItem> items = selectedItems();
> 	QPtrList<CSwordKey> keys;
> 	for (QListViewItem* i = items.first(); i; i = items.next()) {
> 		k = CSwordKey::createInstance( m );
> 		k->key(i->text(0));
> 		keys.append( k );
> 	};
> 	mgr.saveKeyList( keys, CExportManager::Text, true);
> 
> 	keys.setAutoDelete(true);
> 	keys.clear(); //delete all the keys we created
> }
> 
> /** No descriptions */
> void CSearchResultView::copyItems() {
> 	CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
> 
> 	CSwordModuleInfo* m = module();
> 	CSwordKey* k = 0;
> 	QPtrList<QListViewItem> items = selectedItems();
> 	QPtrList<CSwordKey> keys;
> 	for (QListViewItem* i = items.first(); i; i = items.next()) {
> 		k = CSwordKey::createInstance( m );
> 		k->key(i->text(0));
> 		keys.append( k );
> 	};
> 	mgr.copyKeyList( keys, CExportManager::Text, false);
> 
> 	keys.setAutoDelete(true);
> 	keys.clear(); //delete all the keys we created
> }
> 
> /** No descriptions */
> void CSearchResultView::copyItemsWithText() {
> 	CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
> 
> 	CSwordModuleInfo* m = module();
> 	CSwordKey* k = 0;
> 	QPtrList<QListViewItem> items = selectedItems();
> 	QPtrList<CSwordKey> keys;
> 	for (QListViewItem* i = items.first(); i; i = items.next()) {
> 		k = CSwordKey::createInstance( m );
> 		k->key(i->text(0));
> 		keys.append( k );
> 	};
> 	mgr.copyKeyList( keys, CExportManager::Text, true);
> 
> 	keys.setAutoDelete(true);
> 	keys.clear(); //delete all the keys we created
> }
> 
> /** Returns the module which is currently used. */
> CSwordModuleInfo* const CSearchResultView::module() {
> 	return m_module;
> }
> 
> QDragObject* CSearchResultView::dragObject() {
> 	//return a valid DragObject to make DnD possible!
> 
> 	/*
> 	* First get all selected items and fill with them the dndItems list. The return the QDragObject we got from CDRagDropMgr
> 	*/
> 	CDragDropMgr::ItemList dndItems;
> 
> 	QPtrList<QListViewItem> items = selectedItems();
> 	for (items.first(); items.current(); items.next()) {
> 		dndItems.append( CDragDropMgr::Item(m_module->name(), items.current()->text(0), QString::null) ); //no description
> 	};
> 
> 	return CDragDropMgr::dragObject(dndItems, viewport());
> };
> 
> /********************************************
> ************  ModuleResultList **************
> ********************************************/
> 
> CModuleResultView::CModuleResultView(QWidget* parent) : KListView(parent) {
> 	initView();
> 	initConnections();
>    strongsResults = NULL;
> };
> 
> CModuleResultView::~CModuleResultView() {}
> ;
> 
> /** Initializes this widget. */
> void CModuleResultView::initView() {
> 	addColumn(i18n("Work"));
> 	addColumn(i18n("Hits"));
> 
> 	//  setFullWidth(true);
> 	setSorting(0, true);
> 	setSorting(1, true);
> 	setAllColumnsShowFocus(true);
> 
> 
> 	//setup the popup menu
> 	m_popup = new KPopupMenu(this);
> 	// m_popup->insertTitle(i18n("Bible window"));
> 
> 	m_actions.copyMenu = new KActionMenu(i18n("Copy..."), CResMgr::searchdialog::result::moduleList::copyMenu::icon, m_popup);
> 	m_actions.copy.result = new KAction(i18n("Reference only"), KShortcut(0), this, SLOT(copyResult()), this);
> 	m_actions.copyMenu->insert(m_actions.copy.result);
> 	m_actions.copy.resultWithText = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(copyResultWithText()), this);
> 	m_actions.copyMenu->insert(m_actions.copy.resultWithText);
> 	m_actions.copyMenu->plug(m_popup);
> 
> 	m_actions.saveMenu = new KActionMenu(i18n("Save..."), CResMgr::searchdialog::result::moduleList::saveMenu::icon, m_popup);
> 	m_actions.save.result = new KAction(i18n("Reference only"), KShortcut(0), this, SLOT(saveResult()), this);
> 	m_actions.saveMenu->insert(m_actions.save.result);
> 	m_actions.save.resultWithText = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(saveResultWithText()), this);
> 	m_actions.saveMenu->insert(m_actions.save.resultWithText);
> 	m_actions.saveMenu->plug(m_popup);
> 
> 	m_actions.printMenu = new KActionMenu(i18n("Print..."), CResMgr::searchdialog::result::moduleList::printMenu::icon, m_popup);
> 	m_actions.print.result = new KAction(i18n("Reference with text"), KShortcut(0), this, SLOT(printResult()), this);
> 	m_actions.printMenu->insert(m_actions.print.result);
> 
> 
> 	m_actions.printMenu->plug(m_popup);
> }
> 
> /** Initializes the connections of this widget, */
> void CModuleResultView::initConnections() {
> 	connect(this, SIGNAL(executed(QListViewItem*)),
> 			SLOT(executed(QListViewItem*)));
> 	connect(this, SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint&)),
> 			this, SLOT(showPopup(KListView*, QListViewItem*, const QPoint&)));
> }
> 
> /** Setups the tree using the given list of modules. */
> void CModuleResultView::setupTree( ListCSwordModuleInfo modules, const QString& searchedText ) {
> 	clear();
> 	QListViewItem* item = 0;
> 	QListViewItem* oldItem = 0;
> 	sword::ListKey result;
> 
>    if (strongsResults) {
>       delete(strongsResults);
>       strongsResults = NULL;
>       }
> 	ListCSwordModuleInfo::iterator end_it = modules.end();
> 	for (ListCSwordModuleInfo::iterator it(modules.begin()); it != end_it; ++it) {
> 		//   for (modules.first(); modules.current(); modules.next()) {
> 		result = (*it)->searchResult();
> 
> 		item = new KListViewItem(this, (*it)->name(), QString::number(result.Count()) );
> 		item->setPixmap(0,CToolClass::getIconForModule(*it) );
> 		oldItem = item;
>       if (searchedText.find("strong:", 0) == 0) {
>          QString sNumber;
>          sNumber = searchedText.right(searchedText.length() - 7);
>          setupStrongsResults((*it), item, sNumber);
>          item->setOpen(TRUE);
>       }
> 	};
> 
> 	setSelected(currentItem(), true);
> 	executed(currentItem());
> }
> 
> void CModuleResultView::setupStrongsResults(CSwordModuleInfo* module, QListViewItem* parent,
>                                             const QString& sNumber)
>    {
>    QString lText;
>    KListViewItem* item = 0;
> 
>    strongsResults = new StrongsResultClass(module, sNumber);
> 
>    for (int cnt = 0; cnt < strongsResults->Count(); cnt++)
>       {
>       lText = strongsResults->keyText(cnt);
>       item = new KListViewItem(parent, lText, QString::number(strongsResults->keyCount(cnt)));
>       item->setText(0, lText);
>       }
>    }
> 
> 
> /** Is executed when an item was selected in the list. */
> void CModuleResultView::executed( QListViewItem* i ) {
>    QString itemText, lText;
> 
> 	if (CSwordModuleInfo* m = CPointers::backend()->findModuleByName(i->text(0))) {
> 		emit moduleChanged();
> 		emit moduleSelected(m);
>       return;
> 	}
>    if (!strongsResults)
>       return;
> 
>    itemText = i->text(0);
>    for (int cnt = 0; cnt < strongsResults->Count(); cnt++)
>       {
>       lText = strongsResults->keyText(cnt);
>       if (lText == itemText)
>          {
>          //clear the verses list
>          emit moduleChanged();
>          emit strongsSelected(activeModule(), strongsResults->getKeyList(cnt));
>          return;
>          }
>       }
> }
> 
> /** Returns the currently active module. */
> CSwordModuleInfo* const CModuleResultView::activeModule() {
> 	Q_ASSERT(currentItem());
>    QListViewItem* item = currentItem();
> 
>    if (item == NULL)
>       return 0;
> 
>    // we need to find the parent most node because that is the node
>    // that is the module name.
>    while (item->parent())
>       item = item->parent();
> 
>    if (item)
>       return CPointers::backend()->findModuleByName(item->text(0));
> 
>    return 0;
> }
> 
> /** No descriptions */
> void CModuleResultView::showPopup(KListView*, QListViewItem*, const QPoint& point) {
> 	//make sure that all entries have the correct status
> 	m_popup->exec(point);
> }
> 
> /** Copies the whole search result into the clipboard. */
> void CModuleResultView::copyResult() {
> 	if (CSwordModuleInfo* m = activeModule()) {
> 		sword::ListKey result = m->searchResult();
> 		CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
> 		mgr.copyKeyList(&result,m,CExportManager::Text,false);
> 	};
> }
> 
> /** Copies the whole search result with the text into the clipboard. */
> void CModuleResultView::copyResultWithText() {
> 	if (CSwordModuleInfo* m = activeModule()) {
> 		sword::ListKey result = m->searchResult();
> 		CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
> 		mgr.copyKeyList(&result,m,CExportManager::Text,true);
> 	};
> }
> 
> /** Saves the search result keys. */
> void CModuleResultView::saveResult() {
> 	if (CSwordModuleInfo* m = activeModule()) {
> 		sword::ListKey result = m->searchResult();
> 		CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
> 		mgr.saveKeyList(&result,m,CExportManager::Text,false);
> 	};
> }
> 
> /** Saves the search result with it's text. */
> void CModuleResultView::saveResultWithText() {
> 	if (CSwordModuleInfo* m = activeModule()) {
> 		sword::ListKey result = m->searchResult();
> 		CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
> 		mgr.saveKeyList(&result,m,CExportManager::Text,true);
> 	};
> }
> 
> /** Appends the whole search result to the printer queue. */
> void CModuleResultView::printResult() {
> 	if (CSwordModuleInfo* m = activeModule()) {
> 		sword::ListKey result = m->searchResult();
> 		CExportManager mgr(i18n("Print search result..."), true, i18n("Printing search result"));
> 		mgr.printKeyList(&result,m);
> 	};
> }
> 
> /********************************************
> **********  CSearchDialogResultPage *********
> ********************************************/
> 
> CSearchResultPage::CSearchResultPage(QWidget *parent, const char *name ) : 
> 		QVGroupBox(i18n("Search results"),parent,name) {
> 	initView();
> 	initConnections();
> }
> 
> CSearchResultPage::~CSearchResultPage() {}
> 
> /** Initializes the view of this widget. */
> void CSearchResultPage::initView() {
> 
> 	QWidget* insideFrame = new QWidget( this );
> 
>    QVBoxLayout* mainLayout = new QVBoxLayout(insideFrame);
> 
>    QSplitter* splitter = new QSplitter(Vertical, insideFrame);
>    mainLayout->addWidget(splitter);
> 
>    QSplitter* hSplitter = new QSplitter(Horizontal, splitter);
> 
>    m_moduleListBox = new CModuleResultView(hSplitter);
> 
>    m_resultListBox = new CSearchResultView(hSplitter);
> 
>    hSplitter->setResizeMode(m_moduleListBox, QSplitter::FollowSizeHint);
>    hSplitter->setResizeMode(m_resultListBox, QSplitter::Stretch);
> 
>    m_previewDisplay = CDisplay::createReadInstance(0, splitter);
> 
>    m_moduleListBox->resize(m_moduleListBox->sizeHint());
>    splitter->setResizeMode(hSplitter, QSplitter::KeepSize);
>    splitter->setResizeMode(m_previewDisplay->view(), QSplitter::Stretch);
> 
>    m_analyseButton = new QPushButton(i18n("Show search analysis"), this);
>    connect(m_analyseButton, SIGNAL(clicked()), SLOT(showAnalysis()));
>    mainLayout->addSpacing(5);
>    mainLayout->addWidget(m_analyseButton);
> }
> 
> /** Sets the modules which contain the result of each. */
> void CSearchResultPage::setSearchResult(ListCSwordModuleInfo modules) {
>    const QString searchedText = CSearchDialog::getSearchDialog()->searchText();
> 	reset(); //clear current modules
> 
> 
> 	m_modules = modules;
> 	m_moduleListBox->setupTree(modules, searchedText);
> 
> 	//have a Bible or commentary in the modules?
> 	bool enable = false;
> 	//   for (modules.first(); !enable && modules.current(); modules.next()) {
> 	ListCSwordModuleInfo::iterator end_it = modules.end();
> 	for (ListCSwordModuleInfo::iterator it(modules.begin()); it != end_it; ++it) {
> 		if ((*it)->type() == CSwordModuleInfo::Bible ) {
> 			enable = true;
> 			break;
> 		};
> 	};
> 
> 	m_analyseButton->setEnabled(enable);
> }
> 
> 
> /** Resets the current list of modules and the displayed list of found entries. */
> void CSearchResultPage::reset() {
> 	m_moduleListBox->clear();
> 	m_resultListBox->clear();
> 	m_previewDisplay->setText(QString::null);
> 	m_analyseButton->setEnabled(false);
> 	//   m_modules.setAutoDelete(false); //make sure we don't delete modules accidentally
> 	m_modules.clear();
> }
> 
> 
> /** Update the preview of the selected key. */
> void CSearchResultPage::updatePreview(const QString& key) {
> 	using namespace Rendering;
> 
> 	if ( CSwordModuleInfo* module = m_moduleListBox->activeModule() ) {
> 		const QString searchedText = CSearchDialog::getSearchDialog()->searchText();
> 		const int searchFlags = CSearchDialog::getSearchDialog()->searchFlags();
> 
> 		QString text;
> 		CDisplayRendering render;
> 		ListCSwordModuleInfo modules;
> 		modules.append(module);
> 
> 		CTextRendering::KeyTreeItem::Settings settings;
> 
> 		//for bibles only render 5 verses, for all other modules only one entry
> 		if (module->type() == CSwordModuleInfo::Bible) {
> 			CSwordVerseKey vk(module);
> 			vk.key(key);
> 
> 			//first go back and then go forward the keys to be in context
> 			vk.previous(CSwordVerseKey::UseVerse);
> 			vk.previous(CSwordVerseKey::UseVerse);
> 			const QString startKey = vk.key();
> 
> 			vk.key(key);
> 
> 			vk.next(CSwordVerseKey::UseVerse);
> 			vk.next(CSwordVerseKey::UseVerse);
> 			const QString endKey = vk.key();
> 
> 			//    qWarning("want to render from %s to %s", startKey.latin1(), endKey.latin1());
> 			//now render the range
> 			settings.keyRenderingFace = CTextRendering::KeyTreeItem::Settings::CompleteShort;
> 			text = render.renderKeyRange(startKey, endKey, modules, key, settings);
> 			//    qWarning(text.latin1());
> 		}
> 		else {
> 			text = render.renderSingleKey(key, modules, settings);
> 		}
> 
> 		m_previewDisplay->setText( highlightSearchedText(text, searchedText, searchFlags) );
> 		m_previewDisplay->moveToAnchor( CDisplayRendering::keyToHTMLAnchor(key) );
> 	}
> }
> 
> const QString CSearchResultPage::highlightSearchedText(const QString& content, const QString& searchedText, const int searchFlags) {
> 	QString ret = content;
> 
> 	const bool cs = (searchFlags & CSwordModuleSearch::caseSensitive);
> 
> 	//   int index = 0;
> 	int index = ret.find("<body", 0);
> 	int length = searchedText.length();
> 
> 	const QString rep1("<span style=\"background-color:#FFFF66;\">");
> 	const QString rep2("</span>");
> 	const unsigned int repLength = rep1.length() + rep1.length();
> 
>    if (searchedText.find("strong:", 0) == 0)
>       {
>       int idx1, idx2;
>       QString sNumber, lemmaText;
>       const QString rep3("style=\"background-color:#FFFF66;\" ");
>       const unsigned int rep3Length = rep3.length();
>       // get the strongs number from the search text
>       sNumber = searchedText.right(searchedText.length() - 7);
>       // find all the "lemma=" inside the the content
>       while((index = ret.find("lemma=", index, cs)) != -1)
>          {
>          // get the strongs number after the lemma and compare it with the
>          // strongs number we are looking for
>          idx1 = ret.find("\"", index) + 1;
>          idx2 = ret.find("\"", idx1 + 1);
>          lemmaText = ret.mid(idx1, idx2 - idx1);
>          if (lemmaText.find(sNumber) >= 0)
>             {
>             // strongs number is found now we need to highlight it
>             // I believe the easiest way is to insert rep3 just before "lemma="
>             ret = ret.insert(index, rep3);
>             index += rep3Length;
>             }
>          index += 6; // 6 is the length of "lemma="
>          }
>       }
> 	else if (searchFlags & CSwordModuleSearch::exactPhrase) { //exact phrase matching
> 		while ( (index = ret.find(searchedText, index, cs)) != -1 ) {
> 			if (!CToolClass::inHTMLTag(index, ret)) {
> 				ret = ret.insert( index+length, rep2 );
> 				ret = ret.insert( index, rep1 );
> 				index += repLength;
> 			}
> 			index += repLength;
> 		};
> 	}
> 	else if (searchFlags & CSwordModuleSearch::multipleWords) { //multiple words
> 		QStringList words = QStringList::split(" ", searchedText);
> 		for ( int wi = 0; (unsigned int)wi < words.count(); ++wi ) { //search for every word in the list
> 			QString word = words[ wi ];
> 			length = word.length();
> 			//       index = 0; //for every word start at the beginning
> 			index = ret.find("<body", 0);
> 			while ( (index = ret.find(word, index, cs)) != -1 ) { //while we found the word
> 				if (!CToolClass::inHTMLTag(index, ret)) {
> 					ret = ret.insert( index+length, rep2 );
> 					ret = ret.insert( index, rep1 );
> 					index += repLength;
> 				}
> 				index += length;
> 			}
> 		}
> 	}
> 	else { //multiple words or regular expression
> 		//use re as regular expression and replace any occurences
> 		QRegExp regExp( searchedText, cs );
> 		regExp.setMinimal( true );
> 
> 		while ( (index = regExp.search(ret, index)) != -1 ) {
> 			if (!CToolClass::inHTMLTag(index, ret)) {
> 				ret = ret.insert( index + regExp.matchedLength(), rep2 );
> 				ret = ret.insert( index, rep1 );
> 				index += regExp.matchedLength() + repLength;
> 			}
> 			index += length;
> 		}
> 	}
> 
> 	//   qWarning("\n\n\n%s", ret.latin1());
> 
> 	return ret; //not implemented yet
> };
> 
> /** Initializes the signal slot conections of the child widgets, */
> void CSearchResultPage::initConnections() {
> 	connect(m_resultListBox, SIGNAL(keySelected(const QString&)),
> 			this, SLOT(updatePreview(const QString&)));
> 	connect(m_moduleListBox, SIGNAL(moduleSelected(CSwordModuleInfo*)),
> 			m_resultListBox, SLOT(setupTree(CSwordModuleInfo*)));
> 	connect(m_moduleListBox, SIGNAL(moduleChanged()),
> 			m_previewDisplay->connectionsProxy(), SLOT(clear()));
>    // connect the strongs list
>    connect(m_moduleListBox, SIGNAL(strongsSelected(CSwordModuleInfo*, QStringList*)),
>          m_resultListBox, SLOT(setupStrongsTree(CSwordModuleInfo*, QStringList*)));
> }
> 
> /** Shows a dialog with the search analysis of the current search. */
> void CSearchResultPage::showAnalysis() {
> 	CSearchAnalysisDialog dlg(m_modules, this);
> 	dlg.exec();
> }
> 
> /*************************/
> 
> CSearchOptionsPage::CSearchOptionsPage(QWidget *parent, const char *name ) : 
> 		QVGroupBox(i18n("Search parameters"),parent,name) {
> 	initView();
> 	readSettings();
> }
> 
> CSearchOptionsPage::~CSearchOptionsPage() {
> 	saveSettings();
> }
> 
> /** Returns the search text set in this page. */
> const QString CSearchOptionsPage::searchText() {
> 	return m_searchTextCombo->currentText();
> }
> 
> /** Sets the search text used in the page. */
> void CSearchOptionsPage::setSearchText(const QString& text) {
> 	bool found = false;
> 	int i = 0;
> 	for (i = 0; !found && i < m_searchTextCombo->count(); ++i) {
> 		if (m_searchTextCombo->text(i) == text) {
> 			found = true;
> 		}
> 	}
>    // This is needed because in the for loop i is incremented before the comparison (++i)
>    // As a result the index i is actually one greater than expected.
>    i--;
> 	if (!found) {
> 		i = 0;
> 		m_searchTextCombo->insertItem( text,0 );
> 	}
> 
> 	m_searchTextCombo->setCurrentItem(i);
> 	m_searchTextCombo->reset();
> 	m_searchTextCombo->setFocus();
> }
> 
> /** Initializes this page. */
> void CSearchOptionsPage::initView() {
> 
>    // I commented this out because the Search Option page looks better when it resizes.
> 	//this->setSizePolicy( QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
> 
> 	QWidget* insideFrame = new QWidget( this );
> 	QBoxLayout* vLayout = new QBoxLayout( insideFrame, QBoxLayout::Down);
> 	vLayout->setSpacing( 3 );
> 
> 	QHBoxLayout* hBox0 = new QHBoxLayout( vLayout );
> 
> 	QLabel* label = new QLabel(insideFrame);
> 	hBox0->addWidget(label);
> 	label->setText(i18n("Search for:"));
> 	
> 	m_searchTextCombo = new KHistoryCombo(insideFrame);
> 	hBox0->addWidget(m_searchTextCombo);
> 	hBox0->setStretchFactor(m_searchTextCombo, 10);
> 	label->setAutoResize(true);
> 	m_searchTextCombo->setInsertionPolicy( QComboBox::AtBottom );
> 	m_searchTextCombo->setMaxCount(25);
> 	m_searchTextCombo->setDuplicatesEnabled(false);
> 	m_searchTextCombo->setFocusPolicy(QWidget::WheelFocus);
> 	connect( m_searchTextCombo, SIGNAL(activated( const QString& )),
> 				m_searchTextCombo, SLOT( addToHistory( const QString& ))
> 			);
> 	connect( m_searchTextCombo, SIGNAL(returnPressed ( const QString& )),
> 				m_searchTextCombo, SLOT(addToHistory(const QString&))
> 			);
> 	QToolTip::add(m_searchTextCombo, CResMgr::searchdialog::options::searchedText::tooltip);
> 
> 	QPushButton* syntaxButton = new QPushButton(SmallIcon( "contexthelp"), "", insideFrame);
> 	hBox0->addWidget( syntaxButton );
> 	connect( syntaxButton, SIGNAL(clicked()), this, SLOT(syntaxHelp()));
> 
> 	QHBoxLayout* hBox1 = new QHBoxLayout(vLayout);
> 
> 	m_modulesLabel = new QLabel(insideFrame);
> 	hBox1->addWidget(m_modulesLabel);
> 	hBox1->setStretchFactor( m_modulesLabel, 5);
> 	hBox1->addStretch();
> 	m_modulesLabel->setTextFormat(Qt::RichText);
> 	m_modulesLabel->setAlignment( AlignLeft | WordBreak );
> 
> 	m_chooseModulesButton = new QPushButton(SmallIcon("wizard"), i18n("Choose"), insideFrame);
> 	hBox1->addWidget(m_chooseModulesButton);
> 	connect(m_chooseModulesButton, SIGNAL(clicked()),
> 			this, SLOT(chooseModules()));
> 	QToolTip::add
> 		(m_chooseModulesButton, CResMgr::searchdialog::options::moduleChooserButton::tooltip);
> 	
> 
> 	QHBoxLayout* hBox2 = new QHBoxLayout(vLayout);
> 
> 	QLabel* label2 = new QLabel(insideFrame);
> 	label2->setText(i18n("Search scope:"));
> 	hBox2->addWidget(label2);
> 	hBox2->addStretch();
> 	
> 	m_rangeChooserCombo = new KComboBox(insideFrame);
> 	hBox2->addWidget(m_rangeChooserCombo);
> 
> 	m_rangeChooserCombo->setMaximumWidth( 150 );
> 	QToolTip::add
> 		(m_rangeChooserCombo, CResMgr::searchdialog::options::chooseScope::tooltip);
> 	refreshRanges();
> 
> 	m_chooseRangeButton = new QPushButton(SmallIcon("configure"), i18n("Setup"), insideFrame);
> 	hBox2->addWidget(m_chooseRangeButton);
> 	connect(m_chooseRangeButton, SIGNAL(clicked()),
> 			this, SLOT(setupRanges()));
> 
> 	//set the initial focus
> 	m_searchTextCombo->setFocus();
> }
> 
> /** Sets the modules used by the search. */
> void CSearchOptionsPage::setModules( ListCSwordModuleInfo modules ) {
> 	QString t = i18n("Searching in: ");
> 
> 	m_modules.clear(); //remove old modules
> 	ListCSwordModuleInfo::iterator end_it = modules.end();
> 
> 	for (ListCSwordModuleInfo::iterator it(modules.begin()); it != end_it; ++it) {
> 		//ToDo:  Check for containsRef compat
> 		if (*it == 0) { //don't operate on null modules.
> 			continue;
> 		}
> 		
> 		if ( !m_modules.contains(*it) ) {
> 			m_modules.append( *it );
> 			t.append( (*it)->name() );
> 			if (*it != modules.last()) {
> 				t += QString::fromLatin1(", "); // so that it will become a readable list (WLC, LXX, GerLut...)
> 			}
> 		}
> 	};
> 	m_modulesLabel->setText(t);
> 	emit( sigSetSearchButtonStatus( (modules.count() != 0) ) );
> }
> 
> /** Opens the modules chooser dialog. */
> void CSearchOptionsPage::chooseModules() {
> 	CModuleChooserDialog* dlg = new CModuleChooserDialog(this, modules());
> 	connect(dlg, SIGNAL(modulesChanged(ListCSwordModuleInfo)),
> 			this, SLOT(setModules(ListCSwordModuleInfo)));
> 	dlg->exec();
> }
> 
> /** Returns the list of used modules. */
> const ListCSwordModuleInfo CSearchOptionsPage::modules() {
> 	return m_modules;
> }
> 
> /** Return the selected search type,. */
> const int CSearchOptionsPage::searchFlags() {
> 	// FIXME - remove this due to new index search
> 	int ret = CSwordModuleSearch::multipleWords; //"multiple words" is standard
> 	return ret;
> }
> 
> /** Sets all options back to the default. */
> void CSearchOptionsPage::reset() {
> 	m_rangeChooserCombo->setCurrentItem(0); //no scope
> 	m_searchTextCombo->clearEdit();
> }
> 
> /** Reads the settings for the searchdialog from disk. */
> void CSearchOptionsPage::saveSettings() {
> 	CBTConfig::set
> 		(CBTConfig::searchCompletionTexts, m_searchTextCombo->completionObject()->items());
> 	CBTConfig::set
> 		(CBTConfig::searchTexts, m_searchTextCombo->historyItems());
> }
> 
> /** Reads the settings of the last searchdialog session. */
> void CSearchOptionsPage::readSettings() {
> 	m_searchTextCombo->completionObject()->setItems( CBTConfig::get
> 				(CBTConfig::searchCompletionTexts) );
> 	m_searchTextCombo->setHistoryItems( CBTConfig::get
> 											(CBTConfig::searchTexts) );
> }
> 
> void CSearchOptionsPage::aboutToShow() {
> 	m_searchTextCombo->setFocus();
> }
> 
> /** No descriptions */
> void CSearchOptionsPage::setupRanges() {
> 	CRangeChooserDialog* chooser = new CRangeChooserDialog(this);
> 	chooser->exec();
> 
> 	refreshRanges();
> }
> 
> /** No descriptions */
> void CSearchOptionsPage::syntaxHelp() {
> 	QString syntax = i18n (
> 			"<p>Enter search terms separated by spaces.  By default the search "
> 			"function will return results that match any of the search terms. "
> 			"To search for all the terms separate the terms by AND.</p>"
> 			"<p>To search types other than the main text, enter the type followed "
> 			"by \":\", and then the search term.  For example, 'strong:H8077'.</p>"
> 			"<p>Types:<br><table>"
> 			"<tr><td>heading:</td><td>searches headings</td></tr>"
> 			"<tr><td>footnote:</td><td>searches footnotes</td></tr>"
> 			"<tr><td>strong:</td><td>searches Strong's Numbers</td></tr>"
> 			"<tr><td>morph:</td><td>searches Morphology entries</td></tr></table>"
> 			"For more help see: <a href=\"http://lucene.apache.org/java/docs/queryparsersyntax.html\">"
> 			"http://lucene.apache.org/java/docs/queryparsersyntax.html</a></p>");
> 
> 	KMessageBox::about( this, syntax, i18n("Basic Syntax Introduction"));
> }
> 
> 
> /** refreshes the listof ranges and the range combobox. */
> void CSearchOptionsPage::refreshRanges() {
> 	//the first two options are fixed, the others can be edited using the "Setup ranges" button.
> 	m_rangeChooserCombo->clear();
> 	m_rangeChooserCombo->insertItem(i18n("No search scope"));
> 	m_rangeChooserCombo->insertItem(i18n("Last search result"));
> 
> 	//insert the user-defined ranges
> 	CBTConfig::StringMap map = CBTConfig::get
> 								   (CBTConfig::searchScopes);
> 	CBTConfig::StringMap::Iterator it;
> 	for (it = map.begin(); it != map.end(); ++it) {
> 		m_rangeChooserCombo->insertItem(it.key());
> 	};
> }
> 
> /** Returns the selected search scope if a search scope was selected. */
> sword::ListKey CSearchOptionsPage::searchScope() {
> 	if (m_rangeChooserCombo->currentItem() > 1) { //neither "No Scope" nor "Last search result"
> 		CBTConfig::StringMap map = CBTConfig::get
> 									   (CBTConfig::searchScopes);
> 		QString scope = map[ m_rangeChooserCombo->currentText() ];
> 		if (!scope.isEmpty())
> 			return sword::VerseKey().ParseVerseList( (const char*)scope.utf8(), "Genesis 1:1", true);
> 	};
> 	return sword::ListKey();
> }
> 
> /** Returns the selected scope type. */
> const CSwordModuleSearch::scopeType CSearchOptionsPage::scopeType() {
> 	if (m_rangeChooserCombo->currentItem() == 0) {
> 		return CSwordModuleSearch::Scope_NoScope;
> 	}
> 	else if (m_rangeChooserCombo->currentItem() == 1) {
> 		return CSwordModuleSearch::Scope_LastSearch;
> 	}
> 	else {
> 		return CSwordModuleSearch::Scope_Bounds;
> 	};
> 
> 	return CSwordModuleSearch::Scope_NoScope;
> }
> 
> 
> ------------------------------------------------------------------------
> 
> /********* Read the file LICENSE for license details. *********/
> 
> #ifndef CSEARCHDIALOGPAGES_H
> #define CSEARCHDIALOGPAGES_H
> 
> //BibleTime includes
> #include "backend/cswordmoduleinfo.h"
> #include "backend/cswordbackend.h"
> #include "backend/cswordmodulesearch.h"
> 
> //Qt includes
> #include <qwidget.h>
> #include <qvgroupbox.h>
> 
> //KDE includes
> #include <klistview.h>
> 
> //forward declarations
> class QLabel;
> class QCheckBox;
> class QPushButton;
> class QRadioButton;
> 
> class KComboBox;
> class KActionMenu;
> class KAction;
> class KHistoryCombo;
> class KProgress;
> class KPopupMenu;
> 
> class CReadDisplay;
> 
> /**
> * This class is used to keep track of the text strongs results.
> * It only keeps track of one instance of a strongs text result.
> *
> *    The functions of the class are:
> *       - Store an instance of a strongs text result.
> *       - Each strongs text result will contain a list of verses (keyNames).
> *       - The number of verses (keyNames) is returned by keyCount().
> *       - The text for the strongs text result is returned by keyText().
> *       - The list of verses (keyNames) is returned by getKeyList() [as QStringList].
> *
> *   To add a new verse to a strongs text result use addKeyName.
> */
> class StrongsResult
>    {
>    public:
>       StrongsResult() : text("") { keyNameList.clear(); }
>       StrongsResult(const QString& text, const QString &keyName)
>          : text(text)
>          { keyNameList.clear(); keyNameList.append(keyName); }
> 
>       QString keyText() const { return text; }
>       int keyCount() const { return keyNameList.count(); }
>       void addKeyName(const QString& keyName) { keyNameList.append(keyName); }
>       QStringList* getKeyList() { return &keyNameList; }
> 
>       /* ????
>       bool operator==(const StrongsResult &l, const StrongsResult &r)
>          { return (l.keyText() == r.keyText()); }
> 
>       bool operator<(const StrongsResult &l, const StrongsResult &r)
>          { return (l->keyText() < r->keyText()); }
> 
>       bool operator>(const StrongsResult &l, const StrongsResult &r)
>          { return (l->keyText() > r->keyText()); }
>       */
>    private:
>       QString text;
>       QStringList keyNameList;
>    };
> 
> typedef QValueList<StrongsResult> StrongsResultList;
> 
> /**
> * This class is used to keep track of the text strongs results.
> * It keeps track of all instances of all strongs text results.
> * This class makes use of the above class StrongsResult.
> *
> *    The functions of the class are:
> *       - Store an instance of a strongs text result.
> *       - Each strongs text result will contain a list of verses (keyNames).
> *       - The number of verses (keyNames) is returned by keyCount().
> *       - The text for the strongs text result is returned by keyText().
> *       - The list of verses (keyNames) is returned by getKeyList() [as QStringList].
> *
> *   To add a new verse to a strongs text result use addKeyName.
> */
> class StrongsResultClass
>    {
>    public:
>       StrongsResultClass(CSwordModuleInfo* module, const QString& strongsNumber)
>          : srModule(module), lemmaText(strongsNumber)
>          { initStrongsResults(); }
> 
>       QString keyText(int index) const { return srList[index].keyText(); }
>       int keyCount(int index) const { return srList[index].keyCount(); }
>       QStringList* getKeyList(int index) { return srList[index].getKeyList(); }
>       int Count() const { return srList.count(); }
> 
>    private:
>       void initStrongsResults(void);
>       QString getStrongsNumberText(const QString& verseContent, int *startIndex);
> 
>       StrongsResultList srList;
>       CSwordModuleInfo* srModule;
>       QString lemmaText;
>    };
> 
> 
> 
> class CModuleResultView : public KListView {
> 	Q_OBJECT
> public:
> 	CModuleResultView(QWidget* parent);
> 	~CModuleResultView();
> 	/**
> 	* Setups the tree using the given list of modules.
> 	*/
> 	void setupTree( ListCSwordModuleInfo modules, const QString& searchedText );
> 	/**
> 	* Returns the currently active module.
> 	*/
> 	CSwordModuleInfo* const activeModule();
> 
> protected: // Protected methods
> 	/**
> 	* Initializes this widget.
> 	*/
> 	void initView();
> 	/**
> 	* Initializes the connections of this widget
> 	*/
> 	void initConnections();
> 
>    void setupStrongsResults(CSwordModuleInfo* module, QListViewItem* parent, const QString& searchedText);
> 
> protected slots: // Protected slots
> 	/**
> 	* Is executed when an item was selected in the list.
> 	*/
> 	void executed( QListViewItem* );
> 	/**
> 	* Copies the whole search result with the text into the clipboard.
> 	*/
> 	void copyResultWithText();
> 	/**
> 	* Copies the whole search result into the clipboard.
> 	*/
> 	void copyResult();
> 	/**
> 	* This slot opens the popup menu at the given position
> 	*/
> 	void showPopup(KListView*, QListViewItem*, const QPoint&);
> 	/**
> 	* Appends the whole search result to the printer queue.
> 	*/
> 	void printResult();
> 	/**
> 	* Saves the search result with it's text.
> 	*/
> 	void saveResultWithText();
> 	/**
> 	* Saves the search result keys.
> 	*/
> 	void saveResult();
> 
> signals:
> 	void moduleSelected(CSwordModuleInfo*);
> 	void moduleChanged();
>    void strongsSelected(CSwordModuleInfo*, QStringList*);
> 
> private:
> 	struct {
> 		KActionMenu* saveMenu;
> 		struct {
> 			KAction* result;
> 			KAction* resultWithText;
> 		}
> 		save;
> 
> 		KActionMenu* printMenu;
> 		struct {
> 			KAction* result;
> 		}
> 		print;
> 
> 		KActionMenu* copyMenu;
> 		struct {
> 			KAction* result;
> 			KAction* resultWithText;
> 		}
> 		copy;
> 
> 	}
> 	m_actions;
> 	KPopupMenu* m_popup;
>    StrongsResultClass* strongsResults;
> };
> 
> class CSearchResultView  : public KListView {
> 	Q_OBJECT
> public:
> 	CSearchResultView(QWidget* parent);
> 	virtual ~CSearchResultView();
> 	/** Returns the module which is currently used. */
> 	CSwordModuleInfo* const module();
> 
> protected: // Protected methods
> 	/**
> 	* Initializes the view of this widget.
> 	*/
> 	void initView();
> 	void initConnections();
> 	virtual QDragObject* dragObject();
> 
> public slots: // Public slots
> 	void saveItems();
> 	/**
> 	* Setups the list with the given module.
> 	*/
> 	void setupTree(CSwordModuleInfo*);
>    void setupStrongsTree(CSwordModuleInfo*, QStringList*);
> 	void copyItemsWithText();
> 	void copyItems();
> 	void saveItemsWithText();
> 	/**
> 	* Reimplementation to show the popup menu.
> 	*/
> 	virtual void showPopup(KListView*, QListViewItem* i, const QPoint& point);
> 
> protected slots: // Protected slots
> 	void printItems();
> 	/**
> 	* Is connected to the signal executed, which is emitted when a mew item was chosen.
> 	*/
> 	void executed(QListViewItem*);
> 
> private:
> 	struct {
> 		KActionMenu* saveMenu;
> 		struct {
> 			KAction* result;
> 			KAction* resultWithText;
> 		}
> 		save;
> 
> 		KActionMenu* printMenu;
> 		struct {
> 			KAction* result;
> 		}
> 		print;
> 
> 		KActionMenu* copyMenu;
> 		struct {
> 			KAction* result;
> 			KAction* resultWithText;
> 		}
> 		copy;
> 	}
> 	m_actions;
> 	KPopupMenu* m_popup;
> 	CSwordModuleInfo* m_module;
> 
> signals: // Signals
> 	void keySelected(const QString&);
> };
> 
> 
> /** The page of the search dialog which contains the search result part.
>   * @author The BibleTime team
>   */
> class CSearchResultPage : public QVGroupBox  {
> 	Q_OBJECT
> public:
> 	CSearchResultPage(QWidget *parent=0, const char *name=0);
> 	~CSearchResultPage();
> 	/**
> 	* Sets the modules which contain the result of each.
> 	*/
> 	void setSearchResult(ListCSwordModuleInfo modules);
> 
> public slots: // Public slots
> 	/**
> 	* Resets the current l�st of modules and the displayed list of found entries.
> 	*/
> 	void reset();
> 
> protected: // Protected methods
> 	/**
> 	* Initializes the view of this widget.
> 	*/
> 	void initView();
> 	/**
> 	* Initializes the signal slot conections of the child widgets
> 	*/
> 	void initConnections();
> 	/**
> 	* This function highlights the searched text in the content using the search type given by search flags
> 	*/
> 	const QString highlightSearchedText(const QString& content, const QString& searchedText, const int searchFlags);
> 
> private:
> 	CModuleResultView* m_moduleListBox;
> 	CSearchResultView* m_resultListBox;
> 	CReadDisplay* m_previewDisplay;
> 	ListCSwordModuleInfo m_modules;
> 	QPushButton* m_analyseButton;
> 
> protected slots: // Protected slots
> 	/**
> 	* Update the preview of the selected key.
> 	*/
> 	void updatePreview(const QString& key);
> 	/**
> 	* Shows a dialog with the search analysis of the current search.
> 	*/
> 	void showAnalysis();
> 
> };
> 
> class CSearchOptionsPage : public QVGroupBox  {
> 	Q_OBJECT
> public:
> 	CSearchOptionsPage(QWidget *parent=0, const char *name=0);
> 	~CSearchOptionsPage();
> 	/**
> 	* Sets the search text used in the page.
> 	*/
> 	void setSearchText(const QString& text);
> 	/**
> 	* Returns the search text set in this page.
> 	*/
> 	const QString searchText();
> 	/**
> 	* Returns the list of used modules.
> 	*/
> 	const ListCSwordModuleInfo modules();
> 	/**
> 	* Return the selected search type,.
> 	*/
> 	const int searchFlags();
> 	/**
> 	* Sets all options back to the default.
> 	*/
> 	void reset();
> 	/**
> 	* Returns the selected search scope if a search scope was selected.
> 	*/
> 	sword::ListKey searchScope();
> 	/**
> 	* Returns the selected scope type.
> 	*/
> 	const CSwordModuleSearch::scopeType scopeType();
> 
> private:
> 	QLabel* m_modulesLabel;
> 	KHistoryCombo* m_searchTextCombo;
> 	QPushButton* m_chooseModulesButton;
> 	ListCSwordModuleInfo m_modules;
> 
> 	KComboBox* m_rangeChooserCombo;
> 	QPushButton* m_chooseRangeButton;
> 	
> protected: // Protected methods
> 	/**
> 	* Initializes this page.
> 	*/
> 	void initView();
> 	/**
> 	* Reads the settings of the last searchdialog session.
> 	*/
> 	void readSettings();
> 	/**
> 	* Reads the settings for the searchdialog from disk.
> 	*/
> 	void saveSettings();
> 
> public slots: // Public slots
> 	/**
> 	* Sets the modules used by the search.
> 	*/
> 	void setModules( ListCSwordModuleInfo modules );
> 	/**
> 	* Reimplementation.
> 	*/
> 	void aboutToShow();
> 	/**
> 	* Refreshes the list of ranges and the range combobox. 
> 	*/
> 	void refreshRanges();
> 	/**
> 	 * Opens the modules chooser dialog.
> 	 */
> 	void chooseModules();
> 
> protected slots: // Protected slots
> 	void setupRanges();
> 	void syntaxHelp();
> 
> signals:
> 	void sigSetSearchButtonStatus(bool);
> };
> 
> #endif
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> bt-devel mailing list
> bt-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/bt-devel


More information about the bt-devel mailing list