[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/sysadmin/ksystemlog/src
From:       Nicolas Ternisien <nicolas.ternisien () gmail ! com>
Date:       2007-09-05 22:36:49
Message-ID: 1189031809.699555.15466.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 708886 by ternisien:

Re-enabled find and find next

 M  +1 -1      CMakeLists.txt  
 M  +4 -0      detailDialog.h  
 M  +141 -90   findManager.cpp  
 M  +17 -43    findManager.h  
 M  +1 -0      lib/logViewWidgetItem.cpp  
 M  +10 -9     mainWindow.cpp  
 M  +4 -0      mainWindow.h  


--- trunk/playground/sysadmin/ksystemlog/src/CMakeLists.txt #708885:708886
@@ -28,7 +28,7 @@
 	mainWindow.cpp
 
 	loggerDialog.cpp
-#	findManager.cpp
+	findManager.cpp
 
 	detailDialog.cpp
 
--- trunk/playground/sysadmin/ksystemlog/src/detailDialog.h #708885:708886
@@ -46,6 +46,10 @@
 		
 	private:
 		void updateDetails();
+		
+		/**
+		 * Method that replaces the bugged itemAbove() and itemBelow() methods
+		 */
 		void moveToItem(int direction);
 	
 		LogViewWidget* logViewWidget;
--- trunk/playground/sysadmin/ksystemlog/src/findManager.cpp #708885:708886
@@ -22,175 +22,212 @@
 //Project includes
 #include "findManager.h"
 
+#include <kfinddialog.h>
+#include <kfind.h>
+
 #include "mainWindow.h"
+#include "logViewWidget.h"
+#include "tabLogViewsWidget.h"
+#include "view.h"
 
+#include "logging.h"
 
-FindManager::FindManager(KSystemLog* parent, const char* name) :
-	QObject(parent, name),
-	main(parent),
-	findDialog(NULL),
-	findManager(NULL),
-	previousItemFound(NULL),
-	currentItemFound(NULL) {
+#include "logViewWidgetItem.h"
+
+class FindManagerPrivate {
+public:
+	KSystemLog::MainWindow* main;
+
+	/**
+	 * A pointer to the Find dialog
+	 */
+	KFindDialog* findDialog;
+
+	/**
+	 * The manager of the current search
+	 */
+	KFind* findManager;
 	
+	//Previous object found
+	LogViewWidgetItem* previousItemFound;
+
+	//Current object found
+	LogViewWidgetItem* currentItemFound;
+
+
+};
+
+FindManager::FindManager(KSystemLog::MainWindow* parent) :
+	d(new FindManagerPrivate()) {
 	
+	d->main = parent;
+	d->findDialog = NULL;
+	d->findManager = NULL;
+	d->previousItemFound = NULL;
+	d->currentItemFound = NULL;
 }
 
 FindManager::~FindManager() {
-	if (findDialog!=NULL)
-		delete findDialog;
+	//main is managed by itself
+	
+	//previousItemFound and currentItemFound are managed by LogViewWidget
+	
+	delete d->findDialog;
 		
-	if (findManager!=NULL)
-		delete findManager;
+	delete d->findManager;
+	
+	delete d;
 }
 
-void FindManager::slotFind() {
+void FindManager::initializeFind() {
+	logDebug() << "Initializing find dialog..." << endl;
 
-	if (findManager!=NULL) {
-		delete findManager;
-		findManager=NULL;
+	//Delete the previous KFind object if it exists
+	if (d->findManager!=NULL) {
+		delete d->findManager;
+		d->findManager=NULL;
 	}
-	
-	if (findDialog==NULL) {
+
+	if (d->findDialog==NULL) {
 		logDebug() << "KFindDialog creation" << endl;
 		//TODO Save the Find options to Config file
-		findDialog=new KFindDialog(false, main, "find_dialog");
-		connect(findDialog, SIGNAL(okClicked()), this, SLOT(slotFindNext()));
-	
-		findDialog->show();
+		d->findDialog=new KFindDialog(d->main);
+		connect(d->findDialog, SIGNAL(okClicked()), this, SLOT(findNext()));
 	}
-	else {
-		findDialog->show();
 	
-		//KWindowSystem::activateWindow(findDialog->winId());
-		//return;
-	}
-
+	d->findDialog->show();
 }
 
 
-void FindManager::slotFirstFind() {
-	logDebug() << "First Find" << endl;
+void FindManager::initializeFindManager() {
+	logDebug() << "Initializing find manager..." << endl;
 	
-	LogManager* currentManager=main->activeLogManager();
-	K3ListView* list=currentManager->getView()->getLogList();
+	LogViewWidget* logViewWidget=d->main->tabs()->activeLogManager()->usedView()->logViewWidget();
  
-	//Delete the previous KFind object (if it exists)
-	if (findManager!=NULL) {
-		delete findManager;
-		findManager=NULL;
+	//Delete the previous KFind object if it exists
+	if (d->findManager!=NULL) {
+		delete d->findManager;
+		d->findManager=NULL;
 	}
 
 	//TODO Is useful?
-	if (previousItemFound!=NULL) {
-		list->setSelected(previousItemFound, false);
+	if (d->previousItemFound!=NULL) {
+		logViewWidget->setItemSelected(d->previousItemFound, false);
 	}
 	
 	//This creates a find-next-prompt dialog if needed.
-	findManager=new KFind(findDialog->pattern(), findDialog->options(), main, \
                findDialog);
-	connect(findManager, SIGNAL(highlight(const QString&, int, int)), this, \
                SLOT(highlightSearch(const QString&, int, int)));
-	connect(findManager, SIGNAL(findNext()), this, SLOT(slotFindNext()));
+	d->findManager=new KFind(d->findDialog->pattern(), d->findDialog->options(), \
d->main, d->findDialog); +	connect(d->findManager, SIGNAL(highlight(const QString&, \
int, int)), this, SLOT(highlightSearch(const QString&, int, int))); \
+	connect(d->findManager, SIGNAL(findNext()), this, SLOT(findNext()));  
 	//Do not keep the KFindDialog open
-	findDialog->hide();
+	d->findDialog->hide();
 	
+	//d->findManager->closeFindNextDialog();
 	
-	//findManager->closeFindNextDialog();
+	int currentPosition=-1;
 	
-	QListViewItemIterator it(list, QListViewItemIterator::Selected);
-	int itemPos=-1;
-	int currentPos;
-	while (it.current()) {
-		list->setSelected(it.current(), false);
+	QTreeWidgetItemIterator it(logViewWidget, QTreeWidgetItemIterator::Selected);
+	while ( *it != NULL) {
+		LogViewWidgetItem* item=static_cast<LogViewWidgetItem*> (*it);
 		
-		currentPos=list->itemPos(it.current());
-		if (currentPos>=itemPos) {
-			itemPos=currentPos;
-			previousItemFound=static_cast<LogViewWidgetItem*> (it.current());
+		logViewWidget->setItemSelected(item, false);
+		
+		int itemPosition=logViewWidget->indexOfTopLevelItem(item);
+		if (currentPosition>=itemPosition) {
+			currentPosition=itemPosition;
+			d->previousItemFound=item;
 		}
 		
 		++it;
 	}
+	
 	//Unselect all previous items (the last one if always selected)
-	if (previousItemFound!=NULL)
-		list->setSelected(previousItemFound, true);
+	if (d->previousItemFound!=NULL) {
+		logViewWidget->setItemSelected(d->previousItemFound, true);
+	}
 	
 	
 	
 	//If we search from the cursor, the iterator goes to the first selected item
-	if (findDialog->options() & KFind::FromCursor) {
-		currentItemFound=currentManager->getView()->firstSelectedItem();
+	if (d->findDialog->options() & KFind::FromCursor) {
+		d->currentItemFound=logViewWidget->firstSelectedItem();
 		
 		//If nothing is selected, then we initialize the iterator classicaly
-		if (currentItemFound==NULL) {
-			currentItemFound=static_cast<LogViewWidgetItem*> (list->firstChild());
+		if (d->currentItemFound==NULL) {
+			d->currentItemFound=static_cast<LogViewWidgetItem*> \
(logViewWidget->topLevelItem(0));  }
 		
-		previousItemFound=currentItemFound;
+		d->previousItemFound=d->currentItemFound;
 	}
 	//If we search from the last, the iterator is initialized to the last item
-	else if (findDialog->options() & KFind::FindBackwards) {
-		currentItemFound=static_cast<LogViewWidgetItem*> (list->lastItem());
+	else if (d->findDialog->options() & KFind::FindBackwards) {
+		d->currentItemFound=static_cast<LogViewWidgetItem*> \
(logViewWidget->topLevelItem(logViewWidget->topLevelItemCount() - 1));  }
 	//Default initialization
 	else {
-		currentItemFound=static_cast<LogViewWidgetItem*> (list->firstChild());
+		d->currentItemFound=static_cast<LogViewWidgetItem*> \
(logViewWidget->topLevelItem(0));  }
 	
+	logDebug() << "Find manager initialized" << endl;
 }
 
-void FindManager::slotFindNext() {
-	//If we attempt to go to the next search, without have opened the find dialog, we \
                open it
-	if (findDialog==NULL) {
-		slotFind();
+void FindManager::findNext() {
+	logDebug() << "Finding next something..." << endl;
+	
+	//If the dialog has not been initialized, we show it and wait for a search \
launching +	if (d->findDialog==NULL) {
+		initializeFind();
 		return;
 	}
 	
 	//If the KFind object has not been initialized, we call the right method for that
-	if (findManager==NULL) {
-		slotFirstFind();
+	if (d->findManager==NULL) {
+		initializeFindManager();
 	}
 
-	
 	//Keep the Find Dialog opened
 	/*
-	if (findManager->options() != findDialog->options() || \
findManager->pattern()!=findDialog->pattern()) { +	if (d->findManager->options() != \
d->findDialog->options() || d->findManager->pattern()!=d->findDialog->pattern()) {  \
logDebug() << "Reinitialize the search..." << endl;  slotFirstFind();
 	}
 	*/
 
+	LogViewWidget* logViewWidget=d->main->tabs()->activeLogManager()->usedView()->logViewWidget();
  
 	KFind::Result res = KFind::NoMatch;
-	while (res==KFind::NoMatch && currentItemFound!=NULL) {
+	while (res==KFind::NoMatch && d->currentItemFound!=NULL) {
 
 		//Always need new data, because a line is only selected one time
-		//if (findManager->needData())
-			findManager->setData(currentItemFound->exportToText());
+		//if (d->findManager->needData())
+			d->findManager->setData(d->currentItemFound->logLine()->exportToText());
 
 		//Let KFind inspect the text fragment, and display a dialog if a match is found
-		res=findManager->find();
+		res=d->findManager->find();
 
 		//Always need new data, because a line is only selected one time
 		//if (res==KFind::NoMatch ) {
-			if (findDialog->options() & KFind::FindBackwards)
-				currentItemFound=static_cast<LogViewWidgetItem*> \
(currentItemFound->itemAbove()); +			if (d->findDialog->options() & \
KFind::FindBackwards) +				d->currentItemFound=static_cast<LogViewWidgetItem*>( \
findNextItem(logViewWidget, d->currentItemFound, +1) );  else
-				currentItemFound=static_cast<LogViewWidgetItem*> \
(currentItemFound->itemBelow()); \
+				d->currentItemFound=static_cast<LogViewWidgetItem*>( findNextItem(logViewWidget, \
d->currentItemFound, -1) );  //}
 	}
 
 
 	//End of the view
 	if (res==KFind::NoMatch) {
-		if (findManager->shouldRestart()) {
-			delete findManager;
-			findManager=NULL;
-			findDialog->setOptions(findDialog->options() & !KFind::FromCursor);
-			slotFindNext();
+		if (d->findManager->shouldRestart()) {
+			delete d->findManager;
+			d->findManager=NULL;
+			
+			d->findDialog->setOptions(d->findDialog->options() & !KFind::FromCursor);
+			
+			findNext();
 		}
 		else {
-			findManager->closeFindNextDialog();
+			d->findManager->closeFindNextDialog();
 		}
 	}
 
@@ -198,20 +235,34 @@
 
 
 void FindManager::highlightSearch(const QString& /*text*/, int /*matchingIndex*/, \
                int /*matchingLength*/) {
-	LogManager* currentManager=main->activeLogManager();
-	K3ListView* list=currentManager->getView()->getLogList();
+	logDebug() << "Highlighting something" << endl;
+	
+	LogViewWidget* logViewWidget=d->main->tabs()->activeLogManager()->usedView()->logViewWidget();
  
-	if (previousItemFound!=NULL) {
-		list->setSelected(previousItemFound, false);
+	if (d->previousItemFound!=NULL) {
+		logViewWidget->setItemSelected(d->previousItemFound, false);
 	}
 	
-	if (currentItemFound!=NULL) {
-		list->setSelected(currentItemFound, true);
-		list->scrollToItem(currentItemFound);
-		previousItemFound=currentItemFound;
+	if (d->currentItemFound!=NULL) {
+		logViewWidget->setItemSelected(d->currentItemFound, true);
+		logViewWidget->scrollToItem(d->currentItemFound);
+		d->previousItemFound=d->currentItemFound;
 	}
 
 }
 
+LogViewWidgetItem* FindManager::findNextItem(LogViewWidget* logViewWidget, \
LogViewWidgetItem* item, int direction) { +	if (direction < 0)
+		logDebug() << "Go to previous item..." << endl;
+	else
+		logDebug() << "Go to next item..." << endl;
+	
+	QTreeWidgetItem* destinationItem = logViewWidget->topLevelItem( \
logViewWidget->indexOfTopLevelItem(item) + direction ); +	if (destinationItem == \
NULL) { +		logDebug() << "Next or previous item is NULL" << endl;
+	}
+	
+	return static_cast<LogViewWidgetItem*>( destinationItem );
+}
 
 #include "findManager.moc"
--- trunk/playground/sysadmin/ksystemlog/src/findManager.h #708885:708886
@@ -19,72 +19,46 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
  ***************************************************************************/
 
-#ifndef FIND_MANAGER_H
-#define FIND_MANAGER_H
+#ifndef _FIND_MANAGER_H_
+#define _FIND_MANAGER_H_
 
-//Qt includes
-#include <qobject.h>
+#include <QObject>
 
-//KDE includes
-#include <kfinddialog.h>
-#include <kfind.h>
-#include <kdeversion.h>
-#include <kvbox.h>
-
 //Project includes
 #include "logManager.h"
 #include "globals.h"
 
-class KSystemLog;
+namespace KSystemLog {
+	class MainWindow;
+}
 
-/**
- *
- * @short Find Manager
- * @author Nicolas Ternisien <nicolas.ternisien@gmail.com>
- * @version 0.1
- */
+class FindManagerPrivate;
+
 class FindManager : public QObject {
 
 	Q_OBJECT
 	
 	public:
-		/**
-		* Default Constructor
-		*/
-		FindManager(KSystemLog* parent, const char* name);
+		FindManager(KSystemLog::MainWindow* parent);
 		
 		virtual ~FindManager();
 	
 	public slots:
-		void slotFind();
-		void slotFindNext();
-		void slotFirstFind();
+		void findNext();
+		void initializeFind();
 
+	private slots:
 		void highlightSearch(const QString& text, int matchingIndex, int matchingLength);
 
 	private:
-	
-		KSystemLog* main;
+		void initializeFindManager();
 
 		/**
-		 * A pointer to the Find dialog
+		 * Method that replaces the bugged itemAbove() and itemBelow() methods
 		 */
-		KFindDialog* findDialog;
-
-		/**
-		 * The manager of the current search
-		 */
-		KFind* findManager;
+		LogViewWidgetItem* findNextItem(LogViewWidget* logViewWidget, LogViewWidgetItem* \
item, int direction);  
-		//TODO Need a rewritting
-		/*
-		//Previous object found
-		LogListItem* previousItemFound;
-
-		//Current object found
-		LogListItem* currentItemFound;
-		*/
+		FindManagerPrivate* const d;
 };
 
-#endif
-
+#endif // _FIND_MANAGER_H_
--- trunk/playground/sysadmin/ksystemlog/src/lib/logViewWidgetItem.cpp #708885:708886
@@ -41,6 +41,7 @@
 
 #include "logModeItemBuilder.h"
 #include "logViewWidget.h"
+#include "logViewWidgetItem.h"
 
 #include "logMode.h"
 #include "ksystemlogConfig.h"
--- trunk/playground/sysadmin/ksystemlog/src/mainWindow.cpp #708885:708886
@@ -87,6 +87,8 @@
 
 #include "view.h"
 
+#include "findManager.h"
+
 #include "globals.h"
 
 #include "logModeFactory.h"
@@ -145,8 +147,7 @@
 	/**
 	 * Find Manager
 	 */
-	//TODO Need a rewritting
-	//FindManager* findManager;
+	FindManager* findManager;
 	
 	/**
 	 * Tab widget managing different views
@@ -184,8 +185,7 @@
 	setupTabLogViews();
 		
 	//Initialize the find manager
-	//TODO Need a rewritting
-	//findManager=new FindManager(this, "find_manager");
+	d->findManager=new FindManager(this);
 	
 	//Setup the Actions
 	setupActions();
@@ -386,6 +386,10 @@
 	return true;
 }
 
+TabLogViewsWidget* MainWindow::tabs() {
+	return d->tabs;
+}
+
 void MainWindow::showDetailsDialog() {
 	//Create the Detail dialog if it was not created
 	if (d->detailDialog==NULL) {
@@ -610,11 +614,8 @@
 	d->selectAllAction->setToolTip(i18n("Select all lines of the current log"));
 	d->selectAllAction->setWhatsThis(i18n("Selects all lines of the current log. This \
action is useful if you want, for example, to save all the content of the current log \
in a file."));  
-	//TODO Need a rewritting
-	/*
-	KStandardAction::find(findManager, SLOT(slotFind()), actionCollection());
-	KStandardAction::findNext(findManager, SLOT(slotFindNext()), actionCollection());
-	*/
+	actionCollection()->addAction(KStandardAction::Find, d->findManager, \
SLOT(initializeFind())); +	actionCollection()->addAction(KStandardAction::FindNext, \
d->findManager, SLOT(findNext()));  
 	actionCollection()->addAction(KStandardAction::Preferences, this, \
SLOT(showConfigurationDialog()));  
--- trunk/playground/sysadmin/ksystemlog/src/mainWindow.h #708885:708886
@@ -53,6 +53,8 @@
 
 class View;
 
+class TabLogViewsWidget;
+
 namespace KSystemLog {
 
 class MainWindowPrivate;
@@ -75,6 +77,8 @@
 		 * Default Destructor
 		 */
 		virtual ~MainWindow();
+		
+		TabLogViewsWidget* tabs();
 
 	protected:
 		/**


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic