Commit c940aa5b authored by Stefano Crocco's avatar Stefano Crocco Committed by David Faure
Browse files

Add option to select behaviour when splitting a view

Currently there are three possible behaviours:
- duplicate the current view. This is the previous behaviour and remains
  the default one
- have the new view display the start page
- duplicate the current view if it displays a local file and show the
  start page otherwise

The reason for this change is that duplicating a web page requires time
because the page needs to be fetched again and, at least in theory, it
could have side effects.
parent 0da45c34
......@@ -131,6 +131,17 @@ void KKonqGeneralOptions::addHomeUrlWidgets(QVBoxLayout *lay)
formLayout->addRow(webLabel, m_webEngineCombo);
webLabel->setBuddy(m_webEngineCombo);
connect(m_webEngineCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KKonqGeneralOptions::slotChanged);
QLabel *splitLabel = new QLabel(i18n("When splitting a view"));
m_splitBehaviour = new QComboBox(this);
//Keep items order in sync with KonqMainWindow::SplitBehaviour
m_splitBehaviour->addItems({
i18n("Always duplicate current view"),
i18n("Duplicate current view only for local files")
});
splitLabel->setBuddy(m_splitBehaviour);
formLayout->addRow(splitLabel, m_splitBehaviour);
connect(m_splitBehaviour, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KKonqGeneralOptions::slotChanged);
}
KKonqGeneralOptions::~KKonqGeneralOptions()
......@@ -179,6 +190,9 @@ void KKonqGeneralOptions::load()
Q_ASSERT(startComboIndex != -1);
m_startCombo->setCurrentIndex(startComboIndex);
const bool alwaysDuplicateWhenSplitting = userSettings.readEntry("AlwaysDuplicatePageWhenSplittingView", true);
m_splitBehaviour->setCurrentIndex(alwaysDuplicateWhenSplitting ? 0 : 1);
m_webEngineCombo->clear();
// ## Well, the problem with using the trader to find the available parts, is that if a user
// removed a part in keditfiletype text/html, it won't be in the list anymore. Oh well.
......@@ -215,6 +229,7 @@ void KKonqGeneralOptions::defaults()
{
homeURL->setText(QUrl(DEFAULT_HOMEPAGE).toString());
startURL->setText(QUrl(DEFAULT_STARTPAGE).toString());
m_splitBehaviour->setCurrentIndex(0);
bool old = m_pConfig->readDefaults();
m_pConfig->setReadDefaults(true);
......@@ -232,6 +247,7 @@ void KKonqGeneralOptions::save()
startUrl = startURL->text();
userSettings.writeEntry("StartURL", startUrl);
userSettings.writeEntry("HomeURL", homeURL->text());
userSettings.writeEntry("AlwaysDuplicatePageWhenSplittingView", m_splitBehaviour->currentIndex() == 0);
if (m_webEngineCombo->currentIndex() > 0) {
// The user changed the preferred web engine, save into mimeapps.list.
......
......@@ -42,6 +42,8 @@ private:
QLineEdit *homeURL;
QLineEdit *startURL;
QComboBox *m_webEngineCombo;
QComboBox *m_splitBehaviour;
Ui_advancedTabOptions *tabOptions;
};
......
......@@ -52,6 +52,7 @@
#include <config-konqueror.h>
#include <kstringhandler.h>
#include "konqurl.h"
#include "konqsettingsxt.h"
#include <konq_events.h>
#include <konqpixmapprovider.h>
......@@ -2328,34 +2329,44 @@ void KonqMainWindow::slotURLEntered(const QString &text, Qt::KeyboardModifiers m
m_bURLEnterLock = false;
}
void KonqMainWindow::slotSplitViewHorizontal()
void KonqMainWindow::splitCurrentView(Qt::Orientation orientation)
{
if (!m_currentView) {
return;
}
KonqView *oldView = m_currentView;
KonqView *newView = m_pViewManager->splitView(m_currentView, Qt::Horizontal);
KonqView *newView = m_pViewManager->splitView(m_currentView, orientation);
if (newView == nullptr) {
return;
}
KonqOpenURLRequest req;
req.forceAutoEmbed = true;
openView(oldView->serviceType(), oldView->url(), newView, req);
QString mime = oldView->serviceType();
QUrl url = oldView->url();
KSharedConfig::Ptr cfg = KSharedConfig::openConfig("konquerorrc");
const bool alwaysDuplicateView = cfg->group("UserSettings").readEntry("AlwaysDuplicatePageWhenSplittingView", true);
if (!alwaysDuplicateView && !url.isLocalFile()) {
url = QUrl(KonqSettings::startURL());
if (url.isLocalFile()) {
QMimeDatabase db;
mime = db.mimeTypeForUrl(url).name();
} else {
//We can't know the mimetype
mime = "text/html";
}
}
openView(mime, url, newView, req);
}
void KonqMainWindow::slotSplitViewHorizontal()
{
splitCurrentView(Qt::Horizontal);
}
void KonqMainWindow::slotSplitViewVertical()
{
if (!m_currentView) {
return;
}
KonqView *oldView = m_currentView;
KonqView *newView = m_pViewManager->splitView(m_currentView, Qt::Vertical);
if (newView == nullptr) {
return;
}
KonqOpenURLRequest req;
req.forceAutoEmbed = true;
openView(oldView->serviceType(), oldView->url(), newView, req);
splitCurrentView(Qt::Vertical);
}
void KonqMainWindow::slotAddTab()
......
......@@ -528,7 +528,6 @@ private:
void switchToState(FullScreenState newState);
};
private Q_SLOTS:
void slotUndoTextChanged(const QString &newText);
......@@ -594,6 +593,8 @@ private:
void plugViewModeActions();
void unplugViewModeActions();
void splitCurrentView(Qt::Orientation orientation);
QObject *lastFrame(KonqView *view);
QLineEdit *comboEdit();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment