/*************************************************************************** * * * begin : 15 Jan 2004 * * copyright : (C) 2003 by Samokhvalov Anton :) * * * ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include History::History(): d_current_position( -1 ), d_enabled( true ), d_up( false ), d_back( false ), d_forward( false ) { } History::~History() { } void History::add( const KURL& url ) { if ( !d_enabled ) { return; } d_current_position++; d_urls.resize( d_current_position + 1 ); d_urls[ d_current_position ] = url; if ( d_urls.size() >= 2 ) { emitSignal( true, true, false ); } else { emitSignal( true, false, false ); } } void History::up() { d_current_position = -1; d_urls.clear(); emitSignal( true, false, false ); emit goUp(); } void History::back() { if ( d_current_position >= 1 ) { d_current_position--; emit changeUrl( d_urls[ d_current_position ] ); if ( d_current_position <= 0 ) { emitSignal( true, false, true ); } else { emitSignal( true, true, true ); } } } void History::forward() { if ( d_current_position < (int)d_urls.size() - 1 ) { d_current_position++; emit changeUrl( d_urls[ d_current_position ] ); if ( d_current_position == ((int)d_urls.size() - 1) ) { emitSignal( true, true, false ); } else { emitSignal( true, true, true ); } } } void History::clear() { d_urls.clear(); emitSignal( false, false, false ); } void History::setEnabled( bool e ) { d_enabled = e; } void History::emitSignal() { emit stateChanged( d_up, d_back, d_forward ); } void History::emitSignal( bool a, bool b, bool c ) { d_up = a; d_back = b; d_forward = c; emitSignal(); } #include "History.moc"