commit ebf7d8d80eff60061fa4078dda3e70fd55285684 Author: Andrew Lee (李健秋) Date: Wed Aug 12 05:17:53 2015 +0800 Adding upstream version 0.9.0. Signed-off-by: Andrew Lee (李健秋) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..384cad1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +nbproject diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..fcaabf9 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +Upstream Authors: + LXQt team: http://lxqt.org + +Copyright: + Copyright (c) 2013-2014 LXQt team + +License: GPL-2 and LGPL-2.1+ +The full text of the licenses can be found in the 'COPYING' file. diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..eb50fdb --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 2.8.11) + +project(lxqt-powermanagement) + +option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_AUTOMOC ON) + +find_package(Qt5Widgets REQUIRED) +find_package(Qt5DBus REQUIRED) +find_package(Qt5X11Extras REQUIRED) +find_package(Qt5Svg REQUIRED) +find_package(Qt5LinguistTools REQUIRED QUIET) +find_package(lxqt REQUIRED QUIET) +find_package(Qt5Xdg REQUIRED) +message(STATUS "Building with Qt${Qt5Core_VERSION_STRING}") + +include(${LXQT_USE_FILE}) +include(${QTXDG_USE_FILE}) + +include(LXQtTranslate) + +add_subdirectory(config) +add_subdirectory(src) + +# building tarball with CPack ------------------------------------------------- +include(InstallRequiredSystemLibraries) +set(CPACK_PACKAGE_VERSION_MAJOR ${LXQT_MAJOR_VERSION}) +set(CPACK_PACKAGE_VERSION_MINOR ${LXQT_MINOR_VERSION}) +set(CPACK_PACKAGE_VERSION_PATCH ${LXQT_PATCH_VERSION}) +set(CPACK_GENERATOR TBZ2) +set(CPACK_SOURCE_GENERATOR TBZ2) +set(CPACK_SOURCE_IGNORE_FILES /build/;.gitignore;.*~;.git;.kdev4;temp) +include(CPack) diff --git a/CMakeLists.txt.user.3.3-pre1 b/CMakeLists.txt.user.3.3-pre1 new file mode 100644 index 0000000..06e993f --- /dev/null +++ b/CMakeLists.txt.user.3.3-pre1 @@ -0,0 +1,239 @@ + + + + + + EnvironmentId + {5c6f7c82-f2e7-4d03-9d51-5ba00c7370fd} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {5e382e87-0cbd-448b-81ff-a635a0cc40fe} + 0 + 0 + 0 + + false + /home/christian/projekter/Aktive/lxqt/lxqt-powermanagement/build + + + + + false + true + Make + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + clean + + true + true + Make + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + all + + CMakeProjectManager.CMakeBuildConfiguration + + 1 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + lxqt-config-powermanagement + + false + + 2 + + lxqt-config-powermanagement + + CMakeProjectManager.CMakeRunConfiguration.lxqt-config-powermanagement + 3768 + false + true + false + false + true + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + lxqt-powermanagement + + false + + 2 + + lxqt-powermanagement + + CMakeProjectManager.CMakeRunConfiguration.lxqt-powermanagement + 3768 + false + true + false + false + true + + 2 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 16 + + + Version + 16 + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..56f967f --- /dev/null +++ b/LICENSE @@ -0,0 +1,502 @@ +GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +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 this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser 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 Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "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 +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY 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 +LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + powermanagement module for lxde-qt + Copyright (C) 2013 Christian Surlykke + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + {signature of Ty Coon}, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/README.md b/README.md new file mode 100644 index 0000000..c556f53 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +lxqt-powermanagement +==================== + +Power management module for LXQt diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 0000000..3f725eb --- /dev/null +++ b/config/CMakeLists.txt @@ -0,0 +1,78 @@ +project(lxqt-config-powermanagement) + +set(QTX_LIBRARIES Qt5::Widgets Qt5::DBus Qt5::Svg) + +set(config-powermanagement_MOCS + mainwindow.h + lidwatchersettings.h + batterywatchersettings.h + idlenesswatchersettings.h + powermanagementsettings.h +) + +set(config-powermanagement_SRCS + main.cpp + mainwindow.cpp + lidwatchersettings.cpp + batterywatchersettings.cpp + idlenesswatchersettings.cpp + powermanagementsettings.cpp + helpers.cpp + ../src/iconproducer.cpp + ../src/battery.cpp +) + +set(config-powermanagement_UIS + lidwatchersettings.ui + batterywatchersettings.ui + idlenesswatchersettings.ui +) + +set(config-powermanagement_RSCS + config-powermanagement.qrc +) + +set(ICON_FILES + icons/laptop-lid.svg +) + +set(DESKTOP_FILES_IN + lxqt-config-powermanagement.desktop.in +) + +# Translations ********************************** + +lxqt_translate_ts(QM_FILES + UPDATE_TRANSLATIONS ${UPDATE_TRANSLATIONS} + SOURCES + ${config-powermanagement_SRCS} + ${config-powermanagement_UIS} + ${config-powermanagement_MOCS} + INSTALL_DIR + ${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME} +) + +lxqt_app_translation_loader(config-powermanagement_QM_LOADER ${PROJECT_NAME}) +lxqt_translate_desktop(DESKTOP_FILES SOURCES ${DESKTOP_FILES_IN}) + + +qt5_add_resources(RSCS ${config-powermanagement_RSCS}) +qt5_wrap_ui(UIS ${config-powermanagement_UIS}) + +add_executable(${PROJECT_NAME} + ${config-powermanagement_SRCS} + ${UIS} + ${DESKTOP_FILES} + ${QM_FILES} + ${config-powermanagement_QM_LOADER} +) + +target_link_libraries(lxqt-config-powermanagement + ${LXQT_LIBRARIES} + ${QTXDG_LIBRARIES} + ${QTX_LIBRARIES} +) + +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) +install(FILES ${DESKTOP_FILES} DESTINATION share/applications) +install(FILES ${ICON_FILES} DESTINATION share/icons/hicolor/scalable/devices) diff --git a/config/batterywatchersettings.cpp b/config/batterywatchersettings.cpp new file mode 100644 index 0000000..d680ae4 --- /dev/null +++ b/config/batterywatchersettings.cpp @@ -0,0 +1,109 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#include + +#include +#include +#include + +#include "batterywatchersettings.h" +#include "ui_batterywatchersettings.h" +#include "powermanagementsettings.h" +#include "../src/battery.h" + +BatteryWatcherSettings::BatteryWatcherSettings(QWidget *parent) : + QWidget(parent), + mSettings(), + mUi(new Ui::BatteryWatcherSettings), + mChargingIconProducer(), + mDischargingIconProducer() + +{ + mUi->setupUi(this); + fillComboBox(mUi->actionComboBox); + mUi->chargeLevelSlider->setValue(53); + + connect(mUi->groupBox, SIGNAL(clicked()), this, SLOT(saveSettings())); + connect(mUi->actionComboBox, SIGNAL(activated(int)), this, SLOT(saveSettings())); + connect(mUi->warningSpinBox, SIGNAL(editingFinished()), this, SLOT(saveSettings())); + connect(mUi->levelSpinBox, SIGNAL(editingFinished()), this, SLOT(saveSettings())); + connect(mUi->showIconCheckBox, SIGNAL(clicked(bool)), this, SLOT(saveSettings())); + connect(mUi->showIconCheckBox, SIGNAL(clicked(bool)), mUi->previewBox, SLOT(setEnabled(bool))); + connect(mUi->useThemeIconsCheckBox, SIGNAL(clicked(bool)), this, SLOT(saveSettings())); + connect(mUi->useThemeIconsCheckBox, SIGNAL(clicked(bool)), this, SLOT(updatePreview())); + connect(mUi->chargeLevelSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePreview())); + connect(&mChargingIconProducer, SIGNAL(iconChanged()), this, SLOT(onChargeIconChanged())); + connect(&mDischargingIconProducer, SIGNAL(iconChanged()), this, SLOT(onDischargeIconChanged())); + updatePreview(); +} + +BatteryWatcherSettings::~BatteryWatcherSettings() +{ + delete mUi; +} + +void BatteryWatcherSettings::loadSettings() +{ + mUi->groupBox->setChecked(mSettings.isBatteryWatcherEnabled()); + setComboBoxToValue(mUi->actionComboBox, mSettings.getPowerLowAction()); + mUi->warningSpinBox->setValue(mSettings.getPowerLowWarningTime()); + mUi->levelSpinBox->setValue(mSettings.getPowerLowLevel()); + mUi->showIconCheckBox->setChecked(mSettings.isShowIcon()); + mUi->useThemeIconsCheckBox->setChecked(mSettings.isUseThemeIcons()); +} + +void BatteryWatcherSettings::saveSettings() +{ + mSettings.setBatteryWatcherEnabled(mUi->groupBox->isChecked()); + mSettings.setPowerLowAction(currentValue(mUi->actionComboBox)); + mSettings.setPowerLowWarningTime(mUi->warningSpinBox->value()); + mSettings.setPowerLowLevel(mUi->levelSpinBox->value()); + mSettings.setShowIcon(mUi->showIconCheckBox->isChecked()); + mSettings.setUseThemeIcons(mUi->useThemeIconsCheckBox->isChecked()); +} + +void BatteryWatcherSettings::updatePreview() +{ + mUi->previewBox->setTitle(tr("Preview") + QString(" (%1)").arg(mSettings.isUseThemeIcons() ? QIcon::themeName() : tr("built in"))); + + float chargeLevel = mUi->chargeLevelSlider->value(); + mChargingIconProducer.update(chargeLevel, Battery::Charging); + mDischargingIconProducer.update(chargeLevel, Battery::Discharging); + mUi->chargeLevelLabel->setText(tr("Level: %1%").arg(chargeLevel)); +} + +void BatteryWatcherSettings::onChargeIconChanged() +{ + mUi->chargingIcon->setPixmap(mChargingIconProducer.mIcon.pixmap(mUi->chargingIcon->size())); + mUi->chargingLabel->setText(mChargingIconProducer.mIconName); +} + +void BatteryWatcherSettings::onDischargeIconChanged() +{ + mUi->dischargingIcon->setPixmap(mDischargingIconProducer.mIcon.pixmap(mUi->dischargingIcon->size())); + mUi->dischargingLabel->setText(mDischargingIconProducer.mIconName); +} diff --git a/config/batterywatchersettings.h b/config/batterywatchersettings.h new file mode 100644 index 0000000..a27ff12 --- /dev/null +++ b/config/batterywatchersettings.h @@ -0,0 +1,66 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef POWERLOWSETTINGS_H +#define POWERLOWSETTINGS_H + +#include +#include + +#include "../config/powermanagementsettings.h" +#include "../src/iconproducer.h" + +#include "helpers.h" + +namespace Ui { +class BatteryWatcherSettings; +} + +class BatteryWatcherSettings : public QWidget +{ + Q_OBJECT + +public: + explicit BatteryWatcherSettings(QWidget *parent = 0); + ~BatteryWatcherSettings(); + +public slots: + void loadSettings(); + +private slots: + void saveSettings(); + void updatePreview(); + void onChargeIconChanged(); + void onDischargeIconChanged(); + +private: + PowerManagementSettings mSettings; + Ui::BatteryWatcherSettings *mUi; + IconProducer mChargingIconProducer; + IconProducer mDischargingIconProducer; +}; + +#endif // POWERLOWSETTINGS_H diff --git a/config/batterywatchersettings.ui b/config/batterywatchersettings.ui new file mode 100644 index 0000000..c4ae1d0 --- /dev/null +++ b/config/batterywatchersettings.ui @@ -0,0 +1,249 @@ + + + BatteryWatcherSettings + + + + 0 + 0 + 428 + 414 + + + + Battery Watcher Settings + + + + + + + 0 + 0 + + + + E&nable Battery Watcher + + + true + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + When power is low then: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Warning: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + seconds + + + 500 + + + + + + + Level is low at: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + % + + + + + + + Show icon: + + + + + + + + + + + + + + Use icons from theme: + + + + + + + + + + + + + + Preview + + + + + + 100 + + + Qt::Horizontal + + + + + + + + 50 + 50 + + + + + + + Qt::AlignCenter + + + + + + + + 9 + + + + Charging + + + Qt::AlignCenter + + + + + + + + 50 + 50 + + + + + + + Qt::AlignCenter + + + + + + + + + + + + + + + 9 + + + + Discharging + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 15 + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 25 + + + + + + + + + + + + diff --git a/config/helpers.cpp b/config/helpers.cpp new file mode 100644 index 0000000..d8ed276 --- /dev/null +++ b/config/helpers.cpp @@ -0,0 +1,60 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include + +#include + +#include "helpers.h" + +void fillComboBox(QComboBox* comboBox) +{ + comboBox->clear(); + comboBox->addItem(QObject::tr("Nothing"), -1); + comboBox->addItem(QObject::tr("Lock screen"), -2); // FIXME + comboBox->addItem(QObject::tr("Suspend"), LxQt::Power::PowerSuspend); + comboBox->addItem(QObject::tr("Hibernate"), LxQt::Power::PowerHibernate); + comboBox->addItem(QObject::tr("Shutdown"), LxQt::Power::PowerShutdown); +} + +void setComboBoxToValue(QComboBox* comboBox, int value) +{ + for (int index = 0; index < comboBox->count(); index++) + { + if (value == comboBox->itemData(index).toInt()) + { + comboBox->setCurrentIndex(index); + return; + } + } + + comboBox->setCurrentIndex(0); +} + +int currentValue(QComboBox *comboBox) +{ + return comboBox->itemData(comboBox->currentIndex()).toInt(); +} + diff --git a/config/helpers.h b/config/helpers.h new file mode 100644 index 0000000..59e2d2c --- /dev/null +++ b/config/helpers.h @@ -0,0 +1,19 @@ +/* + * File: Settings.h + * Author: christian + * + * Created on 15. februar 2014, 11:44 + */ +#ifndef POWER_MANAGEMENT_SETTINGS_H +#define POWER_MANAGEMENT_SETTINGS_H + +#include + +void fillComboBox(QComboBox* comboBox); + +void setComboBoxToValue(QComboBox* comboBox, int value); + +int currentValue(QComboBox *comboBox); + +#endif // POWER_MANAGEMENT_SETTINGS_H + diff --git a/config/icons/laptop-lid.svg b/config/icons/laptop-lid.svg new file mode 100644 index 0000000..e66164d --- /dev/null +++ b/config/icons/laptop-lid.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/config/idlenesswatchersettings.cpp b/config/idlenesswatchersettings.cpp new file mode 100644 index 0000000..74964cb --- /dev/null +++ b/config/idlenesswatchersettings.cpp @@ -0,0 +1,118 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include + +#include "idlenesswatchersettings.h" +#include "ui_idlenesswatchersettings.h" +#include "helpers.h" + +IdlenessWatcherSettings::IdlenessWatcherSettings(QWidget *parent) : + QWidget(parent), + mSettings(), + mUi(new Ui::IdlenessWatcherSettings) +{ + mUi->setupUi(this); + fillComboBox(mUi->idleActionComboBox); + connect(mUi->idlenessWatcherGroupBox, SIGNAL(clicked()), SLOT(saveSettings())); + connect(mUi->idleActionComboBox, SIGNAL(activated(int)), SLOT(saveSettings())); + connect(mUi->idleTimeMinutesSpinBox, SIGNAL(editingFinished()), SLOT(saveSettings())); + connect(mUi->idleTimeMinutesSpinBox, SIGNAL(valueChanged(int)), SLOT(minutesChanged(int))); + connect(mUi->idleTimeSecondsSpinBox, SIGNAL(valueChanged(int)), SLOT(secondsChanged(int))); + + connect(mUi->idleTimeSecondsSpinBox, SIGNAL(editingFinished()), SLOT(saveSettings())); +} + +IdlenessWatcherSettings::~IdlenessWatcherSettings() +{ + delete mUi; +} + +void IdlenessWatcherSettings::loadSettings() +{ + + mUi->idlenessWatcherGroupBox->setChecked(mSettings.isIdlenessWatcherEnabled()); + setComboBoxToValue(mUi->idleActionComboBox, mSettings.getIdlenessAction()); + + int idlenessTimeSeconds = mSettings.getIdlenessTimeSecs(); + if (idlenessTimeSeconds < 5) idlenessTimeSeconds = 5; + int idlenessTimeMinutes = idlenessTimeSeconds/60; + idlenessTimeSeconds = idlenessTimeSeconds % 60; + mUi->idleTimeMinutesSpinBox->setValue(idlenessTimeMinutes); + mUi->idleTimeSecondsSpinBox->setValue(idlenessTimeSeconds); +} + +void IdlenessWatcherSettings::minutesChanged(int newVal) +{ + if (newVal < 1 && mUi->idleTimeSecondsSpinBox->value() < 5) + { + mUi->idleTimeSecondsSpinBox->setValue(5); + } +} + +void IdlenessWatcherSettings::secondsChanged(int newVal) +{ + if (newVal > 59) + { + mUi->idleTimeSecondsSpinBox->setValue(0); + mUi->idleTimeMinutesSpinBox->setValue(mUi->idleTimeMinutesSpinBox->value() + 1); + } + + else if (newVal < 0) + { + if (mUi->idleTimeMinutesSpinBox->value() < 1) + { + mUi->idleTimeMinutesSpinBox->setValue(0); + mUi->idleTimeSecondsSpinBox->setValue(0); + } + else + { + mUi->idleTimeMinutesSpinBox->setValue(mUi->idleTimeMinutesSpinBox->value() - 1); + mUi->idleTimeSecondsSpinBox->setValue(59); + } + } +} + + + +void IdlenessWatcherSettings::saveSettings() +{ + + mSettings.setIdlenessWatcherEnabled(mUi->idlenessWatcherGroupBox->isChecked()); + mSettings.setIdlenessAction(currentValue(mUi->idleActionComboBox)); + + int idleTimeSecs = 60*mUi->idleTimeMinutesSpinBox->value() + mUi->idleTimeSecondsSpinBox->value(); + if (idleTimeSecs < 5) + { + idleTimeSecs = 5; + mUi->idleTimeMinutesSpinBox->setValue(0); + mUi->idleTimeSecondsSpinBox->setValue(5); + } + + mSettings.setIdlenessTimeSecs(idleTimeSecs); +} diff --git a/config/idlenesswatchersettings.h b/config/idlenesswatchersettings.h new file mode 100644 index 0000000..84af8ca --- /dev/null +++ b/config/idlenesswatchersettings.h @@ -0,0 +1,60 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef IDLE_SETTINGS_H +#define IDLE_SETTINGS_H + +#include +#include + +#include "powermanagementsettings.h" + +namespace Ui { + class IdlenessWatcherSettings; +} + +class IdlenessWatcherSettings : public QWidget +{ + Q_OBJECT + +public: + explicit IdlenessWatcherSettings(QWidget *parent = 0); + ~IdlenessWatcherSettings(); + +public slots: + void loadSettings(); + +private slots: + void minutesChanged(int newVal); + void secondsChanged(int newVal); + void saveSettings(); + +private: + PowerManagementSettings mSettings; + Ui::IdlenessWatcherSettings *mUi; +}; + +#endif // IDLE_SETTINGS_H diff --git a/config/idlenesswatchersettings.ui b/config/idlenesswatchersettings.ui new file mode 100644 index 0000000..bc3a225 --- /dev/null +++ b/config/idlenesswatchersettings.ui @@ -0,0 +1,103 @@ + + + IdlenessWatcherSettings + + + + 0 + 0 + 309 + 177 + + + + Form + + + + + + Enab&le Idleness Watcher + + + true + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 0 + 0 + + + + When idle then: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + 0 + + + + IIdle time: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + minutes + + + 999 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + seconds + + + -1 + + + 60 + + + + + + + + + + + diff --git a/config/lidwatchersettings.cpp b/config/lidwatchersettings.cpp new file mode 100644 index 0000000..e25be49 --- /dev/null +++ b/config/lidwatchersettings.cpp @@ -0,0 +1,83 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include + +#include "lidwatchersettings.h" +#include "ui_lidwatchersettings.h" +#include "helpers.h" + +LidWatcherSettings::LidWatcherSettings(QWidget *parent) : + QWidget(parent), + mSettings(), + mUi(new Ui::LidWatcherSettings) +{ + mUi->setupUi(this); + + fillComboBox(mUi->onBatteryActionComboBox); + fillComboBox(mUi->onAcActionComboBox); + fillComboBox(mUi->extMonOnBatteryActionComboBox); + fillComboBox(mUi->extMonOnAcActionComboBox); + + connect(mUi->lidWatcherSettingsGroupBox, SIGNAL(clicked()), this, SLOT(saveSettings())); + connect(mUi->onBatteryActionComboBox, SIGNAL(activated(int)), this, SLOT(saveSettings())); + connect(mUi->onAcActionComboBox, SIGNAL(activated(int)), this, SLOT(saveSettings())); + connect(mUi->extMonOnBatteryActionComboBox, SIGNAL(activated(int)), this, SLOT(saveSettings())); + connect(mUi->extMonOnAcActionComboBox, SIGNAL(activated(int)), this, SLOT(saveSettings())); + connect(mUi->extMonGroupBox, SIGNAL(clicked()), this, SLOT(saveSettings())); +} + +LidWatcherSettings::~LidWatcherSettings() +{ + delete mUi; +} + +void LidWatcherSettings::loadSettings() +{ + mUi->lidWatcherSettingsGroupBox->setChecked(mSettings.isLidWatcherEnabled()); + + setComboBoxToValue(mUi->onBatteryActionComboBox, mSettings.getLidClosedAction()); + setComboBoxToValue(mUi->onAcActionComboBox, mSettings.getLidClosedAcAction()); + + mUi->extMonGroupBox->setChecked(mSettings.isEnableExtMonLidClosedActions()); + setComboBoxToValue(mUi->extMonOnBatteryActionComboBox, mSettings.getLidClosedExtMonAction()); + setComboBoxToValue(mUi->extMonOnAcActionComboBox, mSettings.getLidClosedExtMonAcAction()); + +} + +void LidWatcherSettings::saveSettings() +{ + mSettings.setLidWatcherEnabled(mUi->lidWatcherSettingsGroupBox->isChecked()); + + mSettings.setLidClosedAction(currentValue(mUi->onBatteryActionComboBox)); + mSettings.setLidClosedAcAction(currentValue(mUi->onAcActionComboBox)); + + mSettings.setEnableExtMonLidClosedActions(mUi->extMonGroupBox->isChecked()); + mSettings.setLidClosedExtMonAction(currentValue(mUi->extMonOnBatteryActionComboBox)); + mSettings.setLidClosedExtMonAcAction(currentValue(mUi->extMonOnAcActionComboBox)); +} diff --git a/config/lidwatchersettings.h b/config/lidwatchersettings.h new file mode 100644 index 0000000..47c9212 --- /dev/null +++ b/config/lidwatchersettings.h @@ -0,0 +1,58 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef LIDSETTINGS_H +#define LIDSETTINGS_H + +#include +#include + +#include "powermanagementsettings.h" + +namespace Ui { +class LidWatcherSettings; +} + +class LidWatcherSettings : public QWidget +{ + Q_OBJECT + +public: + explicit LidWatcherSettings(QWidget *parent = 0); + ~LidWatcherSettings(); + +public slots: + void loadSettings(); + +private slots: + void saveSettings(); + +private: + PowerManagementSettings mSettings; + Ui::LidWatcherSettings *mUi; +}; + +#endif // LIDSETTINGS_H diff --git a/config/lidwatchersettings.ui b/config/lidwatchersettings.ui new file mode 100644 index 0000000..623ecbe --- /dev/null +++ b/config/lidwatchersettings.ui @@ -0,0 +1,152 @@ + + + LidWatcherSettings + + + + 0 + 0 + 276 + 289 + + + + Form + + + QGroupBox QGroupBox { +border: none; +padding-top: 30px; +} + + + + + + Enable &Lid Watcher + + + true + + + true + + + + + + + + + Action when lid is closed + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + On Battery + + + + + + + + Nothing + + + + + Suspend + + + + + Hibernate + + + + + Shut down + + + + + + + + On AC + + + + + + + + + + + + + When &using external monitor + + + true + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 0 + 0 + + + + On Battery + + + + + + + + + + On Ac + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + diff --git a/config/lxqt-config-powermanagement.desktop.in b/config/lxqt-config-powermanagement.desktop.in new file mode 100644 index 0000000..7a3d720 --- /dev/null +++ b/config/lxqt-config-powermanagement.desktop.in @@ -0,0 +1,10 @@ +[Desktop Entry] +Type=Application +Name=Power Management +GenericName=Power Management Settings +Exec=lxqt-config-powermanagement +Icon=preferences-system-power-management +Categories=Settings;DesktopSettings;Qt;LXQt; +OnlyShowIn=LXQt;LXDE; + +#TRANSLATIONS_DIR=translations diff --git a/config/main.cpp b/config/main.cpp new file mode 100644 index 0000000..8ce09d3 --- /dev/null +++ b/config/main.cpp @@ -0,0 +1,42 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + LxQt::SingleApplication a(argc, argv); + + MainWindow mainWindow; + mainWindow.setWindowIcon(QIcon::fromTheme("preferences-system-power-management")); + mainWindow.show(); + a.setActivationWindow(&mainWindow); + + return a.exec(); +} diff --git a/config/mainwindow.cpp b/config/mainwindow.cpp new file mode 100644 index 0000000..f4ce181 --- /dev/null +++ b/config/mainwindow.cpp @@ -0,0 +1,49 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "mainwindow.h" +#include "lidwatchersettings.h" +#include "batterywatchersettings.h" +#include "idlenesswatchersettings.h" + +MainWindow::MainWindow(QWidget *parent) : + LxQt::ConfigDialog(tr("LXQt Powermanagement Configuration"), new PowerManagementSettings(parent)) +{ + BatteryWatcherSettings* batteryWatcherSettings = new BatteryWatcherSettings(this); + addPage(batteryWatcherSettings, tr("Battery"), "battery"); + connect(this, SIGNAL(reset()), batteryWatcherSettings, SLOT(loadSettings())); + + LidWatcherSettings *lidwatcherSettings = new LidWatcherSettings(this); + addPage(lidwatcherSettings, tr("Lid"), "laptop-lid"); + connect(this, SIGNAL(reset()), lidwatcherSettings, SLOT(loadSettings())); + + IdlenessWatcherSettings* idlenessWatcherSettings = new IdlenessWatcherSettings(this); + addPage(idlenessWatcherSettings, tr("idle"), (QStringList() << "user-idle" << "user-away")); + connect(this, SIGNAL(reset()), idlenessWatcherSettings, SLOT(loadSettings())); + + emit reset(); +} diff --git a/config/mainwindow.h b/config/mainwindow.h new file mode 100644 index 0000000..c660df2 --- /dev/null +++ b/config/mainwindow.h @@ -0,0 +1,40 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class MainWindow : public LxQt::ConfigDialog +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = 0); +}; + +#endif // MAINWINDOW_H diff --git a/config/powermanagementsettings.cpp b/config/powermanagementsettings.cpp new file mode 100644 index 0000000..aa34d84 --- /dev/null +++ b/config/powermanagementsettings.cpp @@ -0,0 +1,224 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include + +#include + +#include "powermanagementsettings.h" + +namespace PowerManagementSettingsConstants +{ + const QString RUN_CHECK_LEVEL = "runCheckLevel"; + const QString ENABLE_BATTERY_WATCHER_KEY = "enableBatteryWatcher"; + const QString ENABLE_LID_WATCHER_KEY = "enableLidWatcher"; + const QString ENABLE_IDLENESS_WATCHER_KEY = "enableIdlenessWatcher"; + const QString LID_CLOSED_ACTION_KEY = "lidClosedAction"; + const QString LID_CLOSED_AC_ACTION_KEY = "lidClosedAcAction"; + const QString LID_CLOSED_EXT_MON_ACTION_KEY = "lidClosedExtMonAction"; + const QString LID_CLOSED_EXT_MON_AC_ACTION_KEY = "lidClosedExtMonAcAction"; + const QString ENABLE_EXT_MON_LIDCLOSED_ACTIONS_KEY = "enableExtMonLidClosedActions"; + const QString POWER_LOW_ACTION_KEY = "powerLowAction"; + const QString POWER_LOW_WARNING_KEY = "powerLowWarning"; + const QString POWER_LOW_LEVEL_KEY = "powerLowLevel"; + const QString SHOW_ICON_KEY = "showIcon"; + const QString USE_THEME_ICONS_KEY = "useThemeIcons"; + const QString IDLENESS_ACTION_KEY = "idlenessAction"; + const QString IDLENESS_TIME_MINS_KEY = "idlenessTimeMins"; + const QString IDLENESS_TIME_SECS_KEY = "idlenessTimeSecs"; +} + +using namespace PowerManagementSettingsConstants; + +PowerManagementSettings::PowerManagementSettings(QObject* parent) : LxQt::Settings("lxqt-powermanagement") +{ +} + +PowerManagementSettings::~PowerManagementSettings() +{ +} + +int PowerManagementSettings::getRunCheckLevel() +{ + return value(RUN_CHECK_LEVEL, 0).toInt(); +} + +void PowerManagementSettings::setRunCheckLevel(int newLevel) +{ + setValue(RUN_CHECK_LEVEL, newLevel); +} + +bool PowerManagementSettings::isBatteryWatcherEnabled() +{ + return value(ENABLE_BATTERY_WATCHER_KEY, true).toBool(); +} + +void PowerManagementSettings::setBatteryWatcherEnabled(bool batteryWatcherEnabled) +{ + setValue(ENABLE_BATTERY_WATCHER_KEY, batteryWatcherEnabled); +} + +int PowerManagementSettings::getPowerLowAction() +{ + return value(POWER_LOW_ACTION_KEY, 0).toInt(); +} + +void PowerManagementSettings::setPowerLowAction(int powerLowAction) +{ + setValue(POWER_LOW_ACTION_KEY, powerLowAction); +} + +int PowerManagementSettings::getPowerLowLevel() +{ + return value(POWER_LOW_LEVEL_KEY, 5).toInt(); +} + +void PowerManagementSettings::setPowerLowLevel(int powerLowLevel) +{ + setValue(POWER_LOW_LEVEL_KEY, powerLowLevel); +} + +int PowerManagementSettings::getPowerLowWarningTime() +{ + return value(POWER_LOW_WARNING_KEY, 30).toInt(); +} + +void PowerManagementSettings::setPowerLowWarningTime(int powerLowWarningTime) +{ + setValue(POWER_LOW_WARNING_KEY, powerLowWarningTime); +} + +bool PowerManagementSettings::isShowIcon() +{ + return value(SHOW_ICON_KEY, true).toBool(); +} + +void PowerManagementSettings::setShowIcon(bool showIcon) +{ + setValue(SHOW_ICON_KEY, showIcon); +} + +bool PowerManagementSettings::isUseThemeIcons() +{ + return value(USE_THEME_ICONS_KEY, false).toBool(); +} + +void PowerManagementSettings::setUseThemeIcons(bool useThemeIcons) +{ + setValue(USE_THEME_ICONS_KEY, useThemeIcons); +} + +bool PowerManagementSettings::isLidWatcherEnabled() +{ + return value(ENABLE_LID_WATCHER_KEY, true).toBool(); +} + +void PowerManagementSettings::setLidWatcherEnabled(bool lidWatcherEnabled) +{ + setValue(ENABLE_LID_WATCHER_KEY, lidWatcherEnabled); +} + +int PowerManagementSettings::getLidClosedAcAction() +{ + return value(LID_CLOSED_AC_ACTION_KEY, 0).toInt(); +} + +void PowerManagementSettings::setLidClosedAcAction(int lidClosedAcAction) +{ + setValue(LID_CLOSED_AC_ACTION_KEY, lidClosedAcAction); +} + +int PowerManagementSettings::getLidClosedAction() +{ + return value(LID_CLOSED_ACTION_KEY, 0).toInt(); +} + +void PowerManagementSettings::setLidClosedAction(int lidClosedAction) +{ + setValue(LID_CLOSED_ACTION_KEY, lidClosedAction); +} + +int PowerManagementSettings::getLidClosedExtMonAcAction() +{ + return value(LID_CLOSED_EXT_MON_AC_ACTION_KEY, 0).toInt(); +} + +void PowerManagementSettings::setLidClosedExtMonAcAction(int lidClosedExtMonAcAction) +{ + setValue(LID_CLOSED_EXT_MON_AC_ACTION_KEY, lidClosedExtMonAcAction); +} + +int PowerManagementSettings::getLidClosedExtMonAction() +{ + return value(LID_CLOSED_EXT_MON_ACTION_KEY, 0).toInt(); +} + +void PowerManagementSettings::setLidClosedExtMonAction(int lidClosedExtMonAction) +{ + setValue(LID_CLOSED_EXT_MON_ACTION_KEY, lidClosedExtMonAction); +} + +bool PowerManagementSettings::isEnableExtMonLidClosedActions() +{ + return value(ENABLE_EXT_MON_LIDCLOSED_ACTIONS_KEY, 0).toBool(); +} + +void PowerManagementSettings::setEnableExtMonLidClosedActions(bool enableExtMonLidClosedActions) +{ + setValue(ENABLE_EXT_MON_LIDCLOSED_ACTIONS_KEY, enableExtMonLidClosedActions); +} + +int PowerManagementSettings::getIdlenessAction() +{ + return value(IDLENESS_ACTION_KEY, 0).toInt(); +} + +void PowerManagementSettings::setIdlenessAction(int idlenessAction) +{ + setValue(IDLENESS_ACTION_KEY, idlenessAction); +} + +int PowerManagementSettings::getIdlenessTimeSecs() +{ + return value(IDLENESS_TIME_SECS_KEY, 5).toInt(); +} + +void PowerManagementSettings::setIdlenessTimeSecs(int idlenessTimeSecs) +{ + setValue(IDLENESS_TIME_SECS_KEY, idlenessTimeSecs); +} + + +bool PowerManagementSettings::isIdlenessWatcherEnabled() +{ + return value(ENABLE_IDLENESS_WATCHER_KEY, false).toBool(); +} + +void PowerManagementSettings::setIdlenessWatcherEnabled(bool idlenessWatcherEnabled) +{ + setValue(ENABLE_IDLENESS_WATCHER_KEY, idlenessWatcherEnabled); +} + + diff --git a/config/powermanagementsettings.h b/config/powermanagementsettings.h new file mode 100644 index 0000000..73c69d5 --- /dev/null +++ b/config/powermanagementsettings.h @@ -0,0 +1,95 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef COMMON_H +#define COMMON_H + +#include +#include + +#include + +class PowerManagementSettings : public LxQt::Settings +{ + Q_OBJECT + +public: + PowerManagementSettings(QObject* parent = 0); + ~PowerManagementSettings(); + + int getRunCheckLevel(); + void setRunCheckLevel(int newLevel); + + bool isBatteryWatcherEnabled(); + void setBatteryWatcherEnabled(bool batteryWatcherEnabled); + + int getPowerLowAction(); + void setPowerLowAction(int powerLowAction); + + int getPowerLowLevel(); + void setPowerLowLevel(int powerLowLevel); + + int getPowerLowWarningTime(); + void setPowerLowWarningTime(int powerLowWarningTime); + + bool isShowIcon(); + void setShowIcon(bool showIcon); + + bool isUseThemeIcons(); + void setUseThemeIcons(bool useThemeIcons); + + + bool isLidWatcherEnabled(); + void setLidWatcherEnabled(bool lidWatcherEnabled); + + int getLidClosedAcAction(); + void setLidClosedAcAction(int lidClosedAcAction); + + int getLidClosedAction(); + void setLidClosedAction(int lidClosedAction); + + int getLidClosedExtMonAcAction(); + void setLidClosedExtMonAcAction(int lidClosedExtMonAcAction); + + int getLidClosedExtMonAction(); + void setLidClosedExtMonAction(int lidClosedExtMonAction); + + bool isEnableExtMonLidClosedActions(); + void setEnableExtMonLidClosedActions(bool enableExtMonLidClosedActions); + + int getIdlenessAction(); + void setIdlenessAction(int idlenessAction); + + int getIdlenessTimeSecs(); + void setIdlenessTimeSecs(int idlenessTimeSecs); + + bool isIdlenessWatcherEnabled(); + void setIdlenessWatcherEnabled(bool idlenessWatcherEnabled); +}; + + +#endif // COMMON_H diff --git a/config/translations/lxqt-config-powermanagement.ts b/config/translations/lxqt-config-powermanagement.ts new file mode 100644 index 0000000..52accfe --- /dev/null +++ b/config/translations/lxqt-config-powermanagement.ts @@ -0,0 +1,195 @@ + + + + + BatteryWatcherSettings + + + Battery Watcher Settings + + + + + E&nable Battery Watcher + + + + + Warning: + + + + + seconds + + + + + Level is low at: + + + + + % + + + + + Use icons from theme: + + + + + When power is low then: + + + + + Show icon: + + + + + IdlenessWatcherSettings + + + Form + + + + + Enab&le Idleness Watcher + + + + + When idle then: + + + + + IIdle time: + + + + + minutes + + + + + seconds + + + + + LidWatcherSettings + + + Form + + + + + Enable &Lid Watcher + + + + + Action when lid is closed + + + + + + On Battery + + + + + Nothing + + + + + Suspend + + + + + Hibernate + + + + + Shut down + + + + + On AC + + + + + When &using external monitor + + + + + On Ac + + + + + MainWindow + + + LXQt Powermanagement Configuration + + + + + Battery + + + + + Lid + + + + + idle + + + + + QObject + + + Nothing + + + + + Lock screen + + + + + Suspend + + + + + Hibernate + + + + + Shutdown + + + + diff --git a/config/translations/lxqt-config-powermanagement_ja.desktop b/config/translations/lxqt-config-powermanagement_ja.desktop new file mode 100644 index 0000000..76b29a5 --- /dev/null +++ b/config/translations/lxqt-config-powermanagement_ja.desktop @@ -0,0 +1,5 @@ +# Translations +GenericName[ja]=電源管理の設定 +Name[ja]=電源管理 + +#TRANSLATIONS_DIR=translations diff --git a/config/translations/lxqt-config-powermanagement_ja.ts b/config/translations/lxqt-config-powermanagement_ja.ts new file mode 100644 index 0000000..16810aa --- /dev/null +++ b/config/translations/lxqt-config-powermanagement_ja.ts @@ -0,0 +1,195 @@ + + + + + BatteryWatcherSettings + + + Battery Watcher Settings + バッテリーの監視設定 + + + + E&nable Battery Watcher + バッテリー監視を有効にする(&N) + + + + Warning: + 警告: + + + + seconds + + + + + Level is low at: + 低いと判断するレベル: + + + + % + % + + + + Use icons from theme: + テーマのアイコンを用いる: + + + + When power is low then: + 電源が低いときには: + + + + Show icon: + アイコンを表示: + + + + IdlenessWatcherSettings + + + Form + フォーム + + + + Enab&le Idleness Watcher + アイドル状態の監視 + + + + When idle then: + アイドル時には: + + + + IIdle time: + アイドル状態の時間 + + + + minutes + + + + + seconds + + + + + LidWatcherSettings + + + Form + フォーム + + + + Enable &Lid Watcher + フタの監視を有効にする + + + + Action when lid is closed + フタが閉じていたときの動作 + + + + + On Battery + バッテリー動作時 + + + + Nothing + 何もしない + + + + Suspend + サスペンド + + + + Hibernate + ハイバネート + + + + Shut down + シャットダウン + + + + On AC + AC電源時 + + + + When &using external monitor + 外部モニター使用時 + + + + On Ac + AC電源時 + + + + MainWindow + + + LXQt Powermanagement Configuration + LXQt電源管理の設定 + + + + Battery + バッテリー + + + + Lid + フタ + + + + idle + アイドル + + + + QObject + + + Nothing + 何もしない + + + + Lock screen + スクリーンをロック + + + + Suspend + サスペンド + + + + Hibernate + ハイバネート + + + + Shutdown + シャットダウン + + + diff --git a/config/translations/lxqt-config-powermanagement_pt.desktop b/config/translations/lxqt-config-powermanagement_pt.desktop new file mode 100644 index 0000000..37af097 --- /dev/null +++ b/config/translations/lxqt-config-powermanagement_pt.desktop @@ -0,0 +1,2 @@ +Name[pt]=Gestão de energia +GenericName[pt]=Definições do gestor de energia diff --git a/config/translations/lxqt-config-powermanagement_pt.ts b/config/translations/lxqt-config-powermanagement_pt.ts new file mode 100644 index 0000000..c825f7b --- /dev/null +++ b/config/translations/lxqt-config-powermanagement_pt.ts @@ -0,0 +1,195 @@ + + + + + BatteryWatcherSettings + + + Battery Watcher Settings + Definições do monitorizador de energia + + + + E&nable Battery Watcher + &Ativar monitorizador de energia + + + + Warning: + Aviso: + + + + seconds + segundos + + + + Level is low at: + O nível está baixo em: + + + + % + % + + + + Use icons from theme: + Utilizar ícones do tema: + + + + When power is low then: + Se a energia estiver baixa: + + + + Show icon: + Mostrar ícone: + + + + IdlenessWatcherSettings + + + Form + Formulário + + + + Enab&le Idleness Watcher + Ativar monitori&zador de inatividade + + + + When idle then: + Se existir inatividade: + + + + IIdle time: + Tempo para inatividade: + + + + minutes + minutos + + + + seconds + segundos + + + + LidWatcherSettings + + + Form + Formulário + + + + Enable &Lid Watcher + Ativar monitori&zador da tampa + + + + Action when lid is closed + Ação ao fechar a tampa + + + + + On Battery + Com bateria + + + + Nothing + Nada fazer + + + + Suspend + Suspender + + + + Hibernate + Hibernar + + + + Shut down + Desligar + + + + On AC + Com corrente + + + + When &using external monitor + Ao &utilizar monitor externo + + + + On Ac + Com corrente + + + + MainWindow + + + LXQt Powermanagement Configuration + Configuração do gestor de energia do LxQt + + + + Battery + Bateria + + + + Lid + Tampa + + + + idle + inatividade + + + + QObject + + + Nothing + Nada fazer + + + + Lock screen + Bloquear ecrã + + + + Suspend + Suspender + + + + Hibernate + Hibernar + + + + Shutdown + Desligar + + + diff --git a/config/translations/lxqt-config-powermanagement_ru.desktop b/config/translations/lxqt-config-powermanagement_ru.desktop new file mode 100644 index 0000000..fee8d06 --- /dev/null +++ b/config/translations/lxqt-config-powermanagement_ru.desktop @@ -0,0 +1,3 @@ +# Translations +GenericName[ru]=Настройки управления энергопотреблением +Name[ru]=Управление энергопотреблением \ No newline at end of file diff --git a/config/translations/lxqt-config-powermanagement_ru.ts b/config/translations/lxqt-config-powermanagement_ru.ts new file mode 100644 index 0000000..cafcaae --- /dev/null +++ b/config/translations/lxqt-config-powermanagement_ru.ts @@ -0,0 +1,195 @@ + + + + + BatteryWatcherSettings + + + Battery Watcher Settings + Настройки наблюдения за батареей + + + + E&nable Battery Watcher + &Разрешить наблюдение за батареей + + + + Warning: + Предупреждение: + + + + seconds + секунд + + + + Level is low at: + Низкий уровень при: + + + + % + % + + + + Use icons from theme: + Использовать значки из темы: + + + + When power is low then: + При низком заряде: + + + + Show icon: + Показывать значок: + + + + IdlenessWatcherSettings + + + Form + + + + + Enab&le Idleness Watcher + Включить наблюдение за простоем + + + + When idle then: + При простое: + + + + IIdle time: + Время простоя: + + + + minutes + минут + + + + seconds + секунд + + + + LidWatcherSettings + + + Form + + + + + Enable &Lid Watcher + Включить наблюдение за крышкой + + + + Action when lid is closed + Действие при закрытии крышки + + + + + On Battery + От батареи + + + + Nothing + Ничего + + + + Suspend + Ждущий режим + + + + Hibernate + Спящий режим + + + + Shut down + Выключить + + + + On AC + От сети + + + + When &using external monitor + При использовании внешнего монитора + + + + On Ac + От сети + + + + MainWindow + + + LXQt Powermanagement Configuration + Настройка энергопотребления LXQt + + + + Battery + Батарея + + + + Lid + Крышка + + + + idle + бездействие + + + + QObject + + + Nothing + Ничего + + + + Lock screen + Блокирвать экран + + + + Suspend + Ждущий режим + + + + Hibernate + Спящий режим + + + + Shutdown + Выключить компьютер + + + diff --git a/config/translations/lxqt-config-powermanagement_ru_RU.desktop b/config/translations/lxqt-config-powermanagement_ru_RU.desktop new file mode 100644 index 0000000..24ab6c4 --- /dev/null +++ b/config/translations/lxqt-config-powermanagement_ru_RU.desktop @@ -0,0 +1,3 @@ +# Translations +GenericName[ru_RU]=Настройки управления энергопотреблением +Name[ru_RU]=Управление энергопотреблением \ No newline at end of file diff --git a/config/translations/lxqt-config-powermanagement_ru_RU.ts b/config/translations/lxqt-config-powermanagement_ru_RU.ts new file mode 100644 index 0000000..1ed0b44 --- /dev/null +++ b/config/translations/lxqt-config-powermanagement_ru_RU.ts @@ -0,0 +1,195 @@ + + + + + BatteryWatcherSettings + + + Battery Watcher Settings + Настройки наблюдения за батареей + + + + E&nable Battery Watcher + &Разрешить наблюдение за батареей + + + + Warning: + Предупреждение: + + + + seconds + секунд + + + + Level is low at: + Низкий уровень при: + + + + % + % + + + + Use icons from theme: + Использовать значки из темы: + + + + When power is low then: + При низком заряде: + + + + Show icon: + Показывать значок: + + + + IdlenessWatcherSettings + + + Form + + + + + Enab&le Idleness Watcher + Включить наблюдение за простоем + + + + When idle then: + При простое: + + + + IIdle time: + Время простоя: + + + + minutes + минут + + + + seconds + секунд + + + + LidWatcherSettings + + + Form + + + + + Enable &Lid Watcher + Включить наблюдение за крышкой + + + + Action when lid is closed + Действие при закрытии крышки + + + + + On Battery + От батареи + + + + Nothing + Ничего + + + + Suspend + Ждущий режим + + + + Hibernate + Спящий режим + + + + Shut down + Выключить + + + + On AC + От сети + + + + When &using external monitor + При использовании внешнего монитора + + + + On Ac + От сети + + + + MainWindow + + + LXQt Powermanagement Configuration + Настройка энергопотребления LXQt + + + + Battery + Батарея + + + + Lid + Крышка + + + + idle + бездействие + + + + QObject + + + Nothing + Ничего + + + + Lock screen + Блокирвать экран + + + + Suspend + Ждущий режим + + + + Hibernate + Спящий режим + + + + Shutdown + Выключить компьютер + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..26ace97 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,135 @@ +project(lxqt-powermanagement) + +set(QTX_LIBRARIES Qt5::Widgets Qt5::DBus Qt5::Svg Qt5::X11Extras) + +set(lxqt-powermanagement_MOCS + watcher.h + battery.h + batterywatcher.h + batteryinfoframe.h + batteryinfodialog.h + idlenesswatcher.h + lid.h + lidwatcher.h + powermanagementd.h + trayicon.h + iconproducer.h + ../config/powermanagementsettings.h +) + +set(lxqt-powermanagement_SRCS + watcher.cpp + battery.cpp + batteryinfoframe.cpp + batteryinfodialog.cpp + batterywatcher.cpp + idlenesswatcher.cpp + lid.cpp + lidwatcher.cpp + main.cpp + powermanagementd.cpp + trayicon.cpp + iconproducer.cpp + x11helper.cpp + ../config/powermanagementsettings.cpp +) + +set(lxqt-powermanagement_UIS + batteryinfoframe.ui + batteryinfodialog.ui +) + +set(DESKTOP_FILES_IN + lxqt-powermanagement.desktop.in +) + +qt5_wrap_ui( UIS ${lxqt-powermanagement_UIS}) +qt5_add_dbus_adaptor(lxqt-powermanagement_SRCS + org.freedesktop.ScreenSaver.xml + idlenesswatcher.h + IdlenessWatcher +) + +lxqt_translate_ts(QM_FILES + UPDATE_TRANSLATIONS ${UPDATE_TRANSLATIONS} + SOURCES + ${lxqt-powermanagement_SRCS} + ${lxqt-powermanagement_UIS} + ${lxqt-powermanagement_MOCS} + INSTALL_DIR + ${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME} +) + +lxqt_app_translation_loader(lxqt-powermanagement_QM_LOADER ${PROJECT_NAME}) + +# XCB stuff (TODO: move into findXCB) +find_package(PkgConfig) + +pkg_check_modules(PKG_XCB xcb) +find_path(XCB_INCLUDE_DIR xcb/xcb.h + ${PKG_XCB_INCLUDE_DIRS} +) +find_library(XCB_LIBRARY NAMES xcb + PATHS + ${PKG_XCB_LIBRARY_DIRS} +) + +pkg_check_modules(PKG_X11_XCB x11-xcb) +find_path(X11_XCB_INCLUDE_DIR X11/Xlib-xcb.h + ${PKG_X11_XCB_INCLUDE_DIRS} +) +find_library(X11_XCB_LIBRARY NAMES X11-xcb + PATHS + ${PKG_X11_XCB_LIBRARY_DIRS} +) + +pkg_check_modules(PKG_XCB_SCREENSAVER xcb-screensaver) +find_path(XCB_SCREENSAVER_INCLUDE_DIR xcb/screensaver.h + ${PKG_XCB_SCREENSAVER_INCLUDE_DIRS} +) +find_library(XCB_SCREENSAVER_LIBRARY NAMES xcb-screensaver + PATHS + ${PKG_XCB_SCREENSAVER_LIBRARY_DIRS} +) + +pkg_check_modules(PKG_XCB_DPMS xcb-dpms) +find_path(XCB_DPMS_INCLUDE_DIR xcb/dpms.h + ${PKG_XCB_SCREENSAVER_INCLUDE_DIRS} +) +find_library(XCB_DPMS_LIBRARY NAMES xcb-dpms + PATHS + ${PKG_XCB_DPMS_LIBRARY_DIRS} +) + + +include_directories( + "${CMAKE_CURRENT_BINARY_DIR}" + ${Qt5Gui_PRIVATE_INCLUDE_DIRS} + ${XCB_INCLUDE_DIR} + ${X11_XCB_INCLUDE_DIR} + ${QTXDG_INCLUDE_DIRS} + ${XCB_SCREENSAVER_INCLUDE_DIR} + ${XCB_DPMS_INCLUDE_DIR} +) + +add_executable(lxqt-powermanagement + ${lxqt-powermanagement_SRCS} + ${UIS} + ${RSCS} + ${QM_FILES} + ${lxqt-powermanagement_QM_LOADER} + ${DESKTOP_FILES} +) + +target_link_libraries(lxqt-powermanagement + ${LXQT_LIBRARIES} + ${QTXDG_LIBRARY} + ${QTX_LIBRARIES} + ${XCB_LIBRARY} + ${XCB_SCREENSAVER_LIBRARY} + ${XCB_DPMS_LIBRARY} + ${X11_XCB_LIBRARY} +) + +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) +install(FILES ${DESKTOP_FILES} DESTINATION share/applications) diff --git a/src/battery.cpp b/src/battery.cpp new file mode 100644 index 0000000..22f8b08 --- /dev/null +++ b/src/battery.cpp @@ -0,0 +1,177 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2011 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "battery.h" +#include "../config/powermanagementsettings.h" + +#define UPOWER_SERVICE "org.freedesktop.UPower" +#define UPOWER_PATH "/org/freedesktop/UPower" +#define UPOWER_INTERFACE "org.freedesktop.UPower" +#define DEVICE_INTERFACE "org.freedesktop.UPower.Device" +#define PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties" + +QList Battery::batteries() +{ + QList result; + QDBusInterface uPowerInterface(UPOWER_SERVICE, UPOWER_PATH, UPOWER_SERVICE, QDBusConnection::systemBus()); + + QDBusReply > reply = uPowerInterface.call("EnumerateDevices"); + foreach (QDBusObjectPath objectPath, reply.value()) + { + QDBusInterface *deviceInterface = new QDBusInterface(UPOWER_SERVICE, objectPath.path(), DEVICE_INTERFACE, QDBusConnection::systemBus()); + + if (deviceInterface->property("Type").toUInt() == 2 && + ( deviceInterface->property("PowerSupply").toBool() || // UPower < 0.9.16.3 wrongly reports this false for some laptop batteries + deviceInterface->property("NativePath").toString().contains("power_supply"))) // - hence this line + { + QDBusInterface *propertiesInterface = new QDBusInterface(UPOWER_SERVICE, objectPath.path(), PROPERTIES_INTERFACE, QDBusConnection::systemBus()); + + result << new Battery(deviceInterface, propertiesInterface); + } + else + { + delete deviceInterface; + } + } + + return result; + +} + +Battery::Battery(QDBusInterface *deviceInterface, QDBusInterface *propertiesInterface, QObject* parent) + : QObject(parent), mDeviceInterface(deviceInterface), mPropertiesInterface(propertiesInterface) +{ + if (! connect(mDeviceInterface, SIGNAL(Changed()), this, SLOT(uPowerBatteryChanged())) ) + { + qDebug() << "Could not connect to 'changed' signal, connecting to PropertiesChanged instead and hoping for the best"; + QDBusConnection::systemBus().connect(UPOWER_SERVICE, + mPropertiesInterface->path(), + PROPERTIES_INTERFACE, + "PropertiesChanged", + this, + SLOT(uPowerBatteryChanged())); + + connect(mPropertiesInterface, SIGNAL(PropertiesChanged()), this, SLOT(uPowerBatteryChanged())); + } + + uPowerBatteryChanged(); // To get all properties + + // We assume these do not change during the lifetime of a battery + energyFullDesign = mProperties.value("EnergyFullDesign").toDouble(); + model = mProperties.value("Model").toString(); + technology = technology2String(mProperties.value("Technology, 0").toInt()); +} + +Battery::~Battery() +{ +} + +void Battery::uPowerBatteryChanged() +{ + qDebug() << "uPowerBatteryChanged()"; + + QDBusReply reply = mPropertiesInterface->call("GetAll", "org.freedesktop.UPower.Device"); + mProperties = reply.value(); + + State newState = State(mProperties.value("State").toUInt()); + double newChargeLevel = mProperties.value("Percentage").toDouble(); + + if (newState == state && fabs(newChargeLevel - chargeLevel) < 0.5) + { + // In principle we may miss a change in 'EnergyFull' but we + // assume it's always accompanied by a change in 'Percentage' + return; + } + + chargeLevel = newChargeLevel; + state = newState; + + summary = state2String(state); + if (state == Battery::Charging || state == Battery::Discharging) + { + summary.append(QString(" (%1 %)").arg(chargeLevel, 0, 'f', 0)); + } + + + updated = QDateTime::fromTime_t(mProperties.value("UpdateTime").toULongLong()); + energyFull = mProperties.value("EnergyFull").toDouble(); + capacity = mProperties.value("Capacity").toDouble(); + energyNow = mProperties.value("Energy").toDouble(); + energyRate = mProperties.value("EnergyRate").toDouble(); + voltage = mProperties.value("Voltage").toDouble(); + + qDebug() << "battery now:" + << "summary" << summary + << "updated:" << updated + << "energyFull:" << energyFull + << "energyNow:" << energyNow + << "energyRate:" << energyRate + << "voltage:" << voltage; + + emit chargeStateChange(chargeLevel, state); + emit summaryChanged(summary); +} + + +QString Battery::state2String(State state) +{ + static QMap names; + if (names.isEmpty()) + { + names.insert(Unknown, tr("Unknown")); + names.insert(Charging, tr("Charging")); + names.insert(Discharging, tr("Discharging")); + names.insert(Empty, tr("Empty")); + names.insert(FullyCharged, tr("Fully charged")); + names.insert(PendingCharge, tr("Pending charge")); + names.insert(PendingDischarge, tr("Pending discharge")); + } + + return names.value(state); +} + +QString Battery::technology2String(int tech) +{ + switch (tech) + { + case 1: return tr("Lithium ion"); + case 2: return tr("Lithium polymer"); + case 3: return tr("Lithium iron phosphate"); + case 4: return tr("Lead acid"); + case 5: return tr("Nickel cadmium"); + case 6: return tr("Nickel metal hydride"); + default: return tr("Unknown"); + } +} diff --git a/src/battery.h b/src/battery.h new file mode 100644 index 0000000..111ad0e --- /dev/null +++ b/src/battery.h @@ -0,0 +1,92 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2011 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef BATTERY_H +#define BATTERY_H + +#include +#include +#include +#include + +class Battery : public QObject +{ + Q_OBJECT + +public: + // These must match the UPower api spec + // See http://upower.freedesktop.org/docs/Device.html#Device:State + enum State + { + Unknown = 0, + Charging, + Discharging, + Empty, + FullyCharged, + PendingCharge, + PendingDischarge + }; + + static QList batteries(); + + static QString state2String(State state); + static QString technology2String(int tech); + + + Battery(QDBusInterface *deviceInterface, QDBusInterface *propertiesInterface, QObject* parent = 0); + ~Battery(); + + // This data is all available in mProperties, but we keep it + // here also for easy access (properly converted) + QString summary; + QDateTime updated; + State state; + double energyFullDesign; + double energyFull; + double capacity; + double energyNow; + double energyRate; + QString model; + QString technology; + double voltage; + double chargeLevel; + // -- + + bool haveBattery(); + +signals: + void chargeStateChange(float newChargeLevel, Battery::State newState); + void summaryChanged(QString newSummary); + +private slots: + void uPowerBatteryChanged(); + +private: + QDBusInterface *mDeviceInterface; + QDBusInterface *mPropertiesInterface; + QVariantMap mProperties; +}; +#endif diff --git a/src/batteryinfodialog.cpp b/src/batteryinfodialog.cpp new file mode 100644 index 0000000..3cfff19 --- /dev/null +++ b/src/batteryinfodialog.cpp @@ -0,0 +1,44 @@ +#include "batteryinfodialog.h" +#include "ui_batteryinfodialog.h" + +#include +#include +#include + +BatteryInfoDialog::BatteryInfoDialog(QList batteries, QWidget *parent) : + QDialog(parent), + ui(new Ui::BatteryInfoDialog) +{ + ui->setupUi(this); + + setWindowTitle(tr("Battery Info")); + + if (batteries.size() == 1) + { + BatteryInfoFrame *batteryInfoFrame = new BatteryInfoFrame(batteries[0]); + ui->verticalLayout->insertWidget(0, batteryInfoFrame); + } + else + { + QTabWidget *tabWidget = new QTabWidget(this); + ui->verticalLayout->insertWidget(0, tabWidget); + foreach (Battery *battery, batteries) + { + BatteryInfoFrame *batteryInfoFrame = new BatteryInfoFrame(battery); + tabWidget->addTab(batteryInfoFrame, "BAT"); + } + } + +} + +BatteryInfoDialog::~BatteryInfoDialog() +{ + delete ui; +} + + +void BatteryInfoDialog::toggleShow() +{ + qDebug() << "toggleShow"; + isVisible() ? hide() : show(); +} diff --git a/src/batteryinfodialog.h b/src/batteryinfodialog.h new file mode 100644 index 0000000..168c3fe --- /dev/null +++ b/src/batteryinfodialog.h @@ -0,0 +1,29 @@ +#ifndef BATTERYINFODIALOG_H +#define BATTERYINFODIALOG_H + +#include "battery.h" +#include "batteryinfoframe.h" + +#include +#include + +namespace Ui { +class BatteryInfoDialog; +} + +class BatteryInfoDialog : public QDialog +{ + Q_OBJECT + +public: + explicit BatteryInfoDialog(QList batteries, QWidget *parent = 0); + ~BatteryInfoDialog(); + +public slots: + void toggleShow(); + +private: + Ui::BatteryInfoDialog *ui; +}; + +#endif // BATTERYINFODIALOG_H diff --git a/src/batteryinfodialog.ui b/src/batteryinfodialog.ui new file mode 100644 index 0000000..bfc14a1 --- /dev/null +++ b/src/batteryinfodialog.ui @@ -0,0 +1,64 @@ + + + BatteryInfoDialog + + + + 0 + 0 + 334 + 301 + + + + Dialog + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + BatteryInfoDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + BatteryInfoDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/batteryinfoframe.cpp b/src/batteryinfoframe.cpp new file mode 100644 index 0000000..339e10e --- /dev/null +++ b/src/batteryinfoframe.cpp @@ -0,0 +1,63 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#include +#include + +#include "batteryinfoframe.h" +#include "ui_batteryinfoframe.h" + +BatteryInfoFrame::BatteryInfoFrame(Battery *battery) : + QFrame(), + mBattery(battery), + mUi(new Ui::BatteryInfoFrame) +{ + mUi->setupUi(this); + + mUi->energyFullDesignValue->setText(QString("%1 Wh").arg(mBattery->energyFullDesign, 0, 'f', 2)); + mUi->modelValue->setText(mBattery->model); + mUi->technologyValue->setText(mBattery->technology); + + connect(mBattery, SIGNAL(chargeStateChange(float,Battery::State)), this, SLOT(onBatteryChanged())); + onBatteryChanged(); +} + +BatteryInfoFrame::~BatteryInfoFrame() +{ + delete mUi; +} + +void BatteryInfoFrame::onBatteryChanged() +{ + qDebug() << "BatteryInfoFrame.onBatteryChanged" << "updated:" << mBattery->updated; + + mUi->updatedValue->setText(mBattery->updated.toString("hh:mm:ss")); + mUi->stateValue->setText(Battery::state2String(mBattery->state)); + mUi->energyFullValue->setText(QString("%1 Wh (%2 %)").arg(mBattery->energyFull, 0, 'f', 2).arg(mBattery->capacity, 0, 'f', 1)); + mUi->energyValue->setText(QString("%1 Wh (%2 %)").arg(mBattery->energyNow, 0, 'f', 2).arg(mBattery->chargeLevel, 0, 'f', 1)); + mUi->energyRateValue->setText(QString("%1 W").arg(mBattery->energyRate, 0, 'f', 2)); + mUi->voltageValue->setText(QString("%1 V").arg(mBattery->voltage, 0, 'f', 2)); +} diff --git a/src/batteryinfoframe.h b/src/batteryinfoframe.h new file mode 100644 index 0000000..a00bdbc --- /dev/null +++ b/src/batteryinfoframe.h @@ -0,0 +1,54 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef BATTERYINFOFRAME_H +#define BATTERYINFOFRAME_H + +#include + +#include "battery.h" + +namespace Ui { +class BatteryInfoFrame; +} + +class BatteryInfoFrame : public QFrame +{ + Q_OBJECT + +public: + explicit BatteryInfoFrame(Battery* battery); + ~BatteryInfoFrame(); + +private slots: + void onBatteryChanged(); + +private: + Battery* mBattery; + Ui::BatteryInfoFrame *mUi; +}; + +#endif // BATTERYINFOFRAME_H diff --git a/src/batteryinfoframe.ui b/src/batteryinfoframe.ui new file mode 100644 index 0000000..b280712 --- /dev/null +++ b/src/batteryinfoframe.ui @@ -0,0 +1,180 @@ + + + BatteryInfoFrame + + + Power Management + + + + 12 + + + + + + 11 + + + + Updated: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + false + + + + 21:11:03 + + + + + + + State: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Charging + + + + + + + Energy Full, Design: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 73.26 Wh + + + + + + + Energy Full: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 64.58 Wh (88.2 %) + + + + + + + Energy Now: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 63.41 Wh (98.2 %) + + + + + + + Energy rate: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 15.11 W + + + + + + + Model: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + DELL 00 + + + + + + + Technology: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Lithium ion + + + + + + + Voltage: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 12.27 V + + + + + + + + diff --git a/src/batterywatcher.cpp b/src/batterywatcher.cpp new file mode 100644 index 0000000..9c9505d --- /dev/null +++ b/src/batterywatcher.cpp @@ -0,0 +1,173 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include +#include + +#include +#include +#include + +#include "batterywatcher.h" +#include "../config/powermanagementsettings.h" + +BatteryWatcher::BatteryWatcher(QObject *parent) : Watcher(parent) +{ + mBatteries = Battery::batteries(); + if (mBatteries.isEmpty()) + { + LxQt::Notification::notify(tr("No battery!"), + tr("LXQt could not find data about any battery - monitoring disabled"), + "lxqt-powermanagement"); + } + + foreach (Battery* battery, mBatteries) + { + connect(battery, SIGNAL(chargeStateChange(float,Battery::State)), this, SLOT(batteryChanged())); + } + + mBatteryInfoDialog = new BatteryInfoDialog(mBatteries); + + connect(&mSettings, SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); + connect(LxQt::Settings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(settingsChanged())); + + settingsChanged(); + batteryChanged(); +} + +BatteryWatcher::~BatteryWatcher() +{ +} + +void BatteryWatcher::batteryChanged() +{ + static QTime actionTime; + static LxQt::Notification *notification = 0; + + double totalEnergyFull = 0; + double totalEnergyNow = 0; + bool discharging = true; + double chargeLevel; + + + + foreach (Battery *battery, mBatteries) + { + totalEnergyFull += battery->energyFull; + totalEnergyNow += battery->energyNow; + discharging &= (battery->state == Battery::Discharging); // hmm... + } + + chargeLevel = 100*totalEnergyNow/totalEnergyFull; + + qDebug() << "BatteryChanged" + << "discharging:" << discharging + << "chargeLevel:" << chargeLevel + << "actionTime:" << actionTime; + + bool powerLowActionRequired = + discharging && + chargeLevel < mSettings.getPowerLowLevel() && + mSettings.getPowerLowAction() > 0; + + if (powerLowActionRequired) + { + if (actionTime.isNull()) + { + actionTime = QTime::currentTime().addMSecs(mSettings.getPowerLowWarningTime()*1000); + } + + if (notification == 0) + { + notification = new LxQt::Notification(tr("Power low!"), this); + notification->setTimeout(2000); + } + + int milliSecondsToAction = QTime::currentTime().msecsTo(actionTime); + + if (milliSecondsToAction > 0) + { + int secondsToAction = milliSecondsToAction/1000; + switch (mSettings.getPowerLowAction()) + { + case LxQt::Power::PowerSuspend: + notification->setBody(tr("Suspending in %1 seconds").arg(secondsToAction)); + break; + case LxQt::Power::PowerHibernate: + notification->setBody(tr("Hibernating in %1 seconds").arg(secondsToAction)); + break; + case LxQt::Power::PowerShutdown: + notification->setBody(tr("Shutting down in %1 seconds").arg(secondsToAction)); + break; + } + + notification->update(); + + QTimer::singleShot(200, this, SLOT(batteryChanged())); + } + else + { + doAction(mSettings.getPowerLowAction()); + } + } + else + { + if (!actionTime.isNull()) + { + actionTime = QTime(); + } + + if (notification) + { + delete notification; + notification = 0; + } + } +} + +void BatteryWatcher::settingsChanged() +{ + if (!mSettings.isShowIcon()) + { + while (!mTrayIcons.isEmpty()) + { + mTrayIcons.first()->hide(); + mTrayIcons.takeFirst()->deleteLater(); + } + } + else if (mTrayIcons.isEmpty()) + { + foreach (Battery *battery, mBatteries) + { + mTrayIcons.append(new TrayIcon(battery, this)); + connect(mTrayIcons.last(), SIGNAL(toggleShowInfo()), mBatteryInfoDialog, SLOT(toggleShow())); + mTrayIcons.last()->show(); + } + } +} + diff --git a/src/batterywatcher.h b/src/batterywatcher.h new file mode 100644 index 0000000..e22e39e --- /dev/null +++ b/src/batterywatcher.h @@ -0,0 +1,55 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef BATTERYWATCHER_H +#define BATTERYWATCHER_H + +#include "watcher.h" +#include "battery.h" +#include "trayicon.h" +#include "batteryinfodialog.h" +#include "../config/powermanagementsettings.h" + +class BatteryWatcher : public Watcher +{ + Q_OBJECT +public: + explicit BatteryWatcher(QObject *parent = 0); + virtual ~BatteryWatcher(); + +private slots: + void batteryChanged(); + void settingsChanged(); + +private: + QList mBatteries; + QList mTrayIcons; + + PowerManagementSettings mSettings; + BatteryInfoDialog *mBatteryInfoDialog; +}; + +#endif // BATTERYWATCHER_H diff --git a/src/iconproducer.cpp b/src/iconproducer.cpp new file mode 100644 index 0000000..a6873dd --- /dev/null +++ b/src/iconproducer.cpp @@ -0,0 +1,233 @@ +#include "iconproducer.h" +#include +#include +#include +#include +#include +#include + +IconProducer::IconProducer(Battery *battery, QObject *parent) : QObject(parent) +{ + connect(battery, SIGNAL(chargeStateChange(float,Battery::State)), this, SLOT(update(float,Battery::State))); + connect(&mSettings, SIGNAL(settingsChanged()), this, SLOT(update())); + + mChargeLevel = battery->chargeLevel; + mState = battery->state; + themeChanged(); +} + +IconProducer::IconProducer(QObject *parent): QObject(parent) +{ + themeChanged(); + update(); +} + + +void IconProducer::update(float newChargeLevel, Battery::State newState) +{ + mChargeLevel = newChargeLevel; + mState = newState; + + update(); +} + +void IconProducer::update() +{ + QString newIconName; + + if (mSettings.isUseThemeIcons()) + { + QMap *levelNameMap = (mState == Battery::Discharging ? &mLevelNameMapDischarging : &mLevelNameMapCharging); + foreach (float level, levelNameMap->keys()) + { + if (level >= mChargeLevel) + { + newIconName = levelNameMap->value(level); + break; + } + } + } + + if (mSettings.isUseThemeIcons() && newIconName == mIconName) + { + return; + } + + mIconName = newIconName; + + if (mSettings.isUseThemeIcons()) + { + mIcon = QIcon::fromTheme(mIconName); + } + else + { + mIcon = circleIcon(); + } + + emit iconChanged(); +} + +void IconProducer::themeChanged() +{ + /* + * We maintain specific charge-level-to-icon-name mappings for Oxygen and Awoken and + * asume all other themes adhere to the freedesktop standard. + * This is certainly not true, and as bug reports come in stating that + * this and that theme is not working we will probably have to add new + * mappings beside Oxygen and Awoken + */ + mLevelNameMapDischarging.clear(); + mLevelNameMapCharging.clear(); + + if (QIcon::themeName() == "oxygen") + { // Means: + mLevelNameMapDischarging[10] = "battery-low"; // Use 'battery-low' for levels up to 10 + mLevelNameMapDischarging[20] = "battery-caution"; // - 'battery-caution' for levels between 10 and 20 + mLevelNameMapDischarging[40] = "battery-040"; // - 'battery-040' for levels between 20 and 40, etc.. + mLevelNameMapDischarging[60] = "battery-060"; + mLevelNameMapDischarging[80] = "battery-080"; + mLevelNameMapDischarging[101] = "battery-100"; + mLevelNameMapCharging[10] = "battery-charging-low"; + mLevelNameMapCharging[20] = "battery-charging-caution"; + mLevelNameMapCharging[40] = "battery-charging-040"; + mLevelNameMapCharging[60] = "battery-charging-060"; + mLevelNameMapCharging[80] = "battery-charging-080"; + mLevelNameMapCharging[101] = "battery-charging"; + } + else if (QIcon::themeName().startsWith("AwOken")) // AwOken, AwOkenWhite, AwOkenDark + { + mLevelNameMapDischarging[5] = "battery-000"; + mLevelNameMapDischarging[30] = "battery-020"; + mLevelNameMapDischarging[50] = "battery-040"; + mLevelNameMapDischarging[70] = "battery-060"; + mLevelNameMapDischarging[95] = "battery-080"; + mLevelNameMapDischarging[101] = "battery-100"; + mLevelNameMapCharging[5] = "battery-000-charging"; + mLevelNameMapCharging[30] = "battery-020-charging"; + mLevelNameMapCharging[50] = "battery-040-charging"; + mLevelNameMapCharging[70] = "battery-060-charging"; + mLevelNameMapCharging[95] = "battery-080-charging"; + mLevelNameMapCharging[101] = "battery-100-charging"; + } + else // As default we fall back to the freedesktop scheme. + { + mLevelNameMapDischarging[3] = "battery-empty"; + mLevelNameMapDischarging[10] = "battery-caution"; + mLevelNameMapDischarging[50] = "battery-low"; + mLevelNameMapDischarging[90] = "battery-good"; + mLevelNameMapDischarging[101] = "battery-full"; + mLevelNameMapCharging[3] = "battery-empty"; + mLevelNameMapCharging[10] = "battery-caution-charging"; + mLevelNameMapCharging[50] = "battery-low-charging"; + mLevelNameMapCharging[90] = "battery-good-charging"; + mLevelNameMapCharging[101] = "battery-full-charging"; + } + + update(); +} + + + +QIcon& IconProducer::circleIcon() +{ + static QMap > cache; + + int chargeLevelAsInt = (int) (mChargeLevel + 0.49); + + if (! cache[mState].contains(chargeLevelAsInt)) + { + cache[mState][chargeLevelAsInt] = buildCircleIcon(mState, mChargeLevel); + } + + return cache[mState][chargeLevelAsInt]; +} + +QIcon IconProducer::buildCircleIcon(Battery::State state, double chargeLevel) +{ + static QString svg_template = + "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + " STATE_MARKER\n" + "\n" + ""; + + static QString filledCircle = ""; + static QString plus = ""; + static QString minus = ""; + static QString hollowCircle = ""; + + QString svg = svg_template; + + if (chargeLevel > 99.9) + { + chargeLevel = 99.9; + } + + double angle = M_PI_2 + 2*M_PI*chargeLevel/100; + double circle_endpoint_x = 80.0*cos(angle) + 100; + double circle_endpoint_y = -80.0*sin(angle) + 100; + + QString largeArgFlag = chargeLevel > 50 ? "1" : "0"; + QString sweepFlag = "0"; + + svg.replace(QString("END_X"), QString::number(circle_endpoint_x)); + svg.replace(QString("END_Y"), QString::number(circle_endpoint_y)); + svg.replace(QString("LARGE_ARC_FLAG"), largeArgFlag); + svg.replace(QString("SWEEP_FLAG"), sweepFlag); + + + switch (state) + { + case Battery::FullyCharged: svg.replace("STATE_MARKER", filledCircle); break; + case Battery::Charging: svg.replace("STATE_MARKER", plus); break; + case Battery::Discharging: svg.replace("STATE_MARKER", minus); break; + default: svg.replace("STATE_MARKER", hollowCircle); + } + + if (state != Battery::FullyCharged && state != Battery::Charging && chargeLevel < mSettings.getPowerLowLevel() + 30) + { + if (chargeLevel <= mSettings.getPowerLowLevel() + 10) + { + svg.replace("RED_OPACITY", "1"); + } + else + { + svg.replace("RED_OPACITY", QString::number((mSettings.getPowerLowLevel() + 30 - chargeLevel)/20)); + } + } + else + { + svg.replace("RED_OPACITY", "0"); + } + + qDebug() << svg; + + // Paint the svg on a pixmap and create an icon from that. + QSvgRenderer render(svg.toLatin1()); + QPixmap pixmap(render.defaultSize()); + pixmap.fill(QColor(0,0,0,0)); + QPainter painter(&pixmap); + render.render(&painter); + return QIcon(pixmap); + +} + diff --git a/src/iconproducer.h b/src/iconproducer.h new file mode 100644 index 0000000..1e45f18 --- /dev/null +++ b/src/iconproducer.h @@ -0,0 +1,46 @@ +#ifndef ICONPRODUCER_H +#define ICONPRODUCER_H +#include +#include +#include +#include "../config/powermanagementsettings.h" +#include "battery.h" + +class IconProducer : public QObject +{ + Q_OBJECT + +public: + IconProducer(Battery* battery, QObject *parent = 0); + IconProducer(QObject *parent = 0); + + QIcon mIcon; + QString mIconName; + +signals: + void iconChanged(); + +public slots: + void update(float newChargeLevel, Battery::State newState); + +private slots: + void themeChanged(); + void update(); + +private: + + QIcon &circleIcon(); + QIcon buildCircleIcon(Battery::State state, double chargeLevel); + + + float mChargeLevel; + Battery::State mState; + + PowerManagementSettings mSettings; + + QMap mLevelNameMapCharging; + QMap mLevelNameMapDischarging; + +}; + +#endif // ICONPRODUCER_H diff --git a/src/idlenesswatcher.cpp b/src/idlenesswatcher.cpp new file mode 100644 index 0000000..206c2c2 --- /dev/null +++ b/src/idlenesswatcher.cpp @@ -0,0 +1,285 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright (C) 2013 Alec Moskvin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include +#include +#include +#include + +#include + +#include "screensaveradaptor.h" +#include "idlenesswatcher.h" +#include "x11helper.h" + +/* lockers: + * + * xlock(more) + * i3lock -n + * slock + * alock + * xtrlock + */ + + +IdlenessWatcher::IdlenessWatcher(QObject* parent): + Watcher(parent), + mPSettings(), + mErrorNotification(tr("LxQt Idleness watcher failed to start")), + mDBusWatcher(this), + mInhibitorCookie(0), + mIsLocked(false) +{ + qDebug() << "Starting idlenesswatcher"; + mConn = X11Helper::connection(); + xcb_prefetch_extension_data(mConn, &xcb_screensaver_id); + xcb_prefetch_extension_data(mConn, &xcb_dpms_id); + xcb_screensaver_query_version_cookie_t verCookie = xcb_screensaver_query_version_unchecked(mConn, XCB_SCREENSAVER_MAJOR_VERSION, XCB_SCREENSAVER_MINOR_VERSION); + xcb_dpms_get_version_cookie_t dpmsVerCookie = xcb_dpms_get_version_unchecked(mConn, XCB_DPMS_MAJOR_VERSION, XCB_DPMS_MINOR_VERSION); + // Note that XCB is asynchronous, so we want to make requests ASAP and get the responses as late as possible. + + mScreen = screenOfDisplay(mConn, 0); + mErrorNotification.setUrgencyHint(LxQt::Notification::UrgencyCritical); + mErrorNotification.setIcon("object-unlocked"); + mErrorNotification.setTimeout(0); + + new ScreenSaverAdaptor(this); + QDBusConnection sessionBus = QDBusConnection::sessionBus(); + if (!sessionBus.registerService("org.freedesktop.ScreenSaver") + || !sessionBus.registerObject("/ScreenSaver", this)) + { + mErrorNotification.setBody(tr("D-Bus interface org.freedesktop.ScreenSaver is already registered")); + mErrorNotification.update(); + qWarning() << "ERROR: D-Bus interface org.freedesktop.ScreenSaver is already registered"; + } + + mDBusWatcher.setConnection(QDBusConnection::sessionBus()); + mDBusWatcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); + + connect(&mTimer, SIGNAL(timeout()), SLOT(idleTimeout())); + connect(&mPSettings, SIGNAL(settingsChanged()), SLOT(restartTimer())); + connect(&mDBusWatcher, SIGNAL(serviceUnregistered(QString)), SLOT(serviceUnregistered(QString))); + connect(&mLockProcess, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(screenUnlocked(int,QProcess::ExitStatus))); + connect(&mErrorNotification, SIGNAL(actionActivated(int)), SLOT(notificationAction(int))); + + // Get XCB responses ... + const xcb_query_extension_reply_t* extReply = xcb_get_extension_data(mConn, &xcb_screensaver_id); + const xcb_query_extension_reply_t* dpmsExtReply = xcb_get_extension_data(mConn, &xcb_dpms_id); + xcb_screensaver_query_version_reply_t* verReply = xcb_screensaver_query_version_reply(mConn, verCookie, NULL); + xcb_dpms_get_version_reply_t* dpmsVerReply = xcb_dpms_get_version_reply(mConn, dpmsVerCookie, NULL); + + if (mScreen && extReply && extReply->present && dpmsExtReply && dpmsExtReply->present + && verReply && dpmsVerReply + && verReply->server_major_version == XCB_SCREENSAVER_MAJOR_VERSION + && verReply->server_minor_version >= XCB_SCREENSAVER_MINOR_VERSION + //&& dpmsVerReply->server_major_version == XCB_DPMS_MAJOR_VERSION + //&& dpmsVerReply->server_minor_version >= XCB_DPMS_MINOR_VERSION + ) + { + free(verReply); + free(dpmsVerReply); + } + else + { + mErrorNotification.setBody(tr("The X11 Screensaver extension is not usable")); + mErrorNotification.update(); + if (verReply) + free(verReply); + qCritical() << "ERROR: Can't use the X11 Screensaver Extension!"; + } + + mErrorNotification.setActions(QStringList(tr("Configure..."))); + + qDebug() << "LxQt Screenlocker started."; + qDebug() << "timeout:" << getMaxIdleTimeoutMs() << "ms, lock command:" << mLockCommand; + restartTimer(); +} + +xcb_screen_t* IdlenessWatcher::screenOfDisplay(xcb_connection_t* conn, int screen) +{ + xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(conn)); + for (; iter.rem; --screen, xcb_screen_next(&iter)) + if (screen == 0) + return iter.data; + return NULL; +} + +uint IdlenessWatcher::getIdleTimeMs() +{ + xcb_screensaver_query_info_cookie_t infoCookie = xcb_screensaver_query_info_unchecked(mConn, mScreen->root); + xcb_screensaver_query_info_reply_t* infoReply = xcb_screensaver_query_info_reply(mConn, infoCookie, NULL); + if (!infoReply) + { + qWarning() << "Bad reply from X11 Screensaver"; + return 0; + } + uint msSinceUserInput = infoReply->ms_since_user_input; + free(infoReply); + return msSinceUserInput; +} + +uint IdlenessWatcher::getMaxIdleTimeoutMs() +{ + return 1000*mPSettings.getIdlenessTimeSecs(); +} + +void IdlenessWatcher::idleTimeout() +{ + uint msSinceUserInput = getIdleTimeMs(); + qDebug() << " ms since user input:" << msSinceUserInput; + if (msSinceUserInput >= getMaxIdleTimeoutMs()) + { + doAction(mPSettings.getIdlenessAction()); + } + else + { + qDebug() << "--- Locking screen in" << (getMaxIdleTimeoutMs() - msSinceUserInput) << "(maybe)."; + mTimer.start(getMaxIdleTimeoutMs() - msSinceUserInput); + } +} + +void IdlenessWatcher::restartTimer() +{ + qDebug() << ">>> Timer Restarted, waiting: " << getMaxIdleTimeoutMs() << "msecs"; + mTimer.start(getMaxIdleTimeoutMs()); +} + +void IdlenessWatcher::screenUnlocked(int exitCode, QProcess::ExitStatus exitStatus) +{ + + mIsLocked = false; + emit ActiveChanged(false); + + if (exitCode == 0) + { + restartTimer(); + } + else + { + mErrorNotification.setSummary(tr("ERROR: Screen unlocked")); + if (exitStatus == QProcess::NormalExit) + mErrorNotification.setBody(tr("Locking program \"%1\" exited with error code %2").arg(mLockCommand).arg(exitCode)); + else + mErrorNotification.setBody(tr("Locking program \"%1\" crashed with error code %2").arg(mLockCommand).arg(exitCode)); + mErrorNotification.update(); + mTimer.stop(); + connect(&mErrorNotification, SIGNAL(notificationClosed(CloseReason)), SLOT(idleTimeout())); + } +} + +void IdlenessWatcher::notificationAction(int num) +{ + switch (num) + { + case 0: // "Configure" + QProcess::startDetached("lxqt-config-screenlocker"); + } +} + +void IdlenessWatcher::serviceUnregistered(const QString& service) +{ + for (QMutableMapIterator iter(mInhibitors); iter.hasNext();) + { + if (iter.next().value() == service) + { + qDebug() << "Service unregistered:" << iter.value(); + mDBusWatcher.removeWatchedService(iter.value()); + iter.remove(); + } + } + + if (mInhibitors.isEmpty()) + restartTimer(); +} + +/* ---------- D-Bus methods ---------- */ + +void IdlenessWatcher::Lock() +{ + // lockScreen(); +} + +uint IdlenessWatcher::GetSessionIdleTime() +{ + return getIdleTimeMs() / 1000; +} + +uint IdlenessWatcher::GetActiveTime() +{ + if (!mIsLocked) + return 0; + return mLockTime.secsTo(QDateTime::currentDateTime()); +} + +bool IdlenessWatcher::GetActive() +{ + return mIsLocked; +} + +bool IdlenessWatcher::SetActive(bool activate) +{ + //if (!activate) + return false; + //return lockScreen(); +} + +void IdlenessWatcher::SimulateUserActivity() +{ + restartTimer(); +} + +uint IdlenessWatcher::Inhibit(const QString& applicationName, const QString& reasonForInhibit) +{ + mInhibitorCookie++; + QString service(this->message().service()); + qDebug() << "*** Inhibit by" << applicationName << ":" << reasonForInhibit << ". Service:" << service << "->" << mInhibitorCookie; + mDBusWatcher.addWatchedService(service); + qDebug() << mDBusWatcher.watchedServices(); + mInhibitors.insert(mInhibitorCookie, service); + mTimer.stop(); + return mInhibitorCookie; +} + +void IdlenessWatcher::UnInhibit(uint cookie) +{ + qDebug() << "*** Uninhibit" << cookie; + mDBusWatcher.removeWatchedService(mInhibitors.value(cookie)); + mInhibitors.remove(cookie); + + if (mInhibitors.isEmpty()) + restartTimer(); +} + +uint IdlenessWatcher::Throttle(const QString& applicationName, const QString& reasonForThrottle) +{ + Q_UNUSED(applicationName); + Q_UNUSED(reasonForThrottle); + return 0; +} + +void IdlenessWatcher::UnThrottle(uint cookie) +{ + Q_UNUSED(cookie); +} diff --git a/src/idlenesswatcher.h b/src/idlenesswatcher.h new file mode 100644 index 0000000..1b83f3e --- /dev/null +++ b/src/idlenesswatcher.h @@ -0,0 +1,91 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright (C) 2013 Alec Moskvin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef IDLENESSWATCHER_H +#define IDLENESSWATCHER_H + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "../config/powermanagementsettings.h" +#include "watcher.h" + +class IdlenessWatcher : public Watcher, protected QDBusContext +{ + Q_OBJECT +public: + explicit IdlenessWatcher(QObject* parent = 0); + +signals: + void ActiveChanged(bool in0); + +public slots: + void Lock(); + uint GetSessionIdleTime(); + uint GetActiveTime(); + bool GetActive(); + bool SetActive(bool activate); + void SimulateUserActivity(); + uint Inhibit(const QString& applicationName, const QString& reasonForInhibit); + void UnInhibit(uint cookie); + uint Throttle(const QString& applicationName, const QString& reasonForThrottle); + void UnThrottle(uint cookie); + +private slots: + void idleTimeout(); + void screenUnlocked(int exitCode, QProcess::ExitStatus exitStatus); + void notificationAction(int num); + void serviceUnregistered(const QString& service); + void restartTimer(); + +private: + uint getIdleTimeMs(); + uint getMaxIdleTimeoutMs(); + + static xcb_screen_t* screenOfDisplay(xcb_connection_t* mConn, int screen); + + PowerManagementSettings mPSettings; + QTimer mTimer; + QProcess mLockProcess; + LxQt::Notification mErrorNotification; + QString mLockCommand; + QDateTime mLockTime; + QMap mInhibitors; + QDBusServiceWatcher mDBusWatcher; + xcb_connection_t* mConn; + xcb_screen_t* mScreen; + uint mInhibitorCookie; + bool mIsLocked; + bool mTurnOffDisplay; +}; + +#endif // IDLENESSWATCHER_H diff --git a/src/lid.cpp b/src/lid.cpp new file mode 100644 index 0000000..7c0b7db --- /dev/null +++ b/src/lid.cpp @@ -0,0 +1,74 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2011 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include +#include +#include + +#include "lid.h" + +Lid::Lid() +{ + mUPowerInterface = new QDBusInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", + QDBusConnection::systemBus(), this); + mUPowerPropertiesInterface = new QDBusInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", + QDBusConnection::systemBus(), this); + if (! connect(mUPowerInterface, SIGNAL(Changed()), this, SLOT(uPowerChange()))) + { + qDebug() << "Could not connect to org.freedesktop.UPower.changed(), connecting to org.freedesktop.DBus.Properties.PropertiesChanged(..) instead"; + QDBusConnection::systemBus().connect("org.freedesktop.UPower", + "/org/freedesktop/UPower", + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + this, + SLOT(uPowerChange())); + } + + mIsClosed = mUPowerPropertiesInterface->property("LidIsClosed").toBool(); +} + +bool Lid::haveLid() +{ + return mUPowerInterface->property("LidIsPresent").toBool(); +} + +bool Lid::onBattery() +{ + return mUPowerInterface->property("OnBattery").toBool(); +} + + +void Lid::uPowerChange() +{ + bool newIsClosed = mUPowerInterface->property("LidIsClosed").toBool(); + if (newIsClosed != mIsClosed) + { + mIsClosed = newIsClosed; + emit changed(mIsClosed); + } +} diff --git a/src/lid.h b/src/lid.h new file mode 100644 index 0000000..9043ad5 --- /dev/null +++ b/src/lid.h @@ -0,0 +1,54 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2011 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef LID_H +#define LID_H + +#include + +class Lid : public QObject +{ + Q_OBJECT + +signals: + void changed(bool closed); + +public: + Lid(); + bool haveLid(); + bool onBattery(); + bool isClosed() { return mIsClosed; } + +private: + bool mIsClosed; + QDBusInterface *mUPowerInterface; + QDBusInterface *mUPowerPropertiesInterface; + +private slots: + void uPowerChange(); +}; + +#endif // LID_H diff --git a/src/lidwatcher.cpp b/src/lidwatcher.cpp new file mode 100644 index 0000000..26bb5fe --- /dev/null +++ b/src/lidwatcher.cpp @@ -0,0 +1,127 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include +#include +#include +#include +#include + +#include "lidwatcher.h" +#include "../config/powermanagementsettings.h" + +LidWatcher::LidWatcher(QObject *parent) : Watcher(parent) +{ + inhibitSystemdLogin(); + connect(&mLid, SIGNAL(changed(bool)), this, SLOT(lidChanged(bool))); +} + +LidWatcher::~LidWatcher(){ +} + +void LidWatcher::lidChanged(bool closed) +{ + if (closed) + { + doAction(action()); + } +} + +int LidWatcher::action() +{ + if (mSettings.isEnableExtMonLidClosedActions() && externalMonitorPlugged()) + { + if (mLid.onBattery()) + { + return mSettings.getLidClosedExtMonAction(); + } + else + { + return mSettings.getLidClosedExtMonAcAction(); + } + } + else + { + if (mLid.onBattery()) + { + return mSettings.getLidClosedAction(); + } + else + { + return mSettings.getLidClosedAcAction(); + } + } +} + +bool LidWatcher::externalMonitorPlugged() +{ + int monitorCount = 0; + + QProcess xrandr(this); + xrandr.start("xrandr", QIODevice::ReadOnly); + xrandr.waitForFinished(1000); + + if (xrandr.exitCode() != 0) + { + return false; // Well, what to do? + } + + QTextStream xrandr_stdout(&xrandr); + while (!xrandr_stdout.atEnd()) + { + QString line = xrandr_stdout.readLine(); + qDebug() << ">>" << line; + if (line.indexOf(" connected", 0) > -1) + { + monitorCount++; + } + } + + qDebug() << "monitorCount: " << monitorCount; + + return monitorCount >= 2; +} + +void LidWatcher::inhibitSystemdLogin() +{ + QDBusInterface manager("org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + QDBusConnection::systemBus(), this); + QDBusReply reply = manager.call("Inhibit", "handle-lid-switch", "lxqt-powermanagment", "LidWatcher is in da house!", "block"); + if (reply.isValid()) + { + logindLock = reply.value(); + qDebug() << "Inhibit got:" << logindLock.fileDescriptor(); + } + else + { + qDebug() << "Error from inhibit:" << reply.error(); + } +} + diff --git a/src/lidwatcher.h b/src/lidwatcher.h new file mode 100644 index 0000000..e6c21a9 --- /dev/null +++ b/src/lidwatcher.h @@ -0,0 +1,61 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2012 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ +#ifndef LIDWATCHER_H +#define LIDWATCHER_H + +#include +#include +#include + +#include + +#include "../config/powermanagementsettings.h" +#include "watcher.h" +#include "lid.h" + +class LidWatcher : public Watcher +{ + Q_OBJECT +public: + explicit LidWatcher(QObject *parent = 0); + virtual ~LidWatcher(); + +private slots: + void lidChanged(bool closed); + +private: + int action(); + bool externalMonitorPlugged(); + void inhibitSystemdLogin(); + + Lid mLid; + LxQt::Power mLxQtPower; + PowerManagementSettings mSettings; + QDBusUnixFileDescriptor logindLock; +}; + +#endif // LIDWATCHER_H diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..c03669a --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,52 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include + +#include + +#include "powermanagementd.h" + +int main(int argc, char *argv[]) +{ + + LxQt::Application a(argc, argv); + a.setQuitOnLastWindowClosed(false); + + // To ensure only one instance of lxqt-powermanagement is running we register as a DBus service and refuse to run + // if not able to do so. + // We do not register any object as we don't have any dbus-operations to expose. + if (! QDBusConnection::sessionBus().registerService("org.lxqt.lxqt-powermanagement")) + { + qWarning() << "Unable to register 'org.lxqt.lxqt-powermanagement' service - is another instance of lxqt-powermanagement running?"; + return 1; + } + else + { + PowerManagementd powerManagementd; + return a.exec(); + } +} diff --git a/src/org.freedesktop.ScreenSaver.xml b/src/org.freedesktop.ScreenSaver.xml new file mode 100644 index 0000000..96ad48e --- /dev/null +++ b/src/org.freedesktop.ScreenSaver.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/powermanagementd.cpp b/src/powermanagementd.cpp new file mode 100644 index 0000000..565cc12 --- /dev/null +++ b/src/powermanagementd.cpp @@ -0,0 +1,110 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include + +#include "powermanagementd.h" +#include "../config/powermanagementsettings.h" +#include "idlenesswatcher.h" +#include "lidwatcher.h" +#include "batterywatcher.h" + +#define CURRENT_RUNCHECK_LEVEL 1 + +PowerManagementd::PowerManagementd() : + mBatterywatcherd(0), + mLidwatcherd(0), + mIdlenesswatcherd(0), + mSettings() + { + connect(&mSettings, SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); + settingsChanged(); + + if (mSettings.getRunCheckLevel() < CURRENT_RUNCHECK_LEVEL) + { + performRunCheck(); + mSettings.setRunCheckLevel(CURRENT_RUNCHECK_LEVEL); + } + +} + +PowerManagementd::~PowerManagementd() +{ +} + +void PowerManagementd::settingsChanged() +{ + if (mSettings.isBatteryWatcherEnabled() && !mBatterywatcherd) + { + mBatterywatcherd = new BatteryWatcher(this); + } + else if (mBatterywatcherd && ! mSettings.isBatteryWatcherEnabled()) + { + mBatterywatcherd->deleteLater(); + mBatterywatcherd = 0; + } + + if (mSettings.isLidWatcherEnabled() && !mLidwatcherd) + { + mLidwatcherd = new LidWatcher(this); + } + else if (mLidwatcherd && ! mSettings.isLidWatcherEnabled()) + { + mLidwatcherd->deleteLater(); + mLidwatcherd = 0; + } + + if (mSettings.isIdlenessWatcherEnabled() && !mIdlenesswatcherd) + { + mIdlenesswatcherd = new IdlenessWatcher(this); + } + else if (mIdlenesswatcherd && !mSettings.isIdlenessWatcherEnabled()) + { + mIdlenesswatcherd->deleteLater(); + mIdlenesswatcherd = 0; + } + +} + +void PowerManagementd::runConfigure() +{ + mNotification.close(); + QProcess::startDetached("lxqt-config-powermanagement"); +} + +void PowerManagementd::performRunCheck() +{ + mSettings.setLidWatcherEnabled(Lid().haveLid()); + mSettings.setBatteryWatcherEnabled(! Battery::batteries().isEmpty()); + qDebug() << "performRunCheck, lidWatcherEnabled:" << mSettings.isLidWatcherEnabled() << ", batteryWatcherEnabled:" << mSettings.isBatteryWatcherEnabled(); + mSettings.sync(); + mNotification.setSummary(tr("Power Management")); + mNotification.setBody(tr("You are running LXQt Power Management for the first time.\nYou can configure it from settings... ")); + mNotification.setActions(QStringList() << tr("Configure...")); + mNotification.setTimeout(10000); + connect(&mNotification, SIGNAL(actionActivated(int)), SLOT(runConfigure())); + mNotification.update(); +} diff --git a/src/powermanagementd.h b/src/powermanagementd.h new file mode 100644 index 0000000..926411f --- /dev/null +++ b/src/powermanagementd.h @@ -0,0 +1,43 @@ +/* + * File: powermanagementd.h + * Author: Christian Surlykke + * + * Created on 9. februar 2014, 16:15 + */ + +#ifndef POWERMANAGEMENTD_H +#define POWERMANAGEMENTD_H + +#include + +#include "../config/powermanagementsettings.h" + +class BatteryWatcher; +class LidWatcher; +class IdlenessWatcher; + +class PowerManagementd : public QObject +{ + Q_OBJECT + +public: + PowerManagementd(); + virtual ~PowerManagementd(); + +private slots: + void settingsChanged(); + void runConfigure(); + +private: + void performRunCheck(); + + BatteryWatcher* mBatterywatcherd; + LidWatcher* mLidwatcherd; + IdlenessWatcher* mIdlenesswatcherd; + + PowerManagementSettings mSettings; + LxQt::Notification mNotification; +}; + +#endif /* POWERMANAGEMENTD_H */ + diff --git a/src/translations/lxqt-powermanagement.ts b/src/translations/lxqt-powermanagement.ts new file mode 100644 index 0000000..2566687 --- /dev/null +++ b/src/translations/lxqt-powermanagement.ts @@ -0,0 +1,259 @@ + + + + + Battery + + + Charging + + + + + Discharging + + + + + Empty + + + + + Fully charged + + + + + Pending charge + + + + + Pending discharge + + + + + Unknown + + + + + BatteryInfo + + + Power Management + + + + + Battery info + + + + + Energy Now: + + + + + Updated: + + + + + Technology: + + + + + Model: + + + + + Energy rate: + + + + + Voltage: + + + + + Energy Full, Design: + + + + + Energy Full: + + + + + State: + + + + + Lithium ion + + + + + Lithium polymer + + + + + Lithium iron phosphate + + + + + Lead acid + + + + + Nickel cadmium + + + + + Nickel metal hydride + + + + + Unknown + + + + + BatteryWatcher + + + No battery! + + + + + LXQt could not find data about any battery - monitoring disabled + + + + + Power low! + + + + + Suspending in %1 seconds + + + + + Hibernating in %1 seconds + + + + + Shutting down in %1 seconds + + + + + IdlenessWatcher + + + LxQt Idleness watcher failed to start + + + + + D-Bus interface org.freedesktop.ScreenSaver is already registered + + + + + The X11 Screensaver extension is not usable + + + + + Configure... + + + + + ERROR: Screen unlocked + + + + + Locking program "%1" exited with error code %2 + + + + + Locking program "%1" crashed with error code %2 + + + + + PowerManagementd + + + Power Management + + + + + You are running LXQt Power Management for the first time. +You can configure it from settings... + + + + + Configure... + + + + + TrayIcon + + + Configure + + + + + + About + + + + + Disable icon + + + + + discharging + + + + + charging + + + + + <p> <b>LXQt Powermanagement</b><br/> - Powermanagement for the LXQt Desktop Environment</p><p> Authors:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - and others from the Razor and LXQt projects</p><p> Copyright &copy; 2012-2014</p> + + + + diff --git a/src/translations/lxqt-powermanagement_ja.ts b/src/translations/lxqt-powermanagement_ja.ts new file mode 100644 index 0000000..f845b05 --- /dev/null +++ b/src/translations/lxqt-powermanagement_ja.ts @@ -0,0 +1,259 @@ + + + + + Battery + + + Charging + 充電中 + + + + Discharging + 放電中 + + + + Empty + + + + + Fully charged + 満充電 + + + + Pending charge + 充電中断中 + + + + Pending discharge + 放電中断中 + + + + Unknown + 不明 + + + + BatteryInfo + + + Power Management + 電源管理 + + + + Battery info + バッテリー情報 + + + + Energy Now: + 現在の容量: + + + + Updated: + 更新: + + + + Technology: + 技術: + + + + Model: + 型式: + + + + Energy rate: + エネルギー率: + + + + Voltage: + 電圧: + + + + Energy Full, Design: + 満エネルギー、デザイン: + + + + Energy Full: + 満エネルギー: + + + + State: + 状態: + + + + Lithium ion + リチウムイオン + + + + Lithium polymer + リチウムポリマー + + + + Lithium iron phosphate + リン酸鉄リチウム + + + + Lead acid + 鉛蓄電池 + + + + Nickel cadmium + ニッカド + + + + Nickel metal hydride + ニッケル水素 + + + + Unknown + 不明 + + + + BatteryWatcher + + + No battery! + バッテリーがありません! + + + + LXQt could not find data about any battery - monitoring disabled + バッテリーのデーターを見つけられませんので、監視機能は無効です + + + + Power low! + 電源が少なくなっています! + + + + Suspending in %1 seconds + %1秒でサスペンドに入ります + + + + Hibernating in %1 seconds + %1秒でハイバネートに入ります + + + + Shutting down in %1 seconds + %1秒でシャットダウンします + + + + IdlenessWatcher + + + LxQt Idleness watcher failed to start + LXQtのアイドル状態監視は始動に失敗しました + + + + D-Bus interface org.freedesktop.ScreenSaver is already registered + D-Busインターフェース org.freedesktop.ScreenSaver が既に登録されています + + + + The X11 Screensaver extension is not usable + X11スクリーンセーバー拡張を使えません + + + + Configure... + 設定する + + + + ERROR: Screen unlocked + エラー: スクリーンのロックが解除されました + + + + Locking program "%1" exited with error code %2 + ロック用プログラム "%1" は、エラーコード %2 により終了しました + + + + Locking program "%1" crashed with error code %2 + ロック用プログラム "%1" は、エラーコード %2 によりクラッシュしました + + + + PowerManagementd + + + Power Management + 電源管理 + + + + You are running LXQt Power Management for the first time. +You can configure it from settings... + LXQt電源管理は初めて実行されましたので、設定を行ってください + + + + Configure... + 設定する + + + + TrayIcon + + + Configure + 設定 + + + + + About + 情報 + + + + Disable icon + アイコンを無効 + + + + discharging + 放電中 + + + + charging + 充電中 + + + + <p> <b>LXQt Powermanagement</b><br/> - Powermanagement for the LXQt Desktop Environment</p><p> Authors:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - and others from the Razor and LXQt projects</p><p> Copyright &copy; 2012-2014</p> + <p> <b>LXQt Powermanagement</b><br/> - LXQtデスクトップ環境の電源管理</p><p> 作者:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - その他 Razor-qtおよびLXQtプロジェクトのメンバー</p><p> Copyright &copy; 2012-2014</p> + + + diff --git a/src/translations/lxqt-powermanagement_pt.ts b/src/translations/lxqt-powermanagement_pt.ts new file mode 100644 index 0000000..33e8a49 --- /dev/null +++ b/src/translations/lxqt-powermanagement_pt.ts @@ -0,0 +1,260 @@ + + + + + Battery + + + Charging + A carregar + + + + Discharging + A descarregar + + + + Empty + Vazia + + + + Fully charged + Totalmente carregada + + + + Pending charge + Por carregar + + + + Pending discharge + Por descarregar + + + + Unknown + Desconhecido + + + + BatteryInfo + + + Power Management + Gestão de energia + + + + Battery info + Informações da bateria + + + + Energy Now: + Energia atual: + + + + Updated: + Atualização: + + + + Technology: + Tecnologia: + + + + Model: + Modelo: + + + + Energy rate: + Taxa de energia: + + + + Voltage: + Tensão: + + + + Energy Full, Design: + Energia máxima teórica: + + + + Energy Full: + Energia máxima: + + + + State: + Estado: + + + + Lithium ion + Ião de lítio + + + + Lithium polymer + Polímero de lítio + + + + Lithium iron phosphate + Fosfato de Ferro-Lítio + + + + Lead acid + Ácido de chumbo + + + + Nickel cadmium + Níquel-Cádmio + + + + Nickel metal hydride + Níquel-Hidreto Metálico + + + + Unknown + Desconhecido + + + + BatteryWatcher + + + No battery! + Nenhuma bateria! + + + + LXQt could not find data about any battery - monitoring disabled + O LxQt não consegui encontrar qualquer bateria e a monitorização foi desativada + + + + Power low! + Energia baixa! + + + + Suspending in %1 seconds + Suspensão dentro de %1 segundos + + + + Hibernating in %1 seconds + Hibernação dentro de %1 segundos + + + + Shutting down in %1 seconds + A desligar dentro de %1 segundos + + + + IdlenessWatcher + + + LxQt Idleness watcher failed to start + O monitorizador de inatividade não foi iniciado + + + + D-Bus interface org.freedesktop.ScreenSaver is already registered + A interface D-Bus org.freedesktop.ScreenSaver já está registada + + + + The X11 Screensaver extension is not usable + A extensão X 11 Screensaver não pode ser utilizada + + + + Configure... + Configurar... + + + + ERROR: Screen unlocked + Erro: ecrã não bloqueado + + + + Locking program "%1" exited with error code %2 + O bloqueio do programa "%1" terminou com o erro "%2" + + + + Locking program "%1" crashed with error code %2 + O bloqueio do programa "%1" crashou com o erro "%2" + + + + PowerManagementd + + + Power Management + Gestão de energia + + + + You are running LXQt Power Management for the first time. +You can configure it from settings... + Está a executar a gestão de energia do LxQt pela primeira vez. +Pode configurar as opções nas definições... + + + + Configure... + Configurar... + + + + TrayIcon + + + Configure + Configurar + + + + + About + Sobre + + + + Disable icon + Desativar ícone + + + + discharging + a descarregar + + + + charging + a carregar + + + + <p> <b>LXQt Powermanagement</b><br/> - Powermanagement for the LXQt Desktop Environment</p><p> Authors:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - and others from the Razor and LXQt projects</p><p> Copyright &copy; 2012-2014</p> + <p> <b>Gestor de energia do LxQt</b><br/>Gestão de energia para o ambiente de trabalho LxQt</p><p> Autores:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - e outros colaboradores dos projetos Razor e LxQt</p><p> Direitos de autor &copy; 2012-2015</p> + + + diff --git a/src/translations/lxqt-powermanagement_ru.ts b/src/translations/lxqt-powermanagement_ru.ts new file mode 100644 index 0000000..04145a8 --- /dev/null +++ b/src/translations/lxqt-powermanagement_ru.ts @@ -0,0 +1,260 @@ + + + + + Battery + + + Charging + Заряжается + + + + Discharging + Разряжается + + + + Empty + Пустая + + + + Fully charged + Полностью заряжена + + + + Pending charge + Ожидает заряда + + + + Pending discharge + Ожидает разряда + + + + Unknown + Неизвестно + + + + BatteryInfo + + + Power Management + Управление энергопотреблением + + + + Battery info + Информация о батарее + + + + Energy Now: + Заряд сейчас: + + + + Updated: + Обновлено: + + + + Technology: + Технология: + + + + Model: + Модель: + + + + Energy rate: + Мощность тока: + + + + Voltage: + Напряжение: + + + + Energy Full, Design: + Максимальный заряд: + + + + Energy Full: + + + + + State: + Состояние: + + + + Lithium ion + Литий-ионная + + + + Lithium polymer + Литий-полимерная + + + + Lithium iron phosphate + Литий-железо-фосфатная + + + + Lead acid + Свинцово-кислотная + + + + Nickel cadmium + Никель-кадмиевая + + + + Nickel metal hydride + Никель-металл-гидридная + + + + Unknown + Неизвестно + + + + BatteryWatcher + + + No battery! + Нет батареи! + + + + LXQt could not find data about any battery - monitoring disabled + LXQt не смог найти информацию о какой-либо батарее - наблюдение отменено + + + + Power low! + Низкий заряд! + + + + Suspending in %1 seconds + Ждущий режим через %1 секунд + + + + Hibernating in %1 seconds + Спящий режим через %1 секунд + + + + Shutting down in %1 seconds + Выключение компьютера через %1 секунд + + + + IdlenessWatcher + + + LxQt Idleness watcher failed to start + Не удалось запустить наблюдение за простоем LxQt + + + + D-Bus interface org.freedesktop.ScreenSaver is already registered + Интерфейс D-Bus org.freedesktop.ScreenSaver уже зарегистрирован + + + + The X11 Screensaver extension is not usable + Расширение X11 Скринсейвер непригодно для использования + + + + Configure... + Настроить… + + + + ERROR: Screen unlocked + ОШИБКА: экран разблокирован + + + + Locking program "%1" exited with error code %2 + Программа блокировки экрана "%1" вышла с кодом ошибки %2 + + + + Locking program "%1" crashed with error code %2 + Программа блокировки экрана "%1" упала с кодом ошибки %2 + + + + PowerManagementd + + + Power Management + Управление энергопотреблением + + + + You are running LXQt Power Management for the first time. +You can configure it from settings... + Вы запускаете управление энергопотреблением LXQt впервые. +Вы можете сконфигурировать его в настройках… + + + + Configure... + Настроить… + + + + TrayIcon + + + discharging + разряжается + + + + charging + заряжается + + + + + About + О программе + + + + Configure + Настроить + + + + Disable icon + Не показывать значок + + + + <p> <b>LXQt Powermanagement</b><br/> - Powermanagement for the LXQt Desktop Environment</p><p> Authors:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - and others from the Razor and LXQt projects</p><p> Copyright &copy; 2012-2014</p> + <p> <b>Управление энергопотреблением LXQt</b><br/> - Управление энергопотреблением для окружения рабочего стола LXQt</p><p> Авторы:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - и другие из проектов Razor и LXQt</p><p> Copyright &copy; 2012-2014</p> + + + diff --git a/src/translations/lxqt-powermanagement_ru_RU.ts b/src/translations/lxqt-powermanagement_ru_RU.ts new file mode 100644 index 0000000..f151278 --- /dev/null +++ b/src/translations/lxqt-powermanagement_ru_RU.ts @@ -0,0 +1,260 @@ + + + + + Battery + + + Charging + Заряжается + + + + Discharging + Разряжается + + + + Empty + Пустая + + + + Fully charged + Полностью заряжена + + + + Pending charge + Ожидает заряда + + + + Pending discharge + Ожидает разряда + + + + Unknown + Неизвестно + + + + BatteryInfo + + + Power Management + Управление энергопотреблением + + + + Battery info + Информация о батарее + + + + Energy Now: + Заряд сейчас: + + + + Updated: + Обновлено: + + + + Technology: + Технология: + + + + Model: + Модель: + + + + Energy rate: + Мощность тока: + + + + Voltage: + Напряжение: + + + + Energy Full, Design: + Максимальный заряд: + + + + Energy Full: + + + + + State: + Состояние: + + + + Lithium ion + Литий-ионная + + + + Lithium polymer + Литий-полимерная + + + + Lithium iron phosphate + Литий-железо-фосфатная + + + + Lead acid + Свинцово-кислотная + + + + Nickel cadmium + Никель-кадмиевая + + + + Nickel metal hydride + Никель-металл-гидридная + + + + Unknown + Неизвестно + + + + BatteryWatcher + + + No battery! + Нет батареи! + + + + LXQt could not find data about any battery - monitoring disabled + LXQt не смог найти информацию о какой-либо батарее - наблюдение отменено + + + + Power low! + Низкий заряд! + + + + Suspending in %1 seconds + Ждущий режим через %1 секунд + + + + Hibernating in %1 seconds + Спящий режим через %1 секунд + + + + Shutting down in %1 seconds + Выключение компьютера через %1 секунд + + + + IdlenessWatcher + + + LxQt Idleness watcher failed to start + Не удалось запустить наблюдение за простоем LxQt + + + + D-Bus interface org.freedesktop.ScreenSaver is already registered + Интерфейс D-Bus org.freedesktop.ScreenSaver уже зарегистрирован + + + + The X11 Screensaver extension is not usable + Расширение X11 Скринсейвер непригодно для использования + + + + Configure... + Настроить… + + + + ERROR: Screen unlocked + ОШИБКА: экран разблокирован + + + + Locking program "%1" exited with error code %2 + Программа блокировки экрана "%1" вышла с кодом ошибки %2 + + + + Locking program "%1" crashed with error code %2 + Программа блокировки экрана "%1" упала с кодом ошибки %2 + + + + PowerManagementd + + + Power Management + Управление энергопотреблением + + + + You are running LXQt Power Management for the first time. +You can configure it from settings... + Вы запускаете управление энергопотреблением LXQt впервые. +Вы можете сконфигурировать его в настройках… + + + + Configure... + Настроить… + + + + TrayIcon + + + discharging + разряжается + + + + charging + заряжается + + + + + About + О программе + + + + Configure + Настроить + + + + Disable icon + Не показывать значок + + + + <p> <b>LXQt Powermanagement</b><br/> - Powermanagement for the LXQt Desktop Environment</p><p> Authors:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - and others from the Razor and LXQt projects</p><p> Copyright &copy; 2012-2014</p> + <p> <b>Управление энергопотреблением LXQt</b><br/> - Управление энергопотреблением для окружения рабочего стола LXQt</p><p> Авторы:<br/> &nbsp; Christian Surlykke, Alec Moskvin<br/> &nbsp; - и другие из проектов Razor и LXQt</p><p> Copyright &copy; 2012-2014</p> + + + diff --git a/src/trayicon.cpp b/src/trayicon.cpp new file mode 100644 index 0000000..153cb16 --- /dev/null +++ b/src/trayicon.cpp @@ -0,0 +1,97 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2011 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include +#include +#include +#include +#include "trayicon.h" +#include "../config/powermanagementsettings.h" + +TrayIcon::TrayIcon(Battery *battery, QObject *parent) : QSystemTrayIcon(parent), mIconProducer(battery), mContextMenu() +{ + connect(battery, SIGNAL(summaryChanged(QString)), this, SLOT(updateTooltip(QString))); + updateTooltip(battery->summary); + + connect(&mIconProducer, SIGNAL(iconChanged()), this, SLOT(iconChanged())); + iconChanged(); + + connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(onActivated(QSystemTrayIcon::ActivationReason))); + + mContextMenu.addAction(tr("Configure"), this, SLOT(onConfigureTriggered())); + mContextMenu.addAction(tr("About"), this, SLOT(onAboutTriggered())); + mContextMenu.addAction(tr("Disable icon"), this, SLOT(onDisableIconTriggered())); + setContextMenu(&mContextMenu); +} + +TrayIcon::~TrayIcon() {} + +void TrayIcon::iconChanged() +{ + setIcon(mIconProducer.mIcon); +} + +void TrayIcon::updateTooltip(QString newTooltip) +{ + setToolTip(newTooltip); +} + +void TrayIcon::onConfigureTriggered() +{ + QProcess::startDetached("lxqt-config-powermanagement"); +} + +void TrayIcon::onAboutTriggered() +{ + QMessageBox::about(0, + tr("About"), + tr( "

