/* * * Copyright (C) 2020, KylinSoft Co., Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 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 * along with this program. If not, see . * * Authors: zhangjiaping * Modified by: zhangpengfei * Modified by: zhangzihao * */ #include "mainwindow.h" #include #include #include #include #include #include #include #include #include "qt-single-application.h" #include "qt-local-peer.h" //#include "inotify-manager.h" #include "libsearch.h" #include "global-settings.h" #include "xatom-helper.h" //void handler(int){ // qDebug() << "Recieved SIGTERM!"; // 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); // qDebug() << "indexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString(); // qDebug() << "contentIndexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString(); // ::exit(0); //// InotifyIndex::getInstance("/home")->~InotifyIndex(); // //wait linux kill this thread forcedly //// while (true); //} 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"; // QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/ukui-search/ukui-search.log"; QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/org.ukui/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) 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(); widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); } int main(int argc, char *argv[]) { 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"); qInstallMessageHandler(messageOutput); qRegisterMetaType>("QPair"); qRegisterMetaType("Document"); 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); }*/ //here need to be modified /*-------------ukuisearchdbus Test start-----------------*/ UkuiSearchQDBus usQDBus; usQDBus.setInotifyMaxUserWatches(); /*-------------ukuisearchdbus Test End-----------------*/ //load chinese character and pinyin file to a Map FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt"); /*-------------InotyifyRefact Test Start---------------*/ // QTime t1 = QTime::currentTime(); // InotifyManagerRefact* imr = new InotifyManagerRefact("/home"); // imr->start(); // QTime t2 = QTime::currentTime(); // qDebug() << t1; // 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; /*-------------content index Test End-----------------*/ /*-------------文本搜索 Test start-----------------*/ // FileSearcher *search = new FileSearcher(); // search->onKeywordSearchContent("重要器官移植⑤白血病"); // search->onKeywordSearchContent("g,e,x"); /*-------------文本搜索 Test End-----------------*/ // 加载国际化文件 QTranslator translator; try { if (! translator.load("/usr/share/ukui-search/translations/" + QLocale::system().name())) throw -1; app.installTranslator(&translator); } catch (...) { qDebug() << "Load translations file" << QLocale() << "failed!"; } 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!"; } MainWindow *w = new MainWindow; QStringList arguments = QCoreApplication::arguments(); // centerToScreen(w); w->moveToPanel(); //使用窗管的无边框策略 w->setProperty("useStyleWindowManager", false); //禁用拖动 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); app.setActivationWindow(w); if (QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) { w->moveToPanel(); w->show(); } // if(arguments.size()>1) // w->searchContent(arguments.at(1)); QObject::connect(&app, SIGNAL(messageReceived(const QString&)),w, SLOT(bootOptionsFilter(const QString&))); // qDebug() << "main start"; // FirstIndex* fi = new FirstIndex("/home"); // fi->start(); qDebug() << "main start"; AppMatch::getAppMatch()->start(); AppMatch apm; apm.start(); QThreadPool::globalInstance()->setExpiryTimeout(5); // QThreadPool::globalInstance()->clear(); // setAutoDelete(true); // FirstIndex fi("/home/zhangzihao/Desktop/qwerty"); // FirstIndex* fi = new FirstIndex("/home/zhangzihao/Desktop/qwerty"); FirstIndex fi("/home/zhangzihao/Desktop"); fi.start(); // fi.wait(); // fi->wait(); // fi->exit(); // delete fi; // assert(false); InotifyIndex* ii = InotifyIndex::getInstance("/home"); // InotifyIndex ii("/home"); ii->start(); // qDebug() << "sigset start!"; // sigset( SIGTERM, handler); // qDebug() << "sigset end!"; return app.exec(); }