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