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