From 9b7bcf54c62d4688436e455d2069f79e8ce3d471 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Sat, 20 Mar 2021 15:37:54 +0800 Subject: [PATCH] Feat:Add cloud sync interface. --- libsearch/global-settings.cpp | 79 +++++++++++++++++++++++++++ libsearch/global-settings.h | 10 ++++ libsearch/index/pinyinWithoutTone.txt | 6 +- src/control/search-detail-view.cpp | 7 ++- src/control/search-list-view.cpp | 4 ++ 5 files changed, 102 insertions(+), 4 deletions(-) diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index fdf3a35..9144617 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -141,6 +141,85 @@ QStringList GlobalSettings::getBlockDirs() return m_block_dirs_settings->allKeys(); } +void GlobalSettings::appendCloudData(const QString &key, const QString &value) +{ + QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat); + m_qSettings->beginGroup(key); + QStringList values = m_qSettings->value(key).toStringList(); + m_qSettings->endGroup(); + if (values.contains(value)) { + values.removeOne(value); + } + values.insert(0,value); + + m_qSettings->beginGroup(key); + m_qSettings->setValue(key, values); + m_qSettings->endGroup(); + if (m_qSettings) { + delete m_qSettings; + m_qSettings = NULL; + } +} + +void GlobalSettings::setCloudData(const QString &key, const QStringList &values) +{ + QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat); + m_qSettings->beginGroup(key); + m_qSettings->setValue(key, values); + m_qSettings->endGroup(); + if (m_qSettings) { + delete m_qSettings; + m_qSettings = NULL; + } +} + +bool GlobalSettings::removeOneCloudData(const QString &key, const QString &value) +{ + if (!QFileInfo(CLOUD_FILE).isFile()) return false; + QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat); + m_qSettings->beginGroup(key); + QStringList values = m_qSettings->value(key).toStringList(); + m_qSettings->endGroup(); + if (values.contains(value)) { + values.removeOne(value); + } else return false; + m_qSettings->beginGroup(key); + m_qSettings->setValue(key, values); + m_qSettings->endGroup(); + if (m_qSettings) { + delete m_qSettings; + m_qSettings = NULL; + } + return true; +} + +bool GlobalSettings::removeAllCloudData(const QString &key) +{ + if (!QFileInfo(CLOUD_FILE).isFile()) return false; + QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat); + m_qSettings->beginGroup(key); + m_qSettings->beginGroup(key); + m_qSettings->setValue(key, QStringList()); + m_qSettings->endGroup(); + if (m_qSettings) { + delete m_qSettings; + m_qSettings = NULL; + } + return true; +} + +QStringList GlobalSettings::getCloudData(const QString &key) +{ + if (!QFileInfo(CLOUD_FILE).isFile()) return QStringList(); + QSettings * m_qSettings = new QSettings(CLOUD_FILE, QSettings::IniFormat); + m_qSettings->beginGroup(key); + QStringList values = m_qSettings->value(key).toStringList(); + m_qSettings->endGroup(); + if(m_qSettings) + delete m_qSettings; + return values; +} + //here should be override //MouseZhangZh void GlobalSettings::setValue(const QString &key, const QVariant &value) diff --git a/libsearch/global-settings.h b/libsearch/global-settings.h index 7515b9d..c9aa011 100644 --- a/libsearch/global-settings.h +++ b/libsearch/global-settings.h @@ -25,6 +25,7 @@ #include #include #include +#include //#include //If use pkg_config, it wont build succes,why????????? //My demo can build access yet. @@ -43,6 +44,10 @@ #define PATH_NOT_IN_HOME 2; #define PATH_PARENT_BLOCKED 3; +#define CLOUD_FILE QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-cloud.conf" +#define CLOUD_HISTORY "history" +#define CLOUD_APPLICATIONS "applications" + class LIBSEARCH_EXPORT GlobalSettings : public QObject { Q_OBJECT @@ -69,6 +74,11 @@ public Q_SLOTS: */ bool setBlockDirs(const QString& path, int &returnCode,bool remove = false); QStringList getBlockDirs(); + void appendCloudData(const QString& key, const QString& value); + void setCloudData(const QString& key, const QStringList& values); + bool removeOneCloudData(const QString& key, const QString& value); + bool removeAllCloudData(const QString& key); + QStringList getCloudData(const QString& key); void forceSync(const QString& = nullptr); diff --git a/libsearch/index/pinyinWithoutTone.txt b/libsearch/index/pinyinWithoutTone.txt index 9e3abac..5477369 100644 --- a/libsearch/index/pinyinWithoutTone.txt +++ b/libsearch/index/pinyinWithoutTone.txt @@ -6016,7 +6016,7 @@ feng 仹 cang 仺 ren,lin 任 wang 仼 -bin,fen 份 +fen 份 di 仾 fang,pang 仿 zhong 伀 @@ -6221,7 +6221,7 @@ xu,shu 俆 guang 俇 ku 俈 wu 俉 -dun,jun,shun 俊 +jun 俊 yi 俋 fu 俌 liang,lang 俍 @@ -11420,7 +11420,7 @@ zhi 搘 nuo,nou,nu 搙 la,xie,xian 搚 lian,jian 搛 -shao,xiao,sou 搜 +sou 搜 qiu 搝 qiao,gao,kao 搞 xian 搟 diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index 539db41..38599b0 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -137,7 +137,12 @@ void SearchDetailView::setWebWidget(const QString& keyword) connect(m_webView,&QWebEngineView::loadFinished, this, [ = ](){ m_reload = true; - if (m_engineProfile) m_engineProfile->clearHttpCache(); + if (m_engineProfile){ + m_engineProfile->clearHttpCache(); // 清理缓存 + m_engineProfile->clearAllVisitedLinks(); // 清理浏览记录 + m_engineProfile->cookieStore()->deleteAllCookies(); // 清理cookie + m_engineProfile->cookieStore()->deleteSessionCookies(); // 清理会话cookie + } }); connect(m_webView, &QWebEngineView::urlChanged, this, [ = ](const QUrl& url) { if (m_reload) { diff --git a/src/control/search-list-view.cpp b/src/control/search-list-view.cpp index 6a4da7f..f1d2b79 100644 --- a/src/control/search-list-view.cpp +++ b/src/control/search-list-view.cpp @@ -49,6 +49,10 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const Q_EMIT this->currentRowChanged(getCurrentType(), m_item->m_pathlist.at(this->currentIndex().row())); m_isSelected = true; }); + + connect(this, &SearchListView::doubleClicked, this, [ = ](const QModelIndex& index) { + + }); } SearchListView::~SearchListView()