mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Merge pull request #1841 from innermous/master
Added action with all in one image search engines
This commit is contained in:
commit
95f10443ef
@ -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()));
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user