]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Implemented (QTabBar based) DolphinTabBar class to encapsulate the tab bar handling...
[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 tabPage->setPlacesSelectorVisible(visible);
775 }
776 }
777
778 void DolphinMainWindow::goBack()
779 {
780 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
781 urlNavigator->goBack();
782
783 if (urlNavigator->locationState().isEmpty()) {
784 // An empty location state indicates a redirection URL,
785 // which must be skipped too
786 urlNavigator->goBack();
787 }
788 }
789
790 void DolphinMainWindow::goForward()
791 {
792 m_activeViewContainer->urlNavigator()->goForward();
793 }
794
795 void DolphinMainWindow::goUp()
796 {
797 m_activeViewContainer->urlNavigator()->goUp();
798 }
799
800 void DolphinMainWindow::goHome()
801 {
802 m_activeViewContainer->urlNavigator()->goHome();
803 }
804
805 void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
806 {
807 // The default case (left button pressed) is handled in goBack().
808 if (buttons == Qt::MidButton) {
809 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
810 const int index = urlNavigator->historyIndex() + 1;
811 openNewTab(urlNavigator->locationUrl(index));
812 }
813 }
814
815 void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
816 {
817 // The default case (left button pressed) is handled in goForward().
818 if (buttons == Qt::MidButton) {
819 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
820 const int index = urlNavigator->historyIndex() - 1;
821 openNewTab(urlNavigator->locationUrl(index));
822 }
823 }
824
825 void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
826 {
827 // The default case (left button pressed) is handled in goUp().
828 if (buttons == Qt::MidButton) {
829 openNewTab(activeViewContainer()->url().upUrl());
830 }
831 }
832
833 void DolphinMainWindow::goHome(Qt::MouseButtons buttons)
834 {
835 // The default case (left button pressed) is handled in goHome().
836 if (buttons == Qt::MidButton) {
837 openNewTab(GeneralSettings::self()->homeUrl());
838 }
839 }
840
841 void DolphinMainWindow::compareFiles()
842 {
843 const KFileItemList items = m_viewTab.at(m_tabIndex)->selectedItems();
844 if (items.count() != 2) {
845 // The action is disabled in this case, but it could have been triggered
846 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
847 return;
848 }
849
850 KUrl urlA = items.at(0).url();
851 KUrl urlB = items.at(1).url();
852
853 QString command("kompare -c \"");
854 command.append(urlA.pathOrUrl());
855 command.append("\" \"");
856 command.append(urlB.pathOrUrl());
857 command.append('\"');
858 KRun::runCommand(command, "Kompare", "kompare", this);
859 }
860
861 void DolphinMainWindow::toggleShowMenuBar()
862 {
863 const bool visible = menuBar()->isVisible();
864 menuBar()->setVisible(!visible);
865 if (visible) {
866 createControlButton();
867 } else {
868 deleteControlButton();
869 }
870 }
871
872 void DolphinMainWindow::openTerminal()
873 {
874 QString dir(QDir::homePath());
875
876 // If the given directory is not local, it can still be the URL of an
877 // ioslave using UDS_LOCAL_PATH which to be converted first.
878 KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
879
880 //If the URL is local after the above conversion, set the directory.
881 if (url.isLocalFile()) {
882 dir = url.toLocalFile();
883 }
884
885 KToolInvocation::invokeTerminal(QString(), dir);
886 }
887
888 void DolphinMainWindow::editSettings()
889 {
890 if (!m_settingsDialog) {
891 DolphinViewContainer* container = activeViewContainer();
892 container->view()->writeSettings();
893
894 const KUrl url = container->url();
895 DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
896 connect(settingsDialog, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
897 settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
898 settingsDialog->show();
899 m_settingsDialog = settingsDialog;
900 } else {
901 m_settingsDialog.data()->raise();
902 }
903 }
904
905 void DolphinMainWindow::setActiveTab(int index)
906 {
907 Q_ASSERT(index >= 0);
908 Q_ASSERT(index < m_viewTab.count());
909 if (index == m_tabIndex) {
910 return;
911 }
912
913 m_tabBar->setCurrentIndex(index);
914
915 // hide current tab content
916 if (m_tabIndex >= 0) {
917 DolphinTabPage* hiddenTabPage = m_viewTab.at(m_tabIndex);
918 hiddenTabPage->hide();
919 m_centralWidgetLayout->removeWidget(hiddenTabPage);
920 }
921
922 // show active tab content
923 m_tabIndex = index;
924
925 DolphinTabPage* tabPage = m_viewTab.at(index);
926 m_centralWidgetLayout->addWidget(tabPage, 1);
927 tabPage->show();
928
929 setActiveViewContainer(tabPage->activeViewContainer());
930 }
931
932 void DolphinMainWindow::closeTab()
933 {
934 closeTab(m_tabBar->currentIndex());
935 }
936
937 void DolphinMainWindow::closeTab(int index)
938 {
939 Q_ASSERT(index >= 0);
940 Q_ASSERT(index < m_viewTab.count());
941 if (m_viewTab.count() == 1) {
942 // the last tab may never get closed
943 return;
944 }
945
946 if (index == m_tabIndex) {
947 // The tab that should be closed is the active tab. Activate the
948 // previous tab before closing the tab.
949 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
950 }
951
952 DolphinTabPage* tabPage = m_viewTab.at(index);
953
954 if (tabPage->splitViewEnabled()) {
955 emit rememberClosedTab(tabPage->primaryViewContainer()->url(),
956 tabPage->secondaryViewContainer()->url());
957 } else {
958 emit rememberClosedTab(tabPage->primaryViewContainer()->url(), KUrl());
959 }
960
961 // delete tab
962 m_viewTab.removeAt(index);
963 tabPage->deleteLater();
964
965 m_tabBar->blockSignals(true);
966 m_tabBar->removeTab(index);
967
968 if (m_tabIndex > index) {
969 m_tabIndex--;
970 Q_ASSERT(m_tabIndex >= 0);
971 }
972
973 // if only one tab is left, also remove the tab entry so that
974 // closing the last tab is not possible
975 if (m_viewTab.count() < 2) {
976 actionCollection()->action("close_tab")->setEnabled(false);
977 actionCollection()->action("activate_prev_tab")->setEnabled(false);
978 actionCollection()->action("activate_next_tab")->setEnabled(false);
979 m_tabBar->hide();
980 } else {
981 m_tabBar->blockSignals(false);
982 }
983 }
984
985 void DolphinMainWindow::detachTab(int index)
986 {
987 Q_ASSERT(index >= 0);
988
989 const QString separator(QLatin1Char(' '));
990 QString command = QLatin1String("dolphin");
991
992 const DolphinTabPage* tabPage = m_viewTab.at(index);
993 command += separator + tabPage->primaryViewContainer()->url().url();
994 if (tabPage->splitViewEnabled()) {
995 command += separator + tabPage->secondaryViewContainer()->url().url();
996 command += separator + QLatin1String("-split");
997 }
998
999 KRun::runCommand(command, this);
1000
1001 closeTab(index);
1002 }
1003
1004 void DolphinMainWindow::slotTabMoved(int from, int to)
1005 {
1006 m_viewTab.move(from, to);
1007 m_tabIndex = m_tabBar->currentIndex();
1008 }
1009
1010 void DolphinMainWindow::handleUrl(const KUrl& url)
1011 {
1012 delete m_lastHandleUrlStatJob;
1013 m_lastHandleUrlStatJob = 0;
1014
1015 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1016 activeViewContainer()->setUrl(url);
1017 } else if (KProtocolManager::supportsListing(url)) {
1018 // stat the URL to see if it is a dir or not
1019 m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
1020 if (m_lastHandleUrlStatJob->ui()) {
1021 m_lastHandleUrlStatJob->ui()->setWindow(this);
1022 }
1023 connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
1024 this, SLOT(slotHandleUrlStatFinished(KJob*)));
1025
1026 } else {
1027 new KRun(url, this); // Automatically deletes itself after being finished
1028 }
1029 }
1030
1031 void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
1032 {
1033 m_lastHandleUrlStatJob = 0;
1034 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
1035 const KUrl url = static_cast<KIO::StatJob*>(job)->url();
1036 if (entry.isDir()) {
1037 activeViewContainer()->setUrl(url);
1038 } else {
1039 new KRun(url, this); // Automatically deletes itself after being finished
1040 }
1041 }
1042
1043 void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
1044 {
1045 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
1046 if (!urls.isEmpty() && tab != -1) {
1047 const DolphinView* view = m_viewTab.at(tab)->activeViewContainer()->view();
1048
1049 QString error;
1050 DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event, error);
1051 if (!error.isEmpty()) {
1052 activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
1053 }
1054 }
1055 }
1056
1057 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1058 {
1059 newFileMenu()->setEnabled(isFolderWritable);
1060 }
1061
1062 void DolphinMainWindow::openContextMenu(const QPoint& pos,
1063 const KFileItem& item,
1064 const KUrl& url,
1065 const QList<QAction*>& customActions)
1066 {
1067 QWeakPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, pos, item, url);
1068 contextMenu.data()->setCustomActions(customActions);
1069 const DolphinContextMenu::Command command = contextMenu.data()->open();
1070
1071 switch (command) {
1072 case DolphinContextMenu::OpenParentFolderInNewWindow: {
1073 KRun::run("dolphin %u", KUrl::List() << item.url().upUrl(), this);
1074 break;
1075 }
1076
1077 case DolphinContextMenu::OpenParentFolderInNewTab:
1078 openNewTab(item.url().upUrl());
1079 break;
1080
1081 case DolphinContextMenu::None:
1082 default:
1083 break;
1084 }
1085
1086 delete contextMenu.data();
1087 }
1088
1089 void DolphinMainWindow::updateControlMenu()
1090 {
1091 KMenu* menu = qobject_cast<KMenu*>(sender());
1092 Q_ASSERT(menu);
1093
1094 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1095 // by connecting to the aboutToHide() signal from the parent-menu.
1096 menu->clear();
1097
1098 KActionCollection* ac = actionCollection();
1099
1100 // Add "Edit" actions
1101 bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) |
1102 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Find)), menu) |
1103 addActionToMenu(ac->action("select_all"), menu) |
1104 addActionToMenu(ac->action("invert_selection"), menu);
1105
1106 if (added) {
1107 menu->addSeparator();
1108 }
1109
1110 // Add "View" actions
1111 if (!GeneralSettings::showZoomSlider()) {
1112 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomIn)), menu);
1113 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomOut)), menu);
1114 menu->addSeparator();
1115 }
1116
1117 added = addActionToMenu(ac->action("view_mode"), menu) |
1118 addActionToMenu(ac->action("sort"), menu) |
1119 addActionToMenu(ac->action("additional_info"), menu) |
1120 addActionToMenu(ac->action("show_preview"), menu) |
1121 addActionToMenu(ac->action("show_in_groups"), menu) |
1122 addActionToMenu(ac->action("show_hidden_files"), menu);
1123
1124 if (added) {
1125 menu->addSeparator();
1126 }
1127
1128 added = addActionToMenu(ac->action("split_view"), menu) |
1129 addActionToMenu(ac->action("reload"), menu) |
1130 addActionToMenu(ac->action("view_properties"), menu);
1131 if (added) {
1132 menu->addSeparator();
1133 }
1134
1135 addActionToMenu(ac->action("panels"), menu);
1136 KMenu* locationBarMenu = new KMenu(i18nc("@action:inmenu", "Location Bar"), menu);
1137 locationBarMenu->addAction(ac->action("editable_location"));
1138 locationBarMenu->addAction(ac->action("replace_location"));
1139 menu->addMenu(locationBarMenu);
1140
1141 menu->addSeparator();
1142
1143 // Add "Go" menu
1144 KMenu* goMenu = new KMenu(i18nc("@action:inmenu", "Go"), menu);
1145 connect(menu, SIGNAL(aboutToHide()), goMenu, SLOT(deleteLater()));
1146 goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Back)));
1147 goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Forward)));
1148 goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Up)));
1149 goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Home)));
1150 goMenu->addAction(ac->action("closed_tabs"));
1151 menu->addMenu(goMenu);
1152
1153 // Add "Tool" menu
1154 KMenu* toolsMenu = new KMenu(i18nc("@action:inmenu", "Tools"), menu);
1155 connect(menu, SIGNAL(aboutToHide()), toolsMenu, SLOT(deleteLater()));
1156 toolsMenu->addAction(ac->action("show_filter_bar"));
1157 toolsMenu->addAction(ac->action("compare_files"));
1158 toolsMenu->addAction(ac->action("open_terminal"));
1159 toolsMenu->addAction(ac->action("change_remote_encoding"));
1160 menu->addMenu(toolsMenu);
1161
1162 // Add "Settings" menu entries
1163 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::KeyBindings)), menu);
1164 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)), menu);
1165 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Preferences)), menu);
1166
1167 // Add "Help" menu
1168 KMenu* helpMenu = new KMenu(i18nc("@action:inmenu", "Help"), menu);
1169 connect(menu, SIGNAL(aboutToHide()), helpMenu, SLOT(deleteLater()));
1170 helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::HelpContents)));
1171 helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::WhatsThis)));
1172 helpMenu->addSeparator();
1173 helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::ReportBug)));
1174 helpMenu->addSeparator();
1175 helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage)));
1176 helpMenu->addSeparator();
1177 helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::AboutApp)));
1178 helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::AboutKDE)));
1179 menu->addMenu(helpMenu);
1180
1181 menu->addSeparator();
1182 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)), menu);
1183 }
1184
1185 void DolphinMainWindow::updateToolBar()
1186 {
1187 if (!menuBar()->isVisible()) {
1188 createControlButton();
1189 }
1190 }
1191
1192 void DolphinMainWindow::slotControlButtonDeleted()
1193 {
1194 m_controlButton = 0;
1195 m_updateToolBarTimer->start();
1196 }
1197
1198 void DolphinMainWindow::slotPanelErrorMessage(const QString& error)
1199 {
1200 activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
1201 }
1202
1203 void DolphinMainWindow::slotPlaceActivated(const KUrl& url)
1204 {
1205 DolphinViewContainer* view = activeViewContainer();
1206
1207 if (view->url() == url) {
1208 // We can end up here if the user clicked a device in the Places Panel
1209 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1210 reloadView();
1211 } else {
1212 changeUrl(url);
1213 }
1214 }
1215
1216 void DolphinMainWindow::activeViewChanged()
1217 {
1218 const DolphinTabPage* tabPage = m_viewTab.at(m_tabIndex);
1219 setActiveViewContainer(tabPage->activeViewContainer());
1220 }
1221
1222 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
1223 {
1224 Q_ASSERT(viewContainer);
1225 Q_ASSERT((viewContainer == m_viewTab.at(m_tabIndex)->primaryViewContainer()) ||
1226 (viewContainer == m_viewTab.at(m_tabIndex)->secondaryViewContainer()));
1227 if (m_activeViewContainer == viewContainer) {
1228 return;
1229 }
1230
1231 m_activeViewContainer = viewContainer;
1232 m_actionHandler->setCurrentView(viewContainer->view());
1233
1234 updateHistory();
1235 updateEditActions();
1236 updatePasteAction();
1237 updateViewActions();
1238 updateGoActions();
1239
1240 const KUrl url = m_activeViewContainer->url();
1241 setUrlAsCaption(url);
1242 m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(url)));
1243 m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
1244
1245 emit urlChanged(url);
1246 }
1247
1248 void DolphinMainWindow::setupActions()
1249 {
1250 // setup 'File' menu
1251 m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
1252 KMenu* menu = m_newFileMenu->menu();
1253 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1254 menu->setIcon(KIcon("document-new"));
1255 m_newFileMenu->setDelayed(false);
1256 connect(menu, SIGNAL(aboutToShow()),
1257 this, SLOT(updateNewMenu()));
1258
1259 KAction* newWindow = actionCollection()->addAction("new_window");
1260 newWindow->setIcon(KIcon("window-new"));
1261 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1262 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1263 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1264
1265 KAction* newTab = actionCollection()->addAction("new_tab");
1266 newTab->setIcon(KIcon("tab-new"));
1267 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1268 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1269 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1270
1271 KAction* closeTab = actionCollection()->addAction("close_tab");
1272 closeTab->setIcon(KIcon("tab-close"));
1273 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1274 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1275 closeTab->setEnabled(false);
1276 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1277
1278 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1279
1280 // setup 'Edit' menu
1281 KStandardAction::undo(this,
1282 SLOT(undo()),
1283 actionCollection());
1284
1285 // need to remove shift+del from cut action, else the shortcut for deletejob
1286 // doesn't work
1287 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1288 KShortcut cutShortcut = cut->shortcut();
1289 cutShortcut.remove(Qt::SHIFT | Qt::Key_Delete, KShortcut::KeepEmpty);
1290 cut->setShortcut(cutShortcut);
1291 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1292 KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
1293 // The text of the paste-action is modified dynamically by Dolphin
1294 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1295 // due to the long text, the text "Paste" is used:
1296 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1297
1298 KStandardAction::find(this, SLOT(find()), actionCollection());
1299
1300 KAction* selectAll = actionCollection()->addAction("select_all");
1301 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1302 selectAll->setShortcut(Qt::CTRL | Qt::Key_A);
1303 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1304
1305 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1306 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1307 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1308 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1309
1310 // setup 'View' menu
1311 // (note that most of it is set up in DolphinViewActionHandler)
1312
1313 KAction* split = actionCollection()->addAction("split_view");
1314 split->setShortcut(Qt::Key_F3);
1315 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1316
1317 KAction* reload = actionCollection()->addAction("reload");
1318 reload->setText(i18nc("@action:inmenu View", "Reload"));
1319 reload->setShortcut(Qt::Key_F5);
1320 reload->setIcon(KIcon("view-refresh"));
1321 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1322
1323 KAction* stop = actionCollection()->addAction("stop");
1324 stop->setText(i18nc("@action:inmenu View", "Stop"));
1325 stop->setToolTip(i18nc("@info", "Stop loading"));
1326 stop->setIcon(KIcon("process-stop"));
1327 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1328
1329 KToggleAction* editableLocation = actionCollection()->add<KToggleAction>("editable_location");
1330 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1331 editableLocation->setShortcut(Qt::Key_F6);
1332 connect(editableLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1333
1334 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1335 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1336 replaceLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1337 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1338
1339 // setup 'Go' menu
1340 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1341 connect(backAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
1342 KShortcut backShortcut = backAction->shortcut();
1343 backShortcut.setAlternate(Qt::Key_Backspace);
1344 backAction->setShortcut(backShortcut);
1345
1346 DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
1347 actionCollection()->addAction("closed_tabs", recentTabsMenu);
1348 connect(this, SIGNAL(rememberClosedTab(KUrl,KUrl)),
1349 recentTabsMenu, SLOT(rememberClosedTab(KUrl,KUrl)));
1350 connect(recentTabsMenu, SIGNAL(restoreClosedTab(KUrl,KUrl)),
1351 this, SLOT(openNewActivatedTab(KUrl,KUrl)));
1352
1353 KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1354 connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
1355
1356 KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
1357 connect(upAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
1358
1359 KAction* homeAction = KStandardAction::home(this, SLOT(goHome()), actionCollection());
1360 connect(homeAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goHome(Qt::MouseButtons)));
1361
1362 // setup 'Tools' menu
1363 KAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
1364 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1365 showFilterBar->setIcon(KIcon("view-filter"));
1366 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1367 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1368
1369 KAction* compareFiles = actionCollection()->addAction("compare_files");
1370 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1371 compareFiles->setIcon(KIcon("kompare"));
1372 compareFiles->setEnabled(false);
1373 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1374
1375 KAction* openTerminal = actionCollection()->addAction("open_terminal");
1376 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1377 openTerminal->setIcon(KIcon("utilities-terminal"));
1378 openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
1379 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1380
1381 // setup 'Settings' menu
1382 KToggleAction* showMenuBar = KStandardAction::showMenubar(0, 0, actionCollection());
1383 connect(showMenuBar, SIGNAL(triggered(bool)), // Fixes #286822
1384 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection);
1385 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1386
1387 // not in menu actions
1388 QList<QKeySequence> nextTabKeys;
1389 nextTabKeys.append(KStandardShortcut::tabNext().primary());
1390 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
1391
1392 QList<QKeySequence> prevTabKeys;
1393 prevTabKeys.append(KStandardShortcut::tabPrev().primary());
1394 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
1395
1396 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1397 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
1398 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1399 activateNextTab->setEnabled(false);
1400 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1401 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
1402
1403 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1404 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1405 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1406 activatePrevTab->setEnabled(false);
1407 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1408 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
1409
1410 // for context menu
1411 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1412 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1413 openInNewTab->setIcon(KIcon("tab-new"));
1414 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1415
1416 KAction* openInNewTabs = actionCollection()->addAction("open_in_new_tabs");
1417 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1418 openInNewTabs->setIcon(KIcon("tab-new"));
1419 connect(openInNewTabs, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1420
1421 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1422 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1423 openInNewWindow->setIcon(KIcon("window-new"));
1424 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1425 }
1426
1427 void DolphinMainWindow::setupDockWidgets()
1428 {
1429 const bool lock = GeneralSettings::lockPanels();
1430
1431 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>("lock_panels");
1432 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1433 lockLayoutAction->setActiveIcon(KIcon("object-unlocked"));
1434 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1435 lockLayoutAction->setInactiveIcon(KIcon("object-locked"));
1436 lockLayoutAction->setActive(lock);
1437 connect(lockLayoutAction, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1438
1439 // Setup "Information"
1440 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
1441 infoDock->setLocked(lock);
1442 infoDock->setObjectName("infoDock");
1443 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1444 Panel* infoPanel = new InformationPanel(infoDock);
1445 infoPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1446 connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1447 infoDock->setWidget(infoPanel);
1448
1449 QAction* infoAction = infoDock->toggleViewAction();
1450 createPanelAction(KIcon("dialog-information"), Qt::Key_F11, infoAction, "show_information_panel");
1451
1452 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1453 connect(this, SIGNAL(urlChanged(KUrl)),
1454 infoPanel, SLOT(setUrl(KUrl)));
1455 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1456 infoPanel, SLOT(setSelection(KFileItemList)));
1457 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1458 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1459
1460 // Setup "Folders"
1461 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
1462 foldersDock->setLocked(lock);
1463 foldersDock->setObjectName("foldersDock");
1464 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1465 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1466 foldersPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1467 foldersDock->setWidget(foldersPanel);
1468
1469 QAction* foldersAction = foldersDock->toggleViewAction();
1470 createPanelAction(KIcon("folder"), Qt::Key_F7, foldersAction, "show_folders_panel");
1471
1472 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1473 connect(this, SIGNAL(urlChanged(KUrl)),
1474 foldersPanel, SLOT(setUrl(KUrl)));
1475 connect(foldersPanel, SIGNAL(folderActivated(KUrl)),
1476 this, SLOT(changeUrl(KUrl)));
1477 connect(foldersPanel, SIGNAL(folderMiddleClicked(KUrl)),
1478 this, SLOT(openNewTab(KUrl)));
1479 connect(foldersPanel, SIGNAL(errorMessage(QString)),
1480 this, SLOT(slotPanelErrorMessage(QString)));
1481
1482 // Setup "Terminal"
1483 #ifndef Q_OS_WIN
1484 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1485 terminalDock->setLocked(lock);
1486 terminalDock->setObjectName("terminalDock");
1487 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1488 Panel* terminalPanel = new TerminalPanel(terminalDock);
1489 terminalPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1490 terminalDock->setWidget(terminalPanel);
1491
1492 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1493 connect(terminalPanel, SIGNAL(changeUrl(KUrl)), this, SLOT(slotTerminalDirectoryChanged(KUrl)));
1494 connect(terminalDock, SIGNAL(visibilityChanged(bool)),
1495 terminalPanel, SLOT(dockVisibilityChanged()));
1496
1497 QAction* terminalAction = terminalDock->toggleViewAction();
1498 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4, terminalAction, "show_terminal_panel");
1499
1500 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1501 connect(this, SIGNAL(urlChanged(KUrl)),
1502 terminalPanel, SLOT(setUrl(KUrl)));
1503 #endif
1504
1505 if (GeneralSettings::version() < 200) {
1506 infoDock->hide();
1507 foldersDock->hide();
1508 #ifndef Q_OS_WIN
1509 terminalDock->hide();
1510 #endif
1511 }
1512
1513 // Setup "Places"
1514 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
1515 placesDock->setLocked(lock);
1516 placesDock->setObjectName("placesDock");
1517 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1518
1519 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1520 placesPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1521 placesDock->setWidget(placesPanel);
1522
1523 QAction* placesAction = placesDock->toggleViewAction();
1524 createPanelAction(KIcon("bookmarks"), Qt::Key_F9, placesAction, "show_places_panel");
1525
1526 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1527 connect(placesPanel, SIGNAL(placeActivated(KUrl)),
1528 this, SLOT(slotPlaceActivated(KUrl)));
1529 connect(placesPanel, SIGNAL(placeMiddleClicked(KUrl)),
1530 this, SLOT(openNewTab(KUrl)));
1531 connect(placesPanel, SIGNAL(errorMessage(QString)),
1532 this, SLOT(slotPanelErrorMessage(QString)));
1533 connect(this, SIGNAL(urlChanged(KUrl)),
1534 placesPanel, SLOT(setUrl(KUrl)));
1535 connect(placesDock, SIGNAL(visibilityChanged(bool)),
1536 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1537 connect(this, SIGNAL(settingsChanged()),
1538 placesPanel, SLOT(readSettings()));
1539
1540 // Add actions into the "Panels" menu
1541 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1542 actionCollection()->addAction("panels", panelsMenu);
1543 panelsMenu->setDelayed(false);
1544 const KActionCollection* ac = actionCollection();
1545 panelsMenu->addAction(ac->action("show_places_panel"));
1546 panelsMenu->addAction(ac->action("show_information_panel"));
1547 panelsMenu->addAction(ac->action("show_folders_panel"));
1548 #ifndef Q_OS_WIN
1549 panelsMenu->addAction(ac->action("show_terminal_panel"));
1550 #endif
1551 panelsMenu->addSeparator();
1552 panelsMenu->addAction(lockLayoutAction);
1553 }
1554
1555 void DolphinMainWindow::updateEditActions()
1556 {
1557 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1558 if (list.isEmpty()) {
1559 stateChanged("has_no_selection");
1560 } else {
1561 stateChanged("has_selection");
1562
1563 KActionCollection* col = actionCollection();
1564 QAction* renameAction = col->action("rename");
1565 QAction* moveToTrashAction = col->action("move_to_trash");
1566 QAction* deleteAction = col->action("delete");
1567 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1568 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1569
1570 KFileItemListProperties capabilities(list);
1571 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1572
1573 renameAction->setEnabled(capabilities.supportsMoving());
1574 moveToTrashAction->setEnabled(enableMoveToTrash);
1575 deleteAction->setEnabled(capabilities.supportsDeleting());
1576 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1577 cutAction->setEnabled(capabilities.supportsMoving());
1578 }
1579 }
1580
1581 void DolphinMainWindow::updateViewActions()
1582 {
1583 m_actionHandler->updateViewActions();
1584
1585 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1586 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1587
1588 updateSplitAction();
1589
1590 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1591 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1592 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1593 }
1594
1595 void DolphinMainWindow::updateGoActions()
1596 {
1597 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1598 const KUrl currentUrl = m_activeViewContainer->url();
1599 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1600 }
1601
1602 void DolphinMainWindow::createControlButton()
1603 {
1604 if (m_controlButton) {
1605 return;
1606 }
1607 Q_ASSERT(!m_controlButton);
1608
1609 m_controlButton = new QToolButton(this);
1610 m_controlButton->setIcon(KIcon("applications-system"));
1611 m_controlButton->setText(i18nc("@action", "Control"));
1612 m_controlButton->setPopupMode(QToolButton::InstantPopup);
1613 m_controlButton->setToolButtonStyle(toolBar()->toolButtonStyle());
1614
1615 KMenu* controlMenu = new KMenu(m_controlButton);
1616 connect(controlMenu, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1617
1618 m_controlButton->setMenu(controlMenu);
1619
1620 toolBar()->addWidget(m_controlButton);
1621 connect(toolBar(), SIGNAL(iconSizeChanged(QSize)),
1622 m_controlButton, SLOT(setIconSize(QSize)));
1623 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
1624 m_controlButton, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)));
1625
1626 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1627 // gets edited. In this case we must add them again. The adding is done asynchronously by
1628 // m_updateToolBarTimer.
1629 connect(m_controlButton, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1630 m_updateToolBarTimer = new QTimer(this);
1631 m_updateToolBarTimer->setInterval(500);
1632 connect(m_updateToolBarTimer, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1633 }
1634
1635 void DolphinMainWindow::deleteControlButton()
1636 {
1637 delete m_controlButton;
1638 m_controlButton = 0;
1639
1640 delete m_updateToolBarTimer;
1641 m_updateToolBarTimer = 0;
1642 }
1643
1644 bool DolphinMainWindow::addActionToMenu(QAction* action, KMenu* menu)
1645 {
1646 Q_ASSERT(action);
1647 Q_ASSERT(menu);
1648
1649 const KToolBar* toolBarWidget = toolBar();
1650 foreach (const QWidget* widget, action->associatedWidgets()) {
1651 if (widget == toolBarWidget) {
1652 return false;
1653 }
1654 }
1655
1656 menu->addAction(action);
1657 return true;
1658 }
1659
1660 void DolphinMainWindow::refreshViews()
1661 {
1662 foreach (DolphinTabPage* tabPage, m_viewTab) {
1663 tabPage->refreshViews();
1664 }
1665
1666 if (GeneralSettings::modifiedStartupSettings()) {
1667 // The startup settings have been changed by the user (see bug #254947).
1668 // Synchronize the split-view setting with the active view:
1669 const bool splitView = GeneralSettings::splitView();
1670 m_viewTab.at(m_tabIndex)->setSplitViewEnabled(splitView);
1671 updateSplitAction();
1672 }
1673
1674 emit settingsChanged();
1675 }
1676
1677 void DolphinMainWindow::clearStatusBar()
1678 {
1679 m_activeViewContainer->statusBar()->resetToDefaultText();
1680 }
1681
1682 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1683 {
1684 connect(container, SIGNAL(showFilterBarChanged(bool)),
1685 this, SLOT(updateFilterBarAction(bool)));
1686 connect(container, SIGNAL(writeStateChanged(bool)),
1687 this, SLOT(slotWriteStateChanged(bool)));
1688
1689 const DolphinView* view = container->view();
1690 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1691 this, SLOT(slotSelectionChanged(KFileItemList)));
1692 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1693 this, SLOT(slotRequestItemInfo(KFileItem)));
1694 connect(view, SIGNAL(tabRequested(KUrl)),
1695 this, SLOT(openNewTab(KUrl)));
1696 connect(view, SIGNAL(requestContextMenu(QPoint,KFileItem,KUrl,QList<QAction*>)),
1697 this, SLOT(openContextMenu(QPoint,KFileItem,KUrl,QList<QAction*>)));
1698 connect(view, SIGNAL(directoryLoadingStarted()),
1699 this, SLOT(enableStopAction()));
1700 connect(view, SIGNAL(directoryLoadingCompleted()),
1701 this, SLOT(disableStopAction()));
1702 connect(view, SIGNAL(goBackRequested()),
1703 this, SLOT(goBack()));
1704 connect(view, SIGNAL(goForwardRequested()),
1705 this, SLOT(goForward()));
1706
1707 const KUrlNavigator* navigator = container->urlNavigator();
1708 connect(navigator, SIGNAL(urlChanged(KUrl)),
1709 this, SLOT(changeUrl(KUrl)));
1710 connect(navigator, SIGNAL(historyChanged()),
1711 this, SLOT(updateHistory()));
1712 connect(navigator, SIGNAL(editableStateChanged(bool)),
1713 this, SLOT(slotEditableStateChanged(bool)));
1714 connect(navigator, SIGNAL(tabRequested(KUrl)),
1715 this, SLOT(openNewTab(KUrl)));
1716 }
1717
1718 void DolphinMainWindow::updateSplitAction()
1719 {
1720 QAction* splitAction = actionCollection()->action("split_view");
1721 const DolphinTabPage* tabPage = m_viewTab.at(m_tabIndex);
1722 if (tabPage->splitViewEnabled()) {
1723 if (tabPage->primaryViewActive()) {
1724 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1725 splitAction->setToolTip(i18nc("@info", "Close left view"));
1726 splitAction->setIcon(KIcon("view-left-close"));
1727 } else {
1728 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1729 splitAction->setToolTip(i18nc("@info", "Close right view"));
1730 splitAction->setIcon(KIcon("view-right-close"));
1731 }
1732 } else {
1733 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1734 splitAction->setToolTip(i18nc("@info", "Split view"));
1735 splitAction->setIcon(KIcon("view-right-new"));
1736 }
1737 }
1738
1739 QString DolphinMainWindow::tabName(const KUrl& url) const
1740 {
1741 QString name;
1742 if (url.equals(KUrl("file:///"))) {
1743 name = '/';
1744 } else {
1745 name = url.fileName();
1746 if (name.isEmpty()) {
1747 name = url.protocol();
1748 } else {
1749 // Make sure that a '&' inside the directory name is displayed correctly
1750 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1751 name.replace('&', "&&");
1752 }
1753 }
1754 return name;
1755 }
1756
1757 bool DolphinMainWindow::isKompareInstalled() const
1758 {
1759 static bool initialized = false;
1760 static bool installed = false;
1761 if (!initialized) {
1762 // TODO: maybe replace this approach later by using a menu
1763 // plugin like kdiff3plugin.cpp
1764 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1765 initialized = true;
1766 }
1767 return installed;
1768 }
1769
1770 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
1771 {
1772 QString caption;
1773 if (!url.isLocalFile()) {
1774 caption.append(url.protocol() + " - ");
1775 if (url.hasHost()) {
1776 caption.append(url.host() + " - ");
1777 }
1778 }
1779
1780 const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
1781 caption.append(fileName);
1782
1783 setCaption(caption);
1784 }
1785
1786 QString DolphinMainWindow::squeezedText(const QString& text) const
1787 {
1788 const QFontMetrics fm = fontMetrics();
1789 return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
1790 }
1791
1792 void DolphinMainWindow::createPanelAction(const KIcon& icon,
1793 const QKeySequence& shortcut,
1794 QAction* dockAction,
1795 const QString& actionName)
1796 {
1797 KAction* panelAction = actionCollection()->addAction(actionName);
1798 panelAction->setCheckable(true);
1799 panelAction->setChecked(dockAction->isChecked());
1800 panelAction->setText(dockAction->text());
1801 panelAction->setIcon(icon);
1802 panelAction->setShortcut(shortcut);
1803
1804 connect(panelAction, SIGNAL(triggered()), dockAction, SLOT(trigger()));
1805 connect(dockAction, SIGNAL(toggled(bool)), panelAction, SLOT(setChecked(bool)));
1806 }
1807
1808 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1809 KIO::FileUndoManager::UiInterface()
1810 {
1811 }
1812
1813 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1814 {
1815 }
1816
1817 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1818 {
1819 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1820 if (mainWin) {
1821 DolphinViewContainer* container = mainWin->activeViewContainer();
1822 container->showMessage(job->errorString(), DolphinViewContainer::Error);
1823 } else {
1824 KIO::FileUndoManager::UiInterface::jobError(job);
1825 }
1826 }
1827
1828 #include "dolphinmainwindow.moc"