Files

143 lines
4.4 KiB
C++
Raw Permalink Normal View History

2020-01-17 13:56:30 +08:00
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
* 2014 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
2019-07-04 15:46:12 +08:00
#include "sessionapplication.h"
#include "modulemanager.h"
2019-07-27 17:45:54 +08:00
#include "sessiondbusadaptor.h"
2019-12-31 09:29:25 +08:00
#include "idleadbusdaptor.h"
#include "idlewatcher.h"
2019-07-04 15:46:12 +08:00
#include <QDebug>
#include <QMediaPlayer>
#include <QDesktopWidget>
#include "../tools/ukuipower.h"
#define SESSION_DEFAULT_SETTINGS "org.ukui.session"
#define SESSION_DEFAULT_SETTINGS_PATH "/org/ukui/desktop/session/"
#define QT5_UKUI_STYLE "org.ukui.style"
#define PERIPHERALS_MOUSE "org.ukui.peripherals-mouse"
#define PERIPHERALS_MOUSE_PATH "/org/ukui/desktop/peripherals/mouse/"
2020-07-02 15:30:14 +08:00
#define MOUSE_KEY "cursor-size"
#define FONT_RENDERING_SCHEMAS "org.ukui.font-rendering"
#define FONT_REENDERING_PATH "/org/ukui/desktop/font-rendering/"
#define DPI_KEY "dpi"
QByteArray typeConver(int i){
QString str = QString::number(i);
QByteArray byte;
byte.append(str);
return byte;
}
void SessionApplication::InitialEnvironment()
{
UkuiPower *upower = new UkuiPower();
if(gsettings_usable){
if(upower->canAction(UkuiPower::PowerHibernate))
gs->set("canhibernate",true);
else
gs->set("canhibernate",false);
}
//检查qt主题是否安装
const QByteArray qt_style(QT5_UKUI_STYLE);
QByteArray QT_QPA_PLATFORMTHEME;
2020-04-18 20:36:34 +08:00
if (QGSettings::isSchemaInstalled(qt_style)) {
QT_QPA_PLATFORMTHEME = "ukui";
2020-04-18 20:36:34 +08:00
} else {
QT_QPA_PLATFORMTHEME = "gtk2";
}
qputenv("XDG_CURRENT_DESKTOP","UKUI");
qputenv("QT_QPA_PLATFORMTHEME",QT_QPA_PLATFORMTHEME);
}
2020-04-18 20:36:34 +08:00
void SessionApplication::updateIdleDelay(){
if (gsettings_usable) {
const int time = gs->get("idle-delay").toInt() * 60;
mIdleWatcher->reset(time);
2020-04-18 20:36:34 +08:00
}
}
2020-01-08 17:00:47 +08:00
void SessionApplication::registerDBus()
2019-07-04 15:46:12 +08:00
{
2019-07-27 17:45:54 +08:00
new SessionDBusAdaptor(modman);
2019-08-03 09:54:10 +08:00
QDBusConnection dbus = QDBusConnection::sessionBus();
2020-04-18 20:36:34 +08:00
if (!dbus.registerService(QStringLiteral("org.gnome.SessionManager"))) {
2019-12-31 09:29:25 +08:00
qCritical() << "Can't register org.gnome.SessionManager, there is already a session manager!";
}
2020-04-18 20:36:34 +08:00
if (!dbus.registerObject(("/org/gnome/SessionManager"), modman)) {
qCritical() << "Can't register object, there is already an object registered at "
2019-12-31 09:29:25 +08:00
<< "/org/gnome/SessionManager";
}
int timeout;
2020-04-18 20:36:34 +08:00
if (gsettings_usable) {
timeout = gs->get("idle-delay").toInt() * 60;
2020-04-18 20:36:34 +08:00
connect(gs, &QGSettings::changed, this, &SessionApplication::updateIdleDelay);
} else {
timeout = 5 * 60;
}
mIdleWatcher = new IdleWatcher(timeout);
2019-12-31 09:29:25 +08:00
new IdleDBusAdaptor(mIdleWatcher);
2020-04-18 20:36:34 +08:00
if (!dbus.registerObject("/org/gnome/SessionManager/Presence", mIdleWatcher)) {
2019-12-31 09:29:25 +08:00
qCritical() << "Cant' register object, there is already an object registered at "
<< "org/gnome/SessionManager/Presence";
}
2020-01-08 17:00:47 +08:00
}
SessionApplication::SessionApplication(int& argc, char** argv) :
QApplication(argc, argv)
{
const QByteArray id(SESSION_DEFAULT_SETTINGS);
2020-04-18 20:36:34 +08:00
if (QGSettings::isSchemaInstalled(id)) {
gsettings_usable = true;
gs = new QGSettings(SESSION_DEFAULT_SETTINGS,SESSION_DEFAULT_SETTINGS_PATH,this);
2020-07-02 15:30:14 +08:00
2020-04-18 20:36:34 +08:00
} else {
qWarning() << "Failed to get default value from gsettings, set gsettings_usable to false!";
gsettings_usable = false;
}
2020-01-08 17:00:47 +08:00
InitialEnvironment();
modman = new ModuleManager();
2019-07-27 17:45:54 +08:00
2019-07-13 17:57:05 +08:00
// Wait until the event loop starts
2019-07-04 15:46:12 +08:00
QTimer::singleShot(0, this, SLOT(startup()));
}
SessionApplication::~SessionApplication()
{
delete modman;
delete mIdleWatcher;
2020-01-17 13:56:30 +08:00
//delete mSettings;
delete gs;
2019-07-04 15:46:12 +08:00
}
bool SessionApplication::startup()
{
QTimer::singleShot(0, this, SLOT(registerDBus()));
2020-07-02 15:30:14 +08:00
2019-07-04 15:46:12 +08:00
modman->startup();
2019-12-09 15:22:02 +08:00
2019-07-04 15:46:12 +08:00
return true;
}