1
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
3
Gwenview - A simple image viewer for KDE
4
Copyright 2000-2004 Aur�lien G�teau
5
Copyright 2003 Tudor Calin
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include <kpopupmenu.h>
27
#include <kdeversion.h>
28
#include <kstdaccel.h>
29
#include <kstdguiitem.h>
32
#include "history.moc"
36
const unsigned int MAX_HISTORY_SIZE=12;
38
History::History(KActionCollection* actionCollection) {
39
mPosition=mHistoryList.end();
40
mMovingInHistory=false;
43
QPair<KGuiItem, KGuiItem> backForward = KStdGuiItem::backAndForward();
44
mGoBack=new KToolBarPopupAction(backForward.first,
45
KStdAccel::shortcut(KStdAccel::Back),
46
this, SLOT(goBack()), actionCollection, "go_back");
47
mGoForward=new KToolBarPopupAction(backForward.second,
48
KStdAccel::shortcut(KStdAccel::Forward),
49
this, SLOT(goForward()), actionCollection, "go_forward");
52
connect(mGoBack->popupMenu(),SIGNAL(activated(int)),
53
this,SLOT(goBackTo(int)) );
54
connect(mGoForward->popupMenu(),SIGNAL(activated(int)),
55
this,SLOT(goForwardTo(int)) );
57
connect(mGoBack->popupMenu(), SIGNAL(aboutToShow()),
58
this, SLOT(fillGoBackMenu()) );
59
connect(mGoForward->popupMenu(), SIGNAL(aboutToShow()),
60
this, SLOT(fillGoForwardMenu()) );
68
void History::addURLToHistory(const KURL& url2) {
70
url.setFileName( QString::null );
71
if (!mMovingInHistory) {
72
if (mPosition!=mHistoryList.end() && url.equals(*mPosition, true)) return;
74
// Drop everything after current
75
HistoryList::iterator it=mPosition;
77
mHistoryList.erase(it, mHistoryList.end());
79
mHistoryList.append(url);
80
if(mHistoryList.count()==MAX_HISTORY_SIZE) mHistoryList.pop_front();
81
mPosition=mHistoryList.fromLast();
84
mGoBack->setEnabled(mPosition!=mHistoryList.begin());
85
mGoForward->setEnabled(mPosition!=mHistoryList.fromLast());
89
void History::fillGoBackMenu() {
90
QPopupMenu* menu=mGoBack->popupMenu();
92
HistoryList::ConstIterator it;
95
for(it=mHistoryList.begin(); it!=mPosition; ++it, ++pos) {
96
menu->insertItem( (*it).prettyURL(-1), pos, 0);
100
void History::fillGoForwardMenu() {
101
QPopupMenu* menu=mGoForward->popupMenu();
103
HistoryList::ConstIterator it=mPosition;
107
for(; it!=mHistoryList.end(); ++it, ++pos) {
108
menu->insertItem( (*it).prettyURL(-1), pos, -1);
112
void History::goBack() {
117
void History::goForward() {
122
void History::goBackTo(int id) {
123
for (;id>0; --id) --mPosition;
124
mMovingInHistory=true;
125
emit urlChanged(*mPosition);
126
mMovingInHistory=false;
130
void History::goForwardTo(int id) {
131
for (;id>0; --id) ++mPosition;
132
mMovingInHistory=true;
133
emit urlChanged(*mPosition);
134
mMovingInHistory=false;