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