2020-12-22 10:14:58 +08:00
|
|
|
/*
|
|
|
|
*
|
2021-01-29 11:43:07 +08:00
|
|
|
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2020-12-22 10:14:58 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2021-01-29 11:43:07 +08:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-12-22 10:14:58 +08:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-01-29 11:43:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: zhangjiaping <zhangjiaping@kylinos.cn>
|
|
|
|
* Modified by: zhangpengfei <zhangpengfei@kylinos.cn>
|
|
|
|
* Modified by: zhangzihao <zhangzihao@kylinos.cn>
|
2020-12-22 10:14:58 +08:00
|
|
|
*
|
|
|
|
*/
|
2020-12-21 16:26:59 +08:00
|
|
|
|
2020-12-30 14:42:04 +08:00
|
|
|
#include "mainwindow.h"
|
2020-12-22 10:14:58 +08:00
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QScreen>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <QObject>
|
|
|
|
#include "qt-single-application.h"
|
|
|
|
#include "qt-local-peer.h"
|
2020-12-26 08:56:38 +08:00
|
|
|
//#include "inotify-manager.h"
|
2020-12-30 15:31:36 +08:00
|
|
|
#include "libsearch.h"
|
2021-01-04 14:21:45 +08:00
|
|
|
#include "global-settings.h"
|
2021-01-20 15:33:49 +08:00
|
|
|
#include "xatom-helper.h"
|
2020-12-22 10:14:58 +08:00
|
|
|
|
2021-01-22 09:49:44 +08:00
|
|
|
|
2021-02-21 11:41:20 +08:00
|
|
|
//void handler(int){
|
|
|
|
// qDebug() << "Recieved SIGTERM!";
|
2021-01-23 11:32:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-21 11:41:20 +08:00
|
|
|
// GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
|
|
|
|
// GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2");
|
|
|
|
// GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT, "2");
|
|
|
|
// GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
|
|
|
|
// GlobalSettings::getInstance()->forceSync(INDEX_DATABASE_STATE);
|
|
|
|
// GlobalSettings::getInstance()->forceSync(CONTENT_INDEX_DATABASE_STATE);
|
|
|
|
// GlobalSettings::getInstance()->forceSync(INDEX_GENERATOR_NORMAL_EXIT);
|
|
|
|
// GlobalSettings::getInstance()->forceSync(INOTIFY_NORMAL_EXIT);
|
2021-01-22 17:15:43 +08:00
|
|
|
|
|
|
|
|
2021-02-21 11:41:20 +08:00
|
|
|
// qDebug() << "indexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
|
|
|
// qDebug() << "contentIndexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
|
2021-01-23 11:32:18 +08:00
|
|
|
|
2021-02-21 11:41:20 +08:00
|
|
|
// ::exit(0);
|
2021-01-22 17:15:43 +08:00
|
|
|
|
2021-02-21 11:41:20 +08:00
|
|
|
//// InotifyIndex::getInstance("/home")->~InotifyIndex();
|
2021-01-22 17:15:43 +08:00
|
|
|
|
2021-02-21 11:41:20 +08:00
|
|
|
// //wait linux kill this thread forcedly
|
|
|
|
//// while (true);
|
|
|
|
//}
|
2021-01-22 17:15:43 +08:00
|
|
|
|
|
|
|
|
2021-01-06 17:42:35 +08:00
|
|
|
void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
|
{
|
|
|
|
QByteArray localMsg = msg.toLocal8Bit();
|
|
|
|
QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit();
|
|
|
|
|
|
|
|
bool showDebug = true;
|
2021-01-09 11:25:07 +08:00
|
|
|
// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ukui-search.log";
|
2021-02-25 14:40:44 +08:00
|
|
|
// QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search/ukui-search.log";
|
2021-01-09 11:25:07 +08:00
|
|
|
QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search.log";
|
2021-01-06 17:42:35 +08:00
|
|
|
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);
|
|
|
|
}
|
2020-12-31 21:14:13 +08:00
|
|
|
|
2020-12-22 10:14:58 +08:00
|
|
|
void centerToScreen(QWidget* widget) {
|
|
|
|
if (!widget)
|
|
|
|
return;
|
|
|
|
QDesktopWidget* m = QApplication::desktop();
|
|
|
|
QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos()));
|
|
|
|
int desk_x = desk_rect.width();
|
|
|
|
int desk_y = desk_rect.height();
|
|
|
|
int x = widget->width();
|
|
|
|
int y = widget->height();
|
2021-01-11 20:49:42 +08:00
|
|
|
widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
2020-12-22 10:14:58 +08:00
|
|
|
}
|
2020-12-21 16:26:59 +08:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-01-22 09:49:44 +08:00
|
|
|
unlink(UKUI_SEARCH_PIPE_PATH);
|
|
|
|
int retval = mkfifo(UKUI_SEARCH_PIPE_PATH, 0777);
|
|
|
|
if(retval == -1)
|
|
|
|
{
|
|
|
|
perror("creat fifo error\n");
|
|
|
|
assert(false);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf("create fifo success\n");
|
|
|
|
|
|
|
|
|
2021-01-09 11:25:07 +08:00
|
|
|
qInstallMessageHandler(messageOutput);
|
2021-01-11 20:34:51 +08:00
|
|
|
qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>");
|
2021-01-19 10:44:28 +08:00
|
|
|
qRegisterMetaType<Document>("Document");
|
2021-01-10 15:59:17 +08:00
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
|
|
|
|
|
QtSingleApplication app("ukui-search", argc, argv);
|
|
|
|
app.setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
if(app.isRunning())
|
|
|
|
{
|
|
|
|
app.sendMessage(QApplication::arguments().length() > 1 ? QApplication::arguments().at(1) : app.applicationFilePath());
|
|
|
|
qDebug() << QObject::tr("ukui-search is already running!");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}/*else {
|
|
|
|
QCommandLineParser parser;
|
|
|
|
QCommandLineOption debugOption({"d", "debug"}, QObject::tr("Display debug information"));
|
|
|
|
QCommandLineOption showsearch({"s", "show"}, QObject::tr("show search widget"));
|
|
|
|
parser.addOptions({debugOption, showsearch});
|
|
|
|
parser.process(app);
|
|
|
|
}*/
|
2021-01-09 11:25:07 +08:00
|
|
|
|
2021-01-11 16:59:50 +08:00
|
|
|
|
2021-01-22 17:15:43 +08:00
|
|
|
//here need to be modified
|
2021-01-06 14:14:38 +08:00
|
|
|
/*-------------ukuisearchdbus Test start-----------------*/
|
2021-01-22 17:15:43 +08:00
|
|
|
UkuiSearchQDBus usQDBus;
|
|
|
|
usQDBus.setInotifyMaxUserWatches();
|
2021-01-06 14:14:38 +08:00
|
|
|
|
|
|
|
/*-------------ukuisearchdbus Test End-----------------*/
|
|
|
|
|
2020-12-26 12:45:28 +08:00
|
|
|
//load chinese character and pinyin file to a Map
|
|
|
|
FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt");
|
2020-12-26 21:11:17 +08:00
|
|
|
/*-------------InotyifyRefact Test Start---------------*/
|
2021-01-06 11:21:19 +08:00
|
|
|
// QTime t1 = QTime::currentTime();
|
|
|
|
// InotifyManagerRefact* imr = new InotifyManagerRefact("/home");
|
|
|
|
// imr->start();
|
|
|
|
// QTime t2 = QTime::currentTime();
|
|
|
|
// qDebug() << t1;
|
|
|
|
// qDebug() << t2;
|
2020-12-26 21:11:17 +08:00
|
|
|
/*-------------InotyifyRefact Test End-----------------*/
|
2020-12-26 12:45:28 +08:00
|
|
|
|
2021-01-06 14:14:38 +08:00
|
|
|
/*-------------content index Test Start---------------*/
|
2021-01-06 17:42:35 +08:00
|
|
|
// QTime t3 = QTime::currentTime();
|
|
|
|
// FileTypeFilter* ftf = new FileTypeFilter("/home");
|
|
|
|
// ftf->Test();
|
|
|
|
// QTime t4 = QTime::currentTime();
|
|
|
|
// delete ftf;
|
|
|
|
// ftf = nullptr;
|
|
|
|
// qDebug() << t3;
|
|
|
|
// qDebug() << t4;
|
2021-01-06 14:14:38 +08:00
|
|
|
/*-------------content index Test End-----------------*/
|
2020-12-31 21:14:13 +08:00
|
|
|
/*-------------文本搜索 Test start-----------------*/
|
2021-01-03 16:01:35 +08:00
|
|
|
// FileSearcher *search = new FileSearcher();
|
|
|
|
// search->onKeywordSearchContent("重要器官移植⑤白血病");
|
2021-01-03 16:58:26 +08:00
|
|
|
// search->onKeywordSearchContent("g,e,x");
|
2020-12-31 21:14:13 +08:00
|
|
|
/*-------------文本搜索 Test End-----------------*/
|
|
|
|
|
2020-12-22 10:14:58 +08:00
|
|
|
// 加载国际化文件
|
|
|
|
QTranslator translator;
|
|
|
|
try {
|
2021-01-07 15:21:53 +08:00
|
|
|
if (! translator.load("/usr/share/ukui-search/translations/" + QLocale::system().name())) throw -1;
|
2020-12-22 10:14:58 +08:00
|
|
|
app.installTranslator(&translator);
|
|
|
|
} catch (...) {
|
|
|
|
qDebug() << "Load translations file" << QLocale() << "failed!";
|
|
|
|
}
|
|
|
|
|
2021-02-02 15:15:37 +08:00
|
|
|
QTranslator qt_translator;
|
|
|
|
try {
|
|
|
|
if (! qt_translator.load(":/res/qt-translations/qt_zh_CN.qm")) throw -1;
|
|
|
|
app.installTranslator(&qt_translator);
|
|
|
|
} catch (...) {
|
|
|
|
qDebug() << "Load translations file" << QLocale() << "failed!";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-22 10:14:58 +08:00
|
|
|
MainWindow *w = new MainWindow;
|
|
|
|
QStringList arguments = QCoreApplication::arguments();
|
2021-01-26 18:43:03 +08:00
|
|
|
// centerToScreen(w);
|
|
|
|
w->moveToPanel();
|
2021-01-10 15:59:17 +08:00
|
|
|
|
2021-01-20 15:33:49 +08:00
|
|
|
//使用窗管的无边框策略
|
2021-01-26 18:43:03 +08:00
|
|
|
w->setProperty("useStyleWindowManager", false); //禁用拖动
|
2021-01-20 15:33:49 +08:00
|
|
|
MotifWmHints hints;
|
|
|
|
hints.flags = MWM_HINTS_FUNCTIONS|MWM_HINTS_DECORATIONS;
|
|
|
|
hints.functions = MWM_FUNC_ALL;
|
|
|
|
hints.decorations = MWM_DECOR_BORDER;
|
|
|
|
XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), hints);
|
|
|
|
|
2020-12-22 10:14:58 +08:00
|
|
|
app.setActivationWindow(w);
|
2021-01-26 16:22:03 +08:00
|
|
|
|
|
|
|
if (QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) {
|
2021-01-29 09:27:02 +08:00
|
|
|
w->moveToPanel();
|
2021-01-26 16:22:03 +08:00
|
|
|
w->show();
|
|
|
|
}
|
2020-12-29 20:18:36 +08:00
|
|
|
// if(arguments.size()>1)
|
|
|
|
// w->searchContent(arguments.at(1));
|
2020-12-22 10:14:58 +08:00
|
|
|
QObject::connect(&app, SIGNAL(messageReceived(const QString&)),w, SLOT(bootOptionsFilter(const QString&)));
|
|
|
|
|
2021-01-10 15:59:17 +08:00
|
|
|
// qDebug() << "main start";
|
|
|
|
// FirstIndex* fi = new FirstIndex("/home");
|
|
|
|
// fi->start();
|
2021-01-11 16:59:50 +08:00
|
|
|
qDebug() << "main start";
|
2021-03-05 08:43:02 +08:00
|
|
|
AppMatch::getAppMatch()->start();
|
|
|
|
AppMatch apm;
|
|
|
|
apm.start();
|
2021-01-19 19:26:39 +08:00
|
|
|
QThreadPool::globalInstance()->setExpiryTimeout(5);
|
|
|
|
// QThreadPool::globalInstance()->clear();
|
|
|
|
// setAutoDelete(true);
|
|
|
|
|
|
|
|
// FirstIndex fi("/home/zhangzihao/Desktop/qwerty");
|
|
|
|
// FirstIndex* fi = new FirstIndex("/home/zhangzihao/Desktop/qwerty");
|
2021-02-19 10:46:53 +08:00
|
|
|
FirstIndex fi("/home/zhangzihao/Desktop");
|
2021-01-11 16:59:50 +08:00
|
|
|
fi.start();
|
2021-01-21 21:05:53 +08:00
|
|
|
// fi.wait();
|
2021-01-19 19:26:39 +08:00
|
|
|
// fi->wait();
|
|
|
|
// fi->exit();
|
|
|
|
// delete fi;
|
|
|
|
// assert(false);
|
2021-01-11 16:59:50 +08:00
|
|
|
InotifyIndex* ii = InotifyIndex::getInstance("/home");
|
|
|
|
// InotifyIndex ii("/home");
|
|
|
|
ii->start();
|
2020-12-26 08:56:38 +08:00
|
|
|
|
2021-02-21 11:41:20 +08:00
|
|
|
// qDebug() << "sigset start!";
|
|
|
|
// sigset( SIGTERM, handler);
|
|
|
|
// qDebug() << "sigset end!";
|
2021-01-22 17:15:43 +08:00
|
|
|
|
2021-01-19 19:26:39 +08:00
|
|
|
|
2020-12-22 10:14:58 +08:00
|
|
|
return app.exec();
|
2020-12-21 16:26:59 +08:00
|
|
|
}
|