Commit 1f07a075 authored by Robert Knight's avatar Robert Knight

Make URL highlighting work again. Watch for mouse events on the view and...

Make URL highlighting work again.  Watch for mouse events on the view and process URL filters as necessary.  Adapt filters to recognise email addresses as well.

svn path=/branches/work/konsole-split-view/; revision=658409
parent 63d3cdcd
......@@ -360,7 +360,12 @@ QString UrlFilter::HotSpot::tooltip() const
{
QString url = capturedTexts().first();
return i18n("Click to open '%1' in your browser.",url);
if ( QRegExp(FullUrlRegExp).exactMatch(url) )
return i18n("Click to open '%1' in your browser.",url);
else if ( QRegExp(EmailAddressRegExp).exactMatch(url) )
return i18n("Click to send an email to '%1'.",url);
else
return QString::null;
}
void UrlFilter::HotSpot::activate()
{
......@@ -379,11 +384,21 @@ void UrlFilter::HotSpot::activate()
new KRun(url,QApplication::activeWindow());
}
}
//regexp matches:
// full url:
// protocolname:// or www. followed by numbers, letters dots and dashes
const QString UrlFilter::FullUrlRegExp("([a-z]+://|www\\.)[a-zA-Z0-9\\-\\./]+");
// email address:
// [word chars, dots or dashes]@[word chars, dots or dashes].[word chars]
const QString UrlFilter::EmailAddressRegExp("(\\w|\\.|-)+@(\\w|\\.|-)+\\.\\w+");
UrlFilter::UrlFilter()
{
//regexp matches:
// protocolname:// or www. followed by numbers, letters dots and dashes
setRegExp(QRegExp("([a-z]+://|www\\.)[a-zA-Z0-9\\-\\./]+"));
//FIXME - There is a bug where URLs are not identified if they occur at the very
//end of the output ( the last characters before any trailing whitespace )
setRegExp( QRegExp('('+FullUrlRegExp+'|'+EmailAddressRegExp+')') );
}
UrlFilter::HotSpot::~HotSpot()
{
......
......@@ -246,6 +246,10 @@ public:
protected:
virtual RegExpFilter::HotSpot* newHotSpot(int,int,int,int);
private:
static const QString FullUrlRegExp;
static const QString EmailAddressRegExp;
};
class FilterObject : public QObject
......
......@@ -47,6 +47,7 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
, _viewUrlFilter(0)
, _searchFilter(0)
, _searchToggleAction(0)
, _urlFilterUpdateRequired(false)
{
// handle user interface related to session (menus etc.)
setXMLFile("konsole/sessionui.rc");
......@@ -55,7 +56,7 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
setIdentifier(_session->sessionId());
sessionTitleChanged();
view->installEventFilter(this);
view->installEventFilter(this);
// listen for popup menu requests
connect( _view , SIGNAL(configureRequest(TerminalDisplay*,int,int,int)) , this,
......@@ -68,9 +69,6 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
// listen to title and icon changes
connect( _session , SIGNAL(updateTitle()) , this , SLOT(sessionTitleChanged()) );
// install filter on the view to highlight URLs
view->filterChain()->addFilter( new UrlFilter() );
// take a snapshot of the session state every so often when
// user activity occurs
QTimer* activityTimer = new QTimer(this);
......@@ -83,7 +81,13 @@ SessionController::SessionController(Session* session , TerminalDisplay* view, Q
SessionController::~SessionController()
{
}
void SessionController::requireUrlFilterUpdate()
{
// this method is called every time the screen window's output changes, so do not
// do anything expensive here.
_urlFilterUpdateRequired = true;
}
void SessionController::snapshot()
{
qDebug() << "session" << _session->title() << "snapshot";
......@@ -218,6 +222,29 @@ bool SessionController::eventFilter(QObject* watched , QEvent* event)
connect( _session , SIGNAL(bellRequest(const QString&)) ,
_view , SLOT(bell(const QString&)) );
}
// when a mouse move is received, create the URL filter and listen for output changes if
// it has not already been created. If it already exists, then update only if the output
// has changed since the last update ( _urlFilterUpdateRequired == true )
if ( event->type() == QEvent::MouseMove &&
(!_viewUrlFilter || _urlFilterUpdateRequired) )
{
if ( _view->screenWindow() && !_viewUrlFilter )
{
qDebug() << __FUNCTION__ << "Creating url filter";
connect( _view->screenWindow() , SIGNAL(outputChanged()) , this ,
SLOT(requireUrlFilterUpdate()) );
// install filter on the view to highlight URLs
_viewUrlFilter = new UrlFilter();
_view->filterChain()->addFilter( _viewUrlFilter );
}
qDebug() << __FUNCTION__ << "Updating url filter.";
_view->processFilters();
_urlFilterUpdateRequired = false;
}
}
return false;
......
......@@ -144,6 +144,8 @@ private slots:
// to take a snapshot of the state of the
// foreground process in the terminal
void requireUrlFilterUpdate();
// debugging slots
void debugProcess();
......@@ -171,6 +173,8 @@ private:
static KIcon _activityIcon;
static KIcon _silenceIcon;
bool _urlFilterUpdateRequired;
QPointer<IncrementalSearchBar> _searchBar;
};
......
......@@ -139,6 +139,14 @@ public:
/**
* Updates the filters in the display's filter chain. This will cause
* the hotspots to be updated to match the current image.
*
* The cost of this operation depends on the number of characters
* on screen and the number of filters in the filterChain(),
* it is potentially expensive so should only be called:
*
* 1) When filters are added, removed or changed
* 2) When the displayed image has changed and the user
* wants to see the updated filters.
*/
void processFilters();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment