Merge branch 'main' into 0106-dev

This commit is contained in:
iaom 2021-01-06 14:49:20 +08:00 committed by GitHub
commit 576e2760ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 140 additions and 89 deletions

View File

@ -41,3 +41,4 @@ void FileTypeFilter::Test(){
ig->creatAllIndex(this->result);
}

View File

@ -13,7 +13,8 @@ HEADERS += \
$$PWD/messagelisttemplate.h \
$$PWD/traverse_bfs.h \
# $$PWD/text-content-indexer.h \
$$PWD/file-searcher.h
$$PWD/file-searcher.h \
$$PWD/ukui-search-qdbus.h
SOURCES += \
# $$PWD/chinesecharacterstopinyin.cpp \
@ -29,5 +30,6 @@ SOURCES += \
$$PWD/test-Inotify-Manager.cpp \
$$PWD/traverse_bfs.cpp \
# $$PWD/text-content-indexer.cpp \
$$PWD/file-searcher.cpp
$$PWD/file-searcher.cpp \
$$PWD/ukui-search-qdbus.cpp

View File

@ -1,7 +1,18 @@
#include "inotify.h"
#include "ukui-search-qdbus.h"
InotifyManagerRefact::InotifyManagerRefact(const QString& path) : Traverse_BFS(path)
{
/*-------------ukuisearchdbus Test start-----------------*/
qDebug() << "setInotifyMaxUserWatches start";
UkuiSearchQDBus usQDBus;
usQDBus.setInotifyMaxUserWatches();
qDebug() << "setInotifyMaxUserWatches end";
/*-------------ukuisearchdbus Test End-----------------*/
// dirPath = new QMap<QString, QStringList>();
m_fd = inotify_init();
qDebug() << "m_fd----------->" <<m_fd;

View File

@ -0,0 +1,29 @@
#include "ukui-search-qdbus.h"
#include <QDebug>
UkuiSearchQDBus::UkuiSearchQDBus()
{
this->tmpSystemQDBusInterface = new QDBusInterface("com.ukui.search.qt.systemdbus",
"/",
"com.ukui.search.interface",
QDBusConnection::systemBus());
if (!tmpSystemQDBusInterface->isValid()){
qCritical() << "Create Client Interface Failed When execute chage: " << QDBusConnection::systemBus().lastError();
return;
}
}
UkuiSearchQDBus::~UkuiSearchQDBus(){
delete this->tmpSystemQDBusInterface;
this->tmpSystemQDBusInterface = nullptr;
}
//一键三连
void UkuiSearchQDBus::setInotifyMaxUserWatches()
{
// /proc/sys/fs/inotify/max_user_watches
this->tmpSystemQDBusInterface->call("setInotifyMaxUseWatchesStep1");
// sysctl
this->tmpSystemQDBusInterface->call("setInotifyMaxUseWatchesStep2");
// /etc/sysctl.conf
this->tmpSystemQDBusInterface->call("setInotifyMaxUseWatchesStep3");
}

View File

@ -0,0 +1,16 @@
#ifndef UKUISEARCHQDBUS_H
#define UKUISEARCHQDBUS_H
#include <QDBusInterface>
class UkuiSearchQDBus
{
public:
UkuiSearchQDBus();
~UkuiSearchQDBus();
void setInotifyMaxUserWatches();
private:
QDBusInterface* tmpSystemQDBusInterface;
};
#endif // UKUISEARCHQDBUS_H

View File

@ -11,6 +11,8 @@
#include "index/filetypefilter.h"
#include "index/ukui-search-qdbus.h"
class LIBSEARCH_EXPORT GlobalSearch
{
public:

View File

@ -1,4 +1,4 @@
QT += core concurrent xml widgets
QT += core concurrent xml widgets dbus
VERSION = 0.0.1
TARGET = ukui-search

View File

@ -47,6 +47,12 @@ void centerToScreen(QWidget* widget) {
int main(int argc, char *argv[])
{
/*-------------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---------------*/
@ -58,16 +64,17 @@ int main(int argc, char *argv[])
// qDebug() << t2;
/*-------------InotyifyRefact Test End-----------------*/
/*-------------InotyifyRefact 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;
/*-------------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();

View File

@ -1,4 +1,4 @@
[D-BUS Service]
Name=com.ukui.search.qt.systemdbus
Exec=/usr/bin/ukuiSearchSystemDBus
Exec=/usr/bin/ukui-search-systemdbus
User=root

View File

@ -23,12 +23,10 @@
#include <QSharedPointer>
#include <QRegExp>
#include <stdlib.h>
#include <QGraphicsView>
SysdbusRegister::SysdbusRegister()
{
// mHibernateFile = "/etc/systemd/sleep.conf";
// mHibernateSet = new QSettings(mHibernateFile, QSettings::IniFormat, this);
// mHibernateSet->setIniCodec("UTF-8");
}
SysdbusRegister::~SysdbusRegister()
@ -39,39 +37,20 @@ void SysdbusRegister::exitService() {
qApp->exit(0);
}
//QString SysdbusRegister::GetComputerInfo() {
// QByteArray ba;
// FILE * fp = NULL;
// char cmd[128];
// char buf[1024];
// sprintf(cmd, "dmidecode -t system");
/*
*
* sprintf(cmd, "echo 9999999 | sudo tee -a /proc/sys/fs/inotify/max_user_watches");
* sprintf(cmd, "sysctl -w fs.inotify.max_user_watches=\"9999999\"");
* sprintf(cmd, "echo fs.inotify.max_user_watches=9999999 | sudo tee -a /etc/sysctl.conf");
*/
// if ((fp = popen(cmd, "r")) != NULL){
// rewind(fp);
// while (!feof(fp)) {
// fgets(buf, sizeof (buf), fp);
// ba.append(buf);
// }
// pclose(fp);
// fp = NULL;
// }
// return QString(ba);
//}
QString SysdbusRegister::setInotifyMaxUserWatches5()
QString SysdbusRegister::setInotifyMaxUserWatchesStep1()
{
// QString cmd;
//// cmd = QString("echo 9999999 | sudo tee -a /proc/sys/fs/inotify/max_user_watches");
// cmd = QString("reboot");
// QProcess p;
// p.start(cmd);
// return 123;
QByteArray ba;
FILE * fp = NULL;
char cmd[128];
char buf[1024];
sprintf(cmd, "echo 9999999 | sudo tee -a /proc/sys/fs/inotify/max_user_watches");
if ((fp = popen(cmd, "r")) != NULL){
rewind(fp);
while (!feof(fp)) {
@ -81,46 +60,58 @@ QString SysdbusRegister::setInotifyMaxUserWatches5()
pclose(fp);
fp = NULL;
}
else{
return QString("popen open failed");
}
return QString(ba);
}
////获取免密登录状态
//QString SysdbusRegister::getNoPwdLoginStatus(){
// QByteArray ba;
// FILE * fp = NULL;
// char cmd[128];
// char buf[1024];
// sprintf(cmd, "cat /etc/group |grep nopasswdlogin");
// if ((fp = popen(cmd, "r")) != NULL){
// rewind(fp);
// fgets(buf, sizeof (buf), fp);
// ba.append(buf);
// pclose(fp);
// fp = NULL;
// }else{
// qDebug()<<"popen文件打开失败"<<endl;
// }
// return QString(ba);
//}
QString SysdbusRegister::setInotifyMaxUserWatchesStep2()
{
QByteArray ba;
FILE * fp = NULL;
char cmd[128];
char buf[1024];
sprintf(cmd, "sysctl -w fs.inotify.max_user_watches=\"9999999\"");
if ((fp = popen(cmd, "r")) != NULL){
rewind(fp);
while (!feof(fp)) {
fgets(buf, sizeof (buf), fp);
ba.append(buf);
}
pclose(fp);
fp = NULL;
}
else{
return QString("popen open failed");
}
return QString(ba);
}
////设置免密登录状态
//void SysdbusRegister::setNoPwdLoginStatus() {
QString SysdbusRegister::setInotifyMaxUserWatchesStep3()
{
QByteArray ba;
FILE * fp = NULL;
char cmd[128];
char buf[1024];
sprintf(cmd, "echo fs.inotify.max_user_watches=9999999 | sudo tee -a /etc/sysctl.conf");
if ((fp = popen(cmd, "r")) != NULL){
rewind(fp);
while (!feof(fp)) {
fgets(buf, sizeof (buf), fp);
ba.append(buf);
}
pclose(fp);
fp = NULL;
}
else{
return QString("popen open failed");
}
return QString(ba);
}
//// QString cmd;
//// if(true == status){
//// cmd = QString("gpasswd -a %1 nopasswdlogin").arg(username);
//// } else{
//// cmd = QString("gpasswd -d %1 nopasswdlogin").arg(username);
//// }
//// QProcess::execute(cmd);
// QString cmd;
// cmd = QString("sysctl -w fs.inotify.max_user_watches=\"1\"");
// QProcess::execute(cmd);
//}
//The following example comes from control center
//// 设置自动登录状态
//void SysdbusRegister::setAutoLoginStatus(QString username) {
// QString filename = "/etc/lightdm/lightdm.conf";
// QSharedPointer<QSettings> autoSettings = QSharedPointer<QSettings>(new QSettings(filename, QSettings::IniFormat));
@ -143,19 +134,9 @@ QString SysdbusRegister::setInotifyMaxUserWatches5()
// return time;
//}
//void SysdbusRegister::setSuspendThenHibernate(QString time) {
// mHibernateSet->beginGroup("Sleep");
// mHibernateSet->setValue("HibernateDelaySec", time);
// mHibernateSet->endGroup();
// mHibernateSet->sync();
//}
//void SysdbusRegister::setPasswdAging(int days, QString username) {
// QString cmd;
// cmd = QString("chage -M %1 %2").arg(days).arg(username);
//// cmd = QString("reboot");
// QProcess::execute(cmd);
//}

View File

@ -50,7 +50,9 @@ public slots:
Q_SCRIPTABLE void exitService();
// Q_SCRIPTABLE QString GetComputerInfo();
Q_SCRIPTABLE QString setInotifyMaxUserWatches5();
Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep1();
Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep2();
Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep3();
// // 设置免密登录状态
// Q_SCRIPTABLE void setNoPwdLoginStatus();

View File

@ -2,7 +2,7 @@ QT += core dbus
QT -= gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ukuiSearchSystemDBus
TARGET = ukui-search-systemdbus
TEMPLATE = app
CONFIG += console c++11 link_pkgconfig