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