Skip to content

Commit

Permalink
feat: use base64 encoding for URL in config
Browse files Browse the repository at this point in the history
use base64 encoding for URL in config file

Log:use  base64 encoding for URL in config file
  • Loading branch information
kt286 committed Dec 20, 2022
1 parent 1e1fcef commit 3d3fb43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/grand-search/gui/searchconfig/searchenginewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <DStyleOption>
#include <DLineEdit>

#include <QByteArray>

#define Margin 10

DWIDGET_USE_NAMESPACE
Expand Down Expand Up @@ -93,7 +95,7 @@ SearchEngineWidget::SearchEngineWidget(QWidget *parent)
m_lineEdit->setPlaceholderText(tr("You need to use \"%0\" to replace the keyword in the URL"));
if(userChoice == GRANDSEARCH_WEB_SEARCHENGINE_CUSTOM){
QString searchEngineCustom = SearchConfig::instance()->getConfig(GRANDSEARCH_WEB_GROUP, GRANDSEARCH_WEB_SEARCHENGINE_CUSTOM_ADDR, "").toString();
m_lineEdit->setText(searchEngineCustom);
m_lineEdit->setText(QString::fromStdString(QByteArray::fromBase64(searchEngineCustom.toUtf8()).toStdString()));
m_lineEdit->setVisible(true);
} else {
m_lineEdit->setVisible(false);
Expand Down Expand Up @@ -125,7 +127,7 @@ void SearchEngineWidget::checkedChangedIndex(int index)

if(text == GRANDSEARCH_WEB_SEARCHENGINE_CUSTOM){
QString searchEngineCustom = SearchConfig::instance()->getConfig(GRANDSEARCH_WEB_GROUP, GRANDSEARCH_WEB_SEARCHENGINE_CUSTOM_ADDR, "").toString();
m_lineEdit->setText(searchEngineCustom);
m_lineEdit->setText(QString::fromStdString(QByteArray::fromBase64(searchEngineCustom.toUtf8()).toStdString()));
m_lineEdit->setVisible(true);
} else {
m_lineEdit->setVisible(false);
Expand Down Expand Up @@ -157,6 +159,6 @@ void SearchEngineWidget::setCustomSearchEngineAddress(const QString &text)
m_lineEdit->showAlertMessage(tr("Invalid URL"), m_lineEdit, 2000);
} else {
m_lineEdit->setAlert(false);
SearchConfig::instance()->setConfig(GRANDSEARCH_WEB_GROUP, GRANDSEARCH_WEB_SEARCHENGINE_CUSTOM_ADDR, text);
SearchConfig::instance()->setConfig(GRANDSEARCH_WEB_GROUP, GRANDSEARCH_WEB_SEARCHENGINE_CUSTOM_ADDR, QString::fromStdString(text.toUtf8().toBase64().toStdString()));
}
}
5 changes: 4 additions & 1 deletion src/libgrand-search-daemon/searcher/web/statictextworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "configuration/configer.h"
#include "global/searchhelper.h"

#include <QByteArray>

using namespace GrandSearch;

StaticTextWorker::StaticTextWorker(const QString &name, QObject *parent) : ProxyWorker(name, parent)
Expand Down Expand Up @@ -113,7 +115,8 @@ QString StaticTextWorker::createUrl(const QString &searchEngine) const

auto config = Configer::instance()->group(GRANDSEARCH_WEB_GROUP);
QString searchEngineAddr = config->value(GRANDSEARCH_WEB_SEARCHENGINE_CUSTOM_ADDR, QString(""));
if(searchEngineAddr.isEmpty()) {
searchEngineAddr = QString::fromStdString(QByteArray::fromBase64(searchEngineAddr.toUtf8()).toStdString());
if(searchEngineAddr.isEmpty() || !searchEngineAddr.contains("%0")) {
if (SearchHelper::instance()->isSimplifiedChinese()) {
searchEngineAddr = baidu;
} else {
Expand Down
2 changes: 1 addition & 1 deletion translations/dde-grand-search_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
<message>
<location filename="../src/grand-search/gui/searchconfig/searchenginewidget.cpp" line="87"/>
<source>You need to use &quot;%0&quot; to replace the keyword in the URL</source>
<translation>需要使用 &quot;%0&quot; 来替换URL中关键词</translation>
<translation>需要使用 “%0” 来替换URL中关键词</translation>
</message>
<message>
<location filename="../src/grand-search/gui/searchconfig/searchenginewidget.cpp" line="87"/>
Expand Down

0 comments on commit 3d3fb43

Please sign in to comment.