From aa154a00c29dc5ab9cf07f933cae5cee32614bed Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 12 Mar 2012 05:51:58 +0100 Subject: Check if user has a default search engine set and eventually show a messagewidget to inform and let him set it. REVIEW:104290 --- src/CMakeLists.txt | 1 + src/application.cpp | 4 ++ src/opensearch/opensearchmanager.cpp | 1 + src/opensearch/opensearchmanager.h | 1 + src/opensearch/searchengine.cpp | 3 ++ src/opensearch/searchengine.h | 23 +++++---- src/rekonq.kcfg | 3 ++ src/searchenginebar.cpp | 93 ++++++++++++++++++++++++++++++++++++ src/searchenginebar.h | 55 +++++++++++++++++++++ src/webtab.cpp | 14 +++++- src/webtab.h | 2 + 11 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 src/searchenginebar.cpp create mode 100644 src/searchenginebar.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 10b57b1c..518ce571 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ SET( rekonq_KDEINIT_SRCS previewselectorbar.cpp protocolhandler.cpp rekonqmenu.cpp + searchenginebar.cpp sessionmanager.cpp sslinfodialog.cpp tabpreviewpopup.cpp diff --git a/src/application.cpp b/src/application.cpp index 0eb08cee..40197d78 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -46,6 +46,7 @@ #include "mainview.h" #include "mainwindow.h" #include "opensearchmanager.h" +#include "searchengine.h" #include "sessionmanager.h" #include "syncmanager.h" #include "stackedurlbar.h" @@ -318,6 +319,9 @@ int Application::newInstance() if (isFirstLoad) { + if (ReKonfig::checkDefaultSearchEngine() && !isRekonqCrashed && SearchEngine::defaultEngine().isNull()) + QTimer::singleShot(2000, mainWindow()->currentTab(), SLOT(showSearchEngineBar())); + // updating rekonq configuration updateConfiguration(); diff --git a/src/opensearch/opensearchmanager.cpp b/src/opensearch/opensearchmanager.cpp index 12b93ec2..ad2f7092 100644 --- a/src/opensearch/opensearchmanager.cpp +++ b/src/opensearch/opensearchmanager.cpp @@ -131,6 +131,7 @@ void OpenSearchManager::addOpenSearchEngine(const KUrl &url, const QString &titl connect(m_currentJob, SIGNAL(result(KJob*)), this, SLOT(jobFinished(KJob*))); } + void OpenSearchManager::requestSuggestion(const QString &searchText) { if (!m_activeEngine) diff --git a/src/opensearch/opensearchmanager.h b/src/opensearch/opensearchmanager.h index 84272f26..b2f772fb 100644 --- a/src/opensearch/opensearchmanager.h +++ b/src/opensearch/opensearchmanager.h @@ -46,6 +46,7 @@ // Forward Declarations class OpenSearchEngine; + /** * This class acts as a proxy between the SearchBar plugin * and the individual suggestion engine. diff --git a/src/opensearch/searchengine.cpp b/src/opensearch/searchengine.cpp index b54d9434..aef06a7b 100644 --- a/src/opensearch/searchengine.cpp +++ b/src/opensearch/searchengine.cpp @@ -37,6 +37,7 @@ #include #include + struct SearchEnginePrivate { SearchEnginePrivate() : isLoaded(false) {} @@ -46,8 +47,10 @@ struct SearchEnginePrivate KService::Ptr defaultEngine; }; + K_GLOBAL_STATIC(SearchEnginePrivate, d) + void SearchEngine::reload() { KConfig config("kuriikwsfilterrc"); //Shared with konqueror diff --git a/src/opensearch/searchengine.h b/src/opensearch/searchengine.h index 7825d661..7cd37a67 100644 --- a/src/opensearch/searchengine.h +++ b/src/opensearch/searchengine.h @@ -2,7 +2,7 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2008-2011 by Andrea Diamantini +* Copyright (C) 2008-2012 by Andrea Diamantini * Copyright (C) 2009-2011 by Lionel Chauvin * * @@ -24,6 +24,7 @@ * * ============================================================ */ + #ifndef SEARCHENGINE_H #define SEARCHENGINE_H @@ -40,13 +41,19 @@ namespace SearchEngine { -void reload(); -QString delimiter(); -KService::Ptr defaultEngine(); -KService::List favorites(); -KService::Ptr fromString(const QString &text); -QString buildQuery(KService::Ptr engine, const QString &text); -QString extractQuery(const QString &text); + void reload(); + + QString delimiter(); + + KService::Ptr defaultEngine(); + + KService::List favorites(); + + KService::Ptr fromString(const QString &text); + + QString buildQuery(KService::Ptr engine, const QString &text); + + QString extractQuery(const QString &text); } #endif diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index bdcbcb60..1675c558 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -36,6 +36,9 @@ false + + true + diff --git a/src/searchenginebar.cpp b/src/searchenginebar.cpp new file mode 100644 index 00000000..f8e137ec --- /dev/null +++ b/src/searchenginebar.cpp @@ -0,0 +1,93 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +// Self Includes +#include "searchenginebar.h" +#include "searchenginebar.moc" + +// Auto Includes +#include "rekonq.h" + +// KDE Includes +#include +#include +#include +#include + +// Qt Includes +#include + + +SearchEngineBar::SearchEngineBar(QWidget *parent) + : KMessageWidget(parent) +{ + connect(this, SIGNAL(accepted()), this, SLOT(hideAndDelete())); + connect(this, SIGNAL(accepted()), this, SLOT(slotAccepted())); + + connect(this, SIGNAL(rejected()), this, SLOT(hideAndDelete())); + connect(this, SIGNAL(rejected()), this, SLOT(slotRejected())); + + setMessageType(KMessageWidget::Information); + + QSize sz = size(); + sz.setWidth(qobject_cast(parent)->size().width()); + resize(sz); + + setCloseButtonVisible(false); + + setText(i18n("You don't have a default search engine set. Without it, rekonq will no show proper urlbar suggestions.")); + + KAction *acceptAction = new KAction(i18n("Set it"), this); + connect(acceptAction, SIGNAL(triggered(bool)), this, SIGNAL(accepted())); + addAction(acceptAction); + + KAction *rejectAction = new KAction(i18n("Ignore"), this); + connect(rejectAction, SIGNAL(triggered(bool)), this, SIGNAL(rejected())); + addAction(rejectAction); +} + + +void SearchEngineBar::hideAndDelete() +{ + animatedHide(); + deleteLater(); +} + + +void SearchEngineBar::slotAccepted() +{ + QProcess *proc = new QProcess(parent()); + QStringList args; + args << QL1S("ebrowsing"); + proc->start(QL1S("kcmshell4"), args); +} + + +void SearchEngineBar::slotRejected() +{ + // Remember users choice + ReKonfig::setCheckDefaultSearchEngine(false); +} diff --git a/src/searchenginebar.h b/src/searchenginebar.h new file mode 100644 index 00000000..9e5b8efc --- /dev/null +++ b/src/searchenginebar.h @@ -0,0 +1,55 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +#ifndef SEARCH_ENGINE_BAR_H +#define SEARCH_ENGINE_BAR_H + +// Rekonq Includes +#include "rekonq_defines.h" + +// KDE Includes +#include + + +class REKONQ_TESTS_EXPORT SearchEngineBar : public KMessageWidget +{ + Q_OBJECT + +public: + explicit SearchEngineBar(QWidget *parent); + +private Q_SLOTS: + void hideAndDelete(); + void slotAccepted(); + void slotRejected(); + +Q_SIGNALS: + void accepted(); + void rejected(); +}; + + +#endif // SEARCH_ENGINE_BAR_H diff --git a/src/webtab.cpp b/src/webtab.cpp index cbb38a5e..718d8b98 100644 --- a/src/webtab.cpp +++ b/src/webtab.cpp @@ -39,6 +39,7 @@ #include "opensearchmanager.h" #include "previewselectorbar.h" #include "rsswidget.h" +#include "searchenginebar.h" #include "sessionmanager.h" #include "syncmanager.h" #include "urlbar.h" @@ -253,6 +254,7 @@ void WebTab::showRSSInfo(const QPoint &pos) widget->showAt(pos); } + void WebTab::hideSelectorBar() { m_previewSelectorBar.data()->animatedHide(); @@ -341,8 +343,7 @@ void WebTab::openSearchEngineAdded() void WebTab::showMessageBar() { MessageBar *msgBar = new MessageBar(i18n("It seems rekonq was not closed properly. Do you want " - "to restore the last saved session?") - , this); + "to restore the last saved session?"), this); qobject_cast(layout())->insertWidget(0, msgBar); msgBar->animatedShow(); @@ -363,3 +364,12 @@ void WebTab::loadFinished() QString pageTitle = (page() && page()->isOnRekonqPage()) ? url().url() : m_webView->title(); rApp->historyManager()->addHistoryEntry(url(), pageTitle); } + + +void WebTab::showSearchEngineBar() +{ + SearchEngineBar *seBar = new SearchEngineBar(this); + + qobject_cast(layout())->insertWidget(0, seBar); + seBar->animatedShow(); +} diff --git a/src/webtab.h b/src/webtab.h index 257f7380..92ae2eb5 100644 --- a/src/webtab.h +++ b/src/webtab.h @@ -104,6 +104,8 @@ private Q_SLOTS: void showMessageBar(); void loadFinished(); + + void showSearchEngineBar(); private: KUrl extractOpensearchUrl(QWebElement e); -- cgit v1.2.1