~ubuntu-branches/ubuntu/edgy/gwenview/edgy

« back to all changes in this revision

Viewing changes to src/app/history.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-12-06 17:59:19 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051206175919-8yv9nfmw0pws6p52
Tags: 1.3.1-0ubuntu1
* Sync with Debian
* Edit kde.mk for .pot generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
 
2
/*
 
3
Gwenview - A simple image viewer for KDE
 
4
Copyright 2000-2004 Aur�lien G�teau
 
5
Copyright 2003 Tudor Calin
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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.
 
20
 
 
21
*/
 
22
 
 
23
// KDE
 
24
#include <kaction.h>
 
25
#include <klocale.h>
 
26
#include <kpopupmenu.h>
 
27
#include <kdeversion.h>
 
28
#include <kstdaccel.h>
 
29
#include <kstdguiitem.h>
 
30
 
 
31
// Local
 
32
#include "history.moc"
 
33
namespace Gwenview {
 
34
 
 
35
 
 
36
const unsigned int MAX_HISTORY_SIZE=12;
 
37
 
 
38
History::History(KActionCollection* actionCollection) {
 
39
        mPosition=mHistoryList.end();
 
40
        mMovingInHistory=false;
 
41
 
 
42
        // Actions
 
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");
 
50
 
 
51
        // Connections
 
52
        connect(mGoBack->popupMenu(),SIGNAL(activated(int)),
 
53
                this,SLOT(goBackTo(int)) );
 
54
        connect(mGoForward->popupMenu(),SIGNAL(activated(int)),
 
55
                this,SLOT(goForwardTo(int)) );
 
56
 
 
57
        connect(mGoBack->popupMenu(), SIGNAL(aboutToShow()),
 
58
                this, SLOT(fillGoBackMenu()) );
 
59
        connect(mGoForward->popupMenu(), SIGNAL(aboutToShow()),
 
60
                this, SLOT(fillGoForwardMenu()) );
 
61
}
 
62
 
 
63
 
 
64
History::~History() {
 
65
}
 
66
 
 
67
 
 
68
void History::addURLToHistory(const KURL& url2) {
 
69
        KURL url( url2 );
 
70
        url.setFileName( QString::null );
 
71
        if (!mMovingInHistory) {
 
72
                if (mPosition!=mHistoryList.end() && url.equals(*mPosition, true)) return;
 
73
 
 
74
                // Drop everything after current
 
75
                HistoryList::iterator it=mPosition;
 
76
                ++it;
 
77
                mHistoryList.erase(it, mHistoryList.end());
 
78
 
 
79
                mHistoryList.append(url);
 
80
                if(mHistoryList.count()==MAX_HISTORY_SIZE) mHistoryList.pop_front();
 
81
                mPosition=mHistoryList.fromLast();
 
82
        }
 
83
 
 
84
        mGoBack->setEnabled(mPosition!=mHistoryList.begin());
 
85
        mGoForward->setEnabled(mPosition!=mHistoryList.fromLast());
 
86
}
 
87
 
 
88
 
 
89
void History::fillGoBackMenu() {
 
90
        QPopupMenu* menu=mGoBack->popupMenu();
 
91
        menu->clear();
 
92
        HistoryList::ConstIterator it;
 
93
 
 
94
        int pos=1;
 
95
        for(it=mHistoryList.begin(); it!=mPosition; ++it, ++pos) {
 
96
                menu->insertItem( (*it).prettyURL(-1), pos, 0);
 
97
        }
 
98
}
 
99
 
 
100
void History::fillGoForwardMenu() {
 
101
        QPopupMenu* menu=mGoForward->popupMenu();
 
102
        menu->clear();
 
103
        HistoryList::ConstIterator it=mPosition;
 
104
        ++it;
 
105
 
 
106
        int pos=1;
 
107
        for(; it!=mHistoryList.end(); ++it, ++pos) {
 
108
                menu->insertItem( (*it).prettyURL(-1), pos, -1);
 
109
        }
 
110
}
 
111
 
 
112
void History::goBack() {
 
113
        goBackTo(1);
 
114
}
 
115
 
 
116
 
 
117
void History::goForward() {
 
118
        goForwardTo(1);
 
119
}
 
120
 
 
121
 
 
122
void History::goBackTo(int id) {
 
123
        for (;id>0; --id) --mPosition;
 
124
        mMovingInHistory=true;
 
125
        emit urlChanged(*mPosition);
 
126
        mMovingInHistory=false;
 
127
}
 
128
 
 
129
 
 
130
void History::goForwardTo(int id) {
 
131
        for (;id>0; --id) ++mPosition;
 
132
        mMovingInHistory=true;
 
133
        emit urlChanged(*mPosition);
 
134
        mMovingInHistory=false;
 
135
}
 
136
 
 
137
} // namespace