Commit 48a0e965 authored by Stefano Crocco's avatar Stefano Crocco Committed by David Faure

Allow the user to choose how to open an URL from history when activating it

Previously, when the user double clicked an entry in the history dialog,
the URL was opened in a new window, with no way to change this
behaviour.

Now the user can configure what to do when activating an entry
choosing from:
- always open the URL in the current tab
- always open the URL in a new tab
- always open the URL in a new window
- open the URL in a new tab unless the current tab has a konq: URL or an
  empty URL, in which cases open the URL in the current tab.

This also changes the behaviour of the history dialog so that the entry
is opened when it is activated, not double clicked.

The user's choice is also honoured from the history sidebar module,
except that the last option can't be used because (as far as I can see),
the module can't access the current URL. In the sidebar module, this
option is considered as if it were "always open in a new tab".
parent 954c533f
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KonqSidebarHistoryDlg</class>
<widget class="QWidget" name="KonqSidebarHistoryDlg" >
<property name="geometry" >
<widget class="QWidget" name="KonqSidebarHistoryDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<height>310</height>
<height>444</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="gbLimits" >
<property name="title" >
<widget class="QGroupBox" name="gbDefaultAction">
<property name="title">
<string>Default action</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="lDefault">
<property name="text">
<string>Default action when double clicking an URL</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboDefaultAction"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbLimits">
<property name="title">
<string>Limits</string>
</property>
<layout class="QGridLayout" >
<item row="1" column="2" >
<spacer name="Spacer1" >
<property name="orientation" >
<layout class="QGridLayout">
<item row="0" column="1">
<widget class="QSpinBox" name="spinEntries"/>
</item>
<item row="1" column="2">
<spacer name="Spacer1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>240</width>
<height>16</height>
......@@ -32,89 +55,86 @@
</property>
</spacer>
</item>
<item row="1" column="0" >
<widget class="QCheckBox" name="cbExpire" >
<property name="text" >
<item row="1" column="0">
<widget class="QCheckBox" name="cbExpire">
<property name="text">
<string>URLs e&amp;xpire after</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QSpinBox" name="spinExpire" />
<item row="1" column="1">
<widget class="QSpinBox" name="spinExpire"/>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="lEntries" >
<property name="text" >
<item row="0" column="0">
<widget class="QLabel" name="lEntries">
<property name="text">
<string>Maximum &amp;number of URLs:</string>
</property>
<property name="wordWrap" >
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>spinEntries</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QSpinBox" name="spinEntries" />
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbFonts" >
<property name="title" >
<widget class="QGroupBox" name="gbFonts">
<property name="title">
<string>Custom Fonts For</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="1" >
<widget class="QSpinBox" name="spinNewer" />
<layout class="QGridLayout">
<item row="0" column="1">
<widget class="QSpinBox" name="spinNewer"/>
</item>
<item row="1" column="1" >
<widget class="QSpinBox" name="spinOlder" />
<item row="1" column="1">
<widget class="QSpinBox" name="spinOlder"/>
</item>
<item row="1" column="2" >
<widget class="QComboBox" name="comboOlder" />
<item row="1" column="2">
<widget class="QComboBox" name="comboOlder"/>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="lbNewer" >
<property name="text" >
<item row="0" column="0">
<widget class="QLabel" name="lbNewer">
<property name="text">
<string>URLs newer than</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap" >
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QComboBox" name="comboNewer" />
<item row="0" column="2">
<widget class="QComboBox" name="comboNewer"/>
</item>
<item row="1" column="3" >
<widget class="QPushButton" name="btnFontOlder" >
<property name="text" >
<item row="1" column="3">
<widget class="QPushButton" name="btnFontOlder">
<property name="text">
<string>Choose Font...</string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="lbOlder" >
<property name="text" >
<item row="1" column="0">
<widget class="QLabel" name="lbOlder">
<property name="text">
<string>URLs older than</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap" >
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="3" >
<widget class="QPushButton" name="btnFontNewer" >
<property name="text" >
<item row="0" column="3">
<widget class="QPushButton" name="btnFontNewer">
<property name="text">
<string>Choose Font...</string>
</property>
</widget>
......@@ -123,17 +143,17 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbDetails" >
<property name="title" >
<widget class="QGroupBox" name="gbDetails">
<property name="title">
<string>Details</string>
</property>
<layout class="QHBoxLayout" >
<layout class="QHBoxLayout">
<item>
<widget class="QCheckBox" name="cbDetailedTips" >
<property name="toolTip" >
<widget class="QCheckBox" name="cbDetailedTips">
<property name="toolTip">
<string>Shows the number of times visited and the dates of the first and last visits, in addition to the URL</string>
</property>
<property name="text" >
<property name="text">
<string>Detailed tooltips</string>
</property>
</widget>
......@@ -142,23 +162,23 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<layout class="QHBoxLayout">
<item>
<widget class="QPushButton" name="btnClearHistory" >
<property name="text" >
<widget class="QPushButton" name="btnClearHistory">
<property name="text">
<string>Clear History</string>
</property>
</widget>
</item>
<item>
<spacer name="Spacer3" >
<property name="orientation" >
<spacer name="Spacer3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>418</width>
<height>0</height>
......@@ -169,14 +189,14 @@
</layout>
</item>
<item>
<spacer name="Spacer2" >
<property name="orientation" >
<spacer name="Spacer2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>30</height>
......@@ -186,6 +206,6 @@
</item>
</layout>
</widget>
<resources/>
<resources/>
<connections/>
</ui>
......@@ -31,7 +31,7 @@
KonqSidebarHistoryModule::KonqSidebarHistoryModule(QWidget *parent,
const KConfigGroup &configGroup)
: KonqSidebarModule(parent, configGroup)
: KonqSidebarModule(parent, configGroup), m_settings(KonqHistorySettings::self())
{
m_historyView = new KonqHistoryView(parent);
connect(m_historyView->treeView(), &QAbstractItemView::activated, this, &KonqSidebarHistoryModule::slotActivated);
......@@ -39,17 +39,31 @@ KonqSidebarHistoryModule::KonqSidebarHistoryModule(QWidget *parent,
connect(m_historyView->treeView(), &QAbstractItemView::clicked, this, &KonqSidebarHistoryModule::slotClicked);
connect(m_historyView, &KonqHistoryView::openUrlInNewWindow, this, &KonqSidebarHistoryModule::slotOpenWindow);
connect(m_historyView, &KonqHistoryView::openUrlInNewTab, this, &KonqSidebarHistoryModule::slotOpenTab);
connect(m_settings, &KonqHistorySettings::settingsChanged, this, &KonqSidebarHistoryModule::reparseConfiguration);
reparseConfiguration();
}
KonqSidebarHistoryModule::~KonqSidebarHistoryModule()
{
}
void KonqSidebarHistoryModule::reparseConfiguration()
{
m_defaultAction = m_settings->m_defaultAction;
}
QWidget *KonqSidebarHistoryModule::getWidget()
{
return m_historyView;
}
void KonqSidebarHistoryModule::slotCurViewUrlChanged(const QUrl& url)
{
m_currentUrl = url;
}
// LMB activation (single or double click) handling
void KonqSidebarHistoryModule::slotActivated(const QModelIndex &index)
{
......@@ -57,9 +71,23 @@ void KonqSidebarHistoryModule::slotActivated(const QModelIndex &index)
return;
}
const QUrl url = m_historyView->urlForIndex(index);
if (url.isValid()) {
emit openUrlRequest(url);
if (!url.isValid()) {
return;
}
if (m_defaultAction == KonqHistorySettings::Action::OpenNewWindow) {
slotOpenWindow(url);
return;
}
KParts::BrowserArguments bargs;
//Ideally, if m_defaultAction is Auto, the current tab should only be created if the current tab
//has a konq: or an empty URL. However, it seems you can't get this information from here, so always
//open a new tab unless the default action is OpenCurrentTab
if (m_defaultAction == KonqHistorySettings::Action::OpenCurrentTab) {
bargs.setNewTab(true);
} else if (m_defaultAction == KonqHistorySettings::Action::Auto && !(m_currentUrl.isEmpty() || m_currentUrl.scheme() == "konq")) {
bargs.setNewTab(true);
}
emit openUrlRequest(url, KParts::OpenUrlArguments(), bargs);
}
// Needed for MMB handling; no convenient API in QAbstractItemView
......
......@@ -22,6 +22,7 @@
#define HISTORY_MODULE_H
#include <konqsidebarplugin.h>
#include "konqhistorysettings.h"
class QModelIndex;
class KonqHistoryView;
......@@ -34,16 +35,23 @@ public:
virtual ~KonqSidebarHistoryModule();
virtual QWidget *getWidget() override;
public Q_SLOTS:
void slotCurViewUrlChanged(const QUrl& url) override;
private Q_SLOTS:
void slotActivated(const QModelIndex &index);
void slotPressed(const QModelIndex &index);
void slotClicked(const QModelIndex &index);
void slotOpenWindow(const QUrl &url);
void slotOpenTab(const QUrl &url);
void reparseConfiguration();
private:
KonqHistoryView *m_historyView;
Qt::MouseButtons m_lastPressedButtons;
KonqHistorySettings *m_settings;
KonqHistorySettings::Action m_defaultAction;
QUrl m_currentUrl;
};
#endif // HISTORY_MODULE_H
......@@ -59,6 +59,20 @@ HistorySidebarConfig::HistorySidebarConfig(QWidget *parent, const QVariantList &
QVBoxLayout *topLayout = new QVBoxLayout(this);
dialog = new KonqSidebarHistoryDlg(this);
dialog->comboDefaultAction->addItem(i18nc("Automatically decide which action to perform", "Auto"));
dialog->comboDefaultAction->addItem(i18nc("Open URL in new tab", "Open in new tab"));
dialog->comboDefaultAction->addItem(i18nc("Open URL in current tab", "Open in current tab"));
dialog->comboDefaultAction->addItem(i18nc("Open URL in new window", "Open in new window"));
QString defaultActionToolTip = i18n("Action to carry out when opening an URL from history:<dl>"
"<dl><dt>Auto:</dt><dd>opens the URL in a new tab unless the current tab is empty or an intro page</dd>"
"<dt>Open URL in a new tab:</dt><dd>always opens the URL in a new tab</dd>"
"<dt>Open URL in current tab:</dt><dd>always opens the URL in the current tab</dd>"
"<dt>Open URL in new window:</dt><dd>always opens the URL in a new window</dd>"
"</dl>"
);
dialog->setToolTip(defaultActionToolTip);
dialog->spinEntries->setRange(0, INT_MAX);
dialog->spinExpire->setRange(0, INT_MAX);
dialog->spinExpire->setSuffix(i18n("days"));
......@@ -76,6 +90,8 @@ HistorySidebarConfig::HistorySidebarConfig(QWidget *parent, const QVariantList &
dialog->comboOlder->insertItem(KonqHistorySettings::DAYS,
i18np("Day", "Days", 0));
connect(dialog->comboDefaultAction, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &HistorySidebarConfig::configChanged);
connect(dialog->cbExpire, &QAbstractButton::toggled, dialog->spinExpire, &QWidget::setEnabled);
connect(dialog->spinExpire, QOverload<int>::of(&QSpinBox::valueChanged), this, &HistorySidebarConfig::slotExpireChanged);
......@@ -106,6 +122,9 @@ void HistorySidebarConfig::load()
{
KConfig _config("konquerorrc");
KConfigGroup config(&_config, "HistorySettings");
dialog->comboDefaultAction->setCurrentIndex(config.readEntry("Default Action", 0));
dialog->spinExpire->setValue(config.readEntry("Maximum age of History entries", 90));
dialog->spinEntries->setValue(config.readEntry("Maximum of History entries", 500));
dialog->cbExpire->setChecked(dialog->spinExpire->value() > 0);
......@@ -139,6 +158,8 @@ void HistorySidebarConfig::save()
KonqHistoryProvider::self()->emitSetMaxAge(age);
KonqHistoryProvider::self()->emitSetMaxCount(count);
m_settings->m_defaultAction = static_cast<KonqHistorySettings::Action>(dialog->comboDefaultAction->currentIndex());
m_settings->m_valueYoungerThan = dialog->spinNewer->value();
m_settings->m_valueOlderThan = dialog->spinOlder->value();
......@@ -157,6 +178,8 @@ void HistorySidebarConfig::save()
void HistorySidebarConfig::defaults()
{
dialog->comboDefaultAction->setCurrentIndex(0);
dialog->spinEntries->setValue(500);
dialog->cbExpire->setChecked(true);
dialog->spinExpire->setValue(90);
......
......@@ -96,6 +96,8 @@ public Q_SLOTS:
void openPreviewOnMouseOver(const KFileItem &item); // not used yet
virtual void slotCurViewUrlChanged(const QUrl &url){Q_UNUSED(url);}
Q_SIGNALS:
void started(KIO::Job *);
void completed();
......
......@@ -463,7 +463,7 @@ bool Sidebar_Widget::openUrl(const QUrl &url)
if (m_buttons.isEmpty()) { // special case, since KonqMainWindow uses openURL to launch sidebar before buttons exist
m_urlBeforeInstanceFlag = true;
}
m_storedCurViewUrl = cleanupURL(url);
setStoredCurViewUrl(cleanupURL(url));
m_origURL = m_storedCurViewUrl;
for (int i = 0; i < m_buttons.count(); i++) {
......@@ -478,6 +478,12 @@ bool Sidebar_Widget::openUrl(const QUrl &url)
return ret;
}
void Sidebar_Widget::setStoredCurViewUrl(const QUrl& url)
{
m_storedCurViewUrl = url;
emit curViewUrlChanged(url);
}
QUrl Sidebar_Widget::cleanupURL(const QString &dirtyURL)
{
return cleanupURL(QUrl(dirtyURL));
......@@ -610,6 +616,7 @@ bool Sidebar_Widget::createView(ButtonInfo &buttonInfo)
connectModule(buttonInfo.module);
connect(this, &Sidebar_Widget::fileSelection, buttonInfo.module, &KonqSidebarModule::openPreview);
connect(this, &Sidebar_Widget::fileMouseOver, buttonInfo.module, &KonqSidebarModule::openPreviewOnMouseOver);
connect(this, &Sidebar_Widget::curViewUrlChanged, buttonInfo.module, &KonqSidebarModule::slotCurViewUrlChanged);
return true;
}
......@@ -731,7 +738,7 @@ void Sidebar_Widget::openUrlRequest(const QUrl &url, const KParts::OpenUrlArgume
return;
}
getExtension()->openUrlRequest(url, args, browserArgs);
m_storedCurViewUrl = url;
setStoredCurViewUrl(url);
}
void Sidebar_Widget::createNewWindow(const QUrl &url, const KParts::OpenUrlArguments &args, const KParts::BrowserArguments &browserArgs,
......@@ -795,7 +802,7 @@ void Sidebar_Widget::customEvent(QEvent *ev)
KParts::ReadOnlyPart* rpart = static_cast<KParts::ReadOnlyPart *>( static_cast<KParts::PartActivateEvent *>(ev)->part() );
if (! rpart->url().isEmpty()) {
m_storedCurViewUrl = cleanupURL(rpart->url());
setStoredCurViewUrl(cleanupURL(rpart->url()));
}
if (m_buttons.isEmpty()) { // special case when the event is received but the buttons have not been created yet
......
......@@ -122,6 +122,7 @@ Q_SIGNALS:
void completed();
void fileSelection(const KFileItemList &items);
void fileMouseOver(const KFileItem &item);
void curViewUrlChanged(const QUrl &url);
/* The following public slots are wrappers for browserextension signals */
public Q_SLOTS:
......@@ -141,6 +142,9 @@ private:
QUrl cleanupURL(const QUrl &url);
bool addButton(const QString &desktopFileName, int pos = -1);
bool createView(ButtonInfo &buttonInfo);
//Changes m_storedCurViewUrl and emits the curViewUrlChanged signal
void setStoredCurViewUrl(const QUrl &url);
KonqSidebarModule *loadModule(QWidget *par, const QString &desktopName,
ButtonInfo &buttonInfo, const KSharedConfig::Ptr &config);
void readConfig();
......
......@@ -19,10 +19,12 @@
#include "konqhistorydialog.h"
#include "konqhistoryview.h"
#include "konqhistorysettings.h"
#include "konqhistory.h"
#include "konqmainwindow.h"
#include "konqmainwindowfactory.h"
#include "konqurl.h"
#include <QAction>
#include <QTimer>
......@@ -46,16 +48,18 @@
#include <QPushButton>
KonqHistoryDialog::KonqHistoryDialog(KonqMainWindow *parent)
: QDialog(parent), m_mainWindow(parent)
: QDialog(parent), m_mainWindow(parent), m_settings(KonqHistorySettings::self())
{
setWindowTitle(i18nc("@title:window", "History"));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
m_historyView = new KonqHistoryView(this);
connect(m_historyView->treeView(), SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotOpenWindowForIndex(QModelIndex)));
connect(m_historyView->treeView(), &QTreeView::activated, this, &KonqHistoryDialog::slotOpenIndex);
connect(m_historyView, &KonqHistoryView::openUrlInNewWindow, this, &KonqHistoryDialog::slotOpenWindow);
connect(m_historyView, &KonqHistoryView::openUrlInNewTab, this, &KonqHistoryDialog::slotOpenTab);
connect(m_historyView, &KonqHistoryView::openUrlInCurrentTab, this, &KonqHistoryDialog::slotOpenCurrentTab);
connect(m_settings, &KonqHistorySettings::settingsChanged, this, &KonqHistoryDialog::reparseConfiguration);
KActionCollection *collection = m_historyView->actionCollection();
......@@ -85,6 +89,8 @@ KonqHistoryDialog::KonqHistoryDialog(KonqMainWindow *parent)
create(); // required by windowHandle()
KWindowConfig::restoreWindowSize(windowHandle(), KSharedConfig::openConfig()->group("History Dialog"));
reparseConfiguration();
// give focus to the search line edit when opening the dialog (#240513)
m_historyView->lineEdit()->setFocus();
}
......@@ -111,12 +117,45 @@ void KonqHistoryDialog::slotOpenTab(const QUrl &url)
m_mainWindow->openMultiURL(QList<QUrl>() << url);
}
// Called when double-clicking on a row
void KonqHistoryDialog::slotOpenWindowForIndex(const QModelIndex &index)
void KonqHistoryDialog::slotOpenCurrentTab(const QUrl& url)
{
m_mainWindow->openFilteredUrl(url.toString());
}
void KonqHistoryDialog::slotOpenCurrentOrNewTab(const QUrl& url)
{
QUrl currentUrl(m_mainWindow->currentURL());
if (KonqUrl::hasKonqScheme(currentUrl) || currentUrl.isEmpty()) {
slotOpenCurrentTab(url);
} else {
slotOpenTab(url);
}
}
// Called when activating a row
void KonqHistoryDialog::slotOpenIndex(const QModelIndex &index)
{
const QUrl url = m_historyView->urlForIndex(index);
if (url.isValid()) {
slotOpenWindow(url); // should we call slotOpenTab instead?
if (!url.isValid()) {
return;
}
switch (m_defaultAction) {
case KonqHistorySettings::Action::Auto:
slotOpenCurrentOrNewTab(url);
break;
case KonqHistorySettings::Action::OpenNewTab:
slotOpenTab(url);
break;
case KonqHistorySettings::Action::OpenCurrentTab:
slotOpenCurrentTab(url);
break;
case KonqHistorySettings::Action::OpenNewWindow:
slotOpenWindow(url);
break;
}
}
void KonqHistoryDialog::reparseConfiguration()
{
m_defaultAction = m_settings->m_defaultAction;
}
......@@ -22,6 +22,8 @@
#include <QDialog>
#include "konqhistorysettings.h"
class KonqMainWindow;
class KonqHistoryView;
class QModelIndex;
......@@ -40,11 +42,18 @@ public:
private Q_SLOTS:
void slotOpenWindow(const QUrl &url);
void slotOpenTab(const QUrl &url);
void slotOpenWindowForIndex(const QModelIndex &index);
void slotOpenCurrentTab(const QUrl &url);
void slotOpenCurrentOrNewTab(const QUrl &url);
void slotOpenIndex(const QModelIndex &index);
void reparseConfiguration();
private: