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