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