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