+void DolphinViewContainer::saveContentsPos(int x, int y)
+{
+ m_urlNavigator->savePosition(x, y);
+}
+
+void DolphinViewContainer::restoreContentsPos()
+{
+ if (!url().isEmpty()) {
+ const QPoint pos = m_urlNavigator->savedPosition();
+ m_view->setContentsPosition(pos.x(), pos.y());
+ }
+}
+
+void DolphinViewContainer::activate()
+{
+ setActive(true);
+}
+
+void DolphinViewContainer::restoreView(const KUrl& url)
+{
+ if (KProtocolManager::supportsListing(url)) {
+ m_view->updateView(url, m_urlNavigator->savedRootUrl());
+ if (isActive()) {
+ // When an URL has been entered, the view should get the focus.
+ // The focus must be requested asynchronously, as changing the URL might create
+ // a new view widget. Using QTimer::singleShow() works reliable, however
+ // QMetaObject::invokeMethod() with a queued connection does not work, which might
+ // indicate that we should pass a hint to DolphinView::updateView()
+ // regarding the focus instead. To test: Enter an URL and press CTRL+Enter.
+ // Expected result: The view should get the focus.
+ QTimer::singleShot(0, this, SLOT(requestFocus()));
+ }
+ } else if (KProtocolManager::isSourceProtocol(url)) {
+ QString app = "konqueror";
+ if (url.protocol().startsWith(QLatin1String("http"))) {
+ showErrorMessage(i18nc("@info:status",
+ "Dolphin does not support web pages, the web browser has been launched"));
+ const KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
+ const QString browser = config.readEntry("BrowserApplication");
+ if (!browser.isEmpty()) {
+ app = browser;
+ if (app.startsWith('!')) {
+ // a literal command has been configured, remove the '!' prefix
+ app = app.mid(1);
+ }
+ }
+ } else {
+ showErrorMessage(i18nc("@info:status",
+ "Protocol not supported by Dolphin, Konqueror has been launched"));
+ }
+
+ QString secureUrl = KShell::quoteArg(url.pathOrUrl());
+ const QString command = app + ' ' + secureUrl;
+ KRun::runCommand(command, app, app, this);
+ } else {
+ showErrorMessage(i18nc("@info:status", "Invalid protocol"));
+ }
+}
+
+void DolphinViewContainer::saveRootUrl(const KUrl& url)
+{
+ Q_UNUSED(url);
+ m_urlNavigator->saveRootUrl(m_view->rootUrl());
+}
+
+void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
+{
+ DragAndDropHelper::instance().dropUrls(KFileItem(), destination, event, this);
+}
+
+void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
+{
+ Q_UNUSED(oldUrl);
+ const bool block = m_urlNavigator->signalsBlocked();
+ m_urlNavigator->blockSignals(true);
+ m_urlNavigator->setUrl(newUrl);
+ m_urlNavigator->blockSignals(block);
+}
+
+void DolphinViewContainer::requestFocus()
+{
+ m_view->setFocus();
+}
+
+void DolphinViewContainer::saveUrlCompletionMode(KGlobalSettings::Completion completion)
+{
+ DolphinSettings& settings = DolphinSettings::instance();
+ settings.generalSettings()->setUrlCompletionMode(completion);
+ settings.save();
+}
+
+void DolphinViewContainer::slotHistoryChanged()
+{
+ const int index = m_urlNavigator->historyIndex();
+ if (index > 0) {
+ // The "Go Forward" action is enabled. Try to mark
+ // the previous directory as active item:
+ const KUrl url = m_urlNavigator->historyUrl(index - 1);
+ m_view->activateItem(url);
+ }
+}
+
+void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
+{
+ KUrl url = item.targetUrl();
+
+ if (item.isDir()) {
+ m_view->setUrl(url);
+ return;
+ }
+
+ const GeneralSettings* settings = DolphinSettings::instance().generalSettings();
+ const bool browseThroughArchives = settings->browseThroughArchives();
+ if (browseThroughArchives && item.isFile() && url.isLocalFile()) {
+ // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
+ // zip:/<path>/ when clicking on a zip file, etc.
+ // The .protocol file specifies the mimetype that the kioslave handles.
+ // Note that we don't use mimetype inheritance since we don't want to
+ // open OpenDocument files as zip folders...
+ const QString protocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype());
+ if (!protocol.isEmpty()) {
+ url.setProtocol(protocol);
+ m_view->setUrl(url);
+ return;
+ }
+ }
+
+ item.run();
+}
+
+void DolphinViewContainer::openFile(const KUrl& url)
+{
+ // Using m_dolphinModel for getting the file item instance is not possible
+ // here: openFile() is triggered by an error of the directory lister
+ // job, so the file item must be received "manually".
+ const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+ slotItemTriggered(item);
+}
+