ukui-session-manager/ 0000755 0001750 0001750 00000000000 13636030515 013546 5 ustar feng feng ukui-session-manager/translations/ 0000755 0001750 0001750 00000000000 13622453036 016271 5 ustar feng feng ukui-session-manager/translations/zh_CN.ts 0000644 0001750 0001750 00000004260 13622453036 017644 0 ustar feng feng
MainWindowFormsuspend锁定switchuser切换用户logout注销reboot重启shutdown关机QApplicationUKUI session tools, show the shutdown dialog without any arguments.Logout this computer.注销此电脑Shutdown this computer.关闭此电脑Switch the user of this computer.切换电脑的用户Restart this computer.重启此电脑
ukui-session-manager/translations/bo.ts 0000644 0001750 0001750 00000004606 13607542647 017261 0 ustar feng feng
PowerWinsuspendhibernateswitchuserrebootshutdownlogoutcancelQApplicationUKUI session tools, show the shutdown dialog without any arguments.Logout this computer.Shutdown this computer.Switch the user of this computer.Restart this computer.
ukui-session-manager/man/ 0000755 0001750 0001750 00000000000 13607542647 014335 5 ustar feng feng ukui-session-manager/man/ukui-session-tools.1 0000644 0001750 0001750 00000006471 13607542647 020223 0 ustar feng feng .\" Manual page for ukui-session
.\" (C) 2000 Miguel de Icaza (miguel@helixcode.com)
.\" (C) 2009-2010 Vincent Untz (vuntz@gnome.org)
.\" (C) 2016, Tianjin KYLIN Information Technology Co., Ltd.
.\"
.TH UKUI-SESSION 1 "11 February 2016" "UKUI Desktop Environment"
.\" Please adjust this date when revising the manpage.
.\"
.SH "NAME"
ukui-session \- Start the UKUI Desktop Environment.
.SH "SYNOPSIS"
.B ukui-session [OPTIONS]
.SH "DESCRIPTION"
The \fBukui-session\fP program starts up the UKUI desktop environment. This command is typically executed by your Login/Display Manager (like GDM, LXDM, XDM, SLiM, or from your X startup scripts like .xinitrc). It will load either your saved session, or it will provide a default session for the user as defined by the system administrator (or the default UKUI installation on your system).
.PP
The default session is defined in the dconf keys under
.BI / org / ukui / desktop / session /
.br
When saving a session, \fBukui-session\fP saves the currently running applications in the \fB~/.config/ukui-session/saved-session\fP directory of the users /home.
.PP
\fBukui-session\fP is an X11 session manager. It can manage UKUI applications as well as any other X11 SM compliant ones.
.SH "OPTIONS"
.SS The following options are supported:
.TP
\fB\-a, \-\-autostart=DIR\fR
Start all applications defined in "\fBDIR\fP", instead of starting the applications defined in
.BI / org / ukui / desktop / session / default\-session
.br
Multiple \fB\-\-autostart\fP options can be passed.
.TP
\fB\-f, \-\-failsafe\fR
Run in fail-safe mode. User-specified applications will not be started.
.TP
\fB\-\-debug\fR
Enable debugging code.
.TP
\fB\-\-display=DISPLAY\fR
X display to use.
.TP
\fB\-\-version\fR
Output version information and exit.
.TP
\fB\-?, \-h, \-\-help\fR
Print standard command line options.
.TP
\fB\-\-help\-all\fR
Print all command line options.
.SH "ENVIRONMENT"
.SS \fBukui-session\fP sets several environment variables for the use of its child processes:
.PP
.B "SESSION_MANAGER"
.IP
This variable is used by session-manager aware clients to contact ukui-session.
.PP
.B "DISPLAY"
.IP
This variable is set to the X display being used by \fBukui-session\fP. Note that if the \-\-display option is used this might be different from the setting of the environment variable when ukui-session is invoked.
.SH "FILES"
.PP
.nf
.B ~/.config/autostart
.B /usr/share/autostart
.B /usr/share/ukui/autostart
.fi
.IP
The applications defined in the above directories will be started on login. \fBukui-session-properties(1)\fP can be used to easily configure them.
.PP
.B ~/.config/ukui-session/saved-session
.IP
This directory contains the list of applications of the saved session.
.SH "BUGS"
.SS Should you encounter any bugs, they may be reported at:
https://github.com/ukui/ukui-session-manager/issues
.SH "AUTHORS"
.SS This Manual page was originally written for gnome-session by:
.nf
Miguel de Icaza (2000)
Vincent Untz (2009-2010)
.fi
.SS It has been updated for the MATE Desktop Environment by:
Adam Erdman (2014)
.SS It has been updated for the UKUI Desktop Environment by:
yilei (2016)
.SH "SEE ALSO"
.SS Further information may also be available at: http://wiki.ukui.org/
.P
.BR ukui-session-properties(1),
.BR ukui-session-save(1),
.BR ukui-wm(1)
ukui-session-manager/man/ukui-session.1 0000644 0001750 0001750 00000006471 13607542647 017065 0 ustar feng feng .\" Manual page for ukui-session
.\" (C) 2000 Miguel de Icaza (miguel@helixcode.com)
.\" (C) 2009-2010 Vincent Untz (vuntz@gnome.org)
.\" (C) 2016, Tianjin KYLIN Information Technology Co., Ltd.
.\"
.TH UKUI-SESSION 1 "11 February 2016" "UKUI Desktop Environment"
.\" Please adjust this date when revising the manpage.
.\"
.SH "NAME"
ukui-session \- Start the UKUI Desktop Environment.
.SH "SYNOPSIS"
.B ukui-session [OPTIONS]
.SH "DESCRIPTION"
The \fBukui-session\fP program starts up the UKUI desktop environment. This command is typically executed by your Login/Display Manager (like GDM, LXDM, XDM, SLiM, or from your X startup scripts like .xinitrc). It will load either your saved session, or it will provide a default session for the user as defined by the system administrator (or the default UKUI installation on your system).
.PP
The default session is defined in the dconf keys under
.BI / org / ukui / desktop / session /
.br
When saving a session, \fBukui-session\fP saves the currently running applications in the \fB~/.config/ukui-session/saved-session\fP directory of the users /home.
.PP
\fBukui-session\fP is an X11 session manager. It can manage UKUI applications as well as any other X11 SM compliant ones.
.SH "OPTIONS"
.SS The following options are supported:
.TP
\fB\-a, \-\-autostart=DIR\fR
Start all applications defined in "\fBDIR\fP", instead of starting the applications defined in
.BI / org / ukui / desktop / session / default\-session
.br
Multiple \fB\-\-autostart\fP options can be passed.
.TP
\fB\-f, \-\-failsafe\fR
Run in fail-safe mode. User-specified applications will not be started.
.TP
\fB\-\-debug\fR
Enable debugging code.
.TP
\fB\-\-display=DISPLAY\fR
X display to use.
.TP
\fB\-\-version\fR
Output version information and exit.
.TP
\fB\-?, \-h, \-\-help\fR
Print standard command line options.
.TP
\fB\-\-help\-all\fR
Print all command line options.
.SH "ENVIRONMENT"
.SS \fBukui-session\fP sets several environment variables for the use of its child processes:
.PP
.B "SESSION_MANAGER"
.IP
This variable is used by session-manager aware clients to contact ukui-session.
.PP
.B "DISPLAY"
.IP
This variable is set to the X display being used by \fBukui-session\fP. Note that if the \-\-display option is used this might be different from the setting of the environment variable when ukui-session is invoked.
.SH "FILES"
.PP
.nf
.B ~/.config/autostart
.B /usr/share/autostart
.B /usr/share/ukui/autostart
.fi
.IP
The applications defined in the above directories will be started on login. \fBukui-session-properties(1)\fP can be used to easily configure them.
.PP
.B ~/.config/ukui-session/saved-session
.IP
This directory contains the list of applications of the saved session.
.SH "BUGS"
.SS Should you encounter any bugs, they may be reported at:
https://github.com/ukui/ukui-session-manager/issues
.SH "AUTHORS"
.SS This Manual page was originally written for gnome-session by:
.nf
Miguel de Icaza (2000)
Vincent Untz (2009-2010)
.fi
.SS It has been updated for the MATE Desktop Environment by:
Adam Erdman (2014)
.SS It has been updated for the UKUI Desktop Environment by:
yilei (2016)
.SH "SEE ALSO"
.SS Further information may also be available at: http://wiki.ukui.org/
.P
.BR ukui-session-properties(1),
.BR ukui-session-save(1),
.BR ukui-wm(1)
ukui-session-manager/tools/ 0000755 0001750 0001750 00000000000 13637016220 014704 5 ustar feng feng ukui-session-manager/tools/mainwindow.h 0000644 0001750 0001750 00000002651 13622453036 017241 0 ustar feng feng /*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, 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 MAINWINDOW_H
#define MAINWINDOW_H
#include
#include "powerprovider.h"
#include
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
QRect m_screen;
~MainWindow();
void doevent(QEvent *event, QString test2,int i);
QTimer *timer;
int defaultnum = 0;
private:
Ui::MainWindow *ui;
UkuiPower *m_power;
void ResizeEvent();
protected:
void paintEvent(QPaintEvent *e);
bool eventFilter(QObject *, QEvent *);
void mousePressEvent(QMouseEvent *event);
};
#endif // MAINWINDOW_H
ukui-session-manager/tools/ukuipower.h 0000644 0001750 0001750 00000003211 13622453036 017110 0 ustar feng feng /* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
* Copyright: 2019 Tianjin KYLIN Information Technology Co., Ltd.
* 2012 Razor team
* Authors:
* Christian Surlykke
*
* This program or 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
*
* END_COMMON_COPYRIGHT_HEADER */
#ifndef UKUIPOWER_H
#define UKUIPOWER_H
#include
#include
#include
#include
class PowerProvider;
class UkuiPower : public QObject
{
Q_OBJECT
public:
enum Action {
PowerLogout,
PowerSwitchUser,
PowerHibernate,
PowerReboot,
PowerShutdown,
PowerSuspend,
PowerMonitorOff
};
explicit UkuiPower(QObject *parent = nullptr);
virtual ~UkuiPower();
bool canAction(Action action) const;
QSoundEffect *soundplayer;
void playmusic();
public slots:
bool doAction(Action action);
private:
QList mProviders;
};
#endif // UKUIPOWER_H
ukui-session-manager/tools/mainwindow.ui 0000644 0001750 0001750 00000016361 13622453036 017432 0 ustar feng feng
MainWindow00928900Form030016816855205858010816840Noto Sans CJK SC16color:whitesuspendQt::AlignCenter19030016816855205858010816840Noto Sans CJK SC16color:whiteswitchuserQt::AlignCenter38030016816855205858010816840Noto Sans CJK SC16color:whitelogoutQt::AlignCenter57030016816855205858010816740Noto Sans CJK SC16color:whiterebootQt::AlignCenter76030016816855205858010816840Noto Sans CJK SC16color:whiteshutdownQt::AlignCenter13020130600013040Noto Sans CJK SC20Qt::NoContextMenucolor:white1Qt::AlignCenter04013020Noto Sans CJK SC10color:whiteQt::AlignCenter
ukui-session-manager/tools/powerprovider.cpp 0000644 0001750 0001750 00000021525 13622453036 020330 0 ustar feng feng /* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
* Copyright: 2019 Tianjin KYLIN Information Technology Co., Ltd.
* 2012 Razor team
* Authors:
* Christian Surlykke
*
* This program or 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
*
* END_COMMON_COPYRIGHT_HEADER */
#include "powerprovider.h"
#include
#include
#include
#include
#include
#define LIGHTDM_SERVICE "org.freedesktop.DisplayManager"
#define LIGTHDM_INTERFACE "org.freedesktop.DisplayManager.Seat"
#define SYSTEMD_SERVICE "org.freedesktop.login1"
#define SYSTEMD_PATH "/org/freedesktop/login1"
#define SYSTEMD_INTERFACE "org.freedesktop.login1.Manager"
#define UKUI_SERVICE "org.gnome.SessionManager"
#define UKUI_PATH "/org/gnome/SessionManager"
#define UKUI_INTERFACE "org.gnome.SessionManager"
#define PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
static bool dbusCall(const QString &service,
const QString &path,
const QString &interface,
const QDBusConnection &connection,
const QString &method)
{
QDBusInterface dbus(service, path, interface, connection);
if (!dbus.isValid()) {
qWarning() << "dbusCall: QDBusInterface is invalid" << service << path << interface << method;
return false;
}
QDBusMessage msg = dbus.call(method);
if (!msg.errorName().isEmpty()) {
qWarning() << "Dbus error: " << msg;
}
return msg.arguments().isEmpty() ||
msg.arguments().constFirst().isNull() ||
msg.arguments().constFirst().toBool();
}
static bool dbusCallSystemd(const QString &service,
const QString &path,
const QString &interface,
const QDBusConnection &connection,
const QString &method,
bool needBoolArg)
{
QDBusInterface dbus(service, path, interface, connection);
if (!dbus.isValid()) {
qWarning() << "dbusCall: QDBusInterface is invalid" << service << path << interface << method;
return false;
}
QDBusMessage msg = dbus.call(method, needBoolArg ? QVariant(true) : QVariant());
if (!msg.errorName().isEmpty()) {
qWarning() << "Debus error: " << msg;
}
if (msg.arguments().isEmpty() || msg.arguments().constFirst().isNull())
return true;
QString response = msg.arguments().constFirst().toString();
qDebug() << "systemd:" << method << "=" << response;
return response == QLatin1String("yes") || response == QLatin1String("challenge");
}
bool dbusGetProperty(const QString &service,
const QString &path,
const QString &interface,
const QDBusConnection &connection,
const QString &property)
{
QDBusInterface dbus(service, path, interface, connection);
if (!dbus.isValid()) {
qWarning() << "dbusGetProperty: QDBusinterface is invalid" << service << path << interface << property;
return false;
}
QDBusMessage msg = dbus.call("SwitchToGreeter");//QLatin1String("Get"), dbus.interface(),property
if (!msg.errorName().isEmpty()) {
qWarning() << "Dbus error: " << msg;
}
return !msg.arguments().isEmpty() &&
msg.arguments().constFirst().value().variant().toBool();
}
PowerProvider::PowerProvider(QObject *parent) : QObject(parent)
{
}
PowerProvider::~PowerProvider()
{
}
/************************************************
SystemdProvider
http://www.freedesktop.org/wiki/Software/systemd/logind
************************************************/
SystemdProvider::SystemdProvider(QObject *parent): PowerProvider(parent)
{
}
SystemdProvider::~SystemdProvider()
{
}
bool SystemdProvider::canSwitchUser() const
{
/*
char *seat_id = nullptr;
char *session_id = nullptr;
int ret = 0;
sd_pid_get_session(getpid(), &session_id);
sd_session_get_seat(session_id, &seat_id);
ret = sd_seat_can_multi_session(seat_id);
return ret>0;
*/
QString property = "CanSwitch";
QString xdg_seat_path = qgetenv("XDG_SEAT_PATH");
return dbusGetProperty(QLatin1String(LIGHTDM_SERVICE),
xdg_seat_path,
QLatin1String(LIGTHDM_INTERFACE),
QDBusConnection::systemBus(),
property);
}
bool SystemdProvider::canAction(UkuiPower::Action action) const
{
QString command;
switch (action) {
case UkuiPower::PowerSwitchUser:
return canSwitchUser();
case UkuiPower::PowerReboot:
command = QLatin1String("CanReboot");
break;
case UkuiPower::PowerShutdown:
command = QLatin1String("CanPowerOff");
break;
case UkuiPower::PowerSuspend:
command = QLatin1String("CanSuspend");
break;
case UkuiPower::PowerHibernate:
command = QLatin1String("CanHibernate");
break;
default:
return false;
}
// canAction should be always silent because it can freeze
// g_main_context_iteration Qt event loop in QMessageBox
// on panel startup if there is no DBUS running.
return dbusCallSystemd(QLatin1String(SYSTEMD_SERVICE),
QLatin1String(SYSTEMD_PATH),
QLatin1String(SYSTEMD_INTERFACE),
QDBusConnection::systemBus(),
command,
false);
}
bool SystemdProvider::doSwitchUser()
{
QString command = "SwitchToGreeter";
QString xdg_seat_path = qgetenv("XDG_SEAT_PATH");
return dbusCall(QLatin1String(LIGHTDM_SERVICE),
xdg_seat_path,
QLatin1String(LIGTHDM_INTERFACE),
QDBusConnection::systemBus(),
command);
}
bool SystemdProvider::doAction(UkuiPower::Action action)
{
QString command;
switch (action)
{
case UkuiPower::PowerSwitchUser:
return doSwitchUser();
case UkuiPower::PowerReboot:
command = QLatin1String("Reboot");
break;
case UkuiPower::PowerShutdown:
command = QLatin1String("PowerOff");
break;
case UkuiPower::PowerSuspend:
command = QLatin1String("Suspend");
break;
case UkuiPower::PowerHibernate:
command = QLatin1String("Hibernate");
break;
default:
return false;
}
return dbusCallSystemd(QLatin1String(SYSTEMD_SERVICE),
QLatin1String(SYSTEMD_PATH),
QLatin1String(SYSTEMD_INTERFACE),
QDBusConnection::systemBus(),
command,
true);
}
UKUIProvider::UKUIProvider(QObject *parent): PowerProvider (parent)
{
}
UKUIProvider::~UKUIProvider()
{}
bool UKUIProvider::canAction(UkuiPower::Action action) const
{
QString command;
switch (action) {
case UkuiPower::PowerLogout:
command = QLatin1String("canLogout");
break;
case UkuiPower::PowerReboot:
command = QLatin1String("canReboot");
break;
case UkuiPower::PowerShutdown:
command = QLatin1String("canPowerOff");
break;
default:
return false;
}
return dbusCall(QLatin1String(UKUI_SERVICE),
QLatin1String(UKUI_PATH),
QLatin1String(UKUI_INTERFACE),
QDBusConnection::sessionBus(),
command);
}
bool UKUIProvider::doAction(UkuiPower::Action action)
{
QString command;
switch (action) {
case UkuiPower::PowerLogout:
command = QLatin1String("logout");
break;
case UkuiPower::PowerReboot:
command = QLatin1String("reboot");
break;
case UkuiPower::PowerShutdown:
command = QLatin1String("powerOff");
break;
default:
return false;
}
return dbusCall(QLatin1String(UKUI_SERVICE),
QLatin1String(UKUI_PATH),
QLatin1String(UKUI_INTERFACE),
QDBusConnection::sessionBus(),
command);
}
ukui-session-manager/tools/ukuipower.cpp 0000644 0001750 0001750 00000003513 13622453036 017450 0 ustar feng feng /* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
* Copyright: 2019 Tianjin KYLIN Information Technology Co., Ltd.
* 2012 Razor team
* Authors:
* Christian Surlykke
*
* This program or 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
*
* END_COMMON_COPYRIGHT_HEADER */
#include "ukuipower.h"
#include "powerprovider.h"
#include
UkuiPower::UkuiPower(QObject *parent) : QObject(parent)
{
mProviders.append(new SystemdProvider(this));
mProviders.append(new UKUIProvider(this));
}
UkuiPower::~UkuiPower()
{
}
bool UkuiPower::canAction(UkuiPower::Action action) const
{
for (const PowerProvider *provider : qAsConst(mProviders)) {
if (provider->canAction(action))
return true;
}
return false;
}
bool UkuiPower::doAction(UkuiPower::Action action)
{
for (PowerProvider *provider : qAsConst(mProviders)) {
if (provider->canAction(action) && provider->doAction(action))
return true;
}
return false;
}
void UkuiPower::playmusic(){
QSoundEffect *soundplayer = new QSoundEffect();
soundplayer->setSource(QUrl("qrc:/shutdown.wav"));
soundplayer->play();
}
ukui-session-manager/tools/powerprovider.h 0000644 0001750 0001750 00000003656 13622453036 020002 0 ustar feng feng /* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
* Copyright: 2019 Tianjin KYLIN Information Technology Co., Ltd.
* 2012 Razor team
* Authors:
* Christian Surlykke
*
* This program or 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
*
* END_COMMON_COPYRIGHT_HEADER */
#ifndef POWERPROVIDER_H
#define POWERPROVIDER_H
#include
#include "ukuipower.h"
class PowerProvider : public QObject
{
Q_OBJECT
public:
explicit PowerProvider(QObject *parent = nullptr);
virtual ~PowerProvider();
virtual bool canAction(UkuiPower::Action action) const = 0;
public slots:
virtual bool doAction(UkuiPower::Action action) = 0;
};
class SystemdProvider: public PowerProvider
{
Q_OBJECT
public:
SystemdProvider(QObject *parent = nullptr);
~SystemdProvider();
bool canAction(UkuiPower::Action action) const;
public slots:
bool doAction(UkuiPower::Action action);
private:
bool canSwitchUser() const;
bool doSwitchUser();
};
class UKUIProvider: public PowerProvider
{
Q_OBJECT
public:
UKUIProvider(QObject *parent = nullptr);
~UKUIProvider();
bool canAction(UkuiPower::Action action) const;
public slots:
bool doAction(UkuiPower::Action action);
};
#endif // POWERPROVIDER_H
ukui-session-manager/tools/CMakeLists.txt 0000644 0001750 0001750 00000001047 13622453036 017452 0 ustar feng feng set(tools_SRCS
main.cpp
ukuipower.cpp
powerprovider.cpp
mainwindow.h
mainwindow.cpp
mainwindow.ui
)
add_executable(ukui-session-tools
${tools_SRCS}
${PROJECT_SOURCE_DIR}/data/images.qrc
${PROJECT_SOURCE_DIR}/data/qss.qrc
${PROJECT_SOURCE_DIR}/data/music.qrc
)
target_link_libraries(ukui-session-tools
Qt5::Widgets
Qt5::Core
Qt5::Gui
Qt5::DBus
Qt5::Multimedia
)
install(TARGETS
ukui-session-tools
DESTINATION bin)
ukui-session-manager/tools/main.cpp 0000644 0001750 0001750 00000011526 13637016220 016341 0 ustar feng feng /*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
* 2010-2016 LXQt team
*
* 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, 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
#include
#include
#include
#include
#include
#include "ukuipower.h"
#include "mainwindow.h"
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
UkuiPower powermanager(&a);
QTimer *timer = new QTimer();
bool flag = true;
QCommandLineParser parser;
parser.setApplicationDescription(QApplication::tr("UKUI session tools, show the shutdown dialog without any arguments."));
const QString VERINFO = QStringLiteral("2.0");
a.setApplicationVersion(VERINFO);
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption logoutOption(QStringLiteral("logout"), QApplication::tr("Logout this computer."));
parser.addOption(logoutOption);
QCommandLineOption shutdownOption(QStringLiteral("shutdown"), QApplication::tr("Shutdown this computer."));
parser.addOption(shutdownOption);
QCommandLineOption switchuserOption(QStringLiteral("switchuser"), QApplication::tr("Switch the user of this computer."));
parser.addOption(switchuserOption);
QCommandLineOption rebootOption(QStringLiteral("reboot"), QApplication::tr("Restart this computer."));
parser.addOption(rebootOption);
parser.process(a);
if (parser.isSet(logoutOption)) {
powermanager.playmusic();
QObject::connect(timer,&QTimer::timeout,
[&]()
{
timer->stop();
delete timer;
powermanager.doAction(UkuiPower::Action(0));
a.exit();
});
timer->start(1000);
flag = false;
}
if (parser.isSet(shutdownOption)) {
powermanager.playmusic();
QObject::connect(timer,&QTimer::timeout,
[&]()
{
timer->stop();
delete timer;
powermanager.doAction(UkuiPower::Action(4));
a.exit();
});
timer->start(1000);
flag = false;
}
if (parser.isSet(switchuserOption)) {
powermanager.playmusic();
QObject::connect(timer,&QTimer::timeout,
[&]()
{
timer->stop();
delete timer;
powermanager.doAction(UkuiPower::Action(1));
a.exit();
});
timer->start(1000);
flag = false;
}
if (parser.isSet(rebootOption)) {
powermanager.playmusic();
QObject::connect(timer,&QTimer::timeout,
[&]()
{
timer->stop();
delete timer;
powermanager.doAction(UkuiPower::Action(3));
a.exit();
});
timer->start(1000);
flag = false;
}
if (flag) {
//加载翻译文件
const QString locale = QLocale::system().name();
QTranslator translator;
qDebug() << "local: " << locale;
qDebug() << "path: " << QStringLiteral(UKUI_TRANSLATIONS_DIR) + QStringLiteral("/ukui-session-manager");
if (translator.load(locale, QStringLiteral(UKUI_TRANSLATIONS_DIR) + QStringLiteral("/ukui-session-manager"))) {
a.installTranslator(&translator);
} else {
qDebug() << "Load translations file failed!";
}
MainWindow w ;
//加载qss文件
QFile qss(":/powerwin.qss");
qss.open(QFile::ReadOnly);
a.setStyleSheet(qss.readAll());
qss.close();
w.showFullScreen();
QObject::connect(w.timer,&QTimer::timeout,
[&]()
{
w.timer->stop();
delete w.timer;
if(!w.isVisible()){
qDebug()<