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