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