diff --git a/ukui-search.pro b/ukui-search.pro index d11a6f6..672df77 100644 --- a/ukui-search.pro +++ b/ukui-search.pro @@ -1,7 +1,8 @@ TEMPLATE = subdirs SUBDIRS += $$PWD/libchinese-segmentation \ $$PWD/libsearch \ - $$PWD/src + $$PWD/src \ + $$PWD/ukuisearch-systemdbus # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the diff --git a/ukuisearch-systemdbus/conf/com.ukui.search.qt.systemdbus.conf b/ukuisearch-systemdbus/conf/com.ukui.search.qt.systemdbus.conf new file mode 100644 index 0000000..342a262 --- /dev/null +++ b/ukuisearch-systemdbus/conf/com.ukui.search.qt.systemdbus.conf @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + diff --git a/ukuisearch-systemdbus/conf/com.ukui.search.qt.systemdbus.service b/ukuisearch-systemdbus/conf/com.ukui.search.qt.systemdbus.service new file mode 100644 index 0000000..daf6416 --- /dev/null +++ b/ukuisearch-systemdbus/conf/com.ukui.search.qt.systemdbus.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=com.ukui.search.qt.systemdbus +Exec=/usr/bin/ukuiSearchSystemDBus +User=root diff --git a/ukuisearch-systemdbus/main.cpp b/ukuisearch-systemdbus/main.cpp new file mode 100644 index 0000000..effc06b --- /dev/null +++ b/ukuisearch-systemdbus/main.cpp @@ -0,0 +1,47 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include +#include +#include + +#include + +#include "sysdbusregister.h" + +int main(int argc, char *argv[]){ + + QCoreApplication app(argc, argv); + app.setOrganizationName("Kylin Team"); + app.setApplicationName("ukui-search-service"); + + + QDBusConnection systemBus = QDBusConnection::systemBus(); + if (!systemBus.registerService("com.ukui.search.qt.systemdbus")){ + qCritical() << "QDbus register service failed reason:" << systemBus.lastError(); + exit(1); + } + + if (!systemBus.registerObject("/", new SysdbusRegister(), QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals)){ + qCritical() << "QDbus register object failed reason:" << systemBus.lastError(); + exit(2); + } + + return app.exec(); +} diff --git a/ukuisearch-systemdbus/sysdbusregister.cpp b/ukuisearch-systemdbus/sysdbusregister.cpp new file mode 100644 index 0000000..9a811a8 --- /dev/null +++ b/ukuisearch-systemdbus/sysdbusregister.cpp @@ -0,0 +1,161 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#include "sysdbusregister.h" + +#include +#include +#include +#include + +SysdbusRegister::SysdbusRegister() +{ +// mHibernateFile = "/etc/systemd/sleep.conf"; +// mHibernateSet = new QSettings(mHibernateFile, QSettings::IniFormat, this); +// mHibernateSet->setIniCodec("UTF-8"); +} + +SysdbusRegister::~SysdbusRegister() +{ +} + +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"); + +// 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 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)) { + fgets(buf, sizeof (buf), fp); + ba.append(buf); + } + pclose(fp); + fp = NULL; + } + 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文件打开失败"< autoSettings = QSharedPointer(new QSettings(filename, QSettings::IniFormat)); +// autoSettings->beginGroup("SeatDefaults"); + +// autoSettings->setValue("autologin-user", username); + +// autoSettings->endGroup(); +// autoSettings->sync(); +//} + +//QString SysdbusRegister::getSuspendThenHibernate() { +// mHibernateSet->beginGroup("Sleep"); + +// QString time = mHibernateSet->value("HibernateDelaySec").toString(); + +// mHibernateSet->endGroup(); +// mHibernateSet->sync(); + +// 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); +//} diff --git a/ukuisearch-systemdbus/sysdbusregister.h b/ukuisearch-systemdbus/sysdbusregister.h new file mode 100644 index 0000000..9cbf83b --- /dev/null +++ b/ukuisearch-systemdbus/sysdbusregister.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ +#ifndef SYSDBUSREGISTER_H +#define SYSDBUSREGISTER_H + +#include +#include +#include +#include +#include + +class SysdbusRegister : public QObject +{ + Q_OBJECT + + Q_CLASSINFO("D-Bus Interface", "com.ukui.search.interface") + +public: + explicit SysdbusRegister(); + ~SysdbusRegister(); + +//private: +// QString mHibernateFile; + +// QSettings *mHibernateSet; + +//signals: +// Q_SCRIPTABLE void nameChanged(QString); +// Q_SCRIPTABLE void computerinfo(QString); + +public slots: + + Q_SCRIPTABLE void exitService(); +// Q_SCRIPTABLE QString GetComputerInfo(); + + Q_SCRIPTABLE QString setInotifyMaxUserWatches5(); + +// // 设置免密登录状态 +// Q_SCRIPTABLE void setNoPwdLoginStatus(); + +// // 获取免密登录状态 +// Q_SCRIPTABLE QString getNoPwdLoginStatus(); + +// // 设置自动登录状态 +// Q_SCRIPTABLE void setAutoLoginStatus(QString username); + +// // 获取挂起到休眠时间 +// Q_SCRIPTABLE QString getSuspendThenHibernate(); + +// // 设置挂起到休眠时间 +// Q_SCRIPTABLE void setSuspendThenHibernate(QString time); + +// // 设置密码时效 +// void setPasswdAging(int days, QString username); +}; + +#endif // SYSDBUSREGISTER_H diff --git a/ukuisearch-systemdbus/ukuisearch-systemdbus.pro b/ukuisearch-systemdbus/ukuisearch-systemdbus.pro new file mode 100644 index 0000000..678f858 --- /dev/null +++ b/ukuisearch-systemdbus/ukuisearch-systemdbus.pro @@ -0,0 +1,31 @@ +QT += core dbus +QT -= gui +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = ukuiSearchSystemDBus +TEMPLATE = app + +CONFIG += console c++11 link_pkgconfig +CONFIG -= app_bundle + +DESTDIR = . +INCLUDEPATH += . + +inst1.files += conf/com.ukui.search.qt.systemdbus.service +inst1.path = /usr/share/dbus-1/system-services/ +inst2.files += conf/com.ukui.search.qt.systemdbus.conf +inst2.path = /etc/dbus-1/system.d/ + +target.source += $$TARGET +target.path = /usr/bin +INSTALLS += \ + target \ + inst1 \ + inst2 \ + +HEADERS += \ + sysdbusregister.h + +SOURCES += \ + main.cpp \ + sysdbusregister.cpp