]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
use KAction::setShortcut() instead of QAction::setShortcut()
[dolphin.git] / src / dolphinmainwindow.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
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 "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24 #include "dolphinremoteencoding.h"
25
26 #include <config-nepomuk.h>
27 #ifdef HAVE_NEPOMUK
28 #include "search/dolphinsearchoptionsconfigurator.h"
29 #endif
30
31 #include "dolphinapplication.h"
32 #include "dolphinnewmenu.h"
33 #include "search/dolphinsearchbox.h"
34 #include "settings/dolphinsettings.h"
35 #include "settings/dolphinsettingsdialog.h"
36 #include "dolphinviewcontainer.h"
37 #include "panels/folders/folderspanel.h"
38 #include "panels/places/placespanel.h"
39 #include "panels/information/informationpanel.h"
40 #include "mainwindowadaptor.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "viewproperties.h"
43
44 #ifndef Q_OS_WIN
45 #include "panels/terminal/terminalpanel.h"
46 #endif
47
48 #include "dolphin_generalsettings.h"
49 #include "dolphin_iconsmodesettings.h"
50 #include "draganddrophelper.h"
51
52 #include <kaction.h>
53 #include <kactioncollection.h>
54 #include <kconfig.h>
55 #include <kdesktopfile.h>
56 #include <kdeversion.h>
57 #include <kfiledialog.h>
58 #include <kfileplacesmodel.h>
59 #include <kglobal.h>
60 #include <klineedit.h>
61 #include <ktoolbar.h>
62 #include <kicon.h>
63 #include <kiconloader.h>
64 #include <kio/netaccess.h>
65 #include <kinputdialog.h>
66 #include <klocale.h>
67 #include <kprotocolmanager.h>
68 #include <kmenu.h>
69 #include <kmenubar.h>
70 #include <kmessagebox.h>
71 #include <kfileitemlistproperties.h>
72 #include <konqmimedata.h>
73 #include <kprotocolinfo.h>
74 #include <krun.h>
75 #include <kshell.h>
76 #include <kstandarddirs.h>
77 #include <kstatusbar.h>
78 #include <kstandardaction.h>
79 #include <ktabbar.h>
80 #include <ktoggleaction.h>
81 #include <kurlnavigator.h>
82 #include <kurl.h>
83 #include <kurlcombobox.h>
84 #include <ktoolinvocation.h>
85
86 #include <QDBusMessage>
87 #include <QKeyEvent>
88 #include <QClipboard>
89 #include <QSplitter>
90 #include <QDockWidget>
91 #include <kacceleratormanager.h>
92
93 /*
94 * Remembers the tab configuration if a tab has been closed.
95 * Each closed tab can be restored by the menu
96 * "Go -> Recently Closed Tabs".
97 */
98 struct ClosedTab
99 {
100 KUrl primaryUrl;
101 KUrl secondaryUrl;
102 bool isSplit;
103 };
104 Q_DECLARE_METATYPE(ClosedTab)
105
106 DolphinMainWindow::DolphinMainWindow(int id) :
107 KXmlGuiWindow(0),
108 m_newMenu(0),
109 m_showMenuBar(0),
110 m_tabBar(0),
111 m_activeViewContainer(0),
112 m_centralWidgetLayout(0),
113 m_searchBox(0),
114 #ifdef HAVE_NEPOMUK
115 m_searchOptionsConfigurator(0),
116 #endif
117 m_id(id),
118 m_tabIndex(0),
119 m_viewTab(),
120 m_actionHandler(0),
121 m_remoteEncoding(0),
122 m_settingsDialog(0)
123 {
124 setObjectName("Dolphin#");
125
126 m_viewTab.append(ViewTab());
127
128 new MainWindowAdaptor(this);
129 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
130
131 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
132 undoManager->setUiInterface(new UndoUiInterface());
133
134 connect(undoManager, SIGNAL(undoAvailable(bool)),
135 this, SLOT(slotUndoAvailable(bool)));
136 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
137 this, SLOT(slotUndoTextChanged(const QString&)));
138 connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
139 this, SLOT(clearStatusBar()));
140 connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
141 this, SLOT(showCommand(CommandType)));
142 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
143 this, SLOT(showErrorMessage(const QString&)));
144 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
145 this, SLOT(showErrorMessage(const QString&)));
146 }
147
148 DolphinMainWindow::~DolphinMainWindow()
149 {
150 DolphinApplication::app()->removeMainWindow(this);
151 }
152
153 void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
154 {
155 if (dirs.isEmpty()) {
156 return;
157 }
158
159 const int oldOpenTabsCount = m_viewTab.count();
160
161 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
162 const bool hasSplitView = generalSettings->splitView();
163
164 // Open each directory inside a new tab. If the "split view" option has been enabled,
165 // always show two directories within one tab.
166 QList<KUrl>::const_iterator it = dirs.begin();
167 while (it != dirs.end()) {
168 openNewTab(*it);
169 ++it;
170
171 if (hasSplitView && (it != dirs.end())) {
172 const int tabIndex = m_viewTab.count() - 1;
173 m_viewTab[tabIndex].secondaryView->setUrl(*it);
174 ++it;
175 }
176 }
177
178 // remove the previously opened tabs
179 for (int i = 0; i < oldOpenTabsCount; ++i) {
180 closeTab(0);
181 }
182 }
183
184 void DolphinMainWindow::openFiles(const QList<KUrl>& files)
185 {
186 if (files.isEmpty()) {
187 return;
188 }
189
190 // Get all distinct directories from 'files' and open a tab
191 // for each directory. If the "split view" option is enabled, two
192 // directories are shown inside one tab (see openDirectories()).
193 QList<KUrl> dirs;
194 foreach (const KUrl& url, files) {
195 const KUrl dir(url.directory());
196 if (!dirs.contains(dir)) {
197 dirs.append(dir);
198 }
199 }
200
201 openDirectories(dirs);
202
203 // Select the files. Although the files can be split between several
204 // tabs, there is no need to split 'files' accordingly, as
205 // the DolphinView will just ignore invalid selections.
206 const int tabCount = m_viewTab.count();
207 for (int i = 0; i < tabCount; ++i) {
208 m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
209 if (m_viewTab[i].secondaryView != 0) {
210 m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
211 }
212 }
213 }
214
215 void DolphinMainWindow::toggleViews()
216 {
217 if (m_viewTab[m_tabIndex].primaryView == 0) {
218 return;
219 }
220
221 // move secondary view from the last position of the splitter
222 // to the first position
223 m_viewTab[m_tabIndex].splitter->insertWidget(0, m_viewTab[m_tabIndex].secondaryView);
224
225 DolphinViewContainer* container = m_viewTab[m_tabIndex].primaryView;
226 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
227 m_viewTab[m_tabIndex].secondaryView = container;
228 }
229
230 void DolphinMainWindow::showCommand(CommandType command)
231 {
232 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
233 switch (command) {
234 case KIO::FileUndoManager::Copy:
235 statusBar->setMessage(i18nc("@info:status", "Successfully copied."),
236 DolphinStatusBar::OperationCompleted);
237 break;
238 case KIO::FileUndoManager::Move:
239 statusBar->setMessage(i18nc("@info:status", "Successfully moved."),
240 DolphinStatusBar::OperationCompleted);
241 break;
242 case KIO::FileUndoManager::Link:
243 statusBar->setMessage(i18nc("@info:status", "Successfully linked."),
244 DolphinStatusBar::OperationCompleted);
245 break;
246 case KIO::FileUndoManager::Trash:
247 statusBar->setMessage(i18nc("@info:status", "Successfully moved to trash."),
248 DolphinStatusBar::OperationCompleted);
249 break;
250 case KIO::FileUndoManager::Rename:
251 statusBar->setMessage(i18nc("@info:status", "Successfully renamed."),
252 DolphinStatusBar::OperationCompleted);
253 break;
254
255 case KIO::FileUndoManager::Mkdir:
256 statusBar->setMessage(i18nc("@info:status", "Created folder."),
257 DolphinStatusBar::OperationCompleted);
258 break;
259
260 default:
261 break;
262 }
263 }
264
265 void DolphinMainWindow::refreshViews()
266 {
267 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
268
269 // remember the current active view, as because of
270 // the refreshing the active view might change to
271 // the secondary view
272 DolphinViewContainer* activeViewContainer = m_activeViewContainer;
273
274 const int tabCount = m_viewTab.count();
275 for (int i = 0; i < tabCount; ++i) {
276 m_viewTab[i].primaryView->refresh();
277 if (m_viewTab[i].secondaryView != 0) {
278 m_viewTab[i].secondaryView->refresh();
279 }
280 }
281
282 setActiveViewContainer(activeViewContainer);
283 }
284
285 void DolphinMainWindow::pasteIntoFolder()
286 {
287 m_activeViewContainer->view()->pasteIntoFolder();
288 }
289
290 void DolphinMainWindow::changeUrl(const KUrl& url)
291 {
292 if (!KProtocolManager::supportsListing(url)) {
293 // The URL navigator only checks for validity, not
294 // if the URL can be listed. An error message is
295 // shown due to DolphinViewContainer::restoreView().
296 return;
297 }
298
299 DolphinViewContainer* view = activeViewContainer();
300 if (view != 0) {
301 view->setUrl(url);
302 updateEditActions();
303 updateViewActions();
304 updateGoActions();
305 setUrlAsCaption(url);
306 if (m_viewTab.count() > 1) {
307 m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(m_activeViewContainer->url())));
308 }
309 const QString iconName = KMimeType::iconNameForUrl(url);
310 m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName));
311 emit urlChanged(url);
312 }
313 }
314
315 void DolphinMainWindow::slotEditableStateChanged(bool editable)
316 {
317 KToggleAction* editableLocationAction =
318 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
319 editableLocationAction->setChecked(editable);
320 }
321
322 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
323 {
324 updateEditActions();
325
326 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
327 int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
328 if (m_viewTab[m_tabIndex].secondaryView != 0) {
329 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
330 }
331
332 QAction* compareFilesAction = actionCollection()->action("compare_files");
333 if (selectedUrlsCount == 2) {
334 compareFilesAction->setEnabled(isKompareInstalled());
335 } else {
336 compareFilesAction->setEnabled(false);
337 }
338
339 emit selectionChanged(selection);
340 }
341
342 void DolphinMainWindow::slotWheelMoved(int wheelDelta)
343 {
344 if (wheelDelta > 0) {
345 activatePrevTab();
346 } else {
347 activateNextTab();
348 }
349 }
350
351 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
352 {
353 emit requestItemInfo(item);
354 }
355
356 void DolphinMainWindow::updateHistory()
357 {
358 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
359 const int index = urlNavigator->historyIndex();
360
361 QAction* backAction = actionCollection()->action("go_back");
362 backAction->setToolTip(i18nc("@info", "Go back"));
363 if (backAction != 0) {
364 backAction->setEnabled(index < urlNavigator->historySize() - 1);
365 }
366
367 QAction* forwardAction = actionCollection()->action("go_forward");
368 forwardAction->setToolTip(i18nc("@info", "Go forward"));
369 if (forwardAction != 0) {
370 forwardAction->setEnabled(index > 0);
371 }
372 }
373
374 void DolphinMainWindow::updateFilterBarAction(bool show)
375 {
376 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
377 showFilterBarAction->setChecked(show);
378 }
379
380 void DolphinMainWindow::openNewMainWindow()
381 {
382 DolphinApplication::app()->createMainWindow()->show();
383 }
384
385 void DolphinMainWindow::openNewTab()
386 {
387 openNewTab(m_activeViewContainer->url());
388 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
389
390 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
391 if (navigator->isUrlEditable()) {
392 // if a new tab is opened and the URL is editable, assure that
393 // the user can edit the URL without manually setting the focus
394 navigator->setFocus();
395 }
396 }
397
398 void DolphinMainWindow::openNewTab(const KUrl& url)
399 {
400 QWidget* focusWidget = QApplication::focusWidget();
401
402 if (m_viewTab.count() == 1) {
403 // Only one view is open currently and hence no tab is shown at
404 // all. Before creating a tab for 'url', provide a tab for the current URL.
405 const KUrl currentUrl = m_activeViewContainer->url();
406 m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl)),
407 squeezedText(tabName(currentUrl)));
408 m_tabBar->blockSignals(false);
409 }
410
411 m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(url)),
412 squeezedText(tabName(url)));
413
414 ViewTab viewTab;
415 viewTab.splitter = new QSplitter(this);
416 viewTab.splitter->setChildrenCollapsible(false);
417 viewTab.primaryView = new DolphinViewContainer(this, viewTab.splitter, url);
418 viewTab.primaryView->setActive(false);
419 connectViewSignals(viewTab.primaryView);
420 viewTab.primaryView->view()->reload();
421
422 m_viewTab.append(viewTab);
423
424 actionCollection()->action("close_tab")->setEnabled(true);
425
426 // provide a split view, if the startup settings are set this way
427 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
428 if (generalSettings->splitView()) {
429 const int tabIndex = m_viewTab.count() - 1;
430 createSecondaryView(tabIndex);
431 m_viewTab[tabIndex].secondaryView->setActive(true);
432 m_viewTab[tabIndex].isPrimaryViewActive = false;
433 }
434
435 if (focusWidget != 0) {
436 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
437 // in background, assure that the previous focused widget gets the focus back.
438 focusWidget->setFocus();
439 }
440 }
441
442 void DolphinMainWindow::activateNextTab()
443 {
444 if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) {
445 return;
446 }
447
448 const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count();
449 m_tabBar->setCurrentIndex(tabIndex);
450 }
451
452 void DolphinMainWindow::activatePrevTab()
453 {
454 if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) {
455 return;
456 }
457
458 int tabIndex = m_tabBar->currentIndex() - 1;
459 if (tabIndex == -1) {
460 tabIndex = m_tabBar->count() - 1;
461 }
462 m_tabBar->setCurrentIndex(tabIndex);
463 }
464
465 void DolphinMainWindow::openInNewTab()
466 {
467 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
468 if ((list.count() == 1) && list[0].isDir()) {
469 openNewTab(m_activeViewContainer->view()->selectedUrls()[0]);
470 }
471 }
472
473 void DolphinMainWindow::openInNewWindow()
474 {
475 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
476 if ((list.count() == 1) && list[0].isDir()) {
477 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
478 window->changeUrl(m_activeViewContainer->view()->selectedUrls()[0]);
479 window->show();
480 }
481 }
482
483 void DolphinMainWindow::toggleActiveView()
484 {
485 if (m_viewTab[m_tabIndex].secondaryView == 0) {
486 // only one view is available
487 return;
488 }
489
490 Q_ASSERT(m_activeViewContainer != 0);
491 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
492
493 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
494 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
495 setActiveViewContainer(m_activeViewContainer == right ? left : right);
496 }
497
498 void DolphinMainWindow::showEvent(QShowEvent* event)
499 {
500 KXmlGuiWindow::showEvent(event);
501 if (!event->spontaneous()) {
502 m_activeViewContainer->view()->setFocus();
503 }
504 }
505
506 void DolphinMainWindow::closeEvent(QCloseEvent* event)
507 {
508 DolphinSettings& settings = DolphinSettings::instance();
509 GeneralSettings* generalSettings = settings.generalSettings();
510
511 // Find out if Dolphin is closed directly by the user or
512 // by the session manager because the session is closed
513 bool closedByUser = true;
514 DolphinApplication *application = qobject_cast<DolphinApplication*>(qApp);
515 if (application && application->sessionSaving()) {
516 closedByUser = false;
517 }
518
519 if ((m_viewTab.count() > 1) && generalSettings->confirmClosingMultipleTabs() && closedByUser) {
520 // Ask the user if he really wants to quit and close all tabs.
521 // Open a confirmation dialog with 3 buttons:
522 // KDialog::Yes -> Quit
523 // KDialog::No -> Close only the current tab
524 // KDialog::Cancel -> do nothing
525 KDialog *dialog = new KDialog(this, Qt::Dialog);
526 dialog->setCaption(i18nc("@title:window", "Confirmation"));
527 dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Cancel);
528 dialog->setModal(true);
529 dialog->showButtonSeparator(true);
530 dialog->setButtonGuiItem(KDialog::Yes, KStandardGuiItem::quit());
531 dialog->setButtonGuiItem(KDialog::No, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
532 dialog->setButtonGuiItem(KDialog::Cancel, KStandardGuiItem::cancel());
533 dialog->setDefaultButton(KDialog::Yes);
534
535 bool doNotAskAgainCheckboxResult = false;
536
537 const int result = KMessageBox::createKMessageBox(dialog,
538 QMessageBox::Warning,
539 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
540 QStringList(),
541 i18n("Do not ask again"),
542 &doNotAskAgainCheckboxResult,
543 KMessageBox::Notify);
544
545 if (doNotAskAgainCheckboxResult) {
546 generalSettings->setConfirmClosingMultipleTabs(false);
547 }
548
549 switch (result) {
550 case KDialog::Yes:
551 // Quit
552 break;
553 case KDialog::No:
554 // Close only the current tab
555 closeTab();
556 default:
557 event->ignore();
558 return;
559 }
560 }
561
562 generalSettings->setFirstRun(false);
563
564 settings.save();
565
566 KXmlGuiWindow::closeEvent(event);
567 }
568
569 void DolphinMainWindow::saveProperties(KConfigGroup& group)
570 {
571 const int tabCount = m_viewTab.count();
572 group.writeEntry("Tab Count", tabCount);
573 group.writeEntry("Active Tab Index", m_tabBar->currentIndex());
574
575 for (int i = 0; i < tabCount; ++i) {
576 const DolphinViewContainer* cont = m_viewTab[i].primaryView;
577 group.writeEntry(tabProperty("Primary URL", i), cont->url().url());
578 group.writeEntry(tabProperty("Primary Editable", i), cont->isUrlEditable());
579
580 cont = m_viewTab[i].secondaryView;
581 if (cont != 0) {
582 group.writeEntry(tabProperty("Secondary URL", i), cont->url().url());
583 group.writeEntry(tabProperty("Secondary Editable", i), cont->isUrlEditable());
584 }
585 }
586 }
587
588 void DolphinMainWindow::readProperties(const KConfigGroup& group)
589 {
590 const int tabCount = group.readEntry("Tab Count", 1);
591 for (int i = 0; i < tabCount; ++i) {
592 DolphinViewContainer* cont = m_viewTab[i].primaryView;
593
594 cont->setUrl(group.readEntry(tabProperty("Primary URL", i)));
595 const bool editable = group.readEntry(tabProperty("Primary Editable", i), false);
596 cont->urlNavigator()->setUrlEditable(editable);
597
598 cont = m_viewTab[i].secondaryView;
599 const QString secondaryUrl = group.readEntry(tabProperty("Secondary URL", i));
600 if (!secondaryUrl.isEmpty()) {
601 if (cont == 0) {
602 // a secondary view should be shown, but no one is available
603 // currently -> create a new view
604 toggleSplitView();
605 cont = m_viewTab[i].secondaryView;
606 Q_ASSERT(cont != 0);
607 }
608
609 cont->setUrl(secondaryUrl);
610 const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
611 cont->urlNavigator()->setUrlEditable(editable);
612 } else if (cont != 0) {
613 // no secondary view should be shown, but the default setting shows
614 // one already -> close the view
615 toggleSplitView();
616 }
617
618 // openNewTab() needs to be called only tabCount - 1 times
619 if (i != tabCount - 1) {
620 openNewTab();
621 }
622 }
623
624 const int index = group.readEntry("Active Tab Index", 0);
625 m_tabBar->setCurrentIndex(index);
626 }
627
628 void DolphinMainWindow::updateNewMenu()
629 {
630 m_newMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
631 m_newMenu->slotCheckUpToDate();
632 m_newMenu->setPopupFiles(activeViewContainer()->url());
633 }
634
635 void DolphinMainWindow::createDirectory()
636 {
637 m_newMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
638 m_newMenu->setPopupFiles(activeViewContainer()->url());
639 m_newMenu->createDirectory();
640 }
641
642 void DolphinMainWindow::quit()
643 {
644 close();
645 }
646
647 void DolphinMainWindow::showErrorMessage(const QString& message)
648 {
649 if (!message.isEmpty()) {
650 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
651 statusBar->setMessage(message, DolphinStatusBar::Error);
652 }
653 }
654
655 void DolphinMainWindow::slotUndoAvailable(bool available)
656 {
657 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
658 if (undoAction != 0) {
659 undoAction->setEnabled(available);
660 }
661 }
662
663 void DolphinMainWindow::restoreClosedTab(QAction* action)
664 {
665 if (action->data().toBool()) {
666 // clear all actions except the "Empty Recently Closed Tabs"
667 // action and the separator
668 QList<QAction*> actions = m_recentTabsMenu->menu()->actions();
669 const int count = actions.size();
670 for (int i = 2; i < count; ++i) {
671 m_recentTabsMenu->menu()->removeAction(actions.at(i));
672 }
673 } else {
674 const ClosedTab closedTab = action->data().value<ClosedTab>();
675 openNewTab(closedTab.primaryUrl);
676 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
677
678 if (closedTab.isSplit) {
679 // create secondary view
680 toggleSplitView();
681 m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
682 }
683
684 m_recentTabsMenu->removeAction(action);
685 }
686
687 if (m_recentTabsMenu->menu()->actions().count() == 2) {
688 m_recentTabsMenu->setEnabled(false);
689 }
690 }
691
692 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
693 {
694 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
695 if (undoAction != 0) {
696 undoAction->setText(text);
697 }
698 }
699
700 void DolphinMainWindow::undo()
701 {
702 clearStatusBar();
703 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
704 KIO::FileUndoManager::self()->undo();
705 }
706
707 void DolphinMainWindow::cut()
708 {
709 m_activeViewContainer->view()->cutSelectedItems();
710 }
711
712 void DolphinMainWindow::copy()
713 {
714 m_activeViewContainer->view()->copySelectedItems();
715 }
716
717 void DolphinMainWindow::paste()
718 {
719 m_activeViewContainer->view()->paste();
720 }
721
722 void DolphinMainWindow::updatePasteAction()
723 {
724 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
725 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
726 pasteAction->setEnabled(pasteInfo.first);
727 pasteAction->setText(pasteInfo.second);
728 }
729
730 void DolphinMainWindow::selectAll()
731 {
732 clearStatusBar();
733
734 // if the URL navigator is editable and focused, select the whole
735 // URL instead of all items of the view
736
737 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
738 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses
739 const bool selectUrl = urlNavigator->isUrlEditable() &&
740 lineEdit->hasFocus();
741 if (selectUrl) {
742 lineEdit->selectAll();
743 } else {
744 m_activeViewContainer->view()->selectAll();
745 }
746 }
747
748 void DolphinMainWindow::invertSelection()
749 {
750 clearStatusBar();
751 m_activeViewContainer->view()->invertSelection();
752 }
753
754 void DolphinMainWindow::toggleSplitView()
755 {
756 if (m_viewTab[m_tabIndex].secondaryView == 0) {
757 createSecondaryView(m_tabIndex);
758 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
759 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
760 // remove secondary view
761 m_viewTab[m_tabIndex].secondaryView->close();
762 m_viewTab[m_tabIndex].secondaryView->deleteLater();
763 m_viewTab[m_tabIndex].secondaryView = 0;
764
765 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
766 } else {
767 // The primary view is active and should be closed. Hence from a users point of view
768 // the content of the secondary view should be moved to the primary view.
769 // From an implementation point of view it is more efficient to close
770 // the primary view and exchange the internal pointers afterwards.
771
772 m_viewTab[m_tabIndex].primaryView->close();
773 m_viewTab[m_tabIndex].primaryView->deleteLater();
774 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
775 m_viewTab[m_tabIndex].secondaryView = 0;
776
777 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
778 }
779
780 updateViewActions();
781 }
782
783 void DolphinMainWindow::reloadView()
784 {
785 clearStatusBar();
786 m_activeViewContainer->view()->reload();
787 }
788
789 void DolphinMainWindow::stopLoading()
790 {
791 }
792
793 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
794 {
795 m_activeViewContainer->showFilterBar(show);
796 }
797
798 void DolphinMainWindow::toggleEditLocation()
799 {
800 clearStatusBar();
801
802 QAction* action = actionCollection()->action("editable_location");
803 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
804 urlNavigator->setUrlEditable(action->isChecked());
805 }
806
807 void DolphinMainWindow::replaceLocation()
808 {
809 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
810 navigator->setUrlEditable(true);
811 navigator->setFocus();
812
813 // select the whole text of the combo box editor
814 QLineEdit* lineEdit = navigator->editor()->lineEdit(); // krazy:exclude=qclasses
815 const QString text = lineEdit->text();
816 lineEdit->setSelection(0, text.length());
817 }
818
819 void DolphinMainWindow::goBack()
820 {
821 clearStatusBar();
822 m_activeViewContainer->urlNavigator()->goBack();
823 }
824
825 void DolphinMainWindow::goForward()
826 {
827 clearStatusBar();
828 m_activeViewContainer->urlNavigator()->goForward();
829 }
830
831 void DolphinMainWindow::goUp()
832 {
833 clearStatusBar();
834 m_activeViewContainer->urlNavigator()->goUp();
835 }
836
837 void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
838 {
839 // The default case (left button pressed) is handled in goBack().
840 if (buttons == Qt::MidButton) {
841 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
842 openNewTab(urlNavigator->historyUrl(urlNavigator->historyIndex() + 1));
843 }
844 }
845
846 void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
847 {
848 // The default case (left button pressed) is handled in goForward().
849 if (buttons == Qt::MidButton) {
850 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
851 openNewTab(urlNavigator->historyUrl(urlNavigator->historyIndex() - 1));
852 }
853 }
854
855 void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
856 {
857 // The default case (left button pressed) is handled in goUp().
858 if (buttons == Qt::MidButton) {
859 openNewTab(activeViewContainer()->url().upUrl());
860 }
861 }
862
863 void DolphinMainWindow::goHome()
864 {
865 clearStatusBar();
866 m_activeViewContainer->urlNavigator()->goHome();
867 }
868
869 void DolphinMainWindow::compareFiles()
870 {
871 // The method is only invoked if exactly 2 files have
872 // been selected. The selected files may be:
873 // - both in the primary view
874 // - both in the secondary view
875 // - one in the primary view and the other in the secondary
876 // view
877 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
878
879 KUrl urlA;
880 KUrl urlB;
881 KUrl::List urls = m_viewTab[m_tabIndex].primaryView->view()->selectedUrls();
882
883 switch (urls.count()) {
884 case 0: {
885 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
886 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
887 Q_ASSERT(urls.count() == 2);
888 urlA = urls[0];
889 urlB = urls[1];
890 break;
891 }
892
893 case 1: {
894 urlA = urls[0];
895 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
896 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
897 Q_ASSERT(urls.count() == 1);
898 urlB = urls[0];
899 break;
900 }
901
902 case 2: {
903 urlA = urls[0];
904 urlB = urls[1];
905 break;
906 }
907
908 default: {
909 // may not happen: compareFiles may only get invoked if 2
910 // files are selected
911 Q_ASSERT(false);
912 }
913 }
914
915 QString command("kompare -c \"");
916 command.append(urlA.pathOrUrl());
917 command.append("\" \"");
918 command.append(urlB.pathOrUrl());
919 command.append('\"');
920 KRun::runCommand(command, "Kompare", "kompare", this);
921 }
922
923 void DolphinMainWindow::toggleShowMenuBar()
924 {
925 const bool visible = menuBar()->isVisible();
926 menuBar()->setVisible(!visible);
927 }
928
929 void DolphinMainWindow::openTerminal()
930 {
931 QString dir(QDir::homePath());
932
933 // If the given directory is not local, it can still be the URL of an
934 // ioslave using UDS_LOCAL_PATH which to be converted first.
935 KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
936
937 //If the URL is local after the above conversion, set the directory.
938 if (url.isLocalFile()) {
939 dir = url.toLocalFile();
940 }
941
942 KToolInvocation::invokeTerminal(QString(), dir);
943 }
944
945 void DolphinMainWindow::editSettings()
946 {
947 if (m_settingsDialog == 0) {
948 const KUrl& url = activeViewContainer()->url();
949 m_settingsDialog = new DolphinSettingsDialog(url, this);
950 m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
951 m_settingsDialog->show();
952 } else {
953 m_settingsDialog->raise();
954 }
955 }
956
957 void DolphinMainWindow::setActiveTab(int index)
958 {
959 Q_ASSERT(index >= 0);
960 Q_ASSERT(index < m_viewTab.count());
961 if (index == m_tabIndex) {
962 return;
963 }
964
965 // hide current tab content
966 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
967 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
968 hiddenTab.primaryView->setActive(false);
969 if (hiddenTab.secondaryView != 0) {
970 hiddenTab.secondaryView->setActive(false);
971 }
972 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
973 splitter->hide();
974 m_centralWidgetLayout->removeWidget(splitter);
975
976 // show active tab content
977 m_tabIndex = index;
978
979 ViewTab& viewTab = m_viewTab[index];
980 m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
981 viewTab.primaryView->show();
982 if (viewTab.secondaryView != 0) {
983 viewTab.secondaryView->show();
984 }
985 viewTab.splitter->show();
986
987 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
988 viewTab.secondaryView);
989 }
990
991 void DolphinMainWindow::closeTab()
992 {
993 closeTab(m_tabBar->currentIndex());
994 }
995
996 void DolphinMainWindow::closeTab(int index)
997 {
998 Q_ASSERT(index >= 0);
999 Q_ASSERT(index < m_viewTab.count());
1000 if (m_viewTab.count() == 1) {
1001 // the last tab may never get closed
1002 return;
1003 }
1004
1005 if (index == m_tabIndex) {
1006 // The tab that should be closed is the active tab. Activate the
1007 // previous tab before closing the tab.
1008 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
1009 }
1010 rememberClosedTab(index);
1011
1012 // delete tab
1013 m_viewTab[index].primaryView->deleteLater();
1014 if (m_viewTab[index].secondaryView != 0) {
1015 m_viewTab[index].secondaryView->deleteLater();
1016 }
1017 m_viewTab[index].splitter->deleteLater();
1018 m_viewTab.erase(m_viewTab.begin() + index);
1019
1020 m_tabBar->blockSignals(true);
1021 m_tabBar->removeTab(index);
1022
1023 if (m_tabIndex > index) {
1024 m_tabIndex--;
1025 Q_ASSERT(m_tabIndex >= 0);
1026 }
1027
1028 // if only one tab is left, also remove the tab entry so that
1029 // closing the last tab is not possible
1030 if (m_viewTab.count() == 1) {
1031 m_tabBar->removeTab(0);
1032 actionCollection()->action("close_tab")->setEnabled(false);
1033 } else {
1034 m_tabBar->blockSignals(false);
1035 }
1036 }
1037
1038 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
1039 {
1040 KMenu menu(this);
1041
1042 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1043 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
1044
1045 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1046
1047 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1048 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
1049 QAction* selectedAction = menu.exec(pos);
1050 if (selectedAction == newTabAction) {
1051 const ViewTab& tab = m_viewTab[index];
1052 Q_ASSERT(tab.primaryView != 0);
1053 const KUrl url = (tab.secondaryView != 0) && tab.secondaryView->isActive() ?
1054 tab.secondaryView->url() : tab.primaryView->url();
1055 openNewTab(url);
1056 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1057 } else if (selectedAction == closeOtherTabsAction) {
1058 const int count = m_tabBar->count();
1059 for (int i = 0; i < index; ++i) {
1060 closeTab(0);
1061 }
1062 for (int i = index + 1; i < count; ++i) {
1063 closeTab(1);
1064 }
1065 } else if (selectedAction == closeTabAction) {
1066 closeTab(index);
1067 }
1068 }
1069
1070 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
1071 {
1072 if (buttons & Qt::MidButton) {
1073 openNewTab(url);
1074 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1075 } else {
1076 changeUrl(url);
1077 }
1078 }
1079
1080 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
1081 {
1082 canDecode = KUrl::List::canDecode(event->mimeData());
1083 }
1084
1085 void DolphinMainWindow::searchItems()
1086 {
1087 #ifdef HAVE_NEPOMUK
1088 const KUrl nepomukSearchUrl = m_searchOptionsConfigurator->nepomukSearchUrl();
1089 m_activeViewContainer->setUrl(nepomukSearchUrl);
1090 #endif
1091 }
1092
1093 void DolphinMainWindow::slotTabMoved(int from, int to)
1094 {
1095 m_viewTab.move(from, to);
1096 m_tabIndex = m_tabBar->currentIndex();
1097 }
1098
1099 void DolphinMainWindow::showSearchOptions()
1100 {
1101 #ifdef HAVE_NEPOMUK
1102 m_searchOptionsConfigurator->show();
1103 #endif
1104 }
1105
1106 void DolphinMainWindow::init()
1107 {
1108 DolphinSettings& settings = DolphinSettings::instance();
1109
1110 // Check whether Dolphin runs the first time. If yes then
1111 // a proper default window size is given at the end of DolphinMainWindow::init().
1112 GeneralSettings* generalSettings = settings.generalSettings();
1113 const bool firstRun = generalSettings->firstRun();
1114 if (firstRun) {
1115 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
1116 }
1117
1118 setAcceptDrops(true);
1119
1120 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
1121 m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
1122
1123 setupActions();
1124
1125 const KUrl& homeUrl = generalSettings->homeUrl();
1126 setUrlAsCaption(homeUrl);
1127 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
1128 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1129 connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
1130 ViewProperties props(homeUrl);
1131 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(this,
1132 m_viewTab[m_tabIndex].splitter,
1133 homeUrl);
1134
1135 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
1136 connectViewSignals(m_activeViewContainer);
1137 DolphinView* view = m_activeViewContainer->view();
1138 view->reload();
1139 m_activeViewContainer->show();
1140 m_actionHandler->setCurrentView(view);
1141
1142 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
1143 connect(this, SIGNAL(urlChanged(const KUrl&)),
1144 m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
1145
1146 #ifdef HAVE_NEPOMUK
1147 m_searchOptionsConfigurator = new DolphinSearchOptionsConfigurator(this);
1148 m_searchOptionsConfigurator->hide();
1149 connect(m_searchOptionsConfigurator, SIGNAL(searchOptionsChanged()),
1150 this, SLOT(searchItems()));
1151 connect(this, SIGNAL(urlChanged(KUrl)), m_searchOptionsConfigurator, SLOT(setDirectory(KUrl)));
1152 #endif
1153
1154 m_tabBar = new KTabBar(this);
1155 m_tabBar->setMovable(true);
1156 m_tabBar->setTabsClosable(true);
1157 connect(m_tabBar, SIGNAL(currentChanged(int)),
1158 this, SLOT(setActiveTab(int)));
1159 connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
1160 this, SLOT(closeTab(int)));
1161 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
1162 this, SLOT(openTabContextMenu(int, const QPoint&)));
1163 connect(m_tabBar, SIGNAL(newTabRequest()),
1164 this, SLOT(openNewTab()));
1165 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
1166 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
1167 connect(m_tabBar, SIGNAL(wheelDelta(int)),
1168 this, SLOT(slotWheelMoved(int)));
1169 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
1170 this, SLOT(closeTab(int)));
1171 connect(m_tabBar, SIGNAL(tabMoved(int, int)),
1172 this, SLOT(slotTabMoved(int, int)));
1173
1174 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1175
1176 QWidget* centralWidget = new QWidget(this);
1177 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
1178 m_centralWidgetLayout->setSpacing(0);
1179 m_centralWidgetLayout->setMargin(0);
1180 #ifdef HAVE_NEPOMUK
1181 m_centralWidgetLayout->addWidget(m_searchOptionsConfigurator);
1182 #endif
1183 m_centralWidgetLayout->addWidget(m_tabBar);
1184 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
1185
1186 setCentralWidget(centralWidget);
1187 setupDockWidgets();
1188 emit urlChanged(homeUrl);
1189
1190 setupGUI(Keys | Save | Create | ToolBar);
1191
1192 m_searchBox->setParent(toolBar("searchToolBar"));
1193 m_searchBox->show();
1194 connect(m_searchBox, SIGNAL(requestSearchOptions()),
1195 this, SLOT(showSearchOptions()));
1196 #ifdef HAVE_NEPOMUK
1197 connect(m_searchBox, SIGNAL(searchTextChanged(QString)),
1198 m_searchOptionsConfigurator, SLOT(setCustomSearchQuery(QString)));
1199 #endif
1200
1201 stateChanged("new_file");
1202
1203 QClipboard* clipboard = QApplication::clipboard();
1204 connect(clipboard, SIGNAL(dataChanged()),
1205 this, SLOT(updatePasteAction()));
1206 updatePasteAction();
1207 updateGoActions();
1208
1209 if (generalSettings->splitView()) {
1210 toggleSplitView();
1211 }
1212 updateViewActions();
1213
1214 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1215 showFilterBarAction->setChecked(generalSettings->filterBar());
1216
1217 if (firstRun) {
1218 // assure a proper default size if Dolphin runs the first time
1219 resize(750, 500);
1220 }
1221
1222 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1223 }
1224
1225 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
1226 {
1227 Q_ASSERT(viewContainer != 0);
1228 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
1229 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
1230 if (m_activeViewContainer == viewContainer) {
1231 return;
1232 }
1233
1234 m_activeViewContainer->setActive(false);
1235 m_activeViewContainer = viewContainer;
1236
1237 // Activating the view container might trigger a recursive setActiveViewContainer() call
1238 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1239 // disconnect the activated() signal in this case:
1240 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1241 m_activeViewContainer->setActive(true);
1242 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1243
1244 m_actionHandler->setCurrentView(viewContainer->view());
1245
1246 updateHistory();
1247 updateEditActions();
1248 updateViewActions();
1249 updateGoActions();
1250
1251 const KUrl& url = m_activeViewContainer->url();
1252 setUrlAsCaption(url);
1253 if (m_viewTab.count() > 1 && m_viewTab[m_tabIndex].secondaryView != 0) {
1254 m_tabBar->setTabText(m_tabIndex, tabName(url));
1255 m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
1256 }
1257
1258 emit urlChanged(url);
1259 }
1260
1261 void DolphinMainWindow::setupActions()
1262 {
1263 // setup 'File' menu
1264 m_newMenu = new DolphinNewMenu(this, this);
1265 KMenu* menu = m_newMenu->menu();
1266 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1267 menu->setIcon(KIcon("document-new"));
1268 connect(menu, SIGNAL(aboutToShow()),
1269 this, SLOT(updateNewMenu()));
1270
1271 KAction* newWindow = actionCollection()->addAction("new_window");
1272 newWindow->setIcon(KIcon("window-new"));
1273 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1274 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1275 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1276
1277 KAction* newTab = actionCollection()->addAction("new_tab");
1278 newTab->setIcon(KIcon("tab-new"));
1279 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1280 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1281 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1282
1283 KAction* closeTab = actionCollection()->addAction("close_tab");
1284 closeTab->setIcon(KIcon("tab-close"));
1285 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1286 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1287 closeTab->setEnabled(false);
1288 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1289
1290 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1291
1292 // setup 'Edit' menu
1293 KStandardAction::undo(this,
1294 SLOT(undo()),
1295 actionCollection());
1296
1297 // need to remove shift+del from cut action, else the shortcut for deletejob
1298 // doesn't work
1299 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1300 KShortcut cutShortcut = cut->shortcut();
1301 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
1302 cut->setShortcut(cutShortcut);
1303 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1304 KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
1305 // The text of the paste-action is modified dynamically by Dolphin
1306 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1307 // due to the long text, the text "Paste" is used:
1308 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1309
1310 KAction* selectAll = actionCollection()->addAction("select_all");
1311 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1312 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1313 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1314
1315 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1316 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1317 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1318 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1319
1320 // setup 'View' menu
1321 // (note that most of it is set up in DolphinViewActionHandler)
1322
1323 KAction* split = actionCollection()->addAction("split_view");
1324 split->setShortcut(Qt::Key_F3);
1325 updateSplitAction();
1326 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1327
1328 KAction* reload = actionCollection()->addAction("reload");
1329 reload->setText(i18nc("@action:inmenu View", "Reload"));
1330 reload->setShortcut(Qt::Key_F5);
1331 reload->setIcon(KIcon("view-refresh"));
1332 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1333
1334 KAction* stop = actionCollection()->addAction("stop");
1335 stop->setText(i18nc("@action:inmenu View", "Stop"));
1336 stop->setToolTip(i18nc("@info", "Stop loading"));
1337 stop->setIcon(KIcon("process-stop"));
1338 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1339
1340 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1341 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1342 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1343 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1344
1345 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1346 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1347 replaceLocation->setShortcut(Qt::Key_F6);
1348 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1349
1350 // setup 'Go' menu
1351 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1352 connect(backAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
1353 KShortcut backShortcut = backAction->shortcut();
1354 backShortcut.setAlternate(Qt::Key_Backspace);
1355 backAction->setShortcut(backShortcut);
1356
1357 m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
1358 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1359 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1360 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1361 this, SLOT(restoreClosedTab(QAction *)));
1362
1363 QAction* action = new QAction("Empty Recently Closed Tabs", m_recentTabsMenu);
1364 action->setIcon(KIcon("edit-clear-list"));
1365 action->setData(QVariant::fromValue(true));
1366 m_recentTabsMenu->addAction(action);
1367 m_recentTabsMenu->addSeparator();
1368 m_recentTabsMenu->setEnabled(false);
1369
1370 KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1371 connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
1372
1373 KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
1374 connect(upAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
1375
1376 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1377
1378 // setup 'Tools' menu
1379 KToggleAction* showSearchBar = actionCollection()->add<KToggleAction>("show_search_bar");
1380 showSearchBar->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1381 showSearchBar->setShortcut(Qt::CTRL | Qt::Key_S);
1382 connect(showSearchBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1383
1384 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1385 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1386 showFilterBar->setIcon(KIcon("view-filter"));
1387 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1388 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1389
1390 KAction* compareFiles = actionCollection()->addAction("compare_files");
1391 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1392 compareFiles->setIcon(KIcon("kompare"));
1393 compareFiles->setEnabled(false);
1394 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1395
1396 KAction* openTerminal = actionCollection()->addAction("open_terminal");
1397 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1398 openTerminal->setIcon(KIcon("utilities-terminal"));
1399 openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
1400 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1401
1402 // setup 'Settings' menu
1403 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1404 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1405
1406 // not in menu actions
1407 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1408 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1409 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1410 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1411 KStandardShortcut::tabNext());
1412
1413 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1414 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1415 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1416 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1417 KStandardShortcut::tabPrev());
1418
1419 // for context menu
1420 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1421 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1422 openInNewTab->setIcon(KIcon("tab-new"));
1423 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1424
1425 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1426 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1427 openInNewWindow->setIcon(KIcon("window-new"));
1428 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1429
1430 // 'Search' toolbar
1431 m_searchBox = new DolphinSearchBox(this);
1432 connect(m_searchBox, SIGNAL(search(QString)), this, SLOT(searchItems()));
1433
1434 KAction* search = new KAction(this);
1435 actionCollection()->addAction("search_bar", search);
1436 search->setText(i18nc("@action:inmenu", "Search Bar"));
1437 search->setDefaultWidget(m_searchBox);
1438 search->setShortcutConfigurable(false);
1439 }
1440
1441 void DolphinMainWindow::setupDockWidgets()
1442 {
1443 // setup "Information"
1444 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1445 infoDock->setObjectName("infoDock");
1446 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1447 Panel* infoPanel = new InformationPanel(infoDock);
1448 connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1449 infoDock->setWidget(infoPanel);
1450
1451 KAction* infoAction = new KAction(this);
1452 infoAction->setText(i18nc("@title:window", "Information"));
1453 infoAction->setShortcut(Qt::Key_F11);
1454 infoAction->setIcon(KIcon("dialog-information"));
1455 actionCollection()->addAction("show_info_panel", infoAction);
1456 connect(infoAction, SIGNAL(triggered()), infoDock->toggleViewAction(), SLOT(trigger()));
1457
1458 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1459 connect(this, SIGNAL(urlChanged(KUrl)),
1460 infoPanel, SLOT(setUrl(KUrl)));
1461 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1462 infoPanel, SLOT(setSelection(KFileItemList)));
1463 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1464 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1465
1466 // setup "Folders"
1467 QDockWidget* foldersDock = new QDockWidget(i18nc("@title:window", "Folders"));
1468 foldersDock->setObjectName("foldersDock");
1469 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1470 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1471 foldersDock->setWidget(foldersPanel);
1472
1473 KAction* foldersAction = new KAction(this);
1474 foldersAction->setText(i18nc("@title:window", "Folders"));
1475 foldersAction->setShortcut(Qt::Key_F7);
1476 foldersAction->setIcon(KIcon("folder"));
1477 actionCollection()->addAction("show_folders_panel", foldersAction);
1478 connect(foldersAction, SIGNAL(triggered()), foldersDock->toggleViewAction(), SLOT(trigger()));
1479
1480 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1481 connect(this, SIGNAL(urlChanged(KUrl)),
1482 foldersPanel, SLOT(setUrl(KUrl)));
1483 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1484 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1485
1486 // setup "Terminal"
1487 #ifndef Q_OS_WIN
1488 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1489 terminalDock->setObjectName("terminalDock");
1490 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1491 Panel* terminalPanel = new TerminalPanel(terminalDock);
1492 terminalDock->setWidget(terminalPanel);
1493
1494 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1495
1496 KAction* terminalAction = new KAction(this);
1497 terminalAction->setText(i18nc("@title:window Shell terminal", "Terminal"));
1498 terminalAction->setShortcut(Qt::Key_F4);
1499 terminalAction->setIcon(KIcon("utilities-terminal"));
1500 actionCollection()->addAction("show_terminal_panel", terminalAction);
1501 connect(terminalAction, SIGNAL(triggered()), terminalDock->toggleViewAction(), SLOT(trigger()));
1502
1503 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1504 connect(this, SIGNAL(urlChanged(KUrl)),
1505 terminalPanel, SLOT(setUrl(KUrl)));
1506 #endif
1507
1508 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1509 if (firstRun) {
1510 foldersDock->hide();
1511 #ifndef Q_OS_WIN
1512 terminalDock->hide();
1513 #endif
1514 }
1515
1516 // setup "Places"
1517 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1518 placesDock->setObjectName("placesDock");
1519 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1520
1521 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1522 placesDock->setWidget(placesPanel);
1523 placesPanel->setModel(DolphinSettings::instance().placesModel());
1524 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1525
1526 KAction* placesAction = new KAction(this);
1527 placesAction->setText(i18nc("@title:window", "Places"));
1528 placesAction->setShortcut(Qt::Key_F9);
1529 placesAction->setIcon(KIcon("bookmarks"));
1530 actionCollection()->addAction("show_places_panel", placesAction);
1531 connect(placesAction, SIGNAL(triggered()), placesDock->toggleViewAction(), SLOT(trigger()));
1532
1533 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1534 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1535 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1536 connect(this, SIGNAL(urlChanged(KUrl)),
1537 placesPanel, SLOT(setUrl(KUrl)));
1538 }
1539
1540 void DolphinMainWindow::updateEditActions()
1541 {
1542 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1543 if (list.isEmpty()) {
1544 stateChanged("has_no_selection");
1545 } else {
1546 stateChanged("has_selection");
1547
1548 KActionCollection* col = actionCollection();
1549 QAction* renameAction = col->action("rename");
1550 QAction* moveToTrashAction = col->action("move_to_trash");
1551 QAction* deleteAction = col->action("delete");
1552 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1553 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1554
1555 KFileItemListProperties capabilities(list);
1556 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1557
1558 renameAction->setEnabled(capabilities.supportsMoving());
1559 moveToTrashAction->setEnabled(enableMoveToTrash);
1560 deleteAction->setEnabled(capabilities.supportsDeleting());
1561 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1562 cutAction->setEnabled(capabilities.supportsMoving());
1563 }
1564 updatePasteAction();
1565 }
1566
1567 void DolphinMainWindow::updateViewActions()
1568 {
1569 m_actionHandler->updateViewActions();
1570
1571 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1572 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1573
1574 updateSplitAction();
1575
1576 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1577 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1578 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1579 }
1580
1581 void DolphinMainWindow::updateGoActions()
1582 {
1583 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1584 const KUrl& currentUrl = m_activeViewContainer->url();
1585 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1586 }
1587
1588 void DolphinMainWindow::rememberClosedTab(int index)
1589 {
1590 KMenu* tabsMenu = m_recentTabsMenu->menu();
1591
1592 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1593 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1594
1595 QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
1596
1597 ClosedTab closedTab;
1598 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1599
1600 if (m_viewTab[index].secondaryView != 0) {
1601 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1602 closedTab.isSplit = true;
1603 } else {
1604 closedTab.isSplit = false;
1605 }
1606
1607 action->setData(QVariant::fromValue(closedTab));
1608 action->setIcon(KIcon(iconName));
1609
1610 // add the closed tab menu entry after the separator and
1611 // "Empty Recently Closed Tabs" entry
1612 if (tabsMenu->actions().size() == 2) {
1613 tabsMenu->addAction(action);
1614 } else {
1615 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1616 }
1617
1618 // assure that only up to 8 closed tabs are shown in the menu
1619 if (tabsMenu->actions().size() > 8) {
1620 tabsMenu->removeAction(tabsMenu->actions().last());
1621 }
1622 actionCollection()->action("closed_tabs")->setEnabled(true);
1623 KAcceleratorManager::manage(tabsMenu);
1624 }
1625
1626 void DolphinMainWindow::clearStatusBar()
1627 {
1628 m_activeViewContainer->statusBar()->clear();
1629 }
1630
1631 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1632 {
1633 connect(container, SIGNAL(showFilterBarChanged(bool)),
1634 this, SLOT(updateFilterBarAction(bool)));
1635
1636 DolphinView* view = container->view();
1637 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1638 this, SLOT(slotSelectionChanged(KFileItemList)));
1639 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1640 this, SLOT(slotRequestItemInfo(KFileItem)));
1641 connect(view, SIGNAL(activated()),
1642 this, SLOT(toggleActiveView()));
1643 connect(view, SIGNAL(tabRequested(const KUrl&)),
1644 this, SLOT(openNewTab(const KUrl&)));
1645
1646 const KUrlNavigator* navigator = container->urlNavigator();
1647 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1648 this, SLOT(changeUrl(const KUrl&)));
1649 connect(navigator, SIGNAL(historyChanged()),
1650 this, SLOT(updateHistory()));
1651 connect(navigator, SIGNAL(editableStateChanged(bool)),
1652 this, SLOT(slotEditableStateChanged(bool)));
1653 }
1654
1655 void DolphinMainWindow::updateSplitAction()
1656 {
1657 QAction* splitAction = actionCollection()->action("split_view");
1658 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1659 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1660 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1661 splitAction->setToolTip(i18nc("@info", "Close right view"));
1662 splitAction->setIcon(KIcon("view-right-close"));
1663 } else {
1664 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1665 splitAction->setToolTip(i18nc("@info", "Close left view"));
1666 splitAction->setIcon(KIcon("view-left-close"));
1667 }
1668 } else {
1669 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1670 splitAction->setToolTip(i18nc("@info", "Split view"));
1671 splitAction->setIcon(KIcon("view-right-new"));
1672 }
1673 }
1674
1675 QString DolphinMainWindow::tabName(const KUrl& url) const
1676 {
1677 QString name;
1678 if (url.equals(KUrl("file:///"))) {
1679 name = '/';
1680 } else {
1681 name = url.fileName();
1682 if (name.isEmpty()) {
1683 name = url.protocol();
1684 } else {
1685 // Make sure that a '&' inside the directory name is displayed correctly
1686 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1687 name.replace('&', "&&");
1688 }
1689 }
1690 return name;
1691 }
1692
1693 bool DolphinMainWindow::isKompareInstalled() const
1694 {
1695 static bool initialized = false;
1696 static bool installed = false;
1697 if (!initialized) {
1698 // TODO: maybe replace this approach later by using a menu
1699 // plugin like kdiff3plugin.cpp
1700 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1701 initialized = true;
1702 }
1703 return installed;
1704 }
1705
1706 void DolphinMainWindow::createSecondaryView(int tabIndex)
1707 {
1708 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1709 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1710
1711 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1712 m_viewTab[tabIndex].secondaryView = new DolphinViewContainer(this, 0, view->rootUrl());
1713 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1714 splitter->setSizes(QList<int>() << newWidth << newWidth);
1715 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1716 m_viewTab[tabIndex].secondaryView->view()->reload();
1717 m_viewTab[tabIndex].secondaryView->setActive(false);
1718 m_viewTab[tabIndex].secondaryView->show();
1719 }
1720
1721 QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) const
1722 {
1723 return "Tab " + QString::number(tabIndex) + ' ' + property;
1724 }
1725
1726 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
1727 {
1728 QString caption;
1729 if (url.equals(KUrl("file:///"))) {
1730 caption = '/';
1731 } else {
1732 caption = url.fileName();
1733 if (caption.isEmpty()) {
1734 caption = url.protocol();
1735 }
1736 }
1737
1738 setCaption(caption);
1739 }
1740
1741 void DolphinMainWindow::handleUrl(const KUrl& url)
1742 {
1743 if (KProtocolManager::supportsListing(url)) {
1744 activeViewContainer()->setUrl(url);
1745 }
1746 else {
1747 new KRun(url, this);
1748 }
1749 }
1750
1751 QString DolphinMainWindow::squeezedText(const QString& text) const
1752 {
1753 const QFontMetrics fm = fontMetrics();
1754 return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
1755 }
1756
1757 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1758 KIO::FileUndoManager::UiInterface()
1759 {
1760 }
1761
1762 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1763 {
1764 }
1765
1766 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1767 {
1768 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1769 if (mainWin) {
1770 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1771 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1772 } else {
1773 KIO::FileUndoManager::UiInterface::jobError(job);
1774 }
1775 }
1776
1777 #include "dolphinmainwindow.moc"