Skip to content

Commit

Permalink
fix: modify for code review
Browse files Browse the repository at this point in the history
modify for code review

Log: modify for code review
  • Loading branch information
kt286 committed Jun 22, 2022
1 parent 1303d5a commit 054821c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/grand-search-daemon/searcher/web/statictextworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ 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()) {
if (SearchHelper::instance()->isSimplifiedChinese()) {
searchEngineAddr = baidu;
} else {
searchEngineAddr = google;
}
}

static const QHash<QString, QString> searchEngineChinese{{GRANDSEARCH_WEB_SEARCHENGINE_GOOGLE, "https://www.google.com/search?q=%0"},
{GRANDSEARCH_WEB_SEARCHENGINE_BING, "https://bing.com/search?q=%0"},
Expand Down
24 changes: 18 additions & 6 deletions src/grand-search/gui/searchconfig/searchenginewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ SearchEngineWidget::SearchEngineWidget(QWidget *parent)
m_mainLayout->addWidget(m_comboboxWidget);
m_comboboxWidget->setProperty(GRANDSEARCH_SEARCH_GROUP, GRANDSEARCH_WEB_SEARCHENGINE);

m_lineEdit = new QLineEdit(this);
if(userChoice == "Custom"){
m_lineEdit = new Dtk::Widget::DLineEdit(this);
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->setVisible(true);
Expand All @@ -117,7 +118,7 @@ SearchEngineWidget::SearchEngineWidget(QWidget *parent)
m_mainLayout->addWidget(m_lineEdit);

connect(m_comboboxWidget, &ComboboxWidget::checkedChanged, this, &SearchEngineWidget::checkedChangedIndex);
connect(m_lineEdit, &QLineEdit::textChanged, this, &SearchEngineWidget::setCustomSearchEngineAddress);
connect(m_lineEdit, &DLineEdit::textChanged, this, &SearchEngineWidget::setCustomSearchEngineAddress);
}

SearchEngineWidget::~SearchEngineWidget()
Expand All @@ -139,7 +140,7 @@ void SearchEngineWidget::checkedChangedIndex(int index)
}
SearchConfig::instance()->setConfig(GRANDSEARCH_WEB_GROUP, GRANDSEARCH_WEB_SEARCHENGINE, text);

if(text == "Custom"){
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->setVisible(true);
Expand All @@ -161,7 +162,18 @@ int SearchEngineWidget::getIndex(const QString text) const
return index;
}

void SearchEngineWidget::setCustomSearchEngineAddress(QString text)
void SearchEngineWidget::setCustomSearchEngineAddress(const QString &text)
{
SearchConfig::instance()->setConfig(GRANDSEARCH_WEB_GROUP, GRANDSEARCH_WEB_SEARCHENGINE_CUSTOM_ADDR, text);
if (text.isEmpty()) {
m_lineEdit->setAlert(false);
return;
}

if (!text.contains("%0")) {
m_lineEdit->setAlert(true);
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);
}
}
4 changes: 2 additions & 2 deletions src/grand-search/gui/searchconfig/searchenginewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SearchEngineWidget : public Dtk::Widget::DWidget

private slots:
void checkedChangedIndex(int index);
void setCustomSearchEngineAddress(QString text);
void setCustomSearchEngineAddress(const QString &text);

private:
int getIndex(const QString text) const;
Expand All @@ -51,7 +51,7 @@ private slots:
QVBoxLayout *m_mainLayout = nullptr;
QLabel *m_groupLabel= nullptr;
QLabel *m_contentLabel = nullptr;
QLineEdit *m_lineEdit = nullptr;
Dtk::Widget::DLineEdit *m_lineEdit = nullptr;

QHash<QString, QString> m_groupName; // <searchGroupName, displayGroupName>
GrandSearch::ComboboxWidget* m_comboboxWidget;
Expand Down
10 changes: 10 additions & 0 deletions translations/dde-grand-search_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,16 @@
<source>Custom</source>
<translation>自定义</translation>
</message>
<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>
</message>
<message>
<location filename="../src/grand-search/gui/searchconfig/searchenginewidget.cpp" line="87"/>
<source>Invalid URL</source>
<translation>URL格式错误</translation>
</message>
</context>
<context>
<name>StaticTextWorker</name>
Expand Down

0 comments on commit 054821c

Please sign in to comment.