Warning, file /utilities/konsole/src/SearchHistoryTask.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2006-2008 Robert Knight <robertknight@gmail.com>
0003     SPDX-FileCopyrightText: 2009 Thomas Dreibholz <dreibh@iem.uni-due.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SEARCHHISTORYTASK_H
0009 #define SEARCHHISTORYTASK_H
0010 
0011 #include <QMap>
0012 #include <QPointer>
0013 #include <QRegularExpression>
0014 
0015 #include "Enumeration.h"
0016 #include "ScreenWindow.h"
0017 #include "konsoleprivate_export.h"
0018 #include "session/Session.h"
0019 #include "session/SessionTask.h"
0020 
0021 namespace Konsole
0022 {
0023 // class SearchHistoryThread;
0024 /**
0025  * A task which searches through the output of sessions for matches for a given regular expression.
0026  * SearchHistoryTask operates on ScreenWindow instances rather than sessions added by addSession().
0027  * A screen window can be added to the list to search using addScreenWindow()
0028  *
0029  * When execute() is called, the search begins in the direction specified by searchDirection(),
0030  * starting at the position of the current selection.
0031  *
0032  * FIXME - This is not a proper implementation of SessionTask, in that it ignores sessions specified
0033  * with addSession()
0034  *
0035  * TODO - Implementation requirements:
0036  *          May provide progress feedback to the user when searching very large output logs.
0037  */
0038 class KONSOLEPRIVATE_EXPORT SearchHistoryTask : public SessionTask
0039 {
0040     Q_OBJECT
0041 
0042 public:
0043     /**
0044      * Constructs a new search task.
0045      */
0046     explicit SearchHistoryTask(QObject *parent = nullptr);
0047 
0048     /** Adds a screen window to the list to search when execute() is called. */
0049     void addScreenWindow(Session *session, ScreenWindow *searchWindow);
0050 
0051     /** Sets the regular expression which is searched for when execute() is called */
0052     void setRegExp(const QRegularExpression &expression);
0053     /** Returns the regular expression which is searched for when execute() is called */
0054     QRegularExpression regExp() const;
0055 
0056     /** Specifies the direction to search in when execute() is called. */
0057     void setSearchDirection(Enum::SearchDirection direction);
0058     /** Returns the current search direction.  See setSearchDirection(). */
0059     Enum::SearchDirection searchDirection() const;
0060 
0061     /** The line from which the search will be done **/
0062     void setStartLine(int line);
0063 
0064     /**
0065      * Performs a search through the session's history, starting at the position
0066      * of the current selection, in the direction specified by setSearchDirection().
0067      *
0068      * If it finds a match, the ScreenWindow specified in the constructor is
0069      * scrolled to the position where the match occurred and the selection
0070      * is set to the matching text.  execute() then returns immediately.
0071      *
0072      * To continue the search looking for further matches, call execute() again.
0073      */
0074     void execute() override;
0075 
0076 private:
0077     using ScreenWindowPtr = QPointer<ScreenWindow>;
0078 
0079     void executeOnScreenWindow(const QPointer<Session> &session, const ScreenWindowPtr &window);
0080     void highlightResult(const ScreenWindowPtr &window, int findPos);
0081 
0082     QMap<QPointer<Session>, ScreenWindowPtr> _windows;
0083     QRegularExpression _regExp;
0084     Enum::SearchDirection _direction;
0085     int _startLine;
0086 };
0087 
0088 }
0089 #endif