2
// C++ Implementation: findManager
7
// Author: Nicolas Ternisien <nicolas.ternisien@gmail.com>, (C) 2005
9
// Copyright: See COPYING file that comes with this distribution
14
#include "findManager.h"
16
#include "ksystemlog.h"
19
FindManager::FindManager(KSystemLog* parent, const char* name) :
20
QObject(parent, name),
24
previousItemFound(NULL),
25
currentItemFound(NULL) {
30
FindManager::~FindManager() {
34
if (findManager!=NULL)
38
void FindManager::slotFind() {
40
if (findManager!=NULL) {
45
if (findDialog==NULL) {
46
kdDebug() << "KFindDialog creation" << endl;
47
//TODO Save the Find options to Config file
48
findDialog=new KFindDialog(false, main, "find_dialog");
49
connect(findDialog, SIGNAL(okClicked()), this, SLOT(slotFindNext()));
56
//KWin::activateWindow(findDialog->winId());
63
void FindManager::slotFirstFind() {
64
kdDebug() << "First Find" << endl;
66
LogManager* currentManager=main->activeLogManager();
67
KListView* list=currentManager->getView()->getLogList();
69
//Delete the previous KFind object (if it exists)
70
if (findManager!=NULL) {
76
if (previousItemFound!=NULL) {
77
list->setSelected(previousItemFound, false);
80
//This creates a find-next-prompt dialog if needed.
81
findManager=new KFind(findDialog->pattern(), findDialog->options(), main, findDialog);
82
connect(findManager, SIGNAL(highlight(const QString&, int, int)), this, SLOT(highlightSearch(const QString&, int, int)));
83
connect(findManager, SIGNAL(findNext()), this, SLOT(slotFindNext()));
85
//Do not keep the KFindDialog open
89
//findManager->closeFindNextDialog();
91
QListViewItemIterator it(list, QListViewItemIterator::Selected);
94
while (it.current()) {
95
list->setSelected(it.current(), false);
97
currentPos=list->itemPos(it.current());
98
if (currentPos>=itemPos) {
100
previousItemFound=static_cast<LogListItem*> (it.current());
105
//Unselect all previous items (the last one if always selected)
106
if (previousItemFound!=NULL)
107
list->setSelected(previousItemFound, true);
111
//If we search from the cursor, the iterator goes to the first selected item
112
if (findDialog->options() & KFindDialog::FromCursor) {
113
currentItemFound=currentManager->getView()->getFirstSelectedItem();
115
//If nothing is selected, then we initialize the iterator classicaly
116
if (currentItemFound==NULL) {
117
currentItemFound=static_cast<LogListItem*> (list->firstChild());
120
previousItemFound=currentItemFound;
122
//If we search from the last, the iterator is initialized to the last item
123
else if (findDialog->options() & KFindDialog::FindBackwards) {
124
currentItemFound=static_cast<LogListItem*> (list->lastItem());
126
//Default initialization
128
currentItemFound=static_cast<LogListItem*> (list->firstChild());
133
void FindManager::slotFindNext() {
134
//If we attempt to go to the next search, without have opened the find dialog, we open it
135
if (findDialog==NULL) {
140
//If the KFind object has not been initialized, we call the right method for that
141
if (findManager==NULL) {
146
//Keep the Find Dialog opened
148
if (findManager->options() != findDialog->options() || findManager->pattern()!=findDialog->pattern()) {
149
kdDebug() << "Reinitialize the search..." << endl;
155
KFind::Result res = KFind::NoMatch;
156
while (res==KFind::NoMatch && currentItemFound!=NULL) {
158
//Always need new data, because a line is only selected one time
159
//if (findManager->needData())
160
findManager->setData(currentItemFound->exportToText());
162
//Let KFind inspect the text fragment, and display a dialog if a match is found
163
res=findManager->find();
165
//Always need new data, because a line is only selected one time
166
//if (res==KFind::NoMatch ) {
167
if (findDialog->options() & KFindDialog::FindBackwards)
168
currentItemFound=static_cast<LogListItem*> (currentItemFound->itemAbove());
170
currentItemFound=static_cast<LogListItem*> (currentItemFound->itemBelow());
176
if (res==KFind::NoMatch) {
177
if (findManager->shouldRestart()) {
180
findDialog->setOptions(findDialog->options() & !KFindDialog::FromCursor);
184
findManager->closeFindNextDialog();
191
void FindManager::highlightSearch(const QString& /*text*/, int /*matchingIndex*/, int /*matchingLength*/) {
192
LogManager* currentManager=main->activeLogManager();
193
KListView* list=currentManager->getView()->getLogList();
195
if (previousItemFound!=NULL) {
196
list->setSelected(previousItemFound, false);
199
if (currentItemFound!=NULL) {
200
list->setSelected(currentItemFound, true);
201
list->ensureItemVisible(currentItemFound);
202
previousItemFound=currentItemFound;
208
#include "findManager.moc"