1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Added action with all in one image search engines

This commit is contained in:
Vladislav Tronko 2016-01-20 19:44:22 +02:00
parent 20f35c8a8d
commit b311902cf3
3 changed files with 27 additions and 6 deletions

View File

@ -51,17 +51,21 @@ void ImageFinder::setSearchEngine(ImageFinder::SearchEngine searchEngine)
settings.endGroup(); settings.endGroup();
} }
QString ImageFinder::searchEngineName() const QString ImageFinder::searchEngineName(SearchEngine engine) const
{ {
if (engine == SearchEngine::None)
engine = m_searchEngine;
QStringList searchEngines; QStringList searchEngines;
searchEngines << QSL("Google") << QSL("Yandex") << QSL("TinEye"); 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: case SearchEngine::Google:
return QUrl(QSL("https://www.google.com/searchbyimage?site=search&image_url=%1").arg(imageUrl.toString())); 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 Q_OBJECT
public: public:
enum SearchEngine { enum SearchEngine {
None = -1,
Google = 0, Google = 0,
Yandex, Yandex,
TinEye TinEye
@ -37,9 +38,9 @@ public:
SearchEngine searchEngine() const; SearchEngine searchEngine() const;
void setSearchEngine(SearchEngine searchEngine); 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: private:
QString m_settingsFile; 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(triggered()), view, SLOT(openUrlInSelectedTab()));
connect(action, SIGNAL(ctrlTriggered()), view, SLOT(openUrlInBackgroundTab())); connect(action, SIGNAL(ctrlTriggered()), view, SLOT(openUrlInBackgroundTab()));
menu->addAction(action); 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);
} }
} }