From 5b11ba39c6db4a9c78abcdec55015169aae0288a Mon Sep 17 00:00:00 2001 From: zhangpengfei Date: Wed, 6 Jan 2021 17:42:35 +0800 Subject: [PATCH] Update debian files and some interface optimization. --- debian/control | 9 +++- debian/ukui-search-systemdbus.install | 3 ++ debian/ukui-search.install | 2 +- libsearch/index/file-searcher.cpp | 4 +- libsearch/index/index-generator.cpp | 40 +++++++++------- libsearch/index/index-generator.h | 4 +- libsearch/libsearch.pro | 2 +- src/main.cpp | 69 ++++++++++++++++++++------- 8 files changed, 92 insertions(+), 41 deletions(-) create mode 100644 debian/ukui-search-systemdbus.install diff --git a/debian/control b/debian/control index 4ddb581..bdaaf7d 100644 --- a/debian/control +++ b/debian/control @@ -54,4 +54,11 @@ Depends: ${misc:Depends}, ${shlibs:Depends}, libukui-search0 (= ${binary:Version}), libchinese-segmentation0 (= ${binary:Version}) -Description: Libraries for ukui-search(development files). \ No newline at end of file +Description: Libraries for ukui-search(development files). + +Package: ukui-search-systemdbus +Architecture: any +Depends: ${shlibs:Depends}, + ${misc:Depends}, +Description: ukui-search-systemdbus is a systembus interface to modify max_user_watches nums + permanent. diff --git a/debian/ukui-search-systemdbus.install b/debian/ukui-search-systemdbus.install new file mode 100644 index 0000000..2f81586 --- /dev/null +++ b/debian/ukui-search-systemdbus.install @@ -0,0 +1,3 @@ +/usr/share/dbus-1/system-services/com.ukui.search.qt.systemdbus.service +/etc/dbus-1/system.d/com.ukui.search.qt.systemdbus.conf +/usr/bin/ukui-search-systemdbus diff --git a/debian/ukui-search.install b/debian/ukui-search.install index 1df36c6..fe3409f 100644 --- a/debian/ukui-search.install +++ b/debian/ukui-search.install @@ -1 +1 @@ -usr/bin/* +usr/bin/ukui-search diff --git a/libsearch/index/file-searcher.cpp b/libsearch/index/file-searcher.cpp index d4ea1bb..e36c4fc 100644 --- a/libsearch/index/file-searcher.cpp +++ b/libsearch/index/file-searcher.cpp @@ -66,7 +66,7 @@ void FileSearcher::onKeywordSearch(QString keyword, int begin, int num) } catch(const Xapian::Error &e) { - qDebug() <result(searchResult); @@ -116,7 +116,7 @@ void FileSearcher::onKeywordSearchContent(QString keyword, int begin, int num) } catch(const Xapian::Error &e) { - qDebug() < > *messageList) } catch(const Xapian::Error &e) { - qWarning()<<"creatAllIndex fail!"<setValue(INDEX_DATABASE_STATE,"0"); - return false; + GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE,"1"); + Q_ASSERT(false); } - GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE,"1"); m_doc_list_path->clear(); Q_EMIT this->transactionFinished(); @@ -90,22 +89,30 @@ bool IndexGenerator::creatAllIndex(QList *messageList) } catch(const Xapian::Error &e) { - qWarning()<<"creat content Index fail!"<setValue(CONTENT_INDEX_DATABASE_STATE,"0"); - return false; + qWarning()<<__FILE__<<__LINE__<<__FUNCTION__<<"creat content Index fail!"<setValue(CONTENT_INDEX_DATABASE_STATE,"1"); + Q_ASSERT(false); } - GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE,"1"); m_doc_list_content->clear(); Q_EMIT this->transactionFinished(); return true; } -IndexGenerator::IndexGenerator(QObject *parent) : QObject(parent) +IndexGenerator::IndexGenerator(bool rebuild, QObject *parent) : QObject(parent) { - m_datebase_path = new Xapian::WritableDatabase(INDEX_PATH, Xapian::DB_CREATE_OR_OPEN); - m_database_content = new Xapian::WritableDatabase(CONTENT_INDEX_PATH, Xapian::DB_CREATE_OR_OPEN); - GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE,"1"); + if(rebuild) + { + m_datebase_path = new Xapian::WritableDatabase(INDEX_PATH, Xapian::DB_CREATE_OR_OVERWRITE); + m_database_content = new Xapian::WritableDatabase(CONTENT_INDEX_PATH, Xapian::DB_CREATE_OR_OVERWRITE); + } + else + { + m_datebase_path = new Xapian::WritableDatabase(INDEX_PATH, Xapian::DB_CREATE_OR_OPEN); + m_database_content = new Xapian::WritableDatabase(CONTENT_INDEX_PATH, Xapian::DB_CREATE_OR_OPEN); + } + GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE,"0"); + GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE,"0"); } IndexGenerator::~IndexGenerator() @@ -114,7 +121,8 @@ IndexGenerator::~IndexGenerator() delete m_datebase_path; if(m_database_content) delete m_database_content; - GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT,"1"); + GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE,"2"); + GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT,"2"); } void IndexGenerator::insertIntoDatabase(Document doc) @@ -341,7 +349,7 @@ bool IndexGenerator::deleteAllIndex(QStringList *pathlist) } catch(const Xapian::Error &e) { - qWarning() <> *messageList); diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index fade056..72d26ec 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -25,7 +25,7 @@ include(index/index.pri) include(appsearch/appsearch.pri) include(settingsearch/settingsearch.pri)) -LIBS += -L../libchinese-segmentation/ -lchinese-segmentation +LIBS += -L$$OUT_PWD/../libchinese-segmentation/ -lchinese-segmentation LIBS += -lxapian -lquazip5 SOURCES += \ diff --git a/src/main.cpp b/src/main.cpp index b8cf886..202d251 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,48 @@ #include "libsearch.h" #include "global-settings.h" +void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + QByteArray localMsg = msg.toLocal8Bit(); + QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit(); + + bool showDebug = true; + QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-search.log"; + if (!QFile::exists(logFilePath)) { + showDebug = false; + } + FILE *log_file = nullptr; + + if (showDebug) { + log_file = fopen(logFilePath.toLocal8Bit().constData(), "a+"); + } + + const char *file = context.file ? context.file : ""; + const char *function = context.function ? context.function : ""; + switch (type) { + case QtDebugMsg: + if (!log_file) { + break; + } + fprintf(log_file, "Debug: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); + break; + case QtInfoMsg: + fprintf(log_file? log_file: stdout, "Info: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); + break; + case QtWarningMsg: + fprintf(log_file? log_file: stderr, "Warning: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); + break; + case QtCriticalMsg: + fprintf(log_file? log_file: stderr, "Critical: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); + break; + case QtFatalMsg: + fprintf(log_file? log_file: stderr, "Fatal: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function); + break; + } + + if (log_file) + fclose(log_file); +} void centerToScreen(QWidget* widget) { if (!widget) @@ -64,37 +106,28 @@ int main(int argc, char *argv[]) // qDebug() << t2; /*-------------InotyifyRefact Test End-----------------*/ - /*-------------content index Test Start---------------*/ - QTime t3 = QTime::currentTime(); - FileTypeFilter* ftf = new FileTypeFilter("/home"); - ftf->Test(); - QTime t4 = QTime::currentTime(); - delete ftf; - ftf = nullptr; - qDebug() << t3; - qDebug() << t4; +// QTime t3 = QTime::currentTime(); +// FileTypeFilter* ftf = new FileTypeFilter("/home"); +// ftf->Test(); +// QTime t4 = QTime::currentTime(); +// delete ftf; +// ftf = nullptr; +// qDebug() << t3; +// qDebug() << t4; /*-------------content index Test End-----------------*/ - /*-------------文本搜索 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"); - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QtSingleApplication app("ukui-search", argc, argv); app.setQuitOnLastWindowClosed(false); - + qInstallMessageHandler(messageOutput); if(app.isRunning()) {