1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Merge pull request #1841 from innermous/master

Added action with all in one image search engines
This commit is contained in:
David Rosca 2016-01-20 21:10:28 +01:00
commit 95f10443ef
3 changed files with 27 additions and 6 deletions

View File

@ -51,17 +51,21 @@ void ImageFinder::setSearchEngine(ImageFinder::SearchEngine searchEngine)
settings.endGroup();
}
QString ImageFinder::searchEngineName() const
QString ImageFinder::searchEngineName(SearchEngine engine) const
{
if (engine == SearchEngine::None)
engine = m_searchEngine;
QStringList searchEngines;
searchEngines << QSL("Google") << QSL("Yandex") << QSL("TinEye");
return searchEngines.at(m_searchEngine);
return searchEngines.at(engine);
}
QUrl ImageFinder::getSearchQuery(const QUrl &imageUrl)
QUrl ImageFinder::getSearchQuery(const QUrl &imageUrl, SearchEngine engine)
{
switch (m_searchEngine)
if (engine == SearchEngine::None)
engine = m_searchEngine;
switch (engine)
{
case SearchEngine::Google:
return QUrl(QSL("https://www.google.com/searchbyimage?site=search&image_url=%1").arg(imageUrl.toString()));

View File

@ -27,6 +27,7 @@ class ImageFinder : public QObject
Q_OBJECT
public:
enum SearchEngine {
None = -1,
Google = 0,
Yandex,
TinEye
@ -37,9 +38,9 @@ public:
SearchEngine searchEngine() const;
void setSearchEngine(SearchEngine searchEngine);
QString searchEngineName() const;
QString searchEngineName(SearchEngine engine = SearchEngine::None) const;
QUrl getSearchQuery(const QUrl &imageUrl);
QUrl getSearchQuery(const QUrl &imageUrl, SearchEngine engine = SearchEngine::None);
private:
QString m_settingsFile;

View File

@ -95,5 +95,21 @@ void ImageFinderPlugin::populateWebViewMenu(QMenu *menu, WebView *view, const We
connect(action, SIGNAL(triggered()), view, SLOT(openUrlInSelectedTab()));
connect(action, SIGNAL(ctrlTriggered()), view, SLOT(openUrlInBackgroundTab()));
menu->addAction(action);
Menu* swMenu = new Menu(tr("Search image with..."), menu);
swMenu->setCloseOnMiddleClick(true);
for (int i = 0; i < 3; ++i)
{
ImageFinder::SearchEngine e = static_cast<ImageFinder::SearchEngine>(i);
QString engineName = m_finder->searchEngineName(e);
Action* act = new Action(engineName);
act->setIcon(QIcon(QSL(":/imgfinder/data/%1.png").arg(engineName.toLower())));
act->setData(m_finder->getSearchQuery(r.imageUrl(), e));
connect(act, SIGNAL(triggered()), view, SLOT(openUrlInSelectedTab()));
connect(act, SIGNAL(ctrlTriggered()), view, SLOT(openUrlInBackgroundTab()));
swMenu->addAction(act);
}
menu->addMenu(swMenu);
}
}