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