forked from openkylin/ukui-search
Merge pull request #39 from MouseZhangZh/1230-dev
🧐🧐🧐add globalsetting and something(blockddirs and messagelist refact) in…
This commit is contained in:
commit
556c059b4d
|
@ -187,6 +187,7 @@ QString FileUtils::getMimetype(QString &path, bool getsuffix)
|
|||
return type.preferredSuffix();
|
||||
}
|
||||
|
||||
//aborted
|
||||
QString FileUtils::find(const QString &hanzi)
|
||||
{
|
||||
// static QMap<QString, QStringList> map = loadHanziTable("://index/pinyinWithoutTone.txt");
|
||||
|
@ -375,6 +376,82 @@ void stitchMultiToneWordsBFSHeapLess3(const QString& hanzi, QStringList& resultL
|
|||
return;
|
||||
}
|
||||
|
||||
//BFS+Stack+超过3个多音字只建一个索引,比较折中的方案
|
||||
void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& resultList){
|
||||
QString tempHanzi, resultAllPinYin, resultFirst;
|
||||
QQueue<QString> tempQueue;
|
||||
QQueue<QString> tempQueueFirst;
|
||||
tempHanzi = hanzi;
|
||||
int tempQueueSize = 0;
|
||||
int multiToneWordNum = 0;
|
||||
for (auto i : hanzi){
|
||||
if (FileUtils::map_chinese2pinyin.contains(i)){
|
||||
if (FileUtils::map_chinese2pinyin[i].size() > 1){
|
||||
++multiToneWordNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (multiToneWordNum > 3){
|
||||
QString oneResult, oneResultFirst;
|
||||
for (auto i : hanzi){
|
||||
if (FileUtils::map_chinese2pinyin.contains(i)){
|
||||
oneResult += FileUtils::map_chinese2pinyin[i].first();
|
||||
oneResultFirst += FileUtils::map_chinese2pinyin[i].first().at(0);
|
||||
}
|
||||
else{
|
||||
oneResult += i;
|
||||
oneResultFirst += i;
|
||||
}
|
||||
}
|
||||
resultList.append(oneResult);
|
||||
resultList.append(oneResultFirst);
|
||||
return;
|
||||
}
|
||||
|
||||
if (FileUtils::map_chinese2pinyin.contains(tempHanzi.at(0))){
|
||||
for (auto i : FileUtils::map_chinese2pinyin[tempHanzi.at(0)]){
|
||||
tempQueue.enqueue(i);
|
||||
tempQueueFirst.enqueue(i.at(0));
|
||||
}
|
||||
}
|
||||
else{
|
||||
tempQueue.enqueue(tempHanzi.at(0));
|
||||
tempQueueFirst.enqueue(tempHanzi.at(0));
|
||||
}
|
||||
tempHanzi = tempHanzi.right(tempHanzi.size() - 1);
|
||||
while (tempHanzi.size() != 0) {
|
||||
tempQueueSize = tempQueue.size();
|
||||
if (FileUtils::map_chinese2pinyin.contains(tempHanzi.at(0))){
|
||||
for (int j = 0; j < tempQueueSize; ++j){
|
||||
for (auto i : FileUtils::map_chinese2pinyin[tempHanzi.at(0)]){
|
||||
tempQueue.enqueue(tempQueue.head() + i);
|
||||
tempQueueFirst.enqueue(tempQueueFirst.head() + i.at(0));
|
||||
}
|
||||
tempQueue.dequeue();
|
||||
tempQueueFirst.dequeue();
|
||||
}
|
||||
}
|
||||
else{
|
||||
for (int j = 0; j < tempQueueSize; ++j){
|
||||
tempQueue.enqueue(tempQueue.head() + tempHanzi.at(0));
|
||||
tempQueueFirst.enqueue(tempQueueFirst.head() + tempHanzi.at(0));
|
||||
tempQueue.dequeue();
|
||||
tempQueueFirst.dequeue();
|
||||
}
|
||||
}
|
||||
tempHanzi = tempHanzi.right(tempHanzi.size() - 1);
|
||||
}
|
||||
while(!tempQueue.empty()){
|
||||
resultList.append(tempQueue.dequeue());
|
||||
resultList.append(tempQueueFirst.dequeue());
|
||||
}
|
||||
// delete tempQueue;
|
||||
// delete tempQueueFirst;
|
||||
// tempQueue = nullptr;
|
||||
// tempQueueFirst = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList FileUtils::findMultiToneWords(const QString& hanzi)
|
||||
{
|
||||
// QStringList* output = new QStringList();
|
||||
|
@ -383,7 +460,7 @@ QStringList FileUtils::findMultiToneWords(const QString& hanzi)
|
|||
QStringList stringList = hanzi.split("");
|
||||
|
||||
// stitchMultiToneWordsDFS(hanzi, tempAllPinYin, tempFirst, output);
|
||||
stitchMultiToneWordsBFSHeapLess3(hanzi, output);
|
||||
stitchMultiToneWordsBFSStackLess3(hanzi, output);
|
||||
// qDebug() << output;
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,92 @@
|
|||
#include <QtConcurrent>
|
||||
#include "globalsettings.h"
|
||||
|
||||
static GlobalSettings *global_instance = nullptr;
|
||||
|
||||
GlobalSettings *GlobalSettings::getInstance()
|
||||
{
|
||||
if (!global_instance) {
|
||||
global_instance = new GlobalSettings;
|
||||
}
|
||||
return global_instance;
|
||||
}
|
||||
|
||||
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_settings = new QSettings("org.ukui", "ukui-search-blockdirs", this);
|
||||
}
|
||||
|
||||
GlobalSettings::~GlobalSettings()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const QVariant GlobalSettings::getValue(const QString &key)
|
||||
{
|
||||
return m_cache.value(key);
|
||||
}
|
||||
|
||||
bool GlobalSettings::isExist(const QString &key)
|
||||
{
|
||||
return !m_cache.value(key).isNull();
|
||||
}
|
||||
|
||||
void GlobalSettings::reset(const QString &key)
|
||||
{
|
||||
m_cache.remove(key);
|
||||
QtConcurrent::run([=]() {
|
||||
if (m_mutex.tryLock(1000)) {
|
||||
m_settings->remove(key);
|
||||
m_settings->sync();
|
||||
m_mutex.unlock();
|
||||
}
|
||||
});
|
||||
Q_EMIT this->valueChanged(key);
|
||||
}
|
||||
|
||||
void GlobalSettings::resetAll()
|
||||
{
|
||||
QStringList tmp = m_cache.keys();
|
||||
m_cache.clear();
|
||||
for (auto key : tmp) {
|
||||
Q_EMIT this->valueChanged(key);
|
||||
}
|
||||
QtConcurrent::run([=]() {
|
||||
if (m_mutex.tryLock(1000)) {
|
||||
m_settings->clear();
|
||||
m_settings->sync();
|
||||
m_mutex.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QList<QString> GlobalSettings::getBlockDirs()
|
||||
{
|
||||
return m_cache.keys();
|
||||
}
|
||||
|
||||
void GlobalSettings::setValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
m_cache.insert(key, value);
|
||||
QtConcurrent::run([=]() {
|
||||
if (m_mutex.tryLock(1000)) {
|
||||
m_settings->setValue(key, value);
|
||||
m_settings->sync();
|
||||
m_mutex.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void GlobalSettings::forceSync(const QString &key)
|
||||
{
|
||||
m_settings->sync();
|
||||
if (key.isNull()) {
|
||||
m_cache.clear();
|
||||
for (auto key : m_settings->allKeys()) {
|
||||
m_cache.insert(key, m_settings->value(key));
|
||||
}
|
||||
} else {
|
||||
m_cache.remove(key);
|
||||
m_cache.insert(key, m_settings->value(key));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,39 @@
|
|||
#define GLOBALSETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include "libsearch_global.h"
|
||||
#include <QSettings>
|
||||
#include <QMutex>
|
||||
#include <QVector>
|
||||
|
||||
class LIBSEARCH_EXPORT GlobalSettings : public QObject
|
||||
class GlobalSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GlobalSettings(QObject *parent = nullptr);
|
||||
static GlobalSettings *getInstance();
|
||||
const QVariant getValue(const QString&);
|
||||
bool isExist(const QString&);
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged (const QString&);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setValue(const QString&, const QVariant&);
|
||||
void reset(const QString&);
|
||||
void resetAll();
|
||||
QList<QString> getBlockDirs();
|
||||
|
||||
void forceSync(const QString& = nullptr);
|
||||
|
||||
private:
|
||||
explicit GlobalSettings(QObject *parent = nullptr);
|
||||
~GlobalSettings();
|
||||
|
||||
QSettings* m_settings;
|
||||
QMap<QString, QVariant> m_cache;
|
||||
|
||||
QMutex m_mutex;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,22 @@
|
|||
#include "blockdirs.h"
|
||||
|
||||
//优先级先放一下
|
||||
BlockDirs::BlockDirs(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int BlockDirs::setValue(const QString& path, const int &type)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
int BlockDirs::removeValue(const QString& path, const int &type)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
int BlockDirs::getValues()
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
|
|
@ -2,13 +2,29 @@
|
|||
#define BLOCKDIRS_H
|
||||
|
||||
#include <QObject>
|
||||
#include "globalsettings.h"
|
||||
|
||||
#ifndef MYTYPE
|
||||
#define MYTYPE
|
||||
#define MYDIR 0
|
||||
#define MYFILE 1
|
||||
#endif // MYTYPE
|
||||
|
||||
#ifndef SETVALUERESULT
|
||||
#define SETVALUERESULT
|
||||
#define DONOTHING 1
|
||||
#define FAILED -1
|
||||
#define SUCCESSED 0
|
||||
#endif // SETVALUERESULT
|
||||
|
||||
class BlockDirs : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BlockDirs(QObject *parent = nullptr);
|
||||
|
||||
int setValue(const QString&, const int&);
|
||||
int removeValue(const QString&, const int&);
|
||||
int getValues();
|
||||
Q_SIGNALS:
|
||||
|
||||
};
|
||||
|
|
|
@ -16,16 +16,17 @@ public:
|
|||
virtual void DoSomething(const QFileInfo&) final;
|
||||
QList<QString>* getTargetFileAbsolutePath();
|
||||
void Test();
|
||||
void startIndexText();
|
||||
Q_SIGNALS:
|
||||
private:
|
||||
const QVector<QString> targetFileTypeVec ={
|
||||
// QString(".doc"),
|
||||
QString(".docx"),
|
||||
/* QString(".ppt"),
|
||||
QString(".pptx"),
|
||||
QString(".xls"),
|
||||
QString(".xlsx"),
|
||||
QString(".txt")*/};
|
||||
// QString(".docx"),
|
||||
// QString(".ppt"),
|
||||
// QString(".pptx"),
|
||||
// QString(".xls"),
|
||||
// QString(".xlsx"),
|
||||
QString(".txt")};
|
||||
QList<QString>* result;
|
||||
|
||||
};
|
||||
|
|
|
@ -10,8 +10,9 @@ HEADERS += \
|
|||
# $$PWD/inotify-manager.h \
|
||||
$$PWD/inotify.h \
|
||||
$$PWD/messagelist-manager.h \
|
||||
$$PWD/messagelisttemplate.h \
|
||||
$$PWD/traverse_bfs.h \
|
||||
$$PWD/text-content-indexer.h \
|
||||
# $$PWD/text-content-indexer.h \
|
||||
$$PWD/file-searcher.h
|
||||
|
||||
SOURCES += \
|
||||
|
@ -24,8 +25,9 @@ SOURCES += \
|
|||
# $$PWD/inotify-manager.cpp \
|
||||
$$PWD/inotify.cpp \
|
||||
$$PWD/messagelist-manager.cpp \
|
||||
$$PWD/messagelisttemplate.cpp \
|
||||
$$PWD/test-Inotify-Manager.cpp \
|
||||
$$PWD/traverse_bfs.cpp \
|
||||
$$PWD/text-content-indexer.cpp \
|
||||
# $$PWD/text-content-indexer.cpp \
|
||||
$$PWD/file-searcher.cpp
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#include "messagelisttemplate.h"
|
||||
#include <QtConcurrent>
|
||||
|
||||
//重构部分,暂时不要调用
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::MessageVectorTemplate(SOMETHINGINSTANCE* somethingInstance)
|
||||
{
|
||||
this->somethingInstance = somethingInstance;
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
bool MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::addMessage(const MESSAGETYPE& message)
|
||||
{
|
||||
this->messageVec->append(message);
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
bool MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::sendMessage()
|
||||
{
|
||||
QtConcurrent::run(
|
||||
[&](){
|
||||
// if (this->m_mutex.try_lock(this->m_time)){
|
||||
// std::cout << "send_test_time" << std::endl;
|
||||
// this->m_mutex.unlock();
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
bool MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::sendDeleteMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
void MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::setAutoSendMessageLength(const size_t& length)
|
||||
{
|
||||
this->m_length = length;
|
||||
}
|
||||
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
void MessageVectorTemplate<MESSAGETYPE, SOMETHINGINSTANCE>::MessageVectorTemplate::setAutoSendMessageTime(const size_t& time)
|
||||
{
|
||||
this->m_time = time;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef MESSAGELISTTEMPLATE_H
|
||||
#define MESSAGELISTTEMPLATE_H
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
template<typename MESSAGETYPE, typename SOMETHINGINSTANCE>
|
||||
class MessageVectorTemplate
|
||||
{
|
||||
public:
|
||||
MessageVectorTemplate(SOMETHINGINSTANCE*);
|
||||
|
||||
bool addMessage(const MESSAGETYPE&);
|
||||
bool sendMessage();
|
||||
bool sendDeleteMessage();
|
||||
void setAutoSendMessageLength(const size_t&);
|
||||
void setAutoSendMessageTime(const size_t&);
|
||||
|
||||
|
||||
private:
|
||||
std::unique_ptr<std::vector<MESSAGETYPE>> messageVec = std::make_shared<std::vector<MESSAGETYPE>>();
|
||||
std::unique_ptr<SOMETHINGINSTANCE> somethingInstance;
|
||||
|
||||
size_t m_length = 80000;
|
||||
size_t m_time = 1000;
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
#endif // MESSAGELISTTEMPLATE_H
|
|
@ -63,6 +63,7 @@ void ConfigFile::writeRecently(QString message){
|
|||
m_qSettings->setValue("Recently",recently);
|
||||
m_qSettings->endGroup();
|
||||
}
|
||||
|
||||
QStringList ConfigFile::readRecently(){
|
||||
m_qSettings->beginGroup("Recently");
|
||||
QStringList recently=m_qSettings->value("Recently").toStringList();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "qt-local-peer.h"
|
||||
//#include "inotify-manager.h"
|
||||
#include "libsearch.h"
|
||||
#include "globalsettings.h"
|
||||
|
||||
|
||||
void centerToScreen(QWidget* widget) {
|
||||
|
@ -71,8 +72,14 @@ int main(int argc, char *argv[])
|
|||
/*-------------文本搜索 Test start-----------------*/
|
||||
// FileSearcher *search = new FileSearcher();
|
||||
// search->onKeywordSearchContent("重要器官移植⑤白血病");
|
||||
// search->onKeywordSearchContent("g,e,x");
|
||||
/*-------------文本搜索 Test End-----------------*/
|
||||
|
||||
/*-------------GlobalSettings Test start-----------------*/
|
||||
GlobalSettings::getInstance();
|
||||
|
||||
/*-------------GlobalSettings Test End-----------------*/
|
||||
|
||||
qRegisterMetaType<QVector<QStringList>>("QVector<QStringList>");
|
||||
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
|
|
Loading…
Reference in New Issue