1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-16 03:52:10 +01:00
falkonOfficial/src/plugins/ImageFinder/imagefinder.cpp

85 lines
2.7 KiB
C++
Raw Normal View History

2016-01-13 19:55:37 +01:00
/* ============================================================
2017-08-25 17:11:29 +02:00
* ImageFinder plugin for Falkon
2016-01-13 19:55:37 +01:00
* Copyright (C) 2016 Vladislav Tronko <innermous@gmail.com>
*
* 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 3 of the License, or
* (at your option) any later version.
*
* 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/>.
* ============================================================ */
#include "imagefinder.h"
#include <QApplication>
#include <QSettings>
#include <QUrl>
#include "qzcommon.h"
ImageFinder::ImageFinder(const QString &settingsFile, QObject *parent)
: QObject(parent)
, m_settingsFile(settingsFile)
, m_searchEngine(SearchEngine::Google)
{
QSettings settings(m_settingsFile, QSettings::IniFormat);
settings.beginGroup(QSL("ImageFinder"));
m_searchEngine = static_cast<SearchEngine>(settings.value(QSL("SearchEngine")).toInt());
settings.endGroup();
}
ImageFinder::SearchEngine ImageFinder::searchEngine() const
{
return m_searchEngine;
}
void ImageFinder::setSearchEngine(ImageFinder::SearchEngine searchEngine)
{
m_searchEngine = searchEngine;
QSettings settings(m_settingsFile, QSettings::IniFormat);
settings.beginGroup(QSL("ImageFinder"));
settings.setValue(QSL("SearchEngine"), m_searchEngine);
settings.endGroup();
}
QString ImageFinder::searchEngineName(SearchEngine engine) const
2016-01-13 19:55:37 +01:00
{
if (engine == SearchEngine::None)
engine = m_searchEngine;
2016-01-13 19:55:37 +01:00
QStringList searchEngines;
searchEngines << QSL("Google") << QSL("Yandex") << QSL("TinEye");
return searchEngines.at(engine);
2016-01-13 19:55:37 +01:00
}
QUrl ImageFinder::getSearchQuery(const QUrl &imageUrl, SearchEngine engine)
2016-01-13 19:55:37 +01:00
{
if (engine == SearchEngine::None)
engine = m_searchEngine;
switch (engine)
2016-01-13 19:55:37 +01:00
{
case SearchEngine::Google:
return QUrl(QSL("https://www.google.com/searchbyimage?site=search&image_url=%1").arg(imageUrl.toString()));
break;
case SearchEngine::Yandex:
return QUrl(QSL("https://yandex.com/images/search?&img_url=%1&rpt=imageview").arg(imageUrl.toString()));
break;
case SearchEngine::TinEye:
return QUrl(QSL("http://www.tineye.com/search?url=%1").arg(imageUrl.toString()));
break;
default: return QUrl();
}
}