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