summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/application.cpp6
-rw-r--r--src/application.h2
-rw-r--r--src/mainview.cpp34
-rw-r--r--src/mainview.h2
-rw-r--r--src/mainwindow.cpp5
-rw-r--r--src/rekonq.kcfg5
-rw-r--r--src/searchengine.cpp166
-rw-r--r--src/searchengine.h60
-rw-r--r--src/settings/settings_webkit.ui85
-rw-r--r--src/settings/settingsdialog.cpp10
-rw-r--r--src/tabbar.cpp4
-rw-r--r--src/urlbar/completionwidget.cpp36
-rw-r--r--src/urlbar/completionwidget.h9
-rw-r--r--src/urlbar/listitem.cpp95
-rw-r--r--src/urlbar/listitem.h14
-rw-r--r--src/urlbar/urlresolver.cpp10
-rw-r--r--src/webtab.cpp22
-rw-r--r--src/webview.cpp37
19 files changed, 404 insertions, 199 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e2bcbdb9..a6055ce7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -28,6 +28,7 @@ SET( rekonq_KDEINIT_SRCS
websnap.cpp
webview.cpp
webtab.cpp
+ searchengine.cpp
#----------------------------------------
history/autosaver.cpp
history/historymanager.cpp
diff --git a/src/application.cpp b/src/application.cpp
index db6d3c32..45d115ae 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -329,10 +329,12 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type)
}
-MainWindow *Application::newMainWindow()
+MainWindow *Application::newMainWindow(bool withTab)
{
MainWindow *w = new MainWindow();
- w->mainView()->newWebTab(); // remember using newWebTab and NOT newTab here!!
+
+ if(withTab)
+ w->mainView()->newWebTab(); // remember using newWebTab and NOT newTab here!!
m_mainWindows.prepend(w);
w->show();
diff --git a/src/application.h b/src/application.h
index c268d586..fe3c50c1 100644
--- a/src/application.h
+++ b/src/application.h
@@ -102,7 +102,7 @@ public:
static Application *instance();
MainWindow *mainWindow();
- MainWindow *newMainWindow();
+ MainWindow *newMainWindow(bool withTab = true);
MainWindowList mainWindowList();
static KIcon icon(const KUrl &url);
diff --git a/src/mainview.cpp b/src/mainview.cpp
index cb2e3b11..63c10683 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -456,7 +456,7 @@ void MainView::cloneTab(int index)
// When index is -1 index chooses the current tab
-void MainView::closeTab(int index)
+void MainView::closeTab(int index, bool del)
{
// open default homePage if just one tab is opened
if (count() == 1)
@@ -510,11 +510,15 @@ void MainView::closeTab(int index)
removeTab(index);
updateTabBar(); // UI operation: do it ASAP!!
- tab->deleteLater(); // tab is scheduled for deletion.
QWidget *urlbar = _bars->widget(index);
_bars->removeWidget(urlbar);
- urlbar->deleteLater();
+
+ if(del)
+ {
+ tab->deleteLater(); // tab is scheduled for deletion.
+ urlbar->deleteLater();
+ }
emit tabsChanged();
}
@@ -682,10 +686,26 @@ void MainView::detachTab(int index)
if (index < 0 || index >= count())
return;
- KUrl url = webTab(index)->view()->url();
- closeTab(index);
-
- Application::instance()->loadUrl(url, Rekonq::NewWindow);
+ WebTab *tab = webTab(index);
+ KUrl u = tab->url();
+ kDebug() << u;
+ if( u.scheme() == QL1S("about") )
+ {
+ closeTab(index);
+ Application::instance()->loadUrl(u, Rekonq::NewWindow);
+ }
+ else
+ {
+ QString label = tab->view()->title();
+ QWidget *bar = _bars->widget(index);
+ closeTab(index, false);
+
+ MainWindow *w = Application::instance()->newMainWindow(false);
+ w->mainView()->addTab(tab, Application::icon( u ), label);
+ QStackedWidget *stack = qobject_cast<QStackedWidget *>(w->mainView()->urlBarWidget());
+ stack->insertWidget(0, bar);
+ w->mainView()->updateTabBar();
+ }
}
diff --git a/src/mainview.h b/src/mainview.h
index 272cf82e..367fcb13 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -123,7 +123,7 @@ public slots:
void newTab();
void cloneTab(int index = -1);
- void closeTab(int index = -1);
+ void closeTab(int index = -1, bool del = true);
void closeOtherTabs(int index);
void reloadTab(int index = -1);
void reloadAllTabs();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index cb90f818..fe00ee7e 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -572,6 +572,7 @@ void MainWindow::updateConfiguration()
// ================ WebKit ============================
defaultSettings->setAttribute(QWebSettings::AutoLoadImages, ReKonfig::autoLoadImages());
+ defaultSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, ReKonfig::dnsPrefetch());
defaultSettings->setAttribute(QWebSettings::JavascriptEnabled, ReKonfig::javascriptEnabled());
defaultSettings->setAttribute(QWebSettings::JavaEnabled, ReKonfig::javaEnabled());
defaultSettings->setAttribute(QWebSettings::JavascriptCanOpenWindows, ReKonfig::javascriptCanOpenWindows());
@@ -588,8 +589,8 @@ void MainWindow::updateConfiguration()
// ===== HTML 5 features WebKit support ======
defaultSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, ReKonfig::offlineStorageDatabaseEnabled());
defaultSettings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, ReKonfig::offlineWebApplicationCacheEnabled());
- defaultSettings->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, ReKonfig::localStorageDatabaseEnabled());
- if(ReKonfig::localStorageDatabaseEnabled())
+ defaultSettings->setAttribute(QWebSettings::LocalStorageEnabled, ReKonfig::localStorageEnabled());
+ if(ReKonfig::localStorageEnabled())
{
QString path = KStandardDirs::locateLocal("cache", QString("WebkitLocalStorage/rekonq"), true);
path.remove("rekonq");
diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg
index 860809cd..dd46624f 100644
--- a/src/rekonq.kcfg
+++ b/src/rekonq.kcfg
@@ -117,6 +117,9 @@
<entry name="autoLoadImages" type="Bool">
<default>true</default>
</entry>
+ <entry name="dnsPrefetch" type="Bool">
+ <default>true</default>
+ </entry>
<entry name="javascriptEnabled" type="Bool">
<default>true</default>
</entry>
@@ -147,7 +150,7 @@
<entry name="offlineWebApplicationCacheEnabled" type="Bool">
<default>true</default>
</entry>
- <entry name="localStorageDatabaseEnabled" type="Bool">
+ <entry name="localStorageEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="userCSS" type="Url">
diff --git a/src/searchengine.cpp b/src/searchengine.cpp
new file mode 100644
index 00000000..65f2a4e8
--- /dev/null
+++ b/src/searchengine.cpp
@@ -0,0 +1,166 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2009-2010 by Lionel Chauvin <megabigbug@yahoo.fr>
+*
+*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+//local includes
+#include "searchengine.h"
+
+//KDE includes
+#include <KConfigGroup>
+#include <KServiceTypeTrader>
+
+
+// Defines
+#define QL1S(x) QLatin1String(x)
+
+
+QString SearchEngine::m_delimiter = "";
+
+
+QString SearchEngine::delimiter()
+{
+ if (m_delimiter=="") loadDelimiter();
+ return m_delimiter;
+}
+
+
+void SearchEngine::loadDelimiter()
+{
+ KConfig config("kuriikwsfilterrc"); //Share with konqueror
+ KConfigGroup cg = config.group("General");
+ m_delimiter = cg.readEntry("KeywordDelimiter", ":");
+}
+
+
+KService::Ptr SearchEngine::m_defaultWS;
+
+
+KService::Ptr SearchEngine::defaultWS()
+{
+ if (!m_defaultWS) loadDefaultWS();
+ return m_defaultWS;
+}
+
+
+void SearchEngine::loadDefaultWS()
+{
+ KConfig config("kuriikwsfilterrc"); //Share with konqueror
+ KConfigGroup cg = config.group("General");
+ QString d = cg.readEntry("DefaultSearchEngine", "google");
+ m_defaultWS = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(d));
+}
+
+
+KService::Ptr SearchEngine::fromString(QString text)
+{
+ KService::List providers = KServiceTypeTrader::self()->query("SearchProvider");
+ int i = 0;
+ bool found = false;
+ KService::Ptr service;
+ while(!found && i<providers.size())
+ {
+ foreach(QString key, providers.at(i)->property("Keys").toStringList())
+ {
+ const QString searchPrefix = key + delimiter();
+ if (text.startsWith(searchPrefix))
+ {
+ service = providers.at(i);
+ found = true;
+ }
+ }
+ i++;
+ }
+
+ return service;
+}
+
+
+QString SearchEngine::buildQuery(KService::Ptr engine, QString text)
+{
+ QString query = engine->property("Query").toString();
+ query = query.replace("\\{@}", KUrl::toPercentEncoding(text));
+ return query;
+}
+
+
+KService::List SearchEngine::m_favorites;
+
+
+KService::List SearchEngine::favorites()
+{
+ if (m_favorites.isEmpty()) loadFavorites();
+ return m_favorites;
+}
+
+
+void SearchEngine::loadFavorites()
+{
+ KConfig config("kuriikwsfilterrc"); //Share with konqueror
+ KConfigGroup cg = config.group("General");
+ QStringList f;
+ f << "wikipedia" << "google"; //defaults
+ f = cg.readEntry("FavoriteSearchEngines", f);
+
+ KService::List favorites;
+ KService::Ptr service;
+ foreach(QString e, f)
+ {
+ service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(e));
+ if (service) favorites << service;
+ }
+
+ m_favorites = favorites;
+}
+
+
+KService::Ptr SearchEngine::defaultEngine()
+{
+ int n = ReKonfig::searchEngine();
+ QString engine;
+ switch(n)
+ {
+ case 0:
+ engine = QL1S("google");
+ break;
+ case 1:
+ engine = QL1S("altavista");
+ break;
+ case 2:
+ engine = QL1S("lycos");
+ break;
+ case 3:
+ engine = QL1S("wikipedia");
+ break;
+ case 4:
+ engine = QL1S("wolfram");
+ break;
+ default:
+ engine = QL1S("google");
+ break;
+ }
+
+ return KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine));
+}
+
diff --git a/src/searchengine.h b/src/searchengine.h
new file mode 100644
index 00000000..8cb09b6d
--- /dev/null
+++ b/src/searchengine.h
@@ -0,0 +1,60 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
+* Copyright (C) 2009-2010 by Lionel Chauvin <megabigbug@yahoo.fr>
+*
+*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+#ifndef SEARCHENGINE_H
+#define SEARCHENGINE_H
+
+// Auto Includes
+#include "rekonq.h"
+
+// KDE Includes
+#include <KService>
+
+//Qt Includes
+#include <QString>
+
+class SearchEngine
+{
+public:
+
+ static QString delimiter();
+ static KService::Ptr defaultEngine();
+ static KService::List favorites();
+ static KService::Ptr fromString(QString text);
+ static QString buildQuery(KService::Ptr engine, QString text);
+ static KService::Ptr defaultWS();
+
+ static void loadDelimiter();
+ static void loadFavorites();
+ static void loadDefaultWS();
+
+private:
+ static QString m_delimiter;
+ static KService::List m_favorites;
+ static KService::Ptr m_defaultWS;
+};
+
+#endif \ No newline at end of file
diff --git a/src/settings/settings_webkit.ui b/src/settings/settings_webkit.ui
index e424fd9c..f2e616c8 100644
--- a/src/settings/settings_webkit.ui
+++ b/src/settings/settings_webkit.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>437</width>
- <height>346</height>
+ <width>643</width>
+ <height>560</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -17,99 +17,106 @@
<string>WebKit Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0" colspan="2">
+ <item row="0" column="0">
<widget class="QCheckBox" name="kcfg_autoLoadImages">
<property name="text">
<string>Autoload images</string>
</property>
</widget>
</item>
- <item row="0" column="3">
+ <item row="0" column="1" rowspan="7">
+ <widget class="Line" name="line">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
<widget class="QCheckBox" name="kcfg_linksIncludedInFocusChain">
<property name="text">
<string>Links included in focus chain</string>
</property>
</widget>
</item>
- <item row="1" column="0" colspan="2">
- <widget class="QCheckBox" name="kcfg_javascriptEnabled">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
+ <item row="1" column="0">
+ <widget class="QCheckBox" name="kcfg_dnsPrefetch">
<property name="text">
- <string>JavaScript support</string>
+ <string>prefetch DNS entries</string>
</property>
</widget>
</item>
- <item row="1" column="3">
+ <item row="1" column="2">
<widget class="QCheckBox" name="kcfg_zoomTextOnly">
<property name="text">
<string>Zoom text only</string>
</property>
</widget>
</item>
- <item row="2" column="0" colspan="2">
- <widget class="QCheckBox" name="kcfg_javaEnabled">
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="kcfg_javascriptEnabled">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text">
- <string>Java support</string>
+ <string>JavaScript support</string>
</property>
</widget>
</item>
- <item row="2" column="3">
+ <item row="2" column="2">
<widget class="QCheckBox" name="kcfg_printElementBackgrounds">
<property name="text">
<string>Print element backgrounds</string>
</property>
</widget>
</item>
- <item row="3" column="3">
+ <item row="4" column="2">
<widget class="QCheckBox" name="kcfg_offlineStorageDatabaseEnabled">
<property name="text">
<string>Offline storage database</string>
</property>
</widget>
</item>
- <item row="4" column="3">
- <widget class="QCheckBox" name="kcfg_offlineWebApplicationCacheEnabled">
+ <item row="3" column="0" rowspan="2">
+ <widget class="QCheckBox" name="kcfg_javaEnabled">
<property name="text">
- <string>Offline web application cache</string>
+ <string>Java support</string>
</property>
</widget>
</item>
- <item row="5" column="3">
- <widget class="QCheckBox" name="kcfg_localStorageDatabaseEnabled">
+ <item row="5" column="0">
+ <widget class="QCheckBox" name="kcfg_javascriptCanOpenWindows">
<property name="text">
- <string>Local storage database</string>
+ <string>JavaScript can open windows</string>
</property>
</widget>
</item>
- <item row="3" column="0">
- <widget class="QCheckBox" name="kcfg_javascriptCanOpenWindows">
+ <item row="5" column="2">
+ <widget class="QCheckBox" name="kcfg_offlineWebApplicationCacheEnabled">
<property name="text">
- <string>JavaScript can open windows</string>
+ <string>Offline web application cache</string>
</property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="6" column="0">
<widget class="QCheckBox" name="kcfg_javascriptCanAccessClipboard">
<property name="text">
<string>JavaScript can access clipboard</string>
</property>
</widget>
</item>
- <item row="0" column="2" rowspan="6">
- <widget class="Line" name="line">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="orientation">
- <enum>Qt::Vertical</enum>
+ <item row="6" column="2">
+ <widget class="QCheckBox" name="kcfg_localStorageEnabled">
+ <property name="text">
+ <string>Local Storage</string>
</property>
</widget>
</item>
diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp
index 35f753d3..2f52a8c2 100644
--- a/src/settings/settingsdialog.cpp
+++ b/src/settings/settingsdialog.cpp
@@ -38,6 +38,7 @@
#include "webtab.h"
#include "adblockwidget.h"
#include "networkwidget.h"
+#include "searchengine.h"
//Ui Includes
#include "ui_settings_general.h"
@@ -174,6 +175,7 @@ SettingsDialog::~SettingsDialog()
void SettingsDialog::setWebSettingsToolTips()
{
d->webkitUi.kcfg_autoLoadImages->setToolTip(i18n("Specifies whether images are automatically loaded in web pages."));
+ d->webkitUi.kcfg_dnsPrefetch->setToolTip( i18n("Specifies whether WebKit will try to pre-fetch DNS entries to speed up browsing.") );
d->webkitUi.kcfg_javascriptEnabled->setToolTip(i18n("Enables the execution of JavaScript programs."));
d->webkitUi.kcfg_javaEnabled->setToolTip(i18n("Enables support for Java applets."));
d->webkitUi.kcfg_pluginsEnabled->setToolTip(i18n("Enables support for plugins in web pages."));
@@ -184,7 +186,7 @@ void SettingsDialog::setWebSettingsToolTips()
d->webkitUi.kcfg_printElementBackgrounds->setToolTip(i18n("If enabled, background colors and images are also drawn when the page is printed."));
d->webkitUi.kcfg_offlineStorageDatabaseEnabled->setToolTip(i18n("Enables support for the HTML 5 offline storage feature."));
d->webkitUi.kcfg_offlineWebApplicationCacheEnabled->setToolTip(i18n("Enables support for the HTML 5 web application cache feature."));
- d->webkitUi.kcfg_localStorageDatabaseEnabled->setToolTip(i18n("Enables support for the HTML 5 local storage feature."));
+ d->webkitUi.kcfg_localStorageEnabled->setToolTip(i18n("Enables support for the HTML 5 local storage feature."));
}
@@ -207,7 +209,11 @@ void SettingsDialog::saveSettings()
d->shortcutsEditor->save();
d->adBlockWidg->save();
d->networkWidg->save();
-
+ SearchEngine::loadDefaultWS();
+ SearchEngine::loadDelimiter();
+ SearchEngine::loadFavorites();
+
+
updateButtons();
emit settingsChanged("ReKonfig");
}
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index fca3c6b1..a2f269c4 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -273,7 +273,9 @@ void TabBar::contextMenu(int tab, const QPoint &pos)
menu.addAction(mainWindow->actionByName(QLatin1String("new_tab")));
menu.addAction( mainWindow->actionByName("clone_tab") );
- menu.addAction( mainWindow->actionByName("detach_tab") );
+
+ if(count() > 1)
+ menu.addAction( mainWindow->actionByName("detach_tab") );
menu.addSeparator();
menu.addAction( mainWindow->actionByName("close_tab") );
menu.addAction( mainWindow->actionByName("close_other_tabs") );
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index 8307940b..e0027a92 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -34,6 +34,7 @@
// Local Includes
#include "application.h"
#include "urlresolver.h"
+#include "searchengine.h"
// KDE Includes
#include <KGlobalSettings>
@@ -48,15 +49,12 @@
#include <QEvent>
#include <QKeyEvent>
-// Defines
-#define QL1S(x) QLatin1String(x)
-
CompletionWidget::CompletionWidget(QWidget *parent)
: QFrame(parent, Qt::ToolTip)
, _parent(parent)
, _currentIndex(-1)
- , _searchEngine( defaultSearchEngine() )
+ , _searchEngine( SearchEngine::defaultEngine() )
{
setFrameStyle(QFrame::Panel);
setLayoutDirection(Qt::LeftToRight);
@@ -259,8 +257,6 @@ void CompletionWidget::itemChosen(ListItem *item, Qt::MouseButton button)
}
-
-
void CompletionWidget::suggestUrls(const QString &text)
{
QWidget *w = qobject_cast<QWidget *>(parent());
@@ -284,31 +280,3 @@ void CompletionWidget::suggestUrls(const QString &text)
}
-QString CompletionWidget::defaultSearchEngine()
-{
- int n = ReKonfig::searchEngine();
- QString engine;
- switch(n)
- {
- case 0:
- engine = QL1S("google");
- break;
- case 1:
- engine = QL1S("altavista");
- break;
- case 2:
- engine = QL1S("lycos");
- break;
- case 3:
- engine = QL1S("wikipedia");
- break;
- case 4:
- engine = QL1S("wolfram");
- break;
- default:
- engine = QL1S("google");
- break;
- }
-
- return engine;
-}
diff --git a/src/urlbar/completionwidget.h b/src/urlbar/completionwidget.h
index e9851484..afd9b7e1 100644
--- a/src/urlbar/completionwidget.h
+++ b/src/urlbar/completionwidget.h
@@ -34,6 +34,7 @@
// KDE Includes
#include <KLineEdit>
+#include <KService>
// Qt Includes
#include <QFrame>
@@ -49,8 +50,8 @@ public:
virtual bool eventFilter(QObject *obj, QEvent *ev);
void setVisible(bool visible);
- QString searchEngine() { return _searchEngine; };
- void setCurrentEngine(const QString &engine) { _searchEngine = engine; };
+ KService::Ptr searchEngine() { return _searchEngine; };
+ void setCurrentEngine(KService::Ptr engine) { _searchEngine = engine; };
private slots:
void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton);
@@ -61,8 +62,6 @@ signals:
void nextItemSubChoice();
private:
- QString defaultSearchEngine();
-
void insertSearchList(const UrlSearchList &list, const QString& text);
void popup();
void clear();
@@ -76,7 +75,7 @@ private:
UrlSearchList _list;
int _currentIndex;
- QString _searchEngine;
+ KService::Ptr _searchEngine;
};
#endif // COMPLETION_WIDGET_H
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index 8f299e4f..8671c126 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -36,13 +36,12 @@
#include "application.h"
#include "websnap.h"
#include "completionwidget.h"
+#include "searchengine.h"
// KDE Includes
#include <KIcon>
-#include <KStandardDirs>
#include <KDebug>
#include <QActionGroup>
-#include <KConfigGroup>
#include <KIcon>
// Qt Includes
@@ -254,29 +253,37 @@ PreviewLabel::PreviewLabel(const QString &url, int width, int height, QWidget *p
// ---------------------------------------------------------------
-
SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent)
: ListItem(item, parent)
, m_text(text)
{
- CompletionWidget *w = qobject_cast<CompletionWidget *>(parent);
- QString currentEngine = w->searchEngine();
- kDebug() << currentEngine;
+ KService::Ptr currentEngine = SearchEngine::defaultEngine();
- m_iconLabel = new IconLabel("edit-find", this); //TODO: get the default engine icon
- m_titleLabel = new TextLabel( searchItemTitle(currentEngine, text), QString(), this);
- m_engineBar = new EngineBar(text, currentEngine, parent);
+ QString query = text;
+ KService::Ptr engine = SearchEngine::fromString(text);
+ if (engine)
+ {
+ query = query.remove(0, text.indexOf(SearchEngine::delimiter())+1);
+ }
+ else
+ {
+ engine = currentEngine;
+ }
- // without this it will not work :)
- m_url = m_engineBar->url();
+ m_url = SearchEngine::buildQuery(engine, query);
+
+ m_iconLabel = new IconLabel("edit-find", this); //TODO: get the default engine icon
+ m_titleLabel = new TextLabel( searchItemTitle(engine->name(), query), QString(), this);
+ m_engineBar = new EngineBar(currentEngine, parent);
+
layout()->addWidget( m_iconLabel );
layout()->addWidget( m_titleLabel );
layout()->addWidget( new QLabel( i18n("Engines: "), this ) );
layout()->addWidget( m_engineBar );
layout()->addWidget( new TypeIconLabel(item.type, this) );
-
- connect(m_engineBar, SIGNAL(searchEngineChanged(QString, QString)), this, SLOT(changeSearchEngine(QString, QString)));
+
+ connect(m_engineBar, SIGNAL(searchEngineChanged(KService::Ptr)), this, SLOT(changeSearchEngine(KService::Ptr)));
}
@@ -285,13 +292,11 @@ QString SearchListItem::searchItemTitle(QString engine, QString text)
return QString(i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for <b>%2</b>", engine, text));
}
-
-void SearchListItem::changeSearchEngine(QString url, QString engine)
+void SearchListItem::changeSearchEngine(KService::Ptr engine)
{
- m_titleLabel->setText(searchItemTitle(engine,m_text));
- m_iconLabel->setPixmap(Application::icon( KUrl(url) ).pixmap(16));
- QString url2 = url.replace( QL1S("\\{@}"), m_text);
- m_url = KUrl(url2);
+ m_titleLabel->setText(searchItemTitle(engine->name(),m_text));
+ m_iconLabel->setPixmap(Application::icon( KUrl(engine->property("Query").toString()) ).pixmap(16));
+ m_url = SearchEngine::buildQuery(engine, m_text);
CompletionWidget *w = qobject_cast<CompletionWidget *>(parent());
w->setCurrentEngine( engine );
@@ -307,42 +312,21 @@ void SearchListItem::nextItemSubChoice()
// -----------------------------------------------------------------------------------------------
-EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent)
- : KToolBar(parent)
+EngineBar::EngineBar(KService::Ptr selectedEngine, QWidget *parent)
+: KToolBar(parent)
{
setIconSize(QSize(16,16));
setToolButtonStyle(Qt::ToolButtonIconOnly);
m_engineGroup = new QActionGroup(this);
m_engineGroup->setExclusive(true);
-
- KConfig config("kuriikwsfilterrc"); //Share with konqueror
- KConfigGroup cg = config.group("General");
- QStringList favoriteEngines;
- favoriteEngines << "wikipedia" << "google"; //defaults
- favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines);
-
- // default engine
- CompletionWidget *w = qobject_cast<CompletionWidget *>(parent);
- QString defaultEngine = w->searchEngine();
- KService::Ptr service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(defaultEngine));
-
- m_engineGroup->addAction(newEngineAction(service, selectedEngine));
-
- // set url;
- QString url = service->property("Query").toString();
- url = url.replace("\\{@}",text);
- m_url = KUrl(url);
-
- Q_FOREACH(const QString &engine, favoriteEngines)
+
+ m_engineGroup->addAction(newEngineAction(SearchEngine::defaultEngine(), selectedEngine));
+ foreach(KService::Ptr engine, SearchEngine::favorites())
{
- if(!engine.isEmpty())
+ if(engine->desktopEntryName()!=SearchEngine::defaultEngine()->desktopEntryName())
{
- service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine));
- if(service && service->desktopEntryName() != defaultEngine)
- {
- m_engineGroup->addAction(newEngineAction(service, selectedEngine));
- }
+ m_engineGroup->addAction(newEngineAction(engine, selectedEngine));
}
}
@@ -350,18 +334,14 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget
}
-KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine)
+KAction *EngineBar::newEngineAction(KService::Ptr engine, KService::Ptr selectedEngine)
{
- KAction *a = new KAction(Application::icon(m_url), service->name(), this);
+ QString url = engine->property("Query").toString();
+ KAction *a = new KAction(Application::icon(url), engine->name(), this);
a->setCheckable(true);
- if (service->name()==selectedEngine)
- a->setChecked(true);
-
- QString url = service->property("Query").toString();
-
- a->setData( QStringList() << url << service->desktopEntryName() );
+ if (engine->desktopEntryName()==selectedEngine->desktopEntryName()) a->setChecked(true);
+ a->setData(engine->entryPath());
connect(a, SIGNAL(triggered(bool)), this, SLOT(changeSearchEngine()));
-
return a;
}
@@ -369,8 +349,7 @@ KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngin
void EngineBar::changeSearchEngine()
{
KAction *a = qobject_cast<KAction*>(sender());
- QStringList list = a->data().toStringList();
- emit searchEngineChanged(list.first(), list.last());
+ emit searchEngineChanged(KService::serviceByDesktopPath(a->data().toString()));
}
diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h
index de42fd03..c15ef3f9 100644
--- a/src/urlbar/listitem.h
+++ b/src/urlbar/listitem.h
@@ -126,22 +126,18 @@ class EngineBar : public KToolBar
Q_OBJECT
public:
- EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent = 0);
-
+ EngineBar(KService::Ptr selectedEngine, QWidget *parent = 0);
void selectNextEngine();
- KUrl url() { return m_url; };
signals:
- void searchEngineChanged(QString url, QString engine);
+ void searchEngineChanged(KService::Ptr engine);
private slots:
void changeSearchEngine();
private:
- KAction *newEngineAction(KService::Ptr service, QString selectedEngine);
-
+ KAction *newEngineAction(KService::Ptr engine, KService::Ptr selectedEngine);
QActionGroup *m_engineGroup;
- KUrl m_url;
};
@@ -159,7 +155,7 @@ public slots:
virtual void nextItemSubChoice();
private slots:
- void changeSearchEngine(QString url, QString engine);
+ void changeSearchEngine(KService::Ptr engine);
private:
QString searchItemTitle(QString engine, QString text);
@@ -167,8 +163,8 @@ private:
TextLabel* m_titleLabel;
IconLabel* m_iconLabel;
EngineBar* m_engineBar;
-
QString m_text;
+ KService::Ptr m_currentEngine;
};
diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp
index e4a45105..362484a6 100644
--- a/src/urlbar/urlresolver.cpp
+++ b/src/urlbar/urlresolver.cpp
@@ -184,15 +184,7 @@ UrlSearchList UrlResolver::qurlFromUserInputResolution()
// STEP 2 = Web Searches
UrlSearchList UrlResolver::webSearchesResolution()
{
- UrlSearchList list;
-
- if(KUrl(_typedString).isRelative())
- {
- UrlSearchItem gItem(UrlSearchItem::Search, KUrl(), QString() ); // others will find this url..
- list << gItem;
- }
-
- return list;
+ return UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, KUrl(), QString());
}
diff --git a/src/webtab.cpp b/src/webtab.cpp
index 02511d39..7687a957 100644
--- a/src/webtab.cpp
+++ b/src/webtab.cpp
@@ -119,9 +119,29 @@ WebPage *WebTab::page()
}
+// TODO:
+// Import the "about" check and the one in protocolhandler
+// in some (static?) methods in NewTabPage
KUrl WebTab::url()
{
- return KUrl( view()->url() );
+ KUrl u = KUrl( view()->url() );
+ if( u.scheme() == QL1S("about") )
+ {
+ QWebElement rootElement = page()->mainFrame()->documentElement();
+ if( rootElement.document().findAll("#rekonq-newtabpage").count() == 0 )
+ return u;
+ if( rootElement.findAll(".favorites").count() > 0 )
+ return KUrl("about:favorites");
+ if( rootElement.findAll(".closedTabs").count() > 0 )
+ return KUrl("about:closedTabs");
+ if( rootElement.findAll(".history").count() > 0 )
+ return KUrl("about:history");
+ if( rootElement.findAll(".bookmarks").count() > 0 )
+ return KUrl("about:bookmarks");
+ if( rootElement.findAll(".downloads").count() > 0 )
+ return KUrl("about:downloads");
+ }
+ return u;
}
diff --git a/src/webview.cpp b/src/webview.cpp
index f48afffb..78fd2eaa 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -37,6 +37,7 @@
#include "mainview.h"
#include "webpage.h"
#include "bookmarksmanager.h"
+#include "searchengine.h"
// KDE Includes
#include <KService>
@@ -162,31 +163,13 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
{
KActionMenu *searchMenu = new KActionMenu(KIcon("edit-find"), i18n("Search with"), this);
- KConfig config("kuriikwsfilterrc"); //Share with konqueror
- KConfigGroup cg = config.group("General");
- QStringList favoriteEngines;
- favoriteEngines << "wikipedia" << "google"; //defaults
- favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines);
- QString keywordDelimiter = cg.readEntry("KeywordDelimiter", ":");
- KService::Ptr service;
- KUriFilterData data;
-
- Q_FOREACH(const QString &engine, favoriteEngines)
+ foreach(KService::Ptr engine, SearchEngine::favorites())
{
- if(!engine.isEmpty())
- {
- service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine));
- if(service)
- {
- const QString searchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter;
- data.setData(searchProviderPrefix + "some keyword");
- a = new KAction(service->name(), this);
- a->setIcon( Application::icon( data.uri() ) );
- a->setData(searchProviderPrefix);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(search()));
- searchMenu->addAction(a);
- }
- }
+ a = new KAction(engine->name(), this);
+ a->setIcon( Application::icon( SearchEngine::buildQuery(engine,"")) );
+ a->setData(engine->entryPath());
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(search()));
+ searchMenu->addAction(a);
}
if (!searchMenu->menu()->isEmpty())
@@ -401,9 +384,9 @@ QPoint WebView::mousePos()
void WebView::search()
{
KAction *a = qobject_cast<KAction*>(sender());
- QString search = a->data().toString() + selectedText();
- KUrl urlSearch = KUrl::fromEncoded(search.toUtf8());
-
+ KService::Ptr engine = KService::serviceByDesktopPath(a->data().toString());
+ KUrl urlSearch = KUrl(SearchEngine::buildQuery(engine, selectedText()));
+
emit loadUrl(urlSearch, Rekonq::NewCurrentTab);
}