[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE_3_2_BRANCH: kdebase/khelpcenter
From: Waldo Bastian <bastian () kde ! org>
Date: 2004-04-13 21:16:44
Message-ID: 20040413211644.3438B9A2B () office ! kde ! org
[Download RAW message or body]
CVS commit by waba:
* Fixed crash when "Next Page" fails to find a proper link.
(Partial backport of r1.24)
M +48 -27 view.cpp 1.21.2.1
M +2 -0 view.h 1.14.2.1
--- kdebase/khelpcenter/view.cpp #1.21:1.21.2.1
@@ -220,28 +220,21 @@ void View::slotDecFontSizes()
}
-bool View::eventFilter( QObject *o, QEvent *e )
+bool View::prevPage(bool checkOnly)
{
- if ( e->type() != QEvent::KeyPress ||
- htmlDocument().links().length() == 0 )
- return KHTMLPart::eventFilter( o, e );
-
- QKeyEvent *ke = static_cast<QKeyEvent *>( e );
- if ( ke->state() & Qt::ShiftButton && ke->key() == Key_Space ) {
- // If we're on the first page, it does not make sense to go back.
- if ( baseURL().path().endsWith( "/index.html" ) )
- return KHTMLPart::eventFilter( o, e );
-
- const QScrollBar * const scrollBar = view()->verticalScrollBar();
- if ( scrollBar->value() == scrollBar->minValue() ) {
const DOM::HTMLCollection links = htmlDocument().links();
// The first link on a page (top-left corner) would be the Prev link.
const DOM::Node prevLinkNode = links.item( 0 );
- openURL( urlFromLinkNode( prevLinkNode ) );
+ KURL prevURL = urlFromLinkNode( prevLinkNode );
+ if (!prevURL.isValid())
+ return false;
+
+ if (!checkOnly)
+ openURL( prevURL );
return true;
- }
- } else if ( ke->key() == Key_Space ) {
- const QScrollBar * const scrollBar = view()->verticalScrollBar();
- if ( scrollBar->value() == scrollBar->maxValue() ) {
+}
+
+bool View::nextPage(bool checkOnly)
+{
const DOM::HTMLCollection links = htmlDocument().links();
@@ -254,4 +247,7 @@ bool View::eventFilter( QObject *o, QEve
nextURL = urlFromLinkNode( links.item( links.length() - 2 ) );
+ if (!nextURL.isValid())
+ return false;
+
// If we get a mail link instead of a http URL, or the next link points
// to an index.html page (a index.html page is always the first page
@@ -260,8 +256,33 @@ bool View::eventFilter( QObject *o, QEve
if ( nextURL.protocol() == "mailto" ||
nextURL.path().endsWith( "/index.html" ) )
- return KHTMLPart::eventFilter( o, e );
+ return false;
+ if (!checkOnly)
openURL( nextURL );
return true;
+}
+
+bool View::eventFilter( QObject *o, QEvent *e )
+{
+ if ( e->type() != QEvent::KeyPress ||
+ htmlDocument().links().length() == 0 )
+ return KHTMLPart::eventFilter( o, e );
+
+ QKeyEvent *ke = static_cast<QKeyEvent *>( e );
+ if ( ke->state() & Qt::ShiftButton && ke->key() == Key_Space ) {
+ // If we're on the first page, it does not make sense to go back.
+ if ( baseURL().path().endsWith( "/index.html" ) )
+ return KHTMLPart::eventFilter( o, e );
+
+ const QScrollBar * const scrollBar = view()->verticalScrollBar();
+ if ( scrollBar->value() == scrollBar->minValue() ) {
+ if (prevPage())
+ return true;
+ }
+ } else if ( ke->key() == Key_Space ) {
+ const QScrollBar * const scrollBar = view()->verticalScrollBar();
+ if ( scrollBar->value() == scrollBar->maxValue() ) {
+ if (nextPage())
+ return true;
}
}
@@ -271,5 +292,5 @@ bool View::eventFilter( QObject *o, QEve
KURL View::urlFromLinkNode( const DOM::Node &n ) const
{
- if ( n.nodeType() != DOM::Node::ELEMENT_NODE )
+ if ( n.isNull() || n.nodeType() != DOM::Node::ELEMENT_NODE )
return KURL();
--- kdebase/khelpcenter/view.h #1.14:1.14.2.1
@@ -52,4 +52,6 @@ class View : public KHTMLPart
void slotDecFontSizes();
void slotReload( const KURL &url = KURL() );
+ bool nextPage(bool checkOnly = false);
+ bool prevPage(bool checkOnly = false);
signals:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic