Move the messagebox about continuing search from core to ui

This commit is contained in:
Albert Astals Cid 2014-05-10 11:33:21 +02:00
parent e759c94224
commit 7b7fef0bea
6 changed files with 32 additions and 24 deletions

View file

@ -168,7 +168,7 @@ void DocumentItem::searchText(const QString &text)
m_document->cancelSearch(); m_document->cancelSearch();
m_document->resetSearch(PAGEVIEW_SEARCH_ID); m_document->resetSearch(PAGEVIEW_SEARCH_ID);
m_document->searchText(PAGEVIEW_SEARCH_ID, text, 1, Qt::CaseInsensitive, m_document->searchText(PAGEVIEW_SEARCH_ID, text, 1, Qt::CaseInsensitive,
Okular::Document::AllDocument, true, QColor(100,100,200,40), true); Okular::Document::AllDocument, true, QColor(100,100,200,40));
if (!m_searchInProgress) { if (!m_searchInProgress) {
m_searchInProgress = true; m_searchInProgress = true;

View file

@ -124,9 +124,9 @@ struct RunningSearch
Document::SearchType cachedType; Document::SearchType cachedType;
Qt::CaseSensitivity cachedCaseSensitivity; Qt::CaseSensitivity cachedCaseSensitivity;
bool cachedViewportMove : 1; bool cachedViewportMove : 1;
bool cachedNoDialogs : 1;
bool isCurrentlySearching : 1; bool isCurrentlySearching : 1;
QColor cachedColor; QColor cachedColor;
int pagesDone;
}; };
#define foreachObserver( cmd ) {\ #define foreachObserver( cmd ) {\
@ -1656,16 +1656,16 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa
if ( !searchStruct->match ) if ( !searchStruct->match )
{ {
const int pageCount = m_pagesVector.count(); const int pageCount = m_pagesVector.count();
if (searchStruct->pagesDone < pageCount) if (search->pagesDone < pageCount)
{ {
doContinue = true; doContinue = true;
if ( searchStruct->currentPage >= pageCount || searchStruct->currentPage < 0 ) if ( searchStruct->currentPage >= pageCount || searchStruct->currentPage < 0 )
{ {
const QString question = forward ? i18n("End of document reached.\nContinue from the beginning?") : i18n("Beginning of document reached.\nContinue from the bottom?"); doContinue = false;
if ( search->cachedNoDialogs || KMessageBox::questionYesNo(m_widget, question, QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::Yes ) search->isCurrentlySearching = false;
searchStruct->currentPage = forward ? 0 : pageCount - 1; search->continueOnPage = forward ? 0 : pageCount - 1;
else search->continueOnMatch = RegularAreaRect();
doContinue = false; emit m_parent->searchFinished ( searchStruct->searchID, Document::EndOfDocumentReached );
} }
} }
} }
@ -1684,11 +1684,11 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa
{ {
if (forward) searchStruct->currentPage++; if (forward) searchStruct->currentPage++;
else searchStruct->currentPage--; else searchStruct->currentPage--;
searchStruct->pagesDone++; search->pagesDone++;
} }
else else
{ {
searchStruct->pagesDone = 1; search->pagesDone = 1;
} }
// Both of the previous if branches need to call doContinueDirectionMatchSearch // Both of the previous if branches need to call doContinueDirectionMatchSearch
@ -3276,7 +3276,7 @@ void Document::setNextDocumentDestination( const QString &namedDestination )
} }
void Document::searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, void Document::searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity,
SearchType type, bool moveViewport, const QColor & color, bool noDialogs ) SearchType type, bool moveViewport, const QColor & color )
{ {
d->m_searchCancelled = false; d->m_searchCancelled = false;
@ -3303,7 +3303,6 @@ void Document::searchText( int searchID, const QString & text, bool fromStart, Q
s->cachedType = type; s->cachedType = type;
s->cachedCaseSensitivity = caseSensitivity; s->cachedCaseSensitivity = caseSensitivity;
s->cachedViewportMove = moveViewport; s->cachedViewportMove = moveViewport;
s->cachedNoDialogs = noDialogs;
s->cachedColor = color; s->cachedColor = color;
s->isCurrentlySearching = true; s->isCurrentlySearching = true;
@ -3355,12 +3354,13 @@ void Document::searchText( int searchID, const QString & text, bool fromStart, Q
} }
} }
s->pagesDone = pagesDone;
DoContinueDirectionMatchSearchStruct *searchStruct = new DoContinueDirectionMatchSearchStruct(); DoContinueDirectionMatchSearchStruct *searchStruct = new DoContinueDirectionMatchSearchStruct();
searchStruct->pagesToNotify = pagesToNotify; searchStruct->pagesToNotify = pagesToNotify;
searchStruct->match = match; searchStruct->match = match;
searchStruct->currentPage = currentPage; searchStruct->currentPage = currentPage;
searchStruct->searchID = searchID; searchStruct->searchID = searchID;
searchStruct->pagesDone = pagesDone;
QMetaObject::invokeMethod(this, "doContinueDirectionMatchSearch", Qt::QueuedConnection, Q_ARG(void *, searchStruct)); QMetaObject::invokeMethod(this, "doContinueDirectionMatchSearch", Qt::QueuedConnection, Q_ARG(void *, searchStruct));
} }
@ -3389,8 +3389,7 @@ void Document::continueSearch( int searchID )
RunningSearch * p = *it; RunningSearch * p = *it;
if ( !p->isCurrentlySearching ) if ( !p->isCurrentlySearching )
searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity,
p->cachedType, p->cachedViewportMove, p->cachedColor, p->cachedType, p->cachedViewportMove, p->cachedColor );
p->cachedNoDialogs );
} }
void Document::continueSearch( int searchID, SearchType type ) void Document::continueSearch( int searchID, SearchType type )
@ -3407,8 +3406,7 @@ void Document::continueSearch( int searchID, SearchType type )
RunningSearch * p = *it; RunningSearch * p = *it;
if ( !p->isCurrentlySearching ) if ( !p->isCurrentlySearching )
searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity,
type, p->cachedViewportMove, p->cachedColor, type, p->cachedViewportMove, p->cachedColor );
p->cachedNoDialogs );
} }
void Document::resetSearch( int searchID ) void Document::resetSearch( int searchID )

View file

@ -487,9 +487,10 @@ class OKULAR_EXPORT Document : public QObject
*/ */
enum SearchStatus enum SearchStatus
{ {
MatchFound, ///< Any match was found MatchFound, ///< Any match was found
NoMatchFound, ///< No match was found NoMatchFound, ///< No match was found
SearchCancelled ///< The search was cancelled SearchCancelled, ///< The search was cancelled
EndOfDocumentReached ///< The end of document was reached without any match @since 0.20 (KDE 4.14)
}; };
/** /**
@ -501,10 +502,9 @@ class OKULAR_EXPORT Document : public QObject
* @param type The type of the search. @ref SearchType * @param type The type of the search. @ref SearchType
* @param moveViewport Whether the viewport shall be moved to the position of the matches. * @param moveViewport Whether the viewport shall be moved to the position of the matches.
* @param color The highlighting color of the matches. * @param color The highlighting color of the matches.
* @param noDialogs Whether a search dialog shall be shown.
*/ */
void searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, void searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity,
SearchType type, bool moveViewport, const QColor & color, bool noDialogs = false ); SearchType type, bool moveViewport, const QColor & color );
/** /**
* Continues the search for the given @p searchID. * Continues the search for the given @p searchID.

View file

@ -71,7 +71,6 @@ struct DoContinueDirectionMatchSearchStruct
RegularAreaRect *match; RegularAreaRect *match;
int currentPage; int currentPage;
int searchID; int searchID;
int pagesDone;
}; };
class DocumentPrivate class DocumentPrivate

View file

@ -177,7 +177,7 @@ void SearchTest::test311232()
d.openDocument(testFile, KUrl(), mime); d.openDocument(testFile, KUrl(), mime);
const int searchId = 0; const int searchId = 0;
d.searchText(searchId, " i ", true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor(), true); d.searchText(searchId, " i ", true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor());
QTime t; QTime t;
t.start(); t.start();
while (spy.count() != 1 && t.elapsed() < 500) while (spy.count() != 1 && t.elapsed() < 500)

View file

@ -20,6 +20,8 @@
#include <kcolorscheme.h> #include <kcolorscheme.h>
#include <kpixmapsequence.h> #include <kpixmapsequence.h>
#include <kpixmapsequencewidget.h> #include <kpixmapsequencewidget.h>
#include <kmessagebox.h>
#include <klocalizedstring.h>
SearchLineEdit::SearchLineEdit( QWidget * parent, Okular::Document * document ) SearchLineEdit::SearchLineEdit( QWidget * parent, Okular::Document * document )
: KLineEdit( parent ), m_document( document ), m_minLength( 0 ), : KLineEdit( parent ), m_document( document ), m_minLength( 0 ),
@ -250,6 +252,15 @@ void SearchLineEdit::searchFinished( int id, Okular::Document::SearchStatus endS
setPalette( pal ); setPalette( pal );
} }
if ( endStatus == Okular::Document::EndOfDocumentReached ) {
const bool forward = m_searchType == Okular::Document::NextMatch;
const QString question = forward ? i18n("End of document reached.\nContinue from the beginning?") : i18n("Beginning of document reached.\nContinue from the bottom?");
if ( KMessageBox::questionYesNo(window(), question, QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::Yes ) {
m_document->continueSearch( m_id, m_searchType );
return;
}
}
m_searchRunning = false; m_searchRunning = false;
emit searchStopped(); emit searchStopped();
} }