summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-04-20 00:42:12 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-04-20 00:42:12 +0200
commit7d11112b0c1836695dee398a5122051a0ec99585 (patch)
tree01b1f4be8f1d05f1e2a1c11df3a7df53f488b654
parentthis commit renames Item classes with this logic (diff)
downloadrekonq-7d11112b0c1836695dee398a5122051a0ec99585.tar.xz
Fix default engine implementation and fix a bit code
-rw-r--r--src/urlbar/completionwidget.cpp44
-rw-r--r--src/urlbar/completionwidget.h8
-rw-r--r--src/urlbar/listitem.cpp98
-rw-r--r--src/urlbar/listitem.h7
4 files changed, 86 insertions, 71 deletions
diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp
index be86238d..8307940b 100644
--- a/src/urlbar/completionwidget.cpp
+++ b/src/urlbar/completionwidget.cpp
@@ -28,6 +28,9 @@
#include "completionwidget.h"
#include "completionwidget.moc"
+// Auto Includes
+#include "rekonq.h"
+
// Local Includes
#include "application.h"
#include "urlresolver.h"
@@ -45,11 +48,15 @@
#include <QEvent>
#include <QKeyEvent>
+// Defines
+#define QL1S(x) QLatin1String(x)
+
CompletionWidget::CompletionWidget(QWidget *parent)
- : QFrame( parent, Qt::ToolTip)
+ : QFrame(parent, Qt::ToolTip)
, _parent(parent)
, _currentIndex(-1)
+ , _searchEngine( defaultSearchEngine() )
{
setFrameStyle(QFrame::Panel);
setLayoutDirection(Qt::LeftToRight);
@@ -66,8 +73,8 @@ void CompletionWidget::insertSearchList(const UrlSearchList &list, const QString
int i = 0;
foreach(UrlSearchItem item, _list)
{
- ListItem *suggestion = ListItemFactory::create(item, text);
- suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase: QPalette::Base);
+ ListItem *suggestion = ListItemFactory::create(item, text, this);
+ suggestion->setBackgroundRole(i%2 ? QPalette::AlternateBase : QPalette::Base);
connect(suggestion, SIGNAL(itemClicked(ListItem *, Qt::MouseButton)), this, SLOT(itemChosen(ListItem *, Qt::MouseButton)));
connect(this, SIGNAL(nextItemSubChoice()), suggestion, SLOT(nextItemSubChoice()));
suggestion->setObjectName( QString::number(i++) );
@@ -268,7 +275,6 @@ void CompletionWidget::suggestUrls(const QString &text)
UrlResolver res(text);
UrlSearchList list = res.orderedSearchItems();
-
if(list.count() > 0)
{
clear();
@@ -276,3 +282,33 @@ void CompletionWidget::suggestUrls(const QString &text)
popup();
}
}
+
+
+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 896518fc..e9851484 100644
--- a/src/urlbar/completionwidget.h
+++ b/src/urlbar/completionwidget.h
@@ -49,6 +49,9 @@ public:
virtual bool eventFilter(QObject *obj, QEvent *ev);
void setVisible(bool visible);
+ QString searchEngine() { return _searchEngine; };
+ void setCurrentEngine(const QString &engine) { _searchEngine = engine; };
+
private slots:
void itemChosen(ListItem *item, Qt::MouseButton = Qt::LeftButton);
void suggestUrls(const QString &text);
@@ -58,6 +61,8 @@ signals:
void nextItemSubChoice();
private:
+ QString defaultSearchEngine();
+
void insertSearchList(const UrlSearchList &list, const QString& text);
void popup();
void clear();
@@ -70,7 +75,8 @@ private:
UrlSearchList _list;
int _currentIndex;
- QString *_searchEngine;
+
+ QString _searchEngine;
};
#endif // COMPLETION_WIDGET_H
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index 0ecc56fe..7dc22dda 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -35,6 +35,7 @@
#include "urlresolver.h"
#include "application.h"
#include "websnap.h"
+#include "completionwidget.h"
// KDE Includes
#include <KIcon>
@@ -188,12 +189,7 @@ QLabel *TypeIconLabel::getIcon(QString icon)
IconLabel::IconLabel(const QString &icon, QWidget *parent)
: QLabel(parent)
{
- QPixmap pixmapIcon = KIcon(QWebSettings::iconForUrl(icon)).pixmap(16);
- if (pixmapIcon.isNull())
- {
- pixmapIcon = KIcon("text-html").pixmap(16);
- }
-
+ QPixmap pixmapIcon = Application::icon( KUrl(icon) ).pixmap(16);
setFixedSize(16,16);
setPixmap(pixmapIcon);
}
@@ -220,7 +216,7 @@ TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget
PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text, QWidget *parent)
: ListItem(item, parent)
{
- QLabel *previewLabelIcon = new QLabel(parent);
+ QLabel *previewLabelIcon = new QLabel(this);
previewLabelIcon->setFixedSize(45,33);
new PreviewLabel(item.url.url(), 38, 29, previewLabelIcon);
IconLabel* icon = new IconLabel(item.url.url(), previewLabelIcon);
@@ -229,9 +225,10 @@ PreviewListItem::PreviewListItem(const UrlSearchItem &item, const QString &text,
QVBoxLayout *vLayout = new QVBoxLayout(this);
vLayout->setMargin(0);
- ((QHBoxLayout *)layout())->addLayout(vLayout);
vLayout->addWidget( new TextLabel(item.title, text, this) );
vLayout->addWidget( new TextLabel("<i>" + item.url.url() + "</i>", text, this) );
+ ((QHBoxLayout *)layout())->addLayout(vLayout);
+
layout()->addWidget( new TypeIconLabel(item.type, this) );
}
@@ -259,27 +256,25 @@ PreviewLabel::PreviewLabel(const QString &url, int width, int height, QWidget *p
// ---------------------------------------------------------------
-QString SearchListItem::m_currentEngine = "";
-
-
SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent)
: ListItem(item, parent)
, m_text(text)
{
- if (m_currentEngine == "")
- m_currentEngine = EngineBar::defaultEngine();
+ CompletionWidget *w = qobject_cast<CompletionWidget *>(parent);
+ QString currentEngine = w->searchEngine();
+ kDebug() << currentEngine;
m_iconLabel = new IconLabel("edit-find", this); //TODO: get the default engine icon
- m_titleLabel = new TextLabel(searchItemTitle(m_currentEngine, text));
- m_engineBar = new EngineBar(text, m_currentEngine, this);
+ m_titleLabel = new TextLabel( searchItemTitle(currentEngine, text), QString(), this);
+ m_engineBar = new EngineBar(text, currentEngine, parent);
// without this it will not work :)
m_url = m_engineBar->url();
- layout()->addWidget(m_iconLabel);
- layout()->addWidget(m_titleLabel);
+ layout()->addWidget( m_iconLabel );
+ layout()->addWidget( m_titleLabel );
layout()->addWidget( new QLabel( i18n("Engines: "), this ) );
- layout()->addWidget(m_engineBar);
+ layout()->addWidget( m_engineBar );
layout()->addWidget( new TypeIconLabel(item.type, this) );
connect(m_engineBar, SIGNAL(searchEngineChanged(QString, QString)), this, SLOT(changeSearchEngine(QString, QString)));
@@ -296,9 +291,11 @@ void SearchListItem::changeSearchEngine(QString url, QString engine)
{
m_titleLabel->setText(searchItemTitle(engine,m_text));
m_iconLabel->setPixmap(Application::icon( KUrl(url) ).pixmap(16));
- QString url2 = url.replace("\\{@}",m_text);
+ QString url2 = url.replace( QL1S("\\{@}"), m_text);
m_url = KUrl(url2);
- m_currentEngine = engine;
+
+ CompletionWidget *w = qobject_cast<CompletionWidget *>(parent());
+ w->setCurrentEngine( engine );
}
@@ -327,8 +324,10 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget
favoriteEngines = cg.readEntry("FavoriteSearchEngines", favoriteEngines);
// default engine
- QString defaultEngine = EngineBar::defaultEngine();
+ 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;
@@ -341,7 +340,7 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget
if(!engine.isEmpty())
{
service = KService::serviceByDesktopPath(QString("searchproviders/%1.desktop").arg(engine));
- if(service && service->desktopEntryName()!=defaultEngine)
+ if(service && service->desktopEntryName() != defaultEngine)
{
m_engineGroup->addAction(newEngineAction(service, selectedEngine));
}
@@ -352,45 +351,16 @@ EngineBar::EngineBar(const QString &text, const QString &selectedEngine, QWidget
}
-QString EngineBar::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 engine;
-}
-
-
KAction *EngineBar::newEngineAction(KService::Ptr service, QString selectedEngine)
{
KAction *a = new KAction(Application::icon(m_url), service->name(), this);
a->setCheckable(true);
- if (service->name()==selectedEngine) a->setChecked(true);
+ if (service->name()==selectedEngine)
+ a->setChecked(true);
QString url = service->property("Query").toString();
- a->setData(QStringList() << url << service->name());
+ a->setData( QStringList() << url << service->desktopEntryName() );
connect(a, SIGNAL(triggered(bool)), this, SLOT(changeSearchEngine()));
return a;
@@ -447,18 +417,22 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text
{
ListItem *newItem;
- if (item.type & UrlSearchItem::Browse)
+ switch(item.type)
{
+ case UrlSearchItem::Browse:
newItem = new BrowseListItem(item, text, parent);
- }
- else if (item.type & UrlSearchItem::Search)
- {
+ break;
+
+ case UrlSearchItem::Search:
newItem = new SearchListItem(item, text, parent);
- }
- else
- {
+ break;
+
+ case UrlSearchItem::History:
+ case UrlSearchItem::Bookmark:
+ default:
newItem = new PreviewListItem(item, text, parent);
+ break;
}
-
+
return newItem;
}
diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h
index 67bfb764..de42fd03 100644
--- a/src/urlbar/listitem.h
+++ b/src/urlbar/listitem.h
@@ -128,7 +128,6 @@ class EngineBar : public KToolBar
public:
EngineBar(const QString &text, const QString &selectedEngine, QWidget *parent = 0);
- static QString defaultEngine();
void selectNextEngine();
KUrl url() { return m_url; };
@@ -164,12 +163,12 @@ private slots:
private:
QString searchItemTitle(QString engine, QString text);
+
TextLabel* m_titleLabel;
IconLabel* m_iconLabel;
EngineBar* m_engineBar;
- QString m_text;
- static QString m_currentEngine;
+ QString m_text;
};
@@ -215,7 +214,7 @@ public:
class ListItemFactory
{
public:
- static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent = 0);
+ static ListItem *create(const UrlSearchItem &item, const QString &text, QWidget *parent);
};