Changeset View
Changeset View
Standalone View
Standalone View
krusader/Panel/dirhistoryqueue.cpp
Show All 23 Lines | |||||
24 | #include "krview.h" | 24 | #include "krview.h" | ||
25 | #include "../defaults.h" | 25 | #include "../defaults.h" | ||
26 | #include "../krservices.h" | 26 | #include "../krservices.h" | ||
27 | 27 | | |||
28 | // QtCore | 28 | // QtCore | ||
29 | #include <QDir> | 29 | #include <QDir> | ||
30 | 30 | | |||
31 | DirHistoryQueue::DirHistoryQueue(KrPanel *panel) : | 31 | DirHistoryQueue::DirHistoryQueue(KrPanel *panel) : | ||
32 | _panel(panel), _state(0), _currentPos(0) | 32 | _panel(panel), _currentPos(0) | ||
33 | { | 33 | { | ||
34 | } | 34 | } | ||
35 | 35 | | |||
36 | DirHistoryQueue::~DirHistoryQueue() {} | 36 | DirHistoryQueue::~DirHistoryQueue() {} | ||
37 | 37 | | |||
38 | void DirHistoryQueue::clear() | 38 | void DirHistoryQueue::clear() | ||
39 | { | 39 | { | ||
40 | _urlQueue.clear(); | 40 | _urlQueue.clear(); | ||
41 | _currentItems.clear(); | 41 | _currentItems.clear(); | ||
42 | _currentPos = 0; | 42 | _currentPos = 0; | ||
43 | _state++; | | |||
44 | } | 43 | } | ||
45 | 44 | | |||
46 | QUrl DirHistoryQueue::currentUrl() | 45 | QUrl DirHistoryQueue::currentUrl() | ||
47 | { | 46 | { | ||
48 | if(_urlQueue.count()) | 47 | if(_urlQueue.count()) | ||
49 | return _urlQueue[_currentPos]; | 48 | return _urlQueue[_currentPos]; | ||
50 | else | 49 | else | ||
51 | return QUrl(); | 50 | return QUrl(); | ||
Show All 23 Lines | |||||
75 | 74 | | |||
76 | void DirHistoryQueue::add(QUrl url, QString currentItem) | 75 | void DirHistoryQueue::add(QUrl url, QString currentItem) | ||
77 | { | 76 | { | ||
78 | url.setPath(QDir::cleanPath(url.path())); | 77 | url.setPath(QDir::cleanPath(url.path())); | ||
79 | 78 | | |||
80 | if(_urlQueue.isEmpty()) { | 79 | if(_urlQueue.isEmpty()) { | ||
81 | _urlQueue.push_front(url); | 80 | _urlQueue.push_front(url); | ||
82 | _currentItems.push_front(currentItem); | 81 | _currentItems.push_front(currentItem); | ||
83 | _state++; | | |||
84 | return; | 82 | return; | ||
85 | } | 83 | } | ||
86 | 84 | | |||
87 | if(_urlQueue[_currentPos].matches(url, QUrl::StripTrailingSlash)) { | 85 | if(_urlQueue[_currentPos].matches(url, QUrl::StripTrailingSlash)) { | ||
88 | _currentItems[_currentPos] = currentItem; | 86 | _currentItems[_currentPos] = currentItem; | ||
89 | return; | 87 | return; | ||
90 | } | 88 | } | ||
91 | 89 | | |||
Show All 9 Lines | 98 | if (_urlQueue.count() > 12) { // FIXME: use user-defined size | |||
101 | // no room - remove the oldest entry | 99 | // no room - remove the oldest entry | ||
102 | _urlQueue.pop_back(); | 100 | _urlQueue.pop_back(); | ||
103 | _currentItems.pop_back(); | 101 | _currentItems.pop_back(); | ||
104 | } | 102 | } | ||
105 | 103 | | |||
106 | saveCurrentItem(); | 104 | saveCurrentItem(); | ||
107 | _urlQueue.push_front(url); | 105 | _urlQueue.push_front(url); | ||
108 | _currentItems.push_front(currentItem); | 106 | _currentItems.push_front(currentItem); | ||
109 | | ||||
110 | _state++; | | |||
111 | } | 107 | } | ||
112 | 108 | | |||
113 | void DirHistoryQueue::pushBackRoot() | 109 | void DirHistoryQueue::pushBackRoot() | ||
114 | { | 110 | { | ||
115 | _urlQueue.push_back(QUrl::fromLocalFile(ROOT_DIR)); | 111 | _urlQueue.push_back(QUrl::fromLocalFile(ROOT_DIR)); | ||
116 | _currentItems.push_back(QString()); | 112 | _currentItems.push_back(QString()); | ||
117 | } | 113 | } | ||
118 | 114 | | |||
119 | bool DirHistoryQueue::gotoPos(int pos) | 115 | bool DirHistoryQueue::gotoPos(int pos) | ||
120 | { | 116 | { | ||
121 | if(pos >= 0 && pos < _urlQueue.count()) { | 117 | if(pos >= 0 && pos < _urlQueue.count()) { | ||
122 | saveCurrentItem(); | 118 | saveCurrentItem(); | ||
123 | _currentPos = pos; | 119 | _currentPos = pos; | ||
124 | _state++; | | |||
125 | return true; | 120 | return true; | ||
126 | } | 121 | } | ||
127 | return false; | 122 | return false; | ||
128 | } | 123 | } | ||
129 | 124 | | |||
130 | bool DirHistoryQueue::goBack() | 125 | bool DirHistoryQueue::goBack() | ||
131 | { | 126 | { | ||
132 | return gotoPos(_currentPos + 1); | 127 | return gotoPos(_currentPos + 1); | ||
Show All 28 Lines | 152 | { | |||
161 | if(!_urlQueue.count() || _urlQueue.count() != _currentItems.count()) { | 156 | if(!_urlQueue.count() || _urlQueue.count() != _currentItems.count()) { | ||
162 | clear(); | 157 | clear(); | ||
163 | return false; | 158 | return false; | ||
164 | } | 159 | } | ||
165 | _currentPos = cfg.readEntry("CurrentIndex", 0); | 160 | _currentPos = cfg.readEntry("CurrentIndex", 0); | ||
166 | if(_currentPos >= _urlQueue.count() || _currentPos < 0) | 161 | if(_currentPos >= _urlQueue.count() || _currentPos < 0) | ||
167 | _currentPos = 0; | 162 | _currentPos = 0; | ||
168 | 163 | | |||
169 | _state++; | | |||
170 | return true; | 164 | return true; | ||
171 | } | 165 | } |