diff --git a/krusader/Panel/dirhistoryqueue.cpp b/krusader/Panel/dirhistoryqueue.cpp index 8248921c..c7ab9f46 100644 --- a/krusader/Panel/dirhistoryqueue.cpp +++ b/krusader/Panel/dirhistoryqueue.cpp @@ -1,165 +1,159 @@ /***************************************************************************** * Copyright (C) 2004 Shie Erlich * * Copyright (C) 2004 Rafi Yanai * * Copyright (C) 2010 Jan Lepper * * * * 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. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "dirhistoryqueue.h" #include "krpanel.h" #include "krview.h" #include "../defaults.h" #include "../krservices.h" // QtCore #include DirHistoryQueue::DirHistoryQueue(KrPanel *panel) : _panel(panel), _currentPos(0) { } DirHistoryQueue::~DirHistoryQueue() {} void DirHistoryQueue::clear() { _urlQueue.clear(); _currentItems.clear(); _currentPos = 0; } QUrl DirHistoryQueue::currentUrl() { if(_urlQueue.count()) return _urlQueue[_currentPos]; else return QUrl(); } void DirHistoryQueue::setCurrentUrl(const QUrl &url) { if(_urlQueue.count()) _urlQueue[_currentPos] = url; } QString DirHistoryQueue::currentItem() { if(count()) return _currentItems[_currentPos]; else return QString(); } void DirHistoryQueue::saveCurrentItem() { // if the filesystem-url hasn't been refreshed yet, // avoid saving current item for the wrong url if(count() && _panel->virtualPath().matches(_urlQueue[_currentPos], QUrl::StripTrailingSlash)) _currentItems[_currentPos] = _panel->view->getCurrentItem(); } void DirHistoryQueue::add(QUrl url, QString currentItem) { url.setPath(QDir::cleanPath(url.path())); if(_urlQueue.isEmpty()) { _urlQueue.push_front(url); _currentItems.push_front(currentItem); return; } if(_urlQueue[_currentPos].matches(url, QUrl::StripTrailingSlash)) { _currentItems[_currentPos] = currentItem; return; } for (int i = 0; i < _currentPos; i++) { _urlQueue.pop_front(); _currentItems.pop_front(); } _currentPos = 0; // do we have room for another ? if (_urlQueue.count() > 12) { // FIXME: use user-defined size // no room - remove the oldest entry _urlQueue.pop_back(); _currentItems.pop_back(); } saveCurrentItem(); _urlQueue.push_front(url); _currentItems.push_front(currentItem); } -void DirHistoryQueue::pushBackRoot() -{ - _urlQueue.push_back(QUrl::fromLocalFile(ROOT_DIR)); - _currentItems.push_back(QString()); -} - bool DirHistoryQueue::gotoPos(int pos) { if(pos >= 0 && pos < _urlQueue.count()) { saveCurrentItem(); _currentPos = pos; return true; } return false; } bool DirHistoryQueue::goBack() { return gotoPos(_currentPos + 1); } bool DirHistoryQueue::goForward() { return gotoPos(_currentPos - 1); } void DirHistoryQueue::save(KConfigGroup cfg) { saveCurrentItem(); QList urls; foreach(QUrl url, _urlQueue) { // make sure no passwords are permanently stored url.setPassword(QString()); urls << url; } cfg.writeEntry("Entrys", KrServices::toStringList(urls)); cfg.writeEntry("CurrentItems", _currentItems); cfg.writeEntry("CurrentIndex", _currentPos); } bool DirHistoryQueue::restore(KConfigGroup cfg) { clear(); _urlQueue = KrServices::toUrlList(cfg.readEntry("Entrys", QStringList())); _currentItems = cfg.readEntry("CurrentItems", QStringList()); if(!_urlQueue.count() || _urlQueue.count() != _currentItems.count()) { clear(); return false; } _currentPos = cfg.readEntry("CurrentIndex", 0); if(_currentPos >= _urlQueue.count() || _currentPos < 0) _currentPos = 0; return true; } diff --git a/krusader/Panel/dirhistoryqueue.h b/krusader/Panel/dirhistoryqueue.h index c71f4b26..0d3d0b96 100644 --- a/krusader/Panel/dirhistoryqueue.h +++ b/krusader/Panel/dirhistoryqueue.h @@ -1,78 +1,77 @@ /***************************************************************************** * Copyright (C) 2004 Shie Erlich * * Copyright (C) 2004 Rafi Yanai * * Copyright (C) 2010 Jan Lepper * * * * 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. * * * * This package is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef DIRHISTORYQUEUE_H #define DIRHISTORYQUEUE_H // QtCore #include #include #include # include class KrPanel; class DirHistoryQueue : public QObject { Q_OBJECT public: DirHistoryQueue(KrPanel *panel); ~DirHistoryQueue(); void clear(); int currentPos() { return _currentPos; } int count() { return _urlQueue.count(); } QUrl currentUrl(); void setCurrentUrl(const QUrl &url); const QUrl &get(int pos) { return _urlQueue[pos]; } void add(QUrl url, QString currentItem); - void pushBackRoot(); // add root dir to beginning of history bool gotoPos(int pos); bool goBack(); bool goForward(); bool canGoBack() { return _currentPos < count() - 1; } bool canGoForward() { return _currentPos > 0; } QString currentItem(); // current item of the view void save(KConfigGroup cfg); bool restore(KConfigGroup cfg); public slots: void saveCurrentItem(); private: KrPanel* _panel; int _currentPos; QList _urlQueue; QStringList _currentItems; }; #endif