commit e52eabc834ec681d1e2c06da828bb4396188fd3d Author: Andrew Lee (李健秋) Date: Tue Aug 11 22:56:51 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..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..b633203 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +Upstream Authors: + LXQt team: http://lxqt.org + +Copyright: + Copyright (c) 2014 LXQt team + +License: 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..9381344 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 2.8.11) + +project(lxqt-admin) + +option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF) + +# Set default installation paths +set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Installation path for libraries") + +find_package(Qt5Widgets REQUIRED QUIET) +find_package(lxqt REQUIRED QUIET) +find_package(KF5WindowSystem REQUIRED QUIET) +include(${LXQT_USE_FILE}) + +find_package(PkgConfig) +pkg_check_modules(OOBS REQUIRED + glib-2.0 + liboobs-1 +) + +include(LXQtTranslate) + +add_subdirectory(lxqt-admin-time) +add_subdirectory(lxqt-admin-user) + +# 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/COPYING b/COPYING new file mode 100644 index 0000000..a8dd823 --- /dev/null +++ b/COPYING @@ -0,0 +1,461 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin St, 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 diff --git a/lxqt-admin-time/CMakeLists.txt b/lxqt-admin-time/CMakeLists.txt new file mode 100644 index 0000000..ef876d8 --- /dev/null +++ b/lxqt-admin-time/CMakeLists.txt @@ -0,0 +1,74 @@ +project(lxqt-admin-time) + +# build static helper class first +include_directories ( + ${CMAKE_CURRENT_BINARY_DIR} + ${LXQT_INCLUDE_DIRS} + ${QTXDG_INCLUDE_DIRS} + ${OOBS_INCLUDE_DIRS} +) + +set ( lxqt-admin-time_HDRS + timeadmindialog.h + datetime.h + timezone.h +) + +set ( lxqt-admin-time_SRCS + main.cpp + timeadmindialog.cpp + datetime.cpp + timezone.cpp +) + +set ( lxqt-admin-time_MOCS + timeadmindialog.h + datetime.h + timezone.h +) + +set( lxqt-admin-time_UIS + datetime.ui + timezone.ui +) + +qt5_wrap_cpp(MOCS ${lxqt-admin-time_MOCS}) +qt5_wrap_ui(UIS ${lxqt-admin-time_UIS}) + +# Translations ********************************** +lxqt_translate_ts(lxqt-admin-time_QM_FILES + UPDATE_TRANSLATIONS ${UPDATE_TRANSLATIONS} + SOURCES + ${lxqt-admin-time_HDRS} + ${lxqt-admin-time_SRCS} + ${lxqt-admin-time_UIS} + INSTALL_DIR + "${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME}" +) + +lxqt_translate_desktop(DESKTOP_FILES + SOURCES + lxqt-admin-time.desktop.in +) + +lxqt_app_translation_loader(lxqt-admin-time_QM_LOADER ${PROJECT_NAME}) +#************************************************ + +add_executable(lxqt-admin-time + ${lxqt-admin-time_SRCS} + ${UIS} + ${MOCS} + ${DESKTOP_FILES} + ${lxqt-admin-time_QM_FILES} + ${lxqt-admin-time_QM_LOADER} +) + +target_link_libraries(lxqt-admin-time + KF5::WindowSystem + Qt5::Widgets + ${LXQT_LIBRARIES} + ${OOBS_LIBRARIES} +) + +install(TARGETS lxqt-admin-time RUNTIME DESTINATION bin) +install(FILES ${DESKTOP_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) diff --git a/lxqt-admin-time/datetime.cpp b/lxqt-admin-time/datetime.cpp new file mode 100644 index 0000000..7e5dbcf --- /dev/null +++ b/lxqt-admin-time/datetime.cpp @@ -0,0 +1,103 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * http://lxqt.org + * + * Copyright: 2014 LXQt team + * Authors: + * Hong Jen Yee (PCMan) + * + * 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 "datetime.h" +#include "ui_datetime.h" +#include +#include +#include + +DateTime::DateTime(QWidget *parent) : + QWidget(parent), + ui(new Ui::DateTime) +{ + ui->setupUi(this); + mTimer = new QTimer(this); + connect(mTimer,SIGNAL(timeout()),SLOT(timeout())); + + + //highlight today + QDate date = QDate::currentDate(); + QTextCharFormat format = ui->calendar->dateTextFormat(date); + QBrush brush; + brush.setColor(Qt::green); + format.setBackground(brush); + ui->calendar->setDateTextFormat(date,format); + + reload(); +} + +DateTime::~DateTime() +{ + delete ui; +} + +void DateTime::timeout() +{ + ui->edit_time->blockSignals(true); + ui->edit_time->setTime(QTime::currentTime()); + ui->edit_time->blockSignals(false); +} + +void DateTime::reload() +{ + ui->calendar->setSelectedDate(QDate::currentDate()); + ui->edit_time->setTime(QTime::currentTime()); + mTimer->start(1000); + + mModified = 0; + emit changed(mModified); +} + +void DateTime::on_edit_time_userTimeChanged(const QTime &time) +{ + mModified |= M_TIME; + mTimer->stop(); + + emit changed(mModified); +} + +QDateTime DateTime::dateTime() const +{ + QDateTime dt(ui->calendar->selectedDate(),ui->edit_time->time()); + return dt; +} + +void DateTime::on_calendar_selectionChanged() +{ + QDate date = ui->calendar->selectedDate(); + if (date != QDate::currentDate()) + { + mModified |= M_DATE; + } + else + { + mModified &= ~M_DATE; + } + + emit changed(mModified); +} diff --git a/lxqt-admin-time/datetime.h b/lxqt-admin-time/datetime.h new file mode 100644 index 0000000..2913cda --- /dev/null +++ b/lxqt-admin-time/datetime.h @@ -0,0 +1,71 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * http://lxqt.org + * + * Copyright: 2014 LXQt team + * Authors: + * Hong Jen Yee (PCMan) + * + * 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 DATETIME_H +#define DATETIME_H + +#include + +namespace Ui { +class DateTime; +} + +class DateTime : public QWidget +{ + Q_OBJECT + +public: + explicit DateTime(QWidget *parent = 0); + ~DateTime(); + + enum modified_enum {M_DATE = 0x1, M_TIME = 0x2}; + Q_DECLARE_FLAGS(modified_t, modified_enum) + + QDateTime dateTime() const; + inline modified_t modified() const {return mModified;} + +public Q_SLOTS: + void reload(); + + +private Q_SLOTS: + void on_edit_time_userTimeChanged(const QTime &time); + void timeout(); + void on_calendar_selectionChanged(); + +Q_SIGNALS: + void changed(bool); + +private: + Ui::DateTime *ui; + QTimer * mTimer; + modified_t mModified; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(DateTime::modified_t) + +#endif // DATETIME_H diff --git a/lxqt-admin-time/datetime.ui b/lxqt-admin-time/datetime.ui new file mode 100644 index 0000000..278023e --- /dev/null +++ b/lxqt-admin-time/datetime.ui @@ -0,0 +1,116 @@ + + + DateTime + + + + 0 + 0 + 354 + 308 + + + + + 0 + 0 + + + + Form + + + + + + + 75 + true + + + + Time and date setup + + + + + + + Time: + + + + + + + + 400 + 16777215 + + + + QDateTimeEdit::HourSection + + + HH:mm:ss + + + + + + + + + + Date: + + + + + + + + 400 + 173 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 75 + true + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + + + true + + + + + + + + diff --git a/lxqt-admin-time/lxqt-admin-time.desktop.in b/lxqt-admin-time/lxqt-admin-time.desktop.in new file mode 100644 index 0000000..d739414 --- /dev/null +++ b/lxqt-admin-time/lxqt-admin-time.desktop.in @@ -0,0 +1,11 @@ +[Desktop Entry] +Type=Application +Name=Date and Time +GenericName=Date and Time Settings +Comment=Configure the date and time of your system +Exec=lxqt-admin-time +Icon=preferences-system +Categories=Settings;System;DesktopSettings;Qt;LXQt; +OnlyShowIn=LXQt; + +#TRANSLATIONS_DIR=translations diff --git a/lxqt-admin-time/main.cpp b/lxqt-admin-time/main.cpp new file mode 100644 index 0000000..28ca84f --- /dev/null +++ b/lxqt-admin-time/main.cpp @@ -0,0 +1,39 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * http://lxqt.org + * + * Copyright: 2014 LXQt team + * Authors: + * Hong Jen Yee (PCMan) + * + * 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 "timeadmindialog.h" + +int main(int argc, char **argv) +{ + LxQt::SingleApplication app(argc, argv); + TimeAdminDialog dlg; + dlg.setWindowIcon(QIcon::fromTheme("preferences-system")); + app.setActivationWindow(&dlg); + dlg.show(); + return app.exec(); +} diff --git a/lxqt-admin-time/timeadmindialog.cpp b/lxqt-admin-time/timeadmindialog.cpp new file mode 100644 index 0000000..1a92bcc --- /dev/null +++ b/lxqt-admin-time/timeadmindialog.cpp @@ -0,0 +1,167 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * http://lxqt.org + * + * Copyright: 2014 LXQt team + * Authors: + * Hong Jen Yee (PCMan) + * + * 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 "timeadmindialog.h" +#include +#include +#include +#include +#include + +#include "datetime.h" +#include "timezone.h" + + +#define ZONETAB_PATH "/usr/share/zoneinfo/zone.tab" + +TimeAdminDialog::TimeAdminDialog(QWidget *parent): + LxQt::ConfigDialog(tr("Time and date configuration"),new LxQt::Settings("TimeDate"), parent), + mTimeConfig(OOBS_TIME_CONFIG(oobs_time_config_get())), + mUserLogedIn(false) +{ + oobs_object_update(OOBS_OBJECT(mTimeConfig)); + + setMinimumSize(QSize(400,400)); + mWindowTitle = windowTitle(); + + + mDateTimeWidget = new DateTime(this); + addPage(mDateTimeWidget,tr("Date and time")); + connect(this,SIGNAL(reset()),mDateTimeWidget,SLOT(reload())); + connect(mDateTimeWidget,&DateTime::changed,this,&TimeAdminDialog::onChanged); + mDateTimeWidget->setProperty("pModified",M_TIMEDATE); + + QStringList zones; + QString currentZone; + loadTimeZones(zones,currentZone); + mTimezoneWidget = new Timezone(zones,currentZone,this); + addPage(mTimezoneWidget,tr("Timezone")); + connect(this,&TimeAdminDialog::reset,mTimezoneWidget,&Timezone::reload); + connect(mTimezoneWidget,&Timezone::changed,this,&TimeAdminDialog::onChanged); + mTimezoneWidget->setProperty("pModified",M_TIMEZONE); +} + +TimeAdminDialog::~TimeAdminDialog() +{ + if(mTimeConfig) + g_object_unref(mTimeConfig); +} + +void TimeAdminDialog::onChanged(bool ch) +{ + widgets_modified_enum flag = (widgets_modified_enum) + sender()->property("pModified").toUInt(); + ch ? mWidgetsModified |= flag : mWidgetsModified &= ~flag; + showChangedStar(); +} + + +void TimeAdminDialog::showChangedStar() +{ + if (mWidgetsModified) + setWindowTitle(mWindowTitle + "*"); + else + setWindowTitle(mWindowTitle); +} + +void TimeAdminDialog::closeEvent(QCloseEvent *event) +{ + //save changes to system + if (mWidgetsModified) + { + if (logInUser()) + { + saveChangesToSystem(); + event->accept(); + } + else + { + event->ignore(); + } + } +} + +void TimeAdminDialog::loadTimeZones(QStringList & timeZones, QString & currentTimezone) +{ + timeZones.clear(); + QFile file(ZONETAB_PATH); + if(file.open(QIODevice::ReadOnly)) + { + QByteArray line; + while(!file.atEnd()) + { + line = file.readLine().trimmed(); + if(line.isEmpty() || line[0] == '#') // skip comments or empty lines + continue; + QList items = line.split('\t'); + if(items.length() <= 2) + continue; + timeZones.append(QLatin1String(items[2])); + } + file.close(); + } + currentTimezone = QString::fromLatin1(oobs_time_config_get_timezone(mTimeConfig)); +} + + + +void TimeAdminDialog::saveChangesToSystem() +{ + QByteArray timeZone = mTimezoneWidget->timezone().toLatin1(); + // FIXME: currently timezone settings does not work. is this a bug of system-tools-backend? + if(!timeZone.isEmpty() && mWidgetsModified.testFlag(M_TIMEZONE)) + oobs_time_config_set_timezone(mTimeConfig, timeZone.constData()); + + if(mWidgetsModified.testFlag(M_TIMEDATE)) + { + QDate d = mDateTimeWidget->dateTime().date(); + QTime t = mDateTimeWidget->dateTime().time(); + // oobs seems to use 0 based month + oobs_time_config_set_time(mTimeConfig, d.year(), d.month() - 1, d.day(), t.hour(), t.minute(), t.second()); + } + oobs_object_commit(OOBS_OBJECT(mTimeConfig)); +} + +bool TimeAdminDialog::logInUser() +{ + if (mUserLogedIn) + return true; + + GError* err = NULL; + if(oobs_object_authenticate(OOBS_OBJECT(mTimeConfig), &err)) + { + mUserLogedIn = true; + return true; + } + else if(err) + { + QMessageBox::critical(this, tr("Authentication Error"), QString::fromUtf8(err->message)); + g_error_free(err); + } + + return false; +} diff --git a/lxqt-admin-time/timeadmindialog.h b/lxqt-admin-time/timeadmindialog.h new file mode 100644 index 0000000..0d6cbd2 --- /dev/null +++ b/lxqt-admin-time/timeadmindialog.h @@ -0,0 +1,71 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * http://lxqt.org + * + * Copyright: 2014 LXQt team + * Authors: + * Hong Jen Yee (PCMan) + * + * 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 + +class DateTime; +class Timezone; + +class TimeAdminDialog: public LxQt::ConfigDialog +{ + Q_OBJECT + +public: + TimeAdminDialog(QWidget * parent = NULL) ; + ~TimeAdminDialog(); + + + typedef enum {M_TIMEDATE = 1 , M_TIMEZONE = 0x2} widgets_modified_enum; + Q_DECLARE_FLAGS(widgets_modified_t, widgets_modified_enum) + +protected: + virtual void closeEvent(QCloseEvent * event); + +private Q_SLOTS: + void onChanged(bool); + +private: + bool logInUser(); + void saveChangesToSystem(); + void loadTimeZones(QStringList & timeZones, QString & currentTimezone); + void showChangedStar(); + +private: + OobsTimeConfig* mTimeConfig; + DateTime * mDateTimeWidget; + Timezone * mTimezoneWidget; + bool mUserLogedIn; + QString mWindowTitle; + widgets_modified_t mWidgetsModified; +}; + +Q_DECLARE_METATYPE(TimeAdminDialog::widgets_modified_enum) +Q_DECLARE_OPERATORS_FOR_FLAGS(TimeAdminDialog::widgets_modified_t) diff --git a/lxqt-admin-time/timezone.cpp b/lxqt-admin-time/timezone.cpp new file mode 100644 index 0000000..2be3778 --- /dev/null +++ b/lxqt-admin-time/timezone.cpp @@ -0,0 +1,88 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * http://lxqt.org + * + * Copyright: 2014 LXQt team + * Authors: + * Hong Jen Yee (PCMan) + * + * 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 "timezone.h" +#include "ui_timezone.h" + +Timezone::Timezone(const QStringList & zones, const QString & currentimezone, QWidget *parent) : + QWidget(parent), + ui(new Ui::Timezone), + mZoneChanged(false), + mZonesList(zones) +{ + ui->setupUi(this); + + if (!currentimezone.isEmpty()) + ui->label_timezone->setText(currentimezone); + else + ui->label_timezone->setText(tr("None")); + + mZonesList.sort(); + ui->list_zones->addItems(mZonesList); + + reload(); +} + +Timezone::~Timezone() +{ + delete ui; +} + +void Timezone::reload() +{ + ui->list_zones->setCurrentRow(-1); + mZoneChanged = false; + QList list = ui->list_zones->findItems(ui->label_timezone->text(),Qt::MatchExactly); + if (list.count()) + ui->list_zones->setCurrentItem(list.at(0)); + + emit changed(mZoneChanged); +} + +QString Timezone::timezone() const +{ + if (ui->list_zones->currentItem()) + return ui->list_zones->currentItem()->text(); + else + return QString(); +} + +void Timezone::on_list_zones_itemActivated(QListWidgetItem * item) +{ + bool old = mZoneChanged; + mZoneChanged = item->text() != ui->label_timezone->text(); + + if (mZoneChanged != old) + emit changed(mZoneChanged); +} + +void Timezone::on_edit_filter_textChanged(const QString &arg1) +{ + QRegExp reg(arg1, Qt::CaseInsensitive,QRegExp::Wildcard); + ui->list_zones->clear(); + ui->list_zones->addItems(mZonesList.filter(reg)); +} diff --git a/lxqt-admin-time/timezone.h b/lxqt-admin-time/timezone.h new file mode 100644 index 0000000..072ecb6 --- /dev/null +++ b/lxqt-admin-time/timezone.h @@ -0,0 +1,65 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * http://lxqt.org + * + * Copyright: 2014 LXQt team + * Authors: + * Hong Jen Yee (PCMan) + * + * 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 TIMEZONE_H +#define TIMEZONE_H + +#include + +namespace Ui { +class Timezone; +} + +class QListWidgetItem; +class Timezone : public QWidget +{ + Q_OBJECT + +public: + explicit Timezone(const QStringList & zones, const QString & currentimezone, QWidget *parent = 0); + ~Timezone(); + QString timezone() const; + inline bool isChanged() const {return mZoneChanged;} + +public slots: + void reload(); + +Q_SIGNALS: + void changed(bool); + +private slots: + void on_list_zones_itemActivated(QListWidgetItem *item); + void on_edit_filter_textChanged(const QString &arg1); + +private: + Ui::Timezone *ui; + bool mZoneChanged; + QString mCurrentTimeZone; + QStringList mZonesList; +}; + +#endif // TIMEZONE_H diff --git a/lxqt-admin-time/timezone.ui b/lxqt-admin-time/timezone.ui new file mode 100644 index 0000000..5d26a1c --- /dev/null +++ b/lxqt-admin-time/timezone.ui @@ -0,0 +1,81 @@ + + + Timezone + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + 75 + true + + + + Timezone setup + + + + + + + + + Your current timezone: + + + + + + + TextLabel + + + + + + + + + Filter + + + true + + + + + + + + + + + 75 + true + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + + + true + + + + + + + + diff --git a/lxqt-admin-time/translations/lxqt-admin-time.ts b/lxqt-admin-time/translations/lxqt-admin-time.ts new file mode 100644 index 0000000..ec172cd --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time.ts @@ -0,0 +1,98 @@ + + + + + DateTime + + + Form + + + + + Time and date setup + + + + + Time: + + + + + HH:mm:ss + + + + + Date: + + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + + + + + TimeAdminDialog + + + Time and date configuration + + + + + Date and time + + + + + Timezone + + + + + Authentication Error + + + + + Timezone + + + Form + + + + + Timezone setup + + + + + Your current timezone: + + + + + TextLabel + + + + + Filter + + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + + + + + None + + + + diff --git a/lxqt-admin-time/translations/lxqt-admin-time_it.ts b/lxqt-admin-time/translations/lxqt-admin-time_it.ts new file mode 100644 index 0000000..a8c2224 --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_it.ts @@ -0,0 +1,100 @@ + + + + + DateTime + + + Form + + + + + Time and date setup + Imposta data e ora + + + + Time: + Ora: + + + + HH:mm:ss + + + + + Date: + Data: + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + Il salvataggio richiede privilegi di amministratore, +saranno chiesti dopo la chiusura di questa finestra. + + + + TimeAdminDialog + + + Time and date configuration + Configura data e ora + + + + Date and time + Data e ora + + + + Timezone + Fuso orario + + + + Authentication Error + Errore di autenticazione + + + + Timezone + + + Form + + + + + Timezone setup + Configura fuso orario + + + + Your current timezone: + Fuso orario attuale: + + + + TextLabel + nessuno + + + + Filter + Filtro + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + Il salvataggio richiede privilegi di amministratore, +saranno chiesti dopo la chiusura di questa finestra. + + + + None + + + + diff --git a/lxqt-admin-time/translations/lxqt-admin-time_ja.desktop b/lxqt-admin-time/translations/lxqt-admin-time_ja.desktop new file mode 100644 index 0000000..3d940bb --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_ja.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name[ja]=日時設定 +GenericName[ja]=日時の設定 +Comment[ja]=システムに日付と時刻を設定します + +#TRANSLATIONS_DIR=translations diff --git a/lxqt-admin-time/translations/lxqt-admin-time_ja.ts b/lxqt-admin-time/translations/lxqt-admin-time_ja.ts new file mode 100644 index 0000000..d22a1a0 --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_ja.ts @@ -0,0 +1,98 @@ + + + + + DateTime + + + Form + フォーム + + + + Time and date setup + 日時設定 + + + + Time: + 時刻: + + + + HH:mm:ss + HH:mm:ss + + + + Date: + 日付 + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + <html><head/><body><p>変更の保存には管理権限が必要です。<br>閉じるボタンを押した直後に要求されるでしょう。</p></body></html> + + + + TimeAdminDialog + + + Time and date configuration + 日時設定 + + + + Date and time + 日時 + + + + Timezone + タイムゾーン + + + + Authentication Error + 認証エラー + + + + Timezone + + + Form + フォーム + + + + Timezone setup + タイムゾーン設定 + + + + Your current timezone: + 現在のタイムゾーン + + + + TextLabel + テキストラベル + + + + Filter + フィルター + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + <html><head/><body><p>変更の保存には管理権限が必要です。<br>閉じるボタンを押した直後に要求されるでしょう。</p></body></html> + + + + None + なし + + + diff --git a/lxqt-admin-time/translations/lxqt-admin-time_pt.desktop b/lxqt-admin-time/translations/lxqt-admin-time_pt.desktop new file mode 100644 index 0000000..04ee1aa --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_pt.desktop @@ -0,0 +1,4 @@ +#TRANSLATIONS +Name[pt]=Data e hora +GenericName[pt]=Definições de data e hora +Comment[pt]=Configurar a data e a hora do seu sistema diff --git a/lxqt-admin-time/translations/lxqt-admin-time_pt.ts b/lxqt-admin-time/translations/lxqt-admin-time_pt.ts new file mode 100644 index 0000000..b19df01 --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_pt.ts @@ -0,0 +1,98 @@ + + + + + DateTime + + + Form + Formulário + + + + Time and date setup + Configuração de data e hora + + + + Time: + Hora: + + + + HH:mm:ss + H:mm:ss + + + + Date: + Data: + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + <html><head/><body><p>A gravação de alterações requer permissões de administrador.<br>A senha será solicitada ao clicar em Fechar.</p></body></html> + + + + TimeAdminDialog + + + Time and date configuration + Configuração de data e hora + + + + Date and time + Data e hora + + + + Timezone + Fuso horário + + + + Authentication Error + Erro de autenticação + + + + Timezone + + + Form + Formulário + + + + Timezone setup + Configuração de fuso horário + + + + Your current timezone: + O seu fuso horário: + + + + TextLabel + Texto + + + + Filter + Filtrar + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + <html><head/><body><p>A gravação de alterações requer permissões de administrador.<br>A senha será solicitada ao clicar em Fechar.</p></body></html> + + + + None + Nenhum + + + diff --git a/lxqt-admin-time/translations/lxqt-admin-time_ru.desktop b/lxqt-admin-time/translations/lxqt-admin-time_ru.desktop new file mode 100644 index 0000000..5cbd032 --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_ru.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name[ru]=Дата и время +GenericName[ru]=Настройки даты и времени +Comment[ru]=Настроить дату и время вашей системы + +#TRANSLATIONS_DIR=translations diff --git a/lxqt-admin-time/translations/lxqt-admin-time_ru.ts b/lxqt-admin-time/translations/lxqt-admin-time_ru.ts new file mode 100644 index 0000000..943422a --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_ru.ts @@ -0,0 +1,83 @@ + + + + + DateTime + + + Time and date setup + Настройка даты и времени + + + + Time: + Время: + + + + HH:mm:ss + ЧЧ:мм:сс + + + + Date: + Дата: + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + <html><head/><body><p>Для сохранения изменений необходимы права администратора.<br>Пароль будет запрошен после нажатия на кнопку «Закрыть»</p></body></html> + + + + TimeAdminDialog + + + Time and date configuration + Настройки даты и времени + + + + Date and time + Дата и время + + + + Timezone + Часовой пояс + + + + Authentication Error + Ошибка аутентификации + + + + Timezone + + + Timezone setup + Настройки часового пояса + + + + Your current timezone: + Ваш текущий часовой пояс: + + + + Filter + Фильтр + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + <html><head/><body><p>Для сохранения изменений необходимы права администратора.<br>Пароль будет запрошен после нажатия на кнопку «Закрыть»</p></body></html> + + + + None + Нет + + + diff --git a/lxqt-admin-time/translations/lxqt-admin-time_ru_RU.desktop b/lxqt-admin-time/translations/lxqt-admin-time_ru_RU.desktop new file mode 100644 index 0000000..fdf42d9 --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_ru_RU.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name[ru_RU]=Дата и время +GenericName[ru_RU]=Настройки даты и времени +Comment[ru_RU]=Настроить дату и время вашей системы + +#TRANSLATIONS_DIR=translations diff --git a/lxqt-admin-time/translations/lxqt-admin-time_ru_RU.ts b/lxqt-admin-time/translations/lxqt-admin-time_ru_RU.ts new file mode 100644 index 0000000..e3c6e68 --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-time_ru_RU.ts @@ -0,0 +1,83 @@ + + + + + DateTime + + + Time and date setup + Настройка даты и времени + + + + Time: + Время: + + + + HH:mm:ss + ЧЧ:мм:сс + + + + Date: + Дата: + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + <html><head/><body><p>Для сохранения изменений необходимы права администратора.<br>Пароль будет запрошен после нажатия на кнопку «Закрыть»</p></body></html> + + + + TimeAdminDialog + + + Time and date configuration + Настройки даты и времени + + + + Date and time + Дата и время + + + + Timezone + Часовой пояс + + + + Authentication Error + Ошибка аутентификации + + + + Timezone + + + Timezone setup + Настройки часового пояса + + + + Your current timezone: + Ваш текущий часовой пояс: + + + + Filter + Фильтр + + + + <html><head/><body><p>Saving changes requires admin permissions.<br>You will be requested after clicking close button</p></body></html> + <html><head/><body><p>Для сохранения изменений необходимы права администратора.<br>Пароль будет запрошен после нажатия на кнопку «Закрыть»</p></body></html> + + + + None + Нет + + + diff --git a/lxqt-admin-time/translations/lxqt-admin-user_it.desktop b/lxqt-admin-time/translations/lxqt-admin-user_it.desktop new file mode 100644 index 0000000..0055993 --- /dev/null +++ b/lxqt-admin-time/translations/lxqt-admin-user_it.desktop @@ -0,0 +1,13 @@ +[Desktop Entry] +Type=Application +Name=Users and Groups +GenericName=User and Group Settings +Comment=Configure the users and groups of your system +Exec=lxqt-admin-user +Icon=preferences-system +Categories=Settings;System;DesktopSettings;Qt;LXQt; +OnlyShowIn=LXQt; + +Name[it]=Utenti e gruppi +GenericName[it]=Impostazioni utenti e gruppi +Comment[it]=Configura utenti e gruppi del sistema diff --git a/lxqt-admin-user/CMakeLists.txt b/lxqt-admin-user/CMakeLists.txt new file mode 100644 index 0000000..8ff00e6 --- /dev/null +++ b/lxqt-admin-user/CMakeLists.txt @@ -0,0 +1,68 @@ +project(lxqt-admin-user) + +# build static helper class first +include_directories ( + ${CMAKE_CURRENT_BINARY_DIR} + ${LXQT_INCLUDE_DIRS} + ${QTXDG_INCLUDE_DIRS} + ${OOBS_INCLUDE_DIRS} +) + +set ( lxqt-admin-user_SRCS + main.cpp + mainwindow.cpp + userdialog.cpp + groupdialog.cpp +) + +set ( lxqt-admin-user_MOCS + mainwindow.h + userdialog.h + groupdialog.h +) + +set( lxqt-admin-user_UIS + mainwindow.ui + userdialog.ui + groupdialog.ui +) + +qt5_wrap_cpp(MOCS ${lxqt-admin-user_MOCS}) +qt5_wrap_ui(UIS ${lxqt-admin-user_UIS}) + +# Translations ********************************** +lxqt_translate_ts(lxqt-admin-user_QM_FILES + UPDATE_TRANSLATIONS ${UPDATE_TRANSLATIONS} + SOURCES + ${lxqt-admin-user_MOCS} + ${lxqt-admin-user_SRCS} + ${lxqt-admin-user_UIS} + INSTALL_DIR + "${LXQT_TRANSLATIONS_DIR}/${PROJECT_NAME}" +) + +lxqt_translate_desktop(DESKTOP_FILES + SOURCES + lxqt-admin-user.desktop.in +) +lxqt_app_translation_loader(lxqt-admin-user_QM_LOADER ${PROJECT_NAME}) +#************************************************ + +add_executable(lxqt-admin-user + ${lxqt-admin-user_SRCS} + ${UIS} + ${MOCS} + ${DESKTOP_FILES} + ${lxqt-admin-user_QM_FILES} + ${lxqt-admin-user_QM_LOADER} +) + +target_link_libraries(lxqt-admin-user + KF5::WindowSystem + Qt5::Widgets + ${LXQT_LIBRARIES} + ${OOBS_LIBRARIES} +) + +install(TARGETS lxqt-admin-user RUNTIME DESTINATION bin) +install(FILES ${DESKTOP_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) diff --git a/lxqt-admin-user/groupdialog.cpp b/lxqt-admin-user/groupdialog.cpp new file mode 100644 index 0000000..e3c07ab --- /dev/null +++ b/lxqt-admin-user/groupdialog.cpp @@ -0,0 +1,127 @@ +/* + * + * Copyright (C) 2014 Hong Jen Yee (PCMan) + * + * 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 + * + */ + +#include "groupdialog.h" +#include + +GroupDialog::GroupDialog(OobsGroup *group, QWidget *parent, Qt::WindowFlags f): + QDialog(parent, f), + mGroup(group ? OOBS_GROUP(g_object_ref(group)) : NULL) +{ + ui.setupUi(this); + + OobsGroupsConfig* groupsConfig = OOBS_GROUPS_CONFIG(oobs_groups_config_get()); + if(group) // edit an exiting group + { + ui.groupName->setReadOnly(true); + ui.groupName->setText(oobs_group_get_name(group)); + mOldGId = oobs_group_get_gid(group); + ui.gid->setValue(mOldGId); + } + else // create a new group + { + mOldGId = -1; + ui.gid->setValue(oobs_groups_config_find_free_gid(groupsConfig, 0, 32768)); + } + + GList* groupUsers = oobs_group_get_users(mGroup); // all users in this group + // load all users + OobsUsersConfig* usersConfig = OOBS_USERS_CONFIG(oobs_users_config_get()); + OobsList* users = oobs_users_config_get_users(usersConfig); + if(users) + { + OobsListIter it; + gboolean valid = oobs_list_get_iter_first(users, &it); + while(valid) + { + OobsUser* user = OOBS_USER(oobs_list_get(users, &it)); + QListWidgetItem* item = new QListWidgetItem(); + item->setText(oobs_user_get_login_name(user)); + item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsUserCheckable|Qt::ItemIsSelectable); + if(g_list_find(groupUsers, user)) // the user is in this group + item->setCheckState(Qt::Checked); + else + item->setCheckState(Qt::Unchecked); + QVariant obj = QVariant::fromValue(user); + item->setData(Qt::UserRole, obj); + ui.userList->addItem(item); + valid = oobs_list_iter_next(users, &it); + } + } + g_list_free(groupUsers); +} + +GroupDialog::~GroupDialog() +{ + if(mGroup) + g_object_unref(mGroup); +} + +void GroupDialog::accept() +{ + OobsGroupsConfig* groupsConfig = OOBS_GROUPS_CONFIG(oobs_groups_config_get()); + gid_t gid = ui.gid->value(); + if(gid != mOldGId && oobs_groups_config_is_gid_used(groupsConfig, gid)) + { + QMessageBox::critical(this, tr("Error"), tr("The group ID is in use.")); + return; + } + + if(!mGroup) // create a new group + { + QByteArray groupName = ui.groupName->text().toLatin1(); + if(groupName.isEmpty()) + { + QMessageBox::critical(this, tr("Error"), tr("The group name cannot be empty.")); + return; + } + if(oobs_groups_config_is_name_used(groupsConfig, groupName)) + { + QMessageBox::critical(this, tr("Error"), tr("The group name is in use.")); + return; + } + mGroup = oobs_group_new(groupName); + } + oobs_group_set_gid(mGroup, gid); + + // update users + GList* groupUsers = oobs_group_get_users(mGroup); // all users in this group + int rowCount = ui.userList->count(); + for(int row = 0; row < rowCount; ++row) + { + QListWidgetItem* item = ui.userList->item(row); + QVariant obj = item->data(Qt::UserRole); + OobsUser* user = OOBS_USER(obj.value()); + if(g_list_find(groupUsers, user)) // the user belongs to this group previously + { + if(item->checkState() == Qt::Unchecked) // it's unchecked, remove it + oobs_group_remove_user(mGroup, user); + } + else // the user does not belong to this group previously + { + if(item->checkState() == Qt::Checked) // it's checked, we want it! + oobs_group_add_user(mGroup, user); + } + } + g_list_free(groupUsers); + + oobs_object_commit(OOBS_OBJECT(mGroup)); + QDialog::accept(); +} diff --git a/lxqt-admin-user/groupdialog.h b/lxqt-admin-user/groupdialog.h new file mode 100644 index 0000000..3726a2c --- /dev/null +++ b/lxqt-admin-user/groupdialog.h @@ -0,0 +1,54 @@ +/* + * + * Copyright (C) 2014 Hong Jen Yee (PCMan) + * + * 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 + * + */ + +#ifndef GROUPDIALOG_H +#define GROUPDIALOG_H + +#include +#include "ui_groupdialog.h" +#include +#include +#include + +class GroupDialog : public QDialog +{ + Q_OBJECT + +public: + GroupDialog(OobsGroup* group = NULL, QWidget *parent = NULL, Qt::WindowFlags f = 0); + ~GroupDialog(); + + OobsGroup* group() + { + return mGroup; + } + + virtual void accept(); + +private: + bool hasUser(OobsUser* user); + +private: + Ui::GroupDialog ui; + OobsGroup* mGroup; + gid_t mOldGId; +}; + +#endif // GROUPDIALOG_H diff --git a/lxqt-admin-user/groupdialog.ui b/lxqt-admin-user/groupdialog.ui new file mode 100644 index 0000000..3010c10 --- /dev/null +++ b/lxqt-admin-user/groupdialog.ui @@ -0,0 +1,105 @@ + + + GroupDialog + + + + 0 + 0 + 400 + 360 + + + + Group Settings + + + + + + Group name: + + + + + + + + + + 32768 + + + + + + + Group ID: + + + + + + + Users belong to this group: + + + + + + + + 0 + 1 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + GroupDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + GroupDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/lxqt-admin-user/lxqt-admin-user.desktop.in b/lxqt-admin-user/lxqt-admin-user.desktop.in new file mode 100644 index 0000000..d40aaf6 --- /dev/null +++ b/lxqt-admin-user/lxqt-admin-user.desktop.in @@ -0,0 +1,11 @@ +[Desktop Entry] +Type=Application +Name=Users and Groups +GenericName=User and Group Settings +Comment=Configure the users and groups of your system +Exec=lxqt-admin-user +Icon=preferences-system +Categories=Settings;System;DesktopSettings;Qt;LXQt; +OnlyShowIn=LXQt; + +#TRANSLATIONS_DIR=translations diff --git a/lxqt-admin-user/main.cpp b/lxqt-admin-user/main.cpp new file mode 100644 index 0000000..98feaae --- /dev/null +++ b/lxqt-admin-user/main.cpp @@ -0,0 +1,39 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * (c)LGPL2+ + * + * LXQt - a lightweight, Qt based, desktop toolset + * http://lxqt.org + * + * Copyright: 2014 LXQt team + * Authors: + * Hong Jen Yee (PCMan) + * + * 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 app(argc, argv); + MainWindow window; + window.setWindowIcon(QIcon::fromTheme("preferences-system")); + app.setActivationWindow(&window); + window.show(); + return app.exec(); +} diff --git a/lxqt-admin-user/mainwindow.cpp b/lxqt-admin-user/mainwindow.cpp new file mode 100644 index 0000000..1cce210 --- /dev/null +++ b/lxqt-admin-user/mainwindow.cpp @@ -0,0 +1,249 @@ +/* + * + * Copyright (C) 2014 Hong Jen Yee (PCMan) + * + * 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 + * + */ + +#include "mainwindow.h" +#include +#include +#include "userdialog.h" +#include "groupdialog.h" + +MainWindow::MainWindow(): + QMainWindow(), + mUsersConfig(OOBS_USERS_CONFIG(oobs_users_config_get())), + mGroupsConfig(OOBS_GROUPS_CONFIG(oobs_groups_config_get())) +{ + ui.setupUi(this); + connect(ui.actionAdd, SIGNAL(triggered(bool)), SLOT(onAdd())); + connect(ui.actionDelete, SIGNAL(triggered(bool)), SLOT(onDelete())); + connect(ui.actionProperties, SIGNAL(triggered(bool)), SLOT(onEditProperties())); + connect(ui.actionRefresh, SIGNAL(triggered(bool)), SLOT(onRefresh())); + + onRefresh(); // load the settings + + g_signal_connect(mUsersConfig, "changed" , G_CALLBACK(onUsersConfigChanged), this); + g_signal_connect(mGroupsConfig, "changed" , G_CALLBACK(onGroupsConfigChanged), this); +} + +MainWindow::~MainWindow() +{ + if(mUsersConfig) + { + g_signal_handlers_disconnect_by_func(mUsersConfig, (void*)G_CALLBACK(onUsersConfigChanged), this); + g_object_unref(mUsersConfig); + } + if(mGroupsConfig) + g_object_unref(mGroupsConfig); +} + +void MainWindow::loadUsers() +{ + ui.userList->clear(); + OobsList* users = oobs_users_config_get_users(mUsersConfig); + if(users) + { + OobsListIter it; + gboolean valid = oobs_list_get_iter_first(users, &it); + while(valid) + { + GObject* obj = oobs_list_get(users, &it); + OobsUser* user = OOBS_USER(obj); + uid_t uid = oobs_user_get_uid(user); + if(uid > 499 && oobs_user_get_shell(user)) // exclude system users + { + QString fullName = QString::fromUtf8(oobs_user_get_full_name(user)); + QString loginName = QString::fromLatin1(oobs_user_get_login_name(user)); + QString homeDir = QString::fromLocal8Bit(oobs_user_get_home_directory(user)); + QString groupName; + OobsGroup* group = oobs_user_get_main_group(user); + if(group) + groupName = QString::fromLatin1(oobs_group_get_name(group)); + + QTreeWidgetItem* item = new QTreeWidgetItem(); + item->setData(0, Qt::DisplayRole, loginName); + QVariant obj = QVariant::fromValue(user); + item->setData(0, Qt::UserRole, obj); + item->setData(1, Qt::DisplayRole, uid); + item->setData(2, Qt::DisplayRole, fullName); + item->setData(3, Qt::DisplayRole, groupName); + item->setData(4, Qt::DisplayRole, homeDir); + ui.userList->addTopLevelItem(item); + } + valid = oobs_list_iter_next(users, &it); + } + } +} + +void MainWindow::loadGroups() +{ + ui.groupList->clear(); + // load groups + OobsList* groups = oobs_groups_config_get_groups(mGroupsConfig); + if(groups) + { + OobsListIter it; + gboolean valid = oobs_list_get_iter_first(groups, &it); + while(valid) + { + OobsGroup* group = OOBS_GROUP(oobs_list_get(groups, &it)); + QTreeWidgetItem* item = new QTreeWidgetItem(); + item->setData(0, Qt::DisplayRole, QString::fromLatin1(oobs_group_get_name(group))); + QVariant obj = QVariant::fromValue(group); + item->setData(0, Qt::UserRole, obj); + item->setData(1, Qt::DisplayRole, oobs_group_get_gid(group)); + ui.groupList->addTopLevelItem(item); + valid = oobs_list_iter_next(groups, &it); + } + } +} + +OobsUser *MainWindow::userFromItem(QTreeWidgetItem *item) +{ + if(item) + { + QVariant obj = item->data(0, Qt::UserRole); + OobsUser* user = OOBS_USER(obj.value()); + return user; + } + return NULL; +} + +OobsGroup* MainWindow::groupFromItem(QTreeWidgetItem *item) +{ + if(item) + { + QVariant obj = item->data(0, Qt::UserRole); + return OOBS_GROUP(obj.value()); + } + return NULL; +} + +template +bool MainWindow::authenticate(T *obj) +{ + GError* err = NULL; + if(!oobs_object_authenticate(OOBS_OBJECT(obj), &err)) + { + if(err) + { + QMessageBox::critical(this, tr("Error"), QString::fromUtf8(err->message)); + g_error_free(err); + } + return false; + } + return true; +} + +void MainWindow::onAdd() +{ + if(ui.tabWidget->currentIndex() == PageUsers) + { + if(authenticate(mUsersConfig)) + { + UserDialog dlg(NULL, this); + if(dlg.exec() == QDialog::Accepted) + { + OobsUser* user = dlg.user(); + oobs_users_config_add_user(mUsersConfig, user); + oobs_object_commit(OOBS_OBJECT(mUsersConfig)); + } + } + } + else if (ui.tabWidget->currentIndex() == PageGroups) + { + if(authenticate(mGroupsConfig)) + { + GroupDialog dlg(NULL, this); + if(dlg.exec() == QDialog::Accepted) + { + OobsGroup* group = dlg.group(); + oobs_groups_config_add_group(mGroupsConfig, group); + oobs_object_commit(OOBS_OBJECT(mGroupsConfig)); + } + } + } +} + +void MainWindow::onDelete() +{ + if(ui.tabWidget->currentIndex() == PageUsers) + { + QTreeWidgetItem* item = ui.userList->currentItem(); + OobsUser* user = userFromItem(item); + if(user) + { + if(QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to delete the selected user?"), QMessageBox::Ok|QMessageBox::Cancel) == QMessageBox::Ok) + { + oobs_users_config_delete_user(mUsersConfig, user); + oobs_object_commit(OOBS_OBJECT(mUsersConfig)); + } + } + } + else if(ui.tabWidget->currentIndex() == PageGroups) + { + QTreeWidgetItem* item = ui.groupList->currentItem(); + OobsGroup* group = groupFromItem(item); + if(group) + { + if(QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to delete the selected group?"), QMessageBox::Ok|QMessageBox::Cancel) == QMessageBox::Ok) + { + oobs_groups_config_delete_group(mGroupsConfig, group); + oobs_object_commit(OOBS_OBJECT(mGroupsConfig)); + } + } + } +} + +void MainWindow::onEditProperties() +{ + if(ui.tabWidget->currentIndex() == PageUsers) + { + QTreeWidgetItem* item = ui.userList->currentItem(); + OobsUser* user = userFromItem(item); + if(user) + { + if(authenticate(mUsersConfig)) + { + UserDialog dlg(user, this); + dlg.exec(); + } + } + } + else if(ui.tabWidget->currentIndex() == PageGroups) + { + QTreeWidgetItem* item = ui.groupList->currentItem(); + OobsGroup* group = groupFromItem(item); + if(group) + { + if(authenticate(mGroupsConfig)) + { + GroupDialog dlg(group, this); + dlg.exec(); + } + } + } +} + +void MainWindow::onRefresh() +{ + oobs_object_update(OOBS_OBJECT(mUsersConfig)); + loadUsers(); + oobs_object_update(OOBS_OBJECT(mGroupsConfig)); + loadGroups(); +} diff --git a/lxqt-admin-user/mainwindow.h b/lxqt-admin-user/mainwindow.h new file mode 100644 index 0000000..79fd24b --- /dev/null +++ b/lxqt-admin-user/mainwindow.h @@ -0,0 +1,77 @@ +/* + * + * Copyright (C) 2014 Hong Jen Yee (PCMan) + * + * 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 + * + */ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "ui_mainwindow.h" + +#include +#include +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + enum + { + PageUsers = 0, + PageGroups + }; + +public: + explicit MainWindow(); + virtual ~MainWindow(); + +private: + void loadUsers(); + void loadGroups(); + OobsUser* userFromItem(QTreeWidgetItem* item); + OobsGroup* groupFromItem(QTreeWidgetItem *item); + + template + bool authenticate(T* obj); + + static void onUsersConfigChanged(OobsObject* obj, MainWindow* _this) + { + _this->loadUsers(); + } + + static void onGroupsConfigChanged(OobsObject* obj, MainWindow* _this) + { + _this->loadGroups(); + } + +private Q_SLOTS: + void onAdd(); + void onDelete(); + void onEditProperties(); + void onRefresh(); + +private: + Ui::MainWindow ui; + OobsUsersConfig* mUsersConfig; + OobsGroupsConfig* mGroupsConfig; +}; + +#endif // MAINWINDOW_H diff --git a/lxqt-admin-user/mainwindow.ui b/lxqt-admin-user/mainwindow.ui new file mode 100644 index 0000000..37e505b --- /dev/null +++ b/lxqt-admin-user/mainwindow.ui @@ -0,0 +1,195 @@ + + + MainWindow + + + + 0 + 0 + 640 + 480 + + + + User and Group Settings + + + + + 0 + + + + + 0 + + + true + + + + &Users + + + + + + false + + + false + + + false + + + false + + + + Login Name + + + + + User ID + + + + + Full Name + + + + + Group + + + + + Home Directory + + + + + + + + false + + + Show system users (for advanced users only) + + + + + + + + &Groups + + + + + + false + + + false + + + + Name + + + + + Group ID + + + + + + + + + + + + + toolBar + + + false + + + Qt::ToolButtonTextBesideIcon + + + TopToolBarArea + + + false + + + + + + + + + + + + + + + Add + + + Add new users or groups + + + + + + + + + + Delete + + + Delete selected item + + + + + + + + + + Properties + + + edit properties of the selected item + + + + + + + + + + Refresh + + + Refresh the lists + + + + + + diff --git a/lxqt-admin-user/translations/lxqt-admin-user.ts b/lxqt-admin-user/translations/lxqt-admin-user.ts new file mode 100644 index 0000000..b21e617 --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user.ts @@ -0,0 +1,263 @@ + + + + + GroupDialog + + + Group Settings + + + + + Group name: + + + + + Group ID: + + + + + Users belong to this group: + + + + + + + Error + + + + + The group ID is in use. + + + + + The group name cannot be empty. + + + + + The group name is in use. + + + + + MainWindow + + + User and Group Settings + + + + + &Users + + + + + Login Name + + + + + User ID + + + + + Full Name + + + + + Group + + + + + Home Directory + + + + + Show system users (for advanced users only) + + + + + &Groups + + + + + Name + + + + + Group ID + + + + + toolBar + + + + + Add + + + + + Add new users or groups + + + + + Delete + + + + + Delete selected item + + + + + Properties + + + + + edit properties of the selected item + + + + + Refresh + + + + + Refresh the lists + + + + + Error + + + + + + Confirm + + + + + Are you sure you want to delete the selected user? + + + + + Are you sure you want to delete the selected group? + + + + + UserDialog + + + User Settings + + + + + General + + + + + Full name: + + + + + Login name: + + + + + Set password: + + + + + User ID: + + + + + Main group: + + + + + Advanced + + + + + Login shell: + + + + + Home directory: + + + + + Change password: + + + + + + + Error + + + + + The user ID is in use. + + + + + The user name cannot be empty. + + + + + The user name is in use. + + + + + Confirm + + + + + Are you sure you want to use an "empty password" for the user? + + + + diff --git a/lxqt-admin-user/translations/lxqt-admin-user_it.ts b/lxqt-admin-user/translations/lxqt-admin-user_it.ts new file mode 100644 index 0000000..5a71d1c --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_it.ts @@ -0,0 +1,264 @@ + + + + + GroupDialog + + + Group Settings + Gestione gruppi + + + + Group name: + Nome del gruppo: + + + + Group ID: + ID gruppo: + + + + Users belong to this group: + Utenti appartenenti: + + + + + + Error + Errore + + + + The group ID is in use. + ID già in uso + + + + The group name cannot be empty. + Il nome non può essere vuoto. + + + + The group name is in use. + Il nome è già in uso. + + + + MainWindow + + + User and Group Settings + Impostazioni utenti e gruppi + + + + &Users + remove &_ in source + Utenti + + + + Login Name + Nome Login + + + + User ID + ID utente + + + + Full Name + Nome completo + + + + Group + Gruppo + + + + Home Directory + Cartella Home + + + + Show system users (for advanced users only) + Mostra utenti di sistema (avanzato) + + + + &Groups + Gruppi + + + + Name + Nome + + + + Group ID + ID gruppo + + + + toolBar + + + + + Add + Aggiungi + + + + Add new users or groups + Aggiungi utenti o gruppi nuovi + + + + Delete + Cancella + + + + Delete selected item + Cancella selezionato + + + + Properties + Proprietà + + + + edit properties of the selected item + Modifica proprietà + + + + Refresh + Aggiorna + + + + Refresh the lists + Aggiorna lista + + + + Error + Errore + + + + + Confirm + Conferma + + + + Are you sure you want to delete the selected user? + Si è sicuro di voler cancellare l'utente selezionato? + + + + Are you sure you want to delete the selected group? + Si è sicuro di voler cancellare il gruppo selezionato? + + + + UserDialog + + + User Settings + Impostazioni utente + + + + General + Generali + + + + Full name: + Nome completo: + + + + Login name: + Nome al Login: + + + + Set password: + Scegli il password: + + + + User ID: + ID utente + + + + Main group: + Gruppo principale: + + + + Advanced + Avanzate: + + + + Login shell: + Shell del login: + + + + Home directory: + Cartella home: + + + + Change password: + Cambia password: + + + + + + Error + Errore + + + + The user ID is in use. + ID già in uso. + + + + The user name cannot be empty. + Il nome non può essere vuoto. + + + + The user name is in use. + Il nome è già in uso. + + + + Confirm + Conferma + + + + Are you sure you want to use an "empty password" for the user? + Si è sicuro di volere un password vuoto per l'utente? + + + diff --git a/lxqt-admin-user/translations/lxqt-admin-user_ja.desktop b/lxqt-admin-user/translations/lxqt-admin-user_ja.desktop new file mode 100644 index 0000000..412c497 --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_ja.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name[ja]=ユーザーとグループ +GenericName[ja]=ユーザーとグループの設定 +Comment[ja]=システム上のユーザーとグループを設定します + +#TRANSLATIONS_DIR=translations diff --git a/lxqt-admin-user/translations/lxqt-admin-user_ja.ts b/lxqt-admin-user/translations/lxqt-admin-user_ja.ts new file mode 100644 index 0000000..c26805c --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_ja.ts @@ -0,0 +1,263 @@ + + + + + GroupDialog + + + Group Settings + グループ設定 + + + + Group name: + グループ名: + + + + Group ID: + グループID: + + + + Users belong to this group: + このグループに属しているユーザー: + + + + + + Error + エラー + + + + The group ID is in use. + そのグループIDはすでに使われています + + + + The group name cannot be empty. + グループ名を入力する必要があります + + + + The group name is in use. + そのグループ名はすでに使われています + + + + MainWindow + + + User and Group Settings + ユーザーとグループの設定 + + + + &Users + ユーザー(&U) + + + + Login Name + ログイン名 + + + + User ID + ユーザーID + + + + Full Name + フルネーム + + + + Group + グループ + + + + Home Directory + ホームディレクトリー + + + + Show system users (for advanced users only) + システムユーザーを表示(上級者専用) + + + + &Groups + グループ(&G) + + + + Name + 名前 + + + + Group ID + グループID + + + + toolBar + ツールバー + + + + Add + 追加 + + + + Add new users or groups + 新しいユーザーまたはグループを追加 + + + + Delete + 削除 + + + + Delete selected item + 選択した項目を削除 + + + + Properties + プロパティー + + + + edit properties of the selected item + 選択した項目のプロパティーを編集 + + + + Refresh + 再読込み + + + + Refresh the lists + リストを再読込み + + + + Error + エラー + + + + + Confirm + 確認 + + + + Are you sure you want to delete the selected user? + 本当に、選択したユーザーを削除してよいですか? + + + + Are you sure you want to delete the selected group? + 本当に、選択したグループを削除してよいですか? + + + + UserDialog + + + User Settings + ユーザー設定 + + + + General + 一般 + + + + Full name: + フルネーム: + + + + Login name: + ログイン名: + + + + Set password: + パスワードを設定: + + + + User ID: + ユーザーID: + + + + Main group: + メイングループ: + + + + Advanced + 高度 + + + + Login shell: + ログインシェル: + + + + Home directory: + ホームディレクトリー: + + + + Change password: + パスワードを変更: + + + + + + Error + エラー + + + + The user ID is in use. + そのユーザーIDはすでに使われています + + + + The user name cannot be empty. + ユーザー名を入力する必要があります + + + + The user name is in use. + そのユーザー名はすでに使われています + + + + Confirm + 確認 + + + + Are you sure you want to use an "empty password" for the user? + 本当に、空のパスワードをそのユーザーに設定してよいですか? + + + diff --git a/lxqt-admin-user/translations/lxqt-admin-user_pt.desktop b/lxqt-admin-user/translations/lxqt-admin-user_pt.desktop new file mode 100644 index 0000000..d4beb04 --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_pt.desktop @@ -0,0 +1,4 @@ +#TRANSLATIONS +Name[pt]=Utilizadores e grupos +GenericName[pt]=Definições de utilizadores e grupos +Comment[pt]=Configurar os utilizadores e os grupos do seu sistema diff --git a/lxqt-admin-user/translations/lxqt-admin-user_pt.ts b/lxqt-admin-user/translations/lxqt-admin-user_pt.ts new file mode 100644 index 0000000..c3eb94e --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_pt.ts @@ -0,0 +1,263 @@ + + + + + GroupDialog + + + Group Settings + Definições de grupo + + + + Group name: + Nome do grupo: + + + + Group ID: + ID do grupo: + + + + Users belong to this group: + Utilizadores pertencentes a este grupo: + + + + + + Error + Erro + + + + The group ID is in use. + O ID do grupo já está em utilização. + + + + The group name cannot be empty. + O nome do grupo não pode estar vazio. + + + + The group name is in use. + O nome do grupo já está em utilização. + + + + MainWindow + + + User and Group Settings + Definições de grupo e utilizador + + + + &Users + &Utilizadores + + + + Login Name + Nome de acesso + + + + User ID + ID de utilizador + + + + Full Name + Nome completo + + + + Group + Grupo + + + + Home Directory + Pasta pessoal + + + + Show system users (for advanced users only) + Mostrar utilizadores de sistema + + + + &Groups + &Grupos + + + + Name + Nome + + + + Group ID + ID do grupo + + + + toolBar + Barra de ferramentas + + + + Add + Adicionar + + + + Add new users or groups + Adicionar utilizadores ou grupos + + + + Delete + Eliminar + + + + Delete selected item + Eliminar item selecionado + + + + Properties + Propriedades + + + + edit properties of the selected item + Editar propriedades do item selecionado + + + + Refresh + Atualizar + + + + Refresh the lists + Atualizar as listas + + + + Error + Erro + + + + + Confirm + Confirmação + + + + Are you sure you want to delete the selected user? + Tem a certeza que quer eliminar o utilizador selecionado? + + + + Are you sure you want to delete the selected group? + Tem a certeza que quer eliminar o grupo selecionado? + + + + UserDialog + + + User Settings + Definições de utilizador + + + + General + Geral + + + + Full name: + Nome completo: + + + + Login name: + Nome de acesso: + + + + Set password: + Definir senha: + + + + User ID: + ID de utilizador: + + + + Main group: + Grupo principal: + + + + Advanced + Avançado + + + + Login shell: + Consola de acesso: + + + + Home directory: + Pasta pessoal: + + + + Change password: + Mudar senha: + + + + + + Error + Erro + + + + The user ID is in use. + O ID do utilizador já está em utilização. + + + + The user name cannot be empty. + O nome de utilizador não pode estar vazio. + + + + The user name is in use. + O nome de utilizador já está em utilização. + + + + Confirm + Confirmação + + + + Are you sure you want to use an "empty password" for the user? + Tem a certeza que quer definir uma senha vazia para o utilizador? + + + diff --git a/lxqt-admin-user/translations/lxqt-admin-user_ru.desktop b/lxqt-admin-user/translations/lxqt-admin-user_ru.desktop new file mode 100644 index 0000000..5ad8baf --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_ru.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name[ru]=Пользователи и группы +GenericName[ru]=Настройки пользователей и групп +Comment[ru]=Настроить пользователей и группы вашей системы + +#TRANSLATIONS_DIR=translations diff --git a/lxqt-admin-user/translations/lxqt-admin-user_ru.ts b/lxqt-admin-user/translations/lxqt-admin-user_ru.ts new file mode 100644 index 0000000..b20efea --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_ru.ts @@ -0,0 +1,263 @@ + + + + + GroupDialog + + + Group Settings + Настройки группы + + + + Group name: + Имя группы: + + + + Group ID: + ID группы: + + + + Users belong to this group: + Пользователи, относящиеся к этой группе: + + + + + + Error + Ошибка + + + + The group ID is in use. + ID группы уже используется. + + + + The group name cannot be empty. + Имя группы не может быть пустым. + + + + The group name is in use. + Имя группы уже используется. + + + + MainWindow + + + User and Group Settings + Настройки пользователя и группы + + + + &Users + &Пользователи + + + + Login Name + Логин пользователя + + + + User ID + ID пользователя + + + + Full Name + Полное имя + + + + Group + Группа + + + + Home Directory + Домашний каталог + + + + Show system users (for advanced users only) + Показывать системных пользователей (только для продвинутых пользователей) + + + + &Groups + &Группы + + + + Name + Имя + + + + Group ID + ID группы + + + + toolBar + Панель + + + + Add + Добавить + + + + Add new users or groups + Добавить новых пользователей или группы + + + + Delete + Удалить + + + + Delete selected item + Удалить выбранный элемент + + + + Properties + Свойства + + + + edit properties of the selected item + Редактировать свойства выделенного элемента + + + + Refresh + Обновить + + + + Refresh the lists + Обновить список + + + + Error + Ошибка + + + + + Confirm + Подтвердить + + + + Are you sure you want to delete the selected user? + Вы действительно хотите удалить выбранного пользователя? + + + + Are you sure you want to delete the selected group? + Вы действительно хотите удалить выбранную группу? + + + + UserDialog + + + User Settings + Настройки пользователя + + + + General + Общие + + + + Full name: + Полное имя: + + + + Login name: + Логин пользователя: + + + + Set password: + Установить пароль: + + + + User ID: + ID пользователя: + + + + Main group: + Главная группа: + + + + Advanced + Расширенные + + + + Login shell: + Оболочка: + + + + Home directory: + Домашний каталог: + + + + Change password: + Изменить пароль: + + + + + + Error + Ошибка + + + + The user ID is in use. + Пользовательский ID уже используется. + + + + The user name cannot be empty. + Имя пользователя не может быть пустым. + + + + The user name is in use. + Имя пользователя уже используется. + + + + Confirm + Подтвердить + + + + Are you sure you want to use an "empty password" for the user? + Вы действительно хотите использовать пустой пароль для этого пользователя? + + + diff --git a/lxqt-admin-user/translations/lxqt-admin-user_ru_RU.desktop b/lxqt-admin-user/translations/lxqt-admin-user_ru_RU.desktop new file mode 100644 index 0000000..372cdf4 --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_ru_RU.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] +Name[ru_RU]=Пользователи и группы +GenericName[ru_RU]=Настройки пользователей и групп +Comment[ru_RU]=Настроить пользователей и группы вашей системы + +#TRANSLATIONS_DIR=translations diff --git a/lxqt-admin-user/translations/lxqt-admin-user_ru_RU.ts b/lxqt-admin-user/translations/lxqt-admin-user_ru_RU.ts new file mode 100644 index 0000000..6cfc4da --- /dev/null +++ b/lxqt-admin-user/translations/lxqt-admin-user_ru_RU.ts @@ -0,0 +1,263 @@ + + + + + GroupDialog + + + Group Settings + Настройки группы + + + + Group name: + Имя группы: + + + + Group ID: + ID группы: + + + + Users belong to this group: + Пользователи, относящиеся к этой группе: + + + + + + Error + Ошибка + + + + The group ID is in use. + ID группы уже используется. + + + + The group name cannot be empty. + Имя группы не может быть пустым. + + + + The group name is in use. + Имя группы уже используется. + + + + MainWindow + + + User and Group Settings + Настройки пользователя и группы + + + + &Users + &Пользователи + + + + Login Name + Логин пользователя + + + + User ID + ID пользователя + + + + Full Name + Полное имя + + + + Group + Группа + + + + Home Directory + Домашний каталог + + + + Show system users (for advanced users only) + Показывать системных пользователей (только для продвинутых пользователей) + + + + &Groups + &Группы + + + + Name + Имя + + + + Group ID + ID группы + + + + toolBar + Панель + + + + Add + Добавить + + + + Add new users or groups + Добавить новых пользователей или группы + + + + Delete + Удалить + + + + Delete selected item + Удалить выбранный элемент + + + + Properties + Свойства + + + + edit properties of the selected item + Редактировать свойства выделенного элемента + + + + Refresh + Обновить + + + + Refresh the lists + Обновить список + + + + Error + Ошибка + + + + + Confirm + Подтвердить + + + + Are you sure you want to delete the selected user? + Вы действительно хотите удалить выбранного пользователя? + + + + Are you sure you want to delete the selected group? + Вы действительно хотите удалить выбранную группу? + + + + UserDialog + + + User Settings + Настройки пользователя + + + + General + Общие + + + + Full name: + Полное имя: + + + + Login name: + Логин пользователя: + + + + Set password: + Установить пароль: + + + + User ID: + ID пользователя: + + + + Main group: + Главная группа: + + + + Advanced + Расширенные + + + + Login shell: + Оболочка: + + + + Home directory: + Домашний каталог: + + + + Change password: + Изменить пароль: + + + + + + Error + Ошибка + + + + The user ID is in use. + Пользовательский ID уже используется. + + + + The user name cannot be empty. + Имя пользователя не может быть пустым. + + + + The user name is in use. + Имя пользователя уже используется. + + + + Confirm + Подтвердить + + + + Are you sure you want to use an "empty password" for the user? + Вы действительно хотите использовать пустой пароль для этого пользователя? + + + diff --git a/lxqt-admin-user/userdialog.cpp b/lxqt-admin-user/userdialog.cpp new file mode 100644 index 0000000..e2b9c50 --- /dev/null +++ b/lxqt-admin-user/userdialog.cpp @@ -0,0 +1,178 @@ +/* + * + * Copyright (C) 2014 Hong Jen Yee (PCMan) + * + * 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 + * + */ + +#include "userdialog.h" +#include + +UserDialog::UserDialog(OobsUser* user, QWidget* parent): + QDialog(), + mFullNameChanged(false), + mHomeDirChanged(false), + mUser(user ? OOBS_USER(g_object_ref(user)) : NULL) +{ + ui.setupUi(this); + + // load all groups + OobsGroupsConfig* groupsConfig = OOBS_GROUPS_CONFIG(oobs_groups_config_get()); + OobsList* groups = oobs_groups_config_get_groups(groupsConfig); + if(groups) + { + OobsListIter it; + gboolean valid = oobs_list_get_iter_first(groups, &it); + while(valid) + { + OobsGroup* group = OOBS_GROUP(oobs_list_get(groups, &it)); + ui.mainGroup->addItem(oobs_group_get_name(group)); + valid = oobs_list_iter_next(groups, &it); + } + } + + connect(ui.loginName, SIGNAL(textChanged(QString)), SLOT(onLoginNameChanged(QString))); + + OobsUsersConfig* userConfig = OOBS_USERS_CONFIG(oobs_users_config_get()); + + // add known shells to the combo box for selection + GList* shells = oobs_users_config_get_available_shells(userConfig); + for(GList* l = shells; l; l = l->next) + { + const char* shell = (const char*)l->data; + ui.loginShell->addItem(QLatin1String(shell)); + } + + if(user) // edit an existing user + { + mOldUid = oobs_user_get_uid(user); + ui.loginName->setReadOnly(true); + ui.loginName->setText(oobs_user_get_login_name(user)); + ui.changePasswd->setText(tr("Change password:")); + ui.uid->setValue(mOldUid); + ui.fullName->setText(oobs_user_get_full_name(user)); + ui.loginShell->setEditText(oobs_user_get_shell(user)); + ui.homeDir->setText(QString::fromLocal8Bit(oobs_user_get_home_directory(user))); + + OobsGroup* group = oobs_user_get_main_group(user); + ui.mainGroup->setEditText(oobs_group_get_name(group)); + } + else // create a new user + { + mOldUid = -1; + ui.loginName->setReadOnly(false); + ui.loginName->setFocus(); + ui.changePasswd->setChecked(true); + ui.uid->setValue(oobs_users_config_find_free_uid(userConfig, 1000, 32768)); + ui.loginShell->setEditText(oobs_users_config_get_default_shell(userConfig)); + ui.mainGroup->setCurrentIndex(-1); + } + +} + +UserDialog::~UserDialog() +{ + if(mUser) + g_object_unref(mUser); +} + +void UserDialog::onLoginNameChanged(const QString& text) +{ + if(!mFullNameChanged) + { + ui.fullName->blockSignals(true); + ui.fullName->setText(text); + ui.fullName->blockSignals(false); + } + + if(!mHomeDirChanged) + { + ui.homeDir->blockSignals(true); + ui.homeDir->setText("/home/" + text); + ui.homeDir->blockSignals(false); + } +} + +void UserDialog::onFullNameChanged(const QString& text) +{ + mFullNameChanged = true; +} + +void UserDialog::onHomeDirChanged(const QString& text) +{ + mHomeDirChanged = true; +} + +void UserDialog::accept() +{ + OobsUsersConfig* usersConfig = OOBS_USERS_CONFIG(oobs_users_config_get()); + uid_t uid = ui.uid->value(); + if(uid != mOldUid && oobs_users_config_is_uid_used(usersConfig, uid)) + { + QMessageBox::critical(this, tr("Error"), tr("The user ID is in use.")); + return; + } + + bool createNew; + if(mUser) + createNew = false; + else + { + createNew = true; + QByteArray loginName = ui.loginName->text().toLatin1(); + if(loginName.isEmpty()) + { + QMessageBox::critical(this, tr("Error"), tr("The user name cannot be empty.")); + return; + } + if(oobs_users_config_is_login_used(usersConfig, loginName)) + { + QMessageBox::critical(this, tr("Error"), tr("The user name is in use.")); + return; + } + mUser = oobs_user_new(loginName); + } + oobs_user_set_uid(mUser, uid); + + QByteArray fullName = ui.fullName->text().toUtf8(); + oobs_user_set_full_name(mUser, fullName); + + // change password + if(ui.changePasswd->isChecked()) + { + QByteArray passwd = ui.passwd->text().toLatin1(); + if(passwd.isEmpty()) // show warnings if the password is empty + { + if(QMessageBox::warning(this, tr("Confirm"), tr("Are you sure you want to use an \"empty password\" for the user?"), QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) + oobs_user_set_password_empty(mUser, true); + } + else + oobs_user_set_password(mUser, passwd); + } + + QByteArray homeDir = ui.homeDir->text().toLocal8Bit(); + oobs_user_set_home_directory(mUser, homeDir); + + // main group + OobsGroupsConfig* groupsConfig = OOBS_GROUPS_CONFIG(oobs_groups_config_get()); + QByteArray groupName = ui.mainGroup->currentText().toLatin1(); + OobsGroup* group = oobs_groups_config_get_from_name(groupsConfig, groupName); + oobs_user_set_main_group(mUser, group); + + if(!createNew) + oobs_object_commit_async(OOBS_OBJECT(mUser), NULL, NULL); + QDialog::accept(); +} diff --git a/lxqt-admin-user/userdialog.h b/lxqt-admin-user/userdialog.h new file mode 100644 index 0000000..f31320b --- /dev/null +++ b/lxqt-admin-user/userdialog.h @@ -0,0 +1,65 @@ +/* + * + * Copyright (C) 2014 Hong Jen Yee (PCMan) + * + * 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 + * + */ + +#ifndef USERDIALOG_H +#define USERDIALOG_H + +#include +#include "ui_userdialog.h" +#include +#include +#include + +class UserDialog : public QDialog +{ + Q_OBJECT + +public: + UserDialog(OobsUser* user = NULL, QWidget* parent = NULL); + ~UserDialog(); + + OobsUser* user() + { + return mUser; + } + + virtual void accept(); + +private Q_SLOTS: + void onLoginNameChanged(const QString& text); + void onFullNameChanged(const QString& text); + void onHomeDirChanged(const QString& text); + +private: + Ui::UserDialog ui; + OobsUser* mUser; + uid_t mOldUid; +#if 0 + QByteArray mOldLoginName; + QByteArray mOldFullName; + QByteArray mOldGroupName; + QByteArray mOldHomeDir; +#endif + + bool mFullNameChanged; + bool mHomeDirChanged; +}; + +#endif // USERDIALOG_H diff --git a/lxqt-admin-user/userdialog.ui b/lxqt-admin-user/userdialog.ui new file mode 100644 index 0000000..4e349cc --- /dev/null +++ b/lxqt-admin-user/userdialog.ui @@ -0,0 +1,193 @@ + + + UserDialog + + + + 0 + 0 + 403 + 293 + + + + User Settings + + + + + + 0 + + + + General + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Full name: + + + + + + + + + + Login name: + + + + + + + + + + Set password: + + + + + + + false + + + QLineEdit::Password + + + + + + + 32768 + + + + + + + User ID: + + + + + + + Main group: + + + + + + + true + + + + + + + + Advanced + + + + + + Login shell: + + + + + + + true + + + + + + + + + + Home directory: + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + UserDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + UserDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + changePasswd + toggled(bool) + passwd + setEnabled(bool) + + + 71 + 125 + + + 192 + 129 + + + + + diff --git a/lxqt-admin.kdev4 b/lxqt-admin.kdev4 new file mode 100644 index 0000000..4115283 --- /dev/null +++ b/lxqt-admin.kdev4 @@ -0,0 +1,3 @@ +[Project] +Manager=KDevCMakeManager +Name=lxqt-admin