" + " LXQt Powermanagement
" + " - Powermanagement for the LXQt Desktop Environment" + "

" + "

" + " Authors:
" + "   Christian Surlykke, Alec Moskvin
" + "   - and others from the Razor and LXQt projects" + "

" + "

" + " Copyright © 2012-2014" + "

" + )); +} + + +void TrayIcon::onDisableIconTriggered() +{ + PowerManagementSettings().setShowIcon(false); +} + +void TrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) +{ + qDebug() << "onActivated" << reason; + if (Trigger == reason) emit toggleShowInfo(); +} diff --git a/src/trayicon.h b/src/trayicon.h new file mode 100644 index 0000000..b9050af --- /dev/null +++ b/src/trayicon.h @@ -0,0 +1,64 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright: 2011 Razor team + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef TRAYICON_H +#define TRAYICON_H + +#include +#include + +#include "battery.h" +#include "iconproducer.h" +#include "../config/powermanagementsettings.h" + +class TrayIcon : public QSystemTrayIcon +{ + Q_OBJECT + +public: + TrayIcon(Battery *battery, QObject *parent = 0); + ~TrayIcon(); + +signals: + void toggleShowInfo(); + +public slots: + void iconChanged(); + void updateTooltip(QString newTooltip); + +private slots: + void onConfigureTriggered(); + void onAboutTriggered(); + void onDisableIconTriggered(); + void onActivated(QSystemTrayIcon::ActivationReason reason); + +private: + IconProducer mIconProducer; + QMenu mContextMenu; +}; + +#endif // TRAYICON_H diff --git a/src/watcher.cpp b/src/watcher.cpp new file mode 100644 index 0000000..2bbb240 --- /dev/null +++ b/src/watcher.cpp @@ -0,0 +1,47 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * + * Authors: + * Christian Surlykke + * + * This program or library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include + +#include "../config/powermanagementsettings.h" +#include "watcher.h" + +Watcher::Watcher(QObject *parent) : + QObject(parent) +{ +} + +Watcher::~Watcher() +{ +} + +void Watcher::doAction(int action) +{ + if (action > -1) + { + mPower.doAction((LxQt::Power::Action) action); + } +} + diff --git a/src/watcher.h b/src/watcher.h new file mode 100644 index 0000000..2f9f36d --- /dev/null +++ b/src/watcher.h @@ -0,0 +1,25 @@ +#ifndef WATCHER_H +#define WATCHER_H + +#include +#include + +class Watcher : public QObject +{ + + Q_OBJECT + +public: + Watcher(QObject *parent = 0); + virtual ~Watcher(); + +protected: + void doAction(int action); + +private: + LxQt::Power mPower; + +}; + +#endif /* WATCHER_H */ + diff --git a/src/x11helper.cpp b/src/x11helper.cpp new file mode 100644 index 0000000..ea85023 --- /dev/null +++ b/src/x11helper.cpp @@ -0,0 +1,42 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright (C) 2012 Alec Moskvin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "x11helper.h" + +#include +#include + +Display* X11Helper::display() +{ + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + void* display = native->nativeResourceForWindow("display", 0); + return reinterpret_cast(display); +} + +xcb_connection_t* X11Helper::connection() +{ + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + void* connection = native->nativeResourceForWindow("connection", 0); + return reinterpret_cast(connection); +} diff --git a/src/x11helper.h b/src/x11helper.h new file mode 100644 index 0000000..e649fcb --- /dev/null +++ b/src/x11helper.h @@ -0,0 +1,54 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXDE-Qt - a lightweight, Qt based, desktop toolset + * http://razor-qt.org + * + * Copyright (C) 2013 Alec Moskvin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef X11HELPER_H +#define X11HELPER_H + +#include + +// Avoid polluting everything with X11/Xlib.h: +typedef struct _XDisplay Display; + +/** + * @brief The X11Helper class is class to get the X11 Display or XCB connection + * + * It's intended to be used as a wrapper/replacement for QX11Info, which is removed in Qt5. + */ +class X11Helper +{ +public: + /** + * @brief display Returns the X11 display + * @return + */ + static Display* display(); + + /** + * @brief connection Returns the XCB connection + * @return + */ + static xcb_connection_t* connection(); +}; + +#endif // X11HELPER_H