summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-24 20:12:26 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-24 20:12:26 (GMT)
commitfe8e85f404d88f1d4e02a54e488b4b2ead4e049a (patch)
treec22130b75f850fc2293330c46fbe9787f4f93572
parentd2f4f1c2d7114a8650d5d77845a5feb19a5bde4e (diff)
Re-add web shortcuts to context menu
-rw-r--r--ui/pageview.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/ui/pageview.cpp b/ui/pageview.cpp
index 580db18..d96db07 100644
--- a/ui/pageview.cpp
+++ b/ui/pageview.cpp
@@ -4203,7 +4203,56 @@ void PageView::updatePageStep() {
void PageView::addWebShortcutsMenu( QMenu * menu, const QString & text )
{
+ if ( text.isEmpty() )
+ {
+ return;
+ }
+
+ QString searchText = text;
+ searchText = searchText.replace( QLatin1Char('\n'), QLatin1Char(' ') ).replace(QLatin1Char( '\r'), QLatin1Char(' ') ).simplified();
+
+ if ( searchText.isEmpty() )
+ {
+ return;
+ }
+
+ KUriFilterData filterData( searchText );
+
+ filterData.setSearchFilteringOptions( KUriFilterData::RetrievePreferredSearchProvidersOnly );
+
+ if ( KUriFilter::self()->filterSearchUri( filterData, KUriFilter::NormalTextFilter ) )
+ {
+ const QStringList searchProviders = filterData.preferredSearchProviders();
+
+ if ( !searchProviders.isEmpty() )
+ {
+ QMenu *webShortcutsMenu = new QMenu( menu );
+ webShortcutsMenu->setIcon( QIcon::fromTheme( QStringLiteral("preferences-web-browser-shortcuts") ) );
+
+ const QString squeezedText = KStringHandler::rsqueeze( searchText, 21 );
+ webShortcutsMenu->setTitle( i18n( "Search for '%1' with", squeezedText ) );
+
+ QAction *action = 0;
+
+ foreach( const QString &searchProvider, searchProviders )
+ {
+ action = new QAction( searchProvider, webShortcutsMenu );
+ action->setIcon( QIcon::fromTheme( filterData.iconNameForPreferredSearchProvider( searchProvider ) ) );
+ action->setData( filterData.queryForPreferredSearchProvider( searchProvider ) );
+ connect( action, &QAction::triggered, this, &PageView::slotHandleWebShortcutAction );
+ webShortcutsMenu->addAction( action );
+ }
+
+ webShortcutsMenu->addSeparator();
+ action = new QAction( i18n( "Configure Web Shortcuts..." ), webShortcutsMenu );
+ action->setIcon( QIcon::fromTheme( QStringLiteral("configure") ) );
+ connect( action, &QAction::triggered, this, &PageView::slotConfigureWebShortcuts );
+ webShortcutsMenu->addAction( action );
+
+ menu->addMenu(webShortcutsMenu);
+ }
+ }
}
//BEGIN private SLOTS
@@ -4698,7 +4747,15 @@ void PageView::slotShowSizeAllCursor()
void PageView::slotHandleWebShortcutAction()
{
+ QAction *action = qobject_cast<QAction*>( sender() );
+ if (action) {
+ KUriFilterData filterData( action->data().toString() );
+
+ if ( KUriFilter::self()->filterSearchUri( filterData, KUriFilter::WebShortcutFilter ) ) {
+ KToolInvocation::invokeBrowser( filterData.uri().url() );
+ }
+ }
}
void PageView::slotConfigureWebShortcuts()