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