diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index e349a22..21c5c83 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -31,10 +31,10 @@ QIcon FileUtils::getFileIcon(const QString &uri, bool checkValid) { auto file = wrapGFile(g_file_new_for_uri(uri.toUtf8().constData())); auto info = wrapGFileInfo(g_file_query_info(file.get()->get(), - G_FILE_ATTRIBUTE_STANDARD_ICON, - G_FILE_QUERY_INFO_NONE, - nullptr, - nullptr)); + G_FILE_ATTRIBUTE_STANDARD_ICON, + G_FILE_QUERY_INFO_NONE, + nullptr, + nullptr)); if (!G_IS_FILE_INFO (info.get()->get())) return QIcon::fromTheme("unknown"); GIcon *g_icon = g_file_info_get_icon (info.get()->get()); @@ -190,8 +190,8 @@ QString FileUtils::getMimetype(QString &path, bool getsuffix) //aborted QString FileUtils::find(const QString &hanzi) { -// static QMap map = loadHanziTable("://index/pinyinWithoutTone.txt"); -// static QMap map; + // static QMap map = loadHanziTable("://index/pinyinWithoutTone.txt"); + // static QMap map; QString output; QStringList stringList = hanzi.split(""); @@ -445,23 +445,23 @@ void stitchMultiToneWordsBFSStackLess3(const QString& hanzi, QStringList& result resultList.append(tempQueue.dequeue()); resultList.append(tempQueueFirst.dequeue()); } -// delete tempQueue; -// delete tempQueueFirst; -// tempQueue = nullptr; -// tempQueueFirst = nullptr; + // delete tempQueue; + // delete tempQueueFirst; + // tempQueue = nullptr; + // tempQueueFirst = nullptr; return; } QStringList FileUtils::findMultiToneWords(const QString& hanzi) { -// QStringList* output = new QStringList(); + // QStringList* output = new QStringList(); QStringList output; QString tempAllPinYin, tempFirst; QStringList stringList = hanzi.split(""); -// stitchMultiToneWordsDFS(hanzi, tempAllPinYin, tempFirst, output); + // stitchMultiToneWordsDFS(hanzi, tempAllPinYin, tempFirst, output); stitchMultiToneWordsBFSStackLess3(hanzi, output); -// qDebug() << output; + // qDebug() << output; return output; } diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index 054a272..b8a66a5 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -17,6 +17,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) { m_settings = new QSettings("org.ukui", "ukui-search", this); m_block_dirs_settings = new QSettings("org.ukui","ukui-search-block-dirs",this); + this->forceSync(); //the default number of transparency in mainwindow is 0.7 //if someone changes the num in mainwindow, here should be modified too m_cache.insert(TRANSPARENCY_KEY, 0.7); @@ -32,6 +33,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) } m_cache.remove(TRANSPARENCY_KEY); m_cache.insert(TRANSPARENCY_KEY, m_gsettings->get(TRANSPARENCY_KEY).toDouble()); + } GlobalSettings::~GlobalSettings() diff --git a/libsearch/index/filetypefilter.h b/libsearch/index/filetypefilter.h index efc4404..bbae487 100644 --- a/libsearch/index/filetypefilter.h +++ b/libsearch/index/filetypefilter.h @@ -1,3 +1,4 @@ +//aborted --MouseZhangZh #ifndef FILETYPEFILTER_H #define FILETYPEFILTER_H diff --git a/libsearch/index/first-index.cpp b/libsearch/index/first-index.cpp new file mode 100644 index 0000000..d377ffd --- /dev/null +++ b/libsearch/index/first-index.cpp @@ -0,0 +1,100 @@ +//#include +#include "first-index.h" +#include + +FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path) +{ + QString indexDataBaseStatus = GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString(); + QString contentIndexDataBaseStatus = GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString(); + + qDebug() << "indexDataBaseStatus: " << indexDataBaseStatus; + qDebug() << "contentIndexDataBaseStatus: " << contentIndexDataBaseStatus; + + + if (indexDataBaseStatus == "" || contentIndexDataBaseStatus == ""){ + this->bool_dataBaseExist = false; + } + if (indexDataBaseStatus != "2" || contentIndexDataBaseStatus != "2"){ + this->bool_dataBaseStatusOK = false; + } + + this->q_index = new QQueue>(); + this->q_content_index = new QQueue(); + +// this->mlm = new MessageListManager(); +} + +FirstIndex::~FirstIndex() +{ + delete this->q_index; + this->q_index = nullptr; + this->q_content_index = nullptr; + delete this->q_content_index; +// delete this->mlm; +// this->mlm = nullptr; +} + +void FirstIndex::DoSomething(const QFileInfo& fileInfo){ +// qDebug() << "there are some shit here"; + this->q_index->enqueue(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0")); + for (auto i : this->targetFileTypeVec){ + if (fileInfo.fileName().endsWith(i)){ + this->q_content_index->enqueue(fileInfo.absoluteFilePath()); + } + } +} + +void FirstIndex::run(){ + if (this->bool_dataBaseExist){ + if (this->bool_dataBaseStatusOK){ + this->quit(); +// this->wait(); + } + else{ + //if the parameter is false, index won't be rebuild + //if it is true, index will be rebuild + this->p_indexGenerator = IndexGenerator::getInstance(true); + } + } + else{ + this->p_indexGenerator = IndexGenerator::getInstance(false); + } + QSemaphore sem(5); + QMutex mutex1, mutex2, mutex3; + mutex1.lock(); + mutex2.lock(); + mutex3.lock(); + sem.acquire(4); + QtConcurrent::run([&](){ + sem.acquire(1); + mutex1.unlock(); + this->Traverse(); + sem.release(5); + }); + QtConcurrent::run([&](){ + sem.acquire(2); + mutex2.unlock(); + qDebug() << "index start;"; + this->p_indexGenerator->creatAllIndex(this->q_index); + qDebug() << "index end;"; + sem.release(2); + }); + QtConcurrent::run([&](){ + sem.acquire(2); + mutex3.unlock(); + qDebug() << "content index start;"; + this->p_indexGenerator->creatAllIndex(this->q_content_index); + qDebug() << "content index end;"; + sem.release(2); + }); + mutex1.lock(); + mutex2.lock(); + mutex3.lock(); + sem.acquire(5); + mutex1.unlock(); + mutex2.unlock(); + mutex3.unlock(); + qDebug() << "first index end;"; + this->quit(); +// this->wait(); +} diff --git a/libsearch/index/first-index.h b/libsearch/index/first-index.h new file mode 100644 index 0000000..7f2bc18 --- /dev/null +++ b/libsearch/index/first-index.h @@ -0,0 +1,43 @@ +#ifndef FIRSTINDEX_H +#define FIRSTINDEX_H + +#include +#include +//#include +#include "traverse_bfs.h" +#include "global-settings.h" +#include "index-generator.h" +#include "messagelist-manager.h" + +class FirstIndex : public QThread, public Traverse_BFS +{ +public: + FirstIndex(const QString&); + ~FirstIndex(); + virtual void DoSomething(const QFileInfo &) final; +protected: + void run() override; +private: + FirstIndex(const FirstIndex&) = delete; + void operator=(const FirstIndex&) = delete; + bool bool_dataBaseStatusOK = false; + bool bool_dataBaseExist = false; + IndexGenerator* p_indexGenerator; + + //here should be refact +// MessageListManager* mlm; + + //test + QQueue>* q_index; + QQueue* q_content_index; + const QVector targetFileTypeVec ={ +// QString(".doc"), + QString(".docx"), +// QString(".ppt"), +// QString(".pptx"), +// QString(".xls"), +// QString(".xlsx"), + QString(".txt")}; +}; + +#endif // FIRSTINDEX_H diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index 7b18824..7d9dd84 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -117,6 +117,7 @@ IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent) IndexGenerator::~IndexGenerator() { + qDebug() << "~IndexGenerator"; if(m_datebase_path) delete m_datebase_path; if(m_database_content) diff --git a/libsearch/index/index-generator.h b/libsearch/index/index-generator.h index 6f08b92..ebc53ed 100644 --- a/libsearch/index/index-generator.h +++ b/libsearch/index/index-generator.h @@ -3,7 +3,7 @@ #include #include - +//#include #include #include #include diff --git a/libsearch/index/index.pri b/libsearch/index/index.pri index a0a7b8d..63343ce 100644 --- a/libsearch/index/index.pri +++ b/libsearch/index/index.pri @@ -6,11 +6,11 @@ HEADERS += \ $$PWD/document.h \ $$PWD/filetypefilter.h \ $$PWD/file-reader.h \ + $$PWD/first-index.h \ $$PWD/index-generator.h \ # $$PWD/inotify-manager.h \ $$PWD/inotify.h \ $$PWD/messagelist-manager.h \ - $$PWD/messagelisttemplate.h \ $$PWD/traverse_bfs.h \ # $$PWD/text-content-indexer.h \ $$PWD/file-searcher.h \ @@ -22,11 +22,11 @@ SOURCES += \ $$PWD/document.cpp \ $$PWD/filetypefilter.cpp \ $$PWD/file-reader.cpp \ + $$PWD/first-index.cpp \ $$PWD/index-generator.cpp \ # $$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 \ diff --git a/libsearch/index/inotify.h b/libsearch/index/inotify.h index 427be65..6e5818b 100644 --- a/libsearch/index/inotify.h +++ b/libsearch/index/inotify.h @@ -1,3 +1,4 @@ +//aborted --MouseZhangZh #ifndef INOTIFY_H #define INOTIFY_H diff --git a/libsearch/index/messagelist-manager.cpp b/libsearch/index/messagelist-manager.cpp index 44882bc..a3a06e8 100644 --- a/libsearch/index/messagelist-manager.cpp +++ b/libsearch/index/messagelist-manager.cpp @@ -19,12 +19,12 @@ MessageListManager::MessageListManager(){ MessageListManager::~MessageListManager(){ delete this->messageList; - delete this->indexGeneratorThread; +// delete this->indexGeneratorThread; //delete this->ig; this->messageList = nullptr; this->ig = nullptr; - this->indexGeneratorThread = nullptr; +// this->indexGeneratorThread = nullptr; } void MessageListManager::AddMessage(const QVector& pathVec){ diff --git a/libsearch/index/messagelist-manager.h b/libsearch/index/messagelist-manager.h index d79310b..1f94c64 100644 --- a/libsearch/index/messagelist-manager.h +++ b/libsearch/index/messagelist-manager.h @@ -1,3 +1,4 @@ +//aborted --MouseZhangZh #ifndef MESSAGELISTMANAGER_H #define MESSAGELISTMANAGER_H @@ -22,7 +23,7 @@ private: size_t length = 80000; IndexGenerator* ig; - QThread* indexGeneratorThread; +// QThread* indexGeneratorThread; Q_SIGNALS: bool Send(QStringList*); diff --git a/libsearch/index/messagelisttemplate.cpp b/libsearch/index/messagelisttemplate.cpp deleted file mode 100644 index c0a85e8..0000000 --- a/libsearch/index/messagelisttemplate.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "messagelisttemplate.h" -#include - -//重构部分,暂时不要调用 -template -MessageVectorTemplate::MessageVectorTemplate::MessageVectorTemplate(SOMETHINGINSTANCE* somethingInstance) -{ - this->somethingInstance = somethingInstance; -} - -template -bool MessageVectorTemplate::MessageVectorTemplate::addMessage(const MESSAGETYPE& message) -{ - this->messageVec->append(message); -} - -template -bool MessageVectorTemplate::sendMessage() -{ - QtConcurrent::run( - [&](){ -// if (this->m_mutex.try_lock(this->m_time)){ -// std::cout << "send_test_time" << std::endl; -// this->m_mutex.unlock(); -// } - }); -} - -template -bool MessageVectorTemplate::MessageVectorTemplate::sendDeleteMessage() -{ - -} - -template -void MessageVectorTemplate::MessageVectorTemplate::setAutoSendMessageLength(const size_t& length) -{ - this->m_length = length; -} - -template -void MessageVectorTemplate::MessageVectorTemplate::setAutoSendMessageTime(const size_t& time) -{ - this->m_time = time; -} diff --git a/libsearch/index/messagelisttemplate.h b/libsearch/index/messagelisttemplate.h deleted file mode 100644 index 2b59838..0000000 --- a/libsearch/index/messagelisttemplate.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MESSAGELISTTEMPLATE_H -#define MESSAGELISTTEMPLATE_H -#include -#include -#include -#include -template -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> messageVec = std::make_shared>(); - std::unique_ptr somethingInstance; - - size_t m_length = 80000; - size_t m_time = 1000; - std::mutex m_mutex; -}; - -#endif // MESSAGELISTTEMPLATE_H diff --git a/libsearch/index/traverse_bfs.cpp b/libsearch/index/traverse_bfs.cpp index b554f2e..4862eab 100644 --- a/libsearch/index/traverse_bfs.cpp +++ b/libsearch/index/traverse_bfs.cpp @@ -2,6 +2,7 @@ Traverse_BFS::Traverse_BFS(const QString& path) { + Q_ASSERT('/' == path.at(0)); this->path = path; } diff --git a/libsearch/index/traverse_bfs.h b/libsearch/index/traverse_bfs.h index 0ef67a4..ed5e3c9 100644 --- a/libsearch/index/traverse_bfs.h +++ b/libsearch/index/traverse_bfs.h @@ -9,11 +9,14 @@ class Traverse_BFS { public: - explicit Traverse_BFS(const QString&); void Traverse(); virtual void DoSomething(const QFileInfo&) = 0; void setPath(const QString&); +protected: + explicit Traverse_BFS(const QString&); private: + Traverse_BFS(const Traverse_BFS&) = delete; + void operator=(const Traverse_BFS&) = delete; QString path = "/home"; }; diff --git a/libsearch/libsearch.h b/libsearch/libsearch.h index 86928f2..2205333 100644 --- a/libsearch/libsearch.h +++ b/libsearch/libsearch.h @@ -8,6 +8,7 @@ #include "index/inotify.h" #include "file-utils.h" #include "global-settings.h" +#include "index/first-index.h" #include "index/filetypefilter.h" diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index 72d26ec..c0d214e 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -1,4 +1,4 @@ -QT += core concurrent xml widgets dbus +QT += core xml widgets dbus concurrent VERSION = 0.0.1 TARGET = ukui-search diff --git a/src/main.cpp b/src/main.cpp index 8184b5b..cde613d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,8 @@ void messageOutput(QtMsgType type, const QMessageLogContext &context, const QStr QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit(); bool showDebug = true; - QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-search.log"; +// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-search.log"; + QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search.log"; if (!QFile::exists(logFilePath)) { showDebug = false; } @@ -89,6 +90,12 @@ void centerToScreen(QWidget* widget) { int main(int argc, char *argv[]) { + + qInstallMessageHandler(messageOutput); + + qDebug() << "main start"; + FirstIndex* fi = new FirstIndex("/home"); + fi->start(); /*-------------ukuisearchdbus Test start-----------------*/ // UkuiSearchQDBus usQDBus; // usQDBus.setInotifyMaxUserWatches(); @@ -127,7 +134,8 @@ int main(int argc, char *argv[]) QtSingleApplication app("ukui-search", argc, argv); app.setQuitOnLastWindowClosed(false); - qInstallMessageHandler(messageOutput); + + qDebug() << "main start x2"; if(app.isRunning()) {