]> cloud.milkyroute.net Git - dolphin.git/blob - src/urlnavigator.cpp
One more step towards kdelibs: d-pointer-ify, including moving all members, all priva...
[dolphin.git] / src / urlnavigator.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (<peter.penz@gmx.at>) *
3 * Copyright (C) 2006 by Aaron J. Seigo (<aseigo@kde.org>) *
4 * Copyright (C) 2006 by Patrice Tremblay *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #include "urlnavigator.h"
23
24 #include "bookmarkselector.h"
25 #include "dolphinsettings.h"
26 #include "dolphin_generalsettings.h"
27 #include "protocolcombo.h"
28 #include "urlnavigatorbutton.h"
29
30 #include <assert.h>
31
32 #include <kfileitem.h>
33 #include <kicon.h>
34 #include <klocale.h>
35 #include <kprotocolinfo.h>
36 #include <kurlcombobox.h>
37 #include <kurlcompletion.h>
38
39 #include <QApplication>
40 #include <QClipboard>
41 #include <QDir>
42 #include <QHBoxLayout>
43 #include <QLabel>
44 #include <QLineEdit>
45 #include <QLinkedList>
46 #include <QMouseEvent>
47 #include <QToolButton>
48
49 UrlNavigator::HistoryElem::HistoryElem() :
50 m_url(),
51 m_currentFileName(),
52 m_contentsX(0),
53 m_contentsY(0)
54 {
55 }
56
57 UrlNavigator::HistoryElem::HistoryElem(const KUrl& url) :
58 m_url(url),
59 m_currentFileName(),
60 m_contentsX(0),
61 m_contentsY(0)
62 {
63 }
64
65 UrlNavigator::HistoryElem::~HistoryElem()
66 {
67 }
68
69 class UrlNavigator::Private
70 {
71 public:
72 Private(UrlNavigator* q, KBookmarkManager* bookmarkManager);
73
74 void slotReturnPressed(const QString&);
75 void slotRemoteHostActivated();
76 void slotProtocolChanged(const QString&);
77
78 /**
79 * Appends the widget at the end of the URL navigator. It is assured
80 * that the filler widget remains as last widget to fill the remaining
81 * width.
82 */
83 void appendWidget(QWidget* widget);
84
85 /**
86 * Switches the navigation bar between the breadcrumb view and the
87 * traditional view (see setUrlEditable()) and is connected to the clicked signal
88 * of the navigation bar button.
89 */
90 void switchView();
91
92 /**
93 * Allows to edit the Url of the navigation bar if \a editable
94 * is true. If \a editable is false, each part of
95 * the Url is presented by a button for a fast navigation.
96 */
97 void setUrlEditable(bool editable);
98
99 /**
100 * Updates the history element with the current file item
101 * and the contents position.
102 */
103 void updateHistoryElem();
104 void updateContent();
105
106 /**
107 * Updates all buttons to have one button for each part of the
108 * path \a path. Existing buttons, which are available by m_navButtons,
109 * are reused if possible. If the path is longer, new buttons will be
110 * created, if the path is shorter, the remaining buttons will be deleted.
111 * @param startIndex Start index of path part (/), where the buttons
112 * should be created for each following part.
113 */
114 void updateButtons(const QString& path, int startIndex);
115
116 /**
117 * Deletes all URL navigator buttons. m_navButtons is
118 * empty after this operation.
119 */
120 void deleteButtons();
121
122
123 bool m_active;
124 bool m_showHiddenFiles;
125 int m_historyIndex;
126
127 QHBoxLayout* m_layout;
128
129 QList<HistoryElem> m_history;
130 QToolButton* m_toggleButton;
131 BookmarkSelector* m_bookmarkSelector;
132 KUrlComboBox* m_pathBox;
133 ProtocolCombo* m_protocols;
134 QLabel* m_protocolSeparator;
135 QLineEdit* m_host;
136 QLinkedList<UrlNavigatorButton*> m_navButtons;
137 QWidget* m_filler;
138 UrlNavigator* q;
139 };
140
141
142 UrlNavigator::Private::Private(UrlNavigator* q, KBookmarkManager* bookmarkManager)
143 :
144 m_active(true),
145 m_showHiddenFiles(false),
146 m_historyIndex(0),
147 m_layout(new QHBoxLayout),
148 m_protocols(0),
149 m_protocolSeparator(0),
150 m_host(0),
151 m_filler(0),
152 q(q)
153 {
154 m_layout->setSpacing(0);
155 m_layout->setMargin(0);
156
157 // initialize toggle button which switches between the breadcrumb view
158 // and the traditional view
159 m_toggleButton = new QToolButton();
160 m_toggleButton->setCheckable(true);
161 m_toggleButton->setAutoRaise(true);
162 m_toggleButton->setIcon(KIcon("editinput")); // TODO: is just a placeholder icon (?)
163 m_toggleButton->setFocusPolicy(Qt::NoFocus);
164 m_toggleButton->setMinimumHeight(q->minimumHeight());
165 connect(m_toggleButton, SIGNAL(clicked()),
166 q, SLOT(switchView()));
167
168 // initialize the bookmark selector
169 m_bookmarkSelector = new BookmarkSelector(q, bookmarkManager);
170 connect(m_bookmarkSelector, SIGNAL(bookmarkActivated(const KUrl&)),
171 q, SLOT(setUrl(const KUrl&)));
172
173 // initialize the path box of the traditional view
174 m_pathBox = new KUrlComboBox(KUrlComboBox::Directories, true, q);
175
176 KUrlCompletion* kurlCompletion = new KUrlCompletion(KUrlCompletion::DirCompletion);
177 m_pathBox->setCompletionObject(kurlCompletion);
178 m_pathBox->setAutoDeleteCompletionObject(true);
179
180 connect(m_pathBox, SIGNAL(returnPressed(QString)),
181 q, SLOT(slotReturnPressed(QString)));
182 connect(m_pathBox, SIGNAL(urlActivated(KUrl)),
183 q, SLOT(setUrl(KUrl)));
184
185 // Append a filler widget at the end, which automatically resizes to the
186 // maximum available width. This assures that the URL navigator uses the
187 // whole width, so that the clipboard content can be dropped.
188 m_filler = new QWidget();
189 m_filler->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
190
191 m_layout->addWidget(m_toggleButton);
192 m_layout->addWidget(m_bookmarkSelector);
193 m_layout->addWidget(m_pathBox);
194 m_layout->addWidget(m_filler);
195 }
196
197 void UrlNavigator::Private::appendWidget(QWidget* widget)
198 {
199 m_layout->insertWidget(m_layout->count() - 1, widget);
200 }
201
202 void UrlNavigator::Private::setUrlEditable(bool editable)
203 {
204 if (q->isUrlEditable() != editable) {
205 m_toggleButton->toggle();
206 switchView();
207 }
208 }
209
210 void UrlNavigator::Private::slotReturnPressed(const QString& text)
211 {
212 // Parts of the following code have been taken
213 // from the class KateFileSelector located in
214 // kate/app/katefileselector.hpp of Kate.
215 // Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
216 // Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
217 // Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
218
219 KUrl typedUrl(text);
220 if (typedUrl.hasPass()) {
221 typedUrl.setPass(QString());
222 }
223
224 QStringList urls = m_pathBox->urls();
225 urls.removeAll(typedUrl.url());
226 urls.prepend(typedUrl.url());
227 m_pathBox->setUrls(urls, KUrlComboBox::RemoveBottom);
228
229 q->setUrl(typedUrl);
230 // The URL might have been adjusted by UrlNavigator::setUrl(), hence
231 // synchronize the result in the path box.
232 m_pathBox->setUrl(q->url());
233 }
234
235 void UrlNavigator::Private::slotRemoteHostActivated()
236 {
237 KUrl u = q->url();
238
239 QString host = m_host->text();
240 QString user;
241
242 int marker = host.indexOf("@");
243 if (marker != -1)
244 {
245 user = host.left(marker);
246 u.setUser(user);
247 host = host.right(host.length() - marker - 1);
248 }
249
250 marker = host.indexOf("/");
251 if (marker != -1)
252 {
253 u.setPath(host.right(host.length() - marker));
254 host.truncate(marker);
255 }
256 else
257 {
258 u.setPath("");
259 }
260
261 if (m_protocols->currentProtocol() != u.protocol() ||
262 host != u.host() ||
263 user != u.user())
264 {
265 u.setProtocol(m_protocols->currentProtocol());
266 u.setHost(m_host->text());
267
268 //TODO: get rid of this HACK for file:///!
269 if (u.protocol() == "file")
270 {
271 u.setHost("");
272 if (u.path().isEmpty())
273 {
274 u.setPath("/");
275 }
276 }
277
278 q->setUrl(u);
279 }
280 }
281
282 void UrlNavigator::Private::slotProtocolChanged(const QString& protocol)
283 {
284 KUrl url;
285 url.setProtocol(protocol);
286 //url.setPath(KProtocolInfo::protocolClass(protocol) == ":local" ? "/" : "");
287 url.setPath("/");
288 QLinkedList<UrlNavigatorButton*>::const_iterator it = m_navButtons.begin();
289 const QLinkedList<UrlNavigatorButton*>::const_iterator itEnd = m_navButtons.end();
290 while (it != itEnd) {
291 (*it)->close();
292 (*it)->deleteLater();
293 ++it;
294 }
295 m_navButtons.clear();
296
297 if (KProtocolInfo::protocolClass(protocol) == ":local") {
298 q->setUrl(url);
299 }
300 else {
301 if (!m_host) {
302 m_protocolSeparator = new QLabel("://", q);
303 appendWidget(m_protocolSeparator);
304 m_host = new QLineEdit(q);
305 appendWidget(m_host);
306
307 connect(m_host, SIGNAL(lostFocus()),
308 q, SLOT(slotRemoteHostActivated()));
309 connect(m_host, SIGNAL(returnPressed()),
310 q, SLOT(slotRemoteHostActivated()));
311 }
312 else {
313 m_host->setText("");
314 }
315 m_protocolSeparator->show();
316 m_host->show();
317 m_host->setFocus();
318 }
319 }
320
321 #if 0
322 void UrlNavigator::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
323 {
324 // kDebug() << "received redirection to " << newUrl << endl;
325 kDebug() << "received redirection from " << oldUrl << " to " << newUrl << endl;
326 /* UrlStack::iterator it = m_urls.find(oldUrl);
327 if (it != m_urls.end())
328 {
329 m_urls.erase(++it, m_urls.end());
330 }
331
332 m_urls.append(newUrl);*/
333 }
334 #endif
335
336 void UrlNavigator::Private::switchView()
337 {
338 updateContent();
339 if (q->isUrlEditable()) {
340 m_pathBox->setFocus();
341 } else {
342 q->setUrl(m_pathBox->currentText());
343 }
344 emit q->requestActivation();
345 }
346
347 void UrlNavigator::Private::updateHistoryElem()
348 {
349 assert(m_historyIndex >= 0);
350 const KFileItem* item = 0; // TODO: m_dolphinView->currentFileItem();
351 if (item != 0) {
352 HistoryElem& hist = m_history[m_historyIndex];
353 hist.setCurrentFileName(item->name());
354 }
355 }
356
357 void UrlNavigator::Private::updateContent()
358 {
359 m_bookmarkSelector->updateSelection(q->url());
360
361 m_toggleButton->setToolTip(QString());
362 QString path(q->url().pathOrUrl());
363
364 // TODO: prevent accessing the DolphinMainWindow out from this scope
365 //const QAction* action = dolphinView()->mainWindow()->actionCollection()->action("editable_location");
366 // TODO: registry of default shortcuts
367 //QString shortcut = action? action->shortcut().toString() : "Ctrl+L";
368 const QString shortcut = "Ctrl+L";
369
370 if (m_toggleButton->isChecked()) {
371 delete m_protocols; m_protocols = 0;
372 delete m_protocolSeparator; m_protocolSeparator = 0;
373 delete m_host; m_host = 0;
374 deleteButtons();
375 m_filler->hide();
376
377 m_toggleButton->setToolTip(i18n("Browse (%1, Escape)", shortcut));
378
379 q->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
380 m_pathBox->show();
381 m_pathBox->setUrl(q->url());
382 }
383 else {
384 m_toggleButton->setToolTip(i18n("Edit location (%1)", shortcut));
385
386 q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
387 m_pathBox->hide();
388 m_filler->show();
389
390 // get the data from the currently selected bookmark
391 KBookmark bookmark = m_bookmarkSelector->selectedBookmark();
392
393 QString bookmarkPath;
394 if (bookmark.isNull()) {
395 // No bookmark is a part of the current Url.
396 // The following code tries to guess the bookmark
397 // path. E. g. "fish://root@192.168.0.2/var/lib" writes
398 // "fish://root@192.168.0.2" to 'bookmarkPath', which leads to the
399 // navigation indication 'Custom Path > var > lib".
400 int idx = path.indexOf(QString("//"));
401 idx = path.indexOf("/", (idx < 0) ? 0 : idx + 2);
402 bookmarkPath = (idx < 0) ? path : path.left(idx);
403 }
404 else {
405 bookmarkPath = bookmark.url().pathOrUrl();
406 }
407 const uint len = bookmarkPath.length();
408
409 // calculate the start point for the URL navigator buttons by counting
410 // the slashs inside the bookmark URL
411 int slashCount = 0;
412 for (uint i = 0; i < len; ++i) {
413 if (bookmarkPath.at(i) == QChar('/')) {
414 ++slashCount;
415 }
416 }
417 if ((len > 0) && bookmarkPath.at(len - 1) == QChar('/')) {
418 assert(slashCount > 0);
419 --slashCount;
420 }
421
422 const KUrl currentUrl = q->url();
423 if (!currentUrl.isLocalFile() && bookmark.isNull()) {
424 QString protocol = currentUrl.protocol();
425 if (!m_protocols) {
426 deleteButtons();
427 m_protocols = new ProtocolCombo(protocol, q);
428 appendWidget(m_protocols);
429 connect(m_protocols, SIGNAL(activated(QString)),
430 q, SLOT(slotProtocolChanged(QString)));
431 }
432 else {
433 m_protocols->setProtocol(protocol);
434 }
435 m_protocols->show();
436
437 if (KProtocolInfo::protocolClass(protocol) != ":local") {
438 QString hostText = currentUrl.host();
439
440 if (!currentUrl.user().isEmpty()) {
441 hostText = currentUrl.user() + '@' + hostText;
442 }
443
444 if (!m_host) {
445 // ######### TODO: this code is duplicated from slotProtocolChanged!
446 m_protocolSeparator = new QLabel("://", q);
447 appendWidget(m_protocolSeparator);
448 m_host = new QLineEdit(hostText, q);
449 appendWidget(m_host);
450
451 connect(m_host, SIGNAL(lostFocus()),
452 q, SLOT(slotRemoteHostActivated()));
453 connect(m_host, SIGNAL(returnPressed()),
454 q, SLOT(slotRemoteHostActivated()));
455 }
456 else {
457 m_host->setText(hostText);
458 }
459 m_protocolSeparator->show();
460 m_host->show();
461 }
462 else {
463 delete m_protocolSeparator; m_protocolSeparator = 0;
464 delete m_host; m_host = 0;
465 }
466 }
467 else if (m_protocols) {
468 m_protocols->hide();
469
470 if (m_host) {
471 m_protocolSeparator->hide();
472 m_host->hide();
473 }
474 }
475
476 updateButtons(path, slashCount);
477 }
478 }
479
480 void UrlNavigator::Private::updateButtons(const QString& path, int startIndex)
481 {
482 QLinkedList<UrlNavigatorButton*>::iterator it = m_navButtons.begin();
483 const QLinkedList<UrlNavigatorButton*>::const_iterator itEnd = m_navButtons.end();
484 bool createButton = false;
485 const KUrl currentUrl = q->url();
486
487 int idx = startIndex;
488 bool hasNext = true;
489 do {
490 createButton = (it == itEnd);
491
492 const QString dirName = path.section('/', idx, idx);
493 const bool isFirstButton = (idx == startIndex);
494 hasNext = isFirstButton || !dirName.isEmpty();
495 if (hasNext) {
496 QString text;
497 if (isFirstButton) {
498 // the first URL navigator button should get the name of the
499 // bookmark instead of the directory name
500 const KBookmark bookmark = m_bookmarkSelector->selectedBookmark();
501 text = bookmark.text();
502 if (text.isEmpty()) {
503 if (currentUrl.isLocalFile()) {
504 text = i18n("Custom Path");
505 }
506 else {
507 ++idx;
508 continue;
509 }
510 }
511 }
512
513 UrlNavigatorButton* button = 0;
514 if (createButton) {
515 button = new UrlNavigatorButton(idx, q);
516 appendWidget(button);
517 }
518 else {
519 button = *it;
520 button->setIndex(idx);
521 }
522
523 if (isFirstButton) {
524 button->setText(text);
525 }
526
527 if (createButton) {
528 button->show();
529 m_navButtons.append(button);
530 }
531 else {
532 ++it;
533 }
534 ++idx;
535 }
536 } while (hasNext);
537
538 // delete buttons which are not used anymore
539 QLinkedList<UrlNavigatorButton*>::iterator itBegin = it;
540 while (it != itEnd) {
541 (*it)->close();
542 (*it)->deleteLater();
543 ++it;
544 }
545 m_navButtons.erase(itBegin, m_navButtons.end());
546 }
547
548 void UrlNavigator::Private::deleteButtons()
549 {
550 QLinkedList<UrlNavigatorButton*>::iterator itBegin = m_navButtons.begin();
551 QLinkedList<UrlNavigatorButton*>::iterator itEnd = m_navButtons.end();
552 QLinkedList<UrlNavigatorButton*>::iterator it = itBegin;
553 while (it != itEnd) {
554 (*it)->close();
555 (*it)->deleteLater();
556 ++it;
557 }
558 m_navButtons.erase(itBegin, itEnd);
559 }
560
561 ////
562
563
564 UrlNavigator::UrlNavigator(KBookmarkManager* bookmarkManager,
565 const KUrl& url,
566 QWidget* parent) :
567 QWidget(parent),
568 d( new Private(this, bookmarkManager) )
569 {
570 d->m_history.prepend(HistoryElem(url));
571
572 QFontMetrics fontMetrics(font());
573 setMinimumHeight(fontMetrics.height() + 10);
574
575 if (DolphinSettings::instance().generalSettings()->editableUrl()) {
576 d->m_toggleButton->toggle();
577 }
578
579 setLayout(d->m_layout);
580
581 d->updateContent();
582 }
583
584 UrlNavigator::~UrlNavigator()
585 {
586 delete d;
587 }
588
589 const KUrl& UrlNavigator::url() const
590 {
591 assert(!d->m_history.empty());
592 return d->m_history[d->m_historyIndex].url();
593 }
594
595 KUrl UrlNavigator::url(int index) const
596 {
597 assert(index >= 0);
598 // keep scheme, hostname etc. maybe we will need this in the future
599 // for e.g. browsing ftp repositories.
600 KUrl newurl(url());
601 newurl.setPath(QString());
602 QString path(url().path());
603
604 if (!path.isEmpty()) {
605 if (index == 0) //prevent the last "/" from being stripped
606 path = "/"; //or we end up with an empty path
607 else
608 path = path.section('/', 0, index);
609 }
610
611 newurl.setPath(path);
612 return newurl;
613 }
614
615 UrlNavigator::HistoryElem UrlNavigator::currentHistoryItem() const
616 {
617 return d->m_history[d->m_historyIndex];
618 }
619
620 int UrlNavigator::historySize() const
621 {
622 return d->m_history.count();
623 }
624
625 void UrlNavigator::goBack()
626 {
627 d->updateHistoryElem();
628
629 const int count = d->m_history.count();
630 if (d->m_historyIndex < count - 1) {
631 ++d->m_historyIndex;
632 d->updateContent();
633 emit urlChanged(url());
634 emit historyChanged();
635 }
636 }
637
638 void UrlNavigator::goForward()
639 {
640 if (d->m_historyIndex > 0) {
641 --d->m_historyIndex;
642 d->updateContent();
643 emit urlChanged(url());
644 emit historyChanged();
645 }
646 }
647
648 void UrlNavigator::goUp()
649 {
650 setUrl(url().upUrl());
651 }
652
653 void UrlNavigator::goHome()
654 {
655 setUrl(DolphinSettings::instance().generalSettings()->homeUrl());
656 }
657
658 bool UrlNavigator::isUrlEditable() const
659 {
660 return d->m_toggleButton->isChecked();
661 }
662
663 void UrlNavigator::editUrl(bool editOrBrowse)
664 {
665 d->setUrlEditable(editOrBrowse);
666 if (editOrBrowse) {
667 d->m_pathBox->setFocus();
668 }
669 }
670
671 void UrlNavigator::setActive(bool active)
672 {
673 if (active != d->m_active) {
674 d->m_active = active;
675 update();
676 if (active) {
677 emit activated();
678 }
679 }
680 }
681
682 void UrlNavigator::setShowHiddenFiles( bool show )
683 {
684 d->m_showHiddenFiles = show;
685 }
686
687 void UrlNavigator::dropUrls(const KUrl::List& urls,
688 const KUrl& destination)
689 {
690 emit urlsDropped(urls, destination);
691 }
692
693 void UrlNavigator::setUrl(const KUrl& url)
694 {
695 QString urlStr(url.pathOrUrl());
696
697 // TODO: a patch has been submitted by Filip Brcic which adjusts
698 // the URL for tar and zip files. See https://bugs.kde.org/show_bug.cgi?id=142781
699 // for details. The URL navigator part of the patch has not been committed yet,
700 // as the URL navigator will be subject of change and
701 // we might think of a more generic approach to check the protocol + MIME type for
702 // this use case.
703
704 //kDebug() << "setUrl(" << url << ")" << endl;
705 if ( urlStr.length() > 0 && urlStr.at(0) == '~') {
706 // replace '~' by the home directory
707 urlStr.remove(0, 1);
708 urlStr.insert(0, QDir::home().path());
709 }
710
711 const KUrl transformedUrl(urlStr);
712
713 if (d->m_historyIndex > 0) {
714 // Check whether the previous element of the history has the same Url.
715 // If yes, just go forward instead of inserting a duplicate history
716 // element.
717 HistoryElem& prevHistoryElem = d->m_history[d->m_historyIndex - 1];
718 if (transformedUrl == prevHistoryElem.url()) {
719 goForward();
720 // kDebug() << "goin' forward in history" << endl;
721 return;
722 }
723 }
724
725 if (this->url() == transformedUrl) {
726 // don't insert duplicate history elements
727 // kDebug() << "current url == transformedUrl" << endl;
728 return;
729 }
730
731 d->updateHistoryElem();
732 d->m_history.insert(d->m_historyIndex, HistoryElem(transformedUrl));
733
734 d->updateContent();
735
736 emit urlChanged(transformedUrl);
737 emit historyChanged();
738
739 // Prevent an endless growing of the history: remembering
740 // the last 100 Urls should be enough...
741 if (d->m_historyIndex > 100) {
742 d->m_history.removeFirst();
743 --d->m_historyIndex;
744 }
745
746 /* kDebug() << "history starting ====================" << endl;
747 int i = 0;
748 for (QValueListIterator<UrlNavigator::HistoryElem> it = d->m_history.begin();
749 it != d->m_history.end();
750 ++it, ++i)
751 {
752 kDebug() << i << ": " << (*it).url() << endl;
753 }
754 kDebug() << "history done ========================" << endl;*/
755
756 requestActivation();
757 }
758
759 void UrlNavigator::requestActivation()
760 {
761 setActive(true);
762 }
763
764 void UrlNavigator::storeContentsPosition(int x, int y)
765 {
766 HistoryElem& hist = d->m_history[d->m_historyIndex];
767 hist.setContentsX(x);
768 hist.setContentsY(y);
769 }
770
771 void UrlNavigator::keyReleaseEvent(QKeyEvent* event)
772 {
773 QWidget::keyReleaseEvent(event);
774 if (isUrlEditable() && (event->key() == Qt::Key_Escape)) {
775 d->setUrlEditable(false);
776 }
777 }
778
779 void UrlNavigator::mouseReleaseEvent(QMouseEvent* event)
780 {
781 if (event->button() == Qt::MidButton) {
782 QClipboard* clipboard = QApplication::clipboard();
783 const QMimeData* mimeData = clipboard->mimeData();
784 if (mimeData->hasText()) {
785 const QString text = mimeData->text();
786 setUrl(KUrl(text));
787 }
788 }
789 QWidget::mouseReleaseEvent(event);
790 }
791
792 bool UrlNavigator::isActive() const
793 {
794 return d->m_active;
795 }
796
797 bool UrlNavigator::showHiddenFiles() const
798 {
799 return d->m_showHiddenFiles;
800 }
801
802 #include "urlnavigator.moc"