ukui-power-manager/0000755000175000017500000000000014205117543013217 5ustar fengfengukui-power-manager/readme.md0000644000175000017500000000036414205117452015000 0ustar fengfeng## dbus 服务 ``` 用于提权 使用方法: mkdir build make -j8 sudo make install //这样会讲service文件安装到系统目录下 调用exitService接口退出 //或者重启,否则修改无法生效(注销也不生效) ``` ukui-power-manager/doc/0000755000175000017500000000000014205117452013763 5ustar fengfengukui-power-manager/doc/schedules.md0000644000175000017500000000404014205117452016262 0ustar fengfeng## 计划表 ``` 计划8月份基本完成电源管理的改版工作 保证9月30号之前新版电源管理能够上线使用使用 具体时间节点: 电源显示界面: 0813 :ui改版,去除ui文件【处理中,由于新插入其他工作,预计延期】 0820 :新增消息通知类,用以处理极低电量,低电量等消息通知 0827 :托盘图标显示界面分离 0903 :快捷键亮度调节界面重写 电源管理事件调度后台: 0805 :电源管理基础 调研文档(第一阶段)基本结束(包括upower,亮度调节,cpu调频等)[基本完成] 0806 :亮度调节,cpu调频,关闭显示器的dbus服务接口完成 【亮度调节接口未完成,其他基本完成,demo未补充,预计0810之前完成】 0813 :电源管理事件调度中心核心代码编写完毕;gpu调频接口处理【已经开始着手处理,处理的时候务必保证功能稳定性】 0820 :电源管理基础 调研文档(第二阶段)结束。 电源管理后台( 事件分发,事件调度,策略修改) 代码联调 整机测试,分别在华为990笔记本,华为990台式机,华为9a0笔记本, 飞腾,鲲鹏,清华同方,龙芯4000,龙芯5000,联想机器联调功能。 (国产机器驱动书写未必符合规范,所以一定要) 0827 :新版电源管理后台满足全部设计稿中的功能 0903 :代码优化,编包等,使新版电源管理达到可上线的状态 0910 :电源管理评审,完善设计文档,需求文档 0917 :准备上线,全量测试 ``` ``` 0807备注: 为保证功能稳定性,计划采用逐步替换旧版功能的方式进行修改 预计上线的流程为: -> ui替换 -> 空闲-关闭显示器功能后台采用新版 【时间节点0813】 -> 空闲-all 采用新版 (包括cpu调频,暂不包括gpu调频)【时间节点0820】 -> 合盖处理 采用新版 ;监听电源键 采用新版【时间节点 0827】 -> 完全替换【0903】 -> gpu调频 低电量处理 【0910】 ``` ukui-power-manager/doc/性能测试注意事项.md0000644000175000017500000000112614205117452025041 0ustar fengfeng# 性能测试注意事项 ``` 1.连接电源【使用电池的情况下电源管理会更改调频策略】 2.控制面板设置电源计划为性能模式 如果控制面板-系统-电源-使用电源时的模式选择没有性能模式则需要手动设置【v10sp1 0820-1 版本暂时没有性能模式选项】 gsettings set org.ukui.power-manager power-policy-ac 0 3.控制面板-系统-电源-此时间段后关闭显示器 选为从不 4.控制面板-系统-电源-此时间段后进入睡眠 选为从不 5.控制面板-个性化-屏保-此时间段后开启屏保 选为从不 ``` ukui-power-manager/doc/设计文档.md0000644000175000017500000000003314205117452020650 0ustar fengfeng# 电源管理设计文档 ukui-power-manager/doc/电源管理需求文档.md0000644000175000017500000000351514205117452024726 0ustar fengfeng# 电源管理需求文档 ### 目录 ``` 1.托盘图标 2.任务栏上弹出窗口 3.亮度调节界面 4.消息通知 5.后台服务 6.upower封装 7.upower代码改动 8.低电量处理 9.文档输出 ``` ## 托盘图标 ``` 功能点罗列: 1.支持显示正确的图标 2.区分台式机与笔记本(台式机上不显示图标) 3.支持悬浮显示tooltip 4.支持右键弹出窗口 5.支持选择显示剩余充电时间 需求分析: 1.通过upower接口获取图标名称 2.通过upower获取电量 3.通过upower获取电量改变的信号 4.通过upower封装的接口获取剩余多久充满电(需要用upower封装的接口原因是原生接口数值波动过大) ``` ## 任务栏上弹出窗口 ``` 功能点罗列: 1.支持显示在正确的位置(包括多屏,并且需要监听屏幕改变) 2.支持透明度与毛玻璃效果 3.支持圆角阴影 4.支持跟随主题 5.支持跟随文字大小变化 6.界面内的图标与托盘图标保持一致 7.界面内的文字保持与托盘tooltip一致 ``` ## 亮度调节界面 ``` 功能点罗列: 1.支持透明度与毛玻璃效果 2.支持圆角阴影 3.支持跟随主题 4.支持图标高亮协议 5.支持双屏显示 6.绑定快捷键显示 7.禁止显示10%以下亮度 ``` ## 消息通知 ``` 功能点罗列 1.接收upower的信号和电量,进行消息通知 ``` ## 低电量处理 ``` 功能点罗列: 1.电池低电量之后自动进入省电模式 2.使用电池时自动进入节能模式 3.低电量通知 4.极低电量关机等功能 ``` ## 后台服务 ``` 功能点罗列: 一. 合盖处理 二. 关机键处理 三. 空闲处理 合盖处理 1. 选择合盖子之后的操作,调用相关接口即可 关机键处理 1. 选择关机键按下之后的操作即可 空闲处理 1.关闭显示器 2.睡眠/休眠 3.降低屏幕亮度 ```ukui-power-manager/data/0000755000175000017500000000000014205117452014127 5ustar fengfengukui-power-manager/data/ukui.power.policy.conf0000755000175000017500000000114314205117452020406 0ustar fengfeng ukui-power-manager/data/ukui-power-manager-tray.10000644000175000017500000000146314205117452020711 0ustar fengfeng.TH "UKUI-POWER-MANAGER-TRAY" "1" "29 March,2006" "" "" .SH NAME ukui-power-manager-tray \- UKUI power manager system tray .SH SYNOPSIS \fBukui-power-manager-tray\fR [ \fB\-\-verbose\fR ] [ \fB\-\-debug\fR ] [ \fB\-\-help\fR ] .SH "DESCRIPTION" \fBukui-power-manager-tray\fR is the panel applet of the UKUI power management. .PP It supports features such as suspending, hibernating, screen blanking, cpu frequency switching and more. .SH "OPTIONS" .TP \fB\-\-help\fR Show summary of options. .TP \fB\-\-verbose\fR Show extra debugging. .TP \fB\-\-debug\fR Only show specific debugging options. Useful for developers only. .SH "SEE ALSO" .PP ukui-power-preferences (1). .SH "AUTHOR" .PP This manual page was written by Oliver Grawert for the Debian system and updated by Ow Mun Heng ukui-power-manager/data/gpm-feedback-widget.ui0000644000175000017500000000315414205117452020257 0ustar fengfeng Brightness notification True 0 out True 12 6 True 6 0 True 0.10000000149 False False 1 ukui-power-manager/data/ukui-power-statistics.desktop.in.in0000644000175000017500000000066114205117452023036 0ustar fengfeng[Desktop Entry] _Name=Power Statistics _Comment=Observe power management Icon=ukui-power-statistics Exec=ukui-power-statistics Terminal=false Type=Application Categories=GTK;System;Monitor; OnlyShowIn=UKUI; NoDisplay=false StartupNotify=true X-UKUI-Bugzilla-Bugzilla=UKUI X-UKUI-Bugzilla-Product=ukui-power-manager X-UKUI-Bugzilla-Component=ukui-power-statistics X-UKUI-Bugzilla-Version=@VERSION@ X-Desktop-File-Install-Version=0.10 ukui-power-manager/data/org.ukui.PowerManager.service.in0000644000175000017500000000012014205117452022240 0ustar fengfeng[D-BUS Service] Name=org.ukui.PowerManager Exec=@servicedir@/ukui-power-manager ukui-power-manager/data/gpm-prefs.ui0000644000175000017500000016745714205117452016412 0ustar fengfeng 1 1 61 1 5 23 1 61 1 5 41 100 1 5 1 1 61 1 5 23 1 61 1 5 1 1 61 1 5 23 1 61 1 5 5 Power Management Preferences False center-on-parent dialog True vertical 2 True True 6 True 12 vertical 12 True vertical 6 True 0 <b>Actions</b> True False False 0 True 12 True vertical 6 True 12 True True 0 Put computer to _sleep when inactive for: True False 0 True 1 False False 0 True 12 True True 0 When laptop lid is cl_osed: True False 0 True 1 1 False 1 False 0 True vertical 6 True 0 <b>Display</b> True False False 0 True 12 True vertical 5 True 12 True True 0 Put _display to sleep when inactive for: True False 0 True 1 0 True 12 True True 0 Set display _brightness to: True hscale_ac_brightness False 0 True True adjustment3 0 bottom 1 1 Di_m display when idle True True False True True False False 2 1 False 1 True On AC Power False True 12 vertical 12 True vertical 6 True 0 <b>Actions</b> True False False 0 True 12 True vertical 6 True 12 True True 0 Put computer to _sleep when inactive for: True False 0 True 1 False False 0 True 12 True True 0 When laptop lid is cl_osed: True False 0 True 1 1 True 12 True True 0 When battery po_wer is critically low: True False 0 True 1 2 False 1 False 0 True vertical 6 True 0 <b>Display</b> True False False 0 True 12 True vertical 5 True 12 True True 0 Put _display to sleep when inactive for: True False 0 True 1 0 _Reduce backlight brightness True True False True True False False 1 Di_m display when idle True True False True True False False 2 1 False 1 1 True On Battery Power 1 False True 12 vertical 12 True vertical 6 True 0 <b>Actions</b> True False False 0 True 12 True vertical 6 True 12 True True 0 Put computer to _sleep when inactive for: True False 0 True 1 False False 0 True 12 True True 0 When UPS power is l_ow: True False 0 True 1 1 True 12 True True 0 When UPS power is _critically low: True False 0 True 1 2 False 1 False 0 True vertical 6 True 0 <b>Display</b> True False False 0 True 12 True vertical 5 True 12 True True 0 Put _display to sleep when inactive for: True False 0 True 1 0 1 False 1 2 True On UPS Power 2 False True 12 vertical 12 True vertical 6 True 0 <b>Actions</b> True False False 0 True 12 True vertical 6 True 12 True True 0 When the power _button is pressed: True False 0 True 1 False False 0 True 12 True True 0 When the _suspend button is pressed: True False 0 True 1 1 False 1 False 0 True vertical 6 True 0 <b>Notification Area</b> True False False 0 True 12 True vertical 6 _Never display an icon True True False True True False False 0 _Only display an icon when battery power is low True True False True True radiobutton_notification_never False False 1 Only display an icon when charging or _discharging True True False True True radiobutton_notification_never False False 2 Only display an icon when a battery is p_resent True True False True True radiobutton_notification_never False False 3 _Always display an icon True True False True True radiobutton_notification_never False False 4 1 False 1 3 True General 3 False False 1 True end gtk-help True True True False Provides help about this program True False False 0 True Make Default True True True Sets this policy to be used by all users False False 1 gtk-close True True True True False Closes the program True False False 2 False end 0 button_help button_defaults button_close ukui-power-manager/data/gpm-statistics.ui0000644000175000017500000007532314205117452017453 0ustar fengfeng False 6 Power Statistics center-on-parent dialog True False vertical 2 True False end gtk-help True True True False False True False False 0 True gtk-close True True True False False True False False 1 True False 6 6 True True never automatic in True True False False True 0 True True True True 9 automatic automatic in True True True False Details False True False 9 9 True False 12 True False 6 True False Graph type: False 0 True False 0 True True 1 True True 0 True False 6 True False Data length: False True 0 True False 0 True True 1 True True 1 False True 0 True False True False 6 True False y-axis 90 False True 0 True False There is no data to display. True True 1 True True 0 True False x-axis False True 1 True True 1 True False 6 True Use smoothed line True True False False True False True 0 Show data points True True False False True False True 1 False True 2 1 True False History 1 False True False 9 9 True False 6 True False Graph type: False True 0 True False 0 True True 1 False True 0 True False True False 6 True False y-axis 90 False True 0 True False There is no data to display. True True 1 True True 0 True False x-axis False True 1 True True 3 1 True False 6 True Use smoothed line True True False False True False True 0 Show data points True True False False True False True 1 False True 2 2 True False Statistics 2 False True False 9 9 True False 3 True False Processor wakeups per second: False True 0 True False 0 False True 1 False True 0 True True automatic automatic in True True True True 1 3 True False Wakeups 3 False True True 1 True True 1 button_help button_close ukui-power-manager/data/99-upower-wake-up-usb-device.rules0000644000175000017500000000022514205117452022355 0ustar fengfengSUBSYSTEMS=="usb", ATTRS{product}=="*Mouse",ATTR{power/wakeup}="enabled" SUBSYSTEMS=="usb", ATTRS{product}=="*Keyboard",ATTR{power/wakeup}="enabled" ukui-power-manager/data/ukui-power-manager-tray.desktop.in.in0000644000175000017500000000064314205117452023233 0ustar fengfeng[Desktop Entry] _Name=Power Manager Tray Name[zh_CN]=电源管理程序 _Comment=Power management tray Icon=ukui-power-manager Exec=ukui-power-manager-tray Terminal=false Type=Application NoDisplay=true Categories= OnlyShowIn=UKUI; X-UKUI-Bugzilla-Bugzilla=UKUI X-UKUI-Bugzilla-Product=ukui-power-manager-tray X-UKUI-Bugzilla-Component=ukui-power-manager-tray X-UKUI-Bugzilla-Version=@VERSION@ X-UKUI-AutoRestart=true ukui-power-manager/data/ukui-power-manager.10000644000175000017500000000207414205117452017733 0ustar fengfeng.TH "UKUI-POWER-MANAGER" "1" "29 March,2006" "" "" .SH NAME ukui-power-manager \- UKUI power manager userspace daemon .SH SYNOPSIS \fBukui-power-manager\fR [ \fB\-\-verbose\fR ] [ \fB\-\-debug\fR ] [ \fB\-\-help\fR ] .SH "DESCRIPTION" \fBukui-power-manager\fR is the backend program of the UKUI power management infrastructure providing a complete and integrated solution to power management under the UKUI desktop environment. .PP It supports features such as suspending, hibernating, screen blanking, cpu frequency switching and more in one small neat package. .SH "OPTIONS" .TP \fB\-\-help\fR Show summary of options. .TP \fB\-\-verbose\fR Show extra debugging. .TP \fB\-\-no-daemon\fR Do not detach \fBukui-power-manager\fR into the background so that error messages will be displayed on console. .TP \fB\-\-debug\fR Only show specific debugging options. Useful for developers only. .SH "SEE ALSO" .PP ukui-power-preferences (1). .SH "AUTHOR" .PP This manual page was written by Oliver Grawert for the Debian system and updated by Ow Mun Heng ukui-power-manager/data/acme.ui0000644000175000017500000000213614205117452015375 0ustar fengfeng True 6 True audio-volume-high 6 0 True False False 1 ukui-power-manager/data/power-ignore.conf0000644000175000017500000000003614205117452017412 0ustar fengfeng[Login] HandlePowerKey=ignore ukui-power-manager/data/ukui-power-policy.service0000644000175000017500000000032714205117452021117 0ustar fengfeng[Unit] Description=UKUI Power Policy daemon After=upower.service [Service] Type=dbus Restart=always RestartSec=0 BusName=ukui.power.policy ExecStart=/usr/bin/ukui-power-policy [Install] WantedBy=multi-user.target ukui-power-manager/data/org.ukui.power-manager.gschema.xml.in0000644000175000017500000005000014205117452023165 0ustar fengfeng 'suspend' Whether to hibernate, suspend or do nothing when inactive The type of sleeping that should be performed when the computer is inactive. 'suspend' Battery critical low action The action to take when the battery is critically low. true If the battery event should occur when the lid is shut and the power disconnected If the battery lid close event should occur (for example 'Suspend when lid closed on battery') when the lid is previously shut and the AC power disconnected at a later time. 'suspend' Whether to hibernate, suspend or do nothing when inactive The type of sleeping that should be performed when the computer is inactive. 'shutdown' UPS critical low action The action to take when the UPS is critically low. 'hibernate' UPS low power action The action to take when the UPS is low. true Allow backlight brightness adjustment If the screen brightness should be changed when switching between AC and battery power. true Reduce the backlight brightness when on battery power If the screen should be reduced in brightness when the computer is on battery power. true Reduce the keyboard backlight when on battery power If the keyboard backlight brightness should be reduced when the computer is on battery power 100 Keyboard backlight brightness when on AC power. Percent brightness to set keyboard backlight at when on AC power. Legal values are between 0 and 100. 50 Percent to reduce keyboard backlight by when on battery power. The percentage to reduce the keyboard backlight by when on battery power. For example, if set to '60', the backlight will be cut by 40% on battery power. Legal values are between 0 and 100. 75 Percent to reduce keyboard backlight by when idle. The percentage to reduce the keyboard backlight by when idle. For example, if set to '60', the backlight will be cut by 40% when idle. Legal values are between 0 and 100. 100 The brightness of the screen when idle This is the laptop panel screen brightness used when the session is idle. Only valid when use-time-for-policy is true. true Dim the screen after a period of inactivity when on battery power If the screen should be dimmed to save power when the computer is idle when on battery power. 60 The default amount of time to dim the screen after idle The default amount of time to dim the screen after idle. 50 LCD dimming amount when on battery The amount to dim the brightness of the display when on battery power. Possible values are between 0 and 100. false Dim the screen after a period of inactivity when on AC power If the screen should be dimmed to save power when the computer is idle when on AC power. 'off' Method used to blank screen on AC The DPMS method used to blank the screen when on AC power. 'off' Method used to blank screen on battery The DPMS method used to blank the screen when on battery power. 100.0 LCD brightness when on AC The brightness of the display when on AC power. Possible values are between 0.0 and 100.0. 100.0 LCD brightness when on BAT The brightness of the display when on BAT power. Possible values are between 0.0 and 100.0. 'suspend' Suspend button action The action to take when the system suspend button is pressed. 'hibernate' Hibernate button action The action to take when the system hibernate button is pressed. 'interactive' Power button action The action to take when the system power button is pressed. 'suspend' Laptop lid close action on battery The action to take when the laptop lid is closed and the laptop is on battery power. 'suspend' Laptop lid close action when on AC The action to take when the laptop lid is closed and the laptop is on AC power. true Whether to use time-based notifications If time based notifications should be used. If set to false, then the percentage change is used instead, which may fix a broken ACPI BIOS. false Check CPU load before sleeping If the CPU load should be checked before doing the idle action. false Whether NetworkManager should be connected and disconnected on sleep. Whether NetworkManager should disconnect before suspending or hibernating and connect on resume. true Use ukui-screensaver lock setting Whether to use the screen lock setting of ukui-screensaver to decide if the screen is locked after a hibernate, suspend or blank screen. true Lock screen when blanked Whether the screen is locked when the screen is turned off. Only used if lock-use-screensaver is false. true Lock screen on suspend Whether the screen is locked when the computer wakes up from a suspend. Only used if lock-use-screensaver is false. true Lock screen on hibernate Whether the screen is locked when the computer wakes up from a hibernate. Only used if lock-use-screensaver is false. false Lock GNOME keyring on sleep Whether the GNOME keyring is locked before the computer enters suspend. This means the keyring will have to be unlocked on resume. true Lock GNOME keyring on sleep Whether the GNOME keyring is locked before the computer enters hibernate. This means the keyring will have to be unlocked on resume. true If we should show the low capacity warning for a broken battery If we should show the low capacity warning for a broken battery. true Notify when AC adapter is disconnected If the user should be notified when the AC adapter is disconnected. false Notify when fully charged If a notification message should be displayed when the battery is fully charged. true Notify on a sleep failure If a notification message should be displayed after suspend or hibernate failed. '' The URI to show to the user on sleep failure When sleep fails we can show the user a button to help fix the situation. Leave this blank if the button should not be shown. true Notify on a low power If a notification message should be displayed when the battery is getting low. true Whether we should show the history data points Whether we should show the history data points in the statistics window. true Whether we should smooth the history data Whether we should smooth the history data in the graph. 'power' The default graph type to show for history The default graph type to show in the history window. 21600 The maximum time displayed for history The maximum duration of time displayed on the x-axis of the history graph. true Whether we should show the stats data points Whether we should show the stats data points in the statistics window. true Whether we should smooth the stats data Whether we should smooth the stats data in the graph. 'power' The default graph type to show for stats The default graph type to show in the stats window. 0 The index of the page number to show by default The index of the page number to show by default which is used to return focus to the correct page. '' The ID of the last device selected The identifier of the last device which is used to return focus to the correct device. 20 Percentage considered low The percentage of the battery when it is considered low. Only valid when use-time-for-policy is false. 10 Percentage considered critical The percentage of the battery when it is considered critical. Only valid when use-time-for-policy is false. 5 Percentage action is taken The percentage of the battery when the critical action is performed. Only valid when use-time-for-policy is false. 1200 The time remaining when low The time remaining in seconds of the battery when it is considered low. Only valid when use-time-for-policy is true. 300 The time remaining when critical The time remaining in seconds of the battery when it is considered critical. Only valid when use-time-for-policy is true. 120 The time remaining when action is taken The time remaining in seconds of the battery when critical action is taken. Only valid when use-time-for-policy is true. 900 Sleep timeout computer when on battery The amount of time in seconds the computer on battery power needs to be inactive before it goes to sleep. 900 Sleep timeout computer when on AC The amount of time in seconds the computer on AC power needs to be inactive before it goes to sleep. 0 Sleep timeout computer when on UPS The amount of time in seconds the computer on UPS power needs to be inactive before it goes to sleep. 600 Sleep timeout display when on AC The amount of time in seconds before the display goes to sleep when the computer is on AC power. 600 Sleep timeout display when on battery The amount of time in seconds the computer on battery power needs to be inactive before the display goes to sleep. 600 Sleep timeout display when on UPS The amount of time in seconds the computer on UPS power needs to be inactive before the display goes to sleep. true If sounds should be used If sounds should be used when the power is critically low, or inhibit requests have stopped the policy action. true If preferences and statistics items should be shown in the context menu false If power policy mode should be auto switched when plugged in and out false If power policy mode should be auto switched when plugged in and out 2 power policy mode 1 power policy current 2 power policy current 1 power policy current 1 power policy current 1 power policy current 1 power policy current 'present' When to show the notification icon Display options for the notification icon. ukui-power-manager/data/ukui-power-manager0000644000175000017500000000016514205117452017573 0ustar fengfeng/tmp/ukui-power-manager.log { daily rotate 7 compress notifempty maxsize 10M copytruncate } ukui-power-manager/data/ukui-power-preferences.10000644000175000017500000000106114205117452020615 0ustar fengfeng.TH "UKUI-POWER-PREFERENCES" "1" "11 July, 2005" "" "" .SH NAME ukui-power-preferences \- UKUI power preferences GUI .SH SYNOPSIS \fBukui-power-preferences\fR [ \fB\-\-verbose\fR ] [ \fB\-\-help\fR ] .SH "DESCRIPTION" \fBukui-power-preferences\fR is the gui program for the ukui power management infrastructure .SH "OPTIONS" .TP \fB\-\-help\fR Show summary of options. .TP \fB\-\-verbose\fR Show extra debugging. .SH "SEE ALSO" .PP ukui-power-manager (1). .SH "AUTHOR" .PP This manual page was written by Oliver Grawert for the Debian system. ukui-power-manager/data/Makefile.am0000644000175000017500000000323414205117452016165 0ustar fengfeng#SUBDIRS = icons @INTLTOOL_DESKTOP_RULE@ desktopdir = $(datadir)/applications desktop_in_files = ukui-power-preferences.desktop.in \ ukui-power-statistics.desktop.in desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) @INTLTOOL_DESKTOP_RULE@ autostartdir = $(sysconfdir)/xdg/autostart autostart_in_files = ukui-power-manager.desktop.in \ ukui-power-manager-tray.desktop.in autostart_DATA = $(autostart_in_files:.desktop.in=.desktop) servicedir = $(DBUS_SERVICES_DIR) service_in_files = org.ukui.PowerManager.service.in service_DATA = $(service_in_files:.service.in=.service) $(service_DATA): $(service_in_files) Makefile @sed -e "s|\@servicedir\@|$(bindir)|" $< > $@ @GSETTINGS_RULES@ @INTLTOOL_XML_NOMERGE_RULE@ gsettings_schemas_in_files = org.ukui.power-manager.gschema.xml.in gsettings_SCHEMAS = $(gsettings_schemas_in_files:.xml.in=.xml) #kobe #confdir = $(sysconfdir)/polkit-1/localauthority/50-local.d #conf_DATA = com.ubuntu.enable-hibernate.pkla pkgdata_DATA = \ gpm-statistics.ui \ gpm-feedback-widget.ui \ gpm-prefs.ui \ acme.ui man_MANS = \ ukui-power-manager.1 \ ukui-power-manager-tray.1 \ ukui-power-backlight-helper.1 \ ukui-power-statistics.1 \ ukui-power-preferences.1 EXTRA_DIST = \ $(service_in_files) \ $(autostart_in_files) \ $(desktop_in_files) \ $(gsettings_schemas_in_files) \ $(pkgdata_DATA) \ $(man_MANS) # $(conf_DATA) clean-local : rm -f *~ DISTCLEANFILES = \ ukui-power-manager.desktop \ ukui-power-manager-tray.desktop \ ukui-power-preferences.desktop \ ukui-power-statistics.desktop \ org.ukui.PowerManager.service \ $(gsettings_SCHEMAS) ukui-power-manager/data/ukui-power-manager.desktop.in.in0000644000175000017500000000054014205117452022252 0ustar fengfeng[Desktop Entry] _Name=Power Manager _Comment=Power management daemon Icon=ukui-power-manager Exec= Terminal=false Type=Application NoDisplay=true Categories= OnlyShowIn=UKUI; X-UKUI-Bugzilla-Bugzilla=UKUI X-UKUI-Bugzilla-Product=ukui-power-manager X-UKUI-Bugzilla-Component=ukui-power-manager X-UKUI-Bugzilla-Version=@VERSION@ X-UKUI-AutoRestart=true ukui-power-manager/data/ukui-power-statistics.10000644000175000017500000000120314205117452020504 0ustar fengfeng.TH "UKUI-POWER-STATISTICS" "1" "11 December, 2007" "" "" .SH NAME ukui-power-statistics \- UKUI power statistics GUI .SH SYNOPSIS \fBukui-power-statistics\fR [ \fB\-\-verbose\fR ] [ \fB\-\-help\fR ] .SH "DESCRIPTION" \fBukui-power-statistics\fR is the gui program for the ukui power management infrastructure. .PP It allows users to visualize the power consumption of laptop hardware. .SH "OPTIONS" .TP \fB\-\-help\fR Show summary of options. .TP \fB\-\-verbose\fR Show extra debugging. .SH "SEE ALSO" .PP ukui-power-manager (1), ukui-power-preferences (1). .SH "AUTHOR" .PP This manual page was written by Simon Zheng . ukui-power-manager/data/ukui-power-backlight-helper.10000644000175000017500000000201014205117452021514 0ustar fengfeng.TH "UKUI-POWER-BACKLIGHT-HELPER" "1" "21 April, 2014" "" "" .SH NAME ukui-power-backlight-helper \- helper application for UKUI's power management backlight control .SH SYNOPSIS \fBukui-power-backlight-helper\fR [ \fB\-\-help\fR ] [ \fB\-\-set-brightness\fR ] [ \fB\-\-get-brightness\fR ] [ \fB\-\-get-max-brightness\fR ] .SH "DESCRIPTION" \fBukui-power-backlight-helper\fR is a helper utility for controlling the backlight of TFT displays via the UKUI power manager userspace daemon. .PP The \fBukui-power-backlight-helper\fR requires to be run with root privileges. .SH "OPTIONS" .TP \fB\-\-help\fR Show summary of options. .TP \fB\-\-set-brightness BRIGHTNESS_LEVEL\fR Set the given brightness. .TP \fB\-\-get-brightness\fR Get the current brightness. .TP \fB\-\-get-max-brightness\fR Get the number of brightness levels supported. .SH "SEE ALSO" .PP ukui-power-manager (1). .SH "AUTHOR" .PP This manual page has been written by Mike Gabriel for the Debian system (but may be used by others). ukui-power-manager/data/ukui-power-preferences.desktop.in.in0000644000175000017500000000067214205117452023147 0ustar fengfeng[Desktop Entry] _Name=Power Management _Comment=Configure power management Icon=ukui-power-manager Exec=ukui-power-preferences Terminal=false Type=Application Categories=Settings;HardwareSettings; Keywords=UKUI;power;management;preferences;settings; OnlyShowIn=UKUI; StartupNotify=true X-UKUI-Bugzilla-Bugzilla=UKUI X-UKUI-Bugzilla-Product=ukui-power-manager X-UKUI-Bugzilla-Component=ukui-power-preferences X-UKUI-Bugzilla-Version=@VERSION@ ukui-power-manager/COPYING0000644000175000017500000010451314205117452014255 0ustar fengfeng GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 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, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ukui-power-manager/powermanagement.pro0000644000175000017500000000023014205117452017124 0ustar fengfengTEMPLATE = subdirs CONFIG += ordered SUBDIRS = \ registeredQDbus \ PowerManagementDaemon \ ukui-power-manager-tray \ ukui-upower \ ukui-power-manager/ukui-upower/0000755000175000017500000000000014205117543015513 5ustar fengfengukui-power-manager/ukui-upower/dbus-ukuipower.h0000644000175000017500000000565714205117452020665 0ustar fengfeng/* * Copyright (C) 2020 The Qt Company Ltd. * Copyright (C) 2021 KylinSoft 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 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, see . */ #ifndef DBUS-UKUIPOWER_H #define DBUS-UKUIPOWER_H #include #include #include "dbus.h" QT_BEGIN_NAMESPACE class QByteArray; template class QList; template class QMap; class QString; class QStringList; class QVariant; QT_END_NAMESPACE /* * Adaptor class for interface org.ukui.upower */ class UpowerAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ukui.upower") Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") public: UpowerAdaptor(QObject *parent); virtual ~UpowerAdaptor(); public: // PROPERTIES public Q_SLOTS: // METHODS QString CanHibernate(); QString DaemonVersion(); QString IconName(); bool IsPresent(); bool LowBattery(); QString MachineType(); bool OnBattery(); double Percentage(); int State(); int TimeToEmpty(); int TimeToFull(); QString UPowerVersion(); Q_SIGNALS: // SIGNALS }; #endif ukui-power-manager/ukui-upower/ukui-upower.pro0000644000175000017500000000221514205117452020530 0ustar fengfeng#------------------------------------------------- # # Project created by QtCreator 2019-06-29T11:18:10 # #------------------------------------------------- QT += core gui dbus greaterThan(QT_MAJOR_VERSION, 4):QT += widgets TARGET = ukui-upower TEMPLATE = app CONFIG += c++11 link_pkgconfig PKGCONFIG += gsettings-qt SOURCES += main.cpp\ batteryinfo/batteryinfo.cpp \ upowerinfo/upowerinfo.cpp \ dbus.cpp \ dbus-ukuipower.cpp HEADERS += batteryinfo/batteryinfo.h \ common/common.h \ dbus.h \ dbus-ukuipower.h \ upowerinfo/upowerinfo.h # Default rules for deployment. qnx: target.path = /tmp/usr/bin else: unix:!android: target.path = /usr/bin !isEmpty(target.path): INSTALLS += target desktop.files += resources/ukui-upower.desktop desktop.path = /etc/xdg/autostart/ INSTALLS += desktop xorg.files += resources/10-monitor.conf xorg.path = /usr/share/X11/xorg.conf.d/ INSTALLS += xorg conf.files += resources/org.ukui.power-manager.gschema.xml conf.path=/usr/share/glib-2.0/schemas/ INSTALLS += conf rules.files += resources/99-upower-wake-up-usb-device.rules rules.path = /usr/lib/udev/rules.d/ INSTALLS += rules ukui-power-manager/ukui-upower/dbus-ukuipower.cpp0000644000175000017500000000716414205117452021213 0ustar fengfeng/* * Copyright (C) 2020 The Qt Company Ltd. * Copyright (C) 2021 KylinSoft 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 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, see . */ #include "dbus-ukuipower.h" #include #include #include #include #include #include #include /* * Implementation of adaptor class UpowerAdaptor */ UpowerAdaptor::UpowerAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) { // constructor setAutoRelaySignals(true); } UpowerAdaptor::~UpowerAdaptor() { // destructor } QString UpowerAdaptor::CanHibernate() { // handle method call org.ukui.upower.CanHibernate QString out0; QMetaObject::invokeMethod(parent(), "CanHibernate", Q_RETURN_ARG(QString, out0)); return out0; } QString UpowerAdaptor::DaemonVersion() { // handle method call org.ukui.upower.DaemonVersion QString out0; QMetaObject::invokeMethod(parent(), "DaemonVersion", Q_RETURN_ARG(QString, out0)); return out0; } QString UpowerAdaptor::IconName() { // handle method call org.ukui.upower.IconName QString out0; QMetaObject::invokeMethod(parent(), "IconName", Q_RETURN_ARG(QString, out0)); return out0; } bool UpowerAdaptor::IsPresent() { // handle method call org.ukui.upower.IsPresent bool out0; QMetaObject::invokeMethod(parent(), "IsPresent", Q_RETURN_ARG(bool, out0)); return out0; } bool UpowerAdaptor::LowBattery() { // handle method call org.ukui.upower.LowBattery bool out0; QMetaObject::invokeMethod(parent(), "LowBattery", Q_RETURN_ARG(bool, out0)); return out0; } QString UpowerAdaptor::MachineType() { // handle method call org.ukui.upower.MachineType QString out0; QMetaObject::invokeMethod(parent(), "MachineType", Q_RETURN_ARG(QString, out0)); return out0; } bool UpowerAdaptor::OnBattery() { // handle method call org.ukui.upower.OnBattery bool out0; QMetaObject::invokeMethod(parent(), "OnBattery", Q_RETURN_ARG(bool, out0)); return out0; } double UpowerAdaptor::Percentage() { // handle method call org.ukui.upower.Percentage double out0; QMetaObject::invokeMethod(parent(), "Percentage", Q_RETURN_ARG(double, out0)); return out0; } int UpowerAdaptor::State() { // handle method call org.ukui.upower.State int out0; QMetaObject::invokeMethod(parent(), "State", Q_RETURN_ARG(int, out0)); return out0; } int UpowerAdaptor::TimeToEmpty() { // handle method call org.ukui.upower.TimeToEmpty int out0; QMetaObject::invokeMethod(parent(), "TimeToEmpty", Q_RETURN_ARG(int, out0)); return out0; } int UpowerAdaptor::TimeToFull() { // handle method call org.ukui.upower.TimeToFull int out0; QMetaObject::invokeMethod(parent(), "TimeToFull", Q_RETURN_ARG(int, out0)); return out0; } QString UpowerAdaptor::UPowerVersion() { // handle method call org.ukui.upower.UPowerVersion QString out0; QMetaObject::invokeMethod(parent(), "UPowerVersion", Q_RETURN_ARG(QString, out0)); return out0; } ukui-power-manager/ukui-upower/dbus.h0000644000175000017500000000600514205117452016621 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef DBUS_H #define DBUS_H #include "upowerinfo/upowerinfo.h" #include "batteryinfo/batteryinfo.h" #include #include class DBus : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface","org.ukui.upower") public: explicit DBus(QObject *parent = 0); ~DBus(); public slots: /** * @brief UPowerVersion * ukui-upower版本 * @return */ QString UPowerVersion(void); /** * @brief CanHibernate * @return * 是否可以休眠的接口 * 或可直接调用login1 的 * 重新封装的意义在于可以针对部分机型做特殊处理 * 并且可以 */ QString CanHibernate(void); /** * @brief MachineType * @return * 机器类型判断 */ QString MachineType(); /** * @brief OnBattery * AC状态还是DC状态 * @return */ bool OnBattery(); /** * @brief DaemonVersion * 判断upower版本 * @return */ QString DaemonVersion(); /** * @brief IconName * @return * 图标名称 */ QString IconName(); /** * @brief Percentage * @return * 电量百分比 */ double Percentage(); /** * @brief TimeToFull * @return * 充电过程中,还有多久充满电 */ int TimeToFull(); /** * @brief TimeToEmpty * @return * 放电过程 还有多久耗尽 */ int TimeToEmpty(); /** * @brief IsPresent * 电池是否存在 * @return */ bool IsPresent(); /** * @brief State * @return */ int State(); /** * @brief LowBattery * 低电量 * @return */ bool LowBattery(); signals: /** * @brief lowBatteryState * @return * 低电量状态信号 */ void LowBatteryState(bool); /** * @brief VeryLowBatteryState */ void VeryLowBatteryState(bool); /** * @brief PowerState */ void PowerState(bool); /** * @brief LidState */ void LidState(bool); void BatteryIcon(QString); private: UPowerInfo *upowerinfo; BatteryInfo *batteryinfo; void dealPowerState(bool); void dealLidState(bool); void dealLowBattery(bool); void dealVeryLowBattery(bool); void dealBatteryIcon(QString); }; #endif // DBUS_H ukui-power-manager/ukui-upower/client/0000755000175000017500000000000014205117543016771 5ustar fengfengukui-power-manager/ukui-upower/client/Readme.md0000644000175000017500000000105514205117543020511 0ustar fengfeng关于QDBusInterface QDBusReply的调用 有更多其他调用方式 例如在调用statusnotifier插件的每个应用的dbus时候 void Widget::on_pushButton_clicked() { QDBusInterface iface("org.kde.StatusNotifierItem-2255-1", "/StatusNotifierItem", "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus()); QDBusReply reply=iface.call("Get","org.kde.StatusNotifierItem","Id"); qDebug()<<"reply Id is : "<. */ #ifndef WIDGET_H #define WIDGET_H #include namespace Ui { class Widget; } class Widget : public QWidget { Q_OBJECT public: explicit Widget(QWidget *parent = 0); ~Widget(); private slots: void on_pushButton_clicked(); private: Ui::Widget *ui; }; #endif // WIDGET_H ukui-power-manager/ukui-upower/client/widget.ui0000644000175000017500000000127714205117543020622 0ustar fengfeng Widget 0 0 400 300 Widget 140 100 97 26 PushButton ukui-power-manager/ukui-upower/client/widget.cpp0000644000175000017500000000240214205117543020756 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "widget.h" #include "ui_widget.h" #include #include #include Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); this->setWindowTitle("客户端"); } Widget::~Widget() { delete ui; } void Widget::on_pushButton_clicked() { QDBusInterface iface("org.ukui.power", "/", "org.ukui.power", QDBusConnection::sessionBus()); QDBusReply reply=iface.call("UPowerVersion"); qDebug()<. */ #include "widget.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); } ukui-power-manager/ukui-upower/client/client.pro0000644000175000017500000000054014205117543020770 0ustar fengfeng#------------------------------------------------- # # Project created by QtCreator 2019-06-29T14:06:51 # #------------------------------------------------- QT += core gui dbus greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = client TEMPLATE = app SOURCES += main.cpp\ widget.cpp HEADERS += widget.h FORMS += widget.ui ukui-power-manager/ukui-upower/client/client.pro.user0000644000175000017500000005322214205117543021752 0ustar fengfeng EnvironmentId {5d27143b-51c0-48ec-aa98-3f10b663d06b} ProjectExplorer.Project.ActiveTarget 0 ProjectExplorer.Project.EditorSettings true false true Cpp CppGlobal QmlJS QmlJSGlobal 2 UTF-8 false 4 false 80 true true 1 true false 0 true true 0 8 true 1 true true true false ProjectExplorer.Project.PluginSettings ProjectExplorer.Project.Target.0 桌面 桌面 {50802bd0-2c38-4740-be3c-32c9215a3401} 0 0 0 /home/kylin/ukui/power/ukui-upower/interface/build-client-unknown-Debug true QtProjectManager.QMakeBuildStep true false false false true Qt4ProjectManager.MakeStep false false 2 Build Build ProjectExplorer.BuildSteps.Build true Qt4ProjectManager.MakeStep true clean false 1 Clean Clean ProjectExplorer.BuildSteps.Clean 2 false Debug Qt4ProjectManager.Qt4BuildConfiguration 2 /home/kylin/ukui/power/ukui-upower/interface/build-client-unknown-Release true QtProjectManager.QMakeBuildStep false false false true true Qt4ProjectManager.MakeStep false false 2 Build Build ProjectExplorer.BuildSteps.Build true Qt4ProjectManager.MakeStep true clean false 1 Clean Clean ProjectExplorer.BuildSteps.Clean 2 false Release Qt4ProjectManager.Qt4BuildConfiguration 0 /home/kylin/ukui/power/ukui-upower/interface/build-client-unknown-Profile true QtProjectManager.QMakeBuildStep true false true true true Qt4ProjectManager.MakeStep false false 2 Build Build ProjectExplorer.BuildSteps.Build true Qt4ProjectManager.MakeStep true clean false 1 Clean Clean ProjectExplorer.BuildSteps.Clean 2 false Profile Qt4ProjectManager.Qt4BuildConfiguration 0 3 0 Deploy Deploy ProjectExplorer.BuildSteps.Deploy 1 ProjectExplorer.DefaultDeployConfiguration 1 dwarf cpu-cycles 250 -e cpu-cycles --call-graph dwarf,4096 -F 250 -F true 4096 false false 1000 true false false false false true 0.01 10 true kcachegrind 1 25 1 true false true valgrind 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 Qt4ProjectManager.Qt4RunConfiguration:/home/kylin/ukui/power/ukui-upower/interface/client/client.pro /home/kylin/ukui/power/ukui-upower/interface/client/client.pro false false true true false false true /home/kylin/ukui/power/ukui-upower/interface/build-client-unknown-Debug 1 ProjectExplorer.Project.TargetCount 1 ProjectExplorer.Project.Updater.FileVersion 22 Version 22 ukui-power-manager/ukui-upower/common/0000755000175000017500000000000014205117452017002 5ustar fengfengukui-power-manager/ukui-upower/common/common.h0000644000175000017500000000226514205117452020450 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef COMMON_H #define COMMON_H #define FREEDESKTOP_UPOWER "org.freedesktop.DBus.Properties" #define UPOWER_INTERFACE "org.freedesktop.UPower" #define UPOWER_PATH "/org/freedesktop/UPower" #define UPOWER_SERVICE "org.freedesktop.UPower" #define UPOWER_DISPLAY_PATH "/org/freedesktop/UPower/devices/DisplayDevice" #define UPOWER_DIVICES_SERVICE "org.freedesktop.UPower.Device" #endif // COMMON_H ukui-power-manager/ukui-upower/dbus.cpp0000644000175000017500000000554214205117452017161 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "dbus.h" #define FREEDESKTOP_UPOWER "org.freedesktop.DBus.Properties" #define UPOWER_PATH "/org/freedesktop/UPower" #define UPOWER_SERVICE "org.freedesktop.UPower" #define UPOWER_DISPLAY_PATH "/org/freedesktop/UPower/devices/DisplayDevice" DBus::DBus(QObject *parent) : QObject(parent) { upowerinfo = new UPowerInfo; upowerinfo->initUpowerInfo(); batteryinfo = new BatteryInfo; connect(upowerinfo,&UPowerInfo::acChanged,this,&DBus::dealPowerState); connect(upowerinfo,&UPowerInfo::lidChanged,this,&DBus::dealLidState); connect(batteryinfo,&BatteryInfo::LowBatteryChanged,this,&DBus::dealLowBattery); connect(batteryinfo,&BatteryInfo::VeryLowBatteryChanged,this,&DBus::dealVeryLowBattery); connect(batteryinfo,&BatteryInfo::BatteryIconChanged,this,&DBus::dealBatteryIcon); } DBus::~DBus() { delete upowerinfo; delete batteryinfo; } QString DBus::UPowerVersion() { return "3.1"; } QString DBus::CanHibernate() { return upowerinfo->CanHibernate(); } QString DBus::MachineType() { return upowerinfo->MachineType(); } bool DBus::OnBattery() { return upowerinfo->OnBattery(); } QString DBus::DaemonVersion() { return upowerinfo->DaemonVersion(); } //***************************************** /******************************************/ QString DBus::IconName() { return batteryinfo->IconName(); } double DBus::Percentage() { return batteryinfo->Percentage(); } int DBus::TimeToFull() { return batteryinfo->TimeToFull(); } int DBus::TimeToEmpty() { return batteryinfo->TimeToEmpty(); } bool DBus::IsPresent() { return batteryinfo->IsPresent(); } int DBus::State() { int i=1; return i; } bool DBus::LowBattery() { return batteryinfo->LowBatteryState(); } void DBus::dealPowerState(bool state) { emit PowerState(state); } void DBus::dealLidState(bool state) { emit LidState(state); } void DBus::dealLowBattery(bool state) { emit LowBatteryState(state); } void DBus::dealVeryLowBattery(bool state) { emit VeryLowBatteryState(state); } void DBus::dealBatteryIcon(QString msg) { emit BatteryIcon(msg); } ukui-power-manager/ukui-upower/upowerinfo/0000755000175000017500000000000014205117452017707 5ustar fengfengukui-power-manager/ukui-upower/upowerinfo/upowerinfo.h0000644000175000017500000000405414205117452022260 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef UPOWERINFO_H #define UPOWERINFO_H #include #include #include #include "../common/common.h" class UPowerInfo : public QObject { Q_OBJECT public: explicit UPowerInfo(QObject *parent = nullptr); ~UPowerInfo(); /** * @brief initUpowerInfo * 电池信息初始化 */ void initUpowerInfo(); /** * @brief UPowerVersion * @return * UPower版本 */ QString UPowerVersion(void); /** * @brief CanHibernate * @return * 是否可以休眠的接口 * 或可直接调用login1 的 * 重新封装的意义在于可以针对部分机型做特殊处理 * 并且可以 */ QString CanHibernate(void); /** * @brief MachineType * @return * 机器类型判断 */ QString MachineType(); bool OnBattery(); bool LidIsClosed(); QString DaemonVersion(); QString getBatteryPath(); private slots: void dealMessage(QDBusMessage); private: void dealPowerMessage(bool); void dealLidMessage(bool); QDBusInterface *iface; bool mOnBattery; bool mLidIsClosed; signals: /** * @brief acChanged * 电源状态改变信号 */ void acChanged(bool ); /** * @brief acChanged * 合盖状态改变信号 */ void lidChanged(bool ); }; #endif // UPOWERINFO_H ukui-power-manager/ukui-upower/upowerinfo/upowerinfo.cpp0000644000175000017500000001167314205117452022620 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "upowerinfo.h" UPowerInfo::UPowerInfo(QObject *parent) : QObject(parent) { iface = new QDBusInterface(UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); } UPowerInfo::~UPowerInfo() { delete iface; } void UPowerInfo::initUpowerInfo() { QDBusConnection::systemBus().connect( UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(dealMessage(QDBusMessage))); mOnBattery = OnBattery(); mLidIsClosed = LidIsClosed(); } QString UPowerInfo::UPowerVersion() { return "3.1"; } QString UPowerInfo::CanHibernate() { QDBusInterface interface( "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()); if (!interface.isValid()) { qCritical() << QDBusConnection::sessionBus().lastError().message(); } /*调用远程的 CanHibernate 方法,判断是否可以执行休眠的操作,返回值为yes为允许执行休眠,no为无法执行休眠 * na为交换分区不足*/ QDBusReply reply = interface.call("CanHibernate"); if (reply.isValid()) { return reply.value(); } else { return "Call Dbus method failed"; } } QString UPowerInfo::MachineType() { QDBusReply reply = iface->call("Get", UPOWER_SERVICE, "LidIsPresent"); if (reply.isValid()) { if (true == reply.value().toBool()) { return "book"; } else { return "pc"; } } else { qDebug() << "Get lid is present failed"; return "Get lid is present failed"; } } bool UPowerInfo::OnBattery() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get", UPOWER_SERVICE, "OnBattery"); if (reply.isValid()) { return reply.value().toBool(); } else { qDebug() << "Get on battery failed"; return false; } } bool UPowerInfo::LidIsClosed() { QDBusReply reply = iface->call("Get", UPOWER_SERVICE, "LidIsClosed"); if (reply.isValid()) { return reply.value().toBool(); } else { qDebug() << "Get lid is close failed"; return false; } } QString UPowerInfo::DaemonVersion() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get", UPOWER_SERVICE, "DaemonVersion"); if (reply.isValid()) { return reply.value().toString(); } else { qDebug() << "Get version failed"; return "Get version failed!"; } } QString UPowerInfo::getBatteryPath() { QString batteryPath = ""; QDBusInterface dface(UPOWER_SERVICE, UPOWER_PATH, UPOWER_INTERFACE, QDBusConnection::systemBus()); QDBusReply> reply = dface.call("EnumerateDevices"); if (dface.isValid()) { for (QDBusObjectPath op : reply.value()) { if (op.path().contains("battery_")) { batteryPath = op.path(); break; } } } else { qDebug() << "Enumerate devices failed"; } return batteryPath; } void UPowerInfo::dealMessage(QDBusMessage msg) { QString key; QVariant value; QList outArgs = msg.arguments(); QVariant upowerDate = outArgs.at(1); const QDBusArgument &dbusArgs = upowerDate.value(); dbusArgs.beginMap(); while (!dbusArgs.atEnd()) { dbusArgs.beginMapEntry(); dbusArgs >> key >> value; dbusArgs.endMapEntry(); } dbusArgs.endMap(); if ("LidIsClosed" == key) { dealLidMessage(value.toBool()); } else if ("OnBattery" == key) { dealPowerMessage(value.toBool()); } else { qDebug() << "Upower message get failed"; } } void UPowerInfo::dealPowerMessage(bool value) { if (mOnBattery != value) { mOnBattery = value; emit acChanged(mOnBattery); } } void UPowerInfo::dealLidMessage(bool value) { if (mLidIsClosed != value) { mLidIsClosed = value; emit lidChanged(mLidIsClosed); } } ukui-power-manager/ukui-upower/resources/0000755000175000017500000000000014205117543017525 5ustar fengfengukui-power-manager/ukui-upower/resources/10-monitor.conf0000644000175000017500000000020414205117452022274 0ustar fengfengSection "ServerFlags" option "StandbyTime" "0" option "SuspendTime" "0" option "OffTime" "0" option "BlankTime" "0" EndSection ukui-power-manager/ukui-upower/resources/org.ukui.power-manager.gschema.xml0000644000175000017500000005000014205117543026156 0ustar fengfeng 'suspend' Whether to hibernate, suspend or do nothing when inactive The type of sleeping that should be performed when the computer is inactive. 'suspend' Battery critical low action The action to take when the battery is critically low. true If the battery event should occur when the lid is shut and the power disconnected If the battery lid close event should occur (for example 'Suspend when lid closed on battery') when the lid is previously shut and the AC power disconnected at a later time. 'suspend' Whether to hibernate, suspend or do nothing when inactive The type of sleeping that should be performed when the computer is inactive. 'shutdown' UPS critical low action The action to take when the UPS is critically low. 'hibernate' UPS low power action The action to take when the UPS is low. true Allow backlight brightness adjustment If the screen brightness should be changed when switching between AC and battery power. true Reduce the backlight brightness when on battery power If the screen should be reduced in brightness when the computer is on battery power. true Reduce the keyboard backlight when on battery power If the keyboard backlight brightness should be reduced when the computer is on battery power 100 Keyboard backlight brightness when on AC power. Percent brightness to set keyboard backlight at when on AC power. Legal values are between 0 and 100. 50 Percent to reduce keyboard backlight by when on battery power. The percentage to reduce the keyboard backlight by when on battery power. For example, if set to '60', the backlight will be cut by 40% on battery power. Legal values are between 0 and 100. 75 Percent to reduce keyboard backlight by when idle. The percentage to reduce the keyboard backlight by when idle. For example, if set to '60', the backlight will be cut by 40% when idle. Legal values are between 0 and 100. 100 The brightness of the screen when idle This is the laptop panel screen brightness used when the session is idle. Only valid when use-time-for-policy is true. true Dim the screen after a period of inactivity when on battery power If the screen should be dimmed to save power when the computer is idle when on battery power. 60 The default amount of time to dim the screen after idle The default amount of time to dim the screen after idle. 50 LCD dimming amount when on battery The amount to dim the brightness of the display when on battery power. Possible values are between 0 and 100. false Dim the screen after a period of inactivity when on AC power If the screen should be dimmed to save power when the computer is idle when on AC power. 'off' Method used to blank screen on AC The DPMS method used to blank the screen when on AC power. 'off' Method used to blank screen on battery The DPMS method used to blank the screen when on battery power. 100.0 LCD brightness when on AC The brightness of the display when on AC power. Possible values are between 0.0 and 100.0. 100.0 LCD brightness when on BAT The brightness of the display when on BAT power. Possible values are between 0.0 and 100.0. 'suspend' Suspend button action The action to take when the system suspend button is pressed. 'hibernate' Hibernate button action The action to take when the system hibernate button is pressed. 'interactive' Power button action The action to take when the system power button is pressed. 'suspend' Laptop lid close action on battery The action to take when the laptop lid is closed and the laptop is on battery power. 'suspend' Laptop lid close action when on AC The action to take when the laptop lid is closed and the laptop is on AC power. true Whether to use time-based notifications If time based notifications should be used. If set to false, then the percentage change is used instead, which may fix a broken ACPI BIOS. false Check CPU load before sleeping If the CPU load should be checked before doing the idle action. false Whether NetworkManager should be connected and disconnected on sleep. Whether NetworkManager should disconnect before suspending or hibernating and connect on resume. true Use ukui-screensaver lock setting Whether to use the screen lock setting of ukui-screensaver to decide if the screen is locked after a hibernate, suspend or blank screen. true Lock screen when blanked Whether the screen is locked when the screen is turned off. Only used if lock-use-screensaver is false. true Lock screen on suspend Whether the screen is locked when the computer wakes up from a suspend. Only used if lock-use-screensaver is false. true Lock screen on hibernate Whether the screen is locked when the computer wakes up from a hibernate. Only used if lock-use-screensaver is false. false Lock GNOME keyring on sleep Whether the GNOME keyring is locked before the computer enters suspend. This means the keyring will have to be unlocked on resume. true Lock GNOME keyring on sleep Whether the GNOME keyring is locked before the computer enters hibernate. This means the keyring will have to be unlocked on resume. true If we should show the low capacity warning for a broken battery If we should show the low capacity warning for a broken battery. true Notify when AC adapter is disconnected If the user should be notified when the AC adapter is disconnected. false Notify when fully charged If a notification message should be displayed when the battery is fully charged. true Notify on a sleep failure If a notification message should be displayed after suspend or hibernate failed. '' The URI to show to the user on sleep failure When sleep fails we can show the user a button to help fix the situation. Leave this blank if the button should not be shown. true Notify on a low power If a notification message should be displayed when the battery is getting low. true Whether we should show the history data points Whether we should show the history data points in the statistics window. true Whether we should smooth the history data Whether we should smooth the history data in the graph. 'power' The default graph type to show for history The default graph type to show in the history window. 21600 The maximum time displayed for history The maximum duration of time displayed on the x-axis of the history graph. true Whether we should show the stats data points Whether we should show the stats data points in the statistics window. true Whether we should smooth the stats data Whether we should smooth the stats data in the graph. 'power' The default graph type to show for stats The default graph type to show in the stats window. 0 The index of the page number to show by default The index of the page number to show by default which is used to return focus to the correct page. '' The ID of the last device selected The identifier of the last device which is used to return focus to the correct device. 20 Percentage considered low The percentage of the battery when it is considered low. Only valid when use-time-for-policy is false. 10 Percentage considered critical The percentage of the battery when it is considered critical. Only valid when use-time-for-policy is false. 5 Percentage action is taken The percentage of the battery when the critical action is performed. Only valid when use-time-for-policy is false. 1200 The time remaining when low The time remaining in seconds of the battery when it is considered low. Only valid when use-time-for-policy is true. 300 The time remaining when critical The time remaining in seconds of the battery when it is considered critical. Only valid when use-time-for-policy is true. 120 The time remaining when action is taken The time remaining in seconds of the battery when critical action is taken. Only valid when use-time-for-policy is true. 900 Sleep timeout computer when on battery The amount of time in seconds the computer on battery power needs to be inactive before it goes to sleep. 900 Sleep timeout computer when on AC The amount of time in seconds the computer on AC power needs to be inactive before it goes to sleep. 0 Sleep timeout computer when on UPS The amount of time in seconds the computer on UPS power needs to be inactive before it goes to sleep. 600 Sleep timeout display when on AC The amount of time in seconds before the display goes to sleep when the computer is on AC power. 600 Sleep timeout display when on battery The amount of time in seconds the computer on battery power needs to be inactive before the display goes to sleep. 600 Sleep timeout display when on UPS The amount of time in seconds the computer on UPS power needs to be inactive before the display goes to sleep. true If sounds should be used If sounds should be used when the power is critically low, or inhibit requests have stopped the policy action. true If preferences and statistics items should be shown in the context menu false If power policy mode should be auto switched when plugged in and out false If power policy mode should be auto switched when plugged in and out 2 power policy mode 1 power policy current 2 power policy current 1 power policy current 1 power policy current 1 power policy current 1 power policy current 'present' When to show the notification icon Display options for the notification icon. ukui-power-manager/ukui-upower/resources/99-upower-wake-up-usb-device.rules0000644000175000017500000000022514205117452025752 0ustar fengfengSUBSYSTEMS=="usb", ATTRS{product}=="*Mouse",ATTR{power/wakeup}="enabled" SUBSYSTEMS=="usb", ATTRS{product}=="*Keyboard",ATTR{power/wakeup}="enabled" ukui-power-manager/ukui-upower/resources/ukui-upower.desktop0000644000175000017500000000025714205117452023417 0ustar fengfeng[Desktop Entry] Name=Ukui-Upower Icon=ukui-power-manager Exec=ukui-upower Terminal=false Type=Application NoDisplay=true Categories= OnlyShowIn=UKUI; X-UKUI-AutoRestart=true ukui-power-manager/ukui-upower/server/0000755000175000017500000000000014205117543017021 5ustar fengfengukui-power-manager/ukui-upower/server/dbus-ukuipower.h0000644000175000017500000000565714205117543022174 0ustar fengfeng/* * Copyright (C) 2020 The Qt Company Ltd. * Copyright (C) 2021 KylinSoft 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 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, see . */ #ifndef DBUS-UKUIPOWER_H #define DBUS-UKUIPOWER_H #include #include #include "dbus.h" QT_BEGIN_NAMESPACE class QByteArray; template class QList; template class QMap; class QString; class QStringList; class QVariant; QT_END_NAMESPACE /* * Adaptor class for interface org.ukui.upower */ class UpowerAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ukui.upower") Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") public: UpowerAdaptor(QObject *parent); virtual ~UpowerAdaptor(); public: // PROPERTIES public Q_SLOTS: // METHODS QString CanHibernate(); QString DaemonVersion(); QString IconName(); bool IsPresent(); bool LowBattery(); QString MachineType(); bool OnBattery(); double Percentage(); int State(); int TimeToEmpty(); int TimeToFull(); QString UPowerVersion(); Q_SIGNALS: // SIGNALS }; #endif ukui-power-manager/ukui-upower/server/dbus-ukuipower.cpp0000644000175000017500000000716414205117543022522 0ustar fengfeng/* * Copyright (C) 2020 The Qt Company Ltd. * Copyright (C) 2021 KylinSoft 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 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, see . */ #include "dbus-ukuipower.h" #include #include #include #include #include #include #include /* * Implementation of adaptor class UpowerAdaptor */ UpowerAdaptor::UpowerAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) { // constructor setAutoRelaySignals(true); } UpowerAdaptor::~UpowerAdaptor() { // destructor } QString UpowerAdaptor::CanHibernate() { // handle method call org.ukui.upower.CanHibernate QString out0; QMetaObject::invokeMethod(parent(), "CanHibernate", Q_RETURN_ARG(QString, out0)); return out0; } QString UpowerAdaptor::DaemonVersion() { // handle method call org.ukui.upower.DaemonVersion QString out0; QMetaObject::invokeMethod(parent(), "DaemonVersion", Q_RETURN_ARG(QString, out0)); return out0; } QString UpowerAdaptor::IconName() { // handle method call org.ukui.upower.IconName QString out0; QMetaObject::invokeMethod(parent(), "IconName", Q_RETURN_ARG(QString, out0)); return out0; } bool UpowerAdaptor::IsPresent() { // handle method call org.ukui.upower.IsPresent bool out0; QMetaObject::invokeMethod(parent(), "IsPresent", Q_RETURN_ARG(bool, out0)); return out0; } bool UpowerAdaptor::LowBattery() { // handle method call org.ukui.upower.LowBattery bool out0; QMetaObject::invokeMethod(parent(), "LowBattery", Q_RETURN_ARG(bool, out0)); return out0; } QString UpowerAdaptor::MachineType() { // handle method call org.ukui.upower.MachineType QString out0; QMetaObject::invokeMethod(parent(), "MachineType", Q_RETURN_ARG(QString, out0)); return out0; } bool UpowerAdaptor::OnBattery() { // handle method call org.ukui.upower.OnBattery bool out0; QMetaObject::invokeMethod(parent(), "OnBattery", Q_RETURN_ARG(bool, out0)); return out0; } double UpowerAdaptor::Percentage() { // handle method call org.ukui.upower.Percentage double out0; QMetaObject::invokeMethod(parent(), "Percentage", Q_RETURN_ARG(double, out0)); return out0; } int UpowerAdaptor::State() { // handle method call org.ukui.upower.State int out0; QMetaObject::invokeMethod(parent(), "State", Q_RETURN_ARG(int, out0)); return out0; } int UpowerAdaptor::TimeToEmpty() { // handle method call org.ukui.upower.TimeToEmpty int out0; QMetaObject::invokeMethod(parent(), "TimeToEmpty", Q_RETURN_ARG(int, out0)); return out0; } int UpowerAdaptor::TimeToFull() { // handle method call org.ukui.upower.TimeToFull int out0; QMetaObject::invokeMethod(parent(), "TimeToFull", Q_RETURN_ARG(int, out0)); return out0; } QString UpowerAdaptor::UPowerVersion() { // handle method call org.ukui.upower.UPowerVersion QString out0; QMetaObject::invokeMethod(parent(), "UPowerVersion", Q_RETURN_ARG(QString, out0)); return out0; } ukui-power-manager/ukui-upower/server/dbus.h0000644000175000017500000000600514205117543020130 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef DBUS_H #define DBUS_H #include "upowerinfo/upowerinfo.h" #include "batteryinfo/batteryinfo.h" #include #include class DBus : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface","org.ukui.upower") public: explicit DBus(QObject *parent = 0); ~DBus(); public slots: /** * @brief UPowerVersion * ukui-upower版本 * @return */ QString UPowerVersion(void); /** * @brief CanHibernate * @return * 是否可以休眠的接口 * 或可直接调用login1 的 * 重新封装的意义在于可以针对部分机型做特殊处理 * 并且可以 */ QString CanHibernate(void); /** * @brief MachineType * @return * 机器类型判断 */ QString MachineType(); /** * @brief OnBattery * AC状态还是DC状态 * @return */ bool OnBattery(); /** * @brief DaemonVersion * 判断upower版本 * @return */ QString DaemonVersion(); /** * @brief IconName * @return * 图标名称 */ QString IconName(); /** * @brief Percentage * @return * 电量百分比 */ double Percentage(); /** * @brief TimeToFull * @return * 充电过程中,还有多久充满电 */ int TimeToFull(); /** * @brief TimeToEmpty * @return * 放电过程 还有多久耗尽 */ int TimeToEmpty(); /** * @brief IsPresent * 电池是否存在 * @return */ bool IsPresent(); /** * @brief State * @return */ int State(); /** * @brief LowBattery * 低电量 * @return */ bool LowBattery(); signals: /** * @brief lowBatteryState * @return * 低电量状态信号 */ void LowBatteryState(bool); /** * @brief VeryLowBatteryState */ void VeryLowBatteryState(bool); /** * @brief PowerState */ void PowerState(bool); /** * @brief LidState */ void LidState(bool); void BatteryIcon(QString); private: UPowerInfo *upowerinfo; BatteryInfo *batteryinfo; void dealPowerState(bool); void dealLidState(bool); void dealLowBattery(bool); void dealVeryLowBattery(bool); void dealBatteryIcon(QString); }; #endif // DBUS_H ukui-power-manager/ukui-upower/server/common/0000755000175000017500000000000014205117543020311 5ustar fengfengukui-power-manager/ukui-upower/server/common/common.h0000644000175000017500000000216014205117543021751 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef COMMON_H #define COMMON_H #define FREEDESKTOP_UPOWER "org.freedesktop.DBus.Properties" #define UPOWER_PATH "/org/freedesktop/UPower" #define UPOWER_SERVICE "org.freedesktop.UPower" #define UPOWER_DISPLAY_PATH "/org/freedesktop/UPower/devices/DisplayDevice" #define UPOWER_DIVICES_SERVICE "org.freedesktop.UPower.Device" #endif // COMMON_H ukui-power-manager/ukui-upower/server/widget.h0000644000175000017500000000173114205117543020457 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef WIDGET_H #define WIDGET_H #include namespace Ui { class Widget; } class Widget : public QWidget { Q_OBJECT public: explicit Widget(QWidget *parent = 0); ~Widget(); private: Ui::Widget *ui; protected: void register_dbus(); }; #endif // WIDGET_H ukui-power-manager/ukui-upower/server/dbus.cpp0000644000175000017500000000550014205117543020462 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "dbus.h" #define FREEDESKTOP_UPOWER "org.freedesktop.DBus.Properties" #define UPOWER_PATH "/org/freedesktop/UPower" #define UPOWER_SERVICE "org.freedesktop.UPower" #define UPOWER_DISPLAY_PATH "/org/freedesktop/UPower/devices/DisplayDevice" DBus::DBus(QObject *parent) : QObject(parent) { upowerinfo = new UPowerInfo; batteryinfo = new BatteryInfo; connect(upowerinfo,&UPowerInfo::acChanged,this,&DBus::dealPowerState); connect(upowerinfo,&UPowerInfo::lidChanged,this,&DBus::dealLidState); connect(batteryinfo,&BatteryInfo::LowBatteryChanged,this,&DBus::dealLowBattery); connect(batteryinfo,&BatteryInfo::VeryLowBatteryChanged,this,&DBus::dealVeryLowBattery); connect(batteryinfo,&BatteryInfo::BatteryIconChanged,this,&DBus::dealBatteryIcon); } DBus::~DBus() { delete upowerinfo; delete batteryinfo; } QString DBus::UPowerVersion() { return "3.1"; } QString DBus::CanHibernate() { return upowerinfo->CanHibernate(); } QString DBus::MachineType() { return upowerinfo->MachineType(); } bool DBus::OnBattery() { return upowerinfo->OnBattery(); } QString DBus::DaemonVersion() { return upowerinfo->DaemonVersion(); } //***************************************** /******************************************/ QString DBus::IconName() { return batteryinfo->IconName(); } double DBus::Percentage() { return batteryinfo->Percentage(); } int DBus::TimeToFull() { return batteryinfo->TimeToFull(); } int DBus::TimeToEmpty() { return batteryinfo->TimeToEmpty(); } bool DBus::IsPresent() { return batteryinfo->IsPresent(); } int DBus::State() { int i=1; return i; } bool DBus::LowBattery() { return batteryinfo->LowBatteryState(); } void DBus::dealPowerState(bool state) { emit PowerState(state); } void DBus::dealLidState(bool state) { emit LidState(state); } void DBus::dealLowBattery(bool state) { emit LowBatteryState(state); } void DBus::dealVeryLowBattery(bool state) { emit VeryLowBatteryState(state); } void DBus::dealBatteryIcon(QString msg) { emit BatteryIcon(msg); } ukui-power-manager/ukui-upower/server/widget.ui0000644000175000017500000000126414205117543020646 0ustar fengfeng Widget 0 0 400 300 Widget 130 120 67 17 TextLabel ukui-power-manager/ukui-upower/server/upowerinfo/0000755000175000017500000000000014205117543021216 5ustar fengfengukui-power-manager/ukui-upower/server/upowerinfo/upowerinfo.h0000644000175000017500000000367114205117543023573 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef UPOWERINFO_H #define UPOWERINFO_H #include #include #include #include "../common/common.h" class UPowerInfo : public QObject { Q_OBJECT public: explicit UPowerInfo(QObject *parent = nullptr); ~UPowerInfo(); /** * @brief UPowerVersion * @return * UPower版本 */ QString UPowerVersion(void); /** * @brief CanHibernate * @return * 是否可以休眠的接口 * 或可直接调用login1 的 * 重新封装的意义在于可以针对部分机型做特殊处理 * 并且可以 */ QString CanHibernate(void); /** * @brief MachineType * @return * 机器类型判断 */ QString MachineType(); bool OnBattery(); bool LidIsClosed(); QString DaemonVersion(); private slots: void dealMessage(void); private: void initUpowerInfo(); void dealPowerMessage(void); void dealLidMessage(void); QDBusInterface *iface; bool mOnBattery; bool mLidIsClosed; signals: /** * @brief acChanged * 电源状态改变信号 */ void acChanged(bool ); /** * @brief acChanged * 合盖状态改变信号 */ void lidChanged(bool ); }; #endif // UPOWERINFO_H ukui-power-manager/ukui-upower/server/upowerinfo/upowerinfo.cpp0000644000175000017500000000765414205117543024133 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "upowerinfo.h" UPowerInfo::UPowerInfo(QObject *parent) : QObject(parent) { iface = new QDBusInterface(UPOWER_SERVICE,UPOWER_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); QDBusConnection::systemBus().connect(UPOWER_SERVICE,UPOWER_PATH, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(dealMessage(void)) ); mOnBattery = OnBattery(); mLidIsClosed = LidIsClosed(); } UPowerInfo::~UPowerInfo() { delete iface; } QString UPowerInfo::UPowerVersion() { return "3.1"; } QString UPowerInfo::CanHibernate() { QDBusInterface interface("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()); if (!interface.isValid()) { qCritical() << QDBusConnection::sessionBus().lastError().message(); } /*调用远程的 CanHibernate 方法,判断是否可以执行休眠的操作,返回值为yes为允许执行休眠,no为无法执行休眠 na为交换分区不足*/ QDBusReply reply = interface.call("CanHibernate"); if (reply.isValid()) { return reply.value(); } else { return "Call Dbus method failed"; } } QString UPowerInfo::MachineType() { QDBusReply reply = iface->call("Get",UPOWER_SERVICE,"LidIsPresent"); if(reply.isValid()){ if(true == reply.value().toBool()){ return "book"; } else{ return "pc"; } }else{ return "get lid is present erroy!"; } } bool UPowerInfo::OnBattery() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get",UPOWER_SERVICE,"OnBattery"); if(reply.isValid()){ return reply.value().toBool(); }else { return false; } } bool UPowerInfo::LidIsClosed() { QDBusReply reply = iface->call("Get",UPOWER_SERVICE,"LidIsClosed"); if(reply.isValid()){ return reply.value().toBool(); }else { return false; } } QString UPowerInfo::DaemonVersion() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get",UPOWER_SERVICE,"DaemonVersion"); if(reply.isValid()){ return reply.value().toString(); }else { return "get version erroy!"; } } void UPowerInfo::dealMessage() { dealPowerMessage(); dealLidMessage(); } void UPowerInfo::dealPowerMessage() { bool value; value = OnBattery(); if(mOnBattery != value){ mOnBattery = value; emit acChanged(mOnBattery); } } void UPowerInfo::dealLidMessage() { bool value; value = LidIsClosed(); if(mLidIsClosed != value){ mLidIsClosed = value; emit lidChanged(mLidIsClosed); } } ukui-power-manager/ukui-upower/server/resources/0000755000175000017500000000000014205117543021033 5ustar fengfengukui-power-manager/ukui-upower/server/resources/10-monitor.conf0000644000175000017500000000020414205117543023603 0ustar fengfengSection "ServerFlags" option "StandbyTime" "0" option "SuspendTime" "0" option "OffTime" "0" option "BlankTime" "0" EndSection ukui-power-manager/ukui-upower/server/resources/org.ukui.power-manager.gschema.xml0000644000175000017500000005000014205117543027464 0ustar fengfeng 'suspend' Whether to hibernate, suspend or do nothing when inactive The type of sleeping that should be performed when the computer is inactive. 'suspend' Battery critical low action The action to take when the battery is critically low. true If the battery event should occur when the lid is shut and the power disconnected If the battery lid close event should occur (for example 'Suspend when lid closed on battery') when the lid is previously shut and the AC power disconnected at a later time. 'suspend' Whether to hibernate, suspend or do nothing when inactive The type of sleeping that should be performed when the computer is inactive. 'shutdown' UPS critical low action The action to take when the UPS is critically low. 'hibernate' UPS low power action The action to take when the UPS is low. true Allow backlight brightness adjustment If the screen brightness should be changed when switching between AC and battery power. true Reduce the backlight brightness when on battery power If the screen should be reduced in brightness when the computer is on battery power. true Reduce the keyboard backlight when on battery power If the keyboard backlight brightness should be reduced when the computer is on battery power 100 Keyboard backlight brightness when on AC power. Percent brightness to set keyboard backlight at when on AC power. Legal values are between 0 and 100. 50 Percent to reduce keyboard backlight by when on battery power. The percentage to reduce the keyboard backlight by when on battery power. For example, if set to '60', the backlight will be cut by 40% on battery power. Legal values are between 0 and 100. 75 Percent to reduce keyboard backlight by when idle. The percentage to reduce the keyboard backlight by when idle. For example, if set to '60', the backlight will be cut by 40% when idle. Legal values are between 0 and 100. 100 The brightness of the screen when idle This is the laptop panel screen brightness used when the session is idle. Only valid when use-time-for-policy is true. true Dim the screen after a period of inactivity when on battery power If the screen should be dimmed to save power when the computer is idle when on battery power. 60 The default amount of time to dim the screen after idle The default amount of time to dim the screen after idle. 50 LCD dimming amount when on battery The amount to dim the brightness of the display when on battery power. Possible values are between 0 and 100. false Dim the screen after a period of inactivity when on AC power If the screen should be dimmed to save power when the computer is idle when on AC power. 'off' Method used to blank screen on AC The DPMS method used to blank the screen when on AC power. 'off' Method used to blank screen on battery The DPMS method used to blank the screen when on battery power. 100.0 LCD brightness when on AC The brightness of the display when on AC power. Possible values are between 0.0 and 100.0. 100.0 LCD brightness when on BAT The brightness of the display when on BAT power. Possible values are between 0.0 and 100.0. 'suspend' Suspend button action The action to take when the system suspend button is pressed. 'hibernate' Hibernate button action The action to take when the system hibernate button is pressed. 'interactive' Power button action The action to take when the system power button is pressed. 'suspend' Laptop lid close action on battery The action to take when the laptop lid is closed and the laptop is on battery power. 'suspend' Laptop lid close action when on AC The action to take when the laptop lid is closed and the laptop is on AC power. true Whether to use time-based notifications If time based notifications should be used. If set to false, then the percentage change is used instead, which may fix a broken ACPI BIOS. false Check CPU load before sleeping If the CPU load should be checked before doing the idle action. false Whether NetworkManager should be connected and disconnected on sleep. Whether NetworkManager should disconnect before suspending or hibernating and connect on resume. true Use ukui-screensaver lock setting Whether to use the screen lock setting of ukui-screensaver to decide if the screen is locked after a hibernate, suspend or blank screen. true Lock screen when blanked Whether the screen is locked when the screen is turned off. Only used if lock-use-screensaver is false. true Lock screen on suspend Whether the screen is locked when the computer wakes up from a suspend. Only used if lock-use-screensaver is false. true Lock screen on hibernate Whether the screen is locked when the computer wakes up from a hibernate. Only used if lock-use-screensaver is false. false Lock GNOME keyring on sleep Whether the GNOME keyring is locked before the computer enters suspend. This means the keyring will have to be unlocked on resume. true Lock GNOME keyring on sleep Whether the GNOME keyring is locked before the computer enters hibernate. This means the keyring will have to be unlocked on resume. true If we should show the low capacity warning for a broken battery If we should show the low capacity warning for a broken battery. true Notify when AC adapter is disconnected If the user should be notified when the AC adapter is disconnected. false Notify when fully charged If a notification message should be displayed when the battery is fully charged. true Notify on a sleep failure If a notification message should be displayed after suspend or hibernate failed. '' The URI to show to the user on sleep failure When sleep fails we can show the user a button to help fix the situation. Leave this blank if the button should not be shown. true Notify on a low power If a notification message should be displayed when the battery is getting low. true Whether we should show the history data points Whether we should show the history data points in the statistics window. true Whether we should smooth the history data Whether we should smooth the history data in the graph. 'power' The default graph type to show for history The default graph type to show in the history window. 21600 The maximum time displayed for history The maximum duration of time displayed on the x-axis of the history graph. true Whether we should show the stats data points Whether we should show the stats data points in the statistics window. true Whether we should smooth the stats data Whether we should smooth the stats data in the graph. 'power' The default graph type to show for stats The default graph type to show in the stats window. 0 The index of the page number to show by default The index of the page number to show by default which is used to return focus to the correct page. '' The ID of the last device selected The identifier of the last device which is used to return focus to the correct device. 20 Percentage considered low The percentage of the battery when it is considered low. Only valid when use-time-for-policy is false. 10 Percentage considered critical The percentage of the battery when it is considered critical. Only valid when use-time-for-policy is false. 5 Percentage action is taken The percentage of the battery when the critical action is performed. Only valid when use-time-for-policy is false. 1200 The time remaining when low The time remaining in seconds of the battery when it is considered low. Only valid when use-time-for-policy is true. 300 The time remaining when critical The time remaining in seconds of the battery when it is considered critical. Only valid when use-time-for-policy is true. 120 The time remaining when action is taken The time remaining in seconds of the battery when critical action is taken. Only valid when use-time-for-policy is true. 900 Sleep timeout computer when on battery The amount of time in seconds the computer on battery power needs to be inactive before it goes to sleep. 900 Sleep timeout computer when on AC The amount of time in seconds the computer on AC power needs to be inactive before it goes to sleep. 0 Sleep timeout computer when on UPS The amount of time in seconds the computer on UPS power needs to be inactive before it goes to sleep. 600 Sleep timeout display when on AC The amount of time in seconds before the display goes to sleep when the computer is on AC power. 600 Sleep timeout display when on battery The amount of time in seconds the computer on battery power needs to be inactive before the display goes to sleep. 600 Sleep timeout display when on UPS The amount of time in seconds the computer on UPS power needs to be inactive before the display goes to sleep. true If sounds should be used If sounds should be used when the power is critically low, or inhibit requests have stopped the policy action. true If preferences and statistics items should be shown in the context menu false If power policy mode should be auto switched when plugged in and out false If power policy mode should be auto switched when plugged in and out 2 power policy mode 1 power policy current 2 power policy current 1 power policy current 1 power policy current 1 power policy current 1 power policy current 'present' When to show the notification icon Display options for the notification icon. ukui-power-manager/ukui-upower/server/resources/ukui-upower.desktop0000644000175000017500000000025714205117543024726 0ustar fengfeng[Desktop Entry] Name=Ukui-Upower Icon=ukui-power-manager Exec=ukui-upower Terminal=false Type=Application NoDisplay=true Categories= OnlyShowIn=UKUI; X-UKUI-AutoRestart=true ukui-power-manager/ukui-upower/server/org.ukui.upower.xml0000644000175000017500000000226714205117543022635 0ustar fengfeng ukui-power-manager/ukui-upower/server/widget.cpp0000644000175000017500000000264114205117543021013 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "widget.h" #include "ui_widget.h" #include "dbus.h" #include "dbus-ukuipower.h" #include #include Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); this->setWindowTitle("服务端"); register_dbus(); } Widget::~Widget() { delete ui; } void Widget::register_dbus() { DBus* dbus=new DBus; new UpowerAdaptor(dbus); QDBusConnection con=QDBusConnection::sessionBus(); if(!con.registerService("org.ukui.upower") || !con.registerObject("/",dbus, QDBusConnection::ExportAllSlots| QDBusConnection::ExportAllSignals)) { qDebug()<<"fail"; } } ukui-power-manager/ukui-upower/server/org.ukui.power.xml0000644000175000017500000000202514205117543022440 0ustar fengfeng ukui-power-manager/ukui-upower/server/server.pro0000644000175000017500000000212514205117543021051 0ustar fengfeng#------------------------------------------------- # # Project created by QtCreator 2019-06-29T11:18:10 # #------------------------------------------------- QT += core gui dbus greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = ukui-upower TEMPLATE = app CONFIG += c++11 link_pkgconfig PKGCONFIG += gsettings-qt SOURCES += main.cpp\ batteryinfo/batteryinfo.cpp \ upowerinfo/upowerinfo.cpp \ widget.cpp \ dbus.cpp \ dbus-ukuipower.cpp HEADERS += widget.h \ batteryinfo/batteryinfo.h \ common/common.h \ dbus.h \ dbus-ukuipower.h \ upowerinfo/upowerinfo.h FORMS += widget.ui # Default rules for deployment. qnx: target.path = /tmp/usr/bin else: unix:!android: target.path = /usr/bin !isEmpty(target.path): INSTALLS += target desktop.files += resources/ukui-upower.desktop desktop.path = /etc/xdg/autostart/ INSTALLS += desktop xorg.files += resources/10-monitor.conf xorg.path = /usr/share/X11/xorg.conf.d/ INSTALLS += xorg conf.files += resources/org.ukui.power-manager.gschema.xml conf.path=/usr/share/glib-2.0/schemas/ INSTALLS += conf ukui-power-manager/ukui-upower/server/batteryinfo/0000755000175000017500000000000014205117543021347 5ustar fengfengukui-power-manager/ukui-upower/server/batteryinfo/batteryinfo.cpp0000644000175000017500000001355114205117543024406 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include #include "batteryinfo.h" BatteryInfo::BatteryInfo(QObject *parent) : QObject(parent) { const QByteArray id("org.ukui.power-manager"); mPowerManagementGsettings = new QGSettings(id); mUpower = new UPowerInfo; initBatteryInfo(); connect(mPowerManagementGsettings,&QGSettings::changed,this,[=]{ readSettings(); }); iface = new QDBusInterface(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); QDBusConnection::systemBus().connect(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(dealMessage(void)) ); } BatteryInfo::~BatteryInfo() { delete iface; delete mUpower; delete mPowerManagementGsettings; } void BatteryInfo::initBatteryInfo() { readSettings(); // getBatteryInfo(); mLowBatteryState = false; } void BatteryInfo::dealMessage() { readSettings(); getBatteryInfo(); dealLowBatteryMessage(batteryState); dealBatteryIconMessage(batteryState,mPercentage); } void BatteryInfo::readSettings() { mSetPercentageLow = mPowerManagementGsettings->get("percentageLow").toInt(); mPercentageAction = mPowerManagementGsettings->get("percentageAction").toInt(); } void BatteryInfo::getBatteryInfo() { batteryState = mUpower->OnBattery(); mPercentage = Percentage(); } QString BatteryInfo::IconName() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); // QDBusReply reply = iface->call("Get",UPOWER_DIVICES_SERVICE,"IconName"); // if(reply.isValid()){ // return reply.value().toString(); // }else{ // return "false"; // } getBatteryInfo(); double num = mPercentage; if(true == batteryState){ mIconMessage = QString("battery-level-%1-symbolic").arg((int)num/10*10); }else{ mIconMessage = QString("battery-level-%1-charging-symbolic").arg((int)num/10*10); } return mIconMessage; } double BatteryInfo::Percentage() { double value; // QDBusInterface iface(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get",UPOWER_DIVICES_SERVICE,"Percentage"); if(reply.isValid()){ value = reply.value().toDouble(); return value; }else{ return -1.0; } } int BatteryInfo::TimeToFull() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get",UPOWER_DIVICES_SERVICE,"TimeToFull"); if(reply.isValid()){ return reply.value().toInt(); }else{ return -1; } } int BatteryInfo::TimeToEmpty() { QDBusInterface iface(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); QDBusReply reply = iface.call("Get",UPOWER_DIVICES_SERVICE,"TimeToEmpty"); if(reply.isValid()){ return reply.value().toInt(); }else{ return -1; } } bool BatteryInfo::IsPresent() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get",UPOWER_DIVICES_SERVICE,"IsPresent"); if(reply.isValid()){ return reply.value().toInt(); }else{ return false; } } bool BatteryInfo::LowBatteryState() { readSettings(); getBatteryInfo(); if (mSetPercentageLow > mPercentage) { return true; } else { return false; } } void BatteryInfo::dealLowBatteryMessage(const bool &state) { if (state) { if (mSetPercentageLow > mPercentage) { if (!mLowBatteryState) { mLowBatteryState = true; emit LowBatteryChanged(mLowBatteryState); } if (mPercentageAction > mPercentage) { mVeryLowBatteryState = true; emit VeryLowBatteryChanged(mVeryLowBatteryState); } } else { if (mLowBatteryState) { mLowBatteryState = false; emit LowBatteryChanged(mLowBatteryState); } } } else { if (mLowBatteryState) { mLowBatteryState = false; } } // qDebug()<. */ #ifndef BATTERYINFO_H #define BATTERYINFO_H #include #include #include #include "../common/common.h" #include "../upowerinfo/upowerinfo.h" class BatteryInfo : public QObject { Q_OBJECT public: explicit BatteryInfo(QObject *parent = nullptr); ~BatteryInfo(); /** * @brief IconName * @return * 图标名称 */ QString IconName(); /** * @brief Percentage * @return * 电量百分比 */ double Percentage(); /** * @brief TimeToFull * @return * 充电过程中,还有多久充满电 */ int TimeToFull(); /** * @brief TimeToEmpty * @return * 放电过程 还有多久耗尽 */ int TimeToEmpty(); bool IsPresent(); bool LowBatteryState(); private: QDBusInterface *iface; QGSettings *mPowerManagementGsettings; UPowerInfo *mUpower; bool batteryState; /** * @brief mPercentage * 当前电量百分比 */ double mPercentage; /** * @brief mSetPercentageLow * 用户设置的低电量百分比 */ int mSetPercentageLow; /** * @brief mPercentageAction * 用户设置的极低电量百分比 */ int mPercentageAction; /** * @brief mLowBatteryState * 低电量状态 */ bool mLowBatteryState; bool mVeryLowBatteryState; QString mIconMessage; void initBatteryInfo(); void readSettings(); void getBatteryInfo(); void dealLowBatteryMessage(const bool &state); void dealBatteryIconMessage(const bool &state,const double &precentage); private slots: void dealMessage(void); signals: void LowBatteryChanged(bool); void VeryLowBatteryChanged(bool); void BatteryIconChanged(QString); }; #endif // BATTERYINFO_H ukui-power-manager/ukui-upower/server/main.cpp0000644000175000017500000000153614205117543020456 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "widget.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; // w.show(); return a.exec(); } ukui-power-manager/ukui-upower/org.ukui.upower.xml0000644000175000017500000000226714205117452021326 0ustar fengfeng ukui-power-manager/ukui-upower/org.ukui.power.xml0000644000175000017500000000202514205117452021131 0ustar fengfeng ukui-power-manager/ukui-upower/batteryinfo/0000755000175000017500000000000014205117452020040 5ustar fengfengukui-power-manager/ukui-upower/batteryinfo/batteryinfo.cpp0000644000175000017500000001245114205117452023075 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include #include "batteryinfo.h" BatteryInfo::BatteryInfo(QObject *parent) : QObject(parent) { const QByteArray id("org.ukui.power-manager"); mPowerManagementGsettings = new QGSettings(id); mUpower = new UPowerInfo; QString batteryPath = mUpower->getBatteryPath(); initBatteryInfo(); connect(mPowerManagementGsettings, &QGSettings::changed, this, [=] { readSettings(); }); iface = new QDBusInterface(UPOWER_SERVICE, batteryPath, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); QDBusConnection::systemBus().connect( UPOWER_SERVICE, batteryPath, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(dealMessage(void))); } BatteryInfo::~BatteryInfo() { delete iface; delete mUpower; delete mPowerManagementGsettings; } void BatteryInfo::initBatteryInfo() { readSettings(); // getBatteryInfo(); mLowBatteryState = false; } void BatteryInfo::dealMessage() { readSettings(); getBatteryInfo(); dealLowBatteryMessage(batteryState); dealBatteryIconMessage(batteryState, mPercentage); } void BatteryInfo::readSettings() { mSetPercentageLow = mPowerManagementGsettings->get("percentageLow").toInt(); mPercentageAction = mPowerManagementGsettings->get("percentageAction").toInt(); } void BatteryInfo::getBatteryInfo() { batteryState = mUpower->OnBattery(); mPercentage = Percentage(); } QString BatteryInfo::IconName() { getBatteryInfo(); double num = mPercentage; if (true == batteryState) { mIconMessage = QString("battery-level-%1-symbolic").arg((int)num / 10 * 10); } else { mIconMessage = QString("battery-level-%1-charging-symbolic").arg((int)num / 10 * 10); } return mIconMessage; } double BatteryInfo::Percentage() { double value; QDBusReply reply = iface->call("Get", UPOWER_DIVICES_SERVICE, "Percentage"); if (reply.isValid()) { value = reply.value().toDouble(); return value; } else { qDebug() << "Get percentage failed"; return -1.0; } } int BatteryInfo::TimeToFull() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get", UPOWER_DIVICES_SERVICE, "TimeToFull"); if (reply.isValid()) { return reply.value().toInt(); } else { qDebug() << "Get time to full failed"; return -1; } } int BatteryInfo::TimeToEmpty() { QDBusInterface iface(UPOWER_SERVICE, UPOWER_DISPLAY_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); QDBusReply reply = iface.call("Get", UPOWER_DIVICES_SERVICE, "TimeToEmpty"); if (reply.isValid()) { return reply.value().toInt(); } else { qDebug() << "Get time to empty failed"; return -1; } } bool BatteryInfo::IsPresent() { // QDBusInterface iface(UPOWER_SERVICE,UPOWER_DISPLAY_PATH, // FREEDESKTOP_UPOWER, // QDBusConnection::systemBus()); QDBusReply reply = iface->call("Get", UPOWER_DIVICES_SERVICE, "IsPresent"); if (reply.isValid()) { return reply.value().toInt(); } else { qDebug() << "Get is present failed"; return false; } } bool BatteryInfo::LowBatteryState() { readSettings(); getBatteryInfo(); if (mSetPercentageLow > mPercentage) { return true; } else { qDebug() << "Get low battery state failed"; return false; } } void BatteryInfo::dealLowBatteryMessage(const bool &state) { if (state) { if (mSetPercentageLow > mPercentage) { if (!mLowBatteryState) { mLowBatteryState = true; emit LowBatteryChanged(mLowBatteryState); } if (mPercentageAction > mPercentage) { mVeryLowBatteryState = true; emit VeryLowBatteryChanged(mVeryLowBatteryState); } } else { if (mLowBatteryState) { mLowBatteryState = false; emit LowBatteryChanged(mLowBatteryState); } } } else { if (mLowBatteryState) { mLowBatteryState = false; } } } void BatteryInfo::dealBatteryIconMessage(const bool &state, const double &precentage) { double num = precentage; if (true == state) { mIconMessage = QString("battery-level-%1-symbolic").arg((int)num / 10 * 10); } else { mIconMessage = QString("battery-level-%1-charging-symbolic").arg((int)num / 10 * 10); } emit BatteryIconChanged(mIconMessage); } ukui-power-manager/ukui-upower/batteryinfo/batteryinfo.h0000644000175000017500000000473614205117452022551 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef BATTERYINFO_H #define BATTERYINFO_H #include #include #include #include "../common/common.h" #include "../upowerinfo/upowerinfo.h" class BatteryInfo : public QObject { Q_OBJECT public: explicit BatteryInfo(QObject *parent = nullptr); ~BatteryInfo(); /** * @brief IconName * @return * 图标名称 */ QString IconName(); /** * @brief Percentage * @return * 电量百分比 */ double Percentage(); /** * @brief TimeToFull * @return * 充电过程中,还有多久充满电 */ int TimeToFull(); /** * @brief TimeToEmpty * @return * 放电过程 还有多久耗尽 */ int TimeToEmpty(); bool IsPresent(); bool LowBatteryState(); private: QDBusInterface *iface; QGSettings *mPowerManagementGsettings; UPowerInfo *mUpower; bool batteryState; /** * @brief mPercentage * 当前电量百分比 */ double mPercentage; /** * @brief mSetPercentageLow * 用户设置的低电量百分比 */ int mSetPercentageLow; /** * @brief mPercentageAction * 用户设置的极低电量百分比 */ int mPercentageAction; /** * @brief mLowBatteryState * 低电量状态 */ bool mLowBatteryState; bool mVeryLowBatteryState; QString mIconMessage; void initBatteryInfo(); void readSettings(); void getBatteryInfo(); void dealLowBatteryMessage(const bool &state); void dealBatteryIconMessage(const bool &state,const double &precentage); private slots: void dealMessage(void); signals: void LowBatteryChanged(bool); void VeryLowBatteryChanged(bool); void BatteryIconChanged(QString); }; #endif // BATTERYINFO_H ukui-power-manager/ukui-upower/main.cpp0000644000175000017500000000234614205117452017147 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include #include "dbus.h" #include "dbus-ukuipower.h" #include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); DBus *dbus = new DBus; new UpowerAdaptor(dbus); QDBusConnection con = QDBusConnection::sessionBus(); if (!con.registerService("org.ukui.upower") || !con.registerObject("/", dbus, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals)) { qDebug() << "DBus create fail"; } return a.exec(); } ukui-power-manager/ukui-upower/README.md0000644000175000017500000000045514205117452016775 0ustar fengfengA.使用工具qdbuscpp2xml从dbus.h生成XML文件; qdbuscpp2xml -M dbus.h -o org.ukui.upower.xml B.使用工具qdbusxml2cpp从XML文件生成继承自QDBusAbstractAdaptor的类,供服务端使用 qdbusxml2cpp org.ukui.upower.xml -i dbus.h -a dbus-ukuipower https://blog.51cto.com/9291927/2118468 ukui-power-manager/.github/0000755000175000017500000000000014205117452014556 5ustar fengfengukui-power-manager/.github/workflows/0000755000175000017500000000000014205117452016613 5ustar fengfengukui-power-manager/.github/workflows/build.yml0000644000175000017500000000660614205117452020445 0ustar fengfengname: Check build on: push: branches: - master pull_request: branches: - master schedule: - cron: '0 0 * * *' jobs: archlinux: name: on Archlinux runs-on: ubuntu-20.04 container: docker.io/library/archlinux:latest steps: - name: Checkout ukui-power-manager source code uses: actions/checkout@v2 - name: Refresh pacman repository run: pacman -Sy - name: Install build dependencies run: pacman -S --noconfirm base-devel qt5-tools dbus-glib gtk3 libgnome-keyring libnotify upower intltool mate-common yelp-tools libxrandr libx11 libxext xorgproto glib2 - name: Configure & Make run: | ./autogen.sh; make -j$(nproc); debian: name: on Debian Sid runs-on: ubuntu-20.04 container: docker.io/library/debian:sid env: DEBIAN_FRONTEND: noninteractive steps: - name: Checkout ukui-power-manager source code uses: actions/checkout@v2 - name: Update apt repository run: apt-get update -y - name: Install build dependcies run: apt-get install -y build-essential qt5-default qttools5-dev-tools debhelper-compat qtbase5-dev intltool libcanberra-gtk3-dev libdbus-glib-1-dev libgcrypt20-dev libglib2.0-dev libgtk-3-dev libnotify-dev libtool-bin libupower-glib-dev libwnck-3-dev libx11-dev libxext-dev libxml-parser-perl libxrandr-dev mate-common pkg-config xmlto yelp-tools libqt5charts5-dev libqt5x11extras5-dev libgsettings-qt-dev - name: Configure & Make run: | ./autogen.sh --without-keyring; make -j$(nproc); fedora: name: on Fedora 32 runs-on: ubuntu-20.04 container: docker.io/library/fedora:32 steps: - name: Checkout ukui-power-manager source code uses: actions/checkout@v2 - name: Install build dependencies run: dnf install -y which gcc gcc-c++ make cmake cmake-rpm-macros autoconf automake intltool rpm-build qt5-rpm-macros gtk3-devel libwnck3-devel qt5-qtbase-devel intltool libcanberra-devel libcanberra-gtk3 glib2-devel dbus-glib-devel libnotify-devel libtool libgcrypt-devel upower-devel libX11-devel libXext-devel libXrandr-devel perl-XML-Parser qt5-qtx11extras-devel gsettings-qt-devel mate-common mate-desktop-devel qt5-qtcharts-devel xmlto yelp-tools libgnome-keyring-devel - name: Configure & Make run: | ln -sf /usr/bin/lrelease-qt5 /usr/bin/lrelease; ln -sf /usr/bin/qmake-qt5 /usr/bin/qmake; ./autogen.sh; make -j$(nproc); ubuntu: name: on Ubuntu 20.04 runs-on: ubuntu-20.04 container: docker.io/library/ubuntu:focal env: DEBIAN_FRONTEND: noninteractive steps: - name: Checkout ukui-power-manager source code uses: actions/checkout@v2 - name: Update apt repository run: apt-get update -y - name: Install build dependcies run: apt-get install -y build-essential qt5-default qttools5-dev-tools debhelper-compat qtbase5-dev intltool libcanberra-gtk3-dev libdbus-glib-1-dev libgcrypt20-dev libglib2.0-dev libgtk-3-dev libnotify-dev libtool-bin libupower-glib-dev libwnck-3-dev libx11-dev libxext-dev libxml-parser-perl libxrandr-dev mate-common pkg-config xmlto yelp-tools libqt5charts5-dev libqt5x11extras5-dev libgsettings-qt-dev - name: Configure & Make run: | ./autogen.sh --without-keyring; make -j$(nproc); ukui-power-manager/ukui-power-manager-tray/0000755000175000017500000000000014205117543017713 5ustar fengfengukui-power-manager/ukui-power-manager-tray/enginedevice.h0000644000175000017500000000675514205117543022526 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef ENGINEDEVICE_H #define ENGINEDEVICE_H #include "engine_common.h" #include #include #include #include #include #include #define DBUS_SERVICE "org.freedesktop.UPower" #define DBUS_OBJECT "/org/freedesktop/UPower" #define DBUS_INTERFACE "org.freedesktop.UPower" #define DBUS_INTERFACE_PRO "org.freedesktop.DBus.Properties" #define DBUS_INTERFACE_DEV "org.freedesktop.UPower.Device" class EngineDevice : public QObject { Q_OBJECT private: static EngineDevice* instance; explicit EngineDevice(QObject *parent = nullptr); class Deconstructor { public: ~Deconstructor() { if(instance) { delete instance; instance = nullptr; } } }; static Deconstructor deconstructor; public: static EngineDevice* getInstance() { if(instance==nullptr) { instance = new EngineDevice; } return instance; } Q_SIGNALS: void icon_changed(QString); void engine_signal_discharge(DEV dv); void engine_signal_charge(DEV dv); void engine_signal_fullycharge(DEV dv); void engine_signal_charge_low(DEV dv); void engine_signal_charge_critical(DEV dv); void engine_signal_charge_action(DEV dv); void engine_signal_summary_change(QString summary); void engine_signal_Battery_State(QStringList Battery_State); void one_device_add(DEVICE *dev); void one_device_remove(DEVICE *dev); public Q_SLOTS: void power_device_change_callback(QDBusMessage msg, QString path); public: QGSettings *settings; QList devices; QString previous_icon; QString previous_summary; DEVICE *composite_device; GpmIconPolicy icon_policy; bool power_device_recalculate_icon(); void power_device_recalculate_state(); QString power_device_get_icon_exact(UpDeviceKind device_kind, UpDeviceLevel warning, bool use_state); bool engine_recalculate_summary(); void getProperty(QString path, DEV &dev); QString engine_get_summary(); QStringList engine_get_state (); QString engine_kind_to_string(UpDeviceKind type_enum); QString engine_kind_to_localised_text(UpDeviceKind kind, uint number); void power_device_get_devices(); QStringList engine_get_Battery_State(DEVICE* dv); QString boolToString(bool ret); QString engine_get_device_summary(DEVICE *dv); QString engine_get_device_icon_index(qreal percentage); QString power_device_get_icon(); QString engine_get_device_icon(DEVICE *device); void putAttributes(QMap &map, DEV &btrDetailData); QString engine_get_timestring(int time_secs); QString engine_get_dev_icon(DEV dev); UpDeviceLevel engine_get_warning(DEV dev); }; #endif // ENGINEDEVICE_H ukui-power-manager/ukui-power-manager-tray/mainwindow.h0000644000175000017500000000312214205117543022236 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void initUi(); private: powerwindow *powerWindow; QSystemTrayIcon* trayIcon; QList deviceNames; QGSettings * settings; QMenu *menu; QDBusInterface *iface; private Q_SLOTS: void set_preference_func(); void onSumChanged(QString str); void IconChanged(QString str); void onActivatedIcon(QSystemTrayIcon::ActivationReason reason); }; #endif // MAINWINDOW_H ukui-power-manager/ukui-power-manager-tray/device.cpp0000644000175000017500000000162214205117543021657 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "device.h" #include DEVICE::DEVICE(QObject *parent) : QObject(parent) { } void DEVICE::handleChanged(QDBusMessage msg) { Q_EMIT device_property_changed(msg,m_dev.path); } DEVICE::~DEVICE() { } ukui-power-manager/ukui-power-manager-tray/powertray.h0000644000175000017500000000320014205117452022112 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef POWERTRAY_H #define POWERTRAY_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class PowerTray : public QObject { Q_OBJECT public: explicit PowerTray(QObject *parent = 0); ~PowerTray(); void initPowerTray(); QString getMachineType(); void initUi(); private: powerwindow *powerWindow; QSystemTrayIcon* trayIcon; QList deviceNames; QGSettings * settings; QMenu *menu; QDBusInterface *iface; private Q_SLOTS: void set_preference_func(); void onSumChanged(QString str); void IconChanged(QString str); void onActivatedIcon(QSystemTrayIcon::ActivationReason reason); }; #endif // POWERTRAY_H ukui-power-manager/ukui-power-manager-tray/powerwindow.h0000755000175000017500000001112714205117543022455 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef POWERWINDOW_H #define POWERWINDOW_H #include "engine_common.h" #include #include #include #include #include #include #include #include #include #include #include #include "enginedevice.h" #include #include #include #include #include #include #include #define KYLIN_BATTERY_CHARGING0_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING10_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING20_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING30_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING40_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING50_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING60_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING70_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING80_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING90_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_CHARGING100_PATH1 ":/charging/battery1/1.svg" #define KYLIN_BATTERY_00_PATH1 ":/charging/battery1/1.svg" class stateslider; class settinglabel; class m_PartLineWidget; class powerwindow : public QWidget { Q_OBJECT public: explicit powerwindow(QWidget *parent = nullptr); ~powerwindow(); enum PanelStatePosition { PanelDown = 0, PanelUp, PanelLeft, PanelRight }; void set_window_position(); void setWindowProperty(); void initUI(); void initgsetting(); QGSettings *settings; QStringList m_IconBatterChangeList; QVBoxLayout *m_pmainlayout = nullptr; QHBoxLayout *m_firstlayout = nullptr; QHBoxLayout *lastlayout = nullptr; QWidget *m_firstwidget; QWidget *lastWidget; QPushButton *iconButton; QLabel *percentageLabel; QLabel *powerStateLabel; QLabel *powerTimeToEmpty; m_PartLineWidget *line; EngineDevice* ed; QListWidget *listWidget; QMap device_item_map; settinglabel *settingLabel; void get_power_list(); protected: void paintEvent(QPaintEvent *e); private : QDBusInterface *m_pServiceInterface; // 获取任务栏的高度 QDBusInterface *m_iface; QGSettings *m_pPanelSetting = nullptr; int m_nScreenWidth; // 屏幕分辨率的宽 int m_nScreenHeight; // 屏幕分辨率的高 int m_pPeonySite; // 任务栏位置 int deviceNum = 0; int m_sysFontSize; double transparency; QGSettings *transparency_gsettings; bool eventFilter(QObject *watched, QEvent *event); void watchTranspartency(); private Q_SLOTS: void set_preference_func(); void batteryChange(int dev); void onBatteryChanged(QStringList args); void charge_notify(DEV dev); void discharge_notify(DEV dev); void action_battery_notify(DEV dev); void critical_battery_notify(DEV dev); void low_battery_notify(DEV dev); void full_charge_notify(DEV dev); void IconChanged(QString str); }; class m_PartLineWidget : public QWidget { Q_OBJECT public: explicit m_PartLineWidget(QWidget *parent = nullptr); void paintEvent(QPaintEvent *event); }; class stateslider : public QSlider { public: stateslider(QWidget *parent = 0); }; class settinglabel : public QLabel { Q_OBJECT public: settinglabel(); protected: void mousePressEvent(QMouseEvent *event); Q_SIGNALS: void labelclick(); }; #endif // POWERWINDOW_H ukui-power-manager/ukui-power-manager-tray/enginedevice.cpp0000644000175000017500000007344414205117543023060 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "enginedevice.h" #include "device.h" #include #include #include #include #include EngineDevice* EngineDevice::instance = NULL; void EngineDevice::power_device_get_devices() { QList deviceNames; /* call enum dbus*/ QDBusMessage msg = QDBusMessage::createMethodCall(DBUS_SERVICE,DBUS_OBJECT, DBUS_INTERFACE,"EnumerateDevices"); QDBusMessage res = QDBusConnection::systemBus().call(msg); if(res.type() == QDBusMessage::ReplyMessage) { const QDBusArgument &dbusArg = res.arguments().at(0).value(); dbusArg >> deviceNames; } else { } int len = deviceNames.size(); //qDebug()<m_dev.path = deviceNames.at(i).path(); getProperty(device->m_dev.path,device->m_dev); /* connect the nofity signal to changecallback */ QDBusConnection::systemBus().connect(DBUS_SERVICE,device->m_dev.path,DBUS_INTERFACE_PRO, QString("PropertiesChanged"),device,SLOT(handleChanged(QDBusMessage))); connect(device,SIGNAL(device_property_changed(QDBusMessage,QString)),this,SLOT(power_device_change_callback(QDBusMessage,QString))); /* add to device list*/ devices.append(device); } } EngineDevice::EngineDevice(QObject *parent) : QObject(parent) { icon_policy = GPM_ICON_POLICY_PRESENT; settings = new QGSettings(GPM_SETTINGS_SCHEMA); power_device_get_devices(); } void EngineDevice::getProperty(QString path,DEV& dev) { QDBusMessage msg = QDBusMessage::createMethodCall(DBUS_SERVICE,path, DBUS_INTERFACE_PRO,"GetAll"); msg << DBUS_INTERFACE_DEV; QDBusMessage res = QDBusConnection::systemBus().call(msg); if(res.type() == QDBusMessage::ReplyMessage) { const QDBusArgument &dbusArg = res.arguments().at(0).value(); QMap map; dbusArg >> map; dev.kind = (UpDeviceKind)map.value(QString("Type")).toInt(); dev.Type = engine_kind_to_localised_text ((UpDeviceKind)map.value(QString("Type")).toInt(),1); dev.Model = map.value(QString("Model")).toString(); dev.Device = map.value(QString("NativePath")).toString(); dev.Capacity = (map.value(QString("Capacity")).toDouble()); dev.Energy = QString::number(map.value(QString("Energy")).toDouble(), 'f', 1)+ " Wh"; dev.EnergyEmpty= QString::number(map.value(QString("EnergyEmpty")).toDouble(), 'f', 1)+ " Wh"; dev.EnergyFull = QString::number(map.value(QString("EnergyFull")).toDouble(), 'f', 1)+ " Wh"; dev.EnergyRate = QString::number(map.value(QString("EnergyRate")).toDouble(), 'f', 1) + " W"; dev.IsPresent = (map.value(QString("IsPresent")).toBool()); dev.PowerSupply = boolToString(map.value(QString("PowerSupply")).toBool()); dev.Percentage = map.value(QString("Percentage")).toDouble(); dev.Percentage = ( (float)( (int)( (dev.Percentage + 0.05) * 10 ) ) ) / 10; dev.Online = boolToString(map.value(QString("Online")).toBool()); dev.State = (UpDeviceState)map.value(QString("State")).toInt(); dev.TimeToEmpty = map.value(QString("TimeToEmpty")).toLongLong(); dev.TimeToFull = map.value(QString("TimeToFull")).toLongLong(); dev.Voltage = QString::number(map.value(QString("Voltage")).toDouble(), 'f', 1) + " V"; } } QString EngineDevice::boolToString(bool ret) { return ret ? tr("yes") : tr("no"); } void EngineDevice::putAttributes(QMap& map,DEV &btrDetailData) { if(map.contains("TimeToFull")) { btrDetailData.TimeToFull= map.value(QString("TimeToFull")).toLongLong(); } if(map.contains("TimeToEmpty")) btrDetailData.TimeToEmpty = map.value(QString("TimeToEmpty")).toLongLong(); if(map.contains("EnergyRate")) btrDetailData.EnergyRate = QString::number(map.value(QString("EnergyRate")).toDouble(), 'f', 1) + " W"; if(map.contains("Energy")) btrDetailData.Energy = QString::number(map.value(QString("Energy")).toDouble(), 'f', 1)+ " Wh"; if(map.contains("Voltage")) btrDetailData.Voltage = QString::number(map.value(QString("Voltage")).toDouble(), 'f', 1) + " V"; if(map.contains("WarnLevel")) { btrDetailData.warnlevel = (UpDeviceLevel)map.value(QString("WarnLevel")).toInt(); } if(map.contains("State")) { btrDetailData.State = (UpDeviceState)map.value(QString("State")).toInt(); ////qDebug()<< "state:" << btrDetailData.State; } if(map.contains("Percentage")) { btrDetailData.Percentage = map.value(QString("Percentage")).toDouble(); btrDetailData.Percentage = ( (float)( (int)( (btrDetailData.Percentage + 0.05) * 10 ) ) ) / 10; } if(map.contains("PowerSupply")) btrDetailData.PowerSupply = (map.value(QString("PowerSupply")).toBool()) ? tr("Yes") :tr("No"); if(map.contains("IsPresent")) btrDetailData.IsPresent = (map.value(QString("IsPresent")).toBool()); } void EngineDevice::power_device_change_callback(QDBusMessage msg,QString path) { /* if battery change to display devices */ /* judge state */ static bool init_level = true; static UpDeviceLevel level_old; UpDeviceLevel level; DEVICE *item = nullptr; Q_FOREACH (auto item_tmp, devices) { if(item_tmp->m_dev.path == path) { item = item_tmp; break; } } if(item == nullptr) return; DEV tmp_dev = item->m_dev; const QDBusArgument &arg = msg.arguments().at(1).value(); QMap map; arg >> map; putAttributes(map,item->m_dev); if ((item->m_dev.kind != UP_DEVICE_KIND_BATTERY) && (item->m_dev.kind != UP_DEVICE_KIND_UPS)) return; if(item->m_dev.State != tmp_dev.State) { if(item->m_dev.State==UP_DEVICE_STATE_DISCHARGING) { Q_EMIT engine_signal_discharge(item->m_dev); } else if (item->m_dev.State==UP_DEVICE_STATE_FULLY_CHARGED) { Q_EMIT engine_signal_fullycharge(item->m_dev); } else if (item->m_dev.State==UP_DEVICE_STATE_CHARGING) { Q_EMIT engine_signal_charge(item->m_dev); } //save new state } level = engine_get_warning (item->m_dev); if (init_level) { level_old = level; init_level = false; } /* check the warning state has not changed */ if(level != level_old) { if(level==UP_DEVICE_LEVEL_LOW) { //理论上connect一个dbus,但是代码如狗屎一般,看到这个注释的你好自为之。 int save = settings->get(GPM_SETTINGS_LOW_BAT_AUTO_SAVE).toInt(); if(save)settings->set(GPM_SETTINGS_BAT_POLICY,1); Q_EMIT engine_signal_charge_low(item->m_dev); } else if (level==UP_DEVICE_LEVEL_CRITICAL) { Q_EMIT engine_signal_charge_critical(item->m_dev); } else if(level==UP_DEVICE_LEVEL_ACTION) { Q_EMIT engine_signal_charge_action(item->m_dev); } level_old = level; } /*recaculate state*/ power_device_recalculate_state(); } void EngineDevice::power_device_recalculate_state() { /*recaculate icon*/ power_device_recalculate_icon(); /*recaculate sum*/ engine_recalculate_summary(); } bool EngineDevice::power_device_recalculate_icon() { // /*call a function to obtain icon*/ // QString icon; // icon = power_device_get_icon(); // if(icon.isNull()) // { // if(previous_icon.isNull()) // return false; // Q_EMIT icon_changed(QString()); // previous_icon.clear(); // return true; // } // if(previous_icon.isNull()) // { // Q_EMIT icon_changed(icon); // previous_icon = icon; // return true; // } // if(previous_icon != icon) // { // Q_EMIT icon_changed(icon); // previous_icon = icon; // return true; // } return true; } /** * power_device_get_icon: * * Returns the icon **/ QString EngineDevice::power_device_get_icon() { QString icon; /* GPM_ICON_POLICY_NEVER */ if (icon_policy == GPM_ICON_POLICY_NEVER) { return QString(); } /* we try CRITICAL: BATTERY, UPS, MOUSE, KEYBOARD */ if (icon_policy == GPM_ICON_POLICY_CRITICAL || icon_policy == GPM_ICON_POLICY_ALWAYS) { icon = power_device_get_icon_exact (UP_DEVICE_KIND_BATTERY, UP_DEVICE_LEVEL_CRITICAL, false); if (!icon.isNull()) { return icon; } icon = power_device_get_icon_exact (UP_DEVICE_KIND_UPS, UP_DEVICE_LEVEL_CRITICAL, false); if (!icon.isNull()) { return icon; } icon = power_device_get_icon_exact (UP_DEVICE_KIND_MOUSE, UP_DEVICE_LEVEL_CRITICAL, false); if (!icon.isNull()) { return icon; } icon = power_device_get_icon_exact (UP_DEVICE_KIND_KEYBOARD, UP_DEVICE_LEVEL_CRITICAL, false); if (!icon.isNull()) { return icon; } if(icon_policy == GPM_ICON_POLICY_CRITICAL) { return QString(); } } /* we try GPM_ENGINE_WARNING_LOW: BATTERY, UPS, MOUSE, KEYBOARD */ if (icon_policy == GPM_ICON_POLICY_LOW || icon_policy == GPM_ICON_POLICY_ALWAYS) { icon = power_device_get_icon_exact (UP_DEVICE_KIND_BATTERY, UP_DEVICE_LEVEL_LOW, false); if (!icon.isNull()) { return icon; } icon = power_device_get_icon_exact (UP_DEVICE_KIND_UPS, UP_DEVICE_LEVEL_LOW, false); if (!icon.isNull()) { return icon; } icon = power_device_get_icon_exact (UP_DEVICE_KIND_MOUSE, UP_DEVICE_LEVEL_LOW, false); if (!icon.isNull()) { return icon; } icon = power_device_get_icon_exact (UP_DEVICE_KIND_KEYBOARD, UP_DEVICE_LEVEL_LOW, false); if (!icon.isNull()) { return icon; } if(icon_policy == GPM_ICON_POLICY_LOW) { return QString(); } } /* we try (DIS)CHARGING: BATTERY, UPS */ if (icon_policy == GPM_ICON_POLICY_CHARGE || icon_policy == GPM_ICON_POLICY_ALWAYS) { icon = power_device_get_icon_exact (UP_DEVICE_KIND_BATTERY, UP_DEVICE_LEVEL_NONE, true); if (!icon.isNull()) { return icon; } icon = power_device_get_icon_exact (UP_DEVICE_KIND_UPS, UP_DEVICE_LEVEL_NONE, true); if (!icon.isNull()) { return icon; } if(icon_policy == GPM_ICON_POLICY_CHARGE) { return QString(); } } /* we try PRESENT: BATTERY, UPS */ if (icon_policy == GPM_ICON_POLICY_PRESENT || icon_policy == GPM_ICON_POLICY_ALWAYS) { icon = power_device_get_icon_exact (UP_DEVICE_KIND_BATTERY, UP_DEVICE_LEVEL_NONE, false); if (!icon.isNull()) { return icon; } icon = power_device_get_icon_exact (UP_DEVICE_KIND_UPS, UP_DEVICE_LEVEL_NONE, false); if (!icon.isNull()) { return icon; } if(icon_policy == GPM_ICON_POLICY_PRESENT) { return QString(); } } //always icon = power_device_get_icon_exact (UP_DEVICE_KIND_BATTERY, UP_DEVICE_LEVEL_NONE, false); if (!icon.isNull()) { return icon; } /* we fallback to the ac_adapter icon */ return QString("battery-full-symbolic"); } /** * power_device_get_icon_exact: * * Returns the icon **/ QString EngineDevice::power_device_get_icon_exact (UpDeviceKind device_kind, UpDeviceLevel warning, bool use_state) { DEVICE *device; UpDeviceLevel warning_temp; UpDeviceState state; /* do we have specific device types? */ Q_FOREACH (device, devices) { state = device->m_dev.State; warning_temp = device->m_dev.warnlevel; if ((device->m_dev.kind == device_kind) && (device->m_dev.IsPresent)) { if (warning != UP_DEVICE_LEVEL_NONE) { if (warning_temp == warning) { composite_device = device; return engine_get_device_icon (device); } continue; } if (use_state) { // if (state == UP_DEVICE_STATE_CHARGING || state == UP_DEVICE_STATE_DISCHARGING) { if ( state == UP_DEVICE_STATE_DISCHARGING) { composite_device = device; return engine_get_device_icon (device); } continue; } composite_device = device; return engine_get_device_icon (device); } } return QString(); } /** * engine_recalculate_summary: */ bool EngineDevice::engine_recalculate_summary () { QString summary; QStringList Battery_State; Battery_State = engine_get_state(); summary = engine_get_summary (); if (previous_summary.isNull()) { previous_summary = summary; Q_EMIT engine_signal_summary_change(summary); Q_EMIT engine_signal_Battery_State(Battery_State); return true; } if (previous_summary != summary) { previous_summary = summary; Q_EMIT engine_signal_summary_change(summary); Q_EMIT engine_signal_Battery_State(Battery_State); return true; } return false; } QStringList EngineDevice::engine_get_state() { DEVICE *device; UpDeviceState state; QStringList tooltip; QStringList part; bool is_present; UpDeviceKind kind; Q_FOREACH (device, devices) { is_present = device->m_dev.IsPresent; state = device->m_dev.State; kind = device->m_dev.kind; if ((!is_present)||(kind != UP_DEVICE_KIND_BATTERY)) continue; if (state == UP_DEVICE_STATE_EMPTY) continue; part = engine_get_Battery_State (device); if (!part.isEmpty()) tooltip.append(part); } return tooltip; } QStringList EngineDevice::engine_get_Battery_State(DEVICE* dv) { UpDeviceState state; double percentage; QStringList result; state = dv->m_dev.State; int EMPTY = dv->m_dev.TimeToEmpty; percentage = dv->m_dev.Percentage; bool is_present; is_present = dv->m_dev.IsPresent; if (!is_present) return result; result.append(QString("%1").arg(percentage)); result.append(QString("%1").arg(state)); result.append(QString("%1").arg(EMPTY)); return result; } /** * engine_get_summary: * * Returns the complete tooltip ready for display **/ QString EngineDevice::engine_get_summary () { DEVICE *device; UpDeviceState state; QString tooltip; QString part; bool is_present; UpDeviceKind kind; Q_FOREACH (device, devices) { is_present = device->m_dev.IsPresent; state = device->m_dev.State; kind = device->m_dev.kind; if ((!is_present)||(kind != UP_DEVICE_KIND_BATTERY)) continue; if (state == UP_DEVICE_STATE_EMPTY) continue; part = engine_get_device_summary (device); if (!part.isNull()) tooltip = QString("%1").arg(part); } return tooltip; } /** * * Returns a localised timestring * * Return value: The time string, e.g. "2 hours 3 minutes" **/ QString EngineDevice::engine_get_timestring (int time_secs) { int hours; int minutes; QString result; QString tmp; QString hour_str; QString minute_str; /* Add 0.5 to do rounding */ minutes = (int) ( ( time_secs / 60.0 ) + 0.5 ); if (minutes == 0) { result = (tr("Unknown time")); return result; } if (minutes < 60) { if(minutes==1) minute_str = tr("minute"); else minute_str=tr("minutes"); result=QString("%1 %2").arg(minutes).arg(minute_str); return result; } hours = minutes / 60; minutes = minutes % 60; if (minutes == 0) { if(hours == 1) hour_str = tr("hour"); else hour_str = tr("hours"); result=QString("%1 %2").arg(hours).arg(hour_str); } else { if(minutes==1) minute_str = tr("minute"); else minute_str=tr("minutes"); if(hours == 1) hour_str = tr("hour"); else hour_str = tr("hours"); result = QString("%1 %2 %3 %4").arg(hours).arg(hour_str).arg(minutes).arg(minute_str); } return result; } /** * engine_get_device_summary: **/ QString EngineDevice::engine_get_device_summary(DEVICE* dv) { QString kind_desc; int time_to_full_round; int time_to_empty_round; QString time_to_full_str; QString time_to_empty_str; UpDeviceKind kind; UpDeviceState state; double percentage; bool is_present; uint time_to_full; uint time_to_empty; QString result; kind = dv->m_dev.kind; is_present = dv->m_dev.IsPresent; state = dv->m_dev.State; percentage = dv->m_dev.Percentage; int i; // for (i = 0; i < 2;i++) // { // time_to_empty = time_to_empty + dv->m_dev.TimeToEmpty; // } time_to_empty = dv->m_dev.TimeToEmpty; time_to_full = dv->m_dev.TimeToFull; if (!is_present) return NULL; kind_desc = engine_kind_to_localised_text (kind, 1); if (state == UP_DEVICE_STATE_FULLY_CHARGED) { result = tr("%1% available, charged").arg(percentage); } else if (state == UP_DEVICE_STATE_DISCHARGING) { int is_show = settings->get(GPM_SETTINGS_DISPLAY_LEFT_TIME).toInt(); if(is_show){ result = tr("Left %1h %2m (%3%)").arg((time_to_empty)/3600).arg(((time_to_empty)%3600)/60).arg(percentage); }else{ result = tr("%1% available").arg(percentage); } // result = tr("Left %1h %2m (%3%)").arg((time_to_empty)/3600).arg(((time_to_empty)%3600)/60).arg(percentage); } else if (state == UP_DEVICE_STATE_CHARGING) { //需要connect一个dbus才对,可以但没必要,因为我觉得这个需求很扯 int is_show = settings->get(GPM_SETTINGS_DISPLAY_LEFT_TIME).toInt(); if(is_show){ result = tr("Left %1h %2m to full").arg((time_to_full)/3600).arg(((time_to_full)%3600)/60); }else{ result = tr("charging (%1%)").arg(percentage); } } else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) { /* TRANSLATORS: this is only shown for laptops with multiple batteries */ result = tr("%1 waiting to discharge (%2%)").arg(kind_desc).arg(percentage); } else if (state == UP_DEVICE_STATE_PENDING_CHARGE) { /* TRANSLATORS: this is only shown for laptops with multiple batteries */ result = tr("%1 waiting to charge (%2%)").arg(kind_desc).arg(percentage); } else { printf ("in an undefined state we are not charging or " "discharging and the batteries are also not charged"); result = QString("%1 (%2%)").arg(kind_desc).arg(percentage); } return result; } QString EngineDevice::engine_kind_to_string (UpDeviceKind type_enum) { QString ret; switch (type_enum) { case UP_DEVICE_KIND_LINE_POWER: ret = "line-power"; break; case UP_DEVICE_KIND_BATTERY: ret = "battery"; break; case UP_DEVICE_KIND_UPS: ret = "ups"; break; case UP_DEVICE_KIND_MONITOR: ret = "monitor"; break; case UP_DEVICE_KIND_MOUSE: ret = "mouse"; break; case UP_DEVICE_KIND_KEYBOARD: ret = "keyboard"; break; case UP_DEVICE_KIND_PDA: ret = "pda"; break; case UP_DEVICE_KIND_PHONE: ret = "phone"; break; case UP_DEVICE_KIND_MEDIA_PLAYER: ret = "media-player"; break; case UP_DEVICE_KIND_TABLET: ret = "tablet"; break; case UP_DEVICE_KIND_COMPUTER: ret = "computer"; break; default: ret = "unknown"; } return ret; } /** * engine_kind_to_localised_text: **/ QString EngineDevice::engine_kind_to_localised_text (UpDeviceKind kind, uint number) { Q_UNUSED(number); QString text; switch (kind) { case UP_DEVICE_KIND_LINE_POWER: text = tr("AC adapter"); break; case UP_DEVICE_KIND_BATTERY: /* TRANSLATORS: laptop primary battery */ text = tr("Laptop battery"); break; case UP_DEVICE_KIND_UPS: /* TRANSLATORS: battery-backed AC power source */ text = tr("UPS"); break; case UP_DEVICE_KIND_MONITOR: /* TRANSLATORS: a monitor is a device to measure voltage and current */ text = tr("Monitor"); break; case UP_DEVICE_KIND_MOUSE: /* TRANSLATORS: wireless mice with internal batteries */ text = tr("Mouse"); break; case UP_DEVICE_KIND_KEYBOARD: /* TRANSLATORS: wireless keyboard with internal battery */ text = tr("Keyboard"); break; case UP_DEVICE_KIND_PDA: /* TRANSLATORS: portable device */ text = tr("PDA"); break; case UP_DEVICE_KIND_PHONE: /* TRANSLATORS: cell phone (mobile...) */ text = tr("Cell phone"); break; case UP_DEVICE_KIND_MEDIA_PLAYER: /* TRANSLATORS: media player, mp3 etc */ text = tr("Media player"); break; case UP_DEVICE_KIND_TABLET: /* TRANSLATORS: tablet device */ text = tr("Tablet"); break; case UP_DEVICE_KIND_COMPUTER: /* TRANSLATORS: tablet device */ text = tr("Computer"); break; default: printf ("enum unrecognised: %i", kind); text = tr ("unrecognised"); } return text; } QString EngineDevice::engine_get_device_icon_index (qreal percentage) { if (percentage < 10) return "10"; else if (percentage < 20) return "20"; else if (percentage < 30) return "30"; else if (percentage < 40) return "40"; else if (percentage < 50) return "50"; else if (percentage < 60) return "60"; else if (percentage < 70) return "70"; else if (percentage < 80) return "80"; else if (percentage < 90) return "90"; return "100"; } /** * engine_get_device_icon: * **/ QString EngineDevice::engine_get_device_icon (DEVICE *device) { QString prefix; QString index_str; UpDeviceKind kind; UpDeviceState state; bool is_present; QString result; qreal percentage; kind = device->m_dev.kind; state = device->m_dev.State; percentage = device->m_dev.Percentage; is_present = device->m_dev.IsPresent; /* get correct icon prefix */ prefix = engine_kind_to_string (kind); /* get the icon from some simple rules */ if (kind == UP_DEVICE_KIND_LINE_POWER) { result = ("gpm-ac-adapter"); } else if (kind == UP_DEVICE_KIND_MONITOR) { result = ("gpm-monitor"); } else if (kind == UP_DEVICE_KIND_UPS) { if (!is_present) { /* battery missing */ result.sprintf ("gpm-%s-missing", prefix.toStdString().c_str()); } else if (state == UP_DEVICE_STATE_FULLY_CHARGED) { result.sprintf ("gpm-%s-100", prefix.toStdString().c_str()); } else if (state == UP_DEVICE_STATE_CHARGING) { index_str = engine_get_device_icon_index (percentage); result = QString("gpm-%1-%2-charging").arg(prefix).arg(index_str); } else if (state == UP_DEVICE_STATE_DISCHARGING) { index_str = engine_get_device_icon_index (percentage); result = QString("gpm-%1-%2").arg(prefix).arg(index_str); } } else if (kind == UP_DEVICE_KIND_BATTERY) { if (!is_present) { /* battery missing: battery-missing-symbolic*/ result = QString ("%1-missing-symbolic").arg(prefix); } else if (state == UP_DEVICE_STATE_EMPTY) { /* battery-empty-symbolic */ result = QString ("%1-empty-symbolic").arg(prefix); } else if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* battery-full-charged-symbolic */ /* battery-full-charged-symbolic */ // result = QString("%1-full-charged-symbolic").arg(prefix); index_str = engine_get_device_icon_index(percentage); /* battery-level-percent-charging-symbolic */ result = QString("%1-level-%2-charging-symbolic").arg(prefix). arg(index_str); //result = QString ("%1-full-charged-symbolic").arg(prefix); } else if (state == UP_DEVICE_STATE_CHARGING) { index_str = engine_get_device_icon_index (percentage); /* battery-level-percent-charging-symbolic */ result = QString("%1-level-%2-charging-symbolic").arg(prefix).arg(index_str); } else if (state == UP_DEVICE_STATE_DISCHARGING) { index_str = engine_get_device_icon_index (percentage); result = QString("%1-level-%2-symbolic").arg(prefix).arg(index_str); } else if (state == UP_DEVICE_STATE_PENDING_CHARGE) { index_str = engine_get_device_icon_index (percentage); /* FIXME: do new grey icons */ result = QString("%1-level-%2-charging-symbolic").arg(prefix).arg(index_str); } else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) { index_str = engine_get_device_icon_index (percentage); result = QString("%1-level-%2-symbolic").arg(prefix).arg(index_str); } else { result = ("battery-missing-symbolic"); } } else if (kind == UP_DEVICE_KIND_MOUSE || kind == UP_DEVICE_KIND_KEYBOARD || kind == UP_DEVICE_KIND_PHONE) { if (!is_present) { /* battery missing */ result = QString ("gpm-%1-000").arg(prefix); } else if (state == UP_DEVICE_STATE_FULLY_CHARGED) { result = QString ("gpm-%1-100").arg(prefix); } else if (state == UP_DEVICE_STATE_DISCHARGING) { index_str = engine_get_device_icon_index (percentage); result = QString("gpm-%1-%2").arg(prefix).arg(index_str); } else if (state == UP_DEVICE_STATE_CHARGING) { index_str = engine_get_device_icon_index (percentage); result = QString("gpm-%1-%2-charging").arg(prefix).arg(index_str); } } /* nothing matched */ if (result.isNull()) { result = ("dialog-warning"); } return result; } QString EngineDevice::engine_get_dev_icon (DEV dev) { QString prefix; QString index_str; UpDeviceKind kind; UpDeviceState state; bool is_present; QString result; qreal percentage; kind = dev.kind; state = dev.State; percentage = dev.Percentage; is_present = dev.IsPresent; /* get correct icon prefix */ prefix = engine_kind_to_string (kind); if (kind == UP_DEVICE_KIND_BATTERY) { if (!is_present) { /* battery missing: battery-missing-symbolic*/ result = QString ("%1-missing-symbolic").arg(prefix); } else if (state == UP_DEVICE_STATE_EMPTY) { /* battery-empty-symbolic */ result = QString ("%1-empty-symbolic").arg(prefix); } else if (state == UP_DEVICE_STATE_FULLY_CHARGED) { /* battery-full-charged-symbolic */ result = QString ("%1-full-charged-symbolic").arg(prefix); } else if (state == UP_DEVICE_STATE_CHARGING) { index_str = engine_get_device_icon_index (percentage); /* battery-level-percent-charging-symbolic */ result = QString("%1-level-%2-charging-symbolic").arg(prefix).arg(index_str); } else if (state == UP_DEVICE_STATE_DISCHARGING) { index_str = engine_get_device_icon_index (percentage); result = QString("%1-level-%2-symbolic").arg(prefix).arg(index_str); } else if (state == UP_DEVICE_STATE_PENDING_CHARGE) { index_str = engine_get_device_icon_index (percentage); /* FIXME: do new grey icons */ result = QString("%1-level-%2-charging-symbolic").arg(prefix).arg(index_str); } else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) { index_str = engine_get_device_icon_index (percentage); result = QString("%1-level-%2-symbolic").arg(prefix).arg(index_str); } else { result = ("battery-missing-symbolic"); } } if (result.isNull()) { result = ("dialog-warning"); } return result; } /** * engine_get_warning: * **/ UpDeviceLevel EngineDevice::engine_get_warning (DEV dev) { UpDeviceKind kind; UpDeviceState state; UpDeviceLevel warning_type; /* get device properties */ kind = dev.kind; state = dev.State; /* default to no engine */ warning_type = UP_DEVICE_LEVEL_NONE; /* if the device in question is on ac, don't give a warning */ if (state == UP_DEVICE_STATE_CHARGING) goto out; /* If we have no important engines, we should test for discharging */ if (warning_type == UP_DEVICE_LEVEL_NONE) { if (state == UP_DEVICE_STATE_DISCHARGING) warning_type = UP_DEVICE_LEVEL_DISCHARGING; } out: return warning_type; } ukui-power-manager/ukui-power-manager-tray/xatom-helper.cpp0000644000175000017500000001374614205117452023036 0ustar fengfeng/* * KWin Style UKUI * * Copyright (C) 2020, KylinSoft 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 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, see . * * Authors: Yue Lan * */ #include "xatom-helper.h" #include #include #include #include static XAtomHelper *global_instance = nullptr; XAtomHelper *XAtomHelper::getInstance() { if (!global_instance) global_instance = new XAtomHelper; return global_instance; } bool XAtomHelper::isFrameLessWindow(int winId) { auto hints = getInstance()->getWindowMotifHint(winId); if (hints.flags == MWM_HINTS_DECORATIONS && hints.functions == 1) { return true; } return false; } bool XAtomHelper::isWindowDecorateBorderOnly(int winId) { return isWindowMotifHintDecorateBorderOnly(getInstance()->getWindowMotifHint(winId)); } bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint) { bool isDeco = false; if (hint.flags & MWM_HINTS_DECORATIONS && hint.flags != MWM_HINTS_DECORATIONS) { if (hint.decorations == MWM_DECOR_BORDER) isDeco = true; } return isDeco; } bool XAtomHelper::isUKUICsdSupported() { // fixme: return false; } bool XAtomHelper::isUKUIDecorationWindow(int winId) { if (m_ukuiDecorationAtion == None) return false; Atom type; int format; ulong nitems; ulong bytes_after; uchar *data; bool isUKUIDecoration = false; XGetWindowProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, 0, LONG_MAX, false, m_ukuiDecorationAtion, &type, &format, &nitems, &bytes_after, &data); if (type == m_ukuiDecorationAtion) { if (nitems == 1) { isUKUIDecoration = data[0]; } } return isUKUIDecoration; } UnityCorners XAtomHelper::getWindowBorderRadius(int winId) { UnityCorners corners; Atom type; int format; ulong nitems; ulong bytes_after; uchar *data; if (m_unityBorderRadiusAtom != None) { XGetWindowProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, 0, LONG_MAX, false, XA_CARDINAL, &type, &format, &nitems, &bytes_after, &data); if (type == XA_CARDINAL) { if (nitems == 4) { corners.topLeft = static_cast(data[0]); corners.topRight = static_cast(data[1*sizeof (ulong)]); corners.bottomLeft = static_cast(data[2*sizeof (ulong)]); corners.bottomRight = static_cast(data[3*sizeof (ulong)]); } XFree(data); } } return corners; } void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data) { if (m_unityBorderRadiusAtom == None) return; ulong corners[4] = {data.topLeft, data.topRight, data.bottomLeft, data.bottomRight}; XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof (corners)/sizeof (corners[0])); } void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight) { if (m_unityBorderRadiusAtom == None) return; ulong corners[4] = {(ulong)topLeft, (ulong)topRight, (ulong)bottomLeft, (ulong)bottomRight}; XChangeProperty(QX11Info::display(), winId, m_unityBorderRadiusAtom, XA_CARDINAL, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof (corners)/sizeof (corners[0])); } void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set) { if (m_ukuiDecorationAtion == None) return; XChangeProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, m_ukuiDecorationAtion, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &set, 1); } void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints) { if (m_unityBorderRadiusAtom == None) return; XChangeProperty(QX11Info::display(), winId, m_motifWMHintsAtom, m_motifWMHintsAtom, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *)&hints, sizeof (MotifWmHints)/ sizeof (ulong)); } MotifWmHints XAtomHelper::getWindowMotifHint(int winId) { MotifWmHints hints; if (m_unityBorderRadiusAtom == None) return hints; uchar *data; Atom type; int format; ulong nitems; ulong bytes_after; XGetWindowProperty(QX11Info::display(), winId, m_motifWMHintsAtom, 0, sizeof (MotifWmHints)/sizeof (long), false, AnyPropertyType, &type, &format, &nitems, &bytes_after, &data); if (type == None) { return hints; } else { hints = *(MotifWmHints *)data; XFree(data); } return hints; } XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent) { if (!QX11Info::isPlatformX11()) return; m_motifWMHintsAtom = XInternAtom(QX11Info::display(), "_MOTIF_WM_HINTS", true); m_unityBorderRadiusAtom = XInternAtom(QX11Info::display(), "_UNITY_GTK_BORDER_RADIUS", false); m_ukuiDecorationAtion = XInternAtom(QX11Info::display(), "_KWIN_UKUI_DECORAION", false); } Atom XAtomHelper::registerUKUICsdNetWmSupportAtom() { // fixme: return None; } void XAtomHelper::unregisterUKUICsdNetWmSupportAtom() { // fixme: } ukui-power-manager/ukui-power-manager-tray/mainwindow.cpp0000644000175000017500000000646114205117543022602 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "mainwindow.h" #include "powerwindow.h" #include #include #include #include #include #include #include #include #include #include #include #include #include MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent) { trayIcon = new QSystemTrayIcon(this); EngineDevice* ed; ed = EngineDevice::getInstance(); // connect(ed, SIGNAL(icon_changed(QString)), this,SLOT(IconChanged(QString))); QDBusConnection::sessionBus().connect(QString(),"/","org.ukui.upower", "BatteryIcon",this, SLOT(IconChanged(QString)) ); iface = new QDBusInterface("org.ukui.upower","/","org.ukui.upower",QDBusConnection::sessionBus()); connect(ed, SIGNAL(engine_signal_summary_change(QString)), this,SLOT(onSumChanged(QString))); initUi(); connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(onActivatedIcon(QSystemTrayIcon::ActivationReason))); } void MainWindow::onSumChanged(QString str){ trayIcon->setToolTip(str); } void MainWindow::IconChanged(QString str){ if (!str.isNull()) { QIcon icon = QIcon::fromTheme(str); trayIcon->setIcon(icon); trayIcon->show(); } else { trayIcon->hide(); } } void MainWindow::onActivatedIcon(QSystemTrayIcon::ActivationReason reason) { if (reason == 3){ powerWindow->set_window_position(); powerWindow->show(); } } void MainWindow::initUi() { setWindowFlags(Qt::FramelessWindowHint|Qt::Popup); setAttribute(Qt::WA_StyledBackground,true); setAttribute(Qt::WA_TranslucentBackground); menu = new QMenu(this); menu->setAttribute(Qt::WA_TranslucentBackground); trayIcon->setContextMenu(menu); QAction *pset_preference = new QAction(menu); QIcon icon = QIcon::fromTheme("document-page-setup-symbolic"); pset_preference->setIcon(icon); pset_preference->setText(tr("SetPower")); QDBusReply reply = iface->call("IconName"); qDebug()<addAction(pset_preference); powerWindow = new powerwindow(); powerWindow->hide(); } void MainWindow::set_preference_func() { QProcess::startDetached(QString("ukui-control-center -p &")); } MainWindow::~MainWindow() { delete powerWindow; delete menu; delete trayIcon; delete iface; } ukui-power-manager/ukui-power-manager-tray/xatom-helper.h0000644000175000017500000000624314205117452022475 0ustar fengfeng/* * KWin Style UKUI * * Copyright (C) 2020, KylinSoft 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 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, see . * * Authors: Yue Lan * */ #ifndef XATOMHELPER_H #define XATOMHELPER_H #include #include struct UnityCorners { ulong topLeft = 0; ulong topRight = 0; ulong bottomLeft = 0; ulong bottomRight = 0; }; typedef struct { ulong flags = 0; ulong functions = 0; ulong decorations = 0; long input_mode = 0; ulong status = 0; } MotifWmHints, MwmHints; #define MWM_HINTS_FUNCTIONS (1L << 0) #define MWM_HINTS_DECORATIONS (1L << 1) #define MWM_HINTS_INPUT_MODE (1L << 2) #define MWM_HINTS_STATUS (1L << 3) #define MWM_FUNC_ALL (1L << 0) #define MWM_FUNC_RESIZE (1L << 1) #define MWM_FUNC_MOVE (1L << 2) #define MWM_FUNC_MINIMIZE (1L << 3) #define MWM_FUNC_MAXIMIZE (1L << 4) #define MWM_FUNC_CLOSE (1L << 5) #define MWM_DECOR_ALL (1L << 0) #define MWM_DECOR_BORDER (1L << 1) #define MWM_DECOR_RESIZEH (1L << 2) #define MWM_DECOR_TITLE (1L << 3) #define MWM_DECOR_MENU (1L << 4) #define MWM_DECOR_MINIMIZE (1L << 5) #define MWM_DECOR_MAXIMIZE (1L << 6) #define MWM_INPUT_MODELESS 0 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 #define MWM_INPUT_SYSTEM_MODAL 2 #define MWM_INPUT_FULL_APPLICATION_MODAL 3 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL #define MWM_TEAROFF_WINDOW (1L<<0) namespace UKUI { class Decoration; } class XAtomHelper : public QObject { friend class UKUI::Decoration; Q_OBJECT public: static XAtomHelper *getInstance(); static bool isFrameLessWindow(int winId); bool isWindowDecorateBorderOnly(int winId); bool isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint); bool isUKUICsdSupported(); bool isUKUIDecorationWindow(int winId); UnityCorners getWindowBorderRadius(int winId); void setWindowBorderRadius(int winId, const UnityCorners &data); void setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight); void setUKUIDecoraiontHint(int winId, bool set = true); void setWindowMotifHint(int winId, const MotifWmHints &hints); MotifWmHints getWindowMotifHint(int winId); private: explicit XAtomHelper(QObject *parent = nullptr); Atom registerUKUICsdNetWmSupportAtom(); void unregisterUKUICsdNetWmSupportAtom(); Atom m_motifWMHintsAtom = None; Atom m_unityBorderRadiusAtom = None; Atom m_ukuiDecorationAtion = None; }; #endif // XATOMHELPER_H ukui-power-manager/ukui-power-manager-tray/ukui-power-manager-tray.pro0000644000175000017500000000471114205117543025134 0ustar fengfeng#------------------------------------------------- # # Project created by QtCreator 2020-01-06T10:55:07 # #------------------------------------------------- QT += core gui dbus KWindowSystem x11extras greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = ukui-power-manager-tray TEMPLATE = app target.path = /usr/bin INSTALLS += target # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 TRANSLATIONS+=\ translations/ukui-power-manager-tray_bo.ts \ translations/ukui-power-manager-tray_zh_CN.ts \ translations/ukui-power-manager-tray_tr.ts QM_FILES_INSTALL_PATH = /usr/share/ukui-power-manager/tray/translations/ # CONFIG += lrelase not work for qt5.6, add those from lrelease.prf for compatibility qtPrepareTool(QMAKE_LRELEASE, lrelease) lrelease.name = lrelease lrelease.input = TRANSLATIONS lrelease.output = ${QMAKE_FILE_IN_BASE}.qm lrelease.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_OUT} lrelease.CONFIG = no_link QMAKE_EXTRA_COMPILERS += lrelease PRE_TARGETDEPS += compiler_lrelease_make_all for (translation, TRANSLATIONS) { translation = $$basename(translation) QM_FILES += $$OUT_PWD/$$replace(translation, \\..*$, .qm) } qm_files.files = $$QM_FILES qm_files.path = $$QM_FILES_INSTALL_PATH qm_files.CONFIG = no_check_exist INSTALLS += qm_files # So we can access it from main.cpp DEFINES += QM_FILES_INSTALL_PATH='\\"$${QM_FILES_INSTALL_PATH}\\"' LIBS += -lukui-log4qt CONFIG += c++11 no_keywords link_pkgconfig PKGCONFIG += gsettings-qt x11 SOURCES += \ device.cpp \ enginedevice.cpp \ main.cpp \ powertray.cpp \ powerwindow.cpp \ xatom-helper.cpp HEADERS += \ device.h \ engine_common.h \ enginedevice.h \ powertray.h \ powerwindow.h \ xatom-helper.h FORMS += desktop.files += resources/ukui-power-manager-tray.desktop desktop.path = /etc/xdg/autostart/ INSTALLS += desktop # Default rules for deployment. ukui-power-manager/ukui-power-manager-tray/powertray.cpp0000644000175000017500000001072714205117543022462 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "powertray.h" #include "powerwindow.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kwindowsystem.h" PowerTray::PowerTray(QObject *parent) : QObject(parent) { iface = new QDBusInterface("org.ukui.upower", "/", "org.ukui.upower", QDBusConnection::sessionBus()); while (!iface->isValid()) { QThread::sleep(1); iface = new QDBusInterface("org.ukui.upower", "/", "org.ukui.upower", QDBusConnection::sessionBus()); } QDBusPendingReply reply = iface->call("DaemonVersion"); reply.waitForFinished(); if (reply.isValid()) { qDebug() << "upower version is:" << reply.isValid() ; } else { qDebug() << "upower version get error!"; } } void PowerTray::initPowerTray() { trayIcon = new QSystemTrayIcon(this); EngineDevice *ed; ed = EngineDevice::getInstance(); QDBusConnection::sessionBus().connect( QString(), "/", "org.ukui.upower", "BatteryIcon", this, SLOT(IconChanged(QString))); connect(ed, SIGNAL(engine_signal_summary_change(QString)), this, SLOT(onSumChanged(QString))); initUi(); connect( trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onActivatedIcon(QSystemTrayIcon::ActivationReason))); } QString PowerTray::getMachineType() { QDBusReply reply = iface->call("MachineType"); if (reply.isValid()) { if ("book" == reply.value()) { qDebug() << "book"; return "book"; } else { qDebug() << "pc"; return "pc"; } } else { qDebug() << "upower error"; return "upower error"; } } void PowerTray::onSumChanged(QString str) { trayIcon->setToolTip(str); } void PowerTray::IconChanged(QString str) { if (!str.isNull()) { QIcon icon = QIcon::fromTheme(str); trayIcon->setIcon(icon); trayIcon->show(); } else { trayIcon->hide(); } } void PowerTray::onActivatedIcon(QSystemTrayIcon::ActivationReason reason) { if (reason == 3) { if (powerWindow->isVisible()) { powerWindow->hide(); return; } powerWindow->set_window_position(); powerWindow->show(); KWindowSystem::setState(powerWindow->winId(), NET::SkipTaskbar | NET::SkipPager); } } void PowerTray::initUi() { menu = new QMenu(); menu->setAttribute(Qt::WA_TranslucentBackground); trayIcon->setContextMenu(menu); QAction *pset_preference = new QAction(menu); QIcon icon = QIcon::fromTheme("document-page-setup-symbolic"); pset_preference->setIcon(icon); pset_preference->setText(tr("SetPower")); QDBusReply reply = iface->call("IconName"); qDebug() << reply.value(); IconChanged(reply.value()); connect(pset_preference, &QAction::triggered, this, &PowerTray::set_preference_func); menu->addAction(pset_preference); powerWindow = new powerwindow(); powerWindow->hide(); } void PowerTray::set_preference_func() { QProcess process; process.start( "bash", QStringList() << "-c" << "dpkg -l | grep ukui-control-center"); process.waitForFinished(); QString strResult = process.readAllStandardOutput() + process.readAllStandardError(); if (-1 != strResult.indexOf("3.0")) { QProcess::startDetached(QString("ukui-control-center -p")); } else { QProcess::startDetached(QString("ukui-control-center -m Power")); } } PowerTray::~PowerTray() { delete powerWindow; delete menu; delete trayIcon; delete iface; } ukui-power-manager/ukui-power-manager-tray/resources/0000755000175000017500000000000014205117452021724 5ustar fengfengukui-power-manager/ukui-power-manager-tray/resources/ukui-power-manager-tray.desktop0000644000175000017500000000064314205117452030016 0ustar fengfeng[Desktop Entry] _Name=Power Manager Tray Name[zh_CN]=电源管理程序 _Comment=Power management tray Icon=ukui-power-manager Exec=ukui-power-manager-tray Terminal=false Type=Application NoDisplay=true Categories= OnlyShowIn=UKUI; X-UKUI-Bugzilla-Bugzilla=UKUI X-UKUI-Bugzilla-Product=ukui-power-manager-tray X-UKUI-Bugzilla-Component=ukui-power-manager-tray X-UKUI-Bugzilla-Version=@VERSION@ X-UKUI-AutoRestart=true ukui-power-manager/ukui-power-manager-tray/engine_common.h0000644000175000017500000001677314205117452022716 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef ENGINECOMMON_H #define ENGINECOMMON_H #define GPM_DBUS_SERVICE "org.ukui.PowerManager" #define GPM_DBUS_INTERFACE "org.ukui.PowerManager" #define GPM_DBUS_INTERFACE_BACKLIGHT "org.ukui.PowerManager.Backlight" #define GPM_DBUS_INTERFACE_KBD_BACKLIGHT "org.ukui.PowerManager.KbdBacklight" #define GPM_DBUS_PATH "/org/ukui/PowerManager" #define GPM_DBUS_PATH_BACKLIGHT "/org/ukui/PowerManager/Backlight" #define GPM_DBUS_PATH_KBD_BACKLIGHT "/org/ukui/PowerManager/KbdBacklight" /* common descriptions of this program */ #define GPM_NAME _("Power Manager") #define GPM_DESCRIPTION _("Power Manager for the MATE desktop") /* schema location */ #define GPM_SETTINGS_SCHEMA "org.ukui.power-manager" #define GPM_SETTINGS_KEY_POLICY "icon-policy" /* actions */ #define GPM_SETTINGS_ACTION_CRITICAL_UPS "action-critical-ups" #define GPM_SETTINGS_ACTION_CRITICAL_BATT "action-critical-battery" #define GPM_SETTINGS_ACTION_LOW_UPS "action-low-ups" #define GPM_SETTINGS_ACTION_SLEEP_TYPE_AC "action-sleep-type-ac" #define GPM_SETTINGS_ACTION_SLEEP_TYPE_BATT "action-sleep-type-battery" #define GPM_SETTINGS_SLEEP_WHEN_CLOSED "event-when-closed-battery" /* backlight stuff */ #define GPM_SETTINGS_BACKLIGHT_ENABLE "backlight-enable" #define GPM_SETTINGS_BACKLIGHT_BATTERY_REDUCE "backlight-battery-reduce" #define GPM_SETTINGS_DPMS_METHOD_AC "dpms-method-ac" #define GPM_SETTINGS_DPMS_METHOD_BATT "dpms-method-battery" #define GPM_SETTINGS_IDLE_BRIGHTNESS "idle-brightness" #define GPM_SETTINGS_IDLE_DIM_AC "idle-dim-ac" #define GPM_SETTINGS_IDLE_DIM_BATT "idle-dim-battery" #define GPM_SETTINGS_IDLE_DIM_TIME "idle-dim-time" #define GPM_SETTINGS_BRIGHTNESS_AC "brightness-ac" #define GPM_SETTINGS_BRIGHTNESS_BAT "brightness-bat" #define GPM_SETTINGS_BRIGHTNESS_DIM_BATT "brightness-dim-battery" /* keyboard backlight */ #define GPM_SETTINGS_KBD_BACKLIGHT_BATT_REDUCE "kbd-backlight-battery-reduce" #define GPM_SETTINGS_KBD_BRIGHTNESS_ON_AC "kbd-brightness-on-ac" #define GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_BATT "kbd-brightness-dim-by-on-battery" #define GPM_SETTINGS_KBD_BRIGHTNESS_DIM_BY_ON_IDLE "kbd-brightness-dim-by-on-idle" /* buttons */ #define GPM_SETTINGS_BUTTON_LID_AC "button-lid-ac" #define GPM_SETTINGS_BUTTON_LID_BATT "button-lid-battery" #define GPM_SETTINGS_BUTTON_SUSPEND "button-suspend" #define GPM_SETTINGS_BUTTON_HIBERNATE "button-hibernate" #define GPM_SETTINGS_BUTTON_POWER "button-power" /* general */ #define GPM_SETTINGS_USE_TIME_POLICY "use-time-for-policy" #define GPM_SETTINGS_NETWORKMANAGER_SLEEP "network-sleep" #define GPM_SETTINGS_IDLE_CHECK_CPU "check-type-cpu" /* notify */ #define GPM_SETTINGS_NOTIFY_LOW_CAPACITY "notify-low-capacity" #define GPM_SETTINGS_NOTIFY_DISCHARGING "notify-discharging" #define GPM_SETTINGS_NOTIFY_FULLY_CHARGED "notify-fully-charged" #define GPM_SETTINGS_NOTIFY_SLEEP_FAILED "notify-sleep-failed" #define GPM_SETTINGS_NOTIFY_SLEEP_FAILED_URI "notify-sleep-failed-uri" #define GPM_SETTINGS_NOTIFY_LOW_POWER "notify-low-power" #define GPM_SETTINGS_BAT_POLICY "power-policy-battery" #define GPM_SETTINGS_ON_BAT_AUTO_SAVE "on-battery-auto-save" #define GPM_SETTINGS_LOW_BAT_AUTO_SAVE "low-battery-auto-save" #define GPM_SETTINGS_DISPLAY_LEFT_TIME "dispaly-left-time-of-charge-and-discharge" /* thresholds */ #define GPM_SETTINGS_PERCENTAGE_LOW "percentage-low" #define GPM_SETTINGS_PERCENTAGE_CRITICAL "percentage-critical" #define GPM_SETTINGS_PERCENTAGE_ACTION "percentage-action" #define GPM_SETTINGS_TIME_LOW "time-low" #define GPM_SETTINGS_TIME_CRITICAL "time-critical" #define GPM_SETTINGS_TIME_ACTION "time-action" /* timeout */ #define GPM_SETTINGS_SLEEP_COMPUTER_AC "sleep-computer-ac" #define GPM_SETTINGS_SLEEP_COMPUTER_BATT "sleep-computer-battery" #define GPM_SETTINGS_SLEEP_COMPUTER_UPS "sleep-computer-ups" #define GPM_SETTINGS_SLEEP_DISPLAY_AC "sleep-display-ac" #define GPM_SETTINGS_SLEEP_DISPLAY_BATT "sleep-display-battery" #define GPM_SETTINGS_SLEEP_DISPLAY_UPS "sleep-display-ups" /* ui */ #define GPM_SETTINGS_ICON_POLICY "icon-policy" #define GPM_SETTINGS_ENABLE_SOUND "enable-sound" #define GPM_SETTINGS_SHOW_ACTIONS "show-actions" /* statistics */ #define GPM_SETTINGS_INFO_HISTORY_TIME "info-history-time" #define GPM_SETTINGS_INFO_HISTORY_TYPE "info-history-type" #define GPM_SETTINGS_INFO_HISTORY_GRAPH_SMOOTH "info-history-graph-smooth" #define GPM_SETTINGS_INFO_HISTORY_GRAPH_POINTS "info-history-graph-points" #define GPM_SETTINGS_INFO_STATS_TYPE "info-stats-type" #define GPM_SETTINGS_INFO_STATS_GRAPH_SMOOTH "info-stats-graph-smooth" #define GPM_SETTINGS_INFO_STATS_GRAPH_POINTS "info-stats-graph-points" #define GPM_SETTINGS_INFO_PAGE_NUMBER "info-page-number" #define GPM_SETTINGS_INFO_LAST_DEVICE "info-last-device" #if __aarch64__ #define ARCH64 TRUE #else #define ARCH64 FALSE #endif typedef enum { GPM_ICON_POLICY_ALWAYS, GPM_ICON_POLICY_PRESENT, GPM_ICON_POLICY_CHARGE, GPM_ICON_POLICY_LOW, GPM_ICON_POLICY_CRITICAL, GPM_ICON_POLICY_NEVER } GpmIconPolicy; typedef enum { GPM_ACTION_POLICY_BLANK, GPM_ACTION_POLICY_SUSPEND, GPM_ACTION_POLICY_SHUTDOWN, GPM_ACTION_POLICY_HIBERNATE, GPM_ACTION_POLICY_INTERACTIVE, GPM_ACTION_POLICY_NOTHING } GpmActionPolicy; typedef enum { UP_DEVICE_KIND_UNKNOWN, UP_DEVICE_KIND_LINE_POWER, UP_DEVICE_KIND_BATTERY, UP_DEVICE_KIND_UPS, UP_DEVICE_KIND_MONITOR, UP_DEVICE_KIND_MOUSE, UP_DEVICE_KIND_KEYBOARD, UP_DEVICE_KIND_PDA, UP_DEVICE_KIND_PHONE, UP_DEVICE_KIND_MEDIA_PLAYER, UP_DEVICE_KIND_TABLET, UP_DEVICE_KIND_COMPUTER, UP_DEVICE_KIND_LAST } UpDeviceKind; /** * UpDeviceState: * * The device state. **/ typedef enum { UP_DEVICE_STATE_UNKNOWN, UP_DEVICE_STATE_CHARGING, UP_DEVICE_STATE_DISCHARGING, UP_DEVICE_STATE_EMPTY, UP_DEVICE_STATE_FULLY_CHARGED, UP_DEVICE_STATE_PENDING_CHARGE, UP_DEVICE_STATE_PENDING_DISCHARGE, UP_DEVICE_STATE_LAST } UpDeviceState; /** * UpDeviceTechnology: * * The device technology. **/ typedef enum { UP_DEVICE_TECHNOLOGY_UNKNOWN, UP_DEVICE_TECHNOLOGY_LITHIUM_ION, UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER, UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE, UP_DEVICE_TECHNOLOGY_LEAD_ACID, UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM, UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE, UP_DEVICE_TECHNOLOGY_LAST } UpDeviceTechnology; /** * UpDeviceLevel: * * The warning level of a battery. **/ typedef enum { UP_DEVICE_LEVEL_UNKNOWN, UP_DEVICE_LEVEL_NONE, UP_DEVICE_LEVEL_DISCHARGING, UP_DEVICE_LEVEL_LOW, UP_DEVICE_LEVEL_CRITICAL, UP_DEVICE_LEVEL_ACTION, UP_DEVICE_LEVEL_LAST } UpDeviceLevel; #endif // ENGINECOMMON_H ukui-power-manager/ukui-power-manager-tray/translations/0000755000175000017500000000000014205117543022434 5ustar fengfengukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_zh_CN.qm0000644000175000017500000000604614205117543030556 0ustar fengfengu5 (%2%)%1 waiting to discharge (%2%) EngineDevice %1%Su( %1% available EngineDevice%1%Su( ]QEn%1% available, charged EngineDeviceNmAu5nMVh AC adapter EngineDevicebKg: Cell phone EngineDeviceComputer EngineDevice.vKeyboard EngineDevice {g,u5l`Laptop battery EngineDevice$RiOY %1\e %2R (%3%)Left %1h %2m (%3%) EngineDeviceRiOY%1\e%2RQEnLeft %1h %2m to full EngineDevice Media player EngineDeviceMonitor EngineDevice hMouse EngineDeviceN No EngineDevicePDA EngineDeviceTablet EngineDeviceUPS EngineDeviceg*w Unknown time EngineDevicef/Yes EngineDevicekcW(QEu5 (%1%)charging (%1%) EngineDevice\ehour EngineDevice\ehours EngineDeviceRminute EngineDeviceRminutes EngineDeviceN no EngineDeviceg*R+ unrecognised EngineDevicef/yes EngineDevicenu5nTwaw SetPower PowerTrayS:kcW(QEu5Charging powerwindowkcW(e>u5 Discharging powerwindowRiOY %1\e %2RLeft %1h %2m powerwindow u5n{tVh Power Manager powerwindowu5l`kcW(QEu5N-battery is charging powerwindowu5_ON QEu5'battery is critical low,please plug in! powerwindowu5l`kcW(e>u5N-battery is discharging powerwindowu5sW(]~QEnbattery is fullly charged powerwindowu5l4^sON SeQEu5$battery is low, please plug in power powerwindowQEu5wcharge notification powerwindowu5_ONcritical battery notification powerwindowe>u5wdischarged notification powerwindow QEnu5wfullly charged notification powerwindow]QEnu5 fully charged powerwindow ONu5ϐwlow battery notification powerwindowONu5dO\woperation notification powerwindow|~\bgLnvdO\performing low power operation powerwindowu5nnPowerSet settinglabelukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_zh_CN.ts0000644000175000017500000003704214205117543030567 0ustar fengfeng DeviceForm RemainTime 预计剩余时间 DeviceWidget RemainTime 预计剩余时间 EngineDevice yes no Yes No Unknown time 未知 minute 分钟 minutes 分钟 hour 小时 hours 小时 fully charged 已充满 not charging 未充电 %1% available, charged %1%可用,已充满 %1% available, not charging %1%可用,未充电 %1% available, charging %1%可用,正在充电 %1 waiting to discharge (%2%) %1 等待放电 (%2%) %1 waiting to charge (%2%) %1 等待充电 (%2%) discharging(%1%) 放电(%1%) charging(%1%) 充电(%1%) AC adapter 交流电源适配器 Laptop battery 笔记本电池 UPS Monitor Mouse 鼠标 Keyboard 键盘 PDA Cell phone 手机 Media player Tablet Computer unrecognised 未识别 charging 正在充电 Left %1h %2m (%3%) 剩余 %1小时 %2分钟 (%3%) %1% available %1%可用 Left %1h %2m to full 剩余%1小时%2分钟充满 charging (%1%) 正在充电 (%1%) discharging 放电 empty 电量空 fully 电量满 other 其他 MainWindow SetPower 设置电源和睡眠 ShowPercentage 显示百分比 SetBrightness 调整亮度 discharge notify notification 正在放电 discharged notification 放电通知 battery is discharging! 电池正在放电中 fullly charged notification 充满电通知 battery is fullly charged! 电池已经充满 low battery notification 低电量通知 battery is low,please plug in! 电量低,请充电 critical battery notification 电量很低 battery is critical low,please plug in! 电量很低,请充电 very low battery notification 电量非常低 battery is very low,please plug in! 电量即将耗尽! PowerManagement 电源管理 charge notification 充电通知 battery is charging 电池正在充电中 battery is discharging 电池正在放电中 battery is fullly charged 电量已经充满 电量现在已经充满 battery is low, please plug in power 电量水平低,请插入电源 operation notification 低电量操作通知 performing low power operation 系统将执行设置的操作 Stats Statistics 电源统计 PowerManager 电源管理 PowerStatistics 电源统计 PowerSaveMode 省电模式 BatterySave 电池养护 Brightness 亮度 PowerTray SetPower 设置电源和睡眠 S: tablet device powerwindow Charging 正在充电 Left %1h %2m 剩余 %1小时 %2分钟 Discharging 正在放电 fully charged 已充满电 Left %1h %2m 剩余 %1小时 %2分钟 PowerManagement 电源管理 Power Manager 电源管理器 charge notification 充电通知 battery is charging 电池正在充电中 discharged notification 放电通知 battery is discharging 电池正在放电中 fullly charged notification 充满电通知 battery is fullly charged 电量现在已经充满 low battery notification 低电量通知 battery is low, please plug in power 电量水平低,请及时充电 critical battery notification 电量很低 battery is critical low,please plug in! 电量很低,请充电 operation notification 低电量操作通知 performing low power operation 系统将执行设置的操作 settinglabel PowerSet 电源设置 ukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_bo.ts0000644000175000017500000002314414205117543030164 0ustar fengfeng EngineDevice yes no Yes No Unknown time minute minutes hour hours Left %1h %2m (%3%) charging (%1%) AC adapter %1% available, charged %1% available Left %1h %2m to full %1 waiting to discharge (%2%) %1 waiting to charge (%2%) Laptop battery UPS Monitor Mouse Keyboard PDA Cell phone Media player Tablet Computer unrecognised PowerTray SetPower S: tablet device powerwindow Charging Left %1h %2m Discharging fully charged Power Manager charge notification battery is charging discharged notification battery is discharging fullly charged notification battery is fullly charged low battery notification battery is low, please plug in power critical battery notification battery is critical low,please plug in! operation notification performing low power operation settinglabel PowerSet ukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_tr.ts0000644000175000017500000003427614205117543030221 0ustar fengfeng DeviceForm RemainTime 预计剩余时间 DeviceWidget RemainTime 预计剩余时间 EngineDevice yes no Yes No Unknown time 未知 minute 分钟 minutes 分钟 hour 小时 hours 小时 fully charged 已充满 not charging 未充电 %1% available, charged %1%可用,已充满 %1% available, not charging %1%可用,未充电 %1% available, charging %1%可用,正在充电 %1 waiting to discharge (%2%) %1 等待放电 (%2%) %1 waiting to charge (%2%) %1 等待充电 (%2%) discharging(%1%) 放电(%1%) charging(%1%) 充电(%1%) AC adapter 交流电源适配器 Laptop battery 笔记本电池 UPS Monitor Mouse 鼠标 Keyboard 键盘 PDA Cell phone 手机 Media player Tablet Computer unrecognised 未识别 charging 正在充电 Left %1h %2m (%3%) %1% available Left %1h %2m to full charging (%1%) discharging 放电 empty 电量空 fully 电量满 other 其他 MainWindow SetPower 设置电源和睡眠 ShowPercentage 显示百分比 SetBrightness 调整亮度 discharge notify notification 正在放电 battery is discharging! 电池正在放电 fullly charged notification 电池充满 battery is fullly charged! 电池已经充满 low battery notification 电量低 battery is low,please plug in! 电量低,请充电 critical battery notification 电量很低 battery is critical low,please plug in! 电量很低,请充电 very low battery notification 电量非常低 battery is very low,please plug in! 电量即将耗尽! PowerManagement 电源管理 Stats Statistics 电源统计 PowerManager 电源管理 PowerStatistics 电源统计 PowerSaveMode 省电模式 BatterySave 电池养护 Brightness 亮度 PowerTray SetPower 设置电源和睡眠 S: tablet device powerwindow Charging Left %1h %2m Discharging fully charged 已充满 PowerManagement 电源管理 Power Manager charge notification battery is charging discharged notification battery is discharging fullly charged notification 电池充满 battery is fullly charged low battery notification 电量低 battery is low, please plug in power critical battery notification 电量很低 battery is critical low,please plug in! 电量很低,请充电 operation notification performing low power operation settinglabel PowerSet ukui-power-manager/ukui-power-manager-tray/powerwindow.cpp0000755000175000017500000004472714205117543023024 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "powerwindow.h" #include "enginedevice.h" #include "xatom-helper.h" #include "qdesktopwidget.h" #include #include #include #define PANEL_DBUS_SERVICE "com.ukui.panel.desktop" #define PANEL_DBUS_PATH "/" #define PANEL_DBUS_INTERFACE "com.ukui.panel.desktop" #define UKUI_PANEL_SETTING "org.ukui.panel.settings" #define ORG_UKUI_STYLE "org.ukui.style" #define STYLE_NAME "styleName" #define SYSTEM_FONT_SIZE "systemFontSize" #define DBUS_NAME "org.ukui.SettingsDaemon" #define DBUS_PATH "/org/ukui/SettingsDaemon/wayland" #define MARGIN 4 #define TRANSPARENCY_SETTINGS "org.ukui.control-center.personalise" #define TRANSPARENCY_KEY "transparency" powerwindow::powerwindow(QWidget *parent) : QWidget(parent) { m_iface = new QDBusInterface("org.ukui.upower", "/", "org.ukui.upower", QDBusConnection::sessionBus()); initgsetting(); m_IconBatterChangeList << KYLIN_BATTERY_CHARGING0_PATH1 << KYLIN_BATTERY_CHARGING10_PATH1 << KYLIN_BATTERY_CHARGING20_PATH1 << KYLIN_BATTERY_CHARGING30_PATH1 << KYLIN_BATTERY_CHARGING40_PATH1 << KYLIN_BATTERY_CHARGING50_PATH1 << KYLIN_BATTERY_CHARGING60_PATH1 << KYLIN_BATTERY_CHARGING70_PATH1 << KYLIN_BATTERY_CHARGING80_PATH1 << KYLIN_BATTERY_CHARGING90_PATH1 << KYLIN_BATTERY_CHARGING100_PATH1 << KYLIN_BATTERY_00_PATH1; ed = EngineDevice::getInstance(); connect(ed, SIGNAL(engine_signal_charge(DEV)), this, SLOT(charge_notify(DEV))); connect(ed, SIGNAL(engine_signal_discharge(DEV)), this, SLOT(discharge_notify(DEV))); connect(ed, SIGNAL(engine_signal_fullycharge(DEV)), this, SLOT(full_charge_notify(DEV))); connect(ed, SIGNAL(engine_signal_charge_low(DEV)), this, SLOT(low_battery_notify(DEV))); connect(ed, SIGNAL(engine_signal_charge_critical(DEV)), this, SLOT(critical_battery_notify(DEV))); connect(ed, SIGNAL(engine_signal_charge_action(DEV)), this, SLOT(action_battery_notify(DEV))); // connect(ed, SIGNAL(icon_changed(QString)), this,SLOT(IconChanged(QString))); QDBusConnection::sessionBus().connect( QString(), "/", "org.ukui.upower", "BatteryIcon", this, SLOT(IconChanged(QString))); setWindowProperty(); //设置窗口属性 initUI(); //初始化UI set_window_position(); //设置出现在屏幕的位置以及大小 watchTranspartency(); // ed->engine_policy_settings_cb("iconPolicy"); ed->engine_recalculate_summary(); connect(QApplication::desktop(), &QDesktopWidget::resized, this, [=]() { QTimer::singleShot(1000, this, [=]() { set_window_position(); }); }); connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &powerwindow::set_window_position); connect(qApp, &QApplication::primaryScreenChanged, this, &powerwindow::set_window_position); installEventFilter(this); } powerwindow::~powerwindow() { delete m_pmainlayout; delete m_firstlayout; delete lastlayout; delete m_firstwidget; delete iconButton; delete percentageLabel; delete powerStateLabel; delete powerTimeToEmpty; delete line; delete settingLabel; delete transparency_gsettings; } void powerwindow::setWindowProperty() { //设置任务栏无显示 setWindowFlags(Qt::FramelessWindowHint); // setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); setWindowOpacity(1); setAttribute(Qt::WA_TranslucentBackground); //设置窗口背景透明 setProperty("useSystemStyleBlur", true); //设置毛玻璃效果 setProperty("useStyleWindowManager", false); this->setFixedSize(360, 300); } void powerwindow::initUI() { KWindowEffects::enableBlurBehind(this->winId(), true); // 添加窗管协议 MotifWmHints hints; hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; hints.functions = MWM_FUNC_ALL; hints.decorations = MWM_DECOR_BORDER; XAtomHelper::getInstance()->setWindowMotifHint(this->winId(), hints); m_pmainlayout = new QVBoxLayout(); m_firstlayout = new QHBoxLayout(this); // m_statelayout = new QHBoxLayout(); lastlayout = new QHBoxLayout(); m_firstwidget = new QWidget(); // m_statewidget = new QWidget(); lastWidget = new QWidget(); iconButton = new QPushButton(); percentageLabel = new QLabel(); powerStateLabel = new QLabel(); powerStateLabel->setText(tr("Charging")); powerStateLabel->setVisible(false); powerTimeToEmpty = new QLabel(); powerTimeToEmpty->setVisible(true); line = new m_PartLineWidget(); line->setFixedSize(340, 2); get_power_list(); this->setFixedSize(360, 192 + deviceNum * 65); //电源设置按钮 settingLabel = new settinglabel(); connect(settingLabel, &settinglabel::labelclick, this, &powerwindow::set_preference_func); //第一行布局 m_firstlayout->addWidget(iconButton, 0, Qt::AlignLeft | Qt::AlignCenter); m_firstlayout->addStretch(); m_firstlayout->addWidget(percentageLabel, 0, Qt::AlignLeft | Qt::AlignCenter); m_firstlayout->addStretch(); m_firstlayout->addItem(new QSpacerItem(100, 5, QSizePolicy::Expanding, QSizePolicy::Minimum)); m_firstlayout->addWidget(powerTimeToEmpty, 0, Qt::AlignLeft | Qt::AlignCenter); m_firstlayout->addWidget(powerStateLabel, 0, Qt::AlignLeft | Qt::AlignCenter); m_firstlayout->addStretch(); m_firstwidget->setLayout(m_firstlayout); //电源设置按钮布局 lastlayout->addWidget(settingLabel); lastlayout->addItem(new QSpacerItem(300, 2)); lastWidget->setLayout(lastlayout); //总体布局 m_pmainlayout->addWidget(m_firstwidget); m_pmainlayout->addWidget(line); m_pmainlayout->addWidget(lastWidget); this->setLayout(m_pmainlayout); QDBusReply reply = m_iface->call("IconName"); IconChanged(reply.value()); } void powerwindow::initgsetting() { const QByteArray styleId(ORG_UKUI_STYLE); if (QGSettings::isSchemaInstalled(styleId)) { QGSettings *styleSettings = new QGSettings(styleId); connect(styleSettings, &QGSettings::changed, this, [=](const QString &key) { if (key == STYLE_NAME) { QDBusReply reply = m_iface->call("IconName"); IconChanged(reply.value()); } if (key == SYSTEM_FONT_SIZE) { m_sysFontSize = styleSettings->get(SYSTEM_FONT_SIZE).toInt(); get_power_list(); } }); m_sysFontSize = styleSettings->get(SYSTEM_FONT_SIZE).toInt(); } } void powerwindow::get_power_list() { int size; size = ed->devices.size(); for (int i = 0; i < size; i++) { DEVICE *dv; dv = ed->devices.at(i); //通过提示信息,新建widget if (dv->m_dev.kind == UP_DEVICE_KIND_LINE_POWER) { continue; } if (dv->m_dev.kind == UP_DEVICE_KIND_BATTERY) { //设置百分比大小 QFont ft; ft.setPointSize(m_sysFontSize * 2); percentageLabel->setFont(ft); percentageLabel->setText(QString("%1%").arg(dv->m_dev.Percentage)); powerStateLabel->setVisible(true); powerTimeToEmpty->setVisible(false); } connect(ed, &EngineDevice::engine_signal_Battery_State, this, &powerwindow::onBatteryChanged); continue; } } void powerwindow::set_preference_func() { QProcess process; process.start( "bash", QStringList() << "-c" << "dpkg -l | grep ukui-control-center"); process.waitForFinished(); QString strResult = process.readAllStandardOutput() + process.readAllStandardError(); if (-1 != strResult.indexOf("3.0")) { QProcess::startDetached(QString("ukui-control-center -p")); } else { QProcess::startDetached(QString("ukui-control-center -m Power")); } } void powerwindow::batteryChange(int dev) { if (dev == 4 || dev == 1 || dev == 5) { powerStateLabel->setVisible(true); powerTimeToEmpty->setVisible(false); } else { powerStateLabel->setVisible(false); powerTimeToEmpty->setVisible(true); } } void powerwindow::onBatteryChanged(QStringList args) { // qDebug()<<"电脑电池电量与状态:"<get(GPM_SETTINGS_DISPLAY_LEFT_TIME).toInt(); if (is_show) { powerTimeToEmpty->setText( QString(tr("Left %1h \n %2m")).arg((timeToEmpty) / 3600).arg(((timeToEmpty) % 3600) / 60)); } else { powerTimeToEmpty->setText(QString(tr("Discharging"))); } if (state == 1 || state == 5) { powerStateLabel->setText(tr("Charging")); } else if (state == 4) { powerStateLabel->setText(tr("fully charged")); } batteryChange(state); percentageLabel->setText(QString("%1%").arg(battery)); } void powerwindow::IconChanged(QString str) { if (!str.isNull()) { QIcon icon = QIcon::fromTheme(str); iconButton->setIcon(icon); iconButton->setFixedSize(QSize(48,48)); iconButton->setIconSize(QSize(30,30)); iconButton->setProperty("useIconHighlightEffect", 0x10); // iconButton->setProperty("useBuutonPalette",true); // iconButton->setProperty("isWindowButton",0x1); iconButton->setFlat(true); } } void powerwindow::charge_notify(DEV dev) { QString icon = ed->engine_get_dev_icon(dev); QDBusInterface iface( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); QList args; args << tr("Power Manager") << ((unsigned int)0) << "ukui-power-manager" << tr("charge notification") << tr("battery is charging") << QStringList() << QVariantMap() << (int)-1; iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); } void powerwindow::discharge_notify(DEV dev) { QString icon = ed->engine_get_dev_icon(dev); QDBusInterface iface( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); QList args; args << tr("Power Manager") << ((unsigned int)0) << "ukui-power-manager" << tr("discharged notification") << tr("battery is discharging") << QStringList() << QVariantMap() << (int)-1; iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); } void powerwindow::full_charge_notify(DEV dev) { QString icon = ed->engine_get_dev_icon(dev); QDBusInterface iface( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); QList args; args << tr("Power Manager") << ((unsigned int)0) // <engine_get_dev_icon(dev); QDBusInterface iface( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); QList args; args << tr("Power Manager") << ((unsigned int)0) << "ukui-power-manager" << tr("low battery notification") << tr("battery is low, please plug in power") << QStringList() << QVariantMap() << (int)-1; iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); } void powerwindow::critical_battery_notify(DEV dev) { Q_UNUSED(dev); QDBusInterface iface( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); QList args; args << tr("Power Manager") << ((unsigned int)0) << ed->power_device_get_icon() << tr("critical battery notification") << tr("battery is critical low,please plug in!") << QStringList() << QVariantMap() << (int)-1; iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); } void powerwindow::action_battery_notify(DEV dev) { QString icon = ed->engine_get_dev_icon(dev); QDBusInterface iface( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); QList args; args << tr("Power Manager") << ((unsigned int)0) << "ukui-power-manager" << tr("operation notification") << tr("performing low power operation") << QStringList() << QVariantMap() << (int)-1; iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); } void powerwindow::set_window_position() { QDBusInterface iface("org.ukui.panel", "/panel/position", "org.ukui.panel", QDBusConnection::sessionBus()); QDBusReply reply = iface.call("GetPrimaryScreenGeometry"); // qDebug() << reply.value().at(2).toInt(); switch (reply.value().at(4).toInt()) { case 1: this->setGeometry( reply.value().at(0).toInt() + reply.value().at(2).toInt() - this->width() - MARGIN, reply.value().at(1).toInt() + MARGIN, this->width(), this->height()); break; case 2: this->setGeometry( reply.value().at(0).toInt() + MARGIN, // position_list.at(1).toInt()+reply.value().at(3).toInt()-this->height()-MARGIN, reply.value().at(3).toInt() - this->height() - MARGIN, this->width(), this->height()); break; case 3: this->setGeometry( reply.value().at(2).toInt() - this->width() - MARGIN, reply.value().at(3).toInt() - this->height() - MARGIN, this->width(), this->height()); break; default: this->setGeometry( reply.value().at(0).toInt() + reply.value().at(2).toInt() - this->width() - MARGIN, reply.value().at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN, this->width(), this->height()); break; } } void powerwindow::watchTranspartency() { const QByteArray transparency_id(TRANSPARENCY_SETTINGS); if (QGSettings::isSchemaInstalled(transparency_id)) { transparency_gsettings = new QGSettings(transparency_id); transparency = transparency_gsettings->get(TRANSPARENCY_KEY).toDouble() * 255; this->update(); connect(transparency_gsettings, &QGSettings::changed, this, [=](const QString &key) { if (key == TRANSPARENCY_KEY) { transparency = transparency_gsettings->get(TRANSPARENCY_KEY).toDouble() * 255; this->update(); } }); } else { transparency = 0.75; } } void powerwindow::paintEvent(QPaintEvent *e) { qDebug() << "transparency" << transparency; QStyleOption opt; opt.init(this); QPainter p(this); p.setPen(Qt::NoPen); QColor color = palette().color(QPalette::Base); color.setAlpha(transparency); QBrush brush = QBrush(color); p.setBrush(brush); p.setRenderHint(QPainter::Antialiasing); p.drawRoundedRect(opt.rect, 0, 0); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } m_PartLineWidget::m_PartLineWidget(QWidget *parent) : QWidget(parent) {} void m_PartLineWidget::paintEvent(QPaintEvent *event) { QPainter p(this); QRect rect = this->rect(); p.setRenderHint(QPainter::Antialiasing); // 反锯齿; QColor color = qApp->palette().color(QPalette::Base); if (color.red() == 255 && color.green() == 255 && color.blue() == 255) { color.setRgb(1, 1, 1, 255); } else if (color.red() == 31 && color.green() == 32 && color.blue() == 34) { color.setRgb(255, 255, 255, 255); } p.setBrush(color); p.setOpacity(0.05); p.setPen(Qt::NoPen); p.drawRoundedRect(rect, 0, 0); QWidget::paintEvent(event); } //滑动条组件 stateslider::stateslider(QWidget *parent) : QSlider(parent) { setOrientation(Qt::Orientation::Horizontal); setMaximum(2); /* setMinimumHeight(5); setMinimumWidth(340);*/ setStyleSheet("QSlider::groove:horizontal {" "border: 0px none;" "background: #262626;" "height: 5px;" "width: 340px;" "border-radius: 5px;" "}" "QSlider::handle:horizontal {" "border: 1px solid #5c5c5c;" "width: 10px;" "margin: -10px 0;" "border-radius: 1px; " "background-color: #05B8CC;" "}" "QSlider::add-page:horizontal {" "background: #262626;" "border-radius: 5px;" "}" ); } //设置label settinglabel::settinglabel() : QLabel() { QPalette pe; pe.setColor(QPalette::WindowText, QColor(68, 131, 219)); this->setPalette(pe); this->setText(tr("PowerSet")); } //鼠标点击事件 void settinglabel::mousePressEvent(QMouseEvent *event) { if (event->buttons() == Qt::LeftButton) { Q_EMIT labelclick(); } return; } bool powerwindow::eventFilter(QObject *watched, QEvent *event) { if (watched == this) { if (event->type() == QEvent::WindowDeactivate) { hide(); return true; } else { return false; } } else { return false; } } ukui-power-manager/ukui-power-manager-tray/main.cpp0000644000175000017500000000474514205117543021355 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "powertray.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); #endif QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); int fd = open( QString(homePath.at(0) + "/.config/ukui-power-manager-tray%1.lock").arg(getenv("DISPLAY")).toUtf8().data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd < 0) { exit(1); } if (lockf(fd, F_TLOCK, 0)) { qDebug() << "cant lock single file, ukui-power-manager-tray is already running"; exit(0); } QApplication app(argc, argv); initUkuiLog4qt("ukui-power-manager-tray"); QTranslator translator; if (translator.load(QLocale(), "ukui-power-manager-tray", "_", QM_FILES_INSTALL_PATH)) { app.installTranslator(&translator); } else { qDebug() << "load ukui-power-manager-tray qm file error"; } // QTime dieTime = QTime::currentTime().addMSecs(2000); // while (QTime::currentTime() < dieTime) { // QCoreApplication::processEvents(QEventLoop::AllEvents, 100); // } PowerTray p; if ("book" == p.getMachineType()) { p.initPowerTray(); } else { qDebug() << "No tray required"; exit(0); } return app.exec(); } ukui-power-manager/ukui-power-manager-tray/device.h0000644000175000017500000000305214205117452021322 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef DEVICE_H #define DEVICE_H #include #include "engine_common.h" struct DEV { UpDeviceKind kind; UpDeviceLevel warnlevel; QString Device; QString Type; QString PowerSupply; QString Online; QString Model; QString Energy; QString EnergyEmpty; QString EnergyFull; QString EnergyRate; bool IsPresent; QString IsRechargeable; double Percentage; UpDeviceState State; qlonglong TimeToEmpty; qlonglong TimeToFull; QString Voltage; double Capacity; QString Technology; QString path; }; class DEVICE : public QObject { Q_OBJECT public: explicit DEVICE(QObject *parent = nullptr); ~DEVICE(); Q_SIGNALS: void device_property_changed(QDBusMessage msg,QString path); public Q_SLOTS: void handleChanged(QDBusMessage msg); public: DEV m_dev; }; #endif // DEVICE_H ukui-power-manager/man/0000755000175000017500000000000014205117543013772 5ustar fengfengukui-power-manager/man/ukui-power-manager-tray.10000644000175000017500000000143014205117452020545 0ustar fengfeng.TH ukui-power-manager-tray .SH NAME ukui-power-manager-tray \- The power-manager UI for the UKUI Desktop Environment .SH DESCRIPTION This module show power-manager widget This process is mainly for displaying the power management tray and the main interface after opening the tray icon. Currently, the main interface will show the user the current remaining power and remaining charging time. And provide users with an interface to enter the control panel to set related power operations. .SH "REPORTING BUGS" Report bugs to http://gitlab2.kylin.com/ukui/ukui-power-manager/issues .SH "SEE ALSO" .SS Ukui PowerManager documentation can be found under "Help" by right-clicking on \fBukui-power-manager\fR. Further information may also be available at: http://wiki.ukui-desktop.org/docs .P ukui-power-manager/man/ukui-power-manager.10000644000175000017500000000136014205117452017572 0ustar fengfeng.TH ukui-power-manager .SH NAME ukui-power-manager \- The power-manager for the UKUI Desktop Environment .SH DESCRIPTION This module show power-manager Daemon This program is a background process of power management, which is mainly responsible for controlling the idle operation, closing operation, and low power operation of the operating system. And monitor the action of plugging and unplugging the power cord and perform corresponding operations. .SH "REPORTING BUGS" Report bugs to http://gitlab2.kylin.com/ukui/ukui-power-manager/issues .SH "SEE ALSO" .SS Ukui PowerManager documentation can be found under "Help" by right-clicking on \fBukui-power-manager\fR. Further information may also be available at: http://wiki.ukui-desktop.org/docs .P ukui-power-manager/man/ukui-powermanagement-service.10000644000175000017500000000136514205117452021662 0ustar fengfeng.TH ukui-power-management-server .SH NAME ukui-power-management-server \- The power-manager Dbus Server for the UKUI Desktop Environment .SH DESCRIPTION This module show power-manager Dbus Server This service provides corresponding interfaces for the power management background process, such as shutdown, hibernation, sleep, etc. The main corresponding interface is the corresponding interface provided by systemd. The service is treated as a SystemBus. .SH "REPORTING BUGS" Report bugs to http://gitlab2.kylin.com/ukui/ukui-power-manager/issues .SH "SEE ALSO" .SS Ukui PowerManager documentation can be found under "Help" by right-clicking on \fBukui-power-manager\fR. Further information may also be available at: http://wiki.ukui-desktop.org/docs .P ukui-power-manager/man/ukui-powermanagement.10000644000175000017500000000137414205117452020224 0ustar fengfeng.TH ukui-powermanagement .SH NAME ukui-powermanagement \- The power-manager Daemon for the UKUI Desktop Environment .SH DESCRIPTION This module show power-manager Daemon This program is a background process of power management, which is mainly responsible for controlling the idle operation, closing operation, and low power operation of the operating system. And monitor the action of plugging and unplugging the power cord and perform corresponding operations. .SH "REPORTING BUGS" Report bugs to http://gitlab2.kylin.com/ukui/ukui-power-manager/issues .SH "SEE ALSO" .SS Ukui PowerManager documentation can be found under "Help" by right-clicking on \fBukui-power-manager\fR. Further information may also be available at: http://wiki.ukui-desktop.org/docs .P ukui-power-manager/man/ukui-upower.10000644000175000017500000000136114205117452016350 0ustar fengfeng.TH ukui-upower .SH NAME ukui-upower \- The power-manager Interface for the UKUI Desktop Environment .SH DESCRIPTION This module show power-manager Interface The purpose of this process is to encapsulate upower and provide desktop components with information about upower and battery-related information. And the battery information is processed, and the interfaces and signals are opened to the remaining components. The process service is SessionBus. .SH "REPORTING BUGS" Report bugs to http://gitlab2.kylin.com/ukui/ukui-power-manager/issues .SH "SEE ALSO" .SS Ukui PowerManager documentation can be found under "Help" by right-clicking on \fBukui-power-manager\fR. Further information may also be available at: http://wiki.ukui-desktop.org/docs .P ukui-power-manager/PowerManagementDaemon/0000755000175000017500000000000014205117543017434 5ustar fengfengukui-power-manager/PowerManagementDaemon/PowerManagementDaemon.pro0000644000175000017500000000322014205117543024370 0ustar fengfengQT += core gui dbus greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = ukui-powermanagement CONFIG += c++11 link_pkgconfig PKGCONFIG += gsettings-qt LIBS += -lukui-log4qt # 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 # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ acwatcher/acwatcher.cpp \ eventwatcher.cpp \ gsettingwatcher/gsettingwatcher.cpp \ lowpowerwatcher/lowpowerwatcher.cpp \ main.cpp \ powermanagementdamon.cpp \ idle/idlenesswatcher.cpp \ lidwatcher/lidwatcher.cpp \ powermsgnotificat/powermsgnotificat.cpp \ HEADERS += \ acwatcher/acwatcher.h \ eventwatcher.h \ gsettingwatcher/gsettingwatcher.h \ lowpowerwatcher/lowpowerwatcher.h \ powermanagementdamon.h \ idle/idlenesswatcher.h \ lidwatcher/lidwatcher.h \ common.h \ powermsgnotificat/powermsgnotificat.h \ # Default rules for deployment. qnx: target.path = /tmp/usr/bin else: unix:!android: target.path = /usr/bin !isEmpty(target.path): INSTALLS += target desktop.files += resources/ukui-powermanagement-daemon.desktop desktop.path = /etc/xdg/autostart/ INSTALLS += desktop ukui-power-manager/PowerManagementDaemon/eventwatcher.h0000644000175000017500000000531114205117452022303 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef EVENTWATCHER_H #define EVENTWATCHER_H #include #include #include #include "common.h" class EventWatcher : public QObject { Q_OBJECT public: EventWatcher(); ~EventWatcher(); /** * @brief initEventWatcher * 初始化 */ void initEventWatcher(); /** * @brief dealBrightnessMsg * 处理亮度信息 */ void dealBrightnessMsg(); /** * @brief initSettings * 获取用户设置亮度值 */ void getUserBrightness(); /** * @brief initConfig * 设置亮度值 */ void setBrightness(); /** * @brief controlPowerManagement * 控制电源管理dbus建立 */ int controlPowerManagement(const QString &type); void controlPowerManagement(const QString &type, const int &value); void controlPowerManagement(const QString &type, const QString &contrl); void controlPowerManagement(const QString &type, const qulonglong &brightness); /** * @brief turnOffDisplay * 关闭显示器 */ void turnOffDisplay(); /** * @brief turnOnDisplay * 打开显示器 */ void turnOnDisplay(); /** * @brief lock * 锁屏 */ void lock(); /** * @brief suspend * 睡眠 */ void suspend(); /** * @brief hibernate * 休眠 */ void hibernate(); /** * @brief PowerOff * 关机 */ void powerOff(); /* * =============================================== * 以下为成员变量,包括gsettings等设置相关变量 * =============================================== */ QGSettings *mPowerManagementGsettings; /** * @brief mMaxBrightness * 最大亮度值 */ qulonglong mMaxBrightness; /** * @brief mBrightness * 当前亮度值 */ qulonglong mBrightness; /** * @brief mUserBrightness * 用户配置的亮度值 */ qulonglong mUserBrightness; signals: }; #endif // EVENTWATCHER_H ukui-power-manager/PowerManagementDaemon/powermsgnotificat/0000755000175000017500000000000014205117543023200 5ustar fengfengukui-power-manager/PowerManagementDaemon/powermsgnotificat/powermsgnotificat.cpp0000644000175000017500000000352414205117543027454 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "powermsgnotificat.h" PowerMsgNotificat::PowerMsgNotificat() {} PowerMsgNotificat::~PowerMsgNotificat() {} void PowerMsgNotificat::initPowerMsgNotificat() { QDBusConnection::systemBus().connect( QString(), QString("/"), QString("org.ukui.powermanagement.interface"), QString("CanControl"), this, SLOT(msgNotification(QString))); } void PowerMsgNotificat::msgNotification(QString msg) { QString mType = tr("error message"); notifySend(mType, msg); } void PowerMsgNotificat::notifySend(const QString &type, const QString &arg) { QDBusInterface iface( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); QList args; QStringList argg; QMap pear_map; args << tr("电源管理") << ((unsigned int)0) << QString("ukui-power-manager") << type //显示的是什么类型的信息//系统升级 << arg //显示的具体信息 << argg << pear_map << (int)-1; iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); } ukui-power-manager/PowerManagementDaemon/powermsgnotificat/powermsgnotificat.h0000644000175000017500000000221314205117452027112 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef POWERMSGNOTIFICAT_H #define POWERMSGNOTIFICAT_H #include #include #include #include "eventwatcher.h" class PowerMsgNotificat : public EventWatcher { Q_OBJECT public: PowerMsgNotificat(); ~PowerMsgNotificat(); void initPowerMsgNotificat(); private: void notifySend(const QString &type, const QString &arg); public slots: void msgNotification(QString); }; #endif // POWERMSGNOTIFICAT_H ukui-power-manager/PowerManagementDaemon/powermanagementdamon.cpp0000644000175000017500000000303014205117452024343 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "powermanagementdamon.h" #include PowerManagementDamon::PowerManagementDamon() { eventwatcher = new EventWatcher; eventwatcher->initEventWatcher(); idlenesswatcher = new IdlenessWatchcer; idlenesswatcher->initIdleWatcher(); lidwatcher = new LidWatcher; lidwatcher->initLidWatcher(); acwatcher = new AcWatcher; lowpowerwatcher = new LowPowerWatcher; lowpowerwatcher->initLowPowerWatcher(); gsettingwatcher = new GsettingWatcher; gsettingwatcher->initGsettingWatcher(); powermsgnotificat = new PowerMsgNotificat; powermsgnotificat->initPowerMsgNotificat(); } PowerManagementDamon::~PowerManagementDamon() { delete idlenesswatcher; delete lidwatcher; delete eventwatcher; delete acwatcher; delete lowpowerwatcher; delete gsettingwatcher; delete powermsgnotificat; } ukui-power-manager/PowerManagementDaemon/lidwatcher/0000755000175000017500000000000014205117543021562 5ustar fengfengukui-power-manager/PowerManagementDaemon/lidwatcher/lidwatcher.cpp0000644000175000017500000000556314205117543024425 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "lidwatcher.h" LidWatcher::LidWatcher() { } LidWatcher::~LidWatcher() {} void LidWatcher::initLidWatcher() { inhibitSystemdLogin(); QDBusConnection::systemBus().connect( UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(dealLidWatcherMssage(void))); displayState = true; } void LidWatcher::inhibitSystemdLogin() { QDBusInterface manager( QStringLiteral("org.freedesktop.login1"), QStringLiteral("/org/freedesktop/login1"), QStringLiteral("org.freedesktop.login1.Manager"), QDBusConnection::systemBus()); QDBusReply reply = manager.call( QStringLiteral("Inhibit"), QStringLiteral("handle-lid-switch"), QStringLiteral("lxqt-powermanagment"), QStringLiteral("LidWatcher is in da house!"), QStringLiteral("block")); if (reply.isValid()) { logindLock = reply.value(); qDebug() << "Inhibit got:" << logindLock.fileDescriptor(); } else { qDebug() << "Error from inhibit:" << reply.error(); } } void LidWatcher::dealLidWatcherMssage(void) { QString contrl; QDBusInterface iface(UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); QDBusReply reply = iface.call("Get", "org.freedesktop.UPower", "LidIsClosed"); if (reply.isValid()) { qDebug() << "lid state:" << reply.value(); contrl = mPowerManagementGsettings->get(BUTTON_LID_AC).toString(); qDebug() << "lid close contrl:" << contrl; bool value = reply.value().toBool(); if (true == value) { if ("blank" == contrl) { turnOffDisplay(); displayState = false; } else if ("suspend" == contrl) { suspend(); } else if ("shutdown" == contrl) { powerOff(); } else if ("hibernate" == contrl) { hibernate(); } } else { if ("blank" == contrl && false == displayState) { turnOnDisplay(); displayState = true; } } } else { qDebug() << "Failed to get lid closed event!"; } } ukui-power-manager/PowerManagementDaemon/lidwatcher/lidwatcher.h0000644000175000017500000000220014205117543024053 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef LIDWATCHER_H #define LIDWATCHER_H #include "eventwatcher.h" class LidWatcher : public EventWatcher { Q_OBJECT public: LidWatcher(); ~LidWatcher(); /** * @brief initLidWatcher * 初始化监听盒盖 */ void initLidWatcher(); private: void inhibitSystemdLogin(); QDBusUnixFileDescriptor logindLock; bool displayState; private slots: void dealLidWatcherMssage(void); }; #endif // LIDWATCHER_H ukui-power-manager/PowerManagementDaemon/powerwatcher/0000755000175000017500000000000014205117543022146 5ustar fengfengukui-power-manager/PowerManagementDaemon/powerwatcher/powerwatcher.cpp0000644000175000017500000000142714205117543025370 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "powerwatcher.h" PowerWatcher::PowerWatcher() { } PowerWatcher::~PowerWatcher() { } ukui-power-manager/PowerManagementDaemon/powerwatcher/powerwatcher.h0000644000175000017500000000161114205117543025030 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef POWERWATCHER_H #define POWERWATCHER_H #include "eventwatcher.h" class PowerWatcher : public EventWatcher { Q_OBJECT public: PowerWatcher(); ~PowerWatcher(); }; #endif // POWERWATCHER_H ukui-power-manager/PowerManagementDaemon/powerwatcher/common.h0000644000175000017500000000272014205117543023610 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef COMMON_H #define COMMON_H //Qt #include #include #include //gsettings 配置 #define POWER_MANAGER_SETTINGS "org.ukui.power-manager" #define SLEEP_COMPUTER_BAT_KEY "sleepComputerBattery" #define SLEEP_DISPLAY_AC_KEY "sleepDisplayAc" #define SLEEP_DISPLAY_BAT_KEY "sleepDisplayBattery" #define LOCK_BLANK_SCREEN "lockBlankScreen" #define IDLE_DIM_TIME "idleDimTime" //dbus 配置 #define GNOME_SESSION_MANAGER "org.gnome.SessionManager.Presence" #define SESSION_MANAGER_PATH "/org/gnome/SessionManager/Presence" #define POWER_MANAGEMENT_SERVICE "org.ukui.powermanagement" #define POWER_MANAGEMENT_PATH "/" #define POWER_MANAGEMENT_INTERFACE_NAME "org.ukui.powermanagement.interface" #endif // COMMON_H ukui-power-manager/PowerManagementDaemon/.clang-format0000644000175000017500000001771014205117543022015 0ustar fengfeng--- # 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto Language: Cpp # BasedOnStyle: WebKit # 访问说明符(public、private等)的偏移 AccessModifierOffset: -4 # 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行) AlignAfterOpenBracket: AlwaysBreak # 连续赋值时,对齐所有等号 AlignConsecutiveAssignments: false # 连续声明时,对齐所有声明的变量名 AlignConsecutiveDeclarations: false # 左对齐逃脱换行(使用反斜杠换行)的反斜杠 AlignEscapedNewlines: Right # 水平对齐二元和三元表达式的操作数 AlignOperands: true # 对齐连续的尾随的注释 AlignTrailingComments: true # 允许函数声明的所有参数在放在下一行 AllowAllParametersOfDeclarationOnNextLine: true # 允许短的块放在同一行 AllowShortBlocksOnASingleLine: false # 允许短的case标签放在同一行 AllowShortCaseLabelsOnASingleLine: false # 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All AllowShortFunctionsOnASingleLine: Empty # 允许短的if语句保持在同一行 AllowShortIfStatementsOnASingleLine: false # 允许短的循环保持在同一行 AllowShortLoopsOnASingleLine: false # 总是在定义返回类型后换行(deprecated) AlwaysBreakAfterDefinitionReturnType: None # 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), # AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义) AlwaysBreakAfterReturnType: None # 总是在多行string字面量前换行 AlwaysBreakBeforeMultilineStrings: false # 总是在template声明后换行 AlwaysBreakTemplateDeclarations: true # false表示函数实参要么都在同一行,要么都各自一行 BinPackArguments: false # false表示所有形参要么都在同一行,要么都各自一行 BinPackParameters: false # 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效 BraceWrapping: # class定义后面 AfterClass: true # 控制语句后面 AfterControlStatement: false # enum定义后面 AfterEnum: true # 函数定义后面 AfterFunction: true # 命名空间定义后面 AfterNamespace: true # ObjC定义后面 AfterObjCDeclaration: false # struct定义后面 AfterStruct: true # union定义后面 AfterUnion: true # extern 定义后面 AfterExternBlock: true # catch之前 BeforeCatch: false # else 之前 BeforeElse: false # 缩进大括号 IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true # 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) BreakBeforeBinaryOperators: All # 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似), # Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似), # Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom # 注:这里认为语句块也属于函数 BreakBeforeBraces: Custom # 继承列表的逗号前换行 BreakBeforeInheritanceComma: false # 在三元运算符前换行 BreakBeforeTernaryOperators: true # 在构造函数的初始化列表的逗号前换行 BreakConstructorInitializersBeforeComma: false # 初始化列表前换行 BreakConstructorInitializers: BeforeComma # Java注解后换行 BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true # 每行字符的限制,0表示没有限制 ColumnLimit: 120 # 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变 CommentPragmas: '^ IWYU pragma:' # 紧凑 命名空间 CompactNamespaces: false # 构造函数的初始化列表要么都在同一行,要么都各自一行 ConstructorInitializerAllOnOneLineOrOnePerLine: true # 构造函数的初始化列表的缩进宽度 ConstructorInitializerIndentWidth: 4 # 延续的行的缩进宽度 ContinuationIndentWidth: 4 # 去除C++11的列表初始化的大括号{后和}前的空格 Cpp11BracedListStyle: false # 继承最常用的指针和引用的对齐方式 DerivePointerAlignment: false # 关闭格式化 DisableFormat: false # 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental) ExperimentalAutoDetectBinPacking: false # 固定命名空间注释 FixNamespaceComments: true # 需要被解读为foreach循环而不是函数调用的宏 ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH IncludeBlocks: Preserve # 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前), # 可以定义负数优先级从而保证某些#include永远在最前面 IncludeCategories: - Regex: '^"(llvm|llvm-c|clang|clang-c)/' Priority: 2 - Regex: '^(<|"(gtest|gmock|isl|json)/)' Priority: 3 - Regex: '.*' Priority: 1 IncludeIsMainRegex: '(Test)?$' # 缩进case标签 IndentCaseLabels: true IndentPPDirectives: None # 缩进宽度 IndentWidth: 4 # 函数返回类型换行时,缩进函数声明或函数定义的函数名 IndentWrappedFunctionNames: false JavaScriptQuotes: Leave JavaScriptWrapImports: true # 保留在块开始处的空行 KeepEmptyLinesAtTheStartOfBlocks: true # 开始一个块的宏的正则表达式 MacroBlockBegin: '' # 结束一个块的宏的正则表达式 MacroBlockEnd: '' # 连续空行的最大数量 MaxEmptyLinesToKeep: 1 # 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All NamespaceIndentation: Inner # 使用ObjC块时缩进宽度 ObjCBlockIndentWidth: 4 # 在ObjC的@property后添加一个空格 ObjCSpaceAfterProperty: true # 在ObjC的protocol列表前添加一个空格 ObjCSpaceBeforeProtocolList: true PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 19 # 在一个注释中引入换行的penalty PenaltyBreakComment: 300 # 第一次在<<前换行的penalty PenaltyBreakFirstLessLess: 120 # 在一个字符串字面量中引入换行的penalty PenaltyBreakString: 1000 # 对于每个在行字符数限制之外的字符的penalty PenaltyExcessCharacter: 1000000 # 将函数的返回类型放到它自己的行的penalty PenaltyReturnTypeOnItsOwnLine: 60 # 指针和引用的对齐: Left, Right, Middle PointerAlignment: Right #RawStringFormats: # - Delimiter: pb # Language: TextProto # BasedOnStyle: google # 允许重新排版注释 ReflowComments: true # 允许排序#include SortIncludes: false SortUsingDeclarations: true # 在C风格类型转换后添加空格 SpaceAfterCStyleCast: false # 模板关键字后面添加空格 SpaceAfterTemplateKeyword: true # 在赋值运算符之前添加空格 SpaceBeforeAssignmentOperators: true # 开圆括号之前添加一个空格: Never, ControlStatements, Always SpaceBeforeParens: ControlStatements # 在空的圆括号中添加空格 SpaceInEmptyParentheses: false # 在尾随的评论前添加的空格数(只适用于//) SpacesBeforeTrailingComments: 1 # 在尖括号的<后和>前添加空格 SpacesInAngles: false # 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格 SpacesInContainerLiterals: true # 在C风格类型转换的括号中添加空格 SpacesInCStyleCastParentheses: false # 在圆括号的(后和)前添加空格 SpacesInParentheses: false # 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响 SpacesInSquareBrackets: false # 标准: Cpp03, Cpp11, Auto Standard: Cpp11 # tab宽度 TabWidth: 4 # 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always UseTab: Never ... ukui-power-manager/PowerManagementDaemon/eventwatcher.cpp0000644000175000017500000001005514205117452022637 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "eventwatcher.h" EventWatcher::EventWatcher() { const QByteArray id(POWER_MANAGER_SETTINGS); mPowerManagementGsettings = new QGSettings(id); } EventWatcher::~EventWatcher() { delete mPowerManagementGsettings; } void EventWatcher::initEventWatcher() { getUserBrightness(); setBrightness(); connect(mPowerManagementGsettings, &QGSettings::changed, this, [=](const QString &key) { if (key == BRIGHTNESS_AC) { getUserBrightness(); setBrightness(); } }); } void EventWatcher::getUserBrightness() { mMaxBrightness = controlPowerManagement(GET_MAX_BRIGHTNESS); qDebug() << "max brightness is :" << mMaxBrightness; if (10.0 > mPowerManagementGsettings->get(BRIGHTNESS_AC).toDouble()) { mUserBrightness = 10.0; } else { mUserBrightness = mPowerManagementGsettings->get(BRIGHTNESS_AC).toDouble() * 0.01 * mMaxBrightness; } qDebug() << "user brightness is :" << mUserBrightness; } void EventWatcher::setBrightness() { controlPowerManagement(REGULATE_BRIGHTNESS, mUserBrightness); } void EventWatcher::turnOffDisplay() { if (mPowerManagementGsettings->get(LOCK_BLANK_SCREEN).toBool()) { lock(); qDebug()<<"lock success"; } //调用关闭显示器的接口 if ("wayland" == qgetenv("XDG_SESSION_TYPE")) { system("export QT_QPA_PLATFORM=wayland && kscreen-doctor --dpms off"); } else { system("xset dpms force off"); } qDebug() << "The display is turned off" << qgetenv("XDG_SESSION_TYPE"); } void EventWatcher::turnOnDisplay() { if ("wayland" == qgetenv("XDG_SESSION_TYPE")) { system("export QT_QPA_PLATFORM=wayland && kscreen-doctor --dpms on"); } else { system("xset dpms force on"); } qDebug() << "The display is turned on" << qgetenv("XDG_SESSION_TYPE"); } void EventWatcher::lock() { system("ukui-screensaver-command -l"); qDebug() << "lock success"; } void EventWatcher::suspend() { controlPowerManagement(SUSPEND); qDebug() << "suspend success"; } void EventWatcher::hibernate() { controlPowerManagement(HIBERNATE); qDebug() << "hibernate success"; } void EventWatcher::powerOff() { controlPowerManagement(POWER_OFF); qDebug() << "power off success"; } //此处代码后期可以进行优化 int EventWatcher::controlPowerManagement(const QString &type) { QDBusInterface iface( POWER_MANAGEMENT_SERVICE, POWER_MANAGEMENT_PATH, POWER_MANAGEMENT_INTERFACE_NAME, QDBusConnection::systemBus()); QDBusReply reply = iface.call(type); return reply.value(); } void EventWatcher::controlPowerManagement(const QString &type, const qulonglong &brightness) { QDBusInterface iface( POWER_MANAGEMENT_SERVICE, POWER_MANAGEMENT_PATH, POWER_MANAGEMENT_INTERFACE_NAME, QDBusConnection::systemBus()); iface.call(type, brightness); } void EventWatcher::controlPowerManagement(const QString &type, const int &value) { QDBusInterface iface( POWER_MANAGEMENT_SERVICE, POWER_MANAGEMENT_PATH, POWER_MANAGEMENT_INTERFACE_NAME, QDBusConnection::systemBus()); iface.call(type, value); } void EventWatcher::controlPowerManagement(const QString &type, const QString &contrl) { QDBusInterface iface( POWER_MANAGEMENT_SERVICE, POWER_MANAGEMENT_PATH, POWER_MANAGEMENT_INTERFACE_NAME, QDBusConnection::systemBus()); iface.call(type, contrl); } ukui-power-manager/PowerManagementDaemon/resources/0000755000175000017500000000000014205117452021445 5ustar fengfengukui-power-manager/PowerManagementDaemon/resources/ukui-powermanagement-daemon.desktop0000644000175000017500000000043614205117452030450 0ustar fengfeng[Desktop Entry] Name=Power Manager Name[zh_CN]=电源管理器 Comment=Power management daemon Comment[zh_CN]=电源管理守护程序 Icon=ukui-power-manager Exec=ukui-powermanagement Terminal=false Type=Application NoDisplay=true Categories= OnlyShowIn=UKUI; X-UKUI-AutoRestart=true ukui-power-manager/PowerManagementDaemon/acwatcher/0000755000175000017500000000000014205117452021374 5ustar fengfengukui-power-manager/PowerManagementDaemon/acwatcher/acwatcher.cpp0000644000175000017500000000332014205117452024037 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "acwatcher.h" AcWatcher::AcWatcher() { } AcWatcher::~AcWatcher() {} void AcWatcher::initAcWatcher() { QDBusConnection::systemBus().connect( UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, "PropertiesChanged", this, SLOT(dealAcWatcherMssage(void))); mOnBattery = readOnBattery(); // qDebug()<<"mOnBattery:"< reply = iface.call("Get", "org.freedesktop.UPower", "OnBattery"); if (reply.isValid()) { value = reply.value().toBool(); } else { qDebug() << "OnBattery error!"; } return value; } ukui-power-manager/PowerManagementDaemon/acwatcher/acwatcher.h0000644000175000017500000000262214205117452023510 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef ACWATCHER_H #define ACWATCHER_H #include "eventwatcher.h" class AcWatcher : public EventWatcher { Q_OBJECT public: AcWatcher(); ~AcWatcher(); /** * @brief initAcWatcher * 初始化电源插拔 */ void initAcWatcher(); /** * @brief readOnBattery * 获取电源状态(AC或者battery) * @return */ bool readOnBattery(); bool &mPowerState = mOnBattery; signals: /** * @brief acChanged * 电源状态改变信号 */ void acChanged(bool); private slots: /** * @brief dealAcWatcherMssage * 处理电源插拔消息 */ void dealAcWatcherMssage(void); private: bool mOnBattery; }; #endif // ACWATCHER_H ukui-power-manager/PowerManagementDaemon/PowerManagementDaemon/0000755000175000017500000000000014205117452023650 5ustar fengfengukui-power-manager/PowerManagementDaemon/PowerManagementDaemon/.gitignore0000644000175000017500000000134514205117452025643 0ustar fengfeng# This file is used to ignore files which are generated # ---------------------------------------------------------------------------- *~ *.autosave *.a *.core *.moc *.o *.obj *.orig *.rej *.so *.so.* *_pch.h.cpp *_resource.rc *.qm .#* *.*# core !core/ tags .DS_Store .directory *.debug Makefile* *.prl *.app moc_*.cpp ui_*.h qrc_*.cpp Thumbs.db *.res *.rc /.qmake.cache /.qmake.stash # qtcreator generated files *.pro.user* # xemacs temporary files *.flc # Vim temporary files .*.swp # Visual Studio generated files *.ib_pdb_index *.idb *.ilk *.pdb *.sln *.suo *.vcproj *vcproj.*.*.user *.ncb *.sdf *.opensdf *.vcxproj *vcxproj.* # MinGW generated files *.Debug *.Release # Python byte code *.pyc # Binaries # -------- *.dll *.exe ukui-power-manager/PowerManagementDaemon/gsettingwatcher/0000755000175000017500000000000014205117452022635 5ustar fengfengukui-power-manager/PowerManagementDaemon/gsettingwatcher/gsettingwatcher.h0000644000175000017500000000722414205117452026215 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef GSETTINGWATCHER_H #define GSETTINGWATCHER_H #include #include "eventwatcher.h" #include "acwatcher/acwatcher.h" #include "lowpowerwatcher/lowpowerwatcher.h" class GsettingWatcher : public EventWatcher { Q_OBJECT public: GsettingWatcher(); ~GsettingWatcher(); /** * @brief initGsettingWatcher * 初始化GsettingWatcher */ void initGsettingWatcher(); private: enum policy { Performance = 0, Balance, EnergySaving, }; /* * =============================================== * 以下为相关成员函数 * =============================================== */ /** * @brief initSettingsConnect * 初始化连接 */ void initSettingsConnect(); /** * @brief policyAC * 电源时使用策略 */ void policyAC(); /** * @brief policyBattery * 电池时使用策略 */ void policyBattery(); /** * @brief getCpuFreqMode * 获取CPU支持的调频策略 */ void getCpuFreqMode(); /** * @brief setCpuFreq * 设置CPU调频 */ void setCpuFreq(const int &policy); /** * @brief setGpuFreq * @param policy * 设置GPU模式 */ void setGpuFreq(const int &policy); /** * @brief setPolicy * @param policyState * 根据电池状态设置相应模式 */ void setPolicy(const bool &policyState); /** * @brief setBrightness * @param value * 电池状态改变时亮度调整 */ void setBrightness(const bool &value); bool lowBatteryState(); /* * =============================================== * 以下为成员变量 * =============================================== */ /** * @brief mPowerPolicyAc * AC状态电源策略 */ int mPowerPolicyAc; /** * @brief mPowerPolicyBattery * 电池状态电源策略 */ int mPowerPolicyBattery; /** * @brief mOnBatteryAutoSave * 低电量时自动开启节能模式 */ int mOnBatteryAutoSave; /** * @brief mLowBatteryAutoSave * 低电量时自动开启节能模式 */ int mLowBatteryAutoSave; /** * @brief mLowPrecentState * 低电量状态 */ bool mLowPrecentState; QByteArray mCpuMode; AcWatcher mAcWatcher; private slots: /** * @brief readSettings * 读取用户配置信息 */ void readSettings(); /** * @brief AcWatcherChanged * @param start * 供电状态改变 */ void AcWatcherChanged(const bool &start); /** * @brief setLowPowerState * @param lowPowerState * 更改低电量状态 */ void setLowPowerState(bool lowPowerState); /** * @brief increaseBrightness * 增加亮度 */ void increaseBrightness(); /** * @brief reduceBrightness * 调低亮度 */ void reduceBrightness(); }; #endif // GSETTINGWATCHER_H ukui-power-manager/PowerManagementDaemon/gsettingwatcher/gsettingwatcher.cpp0000644000175000017500000001500314205117452026542 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "gsettingwatcher.h" GsettingWatcher::GsettingWatcher() {} GsettingWatcher::~GsettingWatcher() {} void GsettingWatcher::initGsettingWatcher() { initSettingsConnect(); mAcWatcher.initAcWatcher(); } void GsettingWatcher::initSettingsConnect() { readSettings(); connect(mPowerManagementGsettings, &QGSettings::changed, this, [=](const QString &key) { if (key == POWER_POLICY_AC || key == POWER_POLICY_BATTERY || key == LOW_BATTERY_ATUO_SAVE) { readSettings(); setPolicy(mAcWatcher.mPowerState); } }); setPolicy(mAcWatcher.mPowerState); connect(&mAcWatcher, SIGNAL(acChanged(bool)), this, SLOT(AcWatcherChanged(bool))); QDBusConnection::sessionBus().connect( UKUI_UPOWER_SERVICE, UKUI_UPOWER_PATH, UKUI_UPOWER_INTERFACE, "LowBatteryState", this, SLOT(setLowPowerState(bool))); setLowPowerState(lowBatteryState()); } void GsettingWatcher::readSettings() { mPowerPolicyAc = mPowerManagementGsettings->get(POWER_POLICY_AC).toInt(); mPowerPolicyBattery = mPowerManagementGsettings->get(POWER_POLICY_BATTERY).toInt(); qDebug() << "policy ac :" << mPowerPolicyAc << "policy battery:" << mPowerPolicyBattery; mOnBatteryAutoSave = mPowerManagementGsettings->get(ON_BATTERY_AUTO_SAVE).toInt(); mLowBatteryAutoSave = mPowerManagementGsettings->get(LOW_BATTERY_ATUO_SAVE).toInt(); qDebug() << "On Battery Auto Save:" << mOnBatteryAutoSave << "Low Battery Auto Save:" << mLowBatteryAutoSave; } void GsettingWatcher::AcWatcherChanged(const bool &start) { setPolicy(start); setBrightness(start); } void GsettingWatcher::setPolicy(const bool &policyState) { if (true == policyState) { qDebug() << "power state is battery"; policyBattery(); } else { qDebug() << "power state is ac"; policyAC(); } } void GsettingWatcher::setBrightness(const bool &value) { if (true == value) { // 亮度降低 reduceBrightness(); } else { // 亮度增高 increaseBrightness(); } } void GsettingWatcher::setLowPowerState(bool lowPowerState) { mLowPrecentState = lowPowerState; setPolicy(mAcWatcher.readOnBattery()); qDebug() << "Is it currently in a low battery state:" << mLowPrecentState; } void GsettingWatcher::policyAC() { setCpuFreq(mPowerPolicyAc); setGpuFreq(mPowerPolicyAc); } void GsettingWatcher::policyBattery() { if (EnergySaving == mPowerPolicyBattery) { setCpuFreq(mPowerPolicyBattery); //控制面板设置节能模式 setGpuFreq(mPowerPolicyBattery); } else { if (0 == mLowBatteryAutoSave || !mLowPrecentState) { setCpuFreq(mPowerPolicyBattery); //低电量不自动开启平衡模式 或 非低电量 setCpuFreq(mPowerPolicyBattery); } else { setCpuFreq(EnergySaving); //低电量自动开启省电模式 低电量 setGpuFreq(EnergySaving); } } } void GsettingWatcher::setCpuFreq(const int &policy) { switch (policy) { case Performance: controlPowerManagement(CPU_FREQENCY_MODULATION, "performance"); break; case Balance: getCpuFreqMode(); if (-1 == mCpuMode.indexOf("schedutil")) { if (-1 == mCpuMode.indexOf("ondemand")) { controlPowerManagement(CPU_FREQENCY_MODULATION, "powersave"); } else { controlPowerManagement(CPU_FREQENCY_MODULATION, "ondemand"); } } else { controlPowerManagement(CPU_FREQENCY_MODULATION, "schedutil"); } break; case EnergySaving: controlPowerManagement(CPU_FREQENCY_MODULATION, "powersave"); break; default: break; } } void GsettingWatcher::setGpuFreq(const int &policy) { // qDebug()<<"设置GPU频率"; controlPowerManagement(GPU_FREQENCY_MODULATION, policy); } bool GsettingWatcher::lowBatteryState() { bool value; QDBusInterface iface(UKUI_UPOWER_SERVICE, UKUI_UPOWER_PATH, UKUI_UPOWER_INTERFACE, QDBusConnection::sessionBus()); QDBusReply reply = iface.call("LowBattery"); if (reply.isValid()) { value = reply.value(); } else { value = false; qDebug() << "low battery state error!"; } return value; } void GsettingWatcher::reduceBrightness() { if (10.0 < mPowerManagementGsettings->get(BRIGHTNESS_AC).toDouble()) { mMaxBrightness = controlPowerManagement(GET_MAX_BRIGHTNESS); mUserBrightness = mPowerManagementGsettings->get(BRIGHTNESS_AC).toDouble() - 10; if (10 > mUserBrightness) { mUserBrightness = 10; } mBrightness = mUserBrightness * 0.01 * mMaxBrightness; mPowerManagementGsettings->set(BRIGHTNESS_AC, mUserBrightness); qDebug() << "the brightness value is:" << mBrightness; } else { qDebug() << "Brightness is the lowest value"; } } void GsettingWatcher::increaseBrightness() { if (100.0 > mPowerManagementGsettings->get(BRIGHTNESS_AC).toDouble()) { mMaxBrightness = controlPowerManagement(GET_MAX_BRIGHTNESS); mUserBrightness = mPowerManagementGsettings->get(BRIGHTNESS_AC).toDouble() + 10; if (100 < mUserBrightness) { mUserBrightness = 100; } mBrightness = mUserBrightness * 0.01 * mMaxBrightness; mPowerManagementGsettings->set(BRIGHTNESS_AC, mUserBrightness); qDebug() << "the brightness value is:" << mBrightness; } else { qDebug() << "Brightness is the highest value"; } } void GsettingWatcher::getCpuFreqMode() { QFile file("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"); if (!file.open(QIODevice::ReadOnly)) { qDebug() << file.errorString(); } mCpuMode = file.readAll(); file.close(); } ukui-power-manager/PowerManagementDaemon/powermanagementdamon.h0000644000175000017500000000264114205117452024017 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef POWERMANAGEMENTDAMON_H #define POWERMANAGEMENTDAMON_H #include "idle/idlenesswatcher.h" #include "lidwatcher/lidwatcher.h" #include "acwatcher/acwatcher.h" #include "eventwatcher.h" #include "gsettingwatcher/gsettingwatcher.h" #include "lowpowerwatcher/lowpowerwatcher.h" #include "powermsgnotificat/powermsgnotificat.h" class PowerManagementDamon : public QObject { Q_OBJECT public: PowerManagementDamon(); ~PowerManagementDamon(); private: IdlenessWatchcer *idlenesswatcher; LidWatcher *lidwatcher; EventWatcher *eventwatcher; AcWatcher *acwatcher; GsettingWatcher *gsettingwatcher; LowPowerWatcher *lowpowerwatcher; PowerMsgNotificat *powermsgnotificat; }; #endif // POWERMANAGEMENTDAMON_H ukui-power-manager/PowerManagementDaemon/idle/0000755000175000017500000000000014205117543020351 5ustar fengfengukui-power-manager/PowerManagementDaemon/idle/idlenesswatcher.cpp0000644000175000017500000001460314205117543024245 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "idlenesswatcher.h" IdlenessWatchcer::IdlenessWatchcer() { } IdlenessWatchcer::~IdlenessWatchcer() { delete mTurnOffDisplayTimer; delete mReduceBrightnessTimer; delete mSuspendTimer; } void IdlenessWatchcer::initIdleWatcher() { //初始化gsettings,同时读配置文件 initSettingsConnect(); initTimer(); //监听到空闲信号,开始计时,启动timingBegins函数 QDBusConnection::sessionBus().connect( QString(), QString(SESSION_MANAGER_PATH), GNOME_SESSION_MANAGER, "StatusChanged", this, SLOT(timingBegins(quint32))); QDBusConnection::systemBus().connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep", this, SLOT(timingStop())); connect(mTurnOffDisplayTimer, &QTimer::timeout, [this] { turnOffDisplay(); mTurnOffDisplayTimer->stop(); }); connect(mReduceBrightnessTimer, &QTimer::timeout, [this] { reduceBrightness(); mReduceBrightnessTimer->stop(); }); connect(mSuspendTimer, &QTimer::timeout, [this] { suspend(); mSuspendTimer->stop(); }); //监听到非空闲信号,打断计时 } void IdlenessWatchcer::initSettingsConnect() { readSettings(); connect(mPowerManagementGsettings, &QGSettings::changed, this, [=] { readSettings(); }); } void IdlenessWatchcer::initTimer() { mTurnOffDisplayTimer = new QTimer; mReduceBrightnessTimer = new QTimer; mSuspendTimer = new QTimer; } void IdlenessWatchcer::readSettings() { //读配置文件 mTurnOffDisplayTimeBat = mPowerManagementGsettings->get(SLEEP_DISPLAY_BAT_KEY).toInt(); qDebug() << "mTurnOffDisplayTimeBat" << mTurnOffDisplayTimeBat; mTurnOffDisplayTimeAc = mPowerManagementGsettings->get(SLEEP_DISPLAY_AC_KEY).toInt(); qDebug() << "mTurnOffDisplayTimeAc" << mTurnOffDisplayTimeAc; mReduceBrightnessTime = mPowerManagementGsettings->get(IDLE_DIM_TIME).toInt(); qDebug() << "mReduceBrightnessTime" << mReduceBrightnessTime; mSuspendTimeAc = mPowerManagementGsettings->get(SLEEP_COMPUTER_AC).toInt(); qDebug() << "mSuspendTime" << mSuspendTimeAc; mSuspendTimeBat = mPowerManagementGsettings->get(SLEEP_COMPUTER_BATTERY).toInt(); } void IdlenessWatchcer::timingBegins(quint32 time) { int mTurnOffDisplayTime = turnOffDisplayTime() - mSessionTime; int mSuspendTime = suspendTime() - mSessionTime; int mBrightnessTime = -1; qDebug() << "Idle signal received from SessionManager" << time; if (0 != time) { if (mReduceBrightnessTime >= mSessionTime) { mBrightnessTime = mReduceBrightnessTime - mSessionTime; } if (0 <= mTurnOffDisplayTime) { mTurnOffDisplayTimer->start(mTurnOffDisplayTime * 1000); if (mBrightnessTime < mTurnOffDisplayTime && 0 <= mBrightnessTime) { mReduceBrightnessTimer->start(mBrightnessTime * 1000); } } else { qDebug() << "TurnOffDisplayTimer not started!"; if (0 <= mBrightnessTime) { mReduceBrightnessTimer->start(mBrightnessTime * 1000); } else { qDebug() << "ReduceBrightnessTimer not started!"; } } if (0 < mSuspendTime) { mSuspendTimer->start(mSuspendTime * 1000); } else { qDebug() << "SuspendTimer not started!"; } } else { timingStop(); getUserBrightness(); controlPowerManagement(REGULATE_BRIGHTNESS, mUserBrightness); } } int IdlenessWatchcer::turnOffDisplayTime() { QDBusInterface iface(UKUI_UPOWER_SERVICE, UKUI_UPOWER_PATH, UKUI_UPOWER_INTERFACE, QDBusConnection::sessionBus()); QDBusReply reply = iface.call("OnBattery"); if (reply.isValid()) { if (reply.value()) { qDebug() << "Time to turn off the display in battery state" << mTurnOffDisplayTimeBat; return mTurnOffDisplayTimeBat; } else { qDebug() << "Time to turn off the display in power state" << mTurnOffDisplayTimeAc; return mTurnOffDisplayTimeAc; } } else { qDebug() << "turn off display time get OnBattery error!"; return -1; } } int IdlenessWatchcer::suspendTime() { QDBusInterface iface(UKUI_UPOWER_SERVICE, UKUI_UPOWER_PATH, UKUI_UPOWER_INTERFACE, QDBusConnection::sessionBus()); QDBusReply reply = iface.call("OnBattery"); if (reply.isValid()) { if (reply.value()) { qDebug() << "Time to suspend in battery state" << mSuspendTimeBat; return mSuspendTimeBat; } else { qDebug() << "Time to suspend in power state" << mSuspendTimeAc; return mSuspendTimeAc; } } else { qDebug() << "suspend time get OnBattery error!"; return -1; } } void IdlenessWatchcer::timingStop() { qDebug() << "timing stop"; if (mTurnOffDisplayTimer->isActive()) { mTurnOffDisplayTimer->stop(); } if (mSuspendTimer->isActive()) { mSuspendTimer->stop(); } if (mReduceBrightnessTimer->isActive()) { mReduceBrightnessTimer->stop(); } } void IdlenessWatchcer::reduceBrightness() { if (0.1 < mPowerManagementGsettings->get(BRIGHTNESS_AC).toDouble()) { getUserBrightness(); mBrightness = mUserBrightness * 0.5; controlPowerManagement(REGULATE_BRIGHTNESS, mBrightness); qDebug() << "After idle, the brightness value is:" << mBrightness; } else { qDebug() << "Brightness is the lowest value"; } } ukui-power-manager/PowerManagementDaemon/idle/idlenesswatcher.h0000644000175000017500000000704714205117543023716 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef IDLENESSWATCHER_H #define IDLENESSWATCHER_H #include "eventwatcher.h" #include /** * @brief The IdlenessWatchcer class * 监听空闲的类 * 空闲后会有三个操作,分别是: * 1.降低屏幕亮度 * 2.关闭显示器 * 3.定时睡眠/休眠 */ class IdlenessWatchcer : public EventWatcher { Q_OBJECT public: IdlenessWatchcer(); ~IdlenessWatchcer(); /** * @brief initIdleWatcher * 初始化空闲监控类 * */ void initIdleWatcher(); private: /* * =============================================== * 以下为初始化相关成员函数 * =============================================== */ /** * @brief initSettingsConnect * 初始化GSetting并连接 */ void initSettingsConnect(); /** * @brief initTimer * 初始化定时器 */ void initTimer(); /** * @brief turnOffDisplayTime * 关闭显示器时间 * @return */ int turnOffDisplayTime(); /** * @brief suspendTime * 睡眠时间 * @return */ int suspendTime(); /* * =============================================== * 以下为成员变量,包括定时器,亮度值 * =============================================== */ /** * @brief mTurnOffDisplayTimer * 关闭显示器的定时器 */ QTimer *mTurnOffDisplayTimer; /** * @brief mReduceBrightnessTimer * 降低屏幕亮度的定时器 */ QTimer *mReduceBrightnessTimer; /** * @brief mSuspendTimer * 定时休眠/睡眠的定时器 */ QTimer *mSuspendTimer; /** * @brief mTurnOffDisplayTime * mTurnOffDisplayTime 毫秒后关闭显示器(电源情况下) */ int mTurnOffDisplayTimeAc; /** * @brief mTurnOffDisplayTimeBat * mTurnOffDisplayTimeBat毫秒后关闭显示器(电池情况下) */ int mTurnOffDisplayTimeBat; /** * @brief mReduceBrightnessTime * mReduceBrightnessTime毫秒后降低屏幕亮度 */ int mReduceBrightnessTime; /** * @brief mSuspendTimeBat * mSuspendTimeBat毫秒后睡眠(电池状态下) */ int mSuspendTimeBat; /** * @brief mSuspendTimeAc * mSuspendTimeAc毫秒后睡眠(电源状态下) */ int mSuspendTimeAc; /** * @brief mSessionTime * mSessionTime进入空闲时间 */ const int mSessionTime = 60; private slots: /** * @brief readSettings * 读配置文件 */ void readSettings(); /** * @brief timingBegins * 开始计时 */ void timingBegins(quint32); /** * @brief timingStop * 停止计时 */ void timingStop(); /** * @brief reduceBrightnessTiming * 降低屏幕亮度计时 */ void reduceBrightness(); }; #endif // IDLENESSWATCHER_H ukui-power-manager/PowerManagementDaemon/brightnessbutton/0000755000175000017500000000000014205117543023040 5ustar fengfengukui-power-manager/PowerManagementDaemon/brightnessbutton/buttonwatcher.cpp0000644000175000017500000000257614205117543026447 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "buttonwatcher.h" ButtonWatcher::ButtonWatcher() {} ButtonWatcher::~ButtonWatcher() {} void ButtonWatcher::initButtonWatcher() { QDBusConnection::sessionBus().connect( QString(), SETTINGS_DAEMON_MEDIAKEYS_PATH, SETTINGS_DAEMON_MEDIAKEYS, "brightnessDown", this, SLOT(dealBrightnessDown())); QDBusConnection::sessionBus().connect( QString(), SETTINGS_DAEMON_MEDIAKEYS_PATH, SETTINGS_DAEMON_MEDIAKEYS, "brightnessUp", this, SLOT(dealBrightnessUp())); } void ButtonWatcher::dealBrightnessDown() { emit brightnessDown(); } void ButtonWatcher::dealBrightnessUp() { emit brightnessUp(); } ukui-power-manager/PowerManagementDaemon/brightnessbutton/buttonwatcher.h0000644000175000017500000000207614205117543026107 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef BUTTONWATCHER_H #define BUTTONWATCHER_H #include #include "common.h" class ButtonWatcher : public QObject { Q_OBJECT public: ButtonWatcher(); ~ButtonWatcher(); void initButtonWatcher(); private slots: void dealBrightnessDown(); void dealBrightnessUp(); signals: void brightnessDown(); void brightnessUp(); }; #endif // BUTTONWATCHER_H ukui-power-manager/PowerManagementDaemon/main.cpp0000644000175000017500000000170314205117543021065 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "powermanagementdamon.h" #include #include int main(int argc, char *argv[]) { initUkuiLog4qt("ukui-powermanagement"); QApplication a(argc, argv); PowerManagementDamon w; // w.show(); return a.exec(); } ukui-power-manager/PowerManagementDaemon/common.h0000644000175000017500000000713314205117452021100 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef COMMON_H #define COMMON_H //Qt #include #include #include #include //gsettings 配置 #define POWER_MANAGER_SETTINGS "org.ukui.power-manager" //#define SLEEP_COMPUTER_BAT_KEY "sleepComputerBattery" #define SLEEP_DISPLAY_AC_KEY "sleepDisplayAc" #define SLEEP_DISPLAY_BAT_KEY "sleepDisplayBattery" //空闲关闭显示器 #define SLEEP_COMPUTER_AC "sleepComputerAc" #define SLEEP_COMPUTER_BATTERY "sleepComputerBattery" //空闲随睡 #define LOCK_BLANK_SCREEN "lockBlankScreen" #define IDLE_DIM_TIME "idleDimTime" #define BRIGHTNESS_AC "brightnessAc" //亮度值 #define BRIGHTNESS_BATTERY "brightnessBattery" #define BUTTON_LID_AC "buttonLidAc" //盒盖事件触发操作 #define BUTTON_LID_BATTERY "buttonLidBattery" #define POWER_POLICY_AC "powerPolicyAc" //电源策略(0:性能 1:平衡 2:节能) #define POWER_POLICY_BATTERY "powerPolicyBattery" #define ON_BATTERY_AUTO_SAVE "onBatteryAutoSave" //电池自动开启节能模式 #define LOW_BATTERY_ATUO_SAVE "lowBatteryAutoSave" //低电量时自动开启节能模式 #define PERCENTAGE_LOW "percentageLow" //低电量百分百通知 #define PERCENTAGE_ACTION "percentageAction" //极低电量 #define ACTION_CRITICAL_BATTERY "actionCriticalBattery" //极低电量时执行 //dbus 配置 #define GNOME_SESSION_MANAGER "org.gnome.SessionManager.Presence" #define SESSION_MANAGER_PATH "/org/gnome/SessionManager/Presence" #define POWER_MANAGEMENT_SERVICE "org.ukui.powermanagement" #define POWER_MANAGEMENT_PATH "/" #define POWER_MANAGEMENT_INTERFACE_NAME "org.ukui.powermanagement.interface" #define FREEDESKTOP_UPOWER "org.freedesktop.DBus.Properties" #define UKUI_UPOWER_PATH "/" #define UKUI_UPOWER_SERVICE "org.ukui.upower" #define UKUI_UPOWER_INTERFACE "org.ukui.upower" #define UPOWER_PATH "/org/freedesktop/UPower" #define UPOWER_SERVICE "org.freedesktop.UPower" #define UPOWER_DISPLAY_PATH "/org/freedesktop/UPower/devices/DisplayDevice" //电源管理dbus接口 #define CPU_FREQENCY_MODULATION "CpuFreqencyModulation" #define GET_BRIGHTNESS "GetBrightness" #define GET_MAX_BRIGHTNESS "GetMaxBrightness" #define GPU_FREQENCY_MODULATION "GpuFreqencyModulation" #define HIBERNATE "Hibernate" #define LOCK_SCREEN "LockScreen" #define POWER_OFF "PowerOff" #define REBOOT "Reboot" #define REGULATE_BRIGHTNESS "RegulateBrightness" #define SUSPEND "Suspend" #define TURN_OFF_DISPLAY "TurnOffDisplay" #define EXIT_SERVICE "ExitService" #endif // COMMON_H ukui-power-manager/PowerManagementDaemon/lowpowerwatcher/0000755000175000017500000000000014205117543022670 5ustar fengfengukui-power-manager/PowerManagementDaemon/lowpowerwatcher/lowpowerwatcher.cpp0000644000175000017500000001341314205117543026632 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "lowpowerwatcher.h" LowPowerWatcher::LowPowerWatcher() { } LowPowerWatcher::~LowPowerWatcher() { delete mContrlTimer; } void LowPowerWatcher::initLowPowerWatcher() { mContrlTimer = new QTimer; initConnect(); mPercentageLow = readPercentage(); if (mSetPercentageLow > mPercentageLow) { mLowPowerState = true; } else { mLowPowerState = false; } mNotifyState = false; } void LowPowerWatcher::initConnect() { readSettings(); connect(mPowerManagementGsettings, &QGSettings::changed, this, [=](const QString &key) { readSettings(); if (key == PERCENTAGE_ACTION || key == ACTION_CRITICAL_BATTERY) { veryLowBatteryContrlStop(); } }); QDBusConnection::sessionBus().connect( UKUI_UPOWER_SERVICE, UKUI_UPOWER_PATH, UKUI_UPOWER_INTERFACE, "PowerState", this, SLOT(dealPowerStateMssage(bool))); QDBusConnection::sessionBus().connect( UKUI_UPOWER_SERVICE, UKUI_UPOWER_PATH, UKUI_UPOWER_INTERFACE, "LowBatteryState", this, SLOT(dealLowBatteryMssage(bool))); QDBusConnection::sessionBus().connect( UKUI_UPOWER_SERVICE, UKUI_UPOWER_PATH, UKUI_UPOWER_INTERFACE, "VeryLowBatteryState", this, SLOT(dealVeryLowBatteryMssage(bool))); connect(mContrlTimer, &QTimer::timeout, [this] { veryLowBatteryContrl(mActionCriticalBattery); mContrlTimer->stop(); }); } void LowPowerWatcher::readSettings() { mSetPercentageLow = mPowerManagementGsettings->get(PERCENTAGE_LOW).toInt(); qDebug() << "mSetPercentageLow:" << mSetPercentageLow; mPercentageAction = mPowerManagementGsettings->get(PERCENTAGE_ACTION).toInt(); qDebug() << "mPercentageAction:" << mPercentageAction; mActionCriticalBattery = mPowerManagementGsettings->get(ACTION_CRITICAL_BATTERY).toString(); qDebug() << "mActionCriticalBattery:" << mActionCriticalBattery; } double LowPowerWatcher::readPercentage() { double value; QDBusInterface iface(UPOWER_SERVICE, UPOWER_DISPLAY_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus()); QDBusReply reply = iface.call("Get", "org.freedesktop.UPower.Device", "Percentage"); if (reply.isValid()) { value = reply.value().toDouble(); } else { qDebug() << "Power percentage get error!"; } return value; } void LowPowerWatcher::dealLowBatteryMssage(bool state) { mLowPowerState = state; if (mLowPowerState) { lowBatteryNotify(); } } void LowPowerWatcher::dealVeryLowBatteryMssage(bool state) { if (state && !mNotifyState) { veryLowBatteryNotify(mActionCriticalBattery); } } void LowPowerWatcher::dealPowerStateMssage(bool state) { if (!state) { veryLowBatteryContrlStop(); } } bool LowPowerWatcher::lowPowerState() { return mLowPowerState; } void LowPowerWatcher::lowBatteryNotify() { mPercentageLow = readPercentage(); if (mPercentageLow > mPercentageAction) { QString mType = tr("低电量通知"); notifySend(mType, "系统进入低电量状态"); qDebug() << "low battery notify send success"; } } void LowPowerWatcher::veryLowBatteryNotify(const QString &msg) { mPercentageLow = readPercentage(); QString mType = tr("极低电量通知"); if ("blank" == msg) { notifySend(mType, QString("当前电量为:%1%,系统将于一分钟后关闭显示器").arg(mPercentageLow)); } else if ("suspend" == msg) { notifySend(mType, QString("当前电量为:%1%,系统将于一分钟后睡眠").arg(mPercentageLow)); } else if ("shutdown" == msg) { notifySend(mType, QString("当前电量为:%1%,系统将于一分钟后关机").arg(mPercentageLow)); } else if ("hibernate" == msg) { notifySend(mType, QString("当前电量为:%1%,系统将于一分钟后休眠").arg(mPercentageLow)); } mNotifyState = true; mContrlTimer->start(60000); } void LowPowerWatcher::veryLowBatteryContrl(const QString &contrl) { if ("blank" == contrl) { turnOffDisplay(); } else if ("suspend" == contrl) { suspend(); } else if ("shutdown" == contrl) { powerOff(); } else if ("hibernate" == contrl) { hibernate(); } mNotifyState = false; } void LowPowerWatcher::veryLowBatteryContrlStop() { if (mContrlTimer->isActive()) { mContrlTimer->stop(); mNotifyState = false; } } void LowPowerWatcher::notifySend(const QString &type, const QString &arg) { QDBusInterface iface( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); QList args; QStringList argg; QMap pear_map; args << tr("电源管理") << ((unsigned int)0) << QString("ukui-power-manager") << type //显示的是什么类型的信息//系统升级 << arg //显示的具体信息 << argg << pear_map << (int)-1; iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); } ukui-power-manager/PowerManagementDaemon/lowpowerwatcher/lowpowerwatcher.h0000644000175000017500000000557114205117452026304 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef LOWPOWERWATCHER_H #define LOWPOWERWATCHER_H #include #include "acwatcher/acwatcher.h" #include "eventwatcher.h" class LowPowerWatcher : public EventWatcher { Q_OBJECT public: LowPowerWatcher(); ~LowPowerWatcher(); /** * @brief initLowPowerWatcher * 初始化LowPowerWatcher */ void initLowPowerWatcher(); bool lowPowerState(); private: /** * @brief initConnect * 初始化连接 */ void initConnect(); /** * @brief readSettings * 读取gsetting设置 */ void readSettings(); /** * @brief readPercentage * 从UPower读取当前电量百分比 * @return */ double readPercentage(); /** * @brief lowBatteryNotify * 低电量消息通知 */ void lowBatteryNotify(); /** * @brief veryLowBatteryNotify * @param msg * 极低电量执行操作通知 */ void veryLowBatteryNotify(const QString &msg); /** * @brief veryLowBatteryContrl * 极低电量进行操作 */ void veryLowBatteryContrl(const QString &contrl); /** * @brief veryLowBatteryContrlStop * 极低电量操作计时器打断 */ void veryLowBatteryContrlStop(); void notifySend(const QString &type, const QString &arg); /** * @brief mPercentageLow * 当前电量百分比 */ double mPercentageLow; /** * @brief mSetPercentageLow * 用户设置的低电量百分比 */ int mSetPercentageLow; /** * @brief mPercentageAction * 用户设置的极低电量百分比 */ int mPercentageAction; /** * @brief mActionCriticalBattery * 极低电量进行的操作设置 */ QString mActionCriticalBattery; // AcWatcher *mAcWatcher; QTimer *mContrlTimer; bool mLowPowerState; bool mNotifyState; // signals: // /** // * @brief lowPowerChanged // * 进入低电量状态信号 // */ // void lowPowerChanged(bool); private slots: void dealPowerStateMssage(bool state); void dealLowBatteryMssage(bool state); void dealVeryLowBatteryMssage(bool state); }; #endif // LOWPOWERWATCHER_H ukui-power-manager/registeredQDbus/0000755000175000017500000000000014205117543016313 5ustar fengfengukui-power-manager/registeredQDbus/conf/0000755000175000017500000000000014205117452017237 5ustar fengfengukui-power-manager/registeredQDbus/conf/org.ukui.powermanagement.service0000644000175000017500000000014314205117452025552 0ustar fengfeng[D-BUS Service] Name=org.ukui.powermanagement Exec=/usr/bin/ukui-powermanagement-service User=root ukui-power-manager/registeredQDbus/conf/org.ukui.powermanagement.conf0000644000175000017500000000162514205117452025045 0ustar fengfeng ukui-power-manager/registeredQDbus/sysdbusregister.h0000644000175000017500000000770414205117452021734 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #ifndef SYSDBUSREGISTER_H #define SYSDBUSREGISTER_H #include #include #include #include #include #include #include #include #include #include #include class SysdbusRegister : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.ukui.powermanagement.interface") public: explicit SysdbusRegister(); ~SysdbusRegister(); /** * @brief executeLinuxCmd * @return 返回执行命令后返回内容 * 调用linux终端 */ QString executeLinuxCmd(QString strCmd); private: /** * @brief controlLogin1Connection * 创建与login1的dbus连接 */ void controlLogin1Connection(QString ); QString canControl(const QString ); /** * @brief setSuspendThenHibernate * 设置S3转S4时间(2小时) */ void setSuspendThenHibernate(); //目前用来区分CPU /** * @brief getCpuInfo * 获取CPU信息 * @return */ int getCpuInfo(); /** * @brief getBacklightFile * 查看backlight中文件 * @return */ QString getBacklightFile(int); /** * @brief getBacklightFileNum * 获取backlight中文件个数 * @return */ int getBacklightFileNum(); QProcess mProcess; QByteArray mCpuType; QSettings *mSusThenHibSet; enum policy { Performance = 0, Balance, EnergySaving, }; enum cpuModelName { OTHER = 0, Intel, ZHAOXIN, Phytium, Loongson3A5000, HUAWEI, }; signals: Q_SCRIPTABLE void nameChanged(QString); public slots: Q_SCRIPTABLE void ExitService(); /** * @brief RegulateBrightness * 调整屏幕亮度 */ Q_SCRIPTABLE QString RegulateBrightness(qulonglong); /** * @brief TurnOffDisplay * 关闭显示器 */ Q_SCRIPTABLE void TurnOffDisplay(); /** * @brief CpuFreqencyModulation * cpu调频策略修改 */ Q_SCRIPTABLE void CpuFreqencyModulation(const QString); /** * @brief GpuFreqencyModulation * gpu调频策略修改 */ Q_SCRIPTABLE void GpuFreqencyModulation(const int); /** * @brief LockScreen * 锁屏 */ Q_SCRIPTABLE void LockScreen(); /** * @brief Hibernate * 重写休眠接口,以适应不同项目的休眠需求 */ Q_SCRIPTABLE void Hibernate(); /** * @brief Suspend * 重写睡眠接口,以适应不同项目的休眠需求 */ Q_SCRIPTABLE void Suspend(); /** * @brief PowerOff * 关机接口 */ Q_SCRIPTABLE void PowerOff(); /** * @brief Reboot * 重启接口 */ Q_SCRIPTABLE void Reboot(); /** * @brief GetMaxBrightness * 获取屏幕亮度的最大值 */ Q_SCRIPTABLE qulonglong GetMaxBrightness(); /** * @brief GetMaxBrightness * 获取屏幕当前亮度 */ Q_SCRIPTABLE int GetBrightness(); /** * @brief SuspendThenHibernate * 睡眠转休眠(时间默认设置为2小时) */ Q_SCRIPTABLE void SuspendThenHibernate(); private: int modelName; }; #endif // SYSDBUSREGISTER_H ukui-power-manager/registeredQDbus/sysdbusregister.cpp0000644000175000017500000002166214205117543022267 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include "sysdbusregister.h" #include #include #include #include #include SysdbusRegister::SysdbusRegister() { if (1 == getBacklightFileNum()) { modelName = OTHER; } else { modelName = getCpuInfo(); } mSusThenHibSet = new QSettings(QString("/etc/systemd/sleep.conf"), QSettings::IniFormat, this); mSusThenHibSet->setIniCodec("UTF-8"); } SysdbusRegister::~SysdbusRegister() { delete mSusThenHibSet; } void SysdbusRegister::ExitService() { qApp->exit(0); } QString SysdbusRegister::executeLinuxCmd(QString strCmd) { //调用linux终端命令 mProcess.start("bash", QStringList() << "-c" << strCmd); mProcess.waitForFinished(); QString strResult = mProcess.readAllStandardOutput() + mProcess.readAllStandardError(); return strResult; } QString SysdbusRegister::canControl(const QString control) { QDBusInterface iface( "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()); QDBusReply reply = iface.call(control); if (reply.isValid()) { if ("yes" == reply.value()) { return reply; } else { QDBusMessage message = QDBusMessage::createSignal("/", "org.ukui.powermanagement.interface", "CanControl"); message << reply.value(); QDBusConnection::systemBus().send(message); return reply; } } else { return "error"; } } void SysdbusRegister::controlLogin1Connection(QString type) { bool ctrl = 1; QDBusInterface iface( "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()); iface.call(type, ctrl); } qulonglong SysdbusRegister::GetMaxBrightness() { qulonglong maxValue; switch (modelName) { case ZHAOXIN: maxValue = executeLinuxCmd("cat /sys/class/backlight/acpi_video1/max_brightness").toInt(); break; case Phytium: maxValue = executeLinuxCmd("cat /sys/class/backlight/ec_bl/max_brightness").toInt(); break; case Loongson3A5000: maxValue = executeLinuxCmd( QString("cat /sys/class/backlight/%1/max_brightness").arg(getBacklightFile(Loongson3A5000))) .toInt(); break; case OTHER: maxValue = executeLinuxCmd("cat /sys/class/backlight/*/max_brightness").toInt(); break; default: break; } return maxValue; } int SysdbusRegister::GetBrightness() { int value; switch (modelName) { case ZHAOXIN: value = executeLinuxCmd("cat /sys/class/backlight/acpi_video1/brightness").toInt(); break; case Phytium: value = executeLinuxCmd("cat /sys/class/backlight/ec_bl/brightness").toInt(); break; case Loongson3A5000: value = executeLinuxCmd( QString("cat /sys/class/backlight/%1/brightness").arg(getBacklightFile(Loongson3A5000))) .toInt(); break; case OTHER: value = executeLinuxCmd("cat /sys/class/backlight/*/brightness").toInt(); break; default: break; } return value; } QString SysdbusRegister::RegulateBrightness(qulonglong brightness) { QString msg; switch (modelName) { case ZHAOXIN: break; case Phytium: msg = executeLinuxCmd(QString("echo %1 | tee /sys/class/backlight/ec_bl/brightness").arg(brightness)); break; case Loongson3A5000: msg = executeLinuxCmd(QString("echo %1 | tee /sys/class/backlight/%2/brightness") .arg(brightness) .arg(getBacklightFile(Loongson3A5000))); break; case OTHER: msg = executeLinuxCmd(QString("echo %1 | tee /sys/class/backlight/*/brightness").arg(brightness)); break; default: break; } return msg; } QString SysdbusRegister::getBacklightFile(int type) { if (Loongson3A5000 == type) { QFile loongsonGpuFile("/sys/class/backlight/loongson-gpu"); if (loongsonGpuFile.exists()) { return QString("loongson-gpu"); } else { return QString("loongson_laptop"); } } else { return QString("*"); } } int SysdbusRegister::getBacklightFileNum() { QDir dir("/sys/class/backlight"); QStringList filter; QStringList filterAll; filter << ".*"; dir.setNameFilters(filter); QList fileInfo = dir.entryInfoList(filter); int num = fileInfo.count(); fileInfo = dir.entryInfoList(filterAll); int numAll = fileInfo.count(); return numAll - num; } void SysdbusRegister::TurnOffDisplay() { //关闭显示器由后台处理 } void SysdbusRegister::CpuFreqencyModulation(QString strategy) { int cpuQuantity = executeLinuxCmd("grep -c 'processor' /proc/cpuinfo").toInt(); for (int var = 0; var < cpuQuantity; ++var) { executeLinuxCmd( QString("echo %1 | tee /sys/devices/system/cpu/cpu%2/cpufreq/scaling_governor").arg(strategy).arg(var)); } } void SysdbusRegister::GpuFreqencyModulation(int strategy) { QFile radeonFile("/sys/class/drm/card0/device/power_dpm_state"); QFile amdgpuFile("/sys/class/drm/card0/device/power_dpm_force_performance_level"); if (radeonFile.exists()) { switch (strategy) { case Performance: executeLinuxCmd(QString("echo performance | tee /sys/class/drm/card0/device/power_dpm_state")); break; case Balance: executeLinuxCmd(QString("echo balanced | tee /sys/class/drm/card0/device/power_dpm_state")); break; case EnergySaving: executeLinuxCmd(QString("echo battery | tee /sys/class/drm/card0/device/power_dpm_state")); break; default: break; } } if (amdgpuFile.exists()) { switch (strategy) { case Performance: executeLinuxCmd( QString("echo high | tee /sys/class/drm/card0/device/power_dpm_force_performance_level")); break; case Balance: executeLinuxCmd( QString("echo auto | tee /sys/class/drm/card0/device/power_dpm_force_performance_level")); break; case EnergySaving: executeLinuxCmd( QString("echo low | tee /sys/class/drm/card0/device/power_dpm_force_performance_level")); break; default: break; } } } void SysdbusRegister::LockScreen() { //锁屏目前由后台处理 } void SysdbusRegister::Hibernate() { if ("yes" == canControl("CanHibernate")) { controlLogin1Connection("Hibernate"); } } void SysdbusRegister::Suspend() { if ("yes" == canControl("CanSuspend")) { controlLogin1Connection("Suspend"); } } void SysdbusRegister::PowerOff() { if ("yes" == canControl("CanPowerOff")) { controlLogin1Connection("PowerOff"); } } void SysdbusRegister::Reboot() { if ("yes" == canControl("CanReboot")) { controlLogin1Connection("Reboot"); } } void SysdbusRegister::SuspendThenHibernate() { if ("yes" == canControl("CanSuspendThenHibernate")) { mSusThenHibSet->beginGroup("Sleep"); mSusThenHibSet->setValue("HibernateDelaySec", 7200); mSusThenHibSet->endGroup(); mSusThenHibSet->sync(); controlLogin1Connection("SuspendThenHibernate"); } } int SysdbusRegister::getCpuInfo() { QFile file("/proc/cpuinfo"); if (!file.open(QIODevice::ReadOnly)) { qDebug() << file.errorString(); } mCpuType = file.readAll(); file.close(); if (-1 != mCpuType.indexOf("ZHAOXIN")) { return ZHAOXIN; } else if (-1 != mCpuType.indexOf("D2000")) { return Phytium; } else if (-1 != mCpuType.indexOf("3A5000")) { return Loongson3A5000; } else if (-1 != mCpuType.indexOf("FT-2000")) { return Phytium; } else { return OTHER; } } ukui-power-manager/registeredQDbus/main.cpp0000644000175000017500000000301614205117452017742 0ustar fengfeng/* * Copyright 2021 KylinSoft 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 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, see . */ #include #include #include #include #include #include "sysdbusregister.h" int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); app.setOrganizationName("Kylin Team"); app.setApplicationName("ukui-powermanagement-service"); QDBusConnection systemBus = QDBusConnection::systemBus(); if (!systemBus.registerService("org.ukui.powermanagement")) { 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(); } ukui-power-manager/registeredQDbus/registeredQDbus.pro0000644000175000017500000000122114205117452022124 0ustar fengfengQT += core dbus x11extras QT -= gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = ukui-powermanagement-service TEMPLATE = app CONFIG += console c++11 link_pkgconfig CONFIG -= app_bundle DESTDIR = . INCLUDEPATH += . DEFINES += MODULE_NAME=\\\"pm\\\" inst1.files += conf/org.ukui.powermanagement.service inst1.path = /usr/share/dbus-1/system-services/ inst2.files += conf/org.ukui.powermanagement.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 \ ukui-power-manager/.gitattributes0000644000175000017500000000006414205117452016111 0ustar fengfengdebian/changelog debian/compat debian/source/format ukui-power-manager/0000755000175000017500000000000014205117543013217 5ustar fengfengukui-power-manager/readme.md0000644000175000017500000000000014205117452022260 1ukui-power-manager/readme.mdustar fengfengukui-power-manager/doc/0000755000175000017500000000000014205117452013763 5ustar fengfengukui-power-manager/doc/schedules.md0000644000175000017500000000000014205117452025036 1ukui-power-manager/doc/schedules.mdustar fengfengukui-power-manager/doc/性能测试注意事项.md0000644000175000017500000000000014205117452042370 1ukui-power-manager/doc/性能测试注意事项.mdustar fengfengukui-power-manager/doc/设计文档.md0000644000175000017500000000000014205117452032016 1ukui-power-manager/doc/设计文档.mdustar fengfengukui-power-manager/doc/电源管理需求文档.md0000644000175000017500000000000014205117452042132 1ukui-power-manager/doc/电源管理需求文档.mdustar fengfengukui-power-manager/data/0000755000175000017500000000000014205117452014127 5ustar fengfengukui-power-manager/data/ukui.power.policy.conf0000755000175000017500000000000014205117452031301 1ukui-power-manager/data/ukui.power.policy.confustar fengfengukui-power-manager/data/ukui-power-manager-tray.10000644000175000017500000000000014205117452032100 1ukui-power-manager/data/ukui-power-manager-tray.1ustar fengfengukui-power-manager/data/gpm-feedback-widget.ui0000644000175000017500000000000014205117452031016 1ukui-power-manager/data/gpm-feedback-widget.uiustar fengfengukui-power-manager/data/ukui-power-statistics.desktop.in.in0000644000175000017500000000000014205117452036354 1ukui-power-manager/data/ukui-power-statistics.desktop.in.inustar fengfengukui-power-manager/data/org.ukui.PowerManager.service.in0000644000175000017500000000000014205117452035004 1ukui-power-manager/data/org.ukui.PowerManager.service.inustar fengfengukui-power-manager/data/gpm-prefs.ui0000644000175000017500000000000014205117452025242 1ukui-power-manager/data/gpm-prefs.uiustar fengfengukui-power-manager/data/gpm-statistics.ui0000644000175000017500000000000014205117452027370 1ukui-power-manager/data/gpm-statistics.uiustar fengfengukui-power-manager/data/99-upower-wake-up-usb-device.rules0000644000175000017500000000000014205117452035222 1ukui-power-manager/data/99-upower-wake-up-usb-device.rulesustar fengfengukui-power-manager/data/ukui-power-manager-tray.desktop.in.in0000644000175000017500000000000014205117452036746 1ukui-power-manager/data/ukui-power-manager-tray.desktop.in.inustar fengfengukui-power-manager/data/ukui-power-manager.10000644000175000017500000000000014205117452030146 1ukui-power-manager/data/ukui-power-manager.1ustar fengfengukui-power-manager/data/acme.ui0000644000175000017500000000000014205117452023254 1ukui-power-manager/data/acme.uiustar fengfengukui-power-manager/data/power-ignore.conf0000644000175000017500000000000014205117452027314 1ukui-power-manager/data/power-ignore.confustar fengfengukui-power-manager/data/ukui-power-policy.service0000644000175000017500000000000014205117452032520 1ukui-power-manager/data/ukui-power-policy.serviceustar fengfengukui-power-manager/data/org.ukui.power-manager.gschema.xml.in0000644000175000017500000000000014205117452036652 1ukui-power-manager/data/org.ukui.power-manager.gschema.xml.inustar fengfengukui-power-manager/data/ukui-power-manager0000644000175000017500000000000014205117452027650 1ukui-power-manager/data/ukui-power-managerustar fengfengukui-power-manager/data/ukui-power-preferences.10000644000175000017500000000000014205117452031724 1ukui-power-manager/data/ukui-power-preferences.1ustar fengfengukui-power-manager/data/Makefile.am0000644000175000017500000000000014205117452024634 1ukui-power-manager/data/Makefile.amustar fengfengukui-power-manager/data/ukui-power-manager.desktop.in.in0000644000175000017500000000000014205117452035014 1ukui-power-manager/data/ukui-power-manager.desktop.in.inustar fengfengukui-power-manager/data/ukui-power-statistics.10000644000175000017500000000000014205117452031506 1ukui-power-manager/data/ukui-power-statistics.1ustar fengfengukui-power-manager/data/ukui-power-backlight-helper.10000644000175000017500000000000014205117452033534 1ukui-power-manager/data/ukui-power-backlight-helper.1ustar fengfengukui-power-manager/data/ukui-power-preferences.desktop.in.in0000644000175000017500000000000014205117452036572 1ukui-power-manager/data/ukui-power-preferences.desktop.in.inustar fengfengukui-power-manager/COPYING0000644000175000017500000000000014205117452021010 1ukui-power-manager/COPYINGustar fengfengukui-power-manager/powermanagement.pro0000644000175000017500000000000014205117452026550 1ukui-power-manager/powermanagement.proustar fengfengukui-power-manager/ukui-upower/0000755000175000017500000000000014205117543015513 5ustar fengfengukui-power-manager/ukui-upower/dbus-ukuipower.h0000644000175000017500000000000014205117452032006 1ukui-power-manager/ukui-upower/dbus-ukuipower.hustar fengfengukui-power-manager/ukui-upower/ukui-upower.pro0000644000175000017500000000000014205117452031546 1ukui-power-manager/ukui-upower/ukui-upower.proustar fengfengukui-power-manager/ukui-upower/dbus-ukuipower.cpp0000644000175000017500000000000014205117452032674 1ukui-power-manager/ukui-upower/dbus-ukuipower.cppustar fengfengukui-power-manager/ukui-upower/dbus.h0000644000175000017500000000000014205117452025726 1ukui-power-manager/ukui-upower/dbus.hustar fengfengukui-power-manager/ukui-upower/client/0000755000175000017500000000000014205117543016771 5ustar fengfengukui-power-manager/ukui-upower/client/Readme.md0000644000175000017500000000000014205117543031505 1ukui-power-manager/ukui-upower/client/Readme.mdustar fengfengukui-power-manager/ukui-upower/client/widget.h0000644000175000017500000000000014205117543031337 1ukui-power-manager/ukui-upower/client/widget.hustar fengfengukui-power-manager/ukui-upower/client/widget.ui0000644000175000017500000000000014205117543031713 1ukui-power-manager/ukui-upower/client/widget.uiustar fengfengukui-power-manager/ukui-upower/client/widget.cpp0000644000175000017500000000000014205117543032225 1ukui-power-manager/ukui-upower/client/widget.cppustar fengfengukui-power-manager/ukui-upower/client/main.cpp0000644000175000017500000000000014205117543031327 1ukui-power-manager/ukui-upower/client/main.cppustar fengfengukui-power-manager/ukui-upower/client/client.pro0000644000175000017500000000000014205117543032247 1ukui-power-manager/ukui-upower/client/client.proustar fengfengukui-power-manager/ukui-upower/client/client.pro.user0000644000175000017500000000000014205117543034201 1ukui-power-manager/ukui-upower/client/client.pro.userustar fengfengukui-power-manager/ukui-upower/common/0000755000175000017500000000000014205117452017002 5ustar fengfengukui-power-manager/ukui-upower/common/common.h0000644000175000017500000000000014205117452031374 1ukui-power-manager/ukui-upower/common/common.hustar fengfengukui-power-manager/ukui-upower/dbus.cpp0000644000175000017500000000000014205117452026614 1ukui-power-manager/ukui-upower/dbus.cppustar fengfengukui-power-manager/ukui-upower/upowerinfo/0000755000175000017500000000000014205117452017707 5ustar fengfengukui-power-manager/ukui-upower/upowerinfo/upowerinfo.h0000644000175000017500000000000014205117452035020 1ukui-power-manager/ukui-upower/upowerinfo/upowerinfo.hustar fengfengukui-power-manager/ukui-upower/upowerinfo/upowerinfo.cpp0000644000175000017500000000000014205117452035706 1ukui-power-manager/ukui-upower/upowerinfo/upowerinfo.cppustar fengfengukui-power-manager/ukui-upower/resources/0000755000175000017500000000000014205117543017525 5ustar fengfengukui-power-manager/ukui-upower/resources/10-monitor.conf0000644000175000017500000000000014205117452035066 1ukui-power-manager/ukui-upower/resources/10-monitor.confustar fengfengukui-power-manager/ukui-upower/resources/org.ukui.power-manager.gschema.xml0000644000175000017500000000000014205117543044633 1ukui-power-manager/ukui-upower/resources/org.ukui.power-manager.gschema.xmlustar fengfengukui-power-manager/ukui-upower/resources/99-upower-wake-up-usb-device.rules0000644000175000017500000000000014205117452044214 1ukui-power-manager/ukui-upower/resources/99-upower-wake-up-usb-device.rulesustar fengfengukui-power-manager/ukui-upower/resources/ukui-upower.desktop0000644000175000017500000000000014205117452037314 1ukui-power-manager/ukui-upower/resources/ukui-upower.desktopustar fengfengukui-power-manager/ukui-upower/server/0000755000175000017500000000000014205117543017021 5ustar fengfengukui-power-manager/ukui-upower/server/dbus-ukuipower.h0000644000175000017500000000000014205117543034623 1ukui-power-manager/ukui-upower/server/dbus-ukuipower.hustar fengfengukui-power-manager/ukui-upower/server/dbus-ukuipower.cpp0000644000175000017500000000000014205117543035511 1ukui-power-manager/ukui-upower/server/dbus-ukuipower.cppustar fengfengukui-power-manager/ukui-upower/server/dbus.h0000644000175000017500000000000014205117543030543 1ukui-power-manager/ukui-upower/server/dbus.hustar fengfengukui-power-manager/ukui-upower/server/common/0000755000175000017500000000000014205117543020311 5ustar fengfengukui-power-manager/ukui-upower/server/common/common.h0000644000175000017500000000000014205117543034211 1ukui-power-manager/ukui-upower/server/common/common.hustar fengfengukui-power-manager/ukui-upower/server/widget.h0000644000175000017500000000000014205117543031417 1ukui-power-manager/ukui-upower/server/widget.hustar fengfengukui-power-manager/ukui-upower/server/dbus.cpp0000644000175000017500000000000014205117543031431 1ukui-power-manager/ukui-upower/server/dbus.cppustar fengfengukui-power-manager/ukui-upower/server/widget.ui0000644000175000017500000000000014205117543031773 1ukui-power-manager/ukui-upower/server/widget.uiustar fengfengukui-power-manager/ukui-upower/server/upowerinfo/0000755000175000017500000000000014205117543021216 5ustar fengfengukui-power-manager/ukui-upower/server/upowerinfo/upowerinfo.h0000644000175000017500000000000014205117543037635 1ukui-power-manager/ukui-upower/server/upowerinfo/upowerinfo.hustar fengfengukui-power-manager/ukui-upower/server/upowerinfo/upowerinfo.cpp0000644000175000017500000000000014205117543040523 1ukui-power-manager/ukui-upower/server/upowerinfo/upowerinfo.cppustar fengfengukui-power-manager/ukui-upower/server/resources/0000755000175000017500000000000014205117543021033 5ustar fengfengukui-power-manager/ukui-upower/server/resources/10-monitor.conf0000644000175000017500000000000014205117543037703 1ukui-power-manager/ukui-upower/server/resources/10-monitor.confustar fengfengukui-power-manager/ukui-upower/server/resources/org.ukui.power-manager.gschema.xml0000644000175000017500000000000014205117543047447 1ukui-power-manager/ukui-upower/server/resources/org.ukui.power-manager.gschema.xmlustar fengfengukui-power-manager/ukui-upower/server/resources/ukui-upower.desktop0000644000175000017500000000000014205117543042131 1ukui-power-manager/ukui-upower/server/resources/ukui-upower.desktopustar fengfengukui-power-manager/ukui-upower/server/org.ukui.upower.xml0000644000175000017500000000000014205117543035741 1ukui-power-manager/ukui-upower/server/org.ukui.upower.xmlustar fengfengukui-power-manager/ukui-upower/server/widget.cpp0000644000175000017500000000000014205117543032305 1ukui-power-manager/ukui-upower/server/widget.cppustar fengfengukui-power-manager/ukui-upower/server/org.ukui.power.xml0000644000175000017500000000000014205117543035367 1ukui-power-manager/ukui-upower/server/org.ukui.power.xmlustar fengfengukui-power-manager/ukui-upower/server/server.pro0000644000175000017500000000000014205117543032407 1ukui-power-manager/ukui-upower/server/server.proustar fengfengukui-power-manager/ukui-upower/server/batteryinfo/0000755000175000017500000000000014205117543021347 5ustar fengfengukui-power-manager/ukui-upower/server/batteryinfo/batteryinfo.cpp0000644000175000017500000000000014205117543041267 1ukui-power-manager/ukui-upower/server/batteryinfo/batteryinfo.cppustar fengfengukui-power-manager/ukui-upower/server/batteryinfo/batteryinfo.h0000644000175000017500000000000014205117543040401 1ukui-power-manager/ukui-upower/server/batteryinfo/batteryinfo.hustar fengfengukui-power-manager/ukui-upower/server/main.cpp0000644000175000017500000000000014205117543031407 1ukui-power-manager/ukui-upower/server/main.cppustar fengfengukui-power-manager/ukui-upower/org.ukui.upower.xml0000644000175000017500000000000014205117452033124 1ukui-power-manager/ukui-upower/org.ukui.upower.xmlustar fengfengukui-power-manager/ukui-upower/org.ukui.power.xml0000644000175000017500000000000014205117452032552 1ukui-power-manager/ukui-upower/org.ukui.power.xmlustar fengfengukui-power-manager/ukui-upower/batteryinfo/0000755000175000017500000000000014205117452020040 5ustar fengfengukui-power-manager/ukui-upower/batteryinfo/batteryinfo.cpp0000644000175000017500000000000014205117452036452 1ukui-power-manager/ukui-upower/batteryinfo/batteryinfo.cppustar fengfengukui-power-manager/ukui-upower/batteryinfo/batteryinfo.h0000644000175000017500000000000014205117452035564 1ukui-power-manager/ukui-upower/batteryinfo/batteryinfo.hustar fengfengukui-power-manager/ukui-upower/main.cpp0000644000175000017500000000000014205117452026572 1ukui-power-manager/ukui-upower/main.cppustar fengfengukui-power-manager/ukui-upower/README.md0000644000175000017500000000000014205117452026250 1ukui-power-manager/ukui-upower/README.mdustar fengfengukui-power-manager/.github/0000755000175000017500000000000014205117452014556 5ustar fengfengukui-power-manager/.github/workflows/0000755000175000017500000000000014205117452016613 5ustar fengfengukui-power-manager/.github/workflows/build.yml0000644000175000017500000000000014205117452031360 1ukui-power-manager/.github/workflows/build.ymlustar fengfengukui-power-manager/ukui-power-manager-tray/0000755000175000017500000000000014205117543017713 5ustar fengfengukui-power-manager/ukui-power-manager-tray/enginedevice.h0000644000175000017500000000000014205117543035507 1ukui-power-manager/ukui-power-manager-tray/enginedevice.hustar fengfengukui-power-manager/ukui-power-manager-tray/mainwindow.h0000644000175000017500000000000014205117543034765 1ukui-power-manager/ukui-power-manager-tray/mainwindow.hustar fengfengukui-power-manager/ukui-power-manager-tray/device.cpp0000644000175000017500000000000014205117543034021 1ukui-power-manager/ukui-power-manager-tray/device.cppustar fengfengukui-power-manager/ukui-power-manager-tray/powertray.h0000644000175000017500000000000014205117452034524 1ukui-power-manager/ukui-power-manager-tray/powertray.hustar fengfengukui-power-manager/ukui-power-manager-tray/powerwindow.h0000755000175000017500000000000014205117543035410 1ukui-power-manager/ukui-power-manager-tray/powerwindow.hustar fengfengukui-power-manager/ukui-power-manager-tray/enginedevice.cpp0000644000175000017500000000000014205117543036375 1ukui-power-manager/ukui-power-manager-tray/enginedevice.cppustar fengfengukui-power-manager/ukui-power-manager-tray/xatom-helper.cpp0000644000175000017500000000000014205117452036334 1ukui-power-manager/ukui-power-manager-tray/xatom-helper.cppustar fengfengukui-power-manager/ukui-power-manager-tray/mainwindow.cpp0000644000175000017500000000000014205117543035653 1ukui-power-manager/ukui-power-manager-tray/mainwindow.cppustar fengfengukui-power-manager/ukui-power-manager-tray/xatom-helper.h0000644000175000017500000000000014205117452035446 1ukui-power-manager/ukui-power-manager-tray/xatom-helper.hustar fengfengukui-power-manager/ukui-power-manager-tray/ukui-power-manager-tray.pro0000644000175000017500000000000014205117543042547 1ukui-power-manager/ukui-power-manager-tray/ukui-power-manager-tray.proustar fengfengukui-power-manager/ukui-power-manager-tray/powertray.cpp0000644000175000017500000000000014205117543035413 1ukui-power-manager/ukui-power-manager-tray/powertray.cppustar fengfengukui-power-manager/ukui-power-manager-tray/resources/0000755000175000017500000000000014205117452021724 5ustar fengfengukui-power-manager/ukui-power-manager-tray/resources/ukui-power-manager-tray.desktop0000644000175000017500000000000014205117452050314 1ukui-power-manager/ukui-power-manager-tray/resources/ukui-power-manager-tray.desktopustar fengfengukui-power-manager/ukui-power-manager-tray/engine_common.h0000644000175000017500000000000014205117452036066 1ukui-power-manager/ukui-power-manager-tray/engine_common.hustar fengfengukui-power-manager/ukui-power-manager-tray/translations/0000755000175000017500000000000014205117543022434 5ustar fengfengukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_zh_CN.qm0000644000175000017500000000000014205117543051605 1ukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_zh_CN.qmustar fengfengukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_zh_CN.ts0000644000175000017500000000000014205117543051627 1ukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_zh_CN.tsustar fengfengukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_bo.ts0000644000175000017500000000000014205117543050625 1ukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_bo.tsustar fengfengukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_tr.ts0000644000175000017500000000000014205117543050677 1ukui-power-manager/ukui-power-manager-tray/translations/ukui-power-manager-tray_tr.tsustar fengfengukui-power-manager/ukui-power-manager-tray/powerwindow.cpp0000755000175000017500000000000014205117543036276 1ukui-power-manager/ukui-power-manager-tray/powerwindow.cppustar fengfengukui-power-manager/ukui-power-manager-tray/main.cpp0000644000175000017500000000000014205117543033173 1ukui-power-manager/ukui-power-manager-tray/main.cppustar fengfengukui-power-manager/ukui-power-manager-tray/device.h0000644000175000017500000000000014205117452033132 1ukui-power-manager/ukui-power-manager-tray/device.hustar fengfengukui-power-manager/man/0000755000175000017500000000000014205117543013772 5ustar fengfengukui-power-manager/man/ukui-power-manager-tray.10000644000175000017500000000000014205117452031604 1ukui-power-manager/man/ukui-power-manager-tray.1ustar fengfengukui-power-manager/man/ukui-power-manager.10000644000175000017500000000000014205117452027652 1ukui-power-manager/man/ukui-power-manager.1ustar fengfengukui-power-manager/man/ukui-powermanagement-service.10000644000175000017500000000000014205117452034020 1ukui-power-manager/man/ukui-powermanagement-service.1ustar fengfengukui-power-manager/man/ukui-powermanagement.10000644000175000017500000000000014205117452030724 1ukui-power-manager/man/ukui-powermanagement.1ustar fengfengukui-power-manager/man/ukui-upower.10000644000175000017500000000000014205117452025204 1ukui-power-manager/man/ukui-upower.1ustar fengfengukui-power-manager/PowerManagementDaemon/0000755000175000017500000000000014205117543017434 5ustar fengfengukui-power-manager/PowerManagementDaemon/PowerManagementDaemon.pro0000644000175000017500000000000014205117543041253 1ukui-power-manager/PowerManagementDaemon/PowerManagementDaemon.proustar fengfengukui-power-manager/PowerManagementDaemon/eventwatcher.h0000644000175000017500000000000014205117452035074 1ukui-power-manager/PowerManagementDaemon/eventwatcher.hustar fengfengukui-power-manager/PowerManagementDaemon/powermsgnotificat/0000755000175000017500000000000014205117543023200 5ustar fengfengukui-power-manager/PowerManagementDaemon/powermsgnotificat/powermsgnotificat.cpp0000644000175000017500000000000014205117543047405 1ukui-power-manager/PowerManagementDaemon/powermsgnotificat/powermsgnotificat.cppustar fengfengukui-power-manager/PowerManagementDaemon/powermsgnotificat/powermsgnotificat.h0000644000175000017500000000000014205117452046516 1ukui-power-manager/PowerManagementDaemon/powermsgnotificat/powermsgnotificat.hustar fengfengukui-power-manager/PowerManagementDaemon/powermanagementdamon.cpp0000644000175000017500000000000014205117452041204 1ukui-power-manager/PowerManagementDaemon/powermanagementdamon.cppustar fengfengukui-power-manager/PowerManagementDaemon/lidwatcher/0000755000175000017500000000000014205117543021562 5ustar fengfengukui-power-manager/PowerManagementDaemon/lidwatcher/lidwatcher.cpp0000644000175000017500000000000014205117543041315 1ukui-power-manager/PowerManagementDaemon/lidwatcher/lidwatcher.cppustar fengfengukui-power-manager/PowerManagementDaemon/lidwatcher/lidwatcher.h0000644000175000017500000000000014205117543040427 1ukui-power-manager/PowerManagementDaemon/lidwatcher/lidwatcher.hustar fengfengukui-power-manager/PowerManagementDaemon/powerwatcher/0000755000175000017500000000000014205117543022146 5ustar fengfengukui-power-manager/PowerManagementDaemon/powerwatcher/powerwatcher.cpp0000644000175000017500000000000014205117543043235 1ukui-power-manager/PowerManagementDaemon/powerwatcher/powerwatcher.cppustar fengfengukui-power-manager/PowerManagementDaemon/powerwatcher/powerwatcher.h0000644000175000017500000000000014205117543042347 1ukui-power-manager/PowerManagementDaemon/powerwatcher/powerwatcher.hustar fengfengukui-power-manager/PowerManagementDaemon/powerwatcher/common.h0000644000175000017500000000000014205117543037703 1ukui-power-manager/PowerManagementDaemon/powerwatcher/common.hustar fengfengukui-power-manager/PowerManagementDaemon/.clang-format0000644000175000017500000000000014205117543034303 1ukui-power-manager/PowerManagementDaemon/.clang-formatustar fengfengukui-power-manager/PowerManagementDaemon/eventwatcher.cpp0000644000175000017500000000000014205117452035762 1ukui-power-manager/PowerManagementDaemon/eventwatcher.cppustar fengfengukui-power-manager/PowerManagementDaemon/resources/0000755000175000017500000000000014205117452021445 5ustar fengfengukui-power-manager/PowerManagementDaemon/resources/ukui-powermanagement-daemon.desktop0000644000175000017500000000000014205117452051400 1ukui-power-manager/PowerManagementDaemon/resources/ukui-powermanagement-daemon.desktopustar fengfengukui-power-manager/PowerManagementDaemon/acwatcher/0000755000175000017500000000000014205117452021374 5ustar fengfengukui-power-manager/PowerManagementDaemon/acwatcher/acwatcher.cpp0000644000175000017500000000000014205117452040370 1ukui-power-manager/PowerManagementDaemon/acwatcher/acwatcher.cppustar fengfengukui-power-manager/PowerManagementDaemon/acwatcher/acwatcher.h0000644000175000017500000000000014205117452037502 1ukui-power-manager/PowerManagementDaemon/acwatcher/acwatcher.hustar fengfengukui-power-manager/PowerManagementDaemon/PowerManagementDaemon/0000755000175000017500000000000014205117452023650 5ustar fengfengukui-power-manager/PowerManagementDaemon/PowerManagementDaemon/.gitignore0000644000175000017500000000000014205117452043766 1ukui-power-manager/PowerManagementDaemon/PowerManagementDaemon/.gitignoreustar fengfengukui-power-manager/PowerManagementDaemon/gsettingwatcher/0000755000175000017500000000000014205117452022635 5ustar fengfengukui-power-manager/PowerManagementDaemon/gsettingwatcher/gsettingwatcher.h0000644000175000017500000000000014205117452044706 1ukui-power-manager/PowerManagementDaemon/gsettingwatcher/gsettingwatcher.hustar fengfengukui-power-manager/PowerManagementDaemon/gsettingwatcher/gsettingwatcher.cpp0000644000175000017500000000000014205117452045574 1ukui-power-manager/PowerManagementDaemon/gsettingwatcher/gsettingwatcher.cppustar fengfengukui-power-manager/PowerManagementDaemon/powermanagementdamon.h0000644000175000017500000000000014205117452040316 1ukui-power-manager/PowerManagementDaemon/powermanagementdamon.hustar fengfengukui-power-manager/PowerManagementDaemon/idle/0000755000175000017500000000000014205117543020351 5ustar fengfengukui-power-manager/PowerManagementDaemon/idle/idlenesswatcher.cpp0000644000175000017500000000000014205117543040767 1ukui-power-manager/PowerManagementDaemon/idle/idlenesswatcher.cppustar fengfengukui-power-manager/PowerManagementDaemon/idle/idlenesswatcher.h0000644000175000017500000000000014205117543040101 1ukui-power-manager/PowerManagementDaemon/idle/idlenesswatcher.hustar fengfengukui-power-manager/PowerManagementDaemon/brightnessbutton/0000755000175000017500000000000014205117543023040 5ustar fengfengukui-power-manager/PowerManagementDaemon/brightnessbutton/buttonwatcher.cpp0000644000175000017500000000000014205117543045357 1ukui-power-manager/PowerManagementDaemon/brightnessbutton/buttonwatcher.cppustar fengfengukui-power-manager/PowerManagementDaemon/brightnessbutton/buttonwatcher.h0000644000175000017500000000000014205117543044471 1ukui-power-manager/PowerManagementDaemon/brightnessbutton/buttonwatcher.hustar fengfengukui-power-manager/PowerManagementDaemon/main.cpp0000644000175000017500000000000014205117543032435 1ukui-power-manager/PowerManagementDaemon/main.cppustar fengfengukui-power-manager/PowerManagementDaemon/common.h0000644000175000017500000000000014205117452032456 1ukui-power-manager/PowerManagementDaemon/common.hustar fengfengukui-power-manager/PowerManagementDaemon/lowpowerwatcher/0000755000175000017500000000000014205117543022670 5ustar fengfengukui-power-manager/PowerManagementDaemon/lowpowerwatcher/lowpowerwatcher.cpp0000644000175000017500000000000014205117543045745 1ukui-power-manager/PowerManagementDaemon/lowpowerwatcher/lowpowerwatcher.cppustar fengfengukui-power-manager/PowerManagementDaemon/lowpowerwatcher/lowpowerwatcher.h0000644000175000017500000000000014205117452045056 1ukui-power-manager/PowerManagementDaemon/lowpowerwatcher/lowpowerwatcher.hustar fengfengukui-power-manager/registeredQDbus/0000755000175000017500000000000014205117543016313 5ustar fengfengukui-power-manager/registeredQDbus/conf/0000755000175000017500000000000014205117452017237 5ustar fengfengukui-power-manager/registeredQDbus/conf/org.ukui.powermanagement.service0000644000175000017500000000000014205117452043616 1ukui-power-manager/registeredQDbus/conf/org.ukui.powermanagement.serviceustar fengfengukui-power-manager/registeredQDbus/conf/org.ukui.powermanagement.conf0000644000175000017500000000000014205117452042370 1ukui-power-manager/registeredQDbus/conf/org.ukui.powermanagement.confustar fengfengukui-power-manager/registeredQDbus/sysdbusregister.h0000644000175000017500000000000014205117452034136 1ukui-power-manager/registeredQDbus/sysdbusregister.hustar fengfengukui-power-manager/registeredQDbus/sysdbusregister.cpp0000644000175000017500000000000014205117543035025 1ukui-power-manager/registeredQDbus/sysdbusregister.cppustar fengfengukui-power-manager/registeredQDbus/main.cpp0000644000175000017500000000000014205117452030172 1ukui-power-manager/registeredQDbus/main.cppustar fengfengukui-power-manager/registeredQDbus/registeredQDbus.pro0000644000175000017500000000000014205117452034546 1ukui-power-manager/registeredQDbus/registeredQDbus.proustar fengfengukui-power-manager/.gitattributes0000644000175000017500000000000014205117452024510 1ukui-power-manager/.gitattributesustar fengfeng