+ delete d;
+}
+
+const KUrl& UrlNavigator::url() const
+{
+ assert(!d->m_history.empty());
+ return d->m_history[d->m_historyIndex].url();
+}
+
+KUrl UrlNavigator::url(int index) const
+{
+ assert(index >= 0);
+ // keep scheme, hostname etc. maybe we will need this in the future
+ // for e.g. browsing ftp repositories.
+ KUrl newurl(url());
+ newurl.setPath(QString());
+ QString path(url().path());
+
+ if (!path.isEmpty()) {
+ if (index == 0) //prevent the last "/" from being stripped
+ path = "/"; //or we end up with an empty path
+ else
+ path = path.section('/', 0, index);
+ }
+
+ newurl.setPath(path);
+ return newurl;
+}
+
+UrlNavigator::HistoryElem UrlNavigator::currentHistoryItem() const
+{
+ return d->m_history[d->m_historyIndex];
+}
+
+int UrlNavigator::historySize() const
+{
+ return d->m_history.count();
+}
+
+void UrlNavigator::goBack()
+{
+ d->updateHistoryElem();
+
+ const int count = d->m_history.count();
+ if (d->m_historyIndex < count - 1) {
+ ++d->m_historyIndex;
+ d->updateContent();
+ emit urlChanged(url());
+ emit historyChanged();
+ }
+}
+
+void UrlNavigator::goForward()
+{
+ if (d->m_historyIndex > 0) {
+ --d->m_historyIndex;
+ d->updateContent();
+ emit urlChanged(url());
+ emit historyChanged();
+ }
+}
+
+void UrlNavigator::goUp()
+{
+ setUrl(url().upUrl());
+}
+
+void UrlNavigator::goHome()
+{
+ setUrl(DolphinSettings::instance().generalSettings()->homeUrl());
+}
+
+bool UrlNavigator::isUrlEditable() const
+{
+ return d->m_toggleButton->isChecked();
+}
+
+void UrlNavigator::editUrl(bool editOrBrowse)
+{
+ d->setUrlEditable(editOrBrowse);
+ if (editOrBrowse) {
+ d->m_pathBox->setFocus();
+ }
+}
+
+void UrlNavigator::setActive(bool active)
+{
+ if (active != d->m_active) {
+ d->m_active = active;
+ update();
+ if (active) {
+ emit activated();
+ }
+ }
+}
+
+void UrlNavigator::setShowHiddenFiles( bool show )
+{
+ d->m_showHiddenFiles = show;
+}
+
+void UrlNavigator::dropUrls(const KUrl::List& urls,
+ const KUrl& destination)
+{
+ emit urlsDropped(urls, destination);
+}
+
+void UrlNavigator::setUrl(const KUrl& url)
+{
+ QString urlStr(url.pathOrUrl());
+
+ // TODO: a patch has been submitted by Filip Brcic which adjusts
+ // the URL for tar and zip files. See https://bugs.kde.org/show_bug.cgi?id=142781
+ // for details. The URL navigator part of the patch has not been committed yet,
+ // as the URL navigator will be subject of change and
+ // we might think of a more generic approach to check the protocol + MIME type for
+ // this use case.
+
+ //kDebug() << "setUrl(" << url << ")" << endl;
+ if ( urlStr.length() > 0 && urlStr.at(0) == '~') {
+ // replace '~' by the home directory
+ urlStr.remove(0, 1);
+ urlStr.insert(0, QDir::home().path());
+ }
+
+ const KUrl transformedUrl(urlStr);
+
+ if (d->m_historyIndex > 0) {
+ // Check whether the previous element of the history has the same Url.
+ // If yes, just go forward instead of inserting a duplicate history
+ // element.
+ HistoryElem& prevHistoryElem = d->m_history[d->m_historyIndex - 1];
+ if (transformedUrl == prevHistoryElem.url()) {
+ goForward();
+// kDebug() << "goin' forward in history" << endl;
+ return;
+ }
+ }
+
+ if (this->url() == transformedUrl) {
+ // don't insert duplicate history elements
+// kDebug() << "current url == transformedUrl" << endl;
+ return;
+ }
+
+ d->updateHistoryElem();
+ d->m_history.insert(d->m_historyIndex, HistoryElem(transformedUrl));
+
+ d->updateContent();
+
+ emit urlChanged(transformedUrl);
+ emit historyChanged();
+
+ // Prevent an endless growing of the history: remembering
+ // the last 100 Urls should be enough...
+ if (d->m_historyIndex > 100) {
+ d->m_history.removeFirst();
+ --d->m_historyIndex;
+ }
+
+/* kDebug() << "history starting ====================" << endl;
+ int i = 0;
+ for (QValueListIterator<UrlNavigator::HistoryElem> it = d->m_history.begin();
+ it != d->m_history.end();
+ ++it, ++i)
+ {
+ kDebug() << i << ": " << (*it).url() << endl;
+ }
+ kDebug() << "history done ========================" << endl;*/
+
+ requestActivation();
+}
+
+void UrlNavigator::requestActivation()
+{
+ setActive(true);
+}
+
+void UrlNavigator::storeContentsPosition(int x, int y)
+{
+ HistoryElem& hist = d->m_history[d->m_historyIndex];
+ hist.setContentsX(x);
+ hist.setContentsY(y);
+}
+
+void UrlNavigator::keyReleaseEvent(QKeyEvent* event)
+{
+ QWidget::keyReleaseEvent(event);
+ if (isUrlEditable() && (event->key() == Qt::Key_Escape)) {
+ d->setUrlEditable(false);
+ }
+}
+
+void UrlNavigator::mouseReleaseEvent(QMouseEvent* event)
+{
+ if (event->button() == Qt::MidButton) {
+ QClipboard* clipboard = QApplication::clipboard();
+ const QMimeData* mimeData = clipboard->mimeData();
+ if (mimeData->hasText()) {
+ const QString text = mimeData->text();
+ setUrl(KUrl(text));
+ }
+ }
+ QWidget::mouseReleaseEvent(event);
+}
+
+bool UrlNavigator::isActive() const
+{
+ return d->m_active;
+}
+
+bool UrlNavigator::showHiddenFiles() const
+{
+ return d->m_showHiddenFiles;