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