Import Upstream version 3.1.1.3
This commit is contained in:
commit
904df69fc3
|
@ -0,0 +1,219 @@
|
|||
---
|
||||
# 语言: 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
|
||||
...
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
name: 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);
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
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.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
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
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
@ -0,0 +1,81 @@
|
|||
QT += 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
|
||||
TRANSLATIONS+=\
|
||||
translations/ukui-power-manager-daemon_bo.ts \
|
||||
translations/ukui-power-manager-daemon_zh_CN.ts \
|
||||
translations/ukui-power-manager-daemon_tr.ts
|
||||
|
||||
QM_FILES_INSTALL_PATH = /usr/share/ukui-power-manager/daemon/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
|
||||
|
||||
DEFINES += QM_FILES_INSTALL_PATH='\\"$${QM_FILES_INSTALL_PATH}\\"'
|
||||
|
||||
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
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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:"<<mOnBattery;
|
||||
}
|
||||
|
||||
void AcWatcher::dealAcWatcherMssage()
|
||||
{
|
||||
bool value;
|
||||
value = readOnBattery();
|
||||
// qDebug()<<"当前onBattery:"<<mOnBattery;
|
||||
if (mOnBattery != value) {
|
||||
mOnBattery = value;
|
||||
emit acChanged(mOnBattery);
|
||||
qDebug() << "Power status change signal transmission";
|
||||
}
|
||||
}
|
||||
|
||||
bool AcWatcher::readOnBattery()
|
||||
{
|
||||
bool value;
|
||||
QDBusInterface iface(UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus());
|
||||
QDBusReply<QVariant> reply = iface.call("Get", "org.freedesktop.UPower", "OnBattery");
|
||||
if (reply.isValid()) {
|
||||
value = reply.value().toBool();
|
||||
} else {
|
||||
qDebug() << "OnBattery error!";
|
||||
}
|
||||
return value;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
//Qt
|
||||
#include <QDebug>
|
||||
#include <QtDBus>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QProcess>
|
||||
|
||||
//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
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#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<qulonglong> 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);
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EVENTWATCHER_H
|
||||
#define EVENTWATCHER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QGSettings>
|
||||
#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
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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<bool> 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();
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GSETTINGWATCHER_H
|
||||
#define GSETTINGWATCHER_H
|
||||
|
||||
#include <QFile>
|
||||
#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
|
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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 (mSessionVersion == 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!";
|
||||
}
|
||||
}
|
||||
if (0 == time) {
|
||||
timingStop();
|
||||
getUserBrightness();
|
||||
controlPowerManagement(REGULATE_BRIGHTNESS, mUserBrightness);
|
||||
}
|
||||
}
|
||||
|
||||
int IdlenessWatchcer::turnOffDisplayTime()
|
||||
{
|
||||
QDBusInterface iface(UKUI_UPOWER_SERVICE, UKUI_UPOWER_PATH, UKUI_UPOWER_INTERFACE, QDBusConnection::sessionBus());
|
||||
QDBusReply<bool> 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<bool> 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";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef IDLENESSWATCHER_H
|
||||
#define IDLENESSWATCHER_H
|
||||
|
||||
#include "eventwatcher.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
/**
|
||||
* @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 mSessionVersion
|
||||
* session版本
|
||||
*/
|
||||
const quint32 mSessionVersion = 3;
|
||||
|
||||
/**
|
||||
* @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
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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<QDBusUnixFileDescriptor> reply = manager.call(
|
||||
QStringLiteral("Inhibit"),
|
||||
QStringLiteral("handle-lid-switch"),
|
||||
QStringLiteral("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<QVariant> reply = iface.call("Get", "org.freedesktop.UPower", "LidIsClosed");
|
||||
if (reply.isValid()) {
|
||||
qDebug() << "lid state:" << reply.value();
|
||||
if (getBatteryState()) {
|
||||
contrl = mPowerManagementGsettings->get(BUTTON_LID_BATTERY).toString();
|
||||
} else {
|
||||
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!";
|
||||
}
|
||||
}
|
||||
|
||||
bool LidWatcher::getBatteryState()
|
||||
{
|
||||
|
||||
QDBusInterface iface(UPOWER_SERVICE, UPOWER_PATH, FREEDESKTOP_UPOWER, QDBusConnection::systemBus());
|
||||
QDBusReply<QVariant> reply = iface.call("Get", "org.freedesktop.UPower", "OnBattery");
|
||||
if (reply.isValid()) {
|
||||
return reply.value().toBool();
|
||||
} else {
|
||||
qDebug() << "The battery status obtained by closing the cover is abnormal!";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#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();
|
||||
bool getBatteryState();
|
||||
QDBusUnixFileDescriptor logindLock;
|
||||
|
||||
bool displayState;
|
||||
private slots:
|
||||
void dealLidWatcherMssage(void);
|
||||
};
|
||||
|
||||
#endif // LIDWATCHER_H
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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<QVariant> 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("Low battery notification");
|
||||
notifySend(mType, tr("The system enters a low battery state"));
|
||||
qDebug() << "low battery notify send success";
|
||||
}
|
||||
}
|
||||
|
||||
void LowPowerWatcher::veryLowBatteryNotify(const QString &msg)
|
||||
{
|
||||
mPercentageLow = readPercentage();
|
||||
QString mType = tr("Very low battery notification");
|
||||
if ("blank" == msg) {
|
||||
notifySend(
|
||||
mType,
|
||||
QString(tr("Current power is:%1%. The system will turn off the display in one minute"))
|
||||
.arg(mPercentageLow));
|
||||
} else if ("suspend" == msg) {
|
||||
notifySend(
|
||||
mType, QString(tr("Current power is:%1%,The system will suspend in one minute")).arg(mPercentageLow));
|
||||
} else if ("shutdown" == msg) {
|
||||
notifySend(
|
||||
mType, QString(tr("Current power is:%1%,The system will shutdown in one minute")).arg(mPercentageLow));
|
||||
} else if ("hibernate" == msg) {
|
||||
notifySend(
|
||||
mType, QString(tr("Current power is:%1%,The system will hibernate in one minute")).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<QVariant> args;
|
||||
QStringList argg;
|
||||
QMap<QString, QVariant> pear_map;
|
||||
args << tr("Power Manager") << ((unsigned int)0) << QString("ukui-power-manager")
|
||||
<< type //显示的是什么类型的信息//系统升级
|
||||
<< arg //显示的具体信息
|
||||
<< argg << pear_map << (int)-1;
|
||||
iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LOWPOWERWATCHER_H
|
||||
#define LOWPOWERWATCHER_H
|
||||
#include <QTimer>
|
||||
|
||||
#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
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "powermanagementdamon.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <ukui-log4qt.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
initUkuiLog4qt("ukui-powermanagement");
|
||||
QApplication a(argc, argv);
|
||||
QTranslator translator;
|
||||
if (translator.load(QLocale(), "ukui-power-manager-daemon", "_", QM_FILES_INSTALL_PATH)) {
|
||||
a.installTranslator(&translator);
|
||||
} else {
|
||||
qDebug() << "load ukui-power-manager-tray qm file error";
|
||||
}
|
||||
PowerManagementDamon w;
|
||||
// w.show();
|
||||
return a.exec();
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "powermanagementdamon.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#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
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#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<QVariant> args;
|
||||
QStringList argg;
|
||||
QMap<QString, QVariant> pear_map;
|
||||
args << tr("Power Manager") << ((unsigned int)0) << QString("ukui-power-manager")
|
||||
<< type //显示的是什么类型的信息//系统升级
|
||||
<< arg //显示的具体信息
|
||||
<< argg << pear_map << (int)-1;
|
||||
iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef POWERMSGNOTIFICAT_H
|
||||
#define POWERMSGNOTIFICAT_H
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QObject>
|
||||
|
||||
#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
|
|
@ -0,0 +1,14 @@
|
|||
[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
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="bo_CN">
|
||||
<context>
|
||||
<name>LowPowerWatcher</name>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="130"/>
|
||||
<source>Low battery notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="131"/>
|
||||
<source>The system enters a low battery state</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="139"/>
|
||||
<source>Very low battery notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="143"/>
|
||||
<source>Current power is:%1%. The system will turn off the display in one minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="147"/>
|
||||
<source>Current power is:%1%,The system will suspend in one minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="150"/>
|
||||
<source>Current power is:%1%,The system will shutdown in one minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="153"/>
|
||||
<source>Current power is:%1%,The system will hibernate in one minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="191"/>
|
||||
<source>Power Manager</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>PowerMsgNotificat</name>
|
||||
<message>
|
||||
<location filename="../powermsgnotificat/powermsgnotificat.cpp" line="38"/>
|
||||
<source>error message</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powermsgnotificat/powermsgnotificat.cpp" line="52"/>
|
||||
<source>Power Manager</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="tr_TR">
|
||||
<context>
|
||||
<name>LowPowerWatcher</name>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="130"/>
|
||||
<source>Low battery notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="131"/>
|
||||
<source>The system enters a low battery state</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="139"/>
|
||||
<source>Very low battery notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="143"/>
|
||||
<source>Current power is:%1%. The system will turn off the display in one minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="147"/>
|
||||
<source>Current power is:%1%,The system will suspend in one minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="150"/>
|
||||
<source>Current power is:%1%,The system will shutdown in one minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="153"/>
|
||||
<source>Current power is:%1%,The system will hibernate in one minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="191"/>
|
||||
<source>Power Manager</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>PowerMsgNotificat</name>
|
||||
<message>
|
||||
<location filename="../powermsgnotificat/powermsgnotificat.cpp" line="38"/>
|
||||
<source>error message</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powermsgnotificat/powermsgnotificat.cpp" line="52"/>
|
||||
<source>Power Manager</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
Binary file not shown.
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="zh_CN">
|
||||
<context>
|
||||
<name>LowPowerWatcher</name>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="130"/>
|
||||
<source>Low battery notification</source>
|
||||
<translation>低电量消息通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="131"/>
|
||||
<source>The system enters a low battery state</source>
|
||||
<translation>系统进入低电量状态</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="139"/>
|
||||
<source>Very low battery notification</source>
|
||||
<translation>极低电量消息通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="143"/>
|
||||
<source>Current power is:%1%. The system will turn off the display in one minute</source>
|
||||
<translation>当前电量为:%1,系统将于一分钟后关闭显示器</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="147"/>
|
||||
<source>Current power is:%1%,The system will suspend in one minute</source>
|
||||
<translation>当前电量为:%1%,系统将于一分钟后睡眠</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="150"/>
|
||||
<source>Current power is:%1%,The system will shutdown in one minute</source>
|
||||
<translation>当前电量为:%1%,系统将于一分钟后关机</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="153"/>
|
||||
<source>Current power is:%1%,The system will hibernate in one minute</source>
|
||||
<translation>当前电量为:%1%,系统将于一分钟后关机</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../lowpowerwatcher/lowpowerwatcher.cpp" line="191"/>
|
||||
<source>Power Manager</source>
|
||||
<translation>电源管理器</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>PowerMsgNotificat</name>
|
||||
<message>
|
||||
<location filename="../powermsgnotificat/powermsgnotificat.cpp" line="38"/>
|
||||
<source>error message</source>
|
||||
<translation>错误消息</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powermsgnotificat/powermsgnotificat.cpp" line="52"/>
|
||||
<source>Power Manager</source>
|
||||
<translation>电源管理器</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
|
@ -0,0 +1,2 @@
|
|||
SUBSYSTEMS=="usb", ATTRS{product}=="*Mouse",ATTR{power/wakeup}="enabled"
|
||||
SUBSYSTEMS=="usb", ATTRS{product}=="*Keyboard",ATTR{power/wakeup}="enabled"
|
|
@ -0,0 +1,63 @@
|
|||
#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)
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0"?>
|
||||
<interface>
|
||||
<!-- interface-requires gtk+ 2.6 -->
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
<object class="GtkWindow" id="dialog">
|
||||
<child>
|
||||
<object class="GtkVBox" id="acme_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="acme_image">
|
||||
<property name="visible">True</property>
|
||||
<property name="icon_name">audio-volume-high</property>
|
||||
<property name="icon-size">6</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkProgressBar" id="acme_volume_progressbar">
|
||||
<property name="visible">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.16"/>
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
<object class="GtkWindow" id="window_popup">
|
||||
<property name="title" translatable="yes">Brightness</property>
|
||||
<property name="type_hint">notification</property>
|
||||
<child>
|
||||
<object class="GtkFrame" id="frame_popup">
|
||||
<property name="visible">True</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">out</property>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox_popup">
|
||||
<property name="visible">True</property>
|
||||
<property name="border_width">12</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image_popup">
|
||||
<property name="visible">True</property>
|
||||
<property name="icon-size">6</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkProgressBar" id="progressbar_popup">
|
||||
<property name="visible">True</property>
|
||||
<property name="pulse_step">0.10000000149</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,594 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.16"/>
|
||||
<object class="GtkDialog" id="dialog_stats">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">6</property>
|
||||
<property name="title" translatable="yes">Power Statistics</property>
|
||||
<property name="window_position">center-on-parent</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<child internal-child="vbox">
|
||||
<object class="GtkBox" id="dialog-vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">2</property>
|
||||
<child internal-child="action_area">
|
||||
<object class="GtkButtonBox" id="dialog-action_area1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="button_help">
|
||||
<property name="label">gtk-help</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
<property name="secondary">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="button_close">
|
||||
<property name="label">gtk-close</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">6</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">never</property>
|
||||
<property name="vscrollbar_policy">automatic</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="treeview_devices">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="headers_visible">False</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="treeview-selection1"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkNotebook" id="notebook1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="border_width">9</property>
|
||||
<property name="hscrollbar_policy">automatic</property>
|
||||
<property name="vscrollbar_policy">automatic</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="treeview_info">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="treeview-selection2"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Details</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="tab_fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">9</property>
|
||||
<property name="spacing">9</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Graph type:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="combobox_history_type">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="entry_text_column">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Data length:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="combobox_history_time">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="entry_text_column">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox_history">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_axis_history_y">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label">y-axis</property>
|
||||
<property name="angle">90</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_history_nodata">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">There is no data to display.</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_axis_history_x">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label">x-axis</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox9">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="checkbutton_smooth_history">
|
||||
<property name="label" translatable="yes">Use smoothed line</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="checkbutton_points_history">
|
||||
<property name="label" translatable="yes">Show data points</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">History</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
<property name="tab_fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">9</property>
|
||||
<property name="spacing">9</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Graph type:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkComboBoxText" id="combobox_stats_type">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="entry_text_column">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox_statistics">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_axis_stats_y">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label">y-axis</property>
|
||||
<property name="angle">90</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_stats_nodata">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">There is no data to display.</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_axis_stats_x">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label">x-axis</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">3</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox10">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="checkbutton_smooth_stats">
|
||||
<property name="label" translatable="yes">Use smoothed line</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="checkbutton_points_stats">
|
||||
<property name="label" translatable="yes">Show data points</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel" id="label3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Statistics</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
<property name="tab_fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">9</property>
|
||||
<property name="spacing">9</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">3</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label8">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Processor wakeups per second:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label_total_wakeups">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">automatic</property>
|
||||
<property name="vscrollbar_policy">automatic</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="treeview_wakeups">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="treeview-selection3"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel" id="label7">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Wakeups</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
<property name="tab_fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="0">button_help</action-widget>
|
||||
<action-widget response="0">button_close</action-widget>
|
||||
</action-widgets>
|
||||
<style>
|
||||
<class name="mpm-statistics"/>
|
||||
</style>
|
||||
</object>
|
||||
</interface>
|
|
@ -0,0 +1,3 @@
|
|||
[D-BUS Service]
|
||||
Name=org.ukui.PowerManager
|
||||
Exec=@servicedir@/ukui-power-manager
|
|
@ -0,0 +1,387 @@
|
|||
<schemalist gettext-domain="@GETTEXT_PACKAGE@">
|
||||
<enum id="org.ukui.power-manager.ActionType">
|
||||
<value nick="blank" value="0"/>
|
||||
<value nick="suspend" value="1"/>
|
||||
<value nick="shutdown" value="2"/>
|
||||
<value nick="hibernate" value="3"/>
|
||||
<value nick="interactive" value="4"/>
|
||||
<value nick="nothing" value="5"/>
|
||||
<value nick="notify" value="6"/>
|
||||
</enum>
|
||||
<enum id="org.ukui.power-manager.IconPolicy">
|
||||
<value nick="always" value="0"/>
|
||||
<value nick="present" value="1"/>
|
||||
<value nick="charge" value="2"/>
|
||||
<value nick="low" value="3"/>
|
||||
<value nick="critical" value="4"/>
|
||||
<value nick="never" value="5"/>
|
||||
</enum>
|
||||
<enum id="org.ukui.power-manager.DpmsMethod">
|
||||
<value nick="standby" value="1"/>
|
||||
<value nick="suspend" value="2"/>
|
||||
<value nick="off" value="3"/>
|
||||
</enum>
|
||||
<schema id="org.ukui.power-manager" path="/org/ukui/power-manager/">
|
||||
<key name="action-sleep-type-battery" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'suspend'</default>
|
||||
<summary>Whether to hibernate, suspend or do nothing when inactive</summary>
|
||||
<description>The type of sleeping that should be performed when the computer is inactive.</description>
|
||||
</key>
|
||||
<key name="action-critical-battery" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'suspend'</default>
|
||||
<summary>Battery critical low action</summary>
|
||||
<description>The action to take when the battery is critically low.</description>
|
||||
</key>
|
||||
<key name="event-when-closed-battery" type="b">
|
||||
<default>true</default>
|
||||
<summary>If the battery event should occur when the lid is shut and the power disconnected</summary>
|
||||
<description>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.</description>
|
||||
</key>
|
||||
<key name="action-sleep-type-ac" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'suspend'</default>
|
||||
<summary>Whether to hibernate, suspend or do nothing when inactive</summary>
|
||||
<description>The type of sleeping that should be performed when the computer is inactive.</description>
|
||||
</key>
|
||||
<key name="action-critical-ups" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'shutdown'</default>
|
||||
<summary>UPS critical low action</summary>
|
||||
<description>The action to take when the UPS is critically low.</description>
|
||||
</key>
|
||||
<key name="action-low-ups" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'hibernate'</default>
|
||||
<summary>UPS low power action</summary>
|
||||
<description>The action to take when the UPS is low.</description>
|
||||
</key>
|
||||
<key name="backlight-enable" type="b">
|
||||
<default>true</default>
|
||||
<summary>Allow backlight brightness adjustment</summary>
|
||||
<description>If the screen brightness should be changed when switching between AC and battery power.</description>
|
||||
</key>
|
||||
<key name="backlight-battery-reduce" type="b">
|
||||
<default>true</default>
|
||||
<summary>Reduce the backlight brightness when on battery power</summary>
|
||||
<description>If the screen should be reduced in brightness when the computer is on battery power.</description>
|
||||
</key>
|
||||
<key name="kbd-backlight-battery-reduce" type="b">
|
||||
<default>true</default>
|
||||
<summary>Reduce the keyboard backlight when on battery power</summary>
|
||||
<description>If the keyboard backlight brightness should be reduced when the computer is on battery power</description>
|
||||
</key>
|
||||
<key name="kbd-brightness-on-ac" type="i">
|
||||
<default>100</default>
|
||||
<summary>Keyboard backlight brightness when on AC power.</summary>
|
||||
<description>Percent brightness to set keyboard backlight at when on AC power. Legal values are between 0 and 100.</description>
|
||||
</key>
|
||||
<key name="kbd-brightness-dim-by-on-battery" type="i">
|
||||
<default>50</default>
|
||||
<summary>Percent to reduce keyboard backlight by when on battery power.</summary>
|
||||
<description>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.</description>
|
||||
</key>
|
||||
<key name="kbd-brightness-dim-by-on-idle" type="i">
|
||||
<default>75</default>
|
||||
<summary>Percent to reduce keyboard backlight by when idle.</summary>
|
||||
<description>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.</description>
|
||||
</key>
|
||||
<key name="idle-brightness" type="i">
|
||||
<default>100</default>
|
||||
<summary>The brightness of the screen when idle</summary>
|
||||
<description>This is the laptop panel screen brightness used when the session is idle. Only valid when use-time-for-policy is true.</description>
|
||||
</key>
|
||||
<key name="idle-dim-battery" type="b">
|
||||
<default>true</default>
|
||||
<summary>Dim the screen after a period of inactivity when on battery power</summary>
|
||||
<description>If the screen should be dimmed to save power when the computer is idle when on battery power.</description>
|
||||
</key>
|
||||
<key name="idle-dim-time" type="i">
|
||||
<default>60</default>
|
||||
<summary>The default amount of time to dim the screen after idle</summary>
|
||||
<description>The default amount of time to dim the screen after idle.</description>
|
||||
</key>
|
||||
<key name="brightness-dim-battery" type="i">
|
||||
<default>50</default>
|
||||
<summary>LCD dimming amount when on battery</summary>
|
||||
<description>The amount to dim the brightness of the display when on battery power. Possible values are between 0 and 100.</description>
|
||||
</key>
|
||||
<key name="idle-dim-ac" type="b">
|
||||
<default>false</default>
|
||||
<summary>Dim the screen after a period of inactivity when on AC power</summary>
|
||||
<description>If the screen should be dimmed to save power when the computer is idle when on AC power.</description>
|
||||
</key>
|
||||
<key name="dpms-method-ac" enum="org.ukui.power-manager.DpmsMethod">
|
||||
<default>'off'</default>
|
||||
<summary>Method used to blank screen on AC</summary>
|
||||
<description>The DPMS method used to blank the screen when on AC power.</description>
|
||||
</key>
|
||||
<key name="dpms-method-battery" enum="org.ukui.power-manager.DpmsMethod">
|
||||
<default>'off'</default>
|
||||
<summary>Method used to blank screen on battery</summary>
|
||||
<description>The DPMS method used to blank the screen when on battery power.</description>
|
||||
</key>
|
||||
<key name="brightness-ac" type="d">
|
||||
<default>100.0</default>
|
||||
<summary>LCD brightness when on AC</summary>
|
||||
<description>The brightness of the display when on AC power. Possible values are between 0.0 and 100.0.</description>
|
||||
</key>
|
||||
<key name="brightness-bat" type="d">
|
||||
<default>100.0</default>
|
||||
<summary>LCD brightness when on BAT</summary>
|
||||
<description>The brightness of the display when on BAT power. Possible values are between 0.0 and 100.0.</description>
|
||||
</key>
|
||||
|
||||
<key name="button-suspend" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'suspend'</default>
|
||||
<summary>Suspend button action</summary>
|
||||
<description>The action to take when the system suspend button is pressed.</description>
|
||||
</key>
|
||||
<key name="button-hibernate" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'hibernate'</default>
|
||||
<summary>Hibernate button action</summary>
|
||||
<description>The action to take when the system hibernate button is pressed.</description>
|
||||
</key>
|
||||
<key name="button-power" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'interactive'</default>
|
||||
<summary>Power button action</summary>
|
||||
<description>The action to take when the system power button is pressed.</description>
|
||||
</key>
|
||||
<key name="button-lid-battery" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'suspend'</default>
|
||||
<summary>Laptop lid close action on battery</summary>
|
||||
<description>The action to take when the laptop lid is closed and the laptop is on battery power.</description>
|
||||
</key>
|
||||
<key name="button-lid-ac" enum="org.ukui.power-manager.ActionType">
|
||||
<default>'suspend'</default>
|
||||
<summary>Laptop lid close action when on AC</summary>
|
||||
<description>The action to take when the laptop lid is closed and the laptop is on AC power.</description>
|
||||
</key>
|
||||
<key name="use-time-for-policy" type="b">
|
||||
<default>true</default>
|
||||
<summary>Whether to use time-based notifications</summary>
|
||||
<description>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.</description>
|
||||
</key>
|
||||
<key name="check-type-cpu" type="b">
|
||||
<default>false</default>
|
||||
<summary>Check CPU load before sleeping</summary>
|
||||
<description>If the CPU load should be checked before doing the idle action.</description>
|
||||
</key>
|
||||
<key name="network-sleep" type="b">
|
||||
<default>false</default>
|
||||
<summary>Whether NetworkManager should be connected and disconnected on sleep.</summary>
|
||||
<description>Whether NetworkManager should disconnect before suspending or hibernating and connect on resume.</description>
|
||||
</key>
|
||||
<key name="lock-use-screensaver" type="b">
|
||||
<default>true</default>
|
||||
<summary>Use ukui-screensaver lock setting</summary>
|
||||
<description>Whether to use the screen lock setting of ukui-screensaver to decide if the screen is locked after a hibernate, suspend or blank screen.</description>
|
||||
</key>
|
||||
<key name="lock-blank-screen" type="b">
|
||||
<default>true</default>
|
||||
<summary>Lock screen when blanked</summary>
|
||||
<description>Whether the screen is locked when the screen is turned off. Only used if lock-use-screensaver is false.</description>
|
||||
</key>
|
||||
<key name="lock-suspend" type="b">
|
||||
<default>true</default>
|
||||
<summary>Lock screen on suspend</summary>
|
||||
<description>Whether the screen is locked when the computer wakes up from a suspend. Only used if lock-use-screensaver is false.</description>
|
||||
</key>
|
||||
<key name="lock-hibernate" type="b">
|
||||
<default>true</default>
|
||||
<summary>Lock screen on hibernate</summary>
|
||||
<description>Whether the screen is locked when the computer wakes up from a hibernate. Only used if lock-use-screensaver is false.</description>
|
||||
</key>
|
||||
<key name="lock-keyring-suspend" type="b">
|
||||
<default>false</default>
|
||||
<summary>Lock GNOME keyring on sleep</summary>
|
||||
<description>Whether the GNOME keyring is locked before the computer enters suspend. This means the keyring will have to be unlocked on resume.</description>
|
||||
</key>
|
||||
<key name="lock-keyring-hibernate" type="b">
|
||||
<default>true</default>
|
||||
<summary>Lock GNOME keyring on sleep</summary>
|
||||
<description>Whether the GNOME keyring is locked before the computer enters hibernate. This means the keyring will have to be unlocked on resume.</description>
|
||||
</key>
|
||||
<key name="notify-low-capacity" type="b">
|
||||
<default>true</default>
|
||||
<summary>If we should show the low capacity warning for a broken battery</summary>
|
||||
<description>If we should show the low capacity warning for a broken battery.</description>
|
||||
</key>
|
||||
<key name="notify-discharging" type="b">
|
||||
<default>true</default>
|
||||
<summary>Notify when AC adapter is disconnected</summary>
|
||||
<description>If the user should be notified when the AC adapter is disconnected.</description>
|
||||
</key>
|
||||
<key name="notify-fully-charged" type="b">
|
||||
<default>false</default>
|
||||
<summary>Notify when fully charged</summary>
|
||||
<description>If a notification message should be displayed when the battery is fully charged.</description>
|
||||
</key>
|
||||
<key name="notify-sleep-failed" type="b">
|
||||
<default>true</default>
|
||||
<summary>Notify on a sleep failure</summary>
|
||||
<description>If a notification message should be displayed after suspend or hibernate failed.</description>
|
||||
</key>
|
||||
<key name="notify-sleep-failed-uri" type="s">
|
||||
<default>''</default>
|
||||
<summary>The URI to show to the user on sleep failure</summary>
|
||||
<description>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.</description>
|
||||
</key>
|
||||
<key name="notify-low-power" type="b">
|
||||
<default>true</default>
|
||||
<summary>Notify on a low power</summary>
|
||||
<description>If a notification message should be displayed when the battery is getting low.</description>
|
||||
</key>
|
||||
<key name="info-history-graph-points" type="b">
|
||||
<default>true</default>
|
||||
<summary>Whether we should show the history data points</summary>
|
||||
<description>Whether we should show the history data points in the statistics window.</description>
|
||||
</key>
|
||||
<key name="info-history-graph-smooth" type="b">
|
||||
<default>true</default>
|
||||
<summary>Whether we should smooth the history data</summary>
|
||||
<description>Whether we should smooth the history data in the graph.</description>
|
||||
</key>
|
||||
<key name="info-history-type" type="s">
|
||||
<default>'power'</default>
|
||||
<summary>The default graph type to show for history</summary>
|
||||
<description>The default graph type to show in the history window.</description>
|
||||
</key>
|
||||
<key name="info-history-time" type="i">
|
||||
<default>21600</default>
|
||||
<summary>The maximum time displayed for history</summary>
|
||||
<description>The maximum duration of time displayed on the x-axis of the history graph.</description>
|
||||
</key>
|
||||
<key name="info-stats-graph-points" type="b">
|
||||
<default>true</default>
|
||||
<summary>Whether we should show the stats data points</summary>
|
||||
<description>Whether we should show the stats data points in the statistics window.</description>
|
||||
</key>
|
||||
<key name="info-stats-graph-smooth" type="b">
|
||||
<default>true</default>
|
||||
<summary>Whether we should smooth the stats data</summary>
|
||||
<description>Whether we should smooth the stats data in the graph.</description>
|
||||
</key>
|
||||
<key name="info-stats-type" type="s">
|
||||
<default>'power'</default>
|
||||
<summary>The default graph type to show for stats</summary>
|
||||
<description>The default graph type to show in the stats window.</description>
|
||||
</key>
|
||||
<key name="info-page-number" type="i">
|
||||
<default>0</default>
|
||||
<summary>The index of the page number to show by default</summary>
|
||||
<description>The index of the page number to show by default which is used to return focus to the correct page.</description>
|
||||
</key>
|
||||
<key name="info-last-device" type="s">
|
||||
<default>''</default>
|
||||
<summary>The ID of the last device selected</summary>
|
||||
<description>The identifier of the last device which is used to return focus to the correct device.</description>
|
||||
</key>
|
||||
<key name="percentage-low" type="i">
|
||||
<default>20</default>
|
||||
<summary>Percentage considered low</summary>
|
||||
<description>The percentage of the battery when it is considered low. Only valid when use-time-for-policy is false.</description>
|
||||
</key>
|
||||
<key name="percentage-critical" type="i">
|
||||
<default>10</default>
|
||||
<summary>Percentage considered critical</summary>
|
||||
<description>The percentage of the battery when it is considered critical. Only valid when use-time-for-policy is false.</description>
|
||||
</key>
|
||||
<key name="percentage-action" type="i">
|
||||
<default>5</default>
|
||||
<summary>Percentage action is taken</summary>
|
||||
<description>The percentage of the battery when the critical action is performed. Only valid when use-time-for-policy is false.</description>
|
||||
</key>
|
||||
<key name="time-low" type="i">
|
||||
<default>1200</default>
|
||||
<summary>The time remaining when low</summary>
|
||||
<description>The time remaining in seconds of the battery when it is considered low. Only valid when use-time-for-policy is true.</description>
|
||||
</key>
|
||||
<key name="time-critical" type="i">
|
||||
<default>300</default>
|
||||
<summary>The time remaining when critical</summary>
|
||||
<description>The time remaining in seconds of the battery when it is considered critical. Only valid when use-time-for-policy is true.</description>
|
||||
</key>
|
||||
<key name="time-action" type="i">
|
||||
<default>120</default>
|
||||
<summary>The time remaining when action is taken</summary>
|
||||
<description>The time remaining in seconds of the battery when critical action is taken. Only valid when use-time-for-policy is true.</description>
|
||||
</key>
|
||||
<key name="sleep-computer-battery" type="i">
|
||||
<default>900</default>
|
||||
<summary>Sleep timeout computer when on battery</summary>
|
||||
<description>The amount of time in seconds the computer on battery power needs to be inactive before it goes to sleep.</description>
|
||||
</key>
|
||||
<key name="sleep-computer-ac" type="i">
|
||||
<default>900</default>
|
||||
<summary>Sleep timeout computer when on AC</summary>
|
||||
<description>The amount of time in seconds the computer on AC power needs to be inactive before it goes to sleep.</description>
|
||||
</key>
|
||||
<key name="sleep-computer-ups" type="i">
|
||||
<default>0</default>
|
||||
<summary>Sleep timeout computer when on UPS</summary>
|
||||
<description>The amount of time in seconds the computer on UPS power needs to be inactive before it goes to sleep.</description>
|
||||
</key>
|
||||
<key name="sleep-display-ac" type="i">
|
||||
<default>600</default>
|
||||
<summary>Sleep timeout display when on AC</summary>
|
||||
<description>The amount of time in seconds before the display goes to sleep when the computer is on AC power.</description>
|
||||
</key>
|
||||
<key name="sleep-display-battery" type="i">
|
||||
<default>600</default>
|
||||
<summary>Sleep timeout display when on battery</summary>
|
||||
<description>The amount of time in seconds the computer on battery power needs to be inactive before the display goes to sleep.</description>
|
||||
</key>
|
||||
<key name="sleep-display-ups" type="i">
|
||||
<default>600</default>
|
||||
<summary>Sleep timeout display when on UPS</summary>
|
||||
<description>The amount of time in seconds the computer on UPS power needs to be inactive before the display goes to sleep.</description>
|
||||
</key>
|
||||
<key name="enable-sound" type="b">
|
||||
<default>true</default>
|
||||
<summary>If sounds should be used</summary>
|
||||
<description>If sounds should be used when the power is critically low, or inhibit requests have stopped the policy action.</description>
|
||||
</key>
|
||||
<key name="show-actions" type="b">
|
||||
<default>true</default>
|
||||
<summary>If preferences and statistics items should be shown in the context menu</summary>
|
||||
</key>
|
||||
<key name="idle-power-switch" type="b">
|
||||
<default>false</default>
|
||||
<summary>If power policy mode should be auto switched when plugged in and out</summary>
|
||||
</key>
|
||||
<key name="power-policy-auto" type="b">
|
||||
<default>false</default>
|
||||
<summary>If power policy mode should be auto switched when plugged in and out</summary>
|
||||
</key>
|
||||
<key name="power-policy-mode" type="i">
|
||||
<default>2</default>
|
||||
<summary>power policy mode</summary>
|
||||
</key>
|
||||
<key name="power-policy-ac" type="i">
|
||||
<default>1</default>
|
||||
<summary>power policy current</summary>
|
||||
</key>
|
||||
<key name="power-policy-battery" type="i">
|
||||
<default>2</default>
|
||||
<summary>power policy current</summary>
|
||||
</key>
|
||||
<key name="on-battery-auto-save" type="i">
|
||||
<default>1</default>
|
||||
<summary>power policy current</summary>
|
||||
</key>
|
||||
<key name="low-battery-auto-save" type="i">
|
||||
<default>1</default>
|
||||
<summary>power policy current</summary>
|
||||
</key>
|
||||
<key name="dispaly-left-time-of-charge-and-discharge" type="i">
|
||||
<default>1</default>
|
||||
<summary>power policy current</summary>
|
||||
</key>
|
||||
<key name="power-policy-current" type="i">
|
||||
<default>1</default>
|
||||
<summary>power policy current</summary>
|
||||
</key>
|
||||
<key name="icon-policy" enum="org.ukui.power-manager.IconPolicy">
|
||||
<default>'present'</default>
|
||||
<summary>When to show the notification icon</summary>
|
||||
<description>Display options for the notification icon.</description>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
|
@ -0,0 +1,2 @@
|
|||
[Login]
|
||||
HandlePowerKey=ignore
|
|
@ -0,0 +1,29 @@
|
|||
.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 <mike.gabriel@das-netzwerkteam.de> for
|
||||
the Debian system (but may be used by others).
|
|
@ -0,0 +1,9 @@
|
|||
/tmp/ukui-power-manager.log {
|
||||
daily
|
||||
rotate 7
|
||||
compress
|
||||
notifempty
|
||||
maxsize 10M
|
||||
copytruncate
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
.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 <ogra@ubuntu.com> for
|
||||
the Debian system and updated by Ow Mun Heng <nikeow@yahoo.com>
|
|
@ -0,0 +1,17 @@
|
|||
[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
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
.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 <ogra@ubuntu.com> for
|
||||
the Debian system and updated by Ow Mun Heng <nikeow@yahoo.com>
|
|
@ -0,0 +1,16 @@
|
|||
[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
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
[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
|
|
@ -0,0 +1,21 @@
|
|||
.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 <ogra@ubuntu.com> for
|
||||
the Debian system.
|
|
@ -0,0 +1,15 @@
|
|||
[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@
|
|
@ -0,0 +1,22 @@
|
|||
.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 <simon.zheng@sun.com>.
|
|
@ -0,0 +1,16 @@
|
|||
[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
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!DOCTYPE busconfig PUBLIC
|
||||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<!-- Only root can own the service -->
|
||||
<policy user="root">
|
||||
<allow own="ukui.power.policy"/>
|
||||
</policy>
|
||||
|
||||
<policy context="default">
|
||||
<allow send_destination="ukui.power.policy"/>
|
||||
<allow send_destination="ukui.power.policy"
|
||||
send_interface="org.freedesktop.DBus.Introspectable"/>
|
||||
<allow send_destination="ukui.power.policy"
|
||||
send_interface="org.freedesktop.DBus.Properties"/>
|
||||
</policy>
|
||||
</busconfig>
|
|
@ -0,0 +1,42 @@
|
|||
## 计划表
|
||||
|
||||
|
||||
```
|
||||
计划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】
|
||||
```
|
|
@ -0,0 +1,11 @@
|
|||
# 性能测试注意事项
|
||||
|
||||
```
|
||||
1.连接电源【使用电池的情况下电源管理会更改调频策略】
|
||||
2.控制面板设置电源计划为性能模式
|
||||
如果控制面板-系统-电源-使用电源时的模式选择没有性能模式则需要手动设置【v10sp1 0820-1 版本暂时没有性能模式选项】
|
||||
gsettings set org.ukui.power-manager power-policy-ac 0
|
||||
3.控制面板-系统-电源-此时间段后关闭显示器 选为从不
|
||||
4.控制面板-系统-电源-此时间段后进入睡眠 选为从不
|
||||
5.控制面板-个性化-屏保-此时间段后开启屏保 选为从不
|
||||
```
|
|
@ -0,0 +1,95 @@
|
|||
# 电源管理需求文档
|
||||
|
||||
### 目录
|
||||
```
|
||||
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.降低屏幕亮度
|
||||
|
||||
|
||||
```
|
|
@ -0,0 +1 @@
|
|||
# 电源管理设计文档
|
|
@ -0,0 +1,15 @@
|
|||
.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
|
|
@ -0,0 +1,14 @@
|
|||
.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
|
|
@ -0,0 +1,26 @@
|
|||
.TH ukui 桌面环境电源管理
|
||||
.SH 名称
|
||||
ukui-power-manager \- ukui 桌面环境电源管理
|
||||
.SH 描述
|
||||
ukui 桌面环境电源管理指的是桌面环境中负责电源,电池,锁屏,关闭显示器,注销,重启,等接口调用逻辑的组件
|
||||
.p
|
||||
其根本目的是为了功耗控制
|
||||
.p
|
||||
|
||||
实现以下功能
|
||||
.P
|
||||
1.读取内核电池信息并显示
|
||||
.P
|
||||
2.设置空闲n分钟后进入 休眠/睡眠/关闭显示器 等功能
|
||||
.P
|
||||
3.设置合上盖子后 休眠/睡眠/关闭显示器等功能
|
||||
.P
|
||||
4.设置低电量自动进入省电模式
|
||||
.P
|
||||
.SH "用户手册"
|
||||
http://kylin-desktop.gitee.io/doc/ukui/ukui-power-manager/
|
||||
.p
|
||||
|
||||
.SH "疑问解答"
|
||||
如果您有疑问,请在这里反馈,我们会及时进行解答 https://gitee.com/kylin-desktop/doc/issues
|
||||
.p
|
|
@ -0,0 +1,15 @@
|
|||
.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
|
|
@ -0,0 +1,14 @@
|
|||
.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
|
|
@ -0,0 +1,15 @@
|
|||
.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
|
|
@ -0,0 +1,9 @@
|
|||
TEMPLATE = subdirs
|
||||
|
||||
CONFIG += ordered
|
||||
|
||||
SUBDIRS = \
|
||||
registeredQDbus \
|
||||
PowerManagementDaemon \
|
||||
ukui-power-manager-tray \
|
||||
ukui-upower \
|
|
@ -0,0 +1,12 @@
|
|||
## dbus 服务
|
||||
|
||||
```
|
||||
用于提权
|
||||
|
||||
使用方法:
|
||||
mkdir build
|
||||
make -j8
|
||||
sudo make install //这样会讲service文件安装到系统目录下
|
||||
调用exitService接口退出 //或者重启,否则修改无法生效(注销也不生效)
|
||||
|
||||
```
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
|
||||
|
||||
<!DOCTYPE busconfig PUBLIC
|
||||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<!-- Only root can own the service -->
|
||||
<policy user="root">
|
||||
<allow own="org.ukui.powermanagement"/>
|
||||
<allow send_interface="org.ukui.powermanagement.interface"/>
|
||||
</policy>
|
||||
|
||||
<!-- Allow anyone to invoke methods on the interfaces -->
|
||||
<policy context="default">
|
||||
<allow send_destination="org.ukui.powermanagement"
|
||||
send_interface="org.ukui.powermanagement.interface"/>
|
||||
<allow send_destination="org.ukui.powermanagement"
|
||||
send_interface="org.freedesktop.DBus.Introspectable"/>
|
||||
<allow send_destination="org.ukui.powermanagement"
|
||||
send_interface="org.freedesktop.DBus.Properties"/>
|
||||
</policy>
|
||||
</busconfig>
|
|
@ -0,0 +1,4 @@
|
|||
[D-BUS Service]
|
||||
Name=org.ukui.powermanagement
|
||||
Exec=/usr/bin/ukui-powermanagement-service
|
||||
User=root
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusError>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
#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();
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
QT += 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 \
|
||||
|
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "sysdbusregister.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSharedPointer>
|
||||
#include <QRegExp>
|
||||
#include <stdlib.h>
|
||||
#include <QX11Info>
|
||||
|
||||
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<QString> 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<QFileInfo> 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)
|
||||
{
|
||||
if ("performance" == strategy ||"schedutil" == strategy ||"ondemand" == strategy ||"powersave" == 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SYSDBUSREGISTER_H
|
||||
#define SYSDBUSREGISTER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QCoreApplication>
|
||||
#include <QProcess>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QDBusMessage>
|
||||
#include <QtDBus/QDBusInterface>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusReply>
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
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
|
|
@ -0,0 +1,76 @@
|
|||
#include "batteryicon.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QtDBus>
|
||||
#include <QDebug>
|
||||
#include <QStyleOption>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
#define ORG_UKUI_STYLE "org.ukui.style"
|
||||
#define STYLE_NAME "styleName"
|
||||
#define SYSTEM_FONT_SIZE "systemFontSize"
|
||||
|
||||
BatteryIcon::BatteryIcon(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
this->setFixedSize(QSize(48, 48));
|
||||
this->setIconSize(QSize(30, 30));
|
||||
this->setStyle(new CustomStyle);
|
||||
|
||||
m_iface = new QDBusInterface("org.ukui.upower", "/", "org.ukui.upower", QDBusConnection::sessionBus());
|
||||
QDBusConnection::sessionBus().connect(
|
||||
QString(), "/", "org.ukui.upower", "BatteryIcon", this, SLOT(iconChange(QString)));
|
||||
|
||||
QDBusReply<QString> reply = m_iface->call("IconName");
|
||||
this->setIcon(QIcon::fromTheme(reply.value()));
|
||||
this->setProperty("useIconHighlightEffect", 0x10);
|
||||
this->setFlat(true);
|
||||
}
|
||||
|
||||
void BatteryIcon::iconChange(QString str)
|
||||
{
|
||||
qDebug() << "BatteryIcon::iconChang";
|
||||
if (!str.isNull()) {
|
||||
QIcon icon = QIcon::fromTheme(str);
|
||||
this->setIcon(icon);
|
||||
// this->setProperty("useIconHighlightEffect", 0x10);
|
||||
// this->setProperty("isWindowButton", 0x1);
|
||||
// this->setFlat(true);
|
||||
}
|
||||
}
|
||||
|
||||
void BatteryIcon::gsettingWacther()
|
||||
{
|
||||
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<QString> reply = m_iface->call("IconName");
|
||||
iconChange(reply.value());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// void BatteryIcon::paintEvent(QPaintEvent *ev)
|
||||
//{
|
||||
// QStyleOption opt;
|
||||
// opt.init(this);
|
||||
// QPainter p(this);
|
||||
//// double transparence = transparency * 255;
|
||||
// QColor color = palette().color(QPalette::Base);
|
||||
// color.setAlpha(100);
|
||||
// QBrush brush = QBrush(QColor(0,0,0,0));
|
||||
// p.setBrush(brush);
|
||||
// p.setBrush(this->palette().base());
|
||||
// p.setBrush(QBrush(QColor(19, 19, 20, 0)));
|
||||
// p.setPen(Qt::NoPen);
|
||||
// QPainterPath path;
|
||||
// opt.rect.adjust(0,0,0,0);
|
||||
// path.addRoundedRect(opt.rect,0,0);
|
||||
// p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
||||
// p.drawRoundedRect(opt.rect,0,0);
|
||||
// setProperty("blurRegion",QRegion(path.toFillPolygon().toPolygon()));
|
||||
// style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
//}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef BATTERYICON_H
|
||||
#define BATTERYICON_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QIcon>
|
||||
#include <QGSettings>
|
||||
#include <QtDBus>
|
||||
#include <customstyle.h>
|
||||
|
||||
class BatteryIcon : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BatteryIcon(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void gsettingWacther();
|
||||
|
||||
QDBusInterface *m_iface;
|
||||
|
||||
protected:
|
||||
// void paintEvent(QPaintEvent *);
|
||||
private Q_SLOTS:
|
||||
void iconChange(QString);
|
||||
Q_SIGNALS:
|
||||
|
||||
};
|
||||
|
||||
#endif // BATTERYICON_H
|
|
@ -0,0 +1,456 @@
|
|||
/*
|
||||
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
|
||||
*
|
||||
* This program or library is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "customstyle.h"
|
||||
|
||||
#include <QStyleOptionToolButton>
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
|
||||
//#if QT_CONFIG(toolbutton)
|
||||
/*以下代码是为了处理toolbutton 的箭头*/
|
||||
static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbutton,
|
||||
const QRect &rect, QPainter *painter, const QWidget *widget = 0)
|
||||
{
|
||||
QStyle::PrimitiveElement pe;
|
||||
switch (toolbutton->arrowType) {
|
||||
case Qt::LeftArrow:
|
||||
pe = QStyle::PE_IndicatorArrowLeft;
|
||||
break;
|
||||
case Qt::RightArrow:
|
||||
pe = QStyle::PE_IndicatorArrowRight;
|
||||
break;
|
||||
case Qt::UpArrow:
|
||||
pe = QStyle::PE_IndicatorArrowUp;
|
||||
break;
|
||||
case Qt::DownArrow:
|
||||
pe = QStyle::PE_IndicatorArrowDown;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
QStyleOption arrowOpt = *toolbutton;
|
||||
arrowOpt.rect = rect;
|
||||
style->drawPrimitive(pe, &arrowOpt, painter, widget);
|
||||
}
|
||||
//#endif // QT_CONFIG(toolbutton)
|
||||
|
||||
CustomStyle::CustomStyle(const QString &proxyStyleName, bool multileWins, QObject *parent) : QProxyStyle (proxyStyleName)
|
||||
{
|
||||
pluginName=proxyStyleName;
|
||||
multileWindow=multileWins;
|
||||
}
|
||||
CustomStyle::~CustomStyle()
|
||||
{
|
||||
}
|
||||
|
||||
/*Draws the given control using the provided painter with the style options specified by option.*/
|
||||
void CustomStyle::drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const
|
||||
{
|
||||
|
||||
// if(control == CC_ToolButton)
|
||||
// {
|
||||
// /// 我们需要获取ToolButton的详细信息,通过qstyleoption_cast可以得到
|
||||
// /// 对应的option,通过拷贝构造函数得到一CustomStyle份备份用于绘制子控件
|
||||
// /// 我们一般不用在意option是怎么得到的,大部分的Qt控件都能够提供了option的init方法
|
||||
|
||||
// }
|
||||
switch (cc) {
|
||||
case CC_ToolButton:
|
||||
if (const QStyleOptionToolButton *toolbutton
|
||||
= qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
|
||||
QRect button, menuarea;
|
||||
button = proxy()->subControlRect(cc, toolbutton, SC_ToolButton, widget);
|
||||
menuarea = proxy()->subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget);
|
||||
|
||||
State bflags = toolbutton->state & ~State_Sunken;
|
||||
|
||||
if (bflags & State_AutoRaise) {
|
||||
if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
|
||||
bflags &= ~State_Raised;
|
||||
}
|
||||
}
|
||||
State mflags = bflags;
|
||||
if (toolbutton->state & State_Sunken) {
|
||||
if (toolbutton->activeSubControls & SC_ToolButton)
|
||||
bflags |= State_Sunken;
|
||||
mflags |= State_Sunken;
|
||||
}
|
||||
|
||||
QStyleOption tool = *toolbutton;
|
||||
if (toolbutton->subControls & SC_ToolButton) {
|
||||
if (bflags & (State_Sunken | State_On | State_Raised)) {
|
||||
tool.rect = button;
|
||||
tool.state = bflags;
|
||||
proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
|
||||
}
|
||||
}
|
||||
|
||||
if (toolbutton->state & State_HasFocus) {
|
||||
QStyleOptionFocusRect fr;
|
||||
fr.QStyleOption::operator=(*toolbutton);
|
||||
fr.rect.adjust(3, 3, -3, -3);
|
||||
if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
|
||||
fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
|
||||
toolbutton, widget), 0);
|
||||
proxy()->drawPrimitive(PE_FrameFocusRect, &fr, p, widget);
|
||||
}
|
||||
QStyleOptionToolButton label = *toolbutton;
|
||||
label.state = bflags;
|
||||
int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
|
||||
label.rect = button.adjusted(fw, fw, -fw, -fw);
|
||||
proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
|
||||
|
||||
if (toolbutton->subControls & SC_ToolButtonMenu) {
|
||||
tool.rect = menuarea;
|
||||
tool.state = mflags;
|
||||
if (mflags & (State_Sunken | State_On | State_Raised))
|
||||
proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget);
|
||||
proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget);
|
||||
} else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
|
||||
int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
|
||||
QRect ir = toolbutton->rect;
|
||||
QStyleOptionToolButton newBtn = *toolbutton;
|
||||
newBtn.rect = QRect(ir.right() + 5 - mbi, ir.y() + ir.height() - mbi + 4, mbi - 6, mbi - 6);
|
||||
newBtn.rect = visualRect(toolbutton->direction, button, newBtn.rect);
|
||||
//proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
|
||||
}
|
||||
}
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QProxyStyle::drawComplexControl(cc, opt, p, widget);
|
||||
}
|
||||
|
||||
/*下面对于CE_ToolButtonLabel 的处理是因为quicklaunch 插件出现了箭头*/
|
||||
void CustomStyle::drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *widget) const
|
||||
{
|
||||
switch (element) {
|
||||
|
||||
case CE_PushButton:
|
||||
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
|
||||
proxy()->drawControl(CE_PushButtonBevel, btn, p, widget);
|
||||
QStyleOptionButton subopt = *btn;
|
||||
subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
|
||||
proxy()->drawControl(CE_PushButtonLabel, &subopt, p, widget);
|
||||
}
|
||||
case CE_PushButtonBevel:
|
||||
{
|
||||
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
|
||||
QRect br = btn->rect;
|
||||
int dbi = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
|
||||
if (btn->features & QStyleOptionButton::AutoDefaultButton)
|
||||
br.setCoords(br.left() + dbi, br.top() + dbi, br.right() - dbi, br.bottom() - dbi);
|
||||
|
||||
QStyleOptionButton tmpBtn = *btn;
|
||||
tmpBtn.rect = br;
|
||||
drawPrimitive(PE_PanelButtonCommand, &tmpBtn, p, widget);
|
||||
return;
|
||||
// qDebug()<<" ************** PushButton *********************** ";
|
||||
// p->save();
|
||||
// // painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
// // painter->setPen(Qt::NoPen);
|
||||
// // painter->drawRoundedRect(option->rect,6,6);
|
||||
// if (opt->state & State_MouseOver) {
|
||||
// if (opt->state & State_Sunken) {
|
||||
// p->setRenderHint(QPainter::Antialiasing,true);
|
||||
// p->setPen(Qt::NoPen);
|
||||
// p->setBrush(QColor(0xff,0xff,0xff));
|
||||
// p->drawRoundedRect(opt->rect.adjusted(2,2,-2,-2),6,6);
|
||||
// } else {
|
||||
// p->setRenderHint(QPainter::Antialiasing,true);
|
||||
// p->setPen(Qt::NoPen);
|
||||
// p->setBrush(QColor(0xff,0xff,0xff));
|
||||
// p->drawRoundedRect(opt->rect.adjusted(2,2,-2,-2),6,6);
|
||||
// }
|
||||
// }
|
||||
// p->restore();
|
||||
// return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CE_ToolButtonLabel:
|
||||
{
|
||||
if (const QStyleOptionToolButton *toolbutton
|
||||
= qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
|
||||
QRect rect = toolbutton->rect;
|
||||
int shiftX = 0;
|
||||
int shiftY = 0;
|
||||
// if (toolbutton->state & (State_Sunken | State_On)) {
|
||||
// shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget);
|
||||
// shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, toolbutton, widget);
|
||||
// }
|
||||
// Arrow type always overrules and is always shown
|
||||
bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow;
|
||||
if (((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty())
|
||||
|| toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {
|
||||
int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
|
||||
if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
|
||||
alignment |= Qt::TextHideMnemonic;
|
||||
rect.translate(shiftX, shiftY);
|
||||
p->setFont(toolbutton->font);
|
||||
proxy()->drawItemText(p, rect, alignment, toolbutton->palette,
|
||||
opt->state & State_Enabled, toolbutton->text,
|
||||
QPalette::ButtonText);
|
||||
} else {
|
||||
QPixmap pm;
|
||||
QSize pmSize = toolbutton->iconSize;
|
||||
if (!toolbutton->icon.isNull()) {
|
||||
QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;
|
||||
QIcon::Mode mode;
|
||||
if (!(toolbutton->state & State_Enabled))
|
||||
mode = QIcon::Disabled;
|
||||
else if ((opt->state & State_MouseOver) && (opt->state & State_AutoRaise))
|
||||
mode = QIcon::Active;
|
||||
else
|
||||
mode = QIcon::Normal;
|
||||
pm = toolbutton->icon.pixmap(widget->window()->windowHandle(), toolbutton->rect.size().boundedTo(toolbutton->iconSize),
|
||||
mode, state);
|
||||
pmSize = pm.size() / pm.devicePixelRatio();
|
||||
}
|
||||
|
||||
if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
|
||||
p->setFont(toolbutton->font);
|
||||
QRect pr = rect,
|
||||
tr = rect;
|
||||
int alignment = Qt::TextShowMnemonic;
|
||||
if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
|
||||
alignment |= Qt::TextHideMnemonic;
|
||||
|
||||
if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
|
||||
pr.setHeight(pmSize.height() + 4); //### 4 is currently hardcoded in QToolButton::sizeHint()
|
||||
tr.adjust(0, pr.height() - 1, 0, -1);
|
||||
pr.translate(shiftX, shiftY);
|
||||
if (!hasArrow) {
|
||||
proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pm);
|
||||
} else {
|
||||
drawArrow(proxy(), toolbutton, pr, p, widget);
|
||||
}
|
||||
alignment |= Qt::AlignCenter;
|
||||
} else {
|
||||
pr.setWidth(pmSize.width() + 4); //### 4 is currently hardcoded in QToolButton::sizeHint()
|
||||
tr.adjust(pr.width(), 0, 0, 0);
|
||||
pr.translate(shiftX, shiftY);
|
||||
if (!hasArrow) {
|
||||
proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);
|
||||
} else {
|
||||
drawArrow(proxy(), toolbutton, pr, p, widget);
|
||||
}
|
||||
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
|
||||
}
|
||||
tr.translate(shiftX, shiftY);
|
||||
//const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
|
||||
proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
|
||||
toolbutton->state & State_Enabled, toolbutton->text,
|
||||
QPalette::ButtonText);
|
||||
} else {
|
||||
rect.translate(shiftX, shiftY);
|
||||
if (hasArrow) {
|
||||
drawArrow(proxy(), toolbutton, rect, p, widget);
|
||||
} else {
|
||||
proxy()->drawItemPixmap(p, rect, Qt::AlignCenter, pm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QProxyStyle::drawControl(element, opt, p, widget);
|
||||
}
|
||||
|
||||
void CustomStyle::drawItemPixmap(QPainter *painter, const QRect &rectangle, int alignment, const QPixmap &pixmap) const
|
||||
{
|
||||
return QProxyStyle::drawItemPixmap(painter, rectangle, alignment, pixmap);
|
||||
}
|
||||
|
||||
void CustomStyle::drawItemText(QPainter *painter, const QRect &rectangle, int alignment, const QPalette &palette, bool enabled, const QString &text, QPalette::ColorRole textRole) const
|
||||
{
|
||||
return QProxyStyle::drawItemText(painter, rectangle, alignment, palette, enabled, text, textRole);
|
||||
}
|
||||
|
||||
//绘制简单的颜色圆角等
|
||||
void CustomStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
|
||||
{
|
||||
switch (element) {
|
||||
/*绘制 ToolButton
|
||||
* 任务栏的不同插件需要的样式存在差异
|
||||
* 在同一个PE中有两个toolbutton 的样式
|
||||
*/
|
||||
case PE_PanelButtonTool:{
|
||||
{
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawRoundedRect(option->rect,6,6);
|
||||
if (option->state & State_MouseOver) {
|
||||
if (option->state & State_Sunken) {
|
||||
// painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
// painter->setPen(Qt::NoPen);
|
||||
// painter->setBrush(QColor(0xff,0xff,0xff,0x0f));
|
||||
// painter->drawRoundedRect(option->rect,6,6);
|
||||
} else {
|
||||
// painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
// painter->setPen(Qt::NoPen);
|
||||
// painter->setBrush(QColor(0xff,0xff,0xff,0x1f));
|
||||
// painter->drawRoundedRect(option->rect.adjusted(2,2,-2,-2),6,6);
|
||||
}
|
||||
}
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
case PE_PanelButtonCommand:{
|
||||
if(const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option))
|
||||
{
|
||||
painter->save();
|
||||
if (option->state & State_MouseOver) {
|
||||
if (option->state & State_Sunken) {
|
||||
// painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
// painter->setPen(Qt::NoPen);
|
||||
// painter->setBrush(QColor(0xff,0xff,0xff,0x0f));
|
||||
// painter->drawRoundedRect(button->rect,6,6);
|
||||
} else {
|
||||
// painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
// painter->setPen(Qt::NoPen);
|
||||
// painter->setBrush(QColor(0xff,0xff,0xff,0x1f));
|
||||
// painter->drawRoundedRect(button->rect.adjusted(2,2,-2,-2),6,6);
|
||||
}
|
||||
}
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}break;
|
||||
}
|
||||
return QProxyStyle::drawPrimitive(element, option, painter, widget);
|
||||
|
||||
}
|
||||
|
||||
QPixmap CustomStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const
|
||||
{
|
||||
return QProxyStyle::generatedIconPixmap(iconMode, pixmap, option);
|
||||
}
|
||||
|
||||
QStyle::SubControl CustomStyle::hitTestComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, const QPoint &position, const QWidget *widget) const
|
||||
{
|
||||
return QProxyStyle::hitTestComplexControl(control, option, position, widget);
|
||||
}
|
||||
|
||||
QRect CustomStyle::itemPixmapRect(const QRect &rectangle, int alignment, const QPixmap &pixmap) const
|
||||
{
|
||||
return QProxyStyle::itemPixmapRect(rectangle, alignment, pixmap);
|
||||
}
|
||||
|
||||
QRect CustomStyle::itemTextRect(const QFontMetrics &metrics, const QRect &rectangle, int alignment, bool enabled, const QString &text) const
|
||||
{
|
||||
return QProxyStyle::itemTextRect(metrics, rectangle, alignment, enabled, text);
|
||||
}
|
||||
|
||||
//
|
||||
int CustomStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
switch (metric){
|
||||
case PM_ToolBarIconSize:{
|
||||
return (int)48*qApp->devicePixelRatio();
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QProxyStyle::pixelMetric(metric, option, widget);
|
||||
}
|
||||
|
||||
/*使悬浮点击等样式生效*/
|
||||
void CustomStyle::polish(QWidget *widget)
|
||||
{
|
||||
widget->setAttribute(Qt::WA_Hover);
|
||||
return QProxyStyle::polish(widget);
|
||||
}
|
||||
|
||||
void CustomStyle::polish(QApplication *application)
|
||||
{
|
||||
return QProxyStyle::polish(application);
|
||||
}
|
||||
|
||||
//
|
||||
void CustomStyle::polish(QPalette &palette)
|
||||
{
|
||||
// return QProxyStyle::polish(palette);
|
||||
// QProxyStyle::polish(palette);
|
||||
// palette.setBrush(QPalette::Foreground, Qt::black);
|
||||
QColor lightBlue(200, 0, 0);
|
||||
palette.setBrush(QPalette::Highlight, lightBlue);
|
||||
}
|
||||
|
||||
void CustomStyle::unpolish(QWidget *widget)
|
||||
{
|
||||
return QProxyStyle::unpolish(widget);
|
||||
}
|
||||
|
||||
void CustomStyle::unpolish(QApplication *application)
|
||||
{
|
||||
return QProxyStyle::unpolish(application);
|
||||
}
|
||||
|
||||
QSize CustomStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const
|
||||
{
|
||||
return QProxyStyle::sizeFromContents(type, option, contentsSize, widget);
|
||||
}
|
||||
|
||||
QIcon CustomStyle::standardIcon(QStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
return QProxyStyle::standardIcon(standardIcon, option, widget);
|
||||
}
|
||||
|
||||
QPalette CustomStyle::standardPalette() const
|
||||
{
|
||||
return QProxyStyle::standardPalette();
|
||||
}
|
||||
|
||||
//如果需要背景透明也许需要用到这个函数
|
||||
int CustomStyle::styleHint(QStyle::StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const
|
||||
{
|
||||
switch (hint) {
|
||||
/// 让ScrollView viewport的绘制区域包含scrollbar和corner widget
|
||||
/// 这个例子中没有什么作用,如果我们需要绘制一个背景透明的滚动条
|
||||
/// 这个style hint对我们的意义应该很大,因为我们希望视图能够帮助
|
||||
/// 我们填充滚动条的背景区域,否则当背景透明时底下会出现明显的分割
|
||||
case SH_ScrollView_FrameOnlyAroundContents: {
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||
}
|
||||
|
||||
QRect CustomStyle::subControlRect(QStyle::ComplexControl control, const QStyleOptionComplex *option, QStyle::SubControl subControl, const QWidget *widget) const
|
||||
{
|
||||
return QProxyStyle::subControlRect(control, option, subControl, widget);
|
||||
}
|
||||
|
||||
QRect CustomStyle::subElementRect(QStyle::SubElement element, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
return QProxyStyle::subElementRect(element, option, widget);
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
|
||||
*
|
||||
* This program or library is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef CUSTOMSTYLE_H
|
||||
#define CUSTOMSTYLE_H
|
||||
|
||||
#include <QProxyStyle>
|
||||
#include <QDebug>
|
||||
/*!
|
||||
* \brief The CustomStyle class
|
||||
* \details
|
||||
* 自定义QStyle
|
||||
* 基于QProxyStyle,默认使用QProxyStyle的实例绘制控件,你需要针对某一个控件重新实现若干对应的接口。
|
||||
* QProxyStyle可以从现有的qt style实例化,我们只需要知道这个style的名字即可。
|
||||
* 这种做法带来了不错的扩展性和自由度,因为我们不需要将某个style的代码直接引入我们的项目中,
|
||||
* 也能够“继承”这个style类进行二次开发。
|
||||
*
|
||||
* 下面的方法展现了QStyle的所有的接口,使用QStyle进行控件的绘制使得qt应用能够进行风格的切换,
|
||||
* 从而达到不修改项目源码却对应用外观产生巨大影响的效果。
|
||||
*
|
||||
* \note
|
||||
* 需要注意QStyle与QSS并不兼容,因为QSS本身其实上也是QStyle的一种实现,对一个控件而言,本身理论上只能
|
||||
* 在同一时间调用唯一一个QStyle进行绘制。
|
||||
*/
|
||||
class CustomStyle : public QProxyStyle
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//proxyStyleName 是关于样式类型的,&proxyStyleName = "windows" 会造成toolTips的样式为windows类型样式
|
||||
explicit CustomStyle(const QString &proxyStyleName = "ukui",bool multileWins=false, QObject *parent = nullptr);
|
||||
~CustomStyle();
|
||||
/*!
|
||||
* \brief drawComplexControl
|
||||
* \param control 比如ScrollBar,对应CC枚举类型
|
||||
* \param option
|
||||
* \param painter
|
||||
* \param widget
|
||||
* \details
|
||||
* drawComplexControl用于绘制具有子控件的复杂控件,它本身一般不直接绘制控件,
|
||||
* 而是通过QStyle的其它方法将复杂控件分解成子控件再调用其它的draw方法绘制。
|
||||
* 如果你需要重新实现一个复杂控件的绘制方法,首先考虑的应该是在不改变它原有的绘制流程的情况下,
|
||||
* 对它调用到的其它方法进行重写。
|
||||
*
|
||||
* 如果你不想使用原有的绘制流程,那你需要重写这个接口,然后自己实现一切,
|
||||
* 包括背景的绘制,子控件的位置和状态计算,子控件的绘制等。
|
||||
* 所以,你需要对这个控件有足够的了解之后再尝试直接重写这个接口。
|
||||
*/
|
||||
virtual void drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget = nullptr) const;
|
||||
/*!
|
||||
* \brief drawControl
|
||||
* \param element 比如按钮,对应CE枚举类型
|
||||
* \param option
|
||||
* \param painter
|
||||
* \param widget
|
||||
* \details
|
||||
* drawControl用于绘制基本控件元素,它本身一般只负责绘制控件的一部分或者一层。
|
||||
* 如果你想要知道控件具体如何绘制,你需要同时研究这个控件的源码和QStyle中的源码,
|
||||
* 因为它们都有可能改变控件的绘制流程。
|
||||
*
|
||||
* QStyle一般会遵循QCommonStyle的绘制流程,QCommenStyle是大部分主流style的最基类,
|
||||
* 它本身不能完全称之为一个主题,如果你直接使用它,你的控件将不能被正常绘制,因为它有可能只是
|
||||
* 在特定的时候执行了特定却未实现的绘制方法,它更像一个框架或者规范。
|
||||
*/
|
||||
virtual void drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const;
|
||||
virtual void drawItemPixmap(QPainter *painter, const QRect &rectangle, int alignment, const QPixmap &pixmap) const;
|
||||
virtual void drawItemText(QPainter *painter, const QRect &rectangle, int alignment, const QPalette &palette, bool enabled, const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const;
|
||||
/*!
|
||||
* \brief drawPrimitive
|
||||
* \param element 背景绘制,对应PE枚举类型
|
||||
* \param option
|
||||
* \param painter
|
||||
* \param widget
|
||||
* \details
|
||||
* drawPrimitive用于绘制控件背景,比如按钮和菜单的背景,
|
||||
* 我们一般需要判断控件的状态来绘制不同的背景,
|
||||
* 比如按钮的hover和点击效果。
|
||||
*/
|
||||
virtual void drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const;
|
||||
virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *option) const;
|
||||
virtual QStyle::SubControl hitTestComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, const QPoint &position, const QWidget *widget = nullptr) const;
|
||||
virtual QRect itemPixmapRect(const QRect &rectangle, int alignment, const QPixmap &pixmap) const;
|
||||
virtual QRect itemTextRect(const QFontMetrics &metrics, const QRect &rectangle, int alignment, bool enabled, const QString &text) const;
|
||||
//virtual int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option, const QWidget *widget);
|
||||
virtual int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const;
|
||||
|
||||
/*!
|
||||
* \brief polish
|
||||
* \param widget
|
||||
* \details
|
||||
* polish用于对widget进行预处理,一般我们可以在polish中修改其属性,
|
||||
* 另外,polish是对动画和特效实现而言十分重要的一个方法,
|
||||
* 通过polish我们能够使widget和特效和动画形成对应关系。
|
||||
*/
|
||||
virtual void polish(QWidget *widget);
|
||||
virtual void polish(QApplication *application);
|
||||
virtual void polish(QPalette &palette);
|
||||
virtual void unpolish(QWidget *widget);
|
||||
virtual void unpolish(QApplication *application);
|
||||
|
||||
virtual QSize sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget = nullptr) const;
|
||||
virtual QIcon standardIcon(QStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const;
|
||||
virtual QPalette standardPalette() const;
|
||||
/*!
|
||||
* \brief styleHint
|
||||
* \param hint 对应的枚举是SH
|
||||
* \param option
|
||||
* \param widget
|
||||
* \param returnData
|
||||
* \return
|
||||
* \details
|
||||
* styleHint比较特殊,通过它我们能够改变一些控件的绘制流程或者方式,比如说QMenu是否可以滚动。
|
||||
*/
|
||||
virtual int styleHint(QStyle::StyleHint hint, const QStyleOption *option = nullptr, const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const;
|
||||
/*!
|
||||
* \brief subControlRect
|
||||
* \param control
|
||||
* \param option
|
||||
* \param subControl
|
||||
* \param widget
|
||||
* \return
|
||||
* \details
|
||||
* subControlRect返回子控件的位置和大小信息,这个方法一般在内置流程中调用,
|
||||
* 如果我们要重写某个绘制方法,可能需要用到它
|
||||
*/
|
||||
virtual QRect subControlRect(QStyle::ComplexControl control, const QStyleOptionComplex *option, QStyle::SubControl subControl, const QWidget *widget = nullptr) const;
|
||||
/*!
|
||||
* \brief subElementRect
|
||||
* \param element
|
||||
* \param option
|
||||
* \param widget
|
||||
* \return
|
||||
* \details
|
||||
* 与subControlRect类似
|
||||
*/
|
||||
virtual QRect subElementRect(QStyle::SubElement element, const QStyleOption *option, const QWidget *widget = nullptr) const;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
public Q_SLOTS:
|
||||
private:
|
||||
QString pluginName;
|
||||
bool multileWindow = false;
|
||||
};
|
||||
#endif // CUSTOMSTYLE_H
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "device.h"
|
||||
#include <QDebug>
|
||||
|
||||
DEVICE::DEVICE(QObject *parent) : QObject(parent) {}
|
||||
|
||||
void DEVICE::handleChanged(QDBusMessage msg)
|
||||
{
|
||||
Q_EMIT device_property_changed(msg, m_dev.path);
|
||||
}
|
||||
|
||||
DEVICE::~DEVICE() {}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_H
|
||||
#define DEVICE_H
|
||||
|
||||
#include <QDBusMessage>
|
||||
#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
|
|
@ -0,0 +1,22 @@
|
|||
#include "divider.h"
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
|
||||
Divider::Divider(QWidget *parent) : QFrame(parent)
|
||||
{
|
||||
this->setFixedHeight(1);
|
||||
}
|
||||
|
||||
void Divider::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPainter p(this);
|
||||
QColor color = qApp->palette().color(QPalette::BrightText);
|
||||
color.setAlphaF(0.08);
|
||||
p.save();
|
||||
p.setBrush(color);
|
||||
p.setPen(Qt::transparent);
|
||||
p.drawRoundedRect(this->rect(), 6, 6);
|
||||
p.restore();
|
||||
return QFrame::paintEvent(e);
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef DIVIDER_H
|
||||
#define DIVIDER_H
|
||||
#include <QFrame>
|
||||
|
||||
class Divider : public QFrame
|
||||
{
|
||||
public:
|
||||
Divider(QWidget * parent = nullptr);
|
||||
~Divider() = default;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
};
|
||||
|
||||
#endif // DIVIDER_H
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
|
@ -0,0 +1,935 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "enginedevice.h"
|
||||
#include "device.h"
|
||||
#include <QDBusObjectPath>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDebug>
|
||||
|
||||
EngineDevice *EngineDevice::instance = NULL;
|
||||
|
||||
void EngineDevice::power_device_get_devices()
|
||||
{
|
||||
QList<QDBusObjectPath> 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<QDBusArgument>();
|
||||
dbusArg >> deviceNames;
|
||||
} else {
|
||||
}
|
||||
int len = deviceNames.size();
|
||||
// qDebug()<<deviceNames.at(1).path();
|
||||
for (int i = 0; i < len; i++) {
|
||||
DEVICE *device = new DEVICE;
|
||||
device->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<QDBusArgument>();
|
||||
QMap<QString, QVariant> 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<QString, QVariant> &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<QDBusArgument>();
|
||||
QMap<QString, QVariant> 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) {
|
||||
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
|
||||
**/
|
||||
#if 0
|
||||
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");
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* 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"
|
||||
**/
|
||||
#if 0
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* 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;
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ENGINEDEVICE_H
|
||||
#define ENGINEDEVICE_H
|
||||
|
||||
#include "engine_common.h"
|
||||
#include <QObject>
|
||||
#include <device.h>
|
||||
#include <QDBusMetaType>
|
||||
#include <QDBusVariant>
|
||||
#include <QString>
|
||||
#include <QGSettings>
|
||||
|
||||
|
||||
#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 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);
|
||||
public Q_SLOTS:
|
||||
void power_device_change_callback(QDBusMessage msg, QString path);
|
||||
|
||||
public:
|
||||
QGSettings *settings;
|
||||
QList<DEVICE*> 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<QString, QVariant> &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
|
|
@ -0,0 +1,115 @@
|
|||
#include "kylable.h"
|
||||
#include <QEvent>
|
||||
#include <QProcess>
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
|
||||
#define FOREGROUND_COLOR_NORMAL qApp->palette().text().color()
|
||||
|
||||
static inline qreal mixQreal(qreal a, qreal b, qreal bias)
|
||||
{
|
||||
return a + (b - a) * bias;
|
||||
}
|
||||
|
||||
|
||||
QColor mixColor(const QColor &c1, const QColor &c2, qreal bias)
|
||||
{
|
||||
if (bias <= 0.0) {
|
||||
return c1;
|
||||
}
|
||||
if (bias >= 1.0) {
|
||||
return c2;
|
||||
}
|
||||
if (qIsNaN(bias)) {
|
||||
return c1;
|
||||
}
|
||||
|
||||
qreal r = mixQreal(c1.redF(), c2.redF(), bias);
|
||||
qreal g = mixQreal(c1.greenF(), c2.greenF(), bias);
|
||||
qreal b = mixQreal(c1.blueF(), c2.blueF(), bias);
|
||||
qreal a = mixQreal(c1.alphaF(), c2.alphaF(), bias);
|
||||
|
||||
return QColor::fromRgbF(r, g, b, a);
|
||||
}
|
||||
|
||||
KyLable::KyLable(QWidget *parent) : QLabel(parent)
|
||||
{
|
||||
connect(qApp, &QApplication::paletteChanged, this, &KyLable::onPaletteChanged);
|
||||
onPaletteChanged();
|
||||
}
|
||||
|
||||
void KyLable::onPaletteChanged()
|
||||
{
|
||||
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void KyLable::setPressColor()
|
||||
{
|
||||
QColor hightlight = this->palette().color(QPalette::Active,QPalette::Highlight);
|
||||
QColor mix = this->palette().color(QPalette::Active,QPalette::BrightText);
|
||||
m_foregroundColor = mixColor(hightlight, mix, 0.05);
|
||||
}
|
||||
|
||||
void KyLable::setHoverColor()
|
||||
{
|
||||
QColor hightlight = this->palette().color(QPalette::Active,QPalette::Highlight);
|
||||
QColor mix = this->palette().color(QPalette::Active,QPalette::BrightText);
|
||||
m_foregroundColor = mixColor(hightlight, mix, 0.2);
|
||||
}
|
||||
|
||||
void KyLable::setNormalColor()
|
||||
{
|
||||
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
|
||||
}
|
||||
|
||||
void KyLable::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::WindowText, m_foregroundColor);
|
||||
this->setPalette(pal);
|
||||
return QLabel::paintEvent(event);
|
||||
}
|
||||
|
||||
void KyLable::enterEvent(QEvent *event)
|
||||
{
|
||||
setHoverColor();
|
||||
this->update();
|
||||
}
|
||||
|
||||
void KyLable::leaveEvent(QEvent *event)
|
||||
{
|
||||
setNormalColor();
|
||||
this->update();
|
||||
}
|
||||
|
||||
void KyLable::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
setPressColor();
|
||||
this->update();
|
||||
return QLabel::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void KyLable::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
setHoverColor();
|
||||
this->update();
|
||||
onShowControlCenter();
|
||||
return QLabel::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void KyLable::onShowControlCenter()
|
||||
{
|
||||
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"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef KYLABLE_H
|
||||
#define KYLABLE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QLabel>
|
||||
|
||||
class KyLable : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyLable(QWidget *parent = nullptr);
|
||||
~KyLable() = default;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void enterEvent(QEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
QColor m_foregroundColor;
|
||||
|
||||
void setPressColor();
|
||||
void setHoverColor();
|
||||
void setNormalColor();
|
||||
void onShowControlCenter();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPaletteChanged();
|
||||
|
||||
};
|
||||
|
||||
#endif // KYLABLE_H
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "powertray.h"
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QSharedMemory>
|
||||
#include <QDebug>
|
||||
#include <QTranslator>
|
||||
#include <KWindowEffects>
|
||||
#include <QDesktopWidget>
|
||||
#include <X11/Xlib.h>
|
||||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <ukui-log4qt.h>
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
PowerTray p;
|
||||
if ("book" == p.getMachineType()) {
|
||||
p.initPowerTray();
|
||||
} else {
|
||||
qDebug() << "No tray required";
|
||||
exit(0);
|
||||
p.initPowerTray();
|
||||
}
|
||||
return app.exec();
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#include "percentagelabel.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QDBusReply>
|
||||
#include <QtDBus>
|
||||
|
||||
#define ORG_UKUI_STYLE "org.ukui.style"
|
||||
#define STYLE_NAME "styleName"
|
||||
#define SYSTEM_FONT_SIZE "systemFontSize"
|
||||
|
||||
PercentageLabel::PercentageLabel()
|
||||
{
|
||||
setFontsize();
|
||||
watchGsetting();
|
||||
}
|
||||
|
||||
void PercentageLabel::setFontsize()
|
||||
{
|
||||
qDebug() << "m_sysFontSize:" << m_sysFontSize;
|
||||
ft.setPointSize(m_sysFontSize * 2);
|
||||
this->setFont(ft);
|
||||
}
|
||||
|
||||
void PercentageLabel::watchGsetting()
|
||||
{
|
||||
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 == SYSTEM_FONT_SIZE) {
|
||||
m_sysFontSize = styleSettings->get(SYSTEM_FONT_SIZE).toInt();
|
||||
setFontsize();
|
||||
}
|
||||
});
|
||||
m_sysFontSize = styleSettings->get(SYSTEM_FONT_SIZE).toInt();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef PERCENTAGELABEL_H
|
||||
#define PERCENTAGELABEL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QLabel>
|
||||
#include <QGSettings>
|
||||
|
||||
class PercentageLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PercentageLabel();
|
||||
|
||||
private:
|
||||
void setFontsize();
|
||||
void watchGsetting();
|
||||
|
||||
QFont ft;
|
||||
int m_sysFontSize = 12;
|
||||
Q_SIGNALS:
|
||||
|
||||
};
|
||||
|
||||
#endif // PERCENTAGELABEL_H
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "powertray.h"
|
||||
#include "powerwindow.h"
|
||||
#include <QDebug>
|
||||
#include <QDesktopWidget>
|
||||
#include <QApplication>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QProcess>
|
||||
#include <QDBusInterface>
|
||||
#include <QLabel>
|
||||
#include <QPainter>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QDBusReply>
|
||||
#include <QThread>
|
||||
#include <unistd.h>
|
||||
#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<QString> reply = iface->call("DaemonVersion");
|
||||
reply.waitForFinished();
|
||||
if (reply.isValid()) {
|
||||
qDebug() << "upower version is:" << reply.value();
|
||||
} else {
|
||||
qDebug() << "upower version get error!";
|
||||
}
|
||||
QDBusPendingReply<int> replyState = iface->call("BatteryState");
|
||||
replyState.waitForFinished();
|
||||
if (replyState.isValid()) {
|
||||
qDebug() << "BatteryState is:" << replyState.value();
|
||||
if (0 == replyState.value()){
|
||||
qDebug() << "ukui-power-manager-tray is about to quit";
|
||||
exit(0);
|
||||
}
|
||||
} else {
|
||||
qDebug() << "get BatteryState error!";
|
||||
}
|
||||
}
|
||||
|
||||
void PowerTray::initPowerTray()
|
||||
{
|
||||
trayIcon = new QSystemTrayIcon(this);
|
||||
EngineDevice *ed;
|
||||
ed = EngineDevice::getInstance();
|
||||
// m_isPowerWindowInit = false;
|
||||
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<QString> 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 (!m_isPowerWindowInit) {
|
||||
// powerWindow = new powerwindow();
|
||||
// m_isPowerWindowInit = true;
|
||||
// } else {
|
||||
// qDebug() << "power window init is :" << m_isPowerWindowInit;
|
||||
// }
|
||||
if (reason == 3) {
|
||||
if (powerWindow->isVisible()) {
|
||||
powerWindow->hide();
|
||||
return;
|
||||
}
|
||||
powerWindow->set_window_position();
|
||||
KWindowSystem::setState(powerWindow->winId(), NET::SkipTaskbar | NET::SkipPager);
|
||||
powerWindow->show();
|
||||
}
|
||||
}
|
||||
|
||||
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<QString> 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;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef POWERTRAY_H
|
||||
#define POWERTRAY_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QGSettings>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QMenu>
|
||||
#include <QScrollArea>
|
||||
#include <QDBusObjectPath>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusConnection>
|
||||
#include <QMap>
|
||||
#include <QListWidgetItem>
|
||||
#include <QWidgetAction>
|
||||
#include <QLabel>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <powerwindow.h>
|
||||
|
||||
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<QDBusObjectPath> deviceNames;
|
||||
QGSettings * settings;
|
||||
QMenu *menu;
|
||||
QDBusInterface *iface;
|
||||
// bool m_isPowerWindowInit = false;
|
||||
private Q_SLOTS:
|
||||
void set_preference_func();
|
||||
void onSumChanged(QString str);
|
||||
void IconChanged(QString str);
|
||||
void onActivatedIcon(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
};
|
||||
|
||||
#endif // POWERTRAY_H
|
|
@ -0,0 +1,509 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "powerwindow.h"
|
||||
#include "enginedevice.h"
|
||||
#include "xatom-helper.h"
|
||||
#include "qdesktopwidget.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTimer>
|
||||
#include <KWindowEffects>
|
||||
|
||||
#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 POWER_MANAGER_SETTINGS "org.ukui.power-manager"
|
||||
#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"
|
||||
|
||||
#define POWER_POLICY_AC "powerPolicyAc"
|
||||
#define POWER_POLICY_BATTERY "powerPolicyBattery"
|
||||
|
||||
powerwindow::powerwindow(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
qDebug()<<"power window init";
|
||||
m_iface = new QDBusInterface("org.ukui.upower", "/", "org.ukui.upower", QDBusConnection::sessionBus());
|
||||
qDebug()<<" notification init start";
|
||||
QTimer::singleShot(1000, this, [=] {
|
||||
m_notifyInterface = new QDBusInterface(
|
||||
"org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
QDBusConnection::sessionBus());
|
||||
});
|
||||
qDebug()<<" notification init end";
|
||||
|
||||
// QDBusConnection::sessionBus().connect(
|
||||
// QString(), "/", "org.ukui.upower", "LowBatteryState", this, SLOT(lowBatteryNotify()));
|
||||
// QDBusConnection::sessionBus().connect(
|
||||
// QString(), "/", "org.ukui.upower", "VeryLowBatteryState", this, SLOT(criticalBatteryNotify()));
|
||||
qDebug()<<"upower init";
|
||||
QDBusConnection::sessionBus().connect(
|
||||
QString(), "/", "org.ukui.upower", "PowerState", this, SLOT(chargeNotify(bool)));
|
||||
|
||||
qDebug()<<"energy divice init start";
|
||||
ed = EngineDevice::getInstance();
|
||||
qDebug()<<"energy divice init end";
|
||||
|
||||
connect(ed, SIGNAL(engine_signal_fullycharge(DEV)), this, SLOT(full_charge_notify(DEV)));
|
||||
|
||||
setWindowProperty(); //设置窗口属性
|
||||
initUI(); //初始化UI
|
||||
initgsetting();
|
||||
// set_window_position(); //设置出现在屏幕的位置以及大小
|
||||
watchTranspartency();
|
||||
|
||||
//监听屏幕改变的信号
|
||||
connect(QApplication::desktop(), &QDesktopWidget::resized, this, [=]() {
|
||||
QTimer::singleShot(1000, this, [=]() { set_window_position(); });
|
||||
});
|
||||
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, [=]() { set_window_position(); });
|
||||
connect(QApplication::desktop(), &QDesktopWidget::primaryScreenChanged, this, [=]() { 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 settingLabel;
|
||||
delete transparency_gsettings;
|
||||
}
|
||||
|
||||
void powerwindow::setWindowProperty()
|
||||
{
|
||||
//设置任务栏无显示
|
||||
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_firstlayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_toplayout = new QHBoxLayout();
|
||||
lastlayout = new QHBoxLayout();
|
||||
m_statelayout = new QHBoxLayout();
|
||||
|
||||
m_firstwidget = new QWidget();
|
||||
m_topwidget = new QWidget();
|
||||
lastWidget = new QWidget();
|
||||
m_statewidget = new QWidget();
|
||||
|
||||
iconButton = new BatteryIcon();
|
||||
|
||||
percentageLabel = new PercentageLabel();
|
||||
|
||||
powerStateLabel = new QLabel();
|
||||
powerStateLabel->setText(tr("Charging"));
|
||||
powerStateLabel->setVisible(false);
|
||||
|
||||
powerTimeToEmpty = new QLabel();
|
||||
powerTimeToEmpty->setVisible(true);
|
||||
|
||||
m_segmentationLine_1 = new Divider(this);
|
||||
m_segmentationLine_2 = new Divider(this);
|
||||
|
||||
m_StateSlider = new StateSlider(this);
|
||||
connect(m_StateSlider, &StateSlider::valueChanged, this, &powerwindow::sliderValueChanged);
|
||||
|
||||
m_enduranceIconButtun = new QToolButton(this);
|
||||
m_enduranceIconButtun->setIconSize(QSize(16,16));
|
||||
m_enduranceIconButtun->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
m_enduranceIconButtun->setProperty("useIconHighlightEffect", 0x10);
|
||||
m_enduranceIconButtun->setStyle(new CustomStyle);
|
||||
QIcon icon1 = QIcon::fromTheme("ukui-eco-symbolic");
|
||||
m_enduranceIconButtun->setIcon(icon1);
|
||||
m_enduranceIconButtun->setText(tr("Endurance"));
|
||||
|
||||
m_performanceIconButtun = new QToolButton(this);
|
||||
m_performanceIconButtun->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
m_performanceIconButtun->setProperty("useIconHighlightEffect", 0x10);
|
||||
m_performanceIconButtun->setStyle(new CustomStyle);
|
||||
QIcon icon2 = QIcon::fromTheme("ukui-performance-symbolic");
|
||||
m_performanceIconButtun->setIcon(icon2);
|
||||
m_performanceIconButtun->setText(tr("performance"));
|
||||
|
||||
get_power_list();
|
||||
|
||||
this->setFixedSize(420, 258 + deviceNum * 48);
|
||||
|
||||
//电源设置按钮
|
||||
settingLabel = new KyLable();
|
||||
settingLabel->setText(tr("PowerSettings"));
|
||||
|
||||
toplabel = new QLabel(this);
|
||||
toplabel->setText(tr("PowerMode"));
|
||||
// toplabel->setObjectName("");
|
||||
m_toplayout->addWidget(toplabel);
|
||||
m_toplayout->addItem(new QSpacerItem(10, 2));
|
||||
m_topwidget->setLayout(m_toplayout);
|
||||
|
||||
//第一行布局
|
||||
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::AlignRight | Qt::AlignCenter);
|
||||
m_firstlayout->addWidget(powerStateLabel, 0, Qt::AlignRight | Qt::AlignCenter);
|
||||
m_firstlayout->addStretch();
|
||||
|
||||
m_firstwidget->setLayout(m_firstlayout);
|
||||
|
||||
//滑动条下方标识布局
|
||||
m_statelayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_statelayout->addWidget(m_enduranceIconButtun, 0, Qt::AlignLeft | Qt::AlignCenter);
|
||||
m_statelayout->addItem(new QSpacerItem(300, 2, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
||||
m_statelayout->addWidget(m_performanceIconButtun, 0, Qt::AlignRight);
|
||||
m_statewidget->setLayout(m_statelayout);
|
||||
|
||||
//电源设置按钮布局
|
||||
lastlayout->addWidget(settingLabel);
|
||||
lastlayout->addItem(new QSpacerItem(300, 2));
|
||||
lastWidget->setLayout(lastlayout);
|
||||
lastWidget->setCursor(Qt::PointingHandCursor);
|
||||
|
||||
//总体布局
|
||||
m_pmainlayout->addWidget(m_topwidget);
|
||||
m_pmainlayout->addWidget(m_segmentationLine_1);
|
||||
m_pmainlayout->addWidget(m_firstwidget);
|
||||
m_pmainlayout->addWidget(m_StateSlider, 0 ,Qt::AlignCenter);
|
||||
m_pmainlayout->addWidget(m_statewidget);
|
||||
m_pmainlayout->addWidget(m_segmentationLine_2);
|
||||
m_pmainlayout->addWidget(lastWidget);
|
||||
this->setLayout(m_pmainlayout);
|
||||
}
|
||||
|
||||
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 == SYSTEM_FONT_SIZE) {
|
||||
m_sysFontSize = styleSettings->get(SYSTEM_FONT_SIZE).toInt();
|
||||
get_power_list();
|
||||
}
|
||||
});
|
||||
m_sysFontSize = styleSettings->get(SYSTEM_FONT_SIZE).toInt();
|
||||
}
|
||||
|
||||
const QByteArray powerId(POWER_MANAGER_SETTINGS);
|
||||
m_PowerManagerGsettings = new QGSettings(powerId);
|
||||
qDebug() << "gsettings init";
|
||||
connect(m_PowerManagerGsettings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
if (key == POWER_POLICY_AC || key == POWER_POLICY_BATTERY) {
|
||||
qDebug() << "m_PowerManagerGsettings changed !!!!!!!!!!!!!!";
|
||||
setSliderValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
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::batteryChange(int dev)
|
||||
{
|
||||
if (dev == 4 || dev == 1 || dev == 5) {
|
||||
powerStateLabel->setVisible(true);
|
||||
powerTimeToEmpty->setVisible(false);
|
||||
toplabel->setText(tr("PowerMode"));
|
||||
} else {
|
||||
powerStateLabel->setVisible(false);
|
||||
powerTimeToEmpty->setVisible(true);
|
||||
toplabel->setText(tr("BatteryMode"));
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::onBatteryChanged(QStringList args)
|
||||
{
|
||||
// qDebug()<<"电脑电池电量与状态:"<<args;
|
||||
settings = new QGSettings(GPM_SETTINGS_SCHEMA);
|
||||
int battery = args.at(0).toInt();
|
||||
m_batteryState = args.at(1).toInt();
|
||||
int timeToEmpty = args.at(2).toInt();
|
||||
int is_show = settings->get(GPM_SETTINGS_DISPLAY_LEFT_TIME).toInt();
|
||||
if (is_show) {
|
||||
powerTimeToEmpty->setText(
|
||||
QString(tr("Left %1h %2m")).arg((timeToEmpty) / 3600).arg(((timeToEmpty) % 3600) / 60));
|
||||
} else {
|
||||
powerTimeToEmpty->setText(QString(tr("Discharging")));
|
||||
}
|
||||
if (m_batteryState == 1 || m_batteryState == 5) {
|
||||
powerStateLabel->setText(tr("Charging"));
|
||||
|
||||
} else if (m_batteryState == 4) {
|
||||
powerStateLabel->setText(tr("fully charged"));
|
||||
}
|
||||
batteryChange(m_batteryState);
|
||||
setSliderValue();
|
||||
percentageLabel->setText(QString("%1%").arg(battery));
|
||||
}
|
||||
|
||||
void powerwindow::chargeNotify(bool state)
|
||||
{
|
||||
qDebug() << "powerwindow::chargeNotify";
|
||||
if (!state) {
|
||||
QList<QVariant> args;
|
||||
args << tr("Power Manager") << ((unsigned int)0) << "ukui-power-manager" << tr("charge notification")
|
||||
<< tr("battery is charging") << QStringList() << QVariantMap() << (int)-1;
|
||||
m_notifyInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
} else {
|
||||
QList<QVariant> args;
|
||||
args << tr("Power Manager") << ((unsigned int)0) << "ukui-power-manager" << tr("discharged notification")
|
||||
<< tr("battery is discharging") << QStringList() << QVariantMap() << (int)-1;
|
||||
m_notifyInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::full_charge_notify(DEV dev)
|
||||
{
|
||||
qDebug() << "powerwindow::full_charge_notify";
|
||||
QList<QVariant> args;
|
||||
args << tr("Power Manager")
|
||||
<< ((unsigned int)0)
|
||||
// <<QString("battery-level-100-symbolic")
|
||||
<< "ukui-power-manager" << tr("fullly charged notification") << tr("battery is fullly charged")
|
||||
<< QStringList() << QVariantMap() << (int)-1;
|
||||
m_notifyInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
}
|
||||
|
||||
void powerwindow::lowBatteryNotify()
|
||||
{
|
||||
// qDebug() << "powerwindow::lowBatteryNotify";
|
||||
// QList<QVariant> 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;
|
||||
// m_notifyInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
}
|
||||
|
||||
void powerwindow::criticalBatteryNotify()
|
||||
{
|
||||
// qDebug() << "powerwindow::criticalBatteryNotify";
|
||||
// QList<QVariant> 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;
|
||||
// m_notifyInterface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
}
|
||||
|
||||
void powerwindow::set_window_position()
|
||||
{
|
||||
QDBusInterface iface("org.ukui.panel", "/panel/position", "org.ukui.panel", QDBusConnection::sessionBus());
|
||||
QDBusReply<QVariantList> 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(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
|
||||
this->width(),
|
||||
this->height());
|
||||
break;
|
||||
case 3:
|
||||
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;
|
||||
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::sliderValueChanged(int value)
|
||||
{
|
||||
qDebug() << "slider value" << value << m_batteryState;
|
||||
if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, EnergySaving);
|
||||
m_StateSlider->setToolTip(tr("Better endurance"));
|
||||
break;
|
||||
case 1:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, Balance);
|
||||
m_StateSlider->setToolTip(tr("Better performance"));
|
||||
break;
|
||||
case 2:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, Performance);
|
||||
m_StateSlider->setToolTip(tr("Best performance"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (value) {
|
||||
case 0:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, EnergySaving);
|
||||
m_StateSlider->setToolTip(tr("Better endurance"));
|
||||
break;
|
||||
case 1:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, Balance);
|
||||
m_StateSlider->setToolTip(tr("Better performance"));
|
||||
break;
|
||||
case 2:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, Performance);
|
||||
m_StateSlider->setToolTip(tr("Best performance"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::setSliderValue()
|
||||
{
|
||||
int policy = -1;
|
||||
if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
|
||||
policy = m_PowerManagerGsettings->get(POWER_POLICY_AC).toInt();
|
||||
} else {
|
||||
policy = m_PowerManagerGsettings->get(POWER_POLICY_BATTERY).toInt();
|
||||
}
|
||||
qDebug() << "powerwindow::setSliderValue m_batteryState ; policy is :" << m_batteryState << policy;
|
||||
switch (policy) {
|
||||
case Performance:
|
||||
m_StateSlider->setValue(2);
|
||||
m_StateSlider->setToolTip(tr("Best performance"));
|
||||
break;
|
||||
case Balance:
|
||||
m_StateSlider->setValue(1);
|
||||
m_StateSlider->setToolTip(tr("Better performance"));
|
||||
break;
|
||||
case EnergySaving:
|
||||
m_StateSlider->setValue(0);
|
||||
m_StateSlider->setToolTip(tr("Better endurance"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void powerwindow::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
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.drawRect(opt.rect);
|
||||
}
|
||||
|
||||
bool powerwindow::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == this) {
|
||||
if (event->type() == QEvent::WindowDeactivate) {
|
||||
hide();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef POWERWINDOW_H
|
||||
#define POWERWINDOW_H
|
||||
|
||||
#include "engine_common.h"
|
||||
#include "percentagelabel.h"
|
||||
#include "divider.h"
|
||||
#include "batteryicon.h"
|
||||
#include "stateslider.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QStyleOption>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QDBusInterface>
|
||||
#include <QGSettings>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
#include <QDBusReply>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include "enginedevice.h"
|
||||
#include <QListWidgetItem>
|
||||
#include <QSlider>
|
||||
#include <QMouseEvent>
|
||||
#include <QMap>
|
||||
#include <QProcess>
|
||||
#include <QFont>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include "kylable.h"
|
||||
|
||||
#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 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;
|
||||
|
||||
QVBoxLayout *m_pmainlayout = nullptr;
|
||||
QHBoxLayout *m_toplayout = nullptr;
|
||||
QHBoxLayout *m_firstlayout = nullptr;
|
||||
QHBoxLayout *lastlayout = nullptr;
|
||||
QHBoxLayout *m_statelayout = nullptr;
|
||||
|
||||
QWidget *m_firstwidget;
|
||||
QWidget *lastWidget;
|
||||
QWidget *m_topwidget;
|
||||
QWidget *m_statewidget;
|
||||
|
||||
BatteryIcon *iconButton;
|
||||
PercentageLabel *percentageLabel;
|
||||
QLabel *powerStateLabel;
|
||||
QLabel *powerTimeToEmpty;
|
||||
QLabel *toplabel;
|
||||
QToolButton *m_enduranceIconButtun;
|
||||
QToolButton *m_performanceIconButtun;
|
||||
|
||||
Divider *m_segmentationLine_1;
|
||||
Divider *m_segmentationLine_2;
|
||||
|
||||
StateSlider *m_StateSlider;
|
||||
|
||||
EngineDevice* ed;
|
||||
QListWidget *listWidget;
|
||||
QMap<DEVICE*,QListWidgetItem*> device_item_map;
|
||||
KyLable *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;
|
||||
int m_batteryState;
|
||||
double transparency;
|
||||
QGSettings *transparency_gsettings;
|
||||
QDBusInterface *m_notifyInterface;
|
||||
QGSettings *m_PowerManagerGsettings;
|
||||
enum powerPolicy
|
||||
{
|
||||
Performance = 0,
|
||||
Balance,
|
||||
EnergySaving,
|
||||
};
|
||||
|
||||
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
void watchTranspartency();
|
||||
void setSliderValue();
|
||||
private Q_SLOTS:
|
||||
|
||||
void batteryChange(int dev);
|
||||
void onBatteryChanged(QStringList args);
|
||||
|
||||
void chargeNotify(bool state);
|
||||
void criticalBatteryNotify();
|
||||
void lowBatteryNotify();
|
||||
void full_charge_notify(DEV dev);
|
||||
void sliderValueChanged(int);
|
||||
|
||||
};
|
||||
|
||||
#endif // POWERWINDOW_H
|
|
@ -0,0 +1,17 @@
|
|||
[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
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
#include "stateslider.h"
|
||||
|
||||
//滑动条组件
|
||||
StateSlider::StateSlider(QWidget *parent) : KSlider(parent)
|
||||
{
|
||||
setOrientation(Qt::Orientation::Horizontal);
|
||||
setSliderType(KSliderType::SingleSelectSlider);
|
||||
setMaximum(2);
|
||||
setSingleStep(1);
|
||||
setPageStep(1);
|
||||
setFixedWidth(392);
|
||||
}
|
||||
|
||||
StateSlider::~StateSlider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StateSlider::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
int currentX = event->pos().x();
|
||||
double per = currentX * 1.0 / this->width();
|
||||
int value = per * (this->maximum() - this->minimum()) + this->minimum();
|
||||
this->setValue(value);
|
||||
QSlider::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void StateSlider::setSliderValue()
|
||||
{
|
||||
#if 0
|
||||
int policy = -1;
|
||||
if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
|
||||
policy = m_PowerManagerGsettings->get(POWER_POLICY_AC).toInt();
|
||||
} else {
|
||||
policy = m_PowerManagerGsettings->get(POWER_POLICY_BATTERY).toInt();
|
||||
}
|
||||
switch (policy) {
|
||||
case Performance:
|
||||
this->setValue(2);
|
||||
break;
|
||||
case Balance:
|
||||
this->setValue(1);
|
||||
break;
|
||||
case EnergySaving:
|
||||
this->setValue(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void StateSlider::sliderValueChanged(int value)
|
||||
{
|
||||
#if 0
|
||||
qDebug() << "slider value" << value << m_batteryState;
|
||||
if (1 == m_batteryState || 4 == m_batteryState || 5 == m_batteryState) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, EnergySaving);
|
||||
break;
|
||||
case 1:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, Balance);
|
||||
break;
|
||||
case 2:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_AC, Performance);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (value) {
|
||||
case 0:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, EnergySaving);
|
||||
break;
|
||||
case 1:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, Balance);
|
||||
break;
|
||||
case 2:
|
||||
m_PowerManagerGsettings->set(POWER_POLICY_BATTERY, Performance);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef STATESLIDER_H
|
||||
#define STATESLIDER_H
|
||||
#include <QSlider>
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
#include <QMouseEvent>
|
||||
|
||||
//#include "ktabbar.h"
|
||||
#include "kslider.h"
|
||||
//#include "kwidget.h"
|
||||
|
||||
using namespace kdk;
|
||||
|
||||
class StateSlider : public KSlider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StateSlider(QWidget *parent = 0);
|
||||
~StateSlider();
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
||||
public Q_SLOTS:
|
||||
void sliderValueChanged(int);
|
||||
|
||||
private:
|
||||
void setSliderValue();
|
||||
|
||||
};
|
||||
|
||||
#endif // STATESLIDER_H
|
|
@ -0,0 +1,298 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="bo">
|
||||
<context>
|
||||
<name>EngineDevice</name>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="112"/>
|
||||
<source>yes</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="112"/>
|
||||
<source>no</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="142"/>
|
||||
<source>Yes</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="142"/>
|
||||
<source>No</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="497"/>
|
||||
<source>Unknown time</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="503"/>
|
||||
<location filename="../enginedevice.cpp" line="521"/>
|
||||
<source>minute</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="505"/>
|
||||
<location filename="../enginedevice.cpp" line="523"/>
|
||||
<source>minutes</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="515"/>
|
||||
<location filename="../enginedevice.cpp" line="525"/>
|
||||
<source>hour</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="517"/>
|
||||
<location filename="../enginedevice.cpp" line="527"/>
|
||||
<source>hours</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="578"/>
|
||||
<source>Left %1h %2m (%3%)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="595"/>
|
||||
<source>charging (%1%)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="669"/>
|
||||
<source>AC adapter</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="572"/>
|
||||
<source>%1% available, charged</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="583"/>
|
||||
<source>%1% available</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="593"/>
|
||||
<source>Left %1h %2m to full</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="601"/>
|
||||
<source>%1 waiting to discharge (%2%)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="606"/>
|
||||
<source>%1 waiting to charge (%2%)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="673"/>
|
||||
<source>Laptop battery</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="677"/>
|
||||
<source>UPS</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="681"/>
|
||||
<source>Monitor</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="685"/>
|
||||
<source>Mouse</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="689"/>
|
||||
<source>Keyboard</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="693"/>
|
||||
<source>PDA</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="697"/>
|
||||
<source>Cell phone</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="701"/>
|
||||
<source>Media player</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="705"/>
|
||||
<source>Tablet</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="709"/>
|
||||
<source>Computer</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="713"/>
|
||||
<source>unrecognised</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>PowerTray</name>
|
||||
<message>
|
||||
<location filename="../powertray.cpp" line="123"/>
|
||||
<source>SetPower</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>S:</name>
|
||||
<message>
|
||||
<location filename="enginedevice.cpp" line="826"/>
|
||||
<source></source>
|
||||
<comment>tablet device</comment>
|
||||
<translation></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>powerwindow</name>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="136"/>
|
||||
<location filename="../powerwindow.cpp" line="294"/>
|
||||
<source>Charging</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="154"/>
|
||||
<source>Endurance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="162"/>
|
||||
<source>performance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="170"/>
|
||||
<source>PowerSettings</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="173"/>
|
||||
<location filename="../powerwindow.cpp" line="271"/>
|
||||
<source>PowerMode</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="275"/>
|
||||
<source>BatteryMode</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="289"/>
|
||||
<source>Left %1h %2m</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="291"/>
|
||||
<source>Discharging</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="297"/>
|
||||
<source>fully charged</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="309"/>
|
||||
<location filename="../powerwindow.cpp" line="314"/>
|
||||
<location filename="../powerwindow.cpp" line="324"/>
|
||||
<location filename="../powerwindow.cpp" line="336"/>
|
||||
<location filename="../powerwindow.cpp" line="345"/>
|
||||
<source>Power Manager</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="309"/>
|
||||
<source>charge notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="310"/>
|
||||
<source>battery is charging</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="314"/>
|
||||
<source>discharged notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="315"/>
|
||||
<source>battery is discharging</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="327"/>
|
||||
<source>fullly charged notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="327"/>
|
||||
<source>battery is fullly charged</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="336"/>
|
||||
<source>low battery notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="337"/>
|
||||
<source>battery is low, please plug in power</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="346"/>
|
||||
<source>critical battery notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="346"/>
|
||||
<source>battery is critical low,please plug in!</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="415"/>
|
||||
<location filename="../powerwindow.cpp" line="432"/>
|
||||
<location filename="../powerwindow.cpp" line="468"/>
|
||||
<source>Better endurance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="419"/>
|
||||
<location filename="../powerwindow.cpp" line="436"/>
|
||||
<location filename="../powerwindow.cpp" line="464"/>
|
||||
<source>Better performance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="423"/>
|
||||
<location filename="../powerwindow.cpp" line="440"/>
|
||||
<location filename="../powerwindow.cpp" line="460"/>
|
||||
<source>Best performance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
|
@ -0,0 +1,444 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="zh_CN">
|
||||
<context>
|
||||
<name>DeviceForm</name>
|
||||
<message>
|
||||
<source>RemainTime</source>
|
||||
<translation type="vanished">预计剩余时间</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DeviceWidget</name>
|
||||
<message>
|
||||
<source>RemainTime</source>
|
||||
<translation type="vanished">预计剩余时间</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>EngineDevice</name>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="112"/>
|
||||
<source>yes</source>
|
||||
<translation>是</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="112"/>
|
||||
<source>no</source>
|
||||
<translation>不</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="142"/>
|
||||
<source>Yes</source>
|
||||
<translation>是</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="142"/>
|
||||
<source>No</source>
|
||||
<translation>不</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="497"/>
|
||||
<source>Unknown time</source>
|
||||
<translation>未知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="503"/>
|
||||
<location filename="../enginedevice.cpp" line="521"/>
|
||||
<source>minute</source>
|
||||
<translation>分钟</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="505"/>
|
||||
<location filename="../enginedevice.cpp" line="523"/>
|
||||
<source>minutes</source>
|
||||
<translation>分钟</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="515"/>
|
||||
<location filename="../enginedevice.cpp" line="525"/>
|
||||
<source>hour</source>
|
||||
<translation>小时</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="517"/>
|
||||
<location filename="../enginedevice.cpp" line="527"/>
|
||||
<source>hours</source>
|
||||
<translation>小时</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>fully charged</source>
|
||||
<translation type="vanished">已充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>not charging</source>
|
||||
<translation type="vanished">未充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="572"/>
|
||||
<source>%1% available, charged</source>
|
||||
<translation>%1%可用,已充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1% available, not charging</source>
|
||||
<translation type="vanished">%1%可用,未充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1% available, charging</source>
|
||||
<translation type="vanished">%1%可用,正在充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="601"/>
|
||||
<source>%1 waiting to discharge (%2%)</source>
|
||||
<translation>%1 等待放电 (%2%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="606"/>
|
||||
<source>%1 waiting to charge (%2%)</source>
|
||||
<translation>%1 等待充电 (%2%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>discharging(%1%)</source>
|
||||
<translation type="vanished">放电(%1%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>charging(%1%)</source>
|
||||
<translation type="vanished">充电(%1%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="669"/>
|
||||
<source>AC adapter</source>
|
||||
<translation>交流电源适配器</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="673"/>
|
||||
<source>Laptop battery</source>
|
||||
<translation>笔记本电池</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="677"/>
|
||||
<source>UPS</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="681"/>
|
||||
<source>Monitor</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="685"/>
|
||||
<source>Mouse</source>
|
||||
<translation>鼠标</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="689"/>
|
||||
<source>Keyboard</source>
|
||||
<translation>键盘</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="693"/>
|
||||
<source>PDA</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="697"/>
|
||||
<source>Cell phone</source>
|
||||
<translation>手机</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="701"/>
|
||||
<source>Media player</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="705"/>
|
||||
<source>Tablet</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="709"/>
|
||||
<source>Computer</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="713"/>
|
||||
<source>unrecognised</source>
|
||||
<translation>未识别</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>charging</source>
|
||||
<translation type="vanished">正在充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="578"/>
|
||||
<source>Left %1h %2m (%3%)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="583"/>
|
||||
<source>%1% available</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="593"/>
|
||||
<source>Left %1h %2m to full</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="595"/>
|
||||
<source>charging (%1%)</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>discharging</source>
|
||||
<translation type="vanished">放电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>empty</source>
|
||||
<translation type="vanished">电量空</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>fully</source>
|
||||
<translation type="vanished">电量满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>other</source>
|
||||
<translation type="vanished">其他</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MainWindow</name>
|
||||
<message>
|
||||
<source>SetPower</source>
|
||||
<translation type="vanished">设置电源和睡眠</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ShowPercentage</source>
|
||||
<translation type="vanished">显示百分比</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SetBrightness</source>
|
||||
<translation type="vanished">调整亮度</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>discharge notify notification</source>
|
||||
<translation type="vanished">正在放电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is discharging!</source>
|
||||
<translation type="vanished">电池正在放电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>fullly charged notification</source>
|
||||
<translation type="vanished">电池充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is fullly charged!</source>
|
||||
<translation type="vanished">电池已经充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>low battery notification</source>
|
||||
<translation type="vanished">电量低</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is low,please plug in!</source>
|
||||
<translation type="vanished">电量低,请充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>critical battery notification</source>
|
||||
<translation type="vanished">电量很低</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is critical low,please plug in!</source>
|
||||
<translation type="vanished">电量很低,请充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>very low battery notification</source>
|
||||
<translation type="vanished">电量非常低</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is very low,please plug in!</source>
|
||||
<translation type="vanished">电量即将耗尽!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerManagement</source>
|
||||
<translation type="vanished">电源管理</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Stats</source>
|
||||
<oldsource>Statistics</oldsource>
|
||||
<translation type="vanished">电源统计</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerManager</source>
|
||||
<translation type="vanished">电源管理</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerStatistics</source>
|
||||
<translation type="vanished">电源统计</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerSaveMode</source>
|
||||
<translation type="vanished">省电模式</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>BatterySave</source>
|
||||
<translation type="vanished">电池养护</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Brightness</source>
|
||||
<translation type="vanished">亮度</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>PowerTray</name>
|
||||
<message>
|
||||
<location filename="../powertray.cpp" line="123"/>
|
||||
<source>SetPower</source>
|
||||
<translation type="unfinished">设置电源和睡眠</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>S:</name>
|
||||
<message>
|
||||
<location filename="enginedevice.cpp" line="583"/>
|
||||
<source></source>
|
||||
<comment>tablet device</comment>
|
||||
<translation></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>powerwindow</name>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="136"/>
|
||||
<location filename="../powerwindow.cpp" line="294"/>
|
||||
<source>Charging</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="291"/>
|
||||
<source>Discharging</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="297"/>
|
||||
<source>fully charged</source>
|
||||
<translation type="unfinished">已充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerManagement</source>
|
||||
<translation type="obsolete">电源管理</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="154"/>
|
||||
<source>Endurance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="162"/>
|
||||
<source>performance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="170"/>
|
||||
<source>PowerSettings</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="173"/>
|
||||
<location filename="../powerwindow.cpp" line="271"/>
|
||||
<source>PowerMode</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="275"/>
|
||||
<source>BatteryMode</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="289"/>
|
||||
<source>Left %1h %2m</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="309"/>
|
||||
<location filename="../powerwindow.cpp" line="314"/>
|
||||
<location filename="../powerwindow.cpp" line="324"/>
|
||||
<location filename="../powerwindow.cpp" line="336"/>
|
||||
<location filename="../powerwindow.cpp" line="345"/>
|
||||
<source>Power Manager</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="309"/>
|
||||
<source>charge notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="310"/>
|
||||
<source>battery is charging</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="314"/>
|
||||
<source>discharged notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="315"/>
|
||||
<source>battery is discharging</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="327"/>
|
||||
<source>fullly charged notification</source>
|
||||
<translation type="unfinished">电池充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="327"/>
|
||||
<source>battery is fullly charged</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="336"/>
|
||||
<source>low battery notification</source>
|
||||
<translation type="unfinished">电量低</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="337"/>
|
||||
<source>battery is low, please plug in power</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="346"/>
|
||||
<source>critical battery notification</source>
|
||||
<translation type="unfinished">电量很低</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="346"/>
|
||||
<source>battery is critical low,please plug in!</source>
|
||||
<translation type="unfinished">电量很低,请充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="415"/>
|
||||
<location filename="../powerwindow.cpp" line="432"/>
|
||||
<location filename="../powerwindow.cpp" line="468"/>
|
||||
<source>Better endurance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="419"/>
|
||||
<location filename="../powerwindow.cpp" line="436"/>
|
||||
<location filename="../powerwindow.cpp" line="464"/>
|
||||
<source>Better performance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="423"/>
|
||||
<location filename="../powerwindow.cpp" line="440"/>
|
||||
<location filename="../powerwindow.cpp" line="460"/>
|
||||
<source>Best performance</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
Binary file not shown.
|
@ -0,0 +1,509 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="zh_CN">
|
||||
<context>
|
||||
<name>DeviceForm</name>
|
||||
<message>
|
||||
<source>RemainTime</source>
|
||||
<translation type="vanished">预计剩余时间</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DeviceWidget</name>
|
||||
<message>
|
||||
<source>RemainTime</source>
|
||||
<translation type="vanished">预计剩余时间</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>EngineDevice</name>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="112"/>
|
||||
<source>yes</source>
|
||||
<translation>是</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="112"/>
|
||||
<source>no</source>
|
||||
<translation>不</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="142"/>
|
||||
<source>Yes</source>
|
||||
<translation>是</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="142"/>
|
||||
<source>No</source>
|
||||
<translation>不</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="497"/>
|
||||
<source>Unknown time</source>
|
||||
<translation>未知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="503"/>
|
||||
<location filename="../enginedevice.cpp" line="521"/>
|
||||
<source>minute</source>
|
||||
<translation>分钟</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="505"/>
|
||||
<location filename="../enginedevice.cpp" line="523"/>
|
||||
<source>minutes</source>
|
||||
<translation>分钟</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="515"/>
|
||||
<location filename="../enginedevice.cpp" line="525"/>
|
||||
<source>hour</source>
|
||||
<translation>小时</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="517"/>
|
||||
<location filename="../enginedevice.cpp" line="527"/>
|
||||
<source>hours</source>
|
||||
<translation>小时</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>fully charged</source>
|
||||
<translation type="vanished">已充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>not charging</source>
|
||||
<translation type="vanished">未充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="572"/>
|
||||
<source>%1% available, charged</source>
|
||||
<translation>%1%可用,已充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1% available, not charging</source>
|
||||
<translation type="vanished">%1%可用,未充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>%1% available, charging</source>
|
||||
<translation type="vanished">%1%可用,正在充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="601"/>
|
||||
<source>%1 waiting to discharge (%2%)</source>
|
||||
<translation>%1 等待放电 (%2%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="606"/>
|
||||
<source>%1 waiting to charge (%2%)</source>
|
||||
<translation>%1 等待充电 (%2%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>discharging(%1%)</source>
|
||||
<translation type="vanished">放电(%1%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>charging(%1%)</source>
|
||||
<translation type="vanished">充电(%1%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="669"/>
|
||||
<source>AC adapter</source>
|
||||
<translation>交流电源适配器</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="673"/>
|
||||
<source>Laptop battery</source>
|
||||
<translation>笔记本电池</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="677"/>
|
||||
<source>UPS</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="681"/>
|
||||
<source>Monitor</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="685"/>
|
||||
<source>Mouse</source>
|
||||
<translation>鼠标</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="689"/>
|
||||
<source>Keyboard</source>
|
||||
<translation>键盘</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="693"/>
|
||||
<source>PDA</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="697"/>
|
||||
<source>Cell phone</source>
|
||||
<translation>手机</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="701"/>
|
||||
<source>Media player</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="705"/>
|
||||
<source>Tablet</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="709"/>
|
||||
<source>Computer</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="713"/>
|
||||
<source>unrecognised</source>
|
||||
<translation>未识别</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>charging</source>
|
||||
<translation type="vanished">正在充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="578"/>
|
||||
<source>Left %1h %2m (%3%)</source>
|
||||
<translation>剩余 %1小时 %2分钟 (%3%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="583"/>
|
||||
<source>%1% available</source>
|
||||
<translation>%1%可用</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="593"/>
|
||||
<source>Left %1h %2m to full</source>
|
||||
<translation>剩余%1小时%2分钟充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../enginedevice.cpp" line="595"/>
|
||||
<source>charging (%1%)</source>
|
||||
<translation>正在充电 (%1%)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>discharging</source>
|
||||
<translation type="vanished">放电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>empty</source>
|
||||
<translation type="vanished">电量空</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>fully</source>
|
||||
<translation type="vanished">电量满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>other</source>
|
||||
<translation type="vanished">其他</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MainWindow</name>
|
||||
<message>
|
||||
<source>SetPower</source>
|
||||
<translation type="vanished">设置电源和睡眠</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ShowPercentage</source>
|
||||
<translation type="vanished">显示百分比</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>SetBrightness</source>
|
||||
<translation type="vanished">调整亮度</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>discharge notify notification</source>
|
||||
<translation type="vanished">正在放电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>discharged notification</source>
|
||||
<translation type="vanished">放电通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is discharging!</source>
|
||||
<translation type="vanished">电池正在放电中</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>fullly charged notification</source>
|
||||
<translation type="vanished">充满电通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is fullly charged!</source>
|
||||
<translation type="vanished">电池已经充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>low battery notification</source>
|
||||
<translation type="vanished">低电量通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is low,please plug in!</source>
|
||||
<translation type="vanished">电量低,请充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>critical battery notification</source>
|
||||
<translation type="vanished">电量很低</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is critical low,please plug in!</source>
|
||||
<translation type="vanished">电量很低,请充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>very low battery notification</source>
|
||||
<translation type="vanished">电量非常低</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is very low,please plug in!</source>
|
||||
<translation type="vanished">电量即将耗尽!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerManagement</source>
|
||||
<translation type="vanished">电源管理</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>charge notification</source>
|
||||
<translation type="vanished">充电通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is charging</source>
|
||||
<translation type="vanished">电池正在充电中</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is discharging</source>
|
||||
<translation type="vanished">电池正在放电中</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is fullly charged</source>
|
||||
<translatorcomment>电量已经充满</translatorcomment>
|
||||
<translation type="vanished">电量现在已经充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>battery is low, please plug in power</source>
|
||||
<translation type="vanished">电量水平低,请插入电源</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>operation notification</source>
|
||||
<translation type="vanished">低电量操作通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>performing low power operation</source>
|
||||
<translation type="vanished">系统将执行设置的操作</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Stats</source>
|
||||
<oldsource>Statistics</oldsource>
|
||||
<translation type="vanished">电源统计</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerManager</source>
|
||||
<translation type="vanished">电源管理</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerStatistics</source>
|
||||
<translation type="vanished">电源统计</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerSaveMode</source>
|
||||
<translation type="vanished">省电模式</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>BatterySave</source>
|
||||
<translation type="vanished">电池养护</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Brightness</source>
|
||||
<translation type="vanished">亮度</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>PowerTray</name>
|
||||
<message>
|
||||
<location filename="../powertray.cpp" line="123"/>
|
||||
<source>SetPower</source>
|
||||
<translation>设置电源和睡眠</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>S:</name>
|
||||
<message>
|
||||
<location filename="enginedevice.cpp" line="583"/>
|
||||
<source></source>
|
||||
<comment>tablet device</comment>
|
||||
<translation></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsLabel</name>
|
||||
<message>
|
||||
<source>PowerSet</source>
|
||||
<translation type="vanished">电源设置</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Power settings</source>
|
||||
<translation type="vanished">电源设置</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>powerwindow</name>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="136"/>
|
||||
<location filename="../powerwindow.cpp" line="294"/>
|
||||
<source>Charging</source>
|
||||
<translation>正在充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Left %1h
|
||||
%2m</source>
|
||||
<translation type="vanished">剩余 %1小时
|
||||
%2分钟</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="291"/>
|
||||
<source>Discharging</source>
|
||||
<translation>正在放电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="297"/>
|
||||
<source>fully charged</source>
|
||||
<translation>已充满电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="289"/>
|
||||
<source>Left %1h %2m</source>
|
||||
<translation>剩余 %1小时 %2分钟</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PowerManagement</source>
|
||||
<translation type="obsolete">电源管理</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="154"/>
|
||||
<source>Endurance</source>
|
||||
<translation>续航</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="162"/>
|
||||
<source>performance</source>
|
||||
<translation>性能</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="170"/>
|
||||
<source>PowerSettings</source>
|
||||
<translation>电源设置</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="173"/>
|
||||
<location filename="../powerwindow.cpp" line="271"/>
|
||||
<source>PowerMode</source>
|
||||
<translation>电源模式</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="275"/>
|
||||
<source>BatteryMode</source>
|
||||
<translation>电池模式</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="309"/>
|
||||
<location filename="../powerwindow.cpp" line="314"/>
|
||||
<location filename="../powerwindow.cpp" line="324"/>
|
||||
<location filename="../powerwindow.cpp" line="336"/>
|
||||
<location filename="../powerwindow.cpp" line="345"/>
|
||||
<source>Power Manager</source>
|
||||
<translation>电源管理器</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="309"/>
|
||||
<source>charge notification</source>
|
||||
<translation>充电通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="310"/>
|
||||
<source>battery is charging</source>
|
||||
<translation>电池正在充电中</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="314"/>
|
||||
<source>discharged notification</source>
|
||||
<translation>放电通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="315"/>
|
||||
<source>battery is discharging</source>
|
||||
<translation>电池正在放电中</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="327"/>
|
||||
<source>fullly charged notification</source>
|
||||
<translation>充满电通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="327"/>
|
||||
<source>battery is fullly charged</source>
|
||||
<translation>电量现在已经充满</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="336"/>
|
||||
<source>low battery notification</source>
|
||||
<translation>低电量通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="337"/>
|
||||
<source>battery is low, please plug in power</source>
|
||||
<translation>电量水平低,请及时充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="346"/>
|
||||
<source>critical battery notification</source>
|
||||
<translation>电量很低</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="346"/>
|
||||
<source>battery is critical low,please plug in!</source>
|
||||
<translation>电量很低,请充电</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="415"/>
|
||||
<location filename="../powerwindow.cpp" line="432"/>
|
||||
<location filename="../powerwindow.cpp" line="468"/>
|
||||
<source>Better endurance</source>
|
||||
<translation>更好续航</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="419"/>
|
||||
<location filename="../powerwindow.cpp" line="436"/>
|
||||
<location filename="../powerwindow.cpp" line="464"/>
|
||||
<source>Better performance</source>
|
||||
<translation>更好性能</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../powerwindow.cpp" line="423"/>
|
||||
<location filename="../powerwindow.cpp" line="440"/>
|
||||
<location filename="../powerwindow.cpp" line="460"/>
|
||||
<source>Best performance</source>
|
||||
<translation>最佳性能</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>operation notification</source>
|
||||
<translation type="vanished">低电量操作通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>performing low power operation</source>
|
||||
<translation type="vanished">系统将执行设置的操作</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>settinglabel</name>
|
||||
<message>
|
||||
<source>PowerSet</source>
|
||||
<translation type="vanished">电源设置</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
|
@ -0,0 +1,99 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# 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 kysdk-qtwidgets
|
||||
|
||||
SOURCES += \
|
||||
batteryicon.cpp \
|
||||
device.cpp \
|
||||
divider.cpp \
|
||||
enginedevice.cpp \
|
||||
main.cpp \
|
||||
percentagelabel.cpp \
|
||||
powertray.cpp \
|
||||
powerwindow.cpp \
|
||||
kylable.cpp \
|
||||
stateslider.cpp \
|
||||
xatom-helper.cpp \
|
||||
customstyle.cpp
|
||||
|
||||
|
||||
HEADERS += \
|
||||
batteryicon.h \
|
||||
device.h \
|
||||
divider.h \
|
||||
engine_common.h \
|
||||
enginedevice.h \
|
||||
percentagelabel.h \
|
||||
powertray.h \
|
||||
powerwindow.h \
|
||||
kylable.h \
|
||||
stateslider.h \
|
||||
xatom-helper.h \
|
||||
customstyle.h
|
||||
|
||||
FORMS +=
|
||||
desktop.files += resources/ukui-power-manager-tray.desktop
|
||||
|
||||
desktop.path = /etc/xdg/autostart/
|
||||
|
||||
INSTALLS += desktop
|
||||
|
||||
|
||||
# Default rules for deployment.
|
||||
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Yue Lan <lanyue@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xatom-helper.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <QX11Info>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xatom.h>
|
||||
|
||||
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<ulong>(data[0]);
|
||||
corners.topRight = static_cast<ulong>(data[1*sizeof (ulong)]);
|
||||
corners.bottomLeft = static_cast<ulong>(data[2*sizeof (ulong)]);
|
||||
corners.bottomRight = static_cast<ulong>(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:
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Yue Lan <lanyue@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef XATOMHELPER_H
|
||||
#define XATOMHELPER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
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
|
|
@ -0,0 +1,7 @@
|
|||
A.使用工具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
|
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
#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<QVariant> 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<QVariant> 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<QVariant> 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<QVariant> 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;
|
||||
}
|
||||
}
|
||||
|
||||
int BatteryInfo::getBatteryState()
|
||||
{
|
||||
QDBusReply<QVariant> reply = iface->call("Get", UPOWER_DIVICES_SERVICE, "State");
|
||||
if (reply.isValid()) {
|
||||
return reply.value().toInt();
|
||||
} else {
|
||||
qDebug() << "Get Battery State failed";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BATTERYINFO_H
|
||||
#define BATTERYINFO_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtDBus>
|
||||
#include <QGSettings>
|
||||
#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();
|
||||
|
||||
int getBatteryState();
|
||||
|
||||
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
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#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
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue