2020-12-22 10:14:58 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Tianjin KYLIN Information Technology 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, 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
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 <QtSingleApplication>
|
|
|
|
#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"
|
2020-12-22 10:14:58 +08:00
|
|
|
|
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();
|
|
|
|
widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
|
|
|
|
}
|
2020-12-21 16:26:59 +08:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-01-06 14:14:38 +08:00
|
|
|
/*-------------ukuisearchdbus Test start-----------------*/
|
|
|
|
// UkuiSearchQDBus usQDBus;
|
|
|
|
// usQDBus.setInotifyMaxUserWatches();
|
|
|
|
|
|
|
|
/*-------------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:49:20 +08:00
|
|
|
|
2021-01-06 14:14:38 +08:00
|
|
|
/*-------------content index Test Start---------------*/
|
2021-01-06 08:57:21 +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-----------------*/
|
|
|
|
|
2021-01-03 16:58:26 +08:00
|
|
|
/*-------------GlobalSettings Test start-----------------*/
|
2021-01-06 09:59:08 +08:00
|
|
|
// GlobalSettings::getInstance();
|
2021-01-03 16:58:26 +08:00
|
|
|
|
|
|
|
/*-------------GlobalSettings Test End-----------------*/
|
|
|
|
|
2020-12-22 10:14:58 +08:00
|
|
|
qRegisterMetaType<QVector<QStringList>>("QVector<QStringList>");
|
|
|
|
|
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
|
|
|
|
|
QtSingleApplication app("ukui-search", argc, argv);
|
2021-01-06 11:21:19 +08:00
|
|
|
app.setQuitOnLastWindowClosed(false);
|
2020-12-22 10:14:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2020-12-24 11:06:19 +08:00
|
|
|
}/*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);
|
|
|
|
}*/
|
2020-12-22 10:14:58 +08:00
|
|
|
|
|
|
|
// 加载国际化文件
|
|
|
|
QTranslator translator;
|
|
|
|
try {
|
|
|
|
if (! translator.load("/usr/share/ukui-search/res/translations/" + QLocale::system().name())) throw -1;
|
|
|
|
app.installTranslator(&translator);
|
|
|
|
} catch (...) {
|
|
|
|
qDebug() << "Load translations file" << QLocale() << "failed!";
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow *w = new MainWindow;
|
|
|
|
QStringList arguments = QCoreApplication::arguments();
|
|
|
|
centerToScreen(w);
|
|
|
|
w->show();
|
|
|
|
w->raise();
|
|
|
|
w->activateWindow();
|
|
|
|
// w->loadMainWindow();
|
|
|
|
app.setActivationWindow(w);
|
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&)));
|
|
|
|
|
2020-12-26 08:56:38 +08:00
|
|
|
|
2020-12-22 10:14:58 +08:00
|
|
|
return app.exec();
|
2020-12-21 16:26:59 +08:00
|
|
|
}
|